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.

CCSTUDIO: Intermixing C and assembly code

Part Number: CCSTUDIO

I'm using the TMS320x28335 processor and its related toolsest.

I'm trying to save a value from the stack to a "C"-language variable. I'm using inline assembly as follows:

 

unsigned long RetAddr;

 

asm("POP @AH");

asm("{POP @AL");

asm("MOVL @_RetAddr,ACC");

 

The accumulator is not being stored in RetAddr as I would have expected. What am I doing wrong?

  • Hi Gail,

    Apologies for my delayed response. A couple things:

    • POP @AH and {POP @AL are not valid C28x instructions. The @ prefix denotes indirect addressing and is not valid as a POP destination. I'm also assuming the stray { in the second POP is a typo. You actually don't need two separate POPs at all. The C28x instruction set provides a single POP ACC instruction that pops a full 32-bit value from the stack directly into the accumulator in one operation. Because your invalid POP instructions never actually load anything from the stack, the subsequent MOVL stores whatever garbage value was already sitting in ACC.
    • Before MOVL @_RetAddr, ACC can write to the correct memory location, the Data Page pointer (DP) must be explicitly set to point to your RetAddr variable. Without this step, the MOVL instruction will not store to the correct address, even if ACC contains the right value.

    Can you try changing the code to:

    unsigned long RetAddr;
    asm("POP ACC");
    asm("MOVW DP, #_RetAddr");
    asm("MOVL @_RetAddr, ACC");

    Best Regards,

    Delaney

  • Thanks, Delaney. That fixed the problem.