Describe the fetch, decode and execute cycle
The fetch decode execute (FDE) cycle is the fundamental cycle of instruction execution — also called the instruction cycle.
- Fetch: CPU fetches an instruction from memory (RAM).
- Decode: CPU interprets the instruction into low-level operations it can execute.
- Execute: CPU carries out the low-level operations specified by the decoded instruction.
Fetch Phase
CPU retrieves a machine-language instruction from main memory (RAM): CPU requests instruction from RAM; address goes to MAR; fetched instruction transfers to IR.
- Address Identification: PC’s address moves to MAR (internal CPU bus).
- Address Transmission: MAR puts address on the Address Bus (unidirectional, CPU → RAM).
- Command Issuance: CU asserts a signal on the Control Bus.
- Data Retrieval: RAM receives address + READ command, places instruction onto Data Bus (instructions and data both known as data).
- Data Reception: Instruction travels Data Bus (bidirectional) into MDR. → MDR holds instruction/data transferred to/from memory.
- Instruction Loading: Instruction transfers from MDR to IR for the rest of the cycle. → IR holds the current instruction being executed.
- Preparation: PC is incremented to the next instruction address (usually automatic).
Decode Phase
CPU interprets the machine-language instruction. Mostly done by the CU, which analyzes:
- Opcode (operation code): dictates (规定) the type of operation
- Operands: the data/address to be operated on
- Addressing Modes: determine how to load the operands
Process — the CU interprets the instruction in IR and determines execution steps:
- Instruction Analysis: CU examines instruction in IR; parses Opcode (e.g., ) and Operand.
- Control Signal Preparation: CU generates the micro-operation sequence (control signals) for Execute phase. Transmitted via Control Bus.
- Address Staging: If the instruction needs RAM data (e.g., ) or writes back (e.g., ), the operand address moves from IR into MAR. ACC remains static this phase.
Execute Phase
CPU performs the operation specified by the opcode. Common operations:
- Arithmetic: addition, subtraction, multiplication, division (done by ALU).
- Logical: , , (done by ALU).
- Memory Access: load (read from memory to register) and store (write from register to memory).
- Control: conditional/unconditional jumps that alter execution flow.
Process — CU coordinates components based on instruction type:
A. Data Transfer to/from RAM (e.g., , )
- MAR sends data address → Address Bus.
- CU asserts or → Control Bus.
- : RAM → Data Bus → MDR → ACC.
- : ACC → MDR → Data Bus → RAM.
B. Arithmetic/Logic Operations (e.g., , )
- Data sources (often ACC and MDR with data from RAM) supplied to ALU via internal CPU bus.
- CU sends the operation command (e.g., ) to ALU via Control Bus.
- ALU performs the calculation.
- Result written back to ACC, ready for next operation.
Cycle Completion: CU signals end of cycle; CPU loops back to Fetch using updated PC.
Examples of the FDE Cycle
(1) WRITE Value 0x7E to Address 0x4F2
1. FETCH Phase — Getting the Instruction
- () (Internal CPU Bus).
- ().
- Address Bus.
- CU sends Control Bus.
- Data Bus .
- (Internal CPU Bus).
2. DECODE Phase — Setting Up the Write
- CU decodes from IR; identifies as .
- () .
- () .
3. EXECUTE Phase — Writing to Memory
- () Address Bus.
- CU sends Control Bus.
- () Data Bus.
- RAM receives address, command, and data.
- is set to .
Cycle Complete
- CU signals end of cycle.
- CPU loops back to FETCH using ().
(2) Comparison Instruction:
Compare R1 with R2. Result only sets CPU Status Flags (Zero, Carry, etc.); no register receives the output.
1. FETCH Phase
- () .
- ().
- Address Bus.
- CU sends Control Bus.
- Data Bus .
- ( now in IR).
2. DECODE Phase
- CU decodes from IR.
- Identifies it as an ALU op requiring R1 and R2.
- Prepares signals to use ALU for subtraction; result is not stored in a register like ACC.
3. EXECUTE Phase
- Preparation: () and () → ALU inputs. Comparison = subtraction: .
- ALU Operation: CU sends → ALU via Control Bus.
- Result and Flags: ALU computes .
- Arithmetic result () is discarded.
- The condition is used by ALU to set CPU Status Flags.
- Flag Setting (result = 5, positive, non-zero):
- Zero Flag cleared (0).
- Carry Flag (Borrow) cleared (0, unsigned).
- Sign/Negative Flag cleared (0).
- Control Flow Enablement: these flags now enable conditional instructions (, , etc.) to alter PC based on this comparison.
Cycle Complete
- CU signals cycle end.
- CPU begins next FETCH from ().