Machine Problem 4

22C:18, Spring 1996

Due Tuesday Apr. 2, 1995, in discussion

Douglas W. Jones

Write a compiler for the RPN calculator instruction set used for machine problems 2 and 3. This program should repeatedly accept lines of input from the user and execute them, so that, from a user perspective, the program behaves exactly the same as machine problem 2 (other than a difference in the header printed at the start of a run), but instead of executing the program interpretively, it should compile each line of the input to an M68000 procedure in memory, then call that procedure in order to execute the code.

This was discussed in class in some detail. In summary, your program should set aside some area of memory in which to place the compiled calculator instructions. This stream of instructions should end with an RTS, and after filling this area of memory with the instructions that represent one line of calculator code, your program should use a JSR instruction to get to the first instruction in the compiled code.

If the compiled code uses A0 as the calculator's stack pointer, and if it keeps the topmost item on the stack in D0, your compiler might append the following string of instructions to the compiled code when it encounters an E instruction:

	MOVE.W	D0,-(A0)	; push and
	CLR.W	D0		; put zero on the stack top
Please write the code to compile each one-letter calculator instruction as a procedure. This will simplify your solution to the next assignmens.

Please make it compile the subset of the calculator instruction set from MP2 first, before you make it handle jumps, loads and stores!