Keil Logo

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.

Last Reviewed: Thursday, February 25, 2021


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.