From: Luke D. <cod...@ho...> - 2003-01-29 02:18:21
|
stdcall is not the normal or default C calling convention; cdecl is, so if your assembly code uses stdcall you have to declare the function as __stdc in the C code. Also, you don't have to save all the registers because the caller is required to save most of them. I don't know where Microsoft documents it but based on the GCC source code you only need to save ebx, esi, edi and ebp: /* 1 for registers not available across function calls. These must include the FIXED_REGISTERS and also any registers that can be used without being saved. The latter must include the registers where values are returned and the register where structure-value addresses are passed. Aside from that, you can include as many other registers as you like. The value is an mask - bit 1 is set for call used for 32bit target, while 2 is set for call used for 64bit. Proper value is computed in the CONDITIONAL_REGISTER_USAGE. */ #define CALL_USED_REGISTERS \ /*ax,dx,cx,bx,si,di,bp,sp,st,st1,st2,st3,st4,st5,st6,st7*/ \ { 3, 3, 3, 0, 2, 2, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, \ /*arg,flags,fpsr,dir,frame*/ \ 3, 3, 3, 3, 3, \ (gcc/config/i386/i386.h) Luke ----- Original Message ----- From: "Mikael Aronsson" <mik...@te...> To: "Evan Dembskey" <ev...@te...>; "Mingw-Users" <min...@li...> Sent: Tuesday, January 28, 2003 6:23 PM Subject: Re: [Mingw-users] NASM - Assembly in MinGW > Make sure that your assembly code entry point use normal C calling > convention (stdcall ?), if you don't have any args it's no big deal, save > and restore all the registers and add a function prototype to your C code > and get the calling convention correct, by default you have stdcall, this > means that: > > Arguments are passed right to left. > The called function pops it's own arguments. > '_' prepended to the name and @num_bytes is appended to the name. > > That's it. > > Mikael > > ----- Original Message ----- > From: "Evan Dembskey" <ev...@te...> > To: "Mingw-Users" <min...@li...> > Sent: Tuesday, January 28, 2003 10:48 AM > Subject: [Mingw-users] NASM - Assembly in MinGW > > > > Hi, > > > > > > Sorry for asking two questions in 1 day! > > > > OK, say I have written something in NASM and compiled it. Now, how do I > > call this from within a C app? > > > > > > Regards, > > > > Evan |