Programming languages and translators

IGCSE Computer Science · Software

High-level and low-level languages

high-levelclose to human language; one statement does a lot; portable between different processors
low-levelclose 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.

compilerinterpreter
how it translatesthe whole program at onceone line at a time, executing each as it goes
outputproduces an executable fileproduces no file — it must run every time
errorsreports all errors together at the endstops at the first error it meets
speed of runningfaster — already translatedslower — translating while running
source codeuser does not need ituser 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:

The benefit is that writing, translating, running and fixing all happen in one place, which makes development far faster than using separate tools.

The deciding difference: reports ALL errors or stops at the FIRST error COMPILER — translates the WHOLE program at once source code (whole file) compile EXECUTABLE FILE runs fast, no source code needed reports ALL ERRORS at once at the end — but nothing can run until they are all fixed INTERPRETER — translates and runs LINE BY LINE line 1 → translate → run ✓ line 2 → translate → run ✓ line 3 → ERROR → STOP line 4 not reached yet ✓ see IMMEDIATELY which line has the error → good when DEBUGGING ✗ ten errors means running ten times
The two ways of reporting errors lead to two different uses: an interpreter suits the time of writing, a compiler suits the finished version handed to users.

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.

Common mistake

Saying an interpreter reports all of the errors to the programmer. The opposite is true: an interpreter stops at the first error it meets and goes no further, so it finds errors one at a time — a program with ten errors must be run ten times. It is the compiler that lists all errors at once, because it scans the whole program before producing the executable file. Do not confuse this with “compiling is more convenient”: in exchange, the compiler produces nothing runnable until every error has been fixed, whereas the interpreter runs the part that is correct and stops exactly at the problem line — that is why it is more convenient during development. The second trap: thinking high-level languages are always better. They are easy to write and portable, but the machine code produced by a compiler is not perfectly optimised. Device drivers and embedded systems still use low-level languages, because there every byte and every cycle counts.

Key takeaway

High-level languages are easy to write and portable; low-level languages give direct hardware control and more compact code but run on only one type of processor. A compiler translates the whole program at once, produces an executable file, reports all errors at once, runs fast and hides the source code. An interpreter translates line by line, stops at the first error, runs more slowly and requires the user to have the source code. Hence: interpret to develop, compile to deliver. An integrated development environment brings editing, translating, running and debugging together in one place.

← System software and the operating system · All IGCSE Computer Science lessons · Practice IGCSE Computer Science questions (free, instant scoring) · How the web works →