Loaders

Loader: -

Edit

Loader is a utility program which takes object code as input prepares it for execution and loads the executable code into the memory. Thus loader is actually responsible for initiating the execution process.

Q.        Define loader. What are different functions of it?  – 4 m

Functions of Loader: -

Edit

The loader is responsible for the activities such as allocation, linking, reallocation and loading.

1) It allocates the space for program in the memory, by calculating the size of the program. This activity is called as allocation.

2) It resolves reference of code / data between the object modules by assigning all the user subroutine and library subroutine addresses. This activity is called linking.

Functions of Loader

Edit

3) There are some address dependent locations in the program such address constants must be adjusted according to allocated space; such activity done by loader is called as relocation.

4) Finally it places all the machine instructions and data of corresponding programs and subroutines into the memory. Thus program now becomes ready for execution, this activity is called loading.

Loading Schemes

Edit

Q.        What are different loading schemes?   -- 8 m

Ans: - Based on various functionalities of the loader, there are various types of loaders which are known as loading schemes.

a) Compile and go loader: -

Edit

In this type of loader, the instruction is read line by line, its machine code is obtained and it is directly put in the main memory at some known address. That means the assembler runs in one part of memory and the assembled machine instructions and data is directly put into their assigned memory locations. This scheme is simple to implement. Disadvantages:-1) Wastage of memory as assembler present in memory. 2) There is no production of object file. 3) Multiple programs can’t get handed. 4) Execution time will be more in this scheme as every time program is assembled and then executed.

Compile and go loader

b) General Loader Scheme: -

Edit

In this loader scheme, the source program is converted to object program by translator. The loader accepts these object codes and puts machine instructions and data in an executable form at their assigned memory. The loader occupies some portion of main memory. The program need not be re translated each time while running it. There is no wastage of memory, because assembler is not placed in the memory, instead of it, loader occupies some portion of the memory.

 General Loader Scheme

It is possible to write source program with multiple languages.

c) Absolute Loader:-

Edit

Absolute Loader

Absolute loader is a kind of loader in which relocated object files are created, loader accepts these files and places them at specified locations in the memory. This type of loader is called absolute because no relocation information is needed; rather it is obtained from the programmer. In this scheme, the programmer must have knowledge of memory management. For example

Line Number                                                  Line Number

1          Main   start     1000                                        1          sum     start     5000

:                         :                                                                                   :

15                    jmp      500                                          20                    jmp      2000

                        store

16                    END           location 2000                   21                    END

As from figure it is clear that we have main program from 1000 to 2000 location written by programmer. We have sum program from 5000 to 7000 location written by programmer. It is simple to implement. It allows writing multiple programs. The task of loader becomes simpler. The process of execution is efficient.

Q.        Write a difference between absolute loader and compile and go loader .  ----- 4 m

Sr. No.Absolute Loader    Compile & Go Loader
1)Multiple programs are possibleMultiple programs are not possible
2)This is efficient scheme    This is very less efficient scheme
3)Programmer must have knowledge   of memoryMemory knowledge is not required by programmer
4)Complex than compile & goVery simple scheme.
5)Translator is not in main memoryTranslator is in main memory.
6)Object code is generated    No object code generation

d) Subroutine Linkages: -

Edit

Consider, program A wishes to transfer to subprogram B. Currently the control is in program A. Then using branch and link instruction (BAL), the control can transfer to program B. The value of next instruction in program A is stored. But assembler does not know the value of address of B and will give it as error. This problem is overcome by a mechanism called subroutine linkage. Here assembler uses extern word. These are basically the symbols which are defined externally but referenced in the present program. In this way subroutine linkage will work.

Subroutine Linkages

e) Relocating Loaders: -

Edit

To avoid possible assembling of all subroutines when a single subroutine is change and to perform the tasks of allocation and linking for the programmer, the general class of relocating loader was introduced. The output of a relocating loader is the program and information about all other programs it references. In addition, there is information (relocation information) as to location in this program that must be change if it is to be loaded in an arbitrary location in memory. In the given program X variable will be at 30. But after loading it will be loaded at 530. The address of variable ‘X’ can be found as given below:

500                  +          30        =         530

Segment register         offset               actual address

 Relocating Loaders

f) Direct Linking Loader: -

Edit

The direct linking loader is a general relocatable loader. This type of relocatable allows programmer multiple procedure segments and multiple data segments. This loader performs the translation of source program independently. The assembler must give the loader the following information with each procedure or data segment:

1) The length of segment

2) A list of symbols in current segment

3) A list of external symbols

4) The machine code of source program.

In this way direct linking loader works.

References

Edit
  • Notes by Prof. Dipak Pawar, Team WikiNote, Pune
  • WikiNote Foundation

Last modified: Friday, 20 September 2019, 12:58 AM