Keil Logo

GENERAL: HOW CAN I SET THE PROGRAM COUNTER IN C OR ASSEMBLY?


Information in this article applies to:

  • C166 All Versions
  • C251 All Versions
  • C51 All Versions

QUESTION

I have not found a way to set the program counter (PC) to a selected source line in a C (or assembly) file. Is there a way to do this?

ANSWER

In C or assembly, there is no way to directly manipulate the program counter since it is not defined in the SFR space. However, you can use the jump instructions in assembly to change the program to any part of your code memory.

In the debugger, you may set the program counter by assign a new value to $. For example:

$ = 0x1234

sets the program counter to 1234h in the simulator.

To set the program counter to the address of a line of C code, you may use the name of the file and the line number. For example:

$ = \main\34

sets the program counter to the address of line 34 in the main.c file. Of course, line 34 must have executable code on it.

SEE ALSO

Last Reviewed: Wednesday, March 20, 2002


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.