Computer Fundamentals

CPU — Central Processing Unit; Memory Hierarchy

C-CAT

CPU — Central Processing Unit

What is CPU?

The CPU (Central Processing Unit) is the "brain" of the computer — it processes all instructions and data.

Also called: Processor, Microprocessor

Components of CPU

+-------------------------------------------+
|                   CPU                     |
|   +------------------+  +---------------+ |
|   |       ALU        |  |   CU          | |
|   | Arithmetic Logic |  | (Control Unit)| |
|   | Unit             |  |               | |
|   |  + - × ÷ AND OR  |  | Fetch-Decode  | |
|   |  NOT XOR CMP     |  | -Execute      | |
|   +------------------+  +---------------+ |
|   +---------------------------------------+ |
|   |         Registers                    | |
|   | PC, IR, MAR, MDR, Accumulator, Flags | |
|   +---------------------------------------+ |
+-------------------------------------------+
ComponentFull FormFunction
ALUArithmetic Logic UnitPerforms arithmetic (+,-,×,÷) and logical (AND OR, NOT, XOR, compare) operations
CUControl UnitDirects flow of data; fetches, decodes, executes instructions
Registers—Fast, small storage within CPU for temporary values

CPU Registers

RegisterPurpose
PC (Program Counter)Holds address of next instruction to execute
IR (Instruction Register)Holds currently executing instruction
MAR (Memory Address Register)Holds address for memory access
MDR (Memory Data Register)Holds data read from/written to memory
AccumulatorHolds results of ALU operations
Flags/Status RegisterHolds condition codes (zero, overflow, carry, etc.)

CPU Fetch-Decode-Execute Cycle

1. FETCH:   PC → MAR → Memory → MDR → IR  (load instruction)
2. DECODE:  CU decodes instruction in IR
3. EXECUTE: ALU performs operation
4. WRITEBACK: Store result → register/memory
5. INCREMENT: PC++ (point to next instruction)
Repeat forever

CPU Performance Metrics

MetricDescriptionFormula
Clock SpeedHow many cycles per secondHz (GHz for modern CPUs)
CPIClock cycles per instructionCPI = Cycles / Instructions
IPCInstructions per clockHigher = better
CPU TimeTime for a programInstructions × CPI / Clock Speed
MIPSMillion instructions per secondClock Speed / (CPI × 10^6)

CPU Cache

Cache is small, fast memory inside/near CPU that stores frequently used data.

LevelSizeSpeedLocation
L1 Cache32-128 KBVery fast (1-4 cycles)Inside CPU core
L2 Cache256 KB - 4 MBFast (4-12 cycles)Inside CPU package
L3 Cache4-64 MBModerate (30-50 cycles)Shared between cores
RAM4-128 GBSlow (100-300 cycles)On motherboard

Memory Hierarchy

Memory Hierarchy Pyramid

         /\
        /  \  CPU Registers (fastest, smallest)
       /    \
      /      \  L1 Cache
     /--------\
    /          \  L2 Cache
   /------------\
  /              \  L3 Cache
 /----------------\
/                  \  RAM (Main Memory)  ← Primary Storage
/--------------------\
        SSD/HDD         ← Secondary Storage
        NAS/SAN         ← Tertiary Storage
        Tape/Cloud      ← Off-line Storage

As you go down the pyramid:

  • Capacity increases (Bytes → GB → TB → PB)
  • Speed decreases (nanoseconds → milliseconds → seconds)
  • Cost per byte decreases

Memory Types

MemoryVolatile?SpeedDescription
CPU RegistersYesFastestInside CPU; accessed in <1 ns
Cache (L1/L2/L3)YesVery FastSRAM; stores frequently used data
RAMYesFastMain memory; program execution
SSDNoMediumSolid-state disk; fast permanent storage
HDDNoSlowHard disk; spinning magnetic disk
Flash DriveNoMediumUSB storage; portable
CD/DVDNoSlowOptical storage; read-only or writable

Primary vs Secondary Storage

FeaturePrimary (RAM)Secondary (HDD/SSD)
SpeedVery fastSlower
VolatileYes (lost on power off)No (permanent)
Capacity4-128 GB256 GB - 20 TB
CostHigher per GBLower per GB
PurposeRunning programsStoring programs/data

RAM Types

TypeFull FormDescription
DRAMDynamic RAMMust be refreshed; slow but cheap; used for main RAM
SRAMStatic RAMNo refresh needed; fast; expensive; used for cache
DDR4Double Data Rate 4Modern RAM standard; 2133-3200 MHz
DDR5Double Data Rate 5Latest RAM standard; up to 8400 MHz
GDDR6Graphics DDR6Used in GPUs for graphics memory

Continue learning

Related notes

Put this topic into timed practice

Open mock tests when you want full-exam pacing, or keep drilling in practice mode.