in CO and Architecture retagged by
1 flag 10,972 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

13 Comments

What is PC relative addressing can u explain and how it will not change its address on relocation?
0
0
@ Arjun Sir I think ans should be C because a PC relative instruction should contain the base address but in base register AM both are present separately in Base Register and Index register.
Please tell me if I am wrong.
0
0
Pc relative is position independent .. it means it can be loaded in memory without any need to adjust any address..  search in wikipedia for more info ..
2
2
Sir,

you mentioned "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."

Base register will have segment base address,why do we need to change that?
0
0
In Base addressing mode we dont change the code (instruction) ... we will only be changing the Base register ... And yes both PC relative and Base register addressing mode are relative addressing modes and they both can do Program relocation without changing even a single line of code (set of instructions) ...
3
3
both the options C and D have to be correct as its gate 1998 multiple options may be correct then we have to choose all

even for based addressing mode also we provide the address relative to the base register so we don't need to change the  ASSEMBLY CODE AS ALREADY  ONLY THE OFFSET IS PRESENT IN THE CODE AND WE CALCULATE THE EFFECTIVE ADDRESS
9
9
For relocation in base addressing we need to change the content of the base register only..without any change in the code so then why relocation is not possible here ??
0
0

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.

5
5

Arjun

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)

1
1

https://gateoverflow.in/87078/gate1989-2-ii

then this question contradict the your answer

option C & D both .

2
2

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