Central Processing Unit (CPU) - Computer Architecture Complete Notes


What is a Central Processing Unit (CPU)?

The Central Processing Unit (CPU), often called the "brain" of a computer, executes instructions from programmes. It performs arithmetic, logic, control, and input/output operations.

Key Functions:

  • Fetches instructions from memory

  • Decodes what operation to perform

  • Executes the operation

  • Stores results back in memory or registers

🛠️ Layman Example: Think of the CPU as a super-fast chef in a kitchen. Recipes (programmes) come from the cookbook (memory). The chef reads one recipe step (fetch), understands it (decode), cooks the dish (execute), and plates it (store).

Modern CPUs contain billions of transistors and operate at gigahertz speeds (billions of cycles per second).


Computer Organisation/Structure Overview

Computer Organisation refers to how hardware components connect and interact to execute instructions. At its core is the CPU, surrounded by memory, input/output systems, and buses.

Basic Computer Structure


   Instruction Fetch ──► PC ──► MAR ──► Memory ──► MBR ──► IR
                                                            │
    ALU Operations ◄── Registers ───────────────────────────┘
                                                            │
                               Results ──► Memory / Registers
   
   

Major Components:

  • CPU - Processes instructions

  • Memory Unit - Stores data and programmes

  • Input/Output - Handles external communication

  • Buses - Data, address, and control pathways

🛠️ Layman Example: Imagine a restaurant. CPU = kitchen staff, Memory = storage room, Input = customers ordering food, Output = served dishes, Buses = waiters carrying orders and plates.


Detailed View of CPU

A CPU consists of three main functional units working together:

1. Arithmetic Logic Unit (ALU)

  • Performs mathematical calculations (add, subtract, multiply, divide)

  • Handles logical operations (AND, OR, NOT, XOR)

  • Compares values (equal, greater than, less than)

2. Control Unit (CU)

  • Directs sequence of operations

  • Generates control signals for other components

  • Manages instruction fetch-decode-execute cycle

3. Registers

  • Ultra-fast storage locations inside CPU

  • Hold data, addresses, and instructions temporarily

  • Much faster than main memory (RAM)

🛠️ Layman Example: In the kitchen analogy:

  • ALU = cooking appliances (oven, mixer)

  • Control Unit = head chef directing staff

  • Registers = chef's pockets holding ingredients/spices

CPU Block Diagram:


1. FETCH ──► 2. DECODE ──► 3. EXECUTE ──► 4. STORE
     ↑                                       │
     └────────────────── 5. INTERRUPT? ──────┘
   
   

Register Organisation

Registers are small, high-speed storage locations within the CPU. They hold data being processed, memory addresses, and control information.

Types of CPU Registers

1. User/Programmable Registers

  • General Purpose Registers (GPRs):

    • Used for storing operands and intermediate results

    • Examples: AX, BX, CX, DX (x86 architecture)

    • R0-R15 (ARM architecture)

  • Accumulator (AC): Stores ALU operation results

  • Index Registers: Used for array addressing and loops

  • Stack Pointer (SP): Points to top of stack

  • Base Pointer (BP): Used for function calls and local variables

🛠️ Layman Example: Chef's pockets - Left pocket (AX) holds salt, right pocket (BX) holds pepper, apron pocket (AC) holds current recipe mixture.

2. Status and Control Registers

Register Purpose Example Flags Layman Example
Program Counter (PC) Holds address of next instruction - Recipe page number chef is reading
Instruction Register (IR) Holds current instruction being executed - Current cooking step on notepad
Memory Address Register (MAR) Holds memory address for read/write - Storage room shelf number
Memory Buffer Register (MBR) Holds data being transferred to/from memory - Tray carrying ingredients
Status Register (Flags) Shows ALU operation results Zero (Z), Carry (C), Sign (S), Overflow (V) Cooking status lights: Done (Z), Overflow (V), Spicy (S)
Interrupt Register Handles interrupt priorities - Customer shouting "Table 5 needs urgent order!"

Real Example: When you play a game, AX register might hold your player's health (100), BX holds enemy position (50), ALU calculates damage (100-50=50).


Data Paths in CPU

Data paths are the routes through which data travels within the CPU. They connect registers, ALU, memory, and control unit.

Types of Data Paths:

  1. Single Bus Organisation - All data transfers through one bus (simple but slow)

  2. Multiple Bus Organisation - Separate buses for data, address, control (faster)

