flat assembler
Message board for the users of flat assembler.

 Index > Main > FPU and function call :)
Author
denial

Joined: 12 Sep 2004
Posts: 98
denial
Hello,

I'm learning FASM (and Assembler at all) at the moment, and I've got some more questions I'd like to get an answer about - if you can help me I would be glad

1. I know, and I hope I'm not wrong about this, that functions declared in a library needs to be called through invoke (normal calling convention) and cinvoke (c-calling convention)... I also understand how to use this in FASM, but I would also like to understand the theory behind this... What does this system mean and what exactly means the c-calling convention?

2. As I'm already pretty familiar with handling integer variables, I want to learn about floating point values... Do you know good examples where I could learn it? I read through the FASM manual, but it seems that the FPU is not very easy to handle... Is it also possible to mix up integer and floating-point values while calculating?
Something like this for example (pseudo-c-code):

Code:
int x=1;
float y=5.5;
float z=0;
z=x+y*(x*3.5);

I would be glad if you could help me.

Regards
denial[/code]
21 Nov 2004, 12:52
Matrix

Joined: 04 Sep 2004
Posts: 1166
Location: Overflow
Matrix
21 Nov 2004, 16:41
denial

Joined: 12 Sep 2004
Posts: 98
denial
Thank you. But:
Neither the ... "FAQ" (I would maybe call it as some kind of "helper page", because it isn't really like a typical FAQ) nor the forum search helped me to find general informations about calling conventions. Maybe I'm just too stupid - but I searched about half an hour for this.

Maybe somebody has got a direct link with some general information about this topic? It even got more confused because now I saw in other threads, that there are also other calling conventions like PASCAL... I would like to know the theory behind these things.

Thank you again.
22 Nov 2004, 15:19
crc

Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc
Quote:
What does this system mean and what exactly means the c-calling convention?

In the C calling convention, you push arguments onto the stack; these are used by the function being called. The called function returns a value in eax, and you have manually clean up the stack by doing add esp, #bytes_pushed_to_stack. It's not the cleanest approach, but it does work pretty well.

Obtaining a value in a C function is done by doing mov reg, esp+offset (or something like that; I don't delve into this very much). I hope this little bit of explaination helps...
22 Nov 2004, 15:55
vid
Verbosity in development

Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
as crc said, plus you have to push arguments in reverse order (right to left in fuction declaration).
Code:
;C declaration
int func(int arg1,int arg2,int arg3);
;calling from asm
push arg3value
push arg2value
push arg1value
call _func   ;usualy there is a "_" before functions declared with C

22 Nov 2004, 16:44
Matrix

Joined: 04 Sep 2004
Posts: 1166
Location: Overflow
Matrix
sorry i forgot to mention, stdcall.inc in the fasm include files is for calling procedures ( it pushes parameters reverse order )
22 Nov 2004, 17:48
crc

Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc
Quote:
plus you have to push arguments in reverse order

I suppose I should have mentioned that.....
22 Nov 2004, 18:41
denial

Joined: 12 Sep 2004
Posts: 98
denial
22 Nov 2004, 21:00
THEWizardGenius

Joined: 14 Jan 2005
Posts: 382
Location: California, USA
THEWizardGenius
Yes. All you have to do is use FILD to copy an integer into floating point format, and FIST/FISTP to put it back into memory. You also have to load most constants, except one and zero- just use FLD1 and FLDZ to load those onto the FPU stack. The FPU stack is 8 registers set up as a stack. If you want to know where I learned all this, check out http://www.ragestorm.net/downloads/387intel.txt - it's the official programmers manual to the 80387. Newer extensions can only be found in PDF format that I know of, and you get the PDF's from the Intel developers page. Hope I could be of some help to you.
19 Jan 2005, 01:52
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum