Assembly language is a symbolic, human‑readable form of a computer’s machine instructions.
The CPU can only execute machine code (binary op‑codes), so an assembler must translate the mnemonics into the binary format required by the target architecture.
MOV, ADD and symbolic labels replace long strings of 0s and 1s.FETCH: MAR ← PC ; address of next instruction
MDR ← Memory[MAR]
IR ← MDR
PC ← PC + 1
DECODE: Decode IR to determine opcode and operands
EXECUTE: Perform the operation (ALU, memory access, branch, etc.)
When an interrupt occurs the CPU saves the current PC and status, jumps to a fixed interrupt‑service‑routine (ISR) address, and executes the ISR code. Assemblers must be able to generate ISR entry/exit code and allow the programmer to define interrupt vectors.
Most A‑Level assemblers operate in two passes. The flow‑chart (see figure at the end) summarises the stages.
Source (first pass)
0010: START: LDM #5
0012: ADD ONE
0014: STA RESULT
0016: HLT
0018: ONE: DB 0x01
0019: RESULT: DB 0x00
After Pass 1 the assembler has built the following table:
| Label | Address (hex) |
|---|---|
| START | 10 |
| ONE | 18 |
| RESULT | 19 |
During Pass 2 the forward‑referenced labels ONE and RESULT are replaced by the addresses 18h and 19h respectively.
| Feature | One‑Pass Assembler | Two‑Pass Assembler |
|---|---|---|
| Symbol handling | Labels must be defined before they are used (no forward references). | Labels may be forward‑referenced; the first pass records them. |
| Complexity & speed | Simpler and faster, but limited in capability. | More complex, requires two scans, but supports full language features. |
| Macro support | Rarely included. | Common; directives such as MACRO … ENDM expand reusable code blocks before Pass 2. |
Macros allow a programmer to define a short name for a frequently used sequence of instructions.
MACRO INCX
LDA X
ADD #1
STA X
ENDM
; later in the program
INCX ; expands to the three instructions above
During the macro‑expansion phase the assembler replaces each macro call with its body, then proceeds with the normal two‑pass assembly.
The syllabus expects recognition of the four basic modes. The table uses a hypothetical 8‑bit processor.
| Mode | Description | Example (mnemonic operand) |
|---|---|---|
| Immediate | Operand is a constant encoded directly in the instruction. | LDA #5 |
| Direct | Operand is a memory address that contains the data. | LDA VALUE |
| Indirect | Operand is a memory address that holds the address of the data. | LDA @PTR |
| Indexed | Effective address = base address + contents of an index register (e.g., X). | LDA ARRAY,X |
| Opcode (hex) | Mnemonic | Operand type | Operation |
|---|---|---|---|
| 01 | LDM | Immediate | Load accumulator with a constant. |
| 02 | LDD | Direct | Load accumulator from a memory address. |
| 03 | ADD | Direct/Immediate | Add operand to accumulator. |
| 04 | SUB | Direct/Immediate | Subtract operand from accumulator. |
| 05 | STA | Direct | Store accumulator to a memory address. |
| 06 | JMP | Direct | Unconditional jump to address. |
| 07 | CMP | Direct/Immediate | Compare operand with accumulator (sets status flags). |
| FF | HLT | None | Halt the processor. |
START: LDM #5 ; Load accumulator with decimal 5
ADD ONE ; Add constant ONE
STA RESULT ; Store the sum
HLT ; Stop execution
ONE: DB 0x01 ; constant ONE = 1 (hex)
RESULT: DB 0x00 ; reserve a byte for the result
After the two passes the object file (shown as hexadecimal bytes) might look like:
00: 01 05 ; LDM #5 (opcode 01, immediate 05h)
02: 03 18 ; ADD ONE (opcode 03, address of ONE = 18h)
04: 05 19 ; STA RESULT (opcode 05, address of RESULT = 19h)
06: FF ; HLT
18: 01 ; ONE = 0x01
19: 00 ; RESULT (initialised to 0)
The assembler resolved the symbolic labels ONE and RESULT to actual memory addresses (18h and 19h) during Pass 2.
Assemblers report errors during both passes. Two common examples are:
Error: label LOOP not defined. – occurs when a label is referenced but never declared.Error: immediate value out of range for opcode LDM. – occurs when a constant does not fit the operand field.Most assemblers display the line number and a short description, allowing the programmer to correct the source before execution.
| Translator | Typical Input Language | Output | Key Advantages | Key Disadvantages |
|---|---|---|---|---|
| Assembler | Assembly language (mnemonics + directives) | Object code (machine code + relocation info) | Very close to hardware → fine‑grained control; fast execution; easy to generate interrupt‑service routines. | Programmer must manage registers, memory layout and low‑level details. |
| Compiler | High‑level language (e.g., C, Java) | Object code (or byte‑code for languages like Java) | Abstraction → faster development, portability, automatic optimisation. | Less direct control of hardware; compilation can be time‑consuming. |
| Interpreter | Scripting language (e.g., Python) or byte‑code (Java VM) | Direct execution by an interpreter or virtual machine | Immediate feedback, platform independence, easy debugging. | Generally slower execution; runtime errors may appear later. |
Understanding the role of each translator helps students appreciate why assembly language is still taught at A‑Level despite the prevalence of high‑level languages.
| AO | What is assessed in this topic |
|---|---|
| AO1 | Knowledge of the purpose of an assembler, the two‑pass process, macro directives, CPU registers, fetch‑execute cycle, and basic addressing modes. |
| AO2 | Analysis of how assembly language is converted into machine code: symbol‑table construction, forward‑reference resolution, opcode generation, relocation, and comparison with compilers/interpreters. |
Your generous donation helps us continue providing free Cambridge IGCSE & A-Level resources, past papers, syllabus notes, revision questions, and high-quality online tutoring to students across Kenya.