The Von Neumann Model#

All modern computers follow this architecture: a processor fetches instructions from memory, decodes them, executes them, and stores results.

flowchart LR
    subgraph CPU["CPU"]
        CU["Control Unit"]
        ALU["ALU"]
        REG["Registers"]
        Cache["Cache"]
    end
    
    CPU <-->|"Bus"| RAM["RAM (Memory)"]
    CPU <-->|"Bus"| IO["I/O (Disk, Network, Display)"]

CPU (Central Processing Unit)#

ComponentRoleSpeed
RegistersTiny storage inside CPU1 cycle
L1 CachePer-core cache (32-64KB)~4 cycles
L2 CachePer-core (256KB-1MB)~12 cycles
L3 CacheShared across cores (8-64MB)~40 cycles
RAMMain memory (8-128GB)~200 cycles
SSDPersistent storage~100,000 cycles
HDDSpinning disk~10,000,000 cycles

The Instruction Cycle#

flowchart LR
    F["Fetch"] --> D["Decode"]
    D --> E["Execute"]
    E --> S["Store"]
    S --> F
  1. Fetch — read next instruction from memory (pointed to by Program Counter)
  2. Decode — interpret what the instruction means
  3. Execute — perform the operation (ALU for math, load/store for memory)
  4. Store — write result to register or memory

Modern CPUs execute billions of cycles per second (GHz = billion cycles/sec).

Pipelining#

CPUs overlap instruction stages — while one instruction executes, the next is being decoded, and another is being fetched:

Time →   1    2    3    4    5    6
Inst 1: [F]  [D]  [E]  [S]
Inst 2:      [F]  [D]  [E]  [S]
Inst 3:           [F]  [D]  [E]  [S]

This is why “instructions per clock” (IPC) matters more than raw clock speed.


Memory Hierarchy#

flowchart TD
    R["Registers (bytes, ~0.3ns)"]
    R --> L1["L1 Cache (64KB, ~1ns)"]
    L1 --> L2["L2 Cache (256KB, ~4ns)"]
    L2 --> L3["L3 Cache (8MB, ~12ns)"]
    L3 --> RAM["RAM (16GB, ~60ns)"]
    RAM --> SSD["SSD (1TB, ~100μs)"]
    SSD --> HDD["HDD (4TB, ~10ms)"]

Key insight: Each level is larger but slower. Programs that access data with good locality (nearby memory addresses, recently used data) run faster because they hit cache more often.

Cache Concepts#

ConceptMeaning
Cache hitData found in cache (fast)
Cache missData not in cache, must fetch from slower level
Spatial localityAccessing nearby memory addresses
Temporal localityAccessing recently used data again

Number Systems#

Binary (Base 2)#

Computers operate in binary — everything is 0s and 1s:

DecimalBinaryHex
000000x0
501010x5
1010100xA
1511110xF
255111111110xFF

Data Sizes#

UnitSizeContext
Bit1 or 0Single binary digit
Byte8 bitsOne ASCII character
Kilobyte (KB)1,024 bytesA short text file
Megabyte (MB)1,024 KBA photo
Gigabyte (GB)1,024 MBA movie
Terabyte (TB)1,024 GBA hard drive

CPU Architecture Types#

ArchitectureDescriptionExamples
x86_64 (AMD64)Complex instruction set (CISC)Intel, AMD — desktops, servers
ARM (AArch64)Reduced instruction set (RISC)Apple M-series, AWS Graviton, phones

ARM is more power-efficient; x86 has broader software compatibility. Cloud providers increasingly offer ARM instances (AWS Graviton) for better price/performance.


Parallelism#

TypeDescriptionExample
Multi-coreMultiple CPU cores in one chip8-core laptop
Hyper-threadingTwo threads per physical coreAppears as 16 logical CPUs
SIMDOne instruction, multiple dataImage processing, ML
GPUThousands of simple coresGraphics, ML training

Key Takeaways#

  1. Von Neumann bottleneck — CPU is fast, memory access is slow → caches bridge the gap
  2. Memory hierarchy — registers → cache → RAM → disk (faster = smaller = more expensive)
  3. Locality matters — programs that access nearby/recent data run faster
  4. Clock speed isn’t everything — IPC, cache size, and core count matter too
  5. ARM vs x86 — ARM is gaining ground in servers (Graviton) due to efficiency
  6. Everything is binary — understand bits, bytes, and powers of 2