So, in this code snippet, I am trying to find out the values of $t2, and $t3 in HEX. I get the answer to be $t2 = 0x30 and $t3 to be 0x3C. However, the answer in the back is $t2 = 0x130, $t3 = 0x13C. Can someone explain??
.data
x: .byte 1, 2, 3, 4, 5
y: .word 19, 20, 25, 30, 35
.text
addi $t0, $0, 8
lw $t1, x($t0)
sll 开发者_开发技巧$t2, $t1, 4
ori $t3, $t2, 12
How did you derive your answer? I'm pretty rusty with MIPS and this is based on what I remember from uni.
x points to the byte with data 1. On a little-endian machine, x+5 marks the end of the 4 byte word (with data 19) and x+8 marks the beginning. So 19 (10011) is loaded into $t1, shifted left by 4 to 100110000 (304 or 0x130). Finally, 12 is added to get 0x13C.
Let me know if you don't understand something. And it helps to draw a diagram :)
精彩评论