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