[go: up one dir, main page]

0% found this document useful (0 votes)
47 views9 pages

SPCC - 4

SPCC notes for mumbai university

Uploaded by

Ian Thomas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views9 pages

SPCC - 4

SPCC notes for mumbai university

Uploaded by

Ian Thomas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

SPCC – 4

Loader: A loader is a system software program that performs the loading function. It brings
the object program into memory and starts execution.

Basic Loading principles -


● Loading Operation -
o Loading the program uses program load address (PLA) as a pointer.
o It stores the content of the machine operation code in memory at an address
specified by PLA.
● Basic principles of loading operations-
o Make the program ready for execution: bring the program the executable
program in main memory after proper relocation.
o Start execution: Starting address is passed to computer hardware for execution.
More loading principles -
● Loader reads the size of the executable program.
● Requests to memory manager of OS for requisite space to load the executable
program in the primary memory.
● It loads the executable program in the primary memory. Loader sends the starting
address to the memory address register or program counter so that the computer can
start execution of the loaded program.
Functions of loader -
● Allocation: Allocates the space in memory where the object program can be loaded.
This is done by calculating size of the program
● Linking: Resolves the symbolic references (code/data) between the object modules by
assigning all the user subroutine and library subroutine addresses.
● Relocation: It modifies an object program by changing certain instructions so that it
can be loaded at different addresses. There are some address dependent locations in
● the program such address constants must be adjusted according to allocated space.
● Loading: Places all machine instructions and data of corresponding programs and
subroutines into the memory.
Procedure of loader -
● Step 1: Reads the header of the executable file to find out the size of the text and
data
● Step 2: Creates an address space which is large enough
● Step 3: Copies the instructions and data into primary memory
● Step 4: Copies parameters to the main program onto the stack
● Step 5: Initialize the machine registers and sets the stack pointer
● Step 6: Jumps to a start-up procedure that copies the parameters into the argument
registers and calls the main procedure
Role of loader and linker -
Loader vs Linker -

Types of Loaders -

● Compile and go Loader


● General Loader
● Absolute Loader
● Relocating Loader
● Direct linking Loader
● Dynamic Loader
● Compile and Go Loader:
o Also known as a "Load and Go" loader, it's one of the simplest loaders.
o The compiler produces machine code directly, which is then loaded into
memory and executed immediately.
o It's straightforward but lacks features like separate compilation and linking.
● General Loader:
o A more advanced loader that can handle programs generated by different
compilers.
o It reads the object program, performs relocation if needed, and loads it into
memory for execution.
● Absolute Loader:
o Loads a program into memory at a specific location, known as the absolute
address.
o Program locations are fixed, making it less flexible but straightforward to
implement.
o It's suitable for environments with fixed memory allocation.
● Relocating Loader:
o Allows programs to be loaded into any part of memory, with relocation done
dynamically.
o Handles address references within the program by adjusting them according to
the actual memory location where the program is loaded.
o Provides flexibility in memory allocation and enables multiple programs to
share memory effectively.
● Direct Linking Loader:
o Performs linking as part of the loading process.
o Resolves external references (symbols) by directly including the required code
or data from other modules into the main program.
o It simplifies the linking process but can lead to code duplication if multiple
programs use the same external symbols.
● Dynamic Loader:
o Loads and links modules into memory dynamically during program execution.
o Allows for more flexible memory management as modules can be loaded and
unloaded as needed.
o Commonly used in operating systems to support features like dynamic linking
and shared libraries.
Absolute Loader:

Programmer should take care of two things:


● First thing is specification of starting address of each module to be used.
● Second thing is, while branching from one segment to another the absolute starting
address of respective module is to be known by the programmer.
Roles in absolute loader:
● Allocation is done by programmer
● Linking is done by the programmer
● Relocation is done by the assembler
● Loading is done by the loader
Advantages:
● Simple to implement
● Task of loader becomes simpler
● Allows multiple programs or the source programs written in different languages
● Process of execution is efficient
Disadvantages:
● Programmer must specify the loading address in the assembly program
● In case of multiple subroutines, the programmer must remember the address of each
subroutine.
Relocating Loader:

