MIPS Assembly/Register File

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Registers[edit | edit source]

MIPS has 32 general-purpose registers and another 32 floating-point registers. Registers all begin with a dollar-symbol ($). The floating point registers are named $f0, $f1, ..., $f31. The general-purpose registers have both names and numbers, and are listed below. When programming in MIPS assembly, it is usually best to use the register names.

Number Name Comments
$0 $zero, $r0 Always zero
$1 $at Reserved for assembler
$2, $3 $v0, $v1 First and second return values, respectively
$4, ..., $7 $a0, ..., $a3 First four arguments to functions
$8, ..., $15 $t0, ..., $t7 Temporary registers
$16, ..., $23 $s0, ..., $s7 Saved registers
$24, $25 $t8, $t9 More temporary registers
$26, $27 $k0, $k1 Reserved for kernel (operating system)
$28 $gp Global pointer
$29 $sp Stack pointer
$30 $fp Frame pointer
$31 $ra Return address

Zero Register[edit | edit source]

The zero register ($zero or $0) always contains a value of 0. It is built into the hardware and therefore cannot be modified.

$at Register[edit | edit source]

The $at (Assembler Temporary) register is used for temporary values within pseudo commands. It is not preserved across function calls. For example, with the (slt $at, $a0, $s2) command, $at is set to one if $a0 is less than $s2, otherwise it is set to zero.

$v Registers[edit | edit source]

The $v Registers are used for returning values from functions. They are not preserved across function calls.

Argument Registers[edit | edit source]

The $a registers are used for passing arguments to functions. They are not preserved across function calls.

Temporaries[edit | edit source]

The temporary registers are used by the assembler or assembly language programmer to store intermediate values. They are not preserved across function calls.

Saved Temporaries[edit | edit source]

Saved Temporary registers are used to store longer lasting values. They are preserved across function calls.

$k Registers[edit | edit source]

The k registers are reserved for use by the OS kernel. They may change randomly at any time as they are used by interrupt handlers.

Pointer Registers[edit | edit source]

  • Global Pointer ($gp) - Usually stores a pointer to the global data area (such that it can be accessed with memory offset addressing).
  • Stack Pointer ($sp) - Used to store the value of the stack pointer.
  • Frame Pointer ($fp) - Used to store the value of the frame pointer.
  • Return Address ($ra) - Stores the return address (the location in the program that a function needs to return to).

All Pointer Registers are preserved across function calls.