Keil™, An ARM® Company

Technical Support

A51: READING THE PROGRAM COUNTER


Information in this article applies to:

  • C51 All Versions

QUESTION

How can I get the address currently in the program counter?

ANSWER

The 8051 has no direct way to read the program counter. However, there are several tricks you can use to get the contents of the program counter. Note that the address in the program counter is a 16-bit value. And, the program counter changes while executing code to get its address.

Method 1

       MOV DPTR,$

At this point, DPTR contains the address of the MOV DPTR instruction.

Method 2

       LCALL here
here:
       POP DPH
       POP DPL

At this point, DPTR contains the address of the here label.

MORE INFORMATION

  • Refer to MOV in the 8051 Instruction Set Manual.
  • Refer to LCALL in the 8051 Instruction Set Manual.

FORUM THREADS

The following Discussion Forum threads may provide information related to this topic.

Last Reviewed: Monday, January 08, 2007


Did this article provide the answer you needed?
 
Yes
No
Not Sure