in CO and Architecture retagged by
15,055 views
45 votes
45 votes

The most relevant addressing mode to write position-independent codes is:

  1. Direct mode
  2. Indirect mode
  3. Relative mode
  4. Indexed mode
in CO and Architecture retagged by
15.1k views

4 Comments

Register add mode :  access the local variables

Immediate add mode : access the  constant

Direct/Absolute add mode : access the static variables

Indirect add mode : implement pointer

indexed/ Base index : access the random array

Auto index: access the linear array

relative add mode and base register add mode : relocation at run time

base register add mode : best suit to write positions independent code
32
32
Why are local variables stored in registers? Arent they part of the activation record which gets pushed to the program stack in the main memory? In C programming language there is a special keyword “register” to store the variable in register. Am I missing something?
1
1

6 Answers

32 votes
32 votes
Best answer

(C) Relative Mode since we can just change the content of base register if we wish to relocate.

REFERENCE: https://gateoverflow.in/155280/self-doubt-computer-organization?show=155312

edited by

15 Comments

Why not B) Indirect Mode ?
1
1
since relative addressing mode can be specified with a smaller number of bits
0
0
edited by
Answer: C

Relative mode addressing is most relevant to writing a position-independent code.

Ref: http://en.wikipedia.org/wiki/Addressing_mode#PC-relative
POSITION INDEPENDENT means it can load any wher in the memory.
10
10
why not indexed mode in relatie we have

pc+offset

in case of indexed we have base address array +offset so what is the difference and for me both aree the same ...................................
1
1
can u tell me y D is nt the answer??
1
1

Indexed mode is not the answer because it can be used in relocatable code not positional independent 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.

Whether static or dynamic, a linked library is going to be situated in virtual memory somewhere that the library can’t predict, which is problematic for accessing its own memory. Fortunately, the linker (whether static or dynamic) can help us out by relocating the library’s code, so that it knows where it is. Unfortunately, library writers have to help the linker out by specifying, in the object file, the set of instructions or initialized data that need to be modified to properly relocate it. As long as all that “relocation information” is present, the object file is said to be relocatable.

On the other hand, position-independent code (PIC), as the name suggests, doesn't even need to be relocated. None of its instructions or initialized data encode any assumptions about the region of virtual memory the program will be loaded into; it figures out where it is (usually by referencing the instruction pointer) and makes all memory accesses based on what it finds out.

For more info : http://davidad.github.io/blog/2014/02/19/relocatable-vs-position-independent-code-or/

20
20
@vishal goyal indexed AM is used in the case of array implementation,to access the random array data element.
0
0

@srestha

please check my explanation:)

Here C is the correct answer according to me because:
option A,B are not position-independent .They depend on the memory addresses of their operands.

option D:
here in indexed mode we have the index register(which may be any general purpose register) .and every register has an address.So in an instruction in the indexed mode we have to provide the address of the index register(which can be any one of the registers and is not fixed)  to find out the effective address.

option C:
in case of relative addressing mode we provide the  a constant value by which the program counter is incremented/decremented.And the addressed location is identified relative to the program counter,which identifies the current execution point of the program.
And as a system has only one program counter it's address remains fixed.So it is independent of any address.
So the code can be loaded at any part of the memory.

0
0

@Doraemon

So, it is dependent on PC, then how independent??

0
0

@srestha

PC is a register whose address is known by the system , and the address of the program counter won't change.hence PC address is known. So where ever the instruction goes the address of PC does not change.

 

0
0
@srestha ma'am, Why is Direct mode not the solution? Is there a scenario where running instruction like LD ADR anywhere in the memory be problematic?

PS: Pardon me if the doubt is too silly.
0
0
Is Direct addressing mode position independent?
0
0
1) So, does it mean that if I relocate the simple instruction of LOAD A #200 ( A is the accumulator ) from one segment of memory to another then this above code will not work correctly?

 

2) Whereas if I am using relative addressing mode , this won't be an issue?

 

3) I thought by having the address of the operand right in the instruction will allow it to move anywhere in the memory, seems like this assumption is wrong, isn't it?
0
0
Relative addressing mode works for jump or Branch type instruction, where pc has to certain distance ahead, from where it is locating now.

Say, pc is locating an address 1000 and it need to go 100B ahead.

So, relative address=pc+offset=1000+100=1100.

Direct addressing mode works with address, while relative addressing mode works only with displacement. right?
0
0
So, in a nutshell, because of the displacement nature of PC relative addressing mode it will be PIC but having a static address as in Direct Mode will need the code to be modified if one needs to relocate the code, am I right?
0
0
8 votes
8 votes

Position Independent Code: This code can be placed anywhere in the primary memory, executes properly regardless of its absolute address. This differs from relocatable code which requires a program loader to modify program before execution so it can run from a particular memory location.

Relative Addressing mode is suitable for Program-Independent-Code (PIC) because Effective  Address can be calculated by adding displacement to the PC.

Indexed mode can not be used because Base Address is provided in the instructions itself. Whenever position of code changes, address in  all instructions needs to be changed. However, Base Register Mode (BRM) can be used to write position independent code because in BRM base is present in base register while index or offset is present in the instructions.

ANSWER: (C) Relative Mode

3 votes
3 votes

Answer:- C            " PC Relative Mode "

Code that is position independent will consist of only one segment of code and have it's data also contained within this segment (or section). and PC relative AM is intra segment jump while Base addressing mode is inter segment jump . so, PC Relative mode is the best suitable case

reference: https://stackoverflow.com/questions/22889719/what-is-relocatable-and-absolute-machine-code

1 vote
1 vote
relative mode

1 comment

Basically, "absolute" mode means that the code and RAM variables will be placed exactly where you tell the assembler it will be, while "relocatable" means the assembler builds code chunks and specifies RAM needs that can be placed wherever the linker finds room for them.

 

 position independent:-It's a very useful type of code because it means the operating system does not need to perform any post-loading operations on it in order to be able to start executing.

https://stackoverflow.com/questions/22889719/what-is-relocatable-and-absolute-machine-code

0
0
Answer:

Related questions