Machine Problem 4

22C:18, Fall 1996

Due Thursday Nov. 14, 1995, at 5:00 PM

Douglas W. Jones

Write a SMAL Hawk program to emulate an RPN calculator.

This calculator should have exactly the same external behavior as the calculator for MP3! Large parts of your program will be unchanged. The only difference lies in the way your program evaluates the expressions on the calculator's command line.

In MP3, when you saw the command line E1P, as the calculator processed E, it would push 0 on the stack. As the calculator processed 1, it would multiply the top item on the stack by 10 and then add 1, and as it saw P, it would print the top item on the stack and pop it.

In MP4, when your calculator processes any command, it should store machine instructions in a code buffer, and then, once all commands have been processed, it should execute the code stored in the code buffer. The execution of that code buffer then computes and outputs the calculator's output.

For example, E might append the following instructions to the code buffer to cause a zero to be pushed:

	ADDI   RF,4
	STORES 0,RF
Similarly, 1 might append this to multiply by 10 and add 1:
	LOADS  R3,RF
        ADDSL  R3,R3,2
        SL     R3,1
Similarly, P might append this to pop and print:
	LOADS  R3,RF
	ADDI   RF,-4
        LIL    R1,MYPRINT
        JSRS   R1,R1
When this sequence of instructions is executed, it causes the calculator to do exactly what you expect for E1P!