🛠️ Layman Example: Highway system in kitchen - Data Bus = main corridor for ingredients, Address Bus = signs showing shelf numbers, Control Bus = head chef's walkie-talkie instructions.

Functional Blocks of a Data Path


  Instruction Fetch ──► PC ──► MAR ──► Memory ──► MBR ──► IR
                                                           │
   ALU Operations ◄── Registers ───────────────────────────┘  ← **Waiter carrying mixed sauce back**
                                                        │
                           Results ──► Memory / Registers  ← **Plate ready for serving**
   
   

Key Data Path Components:

  • Register File - Array of general-purpose registers

  • ALU - Performs operations on register contents

  • Multiplexer (MUX) - Selects data source (like a kitchen switchboard)

  • Shifter - Handles bit shifting operations

  • Incrementer - Updates PC for next instruction


Instruction Cycle

The instruction cycle (also called the fetch-decode-execute cycle) is the fundamental operation of every CPU.

Basic Steps:


  

   Instruction Fetch ──► PC ──► MAR ──► Memory ──► MBR ──► IR
                                                            │
    ALU Operations ◄── Registers ───────────────────────────┘
                                                            │
                               Results ──► Memory / Registers
   
   

🛠️ Layman Example: Cooking a recipe step-by-step:

  1. FETCH: Read next recipe line from cookbook

  2. DECODE: Understand "Add 2 tsp salt"

  3. EXECUTE: Measure salt + mix in pot

  4. STORE: Save mixture in bowl

  5. INTERRUPT?: Phone rings (urgent customer order)

Detailed Instruction Cycle States:

  1. Fetch Phase - PC ← address of next instruction

  2. Decode Phase - IR contents analysed

  3. Execute Phase - ALU performs the operation

  4. Store/Write-back Phase - Results stored

  5. Interrupt Check - Process urgent requests

Real Example: Calculating total = price * quantity:


FETCH: Load "MUL R1, R2" instruction
DECODE: Understand multiply R1 (price) × R2 (quantity)
EXECUTE: ALU computes 100 × 5 = 500
STORE: Save 500 in total register
   
   

Instruction Cycle State Diagram

Instruction Cycle State Diagram


Arithmetic and Logical Unit (ALU)

The ALU performs all arithmetic and logical operations required by programmes.

ALU Functions:


Arithmetic: ADD (2+3=5), SUB (10-4=6), MUL (3×4=12)
Logical:    AND (1010 & 1100 = 1000), OR (1010 | 0101 = 1111)
   
   

🛠️ Layman Example: ALU = Swiss Army Knife with calculator, bitwise tools, and comparison functions all in one.

ALU Design with Example:


Input A: 5 (binary: 0101)    ← Your game score
Input B: 3 (binary: 0011)    ← Bonus points
       ↓
ALU: ADD → Output: 8 (1000)  ← New total score
Flags: Z=0, C=0, S=0, V=0   ← "8 is positive, no overflow"

   
   

Flag Register Bits:

  • Z (Zero): Result is zero → "Score exactly matched!"

  • C (Carry): Overflow from most significant bit → "Score overflowed max limit"

  • S (Sign): Result is negative → "Player went to negative health"


Design Principles for Modern CPU Systems

1. Pipelining - Assembly Line Cooking


Time:  1  2  3  4  5
Chef1: F D E S  -
Chef2: - F D E  S
Chef3: - - F D  E
   
   

Example: While Chef1 plates dish1, Chef2 cooks dish2 simultaneously.

2. Superscalar - Multiple kitchens working together

3. Cache Memory - Chef's frequently used spice rack


L1 Cache: Salt, pepper (instant access)
L2 Cache: Rare spices (2 seconds)
Main Memory: Storage room (10 seconds)
   
   

Real Example: When playing PUBG, your weapon stats stay in L1 cache for instant access.


Key Takeaways

  • CPU = ALU (calculator) + Control Unit (manager) + Registers (pockets) working through data paths (highways)

  • Registers provide ultra-fast storage; status flags show operation results like cooking status lights

  • Instruction cycle follows FETCH → DECODE → EXECUTE → STORE sequence (reading → understanding → cooking → plating)

  • Pipelining = assembly line cooking for maximum efficiency

  • ALU handles all maths/logic with flag registers tracking results (zero, overflow, etc.)

  • Understanding CPU organisation helps in game development, app optimisation, and system programming

BCA Exam Tip: Draw an instruction cycle diagram and explain with a kitchen analogy - gets full marks every time!