I’m reviewing for a test, and I cant figure out why the answer for this is 0x605040c rather than 12, or for the one after, why it’s 0123000 rather than 123.
Thanks for the help, the code is below. I’ve run it in QtSPIM and i still cant figure it out!
data
var1: .byte 12
var2: .byte 4,5,6
var3: .word 1,2,3,4,5,6,7,8,9
.globl main
.text
main:
la $t1, var1
la $t2, var2
la $t3, var3
lb $a1,1($t2) #$a1= 0x5
lw $a1, 0($t1) #$a1= 0x605040c
lui $a1,0x123 #$a1= 0x01230000
lw $a1, 0($t3) #$a1= 0x1
sll $a1,$a1,3 #$a1= 0x8
the answer to your questions can generally be answered by reading a reference document about each MIPS instruction that you use.
I will assume that your MIPS machine is little-endian.
First, let’s look at your memory:
Now we’ll analyze the tricky parts of your code:
^ This means load the 32-bit (4-byte) word starting at address t1, in little endian. With t1 = var1, the 4 bytes are 0C 04 05 06. The interpretation as a 32-bit integer is 0605040C.
^ This means load the immediate 16-bit constant into the upper 16 bits, and make the bottom 16 bits all zero. (Refer to the reference, skip down to LUI.)