Low-level languages
low-level languageAlso known as low level language. This is a computer programming language which closely represents machine language. Low-level languages are more difficult to understand than high-level languages but they execute quicker. are languages that sit close to the computer's instruction set Collectively, the set of instructions a processor understands.. An instruction set is the set of instructions that the processor understands.
Two types of low-level language are:
- machine codeLow-level language that is directly understood by the CPU. It is represented by binary numbers.
- assembly languageA low-level programming language closely related to machine language. Also called assembly code.
Machine code
Machine code is the set of instructions that a CPU/processorCentral processing unit - the brain of the computer that processes program instructions. understands directly and can act upon. A programSequences of instructions for a computer. written in machine code would consist of only 0s and 1s - binaryA number system that contains two symbols, 0 and 1. Also known as base 2.. This is very difficult to write and debugThe process of finding and correcting programming errors. . Even a very simple program could have thousands of 0s and 1s in it.
Assembly language
Assembly language sits between machine code and high-level languageAlso known as high-level language. This is a computer programming language used to write programs. High-level languages need to be translated into machine code through a compiler, interpreter or assembler. in terms of ease of use. While high-level languages use statementThe smallest element of a programming language which expresses an action to be carried out. to form instructions, assembly language uses mnemonicShort text codes used for writing instructions in assembly code. - short abbreviations. Each mnemonic directly corresponds with a machine code instruction. Here are some examples of mnemonics:
| Mnemonic | Action |
| LDA | Loads a value from a memory address |
| STA | Stores a value in a memory address |
| ADD | Adds the value held in a memory address to the value held in the accumulator |
| SUB | Subtracts from the accumulator the value held in a memory address |
| MOV | Moves the contents of one memory address to another |
| Mnemonic | LDA |
|---|---|
| Action | Loads a value from a memory address |
| Mnemonic | STA |
|---|---|
| Action | Stores a value in a memory address |
| Mnemonic | ADD |
|---|---|
| Action | Adds the value held in a memory address to the value held in the accumulator |
| Mnemonic | SUB |
|---|---|
| Action | Subtracts from the accumulator the value held in a memory address |
| Mnemonic | MOV |
|---|---|
| Action | Moves the contents of one memory address to another |
In assembly language, programmers write programs as a series of mnemonics. Mnemonics are much easier to understand and debug than machine code, giving programmers a simpler way of directly controlling a computer.
Writing in mnemonics is easy for programmers because they are usually brief representations of the actual commands. They are quicker to write than binary, and it is easier to spot mistakes.
Little Man Computer (LMC) is a simulation of a very basic processor using Von Neumann architectureA description of the processing architecture that all CPUs use. John von Neumann invented the processor architecture which stores a program in memory as instructions and executes them sequentially using the ALU, control unit and registers. This is known as the stored program concept.. It uses an example of simple assembly language that contains a limited set of mnemonic instructions which can be used to program simple assembly programs. LMC is freely available on the internet for students to use.
Opcodes and operands
Many machine code and assembly instructions contain two parts:
- the opcodeOperation code. Specifies instructions that can executed by a CPU/processor in machine code, eg in an instruction like "move the value 3 to the memory address X", the opcode is move. - this is the actual instruction
- the operandData that is manipulated by the CPU/processor according to the given opcode, eg in the instruction ADD 3, the operand is 3. - this is a value that the instruction uses or manipulates
Consider this set of program instructions:
| Assembly language | Opcode | Operand | Instruction |
| INP | 1001 | 00000000 | Input a number |
| STR 6 | 0011 | 00000110 | Store it in address 06 |
| LDR A1 | 0101 | 10100001 | Load data from address A1 |
| ADD #10 | 0010 | 00001010 | Add the number 10 to the loaded address |
| Assembly language | INP |
|---|---|
| Opcode | 1001 |
| Operand | 00000000 |
| Instruction | Input a number |
| Assembly language | STR 6 |
|---|---|
| Opcode | 0011 |
| Operand | 00000110 |
| Instruction | Store it in address 06 |
| Assembly language | LDR A1 |
|---|---|
| Opcode | 0101 |
| Operand | 10100001 |
| Instruction | Load data from address A1 |
| Assembly language | ADD #10 |
|---|---|
| Opcode | 0010 |
| Operand | 00001010 |
| Instruction | Add the number 10 to the loaded address |
Both opcode and operand values are ultimately represented in binary. However, values may also be represented in hexadecimalA number system using 16 symbols from 0-9 and A-F, also known as base 16 and hex. when programming as this number system can represent larger values in fewer characters, for example, denaryThe number system most commonly used by people. It contains 10 unique digits 0 to 9. Also known as decimal or base 10. 250 is 11111010 in binary, but only FA in hexadecimal. Hexadecimal is therefore easier to read and understand by humans.
Compare high-level and low-level languages
Programming languages can be classified into high and low-level languages. High-level languages allow programmers to write in a language that is easier for them to understand than low-level languages. Low-level languages are closer to the computer’s instruction set.
Advantages of high-level languages
- It is easier for programmers to read, write and understand high-level languages.
- One instruction can represent many instructions of machine code.
- The high-level code is portable, so it will work on different machines and CPU/processorCentral processing unit - the brain of the computer that processes program instructions. .
- The programmer doesn’t need to know how the computer will store the data.
Disadvantages of high-level languages
- The code must be translated before it can be understood by the computer.
- The programmer can’t control how the CPU/processorCentral processing unit - the brain of the computer that processes program instructions. will interpret the code, so programs might be less efficient.
Advantages of low-level languages
- The code does not need to be translated for the computer to understand it.
- The program will be faster and more efficient.
- The programmer can control what the CPU will do and how its memory will be used.
Disadvantages of low-level languages
- It is very difficult to learn how to program in a low-level language.
- The code will only work on one type of machine or processor.
- The programmer needs to know how the CPU works.