- A relocating loader load a program in a designated area of memory, relocates it so that it can execute correctly in that area of memory and passes control to it for execution.
- The binary program is stored in a file contains the following:
o A Header record showing the load origin, length and load time execution start address of the program.
o Similarly, A sequence of binary image records containing the program’s code. Each binary image record contains a part of the program’s code in the form of a sequence of bytes, the load address of the first byte of this code and a count of the number of bytes of code.
o Moreover, A table analogous to RELOCTAB table giving linked addresses of address sensitive instructions in the program.
Algorithm: Relocating Loader
1. Program_load_origin = load origin specified in the loader command
2. program_linked_origin = linked origin specified in the header record
3. relocation_factor = program_load_origin – program_linked_origin
4. For each binary image record
a. code_linked_address = linked address specified in the record b. code_load_address = code_linked_address + relocation_factor
c. byte_count = count of the number of bytes in the record
d. Move byte_count bytes from the record to the memory area with start address code_load_address
5. Read RELOCTAB of the program
6. For each entry in the RELOCTAB
a. Instruction_linked_address = address specified in the RELOCTAB entry
b. instruction_load_address = instruction_linked_address + relocation_factor
c. Add relocation_factor to the operand address used in the instruction that has the address instruction_load_address
Practical Relocating Loaders
- Additionally, To avoid possible assembling of all subroutine when a single subroutine is changed and to perform task of allocation and linking for the programmer, the general class of relocating loader was introduced.
- Similarly, Binary symbolic loader (BSS) is an example of relocating loader.
- The output of assembler using BSS loader is
1. Object program
2. Reference about other programs to be accessed
3. Information about address sensitive entities.
- So, Let us consider a program segment as shown below
- Moreover, In the above program, the address of var5iable X in the instruction ADD AREG, X will be 30 If this program is loaded from the memory location 500 for execution then the address of X in the instruction ADD AREG, X must become 530.
- Moreover, Use of segment register makes a program address insensitive Actual address given by content of segment register + address of the operand in instruction So, 500+30=530 is the actual address of variable X.