OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 23, 2024 12:29 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: GCC calling convention
PostPosted: Wed Mar 20, 2002 8:22 am 
I want to call a C-Function from within an asm-function, and pass parameters to it, but I don't know the calling convention.


Top
  
 
 Post subject: Re: GCC calling convention
PostPosted: Wed Mar 20, 2002 9:28 am 
You have to pass parameters right-to-left. That is, if you have a function:
int x(x1, x2, x3)
you have to do this:
push x3
push x2
push x1
call x
add $0x0C, %esp

In case you use NASM or TASM replace the last line with:
add esp,0Ch
Also, the GCC calling conventions assume (AFAIK) that ebx, esi, edi and ebp are preserved during the call (and the segment registers, of course, as well).

So.. it's rather easy.. you just have to push the arguments in reverse order and clean up the stack afterwards..


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: ebeneEinHalb, Google [Bot] and 111 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group