CIE AS & A Level Computer Science, section 4.2 (Assembly language)
Machine code
Machine code is the binary instructions that the processor can execute directly. It is hard for people to read and write.
Assembly language
Assembly language is a low-level language that uses mnemonics (short, memorable codes such as LDD, ADD, STO) instead of binary. Programs are easier to write and understand.
There is usually a one-to-one relationship: each assembly instruction translates into exactly one machine code instruction. Assembly language is specific to a particular processor.
Parts of an instruction
An instruction has an opcode and usually an operand.
Groups of instructions
Instructions are grouped by what they do:
| Group | Examples |
|---|---|
| Data movement | LDM, LDD, LDI, LDX, LDR, STO, MOV |
| Input and output | IN, OUT |
| Arithmetic operations | ADD, SUB, INC, DEC |
| Unconditional and conditional jumps | JMP, JPE, JPN |
| Compare instructions | CMP, CMI |
| Return control | END |
Labels
A label gives a name to a line (such as LOOP:) so a jump can refer to it by name instead of by address.
Why use assembly language?
- Direct control of the hardware, efficient code.
- Used for device drivers, embedded systems and parts of operating systems.
- Harder to write and maintain than high-level languages, and not portable between processors.
Common mistake: saying assembly language is "machine code". Assembly language uses mnemonics and must be translated by an assembler. Also, one assembly statement usually becomes one machine instruction, unlike a high-level language statement.
Exam tip: describe assembly language as low-level, using mnemonics, one-to-one with machine code, processor-specific. Identify the opcode and operand when given an instruction.
Check yourself
What is the difference between machine code and assembly language?
Machine code is binary that the processor executes directly; assembly language uses mnemonics and must be translated into machine code by an assembler.
In `ADD 300`, which part is the opcode?
ADD.
Why is assembly language not portable?
Each processor has its own instruction set, so the code works only on that type of processor.