This week's lab will consist of practice writing out some linked lists of "intermediate code".
fun main() {
var i : Int = 5;
i = i * i + 1;
println("Variable i is $i.");
}
Write a standalone main() procedure that (manually) builds
the linked list of TAC for:
.string 8 ; string region size (multiple of 8)
Variable i is %d.\000 ; ""
.code
proc main,0,32
ASN loc:0,const:5 ; i = 5
MUL loc:8,loc:0,loc:0 ; t1 = i * i
ADD loc:16,loc:8,const:1 ; t2 = t1 + 1
ASN loc:0,loc:16 ; i = t2
PARAM loc:0 ; push param 2 (i)
PARAM str:0 ; push param 1 ("Variable i is %d")
CALL printf,2,loc:24 ; t5 = printf()
RETURN
Write a tacprint() function that prints out a linked list
of three-address
instructions to standard out. Use it to approximate the above (minus the
assembler comments from ; to the end of various lines).
Note: in real life, what corrections or additions are needed for this example?