conversion from .lyx
[fw/sdcc] / doc / SDCCUdoc.lyx
1 #LyX 1.1 created this file. For more info see http://www.lyx.org/
2 \lyxformat 218
3 \textclass article
4 \language english
5 \inputencoding default
6 \fontscheme default
7 \graphics default
8 \paperfontsize default
9 \spacing single 
10 \papersize Default
11 \paperpackage a4
12 \use_geometry 0
13 \use_amsmath 0
14 \paperorientation portrait
15 \secnumdepth 3
16 \tocdepth 3
17 \paragraph_separation indent
18 \defskip medskip
19 \quotes_language swedish
20 \quotes_times 2
21 \papercolumns 1
22 \papersides 1
23 \paperpagestyle default
24
25 \layout Title
26
27 lSDCC Compiler User Guide
28 \layout Standard
29
30
31 \begin_inset LatexCommand \tableofcontents{}
32
33 \end_inset 
34
35
36 \layout Section
37
38 Introduction
39 \layout Subsection
40
41 About SDCC
42 \layout Standard
43
44
45 \emph on 
46 <pending: tabularise these features, this is unreadeble>
47 \newline 
48
49 \newline 
50
51 \series bold 
52 \emph default 
53 SDCC
54 \series default 
55  is a Free ware, retargettable, optimizing ANSI-C compiler by 
56 \series bold 
57 Sandeep Dutta
58 \series default 
59  designed for 8 bit Microprocessors.
60  The current version targets Intel MCS51 based Microprocessors(8051,8052,
61  etc), Zilog Z80 based MCUs, and the Dallas 80C390 MCS51 variant.
62  It can be retargetted for other microprocessors, support for PIC, AVR and
63  186 is under development.
64  The entire source code for the compiler is distributed under GPL.
65  SDCC uses ASXXXX & ASLINK, a Freeware, retargettable assembler & linker.
66  SDCC has extensive language extensions suitable for utilizing various microcont
67 rollers underlying hardware effectively.
68  In addition to the MCU specific optimizations SDCC also does a host of
69  standard optimizations like
70 \emph on 
71  global sub expression elimination, loop optimizations (loop invariant,
72  strength reduction of induction variables and loop reversing), constant
73  folding & propagation, copy propagation, dead code elimination and jumptables
74  for 'switch' statements.
75  
76 \emph default 
77 For the back-end SDCC uses a global register allocation scheme which should
78  be well suited for other 8 bit MCUs.
79  The peep hole optimizer uses a rule based substitution mechanism which
80  is MCU dependent.
81  Supported data-types are 
82 \emph on 
83 char (8 bits, 1 byte), short and int (16 bits, 2 bytes), long (32 bit, 4
84  bytes) 
85 \emph default 
86 and
87 \emph on 
88  float (4 byte IEEE).
89  
90 \emph default 
91 The compiler also allows 
92 \emph on 
93 inline assembler code
94 \emph default 
95  to be embedded anywhere in a function.
96  In addition routines developed in assembly can also be called.
97  SDCC also provides an option to report the relative complexity of a function,
98  these functions can then be further optimized, or hand coded in assembly
99  if needed.
100  SDCC also comes with a companion source level debugger SDCDB, the debugger
101  currently uses ucSim a freeware simulator for 8051 and other micro-controllers.
102  The latest version can be downloaded from 
103 \series bold 
104
105 \begin_inset LatexCommand \htmlurl{http://sdcc.sourceforge.net/}
106
107 \end_inset 
108
109  .
110 \layout Subsection
111
112 Open Source
113 \layout Standard
114
115 All packages used in this compiler system are 
116 \emph on 
117 opensource
118 \emph default 
119  and 
120 \emph on 
121 freeware
122 \emph default 
123 ; source code for all the sub-packages (asxxxx assembler/linker, pre-processor)
124  is distributed with the package.
125  This documentation is maintained using a freeware word processor (LyX).
126  
127 \layout Standard
128
129 This program is free software; you can redistribute it and/or modify it
130  under the terms of the GNU General Public License as published by the Free
131  Software Foundation; either version 2, or (at your option) any later version.
132  This program is distributed in the hope that it will be useful, but WITHOUT
133  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
134  FOR A PARTICULAR PURPOSE.
135  See the GNU General Public License for more details.
136  You should have received a copy of the GNU General Public License along
137  with this program; if not, write to the Free Software Foundation, 59 Temple
138  Place - Suite 330, Boston, MA 02111-1307, USA.
139  In other words, you are welcome to use, share and improve this program.
140  You are forbidden to forbid anyone else to use, share and improve what
141  you give them.
142  Help stamp out software-hoarding! 
143 \newline 
144
145 \newline 
146
147 \emph on 
148 <pending: add a link to gnu>
149 \layout Subsection
150
151 Typographic conventions
152 \layout Standard
153
154 Throughout this manual, we will use the following convention.
155  Commands you have to type in are printed in 
156 \family sans 
157 \series bold 
158 "sans serif"
159 \series default 
160 .
161
162 \family default 
163  Code samples are printed in 
164 \family typewriter 
165 typewriter font.
166
167 \family default 
168  Interesting items and new terms are printed in 
169 \emph on 
170 italicised type.
171 \layout Subsection
172
173 Pending: compatibilaty with previous versions
174 \layout Standard
175
176 This version has numerous bug fixes comperated with the previous version.
177  But we also introduced some incompatibilaties with older versions.
178  Not just for the fun of it, but to make the compiler more stable, efficient
179  and ANSI compliant.
180  
181 \newline 
182
183 \newline 
184 short char
185 \newline 
186 directory structure (2.7)
187 \newline 
188 vararg pars expl int unless casted
189 \newline 
190 never had a regextend
191 \newline 
192 no --noreparms anymore
193 \newline 
194
195 \newline 
196 more?
197 \layout Subsection
198
199 System Requirements
200 \layout Standard
201
202 What do you need before you start installation of SDCC? A computer, and
203  a desire to compute.
204  The preferred method of installation is to compile SDCC from source using
205  GNU GCC and make.
206  For Windows some pre-compiled binary distributions are available for your
207  convenience.
208  You should have some experience with command line tools and compiler use.
209 \layout Subsection
210
211 Other Resources
212 \layout Standard
213
214 The SDCC home page at 
215 \begin_inset LatexCommand \htmlurl{http://sdcc.sourceforge.net/}
216
217 \end_inset 
218
219  is a great place to find distribution sets.
220  You can also find links to the user mailing lists that offer help or discuss
221  SDCC with other SDCC users.
222  Web links to other SDCC related sites can also be found here.
223  This document can be found in the DOC directory of the source package as
224  a text or HTML file.
225  Some of the other tools (simulator and assembler) included with SDCC contain
226  their own documentation and can be found in the source distribution.
227  If you want the latest unreleased software, the complete source package
228  is available directly by anonymous CVS on cvs.sdcc.sourceforge.net.
229 \layout Section
230
231 Installation
232 \layout Subsection
233
234 Linux/Unix Installation
235 \layout Enumerate
236
237
238 \series medium 
239 Download the source package, it will be named something like sdcc-2.x.x.tgz.
240 \layout Enumerate
241
242
243 \series medium 
244 Bring up a command line terminal, such as xterm.
245 \layout Enumerate
246
247
248 \series medium 
249 Unpack the file using a command like: 
250 \family sans 
251 \series bold 
252 "tar -xzf sdcc-2.x.x.tgz"
253 \family default 
254 \series medium 
255 , this will create a sub-directory called sdcc with all of the sources.
256 \layout Enumerate
257
258 Change directory into the main SDCC directory, for example type: 
259 \family sans 
260 \series bold 
261 "cd sdcc"
262 \series default 
263 .
264 \layout Enumerate
265
266
267 \series medium 
268 Type 
269 \family sans 
270 \series bold 
271 "./configure"
272 \family default 
273 \series default 
274 .
275  This configures the package for compilation on your system.
276 \layout Enumerate
277
278
279 \series medium 
280 Type 
281 \family sans 
282 \series bold 
283 "make"
284 \family default 
285 \series medium 
286 .
287
288 \series default 
289  All of the source packages will compile, this can take a while.
290 \layout Enumerate
291
292
293 \series medium 
294 Type 
295 \family sans 
296 \series bold 
297 "make install"
298 \family default 
299 \series default 
300  as root
301 \series medium 
302 .
303
304 \series default 
305  This copies the binary executables to the install directories.
306 \layout Subsection
307
308 Windows Installation
309 \layout Standard
310
311
312 \emph on 
313 <pending: is this complete? where is borland, mingw>
314 \newline 
315
316 \newline 
317
318 \emph default 
319 For installation under Windows you first need to pick between a pre-compiled
320  binary package, or installing the source package along with the Cygwin
321  package.
322  The binary package is the quickest to install, while the Cygwin package
323  includes all of the open source power tools used to compile the complete
324  SDCC source package in the Windows environment.
325  If you are not familiar with the Unix command line environment, you may
326  want to read the section on additional information for Windows users prior
327  to your initial installation.
328 \layout Subsubsection
329
330 Windows Install Using a Binary Package
331 \layout Enumerate
332
333 Download the binary package and unpack it using your favorite unpacking
334  tool (gunzip, WinZip, etc).
335  This should unpack to a group of sub-directories.
336  An example directory structure after unpacking is: c:
337 \backslash 
338 usr
339 \backslash 
340 local
341 \backslash 
342 bin for the executables, c:
343 \backslash 
344 usr
345 \backslash 
346 local
347 \backslash 
348 share
349 \backslash 
350 sdcc
351 \backslash 
352 include and c:
353 \backslash 
354 usr
355 \backslash 
356 local
357 \backslash 
358 share
359 \backslash 
360 sdcc
361 \backslash 
362 lib for the include and libraries.
363 \layout Enumerate
364
365 Adjust your environment PATH to include the location of the bin directory.
366  For example, make a setsdcc.bat file with the following: set PATH=c:
367 \backslash 
368 usr
369 \backslash 
370 local
371 \backslash 
372 bin;%PATH%
373 \layout Enumerate
374
375 When you compile with sdcc, you may need to specify the location of the
376  lib and include folders.
377  For example, sdcc -I c:
378 \backslash 
379 usr
380 \backslash 
381 local
382 \backslash 
383 share
384 \backslash 
385 sdcc
386 \backslash 
387 include -L c:
388 \backslash 
389 usr
390 \backslash 
391 local
392 \backslash 
393 share
394 \backslash 
395 sdcc
396 \backslash 
397 lib
398 \backslash 
399 small test.c
400 \layout Subsubsection
401
402 Windows Install Using Cygwin
403 \layout Enumerate
404
405
406 \series medium 
407 Download and install the cygwin package from the redhat site
408 \series default 
409
410 \begin_inset LatexCommand \htmlurl{http://sources.redhat.com/cygwin/}
411
412 \end_inset 
413
414
415 \series medium 
416 .
417  Currently, this involved downloading a small install program which then
418  automates downloading and installing 
419 \series default 
420 selected parts of
421 \series medium 
422  the package
423 \series default 
424  (a large 80M byte sized dowload for the whole thing)
425 \series medium 
426 .
427
428 \series default 
429  
430 \layout Enumerate
431
432
433 \series medium 
434 Bring up a 
435 \series default 
436 Unix/Bash 
437 \series medium 
438 command line terminal from the Cygwin menu.
439 \layout Enumerate
440
441
442 \series medium 
443 Follow the instructions in the preceding Linux/Unix installation section.
444 \layout Subsection
445
446 Testing out the SDCC Compiler
447 \layout Standard
448
449 The first thing you should do after installing your SDCC compiler is to
450  see if it runs.
451  Type 
452 \family sans 
453 \series bold 
454 "sdcc --version"
455 \family default 
456 \series default 
457  at the prompt, and the program should run and tell you the version.
458  If it doesn't run, or gives a message about not finding sdcc program, then
459  you need to check over your installation.
460  Make sure that the sdcc bin directory is in your executable search path
461  defined by the PATH environment setting (see the Trouble-shooting section
462  for suggestions).
463  Make sure that the sdcc program is in the bin folder, if not perhaps something
464  did not install correctly.
465 \newline 
466
467 \newline 
468
469 \series medium 
470 SDCC binaries are commonly installed in a directory arrangement like this:
471 \series default 
472
473 \newline 
474
475 \layout Standard
476
477
478 \begin_inset  Tabular
479 <lyxtabular version="2" rows="3" columns="2">
480 <features rotate="false" islongtable="false" endhead="0" endfirsthead="0" endfoot="0" endlastfoot="0">
481 <column alignment="left" valignment="top" leftline="true" rightline="false" width="" special="">
482 <column alignment="left" valignment="top" leftline="true" rightline="true" width="" special="">
483 <row topline="true" bottomline="true" newpage="false">
484 <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special="">
485 \begin_inset Text
486
487 \layout Standard
488
489 /
490 \series medium 
491 usr/local/bin
492 \end_inset 
493 </cell>
494 <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="true" rotate="false" usebox="none" width="" special="">
495 \begin_inset Text
496
497 \layout Standard
498
499
500 \series medium 
501 Holds executables(sdcc, s51, aslink, 
502 \series default 
503 ...
504 \series medium 
505 )
506 \end_inset 
507 </cell>
508 </row>
509 <row topline="true" bottomline="false" newpage="false">
510 <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special="">
511 \begin_inset Text
512
513 \layout Standard
514
515 /
516 \series medium 
517 usr/local/share/sdcc/lib 
518 \end_inset 
519 </cell>
520 <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="true" rotate="false" usebox="none" width="" special="">
521 \begin_inset Text
522
523 \layout Standard
524
525
526 \series medium 
527 Holds common C 
528 \series default 
529 libraries
530 \end_inset 
531 </cell>
532 </row>
533 <row topline="true" bottomline="true" newpage="false">
534 <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special="">
535 \begin_inset Text
536
537 \layout Standard
538
539 /
540 \series medium 
541 usr/local/share/sdcc/include
542 \end_inset 
543 </cell>
544 <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="true" rotate="false" usebox="none" width="" special="">
545 \begin_inset Text
546
547 \layout Standard
548
549
550 \series medium 
551 Holds common C header files
552 \end_inset 
553 </cell>
554 </row>
555 </lyxtabular>
556
557 \end_inset 
558
559
560 \newline 
561
562 \newline 
563
564 \series medium 
565 Make sure the compiler works on a very simple example.
566  Type in the following test.c program using your favorite editor:
567 \series default 
568
569 \newline 
570
571 \emph on 
572
573 \newline 
574
575 \series medium 
576 \emph default 
577 Compile this using the following command: 
578 \family sans 
579 \series bold 
580 "sdcc -c test.c"
581 \family default 
582 \series default 
583  
584 \series medium 
585 If all goes well, the compiler will generate a test.asm and test.rel file.
586  Congratulations, you've just compiled your first program with SDCC.
587  We used the -c option to tell SDCC not to link the generated code, just
588  to keep things simple for this step.
589 \series default 
590
591 \newline 
592
593 \newline 
594
595 \series medium 
596 The next step is to try it with the linker.
597  Type in 
598 \family sans 
599 \series bold 
600 "sdcc test.c"
601 \family default 
602 \series medium 
603 .
604  If all goes well the compiler will link with the libraries and produce
605  a test.ihx output file.
606  If this step fails
607 \series default 
608  
609 \series medium 
610 (no test.ihx, and the linker generates warnings), then the problem is most
611  likely that sdcc cannot find the 
612 \series default 
613 /
614 \series medium 
615 usr/local/share/sdcc/lib directory
616 \series default 
617  
618 \series medium 
619 (see the Install trouble-shooting section for suggestions).
620 \series default 
621
622 \newline 
623
624 \newline 
625
626 \series medium 
627 The final test is to ensure sdcc can use the 
628 \series default 
629 standard
630 \series medium 
631  header files and libraries.
632  Edit test.c and change it to the following:
633 \series default 
634
635 \newline 
636
637 \newline 
638 #include <string.h>
639 \newline 
640 main() {
641 \newline 
642
643 \family typewriter 
644 char str1[10];
645 \newline 
646 \SpecialChar ~
647 \SpecialChar ~
648 \SpecialChar ~
649 \SpecialChar ~
650 strcpy(str1, "testing");
651 \newline 
652 }
653 \newline 
654
655 \newline 
656
657 \family default 
658 \series medium 
659 Compile this by typing 
660 \family sans 
661 \series bold 
662 "sdcc test.c"
663 \family default 
664 \series medium 
665 .
666  This should generate a test.ihx output file, and it should give no warnings
667  such as not finding the string.h file.
668  If it cannot find the string.h file, then the problem is that sdcc cannot
669  find the /usr/local/share/sdcc/include directory
670 \series default 
671  
672 \series medium 
673 (see the Install trouble-shooting section for suggestions).
674 \layout Subsection
675
676 Install Trouble-shooting
677 \layout Subsubsection
678
679 SDCC cannot find libraries or header files.
680 \layout Standard
681
682 The default installation assumes the libraries and header files are located
683  at 
684 \begin_inset Quotes eld
685 \end_inset 
686
687 /usr/local/share/sdcc/lib
688 \begin_inset Quotes erd
689 \end_inset 
690
691  and 
692 \begin_inset Quotes eld
693 \end_inset 
694
695 /usr/local/share/sdcc/include
696 \begin_inset Quotes erd
697 \end_inset 
698
699 .
700  An alternative is to specify these locations as compiler options like this:
701  
702 \family sans 
703 \series bold 
704 "sdcc\SpecialChar ~
705 -L\SpecialChar ~
706 /usr/local/sdcc/lib/small\SpecialChar ~
707 -I\SpecialChar ~
708 /usr/local/sdcc/include\SpecialChar ~
709 test.c"
710 \family default 
711 \series default 
712 .
713 \layout Subsubsection
714
715 SDCC does not compile correctly.
716 \layout Standard
717
718 A thing to try is starting from scratch by unpacking the .tgz source package
719  again in an empty directory.
720  Confure it again and build like:
721 \newline 
722
723 \newline 
724
725 \family sans 
726 \series bold 
727 make 2&>1 | tee make.log
728 \family default 
729 \series default 
730
731 \newline 
732
733 \newline 
734 After this you can review the make.log file to locate the problem.
735  Or a relevant part of this be attached to an email that could be helpful
736  when requesting help from the mailing list.
737 \layout Subsubsection
738
739 What the 
740 \begin_inset Quotes sld
741 \end_inset 
742
743 ./configure
744 \begin_inset Quotes srd
745 \end_inset 
746
747  does
748 \layout Standard
749
750 The 
751 \begin_inset Quotes sld
752 \end_inset 
753
754 ./configure
755 \begin_inset Quotes srd
756 \end_inset 
757
758  command is a script that analyzes your system and performs some configuration
759  to ensure the source package compiles on your system.
760  It will take a few minutes to run, and will compile a few tests to determine
761  what compiler features are installed.
762 \layout Subsubsection
763
764 What the 
765 \begin_inset Quotes sld
766 \end_inset 
767
768 make
769 \begin_inset Quotes srd
770 \end_inset 
771
772  does.
773 \layout Standard
774
775 This runs the GNU make tool, which automatically compiles all the source
776  packages into the final installed binary executables.
777 \layout Subsubsection
778
779 What the 
780 \begin_inset Quotes sld
781 \end_inset 
782
783 make install
784 \begin_inset Quotes erd
785 \end_inset 
786
787  command does.
788 \layout Standard
789
790 This will install the compiler, other executables and libraries in to the
791  appropriate system directories.
792  The default is to copy the executables to /usr/local/bin and the libraries
793  and header files to /usr/local/share/sdcc/lib and /usr/local/share/sdcc/include.
794 \layout Subsection
795
796 Additional Information for Windows Users
797 \layout Standard
798
799
800 \emph on 
801 <pending: is this up to date?>
802 \newline 
803
804 \newline 
805
806 \emph default 
807 The standard method of installing on a Unix system involves compiling the
808  source package.
809  This is easily done under Unix, but under Windows it can be a more difficult
810  process.
811  The Cygwin is a large package to download, and the compilation runs considerabl
812 y slower under Windows due to the overhead of the Cygwin tool set.
813  An alternative is to install a pre-compiled Windows binary package.
814  There are various trade-offs between each of these methods.
815  
816 \layout Standard
817
818 The Cygwin package allows a Windows user to run a Unix command line interface
819  (bash shell) and also implements a Unix like file system on top of Windows.
820  Included are many of the famous GNU software development tools which can
821  augment the SDCC compiler.This is great if you have some experience with
822  Unix command line tools and file system conventions, if not you may find
823  it easier to start by installing a binary Windows package.
824  The binary packages work with the Windows file system conventions.
825 \layout Subsubsection
826
827 Getting started with Cygwin
828 \layout Standard
829
830 SDCC is typically distributed as a tarred/gzipped file (.tgz).
831  This is a packed file similar to a .zip file.
832  Cygwin includes the tools you will need to unpack the SDCC distribution
833  (tar and gzip).
834  To unpack it, simply follow the instructions under the Linux/Unix install
835  section.
836  Before you do this you need to learn how to start a cygwin shell and some
837  of the basic commands used to move files, change directory, run commands
838  and so on.
839  The change directory command is 
840 \family sans 
841 \series bold 
842
843 \begin_inset Quotes eld
844 \end_inset 
845
846 cd
847 \begin_inset Quotes erd
848 \end_inset 
849
850
851 \family default 
852 \series default 
853 , the move command is 
854 \family sans 
855 \series bold 
856
857 \begin_inset Quotes eld
858 \end_inset 
859
860 mv
861 \begin_inset Quotes erd
862 \end_inset 
863
864
865 \family default 
866 \series default 
867 .
868  To print the current working directory, type 
869 \family sans 
870 \series bold 
871
872 \begin_inset Quotes eld
873 \end_inset 
874
875 pwd
876 \begin_inset Quotes erd
877 \end_inset 
878
879
880 \family default 
881 \series default 
882 .
883  To make a directory, use 
884 \family sans 
885 \series bold 
886
887 \begin_inset Quotes eld
888 \end_inset 
889
890 mkdir
891 \begin_inset Quotes erd
892 \end_inset 
893
894
895 \family default 
896 \series default 
897 .
898 \layout Standard
899
900 There are some basic differences between Unix and Windows file systems you
901  should understand.
902  When you type in directory paths, Unix and the Cygwin bash prompt uses
903  forward slashes '/' between directories while Windows traditionally uses
904  '
905 \backslash 
906 ' backward slashes.
907  So when you work at the Cygwin bash prompt, you will need to use the forward
908  '/' slashes.
909  Unix does not have a concept of drive letters, such as 
910 \begin_inset Quotes eld
911 \end_inset 
912
913 c:
914 \begin_inset Quotes eld
915 \end_inset 
916
917 , instead all files systems attach and appear as directories.
918 \layout Subsubsection
919
920 Running SDCC as Native Compiled Executables
921 \layout Standard
922
923 If you use the pre-compiled binaries, the install directories for the libraries
924  and header files may need to be specified on the sdcc command line like
925  this: 
926 \family sans 
927 \series bold 
928 "sdcc -L c:
929 \backslash 
930 usr
931 \backslash 
932 local
933 \backslash 
934 sdcc
935 \backslash 
936 lib
937 \backslash 
938 small -I c:
939 \backslash 
940 usr
941 \backslash 
942 local
943 \backslash 
944 sdcc
945 \backslash 
946 include test.c"
947 \family default 
948 \series default 
949  if you are running outside of a Unix bash shell.
950 \layout Standard
951
952 If you have successfully installed and compiled SDCC with the Cygwin package,
953  it is possible to compile into native .exe files by using the additional
954  makefiles included for this purpose.
955  For example, with the Borland 32-bit compiler you would run 
956 \family sans 
957 \series bold 
958 "make -f Makefile.bcc"
959 \family default 
960 \series default 
961 .
962  A command line version of the Borland 32-bit compiler can be downloaded
963  from the Inprise web site.
964 \layout Subsection
965
966 SDCC on Other Platforms
967 \layout Itemize
968
969
970 \series bold 
971 FreeBSD and other non-GNU Unixes 
972 \series default 
973 - Make sure the GNU make is installed as the default make tool.
974 \layout Itemize
975
976 SDCC has been ported to run under a variety of operating systems and processors.
977  If you can run GNU GCC/make then chances are good SDCC can be compiled
978  and run on your system.
979 \layout Subsection
980
981 Advanced Install Options
982 \layout Standard
983
984 The 
985 \begin_inset Quotes eld
986 \end_inset 
987
988 configure
989 \begin_inset Quotes erd
990 \end_inset 
991
992  command has several options.
993  The most commonly used option is --prefix=<directory name>, where <directory
994  name> is the final location for the sdcc executables and libraries, (default
995  location is /usr/local).
996  The installation process will create the following directory structure
997  under the <directory name> specified (if they do not already exist).
998  
999 \newline 
1000
1001 \newline 
1002 bin/ - binary exectables (add to PATH environment variable)
1003 \newline 
1004 bin/share/
1005 \newline 
1006 bin/share/sdcc/include/ - include header files
1007 \newline 
1008 bin/share/sdcc/lib/
1009 \newline 
1010 bin/share/sdcc/lib/small/ - Object & library files for small model library
1011 \newline 
1012 bin/share/sdcc/lib/large/ - Object & library files for large model library
1013 \newline 
1014 bin/share/sdcc/lib/ds390/ - Object & library files forDS80C390 library
1015 \newline 
1016
1017 \newline 
1018 The command 
1019 \family sans 
1020 \series bold 
1021
1022 \begin_inset Quotes sld
1023 \end_inset 
1024
1025 ./configure --prefix=/usr/local
1026 \begin_inset Quotes erd
1027 \end_inset 
1028
1029  
1030 \family default 
1031 \series default 
1032 will configure the compiler to be installed in directory /usr/local/bin.
1033 \layout Subsection
1034
1035 Components of SDCC
1036 \layout Standard
1037
1038 SDCC is not just a compiler, but a collection of tools by various developers.
1039  These include linkers, assemblers, simulators and other components.
1040  Here is a summary of some of the components.
1041  Note that the included simulator and assembler have separate documentation
1042  which you can find in the source package in their respective directories.
1043  As SDCC grows to include support for other processors, other packages from
1044  various developers are included and may have their own sets of documentation.
1045 \layout Standard
1046
1047 You might want to look at the various executables which are installed in
1048  the bin directory.
1049  At the time of this writing, we find the following programs:
1050 \newline 
1051
1052 \newline 
1053
1054 \emph on 
1055 <pending: tabularize this>
1056 \emph default 
1057
1058 \newline 
1059
1060 \newline 
1061
1062 \series bold 
1063 sdcc
1064 \series default 
1065  - The compiler.
1066 \newline 
1067
1068 \series bold 
1069 sdcpp
1070 \series default 
1071  - The C preprocessor.
1072 \newline 
1073
1074 \series bold 
1075 asx8051
1076 \series default 
1077  - The assembler for 8051 type processors.
1078 \newline 
1079
1080 \series bold 
1081 as-z80, as-gbz80
1082 \series default 
1083  - The Z80 and GameBoy Z80 assemblers.
1084 \newline 
1085
1086 \series bold 
1087 aslink
1088 \series default 
1089  -The linker for 8051 type processors.
1090 \newline 
1091
1092 \series bold 
1093 link-z80, link-gbz80
1094 \series default 
1095  - The Z80 and GameBoy Z80 linkers.
1096 \newline 
1097
1098 \series bold 
1099 s51
1100 \series default 
1101  - The ucSim 8051 simulator.
1102 \newline 
1103
1104 \series bold 
1105 sdcdb
1106 \series default 
1107  - The source debugger.
1108 \newline 
1109
1110 \series bold 
1111 packihx
1112 \series default 
1113  - A tool to pack Intel hex files.
1114 \newline 
1115
1116 \newline 
1117 As development for other processors proceeds, this list will expand to include
1118  executables to support processors like AVR, PIC, etc.
1119 \layout Subsubsection
1120
1121 sdcc - The Compiler
1122 \layout Standard
1123
1124 This is the actual compiler, it in turn uses the c-preprocessor and invokes
1125  the assembler and linkage editor.
1126 \layout Subsubsection
1127
1128 sdcpp (C-Preprocessor)
1129 \layout Standard
1130
1131 The preprocessor is a modified version of the GNU preprocessor.
1132  The C preprocessor is used to pull in #include sources, process #ifdef
1133  statements, #defines and so on.
1134 \layout Subsubsection
1135
1136 asx8051, as-z80, as-gbz80, aslink, link-z80, link-gbz80 (The Assemblers
1137  and Linkage Editors)
1138 \layout Standard
1139
1140 This is retargettable assembler & linkage editor, it was developed by Alan
1141  Baldwin.
1142  John Hartman created the version for 8051, and I (Sandeep) have made some
1143  enhancements and bug fixes for it to work properly with the SDCC.
1144 \layout Subsubsection
1145
1146 s51 - Simulator
1147 \layout Standard
1148
1149 S51 is a freeware, opensource simulator developed by Daniel Drotos (
1150 \begin_inset LatexCommand \url{mailto:drdani@mazsola.iit.uni-miskolc.hu}
1151
1152 \end_inset 
1153
1154 ).
1155  The simulator is built as part of the build process.
1156  For more information visit Daniel's website at: 
1157 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
1158
1159 \end_inset 
1160
1161  .
1162 \layout Subsubsection
1163
1164 sdcdb - Source Level Debugger
1165 \layout Standard
1166
1167 Sdcdb is the companion source level debugger.
1168  The current version of the debugger uses Daniel's Simulator S51, but can
1169  be easily changed to use other simulators.
1170 \layout Section
1171
1172 Using SDCC
1173 \layout Subsection
1174
1175 Compiling
1176 \layout Subsubsection
1177
1178 Single Source File Projects
1179 \layout Standard
1180
1181 For single source file 8051 projects the process is very simple.
1182  Compile your programs with the following command 
1183 \family sans 
1184 \series bold 
1185 "sdcc sourcefile.c".
1186
1187 \family default 
1188 \series default 
1189  This will compile, assemble and link your source file.
1190  Output files are as follows
1191 \newline 
1192
1193 \newline 
1194 sourcefile.asm - Assembler source file created by the compiler
1195 \newline 
1196 sourcefile.lst - Assembler listing file created by the Assembler
1197 \newline 
1198 sourcefile.rst - Assembler listing file updated with linkedit information,
1199  created by linkage editor
1200 \newline 
1201 sourcefile.sym - symbol listing for the sourcefile, created by the assembler
1202 \newline 
1203 sourcefile.rel - Object file created by the assembler, input to Linkage editor
1204 \newline 
1205 sourcefile.map - The memory map for the load module, created by the Linker
1206 \newline 
1207 sourcefile.ihx - The load module in Intel hex format (you can select the
1208  Motorola S19 format with --out-fmt-s19)
1209 \newline 
1210 sourcefile.cdb - An optional file (with --debug) containing debug information
1211 \newline 
1212
1213 \layout Subsubsection
1214
1215 Projects with Multiple Source Files
1216 \layout Standard
1217
1218 SDCC can compile only ONE file at a time.
1219  Let us for example assume that you have a project containing the following
1220  files:
1221 \newline 
1222
1223 \newline 
1224 foo1.c (contains some functions)
1225 \newline 
1226 foo2.c (contains some more functions)
1227 \newline 
1228 foomain.c (contains more functions and the function main)
1229 \newline 
1230
1231 \size footnotesize 
1232
1233 \newline 
1234
1235 \size default 
1236 The first two files will need to be compiled separately with the commands:
1237 \size footnotesize 
1238  
1239 \size default 
1240
1241 \newline 
1242
1243 \newline 
1244
1245 \family sans 
1246 \series bold 
1247 sdcc\SpecialChar ~
1248 -c\SpecialChar ~
1249 foo1.c
1250 \family default 
1251 \series default 
1252 \size footnotesize 
1253
1254 \newline 
1255
1256 \family sans 
1257 \series bold 
1258 \size default 
1259 sdcc\SpecialChar ~
1260 -c\SpecialChar ~
1261 foo2.c
1262 \family default 
1263 \series default 
1264
1265 \newline 
1266
1267 \newline 
1268 Then compile the source file containing the 
1269 \emph on 
1270 main()
1271 \emph default 
1272  function and link the files together with the following command: 
1273 \newline 
1274
1275 \newline 
1276
1277 \family sans 
1278 \series bold 
1279 sdcc\SpecialChar ~
1280 foomain.c\SpecialChar ~
1281 foo1.rel\SpecialChar ~
1282 foo2.rel
1283 \family default 
1284 \series default 
1285
1286 \newline 
1287
1288 \newline 
1289 Alternatively, 
1290 \emph on 
1291 foomain.c 
1292 \emph default 
1293 can be separately compiled as well: 
1294 \family sans 
1295 \series bold 
1296
1297 \newline 
1298
1299 \newline 
1300 sdcc\SpecialChar ~
1301 -c\SpecialChar ~
1302 foomain.c
1303 \newline 
1304 sdcc foomain.rel foo1.rel foo2.rel
1305 \newline 
1306
1307 \newline 
1308
1309 \family default 
1310 \series default 
1311 The file containing the 
1312 \emph on 
1313 main()
1314 \emph default 
1315  function
1316 \emph on 
1317  
1318 \emph default 
1319 \noun on 
1320 must
1321 \noun default 
1322  be the 
1323 \noun on 
1324 first
1325 \noun default 
1326  file specified in the command line, since the linkage editor processes
1327  file in the order they are presented to it.
1328 \layout Subsubsection
1329
1330 Projects with Additional Libraries
1331 \layout Standard
1332
1333 Some reusable routines may be compiled into a library, see the documentation
1334  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
1335  for how to create a 
1336 \emph on 
1337 .lib
1338 \emph default 
1339  library file.
1340  Libraries created in this manner can be included in the command line.
1341  Make sure you include the -L <library-path> option to tell the linker where
1342  to look for these files if they are not in the current directory.
1343  Here is an example, assuming you have the source file 
1344 \emph on 
1345 foomain.c
1346 \emph default 
1347  and a library
1348 \emph on 
1349  foolib.lib
1350 \emph default 
1351  in the directory 
1352 \emph on 
1353 mylib
1354 \emph default 
1355  (if that is not the same as your current project):
1356 \newline 
1357
1358 \newline 
1359
1360 \family sans 
1361 \series bold 
1362 sdcc foomain.c foolib.lib -L mylib
1363 \newline 
1364
1365 \newline 
1366
1367 \family default 
1368 \series default 
1369 Note here that
1370 \emph on 
1371  mylib
1372 \emph default 
1373  must be an absolute path name.
1374 \newline 
1375
1376 \newline 
1377 The most efficient way to use libraries is to keep seperate modules in seperate
1378  source files.
1379  The lib file now should name all the modules.rel files.
1380  For an example see the standard library file 
1381 \emph on 
1382 libsdcc.lib
1383 \emph default 
1384  in the directory <installdir>/share/lib/small.
1385 \layout Subsection
1386
1387 Command Line Options
1388 \layout Subsubsection
1389
1390 Processor Selection Options
1391 \layout List
1392 \labelwidthstring 00.00.0000
1393
1394
1395 \series bold 
1396 -mmcs51
1397 \series default 
1398  Generate code for the MCS51 (8051) family of processors.
1399  This is the default processor target.
1400 \layout List
1401 \labelwidthstring 00.00.0000
1402
1403
1404 \series bold 
1405 -mds390
1406 \series default 
1407  Generate code for the DS80C390 processor.
1408 \layout List
1409 \labelwidthstring 00.00.0000
1410
1411
1412 \series bold 
1413 -mz80
1414 \series default 
1415  Generate code for the Z80 family of processors.
1416 \layout List
1417 \labelwidthstring 00.00.0000
1418
1419
1420 \series bold 
1421 -mgbz80
1422 \series default 
1423  Generate code for the GameBoy Z80 processor.
1424 \layout List
1425 \labelwidthstring 00.00.0000
1426
1427
1428 \series bold 
1429 -mavr
1430 \series default 
1431  Generate code for the Atmel AVR processor(In development, not complete).
1432 \layout List
1433 \labelwidthstring 00.00.0000
1434
1435
1436 \series bold 
1437 -mpic14
1438 \series default 
1439  Generate code for the PIC 14-bit processors(In development, not complete).
1440 \layout List
1441 \labelwidthstring 00.00.0000
1442
1443
1444 \series bold 
1445 -mtlcs900h
1446 \series default 
1447  Generate code for the Toshiba TLCS-900H processor(In development, not complete).
1448 \layout Subsubsection
1449
1450 Preprocessor Options
1451 \layout List
1452 \labelwidthstring 00.00.0000
1453
1454
1455 \series bold 
1456 -I<path>
1457 \series default 
1458  The additional location where the pre processor will look for <..h> or 
1459 \begin_inset Quotes eld
1460 \end_inset 
1461
1462 ..h
1463 \begin_inset Quotes erd
1464 \end_inset 
1465
1466  files.
1467 \layout List
1468 \labelwidthstring 00.00.0000
1469
1470
1471 \series bold 
1472 -D<macro[=value]>
1473 \series default 
1474  Command line definition of macros.
1475  Passed to the pre processor.
1476 \layout List
1477 \labelwidthstring 00.00.0000
1478
1479
1480 \series bold 
1481 -M
1482 \series default 
1483  Tell the preprocessor to output a rule suitable for make describing the
1484  dependencies of each object file.
1485  For each source file, the preprocessor outputs one make-rule whose target
1486  is the object file name for that source file and whose dependencies are
1487  all the files `#include'd in it.
1488  This rule may be a single line or may be continued with `
1489 \backslash 
1490 '-newline if it is long.
1491  The list of rules is printed on standard output instead of the preprocessed
1492  C program.
1493  `-M' implies `-E'.
1494 \layout List
1495 \labelwidthstring 00.00.0000
1496
1497
1498 \series bold 
1499 -C
1500 \series default 
1501  Tell the preprocessor not to discard comments.
1502  Used with the `-E' option.
1503 \layout List
1504 \labelwidthstring 00.00.0000
1505
1506
1507 \series bold 
1508 -MM
1509 \size large 
1510 \bar under 
1511  
1512 \series default 
1513 \size default 
1514 \bar default 
1515 Like `-M' but the output mentions only the user header files included with
1516  `#include 
1517 \begin_inset Quotes eld
1518 \end_inset 
1519
1520 file"'.
1521  System header files included with `#include <file>' are omitted.
1522 \layout List
1523 \labelwidthstring 00.00.0000
1524
1525
1526 \series bold 
1527 -Aquestion(answer)
1528 \series default 
1529  Assert the answer answer for question, in case it is tested with a preprocessor
1530  conditional such as `#if #question(answer)'.
1531  `-A-' disables the standard assertions that normally describe the target
1532  machine.
1533 \layout List
1534 \labelwidthstring 00.00.0000
1535
1536
1537 \series bold 
1538 -Aquestion
1539 \series default 
1540  (answer) Assert the answer answer for question, in case it is tested with
1541  a preprocessor conditional such as `#if #question(answer)'.
1542  `-A-' disables the standard assertions that normally describe the target
1543  machine.
1544 \layout List
1545 \labelwidthstring 00.00.0000
1546
1547
1548 \series bold 
1549 -Umacro
1550 \series default 
1551  Undefine macro macro.
1552  `-U' options are evaluated after all `-D' options, but before any `-include'
1553  and `-imacros' options.
1554 \layout List
1555 \labelwidthstring 00.00.0000
1556
1557
1558 \series bold 
1559 -dM
1560 \series default 
1561  Tell the preprocessor to output only a list of the macro definitions that
1562  are in effect at the end of preprocessing.
1563  Used with the `-E' option.
1564 \layout List
1565 \labelwidthstring 00.00.0000
1566
1567
1568 \series bold 
1569 -dD
1570 \series default 
1571  Tell the preprocessor to pass all macro definitions into the output, in
1572  their proper sequence in the rest of the output.
1573 \layout List
1574 \labelwidthstring 00.00.0000
1575
1576
1577 \series bold 
1578 -dN
1579 \size large 
1580 \bar under 
1581  
1582 \series default 
1583 \size default 
1584 \bar default 
1585 Like `-dD' except that the macro arguments and contents are omitted.
1586  Only `#define name' is included in the output.
1587 \layout Subsubsection
1588
1589 Linker Options
1590 \layout List
1591 \labelwidthstring 00.00.0000
1592
1593
1594 \series bold 
1595 -L\SpecialChar ~
1596 --lib-path
1597 \bar under 
1598  
1599 \series default 
1600 \bar default 
1601 <absolute path to additional libraries> This option is passed to the linkage
1602  editor's additional libraries search path.
1603  The path name must be absolute.
1604  Additional library files may be specified in the command line.
1605  See section Compiling programs for more details.
1606 \layout List
1607 \labelwidthstring 00.00.0000
1608
1609
1610 \series bold 
1611 --xram-loc
1612 \series default 
1613 <Value> The start location of the external ram, default value is 0.
1614  The value entered can be in Hexadecimal or Decimal format, e.g.: --xram-loc
1615  0x8000 or --xram-loc 32768.
1616 \layout List
1617 \labelwidthstring 00.00.0000
1618
1619
1620 \series bold 
1621 --code-loc
1622 \series default 
1623 <Value> The start location of the code segment, default value 0.
1624  Note when this option is used the interrupt vector table is also relocated
1625  to the given address.
1626  The value entered can be in Hexadecimal or Decimal format, e.g.: --code-loc
1627  0x8000 or --code-loc 32768.
1628 \layout List
1629 \labelwidthstring 00.00.0000
1630
1631
1632 \series bold 
1633 --stack-loc
1634 \series default 
1635 <Value> The initial value of the stack pointer.
1636  The default value of the stack pointer is 0x07 if only register bank 0
1637  is used, if other register banks are used then the stack pointer is initialized
1638  to the location above the highest register bank used.
1639  eg.
1640  if register banks 1 & 2 are used the stack pointer will default to location
1641  0x18.
1642  The value entered can be in Hexadecimal or Decimal format, eg.
1643  --stack-loc 0x20 or --stack-loc 32.
1644  If all four register banks are used the stack will be placed after the
1645  data segment (equivalent to --stack-after-data)
1646 \layout List
1647 \labelwidthstring 00.00.0000
1648
1649
1650 \series bold 
1651 --stack-after-data
1652 \series default 
1653  This option will cause the stack to be located in the internal ram after
1654  the data segment.
1655 \layout List
1656 \labelwidthstring 00.00.0000
1657
1658
1659 \series bold 
1660 --data-loc
1661 \series default 
1662 <Value> The start location of the internal ram data segment, the default
1663  value is 0x30.The value entered can be in Hexadecimal or Decimal format,
1664  eg.
1665  --data-loc 0x20 or --data-loc 32.
1666 \layout List
1667 \labelwidthstring 00.00.0000
1668
1669
1670 \series bold 
1671 --idata-loc
1672 \series default 
1673 <Value> The start location of the indirectly addressable internal ram, default
1674  value is 0x80.
1675  The value entered can be in Hexadecimal or Decimal format, eg.
1676  --idata-loc 0x88 or --idata-loc 136.
1677 \layout List
1678 \labelwidthstring 00.00.0000
1679
1680
1681 \series bold 
1682 --out-fmt-ihx
1683 \bar under 
1684  
1685 \series default 
1686 \bar default 
1687 The linker output (final object code) is in Intel Hex format.
1688  (This is the default option).
1689 \layout List
1690 \labelwidthstring 00.00.0000
1691
1692
1693 \series bold 
1694 --out-fmt-s19
1695 \bar under 
1696  
1697 \series default 
1698 \bar default 
1699 The linker output (final object code) is in Motorola S19 format.
1700 \layout Subsubsection
1701
1702 MCS51 Options
1703 \layout List
1704 \labelwidthstring 00.00.0000
1705
1706
1707 \series bold 
1708 --model-large
1709 \series default 
1710  Generate code for Large model programs see section Memory Models for more
1711  details.
1712  If this option is used all source files in the project should be compiled
1713  with this option.
1714  In addition the standard library routines are compiled with small model,
1715  they will need to be recompiled.
1716 \layout List
1717 \labelwidthstring 00.00.0000
1718
1719
1720 \series bold 
1721 --model-small
1722 \series default 
1723 \size large 
1724 \emph on 
1725  
1726 \size default 
1727 \emph default 
1728 Generate code for Small Model programs see section Memory Models for more
1729  details.
1730  This is the default model.
1731 \layout Subsubsection
1732
1733 DS390 Options
1734 \layout List
1735 \labelwidthstring 00.00.0000
1736
1737
1738 \series bold 
1739 --model-flat24
1740 \series default 
1741 \size large 
1742 \emph on 
1743  
1744 \size default 
1745 \emph default 
1746 Generate 24-bit flat mode code.
1747  This is the one and only that the ds390 code generator supports right now
1748  and is default when using 
1749 \emph on 
1750 -mds390
1751 \emph default 
1752 .
1753  See section Memory Models for more details.
1754 \layout List
1755 \labelwidthstring 00.00.0000
1756
1757
1758 \series bold 
1759 --stack-10bit
1760 \series default 
1761  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
1762  This is the one and only that the ds390 code generator supports right now
1763  and is default when using 
1764 \emph on 
1765 -mds390
1766 \emph default 
1767 .
1768  In this mode, the stack is located in the lower 1K of the internal RAM,
1769  which is mapped to 0x400000.
1770  Note that the support is incomplete, since it still uses a single byte
1771  as the stack pointer.
1772  This means that only the lower 256 bytes of the potential 1K stack space
1773  will actually be used.
1774  However, this does allow you to reclaim the precious 256 bytes of low RAM
1775  for use for the DATA and IDATA segments.
1776  The compiler will not generate any code to put the processor into 10 bit
1777  stack mode.
1778  It is important to ensure that the processor is in this mode before calling
1779  any re-entrant functions compiled with this option.
1780  In principle, this should work with the 
1781 \emph on 
1782 --stack-auto
1783 \emph default 
1784  option, but that has not been tested.
1785  It is incompatible with the 
1786 \emph on 
1787 --xstack
1788 \emph default 
1789  option.
1790  It also only makes sense if the processor is in 24 bit contiguous addressing
1791  mode (see the 
1792 \emph on 
1793 --model-flat24 option
1794 \emph default 
1795 ).
1796 \layout Subsubsection
1797
1798 Optimization Options
1799 \layout List
1800 \labelwidthstring 00.00.0000
1801
1802
1803 \series bold 
1804 --nogcse
1805 \series default 
1806  Will not do global subexpression elimination, this option may be used when
1807  the compiler creates undesirably large stack/data spaces to store compiler
1808  temporaries.
1809  A warning message will be generated when this happens and the compiler
1810  will indicate the number of extra bytes it allocated.
1811  It recommended that this option NOT be used, #pragma\SpecialChar ~
1812 NOGCSE can be used
1813  to turn off global subexpression elimination for a given function only.
1814 \layout List
1815 \labelwidthstring 00.00.0000
1816
1817
1818 \series bold 
1819 --noinvariant
1820 \series default 
1821  Will not do loop invariant optimizations, this may be turned off for reasons
1822  explained for the previous option.
1823  For more details of loop optimizations performed see section Loop Invariants.It
1824  recommended that this option NOT be used, #pragma\SpecialChar ~
1825 NOINVARIANT can be used
1826  to turn off invariant optimizations for a given function only.
1827 \layout List
1828 \labelwidthstring 00.00.0000
1829
1830
1831 \series bold 
1832 --noinduction
1833 \series default 
1834  Will not do loop induction optimizations, see section strength reduction
1835  for more details.It is recommended that this option is NOT used, #pragma\SpecialChar ~
1836 NOINDUCT
1837 ION can be used to turn off induction optimizations for a given function
1838  only.
1839 \layout List
1840 \labelwidthstring 00.00.0000
1841
1842
1843 \series bold 
1844 --nojtbound
1845 \size large 
1846 \bar under 
1847  
1848 \series default 
1849 \size default 
1850 \bar default 
1851  Will not generate boundary condition check when switch statements are implement
1852 ed using jump-tables.
1853  See section Switch Statements for more details.
1854  It is recommended that this option is NOT used, #pragma\SpecialChar ~
1855 NOJTBOUND can be
1856  used to turn off boundary checking for jump tables for a given function
1857  only.
1858 \layout List
1859 \labelwidthstring 00.00.0000
1860
1861
1862 \series bold 
1863 --noloopreverse
1864 \series default 
1865 \size large 
1866  
1867 \size default 
1868 Will not do loop reversal optimization.
1869 \layout Subsubsection
1870
1871 Other Options
1872 \layout List
1873 \labelwidthstring 00.00.0000
1874
1875
1876 \series bold 
1877 -c\SpecialChar ~
1878 --compile-only
1879 \series default 
1880  will compile and assemble the source, but will not call the linkage editor.
1881 \layout List
1882 \labelwidthstring 00.00.0000
1883
1884
1885 \series bold 
1886 -E
1887 \series default 
1888  Run only the C preprocessor.
1889  Preprocess all the C source files specified and output the results to standard
1890  output.
1891 \layout List
1892 \labelwidthstring 00.00.0000
1893
1894
1895 \series bold 
1896 --stack-auto
1897 \series default 
1898 \size large 
1899 \emph on 
1900  
1901 \size default 
1902 \emph default 
1903 All functions in the source file will be compiled as 
1904 \emph on 
1905 reentrant
1906 \emph default 
1907 , i.e.
1908  the parameters and local variables will be allocated on the stack.
1909  see section Parameters and Local Variables for more details.
1910  If this option is used all source files in the project should be compiled
1911  with this option.
1912  
1913 \layout List
1914 \labelwidthstring 00.00.0000
1915
1916
1917 \series bold 
1918 --xstack
1919 \series default 
1920  Uses a pseudo stack in the first 256 bytes in the external ram for allocating
1921  variables and passing parameters.
1922  See section on external stack for more details.
1923 \layout List
1924 \labelwidthstring 00.00.0000
1925
1926
1927 \series bold 
1928 --callee-saves function1[,function2][,function3]....
1929
1930 \series default 
1931  The compiler by default uses a caller saves convention for register saving
1932  across function calls, however this can cause unneccessary register pushing
1933  & popping when calling small functions from larger functions.
1934  This option can be used to switch the register saving convention for the
1935  function names specified.
1936  The compiler will not save registers when calling these functions, no extra
1937  code will be generated at the entry & exit for these functions to save
1938  & restore the registers used by these functions, this can SUBSTANTIALLY
1939  reduce code & improve run time performance of the generated code.
1940  In the future the compiler (with interprocedural analysis) will be able
1941  to determine the appropriate scheme to use for each function call.
1942  DO NOT use this option for built-in functions such as _muluint..., if this
1943  option is used for a library function the appropriate library function
1944  needs to be recompiled with the same option.
1945  If the project consists of multiple source files then all the source file
1946  should be compiled with the same --callee-saves option string.
1947  Also see #pragma\SpecialChar ~
1948 CALLEE-SAVES.
1949 \layout List
1950 \labelwidthstring 00.00.0000
1951
1952
1953 \series bold 
1954 --debug
1955 \bar under 
1956  
1957 \series default 
1958 \bar default 
1959 When this option is used the compiler will generate debug information, that
1960  can be used with the SDCDB.
1961  The debug information is collected in a file with .cdb extension.
1962  For more information see documentation for SDCDB.
1963 \layout List
1964 \labelwidthstring 00.00.0000
1965
1966
1967 \series bold 
1968 \emph on 
1969 --regextend
1970 \bar under 
1971  
1972 \series default 
1973 \bar default 
1974  This option is obsolete and isn't supported anymore.
1975 \layout List
1976 \labelwidthstring 00.00.0000
1977
1978
1979 \series bold 
1980 \emph on 
1981 --noregparms
1982 \series default 
1983  This option is obsolete and isn't supported anymore.
1984 \layout List
1985 \labelwidthstring 00.00.0000
1986
1987
1988 \series bold 
1989 --peep-file
1990 \series default 
1991 <filename> This option can be used to use additional rules to be used by
1992  the peep hole optimizer.
1993  See section Peep Hole optimizations for details on how to write these rules.
1994 \layout List
1995 \labelwidthstring 00.00.0000
1996
1997
1998 \series bold 
1999 -S
2000 \size large 
2001 \bar under 
2002  
2003 \series default 
2004 \size default 
2005 \bar default 
2006 Stop after the stage of compilation proper; do not assemble.
2007  The output is an assembler code file for the input file specified.
2008 \layout List
2009 \labelwidthstring 00.00.0000
2010
2011
2012 \series bold 
2013 -Wa_asmOption[,asmOption]
2014 \series default 
2015 ...
2016  Pass the asmOption to the assembler.
2017 \layout List
2018 \labelwidthstring 00.00.0000
2019
2020
2021 \series bold 
2022 -Wl_linkOption[,linkOption]
2023 \series default 
2024 ...
2025  Pass the linkOption to the linker.
2026 \layout List
2027 \labelwidthstring 00.00.0000
2028
2029
2030 \series bold 
2031 --int-long-reent
2032 \series default 
2033 \size large 
2034  
2035 \size default 
2036  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
2037  Note by default these libraries are compiled as non-reentrant.
2038  See section Installation for more details.
2039 \layout List
2040 \labelwidthstring 00.00.0000
2041
2042
2043 \series bold 
2044 --cyclomatic
2045 \bar under 
2046  
2047 \series default 
2048 \bar default 
2049 This option will cause the compiler to generate an information message for
2050  each function in the source file.
2051  The message contains some 
2052 \emph on 
2053 important
2054 \emph default 
2055  information about the function.
2056  The number of edges and nodes the compiler detected in the control flow
2057  graph of the function, and most importantly the 
2058 \emph on 
2059 cyclomatic complexity
2060 \emph default 
2061  see section on Cyclomatic Complexity for more details.
2062 \layout List
2063 \labelwidthstring 00.00.0000
2064
2065
2066 \series bold 
2067 --float-reent
2068 \bar under 
2069  
2070 \series default 
2071 \bar default 
2072  Floating point library is compiled as reentrant.See section Installation
2073  for more details.
2074 \layout List
2075 \labelwidthstring 00.00.0000
2076
2077
2078 \series bold 
2079 --nooverlay
2080 \series default 
2081   The compiler will not overlay parameters and local variables of any function,
2082  see section Parameters and local variables for more details.
2083 \layout List
2084 \labelwidthstring 00.00.0000
2085
2086
2087 \series bold 
2088 --main-return
2089 \series default 
2090  This option can be used when the code generated is called by a monitor
2091  program.
2092  The compiler will generate a 'ret' upon return from the 'main' function.
2093  The default option is to lock up i.e.
2094  generate a 'ljmp '.
2095 \layout List
2096 \labelwidthstring 00.00.0000
2097
2098
2099 \series bold 
2100 --no-peep
2101 \series default 
2102   Disable peep-hole optimization.
2103 \layout List
2104 \labelwidthstring 00.00.0000
2105
2106
2107 \series bold 
2108 --peep-asm
2109 \series default 
2110   Pass the inline assembler code through the peep hole optimizer.
2111  This can cause unexpected changes to inline assembler code, please go through
2112  the peephole optimizer rules defined in the source file tree '<target>/peeph.def
2113 ' before using this option.
2114 \layout List
2115 \labelwidthstring 00.00.0000
2116
2117
2118 \series bold 
2119 --iram-size
2120 \series default 
2121 <Value> Causes the linker to check if the interal ram usage is within limits
2122  of the given value.
2123 \layout List
2124 \labelwidthstring 00.00.0000
2125
2126
2127 \series bold 
2128 --nostdincl
2129 \series default 
2130  This will prevent the compiler from passing on the default include path
2131  to the preprocessor.
2132 \layout List
2133 \labelwidthstring 00.00.0000
2134
2135
2136 \series bold 
2137 --nostdlib
2138 \series default 
2139  This will prevent the compiler from passing on the default library path
2140  to the linker.
2141 \layout List
2142 \labelwidthstring 00.00.0000
2143
2144
2145 \series bold 
2146 --verbose
2147 \series default 
2148  Shows the various actions the compiler is performing.
2149 \layout List
2150 \labelwidthstring 00.00.0000
2151
2152
2153 \series bold 
2154 -V
2155 \series default 
2156  Shows the actual commands the compiler is executing.
2157 \layout Subsubsection
2158
2159 Intermediate Dump Options
2160 \layout Standard
2161
2162 The following options are provided for the purpose of retargetting and debugging
2163  the compiler.
2164  These provided a means to dump the intermediate code (iCode) generated
2165  by the compiler in human readable form at various stages of the compilation
2166  process.
2167  
2168 \layout List
2169 \labelwidthstring 00.00.0000
2170
2171
2172 \series bold 
2173 --dumpraw
2174 \series default 
2175  This option will cause the compiler to dump the intermediate code into
2176  a file of named 
2177 \emph on 
2178 <source filename>.dumpraw
2179 \emph default 
2180  just after the intermediate code has been generated for a function, i.e.
2181  before any optimizations are done.
2182  The basic blocks at this stage ordered in the depth first number, so they
2183  may not be in sequence of execution.
2184 \layout List
2185 \labelwidthstring 00.00.0000
2186
2187
2188 \series bold 
2189 --dumpgcse
2190 \series default 
2191  Will create a dump of iCode's, after global subexpression elimination,
2192  into a file named 
2193 \emph on 
2194 <source filename>.dumpgcse.
2195 \layout List
2196 \labelwidthstring 00.00.0000
2197
2198
2199 \series bold 
2200 --dumpdeadcode
2201 \series default 
2202  Will create a dump of iCode's, after deadcode elimination, into a file
2203  named 
2204 \emph on 
2205 <source filename>.dumpdeadcode.
2206 \layout List
2207 \labelwidthstring 00.00.0000
2208
2209
2210 \series bold 
2211 --dumploop
2212 \series default 
2213 \size large 
2214  
2215 \size default 
2216 Will create a dump of iCode's, after loop optimizations, into a file named
2217  
2218 \emph on 
2219 <source filename>.dumploop.
2220 \layout List
2221 \labelwidthstring 00.00.0000
2222
2223
2224 \series bold 
2225 --dumprange
2226 \series default 
2227 \size large 
2228  
2229 \size default 
2230 Will create a dump of iCode's, after live range analysis, into a file named
2231  
2232 \emph on 
2233 <source filename>.dumprange.
2234 \layout List
2235 \labelwidthstring 00.00.0000
2236
2237
2238 \series bold 
2239 --dumlrange
2240 \series default 
2241  Will dump the life ranges for all symbols.
2242 \layout List
2243 \labelwidthstring 00.00.0000
2244
2245
2246 \series bold 
2247 --dumpregassign
2248 \bar under 
2249  
2250 \series default 
2251 \bar default 
2252 Will create a dump of iCode's, after register assignment, into a file named
2253  
2254 \emph on 
2255 <source filename>.dumprassgn.
2256 \layout List
2257 \labelwidthstring 00.00.0000
2258
2259
2260 \series bold 
2261 --dumplrange
2262 \series default 
2263  Will create a dump of the live ranges of iTemp's
2264 \layout List
2265 \labelwidthstring 00.00.0000
2266
2267
2268 \series bold 
2269 --dumpall
2270 \size large 
2271 \bar under 
2272  
2273 \series default 
2274 \size default 
2275 \bar default 
2276 Will cause all the above mentioned dumps to be created.
2277 \layout Subsection
2278
2279 MCS51/DS390 Storage Class Language Extensions
2280 \layout Standard
2281
2282 In addition to the ANSI storage classes SDCC allows the following MCS51
2283  specific storage classes.
2284 \layout Subsubsection
2285
2286 xdata
2287 \layout Standard
2288
2289 Variables declared with this storage class will be placed in the extern
2290  RAM.
2291  This is the 
2292 \series bold 
2293 default
2294 \series default 
2295  storage class for Large Memory model, e.g.:
2296 \newline 
2297
2298 \newline 
2299
2300 \family typewriter 
2301 xdata unsigned char xduc;
2302 \layout Subsubsection
2303
2304 data
2305 \layout Standard
2306
2307 This is the 
2308 \series bold 
2309 default
2310 \series default 
2311  storage class for Small Memory model.
2312  Variables declared with this storage class will be allocated in the internal
2313  RAM, e.g.:
2314 \newline 
2315
2316 \newline 
2317
2318 \family typewriter 
2319 data int iramdata;
2320 \layout Subsubsection
2321
2322 idata
2323 \layout Standard
2324
2325 Variables declared with this storage class will be allocated into the indirectly
2326  addressable portion of the internal ram of a 8051, e.g.:
2327 \newline 
2328
2329 \newline 
2330
2331 \family typewriter 
2332 idata int idi;
2333 \layout Subsubsection
2334
2335 bit
2336 \layout Standard
2337
2338 This is a data-type and a storage class specifier.
2339  When a variable is declared as a bit, it is allocated into the bit addressable
2340  memory of 8051, e.g.:
2341 \newline 
2342
2343 \newline 
2344
2345 \family typewriter 
2346 bit iFlag;
2347 \layout Subsubsection
2348
2349 sfr / sbit
2350 \layout Standard
2351
2352 Like the bit keyword, 
2353 \emph on 
2354 sfr / sbit 
2355 \emph default 
2356 signifies both a data-type and storage class, they are used to describe
2357  the special function registers and special bit variables of a 8051, eg:
2358 \newline 
2359
2360 \newline 
2361
2362 \family typewriter 
2363 sfr at 0x80 P0; /* special function register P0 at location 0x80 */
2364 \newline 
2365 sbit at 0xd7 CY; /* CY (Carry Flag) */
2366 \layout Subsection
2367
2368 Pointers
2369 \layout Standard
2370
2371 SDCC allows (via language extensions) pointers to explicitly point to any
2372  of the memory spaces of the 8051.
2373  In addition to the explicit pointers, the compiler also allows a 
2374 \emph on 
2375 _generic
2376 \emph default 
2377  class of pointers which can be used to point to any of the memory spaces.
2378 \newline 
2379
2380 \newline 
2381 Pointer declaration examples:
2382 \newline 
2383
2384 \size small 
2385
2386 \newline 
2387
2388 \family typewriter 
2389 \size default 
2390 /* pointer physically in xternal ram pointing to object in internal ram
2391  */ 
2392 \newline 
2393 data unsigned char * xdata p;
2394 \newline 
2395
2396 \newline 
2397 /* pointer physically in code rom pointing to data in xdata space */ 
2398 \newline 
2399 xdata unsigned char * code p;
2400 \newline 
2401
2402 \newline 
2403 /* pointer physically in code space pointing to data in code space */ 
2404 \newline 
2405 code unsigned char * code p;
2406 \newline 
2407
2408 \newline 
2409 /* the folowing is a generic pointer physically located in xdata space */
2410 \newline 
2411 char * xdata p;
2412 \family default 
2413 \size small 
2414
2415 \newline 
2416
2417 \newline 
2418
2419 \size default 
2420 Well you get the idea.
2421  
2422 \newline 
2423
2424 \newline 
2425
2426 \emph on 
2427 For compatibility with the previous version of the compiler, the following
2428  syntax for pointer declaration is still supported but will disappear int
2429  the near future.
2430  
2431 \newline 
2432
2433 \newline 
2434
2435 \family typewriter 
2436 unsigned char _xdata *ucxdp; /* pointer to data in external ram */ 
2437 \newline 
2438 unsigned char _data \SpecialChar ~
2439 *ucdp ; /* pointer to data in internal ram */ 
2440 \newline 
2441 unsigned char _code \SpecialChar ~
2442 *uccp ; /* pointer to data in R/O code space */
2443 \newline 
2444 unsigned char _idata *uccp; \SpecialChar ~
2445 /* pointer to upper 128 bytes of ram */
2446 \family default 
2447 \size small 
2448 \emph default 
2449
2450 \newline 
2451
2452 \newline 
2453
2454 \size default 
2455 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
2456 \emph on 
2457 generic
2458 \emph default 
2459  pointers.
2460  These type of pointers can also to be explicitly declared.
2461 \newline 
2462
2463 \newline 
2464
2465 \family typewriter 
2466 unsigned char _generic *ucgp;
2467 \family default 
2468 \size small 
2469
2470 \newline 
2471
2472 \newline 
2473
2474 \size default 
2475 The highest order byte of the 
2476 \emph on 
2477 generic
2478 \emph default 
2479  pointers contains the data space information.
2480  Assembler support routines are called whenever data is stored or retrieved
2481  using 
2482 \emph on 
2483 generic
2484 \emph default 
2485  pointers.
2486  These are useful for developing reusable library routines.
2487  Explicitly specifying the pointer type will generate the most efficient
2488  code.
2489  Pointers declared using a mixture of OLD and NEW style could have unpredictable
2490  results.
2491 \layout Subsection
2492
2493 Parameters & Local Variables
2494 \layout Standard
2495
2496 Automatic (local) variables and parameters to functions can either be placed
2497  on the stack or in data-space.
2498  The default action of the compiler is to place these variables in the internal
2499  RAM (for small model) or external RAM (for Large model).
2500  This in fact makes them 
2501 \emph on 
2502 static
2503 \emph default 
2504  so by default functions are non-reentrant.
2505 \layout Standard
2506
2507 They can be placed on the stack either by using the
2508 \emph on 
2509  --stack-auto
2510 \emph default 
2511  compiler option or by using the 
2512 \emph on 
2513 reentrant
2514 \emph default 
2515  keyword in the function declaration, e.g.:
2516 \newline 
2517
2518 \size small 
2519
2520 \newline 
2521
2522 \family typewriter 
2523 \size default 
2524 unsigned char foo(char i) reentrant 
2525 \newline 
2526
2527 \newline 
2528 ...
2529  
2530 \newline 
2531 }
2532 \newline 
2533
2534 \family default 
2535
2536 \newline 
2537 Since stack space on 8051 is limited, the 
2538 \emph on 
2539 reentrant 
2540 \emph default 
2541 keyword or the
2542 \emph on 
2543  --stack-auto
2544 \emph default 
2545  option should be used sparingly.
2546  Note that the reentrant keyword just means that the parameters & local
2547  variables will be allocated to the stack, it 
2548 \emph on 
2549 does not
2550 \emph default 
2551  mean that the function is register bank independent.
2552 \newline 
2553
2554 \newline 
2555 Local variables can be assigned storage classes and absolute addresses,
2556  e.g.: 
2557 \newline 
2558
2559 \newline 
2560
2561 \family typewriter 
2562 unsigned char foo() {
2563 \newline 
2564 \SpecialChar ~
2565 \SpecialChar ~
2566 \SpecialChar ~
2567 \SpecialChar ~
2568 xdata unsigned char i;
2569 \newline 
2570 \SpecialChar ~
2571 \SpecialChar ~
2572 \SpecialChar ~
2573 \SpecialChar ~
2574 bit bvar;
2575 \newline 
2576 \SpecialChar ~
2577 \SpecialChar ~
2578 \SpecialChar ~
2579 \SpecialChar ~
2580 data at 0x31 unsiged char j;
2581 \newline 
2582 \SpecialChar ~
2583 \SpecialChar ~
2584 \SpecialChar ~
2585 \SpecialChar ~
2586 ...
2587  
2588 \newline 
2589 }
2590 \newline 
2591
2592 \newline 
2593
2594 \family default 
2595 In the above example the variable 
2596 \emph on 
2597 i
2598 \emph default 
2599  will be allocated in the external ram, 
2600 \emph on 
2601 bvar
2602 \emph default 
2603  in bit addressable space and
2604 \emph on 
2605  j
2606 \emph default 
2607  in internal ram.
2608  When compiled with 
2609 \emph on 
2610 --stack-auto
2611 \emph default 
2612  or when a function is declared as 
2613 \emph on 
2614 reentrant
2615 \emph default 
2616  this can only be done for static variables.
2617 \layout Standard
2618
2619 Parameters however are not allowed any storage class, (storage classes for
2620  parameters will be ignored), their allocation is governed by the memory
2621  model in use, and the reentrancy options.
2622 \layout Subsection
2623
2624 Overlaying
2625 \layout Standard
2626
2627 For non-reentrant functions SDCC will try to reduce internal ram space usage
2628  by overlaying parameters and local variables of a function (if possible).
2629  Parameters and local variables of a function will be allocated to an overlayabl
2630 e segment if the function has 
2631 \emph on 
2632 no other function calls and the function is non-reentrant and the memory
2633  model is small.
2634
2635 \emph default 
2636  If an explicit storage class is specified for a local variable, it will
2637  NOT be overlayed.
2638 \layout Standard
2639
2640 Note that the compiler (not the linkage editor) makes the decision for overlayin
2641 g the data items.
2642  Functions that are called from an interrupt service routine should be preceded
2643  by a #pragma\SpecialChar ~
2644 NOOVERLAY if they are not reentrant.
2645 \layout Standard
2646
2647 Also note that the compiler does not do any processing of inline assembler
2648  code, so the compiler might incorrectly assign local variables and parameters
2649  of a function into the overlay segment if the inline assembler code calls
2650  other c-functions that might use the overlay.
2651  In that case the #pragma\SpecialChar ~
2652 NOOVERLAY should be used.
2653 \layout Standard
2654
2655 Parameters and Local variables of functions that contain 16 or 32 bit multiplica
2656 tion or division will NOT be overlayed since these are implemented using
2657  external functions, e.g.:
2658 \newline 
2659
2660 \newline 
2661
2662 \family typewriter 
2663 #pragma SAVE 
2664 \newline 
2665 #pragma NOOVERLAY 
2666 \newline 
2667 void set_error(unsigned char errcd) 
2668 \newline 
2669 {
2670 \newline 
2671 \SpecialChar ~
2672 \SpecialChar ~
2673 \SpecialChar ~
2674 \SpecialChar ~
2675 P3 = errcd;
2676 \newline 
2677
2678 \newline 
2679 #pragma RESTORE 
2680 \newline 
2681
2682 \newline 
2683 void some_isr () interrupt 2 using 1 
2684 \newline 
2685 {
2686 \newline 
2687 \SpecialChar ~
2688 \SpecialChar ~
2689 \SpecialChar ~
2690 \SpecialChar ~
2691 ...
2692 \newline 
2693 \SpecialChar ~
2694 \SpecialChar ~
2695 \SpecialChar ~
2696 \SpecialChar ~
2697 set_error(10);
2698 \newline 
2699 \SpecialChar ~
2700 \SpecialChar ~
2701 \SpecialChar ~
2702 \SpecialChar ~
2703 ...
2704  
2705 \newline 
2706 }
2707 \newline 
2708
2709 \newline 
2710
2711 \family default 
2712 In the above example the parameter 
2713 \emph on 
2714 errcd
2715 \emph default 
2716  for the function 
2717 \emph on 
2718 set_error
2719 \emph default 
2720  would be assigned to the overlayable segment if the #pragma\SpecialChar ~
2721 NOOVERLAY was
2722  not present, this could cause unpredictable runtime behavior when called
2723  from an ISR.
2724  The #pragma\SpecialChar ~
2725 NOOVERLAY ensures that the parameters and local variables for
2726  the function are NOT overlayed.
2727 \layout Subsection
2728
2729 Interrupt Service Routines
2730 \layout Standard
2731
2732 SDCC allows interrupt service routines to be coded in C, with some extended
2733  keywords.
2734 \newline 
2735
2736 \newline 
2737
2738 \family typewriter 
2739 void timer_isr (void) interrupt 2 using 1 
2740 \newline 
2741
2742 \newline 
2743 ..
2744  
2745 \newline 
2746 }
2747 \newline 
2748
2749 \newline 
2750
2751 \family default 
2752 The number following the 
2753 \emph on 
2754 interrupt
2755 \emph default 
2756  keyword is the interrupt number this routine will service.
2757  The compiler will insert a call to this routine in the interrupt vector
2758  table for the interrupt number specified.
2759  The 
2760 \emph on 
2761 using
2762 \emph default 
2763  keyword is used to tell the compiler to use the specified register bank
2764  (8051 specific) when generating code for this function.
2765  Note that when some function is called from an interrupt service routine
2766  it should be preceded by a #pragma\SpecialChar ~
2767 NOOVERLAY if it is not reentrant.
2768  A special note here, int (16 bit) and long (32 bit) integer division, multiplic
2769 ation & modulus operations are implemented using external support routines
2770  developed in ANSI-C, if an interrupt service routine needs to do any of
2771  these operations then the support routines (as mentioned in a following
2772  section) will have to be recompiled using the
2773 \emph on 
2774  --stack-auto
2775 \emph default 
2776  option and the source file will need to be compiled using the 
2777 \emph on 
2778 --int-long-ren
2779 \emph default 
2780 t compiler option.
2781 \layout Standard
2782
2783 If you have multiple source files in your project, interrupt service routines
2784  can be present in any of them, but a prototype of the isr MUST be present
2785  or included in the file that contains the function 
2786 \emph on 
2787 main
2788 \emph default 
2789 .
2790 \layout Standard
2791
2792 Interrupt Numbers and the corresponding address & descriptions for the Standard
2793  8051 are listed below.
2794  SDCC will automatically adjust the interrupt vector table to the maximum
2795  interrupt number specified.
2796 \newline 
2797
2798 \layout Standard
2799
2800
2801 \begin_inset  Tabular
2802 <lyxtabular version="2" rows="6" columns="3">
2803 <features rotate="false" islongtable="false" endhead="0" endfirsthead="0" endfoot="0" endlastfoot="0">
2804 <column alignment="center" valignment="top" leftline="true" rightline="false" width="" special="">
2805 <column alignment="center" valignment="top" leftline="true" rightline="false" width="" special="">
2806 <column alignment="center" valignment="top" leftline="true" rightline="true" width="" special="">
2807 <row topline="true" bottomline="true" newpage="false">
2808 <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special="">
2809 \begin_inset Text
2810
2811 \layout Standard
2812
2813 Interrupt #
2814 \end_inset 
2815 </cell>
2816 <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special="">
2817 \begin_inset Text
2818
2819 \layout Standard
2820
2821 Description
2822 \end_inset 
2823 </cell>
2824 <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="true" rotate="false" usebox="none" width="" special="">
2825 \begin_inset Text
2826
2827 \layout Standard
2828
2829 Vector Address
2830 \end_inset 
2831 </cell>
2832 </row>
2833 <row topline="true" bottomline="false" newpage="false">
2834 <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special="">
2835 \begin_inset Text
2836
2837 \layout Standard
2838
2839 0
2840 \end_inset 
2841 </cell>
2842 <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special="">
2843 \begin_inset Text
2844
2845 \layout Standard
2846
2847 External 0
2848 \end_inset 
2849 </cell>
2850 <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="true" rotate="false" usebox="none" width="" special="">
2851 \begin_inset Text
2852
2853 \layout Standard
2854
2855 0x0003
2856 \end_inset 
2857 </cell>
2858 </row>
2859 <row topline="true" bottomline="false" newpage="false">
2860 <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special="">
2861 \begin_inset Text
2862
2863 \layout Standard
2864
2865 1
2866 \end_inset 
2867 </cell>
2868 <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special="">
2869 \begin_inset Text
2870
2871 \layout Standard
2872
2873 Timer 0
2874 \end_inset 
2875 </cell>
2876 <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="true" rotate="false" usebox="none" width="" special="">
2877 \begin_inset Text
2878
2879 \layout Standard
2880
2881 0x000B
2882 \end_inset 
2883 </cell>
2884 </row>
2885 <row topline="true" bottomline="false" newpage="false">
2886 <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special="">
2887 \begin_inset Text
2888
2889 \layout Standard
2890
2891 2
2892 \end_inset 
2893 </cell>
2894 <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special="">
2895 \begin_inset Text
2896
2897 \layout Standard
2898
2899 External 1
2900 \end_inset 
2901 </cell>
2902 <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="true" rotate="false" usebox="none" width="" special="">
2903 \begin_inset Text
2904
2905 \layout Standard
2906
2907 0x0013
2908 \end_inset 
2909 </cell>
2910 </row>
2911 <row topline="true" bottomline="false" newpage="false">
2912 <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special="">
2913 \begin_inset Text
2914
2915 \layout Standard
2916
2917 3
2918 \end_inset 
2919 </cell>
2920 <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special="">
2921 \begin_inset Text
2922
2923 \layout Standard
2924
2925 Timer 1
2926 \end_inset 
2927 </cell>
2928 <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="true" rotate="false" usebox="none" width="" special="">
2929 \begin_inset Text
2930
2931 \layout Standard
2932
2933 0x001B
2934 \end_inset 
2935 </cell>
2936 </row>
2937 <row topline="true" bottomline="true" newpage="false">
2938 <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special="">
2939 \begin_inset Text
2940
2941 \layout Standard
2942
2943 4
2944 \end_inset 
2945 </cell>
2946 <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="false" rotate="false" usebox="none" width="" special="">
2947 \begin_inset Text
2948
2949 \layout Standard
2950
2951 Serial
2952 \end_inset 
2953 </cell>
2954 <cell multicolumn="0" alignment="center" valignment="top" topline="true" bottomline="false" leftline="true" rightline="true" rotate="false" usebox="none" width="" special="">
2955 \begin_inset Text
2956
2957 \layout Standard
2958
2959 0x0023
2960 \end_inset 
2961 </cell>
2962 </row>
2963 </lyxtabular>
2964
2965 \end_inset 
2966
2967
2968 \newline 
2969
2970 \newline 
2971 If the interrupt service routine is defined without 
2972 \emph on 
2973 using
2974 \emph default 
2975  a register bank or with register bank 0 (using 0), the compiler will save
2976  the registers used by itself on the stack upon entry and restore them at
2977  exit, however if such an interrupt service routine calls another function
2978  then the entire register bank will be saved on the stack.
2979  This scheme may be advantageous for small interrupt service routines which
2980  have low register usage.
2981 \layout Standard
2982
2983 If the interrupt service routine is defined to be using a specific register
2984  bank then only 
2985 \emph on 
2986 a, b & dptr
2987 \emph default 
2988  are save and restored, if such an interrupt service routine calls another
2989  function (using another register bank) then the entire register bank of
2990  the called function will be saved on the stack.
2991  This scheme is recommended for larger interrupt service routines.
2992 \layout Standard
2993
2994 Calling other functions from an interrupt service routine is not recommended,
2995  avoid it if possible.
2996 \newline 
2997
2998 \newline 
2999 Also see the _naked modifier.
3000 \layout Subsection
3001
3002 Critical Functions
3003 \layout Standard
3004
3005 A special keyword may be associated with a function declaring it as 
3006 \emph on 
3007 critical
3008 \emph default 
3009 .
3010  SDCC will generate code to disable all interrupts upon entry to a critical
3011  function and enable them back before returning.
3012  Note that nesting critical functions may cause unpredictable results.
3013 \newline 
3014
3015 \size small 
3016
3017 \newline 
3018
3019 \family typewriter 
3020 \size default 
3021 int foo () critical 
3022 \newline 
3023
3024 \newline 
3025 ...
3026  
3027 \newline 
3028 ...
3029  
3030 \newline 
3031 }
3032 \newline 
3033
3034 \family default 
3035
3036 \newline 
3037 The critical attribute maybe used with other attributes like 
3038 \emph on 
3039 reentrant.
3040 \layout Subsection
3041
3042 Naked Functions
3043 \layout Standard
3044
3045 A special keyword may be associated with a function declaring it as 
3046 \emph on 
3047 _naked.
3048  
3049 \emph default 
3050 The 
3051 \emph on 
3052 _naked
3053 \emph default 
3054  function modifier attribute prevents the compiler from generating prologue
3055  and epilogue code for that function.
3056  This means that the user is entirely responsible for such things as saving
3057  any registers that may need to be preserved, selecting the proper register
3058  bank, generating the 
3059 \emph on 
3060 return
3061 \emph default 
3062  instruction at the end, etc.
3063  Practically, this means that the contents of the function must be written
3064  in inline assembler.
3065  This is particularly useful for interrupt functions, which can have a large
3066  (and often unnecessary) prologue/epilogue.
3067  For example, compare the code generated by these two functions:
3068 \newline 
3069
3070 \newline 
3071
3072 \family typewriter 
3073 data unsigned char counter;
3074 \newline 
3075 void simpleInterrupt(void) interrupt 1
3076 \newline 
3077 {
3078 \newline 
3079 \SpecialChar ~
3080 \SpecialChar ~
3081 \SpecialChar ~
3082 \SpecialChar ~
3083 counter++;
3084 \newline 
3085 }
3086 \newline 
3087
3088 \newline 
3089 void nakedInterrupt(void) interrupt 2 _naked
3090 \newline 
3091 {
3092 \newline 
3093 \SpecialChar ~
3094 \SpecialChar ~
3095 \SpecialChar ~
3096 \SpecialChar ~
3097 _asm
3098 \newline 
3099 \SpecialChar ~
3100 \SpecialChar ~
3101 \SpecialChar ~
3102 \SpecialChar ~
3103 \SpecialChar ~
3104 \SpecialChar ~
3105 inc\SpecialChar ~
3106 \SpecialChar ~
3107 \SpecialChar ~
3108 \SpecialChar ~
3109 \SpecialChar ~
3110 _counter
3111 \newline 
3112 \SpecialChar ~
3113 \SpecialChar ~
3114 \SpecialChar ~
3115 \SpecialChar ~
3116 \SpecialChar ~
3117 \SpecialChar ~
3118 reti\SpecialChar ~
3119 \SpecialChar ~
3120 \SpecialChar ~
3121 \SpecialChar ~
3122 ; MUST explicitly include ret in _naked function.
3123 \newline 
3124 \SpecialChar ~
3125 \SpecialChar ~
3126 \SpecialChar ~
3127 \SpecialChar ~
3128 _endasm;
3129 \newline 
3130 }
3131 \family default 
3132
3133 \newline 
3134
3135 \newline 
3136 For an 8051 target, the generated simpleInterrupt looks like:
3137 \newline 
3138
3139 \newline 
3140
3141 \family typewriter 
3142 _simpleIterrupt:
3143 \newline 
3144 \SpecialChar ~
3145 \SpecialChar ~
3146 \SpecialChar ~
3147 \SpecialChar ~
3148 push\SpecialChar ~
3149 \SpecialChar ~
3150 \SpecialChar ~
3151 \SpecialChar ~
3152 acc
3153 \newline 
3154 \SpecialChar ~
3155 \SpecialChar ~
3156 \SpecialChar ~
3157 \SpecialChar ~
3158 push\SpecialChar ~
3159 \SpecialChar ~
3160 \SpecialChar ~
3161 \SpecialChar ~
3162 b
3163 \newline 
3164 \SpecialChar ~
3165 \SpecialChar ~
3166 \SpecialChar ~
3167 \SpecialChar ~
3168 push\SpecialChar ~
3169 \SpecialChar ~
3170 \SpecialChar ~
3171 \SpecialChar ~
3172 dpl
3173 \newline 
3174 \SpecialChar ~
3175 \SpecialChar ~
3176 \SpecialChar ~
3177 \SpecialChar ~
3178 push\SpecialChar ~
3179 \SpecialChar ~
3180 \SpecialChar ~
3181 \SpecialChar ~
3182 dph
3183 \newline 
3184 \SpecialChar ~
3185 \SpecialChar ~
3186 \SpecialChar ~
3187 \SpecialChar ~
3188 push\SpecialChar ~
3189 \SpecialChar ~
3190 \SpecialChar ~
3191 \SpecialChar ~
3192 psw
3193 \newline 
3194 \SpecialChar ~
3195 \SpecialChar ~
3196 \SpecialChar ~
3197 \SpecialChar ~
3198 mov\SpecialChar ~
3199 \SpecialChar ~
3200 \SpecialChar ~
3201 \SpecialChar ~
3202 \SpecialChar ~
3203 psw,#0x00
3204 \newline 
3205 \SpecialChar ~
3206 \SpecialChar ~
3207 \SpecialChar ~
3208 \SpecialChar ~
3209 inc\SpecialChar ~
3210 \SpecialChar ~
3211 \SpecialChar ~
3212 \SpecialChar ~
3213 \SpecialChar ~
3214 _counter
3215 \newline 
3216 \SpecialChar ~
3217 \SpecialChar ~
3218 \SpecialChar ~
3219 \SpecialChar ~
3220 pop\SpecialChar ~
3221 \SpecialChar ~
3222 \SpecialChar ~
3223 \SpecialChar ~
3224 \SpecialChar ~
3225 psw
3226 \newline 
3227 \SpecialChar ~
3228 \SpecialChar ~
3229 \SpecialChar ~
3230 \SpecialChar ~
3231 pop\SpecialChar ~
3232 \SpecialChar ~
3233 \SpecialChar ~
3234 \SpecialChar ~
3235 \SpecialChar ~
3236 dph
3237 \newline 
3238 \SpecialChar ~
3239 \SpecialChar ~
3240 \SpecialChar ~
3241 \SpecialChar ~
3242 pop\SpecialChar ~
3243 \SpecialChar ~
3244 \SpecialChar ~
3245 \SpecialChar ~
3246 \SpecialChar ~
3247 dpl
3248 \newline 
3249 \SpecialChar ~
3250 \SpecialChar ~
3251 \SpecialChar ~
3252 \SpecialChar ~
3253 pop\SpecialChar ~
3254 \SpecialChar ~
3255 \SpecialChar ~
3256 \SpecialChar ~
3257 \SpecialChar ~
3258 b
3259 \newline 
3260 \SpecialChar ~
3261 \SpecialChar ~
3262 \SpecialChar ~
3263 \SpecialChar ~
3264 pop\SpecialChar ~
3265 \SpecialChar ~
3266 \SpecialChar ~
3267 \SpecialChar ~
3268 \SpecialChar ~
3269 acc
3270 \newline 
3271 \SpecialChar ~
3272 \SpecialChar ~
3273 \SpecialChar ~
3274 \SpecialChar ~
3275 reti
3276 \family default 
3277
3278 \newline 
3279
3280 \newline 
3281 whereas nakedInterrupt looks like:
3282 \newline 
3283
3284 \newline 
3285
3286 \family typewriter 
3287 _nakedInterrupt:
3288 \newline 
3289 \SpecialChar ~
3290 \SpecialChar ~
3291 \SpecialChar ~
3292 \SpecialChar ~
3293 inc\SpecialChar ~
3294 \SpecialChar ~
3295 \SpecialChar ~
3296 \SpecialChar ~
3297 _counter
3298 \newline 
3299 \SpecialChar ~
3300 \SpecialChar ~
3301 \SpecialChar ~
3302 \SpecialChar ~
3303 reti\SpecialChar ~
3304 \SpecialChar ~
3305 \SpecialChar ~
3306 ; MUST explicitly include ret(i) in _naked function.
3307 \family default 
3308
3309 \newline 
3310
3311 \newline 
3312 While there is nothing preventing you from writing C code inside a _naked
3313  function, there are many ways to shoot yourself in the foot doing this,
3314  and is is recommended that you stick to inline assembler.
3315 \layout Subsection
3316
3317 Functions using private banks
3318 \layout Standard
3319
3320 The 
3321 \emph on 
3322 using
3323 \emph default 
3324  attribute (which tells the compiler to use a register bank other than the
3325  default bank zero) should only be applied to 
3326 \emph on 
3327 interrupt
3328 \emph default 
3329  functions (see note 1 below).
3330  This will in most circumstances make the generated ISR code more efficient
3331  since it will not have to save registers on the stack.
3332 \layout Standard
3333
3334 The 
3335 \emph on 
3336 using
3337 \emph default 
3338  attribute will have no effect on the generated code for a 
3339 \emph on 
3340 non-interrupt
3341 \emph default 
3342  function (but may occasionally be useful anyway
3343 \begin_float footnote 
3344 \layout Standard
3345
3346 possible exception: if a function is called ONLY from 'interrupt' functions
3347  using a particular bank, it can be declared with the same 'using' attribute
3348  as the calling 'interrupt' functions.
3349  For instance, if you have several ISRs using bank one, and all of them
3350  call memcpy(), it might make sense to create a specialized version of memcpy()
3351  'using 1', since this would prevent the ISR from having to save bank zero
3352  to the stack on entry and switch to bank zero before calling the function
3353 \end_float 
3354 ).
3355 \newline 
3356
3357 \emph on 
3358 (pending: I don't think this has been done yet)
3359 \layout Standard
3360
3361 An 
3362 \emph on 
3363 interrupt
3364 \emph default 
3365  function using a non-zero bank will assume that it can trash that register
3366  bank, and will not save it.
3367  Since high-priority interrupts can interrupt low-priority ones on the 8051
3368  and friends, this means that if a high-priority ISR 
3369 \emph on 
3370 using
3371 \emph default 
3372  a particular bank occurs while processing a low-priority ISR 
3373 \emph on 
3374 using
3375 \emph default 
3376  the same bank, terrible and bad things can happen.
3377  To prevent this, no single register bank should be 
3378 \emph on 
3379 used
3380 \emph default 
3381  by both a high priority and a low priority ISR.
3382  This is probably most easily done by having all high priority ISRs use
3383  one bank and all low priority ISRs use another.
3384  If you have an ISR which can change priority at runtime, you're on your
3385  own: I suggest using the default bank zero and taking the small performance
3386  hit.
3387 \layout Standard
3388
3389 It is most efficient if your ISR calls no other functions.
3390  If your ISR must call other functions, it is most efficient if those functions
3391  use the same bank as the ISR (see note 1 below); the next best is if the
3392  called functions use bank zero.
3393  It is very inefficient to call a function using a different, non-zero bank
3394  from an ISR.
3395  
3396 \layout Subsection
3397
3398 Absolute Addressing
3399 \layout Standard
3400
3401 Data items can be assigned an absolute address with the 
3402 \emph on 
3403 at <address>
3404 \emph default 
3405  keyword, in addition to a storage class, e.g.:
3406 \newline 
3407
3408 \newline 
3409
3410 \family typewriter 
3411 xdata at 0x8000 unsigned char PORTA_8255 ;
3412 \newline 
3413
3414 \family default 
3415
3416 \newline 
3417 In the above example the PORTA_8255 will be allocated to the location 0x8000
3418  of the external ram.
3419  Note that this feature is provided to give the programmer access to 
3420 \emph on 
3421 memory mapped
3422 \emph default 
3423  devices attached to the controller.
3424  The compiler does not actually reserve any space for variables declared
3425  in this way (they are implemented with an equate in the assembler).
3426  Thus it is left to the programmer to make sure there are no overlaps with
3427  other variables that are declared without the absolute address.
3428  The assembler listing file (.lst) and the linker output files (.rst) and
3429  (.map) are a good places to look for such overlaps.
3430 \newline 
3431
3432 \newline 
3433 Absolute address can be specified for variables in all storage classes,
3434  e.g.:
3435 \newline 
3436
3437 \newline 
3438
3439 \family typewriter 
3440 bit at 0x02 bvar;
3441 \newline 
3442
3443 \newline 
3444
3445 \family default 
3446 The above example will allocate the variable at offset 0x02 in the bit-addressab
3447 le space.
3448  There is no real advantage to assigning absolute addresses to variables
3449  in this manner, unless you want strict control over all the variables allocated.
3450 \layout Subsection
3451
3452 Startup Code
3453 \layout Standard
3454
3455 The compiler inserts a call to the C routine 
3456 \emph on 
3457 _sdcc__external__startup()
3458 \series bold 
3459 \emph default 
3460  
3461 \series default 
3462 at the start of the CODE area.
3463  This routine is in the runtime library.
3464  By default this routine returns 0, if this routine returns a non-zero value,
3465  the static & global variable initialization will be skipped and the function
3466  main will be invoked Other wise static & global variables will be initialized
3467  before the function main is invoked.
3468  You could add a 
3469 \emph on 
3470 _sdcc__external__startup()
3471 \emph default 
3472  routine to your program to override the default if you need to setup hardware
3473  or perform some other critical operation prior to static & global variable
3474  initialization.
3475 \layout Subsection
3476
3477 Inline Assembler Code
3478 \layout Standard
3479
3480 SDCC allows the use of in-line assembler with a few restriction as regards
3481  labels.
3482  All labels defined within inline assembler code 
3483 \emph on 
3484 has to be
3485 \emph default 
3486  of the form 
3487 \emph on 
3488 nnnnn$
3489 \emph default 
3490  where nnnn is a number less than 100 (which implies a limit of utmost 100
3491  inline assembler labels 
3492 \emph on 
3493 per function
3494 \emph default 
3495 \noun on 
3496 )
3497 \noun default 
3498 .
3499  It is strongly recommended that each assembly instruction (including labels)
3500  be placed in a separate line (as the example shows).
3501  When the 
3502 \emph on 
3503 --peep-asm
3504 \emph default 
3505  command line option is used, the inline assembler code will be passed through
3506  the peephole optimizer.
3507  This might cause some unexpected changes in the inline assembler code.
3508  Please go throught the peephole optimizer rules defined in file 
3509 \emph on 
3510 SDCCpeeph.def
3511 \emph default 
3512  carefully before using this option.
3513 \newline 
3514
3515 \newline 
3516
3517 \family typewriter 
3518 _asm 
3519 \newline 
3520 \SpecialChar ~
3521 \SpecialChar ~
3522 \SpecialChar ~
3523 \SpecialChar ~
3524 mov\SpecialChar ~
3525 \SpecialChar ~
3526 \SpecialChar ~
3527 \SpecialChar ~
3528 \SpecialChar ~
3529 b,#10 
3530 \newline 
3531 00001$: 
3532 \newline 
3533 \SpecialChar ~
3534 \SpecialChar ~
3535 \SpecialChar ~
3536 \SpecialChar ~
3537 djnz\SpecialChar ~
3538 \SpecialChar ~
3539 \SpecialChar ~
3540 \SpecialChar ~
3541 b,00001$ 
3542 \newline 
3543 _endasm ;
3544 \family default 
3545 \size small 
3546
3547 \newline 
3548
3549 \newline 
3550
3551 \size default 
3552 The inline assembler code can contain any valid code understood by the assembler
3553 , this includes any assembler directives and comment lines.
3554  The compiler does not do any validation of the code within the 
3555 \family typewriter 
3556 _asm ...
3557  _endasm;
3558 \family default 
3559  keyword pair.
3560  
3561 \newline 
3562
3563 \newline 
3564 Inline assembler code cannot reference any C-Labels, however it can reference
3565  labels defined by the inline assembler, e.g.:
3566 \newline 
3567
3568 \newline 
3569
3570 \family typewriter 
3571 foo() { 
3572 \newline 
3573 \SpecialChar ~
3574 \SpecialChar ~
3575 \SpecialChar ~
3576 \SpecialChar ~
3577 /* some c code */ 
3578 \newline 
3579 \SpecialChar ~
3580 \SpecialChar ~
3581 \SpecialChar ~
3582 \SpecialChar ~
3583 _asm 
3584 \newline 
3585 \SpecialChar ~
3586 \SpecialChar ~
3587 \SpecialChar ~
3588 \SpecialChar ~
3589 \SpecialChar ~
3590 \SpecialChar ~
3591 ; some assembler code 
3592 \newline 
3593 \SpecialChar ~
3594 \SpecialChar ~
3595 \SpecialChar ~
3596 \SpecialChar ~
3597 \SpecialChar ~
3598 \SpecialChar ~
3599 ljmp $0003 
3600 \newline 
3601 \SpecialChar ~
3602 \SpecialChar ~
3603 \SpecialChar ~
3604 \SpecialChar ~
3605 _endasm; 
3606 \newline 
3607 \SpecialChar ~
3608 \SpecialChar ~
3609 \SpecialChar ~
3610 \SpecialChar ~
3611 /* some more c code */ 
3612 \newline 
3613 clabel:\SpecialChar ~
3614 \SpecialChar ~
3615 /* inline assembler cannot reference this label */ 
3616 \newline 
3617 \SpecialChar ~
3618 \SpecialChar ~
3619 \SpecialChar ~
3620 \SpecialChar ~
3621 _asm
3622 \newline 
3623 \SpecialChar ~
3624 \SpecialChar ~
3625 \SpecialChar ~
3626 \SpecialChar ~
3627 $0003: ;label (can be reference by inline assembler only) 
3628 \newline 
3629 \SpecialChar ~
3630 \SpecialChar ~
3631 \SpecialChar ~
3632 \SpecialChar ~
3633 _endasm ; 
3634 \newline 
3635 \SpecialChar ~
3636 \SpecialChar ~
3637 \SpecialChar ~
3638 \SpecialChar ~
3639 /* some more c code */
3640 \newline 
3641 }
3642 \newline 
3643
3644 \newline 
3645
3646 \family default 
3647 In other words inline assembly code can access labels defined in inline
3648  assembly within the scope of the funtion.
3649  
3650 \layout Standard
3651
3652 The same goes the other way, ie.
3653  labels defines in inline assembly CANNOT be accessed by C statements.
3654 \layout Subsection
3655
3656 int(16 bit) and long (32 bit) Support
3657 \layout Standard
3658
3659 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
3660  multiplication and modulus operations are implemented by support routines.
3661  These support routines are all developed in ANSI-C to facilitate porting
3662  to other MCUs, although some model specific assembler optimations are used.
3663  The following files contain the described routine, all of them can be found
3664  in <installdir>/share/sdcc/lib.
3665 \newline 
3666
3667 \newline 
3668
3669 \emph on 
3670 <pending: tabularise this>
3671 \emph default 
3672
3673 \newline 
3674
3675 \newline 
3676 _mulsint.c - signed 16 bit multiplication (calls _muluint)
3677 \newline 
3678 _muluint.c - unsigned 16 bit multiplication
3679 \newline 
3680 _divsint.c - signed 16 bit division (calls _divuint)
3681 \newline 
3682 _divuint.c - unsigned 16 bit division
3683 \newline 
3684 _modsint.c - signed 16 bit modulus (call _moduint)
3685 \newline 
3686 _moduint.c - unsigned 16 bit modulus
3687 \newline 
3688 _mulslong.c - signed 32 bit multiplication (calls _mululong)
3689 \newline 
3690 _mululong.c - unsigned32 bit multiplication
3691 \newline 
3692 _divslong.c - signed 32 division (calls _divulong)
3693 \newline 
3694 _divulong.c - unsigned 32 division
3695 \newline 
3696 _modslong.c - signed 32 bit modulus (calls _modulong)
3697 \newline 
3698 _modulong.c - unsigned 32 bit modulus 
3699 \size footnotesize 
3700
3701 \newline 
3702
3703 \newline 
3704
3705 \size default 
3706 Since they are compiled as 
3707 \emph on 
3708 non-reentrant
3709 \emph default 
3710 , interrupt service routines should not do any of the above operations.
3711  If this is unavoidable then the above routines will need to be compiled
3712  with the 
3713 \emph on 
3714 --stack-auto
3715 \emph default 
3716  option, after which the source program will have to be compiled with 
3717 \emph on 
3718 --int-long-rent
3719 \emph default 
3720  option.
3721 \layout Subsection
3722
3723 Floating Point Support
3724 \layout Standard
3725
3726 SDCC supports IEEE (single precision 4bytes) floating point numbers.The floating
3727  point support routines are derived from gcc's floatlib.c and consists of
3728  the following routines:
3729 \newline 
3730
3731 \newline 
3732
3733 \emph on 
3734 <pending: tabularise this>
3735 \emph default 
3736
3737 \newline 
3738
3739 \newline 
3740 _fsadd.c - add floating point numbers
3741 \newline 
3742 _fssub.c - subtract floating point numbers
3743 \newline 
3744 _fsdiv.c - divide floating point numbers
3745 \newline 
3746 _fsmul.c - multiply floating point numbers
3747 \newline 
3748 _fs2uchar.c - convert floating point to unsigned char
3749 \newline 
3750 _fs2char.c - convert floating point to signed char
3751 \newline 
3752 _fs2uint.c - convert floating point to unsigned int
3753 \newline 
3754 _fs2int.c - convert floating point to signed int
3755 \newline 
3756 _fs2ulong.c - convert floating point to unsigned long
3757 \newline 
3758 _fs2long.c - convert floating point to signed long
3759 \newline 
3760 _uchar2fs.c - convert unsigned char to floating point
3761 \newline 
3762 _char2fs.c - convert char to floating point number
3763 \newline 
3764 _uint2fs.c - convert unsigned int to floating point
3765 \newline 
3766 _int2fs.c - convert int to floating point numbers
3767 \newline 
3768 _ulong2fs.c - convert unsigned long to floating point number
3769 \newline 
3770 _long2fs.c - convert long to floating point number
3771 \size footnotesize 
3772
3773 \newline 
3774
3775 \newline 
3776
3777 \size default 
3778 Note if all these routines are used simultaneously the data space might
3779  overflow.
3780  For serious floating point usage it is strongly recommended that the large
3781  model be used.
3782 \layout Subsection
3783
3784 MCS51 Memory Models
3785 \layout Standard
3786
3787 SDCC allows two memory models for MCS51 code, small and large.
3788  Modules compiled with different memory models should 
3789 \emph on 
3790 never
3791 \emph default 
3792  be combined together or the results would be unpredictable.
3793  The library routines supplied with the compiler are compiled as both small
3794  and large.
3795  The compiled library modules are contained in seperate directories as small
3796  and large so that you can link to either set.
3797  
3798 \layout Standard
3799
3800 When the large model is used all variables declared without a storage class
3801  will be allocated into the external ram, this includes all parameters and
3802  local variables (for non-reentrant functions).
3803  When the small model is used variables without storage class are allocated
3804  in the internal ram.
3805 \layout Standard
3806
3807 Judicious usage of the processor specific storage classes and the 'reentrant'
3808  function type will yield much more efficient code, than using the large
3809  model.
3810  Several optimizations are disabled when the program is compiled using the
3811  large model, it is therefore strongly recommdended that the small model
3812  be used unless absolutely required.
3813 \layout Subsection
3814
3815 DS390 Memory Models
3816 \layout Standard
3817
3818 The only model supported is Flat 24.
3819  This generates code for the 24 bit contiguous addressing mode of the Dallas
3820  DS80C390 part.
3821  In this mode, up to four meg of external RAM or code space can be directly
3822  addressed.
3823  See the data sheets at www.dalsemi.com for further information on this part.
3824 \newline 
3825
3826 \newline 
3827 In older versions of the compiler, this option was used with the MCS51 code
3828  generator (
3829 \emph on 
3830 -mmcs51
3831 \emph default 
3832 ).
3833  Now, however, the '390 has it's own code generator, selected by the 
3834 \emph on 
3835 -mds390
3836 \emph default 
3837  switch.
3838  
3839 \newline 
3840
3841 \newline 
3842 Note that the compiler does not generate any code to place the processor
3843  into 24 bitmode (although 
3844 \emph on 
3845 tinibios
3846 \emph default 
3847  in the ds390 libraries will do that for you).
3848  If you don't use 
3849 \emph on 
3850 tinibios
3851 \emph default 
3852 , the boot loader or similar code must ensure that the processor is in 24
3853  bit contiguous addressing mode before calling the SDCC startup code.
3854 \newline 
3855
3856 \newline 
3857 Like the 
3858 \emph on 
3859 --model-large
3860 \emph default 
3861  option, variables will by default be placed into the XDATA segment.
3862  
3863 \newline 
3864
3865 \newline 
3866 Segments may be placed anywhere in the 4 meg address space using the usual
3867  --*-loc options.
3868  Note that if any segments are located above 64K, the -r flag must be passed
3869  to the linker to generate the proper segment relocations, and the Intel
3870  HEX output format must be used.
3871  The -r flag can be passed to the linker by using the option 
3872 \emph on 
3873 -Wl-r
3874 \emph default 
3875  on the sdcc command line.
3876  However, currently the linker can not handle code segments > 64k.
3877 \layout Subsection
3878
3879 Defines Created by the Compiler
3880 \layout Standard
3881
3882 The compiler creates the following #defines.
3883 \layout Itemize
3884
3885 SDCC - this Symbol is always defined.
3886 \layout Itemize
3887
3888 SDCC_mcs51 or SDCC_ds390 or SDCC_z80, etc - depending on the model used
3889  (e.g.: -mds390)
3890 \layout Itemize
3891
3892 __mcs51 or __ds390 or __z80, etc - depending on the model used (e.g.
3893  -mz80)
3894 \layout Itemize
3895
3896 SDCC_STACK_AUTO - this symbol is defined when 
3897 \emph on 
3898 --stack-auto
3899 \emph default 
3900  option is used.
3901 \layout Itemize
3902
3903 SDCC_MODEL_SMALL - when 
3904 \emph on 
3905 --model-small
3906 \emph default 
3907  is used.
3908 \layout Itemize
3909
3910 SDCC_MODEL_LARGE - when 
3911 \emph on 
3912 --model-large
3913 \emph default 
3914  is used.
3915 \layout Itemize
3916
3917 SDCC_USE_XSTACK - when 
3918 \emph on 
3919 --xstack
3920 \emph default 
3921  option is used.
3922 \layout Itemize
3923
3924 SDCC_STACK_TENBIT - when 
3925 \emph on 
3926 -mds390
3927 \emph default 
3928  is used
3929 \layout Itemize
3930
3931 SDCC_MODEL_FLAT24 - when 
3932 \emph on 
3933 -mds390
3934 \emph default 
3935  is used
3936 \layout Section
3937
3938 SDCC Technical Data
3939 \layout Subsection
3940
3941 Optimizations
3942 \layout Standard
3943
3944 SDCC performs a host of standard optimizations in addition to some MCU specific
3945  optimizations.
3946  
3947 \layout Subsubsection
3948
3949 Sub-expression Elimination
3950 \layout Standard
3951
3952 The compiler does local and global common subexpression elimination, e.g.:
3953  
3954 \newline 
3955
3956 \newline 
3957
3958 \family typewriter 
3959 i = x + y + 1; 
3960 \newline 
3961 j = x + y;
3962 \family default 
3963
3964 \newline 
3965
3966 \newline 
3967 will be translated to
3968 \newline 
3969
3970 \newline 
3971
3972 \family typewriter 
3973 iTemp = x + y 
3974 \newline 
3975 i = iTemp + 1 
3976 \newline 
3977 j = iTemp
3978 \newline 
3979
3980 \family default 
3981
3982 \newline 
3983 Some subexpressions are not as obvious as the above example, e.g.:
3984 \newline 
3985
3986 \newline 
3987
3988 \family typewriter 
3989 a->b[i].c = 10; 
3990 \newline 
3991 a->b[i].d = 11;
3992 \family default 
3993
3994 \newline 
3995
3996 \newline 
3997 In this case the address arithmetic a->b[i] will be computed only once;
3998  the equivalent code in C would be.
3999 \newline 
4000
4001 \newline 
4002
4003 \family typewriter 
4004 iTemp = a->b[i]; 
4005 \newline 
4006 iTemp.c = 10; 
4007 \newline 
4008 iTemp.d = 11;
4009 \family default 
4010
4011 \newline 
4012
4013 \newline 
4014 The compiler will try to keep these temporary variables in registers.
4015 \layout Subsubsection
4016
4017 Dead-Code Elimination
4018 \layout Standard
4019
4020
4021 \family typewriter 
4022 int global; 
4023 \newline 
4024 void f () { 
4025 \newline 
4026 \SpecialChar ~
4027 \SpecialChar ~
4028 int i; 
4029 \newline 
4030 \SpecialChar ~
4031 \SpecialChar ~
4032 i = 1; \SpecialChar ~
4033 /* dead store */ 
4034 \newline 
4035 \SpecialChar ~
4036 \SpecialChar ~
4037 global = 1;\SpecialChar ~
4038 /* dead store */ 
4039 \newline 
4040 \SpecialChar ~
4041 \SpecialChar ~
4042 global = 2; 
4043 \newline 
4044 \SpecialChar ~
4045 \SpecialChar ~
4046 return; 
4047 \newline 
4048 \SpecialChar ~
4049 \SpecialChar ~
4050 global = 3;\SpecialChar ~
4051 /* unreachable */ 
4052 \newline 
4053 }
4054 \family default 
4055
4056 \newline 
4057
4058 \newline 
4059 will be changed to
4060 \newline 
4061
4062 \newline 
4063
4064 \family typewriter 
4065 int global; void f () 
4066 \newline 
4067 {
4068 \newline 
4069 \SpecialChar ~
4070 \SpecialChar ~
4071 global = 2; 
4072 \newline 
4073 \SpecialChar ~
4074 \SpecialChar ~
4075 return; 
4076 \newline 
4077 }
4078 \layout Subsubsection
4079
4080 Copy-Propagation
4081 \layout Standard
4082
4083
4084 \family typewriter 
4085 int f() { 
4086 \newline 
4087 \SpecialChar ~
4088 \SpecialChar ~
4089 int i, j; 
4090 \newline 
4091 \SpecialChar ~
4092 \SpecialChar ~
4093 i = 10; 
4094 \newline 
4095 \SpecialChar ~
4096 \SpecialChar ~
4097 j = i; 
4098 \newline 
4099 \SpecialChar ~
4100 \SpecialChar ~
4101 return j; 
4102 \newline 
4103 }
4104 \family default 
4105
4106 \newline 
4107
4108 \newline 
4109 will be changed to 
4110 \newline 
4111
4112 \newline 
4113
4114 \family typewriter 
4115 int f() { 
4116 \newline 
4117 \SpecialChar ~
4118  \SpecialChar ~
4119  int i,j; 
4120 \newline 
4121 \SpecialChar ~
4122  \SpecialChar ~
4123  i = 10; 
4124 \newline 
4125 \SpecialChar ~
4126  \SpecialChar ~
4127  j = 10; 
4128 \newline 
4129 \SpecialChar ~
4130  \SpecialChar ~
4131  return 10; 
4132 \newline 
4133 }
4134 \newline 
4135
4136 \newline 
4137
4138 \family default 
4139 Note: the dead stores created by this copy propagation will be eliminated
4140  by dead-code elimination.
4141 \layout Subsubsection
4142
4143 Loop Optimizations
4144 \layout Standard
4145
4146 Two types of loop optimizations are done by SDCC loop invariant lifting
4147  and strength reduction of loop induction variables.
4148  In addition to the strength reduction the optimizer marks the induction
4149  variables and the register allocator tries to keep the induction variables
4150  in registers for the duration of the loop.
4151  Because of this preference of the register allocator, loop induction optimizati
4152 on causes an increase in register pressure, which may cause unwanted spilling
4153  of other temporary variables into the stack / data space.
4154  The compiler will generate a warning message when it is forced to allocate
4155  extra space either on the stack or data space.
4156  If this extra space allocation is undesirable then induction optimization
4157  can be eliminated either for the entire source file (with --noinduction
4158  option) or for a given function only using #pragma\SpecialChar ~
4159 NOINDUCTION.
4160 \newline 
4161
4162 \newline 
4163 Loop Invariant:
4164 \newline 
4165
4166 \newline 
4167
4168 \family typewriter 
4169 for (i = 0 ; i < 100 ; i ++) 
4170 \newline 
4171  \SpecialChar ~
4172  \SpecialChar ~
4173 f += k + l;
4174 \family default 
4175
4176 \newline 
4177
4178 \newline 
4179 changed to
4180 \newline 
4181
4182 \newline 
4183
4184 \family typewriter 
4185 itemp = k + l; 
4186 \newline 
4187 for (i = 0; i < 100; i++) 
4188 \newline 
4189 \SpecialChar ~
4190 \SpecialChar ~
4191 f += itemp;
4192 \family default 
4193
4194 \newline 
4195
4196 \newline 
4197 As mentioned previously some loop invariants are not as apparent, all static
4198  address computations are also moved out of the loop.
4199 \newline 
4200
4201 \newline 
4202 Strength Reduction, this optimization substitutes an expression by a cheaper
4203  expression:
4204 \newline 
4205
4206 \newline 
4207
4208 \family typewriter 
4209 for (i=0;i < 100; i++)
4210 \newline 
4211 \SpecialChar ~
4212 \SpecialChar ~
4213 ar[i*5] = i*3;
4214 \family default 
4215
4216 \newline 
4217
4218 \newline 
4219 changed to
4220 \newline 
4221
4222 \newline 
4223
4224 \family typewriter 
4225 itemp1 = 0; 
4226 \newline 
4227 itemp2 = 0; 
4228 \newline 
4229 for (i=0;i< 100;i++) { 
4230 \newline 
4231  \SpecialChar ~
4232  \SpecialChar ~
4233 ar[itemp1] = itemp2; 
4234 \newline 
4235  \SpecialChar ~
4236  \SpecialChar ~
4237 itemp1 += 5; 
4238 \newline 
4239  \SpecialChar ~
4240  \SpecialChar ~
4241 itemp2 += 3; 
4242 \newline 
4243 }
4244 \family default 
4245
4246 \newline 
4247
4248 \newline 
4249 The more expensive multiplication is changed to a less expensive addition.
4250 \layout Subsubsection
4251
4252 Loop Reversing
4253 \layout Standard
4254
4255 This optimization is done to reduce the overhead of checking loop boundaries
4256  for every iteration.
4257  Some simple loops can be reversed and implemented using a 
4258 \begin_inset Quotes eld
4259 \end_inset 
4260
4261 decrement and jump if not zero
4262 \begin_inset Quotes erd
4263 \end_inset 
4264
4265  instruction.
4266  SDCC checks for the following criterion to determine if a loop is reversible
4267  (note: more sophisticated compilers use data-dependency analysis to make
4268  this determination, SDCC uses a more simple minded analysis).
4269 \layout Itemize
4270
4271 The 'for' loop is of the form 
4272 \newline 
4273
4274 \newline 
4275
4276 \family typewriter 
4277 for (<symbol> = <expression> ; <sym> [< | <=] <expression> ; [<sym>++ |
4278  <sym> += 1])
4279 \newline 
4280 \SpecialChar ~
4281 \SpecialChar ~
4282 \SpecialChar ~
4283 \SpecialChar ~
4284 <for body>
4285 \layout Itemize
4286
4287 The <for body> does not contain 
4288 \begin_inset Quotes eld
4289 \end_inset 
4290
4291 continue
4292 \begin_inset Quotes erd
4293 \end_inset 
4294
4295  or 'break
4296 \begin_inset Quotes erd
4297 \end_inset 
4298
4299 .
4300 \layout Itemize
4301
4302 All goto's are contained within the loop.
4303 \layout Itemize
4304
4305 No function calls within the loop.
4306 \layout Itemize
4307
4308 The loop control variable <sym> is not assigned any value within the loop
4309 \layout Itemize
4310
4311 The loop control variable does NOT participate in any arithmetic operation
4312  within the loop.
4313 \layout Itemize
4314
4315 There are NO switch statements in the loop.
4316 \layout Standard
4317
4318 Note djnz instruction can be used for 8-bit values 
4319 \emph on 
4320 only
4321 \emph default 
4322 , therefore it is advantageous to declare loop control symbols as 
4323 \emph on 
4324 char
4325 \emph default 
4326 .
4327  Ofcourse this may not be possible on all situations.
4328 \layout Subsubsection
4329
4330 Algebraic Simplifications
4331 \layout Standard
4332
4333 SDCC does numerous algebraic simplifications, the following is a small sub-set
4334  of these optimizations.
4335 \newline 
4336
4337 \newline 
4338
4339 \family typewriter 
4340 i = j + 0 ; /* changed to */ i = j; 
4341 \newline 
4342 i /= 2; /* changed to */ i >>= 1; 
4343 \newline 
4344 i = j - j ; /* changed to */ i = 0; 
4345 \newline 
4346 i = j / 1 ; /* changed to */ i = j;
4347 \family default 
4348
4349 \newline 
4350
4351 \newline 
4352 Note the subexpressions given above are generally introduced by macro expansions
4353  or as a result of copy/constant propagation.
4354 \layout Subsubsection
4355
4356 'switch' Statements
4357 \layout Standard
4358
4359 SDCC changes switch statements to jump tables when the following conditions
4360  are true.
4361  
4362 \layout Itemize
4363
4364 The case labels are in numerical sequence, the labels need not be in order,
4365  and the starting number need not be one or zero.
4366 \layout Standard
4367
4368
4369 \family typewriter 
4370 switch(i) {\SpecialChar ~
4371  \SpecialChar ~
4372  \SpecialChar ~
4373  \SpecialChar ~
4374  \SpecialChar ~
4375  \SpecialChar ~
4376  \SpecialChar ~
4377  \SpecialChar ~
4378  \SpecialChar ~
4379  \SpecialChar ~
4380  \SpecialChar ~
4381  \SpecialChar ~
4382  \SpecialChar ~
4383 switch (i) { 
4384 \newline 
4385 case 4:...
4386  \SpecialChar ~
4387  \SpecialChar ~
4388  \SpecialChar ~
4389  \SpecialChar ~
4390  \SpecialChar ~
4391  \SpecialChar ~
4392  \SpecialChar ~
4393  \SpecialChar ~
4394  \SpecialChar ~
4395  \SpecialChar ~
4396  \SpecialChar ~
4397  \SpecialChar ~
4398  \SpecialChar ~
4399 case 1: ...
4400  
4401 \newline 
4402 case 5:...
4403  \SpecialChar ~
4404  \SpecialChar ~
4405  \SpecialChar ~
4406  \SpecialChar ~
4407  \SpecialChar ~
4408  \SpecialChar ~
4409  \SpecialChar ~
4410  \SpecialChar ~
4411  \SpecialChar ~
4412  \SpecialChar ~
4413  \SpecialChar ~
4414  \SpecialChar ~
4415  \SpecialChar ~
4416 case 2: ...
4417  
4418 \newline 
4419 case 3:...
4420  \SpecialChar ~
4421  \SpecialChar ~
4422  \SpecialChar ~
4423  \SpecialChar ~
4424  \SpecialChar ~
4425  \SpecialChar ~
4426  \SpecialChar ~
4427  \SpecialChar ~
4428  \SpecialChar ~
4429  \SpecialChar ~
4430  \SpecialChar ~
4431  \SpecialChar ~
4432  \SpecialChar ~
4433 case 3: ...
4434  
4435 \newline 
4436 case 6:...
4437  \SpecialChar ~
4438  \SpecialChar ~
4439  \SpecialChar ~
4440  \SpecialChar ~
4441  \SpecialChar ~
4442  \SpecialChar ~
4443  \SpecialChar ~
4444  \SpecialChar ~
4445  \SpecialChar ~
4446  \SpecialChar ~
4447  \SpecialChar ~
4448  \SpecialChar ~
4449  \SpecialChar ~
4450 case 4: ...
4451  
4452 \newline 
4453 }\SpecialChar ~
4454  \SpecialChar ~
4455  \SpecialChar ~
4456  \SpecialChar ~
4457  \SpecialChar ~
4458  \SpecialChar ~
4459  \SpecialChar ~
4460  \SpecialChar ~
4461  \SpecialChar ~
4462  \SpecialChar ~
4463  \SpecialChar ~
4464  \SpecialChar ~
4465  \SpecialChar ~
4466  \SpecialChar ~
4467  \SpecialChar ~
4468  \SpecialChar ~
4469  \SpecialChar ~
4470  \SpecialChar ~
4471 }
4472 \newline 
4473
4474 \newline 
4475
4476 \family default 
4477 Both the above switch statements will be implemented using a jump-table.
4478 \layout Itemize
4479
4480 The number of case labels is at least three, since it takes two conditional
4481  statements to handle the boundary conditions.
4482 \layout Itemize
4483
4484 The number of case labels is less than 84, since each label takes 3 bytes
4485  and a jump-table can be utmost 256 bytes long.
4486  
4487 \layout Standard
4488
4489 Switch statements which have gaps in the numeric sequence or those that
4490  have more that 84 case labels can be split into more than one switch statement
4491  for efficient code generation, e.g.:
4492 \newline 
4493
4494 \newline 
4495
4496 \family typewriter 
4497 switch (i) { 
4498 \newline 
4499 case 1: ...
4500  
4501 \newline 
4502 case 2: ...
4503  
4504 \newline 
4505 case 3: ...
4506  
4507 \newline 
4508 case 4: ...
4509  
4510 \newline 
4511 case 9: ...
4512  
4513 \newline 
4514 case 10: ...
4515  
4516 \newline 
4517 case 11: ...
4518  
4519 \newline 
4520 case 12: ...
4521  
4522 \newline 
4523 }
4524 \family default 
4525
4526 \newline 
4527
4528 \newline 
4529 If the above switch statement is broken down into two switch statements
4530 \newline 
4531
4532 \newline 
4533
4534 \family typewriter 
4535 switch (i) { 
4536 \newline 
4537 case 1: ...
4538  
4539 \newline 
4540 case 2: ...
4541  
4542 \newline 
4543 case 3: ...
4544  
4545 \newline 
4546 case 4: ...
4547  
4548 \newline 
4549 }
4550 \newline 
4551
4552 \newline 
4553
4554 \family default 
4555 and
4556 \family typewriter 
4557
4558 \newline 
4559
4560 \newline 
4561 switch (i) { 
4562 \newline 
4563 case 9: \SpecialChar ~
4564 ...
4565  
4566 \newline 
4567 case 10: ...
4568  
4569 \newline 
4570 case 11: ...
4571  
4572 \newline 
4573 case 12:\SpecialChar ~
4574 ...
4575  
4576 \newline 
4577 }
4578 \newline 
4579
4580 \newline 
4581
4582 \family default 
4583 then both the switch statements will be implemented using jump-tables whereas
4584  the unmodified switch statement will not be.
4585 \layout Subsubsection
4586
4587 Bit-shifting Operations.
4588 \layout Standard
4589
4590 Bit shifting is one of the most frequently used operation in embedded programmin
4591 g.
4592  SDCC tries to implement bit-shift operations in the most efficient way
4593  possible, e.g.:
4594 \newline 
4595
4596 \newline 
4597 unsigned char i;
4598 \newline 
4599 ...
4600  
4601 \newline 
4602 i>>= 4; 
4603 \newline 
4604 ...
4605 \newline 
4606
4607 \newline 
4608 generates the following code:
4609 \newline 
4610
4611 \newline 
4612 mov a,_i 
4613 \newline 
4614 swap a 
4615 \newline 
4616 anl a,#0x0f 
4617 \newline 
4618 mov _i,a
4619 \newline 
4620
4621 \newline 
4622 In general SDCC will never setup a loop if the shift count is known.
4623  Another example:
4624 \newline 
4625
4626 \newline 
4627
4628 \family typewriter 
4629 unsigned int i; 
4630 \newline 
4631 ...
4632  
4633 \newline 
4634 i >>= 9; 
4635 \newline 
4636 ...
4637 \family default 
4638
4639 \newline 
4640
4641 \newline 
4642 will generate:
4643 \newline 
4644
4645 \newline 
4646
4647 \family typewriter 
4648 mov a,(_i + 1) 
4649 \newline 
4650 mov (_i + 1),#0x00 
4651 \newline 
4652 clr c 
4653 \newline 
4654 rrc a 
4655 \newline 
4656 mov _i,a
4657 \family default 
4658
4659 \newline 
4660
4661 \newline 
4662 Note that SDCC stores numbers in little-endian format (i.e.
4663  lowest order first).
4664 \layout Subsubsection
4665
4666 Bit-rotation
4667 \layout Standard
4668
4669 A special case of the bit-shift operation is bit rotation, SDCC recognizes
4670  the following expression to be a left bit-rotation:
4671 \newline 
4672
4673 \newline 
4674
4675 \family typewriter 
4676 unsigned char i; 
4677 \newline 
4678 ...
4679  
4680 \newline 
4681 i = ((i << 1) | (i >> 7)); 
4682 \family default 
4683
4684 \newline 
4685 ...
4686 \newline 
4687
4688 \newline 
4689 will generate the following code:
4690 \newline 
4691
4692 \newline 
4693
4694 \family typewriter 
4695 mov a,_i 
4696 \newline 
4697 rl a 
4698 \newline 
4699 mov _i,a
4700 \family default 
4701
4702 \newline 
4703
4704 \newline 
4705 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
4706 ns of this case will also be recognized as bit-rotation, i.e.: 
4707 \newline 
4708
4709 \newline 
4710
4711 \family typewriter 
4712 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
4713 \layout Subsubsection
4714
4715 Highest Order Bit
4716 \layout Standard
4717
4718 It is frequently required to obtain the highest order bit of an integral
4719  type (long, int, short or char types).
4720  SDCC recognizes the following expression to yield the highest order bit
4721  and generates optimized code for it, e.g.:
4722 \newline 
4723
4724 \newline 
4725  
4726 \family typewriter 
4727 unsigned int gint; 
4728 \newline 
4729
4730 \newline 
4731 foo () { 
4732 \newline 
4733 unsigned char hob; 
4734 \newline 
4735 \SpecialChar ~
4736 \SpecialChar ~
4737 ...
4738  
4739 \newline 
4740 \SpecialChar ~
4741 \SpecialChar ~
4742 hob = (gint >> 15) & 1; 
4743 \newline 
4744 \SpecialChar ~
4745 \SpecialChar ~
4746 ..
4747  
4748 \newline 
4749 }
4750 \family default 
4751
4752 \newline 
4753
4754 \newline 
4755 will generate the following code:
4756 \newline 
4757
4758 \family typewriter 
4759
4760 \newline 
4761 \SpecialChar ~
4762 \SpecialChar ~
4763 \SpecialChar ~
4764 \SpecialChar ~
4765 \SpecialChar ~
4766 \SpecialChar ~
4767 \SpecialChar ~
4768 \SpecialChar ~
4769 \SpecialChar ~
4770 \SpecialChar ~
4771 \SpecialChar ~
4772 \SpecialChar ~
4773 \SpecialChar ~
4774 \SpecialChar ~
4775 \SpecialChar ~
4776 \SpecialChar ~
4777 \SpecialChar ~
4778 \SpecialChar ~
4779 \SpecialChar ~
4780 \SpecialChar ~
4781 \SpecialChar ~
4782 \SpecialChar ~
4783 \SpecialChar ~
4784 \SpecialChar ~
4785 \SpecialChar ~
4786 \SpecialChar ~
4787 \SpecialChar ~
4788 \SpecialChar ~
4789  61 ;\SpecialChar ~
4790  hob.c 7 
4791 \newline 
4792 \SpecialChar ~
4793 \SpecialChar ~
4794  000A E5*01\SpecialChar ~
4795 \SpecialChar ~
4796 \SpecialChar ~
4797 \SpecialChar ~
4798 \SpecialChar ~
4799 \SpecialChar ~
4800 \SpecialChar ~
4801 \SpecialChar ~
4802 \SpecialChar ~
4803 \SpecialChar ~
4804 \SpecialChar ~
4805 \SpecialChar ~
4806 \SpecialChar ~
4807 \SpecialChar ~
4808 \SpecialChar ~
4809  62\SpecialChar ~
4810 \SpecialChar ~
4811 \SpecialChar ~
4812 \SpecialChar ~
4813 \SpecialChar ~
4814 \SpecialChar ~
4815 \SpecialChar ~
4816 \SpecialChar ~
4817  mov\SpecialChar ~
4818  a,(_gint + 1) 
4819 \newline 
4820 \SpecialChar ~
4821 \SpecialChar ~
4822  000C 33\SpecialChar ~
4823 \SpecialChar ~
4824 \SpecialChar ~
4825 \SpecialChar ~
4826 \SpecialChar ~
4827 \SpecialChar ~
4828 \SpecialChar ~
4829 \SpecialChar ~
4830 \SpecialChar ~
4831 \SpecialChar ~
4832 \SpecialChar ~
4833 \SpecialChar ~
4834 \SpecialChar ~
4835 \SpecialChar ~
4836 \SpecialChar ~
4837 \SpecialChar ~
4838 \SpecialChar ~
4839 \SpecialChar ~
4840  63\SpecialChar ~
4841 \SpecialChar ~
4842 \SpecialChar ~
4843 \SpecialChar ~
4844 \SpecialChar ~
4845 \SpecialChar ~
4846 \SpecialChar ~
4847 \SpecialChar ~
4848  rlc\SpecialChar ~
4849  a 
4850 \newline 
4851 \SpecialChar ~
4852 \SpecialChar ~
4853  000D E4\SpecialChar ~
4854 \SpecialChar ~
4855 \SpecialChar ~
4856 \SpecialChar ~
4857 \SpecialChar ~
4858 \SpecialChar ~
4859 \SpecialChar ~
4860 \SpecialChar ~
4861 \SpecialChar ~
4862 \SpecialChar ~
4863 \SpecialChar ~
4864 \SpecialChar ~
4865 \SpecialChar ~
4866 \SpecialChar ~
4867 \SpecialChar ~
4868 \SpecialChar ~
4869 \SpecialChar ~
4870 \SpecialChar ~
4871  64\SpecialChar ~
4872 \SpecialChar ~
4873 \SpecialChar ~
4874 \SpecialChar ~
4875 \SpecialChar ~
4876 \SpecialChar ~
4877 \SpecialChar ~
4878 \SpecialChar ~
4879  clr\SpecialChar ~
4880  a 
4881 \newline 
4882 \SpecialChar ~
4883 \SpecialChar ~
4884  000E 13\SpecialChar ~
4885 \SpecialChar ~
4886 \SpecialChar ~
4887 \SpecialChar ~
4888 \SpecialChar ~
4889 \SpecialChar ~
4890 \SpecialChar ~
4891 \SpecialChar ~
4892 \SpecialChar ~
4893 \SpecialChar ~
4894 \SpecialChar ~
4895 \SpecialChar ~
4896 \SpecialChar ~
4897 \SpecialChar ~
4898 \SpecialChar ~
4899 \SpecialChar ~
4900 \SpecialChar ~
4901 \SpecialChar ~
4902  65\SpecialChar ~
4903 \SpecialChar ~
4904 \SpecialChar ~
4905 \SpecialChar ~
4906 \SpecialChar ~
4907 \SpecialChar ~
4908 \SpecialChar ~
4909 \SpecialChar ~
4910  rrc\SpecialChar ~
4911  a 
4912 \newline 
4913 \SpecialChar ~
4914 \SpecialChar ~
4915  000F F5*02\SpecialChar ~
4916 \SpecialChar ~
4917 \SpecialChar ~
4918 \SpecialChar ~
4919 \SpecialChar ~
4920 \SpecialChar ~
4921 \SpecialChar ~
4922 \SpecialChar ~
4923 \SpecialChar ~
4924 \SpecialChar ~
4925 \SpecialChar ~
4926 \SpecialChar ~
4927 \SpecialChar ~
4928 \SpecialChar ~
4929 \SpecialChar ~
4930  66\SpecialChar ~
4931 \SpecialChar ~
4932 \SpecialChar ~
4933 \SpecialChar ~
4934 \SpecialChar ~
4935 \SpecialChar ~
4936 \SpecialChar ~
4937 \SpecialChar ~
4938  mov\SpecialChar ~
4939  _foo_hob_1_1,a
4940 \newline 
4941
4942 \newline 
4943
4944 \family default 
4945 Variations of this case however will 
4946 \emph on 
4947 not
4948 \emph default 
4949  be recognized.
4950  It is a standard C expression, so I heartily recommend this be the only
4951  way to get the highest order bit, (it is portable).
4952  Of course it will be recognized even if it is embedded in other expressions,
4953  e.g.:
4954 \newline 
4955
4956 \newline 
4957
4958 \family typewriter 
4959 xyz = gint + ((gint >> 15) & 1);
4960 \family default 
4961
4962 \newline 
4963
4964 \newline 
4965 will still be recognized.
4966 \layout Subsubsection
4967
4968 Peep-hole Optimizer
4969 \layout Standard
4970
4971 The compiler uses a rule based, pattern matching and re-writing mechanism
4972  for peep-hole optimization.
4973  It is inspired by 
4974 \emph on 
4975 copt
4976 \emph default 
4977  a peep-hole optimizer by Christopher W.
4978  Fraser (cwfraser@microsoft.com).
4979  A default set of rules are compiled into the compiler, additional rules
4980  may be added with the 
4981 \emph on 
4982 --peep-file <filename>
4983 \emph default 
4984  option.
4985  The rule language is best illustrated with examples.
4986 \newline 
4987
4988 \newline 
4989
4990 \family typewriter 
4991 replace { 
4992 \newline 
4993 \SpecialChar ~
4994 \SpecialChar ~
4995 mov %1,a 
4996 \newline 
4997 \SpecialChar ~
4998 \SpecialChar ~
4999 mov a,%1
5000 \newline 
5001 } by {
5002 \newline 
5003 \SpecialChar ~
5004 \SpecialChar ~
5005 mov %1,a
5006 \newline 
5007 }
5008 \family default 
5009
5010 \newline 
5011
5012 \newline 
5013 The above rule will change the following assembly sequence:
5014 \newline 
5015
5016 \newline 
5017
5018 \family typewriter 
5019 \SpecialChar ~
5020 \SpecialChar ~
5021 mov r1,a 
5022 \newline 
5023 \SpecialChar ~
5024 \SpecialChar ~
5025 mov a,r1
5026 \family default 
5027
5028 \newline 
5029
5030 \newline 
5031 to
5032 \newline 
5033
5034 \newline 
5035
5036 \family typewriter 
5037 mov r1,a
5038 \family default 
5039
5040 \newline 
5041
5042 \newline 
5043 Note: All occurrences of a 
5044 \emph on 
5045 %n
5046 \emph default 
5047  (pattern variable) must denote the same string.
5048  With the above rule, the assembly sequence:
5049 \newline 
5050
5051 \newline 
5052
5053 \family typewriter 
5054 \SpecialChar ~
5055 \SpecialChar ~
5056 mov r1,a 
5057 \newline 
5058 \SpecialChar ~
5059 \SpecialChar ~
5060 mov a,r2
5061 \family default 
5062
5063 \newline 
5064
5065 \newline 
5066 will remain unmodified.
5067 \newline 
5068
5069 \newline 
5070 Other special case optimizations may be added by the user (via 
5071 \emph on 
5072 --peep-file option
5073 \emph default 
5074 ).
5075  E.g.
5076  some variants of the 8051 MCU allow only 
5077 \family typewriter 
5078 ajmp
5079 \family default 
5080  and 
5081 \family typewriter 
5082 acall
5083 \family default 
5084 .
5085  The following two rules will change all 
5086 \family typewriter 
5087 ljmp
5088 \family default 
5089  and 
5090 \family typewriter 
5091 lcall
5092 \family default 
5093  to 
5094 \family typewriter 
5095 ajmp
5096 \family default 
5097  and 
5098 \family typewriter 
5099 acall
5100 \family default 
5101
5102 \newline 
5103
5104 \newline 
5105
5106 \family typewriter 
5107 replace { lcall %1 } by { acall %1 } 
5108 \newline 
5109 replace { ljmp %1 } by { ajmp %1 }
5110 \family default 
5111
5112 \newline 
5113
5114 \newline 
5115 The 
5116 \emph on 
5117 inline-assembler code
5118 \emph default 
5119  is also passed through the peep hole optimizer, thus the peephole optimizer
5120  can also be used as an assembly level macro expander.
5121  The rules themselves are MCU dependent whereas the rule language infra-structur
5122 e is MCU independent.
5123  Peephole optimization rules for other MCU can be easily programmed using
5124  the rule language.
5125 \newline 
5126
5127 \newline 
5128 The syntax for a rule is as follows:
5129 \newline 
5130
5131 \newline 
5132
5133 \family typewriter 
5134 rule := replace [ restart ] '{' <assembly sequence> '
5135 \backslash 
5136 n' 
5137 \newline 
5138 \SpecialChar ~
5139  \SpecialChar ~
5140  \SpecialChar ~
5141  \SpecialChar ~
5142  \SpecialChar ~
5143  \SpecialChar ~
5144  \SpecialChar ~
5145  \SpecialChar ~
5146  \SpecialChar ~
5147  \SpecialChar ~
5148  \SpecialChar ~
5149  \SpecialChar ~
5150  \SpecialChar ~
5151  \SpecialChar ~
5152  '}' by '{' '
5153 \backslash 
5154 n' 
5155 \newline 
5156 \SpecialChar ~
5157  \SpecialChar ~
5158  \SpecialChar ~
5159  \SpecialChar ~
5160  \SpecialChar ~
5161  \SpecialChar ~
5162  \SpecialChar ~
5163  \SpecialChar ~
5164  \SpecialChar ~
5165  \SpecialChar ~
5166  \SpecialChar ~
5167  \SpecialChar ~
5168  \SpecialChar ~
5169  \SpecialChar ~
5170  \SpecialChar ~
5171  \SpecialChar ~
5172  <assembly sequence> '
5173 \backslash 
5174 n' 
5175 \newline 
5176 \SpecialChar ~
5177  \SpecialChar ~
5178  \SpecialChar ~
5179  \SpecialChar ~
5180  \SpecialChar ~
5181  \SpecialChar ~
5182  \SpecialChar ~
5183  \SpecialChar ~
5184  \SpecialChar ~
5185  \SpecialChar ~
5186  \SpecialChar ~
5187  \SpecialChar ~
5188  \SpecialChar ~
5189  \SpecialChar ~
5190  '}' [if <functionName> ] '
5191 \backslash 
5192 n' 
5193 \newline 
5194
5195 \family default 
5196
5197 \newline 
5198 <assembly sequence> := assembly instruction (each instruction including
5199  labels must be on a separate line).
5200 \newline 
5201
5202 \newline 
5203 The optimizer will apply to the rules one by one from the top in the sequence
5204  of their appearance, it will terminate when all rules are exhausted.
5205  If the 'restart' option is specified, then the optimizer will start matching
5206  the rules again from the top, this option for a rule is expensive (performance)
5207 , it is intended to be used in situations where a transformation will trigger
5208  the same rule again.
5209  A good example of this the following rule:
5210 \newline 
5211
5212 \newline 
5213 replace restart { 
5214 \newline 
5215 \SpecialChar ~
5216 \SpecialChar ~
5217 pop %1 
5218 \newline 
5219 \SpecialChar ~
5220 \SpecialChar ~
5221 push %1 } by { 
5222 \newline 
5223 \SpecialChar ~
5224 \SpecialChar ~
5225 ; nop 
5226 \newline 
5227 }
5228 \newline 
5229
5230 \newline 
5231 Note that the replace pattern cannot be a blank, but can be a comment line.
5232  Without the 'restart' option only the inner most 'pop' 'push' pair would
5233  be eliminated, i.e.:
5234 \newline 
5235
5236 \newline 
5237
5238 \family typewriter 
5239 \SpecialChar ~
5240 \SpecialChar ~
5241 pop ar1 
5242 \newline 
5243 \SpecialChar ~
5244 \SpecialChar ~
5245 pop ar2 
5246 \newline 
5247 \SpecialChar ~
5248 \SpecialChar ~
5249 push ar2 
5250 \newline 
5251 \SpecialChar ~
5252 \SpecialChar ~
5253 push ar1
5254 \family default 
5255
5256 \newline 
5257
5258 \newline 
5259 would result in:
5260 \newline 
5261
5262 \newline 
5263
5264 \family typewriter 
5265 pop ar1 
5266 \newline 
5267 ; nop 
5268 \newline 
5269 push ar1
5270 \family default 
5271
5272 \newline 
5273
5274 \newline 
5275
5276 \emph on 
5277 with
5278 \emph default 
5279  the restart option the rule will be applied again to the resulting code
5280  and then all the pop-push pairs will be eliminated to yield:
5281 \newline 
5282
5283 \newline 
5284
5285 \family typewriter 
5286 ; nop 
5287 \newline 
5288 ; nop
5289 \family default 
5290
5291 \newline 
5292
5293 \newline 
5294 A conditional function can be attached to a rule.
5295  Attaching rules are somewhat more involved, let me illustrate this with
5296  an example.
5297 \newline 
5298
5299 \newline 
5300
5301 \family typewriter 
5302 replace { 
5303 \newline 
5304 \SpecialChar ~
5305  \SpecialChar ~
5306  \SpecialChar ~
5307 ljmp %5 
5308 \newline 
5309 %2:} by { 
5310 \newline 
5311 \SpecialChar ~
5312  \SpecialChar ~
5313  \SpecialChar ~
5314 sjmp %5 
5315 \newline 
5316 %2:} if labelInRange
5317 \family default 
5318
5319 \newline 
5320
5321 \newline 
5322 The optimizer does a look-up of a function name table defined in function
5323  
5324 \emph on 
5325 callFuncByName
5326 \emph default 
5327  in the source file SDCCpeeph.c, with the name 
5328 \emph on 
5329 labelInRange
5330 \emph default 
5331 .
5332  If it finds a corresponding entry the function is called.
5333  Note there can be no parameters specified for these functions, in this
5334  case the use of 
5335 \emph on 
5336 %5
5337 \emph default 
5338  is crucial, since the function 
5339 \emph on 
5340 labelInRange
5341 \emph default 
5342  expects to find the label in that particular variable (the hash table containin
5343 g the variable bindings is passed as a parameter).
5344  If you want to code more such functions, take a close look at the function
5345  labelInRange and the calling mechanism in source file SDCCpeeph.c.
5346  I know this whole thing is a little kludgey, but maybe some day we will
5347  have some better means.
5348  If you are looking at this file, you will also see the default rules that
5349  are compiled into the compiler, you can add your own rules in the default
5350  set there if you get tired of specifying the --peep-file option.
5351 \newline 
5352
5353 \newline 
5354
5355 \emph on 
5356 <pending: this is as far as I got>
5357 \layout Subsection
5358
5359 Pragmas
5360 \layout Standard
5361
5362 SDCC supports the following #pragma directives.
5363  This directives are applicable only at a function level.
5364 \layout Itemize
5365
5366 SAVE - this will save all the current options.
5367 \layout Itemize
5368
5369 RESTORE - will restore the saved options from the last save.
5370  Note that SAVES & RESTOREs cannot be nested.
5371  SDCC uses the same buffer to save the options each time a SAVE is called.
5372 \layout Itemize
5373
5374 NOGCSE - will stop global subexpression elimination.
5375 \layout Itemize
5376
5377 NOINDUCTION - will stop loop induction optimizations.
5378 \layout Itemize
5379
5380 NOJTBOUND - will not generate code for boundary value checking, when switch
5381  statements are turned into jump-tables.
5382 \layout Itemize
5383
5384 NOOVERLAY - the compiler will not overlay the parameters and local variables
5385  of a function.
5386 \layout Itemize
5387
5388 NOLOOPREVERSE - Will not do loop reversal optimization
5389 \layout Itemize
5390
5391 EXCLUDE NONE | {acc[,b[,dpl[,dph]]] - The exclude pragma disables generation
5392  of pair of push/pop instruction in ISR function (using interrupt keyword).
5393  The directive should be placed immediately before the ISR function definition
5394  and it affects ALL ISR functions following it.
5395  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
5396 EXCLUDE\SpecialChar ~
5397 none.
5398 \layout Itemize
5399
5400 CALLEE-SAVES function1[,function2[,function3...]] - The compiler by default
5401  uses a caller saves convention for register saving across function calls,
5402  however this can cause unneccessary register pushing & popping when calling
5403  small functions from larger functions.
5404  This option can be used to switch the register saving convention for the
5405  function names specified.
5406  The compiler will not save registers when calling these functions, extra
5407  code will be generated at the entry & exit for these functions to save
5408  & restore the registers used by these functions, this can SUBSTANTIALLY
5409  reduce code & improve run time performance of the generated code.
5410  In future the compiler (with interprocedural analysis) will be able to
5411  determine the appropriate scheme to use for each function call.
5412  If --callee-saves command line option is used, the function names specified
5413  in #pragma\SpecialChar ~
5414 CALLEE-SAVES is appended to the list of functions specified inthe
5415  command line.
5416 \layout Standard
5417
5418 The pragma's are intended to be used to turn-off certain optimizations which
5419  might cause the compiler to generate extra stack / data space to store
5420  compiler generated temporary variables.
5421  This usually happens in large functions.
5422  Pragma directives should be used as shown in the following example, they
5423  are used to control options & optimizations for a given function; pragmas
5424  should be placed before and/or after a function, placing pragma's inside
5425  a function body could have unpredictable results.
5426 \layout Standard
5427
5428 eg
5429 \layout Standard
5430
5431 #pragma SAVE \SpecialChar ~
5432  /* save the current settings */ 
5433 \newline 
5434 #pragma NOGCSE /* turnoff global subexpression elimination */ 
5435 \newline 
5436 #pragma NOINDUCTION /* turn off induction optimizations */ 
5437 \newline 
5438 int foo () 
5439 \newline 
5440
5441 \newline 
5442 \SpecialChar ~
5443  \SpecialChar ~
5444  ...
5445  
5446 \newline 
5447 \SpecialChar ~
5448  \SpecialChar ~
5449  /* large code */ 
5450 \newline 
5451 \SpecialChar ~
5452  \SpecialChar ~
5453  ...
5454  
5455 \newline 
5456
5457 \newline 
5458 #pragma RESTORE /* turn the optimizations back on */
5459 \layout Standard
5460
5461 The compiler will generate a warning message when extra space is allocated.
5462  It is strongly recommended that the SAVE and RESTORE pragma's be used when
5463  changing options for a function.
5464 \layout Subsection
5465
5466 Library Routines
5467 \layout Standard
5468
5469 The following library routines are provided for your convenience.
5470 \layout Standard
5471
5472 stdio.h - Contains the following functions printf & sprintf these routines
5473  are developed by Martijn van Balen <balen@natlab.research.philips.com>.
5474  
5475 \layout Standard
5476
5477 %[flags][width][b|B|l|L]type
5478 \layout Standard
5479
5480 \SpecialChar ~
5481 \SpecialChar ~
5482 \SpecialChar ~
5483 \SpecialChar ~
5484 \SpecialChar ~
5485 \SpecialChar ~
5486 \SpecialChar ~
5487 \SpecialChar ~
5488 \SpecialChar ~
5489 \SpecialChar ~
5490  flags: -\SpecialChar ~
5491 \SpecialChar ~
5492 \SpecialChar ~
5493 \SpecialChar ~
5494 \SpecialChar ~
5495 \SpecialChar ~
5496 \SpecialChar ~
5497  left justify output in specified field width 
5498 \newline 
5499 \SpecialChar ~
5500 \SpecialChar ~
5501 \SpecialChar ~
5502 \SpecialChar ~
5503 \SpecialChar ~
5504 \SpecialChar ~
5505 \SpecialChar ~
5506 \SpecialChar ~
5507 \SpecialChar ~
5508 \SpecialChar ~
5509 \SpecialChar ~
5510 \SpecialChar ~
5511 \SpecialChar ~
5512 \SpecialChar ~
5513 \SpecialChar ~
5514 \SpecialChar ~
5515  +\SpecialChar ~
5516 \SpecialChar ~
5517 \SpecialChar ~
5518 \SpecialChar ~
5519 \SpecialChar ~
5520 \SpecialChar ~
5521 \SpecialChar ~
5522  prefix output with +/- sign if output is signed type 
5523 \newline 
5524 \SpecialChar ~
5525 \SpecialChar ~
5526 \SpecialChar ~
5527 \SpecialChar ~
5528 \SpecialChar ~
5529 \SpecialChar ~
5530 \SpecialChar ~
5531 \SpecialChar ~
5532 \SpecialChar ~
5533 \SpecialChar ~
5534 \SpecialChar ~
5535 \SpecialChar ~
5536 \SpecialChar ~
5537 \SpecialChar ~
5538 \SpecialChar ~
5539 \SpecialChar ~
5540  space\SpecialChar ~
5541 \SpecialChar ~
5542 \SpecialChar ~
5543  prefix output with a blank if it's a signed positive value 
5544 \newline 
5545 \SpecialChar ~
5546 \SpecialChar ~
5547 \SpecialChar ~
5548 \SpecialChar ~
5549 \SpecialChar ~
5550 \SpecialChar ~
5551 \SpecialChar ~
5552 \SpecialChar ~
5553 \SpecialChar ~
5554  width:\SpecialChar ~
5555 \SpecialChar ~
5556 \SpecialChar ~
5557 \SpecialChar ~
5558 \SpecialChar ~
5559 \SpecialChar ~
5560 \SpecialChar ~
5561 \SpecialChar ~
5562 \SpecialChar ~
5563  specifies minimum number of characters outputted for numbers 
5564 \newline 
5565 \SpecialChar ~
5566 \SpecialChar ~
5567 \SpecialChar ~
5568 \SpecialChar ~
5569 \SpecialChar ~
5570 \SpecialChar ~
5571 \SpecialChar ~
5572 \SpecialChar ~
5573 \SpecialChar ~
5574 \SpecialChar ~
5575 \SpecialChar ~
5576 \SpecialChar ~
5577 \SpecialChar ~
5578 \SpecialChar ~
5579 \SpecialChar ~
5580 \SpecialChar ~
5581 \SpecialChar ~
5582 \SpecialChar ~
5583 \SpecialChar ~
5584 \SpecialChar ~
5585 \SpecialChar ~
5586 \SpecialChar ~
5587 \SpecialChar ~
5588 \SpecialChar ~
5589 \SpecialChar ~
5590  or strings.
5591  
5592 \newline 
5593 \SpecialChar ~
5594 \SpecialChar ~
5595 \SpecialChar ~
5596 \SpecialChar ~
5597 \SpecialChar ~
5598 \SpecialChar ~
5599 \SpecialChar ~
5600 \SpecialChar ~
5601 \SpecialChar ~
5602 \SpecialChar ~
5603 \SpecialChar ~
5604 \SpecialChar ~
5605 \SpecialChar ~
5606 \SpecialChar ~
5607 \SpecialChar ~
5608 \SpecialChar ~
5609 \SpecialChar ~
5610 \SpecialChar ~
5611 \SpecialChar ~
5612 \SpecialChar ~
5613 \SpecialChar ~
5614 \SpecialChar ~
5615 \SpecialChar ~
5616 \SpecialChar ~
5617 \SpecialChar ~
5618  - For numbers, spaces are added on the left when needed.
5619  
5620 \newline 
5621 \SpecialChar ~
5622 \SpecialChar ~
5623 \SpecialChar ~
5624 \SpecialChar ~
5625 \SpecialChar ~
5626 \SpecialChar ~
5627 \SpecialChar ~
5628 \SpecialChar ~
5629 \SpecialChar ~
5630 \SpecialChar ~
5631 \SpecialChar ~
5632 \SpecialChar ~
5633 \SpecialChar ~
5634 \SpecialChar ~
5635 \SpecialChar ~
5636 \SpecialChar ~
5637 \SpecialChar ~
5638 \SpecialChar ~
5639 \SpecialChar ~
5640 \SpecialChar ~
5641 \SpecialChar ~
5642 \SpecialChar ~
5643 \SpecialChar ~
5644 \SpecialChar ~
5645 \SpecialChar ~
5646 \SpecialChar ~
5647 \SpecialChar ~
5648  If width starts with a zero character, zeroes and used 
5649 \newline 
5650 \SpecialChar ~
5651 \SpecialChar ~
5652 \SpecialChar ~
5653 \SpecialChar ~
5654 \SpecialChar ~
5655 \SpecialChar ~
5656 \SpecialChar ~
5657 \SpecialChar ~
5658 \SpecialChar ~
5659 \SpecialChar ~
5660 \SpecialChar ~
5661 \SpecialChar ~
5662 \SpecialChar ~
5663 \SpecialChar ~
5664 \SpecialChar ~
5665 \SpecialChar ~
5666 \SpecialChar ~
5667 \SpecialChar ~
5668 \SpecialChar ~
5669 \SpecialChar ~
5670 \SpecialChar ~
5671 \SpecialChar ~
5672 \SpecialChar ~
5673 \SpecialChar ~
5674 \SpecialChar ~
5675 \SpecialChar ~
5676 \SpecialChar ~
5677  instead of spaces.
5678  
5679 \newline 
5680 \SpecialChar ~
5681 \SpecialChar ~
5682 \SpecialChar ~
5683 \SpecialChar ~
5684 \SpecialChar ~
5685 \SpecialChar ~
5686 \SpecialChar ~
5687 \SpecialChar ~
5688 \SpecialChar ~
5689 \SpecialChar ~
5690 \SpecialChar ~
5691 \SpecialChar ~
5692 \SpecialChar ~
5693 \SpecialChar ~
5694 \SpecialChar ~
5695 \SpecialChar ~
5696 \SpecialChar ~
5697 \SpecialChar ~
5698 \SpecialChar ~
5699 \SpecialChar ~
5700 \SpecialChar ~
5701 \SpecialChar ~
5702 \SpecialChar ~
5703 \SpecialChar ~
5704 \SpecialChar ~
5705  - For strings, spaces are are added on the left or right (when 
5706 \newline 
5707 \SpecialChar ~
5708 \SpecialChar ~
5709 \SpecialChar ~
5710 \SpecialChar ~
5711 \SpecialChar ~
5712 \SpecialChar ~
5713 \SpecialChar ~
5714 \SpecialChar ~
5715 \SpecialChar ~
5716 \SpecialChar ~
5717 \SpecialChar ~
5718 \SpecialChar ~
5719 \SpecialChar ~
5720 \SpecialChar ~
5721 \SpecialChar ~
5722 \SpecialChar ~
5723 \SpecialChar ~
5724 \SpecialChar ~
5725 \SpecialChar ~
5726 \SpecialChar ~
5727 \SpecialChar ~
5728 \SpecialChar ~
5729 \SpecialChar ~
5730 \SpecialChar ~
5731 \SpecialChar ~
5732 \SpecialChar ~
5733 \SpecialChar ~
5734  flag '-' is used) when needed.
5735  
5736 \newline 
5737 \SpecialChar ~
5738 \SpecialChar ~
5739 \SpecialChar ~
5740 \SpecialChar ~
5741 \SpecialChar ~
5742 \SpecialChar ~
5743 \SpecialChar ~
5744 \SpecialChar ~
5745 \SpecialChar ~
5746 \SpecialChar ~
5747 \SpecialChar ~
5748 \SpecialChar ~
5749 \SpecialChar ~
5750 \SpecialChar ~
5751 \SpecialChar ~
5752 \SpecialChar ~
5753 \SpecialChar ~
5754 \SpecialChar ~
5755 \SpecialChar ~
5756 \SpecialChar ~
5757 \SpecialChar ~
5758 \SpecialChar ~
5759 \SpecialChar ~
5760 \SpecialChar ~
5761 \SpecialChar ~
5762  
5763 \newline 
5764 \SpecialChar ~
5765 \SpecialChar ~
5766 \SpecialChar ~
5767 \SpecialChar ~
5768 \SpecialChar ~
5769 \SpecialChar ~
5770 \SpecialChar ~
5771 \SpecialChar ~
5772 \SpecialChar ~
5773  b/B:\SpecialChar ~
5774 \SpecialChar ~
5775 \SpecialChar ~
5776 \SpecialChar ~
5777 \SpecialChar ~
5778 \SpecialChar ~
5779 \SpecialChar ~
5780 \SpecialChar ~
5781 \SpecialChar ~
5782 \SpecialChar ~
5783 \SpecialChar ~
5784  byte argument (used by d, u, o, x, X) 
5785 \newline 
5786 \SpecialChar ~
5787 \SpecialChar ~
5788 \SpecialChar ~
5789 \SpecialChar ~
5790 \SpecialChar ~
5791 \SpecialChar ~
5792 \SpecialChar ~
5793 \SpecialChar ~
5794 \SpecialChar ~
5795  l/L:\SpecialChar ~
5796 \SpecialChar ~
5797 \SpecialChar ~
5798 \SpecialChar ~
5799 \SpecialChar ~
5800 \SpecialChar ~
5801 \SpecialChar ~
5802 \SpecialChar ~
5803 \SpecialChar ~
5804 \SpecialChar ~
5805 \SpecialChar ~
5806  long argument (used by d, u, o, x, X)
5807 \newline 
5808 \SpecialChar ~
5809 \SpecialChar ~
5810 \SpecialChar ~
5811 \SpecialChar ~
5812 \SpecialChar ~
5813 \SpecialChar ~
5814 \SpecialChar ~
5815 \SpecialChar ~
5816 \SpecialChar ~
5817  type:\SpecialChar ~
5818  d\SpecialChar ~
5819 \SpecialChar ~
5820 \SpecialChar ~
5821 \SpecialChar ~
5822 \SpecialChar ~
5823 \SpecialChar ~
5824 \SpecialChar ~
5825  decimal number 
5826 \newline 
5827 \SpecialChar ~
5828 \SpecialChar ~
5829 \SpecialChar ~
5830 \SpecialChar ~
5831 \SpecialChar ~
5832 \SpecialChar ~
5833 \SpecialChar ~
5834 \SpecialChar ~
5835 \SpecialChar ~
5836 \SpecialChar ~
5837 \SpecialChar ~
5838 \SpecialChar ~
5839 \SpecialChar ~
5840 \SpecialChar ~
5841 \SpecialChar ~
5842 \SpecialChar ~
5843  u\SpecialChar ~
5844 \SpecialChar ~
5845 \SpecialChar ~
5846 \SpecialChar ~
5847 \SpecialChar ~
5848 \SpecialChar ~
5849 \SpecialChar ~
5850  unsigned decimal number 
5851 \newline 
5852 \SpecialChar ~
5853 \SpecialChar ~
5854 \SpecialChar ~
5855 \SpecialChar ~
5856 \SpecialChar ~
5857 \SpecialChar ~
5858 \SpecialChar ~
5859 \SpecialChar ~
5860 \SpecialChar ~
5861 \SpecialChar ~
5862 \SpecialChar ~
5863 \SpecialChar ~
5864 \SpecialChar ~
5865 \SpecialChar ~
5866 \SpecialChar ~
5867 \SpecialChar ~
5868  o\SpecialChar ~
5869 \SpecialChar ~
5870 \SpecialChar ~
5871 \SpecialChar ~
5872 \SpecialChar ~
5873 \SpecialChar ~
5874 \SpecialChar ~
5875  unsigned octal number 
5876 \newline 
5877 \SpecialChar ~
5878 \SpecialChar ~
5879 \SpecialChar ~
5880 \SpecialChar ~
5881 \SpecialChar ~
5882 \SpecialChar ~
5883 \SpecialChar ~
5884 \SpecialChar ~
5885 \SpecialChar ~
5886 \SpecialChar ~
5887 \SpecialChar ~
5888 \SpecialChar ~
5889 \SpecialChar ~
5890 \SpecialChar ~
5891 \SpecialChar ~
5892 \SpecialChar ~
5893  x\SpecialChar ~
5894 \SpecialChar ~
5895 \SpecialChar ~
5896 \SpecialChar ~
5897 \SpecialChar ~
5898 \SpecialChar ~
5899 \SpecialChar ~
5900  unsigned hexadecimal number (0-9, a-f) 
5901 \newline 
5902 \SpecialChar ~
5903 \SpecialChar ~
5904 \SpecialChar ~
5905 \SpecialChar ~
5906 \SpecialChar ~
5907 \SpecialChar ~
5908 \SpecialChar ~
5909 \SpecialChar ~
5910 \SpecialChar ~
5911 \SpecialChar ~
5912 \SpecialChar ~
5913 \SpecialChar ~
5914 \SpecialChar ~
5915 \SpecialChar ~
5916 \SpecialChar ~
5917 \SpecialChar ~
5918  X\SpecialChar ~
5919 \SpecialChar ~
5920 \SpecialChar ~
5921 \SpecialChar ~
5922 \SpecialChar ~
5923 \SpecialChar ~
5924 \SpecialChar ~
5925  unsigned hexadecimal number (0-9, A-F) 
5926 \newline 
5927 \SpecialChar ~
5928 \SpecialChar ~
5929 \SpecialChar ~
5930 \SpecialChar ~
5931 \SpecialChar ~
5932 \SpecialChar ~
5933 \SpecialChar ~
5934 \SpecialChar ~
5935 \SpecialChar ~
5936 \SpecialChar ~
5937 \SpecialChar ~
5938 \SpecialChar ~
5939 \SpecialChar ~
5940 \SpecialChar ~
5941 \SpecialChar ~
5942 \SpecialChar ~
5943  c\SpecialChar ~
5944 \SpecialChar ~
5945 \SpecialChar ~
5946 \SpecialChar ~
5947 \SpecialChar ~
5948 \SpecialChar ~
5949 \SpecialChar ~
5950  character 
5951 \newline 
5952 \SpecialChar ~
5953 \SpecialChar ~
5954 \SpecialChar ~
5955 \SpecialChar ~
5956 \SpecialChar ~
5957 \SpecialChar ~
5958 \SpecialChar ~
5959 \SpecialChar ~
5960 \SpecialChar ~
5961 \SpecialChar ~
5962 \SpecialChar ~
5963 \SpecialChar ~
5964 \SpecialChar ~
5965 \SpecialChar ~
5966 \SpecialChar ~
5967 \SpecialChar ~
5968  s\SpecialChar ~
5969 \SpecialChar ~
5970 \SpecialChar ~
5971 \SpecialChar ~
5972 \SpecialChar ~
5973 \SpecialChar ~
5974 \SpecialChar ~
5975  string (generic pointer) 
5976 \newline 
5977 \SpecialChar ~
5978 \SpecialChar ~
5979 \SpecialChar ~
5980 \SpecialChar ~
5981 \SpecialChar ~
5982 \SpecialChar ~
5983 \SpecialChar ~
5984 \SpecialChar ~
5985 \SpecialChar ~
5986 \SpecialChar ~
5987 \SpecialChar ~
5988 \SpecialChar ~
5989 \SpecialChar ~
5990 \SpecialChar ~
5991 \SpecialChar ~
5992 \SpecialChar ~
5993  p\SpecialChar ~
5994 \SpecialChar ~
5995 \SpecialChar ~
5996 \SpecialChar ~
5997 \SpecialChar ~
5998 \SpecialChar ~
5999 \SpecialChar ~
6000  generic pointer (I:data/idata, C:code, X:xdata, P:paged) 
6001 \newline 
6002 \SpecialChar ~
6003 \SpecialChar ~
6004 \SpecialChar ~
6005 \SpecialChar ~
6006 \SpecialChar ~
6007 \SpecialChar ~
6008 \SpecialChar ~
6009 \SpecialChar ~
6010 \SpecialChar ~
6011 \SpecialChar ~
6012 \SpecialChar ~
6013 \SpecialChar ~
6014 \SpecialChar ~
6015 \SpecialChar ~
6016 \SpecialChar ~
6017 \SpecialChar ~
6018  f\SpecialChar ~
6019 \SpecialChar ~
6020 \SpecialChar ~
6021 \SpecialChar ~
6022 \SpecialChar ~
6023 \SpecialChar ~
6024 \SpecialChar ~
6025  float (still to be implemented)
6026 \layout Standard
6027
6028 Also contains a very simple version of printf (printf_small).
6029  This simplified version of printf supports only the following formats.
6030 \layout Standard
6031
6032 format\SpecialChar ~
6033 \SpecialChar ~
6034 \SpecialChar ~
6035 \SpecialChar ~
6036 \SpecialChar ~
6037 output\SpecialChar ~
6038 type\SpecialChar ~
6039 \SpecialChar ~
6040 \SpecialChar ~
6041 \SpecialChar ~
6042 \SpecialChar ~
6043 argument-type 
6044 \newline 
6045 %d \SpecialChar ~
6046 \SpecialChar ~
6047 \SpecialChar ~
6048 \SpecialChar ~
6049 \SpecialChar ~
6050 \SpecialChar ~
6051 \SpecialChar ~
6052 \SpecialChar ~
6053 decimal \SpecialChar ~
6054 \SpecialChar ~
6055 \SpecialChar ~
6056 \SpecialChar ~
6057 \SpecialChar ~
6058  short/int 
6059 \newline 
6060 %ld\SpecialChar ~
6061 \SpecialChar ~
6062 \SpecialChar ~
6063 \SpecialChar ~
6064 \SpecialChar ~
6065 \SpecialChar ~
6066 \SpecialChar ~
6067 \SpecialChar ~
6068 decimal\SpecialChar ~
6069 \SpecialChar ~
6070 \SpecialChar ~
6071 \SpecialChar ~
6072 \SpecialChar ~
6073 \SpecialChar ~
6074 \SpecialChar ~
6075 long 
6076 \newline 
6077 %hd\SpecialChar ~
6078 \SpecialChar ~
6079 \SpecialChar ~
6080 \SpecialChar ~
6081 \SpecialChar ~
6082 \SpecialChar ~
6083 \SpecialChar ~
6084 \SpecialChar ~
6085 decimal\SpecialChar ~
6086 \SpecialChar ~
6087 \SpecialChar ~
6088 \SpecialChar ~
6089 \SpecialChar ~
6090 \SpecialChar ~
6091 \SpecialChar ~
6092 char 
6093 \newline 
6094 %x\SpecialChar ~
6095 \SpecialChar ~
6096 \SpecialChar ~
6097 \SpecialChar ~
6098 \SpecialChar ~
6099 \SpecialChar ~
6100 \SpecialChar ~
6101 \SpecialChar ~
6102 hexadecimal\SpecialChar ~
6103 \SpecialChar ~
6104 \SpecialChar ~
6105 \SpecialChar ~
6106 short/int 
6107 \newline 
6108 %lx\SpecialChar ~
6109 \SpecialChar ~
6110 \SpecialChar ~
6111 \SpecialChar ~
6112 \SpecialChar ~
6113 \SpecialChar ~
6114 \SpecialChar ~
6115 hexadecimal\SpecialChar ~
6116 \SpecialChar ~
6117 \SpecialChar ~
6118 \SpecialChar ~
6119 long 
6120 \newline 
6121 %hx\SpecialChar ~
6122 \SpecialChar ~
6123 \SpecialChar ~
6124 \SpecialChar ~
6125 \SpecialChar ~
6126 \SpecialChar ~
6127 \SpecialChar ~
6128 hexadecimal\SpecialChar ~
6129 \SpecialChar ~
6130 \SpecialChar ~
6131 \SpecialChar ~
6132 char 
6133 \newline 
6134 %o\SpecialChar ~
6135 \SpecialChar ~
6136 \SpecialChar ~
6137 \SpecialChar ~
6138 \SpecialChar ~
6139 \SpecialChar ~
6140 \SpecialChar ~
6141 \SpecialChar ~
6142 \SpecialChar ~
6143 octal\SpecialChar ~
6144 \SpecialChar ~
6145 \SpecialChar ~
6146 \SpecialChar ~
6147 \SpecialChar ~
6148 \SpecialChar ~
6149 \SpecialChar ~
6150 \SpecialChar ~
6151 \SpecialChar ~
6152 short/int 
6153 \newline 
6154 %lo\SpecialChar ~
6155 \SpecialChar ~
6156 \SpecialChar ~
6157 \SpecialChar ~
6158 \SpecialChar ~
6159 \SpecialChar ~
6160 \SpecialChar ~
6161 \SpecialChar ~
6162 octal\SpecialChar ~
6163 \SpecialChar ~
6164 \SpecialChar ~
6165 \SpecialChar ~
6166 \SpecialChar ~
6167 \SpecialChar ~
6168 \SpecialChar ~
6169 \SpecialChar ~
6170 \SpecialChar ~
6171 long 
6172 \newline 
6173 %ho\SpecialChar ~
6174 \SpecialChar ~
6175 \SpecialChar ~
6176 \SpecialChar ~
6177 \SpecialChar ~
6178 \SpecialChar ~
6179 \SpecialChar ~
6180 \SpecialChar ~
6181 octal\SpecialChar ~
6182 \SpecialChar ~
6183 \SpecialChar ~
6184 \SpecialChar ~
6185 \SpecialChar ~
6186 \SpecialChar ~
6187 \SpecialChar ~
6188 \SpecialChar ~
6189 \SpecialChar ~
6190 char 
6191 \newline 
6192 %c\SpecialChar ~
6193 \SpecialChar ~
6194 \SpecialChar ~
6195 \SpecialChar ~
6196 \SpecialChar ~
6197 \SpecialChar ~
6198 \SpecialChar ~
6199 \SpecialChar ~
6200 character\SpecialChar ~
6201 \SpecialChar ~
6202 \SpecialChar ~
6203 \SpecialChar ~
6204 \SpecialChar ~
6205 \SpecialChar ~
6206 char 
6207 \newline 
6208 %s\SpecialChar ~
6209 \SpecialChar ~
6210 \SpecialChar ~
6211 \SpecialChar ~
6212 \SpecialChar ~
6213 \SpecialChar ~
6214 \SpecialChar ~
6215 \SpecialChar ~
6216 character\SpecialChar ~
6217 \SpecialChar ~
6218 \SpecialChar ~
6219 \SpecialChar ~
6220 \SpecialChar ~
6221 _generic pointer
6222 \layout Standard
6223
6224 The routine is very stack intesive, --stack-after-data parameter should
6225  be used when using this routine, the routine also takes about 1K of code
6226  space.
6227  It also expects an external function named putchar(char) to be present
6228  (this can be changed).
6229  When using the %s format the string / pointer should be cast to a generic
6230  pointer.
6231  eg.
6232 \layout Standard
6233
6234 printf_small(
6235 \begin_inset Quotes eld
6236 \end_inset 
6237
6238 my str %s, my int %d
6239 \backslash 
6240 n
6241 \begin_inset Quotes erd
6242 \end_inset 
6243
6244 ,(char _generic *)mystr,myint);
6245 \layout Itemize
6246
6247 stdarg.h - contains definition for the following macros to be used for variable
6248  parameter list, note that a function can have a variable parameter list
6249  if and only if it is 'reentrant'
6250 \begin_deeper 
6251 \layout Standard
6252
6253 va_list, va_start, va_arg, va_end.
6254 \end_deeper 
6255 \layout Itemize
6256
6257 setjmp.h - contains defintion for ANSI setjmp & longjmp routines.
6258  Note in this case setjmp & longjmp can be used between functions executing
6259  within the same register bank, if long jmp is executed from a function
6260  that is using a different register bank from the function issuing the setjmp
6261  function, the results may be unpredictable.
6262  The jump buffer requires 3 bytes of data (the stack pointer & a 16 byte
6263  return address), and can be placed in any address space.
6264 \layout Itemize
6265
6266 stdlib.h - contains the following functions.
6267 \begin_deeper 
6268 \layout Standard
6269
6270 atoi, atol.
6271 \end_deeper 
6272 \layout Itemize
6273
6274 string.h - contains the following functions.
6275 \begin_deeper 
6276 \layout Standard
6277
6278 strcpy, strncpy, strcat, strncat, strcmp, strncmp, strchr, strrchr, strspn,
6279  strcspn, strpbrk, strstr, strlen, strtok, memcpy, memcmp, memset.
6280 \end_deeper 
6281 \layout Itemize
6282
6283 ctype.h - contains the following routines.
6284 \begin_deeper 
6285 \layout Standard
6286
6287 iscntrl, isdigit, isgraph, islower, isupper, isprint, ispunct, isspace,
6288  isxdigit, isalnum, isalpha.
6289 \end_deeper 
6290 \layout Itemize
6291
6292 malloc.h - The malloc routines are developed by Dmitry S.
6293  Obukhov (dso@usa.net).
6294  These routines will allocate memory from the external ram.
6295  Here is a description on how to use them (as described by the author).
6296 \begin_deeper 
6297 \layout Standard
6298
6299 //Example: 
6300 \newline 
6301 \SpecialChar ~
6302 \SpecialChar ~
6303 \SpecialChar ~
6304 \SpecialChar ~
6305  //\SpecialChar ~
6306 \SpecialChar ~
6307 \SpecialChar ~
6308 \SpecialChar ~
6309  #define DYNAMIC_MEMORY_SIZE 0x2000 
6310 \newline 
6311 \SpecialChar ~
6312 \SpecialChar ~
6313 \SpecialChar ~
6314 \SpecialChar ~
6315  //\SpecialChar ~
6316 \SpecialChar ~
6317 \SpecialChar ~
6318 \SpecialChar ~
6319  .....
6320  
6321 \newline 
6322 \SpecialChar ~
6323 \SpecialChar ~
6324 \SpecialChar ~
6325 \SpecialChar ~
6326  //\SpecialChar ~
6327 \SpecialChar ~
6328 \SpecialChar ~
6329 \SpecialChar ~
6330  unsigned char xdata dynamic_memory_pool[DYNAMIC_MEMORY_SIZE]; 
6331 \newline 
6332 \SpecialChar ~
6333 \SpecialChar ~
6334 \SpecialChar ~
6335 \SpecialChar ~
6336  //\SpecialChar ~
6337 \SpecialChar ~
6338 \SpecialChar ~
6339 \SpecialChar ~
6340  unsigned char xdata * current_buffer; 
6341 \newline 
6342 \SpecialChar ~
6343 \SpecialChar ~
6344 \SpecialChar ~
6345 \SpecialChar ~
6346  //\SpecialChar ~
6347 \SpecialChar ~
6348 \SpecialChar ~
6349 \SpecialChar ~
6350  .....
6351  
6352 \newline 
6353 \SpecialChar ~
6354 \SpecialChar ~
6355 \SpecialChar ~
6356 \SpecialChar ~
6357  //\SpecialChar ~
6358 \SpecialChar ~
6359 \SpecialChar ~
6360 \SpecialChar ~
6361  void main(void) 
6362 \newline 
6363 \SpecialChar ~
6364 \SpecialChar ~
6365 \SpecialChar ~
6366 \SpecialChar ~
6367  //\SpecialChar ~
6368 \SpecialChar ~
6369 \SpecialChar ~
6370 \SpecialChar ~
6371  { 
6372 \newline 
6373 \SpecialChar ~
6374 \SpecialChar ~
6375 \SpecialChar ~
6376 \SpecialChar ~
6377  //\SpecialChar ~
6378 \SpecialChar ~
6379 \SpecialChar ~
6380 \SpecialChar ~
6381 \SpecialChar ~
6382 \SpecialChar ~
6383 \SpecialChar ~
6384 \SpecialChar ~
6385  ...
6386  
6387 \newline 
6388 \SpecialChar ~
6389 \SpecialChar ~
6390 \SpecialChar ~
6391 \SpecialChar ~
6392 \SpecialChar ~
6393 //\SpecialChar ~
6394 \SpecialChar ~
6395 \SpecialChar ~
6396 \SpecialChar ~
6397 \SpecialChar ~
6398 \SpecialChar ~
6399 \SpecialChar ~
6400 \SpecialChar ~
6401  init_dynamic_memory(dynamic_memory_pool,DYNAMIC_MEMORY_SIZE); 
6402 \newline 
6403 \SpecialChar ~
6404 \SpecialChar ~
6405 \SpecialChar ~
6406 \SpecialChar ~
6407  //\SpecialChar ~
6408 \SpecialChar ~
6409 \SpecialChar ~
6410 \SpecialChar ~
6411 \SpecialChar ~
6412 \SpecialChar ~
6413 \SpecialChar ~
6414 \SpecialChar ~
6415  //Now it's possible to use malloc.
6416  
6417 \newline 
6418 \SpecialChar ~
6419 \SpecialChar ~
6420 \SpecialChar ~
6421 \SpecialChar ~
6422  //\SpecialChar ~
6423 \SpecialChar ~
6424 \SpecialChar ~
6425 \SpecialChar ~
6426 \SpecialChar ~
6427 \SpecialChar ~
6428 \SpecialChar ~
6429 \SpecialChar ~
6430  ...
6431  
6432 \newline 
6433 \SpecialChar ~
6434 \SpecialChar ~
6435 \SpecialChar ~
6436 \SpecialChar ~
6437  //\SpecialChar ~
6438 \SpecialChar ~
6439 \SpecialChar ~
6440 \SpecialChar ~
6441 \SpecialChar ~
6442 \SpecialChar ~
6443 \SpecialChar ~
6444 \SpecialChar ~
6445  current_buffer = malloc(0x100); 
6446 \newline 
6447 \SpecialChar ~
6448 \SpecialChar ~
6449 \SpecialChar ~
6450 \SpecialChar ~
6451  //
6452 \end_deeper 
6453 \layout Itemize
6454
6455 serial.h - Serial IO routines are also developed by Dmitry S.
6456  Obukhov (dso@usa.net).
6457  These routines are interrupt driven with a 256 byte circular buffer, they
6458  also expect external ram to be present.
6459  Please see documentation in file SDCCDIR/sdcc51lib/serial.c.
6460  Note the header file 
6461 \begin_inset Quotes eld
6462 \end_inset 
6463
6464 serial.h
6465 \begin_inset Quotes erd
6466 \end_inset 
6467
6468  MUST be included in the file containing the 'main' function.
6469 \layout Itemize
6470
6471 ser.h - Alternate serial routine provided by Wolfgang Esslinger <wolfgang@WiredMi
6472 nds.com> these routines are more compact and faster.
6473  Please see documentation in file SDCCDIR/sdcc51lib/ser.c
6474 \layout Itemize
6475
6476 ser_ir.h - Another alternate set of serial routines provided by Josef Wolf
6477  <jw@raven.inka.de>, these routines do not use the external ram.
6478 \layout Itemize
6479
6480 reg51.h - contains register definitions for a standard 8051
6481 \layout Itemize
6482
6483 float.h - contains min, max and other floating point related stuff.
6484 \layout Standard
6485
6486 All library routines are compiled as --model-small, they are all non-reentrant,
6487  if you plan to use the large model or want to make these routines reentrant,
6488  then they will have to be recompiled with the appropriate compiler option.
6489 \layout Standard
6490
6491 Have not had time to do the more involved routines like printf, will get
6492  to them shortly.
6493 \layout Subsection
6494
6495 Interfacing with Assembly Routines
6496 \layout Subsection
6497
6498 Global Registers used for Parameter Passing
6499 \layout Standard
6500
6501 By default the compiler uses the global registers 
6502 \begin_inset Quotes eld
6503 \end_inset 
6504
6505 DPL,DPH,B,ACC
6506 \begin_inset Quotes erd
6507 \end_inset 
6508
6509  to pass the first parameter to a routine, the second parameter onwards
6510  is either allocated on the stack (for reentrant routines or --stack-auto
6511  is used) or in the internal / external ram (depending on the memory model).
6512  
6513 \layout Subsubsection
6514
6515 Assembler Routine(non-reentrant)
6516 \layout Standard
6517
6518 In the following example the function cfunc calls an assembler routine asm_func,
6519  which takes two parameters.
6520 \layout Standard
6521
6522 extern int asm_func(unsigned char, unsigned char);
6523 \layout Standard
6524
6525 \SpecialChar ~
6526
6527 \newline 
6528 int c_func (unsigned char i, unsigned char j) 
6529 \newline 
6530
6531 \newline 
6532 \SpecialChar ~
6533 \SpecialChar ~
6534 \SpecialChar ~
6535 \SpecialChar ~
6536 \SpecialChar ~
6537 \SpecialChar ~
6538 \SpecialChar ~
6539  return asm_func(i,j); 
6540 \newline 
6541
6542 \newline 
6543 int main() 
6544 \newline 
6545
6546 \newline 
6547 \SpecialChar ~
6548 \SpecialChar ~
6549 \SpecialChar ~
6550 return c_func(10,9); 
6551 \newline 
6552 }
6553 \layout Standard
6554
6555 The corresponding assembler function is:-
6556 \layout Standard
6557
6558 \SpecialChar ~
6559 \SpecialChar ~
6560 \SpecialChar ~
6561 \SpecialChar ~
6562 \SpecialChar ~
6563 \SpecialChar ~
6564 \SpecialChar ~
6565  .globl _asm_func_PARM_2 
6566 \newline 
6567 \SpecialChar ~
6568 \SpecialChar ~
6569 \SpecialChar ~
6570 \SpecialChar ~
6571 \SpecialChar ~
6572 \SpecialChar ~
6573 \SpecialChar ~
6574  .globl _asm_func 
6575 \newline 
6576 \SpecialChar ~
6577 \SpecialChar ~
6578 \SpecialChar ~
6579 \SpecialChar ~
6580 \SpecialChar ~
6581 \SpecialChar ~
6582 \SpecialChar ~
6583  .area OSEG 
6584 \newline 
6585 _asm_func_PARM_2:\SpecialChar ~
6586 \SpecialChar ~
6587 \SpecialChar ~
6588 \SpecialChar ~
6589 \SpecialChar ~
6590 \SpecialChar ~
6591  .ds\SpecialChar ~
6592 \SpecialChar ~
6593 \SpecialChar ~
6594 \SpecialChar ~
6595 \SpecialChar ~
6596  1 
6597 \newline 
6598 \SpecialChar ~
6599 \SpecialChar ~
6600 \SpecialChar ~
6601 \SpecialChar ~
6602 \SpecialChar ~
6603 \SpecialChar ~
6604 \SpecialChar ~
6605  .area CSEG 
6606 \newline 
6607 _asm_func: 
6608 \newline 
6609 \SpecialChar ~
6610 \SpecialChar ~
6611 \SpecialChar ~
6612 \SpecialChar ~
6613 \SpecialChar ~
6614 \SpecialChar ~
6615 \SpecialChar ~
6616  mov\SpecialChar ~
6617 \SpecialChar ~
6618 \SpecialChar ~
6619 \SpecialChar ~
6620  a,dpl 
6621 \newline 
6622 \SpecialChar ~
6623 \SpecialChar ~
6624 \SpecialChar ~
6625 \SpecialChar ~
6626 \SpecialChar ~
6627 \SpecialChar ~
6628 \SpecialChar ~
6629  add\SpecialChar ~
6630 \SpecialChar ~
6631 \SpecialChar ~
6632 \SpecialChar ~
6633  a,_asm_func_PARM_2 
6634 \newline 
6635 \SpecialChar ~
6636 \SpecialChar ~
6637 \SpecialChar ~
6638 \SpecialChar ~
6639 \SpecialChar ~
6640 \SpecialChar ~
6641 \SpecialChar ~
6642  mov\SpecialChar ~
6643 \SpecialChar ~
6644 \SpecialChar ~
6645 \SpecialChar ~
6646  dpl,a 
6647 \newline 
6648 \SpecialChar ~
6649 \SpecialChar ~
6650 \SpecialChar ~
6651 \SpecialChar ~
6652 \SpecialChar ~
6653 \SpecialChar ~
6654 \SpecialChar ~
6655  mov\SpecialChar ~
6656 \SpecialChar ~
6657 \SpecialChar ~
6658 \SpecialChar ~
6659  dpl,#0x00 
6660 \newline 
6661 \SpecialChar ~
6662 \SpecialChar ~
6663 \SpecialChar ~
6664 \SpecialChar ~
6665 \SpecialChar ~
6666 \SpecialChar ~
6667 \SpecialChar ~
6668  ret
6669 \layout Standard
6670
6671 Note here that the return values are placed in 'dpl' - One byte return value,
6672  'dpl' LSB & 'dph' MSB for two byte values.
6673  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
6674 b' & 'acc' for four byte values.
6675 \layout Standard
6676
6677 The parameter naming convention is _<function_name>_PARM_<n>, where n is
6678  the parameter number starting from 1, and counting from the left.
6679  The first parameter is passed in 
6680 \begin_inset Quotes eld
6681 \end_inset 
6682
6683 dpl
6684 \begin_inset Quotes erd
6685 \end_inset 
6686
6687  for One bye parameter, 
6688 \begin_inset Quotes eld
6689 \end_inset 
6690
6691 dptr
6692 \begin_inset Quotes erd
6693 \end_inset 
6694
6695  if two bytes, 
6696 \begin_inset Quotes eld
6697 \end_inset 
6698
6699 b,dptr
6700 \begin_inset Quotes erd
6701 \end_inset 
6702
6703  for three bytes and 
6704 \begin_inset Quotes eld
6705 \end_inset 
6706
6707 acc,b,dptr
6708 \begin_inset Quotes erd
6709 \end_inset 
6710
6711  for four bytes, the varaible name for the second parameter will be _<function_n
6712 ame>_PARM_2.
6713 \layout Standard
6714
6715 Assemble the assembler routine with the following command.
6716 \layout Standard
6717
6718 asx8051 -losg asmfunc.asm
6719 \layout Standard
6720
6721 Then compile and link the assembler routine to the C source file with the
6722  following command,
6723 \layout Standard
6724
6725 sdcc cfunc.c asmfunc.rel
6726 \layout Subsubsection
6727
6728 Assembler Routine(reentrant)
6729 \layout Standard
6730
6731 In this case the second parameter onwards will be passed on the stack, the
6732  parameters are pushed from right to left i.e.
6733  after the call the left most parameter will be on the top of the stack.
6734  Here is an example.
6735 \layout Standard
6736
6737 extern int asm_func(unsigned char, unsigned char);
6738 \layout Standard
6739
6740 \SpecialChar ~
6741
6742 \layout Standard
6743
6744 int c_func (unsigned char i, unsigned char j) reentrant 
6745 \newline 
6746
6747 \newline 
6748 \SpecialChar ~
6749 \SpecialChar ~
6750 \SpecialChar ~
6751 \SpecialChar ~
6752 \SpecialChar ~
6753 \SpecialChar ~
6754 \SpecialChar ~
6755  return asm_func(i,j); 
6756 \newline 
6757
6758 \newline 
6759 int main() 
6760 \newline 
6761
6762 \newline 
6763 \SpecialChar ~
6764 \SpecialChar ~
6765 \SpecialChar ~
6766 return c_func(10,9); 
6767 \newline 
6768 }
6769 \layout Standard
6770
6771 The corresponding assembler routine is.
6772 \layout Standard
6773
6774 \SpecialChar ~
6775 \SpecialChar ~
6776 \SpecialChar ~
6777 \SpecialChar ~
6778 \SpecialChar ~
6779 \SpecialChar ~
6780 \SpecialChar ~
6781  .globl _asm_func 
6782 \newline 
6783 _asm_func: 
6784 \newline 
6785 \SpecialChar ~
6786 \SpecialChar ~
6787 \SpecialChar ~
6788 \SpecialChar ~
6789 \SpecialChar ~
6790 \SpecialChar ~
6791 \SpecialChar ~
6792  push\SpecialChar ~
6793  _bp 
6794 \newline 
6795 \SpecialChar ~
6796 \SpecialChar ~
6797 \SpecialChar ~
6798 \SpecialChar ~
6799 \SpecialChar ~
6800 \SpecialChar ~
6801 \SpecialChar ~
6802  mov\SpecialChar ~
6803  _bp,sp 
6804 \newline 
6805 \SpecialChar ~
6806 \SpecialChar ~
6807 \SpecialChar ~
6808 \SpecialChar ~
6809 \SpecialChar ~
6810 \SpecialChar ~
6811 \SpecialChar ~
6812 \SpecialChar ~
6813 mov\SpecialChar ~
6814  r2,dpl
6815 \newline 
6816 \SpecialChar ~
6817 \SpecialChar ~
6818 \SpecialChar ~
6819 \SpecialChar ~
6820 \SpecialChar ~
6821 \SpecialChar ~
6822 \SpecialChar ~
6823  mov\SpecialChar ~
6824  a,_bp 
6825 \newline 
6826 \SpecialChar ~
6827 \SpecialChar ~
6828 \SpecialChar ~
6829 \SpecialChar ~
6830 \SpecialChar ~
6831 \SpecialChar ~
6832 \SpecialChar ~
6833  clr\SpecialChar ~
6834  c 
6835 \newline 
6836 \SpecialChar ~
6837 \SpecialChar ~
6838 \SpecialChar ~
6839 \SpecialChar ~
6840 \SpecialChar ~
6841 \SpecialChar ~
6842 \SpecialChar ~
6843  add\SpecialChar ~
6844  a,#0xfd 
6845 \newline 
6846 \SpecialChar ~
6847 \SpecialChar ~
6848 \SpecialChar ~
6849 \SpecialChar ~
6850 \SpecialChar ~
6851 \SpecialChar ~
6852 \SpecialChar ~
6853  mov\SpecialChar ~
6854  r0,a 
6855 \newline 
6856 \SpecialChar ~
6857 \SpecialChar ~
6858 \SpecialChar ~
6859 \SpecialChar ~
6860 \SpecialChar ~
6861 \SpecialChar ~
6862 \SpecialChar ~
6863  add\SpecialChar ~
6864  a,#0xfc
6865 \newline 
6866 \SpecialChar ~
6867 \SpecialChar ~
6868 \SpecialChar ~
6869 \SpecialChar ~
6870 \SpecialChar ~
6871 \SpecialChar ~
6872 \SpecialChar ~
6873  mov\SpecialChar ~
6874  r1,a 
6875 \newline 
6876 \SpecialChar ~
6877 \SpecialChar ~
6878 \SpecialChar ~
6879 \SpecialChar ~
6880 \SpecialChar ~
6881 \SpecialChar ~
6882 \SpecialChar ~
6883  mov\SpecialChar ~
6884  a,@r0 
6885 \newline 
6886 \SpecialChar ~
6887 \SpecialChar ~
6888 \SpecialChar ~
6889 \SpecialChar ~
6890 \SpecialChar ~
6891 \SpecialChar ~
6892 \SpecialChar ~
6893  add\SpecialChar ~
6894  a,r2
6895 \newline 
6896 \SpecialChar ~
6897 \SpecialChar ~
6898 \SpecialChar ~
6899 \SpecialChar ~
6900 \SpecialChar ~
6901 \SpecialChar ~
6902 \SpecialChar ~
6903  mov\SpecialChar ~
6904  dpl,a 
6905 \newline 
6906 \SpecialChar ~
6907 \SpecialChar ~
6908 \SpecialChar ~
6909 \SpecialChar ~
6910 \SpecialChar ~
6911 \SpecialChar ~
6912 \SpecialChar ~
6913  mov\SpecialChar ~
6914  dph,#0x00 
6915 \newline 
6916 \SpecialChar ~
6917 \SpecialChar ~
6918 \SpecialChar ~
6919 \SpecialChar ~
6920 \SpecialChar ~
6921 \SpecialChar ~
6922 \SpecialChar ~
6923  mov\SpecialChar ~
6924  sp,_bp 
6925 \newline 
6926 \SpecialChar ~
6927 \SpecialChar ~
6928 \SpecialChar ~
6929 \SpecialChar ~
6930 \SpecialChar ~
6931 \SpecialChar ~
6932 \SpecialChar ~
6933  pop\SpecialChar ~
6934  _bp 
6935 \newline 
6936 \SpecialChar ~
6937 \SpecialChar ~
6938 \SpecialChar ~
6939 \SpecialChar ~
6940 \SpecialChar ~
6941 \SpecialChar ~
6942 \SpecialChar ~
6943  ret
6944 \layout Standard
6945
6946 The compiling and linking procedure remains the same, however note the extra
6947  entry & exit linkage required for the assembler code, _bp is the stack
6948  frame pointer and is used to compute the offset into the stack for parameters
6949  and local variables.
6950 \layout Subsection
6951
6952 External Stack
6953 \layout Standard
6954
6955 The external stack is located at the start of the external ram segment,
6956  and is 256 bytes in size.
6957  When --xstack option is used to compile the program, the parameters and
6958  local variables of all reentrant functions are allocated in this area.
6959  This option is provided for programs with large stack space requirements.
6960  When used with the --stack-auto option, all parameters and local variables
6961  are allocated on the external stack (note support libraries will need to
6962  be recompiled with the same options).
6963 \layout Standard
6964
6965 The compiler outputs the higher order address byte of the external ram segment
6966  into PORT P2, therefore when using the External Stack option, this port
6967  MAY NOT be used by the application program.
6968 \layout Subsection
6969
6970 ANSI-Compliance
6971 \layout Standard
6972
6973 Deviations from the compliancy.
6974 \layout Enumerate
6975
6976 functions are not always reentrant.
6977 \layout Enumerate
6978
6979 structures cannot be assigned values directly, cannot be passed as function
6980  parameters or assigned to each other and cannot be a return value from
6981  a function.
6982 \begin_deeper 
6983 \layout Standard
6984
6985 eg
6986 \end_deeper 
6987 \layout Standard
6988
6989 struct s { ...
6990  }; 
6991 \newline 
6992 struct s s1, s2; 
6993 \newline 
6994 foo() 
6995 \newline 
6996
6997 \newline 
6998 ...
6999  
7000 \newline 
7001 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
7002 \newline 
7003 ...
7004  
7005 \newline 
7006 }
7007 \layout Standard
7008
7009 struct s foo1 (struct s parms) /* is invalid in SDCC although allowed in
7010  ANSI */ 
7011 \newline 
7012
7013 \newline 
7014 struct s rets; 
7015 \newline 
7016 ...
7017  
7018 \newline 
7019 return rets;/* is invalid in SDCC although allowed in ANSI */ 
7020 \newline 
7021 }
7022 \layout Enumerate
7023
7024 'long long' (64 bit integers) not supported.
7025 \layout Enumerate
7026
7027 'double' precision floating point not supported.
7028 \layout Enumerate
7029
7030 integral promotions are suppressed.
7031  What does this mean ? The compiler will not implicitly promote an integer
7032  expression to a higher order integer, exception is an assignment or parameter
7033  passing.
7034  
7035 \layout Enumerate
7036
7037 No support for setjmp and longjmp (for now).
7038 \layout Enumerate
7039
7040 Old K&R style function declarations are NOT allowed.
7041 \layout Standard
7042
7043 foo(i,j) /* this old style of function declarations */ 
7044 \newline 
7045 int i,j; /* are valid in ANSI ..
7046  not valid in SDCC */ 
7047 \newline 
7048
7049 \newline 
7050 ...
7051  
7052 \newline 
7053 }
7054 \layout Enumerate
7055
7056 functions declared as pointers must be dereferenced during the call.
7057 \begin_deeper 
7058 \layout Standard
7059
7060 int (*foo)();
7061 \end_deeper 
7062 \layout Standard
7063
7064 \SpecialChar ~
7065  \SpecialChar ~
7066 ...
7067  
7068 \newline 
7069 \SpecialChar ~
7070  \SpecialChar ~
7071 /* has to be called like this */ 
7072 \newline 
7073 \SpecialChar ~
7074  \SpecialChar ~
7075 (*foo)();/* ansi standard allows calls to be made like 'foo()' */
7076 \layout Subsection
7077
7078 Cyclomatic Complexity
7079 \layout Standard
7080
7081 Cyclomatic complexity of a function is defined as the number of independent
7082  paths the program can take during execution of the function.
7083  This is an important number since it defines the number test cases you
7084  have to generate to validate the function.
7085  The accepted industry standard for complexity number is 10, if the cyclomatic
7086  complexity reported by SDCC exceeds 10 you should think about simplification
7087  of the function logic.
7088 \layout Standard
7089
7090 Note that the complexity level is not related to the number of lines of
7091  code in a function.
7092  Large functions can have low complexity, and small functions can have large
7093  complexity levels.
7094  SDCC uses the following formula to compute the complexity.
7095 \layout Standard
7096
7097 complexity = (number of edges in control flow graph) - 
7098 \newline 
7099 \SpecialChar ~
7100  \SpecialChar ~
7101  \SpecialChar ~
7102  \SpecialChar ~
7103  \SpecialChar ~
7104  \SpecialChar ~
7105  \SpecialChar ~
7106 (number of nodes in control flow graph) + 2;
7107 \layout Standard
7108
7109 Having said that the industry standard is 10, you should be aware that in
7110  some cases it may unavoidable to have a complexity level of less than 10.
7111  For example if you have switch statement with more than 10 case labels,
7112  each case label adds one to the complexity level.
7113  The complexity level is by no means an absolute measure of the algorithmic
7114  complexity of the function, it does however provide a good starting point
7115  for which functions you might look at for further optimization.
7116 \layout Section
7117
7118 TIPS
7119 \layout Standard
7120
7121 Here are a few guide-lines that will help the compiler generate more efficient
7122  code, some of the tips are specific to this compiler others are generally
7123  good programming practice.
7124 \layout Itemize
7125
7126 Use the smallest data type to represent your data-value.
7127  If it is known in advance that the value is going to be less than 256 then
7128  use a 'char' instead of a 'short' or 'int'.
7129 \layout Itemize
7130
7131 Use unsigned when it is known in advance that the value is not going to
7132  be negative.
7133  This helps especially if you are doing division or multiplication.
7134 \layout Itemize
7135
7136 NEVER jump into a LOOP.
7137 \layout Itemize
7138
7139 Declare the variables to be local whenever possible, especially loop control
7140  variables (induction).
7141 \layout Itemize
7142
7143 Since the compiler does not do implicit integral promotion, the programmer
7144  should do an explicit cast when integral promotion is required.
7145 \layout Itemize
7146
7147 Reducing the size of division, multiplication & modulus operations can reduce
7148  code size substantially.
7149  Take the following code for example.
7150 \begin_deeper 
7151 \layout Standard
7152
7153 foobar(unsigned int p1, unsigned char ch)
7154 \newline 
7155 {
7156 \newline 
7157 \SpecialChar ~
7158 \SpecialChar ~
7159 \SpecialChar ~
7160 \SpecialChar ~
7161 unsigned char ch1 = p1 % ch ;
7162 \newline 
7163 \SpecialChar ~
7164 \SpecialChar ~
7165 \SpecialChar ~
7166 \SpecialChar ~
7167 ....\SpecialChar ~
7168 \SpecialChar ~
7169 \SpecialChar ~
7170 \SpecialChar ~
7171
7172 \newline 
7173 }
7174 \layout Standard
7175
7176 For the modulus operation the variable ch will be promoted to unsigned int
7177  first then the modulus operation will be performed (this will lead to a
7178  call to a support routine).
7179  If the code is changed to 
7180 \layout Standard
7181
7182 foobar(unsigned int p1, unsigned char ch)
7183 \newline 
7184 {
7185 \newline 
7186 \SpecialChar ~
7187 \SpecialChar ~
7188 \SpecialChar ~
7189 \SpecialChar ~
7190 unsigned char ch1 = (unsigned char)p1 % ch ;
7191 \newline 
7192 \SpecialChar ~
7193 \SpecialChar ~
7194 \SpecialChar ~
7195 \SpecialChar ~
7196 ....\SpecialChar ~
7197 \SpecialChar ~
7198 \SpecialChar ~
7199 \SpecialChar ~
7200
7201 \newline 
7202 }
7203 \layout Standard
7204
7205 It would substantially reduce the code generated (future versions of the
7206  compiler will be smart enough to detect such optimization oppurtunities).
7207 \end_deeper 
7208 \layout Standard
7209
7210 Notes on MCS51 memory layout(Trefor@magera.freeserve.co.uk)
7211 \layout Standard
7212
7213 The 8051 family of micro controller have a minimum of 128 bytes of internal
7214  memory which is structured as follows
7215 \layout Standard
7216
7217 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R7 to R7
7218  
7219 \layout Standard
7220
7221 - Bytes 20-2F - 16 bytes to hold 128 bit variables and 
7222 \layout Standard
7223
7224 - Bytes 30-7F - 60 bytes for general purpose use.
7225 \layout Standard
7226
7227 Normally the SDCC compiler will only utilise the first bank of registers,
7228  but it is possible to specify that other banks of registers should be used
7229  in interrupt routines.
7230  By default, the compiler will place the stack after the last bank of used
7231  registers, i.e.
7232  if the first 2 banks of registers are used, it will position the base of
7233  the internal stack at address 16 (0X10).
7234  This implies that as the stack grows, it will use up the remaining register
7235  banks, and the 16 bytes used by the 128 bit variables, and 60 bytes for
7236  general purpose use.
7237 \layout Standard
7238
7239 By default, the compiler uses the 60 general purpose bytes to hold "near
7240  data".
7241  The compiler/optimiser may also declare some Local Variables in this area
7242  to hold local data.
7243  
7244 \layout Standard
7245
7246 If any of the 128 bit variables are used, or near data is being used then
7247  care needs to be taken to ensure that the stack does not grow so much that
7248  it starts to over write either your bit variables or "near data".
7249  There is no runtime checking to prevent this from happening.
7250 \layout Standard
7251
7252 The amount of stack being used is affected by the use of the "internal stack"
7253  to save registers before a subroutine call is made, - --stack-auto will
7254  declare parameters and local variables on the stack - the number of nested
7255  subroutines.
7256 \layout Standard
7257
7258 If you detect that the stack is over writing you data, then the following
7259  can be done.
7260  --xstack will cause an external stack to be used for saving registers and
7261  (if --stack-auto is being used) storing parameters and local variables.
7262  However this will produce more and code which will be slower to execute.
7263  
7264 \layout Standard
7265
7266 --stack-loc will allow you specify the start of the stack, i.e.
7267  you could start it after any data in the general purpose area.
7268  However this may waste the memory not used by the register banks and if
7269  the size of the "near data" increases, it may creep into the bottom of
7270  the stack.
7271 \layout Standard
7272
7273 --stack-after-data, similar to the --stack-loc, but it automatically places
7274  the stack after the end of the "near data".
7275  Again this could waste any spare register space.
7276 \layout Standard
7277
7278 --data-loc allows you to specify the start address of the near data.
7279  This could be used to move the "near data" further away from the stack
7280  giving it more room to grow.
7281  This will only work if no bit variables are being used and the stack can
7282  grow to use the bit variable space.
7283 \layout Standard
7284
7285 Conclusion.
7286 \layout Standard
7287
7288 If you find that the stack is over writing your bit variables or "near data"
7289  then the approach which best utilised the internal memory is to position
7290  the "near data" after the last bank of used registers or, if you use bit
7291  variables, after the last bit variable by using the --data-loc, e.g.
7292  if two register banks are being used and no data variables, --data-loc
7293  16, and - use the --stack-after-data option.
7294 \layout Standard
7295
7296 If bit variables are being used, another method would be to try and squeeze
7297  the data area in the unused register banks if it will fit, and start the
7298  stack after the last bit variable.
7299 \layout Section
7300
7301 Retargetting for other MCUs.
7302 \layout Standard
7303
7304 The issues for retargetting the compiler are far too numerous to be covered
7305  by this document.
7306  What follows is a brief description of each of the seven phases of the
7307  compiler and its MCU dependency.
7308 \layout Enumerate
7309
7310 Parsing the source and building the annotated parse tree.
7311  This phase is largely MCU independent (except for the language extensions).
7312  Syntax & semantic checks are also done in this phase, along with some initial
7313  optimizations like back patching labels and the pattern matching optimizations
7314  like bit-rotation etc.
7315 \layout Enumerate
7316
7317 The second phase involves generating an intermediate code which can be easy
7318  manipulated during the later phases.
7319  This phase is entirely MCU independent.
7320  The intermediate code generation assumes the target machine has unlimited
7321  number of registers, and designates them with the name iTemp.
7322  The compiler can be made to dump a human readable form of the code generated
7323  by using the --dumpraw option.
7324 \layout Enumerate
7325
7326 This phase does the bulk of the standard optimizations and is also MCU independe
7327 nt.
7328  This phase can be broken down into several sub-phases.
7329 \begin_deeper 
7330 \layout Itemize
7331
7332 Break down intermediate code (iCode) into basic blocks.
7333 \layout Itemize
7334
7335 Do control flow & data flow analysis on the basic blocks.
7336 \layout Itemize
7337
7338 Do local common subexpression elimination, then global subexpression elimination
7339 \layout Itemize
7340
7341 dead code elimination
7342 \layout Itemize
7343
7344 loop optimizations
7345 \layout Itemize
7346
7347 if loop optimizations caused any changes then do 'global subexpression eliminati
7348 on' and 'dead code elimination' again.
7349 \end_deeper 
7350 \layout Enumerate
7351
7352 This phase determines the live-ranges; by live range I mean those iTemp
7353  variables defined by the compiler that still survive after all the optimization
7354 s.
7355  Live range analysis is essential for register allocation, since these computati
7356 on determines which of these iTemps will be assigned to registers, and for
7357  how long.
7358 \layout Enumerate
7359
7360 Phase five is register allocation.
7361  There are two parts to this process.
7362 \begin_deeper 
7363 \layout Enumerate
7364
7365 The first part I call 'register packing' (for lack of a better term).
7366  In this case several MCU specific expression folding is done to reduce
7367  register pressure.
7368 \layout Enumerate
7369
7370 The second part is more MCU independent and deals with allocating registers
7371  to the remaining live ranges.
7372  A lot of MCU specific code does creep into this phase because of the limited
7373  number of index registers available in the 8051.
7374 \end_deeper 
7375 \layout Enumerate
7376
7377 The Code generation phase is (unhappily), entirely MCU dependent and very
7378  little (if any at all) of this code can be reused for other MCU.
7379  However the scheme for allocating a homogenized assembler operand for each
7380  iCode operand may be reused.
7381 \layout Enumerate
7382
7383 As mentioned in the optimization section the peep-hole optimizer is rule
7384  based system, which can reprogrammed for other MCUs.
7385 \layout Section
7386
7387 SDCDB - Source Level Debugger
7388 \layout Standard
7389
7390 SDCC is distributed with a source level debugger.
7391  The debugger uses a command line interface, the command repertoire of the
7392  debugger has been kept as close to gdb (the GNU debugger) as possible.
7393  The configuration and build process is part of the standard compiler installati
7394 on, which also builds and installs the debugger in the target directory
7395  specified during configuration.
7396  The debugger allows you debug BOTH at the C source and at the ASM source
7397  level.
7398 \layout Subsection
7399
7400 Compiling for Debugging
7401 \layout Standard
7402
7403 The --debug option must be specified for all files for which debug information
7404  is to be generated.
7405  The complier generates a .cdb file for each of these files.
7406  The linker updates the .cdb file with the address information.
7407  This .cdb is used by the debugger.
7408 \layout Subsection
7409
7410 How the Debugger Works
7411 \layout Standard
7412
7413 When the --debug option is specified the compiler generates extra symbol
7414  information some of which are put into the the assembler source and some
7415  are put into the .cdb file, the linker updates the .cdb file with the address
7416  information for the symbols.
7417  The debugger reads the symbolic information generated by the compiler &
7418  the address information generated by the linker.
7419  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
7420  execution is controlled by the debugger.
7421  When a command is issued for the debugger, it translates it into appropriate
7422  commands for the simulator.
7423 \layout Subsection
7424
7425 Starting the Debugger
7426 \layout Standard
7427
7428 The debugger can be started using the following command line.
7429  (Assume the file you are debugging has
7430 \layout Standard
7431
7432 the file name foo).
7433 \layout Standard
7434
7435 >sdcdb foo
7436 \layout Standard
7437
7438 The debugger will look for the following files.
7439 \layout Enumerate
7440
7441 foo.c - the source file.
7442 \layout Enumerate
7443
7444 foo.cdb - the debugger symbol information file.
7445 \layout Enumerate
7446
7447 foo.ihx - the intel hex format object file.
7448 \layout Subsection
7449
7450 Command Line Options.
7451 \layout Itemize
7452
7453 --directory=<source file directory> this option can used to specify the
7454  directory search list.
7455  The debugger will look into the directory list specified for source, cdb
7456  & ihx files.
7457  The items in the directory list must be separated by ':', e.g.
7458  if the source files can be in the directories /home/src1 and /home/src2,
7459  the --directory option should be --directory=/home/src1:/home/src2.
7460  Note there can be no spaces in the option.
7461  
7462 \layout Itemize
7463
7464 -cd <directory> - change to the <directory>.
7465 \layout Itemize
7466
7467 -fullname - used by GUI front ends.
7468 \layout Itemize
7469
7470 -cpu <cpu-type> - this argument is passed to the simulator please see the
7471  simulator docs for details.
7472 \layout Itemize
7473
7474 -X <Clock frequency > this options is passed to the simulator please see
7475  simulator docs for details.
7476 \layout Itemize
7477
7478 -s <serial port file> passed to simulator see simulator docs for details.
7479 \layout Itemize
7480
7481 -S <serial in,out> passed to simulator see simulator docs for details.
7482 \layout Subsection
7483
7484 Debugger Commands.
7485 \layout Standard
7486
7487 As mention earlier the command interface for the debugger has been deliberately
7488  kept as close the GNU debugger gdb, as possible, this will help int integration
7489  with existing graphical user interfaces (like ddd, xxgdb or xemacs) existing
7490  for the GNU debugger.
7491 \layout Subsubsection
7492
7493 break [line | file:line | function | file:function]
7494 \layout Standard
7495
7496 Set breakpoint at specified line or function.
7497 \layout Standard
7498
7499 sdcdb>break 100 
7500 \newline 
7501 sdcdb>break foo.c:100
7502 \newline 
7503 sdcdb>break funcfoo
7504 \newline 
7505 sdcdb>break foo.c:funcfoo
7506 \layout Subsubsection
7507
7508 clear [line | file:line | function | file:function ]
7509 \layout Standard
7510
7511 Clear breakpoint at specified line or function.
7512 \layout Standard
7513
7514 sdcdb>clear 100
7515 \newline 
7516 sdcdb>clear foo.c:100
7517 \newline 
7518 sdcdb>clear funcfoo
7519 \newline 
7520 sdcdb>clear foo.c:funcfoo
7521 \layout Subsubsection
7522
7523 continue
7524 \layout Standard
7525
7526 Continue program being debugged, after breakpoint.
7527 \layout Subsubsection
7528
7529 finish
7530 \layout Standard
7531
7532 Execute till the end of the current function.
7533 \layout Subsubsection
7534
7535 delete [n]
7536 \layout Standard
7537
7538 Delete breakpoint number 'n'.
7539  If used without any option clear ALL user defined break points.
7540 \layout Subsubsection
7541
7542 info [break | stack | frame | registers ]
7543 \layout Itemize
7544
7545 info break - list all breakpoints
7546 \layout Itemize
7547
7548 info stack - show the function call stack.
7549 \layout Itemize
7550
7551 info frame - show information about the current execution frame.
7552 \layout Itemize
7553
7554 info registers - show content of all registers.
7555 \layout Subsubsection
7556
7557 step
7558 \layout Standard
7559
7560 Step program until it reaches a different source line.
7561 \layout Subsubsection
7562
7563 next
7564 \layout Standard
7565
7566 Step program, proceeding through subroutine calls.
7567 \layout Subsubsection
7568
7569 run
7570 \layout Standard
7571
7572 Start debugged program.
7573 \layout Subsubsection
7574
7575 ptype variable 
7576 \layout Standard
7577
7578 Print type information of the variable.
7579 \layout Subsubsection
7580
7581 print variable
7582 \layout Standard
7583
7584 print value of variable.
7585 \layout Subsubsection
7586
7587 file filename
7588 \layout Standard
7589
7590 load the given file name.
7591  Note this is an alternate method of loading file for debugging.
7592 \layout Subsubsection
7593
7594 frame
7595 \layout Standard
7596
7597 print information about current frame.
7598 \layout Subsubsection
7599
7600 set srcmode
7601 \layout Standard
7602
7603 Toggle between C source & assembly source.
7604 \layout Subsubsection
7605
7606 ! simulator command
7607 \layout Standard
7608
7609 Send the string following '!' to the simulator, the simulator response is
7610  displayed.
7611  Note the debugger does not interpret the command being sent to the simulator,
7612  so if a command like 'go' is sent the debugger can loose its execution
7613  context and may display incorrect values.
7614 \layout Subsubsection
7615
7616 quit.
7617 \layout Standard
7618
7619 "Watch me now.
7620  Iam going Down.
7621  My name is Bobby Brown"
7622 \layout Subsection
7623
7624 Interfacing with XEmacs.
7625 \layout Standard
7626
7627 Two files are (in emacs lisp) are provided for the interfacing with XEmacs,
7628  sdcdb.el and sdcdbsrc.el.
7629  These two files can be found in the $(prefix)/bin directory after the installat
7630 ion is complete.
7631  These files need to be loaded into XEmacs for the interface to work, this
7632  can be done at XEmacs startup time by inserting the following into your
7633  '.xemacs' file (which can be found in your HOME directory) (load-file sdcdbsrc.el
7634 ) [ .xemacs is a lisp file so the () around the command is REQUIRED), the
7635  files can also be loaded dynamically while XEmacs is running, set the environme
7636 nt variable 'EMACSLOADPATH' to the installation bin directory [$(prefix)/bin],
7637  then enter the following command ESC-x load-file sdcdbsrc.
7638  To start the interface enter the following command ESC-x sdcdbsrc, you
7639  will prompted to enter the file name to be debugged.
7640  
7641 \layout Standard
7642
7643 The command line options that are passed to the simulator directly are bound
7644  to default values in the file sdcdbsrc.el the variables are listed below
7645  these values maybe changed as required.
7646 \layout Itemize
7647
7648 sdcdbsrc-cpu-type '51
7649 \layout Itemize
7650
7651 sdcdbsrc-frequency '11059200
7652 \layout Itemize
7653
7654 sdcdbsrc-serial nil
7655 \layout Standard
7656
7657 The following is a list of key mapping for the debugger interface.
7658 \layout Standard
7659
7660 \SpecialChar ~
7661
7662 \newline 
7663 ;; Current Listing :: 
7664 \newline 
7665 ;;key\SpecialChar ~
7666 \SpecialChar ~
7667 \SpecialChar ~
7668 \SpecialChar ~
7669 \SpecialChar ~
7670 \SpecialChar ~
7671 \SpecialChar ~
7672 \SpecialChar ~
7673 \SpecialChar ~
7674 \SpecialChar ~
7675 \SpecialChar ~
7676 \SpecialChar ~
7677 \SpecialChar ~
7678 \SpecialChar ~
7679 \SpecialChar ~
7680 binding\SpecialChar ~
7681 \SpecialChar ~
7682 \SpecialChar ~
7683 \SpecialChar ~
7684 \SpecialChar ~
7685 \SpecialChar ~
7686 \SpecialChar ~
7687 \SpecialChar ~
7688 \SpecialChar ~
7689 \SpecialChar ~
7690 \SpecialChar ~
7691 \SpecialChar ~
7692 \SpecialChar ~
7693 \SpecialChar ~
7694 \SpecialChar ~
7695 \SpecialChar ~
7696 \SpecialChar ~
7697 \SpecialChar ~
7698 \SpecialChar ~
7699 \SpecialChar ~
7700 \SpecialChar ~
7701 \SpecialChar ~
7702 Comment 
7703 \newline 
7704 ;;---\SpecialChar ~
7705 \SpecialChar ~
7706 \SpecialChar ~
7707 \SpecialChar ~
7708 \SpecialChar ~
7709 \SpecialChar ~
7710 \SpecialChar ~
7711 \SpecialChar ~
7712 \SpecialChar ~
7713 \SpecialChar ~
7714 \SpecialChar ~
7715 \SpecialChar ~
7716 \SpecialChar ~
7717 \SpecialChar ~
7718 \SpecialChar ~
7719 -------\SpecialChar ~
7720 \SpecialChar ~
7721 \SpecialChar ~
7722 \SpecialChar ~
7723 \SpecialChar ~
7724 \SpecialChar ~
7725 \SpecialChar ~
7726 \SpecialChar ~
7727 \SpecialChar ~
7728 \SpecialChar ~
7729 \SpecialChar ~
7730 \SpecialChar ~
7731 \SpecialChar ~
7732 \SpecialChar ~
7733 \SpecialChar ~
7734 \SpecialChar ~
7735 \SpecialChar ~
7736 \SpecialChar ~
7737 \SpecialChar ~
7738 \SpecialChar ~
7739 \SpecialChar ~
7740 \SpecialChar ~
7741 ------- 
7742 \newline 
7743 ;; 
7744 \newline 
7745 ;; n\SpecialChar ~
7746 \SpecialChar ~
7747 \SpecialChar ~
7748 \SpecialChar ~
7749 \SpecialChar ~
7750 \SpecialChar ~
7751 \SpecialChar ~
7752 \SpecialChar ~
7753 \SpecialChar ~
7754 \SpecialChar ~
7755 \SpecialChar ~
7756 \SpecialChar ~
7757 \SpecialChar ~
7758 \SpecialChar ~
7759  sdcdb-next-from-src\SpecialChar ~
7760 \SpecialChar ~
7761 \SpecialChar ~
7762 \SpecialChar ~
7763 \SpecialChar ~
7764 \SpecialChar ~
7765 \SpecialChar ~
7766 \SpecialChar ~
7767 \SpecialChar ~
7768 \SpecialChar ~
7769 SDCDB next command 
7770 \newline 
7771 ;; b\SpecialChar ~
7772 \SpecialChar ~
7773 \SpecialChar ~
7774 \SpecialChar ~
7775 \SpecialChar ~
7776 \SpecialChar ~
7777 \SpecialChar ~
7778 \SpecialChar ~
7779 \SpecialChar ~
7780 \SpecialChar ~
7781 \SpecialChar ~
7782 \SpecialChar ~
7783 \SpecialChar ~
7784 \SpecialChar ~
7785  sdcdb-back-from-src\SpecialChar ~
7786 \SpecialChar ~
7787 \SpecialChar ~
7788 \SpecialChar ~
7789 \SpecialChar ~
7790 \SpecialChar ~
7791 \SpecialChar ~
7792 \SpecialChar ~
7793 \SpecialChar ~
7794 \SpecialChar ~
7795 SDCDB back command 
7796 \newline 
7797 ;; c\SpecialChar ~
7798 \SpecialChar ~
7799 \SpecialChar ~
7800 \SpecialChar ~
7801 \SpecialChar ~
7802 \SpecialChar ~
7803 \SpecialChar ~
7804 \SpecialChar ~
7805 \SpecialChar ~
7806 \SpecialChar ~
7807 \SpecialChar ~
7808 \SpecialChar ~
7809 \SpecialChar ~
7810 \SpecialChar ~
7811  sdcdb-cont-from-src\SpecialChar ~
7812 \SpecialChar ~
7813 \SpecialChar ~
7814 \SpecialChar ~
7815 \SpecialChar ~
7816 \SpecialChar ~
7817 \SpecialChar ~
7818 \SpecialChar ~
7819 \SpecialChar ~
7820 \SpecialChar ~
7821 SDCDB continue command
7822 \newline 
7823 ;; s\SpecialChar ~
7824 \SpecialChar ~
7825 \SpecialChar ~
7826 \SpecialChar ~
7827 \SpecialChar ~
7828 \SpecialChar ~
7829 \SpecialChar ~
7830 \SpecialChar ~
7831 \SpecialChar ~
7832 \SpecialChar ~
7833 \SpecialChar ~
7834 \SpecialChar ~
7835 \SpecialChar ~
7836 \SpecialChar ~
7837  sdcdb-step-from-src\SpecialChar ~
7838 \SpecialChar ~
7839 \SpecialChar ~
7840 \SpecialChar ~
7841 \SpecialChar ~
7842 \SpecialChar ~
7843 \SpecialChar ~
7844 \SpecialChar ~
7845 \SpecialChar ~
7846 \SpecialChar ~
7847 SDCDB step command 
7848 \newline 
7849 ;; ?\SpecialChar ~
7850 \SpecialChar ~
7851 \SpecialChar ~
7852 \SpecialChar ~
7853 \SpecialChar ~
7854 \SpecialChar ~
7855 \SpecialChar ~
7856 \SpecialChar ~
7857 \SpecialChar ~
7858 \SpecialChar ~
7859 \SpecialChar ~
7860 \SpecialChar ~
7861 \SpecialChar ~
7862 \SpecialChar ~
7863  sdcdb-whatis-c-sexp\SpecialChar ~
7864 \SpecialChar ~
7865 \SpecialChar ~
7866 \SpecialChar ~
7867 \SpecialChar ~
7868 \SpecialChar ~
7869 \SpecialChar ~
7870 \SpecialChar ~
7871 \SpecialChar ~
7872 \SpecialChar ~
7873 SDCDB ptypecommand for data at 
7874 \newline 
7875 ;;\SpecialChar ~
7876 \SpecialChar ~
7877 \SpecialChar ~
7878 \SpecialChar ~
7879 \SpecialChar ~
7880 \SpecialChar ~
7881 \SpecialChar ~
7882 \SpecialChar ~
7883 \SpecialChar ~
7884 \SpecialChar ~
7885 \SpecialChar ~
7886 \SpecialChar ~
7887 \SpecialChar ~
7888 \SpecialChar ~
7889 \SpecialChar ~
7890 \SpecialChar ~
7891 \SpecialChar ~
7892 \SpecialChar ~
7893 \SpecialChar ~
7894 \SpecialChar ~
7895 \SpecialChar ~
7896 \SpecialChar ~
7897 \SpecialChar ~
7898 \SpecialChar ~
7899 \SpecialChar ~
7900 \SpecialChar ~
7901 \SpecialChar ~
7902 \SpecialChar ~
7903 \SpecialChar ~
7904 \SpecialChar ~
7905 \SpecialChar ~
7906 \SpecialChar ~
7907 \SpecialChar ~
7908 \SpecialChar ~
7909 \SpecialChar ~
7910 \SpecialChar ~
7911 \SpecialChar ~
7912 \SpecialChar ~
7913 \SpecialChar ~
7914 \SpecialChar ~
7915 \SpecialChar ~
7916 \SpecialChar ~
7917  buffer point 
7918 \newline 
7919 ;; x\SpecialChar ~
7920 \SpecialChar ~
7921 \SpecialChar ~
7922 \SpecialChar ~
7923 \SpecialChar ~
7924 \SpecialChar ~
7925 \SpecialChar ~
7926 \SpecialChar ~
7927 \SpecialChar ~
7928 \SpecialChar ~
7929 \SpecialChar ~
7930 \SpecialChar ~
7931 \SpecialChar ~
7932 \SpecialChar ~
7933  sdcdbsrc-delete\SpecialChar ~
7934 \SpecialChar ~
7935 \SpecialChar ~
7936 \SpecialChar ~
7937 \SpecialChar ~
7938 \SpecialChar ~
7939 \SpecialChar ~
7940 \SpecialChar ~
7941 \SpecialChar ~
7942 \SpecialChar ~
7943 \SpecialChar ~
7944 \SpecialChar ~
7945 \SpecialChar ~
7946 \SpecialChar ~
7947 SDCDB Delete all breakpoints if no arg 
7948 \newline 
7949 ;;\SpecialChar ~
7950 \SpecialChar ~
7951 \SpecialChar ~
7952 \SpecialChar ~
7953 \SpecialChar ~
7954 \SpecialChar ~
7955 \SpecialChar ~
7956 \SpecialChar ~
7957 \SpecialChar ~
7958 \SpecialChar ~
7959 \SpecialChar ~
7960 \SpecialChar ~
7961 \SpecialChar ~
7962 \SpecialChar ~
7963 \SpecialChar ~
7964 \SpecialChar ~
7965 \SpecialChar ~
7966 \SpecialChar ~
7967 \SpecialChar ~
7968 \SpecialChar ~
7969 \SpecialChar ~
7970 \SpecialChar ~
7971 \SpecialChar ~
7972 \SpecialChar ~
7973 \SpecialChar ~
7974 \SpecialChar ~
7975 \SpecialChar ~
7976 \SpecialChar ~
7977 \SpecialChar ~
7978 \SpecialChar ~
7979 \SpecialChar ~
7980 \SpecialChar ~
7981 \SpecialChar ~
7982 \SpecialChar ~
7983 \SpecialChar ~
7984 \SpecialChar ~
7985 \SpecialChar ~
7986 \SpecialChar ~
7987 \SpecialChar ~
7988 \SpecialChar ~
7989 \SpecialChar ~
7990 \SpecialChar ~
7991 \SpecialChar ~
7992 \SpecialChar ~
7993 \SpecialChar ~
7994 \SpecialChar ~
7995 given or delete arg (C-u arg x) 
7996 \newline 
7997 ;; m\SpecialChar ~
7998 \SpecialChar ~
7999 \SpecialChar ~
8000 \SpecialChar ~
8001 \SpecialChar ~
8002 \SpecialChar ~
8003 \SpecialChar ~
8004 \SpecialChar ~
8005 \SpecialChar ~
8006 \SpecialChar ~
8007 \SpecialChar ~
8008 \SpecialChar ~
8009 \SpecialChar ~
8010 \SpecialChar ~
8011  sdcdbsrc-frame\SpecialChar ~
8012 \SpecialChar ~
8013 \SpecialChar ~
8014 \SpecialChar ~
8015 \SpecialChar ~
8016 \SpecialChar ~
8017 \SpecialChar ~
8018 \SpecialChar ~
8019 \SpecialChar ~
8020 \SpecialChar ~
8021 \SpecialChar ~
8022 \SpecialChar ~
8023 \SpecialChar ~
8024 \SpecialChar ~
8025 \SpecialChar ~
8026 SDCDB Display current frame if no arg, 
8027 \newline 
8028 ;;\SpecialChar ~
8029 \SpecialChar ~
8030 \SpecialChar ~
8031 \SpecialChar ~
8032 \SpecialChar ~
8033 \SpecialChar ~
8034 \SpecialChar ~
8035 \SpecialChar ~
8036 \SpecialChar ~
8037 \SpecialChar ~
8038 \SpecialChar ~
8039 \SpecialChar ~
8040 \SpecialChar ~
8041 \SpecialChar ~
8042 \SpecialChar ~
8043 \SpecialChar ~
8044 \SpecialChar ~
8045 \SpecialChar ~
8046 \SpecialChar ~
8047 \SpecialChar ~
8048 \SpecialChar ~
8049 \SpecialChar ~
8050 \SpecialChar ~
8051 \SpecialChar ~
8052 \SpecialChar ~
8053 \SpecialChar ~
8054 \SpecialChar ~
8055 \SpecialChar ~
8056 \SpecialChar ~
8057 \SpecialChar ~
8058 \SpecialChar ~
8059 \SpecialChar ~
8060 \SpecialChar ~
8061 \SpecialChar ~
8062 \SpecialChar ~
8063 \SpecialChar ~
8064 \SpecialChar ~
8065 \SpecialChar ~
8066 \SpecialChar ~
8067 \SpecialChar ~
8068 \SpecialChar ~
8069 \SpecialChar ~
8070 \SpecialChar ~
8071 \SpecialChar ~
8072 \SpecialChar ~
8073 \SpecialChar ~
8074 given or display frame arg 
8075 \newline 
8076 ;;\SpecialChar ~
8077 \SpecialChar ~
8078 \SpecialChar ~
8079 \SpecialChar ~
8080 \SpecialChar ~
8081 \SpecialChar ~
8082 \SpecialChar ~
8083 \SpecialChar ~
8084 \SpecialChar ~
8085 \SpecialChar ~
8086 \SpecialChar ~
8087 \SpecialChar ~
8088 \SpecialChar ~
8089 \SpecialChar ~
8090 \SpecialChar ~
8091 \SpecialChar ~
8092 \SpecialChar ~
8093 \SpecialChar ~
8094 \SpecialChar ~
8095 \SpecialChar ~
8096 \SpecialChar ~
8097 \SpecialChar ~
8098 \SpecialChar ~
8099 \SpecialChar ~
8100 \SpecialChar ~
8101 \SpecialChar ~
8102 \SpecialChar ~
8103 \SpecialChar ~
8104 \SpecialChar ~
8105 \SpecialChar ~
8106 \SpecialChar ~
8107 \SpecialChar ~
8108 \SpecialChar ~
8109 \SpecialChar ~
8110 \SpecialChar ~
8111 \SpecialChar ~
8112 \SpecialChar ~
8113 \SpecialChar ~
8114 \SpecialChar ~
8115 \SpecialChar ~
8116 \SpecialChar ~
8117 \SpecialChar ~
8118 \SpecialChar ~
8119 \SpecialChar ~
8120 \SpecialChar ~
8121 buffer point 
8122 \newline 
8123 ;; !\SpecialChar ~
8124 \SpecialChar ~
8125 \SpecialChar ~
8126 \SpecialChar ~
8127 \SpecialChar ~
8128 \SpecialChar ~
8129 \SpecialChar ~
8130 \SpecialChar ~
8131 \SpecialChar ~
8132 \SpecialChar ~
8133 \SpecialChar ~
8134 \SpecialChar ~
8135 \SpecialChar ~
8136 \SpecialChar ~
8137  sdcdbsrc-goto-sdcdb\SpecialChar ~
8138 \SpecialChar ~
8139 \SpecialChar ~
8140 \SpecialChar ~
8141 \SpecialChar ~
8142 \SpecialChar ~
8143 \SpecialChar ~
8144 \SpecialChar ~
8145 \SpecialChar ~
8146 \SpecialChar ~
8147 Goto the SDCDB output buffer 
8148 \newline 
8149 ;; p\SpecialChar ~
8150 \SpecialChar ~
8151 \SpecialChar ~
8152 \SpecialChar ~
8153 \SpecialChar ~
8154 \SpecialChar ~
8155 \SpecialChar ~
8156 \SpecialChar ~
8157 \SpecialChar ~
8158 \SpecialChar ~
8159 \SpecialChar ~
8160 \SpecialChar ~
8161 \SpecialChar ~
8162 \SpecialChar ~
8163  sdcdb-print-c-sexp\SpecialChar ~
8164 \SpecialChar ~
8165 \SpecialChar ~
8166 \SpecialChar ~
8167 \SpecialChar ~
8168 \SpecialChar ~
8169 \SpecialChar ~
8170 \SpecialChar ~
8171 \SpecialChar ~
8172 \SpecialChar ~
8173 \SpecialChar ~
8174 SDCDB print command for data at 
8175 \newline 
8176 ;;\SpecialChar ~
8177 \SpecialChar ~
8178 \SpecialChar ~
8179 \SpecialChar ~
8180 \SpecialChar ~
8181 \SpecialChar ~
8182 \SpecialChar ~
8183 \SpecialChar ~
8184 \SpecialChar ~
8185 \SpecialChar ~
8186 \SpecialChar ~
8187 \SpecialChar ~
8188 \SpecialChar ~
8189 \SpecialChar ~
8190 \SpecialChar ~
8191 \SpecialChar ~
8192 \SpecialChar ~
8193 \SpecialChar ~
8194 \SpecialChar ~
8195 \SpecialChar ~
8196 \SpecialChar ~
8197 \SpecialChar ~
8198 \SpecialChar ~
8199 \SpecialChar ~
8200 \SpecialChar ~
8201 \SpecialChar ~
8202 \SpecialChar ~
8203 \SpecialChar ~
8204 \SpecialChar ~
8205 \SpecialChar ~
8206 \SpecialChar ~
8207 \SpecialChar ~
8208 \SpecialChar ~
8209 \SpecialChar ~
8210 \SpecialChar ~
8211 \SpecialChar ~
8212 \SpecialChar ~
8213 \SpecialChar ~
8214 \SpecialChar ~
8215 \SpecialChar ~
8216 \SpecialChar ~
8217 \SpecialChar ~
8218  buffer point 
8219 \newline 
8220 ;; g\SpecialChar ~
8221 \SpecialChar ~
8222 \SpecialChar ~
8223 \SpecialChar ~
8224 \SpecialChar ~
8225 \SpecialChar ~
8226 \SpecialChar ~
8227 \SpecialChar ~
8228 \SpecialChar ~
8229 \SpecialChar ~
8230 \SpecialChar ~
8231 \SpecialChar ~
8232 \SpecialChar ~
8233 \SpecialChar ~
8234  sdcdbsrc-goto-sdcdb\SpecialChar ~
8235 \SpecialChar ~
8236 \SpecialChar ~
8237 \SpecialChar ~
8238 \SpecialChar ~
8239 \SpecialChar ~
8240 \SpecialChar ~
8241 \SpecialChar ~
8242 \SpecialChar ~
8243 \SpecialChar ~
8244 Goto the SDCDB output buffer 
8245 \newline 
8246 ;; t\SpecialChar ~
8247 \SpecialChar ~
8248 \SpecialChar ~
8249 \SpecialChar ~
8250 \SpecialChar ~
8251 \SpecialChar ~
8252 \SpecialChar ~
8253 \SpecialChar ~
8254 \SpecialChar ~
8255 \SpecialChar ~
8256 \SpecialChar ~
8257 \SpecialChar ~
8258 \SpecialChar ~
8259 \SpecialChar ~
8260  sdcdbsrc-mode\SpecialChar ~
8261 \SpecialChar ~
8262 \SpecialChar ~
8263 \SpecialChar ~
8264 \SpecialChar ~
8265 \SpecialChar ~
8266 \SpecialChar ~
8267 \SpecialChar ~
8268 \SpecialChar ~
8269 \SpecialChar ~
8270 \SpecialChar ~
8271 \SpecialChar ~
8272 \SpecialChar ~
8273 \SpecialChar ~
8274 \SpecialChar ~
8275 \SpecialChar ~
8276 Toggles Sdcdbsrc mode (turns it off) 
8277 \newline 
8278 ;; 
8279 \newline 
8280 ;; C-c C-f\SpecialChar ~
8281 \SpecialChar ~
8282 \SpecialChar ~
8283 \SpecialChar ~
8284 \SpecialChar ~
8285 \SpecialChar ~
8286 \SpecialChar ~
8287 \SpecialChar ~
8288  sdcdb-finish-from-src\SpecialChar ~
8289 \SpecialChar ~
8290 \SpecialChar ~
8291 \SpecialChar ~
8292 \SpecialChar ~
8293 \SpecialChar ~
8294 \SpecialChar ~
8295 \SpecialChar ~
8296 SDCDB finish command 
8297 \newline 
8298 ;; 
8299 \newline 
8300 ;; C-x SPC\SpecialChar ~
8301 \SpecialChar ~
8302 \SpecialChar ~
8303 \SpecialChar ~
8304 \SpecialChar ~
8305 \SpecialChar ~
8306 \SpecialChar ~
8307 \SpecialChar ~
8308  sdcdb-break\SpecialChar ~
8309 \SpecialChar ~
8310 \SpecialChar ~
8311 \SpecialChar ~
8312 \SpecialChar ~
8313 \SpecialChar ~
8314 \SpecialChar ~
8315 \SpecialChar ~
8316 \SpecialChar ~
8317 \SpecialChar ~
8318 \SpecialChar ~
8319 \SpecialChar ~
8320 \SpecialChar ~
8321 \SpecialChar ~
8322 \SpecialChar ~
8323 \SpecialChar ~
8324 \SpecialChar ~
8325 \SpecialChar ~
8326 Set break for line with point 
8327 \newline 
8328 ;; ESC t\SpecialChar ~
8329 \SpecialChar ~
8330 \SpecialChar ~
8331 \SpecialChar ~
8332 \SpecialChar ~
8333 \SpecialChar ~
8334 \SpecialChar ~
8335 \SpecialChar ~
8336 \SpecialChar ~
8337 \SpecialChar ~
8338  sdcdbsrc-mode\SpecialChar ~
8339 \SpecialChar ~
8340 \SpecialChar ~
8341 \SpecialChar ~
8342 \SpecialChar ~
8343 \SpecialChar ~
8344 \SpecialChar ~
8345 \SpecialChar ~
8346 \SpecialChar ~
8347 \SpecialChar ~
8348 \SpecialChar ~
8349 \SpecialChar ~
8350 \SpecialChar ~
8351 \SpecialChar ~
8352 \SpecialChar ~
8353 \SpecialChar ~
8354 Toggle Sdcdbsrc mode 
8355 \newline 
8356 ;; ESC m\SpecialChar ~
8357 \SpecialChar ~
8358 \SpecialChar ~
8359 \SpecialChar ~
8360 \SpecialChar ~
8361 \SpecialChar ~
8362 \SpecialChar ~
8363 \SpecialChar ~
8364 \SpecialChar ~
8365 \SpecialChar ~
8366  sdcdbsrc-srcmode\SpecialChar ~
8367 \SpecialChar ~
8368 \SpecialChar ~
8369 \SpecialChar ~
8370 \SpecialChar ~
8371 \SpecialChar ~
8372 \SpecialChar ~
8373 \SpecialChar ~
8374 \SpecialChar ~
8375 \SpecialChar ~
8376 \SpecialChar ~
8377 \SpecialChar ~
8378  Toggle list mode 
8379 \newline 
8380 ;; 
8381 \newline 
8382
8383 \layout Section
8384
8385 Other Processors
8386 \layout Subsection
8387
8388 The Z80 and gbz80 port
8389 \layout Standard
8390
8391 SDCC can target both the Zilog Z80 and the Nintendo Gameboy's Z80-like gbz80.
8392  The port is incomplete - long support is incomplete (mul, div and mod are
8393  unimplimented), and both float and bitfield support is missing, but apart
8394  from that the code generated is correct.
8395 \layout Standard
8396
8397 As always, the code is the authoritave reference - see z80/ralloc.c and z80/gen.c.
8398  The stack frame is similar to that generated by the IAR Z80 compiler.
8399  IX is used as the base pointer, HL is used as a temporary register, and
8400  BC and DE are available for holding varibles.
8401  IY is currently unusued.
8402  Return values are stored in HL.
8403  One bad side effect of using IX as the base pointer is that a functions
8404  stack frame is limited to 127 bytes - this will be fixed in a later version.
8405 \layout Section
8406
8407 Support
8408 \layout Standard
8409
8410 SDCC has grown to be large project, the compiler alone (without the Assembler
8411  Package, Preprocessor) is about 40,000 lines of code (blank stripped).
8412  The open source nature of this project is a key to its continued growth
8413  and support.
8414  You gain the benefit and support of many active software developers and
8415  end users.
8416  Is SDCC perfect? No, that's why we need your help.
8417  The developers take pride in fixing reported bugs.
8418  You can help by reporting the bugs and helping other SDCC users.
8419  There are lots of ways to contribute, and we encourage you to take part
8420  in making SDCC a great software package.
8421 \layout Subsection
8422
8423 Reporting Bugs
8424 \layout Standard
8425
8426 Send an email to the mailing list at 'user-sdcc@sdcc.sourceforge.net' or 'devel-sd
8427 cc@sdcc.sourceforge.net'.
8428  Bugs will be fixed ASAP.
8429  When reporting a bug, it is very useful to include a small test program
8430  which reproduces the problem.
8431  If you can isolate the problem by looking at the generated assembly code,
8432  this can be very helpful.
8433  Compiling your program with the --dumpall option can sometimes be useful
8434  in locating optimization problems.
8435 \layout Subsection
8436
8437 Acknowledgments
8438 \layout Standard
8439
8440 Sandeep Dutta(sandeep.dutta@usa.net) - SDCC, the compiler, MCS51 code generator,
8441  Debugger, AVR port
8442 \newline 
8443 Alan Baldwin (baldwin@shop-pdp.kent.edu) - Initial version of ASXXXX & ASLINK.
8444  
8445 \newline 
8446 John Hartman (jhartman@compuserve.com) - Porting ASXXX & ASLINK for 8051
8447 \newline 
8448 Dmitry S.
8449  Obukhov (dso@usa.net) - malloc & serial i/o routines.
8450  
8451 \newline 
8452 Daniel Drotos <drdani@mazsola.iit.uni-miskolc.hu> - for his Freeware simulator
8453 \newline 
8454 Malini Dutta(malini_dutta@hotmail.com) - my wife for her patience and support.
8455 \newline 
8456 Unknown - for the GNU C - preprocessor.
8457 \newline 
8458 Michael Hope - The Z80 and Z80GB port, 186 development
8459 \newline 
8460 Kevin Vigor - The DS390 port.
8461 \newline 
8462 Johan Knol - DS390/TINI libs, lots of fixes and enhancements.
8463 \newline 
8464 Scott Datallo - PIC port.
8465 \newline 
8466 (Thanks to all the other volunteer developers who have helped with coding,
8467  testing, web-page creation, distribution sets, etc.
8468  You know who you are :-)
8469 \newline 
8470
8471 \layout Standard
8472
8473 This document initially written by Sandeep Dutta
8474 \layout Standard
8475
8476 All product names mentioned herein may be trademarks of their respective
8477  companies.
8478  
8479 \layout Standard
8480
8481
8482 \begin_inset LatexCommand \index{}
8483
8484 \end_inset 
8485
8486
8487 \the_end