Write the code of a stack architecture to compute the expression below. The resu
ID: 3549328 • Letter: W
Question
Write the code of a stack architecture to compute the expression below. The result should be stored on the
stack.
(A+B) * C / (D / E)
You can push multiple operands on the stack. The operation will always use the two topmost values. For
example, to evaluate (A+B+C), you can use the code below:
Push A
Push B
Push C
Add // this does (B+C) and puts it on the top of the stack
Add // this adds the previous result to A
Remember, the division operation divides the topmost value in the stack by the second value.
Explanation / Answer
(A+B) * C / (D / E)
push E
push D
Div // this does (D/E) and put that top of the stack ( as top most is D and then E so first push E first and then push D)
push A
push B
Add //this add(A+B) and put that top of the stack
push C
Mul // this multiple result of (A+B) and C and put at top of stack
Div // this does ( result of (A+B)*C / (result of (D/E) ) and put that top of stack
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.