in CO and Architecture retagged by
1 flag 10,960 views
40 votes
40 votes

Which of the following addressing modes permits relocation without any change whatsoever in the code?

  1. Indirect addressing

  2. Indexed addressing

  3. Base register addressing

  4. PC relative addressing

  • 🚩 Edit necessary | 👮 Arjun
in CO and Architecture retagged by
1 flag
11.0k views

4 Comments

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

2
2
option D) PC relative Addressing mode
0
0

@ 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.

0
0

4 Answers

45 votes
45 votes
Best answer

(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.

edited by
by

4 Comments

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?

1
1

@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.

4
4
it is the best answer thanks buddy
0
0
13 votes
13 votes

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

3 Comments

So ,you are supporting both the options,then why the answer is d?
1
1
Bcz Option D is more appropriate
0
0
@rahul sharma sir ,PC-relative AM is applicable only on a particular segment inside the memory at a time,but Base AM is applicable on the whole memory at a time,so it have wide area so (C) should be most appropriate choice
0
0
1 vote
1 vote
C- Base register addressing
1 vote
1 vote

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. 

Answer:

Related questions