I'm trying to round an input double using a specified rounding mode in in-line assembly in C. To do so, I need to grab the FPU control word using fstcw
and then change the bits in the word. Unfortunately I'm encountering an error on the very first line:
double roundD(double n, RoundingMode roundingMode) {
asm("fstcw %%ax \n"
::: "ax"); //clobbers
return n;
}
The assembler error I receive is:
Error: operand type mismatch for 'fstcw'.
I'm under the impression this code snippet should store the FPU control word, which is 16 bits in length, in the AX
register, which is also 16 bits in length. Just to be sure, I also tested the above code with the EAX
register instead of AX
, and received the same error.
What might I be missing here? Please let me know if any further information is needed.