Vous êtes sur la page 1sur 7

Loaders & Linkers

Compiled By: Girish GS


Asst. Professor
BNMIT

Loaders and Linkers


This Chapter gives you

Basic Loader Functions


Machine-Dependent Loader Features
Machine-Independent Loader Features
Loader Design Options
Implementation Examples

System Software for Program Development


The following figure shows the various system software used in the development of program.

The source program written in assembly language or high level language will be converted into
object program, of course by considering macros within the source code. This conversion is
either from the assembler or complier contains translated instructions and data values from the
source program or specific addresses in memory where these items are to be loaded for
execution. The linker combines two or more separate object program and supplies the
information needed to allow references between them. Loader loads an executable program and
starts its execution.
1
BNMIT-ISE

Loaders & Linkers

Basic Loader Functions


Loader: A system software that performs the loading function.
The role of loader is shown in figure. In figure assembler (translator) generates the object
program and later loaded to the memory by the loader for execution.

Figure. Role of loader


Linker: Some systems have a linker to perform the linking operations and a separate loader to
handle relocation and loading

2
BNMIT-ISE

Loaders & Linkers

Figure : The Role of both Loader and Linker


Type of loaders
The different types of loaders are:
absolute loader
bootstrap loader
relocating loader (relative loader)
direct linking loader

Design of an absolute Loader


Consider the design of an absolute loader that might be used with the SIC assembler discussed.
We use the same object program (described in assembler) for SIC machine.

Object program

3
BNMIT-ISE

Loaders & Linkers

Absolute loader operation is simple because our loader doesnt need to perform neither linking
nor program relocation.
All functions are accomplished in one pass
The header record is checked to verify that the correct program has been
presented for loading
Text record is then read and object code it contains is moved to the indicated
address in memory
When the End record is encountered, the loader jumps to the specified address to
begin execution of the loaded program
The following figure shows a representation of the object program after loading. The contents of
memory for which there is no text record are shown as xxxx. This indicates that the previous
contents of these locations remain unchanged.
Memory address

Contents (4x4 Bytes)

0000
0010

xxxxxxxx
xxxxxxxx

xxxxxxxx
xxxxxxxx

xxxxxxxx
xxxxxxxx

xxxxxxxx
xxxxxxxx

0FF0
1000
1010
1020
1030

xxxxxxxx
14103348
20613C10
36482061
000000xx

xxxxxxxx
20390010
0300102A
0810334C
xxxxxxxx

xxxxxxxx
36281030
0C103900
0000454F
xxxxxxxx

xxxxxxxx
30101548
102D0C10
46000003
xxxxxxxx

2030
2040
2050
2060
2070
2080

xxxxxxxx
205D3020
392C205E
00041030
2C103638
xxxxxxxx

xxxxxxxx
3FD8205D
38203F10
E0207930
20644C00
xxxxxxxx

xx041030
28103030
10364C00
20645090
0005xxxx
xxxxxxxx

001030E0
20575490
00F10010
39DC2079
xxxxxxxx
xxxxxxxx

Figure. Program loaded in memory


The following figure shows the algorithm for absolute loader. Although this processing is
extremely simple, there is one aspect that deserves comment. Each byte of assembled code is
given using its hexadecimal representation in character form. For example the machine operation
code for STL instruction would be represented by the pair of characters 1 and 4. When these
are read by loader, they will occupy two bytes of memory 14(hex 31 34)
For execution the operation code must be stored in a single byte with hexadecimal value 14.
Thus each pair of bytes must be packed together into one byte.
begin
4
BNMIT-ISE

Loaders & Linkers

read Header record


verify program name and length
read first Text record
while record type is E do
begin
{if object code is in character form, convert into internal
representation}
move object code to specified location in memory
read next object program record
end
jump to address specified in End record
end
Advantage

Simple and efficient

Disadvantage

The need for programmer to specify the actual address


Difficult to use subroutine libraries

A Simple Bootstrap Loader

When a computer is first turned on or restarted, a special type of absolute loader,


called bootstrap loader, is executed.
This bootstrap loads the first program to be run by the computer usually an
operating system
We will examine a very simple bootstrap loader for SIC/XE.
The bootstrap begins at address 0 in the memory of the machine as shown below
It loads the operating system starting at address 80
Each byte of object code to be loaded is represented on device F1
There is no Header record, End record, or control information (addresses, length, )
The object code from device F1 is always loaded into consecutive bytes of memory,
starting at address 80
After loading the object code from device F1, the bootstrap jumps to address 80 to
begin the execution of the program
Much of the work of the bootstrap loader is performed by the subroutine GETC

5
BNMIT-ISE

Loaders & Linkers

6
BNMIT-ISE

Loaders & Linkers

The algorithm for the bootstrap loader is as follows


Begin
X=0x80 (the address of the next memory location to be loaded
Loop
A GETC (and convert it from the ASCII character
code to the value of the hexadecimal digit)
save the value in the high-order 4 bits of S
A GETC
combine the value to form one byte A (A+S)
store the value (in A) to the address in register X
X X+1
End
It uses a subroutine GETC, which is
GETC

A read one character


if A=0x04 then jump to 0x80
if A<48 then GETC
A A-48 (0x30)
if A<10 then return
A A-7
return

Review questions.
Q. Write short note on absolute loader
Q. Write an algorithm for an absolute loader.
Q. Explain bootstrap loaders.
Q. Write an algorithm for Bootstrap loader.
Q. Briefly explain a simple bootstrap loader with an algorithm

7
BNMIT-ISE

Vous aimerez peut-être aussi