MIPS Architecture - Compiler Register Usage

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.

Registers for O32 Calling Convention
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
Registers for N32 and N64 Calling Conventions
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:

    A funeral is not death, any more than baptism is birth or marriage union. All three are the clumsy devices, coming now too late, now too early, by which Society would register the quick motions of man.
    —E.M. (Edward Morgan)

    ...Often the accurate answer to a usage question begins, “It depends.” And what it depends on most often is where you are, who you are, who your listeners or readers are, and what your purpose in speaking or writing is.
    Kenneth G. Wilson (b. 1923)