Machine Problem 5
22C:18, Fall 1996
Due Thursday Dec. 5, 1995, at 5:00 PM
Douglas W. Jones
Write a SMAL Hawk program to emulate an RPN calculator that includes
the control structures for loops, conditional loop exit, and memory
reference. The following commands should be added to the calculator
language implemented in MP3 and MP4:
- { -- begin loop:
- } -- end loop:
- Curly braces mark the start and end of each loop.
- = -- exit on equals:
- > -- exit on greater:
- < -- exit on less than:
- Comparison operators pop the top two elements on the stack and compare
them, exiting from the immediately enclosing loop if the comparison is true.
For the purpose of comparison, the top item on stack goes on the right hand
side of the comparison operator.
- S -- memory save operation:
- The top item on the stack is used as a memory address, and the item
below it is saved in that address; both are popped from the stack.
- R -- memory recall operation:
- The top item on the stack is used as a memory address, and is replaced
by the value taken from memory.
This calculator should extend the behavior of MP4! Large parts of your
program will be unchanged from MP4 or from one of the solutions to be
distributed. The only difference should be in the addition of memory and
control structures.
You are responsible for deciding on an appropriate memory size.