Reputation: 29
I have a question regarding load words from an array in MIPS. If an array "A" starts with memory location of 100h, and I'd like to load the word into a register, would it be fine if I do something like,
lw $t0, 0x100($t2)
despite the offset place being the memory location, and the offset ($t2) being in the base address? The way I see it is $t2 + 0x100 vs 0x100 + $t2. Or is the only correct way is doing
lw $t0, $t2(0x100)
?
Upvotes: 0
Views: 405
Reputation: 364458
+
is commutative, and the hardware only cares what the final address is.
The asm source syntax only allows constant(reg)
so write it that way as A($t2)
, of course.
The machine code would be the same either way if the other syntax were allowed; there's only one form of the lw
instruction, and that's I-type with a register and a 16-bit immediate.
Upvotes: 1