Compiler Register Usage
The hardware architecture specifies that:
- General purpose register $0 always returns a value of 0.
- General purpose register $31 is used as the link register for jump and link instructions.
- HI and LO are used to access the multiplier/divider results, accessed by the mfhi (move from high) and mflo commands.
These are the only hardware restrictions on the usage of the general purpose registers.
The various MIPS tool-chains implement specific calling conventions that further restrict how the registers are used. These calling conventions are totally maintained by the tool-chain software and are not required by the hardware.
Name | Number | Use | Callee must preserve? |
---|---|---|---|
$zero | $0 | constant 0 | |
$at | $1 | assembler temporary | No |
$v0–$v1 | $2–$3 | values for function returns and expression evaluation | No |
$a0–$a3 | $4–$7 | function arguments | No |
$t0–$t7 | $8–$15 | temporaries | No |
$s0–$s7 | $16–$23 | saved temporaries | Yes |
$t8–$t9 | $24–$25 | temporaries | No |
$k0–$k1 | $26–$27 | reserved for OS kernel | |
$gp | $28 | global pointer | Yes |
$sp | $29 | stack pointer | Yes |
$fp | $30 | frame pointer | Yes |
$ra | $31 | return address |
Name | Number | Use | Callee must preserve? |
---|---|---|---|
$zero | $0 | constant 0 | |
$at | $1 | assembler temporary | No |
$v0–$v1 | $2–$3 | values for function returns and expression evaluation | No |
$a0–$a7 | $4–$11 | function arguments | No |
$t4–$t7 | $12–$15 | temporaries | No |
$s0–$s7 | $16–$23 | saved temporaries | Yes |
$t8–$t9 | $24–$25 | temporaries | No |
$k0–$k1 | $26–$27 | reserved for OS kernel | |
$gp | $28 | global pointer | Yes |
$sp | $29 | stack pointer | Yes |
$s8 | $30 | frame pointer | Yes |
$ra | $31 | return address |
Registers that are preserved across a call are registers that (by convention) will not be changed by a system call or procedure (function) call. For example, $s-registers must be saved to the stack by a procedure that needs to use them, and $sp and $fp are always incremented by constants, and decremented back after the procedure is done with them (and the memory they point to). By contrast, $ra is changed automatically by any normal function call (ones that use jal), and $t-registers must be saved by the program before any procedure call (if the program needs the values inside them after the call).
Read more about this topic: MIPS Architecture
Famous quotes containing the words register and/or usage:
“Every new baby is a blind desperate vote for survival: people who find themselves unable to register an effective political protest against extermination do so by a biological act.”
—Lewis Mumford (18951990)
“Pythagoras, Locke, Socratesbut pages
Might be filled up, as vainly as before,
With the sad usage of all sorts of sages,
Who in his life-time, each was deemed a bore!
The loftiest minds outrun their tardy ages.”
—George Gordon Noel Byron (17881824)