The Gateway to Computer Science Excellence
+22 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

in CO and Architecture by Veteran (52.2k points)
retagged by | 3k views

PC relative addressing:  relocation (relocation within segment )

Base register addressing: position independent code (different segment )

ans :D





isnot here ans violating this ? 

Position independent (By changing the value inbase register, location of address can be changed)

How this could be possible then? 

3 Answers

+25 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.

by Veteran (431k points)
edited by
What is PC relative addressing can u explain and how it will not change its address on relocation?
@ 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.
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 ..

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?
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) ...
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
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 ??

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)


then this question contradict the your answer

option C & D both .

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


by Loyal (7.3k points)
So ,you are supporting both the options,then why the answer is d?
Bcz Option D is more appropriate
@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
+1 vote
C- Base register addressing
by Loyal (5.9k points)
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,385 answers
105,390 users