Archived

This topic is now archived and is closed to further replies.

shmaLbus

inline assembler

Recommended Posts

shmaLbus    122
how the fugg do i convert between floating point and integer types in visual c++''s inline assembler? i know it''s ''ftol'' and that family. i even disassembled a simple program just converting numbers (it is __ftol) and copied exactly what it had and that didn''t even work! any help would be nice

Share this post


Link to post
Share on other sites
shmaLbus    122
hah, yes i am a genious.. thank you (well ok not really, but let me think that). i disassembled it again and just called the address of __ftol and that worked. if anyone really cares here's what it looks like.

        
int i=10;
float f=20.1;
DWORD __ftol_ptr=0x0040ea88;

_asm {
fld f
call [__ftol_ptr]
mov i, eax
}


Edited by - shmaLbus on July 24, 2000 10:33:10 AM

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
The reason you are using __ftol in the first place is to get the result truncated instead of rounded. Try this instead:

-----------------
float f=20.1;
int i;

_asm fld f
_asm fistp i

-----------------

I have not tried this on VC++ but it works beautifully in Watcom C++. When I started using this in a lighting computation, the speed of my entire program increased by 10% because it didn''t have to call a slow function anymore.

Share this post


Link to post
Share on other sites