























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A lecture transcript from dr. Sean peisert's ecs 142 computer science course in spring 2009. The lecture focuses on stack machines, their optimization, and the use of stack machines in code generation. The lecture covers the concept of stack machines, their advantages, an example of a stack machine program, and the optimization of stack machines using an accumulator.
Typology: Study Guides, Projects, Research
1 / 31
This page cannot be seen from the preview
Don't miss anything!
























Lecture 20 Dr. Sean Peisert โ ECS 142 โ Spring 2009 1
2
Consider two instructions
push i โ place the int i on top of the stack
add โ pop two elements, add them, and put the result back on the stack
A program to compute 7 + 5:
push 7
push 5
add 4
Stack Machine. Example.
Each instruction
takes operands from the top of the stack
removes those operands from the stack
computes the required operation on them
pushes the result on the stack 5 ... ... ... ... 7 7 12 5
Why Use a Stack Machine?
This is one reason why Java Bytecodes use a stack evaluation model 7 Optimizing the Stack Machine
The โaddโ instruction is now: acc โ acc + top_of_stack - Only one memory operation! 8
Stack Machine w/Accumulator. Example.
Compute 7 + 5 using an accumulator 10 ... ... ... ... 12 7 7
acc (^75) stack acc โ 7 push acc acc โ (^5) acc โ acc + top of stack pop
Code acc โ 3 push acc acc โ 7 push acc acc โ 5 acc โ acc + top _ of_stack pop acc โ acc + top _ of_stack pop Acc 3 3 7 7 5 12 12 15 15 Stack
From Stack Machines to MIPS
Simulating a Stack Machine
The address of the next location on the stack is kept in MIPS register $sp The top of the stack is at address $sp + 4. 14
Prototypical Reduced Instruction Set Computer (RISC) architecture
Arithmetic operations use registers for operands and results
Must use load and store instructions to use operands and results in memory
32 general purpose registers (32 bits each)
We will use $sp, $a0, and $t1 (a temporary register)
Weโll give you a SPIM document for more details. 16
A Sample of MIPS Instructions
add reg1 reg2 reg sw reg1 offset(reg2) addiu reg1 reg2 imm li reg imm reg โ imm 17
A language with integers and integer operations P โD; P | D D โdef id(ARGS) = E; ARGS โ id, ARGS | id E โint | id | if E 1 = E 2 then E 3 else E 4 | E 1 + E 2 | E 1 โE 2 | id(E 1 ,โฆ,En) 19
20