This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How to obtain the current value of Program Counter

Other Parts Discussed in Thread: TMS320C6747

I need to obtain the current value of PC, but cannot seek the instructions to get it. I work on TMS320C6747. How can I get it?

  • Shan Wang,

    Welcome to the TI E2E forum. I hope you will find many good answers here and in the TI.com documents and in the TI Wiki Pages. Be sure to search those for helpful information and to browse for the questions others have asked on similar topics.

    It does seem like a similar question came up a couple of years ago, so make your search be wide enough to include all of ARM& DSP Microprocessors forums.

    There is no direct C relationship with the DSP's PC, so there is not direct way within C to get this value. but I seem to recall cases where we made suggestions of ways to get approximate values at run-time.

    The exact reason for your request would be helpful. For example, when you halt the processor in CCS, you can examine the Core Registers (View->Registers) and find the current PC value, or you can open a Disassembly Window and view the PC where the current execution pointer is located.

    Or you could write a small assembly function that you call, and that function could copy the value in B3 (return address) to a variable pointer supplied as an argument, or return the value of B3 in A4 as the returned value of the function.

    example function GetPC( void *pPCLocation ) said:

                     .global    _GetPC
    _GetPC:
                     B          B3
                     STW    B3, *A4
                     NOP    4

    I have not tried the function above, but it should work if you put it in a file named GetPC.asm and place it in your CCSv4 or CCSv5 Proejct Folder. Be sure to include a prototype somewhere and use it like this:

    example use of GetPC( void *pPCLocation ) said:

    extern void GetPC( void *pPCLocation );

    void main(void)
    {
                     unsigned int PCAddr;

                     GetPC( &PCAddr );

                     printf( "PC = 0x%X\n" );

    This should return the value of the PC for the printf function call, but it will be wherever the GetPC() function returns to, which will be the beginning of the setup for the printf.

    Regards,
    RandyP

     

    If you need more help, please reply back. If this answers the question, please click  Verify Answer  , below.