Concept of Relocation

The term program relocatability refers to the ability to load and execute a given program into memory. In reality, the program may be loaded at different memory locations, which are called physical addresses.

Relocation is to find a way to map virtual addresses onto physical addresses. Depending on when and how the mapping from the virtual address space to the physical address space takes place in a given relocation scheme, there are two basic types of relocation:

(1)   Static Relocation

Static relocation is performed before or during the loading of the program into memory, by a relocating linker/ loader. In systems with static relocation a swapped-out process must either be swapped back into the same partition from which it was evicted, or software relocation must be repeated whenever the process is to be loaded into a different partition.
Systems with static relocation are practically restricted to supporting only static binding of processes to partitions. This method is slow process because it involves software translation. It is used only once before the initial loading of the program.

(2)   Dynamic Relocation.

In it, mapping from the virtual address space to the physical address space is performed at run-time. This run time mapping from virtual address to physical address is performed by a hardware device known as memory management unit.
When the program is compiled or when a process is executed by CPU will generate the logical address. Put this address as LA and this logical address can never be less than zero, it has to be zero or more.

So whenever the CPU generates the logical address, you add this logical address with the base register (relocation register ) content  and that gives you the physical address in the main memory where the instruction of that data will be found.

Figure 4: Dynamic relocation using relocation register.

The value in the relocation register is added to every address generated by a user process at the time the address is sent to memory (see Figure 4). For example, if the base(relocation register content)  is at 14000, then an attempt by the user to address location 0 is dynamically relocated to location 14000 and an access to location 346 is mapped to location 14346.

User program deals with logical address it never see the physical address.

Keywords: relocation, static relocation, dynamic relocation, logical address, physical address,relocation register,main memory.