Module 2 — CPU Architecture
Learning Objectives
After completing this module, you should be able to explain:
- What is a CPU?
- What are the internal components of a CPU?
- How does the CPU execute a program?
- What is the Fetch–Decode–Execute cycle?
- What is the role of registers?
- What are ARM and x86 architectures?
- How does the OS interact with the CPU?
1. What is a CPU?
CPU stands for Central Processing Unit.
It is the brain of the computer. Every instruction from your C/C++ program eventually reaches the CPU as machine code.
For example:
int a = 10;
int b = 20;
int c = a + b;
The CPU does not understand C.
The compiler converts it into machine instructions such as:
LOAD R1, a
LOAD R2, b
ADD R3, R1, R2
STORE c, R3
The CPU executes these one instruction at a time.
2. CPU Internal Organization
CPU
Every modern CPU mainly consists of
- Control Unit
- ALU
- Registers
- Cache
- Internal buses
3. CPU Components
Control Unit (CU)
The Control Unit acts like a manager.
Responsibilities:
- Fetch instructions
- Decode instructions
- Send control signals
- Coordinate execution
- Control memory access
Without the Control Unit,
nothing happens.
Example
Instruction:
ADD R1,R2
Control Unit tells
The ALU does not decide what to do.
The Control Unit tells it.
Arithmetic Logic Unit (ALU)
The ALU performs
- Arithmetic: +, -, *, /, %
- Logical: AND, OR, NOT, XOR, SHIFT
- Comparison: >, <, ==, !=
Example
10 + 20
ALU output
30
Registers
Registers are tiny memories inside the CPU.
They are the fastest storage available.
Example
Later we'll study each register individually.
Cache
Cache stores recently used data.
Without cache,
CPU would wait hundreds of clock cycles for RAM.
4. CPU Instruction Cycle
Every CPU repeats the same cycle millions or billions of times per second.
Step 1 — Fetch
CPU fetches the next instruction.
Step 2 — Decode
Control Unit understands
MOV
means Move data.
Step 3 — Execute
ALU executes
ADD, SUB, SHIFT, LOAD, STORE
Step 4 — Write Back
Result stored
Register or RAM
Example
a=10
b=20
c=a+b
Execution
5. Fetch–Decode–Execute Diagram
This cycle never stops while the CPU is running.
6. CPU Clock
CPU works according to a clock.
Example
3 GHz
means
3 Billion clock cycles/second
Each instruction takes one or more clock cycles.
Example
- ADD: 1 Cycle
- Multiply: 3 Cycles
- Division: 15 Cycles
(Not exact; varies by CPU.)
7. Single-Core vs Multi-Core
Single Core
Multi-Core
Each core executes instructions independently.
Operating systems schedule different processes or threads onto these cores.
8. Pipeline (High-Level)
Modern CPUs overlap instruction execution.
Without Pipeline
With Pipeline
| Cycle 1 | Fetch I1 | ||
|---|---|---|---|
| Cycle 2 | Decode I1 | Fetch I2 | |
| Cycle 3 | Execute I1 | Decode I2 | Fetch I3 |
Multiple instructions are in progress simultaneously, improving throughput.
9. ARM vs x86
| ARM | x86 |
|---|---|
| RISC | CISC |
| Simple instructions | Complex instructions |
| Lower power | Higher power |
| Mobile | Desktop/Server |
| Automotive | PC |
| Efficient | Feature rich |
Why ARM dominates automotive?
- Lower power
- Smaller silicon area
- Better thermal characteristics
- High performance per watt
- Widely licensed for embedded SoCs
Your ADAS platforms are likely based on ARM Cortex-A or Cortex-R families.
10. Embedded Example
Suppose
Camera captures image.
CPU executes
Each stage is a sequence of machine instructions.
11. OS Interaction with CPU
The OS never "runs" independently; it runs on the CPU just like applications, but with higher privileges (kernel mode).
12. Real-Life Analogy
Imagine a restaurant.
- Chef = CPU
- Recipe = Program
- Ingredients = Memory
- Kitchen Table = Registers
- Knife = ALU
- Manager = Control Unit
- Orders = Instructions
The chef repeatedly:
- Reads the next recipe step (Fetch)
- Understands it (Decode)
- Performs it (Execute)
- Places the result on the plate (Write Back)
13. Interview Questions
Beginner
- What is a CPU?
- What are the main CPU components?
- What is the role of the ALU?
- What is the Control Unit?
- What is a register?
Intermediate
- Explain the Fetch–Decode–Execute cycle.
- Why are registers faster than RAM?
- Why is cache needed?
- How does a multi-core CPU improve performance?
- What is instruction pipelining?
Senior
- Explain how the CPU executes
int c = a + b;. - What happens when the CPU encounters a branch instruction?
- How does pipelining affect performance?
- Why does ARM consume less power than x86?
- How does the OS use timer interrupts to implement multitasking?
Common Mistakes
- ❌ Thinking the ALU controls the CPU. (The Control Unit orchestrates execution.)
- ❌ Assuming the CPU executes C code directly. (It executes machine instructions.)
- ❌ Believing all instructions take one clock cycle. (Execution time varies.)
- ❌ Assuming multi-core CPUs automatically make every program faster. (The software must have parallel work to benefit.)
Summary
The CPU is responsible for executing machine instructions. It repeatedly performs the Fetch–Decode–Execute cycle using the Control Unit, ALU, registers, and caches. Understanding this internal flow is essential before learning about context switching, interrupts, memory management, and scheduling.
Mini Quiz
- Why can't the CPU execute C code directly?
- What is the role of the Control Unit?
- What is the difference between the ALU and the Control Unit?
- Why are registers faster than RAM?
- Explain the Fetch–Decode–Execute cycle in your own words.
- Why is ARM commonly used in embedded and automotive systems?
- Why doesn't adding more CPU cores always speed up a single-threaded application?
Concept Mastery Assessment — Module 02
Verify your conceptual understanding with 12 targeted technical assessment questions. Instant feedback and explanations are provided for every choice.