Inside the CPU: fetch, decode, execute
Registers, the ALU, the program counter, and the loop that fetches and executes instructions. This loop is all a CPU does.
Components
- Program counter (PC): the address of the next instruction to run
- Register file: very fast storage inside the CPU. Cortex-M has r0 to r15
- ALU: the calculator that adds, subtracts, does bit operations and compares
- Control unit: decodes the instruction and signals each part what to do
- Status register: flags recording whether the result was zero, negative, or produced a carry
Instruction cycle
- Fetch: read the instruction at the address the PC points to
- Decode: work out which operation it is and which registers it uses
- Execute: the ALU calculates, or memory is read or written
- Move the PC to the next instruction and go back to 1
A branch instruction changes the PC directly and sends the flow elsewhere. if and for become a compare instruction + a conditional branch in machine code.
From the embedded point of view
A 72 MHz CPU that handles most instructions in one clock executes about 72 million instructions a second. This number is the starting point when you work out the time budget of a control loop.