B
Bořek Tuleja
Guest
I've been learning assembly language for a few past weeks so I got an idea to try to use inline assembly within a C++ DLL for Game Maker Studio 2. I wrote a simple function that negates a value, multiplies it by 2 (I'm using bit left shift for this) and the function returns this value. As you may know it makes no sense to perform these operations on a double value so everything is converted to an int. After many hours I finaly got the right results. Here is the code:
The tested value is 5, Game Maker correctly outputs -10.
My problem is that I would like to return the value directly in the ASM block. I thought the only thing I need to do is leaving the value I want to return in the XMM0 register followed by LEAVE and RET instructions but it doesn't work. The DLL starts normally, function gets called without an error but Game Maker outputs "NaN" instead. I tryed to leave the result in other XMM1 - XMM7 registers but it doesn't work as well. This is why I have to return the value as "return a;".
Does anyone know which register should I use or what to do to return the correct value?
C++:
double testFunc2() {
double a = 5;
/*
1. move A value to register xmm0
2. convert double to int, store in eax
3. neg eax
4. eax * 2
5. convert int to double, store in xmm0
6. move xmm0 value to A
*/
asm(
"movsd xmm0, %0;"
"cvttsd2si eax, xmm0;"
"neg eax;"
"shl eax, 1;"
"cvtsi2sd xmm0, eax;"
"movsd %0, xmm0"
: "=m"(a)
:
: "eax", "xmm0"
);
return a;
}
My problem is that I would like to return the value directly in the ASM block. I thought the only thing I need to do is leaving the value I want to return in the XMM0 register followed by LEAVE and RET instructions but it doesn't work. The DLL starts normally, function gets called without an error but Game Maker outputs "NaN" instead. I tryed to leave the result in other XMM1 - XMM7 registers but it doesn't work as well. This is why I have to return the value as "return a;".
Does anyone know which register should I use or what to do to return the correct value?