The Wayback Machine - https://web.archive.org/web/20240802193935/https://www.geeksforgeeks.org/what-is-program-counter/
Open In App

What is Program Counter?

Last Updated : 25 Oct, 2023
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report

Many complex components come together to make a computer system work seamlessly. One such essential element is the program counter. There is a register in a PC (program counter) processor that contains the address of the next instruction to be executed from memory.

In this article we learn what program counter is, how it works and many more. So, let’s start –

Before going to the direct topic, let us discuss some primary terminologies such as:

CPU (Central Processing Unit)

The full name of the CPU is Central Processing Unit. It is also known as a processor. CPU is the brain of the computer system.

It is an electronic microchip that processes the data and converts it into useful information based on the instructions given and controls all the functions of the computer system.

Instructions

Computer instructions are a group of machine language instructions and they are executed by a specific computer processor. Whatever instruction we give to the computer, it will work on its basis.

Memory

Computer memory is a device that is used to store data and information. In other words, “Computer memory is an important part of the computer in which data is stored, without memory the computer does not work.” .Memory includes RAM and ROM.

What is Program Counter?

There is a register in a PC (program counter) processor that contains the address of the next instruction to be executed from memory.

It is a 16-bit register and is also called instruction counter, instruction pointer, and instruction address register (IAR). PC (program counter) is a digital counter that is needed to execute tasks quickly and track the current execution point.

PC

All the instructions and data present in memory have a special address. As each instruction is processed, the program counter is updated to the address of the next instruction to be fetched. When a byte (machine code) is fetched, the PC is incremented by one. So that it can fetch the next instruction. If the computer is reset or restarted, the program counter returns to zero value.

For example, suppose the content of the PC is 8000H. This means that the processor wants to fetch the instruction byte on 8000H. After fetching the byte at 8000H, the PC automatically increments by one (1). In this way, the processor becomes ready to fetch the next byte of the instruction or to fetch the next opcode.

FAQs on Program Counter

Q.1: Can the program counter be modified?

Answer:

Yes, the program counter can be modified by certain instructions or events during program execution(prosecution). For illustration, raying instructions can change the program counter to deflect the inflow of prosecution to a different part of the program.

Q.2: What happens when the program counter is modified?

Answer:

When the program counter is modified, the central processing unit( CPU) will cost the instruction from the new address specified by the modified program counter. This allows for non-sequential execution(prosecution) and enables features like circles, conditionals, and function calls in programming languages.

Q.3: Is the program counter the same as a memory address?

Answer:

No , The program counter points to the coming instruction to be executed, whereas a memory address refers to a specific position in memory where data or instructions are stored.

Q.4: Can the program counter go backwards?

Answer:

In utmost cases, the program counter moves forward in a successful manner. still, there are certain instructions, similar as circles or jumps, that can beget the program counter to move backward or to a different position in memory.

Q.5: What happens if the program counter points to an invalid address?

Answer:

still, it can lead to a program crash or an error, If the program counter points to an invalid address. The central processing unit( CPU) may essay to cost an instruction from an invalid memory position, performing in undetermined behavior or an exception. 


Similar Reads

How to make counter section one by one in Bootstrap 5 ?
Counter-sections are often used on websites to highlight important statistics or achievements. They are effective in capturing the attention of visitors and conveying information in a visually pleasing manner. Bootstrap 5 provides classes and components that make it easy to create these sections. Configuring the Bootstrap 5 Before we dive into crea
3 min read
Word and Letter Counter using React
The word and letter counter is an application that counts the number of letters and words entered in text and give the number (count) of each in output. Each element present in the text will be considered a letter, and a group of letters with a space will be considered a word. Using this approach, we implement the counter. Preview of Final Output:
3 min read
Program for FCFS CPU Scheduling | Set 1
Given n processes with their burst times, the task is to find average waiting time and average turn around time using FCFS scheduling algorithm. First in, first out (FIFO), also known as first come, first served (FCFS), is the simplest scheduling algorithm. FIFO simply queues processes in the order that they arrive in the ready queue. In this, the
15+ min read
Longest Remaining Time First (LRTF) CPU Scheduling Program
We have given some processes with arrival time and Burst Time and we have to find the completion time (CT), Turn Around Time(TAT), Average Turn Around Time (Avg TAT), Waiting Time(WT), Average Waiting Time (AWT) for the given processes. Prerequisite: CPU Scheduling | Longest Remaining Time First (LRTF) algorithm LRTF is a preemptive scheduling algo
15+ min read
Program to show Belady's Anomaly
Prerequisite - Belady's Anomaly Belady's Anomaly is when the number of page faults increases even after increasing the number of frames. In this article, we demonstrate Belady's Anomaly using FIFO page replacement algorithm.Examples: Reference array is: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 Output : When number of frames is 3, page fault : 9 When numb
8 min read
Formation Of Process from Program
Process: A Process is a program in execution is called as Program. But the conversion of a program into process involves various stages which are clearly defined in this article. Further more after the program is converted into the process memory has to be allocated to these process in the main memory and these memory allocations are handled by O.S
5 min read
Program for Best Fit algorithm in Memory Management using Linked List
Best fit algorithm for memory management: The memory partition in which there is a minimum loss on the allocation of the process is the best-fit memory partition that is allocated to the process.We have already discussed one best-fit algorithm using arrays in this article. However, here we are going to look into another approach using a linked list
15+ min read
Xv6 Operating System -add a user program
Xv6 is a re-implementation of the Unix sixth edition in order to use as a learning tool. xv6 was developed by MIT as a teaching operating system for their “6.828” course. A vital fact about xv6 is that it contains all the core Unix concepts and has a similar structure to Unix even though it lacks some functionality that you would expect from a mode
3 min read
Concurrent Program with Precedence Graph
In this article, we are going to cover the Concurrent Program in the Operating System and will make a Precedence Graph for the program, and will cover the program execution for the same. In concurrent programming, the Real concurrent program is possible on the multiprocessor system. Any two statements Si and Sj can be executed concurrently or paral
2 min read
JavaScript Program for Converting given Time to Words
This article will show you how to convert the given time into words in JavaScript. The given time will be in 12-hour format (hh: mm), where 0 < hh < 12, and 0 <= mm < 60. Examples: Input : hh = 6, mm = 20Output : Six Hour, Twenty MinutesInput : hh = 8, mm = 24Output : Eight Hour, Twenty Four MinutesApproach: First, we create an array co
2 min read
three90RightbarBannerImg