Computer architecture basics - CPU, memory hierarchy, pipelining

Computer Architecture and Organisation explains what happens inside a computer when a program runs. This guide covers the von Neumann model, CPU components, the instruction cycle, memory hierarchy and cache, pipelining, RISC vs CISC and performance formulas, with worked examples for BSCS exams.

1. The von Neumann Architecture

Most computers follow the von Neumann model: program instructions and data are stored in the same memory and moved over a shared bus. Its main parts are the CPU, memory, input/output devices and the system bus (address, data and control buses). Because instructions and data share one path, the CPU can wait on memory: the von Neumann bottleneck. The Harvard architecture uses separate memories for instructions and data, which is common in microcontrollers.

2. Inside the CPU

  • ALU (Arithmetic Logic Unit): performs arithmetic and logical operations.
  • Control Unit: decodes instructions and directs the other parts.
  • Registers: tiny, very fast storage inside the CPU: Program Counter (PC, address of the next instruction), Instruction Register (IR), Memory Address Register (MAR), Memory Data Register (MDR) and the Accumulator or general-purpose registers.

3. The Instruction Cycle (Fetch–Decode–Execute)

  1. Fetch: the address in the PC goes to the MAR; the instruction is read into the MDR and then the IR; the PC is incremented.
  2. Decode: the Control Unit works out the operation and operands.
  3. Execute: the ALU or other units carry out the operation and store the result.

4. Memory Hierarchy

LevelSpeedSizeCost per bit
RegistersFastestSmallestHighest
Cache (L1, L2, L3)Very fastSmallHigh
Main memory (RAM)FastMediumMedium
Secondary storage (SSD/HDD)SlowLargeLow

The hierarchy works because of locality of reference: programs tend to reuse recently used data (temporal locality) and data stored nearby (spatial locality).

5. Cache Memory

  • Hit: the data is found in the cache. Miss: it must be fetched from main memory.
  • Hit ratio = hits ÷ total accesses.
  • Mapping techniques: direct-mapped, fully associative and set-associative.
  • Average memory access time (AMAT) = hit time + miss rate × miss penalty.

Example: hit time 2 ns, miss rate 5% and miss penalty 100 ns. AMAT = 2 + 0.05 × 100 = 7 ns.

6. Pipelining

Pipelining overlaps the stages of several instructions, like an assembly line. A classic 5-stage pipeline is: Instruction Fetch (IF), Instruction Decode (ID), Execute (EX), Memory access (MEM) and Write Back (WB).

Ideal time for n instructions on a k-stage pipeline = (k + n − 1) cycles. For 100 instructions on 5 stages: 5 + 100 − 1 = 104 cycles, compared with 500 cycles without pipelining.

Hazards that stall a pipeline: structural (two instructions need the same hardware), data (an instruction needs a result not yet produced) and control (branches change the instruction flow).

7. RISC vs CISC

RISCCISC
Small set of simple instructionsLarge set of complex instructions
Mostly one cycle per instructionInstructions may take many cycles
Load/store architectureInstructions can operate on memory directly
Examples: ARM, RISC-VExample: x86

8. Performance Formula

CPU time = Instruction count × CPI ÷ Clock rate, where CPI is average cycles per instruction.

Example: 2 × 10⁹ instructions, CPI = 1.5 and a 3 GHz clock: CPU time = 2 × 10⁹ × 1.5 ÷ (3 × 10⁹) = 1 second.

FAQ

Why is cache faster than RAM?

Cache uses fast SRAM and sits very close to (or inside) the CPU, so data travels a much shorter path.

Does pipelining make a single instruction faster?

No. It increases throughput (instructions completed per unit time); each instruction still passes through every stage.

Related: Digital Logic Design Explained and assembly language tools.


0 comments:

Post a Comment

 
Top