[go: up one dir, main page]

0% found this document useful (0 votes)
19 views27 pages

Unit 3

The document discusses the differences between static and dynamic link libraries, highlighting aspects such as linking time, executable size, and update processes. It also explains various types of loaders, including absolute, relocating, dynamic linking, compile-and-go, and bootstrap loaders, detailing their functionalities, advantages, and disadvantages. Additionally, it covers the design of direct linking loaders and absolute loaders, including required data structures and the general loading scheme.

Uploaded by

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

Unit 3

The document discusses the differences between static and dynamic link libraries, highlighting aspects such as linking time, executable size, and update processes. It also explains various types of loaders, including absolute, relocating, dynamic linking, compile-and-go, and bootstrap loaders, detailing their functionalities, advantages, and disadvantages. Additionally, it covers the design of direct linking loaders and absolute loaders, including required data structures and the general loading scheme.

Uploaded by

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

Q.

1 Explain Differences between static link library and dynamic link


library?

Static Link
Library Dynamic Link Library

Linked to the program at Linked to the program at


compile time. runtime.

Increases the size of the Keeps the executable file size


executable file. smaller.

Every program has its own copy Library code is shared among
of the library. multiple programs.

Updates require recompiling the Can be updated independently


entire program. without recompiling.

Faster startup times for May have slightly slower


programs. startup times.

More portable as everything is Less portable; requires the


bundled together. library on the system.

Common extensions: .a (Linux), .lib Common extensions: .so


(Windows) (Linux), .dll (Windows)

Suitable for self-contained or Suitable for modular programs and


embedded systems. shared use

Q.2 What are the different types of Loaders? Explain compile and Go
loader

in detail.

Types of Loaders

Loaders are system programs that load executable files into memory and
prepare them for execution. There are various types of loaders, each with
its own specific functionality. Here are some common types:

1. Absolute Loader

o Loads the executable file into a specific, fixed memory


location and starts execution immediately.

2. Relocating Loader
o Can load programs into any memory location, adjusting
addresses in the program to match the loading location.

3. Dynamic Linking Loader

o Loads and links necessary modules at runtime rather than at


compile time, which is commonly used in operating systems.

4. Compile and Go Loader

o Translates the source code directly into executable code and


loads it into memory for immediate execution.

Compile and Go Loader

The Compile and Go Loader is a simpler type of loader that immediately


loads and executes the program after the compilation phase. It combines
the processes of compilation, loading, and execution into one step. Let’s
explore this in detail:

Working of Compile and Go Loader

1. The source code is given as input to the system.

2. The system’s compiler translates the source code into machine


code.

3. Instead of producing a separate object file, the loader immediately


places the machine code into memory.

4. Once loaded, the program starts executing.

Key Characteristics

 No Object File: The loader does not generate an intermediate


object file; it places the compiled code directly into memory.

 Fast Execution: Because the compilation and loading happen


almost simultaneously, this method is efficient for quick testing and
development.

 Simplicity: The overall process is simple and suitable for small


programs or educational purposes.

Advantages

 Faster Development: Useful for environments where quick


turnaround times are necessary, such as learning and
experimenting with small programs.
 No Need for Intermediate Storage: Saves time and resources by
not creating an intermediate object file.

Disadvantages

 Lack of Flexibility: Difficult to debug or modify the program since


the object code is not stored separately.

 Memory Wastage: If a program has to be executed multiple times,


it needs to be compiled each time, wasting both time and memory.

 Not Suitable for Large Programs: Inefficient for large


applications or systems due to repeated compilation.

Q.3 List and explain different loader schemes in detail.

1. Absolute Loader

Explanation:

 In this scheme, the loader loads the executable program into a pre-
defined and fixed memory location.

 The program must have all addresses specified absolutely, meaning


there is no flexibility in choosing where in memory to load the
program.

 The object code generated by the assembler includes fixed memory


addresses, and the loader simply copies the code into memory at
these addresses.

Advantages:

 Simple to implement because it only needs to load the program into


