Final Unit 3 2025
Final Unit 3 2025
,
Introduction
Preprocessor :
A preprocessor is a program that processes its input data to produce
output that is used as input to another program.
Linker :
A linker is a computer program that takes one or more object files
generated by a compiler and combines them into one, executable
program
Debugger :
Debugger is program which is used to test program or execute
program in single step execution.
INTRODUCTION TO LOADER
Object code, or an object file, is the representation of
code that a compiler or assembler generates by
processing a source code file.
A linker is typically used to generate an executable file
by linking object files together.
Object files often also contain data for use by the code
at runtime, relocation information, program symbols
(names of variables and functions) for linking and/or
debugging purposes, and other debugging information.
Introduction
to
Loader
INTRODUCTION TO LOADER
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
FUNCTION OF LOADER
1. Allocation: It allocates memory for the program in the main
memory.
10/28/2023 13
Loader is utility program which takes object
code as input prepares it for execution and loads
the executable code into the memory.
10/28/2023 15
User defined function and library function
Example - printf() ,scanf()
10/28/2023 17
It is the process of modifying the addresses used
in the address sensitive instructions of a program
So, program Can execute correctly from any
designated area of memory.
Ex. MOVER AREG,X
400
F1
500
Fig.: General Loading scheme
10/28/2023 19
Case II: These two module cannot co-exist at same storage locations.
Main
Storage
0
100 150
A
A
250 151
F1
100
251
F1
200
Relocated address given
Translation time by the loader
address
10/28/2023 Fig.: Relocation to avoid address conflict or storage waste 20
A loader must relocate A and F1 to avoid address
conflict or storage waste.
Relocation refers to adjustment of address field
not to movement of a program.
10/28/2023 21
ARCHITECTURE OF LOADER
Architecture of Loader
ARCHITECTURE OF LOADER
• Source program: This is a program written in a high-level
programming language that needs to be executed.
In this scheme, the source code goes into the translator line by line, and
then that single line of code loads into memory.
Disadvantages:
1. There is no use of the assembler but it is still there so a wastage of
memory takes place.
2. When source code runs multiple times the translation is also done
every time. so re-translation is happening.
3. Difficult to produce an orderly modular program
4. Difficult to handle multiple segments like if the source program is in a
different language. eg. one subroutine is assembly language & another
subroutine is FORTRAN
GENERAL LOADER SCHEME
General Loader Scheme :
Object
Module
A
A
Loader
B
Object
Module
B
Architecture of Loader
GENERAL LOADER SCEMES
• Source program: This is a program written in a high-level
programming language that needs to be executed.
• Dependenacy issues
ABSOLUTE LOADER
Absolute Loader: It loads a program at a specific memory
location, specified in the program’s object code. This location is
usually absolute and does not change when the program is loaded
into memory.
• An Absolute loader is the simplest of all other loaders.
• It takes the output of Assembler and load into memory without
relocation.
• The output of the assembler can be stored on any machine
readable form of storage, But most commonly it is stored on
punched cards or magnetic tape, disk, or drum.
• It loads a binary program in memory for Execution .
10/28/2023 39
Binary program is stored in a file that contains:
Header records: Contains load Origin ,Length of
code, load time execution starting address of
program.
Transfer record: contains entry point of execution
10/28/2023 40
ADVANTAGES OF ABSOLUTE
LOADER
1. It is simple to implement
2. No relocation is required.
3. The process of execution is efficient.
4. The task of loader becomes simpler as it simply obeys
the instruction regarding where to place the object code
to the main memory.
5. This scheme allows multiple programs or the source
programs written in different languages.
DISADVANTAGES OF ABSOLUTE
LOADER
10/28/2023 43
SUBROUTINE LINKAGE LOADER
Subroutine: In given program ,it is often needed to
perform a particular subtask many times on different data
values. such a subtask is usually called a subroutine.
E.g. assume that a program A calls a function F1. The program A and the
function F1 must be linked with each other. But where we have to load in main
storage? A possible solution would be to load them according to address
assigned when they were translated.
Case (I) At the time of translation A has been given storage area from 100 to
250 while F occupies area between 400 to 500. If we were to load these
programs at their translated address , a lot of storage will be wasted.
5. RELOCATING LOADER
Case (II) at the time of translated, both A and F1 may have been translated
with the identical start address 100. A goes from 100 to 250 and F1 goes
from 100 to 200. These two modules cannot co-exist at same. The linker
must relocate A and F1 to avoid address conflict or storage waste A possible
relocation is shown in figure.
It may be noted that relocation more than simply moving a program from one are to
another in the storage. It refers to adjustment of address fields and not to movement of a
program.
It avoid reassembling of all subroutines when
single subroutine change.
All 4 function are performed (i.e. Allocation,
Loading, Linking & reallocation).
Transfer vector is used to solve the problem of
linking & Program length info to solve
allocation.
10/28/2023 52
No suited for loading external data.
Transfer vector increase the size.
Does not facilitate access to data segment that
can be shared.
10/28/2023 53
6. DIRECT LINKING LOADER
It is type of Re-locatable Loader.
It is most common type of loader.
It allows the programmer to use multiple
procedure segments and multiple data segments.
The assembler should give the following
information to the loader:
1.The length of the object code segment.
2.A list of all symbols which are not defined in the
current segment but can be used in the current
segment.
10/28/2023 56
3.A list of all symbols which are defined in the
current segment but can be referred in the current
segment.
4.Information about address constants.
5.Machine code translation of the source program and
relative address.
To place the object code in the memory there are
two situations:1. Address of the object code could
be absolute.2. The address of object code can be
relative.
10/28/2023 57
The list of symbols not defined in the current
segment but used in the current segment are stored
in a data structure called USE table.
The lists of symbols defined in the current segment
and referred by the other segments are stored in a
data structure called DEFINITION table.
10/28/2023 58
Assembler generates 4 types of cards in the
object desk:
ESD:External Symbol Dictionary (ESD) record:
TXT: (TXT) records.
RLD: Relocation and Linkage Directory (RLD):
END :End of object deck
10/28/2023 59
1.ESD:External Symbol Dictionary (ESD) record:
Card contain information about all symbol that are
defined in this program, but that may reference
elsewhere, and all symbol referenced in this
program but defined elsewhere.
Source object symbol Type Relative Length
record Location
no./card no.
1 MAIN SD 0 36
2 RESULT LD 32 -
3 10/28/2023
SUM ER - - 60
Type:
SD: segment definition: symbol in segment
LD: Local definition: symbol is defined in this
program but it can be referenced by other
program.
ER: External symbol: defined in some external
program.
10/28/2023 61
2. TXT: (TEXT) records.
Text card contains actual object code.(translated
source code).
Source object Relative Location Object code
record no.
1 0
2 32
3 -
10/28/2023 62
3. RLD: Relocation and Linkage Directory (RLD):
Card contain information about those locations in
the program whose content depend on the
address at which the program is placed
Source ESD_ID Length(in Flag + or - Relative
object Byte) address
record no.
10/28/2023 64
Allow multiple procedure and data segment.
Allow independent translation of the program.
Relocation Facility.
10/28/2023 65
Not suitable in multitasking.
It is necessary to allocate, relocate, link, and
load all of the subroutines each time in order
to execute a program
loading process can be extremely time
consuming.
10/28/2023 66
Design of direct linking loader is more complicated
than absolute loader.
Input to loader is object module and this is divide into
4 section ESD,TXT,RLD,END
It requires two passes to complete the linking process
Pass I: assigns addresses to all external symbols
(Uses Global EST: GEST)
Pass II: performs actual loading, relocation and
linking.
10/28/2023 67
In Pass I ,a Global External Symbol table(GEST) is
prepared.
It contain every external symbol and corresponding
absolute address value.
10/28/2023 68
Copy of
Object object
Module records
Pass I Pass II
Main
Memory
Object GEST
Module
10/28/2023 69
OVERLAY STRUCTURE
Overlays: The loader can load programs in chunks called
overlays, which allows programs to run in a smaller
memory space by only loading the needed parts of the
program at a time.
OVERLAY STRUCTURE
• Program execution need not be achieved by loading all the
parts of large program in memory.
• So,that we can reduce memory requirement of such program
by loading required parts of program in memory.
• Hence some parts of program are given the same load
address during linking.
• Therefore,at any time,only one of these parts of program can
be loaded in memory because loading of other parts that has
same load address will overwrite it.
10/28/2023 71
OVERLAY STRUCTURE
• Overlay is a part of program that has same load origin as some
other parts of the program .and the program which contains
overlays is called as overlay structured program.
• Note that procedures B and D are never in used the same time;
neither are C and E.
10/28/2023 73
OVERLAY STRUCTURE
10/28/2023 74
ADVANTAGES OF OVERLAY STRUCTURE
1. Increased memory utilization: Overlays allow multiple programs to share the
same physical memory space, increasing memory utilization and reducing the
2. Reduced load time: Only the necessary parts of a program are loaded into
3. Improved reliability: Overlays reduce the risk of memory overflow, which can
3. Compatibility issues: Overlays may not work on all hardware and software
configurations, making it difficult to ensure compatibility across different
systems.
7. Programming design of overlays structure is complex and not possible in all cases
10/28/2023 76
What is linker? Why program relocation is required and
how is it performed?
Any usable program written in any language has to use functions /
subroutines. These functions could be either user defined functions
or they can be library functions.
Email : [email protected]
REFERENCES
1. https://www.geeksforgeeks.org/basic-functions-of-loader/
2. https://www.geeksforgeeks.org/loader-in-compiler-design/
3. https://www.geeksforgeeks.org/compiler-and-go-loader/
4. https://www.geeksforgeeks.org/subroutine-subroutine-nesting-and-stack-
memory/
5. https://www.geeksforgeeks.org/overlays-in-memory-management/