tags:

views:

214

answers:

2

I've run the following code snippet on the MIPS MARS simulator. That simulator is little endian. So the results are as follows:

lui    $t0,0x1DE             # $t0 = 0x01DE0000
ori    $t0,$t0,0xCADE        # $t0 = 0x01DECADE 
lui    $t1,0x1001            # $t1 = 0x10010000
sw     $t0,200($t1)          # $t1 + 200 bytes = 0x01DECADE 
lw     $t2,200($t1)          # $t2 = 0x01DECADE 

So on a little endian MIPS simulator, the value of $t2 at the end of the program is 0x01DECADE. If this simulator was big endian, what would the value be? Would it be 0xDECADE01 or would it still be 0x01DECADE?

A: 

0xDECADE01 - this one. just bytes are reordered.

Andrey
+3  A: 

It would be the same -- the order of the bytes in memory would be different, but you would only see that if you loaded single bytes from 200($t1), 201($t1), 202($t1) and 203($t1)

Chris Dodd
Thanks Chris. That makes sense. Would be nice if someone could run SPIM on a big endian machine to verify.
Barney
@Barney: No need to verify. This is standard endianness stuff. Store behaves depending on endianness, load does exactly the opposite of load. executing them one after the other, with the same data size, will not alter the register value, ever.
Bahbar
@Bahbar: Thanks. "load does exactly the opposite of load." Did you mean "load does exactly the opposite of store"?
Barney
@Barney: err, yes. That's what I meant.
Bahbar