Little Endian Order


The MARS and Spim store and retrieve data from memory using the little endian order. This means that the least significant byte of a variable is stored at the lowest address, that is, the word is stored “little-end-first.” The remaining bytes are stored in the next consecutive memory positions.

Assume the starting offset is 0. A word 0x12345678 is stored as:
Little Endian Order
Definition X:   .word   0x12345678
Offset 0000 0001 0002 0003
Value 78 56 34 12

Retrieving the 2nd Byte Clearing the Value 01 Switching the Lower
and Upper Bytes
     .data
 X:  .word  0x01020304

     .text 
     la  $t0, X
     lb  $a0, 1($t0) 
     li  $v0, 1
     syscall
    .data
 X: .word  0x0102

    .text 
    
    lw  $a0, X 
    li  $v0, 1
    syscall
 
    .data
 X: .half  0x0201

    .text 
    lb  $t0, X
    lb  $t1, X+1
     # Using $t0
     # Using $t1
    lh  $a0, X
    li  $v0, 1
    syscall
 
Output Output Output




2   (0x00000002)


258   (0x0102)


Some computers use the big endian order, which is the reverse of the little endian order.

Assume the starting offset is 0. A word 0x12345678 is stored as:
Big Endian Order
Definition X:   .word   0x12345678
Offset 0000 0001 0002 0003
Value 12 34 56 78




      I’ve locked the door.    
      They’re as safe as houses (very safe).