the program counter
/ P-C /
The program counter is the processor's bookmark: a special register that holds the memory address of the instruction the machine is about to run. Reading a program is like reading a book from top to bottom, and the program counter is your finger on the current line. After each instruction it advances to the next one, the same way your finger slides down to the line below — and a branch or jump is what lets you flip to a different page entirely.
Mechanically it works like this: to run an instruction, the processor fetches whatever lives at the address in the program counter, then (for ordinary instructions) increments the program counter to point at the following instruction — in RISC-V that means adding 4, because each instruction is 4 bytes. Branches and jumps work precisely by overwriting the program counter with a computed address instead of the usual +4, so the next fetch comes from somewhere new. The program counter is therefore the single piece of state that captures 'where am I in the program right now'.
Although it is one of the most important registers, it is special: in RISC-V it is not one of the 32 general-purpose registers and you cannot use it as an arithmetic operand the way you use x5. It is updated as a side effect of running instructions and of control flow. A subtle point: the program counter holds an address (a location in memory), not a count of how many instructions have run — the name is historical. When a program crashes, the saved program counter value is often the first clue, because it tells you exactly which instruction was executing.
If the program counter holds address 0x1000 and the instruction there is a normal add, after it runs the program counter becomes 0x1004 (the next 4-byte instruction). If instead it were a taken branch to 0x2000, the program counter would jump to 0x2000.
Normally the PC just advances by one instruction; branches and jumps overwrite it.
Despite its name, the program counter stores an address, not a tally. And it normally advances by the instruction size (4 bytes in base RISC-V), not by 1 — so 'increment the PC' means 'add 4', not 'add 1'.