Skip to content
GATEiit

GATE CSE 2017 Session 1 Q59: PC-relative branch offset back to instruction i from beq at i+3

Syllabus topic: Instruction set and addressing modes

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

Instr. No.Instruction
iadd R2, R3, R4
i+1sub R5, R6, R7
i+2cmp R1, R9, R10
i+3beq R1, Offset

If the target of the branch instruction is i, then the decimal value of the Offset is ______.

Try it: numerical answer: type the value

Numerical answer. No negative marking.
Show answer and explanation

Answer: -16 (official GATE 2017 final answer key)

Concept used: With PC-relative addressing, Offset = target address − address of the next instruction (PC after fetch).

Concept notes

Loading notes…

First step: Take the address of instruction i as 0; the next instruction after beq (i+4) is at byte 16, so subtract that from the target address.

Full step-by-step solution

Loading…

Answer from the official final answer key. Found a mistake? Use Report issue and we will fix it.

More questions on Instruction set and addressing modes

Every PYQ on this topic →

Share this question

WhatsAppDownload image

Source: official GATE 2017 Session 1 CS question paper and final answer key, organised by IIT Roorkee. Question paper · Answer key