175 lines
5.7 KiB
HTML
175 lines
5.7 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
|
|
|
<!--Converted with LaTeX2HTML 99.1 release (March 30, 1999)
|
|
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.13 Inline Assembler Code</TITLE>
|
|
<META NAME="description" CONTENT="3.13 Inline Assembler Code">
|
|
<META NAME="keywords" CONTENT="sdccman">
|
|
<META NAME="resource-type" CONTENT="document">
|
|
<META NAME="distribution" CONTENT="global">
|
|
|
|
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
|
|
<META NAME="Generator" CONTENT="LaTeX2HTML v99.1 release">
|
|
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">
|
|
|
|
<LINK REL="STYLESHEET" HREF="sdccman.css">
|
|
|
|
<LINK REL="next" HREF="node33.html">
|
|
<LINK REL="previous" HREF="node31.html">
|
|
<LINK REL="up" HREF="node19.html">
|
|
<LINK REL="next" HREF="node33.html">
|
|
</HEAD>
|
|
|
|
<BODY >
|
|
<!--Navigation Panel-->
|
|
<A NAME="tex2html724"
|
|
HREF="node33.html">
|
|
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next_motif.gif"></A>
|
|
<A NAME="tex2html718"
|
|
HREF="node19.html">
|
|
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up_motif.gif"></A>
|
|
<A NAME="tex2html712"
|
|
HREF="node31.html">
|
|
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="previous_motif.gif"></A>
|
|
<A NAME="tex2html720"
|
|
HREF="node1.html">
|
|
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents_motif.gif"></A>
|
|
<A NAME="tex2html722"
|
|
HREF="node61.html">
|
|
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index_motif.gif"></A>
|
|
<BR>
|
|
<B> Next:</B> <A NAME="tex2html725"
|
|
HREF="node33.html">3.14 int(16 bit) and</A>
|
|
<B> Up:</B> <A NAME="tex2html719"
|
|
HREF="node19.html">3. Using SDCC</A>
|
|
<B> Previous:</B> <A NAME="tex2html713"
|
|
HREF="node31.html">3.12 Startup Code</A>
|
|
  <B> <A NAME="tex2html721"
|
|
HREF="node1.html">Contents</A></B>
|
|
  <B> <A NAME="tex2html723"
|
|
HREF="node61.html">Index</A></B>
|
|
<BR>
|
|
<BR>
|
|
<!--End of Navigation Panel-->
|
|
|
|
<H2><A NAME="SECTION000413000000000000000">
|
|
3.13 Inline Assembler Code</A>
|
|
</H2>
|
|
|
|
<P>
|
|
SDCC allows the use of in-line assembler with a few restriction as
|
|
regards labels. All labels defined within inline assembler code <I>has
|
|
to be</I> of the form <I>nnnnn$</I> where nnnn is a number less than
|
|
100 (which implies a limit of utmost 100 inline assembler labels <I>per
|
|
function</I>). It is strongly recommended that each assembly
|
|
instruction (including labels) be placed in a separate line (as the
|
|
example shows). When the <I>-peep-asm</I> command line option is
|
|
used, the inline assembler code will be passed through the peephole
|
|
optimizer. This might cause some unexpected changes in the inline
|
|
assembler code. Please go throught the peephole optimizer rules defined
|
|
in file <I>SDCCpeeph.def</I> carefully before using this option.
|
|
<BR>
|
|
|
|
<BR>
|
|
<TT>_asm </TT>
|
|
<BR>
|
|
<TT> mov b,#10 </TT>
|
|
<BR>
|
|
<TT>00001$: </TT>
|
|
<BR>
|
|
<TT> djnz b,00001$ </TT>
|
|
<BR>
|
|
<TT>_endasm ;</TT>
|
|
<BR>
|
|
|
|
<BR>
|
|
The inline assembler code can contain any valid code understood by
|
|
the assembler, this includes any assembler directives and comment
|
|
lines. The compiler does not do any validation of the code within
|
|
the <TT>_asm ... _endasm;</TT> keyword pair.
|
|
<BR>
|
|
|
|
<BR>
|
|
Inline assembler code cannot reference any C-Labels, however it can
|
|
reference labels defined by the inline assembler, e.g.:
|
|
<BR>
|
|
|
|
<BR>
|
|
<TT>foo() { </TT>
|
|
<BR>
|
|
<TT> /* some c code */ </TT>
|
|
<BR>
|
|
<TT> _asm </TT>
|
|
<BR>
|
|
<TT> ; some assembler code </TT>
|
|
<BR>
|
|
<TT> ljmp $0003 </TT>
|
|
<BR>
|
|
<TT> _endasm; </TT>
|
|
<BR>
|
|
<TT> /* some more c code */ </TT>
|
|
<BR>
|
|
<TT>clabel: /* inline assembler cannot reference this label
|
|
*/ </TT>
|
|
<BR>
|
|
<TT> _asm</TT>
|
|
<BR>
|
|
<TT> $0003: ;label (can be reference by inline assembler
|
|
only) </TT>
|
|
<BR>
|
|
<TT> _endasm ; </TT>
|
|
<BR>
|
|
<TT> /* some more c code */</TT>
|
|
<BR>
|
|
<TT>}</TT>
|
|
<BR>
|
|
<BR>
|
|
In other words inline assembly code can access labels defined in inline
|
|
assembly within the scope of the funtion.
|
|
|
|
<P>
|
|
The same goes the other way, ie. labels defines in inline assembly
|
|
CANNOT be accessed by C statements.
|
|
|
|
<P>
|
|
<HR>
|
|
<!--Navigation Panel-->
|
|
<A NAME="tex2html724"
|
|
HREF="node33.html">
|
|
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next_motif.gif"></A>
|
|
<A NAME="tex2html718"
|
|
HREF="node19.html">
|
|
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up_motif.gif"></A>
|
|
<A NAME="tex2html712"
|
|
HREF="node31.html">
|
|
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="previous_motif.gif"></A>
|
|
<A NAME="tex2html720"
|
|
HREF="node1.html">
|
|
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents_motif.gif"></A>
|
|
<A NAME="tex2html722"
|
|
HREF="node61.html">
|
|
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index_motif.gif"></A>
|
|
<BR>
|
|
<B> Next:</B> <A NAME="tex2html725"
|
|
HREF="node33.html">3.14 int(16 bit) and</A>
|
|
<B> Up:</B> <A NAME="tex2html719"
|
|
HREF="node19.html">3. Using SDCC</A>
|
|
<B> Previous:</B> <A NAME="tex2html713"
|
|
HREF="node31.html">3.12 Startup Code</A>
|
|
  <B> <A NAME="tex2html721"
|
|
HREF="node1.html">Contents</A></B>
|
|
  <B> <A NAME="tex2html723"
|
|
HREF="node61.html">Index</A></B>
|
|
<!--End of Navigation Panel-->
|
|
<ADDRESS>
|
|
<I>Johan Knol</I>
|
|
<BR><I>2001-07-13</I>
|
|
</ADDRESS>
|
|
</BODY>
|
|
</HTML>
|