I get a parse error on line 24(I believe) "parse error before '[' token"
Also, if any of you would like to give me some helpful tips and insights into my project I would appreciate that very much. I'm building a pow function with all calculations done in asm, this piece of code is to change the FPU to round to 0 so that I can split up the exponent into 2 parts (example: 2^3.2 = 2^3 * 2^0.2)
#include <stdio.h>
#include <stdlib.h>
#define PRECISION 3
#define RND_CTL_BIT_SHIFT 10
// floating point rounding modes: IA-32 Manual, Vol. 1, p. 4-20
typedef enum {
ROUND_TOWARD_ZERO = 3 << RND_CTL_BIT_SHIFT
} RoundingMode;
int main(int argc, char **argv)
{
int fpMask = 0x1F9FF;
int localVar = 0x00000;
asm(" FSTCW %[localVarIn] \n" // store FPU control word into localVar
" add %[localVarIn], %[fpMaskOut] \n" // add fpMaskIn to localVar
: [localVarOut] "=m" (localVar)
: [fpMaskOut] "=m" (fpMask)
: [localVarIn] "m" (localVar)
: [fpMaskIn] "m" (localVar)
);
printf("FPU is 0x%08X\n\n", localVar);
return 0;
}
I believe your clobber list is slightly wrong. In GCC, these take the form of the following:
asm("MY ASM CODE" : output0, output1, outputn
: input0, input1, inputn
: clobber0, clobber1, clobbern);
Note that each class is colon-separated (i.e. the set of outputs, the set of inputs etc), then each element within a set is comma-separated. Therefore, try changing your ASM to the following:
asm(" FSTCW %[localVarIn] \n" // store FPU control word into localVar
" add %[localVarIn], %[fpMaskOut] \n" // add fpMaskIn to localVar
: [localVarOut] "=m" (localVar), // Outputs...
[fpMaskOut] "=m" (fpMask)
: [localVarIn] "m" (localVar), // Inputs...
[fpMaskIn] "m" (localVar)