I am trying to experiment with inline assembly, and I am trying to add decimal numbers (no, NOT integers) in inline assembly. Issue is, when I call the following function:
inline double ADD(double num1, double num2) {
double res;
_asm{
push eax; push the former state of eax onto stack
mov eax, num1;
add eax, num2;
mov res, eax;
pop eax; restore the former state of eax now that we are done
} return res;}
The compiler complains of improper operand size at the inline assembly (ALL lines of assembly excluding the push and pop instruction lines). So I have to change to an integer type, such as unsigned long, and then it works, but of course only supports integer types; decimal results are rounded.
Is there any way to add in assembly that allows for decimal results like 8.4?
You need a different set of instructions to manipulate floating point numbers. Here's an introduction that should help: x86 Assembly: Floating Point
Try this:
I haven't done x87 assembly in a decade, but it should be something like:
The instruction you probably want is ADDSD, but I don't know for sure.
Here's the link to Intel's instruction set manuals. http://www.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html/
They used to mail you hard copies for free, but it looks like that's no longer true.
The answer, above, that you have to push the operands onto the FP stack and pop the result is correct.
However, the proximate cause of the "improper operand size" errors is that "extended" registers, "e__" (e.g. eax) are 32-bit and double-precision floating-point numbers are 64-bit.