noviceCdr
noviceCdr

Reputation: 21

MIPS assembly sw storing word to exact memory address

I am trying to assign the value 100 to memory address 8004. When I try the simple instructions below it seems that I am always missing my mark by 16 bits(I think I could be reading this simulator wrong, I haven't used it much). What would the reason be for this discrepancy? My first guess is that $0 register is not at bit 0 and is actually at bit 16 but this is only a guess.

li $24, 100

sw $24, 8004($0)

Simulator screenshot:

enter image description here

Upvotes: 1

Views: 3242

Answers (1)

Peter Cordes
Peter Cordes

Reputation: 365727

You have your simulator displaying memory in rows of 12 bytes, with each row starting with the address it's labelled with.

So your screenshot shows 0x64 (decimal 100) stored at 1f44+3, or decimal address 8007. Clearly your MIPS simulator is in big-endian mode (since MIPS can run in either mode): The LSB of the 32bit integer ends up in the 4th byte. In little-endian mode, the low byte of your 0x00000064 value would be at 0x1f44, and the next 3 bytes would get zeros.

According to https://en.wikipedia.org/wiki/MIPS_instruction_set#Integer, there are byte, halfword, and word store instructions. If you only wanted to affect the single byte whose address you gave, you should have used sb.

Upvotes: 3

Related Questions