Borland make apparebtly dislikes trailing whitespace...
[fw/sdcc] / doc / SDCCUdoc.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
2
3 <!--Converted with LaTeX2HTML 2K.1beta (1.47)
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>lSDCC Compiler User Guide</TITLE>
11 <META NAME="description" CONTENT="lSDCC Compiler User Guide">
12 <META NAME="keywords" CONTENT="SDCCUdoc">
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 v2K.1beta">
18 <META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">
19
20 <LINK REL="STYLESHEET" HREF="SDCCUdoc.css">
21
22 </HEAD>
23
24 <BODY >
25 <!--Navigation Panel-->
26 <IMG WIDTH="81" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next_inactive"
27  SRC="file:/usr/share/latex2html/icons/nx_grp_g.png"> 
28 <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up"
29  SRC="file:/usr/share/latex2html/icons/up_g.png"> 
30 <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous"
31  SRC="file:/usr/share/latex2html/icons/prev_g.png">   
32 <BR>
33 <BR>
34 <BR>
35 <!--End of Navigation Panel-->
36
37 <P>
38
39 <P>
40 <H1 ALIGN="CENTER">lSDCC Compiler User Guide</H1>
41 <BR>
42
43 <H2><A NAME="SECTION00010000000000000000">
44 Contents</A>
45 </H2>
46 <!--Table of Contents-->
47
48 <UL>
49 <LI><A NAME="tex2html122"
50   HREF="SDCCUdoc.html">1 Introduction</A>
51 <UL>
52 <LI><A NAME="tex2html123"
53   HREF="#SECTION00021000000000000000">1.1 About SDCC</A>
54 <LI><A NAME="tex2html124"
55   HREF="#SECTION00022000000000000000">1.2 Open Source</A>
56 <LI><A NAME="tex2html125"
57   HREF="#SECTION00023000000000000000">1.3 Typographic conventions</A>
58 <LI><A NAME="tex2html126"
59   HREF="#SECTION00024000000000000000">1.4 Pending: compatibilaty with previous versions</A>
60 <LI><A NAME="tex2html127"
61   HREF="#SECTION00025000000000000000">1.5 System Requirements</A>
62 <LI><A NAME="tex2html128"
63   HREF="#SECTION00026000000000000000">1.6 Other Resources</A>
64 </UL>
65 <BR>
66 <LI><A NAME="tex2html129"
67   HREF="#SECTION00030000000000000000">2 Installation</A>
68 <UL>
69 <LI><A NAME="tex2html130"
70   HREF="#SECTION00031000000000000000">2.1 Linux/Unix Installation</A>
71 <LI><A NAME="tex2html131"
72   HREF="#SECTION00032000000000000000">2.2 Windows Installation</A>
73 <LI><A NAME="tex2html132"
74   HREF="#SECTION00033000000000000000">2.3 Testing out the SDCC Compiler</A>
75 <LI><A NAME="tex2html133"
76   HREF="#SECTION00034000000000000000">2.4 Install Trouble-shooting</A>
77 <LI><A NAME="tex2html134"
78   HREF="#SECTION00035000000000000000">2.5 Additional Information for Windows Users</A>
79 <LI><A NAME="tex2html135"
80   HREF="#SECTION00036000000000000000">2.6 SDCC on Other Platforms</A>
81 <LI><A NAME="tex2html136"
82   HREF="#SECTION00037000000000000000">2.7 Advanced Install Options</A>
83 <LI><A NAME="tex2html137"
84   HREF="#SECTION00038000000000000000">2.8 Components of SDCC</A>
85 </UL>
86 <BR>
87 <LI><A NAME="tex2html138"
88   HREF="#SECTION00040000000000000000">3 Using SDCC</A>
89 <UL>
90 <LI><A NAME="tex2html139"
91   HREF="#SECTION00041000000000000000">3.1 Compiling</A>
92 <LI><A NAME="tex2html140"
93   HREF="#SECTION00042000000000000000">3.2 Command Line Options</A>
94 <LI><A NAME="tex2html141"
95   HREF="#SECTION00043000000000000000">3.3 MCS51/DS390 Storage Class Language Extensions</A>
96 <LI><A NAME="tex2html142"
97   HREF="#SECTION00044000000000000000">3.4 Pointers</A>
98 <LI><A NAME="tex2html143"
99   HREF="#SECTION00045000000000000000">3.5 Parameters &amp; Local Variables</A>
100 <LI><A NAME="tex2html144"
101   HREF="#SECTION00046000000000000000">3.6 Overlaying</A>
102 <LI><A NAME="tex2html145"
103   HREF="#SECTION00047000000000000000">3.7 Interrupt Service Routines</A>
104 <LI><A NAME="tex2html146"
105   HREF="#SECTION00048000000000000000">3.8 Critical Functions</A>
106 <LI><A NAME="tex2html147"
107   HREF="#SECTION00049000000000000000">3.9 Naked Functions</A>
108 <LI><A NAME="tex2html148"
109   HREF="#SECTION000410000000000000000">3.10 Functions using private banks</A>
110 <LI><A NAME="tex2html149"
111   HREF="#SECTION000411000000000000000">3.11 Absolute Addressing</A>
112 <LI><A NAME="tex2html150"
113   HREF="#SECTION000412000000000000000">3.12 Startup Code</A>
114 <LI><A NAME="tex2html151"
115   HREF="#SECTION000413000000000000000">3.13 Inline Assembler Code</A>
116 <LI><A NAME="tex2html152"
117   HREF="#SECTION000414000000000000000">3.14 int(16 bit) and long (32 bit) Support</A>
118 <LI><A NAME="tex2html153"
119   HREF="#SECTION000415000000000000000">3.15 Floating Point Support</A>
120 <LI><A NAME="tex2html154"
121   HREF="#SECTION000416000000000000000">3.16 MCS51 Memory Models</A>
122 <LI><A NAME="tex2html155"
123   HREF="#SECTION000417000000000000000">3.17 DS390 Memory Models</A>
124 <LI><A NAME="tex2html156"
125   HREF="#SECTION000418000000000000000">3.18 Defines Created by the Compiler</A>
126 </UL>
127 <BR>
128 <LI><A NAME="tex2html157"
129   HREF="#SECTION00050000000000000000">4 SDCC Technical Data</A>
130 <UL>
131 <LI><A NAME="tex2html158"
132   HREF="#SECTION00051000000000000000">4.1 Optimizations</A>
133 <LI><A NAME="tex2html159"
134   HREF="#SECTION00052000000000000000">4.2 Pragmas</A>
135 <LI><A NAME="tex2html160"
136   HREF="#SECTION00053000000000000000">4.3 Library Routines</A>
137 <LI><A NAME="tex2html161"
138   HREF="#SECTION00054000000000000000">4.4 Interfacing with Assembly Routines</A>
139 <LI><A NAME="tex2html162"
140   HREF="#SECTION00055000000000000000">4.5 Global Registers used for Parameter Passing</A>
141 <LI><A NAME="tex2html163"
142   HREF="#SECTION00056000000000000000">4.6 External Stack</A>
143 <LI><A NAME="tex2html164"
144   HREF="#SECTION00057000000000000000">4.7 ANSI-Compliance</A>
145 <LI><A NAME="tex2html165"
146   HREF="#SECTION00058000000000000000">4.8 Cyclomatic Complexity</A>
147 </UL>
148 <BR>
149 <LI><A NAME="tex2html166"
150   HREF="#SECTION00060000000000000000">5 TIPS</A>
151 <LI><A NAME="tex2html167"
152   HREF="#SECTION00070000000000000000">6 Retargetting for other MCUs.</A>
153 <LI><A NAME="tex2html168"
154   HREF="#SECTION00080000000000000000">7 SDCDB - Source Level Debugger</A>
155 <UL>
156 <LI><A NAME="tex2html169"
157   HREF="#SECTION00081000000000000000">7.1 Compiling for Debugging</A>
158 <LI><A NAME="tex2html170"
159   HREF="#SECTION00082000000000000000">7.2 How the Debugger Works</A>
160 <LI><A NAME="tex2html171"
161   HREF="#SECTION00083000000000000000">7.3 Starting the Debugger</A>
162 <LI><A NAME="tex2html172"
163   HREF="#SECTION00084000000000000000">7.4 Command Line Options.</A>
164 <LI><A NAME="tex2html173"
165   HREF="#SECTION00085000000000000000">7.5 Debugger Commands.</A>
166 <LI><A NAME="tex2html174"
167   HREF="#SECTION00086000000000000000">7.6 Interfacing with XEmacs.</A>
168 </UL>
169 <BR>
170 <LI><A NAME="tex2html175"
171   HREF="#SECTION00090000000000000000">8 Other Processors</A>
172 <UL>
173 <LI><A NAME="tex2html176"
174   HREF="#SECTION00091000000000000000">8.1 The Z80 and gbz80 port</A>
175 </UL>
176 <BR>
177 <LI><A NAME="tex2html177"
178   HREF="#SECTION000100000000000000000">9 Support</A>
179 <UL>
180 <LI><A NAME="tex2html178"
181   HREF="#SECTION000101000000000000000">9.1 Reporting Bugs</A>
182 <LI><A NAME="tex2html179"
183   HREF="#SECTION000102000000000000000">9.2 Acknowledgments</A>
184 </UL>
185 <BR>
186 <LI><A NAME="tex2html180"
187   HREF="#SECTION000110000000000000000">About this document ...</A>
188 </UL>
189 <!--End of Table of Contents-->
190
191 <P>
192
193 <H1><A NAME="SECTION00020000000000000000">
194 1 Introduction</A>
195 </H1>
196
197 <P>
198
199 <H2><A NAME="SECTION00021000000000000000">
200 1.1 About SDCC</A>
201 </H2>
202
203 <P>
204 <I>&lt;pending: tabularise these features, this is unreadeble&gt;</I>
205 <BR>
206 <BR><B>SDCC</B> is a Free ware, retargettable, optimizing ANSI-C compiler
207 by <B>Sandeep Dutta</B> designed for 8 bit Microprocessors. The
208 current version targets Intel MCS51 based Microprocessors(8051,8052,
209 etc), Zilog Z80 based MCUs, and the Dallas 80C390 MCS51 variant. It
210 can be retargetted for other microprocessors, support for PIC, AVR
211 and 186 is under development. The entire source code for the compiler
212 is distributed under GPL. SDCC uses ASXXXX &amp; ASLINK, a Freeware,
213 retargettable assembler &amp; linker. SDCC has extensive language extensions
214 suitable for utilizing various microcontrollers underlying hardware
215 effectively. In addition to the MCU specific optimizations SDCC also
216 does a host of standard optimizations like <I>global sub expression
217 elimination, loop optimizations (loop invariant, strength reduction
218 of induction variables and loop reversing), constant folding &amp; propagation,
219 copy propagation, dead code elimination and jumptables for 'switch'
220 statements.</I> For the back-end SDCC uses a global register allocation
221 scheme which should be well suited for other 8 bit MCUs. The peep
222 hole optimizer uses a rule based substitution mechanism which is MCU
223 dependent. Supported data-types are <I>char (8 bits, 1 byte), short
224 and int (16 bits, 2 bytes), long (32 bit, 4 bytes)</I> and <I>float
225 (4 byte IEEE).</I> The compiler also allows <I>inline assembler code</I>
226 to be embedded anywhere in a function. In addition routines developed
227 in assembly can also be called. SDCC also provides an option to report
228 the relative complexity of a function, these functions can then be
229 further optimized, or hand coded in assembly if needed. SDCC also
230 comes with a companion source level debugger SDCDB, the debugger currently
231 uses ucSim a freeware simulator for 8051 and other micro-controllers.
232 The latest version can be downloaded from <B>http://sdcc.sourceforge.net/
233 .</B>
234
235 <P>
236
237 <H2><A NAME="SECTION00022000000000000000">
238 1.2 Open Source</A>
239 </H2>
240
241 <P>
242 All packages used in this compiler system are <I>opensource</I> and
243 <I>freeware</I>; source code for all the sub-packages (asxxxx assembler/linker,
244 pre-processor) is distributed with the package. This documentation
245 is maintained using a freeware word processor (LYX). 
246
247 <P>
248 This program is free software; you can redistribute it and/or modify
249 it under the terms of the GNU General Public License as published
250 by the Free Software Foundation; either version 2, or (at your option)
251 any later version. This program is distributed in the hope that it
252 will be useful, but WITHOUT ANY WARRANTY; without even the implied
253 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
254 the GNU General Public License for more details. You should have received
255 a copy of the GNU General Public License along with this program;
256 if not, write to the Free Software Foundation, 59 Temple Place - Suite
257 330, Boston, MA 02111-1307, USA. In other words, you are welcome to
258 use, share and improve this program. You are forbidden to forbid anyone
259 else to use, share and improve what you give them. Help stamp out
260 software-hoarding! 
261 <BR>
262 <BR><I>&lt;pending: add a link to gnu&gt;</I>
263
264 <P>
265
266 <H2><A NAME="SECTION00023000000000000000">
267 1.3 Typographic conventions</A>
268 </H2>
269
270 <P>
271 Throughout this manual, we will use the following convention. Commands
272 you have to type in are printed in <I><B>&#34;sans
273 serif&#34;</B></I><I>.</I> Code samples are printed in <TT>typewriter
274 font.</TT> Interesting items and new terms are printed in <I>italicised
275 type.</I>
276
277 <P>
278
279 <H2><A NAME="SECTION00024000000000000000">
280 1.4 Pending: compatibilaty with previous versions</A>
281 </H2>
282
283 <P>
284 This version has numerous bug fixes comperated with the previous version.
285 But we also introduced some incompatibilaties with older versions.
286 Not just for the fun of it, but to make the compiler more stable,
287 efficient and ANSI compliant. 
288 <BR>
289 <BR>
290 short char
291 <BR>
292 directory structure (2.7)
293 <BR>
294 vararg pars expl int unless casted
295 <BR>
296 never had a regextend
297 <BR>
298 no -noreparms anymore
299 <BR>
300 <BR>
301 more?
302
303 <P>
304
305 <H2><A NAME="SECTION00025000000000000000">
306 1.5 System Requirements</A>
307 </H2>
308
309 <P>
310 What do you need before you start installation of SDCC? A computer,
311 and a desire to compute. The preferred method of installation is to
312 compile SDCC from source using GNU GCC and make. For Windows some
313 pre-compiled binary distributions are available for your convenience.
314 You should have some experience with command line tools and compiler
315 use.
316
317 <P>
318
319 <H2><A NAME="SECTION00026000000000000000">
320 1.6 Other Resources</A>
321 </H2>
322
323 <P>
324 The SDCC home page at http://sdcc.sourceforge.net/ is a great
325 place to find distribution sets. You can also find links to the user
326 mailing lists that offer help or discuss SDCC with other SDCC users.
327 Web links to other SDCC related sites can also be found here. This
328 document can be found in the DOC directory of the source package as
329 a text or HTML file. Some of the other tools (simulator and assembler)
330 included with SDCC contain their own documentation and can be found
331 in the source distribution. If you want the latest unreleased software,
332 the complete source package is available directly by anonymous CVS
333 on cvs.sdcc.sourceforge.net.
334
335 <P>
336
337 <H1><A NAME="SECTION00030000000000000000">
338 2 Installation</A>
339 </H1>
340
341 <P>
342
343 <H2><A NAME="SECTION00031000000000000000">
344 2.1 Linux/Unix Installation</A>
345 </H2>
346
347 <P>
348
349 <OL>
350 <LI>Download the source package, it will be named something like sdcc-2.x.x.tgz.
351 </LI>
352 <LI>Bring up a command line terminal, such as xterm.
353 </LI>
354 <LI>Unpack the file using a command like: <I><B>&#34;tar
355 -xzf sdcc-2.x.x.tgz&#34;</B></I>, this will create a sub-directory
356 called sdcc with all of the sources.
357 </LI>
358 <LI>Change directory into the main SDCC directory, for example type: <I><B>&#34;cd
359 sdcc&#34;</B></I><I>.</I>
360 </LI>
361 <LI>Type <I><B>&#34;./configure&#34;</B></I>. This configures
362 the package for compilation on your system.
363 </LI>
364 <LI>Type <I><B>&#34;make&#34;</B></I>. All of the source
365 packages will compile, this can take a while.
366 </LI>
367 <LI>Type <I><B>&#34;make install&#34;</B></I> as root. This
368 copies the binary executables to the install directories.
369 </LI>
370 </OL>
371
372 <P>
373
374 <H2><A NAME="SECTION00032000000000000000">
375 2.2 Windows Installation</A>
376 </H2>
377
378 <P>
379 <I>&lt;pending: is this complete? where is borland, mingw&gt;</I>
380 <BR>
381 <BR>
382 For installation under Windows you first need to pick between a pre-compiled
383 binary package, or installing the source package along with the Cygwin
384 package. The binary package is the quickest to install, while the
385 Cygwin package includes all of the open source power tools used to
386 compile the complete SDCC source package in the Windows environment.
387 If you are not familiar with the Unix command line environment, you
388 may want to read the section on additional information for Windows
389 users prior to your initial installation.
390
391 <P>
392
393 <H3><A NAME="SECTION00032100000000000000">
394 2.2.1 Windows Install Using a Binary Package</A>
395 </H3>
396
397 <P>
398
399 <OL>
400 <LI>Download the binary package and unpack it using your favorite unpacking
401 tool (gunzip, WinZip, etc). This should unpack to a group of sub-directories.
402 An example directory structure after unpacking is: c:&#92;usr&#92;local&#92;bin
403 for the executables, c:&#92;usr&#92;local&#92;share&#92;sdcc&#92;include
404 and c:&#92;usr&#92;local&#92;share&#92;sdcc&#92;lib
405 for the include and libraries.
406 </LI>
407 <LI>Adjust your environment PATH to include the location of the bin directory.
408 For example, make a setsdcc.bat file with the following: set PATH=c:&#92;usr&#92;local&#92;bin;%PATH%
409 </LI>
410 <LI>When you compile with sdcc, you may need to specify the location of
411 the lib and include folders. For example, sdcc -I c:&#92;usr&#92;local&#92;share&#92;sdcc&#92;include
412 -L c:&#92;usr&#92;local&#92;share&#92;sdcc&#92;lib&#92;small
413 test.c
414 </LI>
415 </OL>
416
417 <P>
418
419 <H3><A NAME="SECTION00032200000000000000">
420 2.2.2 Windows Install Using Cygwin</A>
421 </H3>
422
423 <P>
424
425 <OL>
426 <LI>Download and install the cygwin package from the redhat sitehttp://sources.redhat.com/cygwin/.
427 Currently, this involved downloading a small install program which
428 then automates downloading and installing selected parts of the package
429 (a large 80M byte sized dowload for the whole thing). 
430 </LI>
431 <LI>Bring up a Unix/Bash command line terminal from the Cygwin menu.
432 </LI>
433 <LI>Follow the instructions in the preceding Linux/Unix installation section.
434 </LI>
435 </OL>
436
437 <P>
438
439 <H2><A NAME="SECTION00033000000000000000">
440 2.3 Testing out the SDCC Compiler</A>
441 </H2>
442
443 <P>
444 The first thing you should do after installing your SDCC compiler
445 is to see if it runs. Type <I><B>&#34;sdcc -version&#34;</B></I>
446 at the prompt, and the program should run and tell you the version.
447 If it doesn't run, or gives a message about not finding sdcc program,
448 then you need to check over your installation. Make sure that the
449 sdcc bin directory is in your executable search path defined by the
450 PATH environment setting (see the Trouble-shooting section for suggestions).
451 Make sure that the sdcc program is in the bin folder, if not perhaps
452 something did not install correctly.
453 <BR>
454 <BR>
455 SDCC binaries are commonly installed in a directory arrangement like
456 this:
457 <BR>
458 <P>
459 <TABLE CELLPADDING=3 BORDER="1">
460 <TR><TD ALIGN="LEFT">/usr/local/bin</TD>
461 <TD ALIGN="LEFT">Holds executables(sdcc, s51, aslink, ...)</TD>
462 </TR>
463 <TR><TD ALIGN="LEFT">/usr/local/share/sdcc/lib</TD>
464 <TD ALIGN="LEFT">Holds common C libraries</TD>
465 </TR>
466 <TR><TD ALIGN="LEFT">/usr/local/share/sdcc/include</TD>
467 <TD ALIGN="LEFT">Holds common C header files</TD>
468 </TR>
469 </TABLE>
470 <BR>
471 <BR>
472 Make sure the compiler works on a very simple example. Type in the
473 following test.c program using your favorite editor:
474 <BR>
475 <BR>
476 Compile this using the following command: <I><B>&#34;sdcc
477 -c test.c&#34;</B></I> If all goes well, the compiler will generate
478 a test.asm and test.rel file. Congratulations, you've just compiled
479 your first program with SDCC. We used the -c option to tell SDCC not
480 to link the generated code, just to keep things simple for this step.
481 <BR>
482 <BR>
483 The next step is to try it with the linker. Type in <I><B>&#34;sdcc
484 test.c&#34;</B></I>. If all goes well the compiler will link with the
485 libraries and produce a test.ihx output file. If this step fails (no
486 test.ihx, and the linker generates warnings), then the problem is
487 most likely that sdcc cannot find the /usr/local/share/sdcc/lib directory
488 (see the Install trouble-shooting section for suggestions).
489 <BR>
490 <BR>
491 The final test is to ensure sdcc can use the standard header files
492 and libraries. Edit test.c and change it to the following:
493 <BR>
494 <BR>#include &lt;string.h&gt;
495 <BR>
496 main() {
497 <BR><TT>char str1[10];</TT>&nbsp;
498 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;strcpy(str1, &#34;testing&#34;);</TT>&nbsp;
499 <BR><TT>}</TT>&nbsp;
500 <BR>&nbsp;
501 <BR>
502 Compile this by typing <I><B>&#34;sdcc test.c&#34;</B></I>.
503 This should generate a test.ihx output file, and it should give no
504 warnings such as not finding the string.h file. If it cannot find
505 the string.h file, then the problem is that sdcc cannot find the /usr/local/share/sdcc/include
506 directory (see the Install trouble-shooting section for suggestions).
507
508 <P>
509
510 <H2><A NAME="SECTION00034000000000000000">
511 2.4 Install Trouble-shooting</A>
512 </H2>
513
514 <P>
515
516 <H3><A NAME="SECTION00034100000000000000">
517 2.4.1 SDCC cannot find libraries or header files.</A>
518 </H3>
519
520 <P>
521 The default installation assumes the libraries and header files are
522 located at ``/usr/local/share/sdcc/lib'' and ``/usr/local/share/sdcc/include''.
523 An alternative is to specify these locations as compiler options like
524 this: <I><B>&#34;sdcc&nbsp;-L&nbsp;/usr/local/sdcc/lib/small&nbsp;-I&nbsp;/usr/local/sdcc/include&nbsp;test.c&#34;</B></I>.
525
526 <P>
527
528 <H3><A NAME="SECTION00034200000000000000">
529 2.4.2 SDCC does not compile correctly.</A>
530 </H3>
531
532 <P>
533 A thing to try is starting from scratch by unpacking the .tgz source
534 package again in an empty directory. Confure it again and build like:
535 <BR>
536 <BR><I><B>make 2SPMamp;&gt;1 | tee make.log</B></I>
537 <BR>
538 <BR>
539 After this you can review the make.log file to locate the problem.
540 Or a relevant part of this be attached to an email that could be helpful
541 when requesting help from the mailing list.
542
543 <P>
544
545 <H3><A NAME="SECTION00034300000000000000">
546 2.4.3 What the ''./configure'' does</A>
547 </H3>
548
549 <P>
550 The ''./configure'' command is a script that analyzes your system
551 and performs some configuration to ensure the source package compiles
552 on your system. It will take a few minutes to run, and will compile
553 a few tests to determine what compiler features are installed.
554
555 <P>
556
557 <H3><A NAME="SECTION00034400000000000000">
558 2.4.4 What the ''make'' does.</A>
559 </H3>
560
561 <P>
562 This runs the GNU make tool, which automatically compiles all the
563 source packages into the final installed binary executables.
564
565 <P>
566
567 <H3><A NAME="SECTION00034500000000000000">
568 2.4.5 What the ''make install'' command does.</A>
569 </H3>
570
571 <P>
572 This will install the compiler, other executables and libraries in
573 to the appropriate system directories. The default is to copy the
574 executables to /usr/local/bin and the libraries and header files to
575 /usr/local/share/sdcc/lib and /usr/local/share/sdcc/include.
576
577 <P>
578
579 <H2><A NAME="SECTION00035000000000000000">
580 2.5 Additional Information for Windows Users</A>
581 </H2>
582
583 <P>
584 <I>&lt;pending: is this up to date?&gt;</I>
585 <BR>
586 <BR>
587 The standard method of installing on a Unix system involves compiling
588 the source package. This is easily done under Unix, but under Windows
589 it can be a more difficult process. The Cygwin is a large package
590 to download, and the compilation runs considerably slower under Windows
591 due to the overhead of the Cygwin tool set. An alternative is to install
592 a pre-compiled Windows binary package. There are various trade-offs
593 between each of these methods. 
594
595 <P>
596 The Cygwin package allows a Windows user to run a Unix command line
597 interface (bash shell) and also implements a Unix like file system
598 on top of Windows. Included are many of the famous GNU software development
599 tools which can augment the SDCC compiler.This is great if you have
600 some experience with Unix command line tools and file system conventions,
601 if not you may find it easier to start by installing a binary Windows
602 package. The binary packages work with the Windows file system conventions.
603
604 <P>
605
606 <H3><A NAME="SECTION00035100000000000000">
607 2.5.1 Getting started with Cygwin</A>
608 </H3>
609
610 <P>
611 SDCC is typically distributed as a tarred/gzipped file (.tgz). This
612 is a packed file similar to a .zip file. Cygwin includes the tools
613 you will need to unpack the SDCC distribution (tar and gzip). To unpack
614 it, simply follow the instructions under the Linux/Unix install section.
615 Before you do this you need to learn how to start a cygwin shell and
616 some of the basic commands used to move files, change directory, run
617 commands and so on. The change directory command is <I><B>``cd''</B></I>,
618 the move command is <I><B>``mv''</B></I>. To print the current
619 working directory, type <I><B>``pwd''</B></I>. To make a directory,
620 use <I><B>``mkdir''</B></I>.
621
622 <P>
623 There are some basic differences between Unix and Windows file systems
624 you should understand. When you type in directory paths, Unix and
625 the Cygwin bash prompt uses forward slashes '/' between directories
626 while Windows traditionally uses '&#92;' backward slashes.
627 So when you work at the Cygwin bash prompt, you will need to use the
628 forward '/' slashes. Unix does not have a concept of drive letters,
629 such as ``c:``, instead all files systems attach and appear
630 as directories.
631
632 <P>
633
634 <H3><A NAME="SECTION00035200000000000000">
635 2.5.2 Running SDCC as Native Compiled Executables</A>
636 </H3>
637
638 <P>
639 If you use the pre-compiled binaries, the install directories for
640 the libraries and header files may need to be specified on the sdcc
641 command line like this: <I><B>&#34;sdcc -L c:&#92;usr&#92;local&#92;sdcc&#92;lib&#92;small
642 -I c:&#92;usr&#92;local&#92;sdcc&#92;include
643 test.c&#34;</B></I> if you are running outside of a Unix bash shell.
644
645 <P>
646 If you have successfully installed and compiled SDCC with the Cygwin
647 package, it is possible to compile into native .exe files by using
648 the additional makefiles included for this purpose. For example, with
649 the Borland 32-bit compiler you would run <I><B>&#34;make
650 -f Makefile.bcc&#34;</B></I>. A command line version of the Borland
651 32-bit compiler can be downloaded from the Inprise web site.
652
653 <P>
654
655 <H2><A NAME="SECTION00036000000000000000">
656 2.6 SDCC on Other Platforms</A>
657 </H2>
658
659 <P>
660
661 <UL>
662 <LI><B>FreeBSD and other non-GNU Unixes</B> - Make sure the GNU make
663 is installed as the default make tool.
664 </LI>
665 <LI>SDCC has been ported to run under a variety of operating systems and
666 processors. If you can run GNU GCC/make then chances are good SDCC
667 can be compiled and run on your system.
668 </LI>
669 </UL>
670
671 <P>
672
673 <H2><A NAME="SECTION00037000000000000000">
674 2.7 Advanced Install Options</A>
675 </H2>
676
677 <P>
678 The ``configure'' command has several options. The most commonly
679 used option is -prefix=&lt;directory name&gt;, where &lt;directory name&gt; is
680 the final location for the sdcc executables and libraries, (default
681 location is /usr/local). The installation process will create the
682 following directory structure under the &lt;directory name&gt; specified
683 (if they do not already exist). 
684 <BR>
685 <BR>
686 bin/ - binary exectables (add to PATH environment variable)
687 <BR>
688 bin/share/
689 <BR>
690 bin/share/sdcc/include/ - include header files
691 <BR>
692 bin/share/sdcc/lib/
693 <BR>
694 bin/share/sdcc/lib/small/ - Object &amp; library files for small model
695 library
696 <BR>
697 bin/share/sdcc/lib/large/ - Object &amp; library files for large model
698 library
699 <BR>
700 bin/share/sdcc/lib/ds390/ - Object &amp; library files forDS80C390 library
701 <BR>
702 <BR>
703 The command <I><B>''./configure -prefix=/usr/local''</B></I>
704 will configure the compiler to be installed in directory /usr/local/bin.
705
706 <P>
707
708 <H2><A NAME="SECTION00038000000000000000">
709 2.8 Components of SDCC</A>
710 </H2>
711
712 <P>
713 SDCC is not just a compiler, but a collection of tools by various
714 developers. These include linkers, assemblers, simulators and other
715 components. Here is a summary of some of the components. Note that
716 the included simulator and assembler have separate documentation which
717 you can find in the source package in their respective directories.
718 As SDCC grows to include support for other processors, other packages
719 from various developers are included and may have their own sets of
720 documentation.
721
722 <P>
723 You might want to look at the various executables which are installed
724 in the bin directory. At the time of this writing, we find the following
725 programs:
726 <BR>
727 <BR><I>&lt;pending: tabularize this&gt;</I>
728 <BR>
729 <BR><B>sdcc</B> - The compiler.
730 <BR><B>sdcpp</B> - The C preprocessor.
731 <BR><B>asx8051</B> - The assembler for 8051 type processors.
732 <BR><B>as-z80, as-gbz80</B> - The Z80 and GameBoy Z80 assemblers.
733 <BR><B>aslink</B> -The linker for 8051 type processors.
734 <BR><B>link-z80, link-gbz80</B> - The Z80 and GameBoy Z80 linkers.
735 <BR><B>s51</B> - The ucSim 8051 simulator.
736 <BR><B>sdcdb</B> - The source debugger.
737 <BR><B>packihx</B> - A tool to pack Intel hex files.
738 <BR>
739 <BR>
740 As development for other processors proceeds, this list will expand
741 to include executables to support processors like AVR, PIC, etc.
742
743 <P>
744
745 <H3><A NAME="SECTION00038100000000000000">
746 2.8.1 sdcc - The Compiler</A>
747 </H3>
748
749 <P>
750 This is the actual compiler, it in turn uses the c-preprocessor and
751 invokes the assembler and linkage editor.
752
753 <P>
754
755 <H3><A NAME="SECTION00038200000000000000">
756 2.8.2 sdcpp (C-Preprocessor)</A>
757 </H3>
758
759 <P>
760 The preprocessor is a modified version of the GNU preprocessor. The
761 C preprocessor is used to pull in #include sources, process #ifdef
762 statements, #defines and so on.
763
764 <P>
765
766 <H3><A NAME="SECTION00038300000000000000">
767 2.8.3 asx8051, as-z80, as-gbz80, aslink, link-z80, link-gbz80 (The Assemblers
768 and Linkage Editors)</A>
769 </H3>
770
771 <P>
772 This is retargettable assembler &amp; linkage editor, it was developed
773 by Alan Baldwin. John Hartman created the version for 8051, and I
774 (Sandeep) have made some enhancements and bug fixes for it to work
775 properly with the SDCC.
776
777 <P>
778
779 <H3><A NAME="SECTION00038400000000000000">
780 2.8.4 s51 - Simulator</A>
781 </H3>
782
783 <P>
784 S51 is a freeware, opensource simulator developed by Daniel Drotos
785 (mailto:drdani@mazsola.iit.uni-miskolc.hu). The simulator is
786 built as part of the build process. For more information visit Daniel's
787 website at: http://mazsola.iit.uni-miskolc.hu/&nbsp;drdani/embedded/s51
788 .
789
790 <P>
791
792 <H3><A NAME="SECTION00038500000000000000">
793 2.8.5 sdcdb - Source Level Debugger</A>
794 </H3>
795
796 <P>
797 Sdcdb is the companion source level debugger. The current version
798 of the debugger uses Daniel's Simulator S51, but can be easily changed
799 to use other simulators.
800
801 <P>
802
803 <H1><A NAME="SECTION00040000000000000000">
804 3 Using SDCC</A>
805 </H1>
806
807 <P>
808
809 <H2><A NAME="SECTION00041000000000000000">
810 3.1 Compiling</A>
811 </H2>
812
813 <P>
814
815 <H3><A NAME="SECTION00041100000000000000">
816 3.1.1 Single Source File Projects</A>
817 </H3>
818
819 <P>
820 For single source file 8051 projects the process is very simple. Compile
821 your programs with the following command <I><B>&#34;sdcc
822 sourcefile.c&#34;.</B></I> This will compile, assemble and link your
823 source file. Output files are as follows
824 <BR>
825 <BR>
826 sourcefile.asm - Assembler source file created by the compiler
827 <BR>
828 sourcefile.lst - Assembler listing file created by the Assembler
829 <BR>
830 sourcefile.rst - Assembler listing file updated with linkedit information,
831 created by linkage editor
832 <BR>
833 sourcefile.sym - symbol listing for the sourcefile, created by the
834 assembler
835 <BR>
836 sourcefile.rel - Object file created by the assembler, input to Linkage
837 editor
838 <BR>
839 sourcefile.map - The memory map for the load module, created by the
840 Linker
841 <BR>
842 sourcefile.ihx - The load module in Intel hex format (you can select
843 the Motorola S19 format with -out-fmt-s19)
844 <BR>
845 sourcefile.cdb - An optional file (with -debug) containing debug
846 information
847 <BR>
848 <P>
849
850 <H3><A NAME="SECTION00041200000000000000">
851 3.1.2 Projects with Multiple Source Files</A>
852 </H3>
853
854 <P>
855 SDCC can compile only ONE file at a time. Let us for example assume
856 that you have a project containing the following files:
857 <BR>
858 <BR>
859 foo1.c (contains some functions)
860 <BR>
861 foo2.c (contains some more functions)
862 <BR>
863 foomain.c (contains more functions and the function main)
864 <BR>
865 <BR>
866 The first two files will need to be compiled separately with the commands:
867
868 <BR>
869 <BR><I><B>sdcc&nbsp;-c&nbsp;foo1.c</B></I>
870 <BR><I><B>sdcc&nbsp;-c&nbsp;foo2.c</B></I>
871 <BR>
872 <BR>
873 Then compile the source file containing the <I>main()</I> function
874 and link the files together with the following command: 
875 <BR>
876 <BR><I><B>sdcc&nbsp;foomain.c&nbsp;foo1.rel&nbsp;foo2.rel</B></I>
877 <BR>
878 <BR>
879 Alternatively, <I>foomain.c</I> can be separately compiled as well:
880 <BR>
881 <BR><I><B>sdcc&nbsp;-c&nbsp;foomain.c</B></I>
882 <BR><I><B>sdcc foomain.rel foo1.rel foo2.rel</B></I>
883 <BR>
884 <BR>
885 The file containing the <I>main()</I> function <SMALL>MUST</SMALL>
886 be the <SMALL>FIRST</SMALL> file specified in the command line, since the
887 linkage editor processes file in the order they are presented to it.
888
889 <P>
890
891 <H3><A NAME="SECTION00041300000000000000">
892 3.1.3 Projects with Additional Libraries</A>
893 </H3>
894
895 <P>
896 Some reusable routines may be compiled into a library, see the documentation
897 for the assembler and linkage editor (which are in &lt;installdir&gt;/share/sdcc/doc)
898 for how to create a <I>.lib</I> library file. Libraries created in
899 this manner can be included in the command line. Make sure you include
900 the -L &lt;library-path&gt; option to tell the linker where to look for
901 these files if they are not in the current directory. Here is an example,
902 assuming you have the source file <I>foomain.c</I> and a library <I>foolib.lib</I>
903 in the directory <I>mylib</I> (if that is not the same as your current
904 project):
905 <BR>
906 <BR><I><B>sdcc foomain.c foolib.lib -L mylib</B></I>
907 <BR>
908 <BR>
909 Note here that <I>mylib</I> must be an absolute path name.
910 <BR>
911 <BR>
912 The most efficient way to use libraries is to keep seperate modules
913 in seperate source files. The lib file now should name all the modules.rel
914 files. For an example see the standard library file <I>libsdcc.lib</I>
915 in the directory &lt;installdir&gt;/share/lib/small.
916
917 <P>
918
919 <H2><A NAME="SECTION00042000000000000000">
920 3.2 Command Line Options</A>
921 </H2>
922
923 <P>
924
925 <H3><A NAME="SECTION00042100000000000000">
926 3.2.1 Processor Selection Options</A>
927 </H3>
928
929 <P>
930
931 <UL>
932 <LI>[<B>-mmcs51</B>]Generate code for the MCS51 (8051) family of processors.
933 This is the default processor target.
934 </LI>
935 <LI>[<B>-mds390</B>]Generate code for the DS80C390 processor.
936 </LI>
937 <LI>[<B>-mz80</B>]Generate code for the Z80 family of processors.
938 </LI>
939 <LI>[<B>-mgbz80</B>]Generate code for the GameBoy Z80 processor.
940 </LI>
941 <LI>[<B>-mavr</B>]Generate code for the Atmel AVR processor(In development,
942 not complete).
943 </LI>
944 <LI>[<B>-mpic14</B>]Generate code for the PIC 14-bit processors(In development,
945 not complete).
946 </LI>
947 <LI>[<B>-mtlcs900h</B>]Generate code for the Toshiba TLCS-900H processor(In
948 development, not complete).
949 </LI>
950 </UL>
951 <P>
952
953 <H3><A NAME="SECTION00042200000000000000">
954 3.2.2 Preprocessor Options</A>
955 </H3>
956
957 <P>
958
959 <UL>
960 <LI>[<B>-I&lt;path&gt;</B>]The additional location where the pre processor
961 will look for &lt;..h&gt; or ``..h'' files.
962 </LI>
963 <LI>[<B>-D&lt;macro[=value]&gt;</B>]Command line definition of macros.
964 Passed to the pre processor.
965 </LI>
966 <LI>[<B>-M</B>]Tell the preprocessor to output a rule suitable for make
967 describing the dependencies of each object file. For each source file,
968 the preprocessor outputs one make-rule whose target is the object
969 file name for that source file and whose dependencies are all the
970 files `#include'd in it. This rule may be a single line or may be
971 continued with `&#92;'-newline if it is long. The list
972 of rules is printed on standard output instead of the preprocessed
973 C program. `-M' implies `-E'.
974 </LI>
975 <LI>[<B>-C</B>]Tell the preprocessor not to discard comments. Used with
976 the `-E' option.
977 </LI>
978 <LI>[<B>-MM</B>]Like `-M' but the output mentions only the user header
979 files included with `#include ``file&#34;'. System header
980 files included with `#include &lt;file&gt;' are omitted.
981 </LI>
982 <LI>[<B>-Aquestion(answer)</B>]Assert the answer answer for question,
983 in case it is tested with a preprocessor conditional such as `#if
984 #question(answer)'. `-A-' disables the standard assertions that normally
985 describe the target machine.
986 </LI>
987 <LI>[<B>-Aquestion</B>](answer) Assert the answer answer for question,
988 in case it is tested with a preprocessor conditional such as `#if
989 #question(answer)'. `-A-' disables the standard assertions that normally
990 describe the target machine.
991 </LI>
992 <LI>[<B>-Umacro</B>]Undefine macro macro. `-U' options are evaluated
993 after all `-D' options, but before any `-include' and `-imacros' options.
994 </LI>
995 <LI>[<B>-dM</B>]Tell the preprocessor to output only a list of the macro
996 definitions that are in effect at the end of preprocessing. Used with
997 the `-E' option.
998 </LI>
999 <LI>[<B>-dD</B>]Tell the preprocessor to pass all macro definitions
1000 into the output, in their proper sequence in the rest of the output.
1001 </LI>
1002 <LI>[<B>-dN</B>]Like `-dD' except that the macro arguments and contents
1003 are omitted. Only `#define name' is included in the output.
1004 </LI>
1005 </UL>
1006 <P>
1007
1008 <H3><A NAME="SECTION00042300000000000000">
1009 3.2.3 Linker Options</A>
1010 </H3>
1011
1012 <P>
1013
1014 <UL>
1015 <LI>[<B>-L&nbsp;-lib-path</B>]&lt;absolute path to additional libraries&gt; This
1016 option is passed to the linkage editor's additional libraries search
1017 path. The path name must be absolute. Additional library files may
1018 be specified in the command line. See section Compiling programs for
1019 more details.
1020 </LI>
1021 <LI>[<B>-xram-loc</B>&lt;Value&gt;]The start location of the external ram,
1022 default value is 0. The value entered can be in Hexadecimal or Decimal
1023 format, e.g.: -xram-loc 0x8000 or -xram-loc 32768.
1024 </LI>
1025 <LI>[<B>-code-loc</B>&lt;Value&gt;]The start location of the code segment,
1026 default value 0. Note when this option is used the interrupt vector
1027 table is also relocated to the given address. The value entered can
1028 be in Hexadecimal or Decimal format, e.g.: -code-loc 0x8000 or -code-loc
1029 32768.
1030 </LI>
1031 <LI>[<B>-stack-loc</B>&lt;Value&gt;]The initial value of the stack pointer.
1032 The default value of the stack pointer is 0x07 if only register bank
1033 0 is used, if other register banks are used then the stack pointer
1034 is initialized to the location above the highest register bank used.
1035 eg. if register banks 1 &amp; 2 are used the stack pointer will default
1036 to location 0x18. The value entered can be in Hexadecimal or Decimal
1037 format, eg. -stack-loc 0x20 or -stack-loc 32. If all four register
1038 banks are used the stack will be placed after the data segment (equivalent
1039 to -stack-after-data)
1040 </LI>
1041 <LI>[<B>-stack-after-data</B>]This option will cause the stack to be
1042 located in the internal ram after the data segment.
1043 </LI>
1044 <LI>[<B>-data-loc</B>&lt;Value&gt;]The start location of the internal ram
1045 data segment, the default value is 0x30.The value entered can be in
1046 Hexadecimal or Decimal format, eg. -data-loc 0x20 or -data-loc 32.
1047 </LI>
1048 <LI>[<B>-idata-loc</B>&lt;Value&gt;]The start location of the indirectly
1049 addressable internal ram, default value is 0x80. The value entered
1050 can be in Hexadecimal or Decimal format, eg. -idata-loc 0x88 or -idata-loc
1051 136.
1052 </LI>
1053 <LI>[<B>-out-fmt-ihx</B>]The linker output (final object code) is in
1054 Intel Hex format. (This is the default option).
1055 </LI>
1056 <LI>[<B>-out-fmt-s19</B>]The linker output (final object code) is in
1057 Motorola S19 format.
1058 </LI>
1059 </UL>
1060 <P>
1061
1062 <H3><A NAME="SECTION00042400000000000000">
1063 3.2.4 MCS51 Options</A>
1064 </H3>
1065
1066 <P>
1067
1068 <UL>
1069 <LI>[<B>-model-large</B>]Generate code for Large model programs see
1070 section Memory Models for more details. If this option is used all
1071 source files in the project should be compiled with this option. In
1072 addition the standard library routines are compiled with small model,
1073 they will need to be recompiled.
1074 </LI>
1075 <LI>[<B>-model-small</B>]Generate code for Small Model programs see
1076 section Memory Models for more details. This is the default model.
1077 </LI>
1078 </UL>
1079 <P>
1080
1081 <H3><A NAME="SECTION00042500000000000000">
1082 3.2.5 DS390 Options</A>
1083 </H3>
1084
1085 <P>
1086
1087 <UL>
1088 <LI>[<B>-model-flat24</B>]Generate 24-bit flat mode code. This is the
1089 one and only that the ds390 code generator supports right now and
1090 is default when using <I>-mds390</I>. See section Memory Models for
1091 more details.
1092 </LI>
1093 <LI>[<B>-stack-10bit</B>]Generate code for the 10 bit stack mode of
1094 the Dallas DS80C390 part. This is the one and only that the ds390
1095 code generator supports right now and is default when using <I>-mds390</I>.
1096 In this mode, the stack is located in the lower 1K of the internal
1097 RAM, which is mapped to 0x400000. Note that the support is incomplete,
1098 since it still uses a single byte as the stack pointer. This means
1099 that only the lower 256 bytes of the potential 1K stack space will
1100 actually be used. However, this does allow you to reclaim the precious
1101 256 bytes of low RAM for use for the DATA and IDATA segments. The
1102 compiler will not generate any code to put the processor into 10 bit
1103 stack mode. It is important to ensure that the processor is in this
1104 mode before calling any re-entrant functions compiled with this option.
1105 In principle, this should work with the <I>-stack-auto</I> option,
1106 but that has not been tested. It is incompatible with the <I>-xstack</I>
1107 option. It also only makes sense if the processor is in 24 bit contiguous
1108 addressing mode (see the <I>-model-flat24 option</I>).
1109 </LI>
1110 </UL>
1111 <P>
1112
1113 <H3><A NAME="SECTION00042600000000000000">
1114 3.2.6 Optimization Options</A>
1115 </H3>
1116
1117 <P>
1118
1119 <UL>
1120 <LI>[<B>-nogcse</B>]Will not do global subexpression elimination, this
1121 option may be used when the compiler creates undesirably large stack/data
1122 spaces to store compiler temporaries. A warning message will be generated
1123 when this happens and the compiler will indicate the number of extra
1124 bytes it allocated. It recommended that this option NOT be used, #pragma&nbsp;NOGCSE
1125 can be used to turn off global subexpression elimination for a given
1126 function only.
1127 </LI>
1128 <LI>[<B>-noinvariant</B>]Will not do loop invariant optimizations,
1129 this may be turned off for reasons explained for the previous option.
1130 For more details of loop optimizations performed see section Loop
1131 Invariants.It recommended that this option NOT be used, #pragma&nbsp;NOINVARIANT
1132 can be used to turn off invariant optimizations for a given function
1133 only.
1134 </LI>
1135 <LI>[<B>-noinduction</B>]Will not do loop induction optimizations,
1136 see section strength reduction for more details.It is recommended
1137 that this option is NOT used, #pragma&nbsp;NOINDUCTION can be used to
1138 turn off induction optimizations for a given function only.
1139 </LI>
1140 <LI>[<B>-nojtbound</B>] Will not generate boundary condition check
1141 when switch statements are implemented using jump-tables. See section
1142 Switch Statements for more details. It is recommended that this option
1143 is NOT used, #pragma&nbsp;NOJTBOUND can be used to turn off boundary
1144 checking for jump tables for a given function only.
1145 </LI>
1146 <LI>[<B>-noloopreverse</B>]Will not do loop reversal optimization.
1147 </LI>
1148 </UL>
1149 <P>
1150
1151 <H3><A NAME="SECTION00042700000000000000">
1152 3.2.7 Other Options</A>
1153 </H3>
1154
1155 <P>
1156
1157 <UL>
1158 <LI>[<B>-c&nbsp;-compile-only</B>]will compile and assemble the source,
1159 but will not call the linkage editor.
1160 </LI>
1161 <LI>[<B>-E</B>]Run only the C preprocessor. Preprocess all the C source
1162 files specified and output the results to standard output.
1163 </LI>
1164 <LI>[<B>-stack-auto</B>]All functions in the source file will be compiled
1165 as <I>reentrant</I>, i.e. the parameters and local variables will
1166 be allocated on the stack. see section Parameters and Local Variables
1167 for more details. If this option is used all source files in the project
1168 should be compiled with this option. 
1169 </LI>
1170 <LI>[<B>-xstack</B>]Uses a pseudo stack in the first 256 bytes in the
1171 external ram for allocating variables and passing parameters. See
1172 section on external stack for more details.
1173 </LI>
1174 <LI>[<B>-callee-saves</B>]<B>function1[,function2][,function3]....</B>
1175 The compiler by default uses a caller saves convention for register
1176 saving across function calls, however this can cause unneccessary
1177 register pushing &amp; popping when calling small functions from larger
1178 functions. This option can be used to switch the register saving convention
1179 for the function names specified. The compiler will not save registers
1180 when calling these functions, no extra code will be generated at the
1181 entry &amp; exit for these functions to save &amp; restore the registers
1182 used by these functions, this can SUBSTANTIALLY reduce code &amp; improve
1183 run time performance of the generated code. In the future the compiler
1184 (with interprocedural analysis) will be able to determine the appropriate
1185 scheme to use for each function call. DO NOT use this option for built-in
1186 functions such as _muluint..., if this option is used for a library
1187 function the appropriate library function needs to be recompiled with
1188 the same option. If the project consists of multiple source files
1189 then all the source file should be compiled with the same -callee-saves
1190 option string. Also see #pragma&nbsp;CALLEE-SAVES.
1191 </LI>
1192 <LI>[<B>-debug</B>]When this option is used the compiler will generate
1193 debug information, that can be used with the SDCDB. The debug information
1194 is collected in a file with .cdb extension. For more information see
1195 documentation for SDCDB.
1196 </LI>
1197 <LI>[<B><I>-regextend</I></B>] <I>This option is obsolete and isn't
1198 supported anymore.</I>
1199 </LI>
1200 <LI>[<B><I>-noregparms</I></B>]<I>This option is obsolete and isn't
1201 supported anymore.</I>
1202 </LI>
1203 <LI>[<B>-peep-file</B>&lt;filename&gt;]This option can be used to use additional
1204 rules to be used by the peep hole optimizer. See section Peep Hole
1205 optimizations for details on how to write these rules.
1206 </LI>
1207 <LI>[<B>-S</B>]Stop after the stage of compilation proper; do not assemble.
1208 The output is an assembler code file for the input file specified.
1209 </LI>
1210 <LI>[<B>-Wa_asmOption[,asmOption]</B>...]Pass the asmOption to
1211 the assembler.
1212 </LI>
1213 <LI>[<B>-Wl_linkOption[,linkOption]</B>...]Pass the linkOption
1214 to the linker.
1215 </LI>
1216 <LI>[<B>-int-long-reent</B>] Integer (16 bit) and long (32 bit) libraries
1217 have been compiled as reentrant. Note by default these libraries are
1218 compiled as non-reentrant. See section Installation for more details.
1219 </LI>
1220 <LI>[<B>-cyclomatic</B>]This option will cause the compiler to generate
1221 an information message for each function in the source file. The message
1222 contains some <I>important</I> information about the function. The
1223 number of edges and nodes the compiler detected in the control flow
1224 graph of the function, and most importantly the <I>cyclomatic complexity</I>
1225 see section on Cyclomatic Complexity for more details.
1226 </LI>
1227 <LI>[<B>-float-reent</B>] Floating point library is compiled as reentrant.See
1228 section Installation for more details.
1229 </LI>
1230 <LI>[<B>-nooverlay</B>] The compiler will not overlay parameters and
1231 local variables of any function, see section Parameters and local
1232 variables for more details.
1233 </LI>
1234 <LI>[<B>-main-return</B>]This option can be used when the code generated
1235 is called by a monitor program. The compiler will generate a 'ret'
1236 upon return from the 'main' function. The default option is to lock
1237 up i.e. generate a 'ljmp '.
1238 </LI>
1239 <LI>[<B>-no-peep</B>] Disable peep-hole optimization.
1240 </LI>
1241 <LI>[<B>-peep-asm</B>] Pass the inline assembler code through the peep
1242 hole optimizer. This can cause unexpected changes to inline assembler
1243 code, please go through the peephole optimizer rules defined in the
1244 source file tree '&lt;target&gt;/peeph.def' before using this option.
1245 </LI>
1246 <LI>[<B>-iram-size</B>&lt;Value&gt;]Causes the linker to check if the interal
1247 ram usage is within limits of the given value.
1248 </LI>
1249 <LI>[<B>-nostdincl</B>]This will prevent the compiler from passing
1250 on the default include path to the preprocessor.
1251 </LI>
1252 <LI>[<B>-nostdlib</B>]This will prevent the compiler from passing on
1253 the default library path to the linker.
1254 </LI>
1255 <LI>[<B>-verbose</B>]Shows the various actions the compiler is performing.
1256 </LI>
1257 <LI>[<B>-V</B>]Shows the actual commands the compiler is executing.
1258 </LI>
1259 </UL>
1260 <P>
1261
1262 <H3><A NAME="SECTION00042800000000000000">
1263 3.2.8 Intermediate Dump Options</A>
1264 </H3>
1265
1266 <P>
1267 The following options are provided for the purpose of retargetting
1268 and debugging the compiler. These provided a means to dump the intermediate
1269 code (iCode) generated by the compiler in human readable form at various
1270 stages of the compilation process. 
1271
1272 <P>
1273
1274 <UL>
1275 <LI>[<B>-dumpraw</B>]This option will cause the compiler to dump the
1276 intermediate code into a file of named <I>&lt;source filename&gt;.dumpraw</I>
1277 just after the intermediate code has been generated for a function,
1278 i.e. before any optimizations are done. The basic blocks at this stage
1279 ordered in the depth first number, so they may not be in sequence
1280 of execution.
1281 </LI>
1282 <LI>[<B>-dumpgcse</B>]Will create a dump of iCode's, after global subexpression
1283 elimination, into a file named <I>&lt;source filename&gt;.dumpgcse.</I>
1284 </LI>
1285 <LI>[<B>-dumpdeadcode</B>]Will create a dump of iCode's, after deadcode
1286 elimination, into a file named <I>&lt;source filename&gt;.dumpdeadcode.</I>
1287 </LI>
1288 <LI>[<B>-dumploop</B>]Will create a dump of iCode's, after loop optimizations,
1289 into a file named <I>&lt;source filename&gt;.dumploop.</I>
1290 </LI>
1291 <LI>[<B>-dumprange</B>]Will create a dump of iCode's, after live range
1292 analysis, into a file named <I>&lt;source filename&gt;.dumprange.</I>
1293 </LI>
1294 <LI>[<B>-dumlrange</B>]Will dump the life ranges for all symbols.
1295 </LI>
1296 <LI>[<B>-dumpregassign</B>]Will create a dump of iCode's, after register
1297 assignment, into a file named <I>&lt;source filename&gt;.dumprassgn.</I>
1298 </LI>
1299 <LI>[<B>-dumplrange</B>]Will create a dump of the live ranges of iTemp's
1300 </LI>
1301 <LI>[<B>-dumpall</B>]Will cause all the above mentioned dumps to be
1302 created.
1303 </LI>
1304 </UL>
1305 <P>
1306
1307 <H2><A NAME="SECTION00043000000000000000">
1308 3.3 MCS51/DS390 Storage Class Language Extensions</A>
1309 </H2>
1310
1311 <P>
1312 In addition to the ANSI storage classes SDCC allows the following
1313 MCS51 specific storage classes.
1314
1315 <P>
1316
1317 <H3><A NAME="SECTION00043100000000000000">
1318 3.3.1 xdata</A>
1319 </H3>
1320
1321 <P>
1322 Variables declared with this storage class will be placed in the extern
1323 RAM. This is the <B>default</B> storage class for Large Memory model,
1324 e.g.:
1325 <BR>
1326 <BR><TT>xdata unsigned char xduc;</TT>
1327
1328 <P>
1329
1330 <H3><A NAME="SECTION00043200000000000000">
1331 3.3.2 data</A>
1332 </H3>
1333
1334 <P>
1335 This is the <B>default</B> storage class for Small Memory model.
1336 Variables declared with this storage class will be allocated in the
1337 internal RAM, e.g.:
1338 <BR>
1339 <BR><TT>data int iramdata;</TT>
1340
1341 <P>
1342
1343 <H3><A NAME="SECTION00043300000000000000">
1344 3.3.3 idata</A>
1345 </H3>
1346
1347 <P>
1348 Variables declared with this storage class will be allocated into
1349 the indirectly addressable portion of the internal ram of a 8051,
1350 e.g.:
1351 <BR>
1352 <BR><TT>idata int idi;</TT>
1353
1354 <P>
1355
1356 <H3><A NAME="SECTION00043400000000000000">
1357 3.3.4 bit</A>
1358 </H3>
1359
1360 <P>
1361 This is a data-type and a storage class specifier. When a variable
1362 is declared as a bit, it is allocated into the bit addressable memory
1363 of 8051, e.g.:
1364 <BR>
1365 <BR><TT>bit iFlag;</TT>
1366
1367 <P>
1368
1369 <H3><A NAME="SECTION00043500000000000000">
1370 3.3.5 sfr / sbit</A>
1371 </H3>
1372
1373 <P>
1374 Like the bit keyword, <I>sfr / sbit</I> signifies both a data-type
1375 and storage class, they are used to describe the special function
1376 registers and special bit variables of a 8051, eg:
1377 <BR>
1378 <BR><TT>sfr at 0x80 P0; /* special function register P0 at location
1379 0x80 */</TT>&nbsp;
1380 <BR><TT>sbit at 0xd7 CY; /* CY (Carry Flag) */</TT>
1381
1382 <P>
1383
1384 <H2><A NAME="SECTION00044000000000000000">
1385 3.4 Pointers</A>
1386 </H2>
1387
1388 <P>
1389 SDCC allows (via language extensions) pointers to explicitly point
1390 to any of the memory spaces of the 8051. In addition to the explicit
1391 pointers, the compiler also allows a <I>_generic</I> class of pointers
1392 which can be used to point to any of the memory spaces.
1393 <BR>
1394 <BR>
1395 Pointer declaration examples:
1396 <BR>
1397 <BR><TT>/* pointer physically in xternal ram pointing to object
1398 in internal ram */ </TT>&nbsp;
1399 <BR><TT>data unsigned char * xdata p;</TT>&nbsp;
1400 <BR>&nbsp;
1401 <BR><TT>/* pointer physically in code rom pointing to data in xdata
1402 space */ </TT>&nbsp;
1403 <BR><TT>xdata unsigned char * code p;</TT>&nbsp;
1404 <BR>&nbsp;
1405 <BR><TT>/* pointer physically in code space pointing to data in
1406 code space */ </TT>&nbsp;
1407 <BR><TT>code unsigned char * code p;</TT>&nbsp;
1408 <BR>&nbsp;
1409 <BR><TT>/* the folowing is a generic pointer physically located
1410 in xdata space */</TT>&nbsp;
1411 <BR><TT>char * xdata p;</TT>
1412 <BR>
1413 <BR>
1414 Well you get the idea. 
1415 <BR>
1416 <BR><I>For compatibility with the previous version of the compiler,
1417 the following syntax for pointer declaration is still supported but
1418 will disappear int the near future. </I>
1419 <BR>
1420 <BR><TT><I>unsigned char _xdata *ucxdp; /* pointer to data
1421 in external ram */ </I></TT>&nbsp;
1422 <BR><TT><I>unsigned char _data &nbsp;*ucdp ; /* pointer to data
1423 in internal ram */ </I></TT>&nbsp;
1424 <BR><TT><I>unsigned char _code &nbsp;*uccp ; /* pointer to data
1425 in R/O code space */</I></TT>&nbsp;
1426 <BR><TT><I>unsigned char _idata *uccp; &nbsp;/* pointer to upper
1427 128 bytes of ram */</I></TT>
1428 <BR>
1429 <BR>
1430 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
1431 <I>generic</I> pointers. These type of pointers can also to be explicitly
1432 declared.
1433 <BR>
1434 <BR><TT>unsigned char _generic *ucgp;</TT>
1435 <BR>
1436 <BR>
1437 The highest order byte of the <I>generic</I> pointers contains the
1438 data space information. Assembler support routines are called whenever
1439 data is stored or retrieved using <I>generic</I> pointers. These are
1440 useful for developing reusable library routines. Explicitly specifying
1441 the pointer type will generate the most efficient code. Pointers declared
1442 using a mixture of OLD and NEW style could have unpredictable results.
1443
1444 <P>
1445
1446 <H2><A NAME="SECTION00045000000000000000">
1447 3.5 Parameters &amp; Local Variables</A>
1448 </H2>
1449
1450 <P>
1451 Automatic (local) variables and parameters to functions can either
1452 be placed on the stack or in data-space. The default action of the
1453 compiler is to place these variables in the internal RAM (for small
1454 model) or external RAM (for Large model). This in fact makes them
1455 <I>static</I> so by default functions are non-reentrant.
1456
1457 <P>
1458 They can be placed on the stack either by using the <I>-stack-auto</I>
1459 compiler option or by using the <I>reentrant</I> keyword in the function
1460 declaration, e.g.:
1461 <BR>
1462 <BR><TT>unsigned char foo(char i) reentrant </TT>&nbsp;
1463 <BR><TT>{ </TT>&nbsp;
1464 <BR><TT>... </TT>&nbsp;
1465 <BR><TT>}</TT>&nbsp;
1466 <BR>
1467 <BR>
1468 Since stack space on 8051 is limited, the <I>reentrant</I> keyword
1469 or the <I>-stack-auto</I> option should be used sparingly. Note that
1470 the reentrant keyword just means that the parameters &amp; local variables
1471 will be allocated to the stack, it <I>does not</I> mean that the function
1472 is register bank independent.
1473 <BR>
1474 <BR>
1475 Local variables can be assigned storage classes and absolute addresses,
1476 e.g.: 
1477 <BR>
1478 <BR><TT>unsigned char foo() {</TT>&nbsp;
1479 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;xdata unsigned char i;</TT>&nbsp;
1480 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;bit bvar;</TT>&nbsp;
1481 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;data at 0x31 unsiged char j;</TT>&nbsp;
1482 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;... </TT>&nbsp;
1483 <BR><TT>}</TT>&nbsp;
1484 <BR>&nbsp;
1485 <BR>
1486 In the above example the variable <I>i</I> will be allocated in the
1487 external ram, <I>bvar</I> in bit addressable space and <I>j</I> in
1488 internal ram. When compiled with <I>-stack-auto</I> or when a function
1489 is declared as <I>reentrant</I> this can only be done for static variables.
1490
1491 <P>
1492 Parameters however are not allowed any storage class, (storage classes
1493 for parameters will be ignored), their allocation is governed by the
1494 memory model in use, and the reentrancy options.
1495
1496 <P>
1497
1498 <H2><A NAME="SECTION00046000000000000000">
1499 3.6 Overlaying</A>
1500 </H2>
1501
1502 <P>
1503 For non-reentrant functions SDCC will try to reduce internal ram space
1504 usage by overlaying parameters and local variables of a function (if
1505 possible). Parameters and local variables of a function will be allocated
1506 to an overlayable segment if the function has <I>no other function
1507 calls and the function is non-reentrant and the memory model is small.</I>
1508 If an explicit storage class is specified for a local variable, it
1509 will NOT be overlayed.
1510
1511 <P>
1512 Note that the compiler (not the linkage editor) makes the decision
1513 for overlaying the data items. Functions that are called from an interrupt
1514 service routine should be preceded by a #pragma&nbsp;NOOVERLAY if they
1515 are not reentrant.
1516
1517 <P>
1518 Also note that the compiler does not do any processing of inline assembler
1519 code, so the compiler might incorrectly assign local variables and
1520 parameters of a function into the overlay segment if the inline assembler
1521 code calls other c-functions that might use the overlay. In that case
1522 the #pragma&nbsp;NOOVERLAY should be used.
1523
1524 <P>
1525 Parameters and Local variables of functions that contain 16 or 32
1526 bit multiplication or division will NOT be overlayed since these are
1527 implemented using external functions, e.g.:
1528 <BR>
1529 <BR><TT>#pragma SAVE </TT>&nbsp;
1530 <BR><TT>#pragma NOOVERLAY </TT>&nbsp;
1531 <BR><TT>void set_error(unsigned char errcd) </TT>&nbsp;
1532 <BR><TT>{</TT>&nbsp;
1533 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;P3 = errcd;</TT>&nbsp;
1534 <BR><TT>} </TT>&nbsp;
1535 <BR><TT>#pragma RESTORE </TT>&nbsp;
1536 <BR>&nbsp;
1537 <BR><TT>void some_isr () interrupt 2 using 1 </TT>&nbsp;
1538 <BR><TT>{</TT>&nbsp;
1539 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;...</TT>&nbsp;
1540 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;set_error(10);</TT>&nbsp;
1541 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;... </TT>&nbsp;
1542 <BR><TT>}</TT>&nbsp;
1543 <BR>&nbsp;
1544 <BR>
1545 In the above example the parameter <I>errcd</I> for the function <I>set_error</I>
1546 would be assigned to the overlayable segment if the #pragma&nbsp;NOOVERLAY
1547 was not present, this could cause unpredictable runtime behavior when
1548 called from an ISR. The #pragma&nbsp;NOOVERLAY ensures that the parameters
1549 and local variables for the function are NOT overlayed.
1550
1551 <P>
1552
1553 <H2><A NAME="SECTION00047000000000000000">
1554 3.7 Interrupt Service Routines</A>
1555 </H2>
1556
1557 <P>
1558 SDCC allows interrupt service routines to be coded in C, with some
1559 extended keywords.
1560 <BR>
1561 <BR><TT>void timer_isr (void) interrupt 2 using 1 </TT>&nbsp;
1562 <BR><TT>{ </TT>&nbsp;
1563 <BR><TT>.. </TT>&nbsp;
1564 <BR><TT>}</TT>&nbsp;
1565 <BR>&nbsp;
1566 <BR>
1567 The number following the <I>interrupt</I> keyword is the interrupt
1568 number this routine will service. The compiler will insert a call
1569 to this routine in the interrupt vector table for the interrupt number
1570 specified. The <I>using</I> keyword is used to tell the compiler to
1571 use the specified register bank (8051 specific) when generating code
1572 for this function. Note that when some function is called from an
1573 interrupt service routine it should be preceded by a #pragma&nbsp;NOOVERLAY
1574 if it is not reentrant. A special note here, int (16 bit) and long
1575 (32 bit) integer division, multiplication &amp; modulus operations are
1576 implemented using external support routines developed in ANSI-C, if
1577 an interrupt service routine needs to do any of these operations then
1578 the support routines (as mentioned in a following section) will have
1579 to be recompiled using the <I>-stack-auto</I> option and the source
1580 file will need to be compiled using the <I>-int-long-ren</I>t compiler
1581 option.
1582
1583 <P>
1584 If you have multiple source files in your project, interrupt service
1585 routines can be present in any of them, but a prototype of the isr
1586 MUST be present or included in the file that contains the function
1587 <I>main</I>.
1588
1589 <P>
1590 Interrupt Numbers and the corresponding address &amp; descriptions for
1591 the Standard 8051 are listed below. SDCC will automatically adjust
1592 the interrupt vector table to the maximum interrupt number specified.
1593 <BR>
1594 <P>
1595 <TABLE CELLPADDING=3 BORDER="1">
1596 <TR><TD ALIGN="CENTER">Interrupt #</TD>
1597 <TD ALIGN="CENTER">Description</TD>
1598 <TD ALIGN="CENTER">Vector Address</TD>
1599 </TR>
1600 <TR><TD ALIGN="CENTER">0</TD>
1601 <TD ALIGN="CENTER">External 0</TD>
1602 <TD ALIGN="CENTER">0x0003</TD>
1603 </TR>
1604 <TR><TD ALIGN="CENTER">1</TD>
1605 <TD ALIGN="CENTER">Timer 0</TD>
1606 <TD ALIGN="CENTER">0x000B</TD>
1607 </TR>
1608 <TR><TD ALIGN="CENTER">2</TD>
1609 <TD ALIGN="CENTER">External 1</TD>
1610 <TD ALIGN="CENTER">0x0013</TD>
1611 </TR>
1612 <TR><TD ALIGN="CENTER">3</TD>
1613 <TD ALIGN="CENTER">Timer 1</TD>
1614 <TD ALIGN="CENTER">0x001B</TD>
1615 </TR>
1616 <TR><TD ALIGN="CENTER">4</TD>
1617 <TD ALIGN="CENTER">Serial</TD>
1618 <TD ALIGN="CENTER">0x0023</TD>
1619 </TR>
1620 </TABLE>
1621 <BR>
1622 <BR>
1623 If the interrupt service routine is defined without <I>using</I> a
1624 register bank or with register bank 0 (using 0), the compiler will
1625 save the registers used by itself on the stack upon entry and restore
1626 them at exit, however if such an interrupt service routine calls another
1627 function then the entire register bank will be saved on the stack.
1628 This scheme may be advantageous for small interrupt service routines
1629 which have low register usage.
1630
1631 <P>
1632 If the interrupt service routine is defined to be using a specific
1633 register bank then only <I>a, b &amp; dptr</I> are save and restored,
1634 if such an interrupt service routine calls another function (using
1635 another register bank) then the entire register bank of the called
1636 function will be saved on the stack. This scheme is recommended for
1637 larger interrupt service routines.
1638
1639 <P>
1640 Calling other functions from an interrupt service routine is not recommended,
1641 avoid it if possible.
1642 <BR>
1643 <BR>
1644 Also see the _naked modifier.
1645
1646 <P>
1647
1648 <H2><A NAME="SECTION00048000000000000000">
1649 3.8 Critical Functions</A>
1650 </H2>
1651
1652 <P>
1653 A special keyword may be associated with a function declaring it as
1654 <I>critical</I>. SDCC will generate code to disable all interrupts
1655 upon entry to a critical function and enable them back before returning.
1656 Note that nesting critical functions may cause unpredictable results.
1657 <BR>
1658 <BR><TT>int foo () critical </TT>&nbsp;
1659 <BR><TT>{ </TT>&nbsp;
1660 <BR><TT>... </TT>&nbsp;
1661 <BR><TT>... </TT>&nbsp;
1662 <BR><TT>}</TT>&nbsp;
1663 <BR>
1664 <BR>
1665 The critical attribute maybe used with other attributes like <I>reentrant.</I>
1666
1667 <P>
1668
1669 <H2><A NAME="SECTION00049000000000000000">
1670 3.9 Naked Functions</A>
1671 </H2>
1672
1673 <P>
1674 A special keyword may be associated with a function declaring it as
1675 <I>_naked.</I> The <I>_naked</I> function modifier attribute prevents
1676 the compiler from generating prologue and epilogue code for that function.
1677 This means that the user is entirely responsible for such things as
1678 saving any registers that may need to be preserved, selecting the
1679 proper register bank, generating the <I>return</I> instruction at
1680 the end, etc. Practically, this means that the contents of the function
1681 must be written in inline assembler. This is particularly useful for
1682 interrupt functions, which can have a large (and often unnecessary)
1683 prologue/epilogue. For example, compare the code generated by these
1684 two functions:
1685 <BR>
1686 <BR><TT>data unsigned char counter;</TT>&nbsp;
1687 <BR><TT>void simpleInterrupt(void) interrupt 1</TT>&nbsp;
1688 <BR><TT>{</TT>&nbsp;
1689 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;counter++;</TT>&nbsp;
1690 <BR><TT>}</TT>&nbsp;
1691 <BR>&nbsp;
1692 <BR><TT>void nakedInterrupt(void) interrupt 2 _naked</TT>&nbsp;
1693 <BR><TT>{</TT>&nbsp;
1694 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;_asm</TT>&nbsp;
1695 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;inc&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_counter</TT>&nbsp;
1696 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reti&nbsp;&nbsp;&nbsp;&nbsp;; MUST explicitly include ret in _naked
1697 function.</TT>&nbsp;
1698 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;_endasm;</TT>&nbsp;
1699 <BR><TT>}</TT>
1700 <BR>
1701 <BR>
1702 For an 8051 target, the generated simpleInterrupt looks like:
1703 <BR>
1704 <BR><TT>_simpleIterrupt:</TT>&nbsp;
1705 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;push&nbsp;&nbsp;&nbsp;&nbsp;acc</TT>&nbsp;
1706 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;push&nbsp;&nbsp;&nbsp;&nbsp;b</TT>&nbsp;
1707 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;push&nbsp;&nbsp;&nbsp;&nbsp;dpl</TT>&nbsp;
1708 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;push&nbsp;&nbsp;&nbsp;&nbsp;dph</TT>&nbsp;
1709 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;push&nbsp;&nbsp;&nbsp;&nbsp;psw</TT>&nbsp;
1710 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;mov&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;psw,#0x00</TT>&nbsp;
1711 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;inc&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_counter</TT>&nbsp;
1712 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;pop&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;psw</TT>&nbsp;
1713 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;pop&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dph</TT>&nbsp;
1714 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;pop&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dpl</TT>&nbsp;
1715 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;pop&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b</TT>&nbsp;
1716 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;pop&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;acc</TT>&nbsp;
1717 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;reti</TT>
1718 <BR>
1719 <BR>
1720 whereas nakedInterrupt looks like:
1721 <BR>
1722 <BR><TT>_nakedInterrupt:</TT>&nbsp;
1723 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;inc&nbsp;&nbsp;&nbsp;&nbsp;_counter</TT>&nbsp;
1724 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;reti&nbsp;&nbsp;&nbsp;; MUST explicitly include ret(i) in _naked
1725 function.</TT>
1726 <BR>
1727 <BR>
1728 While there is nothing preventing you from writing C code inside a
1729 _naked function, there are many ways to shoot yourself in the foot
1730 doing this, and is is recommended that you stick to inline assembler.
1731
1732 <P>
1733
1734 <H2><A NAME="SECTION000410000000000000000">
1735 3.10 Functions using private banks</A>
1736 </H2>
1737
1738 <P>
1739 The <I>using</I> attribute (which tells the compiler to use a register
1740 bank other than the default bank zero) should only be applied to <I>interrupt</I>
1741 functions (see note 1 below). This will in most circumstances make
1742 the generated ISR code more efficient since it will not have to save
1743 registers on the stack.
1744
1745 <P>
1746 The <I>using</I> attribute will have no effect on the generated code
1747 for a <I>non-interrupt</I> function (but may occasionally be useful
1748 anyway<A NAME="tex2html1"
1749   HREF="#foot513"><SUP>1</SUP></A>).
1750 <BR><I>(pending: I don't think this has been done yet)</I>
1751
1752 <P>
1753 An <I>interrupt</I> function using a non-zero bank will assume that
1754 it can trash that register bank, and will not save it. Since high-priority
1755 interrupts can interrupt low-priority ones on the 8051 and friends,
1756 this means that if a high-priority ISR <I>using</I> a particular bank
1757 occurs while processing a low-priority ISR <I>using</I> the same bank,
1758 terrible and bad things can happen. To prevent this, no single register
1759 bank should be <I>used</I> by both a high priority and a low priority
1760 ISR. This is probably most easily done by having all high priority
1761 ISRs use one bank and all low priority ISRs use another. If you have
1762 an ISR which can change priority at runtime, you're on your own: I
1763 suggest using the default bank zero and taking the small performance
1764 hit.
1765
1766 <P>
1767 It is most efficient if your ISR calls no other functions. If your
1768 ISR must call other functions, it is most efficient if those functions
1769 use the same bank as the ISR (see note 1 below); the next best is
1770 if the called functions use bank zero. It is very inefficient to call
1771 a function using a different, non-zero bank from an ISR. 
1772
1773 <P>
1774
1775 <H2><A NAME="SECTION000411000000000000000">
1776 3.11 Absolute Addressing</A>
1777 </H2>
1778
1779 <P>
1780 Data items can be assigned an absolute address with the <I>at &lt;address&gt;</I>
1781 keyword, in addition to a storage class, e.g.:
1782 <BR>
1783 <BR><TT>xdata at 0x8000 unsigned char PORTA_8255 ;</TT>&nbsp;
1784 <BR>
1785 <BR>
1786 In the above example the PORTA_8255 will be allocated to the location
1787 0x8000 of the external ram. Note that this feature is provided to
1788 give the programmer access to <I>memory mapped</I> devices attached
1789 to the controller. The compiler does not actually reserve any space
1790 for variables declared in this way (they are implemented with an equate
1791 in the assembler). Thus it is left to the programmer to make sure
1792 there are no overlaps with other variables that are declared without
1793 the absolute address. The assembler listing file (.lst) and the linker
1794 output files (.rst) and (.map) are a good places to look for such
1795 overlaps.
1796 <BR>
1797 <BR>
1798 Absolute address can be specified for variables in all storage classes,
1799 e.g.:
1800 <BR>
1801 <BR><TT>bit at 0x02 bvar;</TT>&nbsp;
1802 <BR>&nbsp;
1803 <BR>
1804 The above example will allocate the variable at offset 0x02 in the
1805 bit-addressable space. There is no real advantage to assigning absolute
1806 addresses to variables in this manner, unless you want strict control
1807 over all the variables allocated.
1808
1809 <P>
1810
1811 <H2><A NAME="SECTION000412000000000000000">
1812 3.12 Startup Code</A>
1813 </H2>
1814
1815 <P>
1816 The compiler inserts a call to the C routine <I>_sdcc__external__startup()</I>
1817 at the start of the CODE area. This routine is in the runtime library.
1818 By default this routine returns 0, if this routine returns a non-zero
1819 value, the static &amp; global variable initialization will be skipped
1820 and the function main will be invoked Other wise static &amp; global
1821 variables will be initialized before the function main is invoked.
1822 You could add a <I>_sdcc__external__startup()</I> routine to
1823 your program to override the default if you need to setup hardware
1824 or perform some other critical operation prior to static &amp; global
1825 variable initialization.
1826
1827 <P>
1828
1829 <H2><A NAME="SECTION000413000000000000000">
1830 3.13 Inline Assembler Code</A>
1831 </H2>
1832
1833 <P>
1834 SDCC allows the use of in-line assembler with a few restriction as
1835 regards labels. All labels defined within inline assembler code <I>has
1836 to be</I> of the form <I>nnnnn$</I> where nnnn is a number less than
1837 100 (which implies a limit of utmost 100 inline assembler labels <I>per
1838 function</I>). It is strongly recommended that each assembly
1839 instruction (including labels) be placed in a separate line (as the
1840 example shows). When the <I>-peep-asm</I> command line option is
1841 used, the inline assembler code will be passed through the peephole
1842 optimizer. This might cause some unexpected changes in the inline
1843 assembler code. Please go throught the peephole optimizer rules defined
1844 in file <I>SDCCpeeph.def</I> carefully before using this option.
1845 <BR>
1846 <BR><TT>_asm </TT>&nbsp;
1847 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;mov&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b,#10 </TT>&nbsp;
1848 <BR><TT>00001$: </TT>&nbsp;
1849 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;djnz&nbsp;&nbsp;&nbsp;&nbsp;b,00001$ </TT>&nbsp;
1850 <BR><TT>_endasm ;</TT>
1851 <BR>
1852 <BR>
1853 The inline assembler code can contain any valid code understood by
1854 the assembler, this includes any assembler directives and comment
1855 lines. The compiler does not do any validation of the code within
1856 the <TT>_asm ... _endasm;</TT> keyword pair. 
1857 <BR>
1858 <BR>
1859 Inline assembler code cannot reference any C-Labels, however it can
1860 reference labels defined by the inline assembler, e.g.:
1861 <BR>
1862 <BR><TT>foo() { </TT>&nbsp;
1863 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;/* some c code */ </TT>&nbsp;
1864 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;_asm </TT>&nbsp;
1865 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;; some assembler code </TT>&nbsp;
1866 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ljmp $0003 </TT>&nbsp;
1867 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;_endasm; </TT>&nbsp;
1868 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;/* some more c code */ </TT>&nbsp;
1869 <BR><TT>clabel:&nbsp;&nbsp;/* inline assembler cannot reference this label
1870 */ </TT>&nbsp;
1871 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;_asm</TT>&nbsp;
1872 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;$0003: ;label (can be reference by inline assembler
1873 only) </TT>&nbsp;
1874 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;_endasm ; </TT>&nbsp;
1875 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;/* some more c code */</TT>&nbsp;
1876 <BR><TT>}</TT>&nbsp;
1877 <BR>&nbsp;
1878 <BR>
1879 In other words inline assembly code can access labels defined in inline
1880 assembly within the scope of the funtion. 
1881
1882 <P>
1883 The same goes the other way, ie. labels defines in inline assembly
1884 CANNOT be accessed by C statements.
1885
1886 <P>
1887
1888 <H2><A NAME="SECTION000414000000000000000">
1889 3.14 int(16 bit) and long (32 bit) Support</A>
1890 </H2>
1891
1892 <P>
1893 For signed &amp; unsigned int (16 bit) and long (32 bit) variables, division,
1894 multiplication and modulus operations are implemented by support routines.
1895 These support routines are all developed in ANSI-C to facilitate porting
1896 to other MCUs, although some model specific assembler optimations
1897 are used. The following files contain the described routine, all of
1898 them can be found in &lt;installdir&gt;/share/sdcc/lib.
1899 <BR>
1900 <BR><I>&lt;pending: tabularise this&gt;</I>
1901 <BR>
1902 <BR>
1903 _mulsint.c - signed 16 bit multiplication (calls _muluint)
1904 <BR>
1905 _muluint.c - unsigned 16 bit multiplication
1906 <BR>
1907 _divsint.c - signed 16 bit division (calls _divuint)
1908 <BR>
1909 _divuint.c - unsigned 16 bit division
1910 <BR>
1911 _modsint.c - signed 16 bit modulus (call _moduint)
1912 <BR>
1913 _moduint.c - unsigned 16 bit modulus
1914 <BR>
1915 _mulslong.c - signed 32 bit multiplication (calls _mululong)
1916 <BR>
1917 _mululong.c - unsigned32 bit multiplication
1918 <BR>
1919 _divslong.c - signed 32 division (calls _divulong)
1920 <BR>
1921 _divulong.c - unsigned 32 division
1922 <BR>
1923 _modslong.c - signed 32 bit modulus (calls _modulong)
1924 <BR>
1925 _modulong.c - unsigned 32 bit modulus 
1926 <BR>
1927 <BR>
1928 Since they are compiled as <I>non-reentrant</I>, interrupt service
1929 routines should not do any of the above operations. If this is unavoidable
1930 then the above routines will need to be compiled with the <I>-stack-auto</I>
1931 option, after which the source program will have to be compiled with
1932 <I>-int-long-rent</I> option.
1933
1934 <P>
1935
1936 <H2><A NAME="SECTION000415000000000000000">
1937 3.15 Floating Point Support</A>
1938 </H2>
1939
1940 <P>
1941 SDCC supports IEEE (single precision 4bytes) floating point numbers.The
1942 floating point support routines are derived from gcc's floatlib.c
1943 and consists of the following routines:
1944 <BR>
1945 <BR><I>&lt;pending: tabularise this&gt;</I>
1946 <BR>
1947 <BR>
1948 _fsadd.c - add floating point numbers
1949 <BR>
1950 _fssub.c - subtract floating point numbers
1951 <BR>
1952 _fsdiv.c - divide floating point numbers
1953 <BR>
1954 _fsmul.c - multiply floating point numbers
1955 <BR>
1956 _fs2uchar.c - convert floating point to unsigned char
1957 <BR>
1958 _fs2char.c - convert floating point to signed char
1959 <BR>
1960 _fs2uint.c - convert floating point to unsigned int
1961 <BR>
1962 _fs2int.c - convert floating point to signed int
1963 <BR>
1964 _fs2ulong.c - convert floating point to unsigned long
1965 <BR>
1966 _fs2long.c - convert floating point to signed long
1967 <BR>
1968 _uchar2fs.c - convert unsigned char to floating point
1969 <BR>
1970 _char2fs.c - convert char to floating point number
1971 <BR>
1972 _uint2fs.c - convert unsigned int to floating point
1973 <BR>
1974 _int2fs.c - convert int to floating point numbers
1975 <BR>
1976 _ulong2fs.c - convert unsigned long to floating point number
1977 <BR>
1978 _long2fs.c - convert long to floating point number
1979 <BR>
1980 <BR>
1981 Note if all these routines are used simultaneously the data space
1982 might overflow. For serious floating point usage it is strongly recommended
1983 that the large model be used.
1984
1985 <P>
1986
1987 <H2><A NAME="SECTION000416000000000000000">
1988 3.16 MCS51 Memory Models</A>
1989 </H2>
1990
1991 <P>
1992 SDCC allows two memory models for MCS51 code, small and large. Modules
1993 compiled with different memory models should <I>never</I> be combined
1994 together or the results would be unpredictable. The library routines
1995 supplied with the compiler are compiled as both small and large. The
1996 compiled library modules are contained in seperate directories as
1997 small and large so that you can link to either set. 
1998
1999 <P>
2000 When the large model is used all variables declared without a storage
2001 class will be allocated into the external ram, this includes all parameters
2002 and local variables (for non-reentrant functions). When the small
2003 model is used variables without storage class are allocated in the
2004 internal ram.
2005
2006 <P>
2007 Judicious usage of the processor specific storage classes and the
2008 'reentrant' function type will yield much more efficient code, than
2009 using the large model. Several optimizations are disabled when the
2010 program is compiled using the large model, it is therefore strongly
2011 recommdended that the small model be used unless absolutely required.
2012
2013 <P>
2014
2015 <H2><A NAME="SECTION000417000000000000000">
2016 3.17 DS390 Memory Models</A>
2017 </H2>
2018
2019 <P>
2020 The only model supported is Flat 24. This generates code for the 24
2021 bit contiguous addressing mode of the Dallas DS80C390 part. In this
2022 mode, up to four meg of external RAM or code space can be directly
2023 addressed. See the data sheets at www.dalsemi.com for further information
2024 on this part.
2025 <BR>
2026 <BR>
2027 In older versions of the compiler, this option was used with the MCS51
2028 code generator (<I>-mmcs51</I>). Now, however, the '390 has it's own
2029 code generator, selected by the <I>-mds390</I> switch. 
2030 <BR>
2031 <BR>
2032 Note that the compiler does not generate any code to place the processor
2033 into 24 bitmode (although <I>tinibios</I> in the ds390 libraries will
2034 do that for you). If you don't use <I>tinibios</I>, the boot loader
2035 or similar code must ensure that the processor is in 24 bit contiguous
2036 addressing mode before calling the SDCC startup code.
2037 <BR>
2038 <BR>
2039 Like the <I>-model-large</I> option, variables will by default be
2040 placed into the XDATA segment. 
2041 <BR>
2042 <BR>
2043 Segments may be placed anywhere in the 4 meg address space using the
2044 usual -*-loc options. Note that if any segments are located above
2045 64K, the -r flag must be passed to the linker to generate the proper
2046 segment relocations, and the Intel HEX output format must be used.
2047 The -r flag can be passed to the linker by using the option <I>-Wl-r</I>
2048 on the sdcc command line. However, currently the linker can not handle
2049 code segments &gt; 64k.
2050
2051 <P>
2052
2053 <H2><A NAME="SECTION000418000000000000000">
2054 3.18 Defines Created by the Compiler</A>
2055 </H2>
2056
2057 <P>
2058 The compiler creates the following #defines.
2059
2060 <P>
2061
2062 <UL>
2063 <LI>SDCC - this Symbol is always defined.
2064 </LI>
2065 <LI>SDCC_mcs51 or SDCC_ds390 or SDCC_z80, etc - depending on the model
2066 used (e.g.: -mds390)
2067 </LI>
2068 <LI>__mcs51 or __ds390 or __z80, etc - depending on the model used
2069 (e.g. -mz80)
2070 </LI>
2071 <LI>SDCC_STACK_AUTO - this symbol is defined when <I>-stack-auto</I>
2072 option is used.
2073 </LI>
2074 <LI>SDCC_MODEL_SMALL - when <I>-model-small</I> is used.
2075 </LI>
2076 <LI>SDCC_MODEL_LARGE - when <I>-model-large</I> is used.
2077 </LI>
2078 <LI>SDCC_USE_XSTACK - when <I>-xstack</I> option is used.
2079 </LI>
2080 <LI>SDCC_STACK_TENBIT - when <I>-mds390</I> is used
2081 </LI>
2082 <LI>SDCC_MODEL_FLAT24 - when <I>-mds390</I> is used
2083 </LI>
2084 </UL>
2085
2086 <P>
2087
2088 <H1><A NAME="SECTION00050000000000000000">
2089 4 SDCC Technical Data</A>
2090 </H1>
2091
2092 <P>
2093
2094 <H2><A NAME="SECTION00051000000000000000">
2095 4.1 Optimizations</A>
2096 </H2>
2097
2098 <P>
2099 SDCC performs a host of standard optimizations in addition to some
2100 MCU specific optimizations. 
2101
2102 <P>
2103
2104 <H3><A NAME="SECTION00051100000000000000">
2105 4.1.1 Sub-expression Elimination</A>
2106 </H3>
2107
2108 <P>
2109 The compiler does local and global common subexpression elimination,
2110 e.g.: 
2111 <BR>
2112 <BR><TT>i = x + y + 1; </TT>&nbsp;
2113 <BR><TT>j = x + y;</TT>
2114 <BR>
2115 <BR>
2116 will be translated to
2117 <BR>
2118 <BR><TT>iTemp = x + y </TT>&nbsp;
2119 <BR><TT>i = iTemp + 1 </TT>&nbsp;
2120 <BR><TT>j = iTemp</TT>&nbsp;
2121 <BR>
2122 <BR>
2123 Some subexpressions are not as obvious as the above example, e.g.:
2124 <BR>
2125 <BR><TT>a-&gt;b[i].c = 10; </TT>&nbsp;
2126 <BR><TT>a-&gt;b[i].d = 11;</TT>
2127 <BR>
2128 <BR>
2129 In this case the address arithmetic a-&gt;b[i] will be computed only
2130 once; the equivalent code in C would be.
2131 <BR>
2132 <BR><TT>iTemp = a-&gt;b[i]; </TT>&nbsp;
2133 <BR><TT>iTemp.c = 10; </TT>&nbsp;
2134 <BR><TT>iTemp.d = 11;</TT>
2135 <BR>
2136 <BR>
2137 The compiler will try to keep these temporary variables in registers.
2138
2139 <P>
2140
2141 <H3><A NAME="SECTION00051200000000000000">
2142 4.1.2 Dead-Code Elimination</A>
2143 </H3>
2144
2145 <P>
2146 <TT>int global; </TT>&nbsp;
2147 <BR><TT>void f () { </TT>&nbsp;
2148 <BR><TT>&nbsp;&nbsp;int i; </TT>&nbsp;
2149 <BR><TT>&nbsp;&nbsp;i = 1; &nbsp;/* dead store */ </TT>&nbsp;
2150 <BR><TT>&nbsp;&nbsp;global = 1;&nbsp;/* dead store */ </TT>&nbsp;
2151 <BR><TT>&nbsp;&nbsp;global = 2; </TT>&nbsp;
2152 <BR><TT>&nbsp;&nbsp;return; </TT>&nbsp;
2153 <BR><TT>&nbsp;&nbsp;global = 3;&nbsp;/* unreachable */ </TT>&nbsp;
2154 <BR><TT>}</TT>
2155 <BR>
2156 <BR>
2157 will be changed to
2158 <BR>
2159 <BR><TT>int global; void f () </TT>&nbsp;
2160 <BR><TT>{</TT>&nbsp;
2161 <BR><TT>&nbsp;&nbsp;global = 2; </TT>&nbsp;
2162 <BR><TT>&nbsp;&nbsp;return; </TT>&nbsp;
2163 <BR><TT>}</TT>
2164
2165 <P>
2166
2167 <H3><A NAME="SECTION00051300000000000000">
2168 4.1.3 Copy-Propagation</A>
2169 </H3>
2170
2171 <P>
2172 <TT>int f() { </TT>&nbsp;
2173 <BR><TT>&nbsp;&nbsp;int i, j; </TT>&nbsp;
2174 <BR><TT>&nbsp;&nbsp;i = 10; </TT>&nbsp;
2175 <BR><TT>&nbsp;&nbsp;j = i; </TT>&nbsp;
2176 <BR><TT>&nbsp;&nbsp;return j; </TT>&nbsp;
2177 <BR><TT>}</TT>
2178 <BR>
2179 <BR>
2180 will be changed to 
2181 <BR>
2182 <BR><TT>int f() { </TT>&nbsp;
2183 <BR><TT>&nbsp; &nbsp; int i,j; </TT>&nbsp;
2184 <BR><TT>&nbsp; &nbsp; i = 10; </TT>&nbsp;
2185 <BR><TT>&nbsp; &nbsp; j = 10; </TT>&nbsp;
2186 <BR><TT>&nbsp; &nbsp; return 10; </TT>&nbsp;
2187 <BR><TT>}</TT>&nbsp;
2188 <BR>&nbsp;
2189 <BR>
2190 Note: the dead stores created by this copy propagation will be eliminated
2191 by dead-code elimination.
2192
2193 <P>
2194
2195 <H3><A NAME="SECTION00051400000000000000">
2196 4.1.4 Loop Optimizations</A>
2197 </H3>
2198
2199 <P>
2200 Two types of loop optimizations are done by SDCC loop invariant lifting
2201 and strength reduction of loop induction variables. In addition to
2202 the strength reduction the optimizer marks the induction variables
2203 and the register allocator tries to keep the induction variables in
2204 registers for the duration of the loop. Because of this preference
2205 of the register allocator, loop induction optimization causes an increase
2206 in register pressure, which may cause unwanted spilling of other temporary
2207 variables into the stack / data space. The compiler will generate
2208 a warning message when it is forced to allocate extra space either
2209 on the stack or data space. If this extra space allocation is undesirable
2210 then induction optimization can be eliminated either for the entire
2211 source file (with -noinduction option) or for a given function only
2212 using #pragma&nbsp;NOINDUCTION.
2213 <BR>
2214 <BR>
2215 Loop Invariant:
2216 <BR>
2217 <BR><TT>for (i = 0 ; i &lt; 100 ; i ++) </TT>&nbsp;
2218 <BR> <TT>&nbsp; &nbsp;f += k + l;</TT>
2219 <BR>
2220 <BR>
2221 changed to
2222 <BR>
2223 <BR><TT>itemp = k + l; </TT>&nbsp;
2224 <BR><TT>for (i = 0; i &lt; 100; i++) </TT>&nbsp;
2225 <BR><TT>&nbsp;&nbsp;f += itemp;</TT>
2226 <BR>
2227 <BR>
2228 As mentioned previously some loop invariants are not as apparent,
2229 all static address computations are also moved out of the loop.
2230 <BR>
2231 <BR>
2232 Strength Reduction, this optimization substitutes an expression by
2233 a cheaper expression:
2234 <BR>
2235 <BR><TT>for (i=0;i &lt; 100; i++)</TT>&nbsp;
2236 <BR><TT>&nbsp;&nbsp;ar[i*5] = i*3;</TT>
2237 <BR>
2238 <BR>
2239 changed to
2240 <BR>
2241 <BR><TT>itemp1 = 0; </TT>&nbsp;
2242 <BR><TT>itemp2 = 0; </TT>&nbsp;
2243 <BR><TT>for (i=0;i&lt; 100;i++) { </TT>&nbsp;
2244 <BR> <TT>&nbsp; &nbsp;ar[itemp1] = itemp2; </TT>&nbsp;
2245 <BR> <TT>&nbsp; &nbsp;itemp1 += 5; </TT>&nbsp;
2246 <BR> <TT>&nbsp; &nbsp;itemp2 += 3; </TT>&nbsp;
2247 <BR><TT>}</TT>
2248 <BR>
2249 <BR>
2250 The more expensive multiplication is changed to a less expensive addition.
2251
2252 <P>
2253
2254 <H3><A NAME="SECTION00051500000000000000">
2255 4.1.5 Loop Reversing</A>
2256 </H3>
2257
2258 <P>
2259 This optimization is done to reduce the overhead of checking loop
2260 boundaries for every iteration. Some simple loops can be reversed
2261 and implemented using a ``decrement and jump if not zero'' instruction.
2262 SDCC checks for the following criterion to determine if a loop is
2263 reversible (note: more sophisticated compilers use data-dependency
2264 analysis to make this determination, SDCC uses a more simple minded
2265 analysis).
2266
2267 <P>
2268
2269 <UL>
2270 <LI>The 'for' loop is of the form 
2271 <BR>
2272 <BR><TT>for (&lt;symbol&gt; = &lt;expression&gt; ; &lt;sym&gt; [&lt; | &lt;=] &lt;expression&gt;
2273 ; [&lt;sym&gt;++ | &lt;sym&gt; += 1])</TT>&nbsp;
2274 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;&lt;for body&gt;</TT>
2275 </LI>
2276 <LI>The &lt;for body&gt; does not contain ``continue'' or 'break''.
2277 </LI>
2278 <LI>All goto's are contained within the loop.
2279 </LI>
2280 <LI>No function calls within the loop.
2281 </LI>
2282 <LI>The loop control variable &lt;sym&gt; is not assigned any value within the
2283 loop
2284 </LI>
2285 <LI>The loop control variable does NOT participate in any arithmetic operation
2286 within the loop.
2287 </LI>
2288 <LI>There are NO switch statements in the loop.
2289 </LI>
2290 </UL>
2291 Note djnz instruction can be used for 8-bit values <I>only</I>, therefore
2292 it is advantageous to declare loop control symbols as <I>char</I>.
2293 Ofcourse this may not be possible on all situations.
2294
2295 <P>
2296
2297 <H3><A NAME="SECTION00051600000000000000">
2298 4.1.6 Algebraic Simplifications</A>
2299 </H3>
2300
2301 <P>
2302 SDCC does numerous algebraic simplifications, the following is a small
2303 sub-set of these optimizations.
2304 <BR>
2305 <BR><TT>i = j + 0 ; /* changed to */ i = j; </TT>&nbsp;
2306 <BR><TT>i /= 2; /* changed to */ i &gt;&gt;= 1; </TT>&nbsp;
2307 <BR><TT>i = j - j ; /* changed to */ i = 0; </TT>&nbsp;
2308 <BR><TT>i = j / 1 ; /* changed to */ i = j;</TT>
2309 <BR>
2310 <BR>
2311 Note the subexpressions given above are generally introduced by macro
2312 expansions or as a result of copy/constant propagation.
2313
2314 <P>
2315
2316 <H3><A NAME="SECTION00051700000000000000">
2317 4.1.7 'switch' Statements</A>
2318 </H3>
2319
2320 <P>
2321 SDCC changes switch statements to jump tables when the following conditions
2322 are true. 
2323
2324 <P>
2325
2326 <UL>
2327 <LI>The case labels are in numerical sequence, the labels need not be
2328 in order, and the starting number need not be one or zero.
2329 </LI>
2330 </UL>
2331 <TT>switch(i) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;switch (i)
2332 { </TT>&nbsp;
2333 <BR><TT>case 4:... &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case 1: ... </TT>&nbsp;
2334 <BR><TT>case 5:... &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case 2: ... </TT>&nbsp;
2335 <BR><TT>case 3:... &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case 3: ... </TT>&nbsp;
2336 <BR><TT>case 6:... &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case 4: ... </TT>&nbsp;
2337 <BR><TT>}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</TT>&nbsp;
2338 <BR>&nbsp;
2339 <BR>
2340 Both the above switch statements will be implemented using a jump-table.
2341
2342 <P>
2343
2344 <UL>
2345 <LI>The number of case labels is at least three, since it takes two conditional
2346 statements to handle the boundary conditions.
2347 </LI>
2348 <LI>The number of case labels is less than 84, since each label takes
2349 3 bytes and a jump-table can be utmost 256 bytes long. 
2350 </LI>
2351 </UL>
2352 Switch statements which have gaps in the numeric sequence or those
2353 that have more that 84 case labels can be split into more than one
2354 switch statement for efficient code generation, e.g.:
2355 <BR>
2356 <BR><TT>switch (i) { </TT>&nbsp;
2357 <BR><TT>case 1: ... </TT>&nbsp;
2358 <BR><TT>case 2: ... </TT>&nbsp;
2359 <BR><TT>case 3: ... </TT>&nbsp;
2360 <BR><TT>case 4: ... </TT>&nbsp;
2361 <BR><TT>case 9: ... </TT>&nbsp;
2362 <BR><TT>case 10: ... </TT>&nbsp;
2363 <BR><TT>case 11: ... </TT>&nbsp;
2364 <BR><TT>case 12: ... </TT>&nbsp;
2365 <BR><TT>}</TT>
2366 <BR>
2367 <BR>
2368 If the above switch statement is broken down into two switch statements
2369 <BR>
2370 <BR><TT>switch (i) { </TT>&nbsp;
2371 <BR><TT>case 1: ... </TT>&nbsp;
2372 <BR><TT>case 2: ... </TT>&nbsp;
2373 <BR><TT>case 3: ... </TT>&nbsp;
2374 <BR><TT>case 4: ... </TT>&nbsp;
2375 <BR><TT>}</TT>&nbsp;
2376 <BR>&nbsp;
2377 <BR>
2378 and&nbsp;
2379 <BR>&nbsp;
2380 <BR><TT>switch (i) { </TT>&nbsp;
2381 <BR><TT>case 9: &nbsp;... </TT>&nbsp;
2382 <BR><TT>case 10: ... </TT>&nbsp;
2383 <BR><TT>case 11: ... </TT>&nbsp;
2384 <BR><TT>case 12:&nbsp;... </TT>&nbsp;
2385 <BR><TT>}</TT>&nbsp;
2386 <BR>&nbsp;
2387 <BR>
2388 then both the switch statements will be implemented using jump-tables
2389 whereas the unmodified switch statement will not be.
2390
2391 <P>
2392
2393 <H3><A NAME="SECTION00051800000000000000">
2394 4.1.8 Bit-shifting Operations.</A>
2395 </H3>
2396
2397 <P>
2398 Bit shifting is one of the most frequently used operation in embedded
2399 programming. SDCC tries to implement bit-shift operations in the most
2400 efficient way possible, e.g.:
2401 <BR>
2402 <BR>
2403 unsigned char i;
2404 <BR>... 
2405 <BR>
2406 i&gt;&gt;= 4; 
2407 <BR>...
2408 <BR>
2409 <BR>
2410 generates the following code:
2411 <BR>
2412 <BR>
2413 mov a,_i 
2414 <BR>
2415 swap a 
2416 <BR>
2417 anl a,#0x0f 
2418 <BR>
2419 mov _i,a
2420 <BR>
2421 <BR>
2422 In general SDCC will never setup a loop if the shift count is known.
2423 Another example:
2424 <BR>
2425 <BR><TT>unsigned int i; </TT>&nbsp;
2426 <BR><TT>... </TT>&nbsp;
2427 <BR><TT>i &gt;&gt;= 9; </TT>&nbsp;
2428 <BR><TT>...</TT>
2429 <BR>
2430 <BR>
2431 will generate:
2432 <BR>
2433 <BR><TT>mov a,(_i + 1) </TT>&nbsp;
2434 <BR><TT>mov (_i + 1),#0x00 </TT>&nbsp;
2435 <BR><TT>clr c </TT>&nbsp;
2436 <BR><TT>rrc a </TT>&nbsp;
2437 <BR><TT>mov _i,a</TT>
2438 <BR>
2439 <BR>
2440 Note that SDCC stores numbers in little-endian format (i.e. lowest
2441 order first).
2442
2443 <P>
2444
2445 <H3><A NAME="SECTION00051900000000000000">
2446 4.1.9 Bit-rotation</A>
2447 </H3>
2448
2449 <P>
2450 A special case of the bit-shift operation is bit rotation, SDCC recognizes
2451 the following expression to be a left bit-rotation:
2452 <BR>
2453 <BR><TT>unsigned char i; </TT>&nbsp;
2454 <BR><TT>... </TT>&nbsp;
2455 <BR><TT>i = ((i &lt;&lt; 1) | (i &gt;&gt;
2456 7));</TT> 
2457 <BR>...
2458 <BR>
2459 <BR>
2460 will generate the following code:
2461 <BR>
2462 <BR><TT>mov a,_i </TT>&nbsp;
2463 <BR><TT>rl a </TT>&nbsp;
2464 <BR><TT>mov _i,a</TT>
2465 <BR>
2466 <BR>
2467 SDCC uses pattern matching on the parse tree to determine this operation.Variations
2468 of this case will also be recognized as bit-rotation, i.e.: 
2469 <BR>
2470 <BR><TT>i = ((i &gt;&gt; 7) | (i &lt;&lt;
2471 1)); /* left-bit rotation */</TT>
2472
2473 <P>
2474
2475 <H3><A NAME="SECTION000511000000000000000">
2476 4.1.10 Highest Order Bit</A>
2477 </H3>
2478
2479 <P>
2480 It is frequently required to obtain the highest order bit of an integral
2481 type (long, int, short or char types). SDCC recognizes the following
2482 expression to yield the highest order bit and generates optimized
2483 code for it, e.g.:
2484 <BR>
2485 <BR> <TT>unsigned int gint; </TT>&nbsp;
2486 <BR>&nbsp;
2487 <BR><TT>foo () { </TT>&nbsp;
2488 <BR><TT>unsigned char hob; </TT>&nbsp;
2489 <BR><TT>&nbsp;&nbsp;... </TT>&nbsp;
2490 <BR><TT>&nbsp;&nbsp;hob = (gint &gt;&gt; 15) &amp; 1; </TT>&nbsp;
2491 <BR><TT>&nbsp;&nbsp;.. </TT>&nbsp;
2492 <BR><TT>}</TT>
2493 <BR>
2494 <BR>
2495 will generate the following code:
2496 <BR>&nbsp;
2497 <BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 61
2498 ;&nbsp; hob.c 7 </TT>&nbsp;
2499 <BR><TT>&nbsp;&nbsp; 000A E5*01&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 62&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
2500 mov&nbsp; a,(_gint + 1) </TT>&nbsp;
2501 <BR><TT>&nbsp;&nbsp; 000C 33&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 63&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
2502 rlc&nbsp; a </TT>&nbsp;
2503 <BR><TT>&nbsp;&nbsp; 000D E4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 64&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
2504 clr&nbsp; a </TT>&nbsp;
2505 <BR><TT>&nbsp;&nbsp; 000E 13&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 65&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
2506 rrc&nbsp; a </TT>&nbsp;
2507 <BR><TT>&nbsp;&nbsp; 000F F5*02&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 66&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
2508 mov&nbsp; _foo_hob_1_1,a</TT>&nbsp;
2509 <BR>&nbsp;
2510 <BR>
2511 Variations of this case however will <I>not</I> be recognized. It
2512 is a standard C expression, so I heartily recommend this be the only
2513 way to get the highest order bit, (it is portable). Of course it will
2514 be recognized even if it is embedded in other expressions, e.g.:
2515 <BR>
2516 <BR><TT>xyz = gint + ((gint &gt;&gt; 15) &amp; 1);</TT>
2517 <BR>
2518 <BR>
2519 will still be recognized.
2520
2521 <P>
2522
2523 <H3><A NAME="SECTION000511100000000000000">
2524 4.1.11 Peep-hole Optimizer</A>
2525 </H3>
2526
2527 <P>
2528 The compiler uses a rule based, pattern matching and re-writing mechanism
2529 for peep-hole optimization. It is inspired by <I>copt</I> a peep-hole
2530 optimizer by Christopher W. Fraser (cwfraser@microsoft.com). A default
2531 set of rules are compiled into the compiler, additional rules may
2532 be added with the <I>-peep-file &lt;filename&gt;</I> option. The rule language
2533 is best illustrated with examples.
2534 <BR>
2535 <BR><TT>replace { </TT>&nbsp;
2536 <BR><TT>&nbsp;&nbsp;mov %1,a </TT>&nbsp;
2537 <BR><TT>&nbsp;&nbsp;mov a,%1</TT>&nbsp;
2538 <BR><TT>} by {</TT>&nbsp;
2539 <BR><TT>&nbsp;&nbsp;mov %1,a</TT>&nbsp;
2540 <BR><TT>}</TT>
2541 <BR>
2542 <BR>
2543 The above rule will change the following assembly sequence:
2544 <BR>
2545 <BR><TT>&nbsp;&nbsp;mov r1,a </TT>&nbsp;
2546 <BR><TT>&nbsp;&nbsp;mov a,r1</TT>
2547 <BR>
2548 <BR>
2549 to
2550 <BR>
2551 <BR><TT>mov r1,a</TT>
2552 <BR>
2553 <BR>
2554 Note: All occurrences of a <I>%n</I> (pattern variable) must denote
2555 the same string. With the above rule, the assembly sequence:
2556 <BR>
2557 <BR><TT>&nbsp;&nbsp;mov r1,a </TT>&nbsp;
2558 <BR><TT>&nbsp;&nbsp;mov a,r2</TT>
2559 <BR>
2560 <BR>
2561 will remain unmodified.
2562 <BR>
2563 <BR>
2564 Other special case optimizations may be added by the user (via <I>-peep-file
2565 option</I>). E.g. some variants of the 8051 MCU allow only <TT>ajmp</TT>
2566 and <TT>acall</TT>. The following two rules will change all <TT>ljmp</TT>
2567 and <TT>lcall</TT> to <TT>ajmp</TT> and <TT>acall</TT>
2568 <BR>
2569 <BR><TT>replace { lcall %1 } by { acall %1 } </TT>&nbsp;
2570 <BR><TT>replace { ljmp %1 } by { ajmp %1 }</TT>
2571 <BR>
2572 <BR>
2573 The <I>inline-assembler code</I> is also passed through the peep hole
2574 optimizer, thus the peephole optimizer can also be used as an assembly
2575 level macro expander. The rules themselves are MCU dependent whereas
2576 the rule language infra-structure is MCU independent. Peephole optimization
2577 rules for other MCU can be easily programmed using the rule language.
2578 <BR>
2579 <BR>
2580 The syntax for a rule is as follows:
2581 <BR>
2582 <BR><TT>rule := replace [ restart ] '{' &lt;assembly sequence&gt; '&#92;n'
2583 </TT>&nbsp;
2584 <BR><TT>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '}' by '{' '&#92;n'
2585 </TT>&nbsp;
2586 <BR><TT>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;assembly
2587 sequence&gt; '&#92;n' </TT>&nbsp;
2588 <BR><TT>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '}' [if &lt;functionName&gt;
2589 ] '&#92;n' </TT>&nbsp;
2590 <BR>
2591 <BR>&lt;assembly sequence&gt; := assembly instruction (each instruction including
2592 labels must be on a separate line).
2593 <BR>
2594 <BR>
2595 The optimizer will apply to the rules one by one from the top in the
2596 sequence of their appearance, it will terminate when all rules are
2597 exhausted. If the 'restart' option is specified, then the optimizer
2598 will start matching the rules again from the top, this option for
2599 a rule is expensive (performance), it is intended to be used in situations
2600 where a transformation will trigger the same rule again. A good example
2601 of this the following rule:
2602 <BR>
2603 <BR>
2604 replace restart { 
2605 <BR>&nbsp;&nbsp;pop %1 
2606 <BR>&nbsp;&nbsp;push %1 } by { 
2607 <BR>&nbsp;&nbsp;; nop 
2608 <BR>}
2609 <BR>
2610 <BR>
2611 Note that the replace pattern cannot be a blank, but can be a comment
2612 line. Without the 'restart' option only the inner most 'pop' 'push'
2613 pair would be eliminated, i.e.:
2614 <BR>
2615 <BR><TT>&nbsp;&nbsp;pop ar1 </TT>&nbsp;
2616 <BR><TT>&nbsp;&nbsp;pop ar2 </TT>&nbsp;
2617 <BR><TT>&nbsp;&nbsp;push ar2 </TT>&nbsp;
2618 <BR><TT>&nbsp;&nbsp;push ar1</TT>
2619 <BR>
2620 <BR>
2621 would result in:
2622 <BR>
2623 <BR><TT>pop ar1 </TT>&nbsp;
2624 <BR><TT>; nop </TT>&nbsp;
2625 <BR><TT>push ar1</TT>
2626 <BR>
2627 <BR><I>with</I> the restart option the rule will be applied again to the
2628 resulting code and then all the pop-push pairs will be eliminated
2629 to yield:
2630 <BR>
2631 <BR><TT>; nop </TT>&nbsp;
2632 <BR><TT>; nop</TT>
2633 <BR>
2634 <BR>
2635 A conditional function can be attached to a rule. Attaching rules
2636 are somewhat more involved, let me illustrate this with an example.
2637 <BR>
2638 <BR><TT>replace { </TT>&nbsp;
2639 <BR><TT>&nbsp; &nbsp; &nbsp;ljmp %5 </TT>&nbsp;
2640 <BR><TT>%2:} by { </TT>&nbsp;
2641 <BR><TT>&nbsp; &nbsp; &nbsp;sjmp %5 </TT>&nbsp;
2642 <BR><TT>%2:} if labelInRange</TT>
2643 <BR>
2644 <BR>
2645 The optimizer does a look-up of a function name table defined in function
2646 <I>callFuncByName</I> in the source file SDCCpeeph.c, with the name
2647 <I>labelInRange</I>. If it finds a corresponding entry the function
2648 is called. Note there can be no parameters specified for these functions,
2649 in this case the use of <I>%5</I> is crucial, since the function
2650 <I>labelInRange</I> expects to find the label in that particular variable
2651 (the hash table containing the variable bindings is passed as a parameter).
2652 If you want to code more such functions, take a close look at the
2653 function labelInRange and the calling mechanism in source file SDCCpeeph.c.
2654 I know this whole thing is a little kludgey, but maybe some day we
2655 will have some better means. If you are looking at this file, you
2656 will also see the default rules that are compiled into the compiler,
2657 you can add your own rules in the default set there if you get tired
2658 of specifying the -peep-file option.
2659 <BR>
2660 <BR><I>&lt;pending: this is as far as I got&gt;</I>
2661
2662 <P>
2663
2664 <H2><A NAME="SECTION00052000000000000000">
2665 4.2 Pragmas</A>
2666 </H2>
2667
2668 <P>
2669 SDCC supports the following #pragma directives. This directives are
2670 applicable only at a function level.
2671
2672 <P>
2673
2674 <UL>
2675 <LI>SAVE - this will save all the current options.
2676 </LI>
2677 <LI>RESTORE - will restore the saved options from the last save. Note
2678 that SAVES &amp; RESTOREs cannot be nested. SDCC uses the same buffer
2679 to save the options each time a SAVE is called.
2680 </LI>
2681 <LI>NOGCSE - will stop global subexpression elimination.
2682 </LI>
2683 <LI>NOINDUCTION - will stop loop induction optimizations.
2684 </LI>
2685 <LI>NOJTBOUND - will not generate code for boundary value checking, when
2686 switch statements are turned into jump-tables.
2687 </LI>
2688 <LI>NOOVERLAY - the compiler will not overlay the parameters and local
2689 variables of a function.
2690 </LI>
2691 <LI>NOLOOPREVERSE - Will not do loop reversal optimization
2692 </LI>
2693 <LI>EXCLUDE NONE | {acc[,b[,dpl[,dph]]] - The exclude pragma
2694 disables generation of pair of push/pop instruction in ISR function
2695 (using interrupt keyword). The directive should be placed immediately
2696 before the ISR function definition and it affects ALL ISR functions
2697 following it. To enable the normal register saving for ISR functions
2698 use #pragma&nbsp;EXCLUDE&nbsp;none.
2699 </LI>
2700 <LI>CALLEE-SAVES function1[,function2[,function3...]] - The compiler
2701 by default uses a caller saves convention for register saving across
2702 function calls, however this can cause unneccessary register pushing
2703 &amp; popping when calling small functions from larger functions. This
2704 option can be used to switch the register saving convention for the
2705 function names specified. The compiler will not save registers when
2706 calling these functions, extra code will be generated at the entry
2707 &amp; exit for these functions to save &amp; restore the registers used
2708 by these functions, this can SUBSTANTIALLY reduce code &amp; improve
2709 run time performance of the generated code. In future the compiler
2710 (with interprocedural analysis) will be able to determine the appropriate
2711 scheme to use for each function call. If -callee-saves command line
2712 option is used, the function names specified in #pragma&nbsp;CALLEE-SAVES
2713 is appended to the list of functions specified inthe command line.
2714 </LI>
2715 </UL>
2716 The pragma's are intended to be used to turn-off certain optimizations
2717 which might cause the compiler to generate extra stack / data space
2718 to store compiler generated temporary variables. This usually happens
2719 in large functions. Pragma directives should be used as shown in the
2720 following example, they are used to control options &amp; optimizations
2721 for a given function; pragmas should be placed before and/or after
2722 a function, placing pragma's inside a function body could have unpredictable
2723 results.
2724
2725 <P>
2726 eg
2727
2728 <P>
2729 #pragma SAVE &nbsp; /* save the current settings */ 
2730 <BR>#pragma NOGCSE /* turnoff global subexpression elimination */
2731
2732 <BR>#pragma NOINDUCTION /* turn off induction optimizations */ 
2733 <BR>
2734 int foo () 
2735 <BR>{ 
2736 <BR>&nbsp; &nbsp; ... 
2737 <BR>&nbsp; &nbsp; /* large code */ 
2738 <BR>&nbsp; &nbsp; ... 
2739 <BR>} 
2740 <BR>#pragma RESTORE /* turn the optimizations back on */
2741
2742 <P>
2743 The compiler will generate a warning message when extra space is allocated.
2744 It is strongly recommended that the SAVE and RESTORE pragma's be used
2745 when changing options for a function.
2746
2747 <P>
2748
2749 <H2><A NAME="SECTION00053000000000000000">
2750 4.3 Library Routines</A>
2751 </H2>
2752
2753 <P>
2754 The following library routines are provided for your convenience.
2755
2756 <P>
2757 stdio.h - Contains the following functions printf &amp; sprintf these
2758 routines are developed by Martijn van Balen &lt;balen@natlab.research.philips.com&gt;. 
2759
2760 <P>
2761 %[flags][width][b|B|l|L]type
2762
2763 <P>
2764 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; flags: -&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; left justify output in
2765 specified field width 
2766 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; prefix output with
2767 +/- sign if output is signed type 
2768 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; space&nbsp;&nbsp;&nbsp; prefix output with a
2769 blank if it's a signed positive value 
2770 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; width:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; specifies minimum number
2771 of characters outputted for numbers 
2772 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; or strings. 
2773 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - For numbers,
2774 spaces are added on the left when needed. 
2775 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If width starts
2776 with a zero character, zeroes and used 
2777 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; instead of
2778 spaces. 
2779 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - For strings,
2780 spaces are are added on the left or right (when 
2781 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; flag '-' is
2782 used) when needed. 
2783 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
2784 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b/B:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; byte argument (used
2785 by d, u, o, x, X) 
2786 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; l/L:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; long argument (used
2787 by d, u, o, x, X)
2788 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; type:&nbsp; d&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; decimal number 
2789 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; u&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned decimal
2790 number 
2791 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; o&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned octal number
2792
2793 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned hexadecimal
2794 number (0-9, a-f) 
2795 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; X&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned hexadecimal
2796 number (0-9, A-F) 
2797 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; character 
2798 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string (generic pointer)
2799
2800 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; generic pointer (I:data/idata,
2801 C:code, X:xdata, P:paged) 
2802 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; f&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float (still to be
2803 implemented)
2804
2805 <P>
2806 Also contains a very simple version of printf (printf_small). This
2807 simplified version of printf supports only the following formats.
2808
2809 <P>
2810 format&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;output&nbsp;type&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;argument-type 
2811 <BR>%d &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;decimal &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; short/int 
2812 <BR>%ld&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;decimal&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;long 
2813 <BR>%hd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;decimal&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;char 
2814 <BR>%x&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hexadecimal&nbsp;&nbsp;&nbsp;&nbsp;short/int 
2815 <BR>%lx&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hexadecimal&nbsp;&nbsp;&nbsp;&nbsp;long 
2816 <BR>%hx&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hexadecimal&nbsp;&nbsp;&nbsp;&nbsp;char 
2817 <BR>%o&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;octal&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;short/int 
2818 <BR>%lo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;octal&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;long 
2819 <BR>%ho&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;octal&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;char 
2820 <BR>%c&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;character&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;char 
2821 <BR>%s&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;character&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_generic pointer
2822
2823 <P>
2824 The routine is very stack intesive, -stack-after-data parameter should
2825 be used when using this routine, the routine also takes about 1K of
2826 code space. It also expects an external function named putchar(char)
2827 to be present (this can be changed). When using the %s format the
2828 string / pointer should be cast to a generic pointer. eg.
2829
2830 <P>
2831 printf_small(``my str %s, my int %d&#92;n'',(char
2832 _generic *)mystr,myint);
2833
2834 <P>
2835
2836 <UL>
2837 <LI>stdarg.h - contains definition for the following macros to be used
2838 for variable parameter list, note that a function can have a variable
2839 parameter list if and only if it is 'reentrant'
2840
2841 <P>
2842 va_list, va_start, va_arg, va_end.
2843
2844 <P>
2845 </LI>
2846 <LI>setjmp.h - contains defintion for ANSI setjmp &amp; longjmp routines.
2847 Note in this case setjmp &amp; longjmp can be used between functions
2848 executing within the same register bank, if long jmp is executed from
2849 a function that is using a different register bank from the function
2850 issuing the setjmp function, the results may be unpredictable. The
2851 jump buffer requires 3 bytes of data (the stack pointer &amp; a 16 byte
2852 return address), and can be placed in any address space.
2853 </LI>
2854 <LI>stdlib.h - contains the following functions.
2855
2856 <P>
2857 atoi, atol.
2858
2859 <P>
2860 </LI>
2861 <LI>string.h - contains the following functions.
2862
2863 <P>
2864 strcpy, strncpy, strcat, strncat, strcmp, strncmp, strchr, strrchr,
2865 strspn, strcspn, strpbrk, strstr, strlen, strtok, memcpy, memcmp,
2866 memset.
2867
2868 <P>
2869 </LI>
2870 <LI>ctype.h - contains the following routines.
2871
2872 <P>
2873 iscntrl, isdigit, isgraph, islower, isupper, isprint, ispunct, isspace,
2874 isxdigit, isalnum, isalpha.
2875
2876 <P>
2877 </LI>
2878 <LI>malloc.h - The malloc routines are developed by Dmitry S. Obukhov
2879 (dso@usa.net). These routines will allocate memory from the external
2880 ram. Here is a description on how to use them (as described by the
2881 author).
2882
2883 <P>
2884 //Example: 
2885 <BR>&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp;&nbsp; #define DYNAMIC_MEMORY_SIZE 0x2000 
2886 <BR>&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp;&nbsp; ..... 
2887 <BR>&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp;&nbsp; unsigned char xdata dynamic_memory_pool[DYNAMIC_MEMORY_SIZE];
2888
2889 <BR>&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp;&nbsp; unsigned char xdata * current_buffer; 
2890 <BR>&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp;&nbsp; ..... 
2891 <BR>&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp;&nbsp; void main(void) 
2892 <BR>&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp;&nbsp; { 
2893 <BR>&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ... 
2894 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; init_dynamic_memory(dynamic_memory_pool,DYNAMIC_MEMORY_SIZE);
2895
2896 <BR>&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Now it's possible to use malloc. 
2897 <BR>&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ... 
2898 <BR>&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; current_buffer = malloc(0x100); 
2899 <BR>&nbsp;&nbsp;&nbsp;&nbsp; //
2900
2901 <P>
2902 </LI>
2903 <LI>serial.h - Serial IO routines are also developed by Dmitry S. Obukhov
2904 (dso@usa.net). These routines are interrupt driven with a 256 byte
2905 circular buffer, they also expect external ram to be present. Please
2906 see documentation in file SDCCDIR/sdcc51lib/serial.c. Note the header
2907 file ``serial.h'' MUST be included in the file containing the
2908 'main' function.
2909 </LI>
2910 <LI>ser.h - Alternate serial routine provided by Wolfgang Esslinger &lt;wolfgang@WiredMinds.com&gt;
2911 these routines are more compact and faster. Please see documentation
2912 in file SDCCDIR/sdcc51lib/ser.c
2913 </LI>
2914 <LI>ser_ir.h - Another alternate set of serial routines provided by Josef
2915 Wolf &lt;jw@raven.inka.de&gt;, these routines do not use the external ram.
2916 </LI>
2917 <LI>reg51.h - contains register definitions for a standard 8051
2918 </LI>
2919 <LI>float.h - contains min, max and other floating point related stuff.
2920 </LI>
2921 </UL>
2922 All library routines are compiled as -model-small, they are all non-reentrant,
2923 if you plan to use the large model or want to make these routines
2924 reentrant, then they will have to be recompiled with the appropriate
2925 compiler option.
2926
2927 <P>
2928 Have not had time to do the more involved routines like printf, will
2929 get to them shortly.
2930
2931 <P>
2932
2933 <H2><A NAME="SECTION00054000000000000000">
2934 4.4 Interfacing with Assembly Routines</A>
2935 </H2>
2936
2937 <P>
2938
2939 <H2><A NAME="SECTION00055000000000000000">
2940 4.5 Global Registers used for Parameter Passing</A>
2941 </H2>
2942
2943 <P>
2944 By default the compiler uses the global registers ``DPL,DPH,B,ACC''
2945 to pass the first parameter to a routine, the second parameter onwards
2946 is either allocated on the stack (for reentrant routines or -stack-auto
2947 is used) or in the internal / external ram (depending on the memory
2948 model). 
2949
2950 <P>
2951
2952 <H3><A NAME="SECTION00055100000000000000">
2953 4.5.1 Assembler Routine(non-reentrant)</A>
2954 </H3>
2955
2956 <P>
2957 In the following example the function cfunc calls an assembler routine
2958 asm_func, which takes two parameters.
2959
2960 <P>
2961 extern int asm_func(unsigned char, unsigned char);
2962
2963 <P>
2964 &nbsp;
2965 <BR>
2966 int c_func (unsigned char i, unsigned char j) 
2967 <BR>{ 
2968 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return asm_func(i,j); 
2969 <BR>} 
2970 <BR>
2971 int main() 
2972 <BR>{ 
2973 <BR>&nbsp;&nbsp;&nbsp;return c_func(10,9); 
2974 <BR>}
2975
2976 <P>
2977 The corresponding assembler function is:-
2978
2979 <P>
2980 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .globl _asm_func_PARM_2 
2981 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .globl _asm_func 
2982 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .area OSEG 
2983 <BR>
2984 _asm_func_PARM_2:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .ds&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 
2985 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .area CSEG 
2986 <BR>
2987 _asm_func: 
2988 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov&nbsp;&nbsp;&nbsp;&nbsp; a,dpl 
2989 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; add&nbsp;&nbsp;&nbsp;&nbsp; a,_asm_func_PARM_2 
2990 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov&nbsp;&nbsp;&nbsp;&nbsp; dpl,a 
2991 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov&nbsp;&nbsp;&nbsp;&nbsp; dpl,#0x00 
2992 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ret
2993
2994 <P>
2995 Note here that the return values are placed in 'dpl' - One byte return
2996 value, 'dpl' LSB &amp; 'dph' MSB for two byte values. 'dpl', 'dph' and
2997 'b' for three byte values (generic pointers) and 'dpl','dph','b' &amp;
2998 'acc' for four byte values.
2999
3000 <P>
3001 The parameter naming convention is _&lt;function_name&gt;_PARM_&lt;n&gt;,
3002 where n is the parameter number starting from 1, and counting from
3003 the left. The first parameter is passed in ``dpl'' for One bye
3004 parameter, ``dptr'' if two bytes, ``b,dptr'' for three bytes
3005 and ``acc,b,dptr'' for four bytes, the varaible name for the second
3006 parameter will be _&lt;function_name&gt;_PARM_2.
3007
3008 <P>
3009 Assemble the assembler routine with the following command.
3010
3011 <P>
3012 asx8051 -losg asmfunc.asm
3013
3014 <P>
3015 Then compile and link the assembler routine to the C source file with
3016 the following command,
3017
3018 <P>
3019 sdcc cfunc.c asmfunc.rel
3020
3021 <P>
3022
3023 <H3><A NAME="SECTION00055200000000000000">
3024 4.5.2 Assembler Routine(reentrant)</A>
3025 </H3>
3026
3027 <P>
3028 In this case the second parameter onwards will be passed on the stack,
3029 the parameters are pushed from right to left i.e. after the call the
3030 left most parameter will be on the top of the stack. Here is an example.
3031
3032 <P>
3033 extern int asm_func(unsigned char, unsigned char);
3034
3035 <P>
3036 &nbsp;
3037
3038 <P>
3039 int c_func (unsigned char i, unsigned char j) reentrant 
3040 <BR>{ 
3041 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return asm_func(i,j); 
3042 <BR>} 
3043 <BR>
3044 int main() 
3045 <BR>{ 
3046 <BR>&nbsp;&nbsp;&nbsp;return c_func(10,9); 
3047 <BR>}
3048
3049 <P>
3050 The corresponding assembler routine is.
3051
3052 <P>
3053 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .globl _asm_func 
3054 <BR>
3055 _asm_func: 
3056 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; push&nbsp; _bp 
3057 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov&nbsp; _bp,sp 
3058 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mov&nbsp; r2,dpl
3059 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov&nbsp; a,_bp 
3060 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; clr&nbsp; c 
3061 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; add&nbsp; a,#0xfd 
3062 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov&nbsp; r0,a 
3063 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; add&nbsp; a,#0xfc
3064 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov&nbsp; r1,a 
3065 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov&nbsp; a,@r0 
3066 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; add&nbsp; a,r2
3067 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov&nbsp; dpl,a 
3068 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov&nbsp; dph,#0x00 
3069 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov&nbsp; sp,_bp 
3070 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pop&nbsp; _bp 
3071 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ret
3072
3073 <P>
3074 The compiling and linking procedure remains the same, however note
3075 the extra entry &amp; exit linkage required for the assembler code, _bp
3076 is the stack frame pointer and is used to compute the offset into
3077 the stack for parameters and local variables.
3078
3079 <P>
3080
3081 <H2><A NAME="SECTION00056000000000000000">
3082 4.6 External Stack</A>
3083 </H2>
3084
3085 <P>
3086 The external stack is located at the start of the external ram segment,
3087 and is 256 bytes in size. When -xstack option is used to compile
3088 the program, the parameters and local variables of all reentrant functions
3089 are allocated in this area. This option is provided for programs with
3090 large stack space requirements. When used with the -stack-auto option,
3091 all parameters and local variables are allocated on the external stack
3092 (note support libraries will need to be recompiled with the same options).
3093
3094 <P>
3095 The compiler outputs the higher order address byte of the external
3096 ram segment into PORT P2, therefore when using the External Stack
3097 option, this port MAY NOT be used by the application program.
3098
3099 <P>
3100
3101 <H2><A NAME="SECTION00057000000000000000">
3102 4.7 ANSI-Compliance</A>
3103 </H2>
3104
3105 <P>
3106 Deviations from the compliancy.
3107
3108 <P>
3109
3110 <OL>
3111 <LI>functions are not always reentrant.
3112 </LI>
3113 <LI>structures cannot be assigned values directly, cannot be passed as
3114 function parameters or assigned to each other and cannot be a return
3115 value from a function.
3116
3117 <P>
3118 eg
3119
3120 <P>
3121 </LI>
3122 </OL>
3123 struct s { ... }; 
3124 <BR>
3125 struct s s1, s2; 
3126 <BR>
3127 foo() 
3128 <BR>{ 
3129 <BR>... 
3130 <BR>
3131 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
3132 <BR>... 
3133 <BR>}
3134
3135 <P>
3136 struct s foo1 (struct s parms) /* is invalid in SDCC although allowed
3137 in ANSI */ 
3138 <BR>{ 
3139 <BR>
3140 struct s rets; 
3141 <BR>... 
3142 <BR>
3143 return rets;/* is invalid in SDCC although allowed in ANSI */
3144
3145 <BR>}
3146
3147 <P>
3148
3149 <OL>
3150 <LI>'long long' (64 bit integers) not supported.
3151 </LI>
3152 <LI>'double' precision floating point not supported.
3153 </LI>
3154 <LI>integral promotions are suppressed. What does this mean ? The compiler
3155 will not implicitly promote an integer expression to a higher order
3156 integer, exception is an assignment or parameter passing. 
3157 </LI>
3158 <LI>No support for setjmp and longjmp (for now).
3159 </LI>
3160 <LI>Old K&amp;R style function declarations are NOT allowed.
3161 </LI>
3162 </OL>
3163 foo(i,j) /* this old style of function declarations */ 
3164 <BR>
3165 int i,j; /* are valid in ANSI .. not valid in SDCC */ 
3166 <BR>{ 
3167 <BR>... 
3168 <BR>}
3169
3170 <P>
3171
3172 <OL>
3173 <LI>functions declared as pointers must be dereferenced during the call.
3174
3175 <P>
3176 int (*foo)();
3177
3178 <P>
3179 </LI>
3180 </OL>
3181 &nbsp; &nbsp;... 
3182 <BR>&nbsp; &nbsp;/* has to be called like this */ 
3183 <BR>&nbsp; &nbsp;(*foo)();/* ansi standard allows calls to be made like 'foo()'
3184 */
3185
3186 <P>
3187
3188 <H2><A NAME="SECTION00058000000000000000">
3189 4.8 Cyclomatic Complexity</A>
3190 </H2>
3191
3192 <P>
3193 Cyclomatic complexity of a function is defined as the number of independent
3194 paths the program can take during execution of the function. This
3195 is an important number since it defines the number test cases you
3196 have to generate to validate the function. The accepted industry standard
3197 for complexity number is 10, if the cyclomatic complexity reported
3198 by SDCC exceeds 10 you should think about simplification of the function
3199 logic.
3200
3201 <P>
3202 Note that the complexity level is not related to the number of lines
3203 of code in a function. Large functions can have low complexity, and
3204 small functions can have large complexity levels. SDCC uses the following
3205 formula to compute the complexity.
3206
3207 <P>
3208 complexity = (number of edges in control flow graph) - 
3209 <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(number of nodes in control flow graph) + 2;
3210
3211 <P>
3212 Having said that the industry standard is 10, you should be aware
3213 that in some cases it may unavoidable to have a complexity level of
3214 less than 10. For example if you have switch statement with more than
3215 10 case labels, each case label adds one to the complexity level.
3216 The complexity level is by no means an absolute measure of the algorithmic
3217 complexity of the function, it does however provide a good starting
3218 point for which functions you might look at for further optimization.
3219
3220 <P>
3221
3222 <H1><A NAME="SECTION00060000000000000000">
3223 5 TIPS</A>
3224 </H1>
3225
3226 <P>
3227 Here are a few guide-lines that will help the compiler generate more
3228 efficient code, some of the tips are specific to this compiler others
3229 are generally good programming practice.
3230
3231 <P>
3232
3233 <UL>
3234 <LI>Use the smallest data type to represent your data-value. If it is
3235 known in advance that the value is going to be less than 256 then
3236 use a 'char' instead of a 'short' or 'int'.
3237 </LI>
3238 <LI>Use unsigned when it is known in advance that the value is not going
3239 to be negative. This helps especially if you are doing division or
3240 multiplication.
3241 </LI>
3242 <LI>NEVER jump into a LOOP.
3243 </LI>
3244 <LI>Declare the variables to be local whenever possible, especially loop
3245 control variables (induction).
3246 </LI>
3247 <LI>Since the compiler does not do implicit integral promotion, the programmer
3248 should do an explicit cast when integral promotion is required.
3249 </LI>
3250 <LI>Reducing the size of division, multiplication &amp; modulus operations
3251 can reduce code size substantially. Take the following code for example.
3252
3253 <P>
3254 foobar(unsigned int p1, unsigned char ch)
3255 <BR>{
3256 <BR>&nbsp;&nbsp;&nbsp;&nbsp;unsigned char ch1 = p1 % ch ;
3257 <BR>&nbsp;&nbsp;&nbsp;&nbsp;....&nbsp;&nbsp;&nbsp;&nbsp;
3258 <BR>}
3259
3260 <P>
3261 For the modulus operation the variable ch will be promoted to unsigned
3262 int first then the modulus operation will be performed (this will
3263 lead to a call to a support routine). If the code is changed to 
3264
3265 <P>
3266 foobar(unsigned int p1, unsigned char ch)
3267 <BR>{
3268 <BR>&nbsp;&nbsp;&nbsp;&nbsp;unsigned char ch1 = (unsigned char)p1 % ch ;
3269 <BR>&nbsp;&nbsp;&nbsp;&nbsp;....&nbsp;&nbsp;&nbsp;&nbsp;
3270 <BR>}
3271
3272 <P>
3273 It would substantially reduce the code generated (future versions
3274 of the compiler will be smart enough to detect such optimization oppurtunities).
3275
3276 <P>
3277 </LI>
3278 </UL>
3279 Notes on MCS51 memory layout(Trefor@magera.freeserve.co.uk)
3280
3281 <P>
3282 The 8051 family of micro controller have a minimum of 128 bytes of
3283 internal memory which is structured as follows
3284
3285 <P>
3286 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R7
3287 to R7 
3288
3289 <P>
3290 - Bytes 20-2F - 16 bytes to hold 128 bit variables and 
3291
3292 <P>
3293 - Bytes 30-7F - 60 bytes for general purpose use.
3294
3295 <P>
3296 Normally the SDCC compiler will only utilise the first bank of registers,
3297 but it is possible to specify that other banks of registers should
3298 be used in interrupt routines. By default, the compiler will place
3299 the stack after the last bank of used registers, i.e. if the first
3300 2 banks of registers are used, it will position the base of the internal
3301 stack at address 16 (0X10). This implies that as the stack grows,
3302 it will use up the remaining register banks, and the 16 bytes used
3303 by the 128 bit variables, and 60 bytes for general purpose use.
3304
3305 <P>
3306 By default, the compiler uses the 60 general purpose bytes to hold
3307 &#34;near data&#34;. The compiler/optimiser may also declare
3308 some Local Variables in this area to hold local data. 
3309
3310 <P>
3311 If any of the 128 bit variables are used, or near data is being used
3312 then care needs to be taken to ensure that the stack does not grow
3313 so much that it starts to over write either your bit variables or
3314 &#34;near data&#34;. There is no runtime checking to prevent
3315 this from happening.
3316
3317 <P>
3318 The amount of stack being used is affected by the use of the &#34;internal
3319 stack&#34; to save registers before a subroutine call is made,
3320 - -stack-auto will declare parameters and local variables on the
3321 stack - the number of nested subroutines.
3322
3323 <P>
3324 If you detect that the stack is over writing you data, then the following
3325 can be done. -xstack will cause an external stack to be used for
3326 saving registers and (if -stack-auto is being used) storing parameters
3327 and local variables. However this will produce more and code which
3328 will be slower to execute. 
3329
3330 <P>
3331 -stack-loc will allow you specify the start of the stack, i.e. you
3332 could start it after any data in the general purpose area. However
3333 this may waste the memory not used by the register banks and if the
3334 size of the &#34;near data&#34; increases, it may creep
3335 into the bottom of the stack.
3336
3337 <P>
3338 -stack-after-data, similar to the -stack-loc, but it automatically
3339 places the stack after the end of the &#34;near data&#34;.
3340 Again this could waste any spare register space.
3341
3342 <P>
3343 -data-loc allows you to specify the start address of the near data.
3344 This could be used to move the &#34;near data&#34; further
3345 away from the stack giving it more room to grow. This will only work
3346 if no bit variables are being used and the stack can grow to use the
3347 bit variable space.
3348
3349 <P>
3350 Conclusion.
3351
3352 <P>
3353 If you find that the stack is over writing your bit variables or &#34;near
3354 data&#34; then the approach which best utilised the internal
3355 memory is to position the &#34;near data&#34; after the
3356 last bank of used registers or, if you use bit variables, after the
3357 last bit variable by using the -data-loc, e.g. if two register banks
3358 are being used and no data variables, -data-loc 16, and - use the
3359 -stack-after-data option.
3360
3361 <P>
3362 If bit variables are being used, another method would be to try and
3363 squeeze the data area in the unused register banks if it will fit,
3364 and start the stack after the last bit variable.
3365
3366 <P>
3367
3368 <H1><A NAME="SECTION00070000000000000000">
3369 6 Retargetting for other MCUs.</A>
3370 </H1>
3371
3372 <P>
3373 The issues for retargetting the compiler are far too numerous to be
3374 covered by this document. What follows is a brief description of each
3375 of the seven phases of the compiler and its MCU dependency.
3376
3377 <P>
3378
3379 <OL>
3380 <LI>Parsing the source and building the annotated parse tree. This phase
3381 is largely MCU independent (except for the language extensions). Syntax
3382 &amp; semantic checks are also done in this phase, along with some initial
3383 optimizations like back patching labels and the pattern matching optimizations
3384 like bit-rotation etc.
3385 </LI>
3386 <LI>The second phase involves generating an intermediate code which can
3387 be easy manipulated during the later phases. This phase is entirely
3388 MCU independent. The intermediate code generation assumes the target
3389 machine has unlimited number of registers, and designates them with
3390 the name iTemp. The compiler can be made to dump a human readable
3391 form of the code generated by using the -dumpraw option.
3392 </LI>
3393 <LI>This phase does the bulk of the standard optimizations and is also
3394 MCU independent. This phase can be broken down into several sub-phases.
3395
3396 <P>
3397
3398 <UL>
3399 <LI>Break down intermediate code (iCode) into basic blocks.
3400 </LI>
3401 <LI>Do control flow &amp; data flow analysis on the basic blocks.
3402 </LI>
3403 <LI>Do local common subexpression elimination, then global subexpression
3404 elimination
3405 </LI>
3406 <LI>dead code elimination
3407 </LI>
3408 <LI>loop optimizations
3409 </LI>
3410 <LI>if loop optimizations caused any changes then do 'global subexpression
3411 elimination' and 'dead code elimination' again.
3412 </LI>
3413 </UL>
3414 </LI>
3415 <LI>This phase determines the live-ranges; by live range I mean those
3416 iTemp variables defined by the compiler that still survive after all
3417 the optimizations. Live range analysis is essential for register allocation,
3418 since these computation determines which of these iTemps will be assigned
3419 to registers, and for how long.
3420 </LI>
3421 <LI>Phase five is register allocation. There are two parts to this process.
3422
3423 <P>
3424
3425 <OL>
3426 <LI>The first part I call 'register packing' (for lack of a better term).
3427 In this case several MCU specific expression folding is done to reduce
3428 register pressure.
3429 </LI>
3430 <LI>The second part is more MCU independent and deals with allocating
3431 registers to the remaining live ranges. A lot of MCU specific code
3432 does creep into this phase because of the limited number of index
3433 registers available in the 8051.
3434 </LI>
3435 </OL>
3436 </LI>
3437 <LI>The Code generation phase is (unhappily), entirely MCU dependent and
3438 very little (if any at all) of this code can be reused for other MCU.
3439 However the scheme for allocating a homogenized assembler operand
3440 for each iCode operand may be reused.
3441 </LI>
3442 <LI>As mentioned in the optimization section the peep-hole optimizer is
3443 rule based system, which can reprogrammed for other MCUs.
3444 </LI>
3445 </OL>
3446
3447 <P>
3448
3449 <H1><A NAME="SECTION00080000000000000000">
3450 7 SDCDB - Source Level Debugger</A>
3451 </H1>
3452
3453 <P>
3454 SDCC is distributed with a source level debugger. The debugger uses
3455 a command line interface, the command repertoire of the debugger has
3456 been kept as close to gdb (the GNU debugger) as possible. The configuration
3457 and build process is part of the standard compiler installation, which
3458 also builds and installs the debugger in the target directory specified
3459 during configuration. The debugger allows you debug BOTH at the C
3460 source and at the ASM source level.
3461
3462 <P>
3463
3464 <H2><A NAME="SECTION00081000000000000000">
3465 7.1 Compiling for Debugging</A>
3466 </H2>
3467
3468 <P>
3469 The -debug option must be specified for all files for which debug
3470 information is to be generated. The complier generates a .cdb file
3471 for each of these files. The linker updates the .cdb file with the
3472 address information. This .cdb is used by the debugger.
3473
3474 <P>
3475
3476 <H2><A NAME="SECTION00082000000000000000">
3477 7.2 How the Debugger Works</A>
3478 </H2>
3479
3480 <P>
3481 When the -debug option is specified the compiler generates extra
3482 symbol information some of which are put into the the assembler source
3483 and some are put into the .cdb file, the linker updates the .cdb file
3484 with the address information for the symbols. The debugger reads the
3485 symbolic information generated by the compiler &amp; the address information
3486 generated by the linker. It uses the SIMULATOR (Daniel's S51) to execute
3487 the program, the program execution is controlled by the debugger.
3488 When a command is issued for the debugger, it translates it into appropriate
3489 commands for the simulator.
3490
3491 <P>
3492
3493 <H2><A NAME="SECTION00083000000000000000">
3494 7.3 Starting the Debugger</A>
3495 </H2>
3496
3497 <P>
3498 The debugger can be started using the following command line. (Assume
3499 the file you are debugging has
3500
3501 <P>
3502 the file name foo).
3503
3504 <P>
3505 &gt;sdcdb foo
3506
3507 <P>
3508 The debugger will look for the following files.
3509
3510 <P>
3511
3512 <OL>
3513 <LI>foo.c - the source file.
3514 </LI>
3515 <LI>foo.cdb - the debugger symbol information file.
3516 </LI>
3517 <LI>foo.ihx - the intel hex format object file.
3518 </LI>
3519 </OL>
3520
3521 <P>
3522
3523 <H2><A NAME="SECTION00084000000000000000">
3524 7.4 Command Line Options.</A>
3525 </H2>
3526
3527 <P>
3528
3529 <UL>
3530 <LI>-directory=&lt;source file directory&gt; this option can used to specify
3531 the directory search list. The debugger will look into the directory
3532 list specified for source, cdb &amp; ihx files. The items in the directory
3533 list must be separated by ':', e.g. if the source files can be in
3534 the directories /home/src1 and /home/src2, the -directory option
3535 should be -directory=/home/src1:/home/src2. Note there can be no
3536 spaces in the option. 
3537 </LI>
3538 <LI>-cd &lt;directory&gt; - change to the &lt;directory&gt;.
3539 </LI>
3540 <LI>-fullname - used by GUI front ends.
3541 </LI>
3542 <LI>-cpu &lt;cpu-type&gt; - this argument is passed to the simulator please
3543 see the simulator docs for details.
3544 </LI>
3545 <LI>-X &lt;Clock frequency &gt; this options is passed to the simulator please
3546 see simulator docs for details.
3547 </LI>
3548 <LI>-s &lt;serial port file&gt; passed to simulator see simulator docs for details.
3549 </LI>
3550 <LI>-S &lt;serial in,out&gt; passed to simulator see simulator docs for details.
3551 </LI>
3552 </UL>
3553
3554 <P>
3555
3556 <H2><A NAME="SECTION00085000000000000000">
3557 7.5 Debugger Commands.</A>
3558 </H2>
3559
3560 <P>
3561 As mention earlier the command interface for the debugger has been
3562 deliberately kept as close the GNU debugger gdb, as possible, this
3563 will help int integration with existing graphical user interfaces
3564 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
3565
3566 <P>
3567
3568 <H3><A NAME="SECTION00085100000000000000">
3569 7.5.1 break [line | file:line | function | file:function]</A>
3570 </H3>
3571
3572 <P>
3573 Set breakpoint at specified line or function.
3574
3575 <P>
3576 sdcdb&gt;break 100 
3577 <BR>
3578 sdcdb&gt;break foo.c:100
3579 <BR>
3580 sdcdb&gt;break funcfoo
3581 <BR>
3582 sdcdb&gt;break foo.c:funcfoo
3583
3584 <P>
3585
3586 <H3><A NAME="SECTION00085200000000000000">
3587 7.5.2 clear [line | file:line | function | file:function ]</A>
3588 </H3>
3589
3590 <P>
3591 Clear breakpoint at specified line or function.
3592
3593 <P>
3594 sdcdb&gt;clear 100
3595 <BR>
3596 sdcdb&gt;clear foo.c:100
3597 <BR>
3598 sdcdb&gt;clear funcfoo
3599 <BR>
3600 sdcdb&gt;clear foo.c:funcfoo
3601
3602 <P>
3603
3604 <H3><A NAME="SECTION00085300000000000000">
3605 7.5.3 continue</A>
3606 </H3>
3607
3608 <P>
3609 Continue program being debugged, after breakpoint.
3610
3611 <P>
3612
3613 <H3><A NAME="SECTION00085400000000000000">
3614 7.5.4 finish</A>
3615 </H3>
3616
3617 <P>
3618 Execute till the end of the current function.
3619
3620 <P>
3621
3622 <H3><A NAME="SECTION00085500000000000000">
3623 7.5.5 delete [n]</A>
3624 </H3>
3625
3626 <P>
3627 Delete breakpoint number 'n'. If used without any option clear ALL
3628 user defined break points.
3629
3630 <P>
3631
3632 <H3><A NAME="SECTION00085600000000000000">
3633 7.5.6 info [break | stack | frame | registers ]</A>
3634 </H3>
3635
3636 <P>
3637
3638 <UL>
3639 <LI>info break - list all breakpoints
3640 </LI>
3641 <LI>info stack - show the function call stack.
3642 </LI>
3643 <LI>info frame - show information about the current execution frame.
3644 </LI>
3645 <LI>info registers - show content of all registers.
3646 </LI>
3647 </UL>
3648
3649 <P>
3650
3651 <H3><A NAME="SECTION00085700000000000000">
3652 7.5.7 step</A>
3653 </H3>
3654
3655 <P>
3656 Step program until it reaches a different source line.
3657
3658 <P>
3659
3660 <H3><A NAME="SECTION00085800000000000000">
3661 7.5.8 next</A>
3662 </H3>
3663
3664 <P>
3665 Step program, proceeding through subroutine calls.
3666
3667 <P>
3668
3669 <H3><A NAME="SECTION00085900000000000000">
3670 7.5.9 run</A>
3671 </H3>
3672
3673 <P>
3674 Start debugged program.
3675
3676 <P>
3677
3678 <H3><A NAME="SECTION000851000000000000000">
3679 7.5.10 ptype variable </A>
3680 </H3>
3681
3682 <P>
3683 Print type information of the variable.
3684
3685 <P>
3686
3687 <H3><A NAME="SECTION000851100000000000000">
3688 7.5.11 print variable</A>
3689 </H3>
3690
3691 <P>
3692 print value of variable.
3693
3694 <P>
3695
3696 <H3><A NAME="SECTION000851200000000000000">
3697 7.5.12 file filename</A>
3698 </H3>
3699
3700 <P>
3701 load the given file name. Note this is an alternate method of loading
3702 file for debugging.
3703
3704 <P>
3705
3706 <H3><A NAME="SECTION000851300000000000000">
3707 7.5.13 frame</A>
3708 </H3>
3709
3710 <P>
3711 print information about current frame.
3712
3713 <P>
3714
3715 <H3><A NAME="SECTION000851400000000000000">
3716 7.5.14 set srcmode</A>
3717 </H3>
3718
3719 <P>
3720 Toggle between C source &amp; assembly source.
3721
3722 <P>
3723
3724 <H3><A NAME="SECTION000851500000000000000">
3725 7.5.15 ! simulator command</A>
3726 </H3>
3727
3728 <P>
3729 Send the string following '!' to the simulator, the simulator response
3730 is displayed. Note the debugger does not interpret the command being
3731 sent to the simulator, so if a command like 'go' is sent the debugger
3732 can loose its execution context and may display incorrect values.
3733
3734 <P>
3735
3736 <H3><A NAME="SECTION000851600000000000000">
3737 7.5.16 quit.</A>
3738 </H3>
3739
3740 <P>
3741 &#34;Watch me now. Iam going Down. My name is Bobby Brown&#34;
3742
3743 <P>
3744
3745 <H2><A NAME="SECTION00086000000000000000">
3746 7.6 Interfacing with XEmacs.</A>
3747 </H2>
3748
3749 <P>
3750 Two files are (in emacs lisp) are provided for the interfacing with
3751 XEmacs, sdcdb.el and sdcdbsrc.el. These two files can be found in
3752 the $(prefix)/bin directory after the installation is complete. These
3753 files need to be loaded into XEmacs for the interface to work, this
3754 can be done at XEmacs startup time by inserting the following into
3755 your '.xemacs' file (which can be found in your HOME directory) (load-file
3756 sdcdbsrc.el) [ .xemacs is a lisp file so the () around the command
3757 is REQUIRED), the files can also be loaded dynamically while XEmacs
3758 is running, set the environment variable 'EMACSLOADPATH' to the installation
3759 bin directory [$(prefix)/bin], then enter the following command
3760 ESC-x load-file sdcdbsrc. To start the interface enter the following
3761 command ESC-x sdcdbsrc, you will prompted to enter the file name to
3762 be debugged. 
3763
3764 <P>
3765 The command line options that are passed to the simulator directly
3766 are bound to default values in the file sdcdbsrc.el the variables
3767 are listed below these values maybe changed as required.
3768
3769 <P>
3770
3771 <UL>
3772 <LI>sdcdbsrc-cpu-type '51
3773 </LI>
3774 <LI>sdcdbsrc-frequency '11059200
3775 </LI>
3776 <LI>sdcdbsrc-serial nil
3777 </LI>
3778 </UL>
3779 The following is a list of key mapping for the debugger interface.
3780
3781 <P>
3782 &nbsp;
3783 <BR>;; Current Listing :: 
3784 <BR>;;key&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;binding&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Comment
3785
3786 <BR>;;--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;----&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;----
3787
3788 <BR>;; 
3789 <BR>;; n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sdcdb-next-from-src&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SDCDB
3790 next command 
3791 <BR>;; b&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sdcdb-back-from-src&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SDCDB
3792 back command 
3793 <BR>;; c&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sdcdb-cont-from-src&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SDCDB
3794 continue command
3795 <BR>;; s&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sdcdb-step-from-src&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SDCDB
3796 step command 
3797 <BR>;; ?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sdcdb-whatis-c-sexp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SDCDB
3798 ptypecommand for data at 
3799 <BR>;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
3800 buffer point 
3801 <BR>;; x&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sdcdbsrc-delete&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SDCDB
3802 Delete all breakpoints if no arg 
3803 <BR>;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;given
3804 or delete arg (C-u arg x) 
3805 <BR>;; m&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sdcdbsrc-frame&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SDCDB
3806 Display current frame if no arg, 
3807 <BR>;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;given
3808 or display frame arg 
3809 <BR>;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buffer
3810 point 
3811 <BR>;; !&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sdcdbsrc-goto-sdcdb&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Goto
3812 the SDCDB output buffer 
3813 <BR>;; p&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sdcdb-print-c-sexp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SDCDB
3814 print command for data at 
3815 <BR>;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
3816 buffer point 
3817 <BR>;; g&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sdcdbsrc-goto-sdcdb&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Goto
3818 the SDCDB output buffer 
3819 <BR>;; t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sdcdbsrc-mode&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Toggles
3820 Sdcdbsrc mode (turns it off) 
3821 <BR>;; 
3822 <BR>;; C-c C-f&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sdcdb-finish-from-src&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SDCDB
3823 finish command 
3824 <BR>;; 
3825 <BR>;; C-x SPC&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sdcdb-break&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set
3826 break for line with point 
3827 <BR>;; ESC t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sdcdbsrc-mode&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Toggle
3828 Sdcdbsrc mode 
3829 <BR>;; ESC m&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sdcdbsrc-srcmode&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
3830 Toggle list mode 
3831 <BR>;; 
3832 <BR>
3833 <P>
3834
3835 <H1><A NAME="SECTION00090000000000000000">
3836 8 Other Processors</A>
3837 </H1>
3838
3839 <P>
3840
3841 <H2><A NAME="SECTION00091000000000000000">
3842 8.1 The Z80 and gbz80 port</A>
3843 </H2>
3844
3845 <P>
3846 SDCC can target both the Zilog Z80 and the Nintendo Gameboy's Z80-like
3847 gbz80. The port is incomplete - long support is incomplete (mul, div
3848 and mod are unimplimented), and both float and bitfield support is
3849 missing, but apart from that the code generated is correct.
3850
3851 <P>
3852 As always, the code is the authoritave reference - see z80/ralloc.c
3853 and z80/gen.c. The stack frame is similar to that generated by the
3854 IAR Z80 compiler. IX is used as the base pointer, HL is used as a
3855 temporary register, and BC and DE are available for holding varibles.
3856 IY is currently unusued. Return values are stored in HL. One bad side
3857 effect of using IX as the base pointer is that a functions stack frame
3858 is limited to 127 bytes - this will be fixed in a later version.
3859
3860 <P>
3861
3862 <H1><A NAME="SECTION000100000000000000000">
3863 9 Support</A>
3864 </H1>
3865
3866 <P>
3867 SDCC has grown to be large project, the compiler alone (without the
3868 Assembler Package, Preprocessor) is about 40,000 lines of code (blank
3869 stripped). The open source nature of this project is a key to its
3870 continued growth and support. You gain the benefit and support of
3871 many active software developers and end users. Is SDCC perfect? No,
3872 that's why we need your help. The developers take pride in fixing
3873 reported bugs. You can help by reporting the bugs and helping other
3874 SDCC users. There are lots of ways to contribute, and we encourage
3875 you to take part in making SDCC a great software package.
3876
3877 <P>
3878
3879 <H2><A NAME="SECTION000101000000000000000">
3880 9.1 Reporting Bugs</A>
3881 </H2>
3882
3883 <P>
3884 Send an email to the mailing list at 'user-sdcc@sdcc.sourceforge.net'
3885 or 'devel-sdcc@sdcc.sourceforge.net'. Bugs will be fixed ASAP. When
3886 reporting a bug, it is very useful to include a small test program
3887 which reproduces the problem. If you can isolate the problem by looking
3888 at the generated assembly code, this can be very helpful. Compiling
3889 your program with the -dumpall option can sometimes be useful in
3890 locating optimization problems.
3891
3892 <P>
3893
3894 <H2><A NAME="SECTION000102000000000000000">
3895 9.2 Acknowledgments</A>
3896 </H2>
3897
3898 <P>
3899 Sandeep Dutta(sandeep.dutta@usa.net) - SDCC, the compiler, MCS51 code
3900 generator, Debugger, AVR port
3901 <BR>
3902 Alan Baldwin (baldwin@shop-pdp.kent.edu) - Initial version of ASXXXX
3903 &amp; ASLINK. 
3904 <BR>
3905 John Hartman (jhartman@compuserve.com) - Porting ASXXX &amp; ASLINK for
3906 8051
3907 <BR>
3908 Dmitry S. Obukhov (dso@usa.net) - malloc &amp; serial i/o routines. 
3909 <BR>
3910 Daniel Drotos &lt;drdani@mazsola.iit.uni-miskolc.hu&gt; - for his Freeware
3911 simulator
3912 <BR>
3913 Malini Dutta(malini_dutta@hotmail.com) - my wife for her patience
3914 and support.
3915 <BR>
3916 Unknown - for the GNU C - preprocessor.
3917 <BR>
3918 Michael Hope - The Z80 and Z80GB port, 186 development
3919 <BR>
3920 Kevin Vigor - The DS390 port.
3921 <BR>
3922 Johan Knol - DS390/TINI libs, lots of fixes and enhancements.
3923 <BR>
3924 Scott Datallo - PIC port.
3925 <BR>(Thanks to all the other volunteer developers who have helped with
3926 coding, testing, web-page creation, distribution sets, etc. You know
3927 who you are :-)
3928 <BR>
3929 <P>
3930 This document initially written by Sandeep Dutta
3931
3932 <P>
3933 All product names mentioned herein may be trademarks of their respective
3934 companies. 
3935
3936 <P>
3937 <A NAME="959"></A>
3938
3939 <H1><A NAME="SECTION000110000000000000000">
3940 About this document ...</A>
3941 </H1>
3942  <STRONG>lSDCC Compiler User Guide</STRONG><P>
3943 This document was generated using the
3944 <A HREF="http://www-dsed.llnl.gov/files/programs/unix/latex2html/manual/"><STRONG>LaTeX</STRONG>2<tt>HTML</tt></A> translator Version 2K.1beta (1.47)
3945 <P>
3946 Copyright &#169; 1993, 1994, 1995, 1996,
3947 <A HREF="http://cbl.leeds.ac.uk/nikos/personal.html">Nikos Drakos</A>, 
3948 Computer Based Learning Unit, University of Leeds.
3949 <BR>
3950 Copyright &#169; 1997, 1998, 1999,
3951 <A HREF="http://www.maths.mq.edu.au/~ross/">Ross Moore</A>, 
3952 Mathematics Department, Macquarie University, Sydney.
3953 <P>
3954 The command line arguments were: <BR>
3955  <STRONG>latex2html</STRONG> <TT>-no_subdir -split 0 -show_section_numbers /tmp/lyx_tmpdir1913F54AWM/lyx_tmpbuf1913544rwj/SDCCUdoc.tex</TT>
3956 <P>
3957 The translation was initiated by Karl Bongers on 2001-07-05
3958 <BR><HR><H4>Footnotes</H4>
3959 <DL>
3960 <DT><A NAME="foot513">...
3961 anyway</A><A NAME="foot513"
3962  HREF="SDCCUdoc.html#tex2html1"><SUP>1</SUP></A>
3963 <DD>possible exception: if a function is called ONLY from 'interrupt'
3964 functions using a particular bank, it can be declared with the same
3965 'using' attribute as the calling 'interrupt' functions. For instance,
3966 if you have several ISRs using bank one, and all of them call memcpy(),
3967 it might make sense to create a specialized version of memcpy() 'using
3968 1', since this would prevent the ISR from having to save bank zero
3969 to the stack on entry and switch to bank zero before calling the function
3970
3971
3972 </DL><HR>
3973 <!--Navigation Panel-->
3974 <IMG WIDTH="81" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next_inactive"
3975  SRC="file:/usr/share/latex2html/icons/nx_grp_g.png"> 
3976 <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up"
3977  SRC="file:/usr/share/latex2html/icons/up_g.png"> 
3978 <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous"
3979  SRC="file:/usr/share/latex2html/icons/prev_g.png">   
3980 <BR>
3981 <!--End of Navigation Panel-->
3982 <ADDRESS>
3983 Karl Bongers
3984 2001-07-05
3985 </ADDRESS>
3986 </BODY>
3987 </HTML>