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:
“Never to walk from the stations lamps and laurels
Carrying my fathers lean old leather case
Crumbling like the register at the hotel....”
—Philip Larkin (19221986)
“I am using it [the word perceive] here in such a way that to say of an object that it is perceived does not entail saying that it exists in any sense at all. And this is a perfectly correct and familiar usage of the word.”
—A.J. (Alfred Jules)