InTheMoney
InTheMoney

Reputation: 29

MIPS Load Word Placing

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

Answers (1)

Peter Cordes
Peter Cordes

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

Related Questions