lw $t, offset($s)
is encoded as
1000 11ss ssst tttt iiii iiii iiii iiii
Where 100011
is the opcode, sssss
is the number of the base address register, ttttt
is the number of the destination register, and iiiiiiiiiiiiiiii
is an immediate signed offset.
In the case of lw $t0, 4($s1)
that would be:
1000 1110 0010 1000 0000 0000 0000 0100
($s1
is register $17
, i.e. 10001. $t0
is register $8
, i.e. 01000)
When the CPU encounters this instruction word it knows from the bit pattern that this is an lw
, so it forms an effective address formed by the value of register number sssss
+ the immediate offset (sign-extended), loads a word from that address and stores the value in register number ttttt
.
References:
MIPS register table
MIPS instruction set reference