See Below.
mysub() Here is the complete subroutine. Notice that the code in the body of the subroutine is only five statements long. But the entire subroutine, including the code for subroutine linkage, is 22 statements long! Subroutine linkage can be expensive.
# int mysub( int arg )
# {
# int b,c; // b: 0($fp)
# // c: 4($fp)
# b = arg*2;
# c = b + 7;
#
# return c;
# }
.text
.globl mysub
mysub:
# prolog
sub $sp,$sp,4 # 1. Push return address
sw $ra,($sp)
sub $sp,$sp,4 # 2. Push caller's frame pointer
sw $fp,($sp)
sub $sp,$sp,4 # 3. Push register $s1
sw $s1,($sp)
sub $fp,$sp,8 # 4. $fp = $sp - space_for_variables
move $sp,$fp # 5. $sp = $fp
# body of subroutine
mul $s1,$a0,2 # arg*2
sw $s1,0($fp) # b = " "
lw $t0,0($fp) # get b
add $t0,$t0,7 # b+7
sw $t0,4($fp) # c = " "
# epilog
lw $v0,4($fp) # 15. Put return value in $v0
add $sp,$fp,8 # 16. $sp = $fp + space_for_variables
lw $s1,($sp) # 17. Pop register $s1
add $sp,$sp,4 #
lw $fp,($sp) # 18. Pop $fp
add $sp,$sp,4 #
lw $ra,($sp) # 19. Pop $ra
add $sp,$sp,4 #
jr $ra # 20. return to caller
What must the caller do when control returns to it?