Sophie

Sophie

distrib > Fedora > 14 > x86_64 > media > updates > by-pkgid > e677bbbdff6d27fe001f15e0ef2bb4cc > files > 254

sdcc-3.0.0-0.fc14.x86_64.rpm

<!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>
 &nbsp; <B>  <A NAME="tex2html1990"
  HREF="node1.html">Contents</A></B> 
 &nbsp; <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>&nbsp;
<BR>&nbsp;
<BR><TT>int c_func (unsigned char i, unsigned char j)</TT>&nbsp;
<BR><TT>{</TT>&nbsp;
<BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;return asm_func(i,j);</TT>&nbsp;
<BR><TT>}</TT>&nbsp;
<BR>&nbsp;
<BR><TT>int main()</TT>&nbsp;
<BR><TT>{</TT>&nbsp;
<BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;return c_func(10,9);</TT>&nbsp;
<BR><TT>}</TT>

</BLOCKQUOTE>
The corresponding assembler function is:
<BLOCKQUOTE>
<TT>.globl _asm_func_PARM_2 </TT>&nbsp;
<BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.globl _asm_func </TT>&nbsp;
<BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.area OSEG </TT>&nbsp;
<BR><TT>_asm_func_PARM_2:</TT>&nbsp;
<BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.ds    1 </TT>&nbsp;
<BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.area CSEG </TT>&nbsp;
<BR><TT>_asm_func: </TT>&nbsp;
<BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mov&nbsp;&nbsp;&nbsp;&nbsp;a,dpl </TT>&nbsp;
<BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;add&nbsp;&nbsp;&nbsp;&nbsp;a,_asm_func_PARM_2 </TT>&nbsp;
<BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mov&nbsp;&nbsp;&nbsp;&nbsp;dpl,a </TT>&nbsp;
<BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mov&nbsp;&nbsp;&nbsp;&nbsp;dph<A NAME="2404"></A>,#0x00
</TT>&nbsp;
<BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ret</TT>

</BLOCKQUOTE>
The parameter naming convention is _&lt;function_name&gt;_PARM_&lt;n&gt;,
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 _&lt;function_name&gt;_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>
 &nbsp; <B>  <A NAME="tex2html1990"
  HREF="node1.html">Contents</A></B> 
 &nbsp; <B>  <A NAME="tex2html1992"
  HREF="node191.html">Index</A></B> 
<!--End of Navigation Panel-->
<ADDRESS>

2011-03-20
</ADDRESS>
</BODY>
</HTML>