Program counter

The program counter (also referred to as the instruction pointer (IP) in Intel x86 and Itanium microprocessors) is a processor register that indicates where a computer is in its program sequence.

In most processors, the program counter is incremented immediately after an instruction is retrieved. The memory address then points (“points to”) to the next instruction to be executed. In a processor where the incrementation precedes the fetch, the program counter points to the instruction currently being executed.

Instructions are usually retrieved sequentially from memory, but control transfer instructions can change the order by placing a new value in the program counter. Control transfer statements include branches (also called jumps), calls to subroutines, and returns. A control transfer that depends on the truth of a certain statement makes the computer follow a different sequence through the program under different circumstances.

A branch ensures that the next instruction is fetched from somewhere else in memory. A call to a subroutine call not only branches, but also stores the previous contents of the program counter somewhere in computer memory. A return statement retrieves the stored content from the program counter and puts this content back into the program counter. Then sequential execution of the instruction set following the call to the subroutine is resumed.