Sytem Prog Imp
Sytem Prog Imp
Sytem Prog Imp
Introduction: The Source Program written in assembly language or high level language will
be converted to object program, which is in the machine language form for execution. This
conversion either from assembler or from compiler , contains translated instructions and data
values from the source program, or specifies addresses in primary memory where these items are
to be loaded for execution.
Loading - which allocates memory location and brings the object program into memory for
execution - (Loader)
Linking- which combines two or more separate object programs and supplies the information
needed to allow references between them - (Linker)
Relocation - which modifies the object program so that it can be loaded at an address different
from the location originally specified - (Linking Loader)
_____________________________________________________________________________________
Upendra Kumar V
CS Dept, V N C,Hospet. 1
System Programming
The algorithm for this type of loader is given here. The object program and, the object program
loaded into memory by the absolute loader are also shown. Each byte of assembled code is given
using its hexadecimal representation in character form. Easy to read by human beings. Each byte
of object code is stored as a single byte. Most machine store object programs in a binary form,
and we must be sure that our file and device conventions do not cause some of the program bytes
to be interpreted as control characters.
Begin
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
_____________________________________________________________________________________
Upendra Kumar V
CS Dept, V N C,Hospet. 3
System Programming
This needs the design and implementation of a more complex loader. The loader must provide
program relocation and linking, as well as simple loading functions.
Relocation
The concept of program relocation is, the execution of the object program using any part
of the available and sufficient memory. The object program is loaded into memory wherever
there is room for it. The actual starting address of the object program is not known until load
time. Relocation provides the efficient sharing of the machine with larger memory and when
several independent programs are to be run together. It also supports the use of subroutine
libraries efficiently. Loaders that allow for program relocation are called relocating loaders or
relative loaders.
_____________________________________________________________________________________
Upendra Kumar V
CS Dept, V N C,Hospet. 5
System Programming
The relocation bit method is used for simple machines. Relocation bit is 0: no
modification is necessary, and is 1: modification is needed. This is specified in the columns 10-
12 of text record (T), the format of text record, along with relocation bits is as follows.
Text record
col 1: T
col 2-7: starting address
col 8-9: length (byte)
col 10-12: relocation bits
col 13-72: object code
Twelve-bit mask is used in each Text record (col:10-12 – relocation bits), since each text
record contains less than 12 words, unused words are set to 0, and, any value that is to be
modified during relocation must coincide with one of these 3-byte segments. For absolute loader,
there are no relocation bits column 10-69 contains object code. The object program with
relocation by bit mask is as shown below. Observe FFC - means all ten words are to be modified
and, E00 - means first three records are to be modified.
Program Linking
The Goal of program linking is to resolve the problems with external references
(EXTREF) and external definitions (EXTDEF) from different control sections.
_____________________________________________________________________________________
Upendra Kumar V
CS Dept, V N C,Hospet. 6
System Programming
EXTDEF (external definition) - The EXTDEF statement in a control section names symbols,
called external symbols, that are defined in this (present) control section and may be used by
other sections.
ex: EXTDEF BUFFER, BUFFEND, LENGTH
EXTDEF LISTA, ENDA
EXTREF (external reference) - The EXTREF statement names symbols used in this (present)
control section and are defined elsewhere.
ex: EXTREF RDREC, WRREC
EXTREF LISTB, ENDB, LISTC, ENDC
Define record
The format of the Define record (D) along with examples is as shown here.
Col. 1 D
Col. 2-7 Name of external symbol defined in this control section
Col. 8-13 Relative address within this control section (hexadecimal)
Col.14-73 Repeat information in Col. 2-13 for other external symbols
Example records
D LISTA 000040 ENDA 000054
D LISTB 000060 ENDB 000070
Refer record
The format of the Refer record (R) along with examples is as shown here.
Col. 1 R
Col. 2-7 Name of external symbol referred to in this control section
Col. 8-73 Name of other external reference symbols
Example records
R LISTB ENDB LISTC ENDC
R LISTA ENDA LISTC ENDC
R LISTA ENDA LISTB ENDB
Here are the three programs named as PROGA, PROGB and PROGC, which are Chapter: LOADERS & LINKERS
separately assembled and each of which consists of a single control section. LISTA, ENDA in
PROGA, LISTB, ENDB in PROGB and LISTC, ENDC in PROGC are external definitions in
each of the control sections. Similarly LISTB, ENDB, LISTC, ENDC in PROGA, LISTA,
ENDA, LISTC, ENDC in PROGB, and LISTA, ENDA, LISTB, ENDB in PROGC, are external
references. These sample programs given here are used to illustrate linking and relocation. The
following figures give the sample programs and their corresponding object programs. Observe
the object programs, which contain D and R records along with other records.
_____________________________________________________________________________________
Upendra Kumar V
CS Dept, V N C,Hospet. 7
System Programming
0000 PROGA START 0
EXTDEF LISTA, ENDA
EXTREF LISTB, ENDB, LISTC, ENDC
………..
……….
0020 REF1 LDA LISTA 03201D
0023 REF2 +LDT LISTB+4 77100004
0027 REF3 LDX #ENDA-LISTA 050014
.
.
0040 LISTA EQU *
0054 ENDA EQU *
0054 REF4 WORD ENDA-LISTA+LISTC 000014
0057 REF5 WORD ENDC-LISTC-10 FFFFF6
005A REF6 WORD ENDC-LISTC+LISTA-1 00003F
005D REF7 WORD ENDA-LISTA-(ENDB-LISTB) 000014
0060 REF8 WORD LISTB-LISTA FFFFC0
END REF1
_____________________________________________________________________________________ 1
Upendra Kumar V
CS Dept, V N C,Hospet. 0
System Programming
For example, the value for REF4 in PROGA is located at address 4054 (the beginning
address of PROGA plus 0054, the relative address of REF4 within PROGA). The following
figure shows the details of how this value is computed.
_____________________________________________________________________________________ 1
Upendra Kumar V
CS Dept, V N C,Hospet. 1
System Programming
The initial value from the Text record
Keeping these details work through the details of other references and values of these
references are the same in each of the three programs.
Linking Loader uses two-passes logic. ESTAB (external symbol table) is the main
data structure for a linking loader.
ESTAB - ESTAB for the example (refer three programs PROGA PROGB and PROGC) given is
as shown below. The ESTAB has four entries in it; they are name of the control section, the
symbol appearing in the control section, its address and length of the control section.
_____________________________________________________________________________________ 1
Upendra Kumar V
CS Dept, V N C,Hospet. 2
System Programming
Program Logic for Pass 1
Pass 1 assign addresses to all external symbols. The variables & Data structures
used during pass 1 are, PROGADDR (program load address) from OS, CSADDR
Control section Symbol Address Length
PROGA 4000 63
LISTA 4040
ENDA 4054
PROGB 4063 7F
LISTB 40C3
ENDB 40D3
PROGC 40E2 51
LISTC 4112
ENDC 4124
16
(control section address), CSLTH (control section length) and ESTAB. The pass 1
processes the Define Record. The algorithm for Pass 1 of Linking Loader is given below.
3.6.2 Program Logic for Pass 2
Pass 2 of linking loader perform the actual loading, relocation, and linking. It uses
modification record and lookup the symbol in ESTAB to obtain its addres. Finally it
uses end record of a main program to obtain transfer address, which is a starting
address needed for the execution of the program. The pass 2 process Text record and
Modification record of the object programs. The algorithm for Pass 2 of Linking Loader
is given below.
17
3.6.3 Improve Efficiency, How?
The question here is can we improve the efficiency of the linking loader. Also
observe that, even though we have defined Refer record (R), we haven’t made use of it.
The efficiency can be improved by the use of local searching instead of multiple searches
of ESTAB for the same symbol. For implementing this we assign a reference number to
each external symbol in the Refer record. Then this reference number is used in
Modification records instead of external symbols. 01 is assigned to control section name,
_____________________________________________________________________________________ 1
Upendra Kumar V
CS Dept, V N C,Hospet. 3
System Programming
3 ENDB 40D3
4 LISTC 4112
5 ENDC 4124
20
3.7 Machine-independent Loader Features
Here we discuss some loader features that are not directly related to machine
architecture and design. Automatic Library Search and Loader Options are such
Machine-independent Loader Features.
3.7.1 Automatic Library Search
This feature allows a programmer to use standard subroutines without explicitly
including them in the program to be loaded. The routines are automatically retrieved from
a library as they are needed during linking. This allows programmer to use subroutines
from one or more libraries. The subroutines called by the program being loaded are
automatically fetched from the library, linked with the main program and loaded. The
loader searches the library or libraries specified for routines that contain the definitions of
these symbols in the main program.
Ref No. Symbol Address
1 PROGB 4063
2 LISTA 4040
3 ENDA 4054
4 LISTC 4112
5 ENDC 4124
Ref No. Symbol Address
1 PROGC 4063
2 LISTA 4040
3 ENDA 4054
4 LISTB 40C3
5 ENDB 40D3
21
3.7.2 Loader Options
Loader options allow the user to specify options that modify the standard
processing. The options may be specified in three different ways. They are, specified
using a command language, specified as a part of job control language that is processed
_____________________________________________________________________________________ 1
Upendra Kumar V
CS Dept, V N C,Hospet. 4
System Programming
Here is one more example giving, how commands can be specified as a part of
object file, and the respective changes are carried out by the loader.
LIBRARY UTLIB
INCLUDE READ (UTLIB)
INCLUDE WRITE (UTLIB)
DELETE RDREC, WRREC
CHANGE RDREC, READ
CHANGE WRREC, WRITE
NOCALL SQRT, PLOT
The commands are, use UTLIB ( say utility library), include READ and WRITE
control sections from the library, delete the control sections RDREC and WRREC from
the load, the change command causes all external references to the symbol RDREC to be
changed to the symbol READ, similarly references to WRREC is changed to WRITE,
finally, no call to the functions SQRT, PLOT, if they are used in the program.
3.8 Loader Design Options
There are some common alternatives for organizing the loading functions,
including relocation and linking. Linking Loaders – Perform all linking and relocation at
load time. The Other Alternatives are Linkage editors, which perform linking prior to
load time and, Dynamic linking, in which linking function is performed at execution time
22
3.8.1 Linking Loaders
The above diagram shows the processing of an object program using Linking
Loader. The source program is first assembled or compiled, producing an object program.
A linking loader performs all linking and loading operations, and loads the program into
memory for execution.
3.8.2 Linkage Editors
The figure below shows the processing of an object program using Linkage editor.
A linkage editor produces a linked version of the program – often called a load module or
an executable image – which is written to a file or library for later execution. The linked
program produced is generally in a form that is suitable for processing by a relocating
loader.
Some useful functions of Linkage editor are, an absolute object program can be
created, if starting address is already known. New versions of the library can be included
_____________________________________________________________________________________ 1
Upendra Kumar V
CS Dept, V N C,Hospet. 7