Browse Definitions :
Definition

program counter

What is a program counter?

A program counter is a special register in a computer processor that contains the memory address (location) of the next program instruction to be executed. Before the CPU fetches an instruction from memory, it references the program counter for the correct memory address. After the CPU fetches the instruction, it increases the program counter by 1 so it points to the next instruction in the program's sequence.

A program counter is sometimes referred to as an instruction pointer or instruction address register. The program counter makes it possible for the CPU to process a program's operations in an orderly fashion. A program is made up of a set of instructions that tell the CPU which steps to take and in what order. Each instruction is stored at a specific address in memory. The CPU fetches each instruction from memory one at a time, using the program counter as its guide.

What is the purpose of the program counter and instruction register?

The program counter and instruction register, both different types of registers, play a vital role in a processor's instruction cycle. A register is a small data holding place that the processor can access quickly.

The CPU knows which instruction to fetch from memory by referencing its address in the program counter. The instruction register holds the instruction after it is fetched from memory. Once the instruction is in the instruction register, the CPU can decode and execute it. In this sense, the instruction register is dependent on the program counter to ensure that the instruction register contains the correct instruction at any given time.

During a normal instruction cycle, the CPU fetches, decodes and executes one of the program's instructions. Before fetching the instruction from memory, the CPU retrieve's the instruction's address from the program counter. In this way, the CPU knows which instruction to retrieve. For example, if the program counter shows an address of 0851, the CPU knows that it should retrieve the program instruction located at the 0851 memory address.

After determining the correct address, the CPU fetches the instruction, places it into the instruction register, and increments the program counter by 1. The CPU then decodes the instruction in the instruction register. If the instruction is complete, the CPU executes the instruction and continues with the next instruction cycle.

The following image provides a simple overview of the roles that the program counter and instruction register play in the instruction cycle. Here, the program counter shows a memory address of 0005. This causes the CPU to fetch Instruction 6 from memory and load it into the instruction register. The CPU then updates the program counter, decodes Instruction 6, and executes the instruction. The program counter should now read 0006, which points to the next instruction.

A diagram showing how program counter works
Before the CPU fetches an instruction (located in the instruction register) from memory it references the program counter for the correct memory address. Then the CPU fetches the instruction with memory address 000 from memory. Once complete, the program counter increases by 1, and so on.

The figure shows the CPU and memory at their most basic. It does not include components such as the CPU's accumulator or arithmetic logic unit (ALU). The figure also indicates that each instruction fits neatly into a single memory space. In many cases, however, instructions are too large for a single memory location and must be split across multiple addresses.

Today's processors easily accommodate instructions that span multiple memory addresses. When the CPU decodes an instruction in the instruction register, it determines whether the instruction is complete. If it's not, it will fetch the next part of the instruction, again referring to the program counter. After all the instruction's parts are fetched into the instruction register, the CPU will execute the instruction in its entirety and then continue to the next instruction cycle.

Another situation that a CPU routinely encounters is a program's control flow logic. Such logic typically requires the processor to pull its instructions from memory in a nonsequential order. For example, the program might include a function call or conditional loop that requires access to specific instructions that are not next in line, because they're stored in memory.

When the CPU encounters this issue, it updates the program counter to the location specified by the current instruction. Then, when the CPU is ready to launch the next instruction cycle, it can fetch the address from the program counter because it now points to the correct location in memory.

If a computer is restarted or reset, the program counter normally reverts to 0.

Learn the differences between the CPU (central processing unit), GPU (graphics processing unit) and DPU (data processing unit), their use cases and how they help accelerate data center workloads. Explore how improvements in CPU features can help shape server hardware selection.

This was last updated in March 2024

Continue Reading About program counter

Networking
  • local area network (LAN)

    A local area network (LAN) is a group of computers and peripheral devices that are connected together within a distinct ...

  • TCP/IP

    TCP/IP stands for Transmission Control Protocol/Internet Protocol and is a suite of communication protocols used to interconnect ...

  • firewall as a service (FWaaS)

    Firewall as a service (FWaaS), also known as a cloud firewall, is a service that provides cloud-based network traffic analysis ...

Security
  • identity management (ID management)

    Identity management (ID management) is the organizational process for ensuring individuals have the appropriate access to ...

  • fraud detection

    Fraud detection is a set of activities undertaken to prevent money or property from being obtained through false pretenses.

  • single sign-on (SSO)

    Single sign-on (SSO) is a session and user authentication service that permits a user to use one set of login credentials -- for ...

CIO
  • IT budget

    IT budget is the amount of money spent on an organization's information technology systems and services. It includes compensation...

  • project scope

    Project scope is the part of project planning that involves determining and documenting a list of specific project goals, ...

  • core competencies

    For any organization, its core competencies refer to the capabilities, knowledge, skills and resources that constitute its '...

HRSoftware
  • recruitment management system (RMS)

    A recruitment management system (RMS) is a set of tools designed to manage the employee recruiting and hiring process. It might ...

  • core HR (core human resources)

    Core HR (core human resources) is an umbrella term that refers to the basic tasks and functions of an HR department as it manages...

  • HR service delivery

    HR service delivery is a term used to explain how an organization's human resources department offers services to and interacts ...

Customer Experience
  • martech (marketing technology)

    Martech (marketing technology) refers to the integration of software tools, platforms, and applications designed to streamline ...

  • transactional marketing

    Transactional marketing is a business strategy that focuses on single, point-of-sale transactions.

  • customer profiling

    Customer profiling is the detailed and systematic process of constructing a clear portrait of a company's ideal customer by ...

Close