GATE 2017 CS – Question 59
Consider a RISC machine where each instruction is exactly 4 bytes long. Conditional and unconditional branch instructions use PC-relative addressing mode with Offset specified in bytes to the target location of the branch instruction. Further the Offset is always with respect to the address of the next instruction in the program sequence. Consider the following instruction sequence
| Instr. No. | Instruction |
|---|---|
| i | add R2, R3, R4 |
| i+1 | sub R5, R6, R7 |
| i+2 | cmp R1, R9, R10 |
| i+3 | beq R1, Offset |
If the target of the branch instruction is `i`, then the decimal value of the `Offset` is ________.
Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: -16
Explanation
The offset is measured from the address of the next instruction, which is instruction $i + 4$. The target is instruction $i$, which is 4 instructions earlier, so the offset is $-4 \times 4 = -16$ bytes.