What is a programming language? Compare machine, assembly and high-level languages.
5 marks
Answer in brief
A programming language is a set of words, symbols and rules used to write instructions for a computer.
Types of programming languages
Machine language: Instructions are written as machine codes, usually shown using 0s and 1s. The processor can execute the correct machine code directly. It is difficult for people to read and write.
Assembly language: Short names such as ADD are used instead of binary instructions. An assembler converts assembly code into machine code. The instructions depend on the processor.
High-level language: Instructions are written using readable words and expressions. Examples include C and Python. A suitable translator is needed before or during execution.
Example
To add two numbers in C, we can write total = a + b;. The compiler translates the C instructions for the selected computer. We do not need to write the processor’s binary instructions ourselves. The translated code may contain several machine instructions.
Advantages of high-level languages
Easy to read: Meaningful names and familiar expressions make programs easier to understand.
Easy to maintain: A programmer can find and change the required part more easily.
Better portability: The same source can often be used on different computers when suitable compilers and libraries are available.
Compiler and interpreter
A compiler translates a program into another form before the translated program runs. An interpreter carries out instructions through another program. These are ways of implementing a language. C programs are commonly compiled. A language and a compiler are different: C is a language, while GCC is one compiler that supports it.
Reference tables
↔ Scroll horizontally on a small screen
Levels of programming languages
Level
How instructions are written
Translation and use
Machine language
Encoded processor instructions, commonly represented as binary or hexadecimal
Executed by the matching processor; difficult for people to maintain.
Assembly language
Mnemonic instructions such as ADD, with symbolic labels
An assembler produces machine code for a particular architecture.
High-level language
Expressions, functions and control structures close to human reasoning
A compiler or interpreter implements the language. C source is commonly compiled.
↔ Scroll horizontally on a small screen
Translation methods
Method
Typical behaviour
What to remember
Compilation
Translates a source program into another representation before the resulting program runs.
C implementations commonly compile source to native code.
Interpretation
Executes a representation of the program through another program.
A language may have more than one implementation strategy.
Key points
Machine code is processor-specific.
An assembler translates assembly; a compiler can translate C.