Paper Code : BCA601T
Title : System Programming
TOTAL TEACHING HOURS : 65
NO. OF HOURS/ WEEK : 05
IA : 50
Exam :100
Total :150
Loader
• It is a program that places into memory and prepares them for
execution
2 types: absolute loader, direct linking loader
• The assembler outputs the machine language translation of a program
on a secondary storage device
• Loader loads this translated program into memory and transfer control
to it
• Loader program is smaller than assembler; this makes more memory
available to the user program
• Assembler/compiler converts user source program to object program
• Loader is a program which accepts the object program and prepares
these programs for execution and initiates execution.
Databases
Programs loaded in memory read
for execution
Functions of a loader
• Allocation: allocate space in memory for the programs
• Linking: resolve symbolic references between object decks
• Relocation: adjust all address dependent locations, such as address
constants, to corresponds to the allocated space
• Loading: physically place the machine instructions and data into
memory
Loader Schemes
Based on the four functions the loader is divided into different types
1. Compile & go loaders
2. General loader scheme
3. Absolute loader
4. Relocating loader
5. Direct linking loader
6. Dynamic loading
7. Dynamic linking
1. Compile – And – Go Loader
• The assembler run in one part of memory and place the assembled machine
instructions and data
• After assembled, loading directly into assigned memory locations
• This is a simple solution, involving no extra procedures.
• It is used by the WATFOR FORTRAN compiler and several other language
processors.
• Such a loading scheme is commonly called “compile-and-go” or “assemble-
and-go.”
• It is relatively easy to implement.
• Assembler simply places the code into core
• And the “loader” consists of one instruction that transfers to the starting
instruction of the newly assembled program
Advantages
• It is relatively easy to implement
Disadvantages
• A portion of memory is wasted because the core occupied by the
assembler is unavailable to the object program
• It is necessary to retranslate (assemble) the user’s program deck every time
it is run
• It is very difficult to handle multiple segments, especially if the source
programs are in different languages (e.g: one subroutine in assembly
language and another subroutine in FORTRAN or PL/I). This makes it very
difficulty to produce orderly modular programs
Compile – and Go Loader
2. General Loader Scheme
• An output could be saved and loaded whenever the code was to be executed.
• The assembled programs could loaded into the same area in core that the
assembler occupied
• This output form, which may be on cards containing a coded form of the
instructions, is called an object deck/ object component.
• The loader accepts the assembled machine instructions, data, and other
information present in the object format, and places machine instructions and
data in core in an executable computer form.
• The loader is assumed to be smaller than the assembler, so that more memory
available to the user.
• A further advantage is that reassembly is no longer necessary to run the program
at a later date.
• Finally, if all the source program translators (assemblers and compilers) produce
object program and use compatible linkage conventions, it is possible to write
subroutines in several different languages since the object decks to be processed
by the loader will all be in the same “language”.
General Loader Scheme
3. Absolute Loader
• The simplest type of loader scheme, which fits the general model, is called an
absolute loader
• Here the assembler outputs the machine language translation of the source
program in almost the same form as in the “assemble and go” scheme, except
that the data is punched on cards (object deck) instead of being placed
directly in memory.
• The loader accepts the machine language text and places it into core at the
location prescribed by the assembler. This scheme makes more core available
to the user since the assembler is not in memory at load time.
Disadvantages.
• First, the programmer must specify to the assembler the address in core
where the program is to be loaded.
• Furthermore, if there are multiple subroutines, the programmer must
remember the address of each and use that absolute address explicitly in his
other subroutines to perform subroutine linkage.
The four loader functions are accomplished as follows in an absolute
loading scheme:
1. Allocation — by programmer
2. Linking — by programmer
3. Relocation — by assembler
4. Loading — by loader
• The absolute loader is a kind of loader in which relocated object files
are created, loader accepts these files and places them at a specified
location in the memory.
• This type of loader is called absolute loader because no relocating
information is needed, rather it is obtained from the programmer or
assembler.
• The starting address of every module is known to the programmer,
this corresponding starting address is stored in the object file then
the task of loader becomes very simple that is to simply place the
executable form of the machine instructions at the locations
mentioned in the object file.
• the programmer or assembler should have knowledge of memory
management. The programmer should take care of two things:
• Specification of starting address of each module to be used. If some
modification is done in some module then the length of that module may
vary. This causes a change in the starting address of immediate next modules,
it's then the programmer's duty to make necessary changes in the starting
address of respective modules.
• While branching from one segment to another the absolute starting address
of respective module is to be known by the programmer so that such address
can be specified at respective JMP instruction.
Design of Absolute Loader
• Assembler perform the task of allocation, reallocation & linking
• Loader read cards of the object deck, and move the text on the
cards into the absolute locations (absolute location specified by
assembler)
• For a simple absolute loader, all functions are accomplished in
a single pass as follows:
• 1) The Header record of object programs is checked to verify
that the correct program has been presented for loading.
• 2) As each Text record is read, the object code it contains is
moved to the indicated address in memory.
• 3) When the End record is encountered, the loader jumps to the
specified address to begin execution of the loaded program.
Two types the object deck communicate from assembler to the loader
1) It convey machine instructions (that the assembler has created)
along with assigned core location
2) It convey entry point of the program, where loader transfer control
after loading.
This information is transmitted on cards
Card Formats of Absolute Loader
There are 2 cards
TEXT CARDs for instructions & data
TRANSFER CARDS to hold the entry point of program
Advantages:
• It is simple to implement.
• It allows multiple programs or the source programs written in different
languages. If there are multiple programs written in different languages then the
respective language assembler will convert it to the language and common object
file is generated
• The task of loader becomes simpler: it simply obeys the instruction about where
to place the object code to the main memory
• The process of execution is efficient
• More core/memory available to the user, since assembler is not in memory
Disadvantages:
• It's the programmer's duty to adjust all the inter-segment addresses and
manually do the linking activity. For that, it is necessary for a programmer to
know the memory management.
• If multiple segments are present, the programmer must remember the address of
each and use that absolute address explicitly in his other subroutines to perform
subroutine linkage
• If at all any modification is done to some segment the starting address of
immediate next segments may get changed the programmer has to take care of
this issue
4.Subroutine Linkages/Program Linking
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.
• Subroutine linkage method: The way in which a machine makes it
possible to call and return from subroutine is referred to as its
Subroutine linkage method
7/16/2023 24
Subroutine Linkage
• Subroutine Linkage: Instructions
• There are two forms of the Branch and Link
instruction.
• BAL Branch and Link
• BALR Branch and Link, Register.
7/16/2023 25
Subroutine Linkages
• A main program ‘A’ wishes to transfer to subprogram B. The
programmer in program A could write transfer instruction (e.g BAL 14,
B) to subprogram B.
• The assembler does not know the value of this symbol reference;
error will produce
• This mechanism is typically implemented with relocating / direct
linking loader
Entry & Extrn Pseudo Ops
• EXTRN followed by a list of symbols indicates that these symbols are defined
in other programs but referenced in the present program
• ENTRY: If a symbol is defined in one program and referenced in others, insert
it into a symbol list following ENTRY pseudo ops
EXTRN ENTRY
SYMBOLS defined in other SYMBOLS defined in current
programs program
Referenced in present Referenced in others
program
Relocating Loader (Binary Symbolic Subroutine (BSS) Loader)
• Relocating loaders are used to perform allocation and linking for the
programmer
• An example of relocating loader scheme is BSS loader
• BSS loader allows many procedure segments, only one common data
segment
• Assembler assembles each procedure segment independently and passes on
the loader the text and information as to relocation and inter segment
references
The output of a relocating assembler using BSS scheme:
• The object program and information about all other program it references
• There are relocation information dependent on the core location
• The four loader functions are accomplished as follows in relocating
loading scheme
• Allocation – program length
• Linking - transfer vector
• Relocation – relocation bits
• Loading – by loader
• These functions automatically done by the BSS loader
Advantages
• Subroutines are handled efficiently
Disadvantages
• The transfer vector linkage is only useful for transfers, and is not well-suited
for loading or storing external data
• The transfer vector increases the size of the object program in memory
• The BSS loader, processes produces segments but does not facilitate access
to data segments that can be shared. This shortcoming is overcome in many
BSS loaders by allowing one common data segments, often called COMMON.
This facility is implemented by extending the relcoation bits scheme to use
two bits per halfword address field;
• 01=> half word is relocated relative to the procedure segment
• 10=> half word is relocated relative to the common data segment
• 00/11=> half word is not relocated
Direct linking loader
• A direct-linking loader is a general relocatable loader, and is perhaps the
most popular loading scheme presently used.
• The direct-linking loader has the advantage of allowing the programmer
multiple procedure segments and multiple data segments and of giving him
complete freedom in referencing data or instructions contained in other
segments. This provides flexible intersegment referencing and accessing
ability, while at the same time allowing independent translations of
programs.
• The direct linking loader has the advantage of allowing the
programmer multiple procedure segments and multiple data
segments and allows complete freedom in referencing data or
instructions contained in other segments.
• This provides flexible intersegment referencing and accessing ability
,while at the same time allowing independent translation of
programs.
• The assembler (translator) must give the loader the following information
with each procedure or data segment:
1. The length of segment
2. A list of all the symbols in the segment referenced by other segments and
their relative location within the segment
3. A list of all symbols not defined in the segment but referenced in the
segment
4. Information as to where address constants are located in the segment and a
description of how to revise their values
5. The machine code translation of the source program and the relative
addresses assigned.
• The assembler produces four types of cards in the object deck:
ESD, TXT, RLD, and END.
• External Symbol Dictionary (ESD) cards contain information about all symbols
that are defined in this program but that may be referenced elsewhere, and all
symbols referenced in this program but defined elsewhere.
• The text (TXT) cards contain the actual object code translated version of the
source program.
• The Relocation and Linkage Directory (RLD) cards contain information about
those locations in the program whose contents depend on the address at
which the program is placed. For such locations the assembler must supply
information enabling the loader to correct their contents.
• The END card indicates the end of the object deck and specifies the starting
address for execution if the assembled routine is the “main” program.
DESIGN OF A DIRECT - LINKING LOADER
There are four sections to the object deck (and four corresponding card
formats):
1. External Symbol Dictionary cards (ESD)
2. Instructions and data cards, called “text” of program (TXT)
3. Relocation and Linkage Directory cards (RLD)
4. End card (END)
• The ESD cards contain the information necessary to build the external symbol
dictionary or symbol table. External symbols are symbols that can be referred
beyond the subroutine level. The normal labels in the source program are
used only by the assembler, and information about them is not included in the
object deck.
There are three types of external symbols, as illustrated in the above:
1. Segment Definition (SD) — name on START or CSECT card.
2. Local Definition (LD) — specified on ENTRY card. There must be a label in
same program with same name.
3. External Reference (ER) — specified on EXTRN card. There must be a
corresponding ENTRY, START, or CSECT card In another program with same
name.
• Each SD and ER symbol is assigned a unique number (e.g., 1,2,3, .. .) by the
assembler. This number is called the symbol’s identifier, or ID, and is used
conjunction with the RLD cards.
• The TXT cards contain blocks of data and the relative address at which
the data is to be placed.
• Once the loader has decided where to load the program, it merely adds
the Program Load Address (PLA) to the relative address and moves the
data into the resulting location.
• The data on the TXT card may be instructions, non relocated data , or
initial value of address constants.
• The RLD cards contain the following information.
1. The location and length of each address constant that needs to be changed
for relocation or linking
• 2. The external symbol by which the address constant should be modified
(added or subtracted)
3. The operation to be performed (add or subtract)
• The END card specifies the end of the object deck. If the assembler END card
has a symbol in the operand field, it specifies a start of execution point for
the entire program (all subroutines).
• This address is recorded on the END card. There is a final card required to
specify the end of a collection of object decks.
• The loaders usually use either a loader terminate (LDT) or End of File (EOF)
card.
Two pass direct linking loader scheme
Disadvantage of direct linking loader
• It is necessary to allocate, relocate, link, and load all the subroutines
each time, in order to execute a program
• If the program contains many subroutines, the loading process will be
time consuming.
• Even though loader program is smaller than assembler, it uses
consider amount of space.