in CO and Architecture retagged by
15,019 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.0k 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

4 Comments

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