Programming languages exist on a spectrum from low-level (close to machine code) to high-level (close to human language). Each level requires a different type of translator.
10110000 01100001An assembler is a translator that converts assembly language (low-level) into machine code. It is a 1-to-1 translation — each assembly mnemonic maps to exactly one binary machine code instruction.
Assembly language is still used today for device drivers, embedded systems, and performance-critical code where direct hardware control is needed. However, it is very hard to write and maintain.
Some languages — particularly Java — use an intermediate approach. Rather than compiling directly to machine code or interpreting the source line-by-line, Java compiles to bytecode.
Bytecode is not machine code for any specific CPU. It is a compact, intermediate binary format designed to be run by a Virtual Machine (VM).
The Java Virtual Machine (JVM) is installed on each platform (Windows, macOS, Linux) and runs the same .class bytecode file. This is the basis of Java's famous "Write Once, Run Anywhere" principle.
Modern JVMs use Just-In-Time (JIT) compilation. The JVM identifies "hot" code paths (frequently executed sections) and compiles them to native machine code at runtime, caching the result. This combines the portability of interpretation with performance closer to compilation.
| Translator | Input | Output | Used for |
|---|---|---|---|
| Assembler | Assembly language | Machine code | Low-level/hardware programming |
| Compiler | High-level language | Executable/machine code | Fast production software (C, C++, C#) |
| Interpreter | High-level language | No file — runs directly | Scripting, education, rapid dev (Python) |
| JIT Compiler | Bytecode | Native machine code (cached) | Java, JavaScript (V8 engine), .NET |
| Advantage | Disadvantage |
|---|---|
| Direct hardware control — very efficient and fast | Very hard and time-consuming to write |
| Smaller executable size — no abstraction overhead | Hardware-specific — not portable between CPU types |
| Can access CPU registers and memory directly | No built-in error checking — bugs are hard to find |
| Used in embedded systems where resources are very limited | Requires deep knowledge of the specific CPU architecture |
8 questions · 19 marks
| Term | Definition |
|---|
Timed exam conditions.