This is from an example how to use C code in assembler (\Masm32\MasmBasic\MB2C\CalcTest.asc):
extern "C"
int _fltused=1; //get rid of a stupid error message
extern "C"
double _stdcall jjDiv(int x , int y)
{
try
{
float ffx=x*1.001;
float ffy=y*1.001;
return(ffx/ffy);
}
catch (int)
{
return(0); //not very useful ;-)
}
}
Commandline:"%ProgramFiles%\Microsoft Visual Studio 10.0\VC\bin\cl.exe" /c /Oty2 /Zl /EHsc /Gs /GS- /FojjCalc.obj /Fa jjCalc.cpp
Question: What I had in mind was a simple return (x/y) - but Olly tells me C++ uses idiv. What is the correct way to force C++ to return a REAL8? My workaround doesn't look very elegant...
Something like this should probably suffice:
float ffx=(float)x*1.001;
float ffy=(float)y*1.001;
return((double)ffx/ffy);
As it traverses left-to-right
Thanks, Clive - you set me on the right track:
extern "C"
double _stdcall jjDiv(int x , int y)
{
try
{
return((float)x/y);
}
catch (int)
{
return(3.14159);
}
}
The catch hander is pretty useless, though, as fidiv does not trigger the exception. I would have to set the appropriate FPU mask bit :8)