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.

inline assembly for Cortex-M3 in CCS 4.2



I got erros in inline assembly code.

I can not know how to use inline assenbly code in CCS 4.2.

I tried to test a code with ARM Complier style, but I got error messages.

And I tried to test a code with GNU Complier style, but I got error messages.

How can I make a program with inline assembly?

The following is a sample code.

1. ARM compiler style

__inline int qmac(int a, short x, short y)
{
 int i;
 const int mask = 0x80000000;
 
 i = x * y;

  asm("adds i, i, i ");
  asm("it VS ");
  asm("EORVS i, mask, i, asr #31 ");
  asm("adds a, a, i ");
  asm("it VS");
  asm("EORVS a, mask, a, asr #31 ");

 return a;
}

2. GNU compiler style

__inline int qmac(int a, short x, short y)
{
int i;
const int mask = 0x80000000;

i = x * y;

asm("adds  %0, %1, %2" : "=r" (i) : "r" (i), "r" (i));
asm("it VS ");
asm("eorvs %0, %1, %2, asr #31": "=r" (i): "r" (mask), "r" (i));
asm("adds  %0, %1, %2": "=r" (a): "r" (a), "r" (i));
asm("it VS");
asm("eorvs %0, %1, %2, asr #31": "=r" (a): "r" (mask), "r" (a));
 
return a;
}

  • For the TI assemblers, the first column in assembly statements is reserved for labels. You should write your inline assembly statements without at least one space before the instruction, like:

    asm("  adds i, i, i "); 

    Please see this related post for reference.

  • The TI compiler asm statements do not work like that.  The quoted string is simply copied into the assembly output.  References to some C variable like "i" are not replaced with the appropriate register, or stack reference, or something like that.  Your best bet is to write this routine in assembly, and call it from C.

    Thanks and regards,

    -George