-
Notifications
You must be signed in to change notification settings - Fork 139
MIPS registers
Register is a small amount of bits that CPU can access extremely quickly. Typical sizes of one registers are 8, 16, 32 and 64 bits. On RISC processors instruction usually performs only on registers, except loads and stores.
User accessible registers can be written or read by programmer using processor instructions. In some architectures, registers hold only one type of data: integer, floating point, vector, address etc.; in others, so-called general purpose registers can hold any or almost any type of data, usually integer and address.
Some registers stores stack pointer, frame pointer, program counter etc.; they are called special purpose registers. Availability to change their value directly or only with special instruction depends on architecture.
Constant registers saves constant values, e.g. 0, 1, pi; programmer is not available to write to these registers, read-only access.
Model-specific registers saves information about processor itself: model, extensions. Sometimes there are special hardware register with temperature, voltage or random number.
MIPS instruction uses 5 bits for register addressing, so there can be 2^5 = 32 registers. They are not equal.
Number | Name | Use | Preserved across function calls? | Used in project? |
---|---|---|---|---|
0 | $zero |
constant 0 | — | yes |
1 | $at |
assembler temporary | no | yes |
2, 3 | $v0, $v1 |
function return values | no | no |
4 - 7 | $a0 - $a3 |
function arguments | no | no |
8 - 15 | $t0 - $t7 |
temporaries | no | yes |
16 - 23 | $s0 - $s7 |
temporaries | yes | yes |
24, 25 | $t8, $t9 |
temporaries | no | yes |
26, 27 | $k0, $k1 |
reserved for OS kernel | — | no |
28 | $gp |
global pointer | — | no |
29 | $sp |
stack pointer | — | no |
30 | $s8 |
temporaries | yes | yes |
31 | $ra |
return address | — | no |
Registers marked as not used are not used in our simulator now.
Note: the whole table is available by this link |
---|
Zero register is a special register that holds constant 0 inside. It can be overwritten, but write operation like sll $zero, $zero, 0
is not forbidden — it's result will be ignored.
Assembler temporary register is used by assembler while pseudo-instructions are expanded:
bge $s, $t, label
# is equal to
slt $at, $s, $t
beq $at, $zero, label
Return address register is updated by "jump and link" (jal
, jalr
) commands. It stores here address of the consequent instructions. Backward jump can be performed by jr $ra
HI
and LO
register are used by multiplication and division instructions. Multiplication stores higher 32 bits of results to HI
, and lower 32 bits to LO
.
Division instructions stores result to LO
, and remainder to HI
register.
Programmer can read values from HI
and LO
by instructions mfhi
and mflo
, write is required rare, but also possible by mthi
and mtlo
.
addi $t0, $zero, 25
addi $t1, $zero, 6
div $t0, $t1
mflo $t2 # t2 = t0 / t1 = 25 / 6 = 4
mfhi $t3 # t3 = t0 % t1 = 25 % 6 = 1
MIPT-V / MIPT-MIPS — Cycle-accurate pre-silicon simulation.