1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
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>
11 <A HREF="SDCCUdoc-1.html">Next</A>
15 <H1>SDCC Compiler User Guide</H1>
17 <H2>Sandeep Dutta (sandeep.dutta@usa.net)</H2>
19 <H2><A NAME="toc1">1.</A> <A HREF="SDCCUdoc-1.html">Introduction</A></H2>
22 <H2><A NAME="toc2">2.</A> <A HREF="SDCCUdoc-2.html">Installation </A></H2>
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 <= 2.1.7</A>
27 <LI><A HREF="SDCCUdoc-2.html#ss2.3">2.3 Installation for Version >= 2.1.8a</A>
29 <H2><A NAME="toc3">3.</A> <A HREF="SDCCUdoc-3.html">Compiling.</A></H2>
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>
36 <H2><A NAME="toc4">4.</A> <A HREF="SDCCUdoc-4.html">Command Line options</A></H2>
39 <H2><A NAME="toc5">5.</A> <A HREF="SDCCUdoc-5.html">Language Extensions</A></H2>
42 <LI><A HREF="SDCCUdoc-5.html#ss5.1">5.1 Storage Classes.</A>
44 <H2><A NAME="toc6">6.</A> <A HREF="SDCCUdoc-6.html">Optimizations</A></H2>
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>
57 <H2><A NAME="toc7">7.</A> <A HREF="SDCCUdoc-7.html">Pointers</A></H2>
60 <H2><A NAME="toc8">8.</A> <A HREF="SDCCUdoc-8.html">Parameters & Local Variables</A></H2>
63 <LI><A HREF="SDCCUdoc-8.html#ss8.1">8.1 Overlaying</A>
65 <H2><A NAME="toc9">9.</A> <A HREF="SDCCUdoc-9.html">critical Functions.</A></H2>
68 <H2><A NAME="toc10">10.</A> <A HREF="SDCCUdoc-10.html">Absolute addressing.</A></H2>
71 <H2><A NAME="toc11">11.</A> <A HREF="SDCCUdoc-11.html">Interrupt Service Routines</A></H2>
74 <H2><A NAME="toc12">12.</A> <A HREF="SDCCUdoc-12.html">Startup Code</A></H2>
77 <H2><A NAME="toc13">13.</A> <A HREF="SDCCUdoc-13.html">Inline assembler code.</A></H2>
80 <H2><A NAME="toc14">14.</A> <A HREF="SDCCUdoc-14.html">int (16 bit) and long (32 bit ) support.</A></H2>
83 <H2><A NAME="toc15">15.</A> <A HREF="SDCCUdoc-15.html">Floating point support</A></H2>
86 <H2><A NAME="toc16">16.</A> <A HREF="SDCCUdoc-16.html">Memory Models</A></H2>
89 <H2><A NAME="toc17">17.</A> <A HREF="SDCCUdoc-17.html">Flat 24 bit addressing model.</A></H2>
92 <H2><A NAME="toc18">18.</A> <A HREF="SDCCUdoc-18.html">Defines created by the compiler.</A></H2>
95 <H2><A NAME="toc19">19.</A> <A HREF="SDCCUdoc-19.html">Pragmas</A></H2>
98 <H2><A NAME="toc20">20.</A> <A HREF="SDCCUdoc-20.html">Library routines.</A></H2>
102 printf_small("my str %s, my int %d\n",(char _generic *)mystr,myint);
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.
113 <LI><B>setjmp.h </B>- contains defintion for ANSI<B> setjmp </B>& <B>longjmp</B> routines. Note
114 in this case setjmp & 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 & a 16 byte return address), and can be placed in any address
120 <LI><B>stdlib.h</B> - contains the following functions.
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.
127 <LI><B>ctype.h</B> - contains the following routines.
128 <P>iscntrl, isdigit, isgraph, islower, isupper, isprint, ispunct, isspace,
129 isxdigit, isalnum, isalpha.
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).
136 // #define DYNAMIC_MEMORY_SIZE 0x2000
139 // unsigned char xdata dynamic_memory_pool[DYNAMIC_MEMORY_SIZE];
141 // unsigned char xdata * current_buffer;
148 init_dynamic_memory(dynamic_memory_pool,DYNAMIC_MEMORY_SIZE);
150 //Now it's possible to use malloc.
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 <wolfgang@WiredMinds.com>
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 <jw@raven.inka.de> , 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>
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
178 <H2><A NAME="toc21">21.</A> <A HREF="SDCCUdoc-21.html">Interfacing with assembly routines.</A></H2>
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>
184 <H2><A NAME="toc22">22.</A> <A HREF="SDCCUdoc-22.html">External Stack.</A></H2>
187 <H2><A NAME="toc23">23.</A> <A HREF="SDCCUdoc-23.html">ANSI-Compliance.</A></H2>
190 <H2><A NAME="toc24">24.</A> <A HREF="SDCCUdoc-24.html">Cyclomatic Complexity</A></H2>
193 <H2><A NAME="toc25">25.</A> <A HREF="SDCCUdoc-25.html">TIPS</A></H2>
196 <H2><A NAME="toc26">26.</A> <A HREF="SDCCUdoc-26.html">Retargetting for other MCUs.</A></H2>
199 <H2><A NAME="toc27">27.</A> <A HREF="SDCCUdoc-27.html">Reporting Bugs</A></H2>
202 <H2><A NAME="toc28">28.</A> <A HREF="SDCCUdoc-28.html">SDCDB - Source level debugger.</A></H2>
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>
212 <H2><A NAME="toc29">29.</A> <A HREF="SDCCUdoc-29.html">Conclusion</A></H2>
215 <H2><A NAME="toc30">30.</A> <A HREF="SDCCUdoc-30.html">Acknowledgments</A></H2>
218 <H2><A NAME="toc31">31.</A> <A HREF="SDCCUdoc-31.html">Appendix A: The Z80 and gbz80 port</A></H2>
221 <A HREF="SDCCUdoc-1.html">Next</A>