Study Guide
Programming Languages and Translators
Why people write programs in high-level languages that the CPU cannot run directly: how high-level and low-level languages compare, what assembly language and an assembler are, how a compiler and an interpreter each translate and report errors, and what an IDE adds.
Lesson 3.10 Computer Systems
For: Cambridge IGCSE Computer Science learners
Stage: Think
A CPU that knows one language
A CPU can only carry out machine code: patterns of 0s and 1s from its own instruction set (Lesson 3). A school team (made up for this lesson) wants to write a computer game, with thousands of instructions.
Think it through
Would you want the team to write the whole game as 0s and 1s? Say what would be hard about it, and what you would want a programming language to be like instead.
- Hint 1: Imagine finding one mistake among thousands of lines of 0s and 1s.
- Hint 2: What would you want the instructions to look like, so that a person could read them?
Show what happens
A game written in binary would be extremely slow to write and nearly impossible to read or correct. People want a language of words and symbols that they can read and write, where one line can do a lot. The cost is that the CPU cannot run it as it is, so something has to translate it into machine code first.
Programming languages fall into two groups.
A high-level language is written in words and symbols close to human language, such as Python or Java, and one statement can stand for many machine-code instructions. The program is called source code until it is translated. A high-level language is independent of any one type of CPU: the same source code can be translated for different CPUs. That is called machine independence.
A low-level language is close to the instructions the CPU carries out, and so depends on the type of CPU it is written for. Machine code is the lowest level of all, and assembly language, met next, is the other low-level language.
Here is one calculation, adding the numbers held at two memory addresses of a made-up computer and keeping the result, written three ways:
Total ← First + Second // high-level (Cambridge pseudocode)
LOAD 4 // low-level: assembly language
ADD 5
STORE 6
0001 0100 // low-level: machine code
0010 0101
0100 0110One high-level line became three lower-level instructions, and the machine code is the only one of the three that the CPU can carry out without translation.
Stage: Predict
When would you choose each?
Two programs are needed. A phone game must run on both Android phones and iPhones. A tiny chip inside a heart-rate monitor has a very small memory, and its program must switch one particular pin on and off at exactly the right moment.
Think it through
Which kind of language would you choose for each program, and why?
- Hint 1: Which program has to run on different kinds of CPU?
- Hint 2: Which program has to control a particular pin on the chip directly?
Show what happens
For the phone game, a high-level language: the source code can be translated for different CPUs, and it is much quicker to write and correct. For the chip in the monitor, a low-level language may be better, because it can manipulate that particular pin and the small memory directly, and the chip is only ever one kind.
Your choices followed four trade-offs, and each one favours one kind of language. Test your understanding by deciding which kind of language each statement describes.
| Statement | High or low? |
|---|---|
| Easier to read and write, because it is closer to human language | |
| A program written in it only works on one type of CPU | |
| The same source code can be translated to run on different types of computer | |
| Can control particular registers and memory locations directly | |
| Mistakes are easier to find, because the code is readable | |
| Hard to read, and a long program is hard to correct | |
| One statement can stand for many machine-code instructions |
- High: readable, easier to debug, machine independent. Low: close to the hardware, can control it directly, tied to one CPU.
Show the completed table
| Statement | High or low? |
|---|---|
| Easier to read and write, because it is closer to human language | high |
| A program written in it only works on one type of CPU | low |
| The same source code can be translated to run on different types of computer | high |
| Can control particular registers and memory locations directly | low |
| Mistakes are easier to find, because the code is readable | high |
| Hard to read, and a long program is hard to correct | low |
| One statement can stand for many machine-code instructions | high |
Low-level does not mean worse or simpler: it means closer to the machine. It gives control over the hardware at the cost of being harder to write, to read and to correct, and of working on only one kind of CPU. And a high-level program is never run directly by the CPU: it always has to be translated into machine code first.
Apply it
Show the answer
Answer: C. Assembly or machine code, because it controls that hardware directly and the driver is for one card only.
Direct control of one kind of hardware favours a low-level language.
Stage: Discover
Words for the CPU’s instructions
Look back at the three versions of the calculation. A person finds the machine code 0001 0100 almost impossible to remember, but finds LOAD 4 easy.
Think it through
Without being told, what do you think the assembly instruction ADD 5 asks the CPU to do, and how could a program turn it into 0s and 1s?
- Hint 1: Remember the instructions of the fetch-decode-execute cycle in Lesson 2.
Show what happens
It asks the CPU to add the contents of address 5 to the value in the accumulator. To turn it into binary, a program could look up the word ADD in a table of instruction codes and write down the code, followed by the number 5 in binary.
Assembly language is a low-level language in which each machine-code instruction is written as a short word called a mnemonic, such as LOAD, ADD or STORE, followed by what it uses. A mnemonic is easier to remember than a pattern of bits. Each assembly instruction is turned into exactly one machine-code instruction.
The CPU cannot carry out mnemonics, so a program called an assembler translates an assembly language program into machine code. An assembler is one kind of translator, a program that converts code written in one language into machine code.
In the made-up computer used here, each instruction is 8 bits: a 4-bit instruction code, then a 4-bit number.
| Mnemonic | Instruction code |
|---|---|
| LOAD | 0001 |
| ADD | 0010 |
| SUB | 0011 |
| STORE | 0100 |
Do the assembler’s job: use the table to translate each instruction, working from the mnemonic to the code and from the number to 4 bits.
| Assembly language | Machine code |
|---|---|
| LOAD 5 | |
| ADD 6 | |
| SUB 3 | |
| STORE 7 | |
| 0001 0010 | |
| 0100 1000 |
- Look the mnemonic up in the table, then write the number in 4 bits.
Show the completed table
| Assembly language | Machine code |
|---|---|
| LOAD 5 | 0001 0101 |
| ADD 6 | 0010 0110 |
| SUB 3 | 0011 0011 |
| STORE 7 | 0100 0111 |
| LOAD 2 | 0001 0010 |
| STORE 8 | 0100 1000 |
Check your understanding
Show the answer
Answer: B. It turns each assembly language instruction into one machine-code instruction.
An assembler translates assembly language into machine code.
Stage: Predict
Two ways to translate
At a conference, a speaker talks in French to an audience that understands only English. There are two ways to translate. An interpreter stands beside the speaker and says each sentence in English straight after it is spoken. A translator takes the whole written speech away, translates all of it, and hands back a finished English copy.
Think it through
Compare the two ways. Which one starts sooner? What happens if there is a sentence that cannot be translated? And what is it like if the speech is to be given again?
- Hint 1: Which method does nothing until the speech is finished?
- Hint 2: Which method gives you something you can use again without the person?
Show what happens
The beside-the-speaker method starts at once, but if it meets a sentence it cannot translate it stops there, after the earlier sentences have been translated, and the translator must be there each time the speech is given. The take-it-away method makes the audience wait, but it finds every problem in the whole speech, and then leaves a finished copy that can be used again and again without the translator.
These two ways are how high-level programs are translated.
A compiler translates the whole source code at once, before any of it runs, and produces an executable file of machine code. If it finds errors, it gives an error report for the whole code. Running the program means running the executable: the compiler does not run it.
An interpreter translates and executes the code line by line: it translates one line, carries it out, then moves to the next. It produces no executable file. When it finds an error it stops and reports it.
The same short program shows the difference. Its third line has a mistake: the statement is unfinished.
OUTPUT "Start"
Total ← 5 + 3
OUTPUT Total +
OUTPUT "End"A compiler looks at the whole program before anything runs.
Compiler
Step 1 of 4: The whole source code is read
The compiler reads all four lines before running anything.
Compiler
Step 2 of 4: The mistake is found
It finds the unfinished statement on line 3.
Compiler
Step 3 of 4: An error report is given
The compiler reports every error it found in the whole code (here only one, on line 3) and produces no executable file.
Programmer
Step 4 of 4: Nothing has run
The word Start was never displayed. The programmer corrects the code and compiles it again; only then is an executable produced, which runs as often as needed.
An interpreter translates and runs one line at a time, so it does some of the work before it reaches the mistake.
Interpreter
Step 1 of 4: Line 1 is translated and run
The word Start is displayed on the screen.
Interpreter
Step 2 of 4: Line 2 is translated and run
Total is set to 8.
Interpreter
Step 3 of 4: Line 3 has the mistake
The interpreter cannot translate the unfinished statement, so it stops and reports the error.
Programmer
Step 4 of 4: Line 4 was never reached
The program stopped on line 3, so “End” was not displayed. The programmer corrects line 3 and runs the program again, with the interpreter translating it again.
A compiler does not run a program: it only translates it. The program runs afterwards, as the executable file, and no compiler is needed for that. An interpreter is different, because it translates the code every time the program is run.
Stage: Explain
Which translator would you choose?
| Statement | Compiler or interpreter? |
|---|---|
| Translates the whole program before any of it runs | |
| Stops at the first error and has already run the lines before it | |
| Produces an executable file that runs without the translator | |
| The translator must be present every time the program runs | |
| Gives a report of all the errors it found in the code | |
| A few lines can be tested straight away, with no waiting for the whole program | |
| The finished program usually runs faster, because it is already machine code |
- Compiler: whole code, executable file, error report. Interpreter: line by line, stops at the first error, needed every run.
Show the completed table
| Statement | Compiler or interpreter? |
|---|---|
| Translates the whole program before any of it runs | compiler |
| Stops at the first error and has already run the lines before it | interpreter |
| Produces an executable file that runs without the translator | compiler |
| The translator must be present every time the program runs | interpreter |
| Gives a report of all the errors it found in the code | compiler |
| A few lines can be tested straight away, with no waiting for the whole program | interpreter |
| The finished program usually runs faster, because it is already machine code | compiler |
Do not confuse: Compiler and interpreter
- StrengthsCompiler
- The executable runs quickly and without the translator, and can be shared without giving away the source code.A finished game sold to customers.
- WeaknessesCompiler
- The whole program must be translated before any of it can be tried, and a long list of errors can be hard to work through. The executable suits one type of CPU.Waiting for a large program to compile after each small change.
- StrengthsInterpreter
- Part of a program can be run and tested straight away, and it stops at the line with the error, which helps to find it.A pupil trying out a new program line by line.
- WeaknessesInterpreter
- It is slower to run, because it translates as it goes, and the interpreter and the source code are both needed each time. Errors in later lines are not found until they are reached.Running a long program that is already finished.
Stage: Apply
Development and the final program
A pupil is writing a program to organise a school quiz. While writing it, the pupil often changes a few lines and wants to try them. When it is finished, the school wants to give copies to ten other schools. Which translator suits each stage?
- Name what the stage needs. During development, the pupil needs to test small changes at once, and to find the line where something goes wrong.
- Match the translator. An interpreter runs the code line by line, so a change can be tried straight away, and it stops at the line with the error. So an interpreter suits development.
- Name what the final stage needs. The finished program must run quickly for other people, who should not need the translator or the source code.
- Match the translator. A compiler produces an executable file that runs without the translator, and it can be given to others without the source code. So a compiler suits the final program.
That is why an interpreter is mostly used when a program is being developed, and a compiler for the final program.
Apply it
Show the answer
Answer: C. An interpreter, because it runs line by line and stops at the line with the error.
For developing and testing, an interpreter.
Apply it
Show the answer
Answer: A. The executable file runs without the compiler or the source code, and the program runs quickly.
For the final program: an executable, run without the source code.
Apply it
Show the answer
Answer: C. It describes an interpreter: a compiler translates all of it first, reports errors, and does not run.
Running up to the error is interpreter behaviour.
Stage: Discover
Tools for writing code
A pupil writes a program in a plain text editor. The pupil saves the file, opens a separate translator, runs it, reads a list of errors that give only line numbers, and goes back to the editor to find each one.
Think it through
What could be done to make this whole process faster and less error-prone for the pupil? Suggest two things a better tool could do.
- Hint 1: What could the editor do while the pupil is typing?
- Hint 2: What could be built in, so that the pupil does not need separate programs?
Show what happens
For example: colour or highlight the code so that mistakes are easier to spot; suggest the rest of a word as the pupil types; put the translator and the output in the same place as the editor; and point to the line with an error and say what is wrong. These ideas are what an IDE offers.
An integrated development environment (IDE) brings the tools for writing, translating, running and correcting code into one program. Its common functions are:
- Code editor: a text editor made for code, with features such as line numbers and colours for the different kinds of word.
- Run-time environment: a place to run the program and see what it does, often with tools to help find faults, such as running it a line at a time.
- Translators: a built-in compiler or interpreter, so the code can be translated and run at the press of a button.
- Error diagnostics: finding mistakes in the code, and showing where they are and what is wrong.
- Auto-completion: suggesting the rest of a keyword or a variable name while it is being typed, so it is quicker to type and has fewer typing mistakes.
- Auto-correction: fixing, or offering to fix, small mistakes automatically, such as a missing closing bracket.
- Prettyprint: laying the code out neatly, with colour for keywords and indentation that shows its structure, so it is easier to read. Compare:
FOR Index ← 1 TO 3
OUTPUT Index
NEXT Index
FOR Index ← 1 TO 3
OUTPUT Index
NEXT Index| Description | IDE function |
|---|---|
| The IDE draws a red line under line 12 and says that a bracket is missing | |
| The pupil types “pri” and the IDE offers to finish the word as print | |
| The code is indented and coloured so that its structure is easy to see | |
| The IDE adds the missing closing bracket for the pupil | |
| A Run button starts the program and its output appears in a panel | |
| The code is turned into machine code without leaving the IDE |
- Each function has a different job: write, run, translate, find errors, suggest, fix, or lay out neatly.
Show the completed table
| Description | IDE function |
|---|---|
| The IDE draws a red line under line 12 and says that a bracket is missing | diagnostics |
| The pupil types “pri” and the IDE offers to finish the word as print | completion |
| The code is indented and coloured so that its structure is easy to see | prettyprint |
| The IDE adds the missing closing bracket for the pupil | correction |
| A Run button starts the program and its output appears in a panel | run-time |
| The code is turned into machine code without leaving the IDE | translator |
Apply it
Show the answer
Answer: A. An IDE is a program for writing and running code; it contains a translator and other tools such as an editor.
An IDE contains a translator, but does more.
Stage: Consolidate
Show what you know
Think it through
A pupil has written a program in a high-level language and wants other people to be able to run it. Explain the route from the source code to the CPU carrying it out, for a compiler and for an interpreter, and say which you would use for the final program.
Show a model answer
A good answer covers both and chooses. For example: “The source code is in a high-level language, which the CPU cannot run. A compiler translates the whole of it into machine code before it runs, as an executable file, which is then run by the CPU, with an error report if there are mistakes. An interpreter translates and runs it one line at a time, and stops at an error, so it has to be there every time. For the final program I would compile it, so that other people receive a fast executable and do not need the translator or the source code. An interpreter is better while I am still writing and testing.”
Check your understanding
Show the answer
Answer: C. An assembler translates assembly language into machine code.
Assembler: assembly language to machine code.
- The CPU can only carry out machine code. Anything else has to be translated.
- A high-level language is readable, easier to write and debug, and independent of the CPU. A low-level language (assembly language and machine code) is tied to one type of CPU and hard to read, but can control the hardware directly.
- Assembly language writes each instruction as a mnemonic, such as LOAD. An assembler translates it into machine code.
- A compiler translates the whole program before it runs, producing an executable file and reporting all the errors it finds. An interpreter translates and runs it line by line and stops at the first error.
- An interpreter is mostly used while developing a program; a compiler is used for the final program.
- An IDE brings the tools together: code editor, run-time environment, translators, error diagnostics, auto-completion, auto-correction and prettyprint.
Sources and scope
- What this lesson is. The tenth lesson of the Computer Systems module, written for this site. It teaches Cambridge IGCSE Computer Science (0478) point 4.2 (2026 to 2028, version 6): high-level and low-level languages, assembly language, compilers and interpreters, and IDEs. Its curriculum links are provisional and imply no endorsement by any examination board. It has not been approved by the site owner.
- Original material. The made-up computer with 8-bit instructions and its instruction codes, the four-line program with the unfinished statement, the quiz program and the people named are fictional and were written for this lesson. The programs are in Cambridge pseudocode, or in the made-up assembly language.
- Simplified on purpose. Real instruction sets are far larger and encode instructions in many different ways. Real compilers work in several stages, and many modern languages are translated to an intermediate form first and then run by a program that is both a compiler and an interpreter; the lesson keeps to the course’s two simple models. Real compilers report errors in different ways, and some also stop after a number of errors.
A register that holds the data the ALU is working on and the results of its calculations.
A program that translates an assembly language program into machine code.
A low-level language that writes each machine-code instruction as a short word called a mnemonic.
The number system with only two digits, 0 and 1, in which each column is worth twice the column to its right.
A single binary digit: 0 or 1. The smallest unit of data a computer stores.
A translator that converts the whole of a program into machine code before it runs, producing an executable file.
The part of a computer that carries out instructions: it fetches each instruction from memory, decodes it and executes it, processing data so that a result can be output.
A programming language written in words and symbols close to human language, which is independent of any one type of CPU and must be translated before it can run.
The list of all the machine-code commands that a particular CPU can process.
A program that brings together the tools for writing, translating, running and correcting code in one place.
A translator that converts a program one line at a time and carries out each line as soon as it is translated.
A programming language close to the instructions a CPU carries out, so that it depends on one type of CPU, such as assembly language and machine code.
Instructions written in binary, the only form of instruction that a CPU can carry out directly.
A short, memorable word used in assembly language in place of a binary instruction, such as LOAD or ADD.
A precise but language-independent way of writing an algorithm, with set keywords such as IF, WHILE and OUTPUT, that is not tied to any one programming language.
A high-level programming language written as text, popular for learning and for real work, in which indentation shows which lines belong together.
The program as the programmer wrote it, in a high-level or assembly language, before it is translated.
A program that converts code written in a programming language into machine code that a CPU can carry out.
Your progress on this lesson
Saved in this browser only. It is not sent anywhere, does not follow you to another device, and is lost if you clear this site’s data.
This browser is not allowing the site to save progress, so it will be forgotten when you leave the page.