| Mode (syllabus name) | Syllabus syntax | Common hardware name | Typical instruction (9618) | Typical use |
|---|---|---|---|---|
| Immediate | #n | Immediate | LDM R0, #n | Load a constant, set flags |
| Direct (absolute) | <address> | Direct | LDD R1, <addr> | Fixed variables, I/O ports |
| Register‑indirect | (R) | Register Indirect | LDD R2, (R3) | Pointer dereferencing, stack access |
| Indexed (base‑indexed) | <address>(R) | Indexed | LDX R4, <addr>(R5) | Array element access |
| Based‑indexed with displacement | <address>(R1+R2*scale+disp) | Based‑Indexed + Displacement | LDX R6, <addr>(R7+R8*4+8) | Structure fields, multi‑dimensional arrays |
| PC‑relative (branch) | label | Relative | BR label | Loops, conditional branches, function calls |
| Stack‑relative | PUSH / POP | Stack‑relative | PUSH R0 / POP R1 | Procedure call/return, local variables |
| Syllabus symbol | Meaning | Hardware mode | Example instruction |
|---|---|---|---|
#n | Literal constant n | Immediate | LDM R0, #5 |
<addr> | Absolute memory address | Direct | LDD R1, <0x3C00> |
(R) | Address stored in register R | Register‑indirect | LDD R2, (R3) |
<addr>(R) | Base address + contents of R (no scaling) | Indexed | LDX R4, <0x2000>(R5) |
<addr>(R1+R2*scale+disp) | Base + (index × scale) + displacement | Based‑Indexed + Displacement | LDX R6, <0x1000>(R7+R8*4+8) |
label | Signed offset from the current PC | PC‑relative | BR label |
PUSH / POP | Implicit use of the stack pointer (SP) | Stack‑relative | PUSH R0 / POP R1 |
The 9618 specification assumes a single accumulator register (ACC) for arithmetic results, but the instruction set also provides a small set of general‑purpose registers (R0‑R9) for address manipulation. All examples below respect the “one‑accumulator” rule for arithmetic, using the GP registers only for addressing.
CALL which is PC‑relative).Consider the following 5‑line source program:
;--- Source -------------------------------------------------
START: LDM R0, #10 ; load constant
LDD R1, (R2) ; load via pointer
BR END ; skip the next line
LDD R1, <VALUE> ; never executed
END: NOP
VALUE: .WORD 0x55AA
| Label | Address (hex) |
|---|---|
| START | 0x0000 |
| END | 0x0014 |
| VALUE | 0x0016 |
| Address | Machine code (binary) | Explanation |
|---|---|---|
| 0x0000 | 0010 0000 0000 1010 | LDM R0, #10 (opcode 0010, immediate 1010) |
| 0x0002 | 0101 0001 0010 0011 | LDD R1, (R2) (opcode 0101, reg 0010 = R2) |
| 0x0004 | 1000 0000 0000 1010 | BR END (offset +10 bytes = 0x000A) |
| 0x0006 | 0101 0001 0000 0110 | LDD R1, <VALUE> (direct address 0x0016) |
| 0x0008 | 0000 0000 0000 0000 | NOP |
| 0x0016 | 0101 0101 1010 1010 | Data word 0x55AA |
The symbol table from Pass 1 supplies the concrete address for END and VALUE during Pass 2, allowing the assembler to encode the correct offsets and absolute addresses.
For indexed and based‑indexed modes the general formula is:
EA = Base + (Index × Scale) + Displacement
Given int a[10]; at address 0x1000 and the index i in R1:
LDX R0, <0x1000>(R1*4) ; scale = 4 (size of int)
EA = 0x1000 + (i × 4). The element a[i] is loaded into R0.
struct Point { int x; int y; }; // offsets: x=0, y=4
; address of variable p is in R3
LDX R4, (R3+4) ; load p.y
Here Base = contents of R3, Index = 0, Scale = 1, Displacement = 4.
| Operation | Assembly mnemonic (9618) | Typical use |
|---|---|---|
| Logical left shift | LSL Rdst, Rsrc, #n | Multiply by 2ⁿ, move bits into higher positions. |
| Logical right shift | LSR Rdst, Rsrc, #n | Unsigned division by 2ⁿ, clear high bits. |
| Arithmetic right shift | ASR Rdst, Rsrc, #n | Signed division preserving sign bit. |
| Bitwise AND (masking) | AND Rdst, Rsrc, #mask | Extract specific bits. |
| Bitwise OR | ORR Rdst, Rsrc, #mask | Set specific bits. |
| Bitwise XOR | EOR Rdst, Rsrc, #mask | Toggle bits. |
| Test‑and‑set | TSB Rdst, Rsrc, #bit | Set a single bit and record previous value. |
| Clear‑bit | AND Rdst, Rsrc, #~bit | Force a bit to 0. |
Example – Extract the low 4 bits of a byte stored at address 0x3000:
LDD R0, <0x3000> ; load byte
AND R0, R0, #0x0F ; mask with 0000 1111
| Mode | Memory accesses per instruction | Typical cycle count (illustrative) |
|---|---|---|
| Immediate | 1 (instruction only) | 2‑3 cycles |
| Direct | 2 (instruction + operand fetch) | 3‑4 cycles |
| Register‑indirect / Indexed | 2 (instruction + EA‑derived fetch) | 3‑5 cycles (EA calculation) |
| Based‑indexed with displacement | 2 (plus internal arithmetic) | 4‑6 cycles |
| PC‑relative (branch) | 1 (offset encoded) | 2‑3 cycles (pipeline flush if taken) |
| Stack‑relative (PUSH/POP) | 2 (access SP and operand) | 3‑4 cycles |
When answering exam questions, always comment on the extra memory accesses or arithmetic steps introduced by the chosen mode.
Two equivalent code fragments are given. For each fragment state the total number of memory accesses and the estimated cycle count (use the table above).
Fragment A:
LDD R0, <ARRAY> ; load first element (direct)
LDX R1, <ARRAY>(R2*4) ; load ARRAY[i] (based‑indexed)
Fragment B:
LDD R0, (R3) ; R3 holds address of ARRAY[0] (register‑indirect)
ADD R4, R2, #4 ; R4 = i*4
ADD R4, R3, R4 ; R4 = base + offset
LDD R1, (R4) ; load ARRAY[i] via indirect
Answer (teacher guide)
;--- Data -------------------------------------------------
DATA1: .WORD 0x1234
DATA2: .WORD 0xABCD
ARRAY: .WORD 5, 10, 15, 20 ; base = 0x2000
;--- Registers before execution ----------------------------
R0 = 0x0000 ; result register
R1 = 0x0002 ; index = 2
R2 = <DATA1> ; 0x1000
R3 = <ARRAY> ; 0x2000
;--- Instructions -----------------------------------------
LDD R0, (R2) ; 1
LDX R0, <0x2000>(R1*2) ; 2
LDM R0, #0x55 ; 3
BR END ; 4
LDD R0, <DATA2> ; 5 (skipped)
END: NOP
Answer key
#n (Immediate).<addr>).(R)).<addr>(R)) with appropriate scale.(R+disp) or full form).label).PUSH / POP).#n, <address>, LDM, LDD, LDX) and map them to the correct hardware mode.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.