6.1. Converting Proprietary TI C29x asm() Statements Embedded in C/C++ Source

Embedded in the C/C++ source code for your TI C29x application, you may be making use of asm() statements. In general, asm() statements are used to insert literal assembly language code into the compiler generated code for a given compilation unit. The cl2000 compiler supports a no-frills implementation of asm() statements; what you specify in the string argument to the asm() statement is exactly what will be inserted into the compiler generated code. The cl2000’s implementation of asm() statements does not support the notion of C expression operands, for example.

The c29clang compiler supports the GCC-style asm() statements that allows for specifying C expression operands. For example, the following definition of add() contains an example of an embedded GCC-style asm() statement:

int add(int i, int j) {
  int res;
  asm("\tADD %0, %1, %2\n"
      : "=r" (res)
      : "r" (i), "r" (j));
  return res;
}

where (res) is an output operand and (i) and (j) are input operands. If compiled with optimization (-O1 option), the c29clang compiler will generate the following instructions for the above function:

add:
        add     r0, r1
        bx      lr

For more information about using GCC-style asm() statements, please refer to How to Use Inline Assembly Language in C Code in the C Extensions part of Using the GNU Compiler Collection (GCC) online documentation.

Note

Use Caution When Defining Symbols Inside an asm() Statement

Inlining a function that contains an asm() statement that contains a symbol definition when compiling with the c29clang compiler can cause a “symbol multiply defined” error.

Please see Inlining Functions that Contain asm() Statements for more details.