[prev] 27 [next]

Rendering C in MIPS: Functions (cont)

Register usage conventions when f() (caller) calls g() (callee):
  • caller saved registers (saved by f())
    • f() tells g() "If there is anything I want to preserve in these registers, I have already saved it before calling you"
    • g() tells f() "Don't assume that these registers will be unchanged when I return to you"
    • e.g.  $t0 .. $t9,   $a0 .. $a3
  • callee saved registers (saved by g())
    • f() tells g() "I assume the values of these registers will be unchanged when you return"
    • g() tells f() "If I need to use these registers, I will save them first and restore them before returning"
    • e.g.  $s0 .. $s7,   $sp,   $fp