The fetch-decode-execute cycle represents the steps that a computer follows to run
a program. The CPU fetches an instruction (transfers it from main memory to the
instruction register), decodes it (determines the opcode and fetches any data necessary
to carry out the instruction), and executes it (performs the operation(s) indicated
by the instruction). Notice that a large part of this cycle is spent copying data
from one location to another. When a program is initially loaded, the address of the
first instruction must be placed in the PC. The steps in this cycle, which take place
in specific clock cycles, are listed below. Note that Steps 1 and 2 make up the fetch
phase, Step 3 makes up the decode phase, and Step 4 is the execute phase.
1. Copy the contents of the PC to the MAR: MAR← PC.
2. Go to main memory and fetch the instruction found at the address in the MAR,
placing this instruction in the IR; increment PC by 1 (PC now points to the
next instruction in the program): IR ← M[MAR] and then PC ← PC+1. (Note:
Because MARIE is word-addressable, the PC is incremented by one, which
results in the next word’s address occupying the PC. If MARIE were byteaddressable,
the PC would need to be incremented by 2 to point to the address
of the next instruction, because each instruction would require two bytes. On a
byte-addressable machine with 32-bit words, the PC would need to be incremented
by 4.)
3. Copy the rightmost 12 bits of the IR into the MAR; decode the leftmost four
bits to determine the opcode, MAR← IR[11–0], and decode IR[15–12].
4. If necessary, use the address in the MAR to go to memory to get data, placing
the data in the MBR (and possibly the AC), and then execute the instruction
MBR← M[MAR] and execute the actual instruction.
This cycle is illustrated in the flowchart in Figure 4.11.
Note that computers today, even with large instruction sets, long instructions,
and huge memories, can execute millions of these fetch-decode-execute cycles in
the blink of an eye.