a specific memory location.

 Fast loading since no address modification is required.

Disadvantages:

 Lacks flexibility: The program must be loaded into the specified


memory location only.

 Not suitable for multitasking environments because it doesn’t


support dynamic memory allocation.
2. Relocating Loader (or Relocatable Loader)

Explanation:

 A relocating loader allows a program to be loaded into any memory


location, not a fixed one.

 It uses relocation information stored in the program’s object file to


adjust addresses during the loading process. The assembler
generates the necessary relocation information, which helps the
loader adjust the addresses.

 This makes the program more flexible and suitable for systems
where memory allocation must be dynamic.

Advantages:

 Allows programs to be loaded at any memory location.

 More suitable for operating systems that support multiprogramming


and require efficient memory management.

Disadvantages:

 More complex than the absolute loader since it needs to modify


addresses during the loading process.

 Slightly more time-consuming compared to the absolute loader due


to address adjustment.

3. Dynamic Linking Loader

Explanation:

 A dynamic linking loader doesn’t link all the modules of a program


at load time. Instead, some modules are loaded and linked when
they are needed during program execution.

 This scheme is commonly used in modern operating systems where


libraries or modules can be shared among different programs.

 Dynamic linking reduces the memory footprint of applications and


allows updates to shared libraries without recompiling dependent
programs.

Advantages:

 Reduces the size of executable files since libraries are loaded only
when needed.
 Facilitates sharing of common code among multiple programs,
reducing memory usage.

 Easier updates to libraries: Programs automatically use the updated


version of a library without recompilation.

Disadvantages:

 Slightly increases the overhead during program execution because


modules are linked dynamically.

 Dependency issues may arise if the required dynamic libraries are


not available or incompatible.

4. Compile-and-Go Loader

Explanation:

 As explained earlier, this scheme combines the compilation, loading,


and execution into one step.

 The source program is compiled, loaded into memory, and


immediately executed, without generating an intermediate object
file.

Advantages:

 Simplifies the process for small and simple programs.

 Useful for environments like educational purposes, where quick


compilation and execution are needed.

Disadvantages:

 Memory and time are wasted if a program needs to be re-executed


multiple times because it has to be recompiled each time.

 Debugging is difficult because there is no object code file to analyze.

5. Bootstrap Loader

Explanation:

 A bootstrap loader is a special type of loader used when a computer


is first turned on or restarted. It loads the operating system into
memory from a non-volatile storage device (e.g., a hard disk).
 This loader is typically stored in the system’s ROM and is
responsible for initializing the system and starting the operating
system.

Advantages:

 Essential for system startup and for loading the operating system.

 Simple and reliable because it is usually implemented in firmware.

Disadvantages:

 Limited in functionality since it mainly focuses on loading the


operating system.

Q.4 Explain Design of Direct linking loaders and explain required


data

structures.

Design of Direct Linking Loaders

A Direct Linking Loader is a type of loader that loads a program into


memory and links its various segments or modules by resolving external
references during the loading process. It is often used in multi-module
programs where modules need to be linked together efficiently.

Features of Direct Linking Loaders

1. Direct Address Resolution: The loader directly links modules at


load time by resolving addresses of symbols and external
references, making sure the program can execute properly without
needing further linking.

2. Efficient Loading: The program is loaded in a way that all external


symbol references are resolved in a single pass.

3. No Need for Relocation: Since linking is done before execution,


the program can be executed immediately after loading.

How Direct Linking Loaders Work

1. The loader reads the object modules generated by the assembler or


compiler.
2. It builds and maintains several data structures to facilitate linking
and address resolution.

3. The loader assigns addresses to various program sections and


adjusts addresses in the object code to ensure that external
references are correctly linked.

4. Once all addresses are resolved, the code is loaded into memory,
and the program can be executed.

Required Data Structures for Direct Linking Loaders

The design of a Direct Linking Loader relies on several key data structures
to manage information about the program and its external references:

1. Program Relocation Table

o Purpose: Stores information about which parts of the code or


