GCSE Computer Science topics
- Edexcel GCSE Computer Science: 4.5 Programming languages
- Cambridge / OCR Computer Science: 2.5 Translators and facilities of languages
- AQA GCSE Computer Science: 3.2.13 Classification of programming languages
Programming languages are divided into two general categories: low level languages and high level languages. The 'low' and 'high' refer to how 'distant' a language is from the hardware of a computer system. You can also think of this as how abstract a language is.
A high level language is relatively 'far' from the hardware, and has a greater number of abstract features (such as 'IF...THEN' statements and loops). This means high level languages are more English like.
In contrast, a low level language is 'closer' to the hardware, with fewer abstractions. Low level programming languages include instructions for directly manipulating the contents of CPU registers and memory addresses. These technical features are hidden by the abstraction of higher level languages.
For example, in a high level language a programmer might write the code 'IF grade == 90 THEN'. In a low level language, a programmer would need to break down the process into several steps: load the data for 'grade' into memory or a register. Load the data '90' into memory or a register. Compare the two pieces of data. Jump to the address of the appropriate instruction if the comparison showed they were they same. Optionally jump to the address of the appropriate instruction if the comparison showed they were
Low level languages feature fewer abstractions (such as 'IF' statements or loops) than higher level languages. In a low level programming language the programmer must deal with a larger number of technical concepts, such as memory addresses and registers. These technical features are hidden by the abstraction of higher level languages. For example, instead of using named variables common in higher level languages, programmers will need to instructions for manipulating data in registers and memory addresses, and manually keep track of where items of data are stored.
Low level programming languages are more closely 'tied' to hardware than high level languages. Low level languages have instructions specific to a certain make of CPU. This means programs written in low level languages are less portable - for example, an assembly language program written for an Intel x64 CPU will not run on an ARM CPU.
The two main examples of low level languages are machine code and assembly language.
Machine code is simply a binary representation of a CPU's instructions. Each instruction a CPU can 'understand' has its own binary representation. Since binary is the only thing a computer can process, all computer programs need to be translated into machine code before they can be run. To make it easier to read, machine code is often written in hexadecimal.
It is possible to write programs in machine code, but it is extremely difficult. Reading a machine code program (such as the one below) is extremely hard without a thorough understanding of the CPU's instruction set.
Assembly language uses short mnemonics ('opcodes') to represent each machine code instruction. For example, instead of the machine code instruction 8B (hexadecimal) or 10001011 (binary), assembly language might use the mnemonic 'MOV'. This makes assembly language significantly easier to read and write than machine code.
However, assembly language is still significantly harder to learn than a high level programming language. There are still no high level abstractions to aid the programmer. The assembly language example below shows the same program as the machine code above. Although it is slightly clearer than a collection of hexadecimal numbers, you still need a thorough understanding of the CPU's instruction set to understand the purpose of the program.
High level programming languages let programmers write code using 'English-like' statements. Although code might seem hard to understand to non-programmers, it is much clearer and easier to read than low level languages. Python, Java, Pascal, and C++ are examples of high level languages.
Advantages and disadvantages
The main advantage of high level programming languages is that code is easier to read, write, and debug. This reduces development and maintenance time, which should also reduce costs. Another key advantage is that high level languages tend to be more portable. For example, a Python program written on a PC should run and produce the same output using the Python environment on a Mac. This is possible because high level languages do not have features specific to one type of hardware. In contrast, an assembly language program written for one CPU type will not work on a different type of CPU.
A disadvantage of high level programming languages is that programs must be translated into machine code before execution. This is done using a translator (either a compiler or an interpreter). Translation takes time, so can slow down the execution of a program compared to one written in a low level language. In general, high level languages are also less memory efficient than low level languages.
Another potential drawback of high level languages is that they do not let the program control hardware directly. This type of control might be essential when connecting some types of external devices.
The only language a computer can 'understand' is binary (machine code). Humans can understand binary (sort of!) but we prefer to write programs in programming languages such as Python, Java, or C. This means we need a way of converting a program written in a language such as these into machine code.
Translators are programs to do this conversion. Translators convert a program written in a high level or low level language into machine code. Assemblers, interpreters, and compilers are all types of translator.
An assembler translates assembly language programs into machine code. An assembler is a type of translator.
An interpreter translates a high level language into machine code. The difference between an interpreter and a compiler is the way the translation is performed. An interpreter translates one line of code into machine code, executes that code, and then translates the next line of the program.
- Translate one line of code into machine code
- Execute this line of code
- Until the end of the program
A compiler translates a high level language into machine code. The difference between a compiler and an interpreter is the way the translation is performed. A compiler translates an entire program into machine code before executing any of the code.
- Translate each line of code into machine code
- Start the execution of the program
Use these resources to help you learn more about programming languages and translators.