• retagged by
20,082 views
53 53 votes

Which of the following addressing modes are suitable for program relocation at run time?

  1. Absolute addressing

  2. Based addressing

  3. Relative addressing

  4. Indirect addressing

  1. I and IV
  2. I and II
  3. II and III
  4. I, II and IV

7 Answers

Best answer
50 50 votes

Answer: (C)

A displacement type addressing should be preferred. So, (I) is not the answer.

Indirect Addressing leads to extra memory reference which is not preferable at run time. So, (IV) is not the answer.

• edited by
23 23 votes

THE ANSWER IS  C.

Let us consider the following code.
Let the base register be updated with the value 203
address     code
200            ADD B,M[400] // absolute addressing
201            ADD  C,M[M[400]]//  indirect addressing                     
202            ADD C,PC(197)// relative addressing mode
203            ADD  A, 197(base register)   //base register addressing mode.

400               420
                     -
                     -
420               600
421               halt.

 

NOW LET THE CODE BE SHIFTED TO  LOCATION 700.
And let  addresses 200-421 be loaded with some other code
Let the base register be updated with the value 203
address     code
500            ADD B,M[400]    // absolute addressing
501            ADD  C,M[M[400]]     //  indirect addressing                     
502            ADD C,PC(197)   // relative addressing mode
503            ADD  A, 197(base register)   //base register addressing mode.
                     -

700               420
                     -
                     -
720               600
721               halt.

 

Absolute addressing mode.& indirect addressing mode.

When the code at address 700 is executed then we observe that it tries to fetch the operand at  400.But the physical address space of the code does not contain 400.hence it tries to access an invalid address.

Simlilar thing happens when it tries to access  400 for indirect addressing mode.

 

PC Relative.
we see that  we can execute the code  ADD C,PC(197)  and it gives perfectly valid values even when it is shifted.

 

Base Register .
we see that  we can execute the code  ADD A,197(base register)  and it gives perfectly valid values even when it is shifted. We just need to update the base register.
 

Here I am only considering the validity of each individual line and wheather the lines will be executed  when relocated.

Please revert back if u find anything wrong or can give extra information :).

12 12 votes
It should be a displacement type of addressing mode so option c.
5 5 votes

I. Absolute Addressing:
In absolute addressing, the address is fixed and does not change based on where the program is loaded in memory. This makes it unsuitable for program relocation at runtime because the program's code would need to be modified or rewritten if it is relocated to a different memory location.
So, it is not suitable for relocation.

II. Based Addressing:
Based addressing uses a base register, and addresses are calculated as an offset from this base. If the base register can be modified at runtime, the program can be relocated by changing the value in the base register. This can allow the program to be relocated dynamically.
Suitable for relocation.

III. Relative Addressing:
In relative addressing, the address is specified as an offset relative to the program counter (PC) or another register. Since this offset is not dependent on the absolute location in memory, it makes the program independent of where it is loaded, allowing it to be relocated easily during runtime.
Suitable for relocation.

IV. Indirect Addressing:
In indirect addressing, the address is stored in a location pointed to by a register or memory. While this can provide some flexibility, it does not inherently solve the problem of relocation, as the program still depends on a specific base or reference address to work.
Not inherently suitable for relocation, but it can be used in conjunction with other addressing modes to allow relocation.

So, answer is option (C) II and III

3 3 votes
Program relocation at run time transfer complete block to some memory locations. This requires as base address and block should be relatively addressed through this base address .This require both base address and relative address. So( C)  is correct option.

Absolute addressing mode and indirect addressing modes is used for one instruction at one time, not for whole block So both are not suitable for program relocation at run time.
0 0 votes

Indexed Addressing:

EA = Base address (hardcoded in the instruction itself) + Index register

The base is a constant baked into the instruction — absolute, fixed. The index register just adds an offset on top (useful for array traversal etc.). Since the base is hardcoded as an absolute address → bad for PIC 

Base Register Addressing:

EA = Base register + offset (offset in instruction)

Here the base register is loaded by the OS with the program's starting address at load time. So if the OS relocates the program, it just updates the base register and everything still works. → Good for relocatable code but needs OS intervention (but not as clean as PC-relative)

PC-Relative:

EA = PC + offset

No OS intervention needed, no hardcoded absolute addresses, inherently position-independent. → Best for PIC 

So the hierarchy for PIC suitability is:

PC-relative > Base register > Indexed > Direct

Answer:
Position:
Show:

Related questions

56 56 votes
6 answers 6 answers
14.4k
14.4k views
Kathleen asked Sep 18, 2014
14,380 views
The following finite state machine accepts all those binary strings in which the number of $1$’s and $0$’s are respectively: divisible by $3$ and $2$odd and eveneven ...
51 51 votes
7 answers 7 answers
21.6k
21.6k views
Kathleen asked Sep 18, 2014
21,590 views
The minimum number of colours required to colour the following graph, such that no two adjacent vertices are assigned the same color, is$2$$3$$4$$5$
38 38 votes
5 answers 5 answers
26.6k
26.6k views
Kathleen asked Sep 18, 2014
26,608 views
Let $A = 1111 1010$ and $B = 0000 1010$ be two $8-bit$ $2’s$ complement numbers. Their product in $2’s$ complement is$1100 0100$$1001 1100$$1010 0101$$1101 0101$
60 60 votes
7 answers 7 answers
20.8k
20.8k views
Kathleen asked Sep 18, 2014
20,760 views
Two matrices $M_1$ and $M_2$ are to be stored in arrays $A$ and $B$ respectively. Each array can be stored either in row-major or column-major order in contiguous memory ...