data need to be relocated when the program is loaded into a
specific memory location.

o Contents: Contains entries specifying the addresses or


sections in the code that need modification based on where
the program is loaded in memory.

2. Symbol Table

o Purpose: Maintains information about symbols (such as


variable names, function names, and labels) that are defined
or referenced in the program.

o Contents: Each entry in the symbol table includes:

 Symbol Name: The name of the symbol.

 Address: The memory address assigned to the symbol


during loading.

 Length: The size of the data associated with the symbol


(if applicable).

o The symbol table is used to resolve addresses of symbols


during the linking process.

3. External Symbol Table


o Purpose: Contains information about symbols that are
defined in other modules and are referenced in the current
module.

o Contents: Each entry in the external symbol table includes:

 Symbol Name: The name of the external symbol.

 Address: The address where the symbol is defined


(resolved during linking).

4. Load Map

o Purpose: Provides a detailed summary of the memory layout


of the loaded program, including where each module and
segment is loaded.

o Contents: Contains information about the memory addresses


assigned to each module, symbol, and segment. This helps in
debugging and understanding the program’s memory usage.

5. Linking Table

o Purpose: Manages information about external references and


their resolutions.

o Contents: Contains entries that specify which symbols from


other modules need to be linked and how to resolve them
during the loading process.

Q.5 Explain “General loading scheme (using suitable diagram)”


with

advantages and disadvantages?


General Loading Scheme

The General Loading Scheme is a common and comprehensive


approach used to load and link programs in a modular and flexible
way. It outlines how a loader manages multiple object modules,
resolves external references, and prepares the program for
execution. The scheme encompasses steps like loading,
relocation, and linking.

Working of the General Loading Scheme

The General Loading Scheme involves several stages:

1. Loading: The object code from each module is loaded into


memory. The memory addresses are determined, but the
program is not yet executable because external references
need to be resolved.

2. Relocation: The addresses in the code and data are adjusted


based on where each module is loaded in memory. This
process ensures that the program’s memory references are
accurate.

3. Linking: External references between modules are resolved.


For example, if Module A calls a function defined in Module
B, the loader updates the call in Module A to point to the
correct address in Module B.

4. Memory Allocation: Memory is allocated for the code, data,


and stack segments of each module.
5. Transfer Control: Once all modules are loaded, linked, and
ready for execution, control is transferred to the starting
address of the program.

Advantages of the General Loading Scheme

1. Flexibility: The scheme can handle multiple object modules


and resolve complex external references, making it suitable
for large programs.

2. Efficient Memory Use: Relocation allows efficient use of


memory by loading programs at available memory locations.

3. Modularity: Programs can be divided into smaller,


manageable modules, promoting easier debugging and
maintenance.

4. Code Reusability: Commonly used code (like libraries) can be


reused across multiple programs, saving space and
promoting efficient memory usage.

Disadvantages of the General Loading Scheme

1. Complexity: The loading and linking process is more


complicated compared to simple schemes like the Absolute
Loader. The loader needs to maintain multiple data
structures and perform complex address resolution.

2. Execution Time Overhead: The relocation and linking


processes can add overhead to the program’s startup time,
making it slower to begin execution.

3. Dependency Issues: The program may fail to execute


correctly if any required module is missing or if there are
errors in resolving external references.

4. Memory Fragmentation: Memory allocation might lead to


fragmentation if there are many modules loaded
dynamically.

Q.6 Give complete design of Direct Linking Loader?

REFER QUES 4
Q.7 Give complete design of Absolute Loader with suitable
example?

Explanation:

 In this scheme, the loader loads the executable program into


a pre-defined and fixed memory location.

 The program must have all addresses specified absolutely,


meaning there is no flexibility in choosing where in memory
to load the program.

 The object code generated by the assembler includes fixed


memory addresses, and the loader simply copies the code
into memory at these addresses.

How an Absolute Loader Works

1. Reading Object Code: The absolute loader reads the object


module from the secondary storage (like a disk).

2. Loading into Memory: It loads the program into the memory


