1

I was reading about 32 bits Mips architecture. As far as I Know Mips memory is indexed using 32 bit locations and each location contain 32 bits value.

In load word instruction its in the following format : lw $t, offset($s) which means -> $t = memoryIndex($s + offset), where $s, $t are registers that contain 32 bits value and offset is a 16 bit immediate value.

If $s contains 32 bits value and the memory can be indexed using 32 bits value, why do we need an immediate value as an offset ?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Mason
  • 51
  • 1
  • 4
  • 3
    You don't "need" it, but it simplifies things if you don't need to calculate the `$s+offset` beforehand in a register (which would again need an immediate of course). PS: memory is bytes, not words. – Jester Feb 18 '20 at 01:55
  • So LUI + LW can load from any arbitrary 32-bit address in 2 instructions, instead of 3. And for loop unrolling, and other stuff, avoiding ADDIU instructions for pointer math. – Peter Cordes Feb 18 '20 at 01:59
  • 1
    saves on registers and instructions sometimes. some of these instructions are encoded to always have an offset and if you dont need it then use zero. it is common enough to want a base plus offset to design the instruction set to have features for that also how mips instructions works you often have spare bits so why not make them an offset? – old_timer Feb 18 '20 at 03:19

0 Answers0