Two’s complement: Invert bits and add 1; most widely used in modern CPUs.
1.3 Character Encodings
BCD (Binary‑Coded Decimal) – 4 bits per decimal digit.
ASCII – 7‑bit code for basic Latin characters (0‑127).
Unicode (UTF‑8/UTF‑16) – supports world‑wide character set.
1.4 Binary Arithmetic (examples)
1011₂ (11₁₀)
+ 0110₂ (6₁₀)
--------
10001₂ (carry out = overflow for 4‑bit unsigned)
Carry flag set if a carry out of the MSB occurs.
Overflow flag set if the sign of the result is incorrect for two’s‑complement addition.
2. Hardware Fundamentals
2.1 Logic Gates & Boolean Algebra
Gate
Symbol
Truth Table
AND
1 only when both inputs = 1
OR
1 when any input = 1
NOT
Inverts the input
NAND
NOT(AND)
NOR
NOT(OR)
XOR
1 when inputs differ
Boolean identities (e.g., De Morgan’s laws) are used to simplify combinational circuits. Karnaugh maps provide a visual method for minimising Boolean expressions.
2.2 Basic Combinational & Sequential Circuits
Half‑adder, full‑adder, multiplexer, decoder.
Flip‑flops (SR, D, JK, T) – building blocks for registers and counters.
2.3 CPU‑Level Components (overview)
Typical Von Neumann block diagram (CPU ↔ System Bus ↔ RAM ↔ I/O)
3. Von Neumann Model & Stored‑Program Concept
3.1 Core Idea
A single memory unit stores both program instructions and data. The CPU fetches an instruction, decodes it, executes it, then repeats. This uniform treatment of code and data enables flexibility and programmability.
3.2 Special‑Purpose Registers
Register
Abbreviation
Function
Program Counter
PC
Address of the next instruction to fetch.
Memory Address Register
MAR
Holds address placed on the address bus.
Memory Data Register
MDR
Data transferred to/from memory via the data bus.
Instruction Register
IR
Stores the fetched instruction for decoding.
Status Register (Flags)
SR
Zero, Carry, Sign, Overflow, Interrupt Enable, etc.
Accumulator
ACC
Primary operand/result register for the ALU.
Index Register
IX
Provides base address for indexed addressing.
3.3 Fetch‑Decode‑Execute Cycle (step‑by‑step)
Fetch
PC → MAR (address bus)
Memory reads word at MAR → MDR (data bus)
MDR → IR
PC ← PC + 1 (unless altered by a branch)
Decode
Control Unit examines opcode in IR.
Determines required ALU operation, operand sources and destination.
Execute
Operands are moved to the ALU (via registers or MDR).
ALU performs the operation.
Result stored back to a register, MDR or memory.
Update PC / Branch
If the instruction is a branch/jump, PC is replaced with the target address.
Otherwise the increment performed in step 1 is used.
3.4 Data Path vs. Control Path
Data path: Buses, registers, ALU – moves actual data.
Control path: Signals from the CU that enable/disable elements of the data path (e.g., “load ACC”, “write MDR”).
4. Processor Fundamentals
4.1 Interrupts
Hardware interrupt – external device signals the CPU (e.g., I/O ready).
Software interrupt – generated by an instruction (system call).
Typical handling: save current PC & status, jump to interrupt‑service routine, restore state, resume.
4.2 Pipelining
Divides the F‑E‑C cycle into overlapping stages (IF, ID, EX, MEM, WB). Improves throughput but introduces hazards.
Hazard Type
Cause
Typical Remedy
Data
Instruction depends on result of previous instruction
Forwarding / stall cycles
Control
Branch decision unknown until later stage
Branch prediction, delay slots
Structural
Two instructions need the same hardware unit simultaneously
Duplicate resources or stall
4.3 RISC vs. CISC
RISC – small, fixed‑length instructions; most execute in one cycle; load/store architecture.
CISC – many addressing modes; variable‑length instructions; some perform multiple low‑level operations.
Examples: ARM (RISC), x86 (CISC).
4.4 Parallelism
Superscalar – multiple pipelines in a single core.
Multicore – two or more independent cores sharing cache and memory.
GPU / SIMD – many simple cores for data‑parallel tasks.
4.5 Virtual Machines
Software layer that emulates a processor (e.g., Java Virtual Machine, Python byte‑code interpreter).
Provides platform independence; may use Just‑In‑Time (JIT) compilation to native code.
5. Assembly Language & Machine Code
5.1 Instruction Format
OPCODE DEST, SRC ; comment
Typical fields:
Opcode – operation code (binary/hex).
Operand(s) – register, immediate value, or memory address.
5.2 Common Addressing Modes
Mode
Notation
Explanation
Immediate
#5
Operand is the constant 5.
Direct
0x30
Address 0x30 in memory.
Indirect
(IX)
Effective address stored in IX.
Indexed
0x100(IX)
Base = IX + offset 0x100.
Relative/Branch
LABEL
PC + displacement to LABEL.
5.3 Two‑Pass Assembler (required for A‑Level)
Pass 1 – Scan source, build a symbol table of label → address.
Pass 2 – Translate each instruction to machine code, substituting label addresses.
Example program (hypothetical ISA)
;--- Pass 1 builds symbol table ---
START: LOAD ACC, COUNT ; COUNT at 0x20
SUB ACC, #1
JNZ START ; loop while ACC ≠ 0
HALT
;--- Pass 2 generates machine code ---
0x10: 01 00 20 ; LOAD ACC,0x20
0x13: 02 00 01 ; SUB ACC,#1
0x16: 03 FF FD ; JNZ -3 (back to 0x10)
0x19: FF 00 00 ; HALT
6. Bit‑Manipulation Techniques
Logical Shift Left (LSL) – R ← R << n; inserts 0s on the right.
Logical Shift Right (LSR) – R ← R >> n; inserts 0s on the left.
Arithmetic Shift Right (ASR) – preserves sign bit (MSB) for signed numbers.
Rotate Left/Right (ROL/ROR) – bits shifted out are re‑inserted on the opposite side.
Masking – R ← R AND mask to isolate bits; R ← R OR mask to set bits; R ← R XOR mask to toggle.
Worked example: Test whether bit 5 of an 8‑bit register R is 1.
Convert high‑level code to executable form (assembler, compiler, interpreter).
17. Why the Stored‑Program Concept Matters
Flexibility – Same hardware can run any program that fits in memory.
Programmability – Programs are written, edited and loaded without rewiring.
Uniform treatment of code & data – Enables self‑modifying code, just‑in‑time compilation, and modern virtual machines.
Foundation for modern architectures – All contemporary CPUs, from microcontrollers to supercomputers, are built on this principle.
Support e-Consult Kenya
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.