starting at a specific address as defined in the object code.

3. Transfer Control: After the code is loaded into the correct


memory location, the loader transfers control to the starting
address of the program so that execution can begin.

Advantages of Absolute Loader

1. Simplicity: The design and implementation of the loader are


straightforward because it does not perform address
modification or complex linking.
2. Fast Loading: Since there is no need for relocation or symbol
resolution, the loading process is quick and efficient.

3. Predictable Execution: The program always loads into the


same memory location, which can simplify debugging and
analysis.

Disadvantages of Absolute Loader

1. Lack of Flexibility: The program must be loaded into a


specific, predefined memory location. If the memory space is
occupied, the program cannot be loaded.

2. Memory Management: It does not support dynamic memory


allocation or multitasking environments effectively.

3. Difficult to Share Code: Since absolute addresses are used,


sharing libraries or code among programs is inefficient and
often impossible.

Q.8 What is the need of DLL? Differentiate between Dynamic and


static linking?

Dynamic Link Libraries (DLLs) are essential components in


modern software development. They provide several key benefits
that help improve the efficiency, flexibility, and maintainability of
software systems:
1. Memory Efficiency: DLLs allow multiple programs to share
the same code in memory. Instead of each program having a
separate copy of the code, DLLs enable code reuse, reducing
memory consumption.
2. Modularity: By breaking down a program into multiple
modules or libraries, developers can design programs in a
more modular way. This makes programs easier to update,
debug, and maintain.
3. Reduced Disk Space: Since the same DLL can be used by
multiple programs, the need for duplicating code is
minimized, saving disk space.
4. Simplified Updates: When a DLL needs to be updated (for
bug fixes or feature enhancements), only the DLL itself
needs to be replaced rather than recompiling and
redistributing the entire application. This can make
maintenance and software updates more efficient.
5. Faster Load Times: Programs using DLLs can be loaded
faster because DLLs are loaded into memory only when
required. This reduces the initial load time of applications.
6. Code Reusability: DLLs facilitate code reuse across multiple
applications. Common functions, like those in the Windows
API, can be packaged into DLLs and used by various
programs
REFER Q.1 FOR DIFFERENCE

Q.9 What is absolute loader? Explain design of absolute loader


with suitable
example and flowchart
Explanation:

 In this scheme, the loader loads the executable program into


a pre-defined and fixed memory location.

 The program must have all addresses specified absolutely,


meaning there is no flexibility in choosing where in memory
to load the program.

 The object code generated by the assembler includes fixed


memory addresses, and the loader simply copies the code
into memory at these addresses.

How an Absolute Loader Works

1. Reading Object Code: The absolute loader reads the object


module from the secondary storage (like a disk).
2. Loading into Memory: It loads the program into the memory
starting at a specific address as defined in the object code.
3. Transfer Control: After the code is loaded into the correct
memory location, the loader transfers control to the starting
address of the program so that execution can begin.

Design of Absolute Loader

The design of an Absolute Loader is straightforward because it


does not require any relocation or address modification. Here are
the key components and steps involved in the design of an
Absolute Loader:

1. Input

 The object code of the program.

 The object code specifies the memory address where the


program must be loaded.

2. Memory Layout

 The loader does not change any addresses in the object


code. It assumes the code has been generated with the
correct absolute addresses.

 The object code contains both instructions and data, all with
predefined addresses.

3. Loading Process

 The absolute loader loads the object code at the given


address without modification.

 The object code is loaded exactly as it is into the


corresponding memory locations.
4. Execution Control

 After the program is loaded into memory, the loader


transfers control to the starting point of the program (the
entry point), where execution begins.

DIAGRAM : FLOWCHART OF ABSOLUTE


LOADER

Example of Absolute Loader

Consider an example where the object code is compiled for an


application that should start at memory address 1000.

Object Code:

Memory Machine Instructi


Address Code on

1000 1100 LOAD A

1004 1200 ADD B

1008 1300 STORE C


Memory Machine Instructi
Address Code on

1012 1400 HALT

Steps:

