The Program Counter (PC) register is crucial for maintaining the CPU's instruction sequence.
It stores the memory address of the next instruction (e.g., adding two numbers, storing a number, etc.,) to be fetched and executed by the CPU.
After each instruction is completed, the PC updates to point to the following instruction, ensuring a smooth and orderly program flow.
In cases where an instruction requires a jump or branch to a different part of the program (think about the moment you want to exit a loop: you want to jump to the code below the loop,) the PC is adjusted accordingly to reflect this new path.
Every program stores its own value in the program counter register, so when programs must 'switch' on the CPU, the previous program's program counter is copied from the CPU to main memory, while the next program's counter is copied from main memory into the CPU.