0% found this document useful (0 votes)
13 views

Module 4

ss ktu module 4

Uploaded by

alaina2026
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Module 4

ss ktu module 4

Uploaded by

alaina2026
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 59

Loaders and Linkers

• An object program contains translated instructions and data values


from the source program and specifies addresses in memory where
these items are to be loaded.
• Loading : brings the object program into memory for execution
• Relocation : modifies the object program so that it can be loaded at an
address different from the location originally specified
• Linking : combines two or more separate object programs and supplies the
information needed to allow references between them
Basic Loader Functions
• A loader is a system program that performs the loading function.
Many loaders also support program linking and relocation.
• Some systems have a linker(or a linkage editor) to perform the linking
operations and a separate loader to handle relocation and loading.
• The major functions performed by loader are:
• Allocation-Allocates the space for program in the memory.
• Linking
• Relocation
• Loading
Design of an Absolute Loader
• Absolute Loader is a primitive type of loader, which does only the
loading function.
• It does not perform linking and program relocation. All functions are
accomplished in a single pass:
• The Header record of object programs is checked to verify that the correct
program has been presented for loading.
• As each Text record is read, the 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.
Algorithm for an absolute loader
Begin
read Header record
verify program name and length
read first Text record
while record type is not ‘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
Loading of an absolute program
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 loader loads the first program to be run by the
computer usually an operating system.
Bootstrap begins itself at address 0
Load OS at address 80
There is no Header Record, Text Record or Control Record
A bootstrap loader for SIC/XE
A bootstrap loader for SIC/XE Cont..
Absolute Loader
• Drawback of absolute loaders
• Programmer needs to specify the actual address at which it will be loaded
into memory
• Difficult to run several programs concurrently, sharing memory between them
• Difficult to use subroutine libraries.
• Solution:
• A more complex loader that provides
• Program relocation
• Program linking
Relocating Loaders
• Motivation
• Efficient sharing of the machine with larger memory and when several
independent programs are to be run together
• Support the use of subroutine libraries efficiently
• Two methods for specifying relocation
• Modification Record
• Relocation Bit
• Each instruction is associated with one relocation bit
• These relocation bit in a Text record is gathered into bit masks
• Loader that allow program relocation are called relocating loaders or
relative loaders
• A modification record is used to describe each part of the object code
that must be changed when the program is relocated
• Modification record
• col 1: M
• col 2-7: relocation address
• col 8-9: length (half byte)
• col 10: flag (+/-)
• col 11-17: segment name
• Most of the instructions in this program use relative addressing or
immediate addressing
• The only portion of the assembled program that contains actual
addresses are the extended format instructions(line 15,35 and 65)
• So these are get affected with relocation
• Note that one modification record for each value that must be
changed during relocation.
• Each modification record specifies the starting address and the length
of the field whose value is to be altered.
• It describes the modification to be performed
• In this example, all modifications add the value of the symbol COPY,
which represents the starting address of the program
• Modification record scheme is convenient for machines with small
architecture
• It is not well suited to use this for complex architectures
• So we are considering the relocatable program written for SIC
CE poonjar 23
• If a machine primarily uses direct addressing and has a fixed
instruction format
• There are many addresses needed to be modified
• It is often more efficient to specify relocation using relocation bit
• There are no modification records, the text records are same as
before except that there is a relocation bit associated with each word
of the object code
• All SIC instructions occupy one word, this means that there is one
relocation bit for each possible instruction
• The relocation bits are gathered together into a bit mask following
the length indicator in each Text record.
• This mask is represented (in character form) as three hexadecimal
digits
• If the relocation bit corresponding to a word of object code is set to 1,
the programs starting address is to be added to this word when the
program is relocated
• A bit value 0 indicates that no modification is necessary
• If the text record contains fewer than 12 words of object code, the
bits corresponding to unused words are set to 0
• Consider for the first text record, the bit mask FFC (representing in bit
string 111111111100) specifies that 10 words of object code are to be
modified during relocation(line 10 to 55)
• For second Text record, mask E00, specifies that the first three words
are to be modified
• The remainder of the object code in this record is represented data constants,
RSUB instruction and thus do not require modification
• Other text record follows the same pattern
• Note that: the object code generated for the LDX instruction on line
210 begins a new Text record even though there is room for it in the
preceding record
• This occurs because each relocation bit is associated with a 3-byte
segment of object code in the Text Record
Program Linking
• The control sections could be assembled together (ie., in the same
invocation of the assembler) or they could be assembled
independently of one another
• In either case they would appear as separate segments of object code
after assembly
• The loader has to link, relocate and load the control section
Program Linking
• Program linking consists of two types of variables-EXTDEF and EXTREF
• EXTDEF-Symbols that are defined in current control section and may
be used by other control sections.
• EXTREF-Symbols used in present control section and are defined
elsewhere.
• The loader does not know which control sections were assembled at
the same time
• Consider the three separately assembled programs in Fig.
• Each consists of a single control section.
• Each program contains a list of items, LISTA, LISTB, LIST C; and it ends
with ENDA,ENDB,ENDC
• LISTA---ENDA, LISTB---ENDB, LISTC---ENDC.
• The labels on the beginnings and ends of the lists are external
symbols(they are available for linking)
• Note: Each program contains exactly the same set of references to
these external symbols.
• REF1, REF2, REF3 for Instruction operands
• REF4, REF5, REF6, REF7, REF8 are the values of data words
• Omitted the instructions which do not involve linking and relocation
CE poonjar 47
• The fig. (a) shows that three programs might look like this after being
linking and loading
• PROGA has been loaded at starting address 4000, PROGB and PROGC
are following
• Note: each of REF4 through REF8 has resulted (after relocation and
linking is performed) in the same value in each of the three programs
because the same source expression appeared in each program

53
54
Relocation and Linking operations performed
on REF4 from PROG A
55
Program after linking and loading (a) 56
57
58
In PROGA , the reference REF
program counter relative w
displacement 01D . When t
instruction is executed, th
program counter contains
value 4023(the actual addre
the next instruction).
59 The res
target address is 4040

You might also like