Which of the following addressing modes permits relocation without any change whatsoever in the code?
View worked solution
Answer: D
A program is said to be position-independent (or relocatable without any change in the code) if it can be loaded at any memory location and executed without modifying any of its instructions.
Let's analyze the options:
- PC-Relative Addressing: The effective address is calculated as: When the entire code block is relocated to a different memory address, the relative distance (offset) between the instruction and the target operand or branch destination remains exactly the same. Thus, the offset encoded in the instruction does not need to be modified at all. This makes PC-relative addressing ideal for position-independent code.
- Base Register Addressing: While it helps in relocation, it requires the base register to be explicitly loaded with the new starting address of the program before execution, which requires an external change or setup.
- Indirect and Indexed Addressing: These modes typically rely on absolute memory addresses or pointers stored in memory, which must be updated (relocated) when the program's location changes.
Therefore, PC-relative addressing permits relocation without any change whatsoever in the code.
Free practice · Your answers on this page are not saved.
