Sub topic 2
The Stored-Program Model and the Instruction Cycle
Assume you know binary and hexadecimal numbers, basic logic gates, registers, and memory. This chapter explains how a processor retrieves and executes instructions stored in memory.
The stored-program model
The stored-program model stores both program instructions and data in memory. An instruction is a binary pattern that tells the processor what operation to perform, such as adding two registers or loading a value from memory.
The processor uses a register called the program counter (PC). The PC contains the address of the next instruction. After fetching an instruction, the processor usually increments the PC so that it points to the following instruction. A branch or jump instruction can replace the PC with a different address.
The instruction itself is copied into the instruction register (IR). The control unit decodes the bit fields in the IR and generates control signals for the datapath, registers, memory, and arithmetic logic unit (ALU).
The fetch-decode-execute cycle
The processor repeats these stages:
- Fetch: Read the instruction from the memory address held in the PC.
- Decode: Interpret the opcode and identify registers, constants, and addressing information.
- Execute: Perform the requested operation.
- Memory access: Read or write memory when the instruction requires it.
- Write-back: Store the result in a register or another destination.
Some processors combine or pipeline these stages. The logical sequence remains the same.
A simple register-transfer description is:
T0: MAR <- PC
T1: MDR <- M[MAR], PC <- PC + 1
T2: IR <- MDR
T3: Decode IR and select the execute sequenceThe memory address register (MAR) holds the address for a memory operation. The memory data register (MDR) holds data moving between the processor and memory. M[MAR] means the contents of memory at the address in MAR. The arrows show transfers controlled by clock steps.
A worked instruction example
Suppose the instruction ADD R1, R2 means:
R1 <- R1 + R2During decoding, the control unit identifies ADD as the operation and R1 and R2 as source and destination registers. During execution, the register file supplies both values to the ALU. The ALU adds them, and the result is written into R1. The control unit may also update status flags such as zero, carry, or overflow.
Exercise
During fetch, what are the usual values after T1 if PC initially contains 200 and each instruction occupies one memory word?
Show answer
MDR contains M[200], and PC contains 201. The instruction is then copied from MDR to IR during T2.