|1||PUSH word||push contents of word on top of stack|
|2||POP word||pop top of stack and store at word|
|3||ADD||remove top two elements of stack, compute their sum, and push result on top of stack|
|4||SUB||remove top two elements of stack, compute their difference (second from top element - top element), and push result on top of stack|
For example, the sequence: PUSH 1, PUSH 2, ADD, POP 3 would store the sum of the contents of locations 1 and 2 into location 3, and would leave the stack empty. Each instruction is stored as a single byte, in which the opcode is the high-order 3 bits and the address (for PUSH and POP) the low-order 5 bits.
Your program should interpret the sequence of stack computer instructions starting at byte 500H (up to the halt instruction), using bytes 600H to 61FH for the simulated memory. (We will test the program by storing our own instruction sequence at 500H, and some values at 600H.)
For (2 points) extra credit: instead of interpreting the stack computer instructions, translate them into 8088 instructions starting at location 700H and then execute the resulting code. (This is of no advantage if the stack instructions are to be executed just once, but potentially a big gain if they are to be executed many times, since the translation only has to be done once. This is a very simplified analog of the Java "Just In Time" bytecode compiler, which translates JVM instructions into x86 instructions as needed during execution.)
Be sure to include comments in your program, and in particular include a line with your name and whether you are claiming the extra credit. A good solution will include error checks (for example, that the opcode is valid and that there is data on the stack before a POP, ADD, or SUB is executed); it is sufficient to halt on an error.
This assignment is due on October 17th. There is a penalty of 1/2 point (out of a total of 8 points) for each day late.
Email your assignment (the listing file produced by the Dewar assembler)
to our e-tutor, Aldo Nunez, at email@example.com. Include
your name and "Asgn 2" in the subject line.