High-level and low-level languages
The processor only understands machine code: binary instructions such as `10110000 01100001`.
A low-level language is close to machine code. It is written for one type of processor. Machine code and assembly language are low-level.
A high-level language is close to English and maths. Python, Java and Visual Basic are high-level. One line of high-level code becomes many machine code instructions.
?Why?High-level languages save programmers time and reduce mistakes. Low-level languages are used when every byte and every microsecond matters, for example in a washing machine's chip.
!Watch out"Low-level" does not mean "worse". It means "close to the hardware".
Assembly language and mnemonics
Assembly language is a low-level language. Each instruction matches one machine code instruction.
Instead of binary, it uses short codes called mnemonics. A mnemonic is a few letters that are easy to remember, such as `LDA` for "load" or `ADD` for "add".
Assembly lets the programmer work directly with memory addresses and the accumulator (ACC) register.
LDA 20 // copy the number at memory address 20 into the ACC
ADD 21 // add the number at address 21 to the ACC
STO 22 // store the ACC into address 22
END // stop
If address 20 holds 7 and address 21 holds 5:
after LDA 20 ACC = 7
after ADD 21 ACC = 12
after STO 22 address 22 holds 12
# The same job in one high-level line
c = a + b
?Why?Assembly is easier for humans than binary but still gives full control of the processor. That is why it is used for device drivers and small embedded systems.
!Watch outThe exact mnemonics change between processor types. In the exam, you will not need to learn a set; you need to know what a mnemonic is.
The assembler
The processor cannot run assembly language directly. It must be translated into machine code first.
An assembler is the translator for assembly language. It turns each mnemonic into its matching binary instruction.
Because one assembly line equals one machine code instruction, assembling is a simple one-to-one translation.
e.g.ExampleLDA 20 → assembler → 0001 0100 (made-up example code)
ADD 21 → assembler → 0011 0101
The binary values depend on the processor's instruction set.
?Why?Each processor has its own instruction set, so each needs its own assembler.
Translators for high-level languages: the compiler
A translator turns source code (the code a person writes) into machine code. There are three types: assembler, compiler and interpreter.
A compiler translates the whole program in one go, before it runs.
If there are errors, it lists all of them at the end in an error report. The program will not run until every error is fixed.
When there are no errors, it produces an executable file (for example a `.exe`). This file can run again and again without the compiler and without the source code.
e.g.ExampleA games studio finishes a game.
They compile it once into an executable.
Players download and run the executable.
Players never see the source code, and they do not need a compiler.
?Why?Translation happens once, so the finished program runs fast. Keeping the source code hidden also protects the company's work from being copied.
Translators for high-level languages: the interpreter
An interpreter translates and runs the program one line at a time.
It reads line 1, translates it and runs it. Then it moves to line 2, and so on.
When it meets an error, it stops at that line and reports it. The lines before the error have already run.
It does not create an executable file. The program must be translated again every time it runs, so the interpreter must be present every time.
e.g.ExampleA student runs a Python program with a typing mistake on line 3.
Lines 1 and 2 run and show their output.
At line 3, the interpreter stops with an error message naming line 3.
The student fixes it and runs again.
?Why?Stopping at the exact line makes it easy to find and fix mistakes. That is why interpreters are used mainly while a program is being developed.
Compiler or interpreter? Compare them
Try the translators toy. The same program has an error on line 3. Run it with the compiler, then with the interpreter. Notice which lines run before you see the error.
In the exam, give the point for both sides when you compare, for example "a compiler translates the whole program at once, whereas an interpreter translates one line at a time".
!Watch outA compiler does not "run" the program. It only translates it. The executable runs afterwards.
There is something to try for this step in the IGCSE library.
The IDE: a programmer's toolbox
An IDE (integrated development environment) is one program that holds all the tools for writing, translating and testing code. Examples are IDLE, Thonny, Visual Studio Code and PyCharm.
Cambridge lists seven features. Learn each one with what it does for the programmer.
e.g.ExampleTyping in Thonny:
You type `pri` and the IDE offers `print` (auto-completion).
You forget a closing bracket and the line is underlined in red (error diagnostics).
`print` shows in one colour and the text in quotes in another (prettyprint).
!Watch outAuto-completion and auto-correction are different. Auto-completion suggests what comes next. Auto-correction changes a mistake you already typed.