Module 6 — Instruction Register (IR) & Fetch–Decode–Execute Cycle
Learning Objectives
By the end of this module, you should be able to explain:
- What is the Instruction Register (IR)?
- Why is it needed?
- What happens after the Program Counter points to an instruction?
- How does the CPU understand an instruction?
- What does the Control Unit do?
- What are micro-operations?
- How do instructions move through the CPU?
- How does this relate to Operating Systems?
1. What is an Instruction?
Suppose we write
int c = a + b;
The CPU cannot understand C.
Compiler converts it into machine instructions.
Example
LOAD R1, [a]
LOAD R2, [b]
ADD R3, R1, R2
STORE [c], R3
Each line above is an instruction.
What is an Instruction?
An instruction tells the CPU
Perform one operation.
Examples
- ADD
- SUB
- LOAD
- STORE
- MOV
- JMP
- CALL
- RET
- CMP
Everything the CPU does is made from these basic instructions.
2. Instruction Register (IR)
The Instruction Register stores the instruction currently being executed.
Think of it as the CPU's current working instruction.
Example
Memory
Program CounterPC =1000
CPU fetchesLOAD R1,a
Instruction Register now contains
Only after the instruction is copied into the IR does the CPU decode and execute it.
Visualization
3. Why Do We Need an Instruction Register?
Suppose CPU directly executed instructions from RAM.
Problem
RAM is much slower than the CPU.
Instead
The IR provides a stable copy of the current instruction while the CPU decodes and executes it.
4. Fetch–Decode–Execute Cycle
Every processor repeatedly performs:
This happens billions of times every second.
5. Step 1 — Fetch
SupposePC =1000
CPU performsMemory[1000]
ReturnsADD R1,R2
Instruction copied into IR.
PC updated1004
Diagram
Step 2 — Decode
Instruction RegisterADD R1,R2
Control Unit asks
What instruction is this?
AnswerADD
Operands?R1R2
Destination?R1
Decoded successfully.
Step 3 — Execute
Control Unit enables
- ALU
- Registers
- Internal buses
Execution
Step 4 — Write Back
Result storedR1=30
Now
Program Counter already points to the next instruction.
Cycle repeats.
Complete Execution
Suppose
LOAD R1,a
LOAD R2,b
ADD
STORE
Execution
This never stops while the CPU is running.
6. What Does the Control Unit Actually Do?
Many engineers think the ALU controls the CPU.
Wrong.
The Control Unit is the brain inside the CPU.
Responsibilities
- Reads IR
- Decodes instruction
- Generates control signals
- Enables registers
- Starts ALU
- Reads memory
- Writes memory
- Updates PC
Without the Control Unit
nothing executes.
Example
InstructionADD R1,R2
Control Unit internally performs
7. Micro-Operations
A single instruction is actually broken into many smaller hardware steps called micro-operations.
Example
InstructionLOAD R1,[2000]
Internally
One assembly instruction often becomes multiple micro-operations.
8. Machine Instruction Format
An instruction contains fields.
ExampleADD R1,R2
Internally
| Opcode | Destination Register | Source Register |
|---|---|---|
| 0001 | 001 | 010 |
Meaning
The CPU decodes these bit fields.
9. Example Execution
Suppose
RegistersR1=5R2=8
InstructionADD R1,R2
Execution
10. Real Embedded Example
Suppose
Camera frame arrives.
Driver
Every instruction inside the ISR follows the same Fetch–Decode–Execute cycle.
Whether it's a simple MOV or a complex algorithm, the CPU still executes one machine instruction at a time (or multiple simultaneously in a pipelined processor, as we'll see later).
11. Relation to Operating Systems
The OS itself is just another program executing instructions.
Scheduler
Context Switch
Interrupt Handler
The CPU doesn't know it's running an operating system—it simply executes instructions according to the current privilege level and execution state.
12. ARM Example
InstructionADD R0,R1,R2
MeaningR0 = R1 + R2
Execution
x86 Example
InstructionADD EAX,EBX
MeaningEAX=EAX+EBX
Same CPU cycle
13. Complete CPU Data Flow
This diagram captures the essence of instruction execution.
14. Why Is This Important?
Every OS concept builds on this:
- Process execution
- Thread execution
- Interrupts
- Scheduling
- Context Switching
- Virtual Memory
- Device Drivers
Without the Fetch–Decode–Execute cycle, nothing in the system runs.
Interview Questions
Beginner
- What is the Instruction Register?
- What is an instruction?
- Explain the Fetch–Decode–Execute cycle.
- What is the role of the Control Unit?
Intermediate
- What happens after the Program Counter identifies an instruction?
- Why do we need an Instruction Register?
- Explain the execution of an ADD instruction.
- What is an opcode?
Senior
- Explain how a CPU executes one machine instruction internally.
- What are micro-operations?
- How does the Control Unit generate control signals?
- Why are instructions broken into micro-operations?
- How does the Fetch–Decode–Execute cycle interact with pipelining?
Common Mistakes
- ❌ Thinking the CPU executes C statements directly. It executes machine instructions.
- ❌ Believing the Instruction Register stores an entire program. It stores only the current instruction.
- ❌ Assuming one assembly instruction always maps to one hardware action. Many instructions require multiple micro-operations.
- ❌ Thinking the ALU controls execution. The Control Unit orchestrates the entire process.
Summary
The Instruction Register temporarily holds the instruction currently being processed by the CPU. The processor repeatedly performs the Fetch–Decode–Execute cycle: it fetches the instruction pointed to by the Program Counter, stores it in the Instruction Register, decodes it using the Control Unit, executes it using the ALU and registers, writes back the result, and proceeds to the next instruction. This cycle underpins every program, operating system, interrupt handler, and device driver.
Mini Quiz
- Why is an Instruction Register needed?
- What are the four major stages of the instruction cycle?
- What is the role of the Control Unit?
- What is an opcode?
- Why can a single assembly instruction require multiple micro-operations?
- Does the CPU distinguish between application code and operating system code during execution?
- What happens immediately after an instruction is fetched?
Concept Mastery Assessment — Module 06
Verify your conceptual understanding with 12 targeted technical assessment questions. Instant feedback and explanations are provided for every choice.