Top Qs
Timeline
Chat
Perspective
Program counter
Register that stores where in a program a processor is executing From Wikipedia, the free encyclopedia
Remove ads
A program counter (PC)[1] is a register that stores where a computer program is being executed by a processor.[2] It is also commonly called the instruction pointer (IP) in Intel x86 and Itanium microprocessors, and sometimes called the instruction address register (IAR),[3][1] the instruction counter,[4] or just part of the instruction sequencer.[5]
This article needs additional citations for verification. (February 2025) |

Usually, a PC stores a memory address to an instruction. Further, it usually is incremented after fetching an instruction, and therefore points to the next instruction to be executed.[6] For a processor that increments before fetch, the PC points to the instruction being executed. In some processors, the PC points some distance beyond the current instruction. For instance, in the ARM7, the value of PC visible to the programmer points beyond the current instruction and beyond the delay slot.[7] For modern processors, the location of execution in the program is complicated by instruction-level parallelism and out-of-order execution.
By default, a processor fetches instructions sequentially from memory, but a control transfer instruction changes the sequence by writing a value in the PC. A branch allows the next instruction to be fetched from elsewhere in memory. A function call not only branches but caches the value of the PC. A return restores the value in the PC to resume execution with the instruction following the call. A transfer that is conditional on the truth of some condition lets the computer follow a different sequence under different conditions.
Remove ads
Hardware implementation
Summarize
Perspective
In a simple central processing unit (CPU), the PC is a digital counter (which is the origin of the term "program counter") that may be one of several hardware registers. The instruction cycle[8] begins with a fetch, in which the CPU places the value of the PC on the address bus to send it to the memory. The memory responds by sending the contents of that memory location on the data bus. (This is the stored-program computer model, in which a single memory space contains both executable instructions and ordinary data.[9]) Following the fetch, the CPU proceeds to execution, taking some action based on the memory contents that it obtained. At some point in this cycle, the PC will be modified so that the next instruction executed is a different one (typically, incremented so that the next instruction is the one starting at the memory address immediately following the last memory location of the current instruction).
Like other processor registers, the PC may be a bank of binary latches, each one representing one bit of the value of the PC.[10] The number of bits (the width of the PC) relates to the processor architecture. For instance, a “32-bit” CPU may use 32 bits to be able to address 232 units of memory. On some processors, the width of the program counter instead depends on the addressable memory; for example, some AVR microcontrollers have a PC which wraps around after 12 bits.[11]
If the PC is a binary counter, it may increment when a pulse is applied to its COUNT UP input, or the CPU may compute some other value and load it into the PC by a pulse to its LOAD input.[12]
To identify the current instruction, the PC may be combined with other registers that identify a segment or page. This approach permits a PC with fewer bits by assuming that most memory units of interest are within the current vicinity.
Remove ads
Consequences in machine architecture
Use of a PC that normally increments assumes that what a computer does is execute a usually linear sequence of instructions. Such a PC is central to the von Neumann architecture. Thus programmers write a sequential control flow even for algorithms that do not have to be sequential. The resulting “von Neumann bottleneck” led to research into parallel computing,[13] including non-von Neumann or dataflow models that did not use a PC; for example, rather than specifying sequential steps, the high-level programmer might specify desired function and the low-level programmer might specify this using combinatory logic.
This research also led to ways to making conventional, PC-based, CPUs run faster, including:
- Pipelining, in which different hardware in the CPU executes different phases of multiple instructions simultaneously.
- The very long instruction word (VLIW) architecture, where a single instruction can achieve multiple effects.
- Techniques to predict out-of-order execution and prepare subsequent instructions for execution outside the regular sequence.
Remove ads
Consequences in high-level programming
Modern high-level programming languages still follow the sequential-execution model and, indeed, a common way of identifying programming errors is with a “procedure execution” in which the programmer's finger identifies the point of execution as a PC would. The high-level language is essentially the machine language of a virtual machine,[14] too complex to be built as hardware but instead emulated or interpreted by software.
However, new programming models transcend sequential-execution programming:
- When writing a multi-threaded program, the programmer may write each thread as a sequence of instructions without specifying the timing of any instruction relative to instructions in other threads.
- In event-driven programming, the programmer may write sequences of instructions to respond to events without specifying an overall sequence for the program.
- In dataflow programming, the programmer may write each section of a computing pipeline without specifying the timing relative to other sections.
See also
- Branch prediction – Digital circuit
- Instruction cache – Hardware cache of the central processing unit
- Instruction cycle – Basic instruction cycle in a computer
- Instruction unit – Computer component responsible for organising program instructions to be fetched from memory
- Instruction pipeline – Method of improving instruction-level parallelism
- Instruction register – Register in a CPU control unit holding the currently-executing instruction
- Instruction scheduling – Compiler optimization technique
- Program status word – Computer processor element
Remove ads
References
Wikiwand - on
Seamless Wikipedia browsing. On steroids.
Remove ads
