Help with finding address from MIPS instruction in hex
Hi I am stuck on my assignment, which requires me to write a c program which reads in an input file such as this:
Registers
r1 = 0c100009
Instructions
0c100009
3c071001
8ce20011
84e33080
80e48000
ace2ffff
a4e39001
a0e48088
03e00008
and find out whether the instruction is a save or load, how ma开发者_开发百科ny bytes accessed by the instruction, and the address of the first of these bytes in memory.
I need help understanding how the instructions work. I do know that I have to translate the instruction to binary, for example
8ce20011
to
100011 00111 00010 0000000000010001
which is
lw $t3 17($s7)
but i don't know how to calculate the address and the number of bytes accessed. I am suppose to ignore all the instructions that are not save or load.
And also, what does it mean by sign extend?
Thank you for your help.
You are on the right track.
The opcode 8ce20011 disassembles to "lw v0, 17(a3)" or equivalently "lw $2,17($7)"
In your "lw $t3, 17($7)" example, you need to know the current value of $7 (i.e. $a3) before you can calculate the address that it is loading from. Hint: look at the previous instruction. A "lw" instruction loads a word, or 4 bytes.
Incidentally, "lw" with an offset like 17 which is not aligned on a word boundary is illegal and causes a Trap in MIPS.
Sign extension
精彩评论