<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <!--Converted with LaTeX2HTML 2008 (1.71) original version by: Nikos Drakos, CBLU, University of Leeds * revised and updated by: Marcus Hennecke, Ross Moore, Herb Swan * with significant contributions from: Jens Lippmann, Marek Rouchal, Martin Wilck and others --> <HTML> <HEAD> <TITLE>3.14.3 Assembler Routine (non-reentrant)</TITLE> <META NAME="description" CONTENT="3.14.3 Assembler Routine (non-reentrant)"> <META NAME="keywords" CONTENT="sdccman"> <META NAME="resource-type" CONTENT="document"> <META NAME="distribution" CONTENT="global"> <META NAME="Generator" CONTENT="LaTeX2HTML v2008"> <META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css"> <LINK REL="STYLESHEET" HREF="sdccman.css"> <LINK REL="next" HREF="node89.html"> <LINK REL="previous" HREF="node87.html"> <LINK REL="up" HREF="node85.html"> <LINK REL="next" HREF="node89.html"> </HEAD> <BODY > <!--Navigation Panel--> <A NAME="tex2html1993" HREF="node89.html"> <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A> <A NAME="tex2html1987" HREF="node85.html"> <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A> <A NAME="tex2html1981" HREF="node87.html"> <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A> <A NAME="tex2html1989" HREF="node1.html"> <IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A> <A NAME="tex2html1991" HREF="node191.html"> <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A> <BR> <B> Next:</B> <A NAME="tex2html1994" HREF="node89.html">3.14.4 Assembler Routine (reentrant)</A> <B> Up:</B> <A NAME="tex2html1988" HREF="node85.html">3.14 Interfacing with Assembler</A> <B> Previous:</B> <A NAME="tex2html1982" HREF="node87.html">3.14.2 Registers usage</A> <B> <A NAME="tex2html1990" HREF="node1.html">Contents</A></B> <B> <A NAME="tex2html1992" HREF="node191.html">Index</A></B> <BR> <BR> <!--End of Navigation Panel--> <H2><A NAME="SECTION004143000000000000000"> 3.14.3 Assembler Routine (non-reentrant)</A> </H2> <P> In the following example<A NAME="2377"></A><A NAME="2378"></A> the function c_func calls an assembler routine asm_func, which takes two parameters<A NAME="2379"></A>. <BLOCKQUOTE> <TT>extern int asm_func(unsigned char, unsigned char);</TT> <BR> <BR><TT>int c_func (unsigned char i, unsigned char j)</TT> <BR><TT>{</TT> <BR><TT> return asm_func(i,j);</TT> <BR><TT>}</TT> <BR> <BR><TT>int main()</TT> <BR><TT>{</TT> <BR><TT> return c_func(10,9);</TT> <BR><TT>}</TT> </BLOCKQUOTE> The corresponding assembler function is: <BLOCKQUOTE> <TT>.globl _asm_func_PARM_2 </TT> <BR><TT> .globl _asm_func </TT> <BR><TT> .area OSEG </TT> <BR><TT>_asm_func_PARM_2:</TT> <BR><TT> .ds 1 </TT> <BR><TT> .area CSEG </TT> <BR><TT>_asm_func: </TT> <BR><TT> mov a,dpl </TT> <BR><TT> add a,_asm_func_PARM_2 </TT> <BR><TT> mov dpl,a </TT> <BR><TT> mov dph<A NAME="2404"></A>,#0x00 </TT> <BR><TT> ret</TT> </BLOCKQUOTE> The parameter naming convention is _<function_name>_PARM_<n>, where n is the parameter number starting from 1, and counting from the left. The first parameter is passed in <I>DPH</I>, <I>DPL</I>, <I>B</I> and <I>ACC</I> according to the description above. The variable name for the second parameter will be _<function_name>_PARM_2. <BR> <BR> Assemble the assembler routine with the following command: <BR> <BR><I><B>sdas8051 -losg asmfunc.asm</B></I> <BR> <BR> Then compile and link the assembler routine to the C source file with the following command: <BR> <BR><I><B>sdcc cfunc.c asmfunc.rel</B></I> <P> <HR> <!--Navigation Panel--> <A NAME="tex2html1993" HREF="node89.html"> <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A> <A NAME="tex2html1987" HREF="node85.html"> <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A> <A NAME="tex2html1981" HREF="node87.html"> <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A> <A NAME="tex2html1989" HREF="node1.html"> <IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A> <A NAME="tex2html1991" HREF="node191.html"> <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A> <BR> <B> Next:</B> <A NAME="tex2html1994" HREF="node89.html">3.14.4 Assembler Routine (reentrant)</A> <B> Up:</B> <A NAME="tex2html1988" HREF="node85.html">3.14 Interfacing with Assembler</A> <B> Previous:</B> <A NAME="tex2html1982" HREF="node87.html">3.14.2 Registers usage</A> <B> <A NAME="tex2html1990" HREF="node1.html">Contents</A></B> <B> <A NAME="tex2html1992" HREF="node191.html">Index</A></B> <!--End of Navigation Panel--> <ADDRESS> 2011-03-20 </ADDRESS> </BODY> </HTML>