CREATE OWN LIBRARY

Address Relocation

 

Relocation:

Important point: This chapter is very important to know how to relocate an address from a relocatable address to an absolute address. And also important for examination: NET/GATE/Engineering/Degree

 

When assembly code (Intermediate code) is generated by the compiler then initially assembler assigns an address line to each instruction of the assembly code which is starting from  address line number 0.

 

 

Here the address line is starting from 0 and at address line 7 there is a goto statement with level L3.

 

This address is called a relocatable address because it can be changed that the time of loading at the main memory. 

 

Now when the assembler converts the assembly code to object code, it changes the level number of the corresponding goto statement to the address number. 

 

 

Assembler assumes that address will be started from 0 that is why assembler assigns the address line to object code starting from 0.  But practically at the time of loading the object code in main memory, the memory address may not be free from 0. Because most of the cases main memory allocate Operating System (OS) first and many other processes also allocated main memory for execution. 

 

So, object code might be loaded anywhere in the memory as per the free location. Then the address of each instruction has been changed at the time of loading in the main memory this concept is called relocation

 

Let us load the object code in the main memory with starting address 105. 

 

 

So, the assembler does not know the actual address (absolute address) of the program, it can assume a relocatable address. 

 

But if early memory binding is done at the time of compilation i.e. compiler assigns directly absolute address not relocatable address, then this memory binding is called compile time binding. 

But recently this concept is not used.

 

So, the relocation information segment of the object code contains all the relocatable addresses assigned in the object code. Later when the program finally loaded to the main memory, the relocation information segment provides all the relocatable addresses which are going to change at the absolute address