Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA: This answer is already exists in the archive( http://www.chegg.com/homewor

ID: 3601370 • Letter: J

Question

JAVA: This answer is already exists in the archive( http://www.chegg.com/homework-help/questions-and-answers/need-help-java-programming-homework-question-assume-machine-single-register-six-instructio-q8350267)  I am mainly looking for comments detailing the steps so I can understand the process used.Thanks

Use of Stacks Assume a Machine has a single register and six instructions (Problem 2.3.10 from the LAT text.)

LD A places the operand A in the register

ST A places the contents of the register into the variable A

AD A adds the contents of the variable A to the register

SB A subtracts the contents of the variable A from the register

ML A multiples the contents of the register by the variable A

DV A divides the contents of the register by the variable A

Write a program that accepts a postfix expression containing single letter operands and the operators +, -, *, and / and prints a sequence of instructions to evaluate the expression and leaves the result in the register. Use variables of the form TEMPn as temporary variables. For example, using the postfix expression ABC*+DE-/ should print the following:

LD B

ML C

ST TEMP1

LD A

AD TEMP1

ST TEMP2

LD D

SB E

ST TEMP3

LD TEMP2

DV TEMP3

ST TEMP4

Use the following postfix expressions for input

AB+C-

AB-C+DEF-+$

ABC-/BA-+/

ABCDE-+$*EF*

Explanation / Answer

Below is the step by step exapnation of every operation performed on register:

using the postfix expression ABC*+DE-/ should print the following:

LD B -->Add B in Register

ML C -->Multiple Register Content(B) with C

ST TEMP1 -->Assign the Register's content to Variable TEMP1

LD A --> places the operand A in the register

AD TEMP1 -->adds the contents of the variable TEMP1 to the register

ST TEMP2 -->places the contents of the register into the variable TEMP2

LD D -->places the operand D in the register

SB E -->subtracts the contents of the variable E from the register

ST TEMP3 --> places the contents of the register into the variable TEMP3

LD TEMP2 -->places the operand TEMP2 in the register

DV TEMP3 -->divides the contents of the register by the variable TEMP3

ST TEMP4 --> places the contents of the register into the variable TEMP4