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.

TMS320F28377D: Function-like Macro with Assembly Instruction does not Compile

Part Number: TMS320F28377D

I'm trying to define a macro that will insert a number of no-op instructions based on the number entered in the macro. When I try and compile I get the following error:

"F2837xD_SysCtrl.asm", ERROR! at EOF: [E0300] The following symbols are undefined:
x

Here is the code:

#define NOP_N(x)  asm(" RPT #(x) || NOP")

....

NOP_N(20);

I realize there are other solutions, but why does the compiler not treat the assembly instruction with an input the same way it does for C code? Is there some syntax I'm missing here, or is it simply that the compiler doesn't support this type of functionality?

Compiler Version:  ti-cgt-c2000_18.12.3.LTS

  • is it simply that the compiler doesn't support this type of functionality?

    Yes.  For details, please search the C28x compiler manual for the sub-chapter titled The __asm Statement.

    For this specific case, there is a way to do it.  

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    #define NOP_N(x) \
    do \
    { \
    asm(" .loop " #x "\n" \
    " nop\n" \
    " .endloop"); \
    } while (0)
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    When you use it, the compiler issues a warning diagnostic similar to ...

    Fullscreen
    1
    "file.c", line 12: warning: this assembly directive potentially unsafe inside a function
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    The warning is legitimate, because this macro causes real problems if you invoke it outside of a function.

    Since I wrote this macro, I think it is fine for me to call it an ugly hack.  If you don't want to use it, I understand.

    Thanks and regards,

    -George

  • George, thank you for the quick response and example macro. I re-read through Section 6.9:  The __asm Statement in the compiler manual, and really only find the following blurb that might explain the anomaly with the function-like macro substitution issue with assembly statements:  "The __asm statement does not provide any way to refer to local variables. If your assembly code needs to refer to local variables, you will need to write the entire function in assembly code.". I was hoping for a more explicit answer regarding the compilation and macro substitution process that prevents this method from working as it does in all other situations. I will consider using your solution long term; however, short-term I am in need of a method that will not change the Executable Object Image and unfortunately the method I was trying didn't work.

    Thanks again for your thoughtful response,

    Adam