What is the use of a $zero register in MIPS?
What does it mean?
lw $t0, myInteger($zero)
A zero register is a processor register that always returns the value zero. It is found primarily in high-performance instruction set architectures, notably the CDC 6600, System/360 and MIPS architecture, among others.
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.
Registers. MIPS has 32 general-purpose registers and another 32 floating-point registers.
The zero register always holds the constant 0. There's not really anything special about it except for the fact that 0 happens to be a very useful constant. So useful that the MIPS designers dedicated a register to holding its value. (This way you don't have to waste another register, or any memory, holding the value.)
EDIT:
As for the question of what that line of code means, it loads the word from MEMORY[myInteger + 0]
into the $t0
register. The lw
command takes both a constant (myInteger
) and a register ($zero
). Not sure why that is, but that's just how the instructions work. Since myInteger
was used as the constant, a register had to be provided, so $zero
was used.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With