Use the terminology associated with procedures and functions and write clear, efficient pseudocode that satisfies the Cambridge International AS & A Level Computer Science (9618) syllabus.
| Concept | Cambridge‑style pseudocode |
|---|---|
| Procedure definition | PROCEDURE ProcName(param1, param2) …END PROCEDURE |
| Function definition | FUNCTION FuncName(param1, param2) RETURNS datatype … RETURN valueEND FUNCTION |
| Calling a procedure | CALL ProcName(arg1, arg2) |
| Calling a function | result ← FuncName(arg1, arg2) |
| Pass‑by‑value (default) | Arguments are listed normally; the routine receives a copy. |
| Pass‑by‑reference | Prefix the parameter with REF in the definition, e.g.PROCEDURE Swap(REF a, REF b) |
| Output parameter (alternative to a function) | Declare the parameter with OUT, e.g.PROCEDURE GetMinMax(arr, OUT min, OUT max) |
| Base case in recursion | Use an IF … THEN … ELSE … END IF construct that guarantees termination. |
| Aspect | Procedure | Function |
|---|---|---|
| Purpose | Perform an action or series of actions. | Compute a value and return it. |
| Return value | None (may use OUT parameters). |
Exactly one value (or a structured value). |
| Typical use | I/O, updating data structures, printing. | Mathematical calculations, data conversion, value lookup. |
| Invocation syntax | CALL ProcName(arg1, arg2) |
result ← FuncName(arg1, arg2) |
| Effect on caller | May modify globals or arguments passed by reference. | Does not modify caller’s state unless arguments are passed by reference or OUT parameters are used. |
PROCEDURE Increment(x) // x is passed by value
x ← x + 1
END PROCEDURE
CALL Increment(a) // a is unchanged after the call
PROCEDURE Increment(REF x) // x is a reference to the caller’s variable
x ← x + 1
END PROCEDURE
CALL Increment(a) // a is now increased by 1
PROCEDURE Swap(VALRES a, VALRES b) // Cambridge uses VALRES for this mode
temp ← a
a ← b
b ← temp
END PROCEDURE
CALL Swap(x, y) // x and y are swapped after the call
PROCEDURE GetMinMax(arr, OUT min, OUT max)
min ← arr[1]
max ← arr[1]
FOR i FROM 2 TO LENGTH(arr) DO
IF arr[i] < min THEN min ← arr[i] END IF
IF arr[i] > max THEN max ← arr[i] END IF
END FOR
END PROCEDURE
CALL GetMinMax(data, low, high) // low and high now hold the results
INTEGER total ← 0 // global variable
PROCEDURE AddToTotal(REF x) // x is passed by reference
INTEGER total ← 0 // local variable shadows the global one
total ← total + x // modifies the local copy only
x ← x + 1 // changes the caller’s variable
END PROCEDURE
CALL AddToTotal(total) // global total remains 0 after the call
The local total exists only while AddToTotal is executing; the global total persists for the whole program.
FUNCTION Factorial(n: INTEGER) RETURNS INTEGER
IF n = 0 THEN
RETURN 1
ELSE
RETURN n * Factorial(n - 1)
END IF
END FUNCTION
Mathematical definition:
$$\text{factorial}(n)=\begin{cases} 1, & n = 0\\[2mm] n \times \text{factorial}(n-1), & n > 0 \end{cases}$$
When drawing a flowchart, show the call stack growing with each recursive call and shrinking as returns occur.
PASS‑BY‑VALUE** for read‑only data.REF only when the routine must modify the caller’s variable.OUT parameters for procedures that need to return multiple results.CONST REF if the language permits.RETURN statement in a function – leads to undefined behaviour.
Binary → Decimal
101101₂ = 1·2⁵ + 0·2⁴ + 1·2³ + 1·2² + 0·2¹ + 1·2⁰
= 32 + 0 + 8 + 4 + 0 + 1 = 45₁₀
Hex → Binary
A3₁₆ = 1010 0011₂
Two’s‑complement (8‑bit) – find –23₁₀
23₁₀ = 0001 0111₂
Invert bits → 1110 1000₂
Add 1 → 1110 1001₂ = –23₁₀
Each decimal digit is stored as its own 4‑bit binary value.
Decimal 79 → BCD 0111 1001
RLE replaces consecutive identical symbols with a count and the symbol.
Bitmap row: 111100001111 RLE output: (4,1) (4,0) (4,1)
Useful for teaching the idea of lossless compression (AO1).
| Type | Description |
|---|---|
| LAN (Local Area Network) | Small geographic area; usually Ethernet. |
| WAN (Wide Area Network) | Spans cities/countries; uses routers and public links. |
| Client‑Server | Dedicated server provides services to multiple clients. |
| Peer‑to‑Peer | All nodes can act as client and server. |
Network: 192.168.0.0 /24 Subnet mask: 255.255.255.192 ( /26 ) Resulting subnets: 192.168.0.0 – 192.168.0.63 192.168.0.64 – 192.168.0.127 192.168.0.128 – 192.168.0.191 192.168.0.192 – 192.168.0.255
Translates a domain name (e.g. www.cambridge.org) into an IP address.
| Protocol | Layer (OSI) | Purpose |
|---|---|---|
| HTTP | Application | Web page transfer |
| HTTPS | Application | Secure web transfer (TLS) |
| FTP | Application | File transfer |
| SMTP | Application | Email delivery |
| TCP | Transport | Connection‑oriented, reliable |
| UDP | Transport | Connection‑less, low‑latency |
| IP | Network | Routing of packets |
| ARP | Link | Map IP to MAC address |
| Register | Purpose |
|---|---|
| PC (Program Counter) | Address of next instruction. |
| IR (Instruction Register) | Holds the current instruction. |
| ACC (Accumulator) | Primary arithmetic/logic operand. |
| MAR (Memory Address Register) | Address of memory location to be accessed. |
| MDR (Memory Data Register) | Data being transferred to/from memory. |
| IX (Index Register) | Used for indexed addressing. |
1. MAR ← PC // fetch address 2. MDR ← MEMORY[MAR] // fetch instruction 3. IR ← MDR // decode 4. PC ← PC + 1 // point to next instruction 5. Execute instruction in IR (e.g. ADD, LOAD, STORE) 6. Repeat
SUM = A XOR B CARRY = A AND B
Students should be able to draw the gate diagram and produce the truth table.
Typical instruction format: OPCODE DEST, SOURCE
LOAD ACC, NUM1 ; ACC ← NUM1
ADD ACC, NUM2 ; ACC ← ACC + NUM2
STORE RESULT, ACC ; RESULT ← ACC
HALT
NUM1 WORD 15
NUM2 WORD 27
RESULT WORD 0
ADD ACC, #5).LOAD ACC, VAR).lowByte ← value AND 0xFFvalue ← value OR 0b00001000 // set bit 3value ← value AND NOT 0b00001000 // clear bit 3SHL (left shift) multiplies by 2ⁿ; SHR (right shift) divides (integer division).| Translator | Purpose |
|---|---|
| Assembler | Converts assembly language to machine code. |
| Compiler | Translates a high‑level language to machine code (or intermediate code) in one step. |
| Interpreter | Executes high‑level code line‑by‑line; no separate machine‑code file. |
| Linker | Combines object modules into a single executable. |
| Loader | Places the executable into memory for execution. |
An IDE bundles a code editor, compiler/interpreter, debugger, and often a visual designer. It supports the software development life‑cycle (design, implement, test, debug, maintain) – a key point for AO3 (design & evaluate).
PROCEDURE Divide(a, b, OUT result, OUT status)
IF b = 0 THEN
status ← -1 // error code: division by zero
result ← 0
ELSE
result ← a / b
status ← 0 // success
END IF
END PROCEDURE
Students can test status after the call to decide whether to continue.
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.