1. The absolute loader reads the object code and starts at


memory address 1000.

2. The loader loads the LOAD A instruction at address 1000,


the ADD B instruction at address 1004, and so on, directly
placing them in memory.

3. After loading, the loader transfers control to memory


address 1000 to execute the first instruction (LOAD A).

Q.10 Explain Design of Direct linking loaders.

Design of Direct Linking Loaders

A Direct Linking Loader is a type of loader that loads a program into


memory and links its various segments or modules by resolving external
references during the loading process. It is often used in multi-module
programs where modules need to be linked together efficiently.

Features of Direct Linking Loaders

 Direct Address Resolution: The loader directly links modules at


load time by resolving addresses of symbols and external
references, making sure the program can execute properly without
needing further linking.

 Efficient Loading: The program is loaded in a way that all external


symbol references are resolved in a single pass.

 No Need for Relocation: Since linking is done before execution,


the program can be executed immediately after loading.

How Direct Linking Loaders Work

 The loader reads the object modules generated by the assembler or


compiler.

 It builds and maintains several data structures to facilitate linking


and address resolution.
 The loader assigns addresses to various program sections and
adjusts addresses in the object code to ensure that external
references are correctly linked.

 Once all addresses are resolved, the code is loaded into memory,
and the program can be executed.

Required Data Structures for Direct Linking Loaders

The design of a Direct Linking Loader relies on several key data structures
to manage information about the program and its external references:

 Program Relocation Table

1. Purpose: Stores information about which parts of the code or


data need to be relocated when the program is loaded into a
specific memory location.

2. Contents: Contains entries specifying the addresses or


sections in the code that need modification based on where
the program is loaded in memory.

 Symbol Table

1. Purpose: Maintains information about symbols (such as


variable names, function names, and labels) that are defined
or referenced in the program.

2. Contents: Each entry in the symbol table includes:

1. Symbol Name: The name of the symbol.

2. Address: The memory address assigned to the symbol


during loading.

3. Length: The size of the data associated with the symbol


(if applicable).

3. The symbol table is used to resolve addresses of symbols


during the linking process.
 External Symbol Table

1. Purpose: Contains information about symbols that are


defined in other modules and are referenced in the current
module.

2. Contents: Each entry in the external symbol table includes:

1. Symbol Name: The name of the external symbol.

2. Address: The address where the symbol is defined


(resolved during linking).

 Load Map

1. Purpose: Provides a detailed summary of the memory layout


of the loaded program, including where each module and
segment is loaded.

2. Contents: Contains information about the memory addresses


assigned to each module, symbol, and segment. This helps in
debugging and understanding the program’s memory usage.

 Linking Table

1. Purpose: Manages information about external references and


their resolutions.

2. Contents: Contains entries that specify which symbols from


other modules need to be linked and how to resolve them
during the loading process.

Q.11 Explain in brief Compile and Go loading scheme. What are


advantages

and disadvantages of it.

Compile and Go Loading Scheme

The Compile and Go Loading Scheme is a simple method of program


execution where the program is compiled, loaded into memory, and
immediately executed in a single step. The compiler generates the object
code in memory rather than storing it in a file, and the program is
executed directly after compilation.

Process of Compile and Go Loading Scheme


1. Input Source Code:

o The user writes the source code, which is input into the
compiler.

2. Compilation:

o The source code is compiled directly into memory, generating


the machine code required for execution.

3. Loading:

o The compiler places the object code (machine code) into the
memory itself.

4. Execution:

o After compilation, control is transferred to the starting address


of the program in memory, and the program begins execution.

Example Flow

1. A user writes a program in a high-level language like BASIC or


assembly.

2. The compiler translates the code directly into memory.

3. Execution begins immediately after compilation without saving the


compiled code to disk.

Advantages of Compile and Go Loading Scheme

1. Simplicity:

o The process is straightforward since compilation, loading, and


execution are integrated into a single step.

2. No Intermediate Files:

o The scheme eliminates the need for creating and managing


object files, saving disk space.

