Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!rutgers!apple!bionet!agate!ucbvax!hplabs!hp-sdd!megatek!spot!hollen From: hollen@spot.megatek.uucp (Dion Hollenbeck) Newsgroups: comp.sys.ibm.pc Subject: Re: Calling a "C" function from assembly language Message-ID: <391@megatek.UUCP> Date: 25 Oct 88 19:01:55 GMT References: <5876@killer.DALLAS.TX.US> Sender: news@megatek.UUCP Reply-To: hollen@megatek.UUCP () Organization: Megatek Corporation, San Diego, Ca. Lines: 26 From article <5876@killer.DALLAS.TX.US>, by cy@killer.DALLAS.TX.US (Cyrus Foughty): > > I have a assembly language program from which I want to > call a "C" function. I know this is backwards from what > everyone else does. BTW, I am using Microsoft Masm and > "C" 5.1 for this little dodad. [...stuff deleted...] > How do I do it? The key is in the mixed language section of the C reference manual, although it is implied rather than stated exactly. You need to know that a C function pushes its parameters on the stack from right to left. Byte width parameters are pushed as words with high order bits zeroed and long width (32-bits) parameters are pushed high 16-bits first and low 16-bits second. The calling assembly is responsible for stripping the pushed parms off the stack on return from the called function. I recommend using "ADD SP,xxx" where xxx = number of words to strip from stack (remember bytes went on stack as words). Dion Hollenbeck (619) 455-5590 x2814 Megatek Corporation, 9645 Scranton Road, San Diego, CA 92121 seismo!s3sun!megatek!hollen ames!scubed/