Article View: alt.msdos.programmer
Article #187Re: Calling C functions from assembly
From: Patrick Gaughan
Date: Tue, 01 Aug 1989 15:59
Date: Tue, 01 Aug 1989 15:59
43 lines
1681 bytes
1681 bytes
Well, I've done some stuff in this area...
The easiest way I can think of is to use the LARGE option on your C
compiler, declare the C functions as far labels and use far calls from
the assembly language routine.
Example:
/* c program */
#include <stdio.h>
int cfnct(a,b)
int a,b;
{
printf("a + b = %d\n",a+b);
return (a+b);
}
; asm program
( miscellaneous instructions )
EXTERN _cfcnt:FAR ; depending on linker, name may not be
. ; case sensitive
.
.
push b
push a
call cfcnt
add sp,4
(function return value in ax, if the function was a long or ptr
type, dx would return the upper half of the return value)
I'm pretty sure this is correct, but you'll have to try it and prove
it for yourself. Like most programmers, I don't memorize every rule,
but given a machine and I few tries at it, I can usually remember how
to do it.
Disclaimer: You're getting desperate if you think I have all the
right answers...
Patrick Gaughan
pgaughan@nmsu.edu
Technical Details
Message-ID:
<PGAUGHAN.89Aug1095907@dante.nmsu.EDU>Path:
arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!ames!topgun.dspo.gov!lanl!opus!pgaughanReferences:
<12324@s.ms.uky.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!ames!topgun.dspo.gov!lanl!opus!pgaughan From: pgaughan@dante.nmsu.EDU (Patrick Gaughan) Newsgroups: alt.msdos.programmer,comp.sys.ibm.pc Subject: Re: Calling C functions from assembly Message-ID: <PGAUGHAN.89Aug1095907@dante.nmsu.EDU> Date: 1 Aug 89 15:59:07 GMT References: <12324@s.ms.uky.edu> Sender: news@nmsu.edu Followup-To: alt.msdos.programmer Organization: New Mexico State University, Las Cruces, NM Lines: 43 In-reply-to: simon@ms.uky.edu's message of 1 Aug 89 14:21:07 GMT