3. Faster Execution for Small Programs:

o It is faster for small programs because the compilation and


execution occur consecutively without intermediate steps.

Disadvantages of Compile and Go Loading Scheme

1. Wastage of Memory:
o Memory used for the compiler becomes unavailable for the
program, as the compiler and the program must reside in
memory simultaneously.

2. Limited Modularity:

o Each time the program is executed, it must be recompiled,


which is inefficient for larger programs or repeated executions.

3. Lack of Flexibility:

o The scheme does not support modular programs that consist


of multiple files or external libraries.

4. Error Handling:

o If errors occur during compilation, the entire process must be


restarted.

5. Not Suitable for Production:

o This approach is rarely used in modern production systems


because it does not allow for reusable object files or libraries.

Q.12 Describe the concept of DLL? How dynamic linking can be


done with or

without import.

Concept of DLL (Dynamic Link Library)

A Dynamic Link Library (DLL) is a collection of precompiled


functions, classes, or resources that applications or other DLLs
can load and use at runtime. DLLs allow multiple programs to
share code and resources, improving modularity, reducing
redundancy, and saving memory.

Unlike static linking, where all required functions are embedded


in the executable at compile time, DLLs are loaded and linked
dynamically during program execution.

Features of DLL:

1. Modularity: Programs can be split into smaller modules


(DLLs), which can be developed and updated independently.

2. Code Reusability: DLLs allow multiple applications to use the


same code, saving storage and reducing memory usage.
3. Dynamic Linking: Functions are linked and loaded only when
required, optimizing memory and performance.

4. Version Control: Updates can be made to DLLs without


recompiling dependent programs.

Advantages of DLL:

1. Reduced Disk Space and Memory Usage:

o Common code is stored in a DLL, and multiple


programs can share it instead of each program
including its own copy.

2. Improved Maintainability:

o DLLs can be updated independently without requiring


changes to the programs using them.

3. Faster Compilation:

o Only the DLLs and the dependent application need to


be recompiled when changes are made, not the entire
program.

Dynamic Linking

Dynamic linking is the process of linking libraries at runtime


instead of during the compilation of the program. It allows a
program to load external libraries (DLLs) only when needed. This
makes the program lightweight and memory-efficient.

Dynamic linking can be done with import or without import.

Dynamic Linking With Import

1. Import Libraries:

o A static library (import library) is linked during compile


time. This library acts as a bridge between the
application and the DLL.

o At runtime, the import library automatically loads the


corresponding DLL and resolves the external
references to the functions or resources in the DLL.
2. Process:

o During compilation, the program uses a stub


(placeholder) from the import library for the functions
in the DLL.

o At runtime, the operating system loads the DLL into


memory and updates the stubs with the actual
addresses of the functions in the DLL.

3. Advantages:

o Simplifies development as the compiler automatically


handles the linking.

o Resolves dependencies before program execution,


reducing runtime errors.

4. Example:

o In Windows, functions like MessageBox() from


user32.dll can be used through an import library.

Dynamic Linking Without Import

1. Explicit Loading:

o The program explicitly loads the DLL at runtime using


system calls like LoadLibrary() (Windows) or dlopen()
(Linux).

o Functions in the DLL are accessed through pointers


obtained using calls like GetProcAddress() (Windows)
or dlsym() (Linux).

2. Process:

o The program manually loads the DLL into memory


when needed.

o Function pointers are resolved explicitly for each


required function.

o After execution, the DLL is unloaded using calls like


FreeLibrary() (Windows) or dlclose() (Linux).

3. Advantages:

o Provides flexibility as the program can decide when


and which DLLs to load.
o Useful for plugins or optional features where loading
the DLL depends on runtime conditions.

4. Disadvantages:

o Increases complexity as developers must manually


manage DLL loading, function resolution, and
unloading.

o Errors may occur if the DLL or functions are unavailable


at runtime.

5. Example:

o A program that dynamically loads a custom plugin


(e.g., plugin.dll) based on user input.

Q.13 Write short notes on :

