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 refer to macros from within inline assembly in C compiled by MSP430 TI compiler?

Other Parts Discussed in Thread: MSP430FR5969

How does one refer to macros defined in msp430*.h  from within inline assembly in a C source file compiled by MSP430 TI compiler?

#include <msp430.h>
int main() {
    asm ( " BIS.B #BIT0, &P1OUT " );
}

results in

"/tmp/005274EP3KP", ERROR!   at EOF: [E0300] The following symbols are undefined:
  BIT0
  P1OUT
1 Assembly Error, No Assembly Warnings

Including the following at the top of the C source file or before the above 'asm' statement:

asm ( " .cdecls C,LIST, \"msp430fr5969.h\" " )

results in either

"../src/main.c", line 10: error #1120: this assembly directive not allowed at this scope

"../src/main.c", line 96: error #1118: this assembly directive not allowed inside a function

An attempt to use parameters defined in the C source (implied in this post):

 asm ( " BIS.B #BIT0, %[portreg]" : [portreg] "m" (P3OUT) );

results in

"../src/main.c", line 98: error #18: expected a ")"

I could not find info in neither of the following:

SLAU132J : MSP430 Optimizing C/C++ Compiler v 4.4 (Sections 5.10 and 6.6.5)
SLAA140 : Mixing C and Assembler With the MSP430

Closest related post: http://e2e.ti.com/support/development_tools/compiler/f/343/t/219557

Compiler version: cl430: MSP430 C/C++ Compiler                   v4.4.3 (CCSv6)
Host: Linux x86

  • Alexei Colin said:
    How does one refer to macros defined in msp430*.h  from within inline assembly in a C source file compiled by MSP430 TI compiler?

    It cannot be done.  I'll give you credit for trying.  You thoroughly explored every possibility.  

    Have you tried coding the operation in plain old C?  I know you can refer to things like P1OUT and BIT0 from C.

    Thanks and regards,

    -George

  • Alright, thank you for confirming. Yes, I've got a C version and an alternative (ugly but for the sake of precision) inline ASM version using magic numbers from msp430fr5969.h and msp430fr5969.cmd, for example: asm ( " BIS.B #0x20, &0x0222 " );
  • You're not supposed to need to use assembly at all.  You should be able to write this in your C code and the compiler will generate a single BIS instruction:

    #include <msp430.h>
    int main() {
        P1OUT |= BIT0;
    }

    Is there a reason you must use assembly code in this case?

  • Yes, I understand. The above is a distilled toy example, not a real use case. The small snippet in my application needs to be explicit and definite in terms of instructions and relying on the C compiler and the optimization level flags passed to it is a bit too fragile in this case. Thanks for the quick replies.