flat assembler
Message board for the users of flat assembler.

Index > Main > FPU and function call :)

Author
Thread Post new topic Reply to topic
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 Smile

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.
Thank you in advance.

Regards
denial[/code]
Post 21 Nov 2004, 12:52
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
Post 21 Nov 2004, 16:41
View user's profile Send private message Visit poster's website Reply with quote
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.
Post 22 Nov 2004, 15:19
View user's profile Send private message Reply with quote
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...
Post 22 Nov 2004, 15:55
View user's profile Send private message Visit poster's website Reply with quote
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
  add esp,4*3  ;sizeof(int)*number_of_arguments
    
Post 22 Nov 2004, 16:44
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
sorry i forgot to mention, stdcall.inc in the fasm include files is for calling procedures ( it pushes parameters reverse order )
Post 22 Nov 2004, 17:48
View user's profile Send private message Visit poster's website Reply with quote
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.....
Post 22 Nov 2004, 18:41
View user's profile Send private message Visit poster's website Reply with quote
denial



Joined: 12 Sep 2004
Posts: 98
denial
thank your for your answers Smile
Post 22 Nov 2004, 21:00
View user's profile Send private message Reply with quote
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.
Post 19 Jan 2005, 01:52
View user's profile Send private message AIM Address Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.