The basic functions of loaders
1. Loading – brings the object program into memory for execution

  1. Bootstrapping
    1. Actions taken when a computer is first powered on
    2. The hardware logic reads a program from address 0 of ROM (Read Only Memory)
      1. ROM is installed by the manufacturer
      2. ROM contains bootstrapping program and some other routines that controls hardware (e.g. BIOS)
  2. Bootstrapping is a loader
    1. Loads OS from disk into memory and makes it run
    2. The location of OS on disk (or floppy) usually starts at the first sector
    3. Starting address in memory is usually fixed to 0
      1. no need of relocation
    4. This kind of loader is simple
      1. no relocation
      2. no linking
      3. called “absolute loader”


2. Relocation – modifies the object program so that it can be loaded at an address different from the location originally specified

  1. Assembler review
    1. Assembler generates an object code assuming that the program starts at memory address 0
    2. Loader decides the starting address of a program
    3. Assembler generates modification record
  2. Limits of modification record
    1. Record format
      1. (address, length)
    2. It can be huge when direct addressing is frequently used
    3. If instruction format is fixed for absolute addressing, the length part can be removed
    4. Instead of address field, bit-vector can be used
      1. 1101100..... means instruction 1 2 4 5. .. need to be modified
  3. Hardware support for relocation
    1. Base register
      1. assembler and loader do not need to worry about relocation


3.  Linking – combines two or more separate object programs and also supplies the information needed to reference them.

  • Background
  1. A large problem is better broken into several small pieces
  2. Each piece is better implemented independently
    1. assembled (compiled) independently
  3. There are many data structures shared among those pieces
    1. variables and procedures
  4. Some programs are used by many different programs
    1. print(), file operations, exp(), sin(), ...
    2. these are usually provided as library functions
  • Requirements for linking
  1. Each module defines
    1. which symbols are used by other modules
    2. symbols undefined in a module are assumed to be defined in other modules
      1. if these symbols are declared explicitly, it helps linker to resolve
  • Principles
  • Assembler evaluates as much as possible
    1. expressions
  • If some cannot be resolved,
    1. provide the modification records