Question
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:
If the target of the branch instruction is , then the decimal value of the Offset is ______.
Official answer and solution
- Official answer
- -16
- From
- Official GATE 2017 answer key
Solution
Calculate the PC-relative byte offset from the next instruction address to the target branch address.
Each instruction is 4 bytes long. Let be the memory address of instruction .
The addresses of the instructions in sequence are:
- Address of instruction :
- Address of instruction :
- Address of instruction :
- Address of instruction (
beq R1, Offset):
The next instruction in sequence is at address .
The PC-relative offset is defined with respect to the address of the next instruction:
Here, the target instruction is instruction at address . Therefore:
-16.0
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2017 Computer Science and Information Technology (CS) Session 1
- Question
- 49 of 65, printed as CS Q.49
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.