AQA 7517, section 4.6.2.1
Programming languages have developed over time, from languages close to the hardware to ones close to human thinking. They are classified as low-level or high-level.
Development of languages
- Machine code: the first computers were programmed directly in binary.
- Assembly language: mnemonics replaced the binary, making programs easier to write.
- High-level languages: languages such as FORTRAN, COBOL, C, Python and Java let people write in a form close to English and maths.
Each step moved further from the hardware and closer to the programmer.
Low-level languages
Low-level languages are close to the hardware, and are specific to a type of processor. There are two.
Machine code
Machine code is the language the processor executes directly. Each instruction is a binary pattern (an opcode and operands) that the processor's circuits understand.
00010101 00000101 (an example: load the value 5)
- It is the only language the processor understands, so all other languages must be translated into it.
- It is specific to a particular processor (an instruction set).
- It is very hard for humans to read and write.
Assembly language
Assembly language uses mnemonics (short, memorable codes) instead of binary patterns, and labels for addresses.
LDA 5 ; load the number 5 into the accumulator
ADD 3 ; add 3
STA total ; store the result in the memory location called total
HLT ; halt
- There is generally a one-to-one relationship: one assembly instruction becomes one machine code instruction.
- It is still specific to a processor.
- It is translated into machine code by an assembler.
High-level languages
High-level languages are designed to be close to human language and independent of the hardware. They hide the details of registers and memory addresses.
Imperative high-level languages, such as Python, C, Java and Pascal, are the ones in the specification. An imperative language is made of statements that tell the computer what to do, step by step, changing the state (the values in variables) as they run. The statements are executed in sequence, with selection and iteration.
total = 0
for n in range(1, 6):
total = total + n
print(total) # 15
Relationship to low-level languages
Imperative languages are modelled on how the hardware works. A processor follows a sequence of instructions that change the contents of memory and registers, and in the same way an imperative program is a sequence of statements that change the values of variables. One high-level statement is translated into many machine code instructions. A compiler or interpreter does the translating (4.6.3.1).
High-level: total = a + b
Assembly: LDA a
ADD b
STA total
Machine code: 00010001 ... (binary for each instruction)
Comparing the levels
| Machine code | Assembly language | High-level language | |
|---|---|---|---|
| Form | Binary | Mnemonics | Close to English and maths |
| Readability | Very poor | Poor | Good |
| Ease of writing | Very hard | Hard | Easier |
| Translation | None needed | Assembler | Compiler or interpreter |
| Portable between processors? | No | No | Yes (mostly) |
| Instructions per statement | 1 | 1 | Many |
| Control of hardware | Complete | Almost complete | Limited |
| Speed and size of the result | Fastest and smallest, if written well | Very fast and small | Usually slower and larger |
Advantages of low-level (machine code and assembly)
- Direct control over the hardware, memory and registers.
- Programs can be very fast and use little memory, because the programmer chooses every instruction.
- Useful for device drivers, embedded systems and parts of operating systems where speed or hardware access matters.
Disadvantages of low-level
- Hard to write, read and debug, and programs are long.
- Not portable: they work on only one type of processor, and have to be rewritten for another.
- Slow to develop and more likely to contain mistakes.
Advantages of high-level
- Easier and quicker to write, read, test and maintain.
- Portable: the same program can run on different processors with a suitable translator.
- Provides built-in features such as data structures and libraries.
Disadvantages of high-level
- Less control over the hardware.
- The translated code may be less efficient (slower and larger) than expert hand-written assembly.
- Needs a translator, and more memory to run.
Worked example
Task: a company is writing (a) the firmware for a tiny sensor with very little memory, and (b) a payroll program. Suggest a type of language for each.
- (a) Assembly language (or a low-level style), because every byte of memory and every clock cycle matters, and direct control of the hardware is needed.
- (b) A high-level language, because it is quicker and easier to write and maintain, the program is long and complex, and it needs to run on different computers.
Exam tip: don't just say "low-level is harder". Compare in terms of readability, portability, speed and control of hardware, and link the choice to the situation in the question.
Check yourself
What are the two types of low-level language?
Machine code and assembly language.
What does it mean to say assembly language has a one-to-one relationship with machine code?
Each assembly language instruction is translated into exactly one machine code instruction.
Give one advantage and one disadvantage of a high-level language compared with assembly language
Advantage: it is easier and quicker to write, read and debug, and is portable. Disadvantage: less control over the hardware, and the translated code is often slower or larger.
What is an imperative high-level language?
A language made of statements that are executed step by step to change the state of the program (variable values). Examples are Python, C and Java.