6.In a MIPS32 program, the instruction at memory address 0x0040_8400 is j end_if
ID: 3564979 • Letter: 6
Question
6.In a MIPS32 program, the instruction at memory address 0x0040_8400 is j end_if which jumps to the label end_if
which is at memory address 0x0040_928C. What would be the encoding of this instruction? Express your answer as
an 8-hexdigit integer. For full credit explain how your answer was obtained.
7. In a MIPS32 program, the instruction at memory address 0x0040_8400 is beq $t0, $t1, loop which jumps to the
label loop which is at memory address 0x0040_81E8. What would be the encoding of this instruction? Express your
answer as an 8-hexdigit integer. For full credit explain how your answer was obtained.
Explanation / Answer
The instruction format of j is
000010b - instruction index(address to which the jump should happen right shifted by 2)
the upper 4 bits of the effective address is same as the current PC
current PC is at 0x00408400 and the effective address should be 0x0040928C,so the jump is possible.
so the value to be written to the instruction will be (0x040928C>>2) (remove upper 4 bits)= (0000-0100-0000-1001-0010-1000-1100 >> 2)
= 0000-0100-0000-1001-0010-1000-11
effective instruction is
000010 - 0000-0100-0000-1001-0010-1000-11 = 0000-1000-0001-0000-0010-0100-1010-0011 = 0x081024A3
beq instruction format is
000100 - rs(5bits) - rt(5bits) - offset(the offset of resltant address with respect to current PC)
beq rs,rt,offset
beq $t0,$t1,((0x004081e8 - 0x00408400)>>2)
rs = $t0 = 01000
rt = $t1 = 01001
offset = (0xFFDE8 >>2 ) = 1111-1111-1101-1110-1000 >>2 = 1111-1111-0111-1010
as we need only 16 bits in offset we truncate the remaining upper bits
effective instruction is
000100 - 01000 - 01001 - 1111-1111-0111-1010 = 0001-0010-0000-1001-1111-1111-0111-1010 = 0x1209FF7A
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.