MIPS has two primary types of registers, integer registers and floating point registers. In addition, MIPS has a small number of special purpose control registers.
There are register usage conventions that specify how main programs and subprograms should coordinate their use of registers. Adhering to these conventions is not mandatory, but it is helpful for avoiding problems that are difficult to debug.
Simple programs should only use the following registers:
syscall
parameters
syscall
codes
and return values
For more complex programs, there are register usage conventions that specify how main programs and subprograms should coordinate their use of registers.
Alternate Name | Register Name | Use |
---|---|---|
$zero | $0 | constant value 0 |
$s0 - $s8 | $16 - $23, $30 | saved values - preserved across calls |
$sp | $29 | stack pointer - preserved across calls |
$ra | $31 | return address - not preserved across calls |
$a0 - $a3 | $4 - $7 | the first four parameters - not preserved across calls |
$t0 - $t9 | $8 - $15, $24 - $25 | temporaries - not preserved across calls |
$v0 - $v1 | $2 - $3 | expression evaluation and subprogram return value - not preserved across calls |
$at | $1 | reserved by the assembler - dangerous to use |
$gp | $28 | global pointer - dangerous to use |
$k0 - $k1 | $26 - $27 | reserved by the operating system - dangerous to use |
The usage convention designations have significant implications for both subprograms and their callers.
Register $0 is special in that it always contains the value 0. If it is specified as a destination operand of an instruction then the result of the instruction is not stored.
When writing MAL code, it is easier to stick to the conventions if you refer to registers by their alternate name.
Alternate Name | Register Name | Use |
---|---|---|
$zero | $0 | constant value 0 |
$s0 - $s8 | $16 - $23, $30 | saved values - preserved across calls |
$sp | $29 | stack pointer - preserved across calls |
$ra | $31 | return address - not preserved across calls |
$a0 - $a3 | $4 - $7 | the first four parameters - not preserved across calls |
$t0 - $t9 | $8 - $15, $24 - $25 | temporaries - not preserved across calls |
$v0 - $v1 | $2 - $3 | expression evaluation and subprogram return value - not preserved across calls |
$at | $1 | reserved by the assembler - dangerous to use |
$gp | $28 | global pointer - dangerous to use |
$k0 - $k1 | $26 - $27 | reserved by the operating system - dangerous to use |
Unfortunately, the MIPS floating-point registers do not have alternate names.
Register Name | Use |
---|---|
$f0, $f2 | floating point subprogram return value - not preserved across calls |
$f4 - $f10 | temporaries - not preserved across calls |
$f12, $f14 | the first 2 floating point parameters - not preserved across calls |
$f16, $f18 | temporaries - not preserved across calls |
$f20 - $f30 | saved values - preserved across calls |