http://ozark.hendrix.edu/~burch/cs/230/cso/ch13-sub/index.html
Assembly programmers divide the registers into caller-save registers and callee-save registers. Caller-save registers are those that the subroutine may change, such as R0 through R3 in the ARM convention described above: They are caller-save because since a caller of a subroutine must save the registers’ values if it wants the values after the subroutine completes. Callee-save registers are those that a subroutine must leave unchanged, like R4 through R12 is the convention described above: Upon being called, the subroutine (the callee) must save the registers’ values if it wishes to use them.
It’s beneficial for a calling convention to designate both caller-save registers and callee-save registers. If the convention designated all registers as callee-save, then subroutines would not be able to use any registers at all without saving them onto the stack first — which would be a waste, since some of the saved registers would be transient values that the calling subroutine did not care about long-term. And if the convention designated all registers as caller-save, then programmers would be forced to save many registers before every call to a subroutine and to restore them afterwards, lengthening the amount of time to call a subroutine.
/************ comment ******************/
Caller only needs to save the caller-save registers that is live *across* the subroutine call. If it will not be used after the calling, there is no need to save/restore them.
Callee only needs to save the callee-save registers that are used in the body of its subroutine.
If it is a leaf procedure, just use the caller-save registers as often as possible. If it is a non-leaf procedure, if the variable is live across the call, callee-save register is preferred. Otherwise, just use the caller-save registers.
http://classes.engr.oregonstate.edu/eecs/spring2009/cs472/MIPSXCallingXConventionsXSummary.pdf
For MIPS, argument registers $a0 ~ $a3 are used to pass the first four
arguments to a subroutine. These arguments are not copied into the Argument Section by the calling subroutine, but the space is reserved. If this procedure is non-leaf, before calling other subroutine, it should save the argument registers(the number is according to its own argument number) in the reserved area of caller’s stack frame. Then it can reuse the argument registers to pass the arguments to the callee.
40.425869
-86.908066