complement notes in 11.04
This commit is contained in:
56
notes/7.md
Normal file
56
notes/7.md
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
# Code Generation 2
|
||||||
|
|
||||||
|
## Stack Machine
|
||||||
|
|
||||||
|
Consider two instructions
|
||||||
|
* `push i`
|
||||||
|
* `add i`
|
||||||
|
|
||||||
|
It is not efficient because all stack is considered as memory (which is slower than register).
|
||||||
|
|
||||||
|
### Utilizing Register Files
|
||||||
|
|
||||||
|
Keep the top of the stack in a register, so `add` requires only a single memory access.
|
||||||
|
|
||||||
|
* `acc <- i`
|
||||||
|
* `push acc`
|
||||||
|
* `pop`
|
||||||
|
* `add`
|
||||||
|
|
||||||
|
|
||||||
|
### Code Generation From Stack Machine
|
||||||
|
|
||||||
|
Assume that stack grows towards lower addresses.
|
||||||
|
|
||||||
|
|
||||||
|
## MIPS
|
||||||
|
|
||||||
|
32 regs
|
||||||
|
|
||||||
|
`$sp`, `$a0`, `$t1`
|
||||||
|
|
||||||
|
* `lw`
|
||||||
|
* `add`
|
||||||
|
* `sw`
|
||||||
|
* `addi`
|
||||||
|
* `li`
|
||||||
|
* `mv`
|
||||||
|
|
||||||
|
|
||||||
|
Converting Stack to MIPS ISA
|
||||||
|
|
||||||
|
* `acc <- i`
|
||||||
|
* `li $a0 i`
|
||||||
|
|
||||||
|
### Optimizing
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Branch
|
||||||
|
|
||||||
|
`beq $1 $2 lbl`
|
||||||
|
`b lbl`
|
||||||
|
|
||||||
|
|
||||||
|
## Function
|
||||||
|
|
||||||
BIN
pdf/L7.pdf
Normal file
BIN
pdf/L7.pdf
Normal file
Binary file not shown.
Reference in New Issue
Block a user