# void main (void) { # int x = 3; # x = 5; # foo (x+1); # x = 9; # } # void foo (int param) { # int y = 7; # y = param; # } .text # void main (void) { __start: # Stack frame # 4($sp) = x (local variable) # Register $t0 used for scratch work. # int x = 3; addi $sp,$sp,-4 li $t0,3 sw $t0,4($sp) # x = 5; li $t0,5 sw $t0,4($sp) # foo (x+1); lw $t0,4($sp) add $t0,$t0,1 addi $sp,$sp,-4 sw $t0,4($sp) jal foo addi $sp,$sp,4 # x = 9; li $t0,9 sw $t0,4($sp) # } done # void foo (int param) { foo: # Stack frame # 4($sp) = y (local variable) # 8($sp) = return address # 12($sp) = param (parameter) # Note that param is already there -- we don't have to allocate # space for it. # Register $t0 used for scratch work. addi $sp,$sp,-8 sw $ra,8($sp) # int y = 7; li $t0,7 sw $t0,4($sp) # y = param; lw $t0,12($sp) sw $t0,4($sp) # } lw $ra,8($sp) addi $sp,$sp,8 jr $ra