# ------------------------------------------------------ # FuncDef for main([]) main: addi $sp, $sp, -12 # alloc space for $ra, $sp, and local vars sw $ra, 0($sp) sw $fp, 4($sp) add $fp, $0, $sp # result = max([10, 2]) addi $t0, $fp, 8 # compute address of result # max([10, 2]) addi $sp, $sp, -4 # all regs are caller saved... sw $t0, 0($sp) addi $sp, $sp, -8 # push arguments addi $t0, $0, 10 sw $t0, 0($sp) addi $t0, $0, 2 sw $t0, 4($sp) jal max # okay, now invoke max() addi $sp, $sp, 8 # pop arguments and... lw $t0, 0($sp) # restore the saved register addi $sp, $sp, 4 # and "free" it's space add $t1, $0, $v0 # assign return value to result sw $t1, 0($t0) # printInt([result]) addi $sp, $sp, -4 # make room for the argument lw $t0, 8($fp) # fetch the argument sw $t0, 0($sp) # push and.. jal printInt # jump to function addi $sp, $sp, 4 # pop the argument add $t0, $0, $v0 __L1: nop lw $ra, 0($fp) # code to "return" from function lw $fp, 4($fp) addi $sp, $sp, 12 jr $ra # jump back to caller, where ever that is