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.

TMS320F28388D: Getting SP in C code

Part Number: TMS320F28388D

Hello,

I want to get stack pointer in c code ,thus can monitor the stack .I have gone through other forum and came to understand that c28x SP is not memory mapped and need c callable assembly function to get SP .

is there any example of the c callable assembly function available, or can someone show how to do the same.

Thanks,

Stevin Martin

  • Hi Martin,

    You will have to write a c-callable assembly function that returns the SP

    The assembly function reads SP and returns its value. You can then call this assembly function from C code. 

    For e.g.:

    Assembly code

        .global _varSP
        .global _getsp

    _getsp:
            MOV    AL, SP
            MOV     @_varSP,AL        
            LRET

    C code

    extern "C"{
    extern int getsp();         /* declare external asm function */
    int varSP = 0;              /* define global variable to store SP  */
    }
    void main()
    {   
        getsp();        /* call function normally         */
    }

    Best Regards

    Siddharth