Demonstrate an understanding of how assembly‑language instructions are organised into logical groups (segments, blocks, sub‑routines and macros), how these groups relate to machine code, and how the assembler translates the source into an executable program.
Mnemonic: ADD R1, R2, R3
Opcode: 0001 01 001 010 011
│ │ │ │ └─ R3 (destination)
│ │ │ └──── R2 (source)
│ │ └────── R1 (source)
│ └────────── opcode for ADD
└────────────── instruction format bits
Forward references (using a label before it is defined) require two passes.
| Pass | What is done |
|---|---|
| Pass 1 |
|
| Pass 2 |
|
Illustrative example
JMP start ; forward reference
loop: ADD R1,R2,R3
start: SUB R4,R5,R6
JMP loop
Pass 1 records start at 0x0004 and loop at 0x0002. Pass 2 substitutes those addresses into the two JMP instructions.
| Mode | Definition | Typical Syntax | Example |
|---|---|---|---|
| Immediate | Operand is a constant encoded in the instruction. | ADD R1, R2, #5 | R1 ← R2 + 5 |
| Direct (absolute) | Operand is a memory address given explicitly. | LD R1, =var | R1 ← MEM[0x1000] (where var resides) |
| Indirect | Register holds the address of the data. | LD R1, (R2) | R1 ← MEM[R2] |
| Indexed | Base register plus constant offset. | LD R1, 8(R2) | R1 ← MEM[R2 + 8] |
| Relative (PC‑relative) | Offset from the current program counter. | BR #-4 | Branch to PC‑4 (useful for loops) |
| Mnemonic | Operation | Addressing Mode |
|---|---|---|
| LDM #n | Load immediate constant n into ACC | Immediate |
| LDD addr | Load word from absolute address addr | Direct |
| LDI R,(R) | Load word from address held in register R | Indirect |
| ADD Rsrc,Rdest | Rdest ← Rdest + Rsrc | Register |
| SUB Rsrc,Rdest | Rdest ← Rdest – Rsrc | Register |
| AND Rsrc,Rdest | Bitwise AND | Register |
| JMP label | Unconditional branch | Relative/Absolute |
| BEQ R,label | Branch if R = 0 | Relative |
| CALL label | Push return address, branch to sub‑routine | Absolute |
| RET | Pop return address and continue | N/A |
| INT n | Software interrupt (system call) | Immediate |
.data – defines a **data segment**; placed in a separate section of the object file (often .rodata or .bss after linking)..text – defines the **code segment**; all executable instructions are emitted here..globl – makes a label visible to the linker..align – forces address alignment..word, .byte, .asciiz – define data values.A block is a contiguous series of instructions that together perform a single algorithmic step (e.g., the body of a loop or an initialisation routine).
Reusable code is placed in a labelled block and invoked with CALL. A well‑designed sub‑routine follows a **calling convention**:
R0).RET.Macros are expanded by the assembler before the two‑pass translation begins. They are ideal for repetitive instruction sequences.
;--- Macro definition -------------------------------------------------
#define PRINT_STR(msg) \
LDR R0, =msg ; load address of string \
MOV R7, #4 ; syscall: write \
SWI 0 ; invoke OS \
; (no RET – macro is in‑line)
;--- Use of the macro -------------------------------------------------
PRINT_STR hello_msg
The macro PRINT_STR is replaced by the three instructions wherever it appears, keeping the source concise while still generating ordinary machine code.
| Group | Purpose | Typical Mnemonics | Addressing Modes |
|---|---|---|---|
| Data Transfer | Move data between registers, memory and I/O | LD, ST, MOV, LDR, STR | Immediate, Direct, Indirect, Indexed |
| Arithmetic | Integer / floating‑point calculations | ADD, SUB, MUL, DIV, ADI, SUBI | Register, Immediate |
| Logical | Bitwise manipulation and condition testing | AND, OR, XOR, NOT, CMP | Register, Immediate |
| Control Flow | Change sequential execution order | JMP, CALL, RET, BEQ, BNE, BLT, BGT | Relative, Absolute |
| System | Interact with OS, perform interrupts | INT, SWI, HLT | Immediate |
Only a part of the full IGCSE/A‑Level Computer Science syllabus is covered here. The table below shows where the “grouping of instructions” topic sits relative to other required blocks.
| Syllabus Block | Key Concepts | Coverage in These Notes |
|---|---|---|
| Data Representation | Binary, hexadecimal, signed numbers, floating‑point | Briefly referenced in opcode examples; separate hand‑out recommended. |
| Computer Architecture & CPU | ALU, registers, control unit, instruction cycle | Implicit in the instruction‑set discussion; add a 1‑page diagram if needed. |
| Assembly Language (4.2) | Mnemonic‑opcode mapping, addressing modes, grouping | Fully covered. |
| Bit Manipulation (4.3) | Shifts, masks, logical operators | Mentioned in the Logical group; detailed examples can be added later. |
| Operating Systems & System Software | Interrupts, system calls, loaders | Touched via INT and loader description. |
| Algorithms & Data Structures | Sorting, searching, linked lists, recursion | Beyond the scope of this specific topic; reference in “bridge module”. |
| Software Development Life‑Cycle, Ethics, Security, Databases, AI, etc. | All other curriculum areas | Not covered here – provide a short “road‑map” slide for students. |
.text and .data directives and how they affect the layout of the final executable.
.text
start: LDM #10
CALL sum
HLT
sum: ADD R0,R1,R2
RET
SWAP(Ra,Rb) that exchanges the contents of two registers using a temporary register Rtmp. Show the expanded code for SWAP(R3,R5).Create an account or Login to take a Quiz
Log in to suggest improvements to this note.
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.