5b76eac9bd7dfa6fe1603eeb0c603e98515352a4
[fw/sdcc] / doc / SDCCUdoc.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</TITLE>
6  <LINK HREF="SDCCUdoc-1.html" REL=next>
7
8
9 </HEAD>
10 <BODY>
11 <A HREF="SDCCUdoc-1.html">Next</A>
12 Previous
13 Contents
14 <HR>
15 <H1>SDCC Compiler User Guide</H1>
16
17 <H2>Sandeep Dutta (sandeep.dutta@usa.net)</H2>
18 <P>
19 <H2><A NAME="toc1">1.</A> <A HREF="SDCCUdoc-1.html">Introduction</A></H2>
20
21 <P>
22 <H2><A NAME="toc2">2.</A> <A HREF="SDCCUdoc-2.html">Installation </A></H2>
23
24 <UL>
25 <LI><A HREF="SDCCUdoc-2.html#ss2.1">2.1 Components of SDCC</A>
26 <LI><A HREF="SDCCUdoc-2.html#ss2.2">2.2 Installation for Version &lt;= 2.1.7</A>
27 <LI><A HREF="SDCCUdoc-2.html#ss2.3">2.3 Installation for Version &gt;= 2.1.8a</A>
28 <P>
29 <H2><A NAME="toc3">3.</A> <A HREF="SDCCUdoc-3.html">Compiling.</A></H2>
30
31 <UL>
32 <LI><A HREF="SDCCUdoc-3.html#ss3.1">3.1 Single Source file projects.</A>
33 <LI><A HREF="SDCCUdoc-3.html#ss3.2">3.2 Projects with multiple source files.</A>
34 <LI><A HREF="SDCCUdoc-3.html#ss3.3">3.3 Projects with additional libraries.</A>
35 <P>
36 <H2><A NAME="toc4">4.</A> <A HREF="SDCCUdoc-4.html">Command Line options</A></H2>
37
38 <P>
39 <H2><A NAME="toc5">5.</A> <A HREF="SDCCUdoc-5.html">Language Extensions</A></H2>
40
41 <UL>
42 <LI><A HREF="SDCCUdoc-5.html#ss5.1">5.1 Storage Classes.</A>
43 <P>
44 <H2><A NAME="toc6">6.</A> <A HREF="SDCCUdoc-6.html">Optimizations</A></H2>
45
46 <UL>
47 <LI><A HREF="SDCCUdoc-6.html#ss6.1">6.1 Sub-expression elimination</A>
48 <LI><A HREF="SDCCUdoc-6.html#ss6.2">6.2 Dead-Code elimination.</A>
49 <LI><A HREF="SDCCUdoc-6.html#ss6.3">6.3 Copy-Propagation:</A>
50 <LI><A HREF="SDCCUdoc-6.html#ss6.4">6.4 Loop optimizations</A>
51 <LI><A HREF="SDCCUdoc-6.html#ss6.5">6.5 Algebraic simplifications:</A>
52 <LI><A HREF="SDCCUdoc-6.html#ss6.6">6.6 'switch' statements.</A>
53 <LI><A HREF="SDCCUdoc-6.html#ss6.7">6.7 bit-shifting operations.</A>
54 <LI><A HREF="SDCCUdoc-6.html#ss6.8">6.8 Highest Order Bit.</A>
55 <LI><A HREF="SDCCUdoc-6.html#ss6.9">6.9 Peep-hole optimizer.</A>
56 <P>
57 <H2><A NAME="toc7">7.</A> <A HREF="SDCCUdoc-7.html">Pointers</A></H2>
58
59 <P>
60 <H2><A NAME="toc8">8.</A> <A HREF="SDCCUdoc-8.html">Parameters &amp; Local Variables</A></H2>
61
62 <UL>
63 <LI><A HREF="SDCCUdoc-8.html#ss8.1">8.1 Overlaying</A>
64 <P>
65 <H2><A NAME="toc9">9.</A> <A HREF="SDCCUdoc-9.html">critical Functions.</A></H2>
66
67 <P>
68 <H2><A NAME="toc10">10.</A> <A HREF="SDCCUdoc-10.html">Absolute addressing.</A></H2>
69
70 <P>
71 <H2><A NAME="toc11">11.</A> <A HREF="SDCCUdoc-11.html">Interrupt Service Routines</A></H2>
72
73 <P>
74 <H2><A NAME="toc12">12.</A> <A HREF="SDCCUdoc-12.html">Startup Code</A></H2>
75
76 <P>
77 <H2><A NAME="toc13">13.</A> <A HREF="SDCCUdoc-13.html">Inline assembler code.</A></H2>
78
79 <P>
80 <H2><A NAME="toc14">14.</A> <A HREF="SDCCUdoc-14.html">int (16 bit) and long (32 bit ) support.</A></H2>
81
82 <P>
83 <H2><A NAME="toc15">15.</A> <A HREF="SDCCUdoc-15.html">Floating point support</A></H2>
84
85 <P>
86 <H2><A NAME="toc16">16.</A> <A HREF="SDCCUdoc-16.html">Memory Models</A></H2>
87
88 <P>
89 <H2><A NAME="toc17">17.</A> <A HREF="SDCCUdoc-17.html">Flat 24 bit addressing model.</A></H2>
90
91 <P>
92 <H2><A NAME="toc18">18.</A> <A HREF="SDCCUdoc-18.html">Defines created by the compiler.</A></H2>
93
94 <P>
95 <H2><A NAME="toc19">19.</A> <A HREF="SDCCUdoc-19.html">Pragmas</A></H2>
96
97 <P>
98 <H2><A NAME="toc20">20.</A> <A HREF="SDCCUdoc-20.html">Library routines.</A></H2>
99
100 <P>
101 <PRE>
102 printf_small("my str %s, my int %d\n",(char _generic *)mystr,myint);
103   
104 </PRE>
105
106 <P>
107 <UL>
108 <LI><B>stdarg.h </B>- contains definition for the following macros to be used for
109 variable parameter list, note that a function can have a variable parameter
110 list if and only if it is 'reentrant'
111 <P>va_list, va_start, va_arg, va_end.
112 </LI>
113 <LI><B>setjmp.h </B>- contains defintion for ANSI<B> setjmp </B>&amp; <B>longjmp</B> routines. Note
114 in this case setjmp &amp; longjmp can be used between functions executing within
115 the same register bank, if long jmp is executed from a function that is using
116 a different register bank from the function issuing the setjmp function, the
117 results may be unpredictable. The jump buffer requires 3 bytes of data (the
118 stack pointer &amp; a 16 byte return address), and can be placed in any address
119 space.</LI>
120 <LI><B>stdlib.h</B> - contains the following functions.
121 <P>atoi, atol.
122 </LI>
123 <LI><B>string.h </B>- contains the following functions.
124 <P>strcpy, strncpy, strcat, strncat, strcmp, strncmp, strchr, strrchr, strspn,
125 strcspn, strpbrk, strstr, strlen, strtok, memcpy, memcmp, memset.
126 </LI>
127 <LI><B>ctype.h</B> - contains the following routines.
128 <P>iscntrl, isdigit, isgraph, islower, isupper, isprint, ispunct, isspace,
129 isxdigit, isalnum, isalpha.
130 </LI>
131 <LI><B>malloc.h</B> - The malloc routines are developed by Dmitry S. Obukhov (dso@usa.net).
132 These routines will allocate memory from the external ram. Here is a description
133 on how to use them (as described by the author).
134 <PRE>
135 //Example: 
136      //     #define DYNAMIC_MEMORY_SIZE 0x2000 
137      //    
138  ..... 
139      //     unsigned char xdata dynamic_memory_pool[DYNAMIC_MEMORY_SIZE];
140  
141      //     unsigned char xdata * current_buffer; 
142      //     ..... 
143     
144  //     void main(void) 
145      //     { 
146      //         ... 
147      //        
148  init_dynamic_memory(dynamic_memory_pool,DYNAMIC_MEMORY_SIZE); 
149      //        
150  //Now it's possible to use malloc. 
151      //         ... 
152      //         current_buffer
153  = malloc(0x100); 
154      //
155   
156 </PRE>
157 </LI>
158 <LI><B>serial.h</B> - Serial IO routines are also developed by Dmitry S. Obukhov (dso@usa.net).
159 These routines are interrupt driven with a 256 byte circular buffer, they also
160 expect external ram to be present. Please see documentation in file SDCCDIR/sdcc51lib/serial.c
161 . Note the header file "serial.h" MUST be included in the file containing the
162 'main' function.</LI>
163 <LI><B>ser.h </B>- Alternate serial routine provided by Wolfgang Esslinger &lt;wolfgang@WiredMinds.com&gt;
164 these routines are more compact and faster. Please see documentation in file
165 SDCCDIR/sdcc51lib/ser.c</LI>
166 <LI><B>ser_ir.h </B>- Another alternate set of serial routines provided by Josef Wolf
167 &lt;jw@raven.inka.de&gt; , these routines do not use the external ram.</LI>
168 <LI><B>reg51.h</B> - contains register definitions for a standard 8051</LI>
169 <LI><B>reg552.h </B>- contains register definitions for 80C552.</LI>
170 <LI><B>float.h</B> - contains min, max and other floating point related stuff.</LI>
171 </UL>
172 <P>All library routines are compiled as --model-small , they are all non-reentrant,
173 if you plan to use the large model or want to make these routines reentrant,
174 then they will have to be recompiled with the appropriate compiler option.
175 <P>Have not had time to do the more involved routines like printf, will get
176 to them shortly.
177 <P>
178 <H2><A NAME="toc21">21.</A> <A HREF="SDCCUdoc-21.html">Interfacing with assembly routines.</A></H2>
179
180 <UL>
181 <LI><A HREF="SDCCUdoc-21.html#ss21.1">21.1 Global registers used for parameter passing.</A>
182 <LI><A HREF="SDCCUdoc-21.html#ss21.2">21.2 With --noregparms option.</A>
183 <P>
184 <H2><A NAME="toc22">22.</A> <A HREF="SDCCUdoc-22.html">External Stack.</A></H2>
185
186 <P>
187 <H2><A NAME="toc23">23.</A> <A HREF="SDCCUdoc-23.html">ANSI-Compliance.</A></H2>
188
189 <P>
190 <H2><A NAME="toc24">24.</A> <A HREF="SDCCUdoc-24.html">Cyclomatic Complexity</A></H2>
191
192 <P>
193 <H2><A NAME="toc25">25.</A> <A HREF="SDCCUdoc-25.html">TIPS</A></H2>
194
195 <P>
196 <H2><A NAME="toc26">26.</A> <A HREF="SDCCUdoc-26.html">Retargetting for other MCUs.</A></H2>
197
198 <P>
199 <H2><A NAME="toc27">27.</A> <A HREF="SDCCUdoc-27.html">Reporting Bugs</A></H2>
200
201 <P>
202 <H2><A NAME="toc28">28.</A> <A HREF="SDCCUdoc-28.html">SDCDB - Source level debugger.</A></H2>
203
204 <UL>
205 <LI><A HREF="SDCCUdoc-28.html#ss28.1">28.1 Compiling for debugging.</A>
206 <LI><A HREF="SDCCUdoc-28.html#ss28.2">28.2 How the debugger works.</A>
207 <LI><A HREF="SDCCUdoc-28.html#ss28.3">28.3 Starting the debugger.</A>
208 <LI><A HREF="SDCCUdoc-28.html#ss28.4">28.4 Command line options.</A>
209 <LI><A HREF="SDCCUdoc-28.html#ss28.5">28.5 Debugger Commands.</A>
210 <LI><A HREF="SDCCUdoc-28.html#ss28.6">28.6 Interfacing with XEmacs.</A>
211 <P>
212 <H2><A NAME="toc29">29.</A> <A HREF="SDCCUdoc-29.html">Conclusion</A></H2>
213
214 <P>
215 <H2><A NAME="toc30">30.</A> <A HREF="SDCCUdoc-30.html">Acknowledgments</A></H2>
216
217 <P>
218 <H2><A NAME="toc31">31.</A> <A HREF="SDCCUdoc-31.html">Appendix A: The Z80 and gbz80 port</A></H2>
219
220 <HR>
221 <A HREF="SDCCUdoc-1.html">Next</A>
222 Previous
223 Contents
224 </BODY>
225 </HTML>