Which of the following addressing modes permits relocation without any change whatsoever in the code?
Base register addressing
PC relative addressing
(D) PC relative addressing is the best option. For Base register addressing, we have to change the address in the base register while in PC relative there is absolutely no change in code needed.
Cristine in Base addressing you still need to change the content of base register whereas in relative addressing you just need the offset. PIC is commonly used for shared libraries, so that the same library code can be loaded in a location in each program address space where it will not overlap any other uses of memory. Libraries do not depend on anything outside the code.
Sir what if multiple Answers are Correct ?
Why not Base Register Addressing ? We aren't modifying the code right?
Answer should be Both, but the Answer is PC - Relative only because we are modifying something in Base Register (but the modification is not in code)
Code relocation can be done whenever addresses are not directly specified in the program (absolute), but are relative to some variable or other modifiable source.
For 3), base addressing, a register points to the base of the structure and the effective address is obtained by computing an offset from the base. The base address register can be loaded at run time to point to the base of the structure so the code doesn't have to be modified.
For 4), PC relative, the effective memory address is obtained by computing an offset from the current PC. No matter where the code is loaded in memory, the offsets are always the same so the code needs no modification.
It's a test series conducted by Kiran sir i.e...