How to know the program counter value in any microcontroller?

Status
Not open for further replies.

Surender Reddy

Full Member level 2
Joined
Jan 28, 2012
Messages
129
Helped
7
Reputation
14
Reaction score
7
Trophy points
1,298
Location
Bangalore, India
Visit site
Activity points
2,186
How to know the program counter value in any microcontroller?
As I have read, Atmega8 have 12-bit program counter and PIC18F452 have 21-bit program counter.
Program counter is one which holds the address of next instruction to be executed.but
How to read the value of program counter .i.e How many instructions it is executed?
 

Hi,

if you can´t access it with registers, then:

perfom a "call" and within the called function read the contents of the stack.
Mind not to change the stack pointer.


Klaus
 

Program counter is part of architecture which change per machine cycle in case of 1 instrunction/cycle rate is there. and it is not accessible.
alteration to this value may cause undetermined program execution.
 

In many IDEs, download the code and debug options are there.

You can also do step by step execution of the code.

You have simulator options in IDEs.


Or else, the board or chip should have in circuit debugger.
 

controller may share all data with ICD but not accessible.
 

Without reading the value of PC, How can we know that it fetch the next instruction?
It is One of my interview question with one MNC.
Program counter is part of architecture which change per machine cycle in case of 1 instrunction/cycle rate is there. and it is not accessible.
alteration to this value may cause undetermined program execution.
 

see while debugging u can see that in keil ide tool a register name PC is stored in it.it After each execution u will see that the pc shows the values of next instruction set.what ide u r using?
 

Here i am using Mplax IDE for PIC18f452 & Avr Studio6 fot Atmega32.........
see while debugging u can see that in keil ide tool a register name PC is stored in it.it After each execution u will see that the pc shows the values of next instruction set.what ide u r using?
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…