SPCC Module 4
SPCC Module 4
Module 4
• Functions of loaders
• Relocating loader,
• 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.
ABSOLUTE LOADER
In this scheme, 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.
ABSOLUTE LOADER
• The term "relocating" refers to the ability of the loader to adjust, or "relocate", the
absolute addresses in a program so that it can be loaded at an address different from the
one originally specified for it.
• It achieves this by modifying the object code of a program based on the offset address,
which is the starting address where the program is loaded in main memory.
RELOCATING LOADER
• For instance, if a program has an instruction that refers to a memory location, the address
of that memory location is determined when the program is assembled or compiled.
• If the program is later loaded into a different part of memory, the addresses referred to by
those instructions will be incorrect. The relocating loader adjusts these addresses based
on the new location of the program in memory.
DIRECT LINKING LOADER
• The direct linking loader is the most common type of loader. The loader cannot have the
direct access to the source code. The assembler should give the following information to
the loader
✓ The length of the object code segment
✓ The list of all the symbols which are not defined in the current segment but can be
used in the current segment.
✓ The list of all the symbols which are defined in the current segment but can be
referred by the other segments.
• The list of symbols which are not defined in the current segment but can be used in the
current segment are stored in a data structure called USE table. The list of symbols which
are defined in the current segment and can be referred by the other segments are stored in
a data structure called DEFINITION table.
DIRECT LINKING LOADER
• There are 4 types of cards available in the direct linking loader. They are
i. ESD-External symbol dictionary
ii. TXT-card
iii. RLD-Relocation and linking dictionary
iv. END-card
Advantages of Direct Linking Loader:
Simplicity: Direct linking loaders are simpler to implement because they do not require any relocation or
address modification during loading. This simplicity can make them suitable for resource-constrained
environments or for simple programs where complexity is not a major concern.
Faster Loading: Since direct linking loaders do not perform any address adjustments, they can load
programs into memory more quickly compared to relocating loaders. This can be advantageous for
programs that need to start execution promptly.
DIRECT LINKING LOADER
Disadvantages of Direct Linking Loader:
1. Lack of Flexibility: One of the significant drawbacks of direct linking loaders is their lack of
flexibility in terms of memory layout. Programs loaded using direct linking loaders are typically
bound to specific memory addresses, making it challenging to load them at different locations
without modification.
2. Memory Fragmentation: Direct linking loaders can contribute to memory fragmentation because
they load programs into fixed memory locations. This can lead to inefficient memory usage over
time, especially if programs are loaded and unloaded frequently.
3. Inability to Handle Overlays: Direct linking loaders are not well-suited for handling overlay
techniques, which involve dynamically swapping portions of a program in and out of memory. This
limitation can be problematic for large programs that need to manage memory usage efficiently.
4. Limited Portability: Programs loaded by direct linking loaders may have limited portability across
different systems or memory configurations. They are often tied to specific memory layouts and may
require modifications to run on systems with different memory architectures.
DYNAMIC LINKING AND LOADING
• Definition: Dynamic loading refers to the capability of a program to load and execute
modules (code or data) at run time, as opposed to being loaded statically during
compilation or linking.
• Usage: This feature allows programs to be more flexible and efficient by loading only
the necessary modules or libraries when they are required, rather than loading everything
at startup.
• Benefits:
• Reduced memory usage: Only necessary modules are loaded, saving memory.
• Faster startup times: Only essential components are loaded initially, improving startup
speed.
• Flexibility: Modules can be loaded and unloaded dynamically, enabling features like
plug-ins and modular architecture.
DYNAMIC LINKING AND LOADING
• Definition: Dynamic linking is a mechanism where a program is linked to libraries (code or
data) at run time, allowing multiple programs to share a single copy of a library in memory.
• Usage: This feature promotes code reusability and reduces memory overhead by allowing
multiple programs to use common libraries without each program having its own copy of
the library.
• Benefits:
• Code reuse: Multiple programs can use the same shared libraries, reducing duplication.
• Memory efficiency: Shared libraries are loaded into memory once and shared among
programs, saving memory.
• Updates: Libraries can be updated independently without requiring changes to every
program using them.
• Example: On a Unix-like system, dynamic linking is commonly used with shared libraries
(e.g., .so files), where programs dynamically link to these libraries at runtime.
UNIVERSITY QUESTIONS
• What are the main functions of Loader? Enlist the loader schemes [05]
• Explain Direct Linking Loader in detail [10]
• What are the functions of Loader [05]
• What is Relocation and Linking Concept in Loaders [05]
• Explain different types of Loaders in detail [10]
• Explain absolute loader. State its advantages and disadvantages [05]
• Explain Dynamic Linking Loader in detail [10]