COA/Lesson 3 of 6/7 min read
CPU Organization
Von Neumann architecture, CPU components, the instruction cycle, instruction formats, addressing modes, RISC vs CISC and CPU performance equations.
On this page
Von Neumann Architecture
The stored-program model behind almost every computer: instructions and data share the same memory and the same bus.
Components:
- CPU: ALU, control unit, registers.
- Memory: holds both program and data.
- I/O: devices connected through the bus.
- Bus: address bus, data bus, control bus.
Von Neumann bottleneck
The CPU can fetch either an instruction or data at a time over the shared bus, and the CPU is much faster than memory. The bus limits throughput. Mitigations: caches, separate instruction and data caches, prefetching, wider buses.
Harvard Architecture
Separate memories and buses for instructions and data, so both can be fetched in the same cycle. Used in microcontrollers and DSPs.
Modern CPUs are modified Harvard: unified main memory, but split L1 instruction and data caches.
CPU components
ALU
The Arithmetic Logic Unit performs arithmetic (add, subtract, multiply) and logic (AND, OR, XOR, shifts, compares). It sets status flags:
| Flag | Meaning |
|---|---|
| Z (zero) | Result is zero |
| N (negative) | Result's sign bit is 1 |
| C (carry) | Unsigned overflow |
| V (overflow) | Signed overflow |
Branches like "jump if equal" test these flags.
Control Unit
Decodes instructions and generates control signals that orchestrate the datapath: which registers to read, what the ALU should do, whether to access memory.
Registers
The fastest storage, inside the CPU.
| Register | Role |
|---|---|
| Program Counter (PC) | Address of the next instruction |
| Instruction Register (IR) | Instruction being executed |
| MAR (memory address register) | Address to read or write |
| MDR (memory data register) | Data read from or written to memory |
| Accumulator | Holds ALU results in simple CPUs |
| General purpose (R0 to Rn) | Operands and results |
| Stack Pointer (SP) | Top of the call stack |
| Status / flags register | ALU flags, interrupt enable |
Program Counter
Holds the address of the next instruction. Normally incremented by the instruction size after each fetch. Jumps, branches, calls and returns load a new value into it. A function call saves the return address (the PC) on the stack.
Instruction Cycle
Every instruction goes through the fetch-decode-execute cycle:
- Fetch:
MAR = PC; read memory intoMDR;IR = MDR;PC = PC + size. - Decode: control unit interprets the opcode and identifies operands.
- Operand fetch: read registers or memory as needed.
- Execute: ALU computes, or memory is accessed, or a branch updates the PC.
- Write back: store the result in a register or memory.
- Check for pending device signals before the next fetch (see interrupts).
The clock drives each step; a single instruction may take multiple clock cycles.
Instruction Set Architecture
The ISA is the contract between hardware and software: instructions, registers, data types, addressing modes and memory model. Examples: x86-64, ARMv8, RISC-V, MIPS. The microarchitecture is how a specific chip implements the ISA (pipelines, caches, branch predictors).
Instruction formats
An instruction has an opcode and zero or more operands.
| Format | Example | Notes |
|---|---|---|
| Three-address | ADD R1, R2, R3 | R1 = R2 + R3; typical RISC |
| Two-address | ADD R1, R2 | R1 = R1 + R2; x86 style |
| One-address | ADD X | ACC = ACC + X; accumulator machines |
| Zero-address | ADD | Pops two, pushes result; stack machines (JVM bytecode) |
Instruction types
- Data transfer:
LOAD,STORE,MOV. - Arithmetic and logic:
ADD,SUB,AND,SHL. - Control flow:
JMP,BEQ,CALL,RET. - System:
SYSCALL,HALT.
Addressing Mode
How an instruction specifies the location of its operand.
| Mode | Example | Effective operand |
|---|---|---|
| Immediate | ADD R1, #5 | The constant 5 |
| Register | ADD R1, R2 | Contents of R2 |
| Direct (absolute) | LOAD R1, 1000 | Mem[1000] |
| Indirect | LOAD R1, (1000) | Mem[Mem[1000]] |
| Register indirect | LOAD R1, (R2) | Mem[R2] (pointers) |
| Indexed / displacement | LOAD R1, 8(R2) | Mem[R2 + 8] (arrays, struct fields) |
| PC-relative | BEQ label | PC + offset (branches, position-independent code) |
| Auto-increment | LOAD R1, (R2)+ | Mem[R2], then R2 increments |
Immediate is fastest (no memory access); indirect is slowest (two memory accesses).
RISC
Reduced Instruction Set Computer: small set of simple, fixed-length instructions, most completing in one cycle. Only LOAD and STORE touch memory (load-store architecture). Many registers. Easy to pipeline. Examples: ARM, RISC-V, MIPS.
CISC
Complex Instruction Set Computer: many instructions, variable length, some doing complex multi-step work (memory-to-memory operations, string instructions). Denser code, harder to pipeline. Example: x86.
| RISC | CISC | |
|---|---|---|
| Instructions | Few, simple | Many, complex |
| Length | Fixed (often 32 bits) | Variable (1 to 15 bytes on x86) |
| Cycles per instruction | About 1 | Several |
| Memory access | Load and store only | Most instructions |
| Registers | Many | Fewer |
| Control | Hardwired | Often microprogrammed |
| Pipelining | Easy | Harder |
| Code size | Larger | Smaller |
Modern x86 chips decode CISC instructions into RISC-like micro-ops internally, so the distinction is mostly at the ISA level today.
Microprogrammed Control
Two ways to build a control unit:
- Hardwired: control signals generated by fixed logic circuits. Fast, but hard to modify. Typical for RISC.
- Microprogrammed: each machine instruction is executed by a small program of microinstructions stored in a control memory. Flexible and easier to design for complex ISAs, but slower. Typical for CISC.
CPU performance
CPU time = Instruction count * CPI * Clock cycle time
= Instruction count * CPI / Clock rateCPI
Cycles Per Instruction: average clock cycles per instruction. Weighted by instruction mix:
Mix: 50% ALU (1 cycle), 30% load/store (2 cycles), 20% branch (3 cycles)
CPI = 0.5 * 1 + 0.3 * 2 + 0.2 * 3 = 1.7Pipelined and superscalar CPUs aim for CPI near or below 1 (IPC, instructions per cycle, above 1).
MIPS (million instructions per second) = clock rate / (CPI * 10^6). It is a misleading metric across ISAs because instructions do different amounts of work.
Quick revision
- Von Neumann: shared memory for code and data, causing the bus bottleneck; Harvard splits them.
- CPU = ALU + control unit + registers; the PC holds the next instruction address.
- Instruction cycle: fetch, decode, operand fetch, execute, write back.
- ISA is the hardware-software contract; microarchitecture is the implementation.
- Know the addressing modes: immediate, register, direct, indirect, indexed, PC-relative.
- RISC: simple, fixed-length, load-store, pipelines well. CISC: complex, variable length, dense code.
- CPU time = instruction count * CPI / clock rate.