i) Subroutine Linkage

Subroutine linkage refers to the mechanism by which control is


transferred between the main program and subroutines, as well
as the exchange of data between them. Subroutines are reusable
blocks of code that perform a specific task, and linkage ensures
proper execution and return between the caller and the
subroutine.

Components of Subroutine Linkage

1. Call Mechanism:

o The main program (caller) invokes the subroutine using


a call instruction.

o Control is transferred to the entry point of the


subroutine.

2. Passing Parameters:

o Data or arguments are passed to the subroutine


through:

 Registers

 Stack

 Memory locations

 Global variables
3. Return Address:

o When the subroutine finishes execution, control must


return to the instruction immediately following the call
in the main program.

o The return address is typically stored in the stack or a


register.

4. Preservation of Caller State:

o The subroutine preserves the state of the caller


(registers, flags, etc.) to avoid interference.

5. Return Mechanism:

o A return instruction in the subroutine transfers control


back to the caller.

Key Concepts

 Stack Frame: Used to manage local variables, parameters,


and return addresses during nested calls.

 Recursion: Subroutines that call themselves, managed via


stack for proper linkage.

Example in Assembly

assembly

Copy code

CALL SUBROUTINE ; Call subroutine

... ; Code after return

SUBROUTINE:

; Perform task

RET ; Return to caller

ii) Overlays

Overlays are a memory management technique used in systems


with limited memory. They allow programs larger than the
available memory to run by loading only the required parts of a
program into memory at a time.
Concept of Overlays

 The program is divided into overlays or sections, each


containing related functionality.

 Only one overlay resides in memory at a time, and others


are loaded dynamically as needed.

 Overlays are managed by the operating system or a loader,


which ensures that the appropriate section is loaded for
execution.

Structure of Overlays

1. Root: The core part of the program that remains in memory


throughout execution.

2. Overlay Segments: Parts of the program loaded and


unloaded dynamically.

How Overlays Work

1. The root program decides which overlay is needed.

2. The loader loads the requested overlay into memory,


replacing the previously loaded overlay.

3. Execution continues from the loaded overlay.

Advantages of Overlays

1. Efficient Use of Memory: Allows execution of large programs


in limited memory.

2. Modularity: Encourages dividing the program into logical


modules.

Disadvantages of Overlays

1. Programming Overhead: Requires careful design to partition


the program.

2. Runtime Overhead: Loading overlays can slow down


execution.

Q.14 With the help of diagram explain General Loading Scheme.

General Loading Scheme


The General Loading Scheme is a flexible and versatile method of
loading programs into memory for execution. It is designed to handle
various types of object programs, including relocatable and non-
relocatable code, by making use of loaders that resolve addresses and link
modules.

Features of the General Loading Scheme

1. Relocation:

o Adjusts the relative addresses in the program so that they can


execute correctly at any memory location.

2. Linking:

o Resolves references between different modules and external


symbols.

3. Loading:

o Places the program into memory for execution.

4. Starting Execution:

o Transfers control to the starting address of the program.

Steps in the General Loading Scheme

1. Program Reading:

o The loader reads the object program (input) from secondary


storage.

2. Relocation and Linking:

o Address references are adjusted based on the program's


loading location.

o External and symbolic references are resolved using


information from a relocation table and external symbol table.

3. Loading:

o The adjusted machine code is placed in the memory at the


specified locations.

4. Execution:
o Control is passed to the starting address for program
execution.

Advantages of General Loading Scheme

1. Flexibility:

o Can handle relocatable and non-relocatable code.

2. Efficient Resource Use:

o Only necessary modules are loaded into memory.

3. Reusability:

o Allows modular programming by linking multiple object files.

4. Dynamic Linking:

o Supports dynamic linking, reducing memory usage.

Disadvantages of General Loading Scheme

1. Complexity:

o Requires additional processing for relocation and linking.

2. Time Overhead:

o Increases load time due to relocation and linking steps.

3. Dependency on Tables:

o Relocation and external symbol tables must be accurately


maintained.

You might also like