Skip to content
Official PYQ · 2017

GATE CS 2017 Set 1 Q49 — Machine Instructions and Addressing Modes

Explain with AI
Consider a RISC machine where each instruction is exactly 44 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 sequenceInstr. No.Instructioni:add R2, R3, R4i+1:sub R5, R6, R7i+2:cmp R1, R9, R10i+3:beq R1, Offset\begin{array}{ll} \text{Instr. No.} & \text{Instruction} \\ \hline \text{i:} & \text{add R2, R3, R4} \\ \text{i+1:} & \text{sub R5, R6, R7} \\ \text{i+2:} & \text{cmp R1, R9, R10} \\ \text{i+3:} & \text{beq R1, Offset} \\ \end{array}If the target of the branch instruction is i,i, then the decimal value of the Offset is ____________ .
View worked solution

Answer: -16.0

Let the memory address of the first instruction ii be AA. Since each instruction is exactly 44 bytes long, we can determine the addresses of the instructions as follows:

  • Instruction ii: AA
  • Instruction i+1i+1: A+4A + 4
  • Instruction i+2i+2: A+8A + 8
  • Instruction i+3i+3 (Branch instruction): A+12A + 12
  • Next instruction (after the branch): A+16A + 16

According to the problem statement, the branch offset is calculated with respect to the address of the next instruction in the program sequence:

Target Address=Address of next instruction+Offset\text{Target Address} = \text{Address of next instruction} + \text{Offset}

We are given that the target of the branch is instruction ii (address AA):

A=(A+16)+OffsetA = (A + 16) + \text{Offset}

Solving for the offset:

Offset=A−(A+16)=−16\text{Offset} = A - (A + 16) = -16

Thus, the decimal value of the Offset is -16.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Machine Instructions and Addressing Modes questions