0

Cheers, so I am a little confused with the whole endianess things, and as I thought I had it figured out I cam across an example and completely lost it. So the code is as follows:

.text
        .globl __start
__start:

    lw $t7, stringInWordForm

    sw $t7, string

Exit:   li $v0, 10          # terminate
        syscall
#################################################
# #
# data segment #
# #
#################################################

.data
    string: .asciiz "abcd"
    stringInWordForm: .word 0x44434241  


I start by saving the base address of the string into $s0. So I got the following thing:

 0x10000    0x10001    0x10002    0x10003
    -          -          -          -
|   a    |     b    |     c    |     d    |

Then I load what is hold at position stringInWordForm into register $t7. Using QtSpim, after the load I am shown that what is actually inside the register is (as expected)

$t7 = 0x44434241 # in hexadecimal form, in decimal there are stored: D C B A

However, after I store the word, I see that what has been saved is A B C D. My thought process/assumptions are as follows:

       most sig byte                        least sig byte
$t7 = |     44      |    43   |    42     |       41        |
-----------------------------------------
 0x10000    0x10001    0x10002    0x10003
    -          -          -          -
|   a    |     b    |     c    |     d    |

So since we have a big endian approach, we first store the MOST significant byte of the register FIRST (in the lowest position), so I would expect:

 0x10000    0x10001    0x10002    0x10003
    -          -          -          -
  (44)        (43)       (42)      (41)
|   D    |     C    |     B    |     A    |

What am I thinking wrong here?

george.zrs
  • 131
  • 7
  • 1
    MARS simulates a little-endian MIPS. Apparently QtSPIM is the same (on your machine). – Peter Cordes May 10 '21 at 20:22
  • Also, `la $s0, string` seems pointless; you're using symbols directly in the load and store, not `4($s0)` or whatever. – Peter Cordes May 10 '21 at 20:24
  • My bad on the la, the code snippet has more code later but I forgot to remove it. As for your first question I don't know how to answer that because I don't know exactly what MARS is. A textbook I am using mentions that MIPS is Big Endian, but I don't know if I am confusing that with QtSpim's endianess, because as it looks QtSpim is little endian (I think this is correct here because it stores the least to the smallest position as it seems ) – george.zrs May 10 '21 at 20:29
  • I edited my first comment after finding a duplicate that answers your question: SPIM emulates a MIPS with the native endianness of the host machine. (MARS is another emulator, like SPIM but different, written in Java with an arguably nicer GUI IDE than QtSPIM.) – Peter Cordes May 10 '21 at 20:31

0 Answers0