Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Basic Functions of Loader

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Assemblers and compilers are used to convert source code to object code. The loader will accept that object code, make it ready for execution, and helps to execute. Loader performs its task via four functions, these are as follows:

  1. Allocation: It allocates memory for the program in the main memory.
  2. Linking: It combines two or more separate object programs or modules and supplies necessary information.
  3. Relocation: It modifies the object program so that it can be loaded at an address different from the location. 
  4. Loading: It brings the object program into the main memory for execution.

A general loading scheme is shown below:

Functions of Loader

Functions of Loader

Allocation: 

In order to allocate memory to the program, the loader allocates the memory on the basis of the size of the program, this is known as allocation. The loader gives the space in memory where the object program will be loaded for execution.

Linking: 

The linker resolves the symbolic reference code or data between the object modules by allocating all of the user subroutine and library subroutine addresses. This process is known as linking. In any language, a program written has a function, it can be user-defined or can be a library function. For example, in C language we have a printf() function. When the program control goes to the line where the printf() is written, then the linker comes into the picture and it links that line to the module where the actual implementation of the printf() function is written.

Relocation:

There are some address-dependent locations in the program, and these address constants must be modified to fit the available space, this can be done by loader and this is known as relocation. In order to allow the object program to be loaded at a different address than the one initially supplied, the loader modifies the object program by modifying specific instructions.

Loading:

The loader loads the program into the main memory for execution of that program. It loads machine instruction and data of related programs and subroutines into the main memory, this process is known as loading. The loader performs loading; hence, the assembler must provide the loader with the object program.

eg. Absolute Loader

Absolute Loader:

The absolute loader transfers the text of the program into memory at the address provided by the assembler after reading the object program line by line. There are two types of information that the object program must communicate from the assembler to the loader.

It must convey the machine instructions that the assembler has created along with the memory address.
It must convey the start of the execution. At this point, the software will begin to run after it has loaded.

The object program is the sequence of the object records. Each object record specifies some specific aspect of the program in the object module. There are two types of records:

Text record containing a binary image of the assembly program.
Transfer the record that contains the execution’s starting or entry point.

The formats of text and transfer records are shown below:

 

Algorithm:

The algorithm for the absolute loader is quite simple. The object file is read record by record by the loader, and the binary image is moved to the locations specified in the record. The final record is a transfer record. When the control reaches the transfer record, it is transferred to the entry point for execution.

Flowchart:

 

My Personal Notes arrow_drop_up
Last Updated : 21 Nov, 2022
Like Article
Save Article
Similar Reads