In C to MIPS conversion I see a lot 0some register or 4some

In C to MIPS conversion I see a lot 0(some register) or 4(some register) in a lot of the code. I\'ve been trying to find a solid example to it along with a reason why it is done but have no luck. Can anyone explain what the 0 and 4 before a register does as well as provide an example?

Solution

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.

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.)

MIPS is a load/store architecture, meaning that values are loaded from memory address into registers and stored from registers to memory address. For example:

MIPS load and store instructions are the only ones that can directly address memory.

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
In C to MIPS conversion I see a lot 0(some register) or 4(some register) in a lot of the code. I\'ve been trying to find a solid example to it along with a reas

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site