What will happen when the following snippet of code is executed: li $s0, 0x10000
ID: 3878855 • Letter: W
Question
What will happen when the following snippet of code is executed:
li $s0, 0x10000014
lw $t0, 8($s0)
The value, 0x10000014, will be copied from $s0 into $t0.
The value currently in $t0 will be copied to the memory address, 0x10000014.
The value currently at the memory address, 0x10000014, will be copied into $t0.
The value currently in $t0 will be copied to the memory address, 0x10000022.
The value currently at the memory address, 0x10000022, will be copied into $t0.
The value currently in $t0 will be copied to the memory address, 0x1000001C.
The value currently at the memory address, 0x1000001C, will be copied into $t0.
Explanation / Answer
li $s0, 0x10000014
lw $t0, 8($s0)
The first instruction is:
li $s0, 0x10000014
The li instruction loads the given immediate value to the register mentioned.
Hence after execution of this instruction, the register $s0 will have the value 0x10000014 stored in it.
The next instruction is
lw $t0, 8($s0)
The format of load word is:
lw RegDest, Offset(RegSource)
where RegDest and RegSource are MIPS registers and Offset is an immediate value.
The instruction will load the word present at the address (RegSource + Offset) to the register RegDest.
Now we know that $s0 has the value 0x10000014. Then ($s0 + 8) will be equal to
0x10000014 + 0x00000008 = 0x1000001C ( not 0x10000022, because 4 + 8 = 12 = C in HEX)
Hence the address resulting from addition of Offset and RegSource is 0x1000001C.
The value present at this address will be loaded in the register RegDest. RegDest in our question is $t0.
Hence, The value currently at the memory address, 0x1000001C, will be copied into $t0.
Please give a thumbms up if you find this solution helpful and comment if you have any doubts in it.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.