The point
Get one program all the way to a running executable. Nothing in this course feels real until that happens, and the three problems of code generation stop being a list the moment you have to solve them.
Do this
- By hand first. Take three TAC instructions —
— and write the MIPS yourself, assumingt0 = 2 + 3 total = t0 PRINT totaltotallives at0($sp). You needli,add,sw,lw, and two syscalls. - Assemble and run YOUR version. Wrap it in a
.text / .globl main / main:skeleton and runspim -file yours.s. Fix it until it prints 5. - Name the decisions you just made. For each of Dragon's three problems — instruction selection, register allocation, evaluation order — write one sentence saying what you chose and what the alternative was.
- Now implement the code generator for those three TAC opcodes.
- Diff. Compare the compiler's output with your hand-written version. Where the compiler emitted more instructions, say why, and whether the extras are actually necessary.
- Finish the phase and run every test in
tests/.
The two syscalls you need
li $v0, 1 # print integer, value in $a0
syscall
li $v0, 10 # exit
syscall
Deliverable
Your hand-written .s, the compiler's, a screenshot of both running in SPIM, your three sentences from step 3, and your answer to step 5. This is Lab Questions 9 and 10.