Department of Electrical and Computer Engineering
The University of Texas at Austin
EE 306, Fall 2006
Instructor: Yale N. Patt
TAs: Aseem Bathla, Cameron Davison, Lisa de la Fuente, Phillip Duran, Jose Joao,
Jasveen Kaur, Rustam Miftakhutdinov,
Veynu Narasiman, Nady Obeid, Poorna Samanta.
Supplemental Note: A stack machine
November 27, 2006
Let's assume we add opcodes SUB, MUL, and DIV to the LC-3 (making
it the LC-3.5, perhaps). And, assume we replace the register file with
a stack. The instructions would work as follows:
* Loads would take from memory and PUSH on the stack
* Stores would POP the stack and write to memory
* Operates would POP, POP, operate, and PUSH
Note that no addresses are needed for operates since the computer knows
EXACTLY where to find the sources and where to write the destination.
With such a machine, a high-level language programmer could write
and the LC-3.5 Compiler would translate this to:
Actually, in mathematics, we call this representation Postfix or Polish
Suppose I do not have an LC-3.5, and am stuck with just the LC-3, and
I wish to Simulate a Stack machine (as in the Calculator program in Chap.10).
1. I could write subroutines to ADD, SUB, MUL, and DIV.
Each subroutine would POP the top two elements from the stack, perform
the operation, and PUSH the result onto the stack.
2. Then my main routine to perform the above assignment statement would be: