An exercise problem stated that :

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

Somewhere it explained as :

Base register addressing : In this mode , content of base register is added to the address part of the instruction to obtain effective address . A Base register is assumed to hold a base address and the address field of the instruction gives a displacement relative to the base address with a base register , the displacement values of the instruction do not have to change only the value of the base register requires updating to reflect the beginning of a new memory of constant .

Hence , option (3) is true .

I found another explanation too , which stated that base addressing mode and relative addressing mode are suitable for relocation at run time .

My question is :

Which addressing modes permits relocation without any change whatsoever in the code?

Can you explain it in a formal way, please?


1 Answer 1


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.

In the 2 modes that you correctly specified as able to support relocation of code and data, the effective address is calculated based on the value loaded in another register.

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.

Now the other 2 selections are a little more tricky. 1. Indirect addressing. This supports relocatable code since the effective address is determined based upon the contents of the initial load. Code and data can move but with a data structure containing pointers to the code and/or data being at a fixed address. For example, the operating system may define that a pointer to the system's CPU database is always located at address 80002000, but the CPU database can be loaded at any address. You COULD argue that the entire program is not relocatable because the pointers are at fixed locations, but really relocation is the one of the purposes of this addressing mode.

  1. Indexed Addressing. This depends upon a bit more definition of the term. If you mean indexed ABSOLUTE mode, then no, I wouldn't consider this to be a mode that supports relocation. In this case the effective address of data is based on an offset from a literal fixed address (ex: 1000 + R5). In order to relocate this data (or code) the literal address would have to be changed in the code. If it's indexed relative to a base register, then yes it supports code relocation since the base register can be loaded at run time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.