# # code from 1/22 class # #### start of standard boilerplate .text .globl main main: # # opening linkage (save return address) # addi $sp, $sp, -4 sw $ra, 0($sp) #### end of standard boilerplate # C code: # f = (g + h) - (i + j) # where all variables are 32-bit integers # for purposes of discussion, put these variables one after another in # an area labeled "Local" # register usage: # $s0 for f # $s1 for g # $s2 for h # $s3 for i # $s4 for j # $s5 for address of Local la $s5, Local # $s5 <- &Local lw $s1, 4($s5) # $s1 <- g lw $s2, 8($s5) # $s2 <- h lw $s3, 12($s5) # $s3 <- i lw $s4, 16($s5) # $s4 <- h add $t0, $s1, $s2 # $t0 <- g + h add $t1, $s3, $s4 # $t1 <- i + j sub $s0, $t0, $t1 # $s0 <- (g + h) - (i + j) sw $s0, 0($s5) # f <- $s0 #### start of more standard boilerplate # # closing linkage (get return address and restore stack pointer) # lw $ra, 0($sp) addi $sp, $sp, 4 jr $ra .end main .data #### end of standard boilerplate # # area for variables and constants # # example: Local: .word 1, 4, 2, 3, 1 # values for f, g, h, i, j