● Relocating loaders prevent the need to reassemble all subroutines when only one
subroutine changes, streamlining the programming process.
● These loaders execute the object program by utilising available memory space
efficiently, ensuring smooth program execution.
● They manage the organisation and loading of program components into memory,
reducing the need for extensive reassembly.
● The assembler divides the program into segments, assembling each independently
and providing the loader with details on relocation and references.
● The assembler also supplies the loader with additional information such as the overall
program length and the length of the transfer vector.
● The transfer vector stores names of external subroutines and is crucial for linking
different parts of the program.
● When a subroutine is called, the program transfers control to the corresponding entry
in the transfer vector.
● Finally, the loader calculates the absolute location of each program component in
memory, ensuring precise execution.
Advantages:
● Avoids need to reassemble all subroutines when a single subroutine is changed.
● Performs task of allocation and linking for programmers.
Disadvantages:
● Difficult to implement.
● Algorithms depend on the file structure of the program.
● Slower than absolute loader.
Direct linking loader:
● It is a type of relocatable loader.
● Allowing the programmer multiple procedure segments and multiple data segments
and giving the programmer complete freedom in referencing data or instruction
contained in other segments.
● The programmer is free to reference data or instructions that are contained in the
other segment.
● The direct linking loaders provide flexible intersegment referencing and accessing
ability.
● The loader doesn’t have direct access to source code. It works with object code
generated by assembler.
● Placing code into memory-
o If the addresses of the object code are absolute, the loader can directly place
the code in memory without any additional adjustments.
o If the addresses are relative, it is the responsibility of the assembler to inform
the loader about these relative addresses. The assembler assigns relative
addresses.
● Information provided by assembler to loader -
o Length of program.
o List of symbols (both defined and referenced in this and other segments).
o Address constants – Their location and how to revise their values.
o Machine code translation of source program with relative addresses assigned.
Types of cards in object code:
● External Symbol Directory (ESD):
o It contains information about all symbols that are defined in the present
program, but that may be referenced at some other location.
● Text (TXT):
o Object code of source program
● Relocation and linkage directory (RLD):
o It contains information about location in the program whose contents depend
on the address at which the program is placed.
● END: End of object file and specifies start address for execution.
Dynamic linking and loading:
● Sometimes, a program may require more storage space than the available one.
● Execution of such a program can be possible if all the segments are not required
simultaneously to be present in the main memory.
● In such a situation, only those segments are resident in the memory that are needed
at the time of execution.
What would happen if the required segment were not present in memory?
● Execution process will be delayed until the required segment gets loaded into the
memory.
● The overall effect of this is efficiency of execution gets degraded.
● The efficiency can be improved by selecting all interdependent segments.
● Assembler cannot do this task; the user must specify such dependencies.
● Interdependency of the segments can be specified by a tree-like structure called
overlay structure.
Overlay Structure:
● Contains multiple root nodes and edges.
● Each node represents a segment.
● Memory requirement specification is crucial.
● Segments can coexist in memory if on the same path.
● Program subroutines are required at different times.
● Recognizing mutual exclusivity of subroutines helps identify overlays.
Dynamic loading:
● For overlay structure to work, it is necessary for the module loader to load the
various procedures as they are needed.
● Portion of the loader that intercepts the calls and loads the necessary procedure is
called the overlay supervisor or flipper.
● It is called dynamic loading (load on call).
Dynamic Linking:
● In dynamic linking, loading and linking of external references are postponed until the
execution time.
● Steps involved:
o The assembler generates text, binding, and relocation data from a
source program.
o The loader loads only the main program.
o When the main program executes a transfer instruction to an external address,
the loader is invoked.
o The segment containing the external references is loaded into memory.
Advantages:
● No overhead is incurred.
● System can be dynamically reconfigured.
Disadvantages:
● Overhead and complexity incurred because of postponed binding

You might also like