Computer Engineering is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

Language processors: compilers, interpreters, assemblers, linkers and loaders

Clear, exam-focused notes that define and compare the five main language processors (compilers, interpreters, assemblers, linkers, loaders), explain their roles, give precise definitions, diagrams to draw, commands to remember, worked examples and likely exam questions.

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

Language processors are the tools that turn human-written programs into running code on hardware. An engineer uses them every day when writing, building, debugging and deploying software: choosing compilation or interpretation affects performance, debugging, binary size and deployment.

Key ideas

Start with definitions (each bolded term defined at first use):

  • Source program — a program written in a high-level or assembly language intended to be translated or executed. Assumed to be a sequence of characters organized into files.

  • Target machine — the hardware (and its instruction set and ABI) where code will run.

  • Compiler — a program that performs a systematic translation from a source language S to a target language T (typically machine code or an intermediate object format). Formal statement used in exams: for all source programs p and for all valid inputs i, if semantics_S(p, i) is defined then semantics_T(compile(p), i) = semantics_S(p, i), subject to assumptions about defined behaviour in S and ABI constraints in T. Assumes source semantics are specified and that side-effects mapped correctly.

  • Interpreter — a program that directly executes the semantics of a source program by reading its representation and performing the specified operations at runtime. A formal relation: run_int(p, i) = semantics_S(p, i) without producing a permanent machine-code translation; may produce the same externally observable behaviour but typically with different performance and resource use.

  • Assembler — a translator from an assembly language (mnemonics + directives) to machine code or object format. It primarily maps assembly instructions to opcodes but may expand pseudo-instructions into multiple machine instructions; it resolves local labels, handles forward references (often via two passes), and emits relocatable object records.

  • Linker — a program that combines one or more object files and libraries (static archives, e.g., .a, and shared libraries, e.g., .so) into a single executable or library. Main tasks: symbol resolution (match undefined references to symbol definitions) and relocation (adjust addresses inside code/data to reflect final placement). Define these:

    • Symbol table — table listing symbols (names), attributes (defined/undefined, section, value/address or offset, size), and linkage (local/global).
    • Relocation — the process of modifying addresses and constants inside code/data according to the final load-time addresses of sections and symbols. In ELF-based systems, dynamic linking commonly uses relocation entries (REL/RELA) and indirection via the Procedure Linkage Table (PLT) and Global Offset Table (GOT).
  • Loader — the system component that sets up the process address space (maps the executable and required shared libraries), initializes the stack, performs any required dynamic link resolution, then transfers control to the program's entry point. Distinguish static linking (linking done ahead-of-time) from dynamic linking (some resolution deferred until load-time or at runtime via the dynamic loader).

  • Object file — the output of an assembler or compiler back end; contains machine code and metadata (sections like .text, .data, .bss), a symbol table, relocation records and possibly debug information. Common ELF file types: relocatable (ET_REL), executable (ET_EXEC), and shared object (ET_DYN). Draw and label a rectangular layout: boxes for .text, .data, .bss (with sizes), a symbol-table box, a relocation-entries box, and an optional debug/info box. Label each box with: name, purpose, and examples (e.g., .text: code, .data: initialized globals, .bss: zero-initialized data).

Precise behaviour and assumptions universities ask for:

  • Correctness condition for a compiler (given above). State assumptions: defined behaviour only, deterministic source semantics, target ABI stable, no unspecified conversions.
  • Linking rule (exact): For each undefined symbol in the set of input object files, the linker must find exactly one definition or report an error; if multiple strong definitions exist, the linker reports an error unless weak/strong rules apply. Explain weak vs. strong linkage briefly (weak allows overridden definitions). For static linking, all undefined references must be resolved at link time; for dynamic linking, undefined references to shared library symbols may be left for the dynamic linker to resolve at load time or on first call.

When to use which processor (practical rules):

  • Use a compiler when you need performance and static checks (C, C++).
  • Use an interpreter when fast edit-run cycle, portability, or dynamic features are primary (Python, JavaScript engines). Note: modern engines mix: interpreters + JIT compilers.
  • Use an assembler when writing low-level code or when compiler outputs assembly; linker/loader are used to combine units and prepare runtime execution.

Diagrams to draw in an exam (describe exactly):

  1. Compilation pipeline: draw a horizontal sequence of boxes labeled: Source file -> Preprocessor -> Lexical analyser -> Parser -> Semantic analyser -> Intermediate code generator -> Optimiser -> Code generator -> Assembler -> Linker -> Executable -> Loader -> Running process. Draw arrows between boxes. Under each box write one or two words describing output (e.g., tokens, AST, IR, assembly).
  2. Object file layout: draw one large rectangle split into .text, .data, .bss, symbol table, relocation table; annotate each with purpose.

Short, exact definitions should be memorised (compiler, interpreter, assembler, linker, loader, object file, relocation, symbol resolution, static vs dynamic linking).

Formulas

