Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!uwvax!rocky.cs.wisc.edu!g-tookey From: g-tookey@rocky.cs.wisc.edu. (Richard Schaut) Newsgroups: comp.sys.ibm.pc Subject: Re: Calling C functions from assembly Message-ID: <8096@spool.cs.wisc.edu> Date: 3 Aug 89 18:34:50 GMT References: <12324@s.ms.uky.edu> <216100115@trsvax> Sender: news@spool.cs.wisc.edu Reply-To: g-tookey@rocky.CS.WISC.EDU (Richard Schaut) Organization: U of Wisconsin CS Dept Lines: 42 In article <216100115@trsvax> don@trsvax.UUCP writes: > >>>I'm trying to call some C functions from assembly, using MSC 5.0 and either >>>MASM or TASM. I could write a dummy _main() in C, if this makes things >>>easier, but I'm still not sure what needs to be setup to call a C subroutine. >>> >>>Can anyone clue me in on how to do this? > >>[...] >>Note that the parameters are pushed onto the stack in reverse order. As >>for how to retrieve the functions return value, you'l have to consult >>you compilers documentation. There is no set convention, however most > ^^^^^^^^^^^^^^^^^^^^^^^^^^ >>use one of the CPU registers. > >Is this correct? I thought it was a well-established convention to place >the return value in the AX register. Are there some commercial compilers >which return it somewhere else? Most reputable compilers use AX for 16 bit values and AX DX for 32 bit values, but the off-brand compilers may use something else. Also, once the size of the return value gets larger than 32 bits, then all bets are off (I've even seen some compilers use the stack, e.g. MIX C under CP/M). The safest thing is to not make any assumptions whatsoever about how functions return values for a given compiler. If the compiler's documentation is silent on the subject, then it's best to drop the whole thing in /dev/nul and get a real compiler. Rick Please send e-mail to: schaut@madnix.UUCP ArpaNet: madnix!schaut@cs.wisc.edu UseNet: ...uwvax!astroatc!nicmad!madnix!schaut {decvax!att}! Madison: an alternative to reality I am posting this through a friend's account. His consent to my use of his account in no way implies his consent to responsibility for the opinions expressed herein.