Assume a Machine has a single register and six instructions

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-
ABC+/CBA*+
ABC+-
AB-*CBA+-*
AB-C+DEF-+$
ABC-/BA-+/
ABCDE-+$*EF*-
ABC+$CBA-+*
ABC+*CBA-+*
AB0+/CBA+-/

Keep in mind that you are NOT evaluating the postfix expression, you are generating the machine language instructions that would perform the evaluation if actually executed.

In your analysis, be sure to discuss the implementation you choose and why, why a stack makes sense. Consider a recursive solution (you do not need to implement recursion) and compare it to your iterative solution. Is one better than the other? Why? Tell us what you learned and what you would do differently. Be sure to review the programming assignment guidelines, including the formatting requirements for the analysis. You may not use library functions. You must write your own code, in particular you must write the stack code. Be sure to include the stack source code in your suibmission. You must read and write from named files.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.