Which of the following addressing modes permits relocation without any change whatsoever in the code?
Indirect addressing
Indexed addressing
Base register addressing
PC relative addressing
PC relative addressing permits the relocation without any change whatsoever in the code .
Relocatable-Code is quite like position-independent code in many ways, but it has a very subtle difference. As it's name suggests, this type of code is relocatable in that code can be loaded anywhere in memory, but usually has be relocated or fixed up before it is executable.
Reference:- https://stackoverflow.com/questions/22889719/what-is-relocatable-and-absolute-machine-code
@srestha there no other option fits. Also every relocatable code is position independent but has to be later fixed to an address. Whereas in case of Position independent code we don’t even need to fix it later. So here it is PIC, whereas there it is relocatable code.
(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.
what’s the correct answer for this then?? as pc relative mode is position independent within the segment only (intra-segment) and base register AM is position independent among the segments(inter-segment). and thus base register mode definitely require a change in the base address.. but in pc relative mode..no change is needed.
so, D should be the only answer here? what is the supporting explanation for option C?
@Pranavpurkar It’s simple. Both PC-relative and Based AM are suitable for program relocation at runtime.
But, without changing the code? → Then only PC-relative can do it. Why?
This is because in PC- relative AM : PC ← PC + Relative value. No need to change anything in code.
But in Based AM : PC ← [base register value] + relative value. After this step, we also need to change the address in the base register, so that now our base address register contains the updated base address. This requires change in code.
Ans: D
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.
ref: https://cs.stackexchange.com/questions/48730/which-addressing-modes-permits-relocation-without-any-change-whatsoever-in-the-c
Option D, PC relative addressing
w.r.t Morris Mano,
The base register addressing mode is used in computers to facilitate the relocation of programs in memory. When programs and data are moved from one segment of memory to another, as required in multiprogramming systems, the address values of instructions must reflect this change of position. With a base register, the displacement values of instructions do not have to change. Only the value of the base register requires updating to reflect the beginning of a new memory segment.
In PC Relative Addressing Mode, nothing need to be changed.
64.3k questions
77.9k answers
244k comments
80.0k users