C Programming • Introduction to Computer, Programming & algorithms
C Programming / Loader

Loader

Notes 1 Introduction to Computer, Programming & algorithms

A loader is a system program that loads an executable program from secondary storage into main memory (RAM) so that the CPU can execute it. It also prepares the required memory and addresses before execution begins.

Notes

What is a Loader?

A loader is a system program that loads an executable program from secondary storage into main memory (RAM) so that the CPU can execute it. It also prepares the required memory and addresses before execution begins.

Real World Example

🌍 Real World Example

Think about opening Microsoft Word. The program is stored on your computer's storage. When you click its icon, the operating system loads the required program into RAM so that the CPU can start running it.

How Does a Loader Work?

EXECUTABLE FILE ↓ LOADER ↓ LOAD INTO RAM ↓ MEMORY SETUP ↓ CPU STARTS EXECUTION

Step 1 — Locate the Program

The loader finds the executable program stored on secondary storage such as an HDD or SSD.

Step 2 — Load into Main Memory

The executable program is copied from storage into the required locations in main memory (RAM).

Step 3 — Memory and Address Setup

The loader prepares the memory layout and adjusts addresses when required so that the program can run correctly.

Step 4 — Transfer Control

After the program is ready in memory, control is transferred to the program's entry point and execution begins.

Main Functions of a Loader

  • Loads the executable program into main memory.
  • Allocates the required memory.
  • Performs address relocation when required.
  • Helps prepare the runtime environment.
  • Transfers control to the program's entry point.

Types of Loader

Type Meaning
Absolute Loader Loads the program at a fixed memory address.
Relocating Loader Can load the program at different memory locations by adjusting addresses.

Loader in Program Execution

SOURCE PROGRAM ↓ COMPILER ↓ ASSEMBLER ↓ LINKER ↓ EXECUTABLE FILE ↓ LOADER ↓ RAM ↓ CPU ↓ PROGRAM EXECUTES
💡 In Simple Words

What Happens When You Switch On a PC?

The process of starting or resetting a computer is called Booting. It connects the initial hardware startup with loading the operating system into main memory so that the computer becomes ready for use.

1. Power On and Reset Vector

When the power button is pressed, the power supply provides power to the motherboard. The CPU starts from a predefined location called the Reset Vector, which points to the system firmware such as BIOS or UEFI.

2. POST — Power-On Self-Test

The BIOS or UEFI performs POST to check whether important hardware components are working properly.

  • RAM: Memory check
  • CPU: Basic processor operation
  • Graphics: Display initialization
  • Keyboard: Input-device check
  • Storage: Detection of available boot devices

If a critical hardware problem is detected, the firmware may report the problem through error messages or diagnostic signals.

3. Locating a Bootable Device

After POST, the firmware checks the configured boot order to find a bootable storage device such as an SSD, HDD, or USB drive.

On traditional BIOS-based systems, boot information may involve the Master Boot Record (MBR). Modern UEFI systems generally use the EFI System Partition (ESP) and a boot manager.

4. Loading the Bootloader

The firmware starts the system's bootloader. Examples include Windows Boot Manager and GRUB for Linux systems.

The bootloader prepares the next stage of the startup process and locates the operating system kernel.

5. Loading the Kernel

The bootloader loads the OS Kernel into RAM and transfers control to it. The kernel then initializes the operating environment and starts the required system services and drivers.

6. Operating System Starts

After the kernel and essential services are initialized, the operating system starts its user environment, such as a GUI or CLI, and the computer becomes ready for use.

POWER ON ↓ CPU RESET VECTOR ↓ BIOS / UEFI ↓ POST ↓ BOOTABLE DEVICE ↓ BOOTLOADER ↓ OS KERNEL ↓ OPERATING SYSTEM ↓ USER INTERFACE
💡 In Simple Words

When you switch on a computer, the firmware first checks the hardware, finds a bootable device, starts the bootloader, and the bootloader loads the operating system kernel into RAM. The kernel then starts the operating system.

Loader vs Bootloader

Loader Bootloader
Loads an executable program into main memory for execution. Starts the operating system boot process and loads the OS kernel.
Usually works with normal executable programs. Works during system startup.
Prepares a program for CPU execution. Prepares and transfers control to the operating system.
📌 Remember

Loader → Loads a program into RAM
Bootloader → Loads/starts the operating system

The linker creates the executable, while the loader puts that executable into RAM so the CPU can run it.

Quick Revision

Point Remember
Input Executable file
Main Job Load program into RAM for execution
Memory Main Memory / RAM
Types Absolute Loader, Relocating Loader
Final Action Transfers control to the program

Important Exam Questions

Short Answer Questions

  1. What is a loader?
  2. What is the main function of a loader?
  3. Where does the loader load an executable program?
  4. What is an absolute loader?
  5. What is a relocating loader?

Long Answer Questions

  1. Define a loader and explain its working.
  2. Explain the main functions of a loader.
  3. Explain the different types of loader.
  4. Explain the role of a loader in program execution.
🎥 Recommended Learning

Watch a simple Hindi explanation of loader and the program execution process.

▶ Watch: Loader in Operating System — Hindi Explanation

📝 Handwritten Notes

A short handwritten-style revision sheet for Loader will be provided here.

🧠 Mind Map

Use the mind map for quick revision of loader, memory loading and program execution.