Consider the following MIPS code dont worry about what it do
Consider the following MIPS code (don\'t worry about what it does): loop: beq $s0, $s1, done addi $t0, $t0, 7 addi St1, St2, 4 addi $s0, $s0, 1 j loop done: beq St1, $15, skip addi St0, Sto, 1 addi St1, St2, St0 skip addi $t5, $0, 10 beq St1, St5, done j end Compute the branch offset for each beq in number of words away from the branch (e.g., \"branch offset is 2\") Assume label loop is at location 0 times 00114214 and label end is at location 0 times 00032794. Compute the correct value to place in the jump address field for each jump instruction in the MIPS code above
Solution
A conditional jump is called a branch in MIPS. The offset is a 16-bit value. It can be computed as follows:
Offset = target instruction - (branch instruction + 1).
Now let us number each instruction starting form 0 as follows.
0 loop: beq $s0, $s1, done
offset of instruction 0 = 5 – (0 + 1) = 4
offset of instruction 5 = 8 – (5 + 1) = 2
offset of instruction 9 = 5 – (9 + 1) = 5
