| CodeGuru Home | VC++ / MFC / C++ | .NET / C# | Visual Basic | Newsletters | VB Forums | Developer.com |
|
|||||||
| Assembly Questions and Answers for Assembly here! |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
MSVC inline assembly query
I am a bit of a newbie to assembly and only need to do one thing at present, which is access the FSINCOS operation on the x87 math co-processer. I have trawled the web and found a few references and have come up with the following code:
void SinCos(double Angle, double *SinAns, double *CosAns) { __asm { fld QWORD PTR [Angle] fsincos fstp QWORD PTR [CosAns] fstp QWORD PTR [SinAns] fwait } } main() { double s=0.0; double c=0.0; double ang = 3.0; SinCos(ang,&s,&c); //call one version of the code //call the other one version of the code __asm { fld QWORD PTR [ang] fsincos fstp QWORD PTR [c] fstp QWORD PTR [s] fwait }; } When I single step through it and look at the registers the operation is occuring as expected but only the second version pops the values into "c" and "s". I am using VC++ 6.0 Professional with the default compiler options: /nologo /MLd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Fp"Debug/small_test.pch" /YX /Fo"Debug/" Please help. |
|
#2
|
|||
|
|||
|
Re: MSVC inline assembly query
I'm no expert in x86 assembly, so this could be pretty far off, but I notice one big difference in the two versions of the function you showed. In the first one, the symbols that you pass to the fstp instructions are already declared as pointers in your C code, while in your second version (the one that works), the symbols are plain old double variables.
It seems, then, that in your assembly, you have an extra level of indirection. Instead of storing the result in the variable, you're altering the actual value of the pointer that you're passing to your SinCos function. I don't know exactly how to syntactically fix what you're seeing. Remove the "ptr" token in those lines of code, maybe? |
|
#3
|
|||
|
|||
|
Re: MSVC inline assembly query
Bob Davis is correct, you have an extra level of indirection.
You need to do something like: Code:
void SinCos( double ang, double* sinAns, double* cosAns )
{
_asm
{
fld QWORD PTR [ang]
fsincos
mov ebx,[cosAns] ; get the pointer into ebx
fstp QWORD PTR [ebx] ; store the result through the pointer
mov ebx,[sinAns]
fstp QWORD PTR [ebx]
}
}
John |
|
#4
|
|||
|
|||
|
Re: MSVC inline assembly query
[ Moved thread ]
__________________
Ciao, Andreas "Software is like sex, it's better when it's free." - Linus Torvalds Article(s): Allocators (STL) Function Objects (STL) |
![]() |
| Bookmarks |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|