Programming languages and translators
IGCSE Computer Science · Software
High-level and low-level languages
| high-level | close to human language; one statement does a lot; portable between different processors |
| low-level | close to the machine; assembly language uses mnemonics like $\text{LDA}$ and $\text{ADD}$; machine code is pure binary |
High-level languages are easier and faster to write, easier to read and debug, and the same program runs on different machines after re-translation.
Low-level languages give direct control of the hardware and can produce faster, smaller code — but they are hard to write, easy to get wrong, and specific to one processor, so the program will not run on a different type of machine.
Note that high-level is not simply better. It is the right choice for almost all programs, but device drivers and embedded systems still use low-level code where every byte and every cycle matters.
Assembly language and the assembler
Assembly language replaces binary instructions with short mnemonics, so $\text{ADD}$ is far easier to read than a string of bits. Each mnemonic corresponds to one machine-code instruction.
An assembler translates assembly language into machine code.
Compiler and interpreter
Both translate high-level code into machine code, but they work completely differently.
| compiler | interpreter | |
| how it translates | the whole program at once | one line at a time, executing each as it goes |
| output | produces an executable file | produces no file — it must run every time |
| errors | reports all errors together at the end | stops at the first error it meets |
| speed of running | faster — already translated | slower — translating while running |
| source code | user does not need it | user needs it and the interpreter |
The consequence the exam asks about: an interpreter is better for developing and debugging, because it stops exactly at the offending line so the programmer sees immediately where the problem is. A compiler is better for the finished program, because it runs faster and the source code stays private.
Note what "stops at the first error" really means: the interpreter finds errors one at a time, so a program with ten errors must be run ten times. The compiler lists all ten at once — but gives nothing runnable until they are all fixed.
Integrated Development Environments
An IDE brings the tools a programmer needs into one program:
- code editor with line numbering, colour-coded syntax highlighting and auto-completion;
- error diagnostics — underlining mistakes as you type and explaining them;
- a translator — compiler or interpreter, built in;
- a run-time environment to execute the program without leaving the IDE;
- debugging tools — breakpoints to pause execution, and variable watches to see values change.
The benefit is that writing, translating, running and fixing all happen in one place, which makes development far faster than using separate tools.
Worked example: choosing a compiler or an interpreter
A programmer is partway through writing a large program and will release it to customers when finished. State whether an interpreter or a compiler should be used at each stage, and explain.
Solution
Writing and debugging stage → use an INTERPRETER.
Reason one — see immediately where the error is. An interpreter translates and runs one line at a time, and it stops exactly at the line with the error. The programmer knows at once where the problem is without having to hunt for it.
Reason two — quickly test small sections. There is no need to translate the whole program again after changing a single word. Once edited it can be run straight away, so the edit – test – edit cycle is very fast.
Reason three — an unfinished program can be run. An interpreter runs as far as it gets, so the programmer can test the part already written even though the later part is not complete.
A drawback that is acceptable at this stage: the program runs more slowly, but during development run speed matters less than the speed of finding errors.
Release-to-customers stage → use a COMPILER.
Reason one — runs faster. The program has already been translated into machine code, so when the customer runs it, no time is spent translating.
Reason two — customers do not need the source code. The compiler produces an independent executable file. The customer simply receives that file and can run it straight away, without installing any translator.
Reason three — protects the source code. Because customers only receive the translated file, they cannot read the source code. This protects the programmer's effort and know-how.
With an interpreter it is the opposite: the customer must have both the source code and the interpreter in order to run it.
Conclusion. The two tools do not replace each other but serve two different stages: interpreting to write and fix, compiling to deliver.
In practice many programming environments provide both, for exactly this reason.
Worked example: when low-level languages are still needed
High-level languages are much easier to write. Explain why low-level languages are still used in some cases, and state the price paid.
Solution
Advantages of low-level languages.
Direct control of the hardware. A low-level language lets the programmer intervene directly in each register, each memory location and each pin of the processor.
Some jobs can only be done this way: writing device drivers, programming microcontrollers, or writing the core of an operating system.
Faster and more compact code. A high-level language's compiler produces machine code that is fairly good but not perfectly optimised. A skilled programmer writing assembly by hand can produce code that is faster and takes less memory.
This matters in embedded systems — washing machines, medical devices, sensors — where memory is only a few kilobytes and every byte counts.
The price paid.
Hard to write and error-prone. A task that a high-level language does in one line may need dozens of instructions in assembly. The program is much longer, so the chance of making mistakes is also much greater.
Hard to read and maintain. Assembly code is very hard for others to understand — or for the author themself after a few months. Later modifications are therefore expensive.
Not portable. This is the most serious limitation. A low-level language is tied to one specific type of processor. To run on a different type of machine it has to be rewritten almost from scratch.
A high-level language only needs to be recompiled with a different compiler to run.
Conclusion. A high-level language is not simply better — it is the right choice for almost every ordinary program.
A low-level language is only worth using where performance or control of the hardware matters more than development cost: device drivers, embedded systems, and speed-critical sections of code.