Section 2.9 Instruction Execution Process and Timing
A microcontroller CPU is powered by a finite-state machine that fetches, decodes, and executes each instruction. In the process, the program counter must be incremented or changed to reflect the next instruction to execute. Control signals are generated to carry out the instruction and enable access to any areas where data is read from or written to. An example state diagram depicting this fetch, decode, and execution process is shown in FigureΒ 2.9.1.
Each state is described below.
-
The next instruction in memory is read, indicated by the address stored in the program counter.
-
The instruction is decoded into a set of commands or signals for each of the components in the processor.
-
The program counter increments so that it points to the next location in memory.
-
Data is loaded from memory (or input device(s)) into register(s), the location of this data is usually stored in the instruction code as an operand.
-
If the ALU is required to execute the operation, the processor instructs the hardware to carry this out.
-
The result is written back to a memory location, to a register, or even to an output device.
Some microcontrollers use a concept known as pipelining to speed up the rate at which the CPU can process the next instruction. The timing of this process is depicted in FigureΒ 2.9.2.
