Reputation: 6337
I'm trying to convert a 32-bit float into an extended precision 80-bit float. I'm using MSVC x86. I tried the following inline ASM code:
void Convert32To80(float *value, void *outValue)
{
__asm
{
fld float ptr [value];
fstp tbyte ptr [outValue];
}
}
Here, void *outValue
is a buffer that is large enough to hold 10 bytes.
This looks right to me, but it's crashing when it's run.
Any help is appreciated!
Upvotes: 2
Views: 1130
Reputation: 37797
Updated Note for posterity: Apparently, MSVC 2010 has no type for 80bit floating point types, so the obvious solution in C or C++ code along the lines of
float inValue = 666.666f;
long double outValue = (long double)inValue;
does NOT work, and you are actually forced to directly use assembly language.
Upvotes: 1
Reputation: 613013
OK, this should do it:
void Convert32To80(float *value, void *outValue)
{
__asm
{
mov eax,dword ptr [value]
fld dword ptr [eax]
mov ecx,dword ptr [outValue]
fstp tbyte ptr [ecx]
}
}
All I did was wrote some C code to do the same, but for a float to double conversion, looked at the dissasembly and then modified as necessary.
Note that I am no expert with MSVC and I'm not 100% sure that I can use the EAX and ECX registers like that without saving/restoring them. Others may know more and offer corrections.
Upvotes: 3