For this programming/tool topic we list the command syntax and short meaning to remember (one per line): gcc -c file.c — compile file.c to object file file.o (stops before linking). -c means "compile only". gcc file.o -o exe — link object file(s) to produce executable exe. gcc -Wall -O2 -g file.c -o exe — compile with warnings (-Wall), optimisation level 2 (-O2), include debug symbols (-g), output exe. as file.s -o file.o — assemble assembly source file.s into object file.o. ld file1.o file2.o -o exe — link object files into executable using linker ld (low-level invocation). objdump -d file.o — disassemble .text section from object file (useful to inspect generated code). nm file.o — list symbols in an object or binary (shows defined/undefined and values/addresses: section-relative for object files; virtual addresses for executables/shared objects). readelf -a file — show ELF headers and sections for native executable/object files (GNU/Linux ELF tool). strace -o trace.txt ./exe — trace system calls of a running executable (Linux debugging).

Explain: file.c is input source file; file.o object file; exe executable name; flags like -O2 are compiler options (optimisation), -g include debug info.

Worked examples

Example 1 — single C file compilation, step-by-step (small source): Source (file.c): int sum(int a, int b) { return a + b; } int main() { return sum(2,3); } Steps:

  1. Preprocessor: expands macros and includes (none here) → same source.
  2. Lexical analysis: produces tokens: "int", "sum", "(" , "int", "a", "," "int", "b", ")", "{" ...
  3. Parsing: build an abstract syntax tree (AST) with nodes for function definitions and return expressions. Draw a small tree: root=program -> func_def(sum) with params a,b and body return(a+b), func_def(main) ...
  4. Semantic analysis: check types (both int), resolve that sum is defined before use or declared, build symbol table entries: sum: func int(int,int), main: func int().
  5. Intermediate code generation: produce three-address code or IR, e.g., t1 = 2; t2 = 3; t3 = call sum(t1, t2); return t3.
  6. Optimiser: may inline sum because small and called once (optional). If inlined, final IR for main becomes return 2+3.
  7. Code generation: produce assembly for target (load immediate, add, return value in register). Example assembly fragment (conceptual) shown in exam answers.
  8. Assembler: translate assembly mnemonics to machine opcodes; emit object file with .text containing code, symbol table with global symbol main and maybe local labels.
  9. Linker: for a single file, mostly resolves startup code and standard libraries; produces executable with entry point and resolved addresses.
  10. Loader: places executable in memory, sets registers and stack, jumps to startup, which calls main. Final result: program exits with status 5.

Example 2 — two-file linking (symbol resolution and relocation), conceptual trace: Files: a.c defines int x = 10; void inc() { x++; } and b.c has extern int x; int main(){ inc(); return x; }.

  1. Each file compiled to object: a.o defines symbol x (data) and inc (text); b.o has undefined reference to inc and to symbol x (reads/writes), but emits relocations marking where addresses must be fixed when linked.
  2. Linker input: a.o (defines x, inc), b.o (references inc and x). Linker builds global symbol table mapping x to object a.o's data address, inc to its code address.
  3. For each relocation in b.o, the linker replaces placeholders with the final addresses from the symbol table (this is relocation). If a.o and b.o place sections at final offsets, relocation modifies code/data bytes accordingly.
  4. If a definition is missing, linker error: undefined reference. If multiple strong definitions of x appear, linker reports duplicate symbol (unless language and linker allow weak symbols).
  5. Final executable contains combined sections; loader will map them and at runtime the program returns 11.

(These examples give the step-by-step algorithmic trace exam answers expect; include a drawn pipeline and object-layout for full marks.)

Common mistakes

  • Thinking interpreters always run slower than compiled code; modern JIT interpreters can match or exceed performance for long-running code.
  • Forgetting relocation: students often forget to mention relocation entries or symbol table when explaining linking.
  • Mixing up .data and .bss: .data holds initialised globals; .bss holds zero-initialised globals and does not occupy file space (only memory at load time).

For your exam

Typical question types and what full-marks answers include:

  • Definitions and short notes: give concise definitions (as above) and a one-line example.
  • Diagram question: draw the compilation pipeline or object file layout; label each box and explain outputs in one sentence.
  • Derivation/Explanation: Formal correctness of a compiler or the steps of linking; state assumptions (undefined behaviour, ABI) and list steps precisely.
  • Trace/Algorithm: Given small source files, show lexical tokens, AST or IR, and outline symbol-table entries and relocation steps—step-by-step.
  • Command-line/Tool question: show the correct sequence of gcc -c, as, ld or gcc linking and explain flags; show nm or objdump usage. Full-mark answers include clear definitions, one-line description of responsibilities, a correct pipeline diagram, and one worked example or command trace.

Quick check

  1. What is the job of a linker?
  2. How does an assembler differ from an interpreter?
  3. Why does .bss not increase executable file size? Answers: Linker: combine object files, perform symbol resolution and relocation. Assembler: translates assembly to object code (one-to-one to machine instructions); interpreter: executes source program instructions directly at runtime. .bss holds zero-initialised data which the loader allocates at run-time but is not stored in file, so it does not increase file size.

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?