| Translator | What it does | Typical output |
|---|---|---|
| Assembler | Converts symbolic assembly language (mnemonics) into machine code. | Object file containing binary instructions. |
| Compiler | Translates an entire high‑level program into a lower‑level language (usually assembly or machine code) before execution. | Executable binary (or a set of object files that are later linked). |
| Interpreter | Translates and executes statements one at a time at run‑time. | No permanent binary; the interpreter program performs the translation each time. |
| Mixed‑mode (e.g., Java, C#) | Source is first compiled to an intermediate “byte‑code”. The byte‑code is then interpreted or JIT‑compiled to native machine code at run‑time. | Byte‑code files (.class, .dll) plus a virtual machine/JIT compiler. |
| Aspect | Compilation | Interpretation |
|---|---|---|
| When translation occurs | Before execution (offline) | During execution (online) |
| Execution speed | Generally faster – native code runs directly on the CPU. | Slower – each statement must be parsed and executed each time. |
| Error detection | Many errors caught at compile‑time (syntax, type, undeclared identifiers). | Errors may appear only at run‑time (e.g., division by zero). |
| Portability of output | Binaries are platform‑specific; source remains portable. | Source is portable if an interpreter exists for the target platform. |
| Build time | Longer initial build (compilation, linking). | Shorter start‑up; translation happens continuously. |
| Typical use‑cases | System software, performance‑critical applications, embedded devices. | Scripting, rapid prototyping, teaching environments. |
Suggested diagram: <img src="compiler-phases.png" alt="Compiler phases flow‑chart">
For a 32‑bit RISC processor, the assembly instruction ADD R1, R2, R3 might be encoded as:
0100 0010 0011 0001 0000 0000 0000 0000 │ │ │ │ │ │ │ │ │ │ └─ Unused bits (padding) │ │ │ └─ Destination register R1 (0010) │ │ └─ Source register R2 (0011) │ └─ Source register R3 (0001) └─ Opcode for ADD (0100)
This 32‑bit word is what the CPU fetches and executes.
// Before optimisation int a = 5; int b = 10; // b is never used int c = a + 2; print(c);
After optimisation the assignment to b is removed.
// Before optimisation (n = 4)
for (int i = 0; i < 4; i++) {
sum += a[i];
}
After unrolling the loop (four iterations are expanded):
sum += a[0]; sum += a[1]; sum += a[2]; sum += a[3];
Unrolling reduces loop‑control overhead at the cost of a larger code size.
missing ';' before '}'cannot assign String to int'x' was not declared in this scopeCompilers reduce the frequency of run‑time failures, but they cannot eliminate errors that depend on dynamic data.
Although an IDE is not a translator, it forms part of the “language‑toolchain” described in the syllabus. Three core IDE features are:
Examples: Eclipse (Java), Visual Studio Code (multiple languages), PyCharm (Python).
javac translates .java files into platform‑independent .class files.This hybrid approach gives the portability of interpretation together with the speed of compilation for “hot spots”.
| Syllabus Item | Covered? | Notes / Action |
|---|---|---|
| Purpose of a compiler (human‑ vs. machine‑readability, portability, performance, safety, distribution) | ✔ | |
| Types of translators (assembler, compiler, interpreter, mixed‑mode) | ✔ | |
| Compilation vs. interpretation comparison | ✔ | |
| Standard compiler phases (lexical → linking) | ✔ | |
| Optimisation techniques (dead‑code elimination, loop unrolling) | ✔ | |
| Compile‑time and run‑time error handling | ✔ | |
| Target‑specific concerns (ISA, endianness, register allocation, calling conventions) | ✔ | |
| IDE support (syntax checking, code completion, debugging) | ✔ | |
| Mixed‑mode translation (Java/C# byte‑code + JIT) | ✔ | |
| Assessment objectives (AO1‑AO3) linkage | ✔ |
A compiler is the essential bridge that converts human‑readable high‑level programs into the binary instructions a computer can execute. It provides speed, static error checking, and the ability to generate platform‑specific binaries while supporting source‑level portability. Understanding the full translation chain—including assemblers, interpreters, IDE support, and mixed‑mode approaches—enables students to meet the full range of requirements in the Cambridge AS/A‑Level Computer Science (9618) syllabus.
Create an account or Login to take a Quiz
Log in to suggest improvements to this note.
Your generous donation helps us continue providing free Cambridge IGCSE & A-Level resources, past papers, syllabus notes, revision questions, and high-quality online tutoring to students across Kenya.