Reshaped doc's
[fw/sdcc] / doc / sdccman.html / node32.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
2
3 <!--Converted with LaTeX2HTML 99.1 release (March 30, 1999)
4 original version by:  Nikos Drakos, CBLU, University of Leeds
5 * revised and updated by:  Marcus Hennecke, Ross Moore, Herb Swan
6 * with significant contributions from:
7   Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
8 <HTML>
9 <HEAD>
10 <TITLE>3.13 Inline Assembler Code</TITLE>
11 <META NAME="description" CONTENT="3.13 Inline Assembler Code">
12 <META NAME="keywords" CONTENT="sdccman">
13 <META NAME="resource-type" CONTENT="document">
14 <META NAME="distribution" CONTENT="global">
15
16 <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
17 <META NAME="Generator" CONTENT="LaTeX2HTML v99.1 release">
18 <META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">
19
20 <LINK REL="STYLESHEET" HREF="sdccman.css">
21
22 <LINK REL="next" HREF="node33.html">
23 <LINK REL="previous" HREF="node31.html">
24 <LINK REL="up" HREF="node19.html">
25 <LINK REL="next" HREF="node33.html">
26 </HEAD>
27
28 <BODY >
29 <!--Navigation Panel-->
30 <A NAME="tex2html724"
31  HREF="node33.html">
32 <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next_motif.gif"></A> 
33 <A NAME="tex2html718"
34  HREF="node19.html">
35 <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up_motif.gif"></A> 
36 <A NAME="tex2html712"
37  HREF="node31.html">
38 <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="previous_motif.gif"></A> 
39 <A NAME="tex2html720"
40  HREF="node1.html">
41 <IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents_motif.gif"></A> 
42 <A NAME="tex2html722"
43  HREF="node61.html">
44 <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index_motif.gif"></A> 
45 <BR>
46 <B> Next:</B> <A NAME="tex2html725"
47  HREF="node33.html">3.14 int(16 bit) and</A>
48 <B> Up:</B> <A NAME="tex2html719"
49  HREF="node19.html">3. Using SDCC</A>
50 <B> Previous:</B> <A NAME="tex2html713"
51  HREF="node31.html">3.12 Startup Code</A>
52  &nbsp <B>  <A NAME="tex2html721"
53  HREF="node1.html">Contents</A></B> 
54  &nbsp <B>  <A NAME="tex2html723"
55  HREF="node61.html">Index</A></B> 
56 <BR>
57 <BR>
58 <!--End of Navigation Panel-->
59
60 <H2><A NAME="SECTION000413000000000000000">
61 3.13 Inline Assembler Code</A>
62 </H2>
63
64 <P>
65 SDCC allows the use of in-line assembler with a few restriction as
66 regards labels. All labels defined within inline assembler code <I>has
67 to be</I> of the form <I>nnnnn$</I> where nnnn is a number less than
68 100 (which implies a limit of utmost 100 inline assembler labels <I>per
69 function</I>). It is strongly recommended that each assembly
70 instruction (including labels) be placed in a separate line (as the
71 example shows). When the <I>-peep-asm</I> command line option is
72 used, the inline assembler code will be passed through the peephole
73 optimizer. This might cause some unexpected changes in the inline
74 assembler code. Please go throught the peephole optimizer rules defined
75 in file <I>SDCCpeeph.def</I> carefully before using this option.
76 <BR>
77
78 <BR>
79 <TT>_asm </TT>&nbsp;
80 <BR>
81 <TT>&nbsp;&nbsp;&nbsp;&nbsp;mov&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b,#10 </TT>&nbsp;
82 <BR>
83 <TT>00001$: </TT>&nbsp;
84 <BR>
85 <TT>&nbsp;&nbsp;&nbsp;&nbsp;djnz&nbsp;&nbsp;&nbsp;&nbsp;b,00001$ </TT>&nbsp;
86 <BR>
87 <TT>_endasm ;</TT>
88 <BR>
89
90 <BR>
91 The inline assembler code can contain any valid code understood by
92 the assembler, this includes any assembler directives and comment
93 lines. The compiler does not do any validation of the code within
94 the <TT>_asm ... _endasm;</TT> keyword pair. 
95 <BR>
96
97 <BR>
98 Inline assembler code cannot reference any C-Labels, however it can
99 reference labels defined by the inline assembler, e.g.:
100 <BR>
101
102 <BR>
103 <TT>foo() { </TT>&nbsp;
104 <BR>
105 <TT>&nbsp;&nbsp;&nbsp;&nbsp;/* some c code */ </TT>&nbsp;
106 <BR>
107 <TT>&nbsp;&nbsp;&nbsp;&nbsp;_asm </TT>&nbsp;
108 <BR>
109 <TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;; some assembler code </TT>&nbsp;
110 <BR>
111 <TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ljmp $0003 </TT>&nbsp;
112 <BR>
113 <TT>&nbsp;&nbsp;&nbsp;&nbsp;_endasm; </TT>&nbsp;
114 <BR>
115 <TT>&nbsp;&nbsp;&nbsp;&nbsp;/* some more c code */ </TT>&nbsp;
116 <BR>
117 <TT>clabel:&nbsp;&nbsp;/* inline assembler cannot reference this label
118 */ </TT>&nbsp;
119 <BR>
120 <TT>&nbsp;&nbsp;&nbsp;&nbsp;_asm</TT>&nbsp;
121 <BR>
122 <TT>&nbsp;&nbsp;&nbsp;&nbsp;$0003: ;label (can be reference by inline assembler
123 only) </TT>&nbsp;
124 <BR>
125 <TT>&nbsp;&nbsp;&nbsp;&nbsp;_endasm ; </TT>&nbsp;
126 <BR>
127 <TT>&nbsp;&nbsp;&nbsp;&nbsp;/* some more c code */</TT>&nbsp;
128 <BR>
129 <TT>}</TT>&nbsp;
130 <BR>&nbsp;
131 <BR>
132 In other words inline assembly code can access labels defined in inline
133 assembly within the scope of the funtion. 
134
135 <P>
136 The same goes the other way, ie. labels defines in inline assembly
137 CANNOT be accessed by C statements.
138
139 <P>
140 <HR>
141 <!--Navigation Panel-->
142 <A NAME="tex2html724"
143  HREF="node33.html">
144 <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next_motif.gif"></A> 
145 <A NAME="tex2html718"
146  HREF="node19.html">
147 <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up_motif.gif"></A> 
148 <A NAME="tex2html712"
149  HREF="node31.html">
150 <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="previous_motif.gif"></A> 
151 <A NAME="tex2html720"
152  HREF="node1.html">
153 <IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents_motif.gif"></A> 
154 <A NAME="tex2html722"
155  HREF="node61.html">
156 <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index_motif.gif"></A> 
157 <BR>
158 <B> Next:</B> <A NAME="tex2html725"
159  HREF="node33.html">3.14 int(16 bit) and</A>
160 <B> Up:</B> <A NAME="tex2html719"
161  HREF="node19.html">3. Using SDCC</A>
162 <B> Previous:</B> <A NAME="tex2html713"
163  HREF="node31.html">3.12 Startup Code</A>
164  &nbsp <B>  <A NAME="tex2html721"
165  HREF="node1.html">Contents</A></B> 
166  &nbsp <B>  <A NAME="tex2html723"
167  HREF="node61.html">Index</A></B> 
168 <!--End of Navigation Panel-->
169 <ADDRESS>
170 <I>Johan Knol</I>
171 <BR><I>2001-07-13</I>
172 </ADDRESS>
173 </BODY>
174 </HTML>