Skip to content
Official PYQ · 1987

GATE CS 1987 Q1-V — Machine Instructions and Addressing Modes

Explain with AI

The most relevant addressing mode to write position-independent codes is:

Choose one option
View worked solution

Answer: C

Position-Independent Code (PIC) is machine code that can execute correctly regardless of its absolute address in memory. This is essential for shared libraries and dynamic loading, where the code might be loaded at different memory locations during different executions.

To achieve position independence, memory references (such as jump targets or data locations) must not use absolute memory addresses. Instead, they should be specified relative to the current instruction's address, which is held in the Program Counter (PC).

  • Relative Mode (PC-Relative Addressing): The effective address is calculated as:
    Effective Address=Program Counter (PC)+Offset\text{Effective Address} = \text{Program Counter (PC)} + \text{Offset}
    Since the relative offset between the instruction and the target address remains constant even if the entire program is relocated to a different memory address, the code executes correctly without needing any address relocation at load time.
  • Direct Mode: Uses absolute memory addresses, making the code position-dependent.
  • Indirect Mode: Accesses memory through a pointer containing an absolute address, which also typically depends on the load address.
  • Indexed Mode: Typically adds an offset to an index register, which is generally used for array operations rather than general position independence.

Therefore, Relative mode is the most relevant addressing mode for writing position-independent code.

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

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