How a CPU runs one instruction
A CPU runs a program one instruction at a time. The idea to keep: a register called the program counter points at an instruction, and the CPU fetches it, decodes it, executes it, then moves on.
The short version
Arm describes its instructions with a simple model: the processor fetches an instruction, decodes it and executes it, in the order the instructions sit in memory. Real processors overlap these steps, so this is simplified, but they must give the same result as if they ran one at a time. In RISC-V, the program counter (pc) holds the address of the current instruction, and fetching it is an implicit read from memory.
Step by step
- The pc holds the address of the current instruction.
- Fetch: the CPU reads that instruction from memory. In RV32I, every instruction is 32 bits and sits on a 4-byte boundary.
- Decode: it works out which operation the bits ask for.
- Execute:
ADD x3, x1, x2reads x1 and x2 and writes the sum to x3, ignoring overflow. Only load and store instructions touch memory; arithmetic works on registers. - The pc moves to the next instruction. A jump can send it elsewhere:
JALadds an offset to its own address and saves pc+4 in a register to return to.
Why it matters
This loop is why a program is a list: the order in memory is the order of work, until a jump says otherwise. Pipelines make the loop faster, not different: Arm requires the result to match the one-at-a-time model.
Sources
- Simple sequential execution — Arm A64 Instruction Set Architecture Guide — fetch, decode, execute in order; real processors overlap steps but must match this model
- RV32I Base Integer Instruction Set — RISC-V ISA manual — the pc holds the current instruction's address, fixed 32-bit instructions on 4-byte boundaries,
ADD, load/store,JAL - Introduction — RISC-V ISA manual — instruction fetch is an implicit memory read