# Compilers, interpreters and assemblers

> CIE A-Level Computer Science · 9618 (2022-2024)
> Source: https://www.owlsprep.com/study/cie-9618-u5-compilers-interpreters-and-assemblers/

This sub-topic covers the three core types of system translator, explaining how each converts human-readable source code into executable machine code. You will learn their functions, compare their pros and cons, and identify common use cases for exams.

**Prerequisites:** [Basic understanding of system software](https://www.owlsprep.com/study/cie-9618-u5-introduction-to-system-software/); Difference between high-level and low-level programming languages

## Learning objectives

- Distinguish between compilers, interpreters and assemblers by function
- Explain the core purpose of each translator type
- Compare advantages and disadvantages of each translator
- Identify appropriate use cases for each translator

## 1. Assemblers: Function and Key Properties

**Assembler** — A translator that converts low-level assembly language source code into processor-specific machine code. Each assembly instruction maps to exactly one machine code instruction for the target processor.

*Example:* An ARM assembler converts ARM assembly mnemonics into binary machine code that runs natively on ARM processors.

Assembly language uses human-readable mnemonics (abbreviations) for machine instructions and symbolic labels for memory locations. Assemblers resolve these symbols into actual binary memory addresses during translation.

**Worked example:** Explain why an assembler is required to run an assembly program on a Raspberry Pi.

1. The Raspberry Pi's ARM processor can only execute binary machine code, not human-readable assembly mnemonics.
2. The assembler translates each assembly instruction into its corresponding binary machine code, and resolves any symbolic labels to actual memory addresses.
3. The output is a fully executable binary file that can be loaded and run directly on the Raspberry Pi's processor.

> **Exam tip:** Always mention that 1 assembly instruction maps to 1 machine code instruction when describing assemblers — this is a common marking point.

## 2. Compilers: Function, Advantages and Disadvantages

**Compiler** — A translator that converts an entire high-level source code program into standalone executable machine code (or object code) in one full pass before execution. The original source code is not required to run the compiled output.

*Example:* A C compiler converts all `.c` source files into a standalone `.exe` executable that runs natively on Windows.

Compilers perform multiple stages of translation including lexical analysis, syntax checking, semantic analysis, code generation and optimization. The optimized executable can be distributed to end users who do not have the compiler installed.

**Worked example:** A developer wants to distribute a desktop app to 100,000 users who have no programming tools installed. Explain why a compiler is the right choice here.

1. Compilers produce standalone executable files that do not require the original source code or any programming tools to run on a user's device.
2. Compiled code runs directly on the processor, so it is much faster than code run via an interpreter.
3. Compilers can optimize the code during translation to produce a smaller, faster app, which improves the end user experience.

## 3. Interpreters: Function, Advantages and Comparison

**Interpreter** — A translator that reads and executes source code line-by-line during execution, rather than translating the entire program upfront. No standalone executable is produced, so the interpreter is required to run the program every time.

*Example:* Python and JavaScript are commonly run via interpreters during development and for web applications.

Interpreters stop execution as soon as they encounter an error on a line, which makes it easy to identify and fix issues quickly. No full retranslation is required after small changes, so this speeds up development and testing.

**Worked example:** A beginner programmer testing small Python snippets while learning uses an interpreter. Explain why this is suitable.

1. Interpreters allow code to be run immediately, with no upfront full compilation step after every change.
2. If an error exists in one line, the interpreter stops at that line, making it easy for the beginner to find and fix the mistake quickly.
3. No compilation wait time means the programmer can test ideas and learn much faster than with a compiled workflow.

| Feature | Compiler | Interpreter | Assembler |
| --- | --- | --- | --- |
| Translation timing | Full translation before execution | Line-by-line during execution | Full translation before execution |
| Output | Standalone executable | No standalone executable | Executable machine code |
| Execution speed | Fast | Slow | Very fast |
| Error reporting | All errors reported after translation | Stops at first error encountered | Errors reported after assembly |
| Primary use case | Distributed end-user applications | Development, teaching, scripting | Low-level system programming |

## Common pitfalls

- **Wrong:** Claiming interpreters translate all source code to machine code upfront before execution.
  - Why it fails: This confuses compilers and interpreters. Upfront full translation is the defining feature of a compiler.
  - Correct: State that interpreters translate and execute source code one line at a time during execution, with no upfront full translation.
- **Wrong:** Claiming assemblers translate high-level language to machine code.
  - Why it fails: Assemblers only translate low-level assembly language, not high-level source code.
  - Correct: State that assemblers convert low-level assembly language to processor-specific machine code, with one assembly instruction mapping to one machine code instruction.
- **Wrong:** Claiming all compiled code is tied to a single processor architecture.
  - Why it fails: This is only true for natively compiled machine code. Compiled intermediate bytecode (like Java bytecode) can run on any architecture with a suitable runtime.
  - Correct: Specify that natively compiled machine code is architecture-specific, while compiled intermediate code is cross-platform.
- **Wrong:** Confusing assembler output with compiler output.
  - Why it fails: Both produce machine code, but they take different types of input, which is the key distinction examiners look for.
  - Correct: Always state the input type for each translator: assembler → assembly language, compiler → high-level source code.

## Cheatsheet

| Translator | Input | Key Feature | Common Use Case |
| --- | --- | --- | --- |
| Assembler | Low-level assembly language | 1 instruction → 1 machine code, translated upfront | Low-level firmware, driver development |
| Compiler | High-level source code | Full translation upfront, standalone output | Distribution of end-user applications |
| Interpreter | High-level source/bytecode | Line-by-line translation during execution | Development, teaching, scripting |

## What's next

Understanding translators is a core foundation for all advanced topics in system software and software development for CIE 9618. This knowledge will help you when learning about the individual stages of compilation, how linkers and loaders prepare code for execution, and how software is built for different platforms. You will also rely on these distinctions when answering questions about programming language classifications and system architecture in both Paper 1 and practical assessments.

- [Linkers and Loaders](https://www.owlsprep.com/study/cie-9618-u5-linkers-and-loaders/)
- [Virtual Memory](https://www.owlsprep.com/study/cie-9618-u5-virtual-memory/)
- [File management](https://www.owlsprep.com/study/cie-9618-u5-file-management/)

---

From [OwlsPrep](https://www.owlsprep.com) — free study guides for A-Level, IB, AP and IGCSE, written against the official syllabus. Canonical page: https://www.owlsprep.com/study/cie-9618-u5-compilers-interpreters-and-assemblers/
