A CPU does the same three things over and over, for as long as it runs:
- Fetch: read the instruction the program counter points at, and advance the PC.
- Decode: work out what the instruction asks for, from its opcode.
- Execute: carry it out.
Then it starts again with the next instruction.
In Tiny8, each step of the cycle is one or more clock cycles:
- F1
MAR ← PC - F2
MDR ← M[MAR], PC ← PC + 1 - F3
IR ← MDR - D decode IR[7:4];
MAR ← IR[3:0] - E1 and possibly E2, depending on the instruction.
Fetch and decode are identical for every instruction; only execute differs. So LOAD, STORE, ADD and SUB take 3 + 1 + 2 = 6 cycles, and JMP, JZ and HALT take 3 + 1 + 1 = 5.
HALT is the only way out: it leaves the control unit stuck in E1, so the loop stops.