Assembler, Linker, & Loader

Compiler \to Linker \to Loader

Compiler: Turns high-level source code into machine code.

Assembler: Encodes assembly code into machine code.

Note: Javac

Linker: Combine object files into an executable.

Loader: Brings executable into memory and starts execution.

Example: Manually calling the compiler, assembler, and linker

# Compiler
gcc -S sum.c
# Assembler
as -o sum.o sum.s
# Linker
ld -o sum sum.o
# Execute (Uses Loader)
./sum

Assembly and Machine Language

\text{Assembly Language} \to \text{(Assembler)} \to \text{Machine Language}

Assembly Language: Symbolic representation of machine language.

Machine Language: Set of instruction codes used to represent operations and date.

When to Use Assembly:

  1. Speed and size is critically important
  2. To use specialized instructions not available in high-level languages
    • e.g., INT, single instruction loop, SIMD, etc.
  3. Platform only supports assembly.

Assembly Drawbacks:

More on Assembly:

More on Assemblers

\text{Assembler's Job: } \text{Source} \to \text{Object}

Assembler: Translate a file of assembly language statements (source) into a file of binary machine instructions and binary data (object).

Two Major Parts

  1. Identifies memory locations with symbolic references (labels), both code and data
  2. Translate assembly statement into opcodes, register specifies, and labels not valid instructions.

Object File Contains: