in CO and Architecture retagged by
12,007 views
41 votes
41 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
in CO and Architecture retagged by
12.0k views

4 Comments

Indirect addressing means that the address of the data is held in an intermediate location so that the address is first 'looked up' and then used to locate the data itself

Refer thishttp://www.teach-ict.com/as_as_computing/ocr/H447/F453/3_3_8/lowlevel/miniweb/pg4.htm

5
5

Base addressing: The operand’s offset is sum of an 8 bit or 16 bit displacement and the contents of the base register BX or BP.BX is used as a base register for data segment ,and BP is used as a base register for stack segment.

Example:MOV AL,[BX+05]

Relative addressing:

   +----+------------------------------+
   |jump|           offset             |    jump relative
   +----+------------------------------+

   (Effective PC address = next instruction address + offset, offset may be negative)

The effective address for a PC-relative instruction address is the offset parameter added to the address of the next instruction. This offset is usually signed to allow reference to code both before and after the instruction.

Refer this :

http://www.geeksforgeeks.org/addressing-modes/

https://en.wikipedia.org/wiki/Addressing_mode#PC-relative

7
7
0
0

4 Answers

42 votes
42 votes
Best answer

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

4 Comments

What about indexed addressing ?

Will it be suitable at runtime ?
0
0
In case of indexed addressing, we take the support of index register which is used to store the index of the array, this addressing is basically used for accessing arrays
3
3

@Rajarshi Sarkar@kenzou@Arjun Why we are even comparing Indirect Addressing mode with Base Addressing mode or Relative Addressing mode coz in Indirect addressing mode, we are referring to an operand, whereas during relocation we are concerned about the addresses of instructions (for example, any Branch Statements). Correct me, if i am wrong.

 

1
1
14 votes
14 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 :).

2 Comments

Best Explaination Sirrrrrrrr
1
1
nice example
0
0
10 votes
10 votes
It should be a displacement type of addressing mode so option c.
by
0 votes
0 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.

1 comment

edited by

@Shailendra_

Indirect Addressing mode is not used coz even if we relocate our program, it may point to older location, containing our operand. For example, we have an instruction ADD X; (given it is indirect address mode). X has a value, say 400. Effective address is calculated as $Ac \leftarrow Ac + M[M[x]]]$. Memory location of X is changed according to Program Relocation but value at that address is old value (i.e. 400).

Correct me, if i am wrong.

0
0
Answer:

Related questions