Your problem is to convert a given infix expression into a sequence of assembly
ID: 3801611 • Letter: Y
Question
Your problem is to convert a given infix expression into a sequence of assembly instructions that evaluates the expression and leaves the result in the register. You will do this by using postfix expressions. First, you will convert a given infix expression into the corresponding postfix expression. In the second step, you will convert postfix to the required sequence of assembly instructions. You will read the infix expression from a file, and write the result to another file.
For example,
given the following infix expression:
( ( A + ( B * C ) ) / ( D - E ) )
we get the postfix expression:
A B C * + D E - /
This results in an assembly program that looks like:
Your program output should be:
Requirements:
You CANNOT use std::string and must construct your stack using a linked list you build.
Implementation:
Create a generic (template) ADT stack class.
Implement using a linked list.
You must implement a destructor, copy constructor, constant time swap, and assignment.
You will need to have a stack of strings.
Use the following files as a starting point:
-----------------------------------------------------------------------
stack.hpp
-----------------------------------------------------------------------
Opcode Operand Comment LOAD B Load in B. MULR C B * C. STOR TMP1 Save results of B * C. LOAD A Load A. ADDR TMP1 Add A to B * C. STOR TMP2 Save result. LOAD D Load D. SUBR E D - E. STOR TMP3 Save result. LOAD TMP2 Get A + B * C. DIVR TMP3 Divide it by D - E. STOR TMP4 Save result, also still in register.