How Does a CPU Work? | Fetch–Decode–Execute Cycle Explained with Animation
Summary
This video explains the fundamental process of how a computer's CPU executes instructions using a kitchen analogy. It details the fetch-decode-execute cycle, describing the roles of key components like the Program Counter (PC), Memory Address Register (MAR), Memory Data Register (MDR), Instruction Register (IR), Control Unit, and Arithmetic Logic Unit (ALU). The explanation clarifies the distinctions between related components, such as MAR vs. MDR and PC vs. IR, to help viewers understand the intricate steps involved in processing a single instruction.
Key Insights
The Memory Address Register (MAR) stores the address to be accessed.
The address from the Program Counter is copied into the Memory Address Register (MAR). The MAR's function is to store the memory address of the location being accessed, not the instruction itself.
The Memory Data Register (MDR) holds the fetched instruction or data.
The incoming instruction arrives at the Memory Data Register (MDR). The MDR stores the actual data or instruction being transferred between the CPU and memory.
The Instruction Register (IR) holds the currently processed instruction.
From the MDR, the instruction moves into the Instruction Register (IR). The IR holds the specific instruction the CPU is actively working on at that moment.
The Control Unit interprets the instruction held in the IR.
The Control Unit, acting as the 'head chef', receives the instruction from the Instruction Register (IR) and interprets its meaning. It identifies the operation (e.g., 'add') and the operands (e.g., 'seven' and 'five').
The instruction cycle (fetch-decode-execute) is the fundamental operation of a CPU.
This cyclical process is the core mechanism by which CPUs process commands and perform computations.
Sections
Introduction to CPU Instruction Execution
A CPU executes instructions almost instantly, but the internal process is complex.
The video introduces the concept of instant computer response to button clicks and poses the question of what actually happens inside the CPU.
The CPU is compared to a busy kitchen with specialized components.
An analogy is used where the CPU is likened to a kitchen, and its various parts are assigned specific roles to perform tasks.
The Fetch Stage of the Instruction Cycle
The Program Counter (PC) holds the address of the next instruction.
Before executing an instruction, the CPU needs to know where to find it. The Program Counter (PC) serves as a reminder, pointing to the memory address of the next instruction to be fetched. Initially, it points to memory address five.
The Memory Address Register (MAR) stores the address to be accessed.
The address from the Program Counter is copied into the Memory Address Register (MAR). The MAR's function is to store the memory address of the location being accessed, not the instruction itself.
The address bus carries the memory address from CPU to RAM.
The address stored in the MAR is sent to the computer's main memory (RAM) via the address bus. This signifies which specific memory location the CPU intends to access.
The control bus transmits control signals like 'read'.
Along with the address, the CPU sends a 'read' signal through the control bus. The control bus handles signals that dictate operations (like read or write), distinct from data or addresses.
RAM retrieves the instruction at the specified address.
With the address and the read signal received, RAM accesses the specified memory location (e.g., location five) and retrieves the instruction, such as 'add seven, five'.
The data bus transfers instructions or data back to the CPU.
The retrieved instruction travels back to the CPU along the data bus. The data bus is bi-directional, capable of carrying either instructions/data into the CPU or out to memory.
The Memory Data Register (MDR) holds the fetched instruction or data.
The incoming instruction arrives at the Memory Data Register (MDR). The MDR stores the actual data or instruction being transferred between the CPU and memory.
The Instruction Register (IR) holds the currently processed instruction.
From the MDR, the instruction moves into the Instruction Register (IR). The IR holds the specific instruction the CPU is actively working on at that moment.
The Program Counter updates to the next instruction's address after fetch.
Once an instruction is fetched, the Program Counter is updated to point to the memory address of the subsequent instruction (e.g., from address five to six), preparing for the next cycle.
The Decode Stage
The Control Unit interprets the instruction held in the IR.
The Control Unit, acting as the 'head chef', receives the instruction from the Instruction Register (IR) and interprets its meaning. It identifies the operation (e.g., 'add') and the operands (e.g., 'seven' and 'five').
The Control Unit orchestrates subsequent actions without performing them.
The Control Unit understands the instruction and determines which other CPU components are needed, like the ALU for arithmetic operations, but it does not perform the calculations itself.
The Execute Stage
The ALU performs the operation specified by the instruction.
The Control Unit directs the Arithmetic Logic Unit (ALU), the 'cook', to perform the required operation. In the example 'add seven, five', the ALU calculates 7 + 5.
The Accumulator stores the intermediate result of the execution.
The result of the operation (e.g., 12) is stored in a special register called the Accumulator (AC), which holds intermediate results for potential use in subsequent operations.
Summary of the Fetch-Decode-Execute Cycle
The CPU repeatedly cycles through Fetch, Decode, and Execute.
The entire process of fetching an instruction, decoding its meaning, and executing the required operation is performed continuously by the CPU.
Fetch: PC -> MAR -> Address Bus -> RAM; RAM -> Data Bus -> MDR -> IR; PC increments.
Recap of the fetch stage: PC provides address to MAR, address bus sends to RAM, control bus signals read, RAM returns instruction via data bus to MDR, then IR; PC advances.
Decode/Execute: Control Unit interprets, ALU calculates, result stored.
Recap of decode and execute: Control unit decodes the instruction from IR, directs ALU to perform the calculation, and the result is stored, often in the accumulator.
The instruction cycle (fetch-decode-execute) is the fundamental operation of a CPU.
This cyclical process is the core mechanism by which CPUs process commands and perform computations.
Key Register Distinctions
MAR stores memory addresses; MDR holds data/instructions being transferred.
Clarification: MAR remembers 'where' to look in memory (e.g., address five), while MDR holds 'what' is being transferred (e.g., 'add seven five').
PC holds the next instruction's address; IR holds the current instruction.
Clarification: The Program Counter (PC) tracks 'what comes next' (e.g., address six), whereas the Instruction Register (IR) holds 'what is happening now' (e.g., 'add seven five').
Control Unit directs operations; ALU performs calculations.
Clarification: The Control Unit is the orchestrator ('controls'), while the ALU is the performer of calculations ('calculates').
Interactive Challenge and Conclusion
Quiz questions reinforce understanding of register functions.
A quick challenge asks viewers to identify registers: MAR for current address, IR for current instruction, PC for next instruction address.
The kitchen analogy represents electronic circuits performing specific jobs.
The video emphasizes that the kitchen analogy is a facilitator for understanding; actual CPU components are electronic circuits, not literal kitchen items. Technical terms should be used in formal contexts.
Real CPUs may handle instructions and operands differently than the example.
The 'add 7 5' example is simplified; actual CPUs might represent instructions and their associated data in more complex ways.
Ask a Question
*Uses 1 Wisdom coin from your coin balance






![AI Engineer Full Course in 3 Hours [FREE]](https://i.ytimg.com/vi/XFNggsFFZJw/hqdefault.jpg)




