The instruction cycle, also called the fetch-decode-execute cycle is the cycle that the CPU follows from boot-up to shutdown. Execution of instructions in CPU-land is cyclical and infinite and it operates in the three following stages described below. Also note that most processors also support interrupts.
Fetch
Load the next instruction from memory. This is done via the program counter.
Decode
Figure out from the instruction what needs to be done. The ISA will usually specify what a certain operation translates to in machine code.
Execute
Do what the instruction specifies.
CPU Instructions
CPU instructions are usually very simple. Some examples are
- Reading from memory
- Writing/storing to memory
- Simple arithmetic like adding two numbers
- Bitwise Operations
- Control flow Some of these operations are executed by the ALU.
Initiation
Non-testable
At startup, the first instruction cycle begins with an initial PC value that is predefined by the system’s architecture. For example for AMD architecture CPUs it’s 0x00000000. Typically this address points to a set of instructions in read-only memory (ROM) which begins the process of booting the operating system.