Using Variables in ASM Function Call


#1

Hi,

I get the following error when trying to use a variable in in ASM function-call:

/Applications/Axoloti.app/Contents/Java/CMSIS/Include/core_cmInstr.h:621:72: error: impossible constraint in 'asm'
   __ASM ("ssat %0, %1, %2" : "=r" (__RES) :  "I" (ARG2), "r" (__ARG1) ); \

The relevant line is:

inVals[0] = __SSAT(inlet_ENERGYi + offset, bits[0]);

(where 'bits' is an array containing number of bits used for various values).

Is there some way to get this to work?

I can get it to work, using string-substitution, or something, perhaps?

a|x


#2

The number of bits for the saturation instructions need to be known at compile time.
If it can't be known at compile time, you could wrap it in a switch statement:

switch (bits[0]) {
  case 0: inVals[0]  = __SSAT(inlet_ENERGYi + offset, 0); break;
  case 1: inVals[0]  = __SSAT(inlet_ENERGYi + offset, 1); break;
  case 2: inVals[0]  = __SSAT(inlet_ENERGYi + offset, 2); break;
  // and so on...
  default:
}

Or use an attribute (does string substitution in the object code), enabling the use of the fast assembly function.


#3

I see, thanks for getting back to me.

a|x