go to single .html
[fw/sdcc] / doc / SDCCUdoc-13.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
2 <HTML>
3 <HEAD>
4  <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.7">
5  <TITLE>SDCC Compiler User Guide: Inline assembler code.</TITLE>
6  <LINK HREF="SDCCUdoc-14.html" REL=next>
7  <LINK HREF="SDCCUdoc-12.html" REL=previous>
8  <LINK HREF="SDCCUdoc.html#toc13" REL=contents>
9 </HEAD>
10 <BODY>
11 <A HREF="SDCCUdoc-14.html">Next</A>
12 <A HREF="SDCCUdoc-12.html">Previous</A>
13 <A HREF="SDCCUdoc.html#toc13">Contents</A>
14 <HR>
15 <H2><A NAME="Inline"></A> <A NAME="s13">13. Inline assembler code.</A> </H2>
16
17 <P>SDCC allows the use of in-line assembler with a few restriction as regards
18 labels. All labels defined within inline assembler code HAS TO BE of the form
19 nnnnn$ where nnnn is a number less than 100 (which implies a limit of
20 utmost 100 inline assembler labels per function). It is strongly recommended
21 that each assembly instruction (including labels) be placed in a separate line
22 ( as the example shows). When the <B>--peep-asm</B> command line option is used, the
23 inline assembler code will be passed through the peephole optimizer, this might
24 cause some unexpected changes in the inline assembler code, please go throught
25 the peephole optimizer rules defined in file 'SDCCpeeph.def' carefully before
26 using this option.
27 <P>
28 <PRE>
29 eg_asm 
30          mov b,#10 
31 00001$: 
32          djnz b,00001$
33  
34 _endasm ;
35  
36 </PRE>
37 <P>The inline assembler code can contain any valid code understood by the
38 assembler (this includes any assembler directives and comment lines ) . The
39 compiler does not do any validation of the code within the _asm ... _endasm;
40 keyword pair. 
41 <P>Inline assembler code cannot reference any C-Labels however it can reference
42 labels defined by the inline assembler.
43 <P>
44 <PRE>
45 egfoo() { 
46 ... /* some c code */ 
47 _asm 
48      ; some assembler code 
49  
50    ljmp $0003 
51 _endasm ; 
52 ... /* some more c code */ 
53 clabel:   /* inline
54  assembler cannot reference this label */ 
55 _asm 
56    $0003: ;label (can
57  be reference by inline assembler only) 
58 _endasm ; 
59 ... 
60 }
61  
62 </PRE>
63 <P>In other words inline assembly code can access labels defined in inline
64 assembly. The same goes the other way, ie. labels defines in inline assembly
65 CANNOT be accessed by C statements.
66 <HR>
67 <A HREF="SDCCUdoc-14.html">Next</A>
68 <A HREF="SDCCUdoc-12.html">Previous</A>
69 <A HREF="SDCCUdoc.html#toc13">Contents</A>
70 </BODY>
71 </HTML>