the pslatex font seems to cause less problems on windoze machines then times
[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 Standard
4438
4439 Note djnz instruction can be used for 8-bit values 
4440 \emph on 
4441 only
4442 \emph default 
4443 , therefore it is advantageous to declare loop control symbols as 
4444 \emph on 
4445 char
4446 \emph default 
4447 .
4448  Ofcourse this may not be possible on all situations.
4449 \layout Subsubsection
4450
4451 Algebraic Simplifications
4452 \layout Standard
4453
4454 SDCC does numerous algebraic simplifications, the following is a small sub-set
4455  of these optimizations.
4456 \newline 
4457
4458 \newline 
4459
4460 \family typewriter 
4461 i = j + 0 ; /* changed to */ i = j; 
4462 \newline 
4463 i /= 2; /* changed to */ i >>= 1; 
4464 \newline 
4465 i = j - j ; /* changed to */ i = 0; 
4466 \newline 
4467 i = j / 1 ; /* changed to */ i = j;
4468 \family default 
4469
4470 \newline 
4471
4472 \newline 
4473 Note the subexpressions given above are generally introduced by macro expansions
4474  or as a result of copy/constant propagation.
4475 \layout Subsubsection
4476
4477 'switch' Statements
4478 \layout Standard
4479
4480 SDCC changes switch statements to jump tables when the following conditions
4481  are true.
4482  
4483 \layout Itemize
4484
4485 The case labels are in numerical sequence, the labels need not be in order,
4486  and the starting number need not be one or zero.
4487 \newline 
4488
4489 \newline 
4490
4491 \family typewriter 
4492 switch(i) {\SpecialChar ~
4493  \SpecialChar ~
4494  \SpecialChar ~
4495  \SpecialChar ~
4496  \SpecialChar ~
4497  \SpecialChar ~
4498  \SpecialChar ~
4499  \SpecialChar ~
4500  \SpecialChar ~
4501  \SpecialChar ~
4502  \SpecialChar ~
4503  \SpecialChar ~
4504  \SpecialChar ~
4505 switch (i) { 
4506 \newline 
4507 case 4:...
4508  \SpecialChar ~
4509  \SpecialChar ~
4510  \SpecialChar ~
4511  \SpecialChar ~
4512  \SpecialChar ~
4513  \SpecialChar ~
4514  \SpecialChar ~
4515  \SpecialChar ~
4516  \SpecialChar ~
4517  \SpecialChar ~
4518  \SpecialChar ~
4519  \SpecialChar ~
4520  \SpecialChar ~
4521 case 1: ...
4522  
4523 \newline 
4524 case 5:...
4525  \SpecialChar ~
4526  \SpecialChar ~
4527  \SpecialChar ~
4528  \SpecialChar ~
4529  \SpecialChar ~
4530  \SpecialChar ~
4531  \SpecialChar ~
4532  \SpecialChar ~
4533  \SpecialChar ~
4534  \SpecialChar ~
4535  \SpecialChar ~
4536  \SpecialChar ~
4537  \SpecialChar ~
4538 case 2: ...
4539  
4540 \newline 
4541 case 3:...
4542  \SpecialChar ~
4543  \SpecialChar ~
4544  \SpecialChar ~
4545  \SpecialChar ~
4546  \SpecialChar ~
4547  \SpecialChar ~
4548  \SpecialChar ~
4549  \SpecialChar ~
4550  \SpecialChar ~
4551  \SpecialChar ~
4552  \SpecialChar ~
4553  \SpecialChar ~
4554  \SpecialChar ~
4555 case 3: ...
4556  
4557 \newline 
4558 case 6:...
4559  \SpecialChar ~
4560  \SpecialChar ~
4561  \SpecialChar ~
4562  \SpecialChar ~
4563  \SpecialChar ~
4564  \SpecialChar ~
4565  \SpecialChar ~
4566  \SpecialChar ~
4567  \SpecialChar ~
4568  \SpecialChar ~
4569  \SpecialChar ~
4570  \SpecialChar ~
4571  \SpecialChar ~
4572 case 4: ...
4573  
4574 \newline 
4575 }\SpecialChar ~
4576  \SpecialChar ~
4577  \SpecialChar ~
4578  \SpecialChar ~
4579  \SpecialChar ~
4580  \SpecialChar ~
4581  \SpecialChar ~
4582  \SpecialChar ~
4583  \SpecialChar ~
4584  \SpecialChar ~
4585  \SpecialChar ~
4586  \SpecialChar ~
4587  \SpecialChar ~
4588  \SpecialChar ~
4589  \SpecialChar ~
4590  \SpecialChar ~
4591  \SpecialChar ~
4592  \SpecialChar ~
4593 }
4594 \newline 
4595
4596 \newline 
4597
4598 \family default 
4599 Both the above switch statements will be implemented using a jump-table.
4600 \layout Itemize
4601
4602 The number of case labels is at least three, since it takes two conditional
4603  statements to handle the boundary conditions.
4604 \layout Itemize
4605
4606 The number of case labels is less than 84, since each label takes 3 bytes
4607  and a jump-table can be utmost 256 bytes long.
4608  
4609 \layout Standard
4610
4611 Switch statements which have gaps in the numeric sequence or those that
4612  have more that 84 case labels can be split into more than one switch statement
4613  for efficient code generation, e.g.:
4614 \newline 
4615
4616 \newline 
4617
4618 \family typewriter 
4619 switch (i) { 
4620 \newline 
4621 case 1: ...
4622  
4623 \newline 
4624 case 2: ...
4625  
4626 \newline 
4627 case 3: ...
4628  
4629 \newline 
4630 case 4: ...
4631  
4632 \newline 
4633 case 9: ...
4634  
4635 \newline 
4636 case 10: ...
4637  
4638 \newline 
4639 case 11: ...
4640  
4641 \newline 
4642 case 12: ...
4643  
4644 \newline 
4645 }
4646 \family default 
4647
4648 \newline 
4649
4650 \newline 
4651 If the above switch statement is broken down into two switch statements
4652 \newline 
4653
4654 \newline 
4655
4656 \family typewriter 
4657 switch (i) { 
4658 \newline 
4659 case 1: ...
4660  
4661 \newline 
4662 case 2: ...
4663  
4664 \newline 
4665 case 3: ...
4666  
4667 \newline 
4668 case 4: ...
4669  
4670 \newline 
4671 }
4672 \newline 
4673
4674 \newline 
4675
4676 \family default 
4677 and
4678 \family typewriter 
4679
4680 \newline 
4681
4682 \newline 
4683 switch (i) { 
4684 \newline 
4685 case 9: \SpecialChar ~
4686 ...
4687  
4688 \newline 
4689 case 10: ...
4690  
4691 \newline 
4692 case 11: ...
4693  
4694 \newline 
4695 case 12:\SpecialChar ~
4696 ...
4697  
4698 \newline 
4699 }
4700 \newline 
4701
4702 \newline 
4703
4704 \family default 
4705 then both the switch statements will be implemented using jump-tables whereas
4706  the unmodified switch statement will not be.
4707 \layout Subsubsection
4708
4709 Bit-shifting Operations.
4710 \layout Standard
4711
4712 Bit shifting is one of the most frequently used operation in embedded programmin
4713 g.
4714  SDCC tries to implement bit-shift operations in the most efficient way
4715  possible, e.g.:
4716 \newline 
4717
4718 \family typewriter 
4719
4720 \newline 
4721 unsigned char i;
4722 \newline 
4723 ...
4724  
4725 \newline 
4726 i>>= 4; 
4727 \newline 
4728 ...
4729 \newline 
4730
4731 \family default 
4732
4733 \newline 
4734 generates the following code:
4735 \newline 
4736
4737 \family typewriter 
4738
4739 \newline 
4740 mov a,_i 
4741 \newline 
4742 swap a 
4743 \newline 
4744 anl a,#0x0f 
4745 \newline 
4746 mov _i,a
4747 \family default 
4748
4749 \newline 
4750
4751 \newline 
4752 In general SDCC will never setup a loop if the shift count is known.
4753  Another example:
4754 \newline 
4755
4756 \newline 
4757
4758 \family typewriter 
4759 unsigned int i; 
4760 \newline 
4761 ...
4762  
4763 \newline 
4764 i >>= 9; 
4765 \newline 
4766 ...
4767 \family default 
4768
4769 \newline 
4770
4771 \newline 
4772 will generate:
4773 \newline 
4774
4775 \newline 
4776
4777 \family typewriter 
4778 mov a,(_i + 1) 
4779 \newline 
4780 mov (_i + 1),#0x00 
4781 \newline 
4782 clr c 
4783 \newline 
4784 rrc a 
4785 \newline 
4786 mov _i,a
4787 \family default 
4788
4789 \newline 
4790
4791 \newline 
4792 Note that SDCC stores numbers in little-endian format (i.e.
4793  lowest order first).
4794 \layout Subsubsection
4795
4796 Bit-rotation
4797 \layout Standard
4798
4799 A special case of the bit-shift operation is bit rotation, SDCC recognizes
4800  the following expression to be a left bit-rotation:
4801 \newline 
4802
4803 \newline 
4804
4805 \family typewriter 
4806 unsigned char i; 
4807 \newline 
4808 ...
4809  
4810 \newline 
4811 i = ((i << 1) | (i >> 7)); 
4812 \family default 
4813
4814 \newline 
4815 ...
4816 \newline 
4817
4818 \newline 
4819 will generate the following code:
4820 \newline 
4821
4822 \newline 
4823
4824 \family typewriter 
4825 mov a,_i 
4826 \newline 
4827 rl a 
4828 \newline 
4829 mov _i,a
4830 \family default 
4831
4832 \newline 
4833
4834 \newline 
4835 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
4836 ns of this case will also be recognized as bit-rotation, i.e.: 
4837 \newline 
4838
4839 \newline 
4840
4841 \family typewriter 
4842 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
4843 \layout Subsubsection
4844
4845 Highest Order Bit
4846 \layout Standard
4847
4848 It is frequently required to obtain the highest order bit of an integral
4849  type (long, int, short or char types).
4850  SDCC recognizes the following expression to yield the highest order bit
4851  and generates optimized code for it, e.g.:
4852 \newline 
4853
4854 \newline 
4855  
4856 \family typewriter 
4857 unsigned int gint; 
4858 \newline 
4859
4860 \newline 
4861 foo () { 
4862 \newline 
4863 unsigned char hob; 
4864 \newline 
4865 \SpecialChar ~
4866 \SpecialChar ~
4867 ...
4868  
4869 \newline 
4870 \SpecialChar ~
4871 \SpecialChar ~
4872 hob = (gint >> 15) & 1; 
4873 \newline 
4874 \SpecialChar ~
4875 \SpecialChar ~
4876 ..
4877  
4878 \newline 
4879 }
4880 \family default 
4881
4882 \newline 
4883
4884 \newline 
4885 will generate the following code:
4886 \newline 
4887
4888 \family typewriter 
4889
4890 \newline 
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 \SpecialChar ~
4908 \SpecialChar ~
4909 \SpecialChar ~
4910 \SpecialChar ~
4911 \SpecialChar ~
4912 \SpecialChar ~
4913 \SpecialChar ~
4914 \SpecialChar ~
4915 \SpecialChar ~
4916 \SpecialChar ~
4917 \SpecialChar ~
4918 \SpecialChar ~
4919  61 ;\SpecialChar ~
4920  hob.c 7 
4921 \newline 
4922 \SpecialChar ~
4923 \SpecialChar ~
4924  000A E5*01\SpecialChar ~
4925 \SpecialChar ~
4926 \SpecialChar ~
4927 \SpecialChar ~
4928 \SpecialChar ~
4929 \SpecialChar ~
4930 \SpecialChar ~
4931 \SpecialChar ~
4932 \SpecialChar ~
4933 \SpecialChar ~
4934 \SpecialChar ~
4935 \SpecialChar ~
4936 \SpecialChar ~
4937 \SpecialChar ~
4938 \SpecialChar ~
4939  62\SpecialChar ~
4940 \SpecialChar ~
4941 \SpecialChar ~
4942 \SpecialChar ~
4943 \SpecialChar ~
4944 \SpecialChar ~
4945 \SpecialChar ~
4946 \SpecialChar ~
4947  mov\SpecialChar ~
4948  a,(_gint + 1) 
4949 \newline 
4950 \SpecialChar ~
4951 \SpecialChar ~
4952  000C 33\SpecialChar ~
4953 \SpecialChar ~
4954 \SpecialChar ~
4955 \SpecialChar ~
4956 \SpecialChar ~
4957 \SpecialChar ~
4958 \SpecialChar ~
4959 \SpecialChar ~
4960 \SpecialChar ~
4961 \SpecialChar ~
4962 \SpecialChar ~
4963 \SpecialChar ~
4964 \SpecialChar ~
4965 \SpecialChar ~
4966 \SpecialChar ~
4967 \SpecialChar ~
4968 \SpecialChar ~
4969 \SpecialChar ~
4970  63\SpecialChar ~
4971 \SpecialChar ~
4972 \SpecialChar ~
4973 \SpecialChar ~
4974 \SpecialChar ~
4975 \SpecialChar ~
4976 \SpecialChar ~
4977 \SpecialChar ~
4978  rlc\SpecialChar ~
4979  a 
4980 \newline 
4981 \SpecialChar ~
4982 \SpecialChar ~
4983  000D E4\SpecialChar ~
4984 \SpecialChar ~
4985 \SpecialChar ~
4986 \SpecialChar ~
4987 \SpecialChar ~
4988 \SpecialChar ~
4989 \SpecialChar ~
4990 \SpecialChar ~
4991 \SpecialChar ~
4992 \SpecialChar ~
4993 \SpecialChar ~
4994 \SpecialChar ~
4995 \SpecialChar ~
4996 \SpecialChar ~
4997 \SpecialChar ~
4998 \SpecialChar ~
4999 \SpecialChar ~
5000 \SpecialChar ~
5001  64\SpecialChar ~
5002 \SpecialChar ~
5003 \SpecialChar ~
5004 \SpecialChar ~
5005 \SpecialChar ~
5006 \SpecialChar ~
5007 \SpecialChar ~
5008 \SpecialChar ~
5009  clr\SpecialChar ~
5010  a 
5011 \newline 
5012 \SpecialChar ~
5013 \SpecialChar ~
5014  000E 13\SpecialChar ~
5015 \SpecialChar ~
5016 \SpecialChar ~
5017 \SpecialChar ~
5018 \SpecialChar ~
5019 \SpecialChar ~
5020 \SpecialChar ~
5021 \SpecialChar ~
5022 \SpecialChar ~
5023 \SpecialChar ~
5024 \SpecialChar ~
5025 \SpecialChar ~
5026 \SpecialChar ~
5027 \SpecialChar ~
5028 \SpecialChar ~
5029 \SpecialChar ~
5030 \SpecialChar ~
5031 \SpecialChar ~
5032  65\SpecialChar ~
5033 \SpecialChar ~
5034 \SpecialChar ~
5035 \SpecialChar ~
5036 \SpecialChar ~
5037 \SpecialChar ~
5038 \SpecialChar ~
5039 \SpecialChar ~
5040  rrc\SpecialChar ~
5041  a 
5042 \newline 
5043 \SpecialChar ~
5044 \SpecialChar ~
5045  000F F5*02\SpecialChar ~
5046 \SpecialChar ~
5047 \SpecialChar ~
5048 \SpecialChar ~
5049 \SpecialChar ~
5050 \SpecialChar ~
5051 \SpecialChar ~
5052 \SpecialChar ~
5053 \SpecialChar ~
5054 \SpecialChar ~
5055 \SpecialChar ~
5056 \SpecialChar ~
5057 \SpecialChar ~
5058 \SpecialChar ~
5059 \SpecialChar ~
5060  66\SpecialChar ~
5061 \SpecialChar ~
5062 \SpecialChar ~
5063 \SpecialChar ~
5064 \SpecialChar ~
5065 \SpecialChar ~
5066 \SpecialChar ~
5067 \SpecialChar ~
5068  mov\SpecialChar ~
5069  _foo_hob_1_1,a
5070 \newline 
5071
5072 \newline 
5073
5074 \family default 
5075 Variations of this case however will 
5076 \emph on 
5077 not
5078 \emph default 
5079  be recognized.
5080  It is a standard C expression, so I heartily recommend this be the only
5081  way to get the highest order bit, (it is portable).
5082  Of course it will be recognized even if it is embedded in other expressions,
5083  e.g.:
5084 \newline 
5085
5086 \newline 
5087
5088 \family typewriter 
5089 xyz = gint + ((gint >> 15) & 1);
5090 \family default 
5091
5092 \newline 
5093
5094 \newline 
5095 will still be recognized.
5096 \layout Subsubsection
5097
5098 Peep-hole Optimizer
5099 \layout Standard
5100
5101 The compiler uses a rule based, pattern matching and re-writing mechanism
5102  for peep-hole optimization.
5103  It is inspired by 
5104 \emph on 
5105 copt
5106 \emph default 
5107  a peep-hole optimizer by Christopher W.
5108  Fraser (cwfraser@microsoft.com).
5109  A default set of rules are compiled into the compiler, additional rules
5110  may be added with the 
5111 \emph on 
5112 --peep-file <filename>
5113 \emph default 
5114  option.
5115  The rule language is best illustrated with examples.
5116 \newline 
5117
5118 \newline 
5119
5120 \family typewriter 
5121 replace { 
5122 \newline 
5123 \SpecialChar ~
5124 \SpecialChar ~
5125 mov %1,a 
5126 \newline 
5127 \SpecialChar ~
5128 \SpecialChar ~
5129 mov a,%1
5130 \newline 
5131 } by {
5132 \newline 
5133 \SpecialChar ~
5134 \SpecialChar ~
5135 mov %1,a
5136 \newline 
5137 }
5138 \family default 
5139
5140 \newline 
5141
5142 \newline 
5143 The above rule will change the following assembly sequence:
5144 \newline 
5145
5146 \newline 
5147
5148 \family typewriter 
5149 \SpecialChar ~
5150 \SpecialChar ~
5151 mov r1,a 
5152 \newline 
5153 \SpecialChar ~
5154 \SpecialChar ~
5155 mov a,r1
5156 \family default 
5157
5158 \newline 
5159
5160 \newline 
5161 to
5162 \newline 
5163
5164 \newline 
5165
5166 \family typewriter 
5167 mov r1,a
5168 \family default 
5169
5170 \newline 
5171
5172 \newline 
5173 Note: All occurrences of a 
5174 \emph on 
5175 %n
5176 \emph default 
5177  (pattern variable) must denote the same string.
5178  With the above rule, the assembly sequence:
5179 \newline 
5180
5181 \newline 
5182
5183 \family typewriter 
5184 \SpecialChar ~
5185 \SpecialChar ~
5186 mov r1,a 
5187 \newline 
5188 \SpecialChar ~
5189 \SpecialChar ~
5190 mov a,r2
5191 \family default 
5192
5193 \newline 
5194
5195 \newline 
5196 will remain unmodified.
5197 \newline 
5198
5199 \newline 
5200 Other special case optimizations may be added by the user (via 
5201 \emph on 
5202 --peep-file option
5203 \emph default 
5204 ).
5205  E.g.
5206  some variants of the 8051 MCU allow only 
5207 \family typewriter 
5208 ajmp
5209 \family default 
5210  and 
5211 \family typewriter 
5212 acall
5213 \family default 
5214 .
5215  The following two rules will change all 
5216 \family typewriter 
5217 ljmp
5218 \family default 
5219  and 
5220 \family typewriter 
5221 lcall
5222 \family default 
5223  to 
5224 \family typewriter 
5225 ajmp
5226 \family default 
5227  and 
5228 \family typewriter 
5229 acall
5230 \family default 
5231
5232 \newline 
5233
5234 \newline 
5235
5236 \family typewriter 
5237 replace { lcall %1 } by { acall %1 } 
5238 \newline 
5239 replace { ljmp %1 } by { ajmp %1 }
5240 \family default 
5241
5242 \newline 
5243
5244 \newline 
5245 The 
5246 \emph on 
5247 inline-assembler code
5248 \emph default 
5249  is also passed through the peep hole optimizer, thus the peephole optimizer
5250  can also be used as an assembly level macro expander.
5251  The rules themselves are MCU dependent whereas the rule language infra-structur
5252 e is MCU independent.
5253  Peephole optimization rules for other MCU can be easily programmed using
5254  the rule language.
5255 \newline 
5256
5257 \newline 
5258 The syntax for a rule is as follows:
5259 \newline 
5260
5261 \newline 
5262
5263 \family typewriter 
5264 rule := replace [ restart ] '{' <assembly sequence> '
5265 \backslash 
5266 n' 
5267 \newline 
5268 \SpecialChar ~
5269  \SpecialChar ~
5270  \SpecialChar ~
5271  \SpecialChar ~
5272  \SpecialChar ~
5273  \SpecialChar ~
5274  \SpecialChar ~
5275  \SpecialChar ~
5276  \SpecialChar ~
5277  \SpecialChar ~
5278  \SpecialChar ~
5279  \SpecialChar ~
5280  \SpecialChar ~
5281  \SpecialChar ~
5282  '}' by '{' '
5283 \backslash 
5284 n' 
5285 \newline 
5286 \SpecialChar ~
5287  \SpecialChar ~
5288  \SpecialChar ~
5289  \SpecialChar ~
5290  \SpecialChar ~
5291  \SpecialChar ~
5292  \SpecialChar ~
5293  \SpecialChar ~
5294  \SpecialChar ~
5295  \SpecialChar ~
5296  \SpecialChar ~
5297  \SpecialChar ~
5298  \SpecialChar ~
5299  \SpecialChar ~
5300  \SpecialChar ~
5301  \SpecialChar ~
5302  <assembly sequence> '
5303 \backslash 
5304 n' 
5305 \newline 
5306 \SpecialChar ~
5307  \SpecialChar ~
5308  \SpecialChar ~
5309  \SpecialChar ~
5310  \SpecialChar ~
5311  \SpecialChar ~
5312  \SpecialChar ~
5313  \SpecialChar ~
5314  \SpecialChar ~
5315  \SpecialChar ~
5316  \SpecialChar ~
5317  \SpecialChar ~
5318  \SpecialChar ~
5319  \SpecialChar ~
5320  '}' [if <functionName> ] '
5321 \backslash 
5322 n' 
5323 \newline 
5324
5325 \family default 
5326
5327 \newline 
5328 <assembly sequence> := assembly instruction (each instruction including
5329  labels must be on a separate line).
5330 \newline 
5331
5332 \newline 
5333 The optimizer will apply to the rules one by one from the top in the sequence
5334  of their appearance, it will terminate when all rules are exhausted.
5335  If the 'restart' option is specified, then the optimizer will start matching
5336  the rules again from the top, this option for a rule is expensive (performance)
5337 , it is intended to be used in situations where a transformation will trigger
5338  the same rule again.
5339  A good example of this the following rule:
5340 \newline 
5341
5342 \newline 
5343
5344 \family typewriter 
5345 replace restart { 
5346 \newline 
5347 \SpecialChar ~
5348 \SpecialChar ~
5349 pop %1 
5350 \newline 
5351 \SpecialChar ~
5352 \SpecialChar ~
5353 push %1 } by { 
5354 \newline 
5355 \SpecialChar ~
5356 \SpecialChar ~
5357 ; nop 
5358 \newline 
5359 }
5360 \family default 
5361
5362 \newline 
5363
5364 \newline 
5365 Note that the replace pattern cannot be a blank, but can be a comment line.
5366  Without the 'restart' option only the inner most 'pop' 'push' pair would
5367  be eliminated, i.e.:
5368 \newline 
5369
5370 \newline 
5371
5372 \family typewriter 
5373 \SpecialChar ~
5374 \SpecialChar ~
5375 pop ar1 
5376 \newline 
5377 \SpecialChar ~
5378 \SpecialChar ~
5379 pop ar2 
5380 \newline 
5381 \SpecialChar ~
5382 \SpecialChar ~
5383 push ar2 
5384 \newline 
5385 \SpecialChar ~
5386 \SpecialChar ~
5387 push ar1
5388 \family default 
5389
5390 \newline 
5391
5392 \newline 
5393 would result in:
5394 \newline 
5395
5396 \newline 
5397
5398 \family typewriter 
5399 \SpecialChar ~
5400 \SpecialChar ~
5401 pop ar1 
5402 \newline 
5403 \SpecialChar ~
5404 \SpecialChar ~
5405 ; nop 
5406 \newline 
5407 \SpecialChar ~
5408 \SpecialChar ~
5409 push ar1
5410 \family default 
5411
5412 \newline 
5413
5414 \newline 
5415
5416 \emph on 
5417 with
5418 \emph default 
5419  the restart option the rule will be applied again to the resulting code
5420  and then all the pop-push pairs will be eliminated to yield:
5421 \newline 
5422
5423 \newline 
5424
5425 \family typewriter 
5426 \SpecialChar ~
5427 \SpecialChar ~
5428 ; nop 
5429 \newline 
5430 \SpecialChar ~
5431 \SpecialChar ~
5432 ; nop
5433 \family default 
5434
5435 \newline 
5436
5437 \newline 
5438 A conditional function can be attached to a rule.
5439  Attaching rules are somewhat more involved, let me illustrate this with
5440  an example.
5441 \newline 
5442
5443 \newline 
5444
5445 \family typewriter 
5446 replace { 
5447 \newline 
5448 \SpecialChar ~
5449  \SpecialChar ~
5450  \SpecialChar ~
5451 ljmp %5 
5452 \newline 
5453 %2:
5454 \newline 
5455 } by { 
5456 \newline 
5457 \SpecialChar ~
5458  \SpecialChar ~
5459  \SpecialChar ~
5460 sjmp %5 
5461 \newline 
5462 %2:
5463 \newline 
5464 } if labelInRange
5465 \family default 
5466
5467 \newline 
5468
5469 \newline 
5470 The optimizer does a look-up of a function name table defined in function
5471  
5472 \emph on 
5473 callFuncByName
5474 \emph default 
5475  in the source file SDCCpeeph.c, with the name 
5476 \emph on 
5477 labelInRange
5478 \emph default 
5479 .
5480  If it finds a corresponding entry the function is called.
5481  Note there can be no parameters specified for these functions, in this
5482  case the use of 
5483 \emph on 
5484 %5
5485 \emph default 
5486  is crucial, since the function 
5487 \emph on 
5488 labelInRange
5489 \emph default 
5490  expects to find the label in that particular variable (the hash table containin
5491 g the variable bindings is passed as a parameter).
5492  If you want to code more such functions, take a close look at the function
5493  labelInRange and the calling mechanism in source file SDCCpeeph.c.
5494  I know this whole thing is a little kludgey, but maybe some day we will
5495  have some better means.
5496  If you are looking at this file, you will also see the default rules that
5497  are compiled into the compiler, you can add your own rules in the default
5498  set there if you get tired of specifying the --peep-file option.
5499 \layout Subsection
5500
5501 Pragmas
5502 \layout Standard
5503
5504 SDCC supports the following #pragma directives.
5505  This directives are applicable only at a function level.
5506 \layout Itemize
5507
5508 SAVE - this will save all the current options.
5509 \layout Itemize
5510
5511 RESTORE - will restore the saved options from the last save.
5512  Note that SAVES & RESTOREs cannot be nested.
5513  SDCC uses the same buffer to save the options each time a SAVE is called.
5514 \layout Itemize
5515
5516 NOGCSE - will stop global subexpression elimination.
5517 \layout Itemize
5518
5519 NOINDUCTION - will stop loop induction optimizations.
5520 \layout Itemize
5521
5522 NOJTBOUND - will not generate code for boundary value checking, when switch
5523  statements are turned into jump-tables.
5524 \layout Itemize
5525
5526 NOOVERLAY - the compiler will not overlay the parameters and local variables
5527  of a function.
5528 \layout Itemize
5529
5530 NOLOOPREVERSE - Will not do loop reversal optimization
5531 \layout Itemize
5532
5533 EXCLUDE NONE | {acc[,b[,dpl[,dph]]] - The exclude pragma disables generation
5534  of pair of push/pop instruction in ISR function (using interrupt keyword).
5535  The directive should be placed immediately before the ISR function definition
5536  and it affects ALL ISR functions following it.
5537  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
5538 EXCLUDE\SpecialChar ~
5539 none.
5540 \layout Itemize
5541
5542 CALLEE-SAVES function1[,function2[,function3...]] - The compiler by default
5543  uses a caller saves convention for register saving across function calls,
5544  however this can cause unneccessary register pushing & popping when calling
5545  small functions from larger functions.
5546  This option can be used to switch the register saving convention for the
5547  function names specified.
5548  The compiler will not save registers when calling these functions, extra
5549  code will be generated at the entry & exit for these functions to save
5550  & restore the registers used by these functions, this can SUBSTANTIALLY
5551  reduce code & improve run time performance of the generated code.
5552  In future the compiler (with interprocedural analysis) will be able to
5553  determine the appropriate scheme to use for each function call.
5554  If --callee-saves command line option is used, the function names specified
5555  in #pragma\SpecialChar ~
5556 CALLEE-SAVES is appended to the list of functions specified inthe
5557  command line.
5558 \layout Standard
5559
5560 The pragma's are intended to be used to turn-off certain optimizations which
5561  might cause the compiler to generate extra stack / data space to store
5562  compiler generated temporary variables.
5563  This usually happens in large functions.
5564  Pragma directives should be used as shown in the following example, they
5565  are used to control options & optimizations for a given function; pragmas
5566  should be placed before and/or after a function, placing pragma's inside
5567  a function body could have unpredictable results.
5568 \newline 
5569
5570 \newline 
5571
5572 \family typewriter 
5573 #pragma SAVE /* save the current settings */ 
5574 \newline 
5575 #pragma NOGCSE /* turnoff global subexpression elimination */ 
5576 \newline 
5577 #pragma NOINDUCTION /* turn off induction optimizations */ 
5578 \newline 
5579 int foo () 
5580 \newline 
5581
5582 \newline 
5583 \SpecialChar ~
5584  \SpecialChar ~
5585  ...
5586  
5587 \newline 
5588 \SpecialChar ~
5589  \SpecialChar ~
5590  /* large code */ 
5591 \newline 
5592 \SpecialChar ~
5593  \SpecialChar ~
5594  ...
5595  
5596 \newline 
5597
5598 \newline 
5599 #pragma RESTORE /* turn the optimizations back on */
5600 \family default 
5601
5602 \newline 
5603
5604 \newline 
5605 The compiler will generate a warning message when extra space is allocated.
5606  It is strongly recommended that the SAVE and RESTORE pragma's be used when
5607  changing options for a function.
5608 \layout Subsection
5609
5610
5611 \emph on 
5612 <pending: this is messy and incomplete>
5613 \emph default 
5614  Library Routines
5615 \layout Standard
5616
5617 The following library routines are provided for your convenience.
5618 \layout Standard
5619
5620 stdio.h - Contains the following functions printf & sprintf these routines
5621  are developed by Martijn van Balen <balen@natlab.research.philips.com>.
5622  
5623 \layout Standard
5624
5625 %[flags][width][b|B|l|L]type
5626 \layout Standard
5627
5628 \SpecialChar ~
5629 \SpecialChar ~
5630 \SpecialChar ~
5631 \SpecialChar ~
5632 \SpecialChar ~
5633 \SpecialChar ~
5634 \SpecialChar ~
5635 \SpecialChar ~
5636 \SpecialChar ~
5637 \SpecialChar ~
5638  flags: -\SpecialChar ~
5639 \SpecialChar ~
5640 \SpecialChar ~
5641 \SpecialChar ~
5642 \SpecialChar ~
5643 \SpecialChar ~
5644 \SpecialChar ~
5645  left justify output in specified field width 
5646 \newline 
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 \SpecialChar ~
5660 \SpecialChar ~
5661 \SpecialChar ~
5662 \SpecialChar ~
5663  +\SpecialChar ~
5664 \SpecialChar ~
5665 \SpecialChar ~
5666 \SpecialChar ~
5667 \SpecialChar ~
5668 \SpecialChar ~
5669 \SpecialChar ~
5670  prefix output with +/- sign if output is signed type 
5671 \newline 
5672 \SpecialChar ~
5673 \SpecialChar ~
5674 \SpecialChar ~
5675 \SpecialChar ~
5676 \SpecialChar ~
5677 \SpecialChar ~
5678 \SpecialChar ~
5679 \SpecialChar ~
5680 \SpecialChar ~
5681 \SpecialChar ~
5682 \SpecialChar ~
5683 \SpecialChar ~
5684 \SpecialChar ~
5685 \SpecialChar ~
5686 \SpecialChar ~
5687 \SpecialChar ~
5688  space\SpecialChar ~
5689 \SpecialChar ~
5690 \SpecialChar ~
5691  prefix output with a blank if it's a signed positive value 
5692 \newline 
5693 \SpecialChar ~
5694 \SpecialChar ~
5695 \SpecialChar ~
5696 \SpecialChar ~
5697 \SpecialChar ~
5698 \SpecialChar ~
5699 \SpecialChar ~
5700 \SpecialChar ~
5701 \SpecialChar ~
5702  width:\SpecialChar ~
5703 \SpecialChar ~
5704 \SpecialChar ~
5705 \SpecialChar ~
5706 \SpecialChar ~
5707 \SpecialChar ~
5708 \SpecialChar ~
5709 \SpecialChar ~
5710 \SpecialChar ~
5711  specifies minimum number of characters outputted for numbers 
5712 \newline 
5713 \SpecialChar ~
5714 \SpecialChar ~
5715 \SpecialChar ~
5716 \SpecialChar ~
5717 \SpecialChar ~
5718 \SpecialChar ~
5719 \SpecialChar ~
5720 \SpecialChar ~
5721 \SpecialChar ~
5722 \SpecialChar ~
5723 \SpecialChar ~
5724 \SpecialChar ~
5725 \SpecialChar ~
5726 \SpecialChar ~
5727 \SpecialChar ~
5728 \SpecialChar ~
5729 \SpecialChar ~
5730 \SpecialChar ~
5731 \SpecialChar ~
5732 \SpecialChar ~
5733 \SpecialChar ~
5734 \SpecialChar ~
5735 \SpecialChar ~
5736 \SpecialChar ~
5737 \SpecialChar ~
5738  or strings.
5739  
5740 \newline 
5741 \SpecialChar ~
5742 \SpecialChar ~
5743 \SpecialChar ~
5744 \SpecialChar ~
5745 \SpecialChar ~
5746 \SpecialChar ~
5747 \SpecialChar ~
5748 \SpecialChar ~
5749 \SpecialChar ~
5750 \SpecialChar ~
5751 \SpecialChar ~
5752 \SpecialChar ~
5753 \SpecialChar ~
5754 \SpecialChar ~
5755 \SpecialChar ~
5756 \SpecialChar ~
5757 \SpecialChar ~
5758 \SpecialChar ~
5759 \SpecialChar ~
5760 \SpecialChar ~
5761 \SpecialChar ~
5762 \SpecialChar ~
5763 \SpecialChar ~
5764 \SpecialChar ~
5765 \SpecialChar ~
5766  - For numbers, spaces are added on the left when needed.
5767  
5768 \newline 
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 \SpecialChar ~
5786 \SpecialChar ~
5787 \SpecialChar ~
5788 \SpecialChar ~
5789 \SpecialChar ~
5790 \SpecialChar ~
5791 \SpecialChar ~
5792 \SpecialChar ~
5793 \SpecialChar ~
5794 \SpecialChar ~
5795 \SpecialChar ~
5796  If width starts with a zero character, zeroes and used 
5797 \newline 
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 \SpecialChar ~
5815 \SpecialChar ~
5816 \SpecialChar ~
5817 \SpecialChar ~
5818 \SpecialChar ~
5819 \SpecialChar ~
5820 \SpecialChar ~
5821 \SpecialChar ~
5822 \SpecialChar ~
5823 \SpecialChar ~
5824 \SpecialChar ~
5825  instead of spaces.
5826  
5827 \newline 
5828 \SpecialChar ~
5829 \SpecialChar ~
5830 \SpecialChar ~
5831 \SpecialChar ~
5832 \SpecialChar ~
5833 \SpecialChar ~
5834 \SpecialChar ~
5835 \SpecialChar ~
5836 \SpecialChar ~
5837 \SpecialChar ~
5838 \SpecialChar ~
5839 \SpecialChar ~
5840 \SpecialChar ~
5841 \SpecialChar ~
5842 \SpecialChar ~
5843 \SpecialChar ~
5844 \SpecialChar ~
5845 \SpecialChar ~
5846 \SpecialChar ~
5847 \SpecialChar ~
5848 \SpecialChar ~
5849 \SpecialChar ~
5850 \SpecialChar ~
5851 \SpecialChar ~
5852 \SpecialChar ~
5853  - For strings, spaces are are added on the left or right (when 
5854 \newline 
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 \SpecialChar ~
5872 \SpecialChar ~
5873 \SpecialChar ~
5874 \SpecialChar ~
5875 \SpecialChar ~
5876 \SpecialChar ~
5877 \SpecialChar ~
5878 \SpecialChar ~
5879 \SpecialChar ~
5880 \SpecialChar ~
5881 \SpecialChar ~
5882  flag '-' is used) when needed.
5883  
5884 \newline 
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 \SpecialChar ~
5900 \SpecialChar ~
5901 \SpecialChar ~
5902 \SpecialChar ~
5903 \SpecialChar ~
5904 \SpecialChar ~
5905 \SpecialChar ~
5906 \SpecialChar ~
5907 \SpecialChar ~
5908 \SpecialChar ~
5909 \SpecialChar ~
5910  
5911 \newline 
5912 \SpecialChar ~
5913 \SpecialChar ~
5914 \SpecialChar ~
5915 \SpecialChar ~
5916 \SpecialChar ~
5917 \SpecialChar ~
5918 \SpecialChar ~
5919 \SpecialChar ~
5920 \SpecialChar ~
5921  b/B:\SpecialChar ~
5922 \SpecialChar ~
5923 \SpecialChar ~
5924 \SpecialChar ~
5925 \SpecialChar ~
5926 \SpecialChar ~
5927 \SpecialChar ~
5928 \SpecialChar ~
5929 \SpecialChar ~
5930 \SpecialChar ~
5931 \SpecialChar ~
5932  byte argument (used by d, u, o, x, X) 
5933 \newline 
5934 \SpecialChar ~
5935 \SpecialChar ~
5936 \SpecialChar ~
5937 \SpecialChar ~
5938 \SpecialChar ~
5939 \SpecialChar ~
5940 \SpecialChar ~
5941 \SpecialChar ~
5942 \SpecialChar ~
5943  l/L:\SpecialChar ~
5944 \SpecialChar ~
5945 \SpecialChar ~
5946 \SpecialChar ~
5947 \SpecialChar ~
5948 \SpecialChar ~
5949 \SpecialChar ~
5950 \SpecialChar ~
5951 \SpecialChar ~
5952 \SpecialChar ~
5953 \SpecialChar ~
5954  long argument (used by d, u, o, x, X)
5955 \newline 
5956 \SpecialChar ~
5957 \SpecialChar ~
5958 \SpecialChar ~
5959 \SpecialChar ~
5960 \SpecialChar ~
5961 \SpecialChar ~
5962 \SpecialChar ~
5963 \SpecialChar ~
5964 \SpecialChar ~
5965  type:\SpecialChar ~
5966  d\SpecialChar ~
5967 \SpecialChar ~
5968 \SpecialChar ~
5969 \SpecialChar ~
5970 \SpecialChar ~
5971 \SpecialChar ~
5972 \SpecialChar ~
5973  decimal number 
5974 \newline 
5975 \SpecialChar ~
5976 \SpecialChar ~
5977 \SpecialChar ~
5978 \SpecialChar ~
5979 \SpecialChar ~
5980 \SpecialChar ~
5981 \SpecialChar ~
5982 \SpecialChar ~
5983 \SpecialChar ~
5984 \SpecialChar ~
5985 \SpecialChar ~
5986 \SpecialChar ~
5987 \SpecialChar ~
5988 \SpecialChar ~
5989 \SpecialChar ~
5990 \SpecialChar ~
5991  u\SpecialChar ~
5992 \SpecialChar ~
5993 \SpecialChar ~
5994 \SpecialChar ~
5995 \SpecialChar ~
5996 \SpecialChar ~
5997 \SpecialChar ~
5998  unsigned decimal number 
5999 \newline 
6000 \SpecialChar ~
6001 \SpecialChar ~
6002 \SpecialChar ~
6003 \SpecialChar ~
6004 \SpecialChar ~
6005 \SpecialChar ~
6006 \SpecialChar ~
6007 \SpecialChar ~
6008 \SpecialChar ~
6009 \SpecialChar ~
6010 \SpecialChar ~
6011 \SpecialChar ~
6012 \SpecialChar ~
6013 \SpecialChar ~
6014 \SpecialChar ~
6015 \SpecialChar ~
6016  o\SpecialChar ~
6017 \SpecialChar ~
6018 \SpecialChar ~
6019 \SpecialChar ~
6020 \SpecialChar ~
6021 \SpecialChar ~
6022 \SpecialChar ~
6023  unsigned octal number 
6024 \newline 
6025 \SpecialChar ~
6026 \SpecialChar ~
6027 \SpecialChar ~
6028 \SpecialChar ~
6029 \SpecialChar ~
6030 \SpecialChar ~
6031 \SpecialChar ~
6032 \SpecialChar ~
6033 \SpecialChar ~
6034 \SpecialChar ~
6035 \SpecialChar ~
6036 \SpecialChar ~
6037 \SpecialChar ~
6038 \SpecialChar ~
6039 \SpecialChar ~
6040 \SpecialChar ~
6041  x\SpecialChar ~
6042 \SpecialChar ~
6043 \SpecialChar ~
6044 \SpecialChar ~
6045 \SpecialChar ~
6046 \SpecialChar ~
6047 \SpecialChar ~
6048  unsigned hexadecimal number (0-9, a-f) 
6049 \newline 
6050 \SpecialChar ~
6051 \SpecialChar ~
6052 \SpecialChar ~
6053 \SpecialChar ~
6054 \SpecialChar ~
6055 \SpecialChar ~
6056 \SpecialChar ~
6057 \SpecialChar ~
6058 \SpecialChar ~
6059 \SpecialChar ~
6060 \SpecialChar ~
6061 \SpecialChar ~
6062 \SpecialChar ~
6063 \SpecialChar ~
6064 \SpecialChar ~
6065 \SpecialChar ~
6066  X\SpecialChar ~
6067 \SpecialChar ~
6068 \SpecialChar ~
6069 \SpecialChar ~
6070 \SpecialChar ~
6071 \SpecialChar ~
6072 \SpecialChar ~
6073  unsigned hexadecimal number (0-9, A-F) 
6074 \newline 
6075 \SpecialChar ~
6076 \SpecialChar ~
6077 \SpecialChar ~
6078 \SpecialChar ~
6079 \SpecialChar ~
6080 \SpecialChar ~
6081 \SpecialChar ~
6082 \SpecialChar ~
6083 \SpecialChar ~
6084 \SpecialChar ~
6085 \SpecialChar ~
6086 \SpecialChar ~
6087 \SpecialChar ~
6088 \SpecialChar ~
6089 \SpecialChar ~
6090 \SpecialChar ~
6091  c\SpecialChar ~
6092 \SpecialChar ~
6093 \SpecialChar ~
6094 \SpecialChar ~
6095 \SpecialChar ~
6096 \SpecialChar ~
6097 \SpecialChar ~
6098  character 
6099 \newline 
6100 \SpecialChar ~
6101 \SpecialChar ~
6102 \SpecialChar ~
6103 \SpecialChar ~
6104 \SpecialChar ~
6105 \SpecialChar ~
6106 \SpecialChar ~
6107 \SpecialChar ~
6108 \SpecialChar ~
6109 \SpecialChar ~
6110 \SpecialChar ~
6111 \SpecialChar ~
6112 \SpecialChar ~
6113 \SpecialChar ~
6114 \SpecialChar ~
6115 \SpecialChar ~
6116  s\SpecialChar ~
6117 \SpecialChar ~
6118 \SpecialChar ~
6119 \SpecialChar ~
6120 \SpecialChar ~
6121 \SpecialChar ~
6122 \SpecialChar ~
6123  string (generic pointer) 
6124 \newline 
6125 \SpecialChar ~
6126 \SpecialChar ~
6127 \SpecialChar ~
6128 \SpecialChar ~
6129 \SpecialChar ~
6130 \SpecialChar ~
6131 \SpecialChar ~
6132 \SpecialChar ~
6133 \SpecialChar ~
6134 \SpecialChar ~
6135 \SpecialChar ~
6136 \SpecialChar ~
6137 \SpecialChar ~
6138 \SpecialChar ~
6139 \SpecialChar ~
6140 \SpecialChar ~
6141  p\SpecialChar ~
6142 \SpecialChar ~
6143 \SpecialChar ~
6144 \SpecialChar ~
6145 \SpecialChar ~
6146 \SpecialChar ~
6147 \SpecialChar ~
6148  generic pointer (I:data/idata, C:code, X:xdata, P:paged) 
6149 \newline 
6150 \SpecialChar ~
6151 \SpecialChar ~
6152 \SpecialChar ~
6153 \SpecialChar ~
6154 \SpecialChar ~
6155 \SpecialChar ~
6156 \SpecialChar ~
6157 \SpecialChar ~
6158 \SpecialChar ~
6159 \SpecialChar ~
6160 \SpecialChar ~
6161 \SpecialChar ~
6162 \SpecialChar ~
6163 \SpecialChar ~
6164 \SpecialChar ~
6165 \SpecialChar ~
6166  f\SpecialChar ~
6167 \SpecialChar ~
6168 \SpecialChar ~
6169 \SpecialChar ~
6170 \SpecialChar ~
6171 \SpecialChar ~
6172 \SpecialChar ~
6173  float (still to be implemented)
6174 \layout Standard
6175
6176 Also contains a very simple version of printf (printf_small).
6177  This simplified version of printf supports only the following formats.
6178 \layout Standard
6179
6180 format\SpecialChar ~
6181 \SpecialChar ~
6182 \SpecialChar ~
6183 \SpecialChar ~
6184 \SpecialChar ~
6185 output\SpecialChar ~
6186 type\SpecialChar ~
6187 \SpecialChar ~
6188 \SpecialChar ~
6189 \SpecialChar ~
6190 \SpecialChar ~
6191 argument-type 
6192 \newline 
6193 %d \SpecialChar ~
6194 \SpecialChar ~
6195 \SpecialChar ~
6196 \SpecialChar ~
6197 \SpecialChar ~
6198 \SpecialChar ~
6199 \SpecialChar ~
6200 \SpecialChar ~
6201 decimal \SpecialChar ~
6202 \SpecialChar ~
6203 \SpecialChar ~
6204 \SpecialChar ~
6205 \SpecialChar ~
6206  short/int 
6207 \newline 
6208 %ld\SpecialChar ~
6209 \SpecialChar ~
6210 \SpecialChar ~
6211 \SpecialChar ~
6212 \SpecialChar ~
6213 \SpecialChar ~
6214 \SpecialChar ~
6215 \SpecialChar ~
6216 decimal\SpecialChar ~
6217 \SpecialChar ~
6218 \SpecialChar ~
6219 \SpecialChar ~
6220 \SpecialChar ~
6221 \SpecialChar ~
6222 \SpecialChar ~
6223 long 
6224 \newline 
6225 %hd\SpecialChar ~
6226 \SpecialChar ~
6227 \SpecialChar ~
6228 \SpecialChar ~
6229 \SpecialChar ~
6230 \SpecialChar ~
6231 \SpecialChar ~
6232 \SpecialChar ~
6233 decimal\SpecialChar ~
6234 \SpecialChar ~
6235 \SpecialChar ~
6236 \SpecialChar ~
6237 \SpecialChar ~
6238 \SpecialChar ~
6239 \SpecialChar ~
6240 char 
6241 \newline 
6242 %x\SpecialChar ~
6243 \SpecialChar ~
6244 \SpecialChar ~
6245 \SpecialChar ~
6246 \SpecialChar ~
6247 \SpecialChar ~
6248 \SpecialChar ~
6249 \SpecialChar ~
6250 hexadecimal\SpecialChar ~
6251 \SpecialChar ~
6252 \SpecialChar ~
6253 \SpecialChar ~
6254 short/int 
6255 \newline 
6256 %lx\SpecialChar ~
6257 \SpecialChar ~
6258 \SpecialChar ~
6259 \SpecialChar ~
6260 \SpecialChar ~
6261 \SpecialChar ~
6262 \SpecialChar ~
6263 hexadecimal\SpecialChar ~
6264 \SpecialChar ~
6265 \SpecialChar ~
6266 \SpecialChar ~
6267 long 
6268 \newline 
6269 %hx\SpecialChar ~
6270 \SpecialChar ~
6271 \SpecialChar ~
6272 \SpecialChar ~
6273 \SpecialChar ~
6274 \SpecialChar ~
6275 \SpecialChar ~
6276 hexadecimal\SpecialChar ~
6277 \SpecialChar ~
6278 \SpecialChar ~
6279 \SpecialChar ~
6280 char 
6281 \newline 
6282 %o\SpecialChar ~
6283 \SpecialChar ~
6284 \SpecialChar ~
6285 \SpecialChar ~
6286 \SpecialChar ~
6287 \SpecialChar ~
6288 \SpecialChar ~
6289 \SpecialChar ~
6290 \SpecialChar ~
6291 octal\SpecialChar ~
6292 \SpecialChar ~
6293 \SpecialChar ~
6294 \SpecialChar ~
6295 \SpecialChar ~
6296 \SpecialChar ~
6297 \SpecialChar ~
6298 \SpecialChar ~
6299 \SpecialChar ~
6300 short/int 
6301 \newline 
6302 %lo\SpecialChar ~
6303 \SpecialChar ~
6304 \SpecialChar ~
6305 \SpecialChar ~
6306 \SpecialChar ~
6307 \SpecialChar ~
6308 \SpecialChar ~
6309 \SpecialChar ~
6310 octal\SpecialChar ~
6311 \SpecialChar ~
6312 \SpecialChar ~
6313 \SpecialChar ~
6314 \SpecialChar ~
6315 \SpecialChar ~
6316 \SpecialChar ~
6317 \SpecialChar ~
6318 \SpecialChar ~
6319 long 
6320 \newline 
6321 %ho\SpecialChar ~
6322 \SpecialChar ~
6323 \SpecialChar ~
6324 \SpecialChar ~
6325 \SpecialChar ~
6326 \SpecialChar ~
6327 \SpecialChar ~
6328 \SpecialChar ~
6329 octal\SpecialChar ~
6330 \SpecialChar ~
6331 \SpecialChar ~
6332 \SpecialChar ~
6333 \SpecialChar ~
6334 \SpecialChar ~
6335 \SpecialChar ~
6336 \SpecialChar ~
6337 \SpecialChar ~
6338 char 
6339 \newline 
6340 %c\SpecialChar ~
6341 \SpecialChar ~
6342 \SpecialChar ~
6343 \SpecialChar ~
6344 \SpecialChar ~
6345 \SpecialChar ~
6346 \SpecialChar ~
6347 \SpecialChar ~
6348 character\SpecialChar ~
6349 \SpecialChar ~
6350 \SpecialChar ~
6351 \SpecialChar ~
6352 \SpecialChar ~
6353 \SpecialChar ~
6354 char 
6355 \newline 
6356 %s\SpecialChar ~
6357 \SpecialChar ~
6358 \SpecialChar ~
6359 \SpecialChar ~
6360 \SpecialChar ~
6361 \SpecialChar ~
6362 \SpecialChar ~
6363 \SpecialChar ~
6364 character\SpecialChar ~
6365 \SpecialChar ~
6366 \SpecialChar ~
6367 \SpecialChar ~
6368 \SpecialChar ~
6369 _generic pointer
6370 \layout Standard
6371
6372 The routine is very stack intesive, --stack-after-data parameter should
6373  be used when using this routine, the routine also takes about 1K of code
6374  space.
6375  It also expects an external function named putchar(char) to be present
6376  (this can be changed).
6377  When using the %s format the string / pointer should be cast to a generic
6378  pointer.
6379  eg.
6380 \layout Standard
6381
6382 printf_small(
6383 \begin_inset Quotes eld
6384 \end_inset 
6385
6386 my str %s, my int %d
6387 \backslash 
6388 n
6389 \begin_inset Quotes erd
6390 \end_inset 
6391
6392 ,(char _generic *)mystr,myint);
6393 \layout Itemize
6394
6395 stdarg.h - contains definition for the following macros to be used for variable
6396  parameter list, note that a function can have a variable parameter list
6397  if and only if it is 'reentrant'
6398 \begin_deeper 
6399 \layout Standard
6400
6401 va_list, va_start, va_arg, va_end.
6402 \end_deeper 
6403 \layout Itemize
6404
6405 setjmp.h - contains defintion for ANSI setjmp & longjmp routines.
6406  Note in this case setjmp & longjmp can be used between functions executing
6407  within the same register bank, if long jmp is executed from a function
6408  that is using a different register bank from the function issuing the setjmp
6409  function, the results may be unpredictable.
6410  The jump buffer requires 3 bytes of data (the stack pointer & a 16 byte
6411  return address), and can be placed in any address space.
6412 \layout Itemize
6413
6414 stdlib.h - contains the following functions.
6415 \begin_deeper 
6416 \layout Standard
6417
6418 atoi, atol.
6419 \end_deeper 
6420 \layout Itemize
6421
6422 string.h - contains the following functions.
6423 \begin_deeper 
6424 \layout Standard
6425
6426 strcpy, strncpy, strcat, strncat, strcmp, strncmp, strchr, strrchr, strspn,
6427  strcspn, strpbrk, strstr, strlen, strtok, memcpy, memcmp, memset.
6428 \end_deeper 
6429 \layout Itemize
6430
6431 ctype.h - contains the following routines.
6432 \begin_deeper 
6433 \layout Standard
6434
6435 iscntrl, isdigit, isgraph, islower, isupper, isprint, ispunct, isspace,
6436  isxdigit, isalnum, isalpha.
6437 \end_deeper 
6438 \layout Itemize
6439
6440 malloc.h - The malloc routines are developed by Dmitry S.
6441  Obukhov (dso@usa.net).
6442  These routines will allocate memory from the external ram.
6443  Here is a description on how to use them (as described by the author).
6444 \begin_deeper 
6445 \layout Standard
6446
6447 //Example: 
6448 \newline 
6449 \SpecialChar ~
6450 \SpecialChar ~
6451 \SpecialChar ~
6452 \SpecialChar ~
6453  //\SpecialChar ~
6454 \SpecialChar ~
6455 \SpecialChar ~
6456 \SpecialChar ~
6457  #define DYNAMIC_MEMORY_SIZE 0x2000 
6458 \newline 
6459 \SpecialChar ~
6460 \SpecialChar ~
6461 \SpecialChar ~
6462 \SpecialChar ~
6463  //\SpecialChar ~
6464 \SpecialChar ~
6465 \SpecialChar ~
6466 \SpecialChar ~
6467  .....
6468  
6469 \newline 
6470 \SpecialChar ~
6471 \SpecialChar ~
6472 \SpecialChar ~
6473 \SpecialChar ~
6474  //\SpecialChar ~
6475 \SpecialChar ~
6476 \SpecialChar ~
6477 \SpecialChar ~
6478  unsigned char xdata dynamic_memory_pool[DYNAMIC_MEMORY_SIZE]; 
6479 \newline 
6480 \SpecialChar ~
6481 \SpecialChar ~
6482 \SpecialChar ~
6483 \SpecialChar ~
6484  //\SpecialChar ~
6485 \SpecialChar ~
6486 \SpecialChar ~
6487 \SpecialChar ~
6488  unsigned char xdata * current_buffer; 
6489 \newline 
6490 \SpecialChar ~
6491 \SpecialChar ~
6492 \SpecialChar ~
6493 \SpecialChar ~
6494  //\SpecialChar ~
6495 \SpecialChar ~
6496 \SpecialChar ~
6497 \SpecialChar ~
6498  .....
6499  
6500 \newline 
6501 \SpecialChar ~
6502 \SpecialChar ~
6503 \SpecialChar ~
6504 \SpecialChar ~
6505  //\SpecialChar ~
6506 \SpecialChar ~
6507 \SpecialChar ~
6508 \SpecialChar ~
6509  void main(void) 
6510 \newline 
6511 \SpecialChar ~
6512 \SpecialChar ~
6513 \SpecialChar ~
6514 \SpecialChar ~
6515  //\SpecialChar ~
6516 \SpecialChar ~
6517 \SpecialChar ~
6518 \SpecialChar ~
6519  { 
6520 \newline 
6521 \SpecialChar ~
6522 \SpecialChar ~
6523 \SpecialChar ~
6524 \SpecialChar ~
6525  //\SpecialChar ~
6526 \SpecialChar ~
6527 \SpecialChar ~
6528 \SpecialChar ~
6529 \SpecialChar ~
6530 \SpecialChar ~
6531 \SpecialChar ~
6532 \SpecialChar ~
6533  ...
6534  
6535 \newline 
6536 \SpecialChar ~
6537 \SpecialChar ~
6538 \SpecialChar ~
6539 \SpecialChar ~
6540 \SpecialChar ~
6541 //\SpecialChar ~
6542 \SpecialChar ~
6543 \SpecialChar ~
6544 \SpecialChar ~
6545 \SpecialChar ~
6546 \SpecialChar ~
6547 \SpecialChar ~
6548 \SpecialChar ~
6549  init_dynamic_memory(dynamic_memory_pool,DYNAMIC_MEMORY_SIZE); 
6550 \newline 
6551 \SpecialChar ~
6552 \SpecialChar ~
6553 \SpecialChar ~
6554 \SpecialChar ~
6555  //\SpecialChar ~
6556 \SpecialChar ~
6557 \SpecialChar ~
6558 \SpecialChar ~
6559 \SpecialChar ~
6560 \SpecialChar ~
6561 \SpecialChar ~
6562 \SpecialChar ~
6563  //Now it's possible to use malloc.
6564  
6565 \newline 
6566 \SpecialChar ~
6567 \SpecialChar ~
6568 \SpecialChar ~
6569 \SpecialChar ~
6570  //\SpecialChar ~
6571 \SpecialChar ~
6572 \SpecialChar ~
6573 \SpecialChar ~
6574 \SpecialChar ~
6575 \SpecialChar ~
6576 \SpecialChar ~
6577 \SpecialChar ~
6578  ...
6579  
6580 \newline 
6581 \SpecialChar ~
6582 \SpecialChar ~
6583 \SpecialChar ~
6584 \SpecialChar ~
6585  //\SpecialChar ~
6586 \SpecialChar ~
6587 \SpecialChar ~
6588 \SpecialChar ~
6589 \SpecialChar ~
6590 \SpecialChar ~
6591 \SpecialChar ~
6592 \SpecialChar ~
6593  current_buffer = malloc(0x100); 
6594 \newline 
6595 \SpecialChar ~
6596 \SpecialChar ~
6597 \SpecialChar ~
6598 \SpecialChar ~
6599  //
6600 \end_deeper 
6601 \layout Itemize
6602
6603 serial.h - Serial IO routines are also developed by Dmitry S.
6604  Obukhov (dso@usa.net).
6605  These routines are interrupt driven with a 256 byte circular buffer, they
6606  also expect external ram to be present.
6607  Please see documentation in file SDCCDIR/sdcc51lib/serial.c.
6608  Note the header file 
6609 \begin_inset Quotes eld
6610 \end_inset 
6611
6612 serial.h
6613 \begin_inset Quotes erd
6614 \end_inset 
6615
6616  MUST be included in the file containing the 'main' function.
6617 \layout Itemize
6618
6619 ser.h - Alternate serial routine provided by Wolfgang Esslinger <wolfgang@WiredMi
6620 nds.com> these routines are more compact and faster.
6621  Please see documentation in file SDCCDIR/sdcc51lib/ser.c
6622 \layout Itemize
6623
6624 ser_ir.h - Another alternate set of serial routines provided by Josef Wolf
6625  <jw@raven.inka.de>, these routines do not use the external ram.
6626 \layout Itemize
6627
6628 reg51.h - contains register definitions for a standard 8051
6629 \layout Itemize
6630
6631 float.h - contains min, max and other floating point related stuff.
6632 \layout Standard
6633
6634 All library routines are compiled as --model-small, they are all non-reentrant,
6635  if you plan to use the large model or want to make these routines reentrant,
6636  then they will have to be recompiled with the appropriate compiler option.
6637 \layout Standard
6638
6639 Have not had time to do the more involved routines like printf, will get
6640  to them shortly.
6641 \layout Subsection
6642
6643 Interfacing with Assembly Routines
6644 \layout Subsubsection
6645
6646 Global Registers used for Parameter Passing
6647 \layout Standard
6648
6649 The compiler always uses the global registers 
6650 \emph on 
6651 DPL,DPH,B 
6652 \emph default 
6653 and
6654 \emph on 
6655  ACC
6656 \emph default 
6657  to pass the first parameter to a routine.
6658  The second parameter onwards is either allocated on the stack (for reentrant
6659  routines or if --stack-auto is used) or in the internal / external ram
6660  (depending on the memory model).
6661  
6662 \layout Subsubsection
6663
6664 Assembler Routine(non-reentrant)
6665 \layout Standard
6666
6667 In the following example the function cfunc calls an assembler routine asm_func,
6668  which takes two parameters.
6669 \newline 
6670
6671 \newline 
6672
6673 \family typewriter 
6674 extern int asm_func(unsigned char, unsigned char);
6675 \newline 
6676
6677 \newline 
6678 int c_func (unsigned char i, unsigned char j)
6679 \newline 
6680 {
6681 \newline 
6682 \SpecialChar ~
6683 \SpecialChar ~
6684 \SpecialChar ~
6685 \SpecialChar ~
6686 return asm_func(i,j);
6687 \newline 
6688 }
6689 \newline 
6690
6691 \newline 
6692 int main()
6693 \newline 
6694 {
6695 \newline 
6696 \SpecialChar ~
6697 \SpecialChar ~
6698 \SpecialChar ~
6699 \SpecialChar ~
6700 return c_func(10,9);
6701 \newline 
6702 }
6703 \newline 
6704
6705 \newline 
6706
6707 \family default 
6708 The corresponding assembler function is:
6709 \newline 
6710
6711 \newline 
6712
6713 \family typewriter 
6714 .globl _asm_func_PARM_2 
6715 \newline 
6716 \SpecialChar ~
6717 \SpecialChar ~
6718 \SpecialChar ~
6719 \SpecialChar ~
6720 \SpecialChar ~
6721 \SpecialChar ~
6722 \SpecialChar ~
6723 \SpecialChar ~
6724 .globl _asm_func 
6725 \newline 
6726 \SpecialChar ~
6727 \SpecialChar ~
6728 \SpecialChar ~
6729 \SpecialChar ~
6730 \SpecialChar ~
6731 \SpecialChar ~
6732 \SpecialChar ~
6733 \SpecialChar ~
6734 .area OSEG 
6735 \newline 
6736 _asm_func_PARM_2:
6737 \newline 
6738 \SpecialChar ~
6739 \SpecialChar ~
6740 \SpecialChar ~
6741 \SpecialChar ~
6742 \SpecialChar ~
6743 \SpecialChar ~
6744 \SpecialChar ~
6745 \SpecialChar ~
6746 .ds      1 
6747 \newline 
6748 \SpecialChar ~
6749 \SpecialChar ~
6750 \SpecialChar ~
6751 \SpecialChar ~
6752 \SpecialChar ~
6753 \SpecialChar ~
6754 \SpecialChar ~
6755 \SpecialChar ~
6756 .area CSEG 
6757 \newline 
6758 _asm_func: 
6759 \newline 
6760 \SpecialChar ~
6761 \SpecialChar ~
6762 \SpecialChar ~
6763 \SpecialChar ~
6764 \SpecialChar ~
6765 \SpecialChar ~
6766 \SpecialChar ~
6767 \SpecialChar ~
6768 mov     a,dpl 
6769 \newline 
6770 \SpecialChar ~
6771 \SpecialChar ~
6772 \SpecialChar ~
6773 \SpecialChar ~
6774 \SpecialChar ~
6775 \SpecialChar ~
6776 \SpecialChar ~
6777 \SpecialChar ~
6778 add     a,_asm_func_PARM_2 
6779 \newline 
6780 \SpecialChar ~
6781 \SpecialChar ~
6782 \SpecialChar ~
6783 \SpecialChar ~
6784 \SpecialChar ~
6785 \SpecialChar ~
6786 \SpecialChar ~
6787 \SpecialChar ~
6788 mov     dpl,a 
6789 \newline 
6790 \SpecialChar ~
6791 \SpecialChar ~
6792 \SpecialChar ~
6793 \SpecialChar ~
6794 \SpecialChar ~
6795 \SpecialChar ~
6796 \SpecialChar ~
6797 \SpecialChar ~
6798 mov     dpl,#0x00 
6799 \newline 
6800 \SpecialChar ~
6801 \SpecialChar ~
6802 \SpecialChar ~
6803 \SpecialChar ~
6804 \SpecialChar ~
6805 \SpecialChar ~
6806 \SpecialChar ~
6807 \SpecialChar ~
6808 ret
6809 \newline 
6810
6811 \newline 
6812
6813 \family default 
6814 Note here that the return values are placed in 'dpl' - One byte return value,
6815  'dpl' LSB & 'dph' MSB for two byte values.
6816  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
6817 b' & 'acc' for four byte values.
6818 \layout Standard
6819
6820 The parameter naming convention is _<function_name>_PARM_<n>, where n is
6821  the parameter number starting from 1, and counting from the left.
6822  The first parameter is passed in 
6823 \begin_inset Quotes eld
6824 \end_inset 
6825
6826 dpl
6827 \begin_inset Quotes erd
6828 \end_inset 
6829
6830  for One bye parameter, 
6831 \begin_inset Quotes eld
6832 \end_inset 
6833
6834 dptr
6835 \begin_inset Quotes erd
6836 \end_inset 
6837
6838  if two bytes, 
6839 \begin_inset Quotes eld
6840 \end_inset 
6841
6842 b,dptr
6843 \begin_inset Quotes erd
6844 \end_inset 
6845
6846  for three bytes and 
6847 \begin_inset Quotes eld
6848 \end_inset 
6849
6850 acc,b,dptr
6851 \begin_inset Quotes erd
6852 \end_inset 
6853
6854  for four bytes, the varible name for the second parameter will be _<function_na
6855 me>_PARM_2.
6856 \newline 
6857
6858 \newline 
6859 Assemble the assembler routine with the following command:
6860 \newline 
6861
6862 \newline 
6863
6864 \family sans 
6865 \series bold 
6866 asx8051 -losg asmfunc.asm
6867 \newline 
6868
6869 \newline 
6870
6871 \family default 
6872 \series default 
6873 Then compile and link the assembler routine to the C source file with the
6874  following command:
6875 \newline 
6876
6877 \newline 
6878
6879 \family sans 
6880 \series bold 
6881 sdcc cfunc.c asmfunc.rel
6882 \layout Subsubsection
6883
6884 Assembler Routine(reentrant)
6885 \layout Standard
6886
6887 In this case the second parameter onwards will be passed on the stack, the
6888  parameters are pushed from right to left i.e.
6889  after the call the left most parameter will be on the top of the stack.
6890  Here is an example:
6891 \newline 
6892
6893 \newline 
6894
6895 \family typewriter 
6896 extern int asm_func(unsigned char, unsigned char);
6897 \newline 
6898
6899 \newline 
6900 int c_func (unsigned char i, unsigned char j) reentrant 
6901 \newline 
6902
6903 \newline 
6904 \SpecialChar ~
6905 \SpecialChar ~
6906 \SpecialChar ~
6907 \SpecialChar ~
6908 return asm_func(i,j); 
6909 \newline 
6910
6911 \newline 
6912
6913 \newline 
6914 int main() 
6915 \newline 
6916
6917 \newline 
6918 \SpecialChar ~
6919 \SpecialChar ~
6920 \SpecialChar ~
6921 \SpecialChar ~
6922 return c_func(10,9); 
6923 \newline 
6924 }
6925 \newline 
6926
6927 \family default 
6928
6929 \newline 
6930 The corresponding assembler routine is:
6931 \newline 
6932
6933 \newline 
6934
6935 \family typewriter 
6936 .globl _asm_func 
6937 \newline 
6938 _asm_func: 
6939 \newline 
6940 \SpecialChar ~
6941 \SpecialChar ~
6942 \SpecialChar ~
6943 \SpecialChar ~
6944 push  _bp 
6945 \newline 
6946 \SpecialChar ~
6947 \SpecialChar ~
6948 \SpecialChar ~
6949 \SpecialChar ~
6950 mov  _bp,sp 
6951 \newline 
6952 \SpecialChar ~
6953 \SpecialChar ~
6954 \SpecialChar ~
6955 \SpecialChar ~
6956 mov  r2,dpl
6957 \newline 
6958 \SpecialChar ~
6959 \SpecialChar ~
6960 \SpecialChar ~
6961 \SpecialChar ~
6962 mov  a,_bp 
6963 \newline 
6964 \SpecialChar ~
6965 \SpecialChar ~
6966 \SpecialChar ~
6967 \SpecialChar ~
6968 clr  c 
6969 \newline 
6970 \SpecialChar ~
6971 \SpecialChar ~
6972 \SpecialChar ~
6973 \SpecialChar ~
6974 add  a,#0xfd 
6975 \newline 
6976 \SpecialChar ~
6977 \SpecialChar ~
6978 \SpecialChar ~
6979 \SpecialChar ~
6980 mov  r0,a 
6981 \newline 
6982 \SpecialChar ~
6983 \SpecialChar ~
6984 \SpecialChar ~
6985 \SpecialChar ~
6986 add  a,#0xfc
6987 \newline 
6988 \SpecialChar ~
6989 \SpecialChar ~
6990 \SpecialChar ~
6991 \SpecialChar ~
6992 mov  r1,a 
6993 \newline 
6994 \SpecialChar ~
6995 \SpecialChar ~
6996 \SpecialChar ~
6997 \SpecialChar ~
6998 mov  a,@r0 
6999 \newline 
7000 \SpecialChar ~
7001 \SpecialChar ~
7002 \SpecialChar ~
7003 \SpecialChar ~
7004 add  a,r2
7005 \newline 
7006 \SpecialChar ~
7007 \SpecialChar ~
7008 \SpecialChar ~
7009 \SpecialChar ~
7010 mov  dpl,a 
7011 \newline 
7012 \SpecialChar ~
7013 \SpecialChar ~
7014 \SpecialChar ~
7015 \SpecialChar ~
7016 mov  dph,#0x00 
7017 \newline 
7018 \SpecialChar ~
7019 \SpecialChar ~
7020 \SpecialChar ~
7021 \SpecialChar ~
7022 mov  sp,_bp 
7023 \newline 
7024 \SpecialChar ~
7025 \SpecialChar ~
7026 \SpecialChar ~
7027 \SpecialChar ~
7028 pop  _bp 
7029 \newline 
7030 \SpecialChar ~
7031 \SpecialChar ~
7032 \SpecialChar ~
7033 \SpecialChar ~
7034 ret
7035 \newline 
7036
7037 \newline 
7038
7039 \family default 
7040 The compiling and linking procedure remains the same, however note the extra
7041  entry & exit linkage required for the assembler code, _bp is the stack
7042  frame pointer and is used to compute the offset into the stack for parameters
7043  and local variables.
7044 \layout Subsection
7045
7046 External Stack
7047 \layout Standard
7048
7049 The external stack is located at the start of the external ram segment,
7050  and is 256 bytes in size.
7051  When --xstack option is used to compile the program, the parameters and
7052  local variables of all reentrant functions are allocated in this area.
7053  This option is provided for programs with large stack space requirements.
7054  When used with the --stack-auto option, all parameters and local variables
7055  are allocated on the external stack (note support libraries will need to
7056  be recompiled with the same options).
7057 \layout Standard
7058
7059 The compiler outputs the higher order address byte of the external ram segment
7060  into PORT P2, therefore when using the External Stack option, this port
7061  MAY NOT be used by the application program.
7062 \layout Subsection
7063
7064 ANSI-Compliance
7065 \layout Standard
7066
7067 Deviations from the compliancy.
7068 \layout Itemize
7069
7070 functions are not always reentrant.
7071 \layout Itemize
7072
7073 structures cannot be assigned values directly, cannot be passed as function
7074  parameters or assigned to each other and cannot be a return value from
7075  a function, e.g.:
7076 \family typewriter 
7077
7078 \newline 
7079
7080 \newline 
7081 struct s { ...
7082  }; 
7083 \newline 
7084 struct s s1, s2; 
7085 \newline 
7086 foo() 
7087 \newline 
7088
7089 \newline 
7090 \SpecialChar ~
7091 \SpecialChar ~
7092 \SpecialChar ~
7093 \SpecialChar ~
7094 ...
7095  
7096 \newline 
7097 \SpecialChar ~
7098 \SpecialChar ~
7099 \SpecialChar ~
7100 \SpecialChar ~
7101 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
7102 \newline 
7103 \SpecialChar ~
7104 \SpecialChar ~
7105 \SpecialChar ~
7106 \SpecialChar ~
7107 ...
7108  
7109 \newline 
7110 }
7111 \newline 
7112 struct s foo1 (struct s parms) /* is invalid in SDCC although allowed in
7113  ANSI */ 
7114 \newline 
7115
7116 \newline 
7117 \SpecialChar ~
7118 \SpecialChar ~
7119 \SpecialChar ~
7120 \SpecialChar ~
7121 struct s rets; 
7122 \newline 
7123 \SpecialChar ~
7124 \SpecialChar ~
7125 \SpecialChar ~
7126 \SpecialChar ~
7127 ...
7128  
7129 \newline 
7130 \SpecialChar ~
7131 \SpecialChar ~
7132 \SpecialChar ~
7133 \SpecialChar ~
7134 return rets;/* is invalid in SDCC although allowed in ANSI */ 
7135 \newline 
7136 }
7137 \layout Itemize
7138
7139 'long long' (64 bit integers) not supported.
7140 \layout Itemize
7141
7142 'double' precision floating point not supported.
7143 \layout Itemize
7144
7145 No support for setjmp and longjmp (for now).
7146 \layout Itemize
7147
7148 Old K&R style function declarations are NOT allowed.
7149 \newline 
7150
7151 \family typewriter 
7152
7153 \newline 
7154 foo(i,j) /* this old style of function declarations */ 
7155 \newline 
7156 int i,j; /* are valid in ANSI but not valid in SDCC */ 
7157 \newline 
7158
7159 \newline 
7160 \SpecialChar ~
7161 \SpecialChar ~
7162 \SpecialChar ~
7163 \SpecialChar ~
7164 ...
7165  
7166 \newline 
7167 }
7168 \layout Itemize
7169
7170 functions declared as pointers must be dereferenced during the call.
7171 \newline 
7172
7173 \family typewriter 
7174
7175 \newline 
7176 int (*foo)();
7177 \newline 
7178 ...
7179  
7180 \newline 
7181 /* has to be called like this */ 
7182 \newline 
7183 (*foo)(); /* ansi standard allows calls to be made like 'foo()' */
7184 \layout Subsection
7185
7186 Cyclomatic Complexity
7187 \layout Standard
7188
7189 Cyclomatic complexity of a function is defined as the number of independent
7190  paths the program can take during execution of the function.
7191  This is an important number since it defines the number test cases you
7192  have to generate to validate the function.
7193  The accepted industry standard for complexity number is 10, if the cyclomatic
7194  complexity reported by SDCC exceeds 10 you should think about simplification
7195  of the function logic.
7196  Note that the complexity level is not related to the number of lines of
7197  code in a function.
7198  Large functions can have low complexity, and small functions can have large
7199  complexity levels.
7200  
7201 \newline 
7202
7203 \newline 
7204 SDCC uses the following formula to compute the complexity:
7205 \newline 
7206
7207 \layout Standard
7208
7209 complexity = (number of edges in control flow graph) - (number of nodes
7210  in control flow graph) + 2;
7211 \newline 
7212
7213 \newline 
7214 Having said that the industry standard is 10, you should be aware that in
7215  some cases it be may unavoidable to have a complexity level of less than
7216  10.
7217  For example if you have switch statement with more than 10 case labels,
7218  each case label adds one to the complexity level.
7219  The complexity level is by no means an absolute measure of the algorithmic
7220  complexity of the function, it does however provide a good starting point
7221  for which functions you might look at for further optimization.
7222 \layout Section
7223
7224 TIPS
7225 \layout Standard
7226
7227 Here are a few guidelines that will help the compiler generate more efficient
7228  code, some of the tips are specific to this compiler others are generally
7229  good programming practice.
7230 \layout Itemize
7231
7232 Use the smallest data type to represent your data-value.
7233  If it is known in advance that the value is going to be less than 256 then
7234  use a 'char' instead of a 'short' or 'int'.
7235 \layout Itemize
7236
7237 Use unsigned when it is known in advance that the value is not going to
7238  be negative.
7239  This helps especially if you are doing division or multiplication.
7240 \layout Itemize
7241
7242 NEVER jump into a LOOP.
7243 \layout Itemize
7244
7245 Declare the variables to be local whenever possible, especially loop control
7246  variables (induction).
7247 \layout Itemize
7248
7249 Since the compiler does not do implicit integral promotion, the programmer
7250  should do an explicit cast when integral promotion is required.
7251 \layout Itemize
7252
7253 Reducing the size of division, multiplication & modulus operations can reduce
7254  code size substantially.
7255  Take the following code for example.
7256 \family typewriter 
7257
7258 \newline 
7259
7260 \newline 
7261 foobar(unsigned int p1, unsigned char ch)
7262 \newline 
7263 {
7264 \newline 
7265     unsigned char ch1 = p1 % ch ;
7266 \newline 
7267     ....
7268     
7269 \newline 
7270 }
7271 \newline 
7272
7273 \family default 
7274
7275 \newline 
7276 For the modulus operation the variable ch will be promoted to unsigned int
7277  first then the modulus operation will be performed (this will lead to a
7278  call to support routine _muduint()), and the result will be casted to an
7279  int.
7280  If the code is changed to 
7281 \newline 
7282
7283 \family typewriter 
7284
7285 \newline 
7286 foobar(unsigned int p1, unsigned char ch)
7287 \newline 
7288 {
7289 \newline 
7290     unsigned char ch1 = (unsigned char)p1 % ch ;
7291 \newline 
7292     ....
7293     
7294 \newline 
7295 }
7296 \newline 
7297
7298 \family default 
7299
7300 \newline 
7301 It would substantially reduce the code generated (future versions of the
7302  compiler will be smart enough to detect such optimization oppurtunities).
7303 \layout Subsection
7304
7305 Notes on MCS51 memory layout
7306 \layout Standard
7307
7308 The 8051 family of micro controller have a minimum of 128 bytes of internal
7309  memory which is structured as follows
7310 \newline 
7311
7312 \newline 
7313 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R7 to R7
7314  
7315 \newline 
7316 - Bytes 20-2F - 16 bytes to hold 128 bit variables and 
7317 \newline 
7318 - Bytes 30-7F - 60 bytes for general purpose use.
7319 \newline 
7320
7321 \newline 
7322 Normally the SDCC compiler will only utilise the first bank of registers,
7323  but it is possible to specify that other banks of registers should be used
7324  in interrupt routines.
7325  By default, the compiler will place the stack after the last bank of used
7326  registers, i.e.
7327  if the first 2 banks of registers are used, it will position the base of
7328  the internal stack at address 16 (0X10).
7329  This implies that as the stack grows, it will use up the remaining register
7330  banks, and the 16 bytes used by the 128 bit variables, and 60 bytes for
7331  general purpose use.
7332 \layout Standard
7333
7334 By default, the compiler uses the 60 general purpose bytes to hold "near
7335  data".
7336  The compiler/optimiser may also declare some Local Variables in this area
7337  to hold local data.
7338  
7339 \layout Standard
7340
7341 If any of the 128 bit variables are used, or near data is being used then
7342  care needs to be taken to ensure that the stack does not grow so much that
7343  it starts to over write either your bit variables or "near data".
7344  There is no runtime checking to prevent this from happening.
7345 \layout Standard
7346
7347 The amount of stack being used is affected by the use of the "internal stack"
7348  to save registers before a subroutine call is made (--stack-auto will declare
7349  parameters and local variables on the stack) and the number of nested subroutin
7350 es.
7351 \layout Standard
7352
7353 If you detect that the stack is over writing you data, then the following
7354  can be done.
7355  --xstack will cause an external stack to be used for saving registers and
7356  (if --stack-auto is being used) storing parameters and local variables.
7357  However this will produce more code which will be slower to execute.
7358  
7359 \layout Standard
7360
7361 --stack-loc will allow you specify the start of the stack, i.e.
7362  you could start it after any data in the general purpose area.
7363  However this may waste the memory not used by the register banks and if
7364  the size of the "near data" increases, it may creep into the bottom of
7365  the stack.
7366 \layout Standard
7367
7368 --stack-after-data, similar to the --stack-loc, but it automatically places
7369  the stack after the end of the "near data".
7370  Again this could waste any spare register space.
7371 \layout Standard
7372
7373 --data-loc allows you to specify the start address of the near data.
7374  This could be used to move the "near data" further away from the stack
7375  giving it more room to grow.
7376  This will only work if no bit variables are being used and the stack can
7377  grow to use the bit variable space.
7378 \newline 
7379
7380 \newline 
7381 Conclusion.
7382 \newline 
7383
7384 \newline 
7385 If you find that the stack is over writing your bit variables or "near data"
7386  then the approach which best utilised the internal memory is to position
7387  the "near data" after the last bank of used registers or, if you use bit
7388  variables, after the last bit variable by using the --data-loc, e.g.
7389  if two register banks are being used and no bit variables, --data-loc 16,
7390  and use the --stack-after-data option.
7391 \layout Standard
7392
7393 If bit variables are being used, another method would be to try and squeeze
7394  the data area in the unused register banks if it will fit, and start the
7395  stack after the last bit variable.
7396 \layout Section
7397
7398 Retargetting for other MCUs.
7399 \layout Standard
7400
7401 The issues for retargetting the compiler are far too numerous to be covered
7402  by this document.
7403  What follows is a brief description of each of the seven phases of the
7404  compiler and its MCU dependency.
7405 \layout Itemize
7406
7407 Parsing the source and building the annotated parse tree.
7408  This phase is largely MCU independent (except for the language extensions).
7409  Syntax & semantic checks are also done in this phase, along with some initial
7410  optimizations like back patching labels and the pattern matching optimizations
7411  like bit-rotation etc.
7412 \layout Itemize
7413
7414 The second phase involves generating an intermediate code which can be easy
7415  manipulated during the later phases.
7416  This phase is entirely MCU independent.
7417  The intermediate code generation assumes the target machine has unlimited
7418  number of registers, and designates them with the name iTemp.
7419  The compiler can be made to dump a human readable form of the code generated
7420  by using the --dumpraw option.
7421 \layout Itemize
7422
7423 This phase does the bulk of the standard optimizations and is also MCU independe
7424 nt.
7425  This phase can be broken down into several sub-phases:
7426 \newline 
7427
7428 \newline 
7429 Break down intermediate code (iCode) into basic blocks.
7430 \newline 
7431 Do control flow & data flow analysis on the basic blocks.
7432 \newline 
7433 Do local common subexpression elimination, then global subexpression elimination
7434 \newline 
7435 Dead code elimination
7436 \newline 
7437 Loop optimizations
7438 \newline 
7439 If loop optimizations caused any changes then do 'global subexpression eliminati
7440 on' and 'dead code elimination' again.
7441 \layout Itemize
7442
7443 This phase determines the live-ranges; by live range I mean those iTemp
7444  variables defined by the compiler that still survive after all the optimization
7445 s.
7446  Live range analysis is essential for register allocation, since these computati
7447 on determines which of these iTemps will be assigned to registers, and for
7448  how long.
7449 \layout Itemize
7450
7451 Phase five is register allocation.
7452  There are two parts to this process.
7453 \newline 
7454
7455 \newline 
7456 The first part I call 'register packing' (for lack of a better term).
7457  In this case several MCU specific expression folding is done to reduce
7458  register pressure.
7459 \newline 
7460
7461 \newline 
7462 The second part is more MCU independent and deals with allocating registers
7463  to the remaining live ranges.
7464  A lot of MCU specific code does creep into this phase because of the limited
7465  number of index registers available in the 8051.
7466 \layout Itemize
7467
7468 The Code generation phase is (unhappily), entirely MCU dependent and very
7469  little (if any at all) of this code can be reused for other MCU.
7470  However the scheme for allocating a homogenized assembler operand for each
7471  iCode operand may be reused.
7472 \layout Itemize
7473
7474 As mentioned in the optimization section the peep-hole optimizer is rule
7475  based system, which can reprogrammed for other MCUs.
7476 \layout Section
7477
7478 SDCDB - Source Level Debugger
7479 \layout Standard
7480
7481 SDCC is distributed with a source level debugger.
7482  The debugger uses a command line interface, the command repertoire of the
7483  debugger has been kept as close to gdb (the GNU debugger) as possible.
7484  The configuration and build process is part of the standard compiler installati
7485 on, which also builds and installs the debugger in the target directory
7486  specified during configuration.
7487  The debugger allows you debug BOTH at the C source and at the ASM source
7488  level.
7489 \layout Subsection
7490
7491 Compiling for Debugging
7492 \layout Standard
7493
7494 The \SpecialChar \-
7495 \SpecialChar \-
7496 debug option must be specified for all files for which debug information
7497  is to be generated.
7498  The complier generates a .cdb file for each of these files.
7499  The linker updates the .cdb file with the address information.
7500  This .cdb is used by the debugger.
7501 \layout Subsection
7502
7503 How the Debugger Works
7504 \layout Standard
7505
7506 When the --debug option is specified the compiler generates extra symbol
7507  information some of which are put into the the assembler source and some
7508  are put into the .cdb file, the linker updates the .cdb file with the address
7509  information for the symbols.
7510  The debugger reads the symbolic information generated by the compiler &
7511  the address information generated by the linker.
7512  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
7513  execution is controlled by the debugger.
7514  When a command is issued for the debugger, it translates it into appropriate
7515  commands for the simulator.
7516 \layout Subsection
7517
7518 Starting the Debugger
7519 \layout Standard
7520
7521 The debugger can be started using the following command line.
7522  (Assume the file you are debugging has the file name foo).
7523 \newline 
7524
7525 \newline 
7526
7527 \family sans 
7528 \series bold 
7529 sdcdb foo
7530 \newline 
7531
7532 \family default 
7533 \series default 
7534
7535 \newline 
7536 The debugger will look for the following files.
7537 \layout Itemize
7538
7539 foo.c - the source file.
7540 \layout Itemize
7541
7542 foo.cdb - the debugger symbol information file.
7543 \layout Itemize
7544
7545 foo.ihx - the intel hex format object file.
7546 \layout Subsection
7547
7548 Command Line Options.
7549 \layout Itemize
7550
7551 --directory=<source file directory> this option can used to specify the
7552  directory search list.
7553  The debugger will look into the directory list specified for source, cdb
7554  & ihx files.
7555  The items in the directory list must be separated by ':', e.g.
7556  if the source files can be in the directories /home/src1 and /home/src2,
7557  the --directory option should be --directory=/home/src1:/home/src2.
7558  Note there can be no spaces in the option.
7559  
7560 \layout Itemize
7561
7562 -cd <directory> - change to the <directory>.
7563 \layout Itemize
7564
7565 -fullname - used by GUI front ends.
7566 \layout Itemize
7567
7568 -cpu <cpu-type> - this argument is passed to the simulator please see the
7569  simulator docs for details.
7570 \layout Itemize
7571
7572 -X <Clock frequency > this options is passed to the simulator please see
7573  the simulator docs for details.
7574 \layout Itemize
7575
7576 -s <serial port file> passed to simulator see the simulator docs for details.
7577 \layout Itemize
7578
7579 -S <serial in,out> passed to simulator see the simulator docs for details.
7580 \layout Subsection
7581
7582 Debugger Commands.
7583 \layout Standard
7584
7585 As mention earlier the command interface for the debugger has been deliberately
7586  kept as close the GNU debugger gdb, as possible.
7587  This will help the integration with existing graphical user interfaces
7588  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
7589 \layout Subsubsection
7590
7591 break [line | file:line | function | file:function]
7592 \layout Standard
7593
7594 Set breakpoint at specified line or function:
7595 \newline 
7596
7597 \newline 
7598
7599 \family sans 
7600 \series bold 
7601 sdcdb>break 100 
7602 \newline 
7603 sdcdb>break foo.c:100
7604 \newline 
7605 sdcdb>break funcfoo
7606 \newline 
7607 sdcdb>break foo.c:funcfoo
7608 \layout Subsubsection
7609
7610 clear [line | file:line | function | file:function ]
7611 \layout Standard
7612
7613 Clear breakpoint at specified line or function:
7614 \newline 
7615
7616 \newline 
7617
7618 \family sans 
7619 \series bold 
7620 sdcdb>clear 100
7621 \newline 
7622 sdcdb>clear foo.c:100
7623 \newline 
7624 sdcdb>clear funcfoo
7625 \newline 
7626 sdcdb>clear foo.c:funcfoo
7627 \layout Subsubsection
7628
7629 continue
7630 \layout Standard
7631
7632 Continue program being debugged, after breakpoint.
7633 \layout Subsubsection
7634
7635 finish
7636 \layout Standard
7637
7638 Execute till the end of the current function.
7639 \layout Subsubsection
7640
7641 delete [n]
7642 \layout Standard
7643
7644 Delete breakpoint number 'n'.
7645  If used without any option clear ALL user defined break points.
7646 \layout Subsubsection
7647
7648 info [break | stack | frame | registers ]
7649 \layout Itemize
7650
7651 info break - list all breakpoints
7652 \layout Itemize
7653
7654 info stack - show the function call stack.
7655 \layout Itemize
7656
7657 info frame - show information about the current execution frame.
7658 \layout Itemize
7659
7660 info registers - show content of all registers.
7661 \layout Subsubsection
7662
7663 step
7664 \layout Standard
7665
7666 Step program until it reaches a different source line.
7667 \layout Subsubsection
7668
7669 next
7670 \layout Standard
7671
7672 Step program, proceeding through subroutine calls.
7673 \layout Subsubsection
7674
7675 run
7676 \layout Standard
7677
7678 Start debugged program.
7679 \layout Subsubsection
7680
7681 ptype variable 
7682 \layout Standard
7683
7684 Print type information of the variable.
7685 \layout Subsubsection
7686
7687 print variable
7688 \layout Standard
7689
7690 print value of variable.
7691 \layout Subsubsection
7692
7693 file filename
7694 \layout Standard
7695
7696 load the given file name.
7697  Note this is an alternate method of loading file for debugging.
7698 \layout Subsubsection
7699
7700 frame
7701 \layout Standard
7702
7703 print information about current frame.
7704 \layout Subsubsection
7705
7706 set srcmode
7707 \layout Standard
7708
7709 Toggle between C source & assembly source.
7710 \layout Subsubsection
7711
7712 ! simulator command
7713 \layout Standard
7714
7715 Send the string following '!' to the simulator, the simulator response is
7716  displayed.
7717  Note the debugger does not interpret the command being sent to the simulator,
7718  so if a command like 'go' is sent the debugger can loose its execution
7719  context and may display incorrect values.
7720 \layout Subsubsection
7721
7722 quit.
7723 \layout Standard
7724
7725 "Watch me now.
7726  Iam going Down.
7727  My name is Bobby Brown"
7728 \layout Subsection
7729
7730 Interfacing with XEmacs.
7731 \layout Standard
7732
7733 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
7734  sdcdb.el and sdcdbsrc.el.
7735  These two files can be found in the $(prefix)/bin directory after the installat
7736 ion is complete.
7737  These files need to be loaded into XEmacs for the interface to work.
7738  This can be done at XEmacs startup time by inserting the following into
7739  your '.xemacs' file (which can be found in your HOME directory): 
7740 \newline 
7741
7742 \newline 
7743
7744 \family typewriter 
7745 (load-file sdcdbsrc.el) 
7746 \family default 
7747
7748 \newline 
7749
7750 \newline 
7751 .xemacs is a lisp file so the () around the command is REQUIRED.
7752  The files can also be loaded dynamically while XEmacs is running, set the
7753  environment variable 'EMACSLOADPATH' to the installation bin directory
7754  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
7755  To start the interface enter the following command: 
7756 \newline 
7757
7758 \newline 
7759
7760 \family sans 
7761 \series bold 
7762 ESC-x sdcdbsrc
7763 \family default 
7764 \series default 
7765
7766 \newline 
7767
7768 \newline 
7769 You will prompted to enter the file name to be debugged.
7770  
7771 \newline 
7772
7773 \newline 
7774 The command line options that are passed to the simulator directly are bound
7775  to default values in the file sdcdbsrc.el.
7776  The variables are listed below, these values maybe changed as required.
7777 \layout Itemize
7778
7779 sdcdbsrc-cpu-type '51
7780 \layout Itemize
7781
7782 sdcdbsrc-frequency '11059200
7783 \layout Itemize
7784
7785 sdcdbsrc-serial nil
7786 \layout Standard
7787
7788 The following is a list of key mapping for the debugger interface.
7789 \layout Standard
7790
7791 \SpecialChar ~
7792
7793 \family typewriter 
7794
7795 \newline 
7796 ;; Current Listing :: 
7797 \newline 
7798 ;;key\SpecialChar ~
7799 \SpecialChar ~
7800 \SpecialChar ~
7801 \SpecialChar ~
7802 \SpecialChar ~
7803 \SpecialChar ~
7804 \SpecialChar ~
7805 \SpecialChar ~
7806 \SpecialChar ~
7807 \SpecialChar ~
7808 \SpecialChar ~
7809 \SpecialChar ~
7810 \SpecialChar ~
7811 \SpecialChar ~
7812 \SpecialChar ~
7813 binding\SpecialChar ~
7814 \SpecialChar ~
7815 \SpecialChar ~
7816 \SpecialChar ~
7817 \SpecialChar ~
7818 \SpecialChar ~
7819 \SpecialChar ~
7820 \SpecialChar ~
7821 \SpecialChar ~
7822 \SpecialChar ~
7823 \SpecialChar ~
7824 \SpecialChar ~
7825 \SpecialChar ~
7826 \SpecialChar ~
7827 \SpecialChar ~
7828 \SpecialChar ~
7829 \SpecialChar ~
7830 \SpecialChar ~
7831 \SpecialChar ~
7832 \SpecialChar ~
7833 \SpecialChar ~
7834 \SpecialChar ~
7835 Comment 
7836 \newline 
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 \SpecialChar ~
7864 \SpecialChar ~
7865 \SpecialChar ~
7866 \SpecialChar ~
7867 \SpecialChar ~
7868 \SpecialChar ~
7869 \SpecialChar ~
7870 \SpecialChar ~
7871 \SpecialChar ~
7872 \SpecialChar ~
7873 \SpecialChar ~
7874 ------- 
7875 \newline 
7876 ;; 
7877 \newline 
7878 ;; n\SpecialChar ~
7879 \SpecialChar ~
7880 \SpecialChar ~
7881 \SpecialChar ~
7882 \SpecialChar ~
7883 \SpecialChar ~
7884 \SpecialChar ~
7885 \SpecialChar ~
7886 \SpecialChar ~
7887 \SpecialChar ~
7888 \SpecialChar ~
7889 \SpecialChar ~
7890 \SpecialChar ~
7891 \SpecialChar ~
7892  sdcdb-next-from-src\SpecialChar ~
7893 \SpecialChar ~
7894 \SpecialChar ~
7895 \SpecialChar ~
7896 \SpecialChar ~
7897 \SpecialChar ~
7898 \SpecialChar ~
7899 \SpecialChar ~
7900 \SpecialChar ~
7901 \SpecialChar ~
7902 SDCDB next command 
7903 \newline 
7904 ;; b\SpecialChar ~
7905 \SpecialChar ~
7906 \SpecialChar ~
7907 \SpecialChar ~
7908 \SpecialChar ~
7909 \SpecialChar ~
7910 \SpecialChar ~
7911 \SpecialChar ~
7912 \SpecialChar ~
7913 \SpecialChar ~
7914 \SpecialChar ~
7915 \SpecialChar ~
7916 \SpecialChar ~
7917 \SpecialChar ~
7918  sdcdb-back-from-src\SpecialChar ~
7919 \SpecialChar ~
7920 \SpecialChar ~
7921 \SpecialChar ~
7922 \SpecialChar ~
7923 \SpecialChar ~
7924 \SpecialChar ~
7925 \SpecialChar ~
7926 \SpecialChar ~
7927 \SpecialChar ~
7928 SDCDB back command 
7929 \newline 
7930 ;; c\SpecialChar ~
7931 \SpecialChar ~
7932 \SpecialChar ~
7933 \SpecialChar ~
7934 \SpecialChar ~
7935 \SpecialChar ~
7936 \SpecialChar ~
7937 \SpecialChar ~
7938 \SpecialChar ~
7939 \SpecialChar ~
7940 \SpecialChar ~
7941 \SpecialChar ~
7942 \SpecialChar ~
7943 \SpecialChar ~
7944  sdcdb-cont-from-src\SpecialChar ~
7945 \SpecialChar ~
7946 \SpecialChar ~
7947 \SpecialChar ~
7948 \SpecialChar ~
7949 \SpecialChar ~
7950 \SpecialChar ~
7951 \SpecialChar ~
7952 \SpecialChar ~
7953 \SpecialChar ~
7954 SDCDB continue command
7955 \newline 
7956 ;; s\SpecialChar ~
7957 \SpecialChar ~
7958 \SpecialChar ~
7959 \SpecialChar ~
7960 \SpecialChar ~
7961 \SpecialChar ~
7962 \SpecialChar ~
7963 \SpecialChar ~
7964 \SpecialChar ~
7965 \SpecialChar ~
7966 \SpecialChar ~
7967 \SpecialChar ~
7968 \SpecialChar ~
7969 \SpecialChar ~
7970  sdcdb-step-from-src\SpecialChar ~
7971 \SpecialChar ~
7972 \SpecialChar ~
7973 \SpecialChar ~
7974 \SpecialChar ~
7975 \SpecialChar ~
7976 \SpecialChar ~
7977 \SpecialChar ~
7978 \SpecialChar ~
7979 \SpecialChar ~
7980 SDCDB step command 
7981 \newline 
7982 ;; ?\SpecialChar ~
7983 \SpecialChar ~
7984 \SpecialChar ~
7985 \SpecialChar ~
7986 \SpecialChar ~
7987 \SpecialChar ~
7988 \SpecialChar ~
7989 \SpecialChar ~
7990 \SpecialChar ~
7991 \SpecialChar ~
7992 \SpecialChar ~
7993 \SpecialChar ~
7994 \SpecialChar ~
7995 \SpecialChar ~
7996  sdcdb-whatis-c-sexp\SpecialChar ~
7997 \SpecialChar ~
7998 \SpecialChar ~
7999 \SpecialChar ~
8000 \SpecialChar ~
8001 \SpecialChar ~
8002 \SpecialChar ~
8003 \SpecialChar ~
8004 \SpecialChar ~
8005 \SpecialChar ~
8006 SDCDB ptypecommand for data at 
8007 \newline 
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 \SpecialChar ~
8044 \SpecialChar ~
8045 \SpecialChar ~
8046 \SpecialChar ~
8047 \SpecialChar ~
8048 \SpecialChar ~
8049 \SpecialChar ~
8050 \SpecialChar ~
8051 \SpecialChar ~
8052 \SpecialChar ~
8053 \SpecialChar ~
8054  buffer point 
8055 \newline 
8056 ;; x\SpecialChar ~
8057 \SpecialChar ~
8058 \SpecialChar ~
8059 \SpecialChar ~
8060 \SpecialChar ~
8061 \SpecialChar ~
8062 \SpecialChar ~
8063 \SpecialChar ~
8064 \SpecialChar ~
8065 \SpecialChar ~
8066 \SpecialChar ~
8067 \SpecialChar ~
8068 \SpecialChar ~
8069 \SpecialChar ~
8070  sdcdbsrc-delete\SpecialChar ~
8071 \SpecialChar ~
8072 \SpecialChar ~
8073 \SpecialChar ~
8074 \SpecialChar ~
8075 \SpecialChar ~
8076 \SpecialChar ~
8077 \SpecialChar ~
8078 \SpecialChar ~
8079 \SpecialChar ~
8080 \SpecialChar ~
8081 \SpecialChar ~
8082 \SpecialChar ~
8083 \SpecialChar ~
8084 SDCDB Delete all breakpoints if no arg 
8085 \newline 
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 \SpecialChar ~
8122 \SpecialChar ~
8123 \SpecialChar ~
8124 \SpecialChar ~
8125 \SpecialChar ~
8126 \SpecialChar ~
8127 \SpecialChar ~
8128 \SpecialChar ~
8129 \SpecialChar ~
8130 \SpecialChar ~
8131 \SpecialChar ~
8132 given or delete arg (C-u arg x) 
8133 \newline 
8134 ;; m\SpecialChar ~
8135 \SpecialChar ~
8136 \SpecialChar ~
8137 \SpecialChar ~
8138 \SpecialChar ~
8139 \SpecialChar ~
8140 \SpecialChar ~
8141 \SpecialChar ~
8142 \SpecialChar ~
8143 \SpecialChar ~
8144 \SpecialChar ~
8145 \SpecialChar ~
8146 \SpecialChar ~
8147 \SpecialChar ~
8148  sdcdbsrc-frame\SpecialChar ~
8149 \SpecialChar ~
8150 \SpecialChar ~
8151 \SpecialChar ~
8152 \SpecialChar ~
8153 \SpecialChar ~
8154 \SpecialChar ~
8155 \SpecialChar ~
8156 \SpecialChar ~
8157 \SpecialChar ~
8158 \SpecialChar ~
8159 \SpecialChar ~
8160 \SpecialChar ~
8161 \SpecialChar ~
8162 \SpecialChar ~
8163 SDCDB Display current frame if no arg, 
8164 \newline 
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 \SpecialChar ~
8202 \SpecialChar ~
8203 \SpecialChar ~
8204 \SpecialChar ~
8205 \SpecialChar ~
8206 \SpecialChar ~
8207 \SpecialChar ~
8208 \SpecialChar ~
8209 \SpecialChar ~
8210 \SpecialChar ~
8211 \SpecialChar ~
8212 given or display frame arg 
8213 \newline 
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 \SpecialChar ~
8251 \SpecialChar ~
8252 \SpecialChar ~
8253 \SpecialChar ~
8254 \SpecialChar ~
8255 \SpecialChar ~
8256 \SpecialChar ~
8257 \SpecialChar ~
8258 \SpecialChar ~
8259 \SpecialChar ~
8260 \SpecialChar ~
8261 buffer point 
8262 \newline 
8263 ;; !\SpecialChar ~
8264 \SpecialChar ~
8265 \SpecialChar ~
8266 \SpecialChar ~
8267 \SpecialChar ~
8268 \SpecialChar ~
8269 \SpecialChar ~
8270 \SpecialChar ~
8271 \SpecialChar ~
8272 \SpecialChar ~
8273 \SpecialChar ~
8274 \SpecialChar ~
8275 \SpecialChar ~
8276 \SpecialChar ~
8277  sdcdbsrc-goto-sdcdb\SpecialChar ~
8278 \SpecialChar ~
8279 \SpecialChar ~
8280 \SpecialChar ~
8281 \SpecialChar ~
8282 \SpecialChar ~
8283 \SpecialChar ~
8284 \SpecialChar ~
8285 \SpecialChar ~
8286 \SpecialChar ~
8287 Goto the SDCDB output buffer 
8288 \newline 
8289 ;; p\SpecialChar ~
8290 \SpecialChar ~
8291 \SpecialChar ~
8292 \SpecialChar ~
8293 \SpecialChar ~
8294 \SpecialChar ~
8295 \SpecialChar ~
8296 \SpecialChar ~
8297 \SpecialChar ~
8298 \SpecialChar ~
8299 \SpecialChar ~
8300 \SpecialChar ~
8301 \SpecialChar ~
8302 \SpecialChar ~
8303  sdcdb-print-c-sexp\SpecialChar ~
8304 \SpecialChar ~
8305 \SpecialChar ~
8306 \SpecialChar ~
8307 \SpecialChar ~
8308 \SpecialChar ~
8309 \SpecialChar ~
8310 \SpecialChar ~
8311 \SpecialChar ~
8312 \SpecialChar ~
8313 \SpecialChar ~
8314 SDCDB print command for data at 
8315 \newline 
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 \SpecialChar ~
8352 \SpecialChar ~
8353 \SpecialChar ~
8354 \SpecialChar ~
8355 \SpecialChar ~
8356 \SpecialChar ~
8357 \SpecialChar ~
8358 \SpecialChar ~
8359 \SpecialChar ~
8360 \SpecialChar ~
8361 \SpecialChar ~
8362  buffer point 
8363 \newline 
8364 ;; g\SpecialChar ~
8365 \SpecialChar ~
8366 \SpecialChar ~
8367 \SpecialChar ~
8368 \SpecialChar ~
8369 \SpecialChar ~
8370 \SpecialChar ~
8371 \SpecialChar ~
8372 \SpecialChar ~
8373 \SpecialChar ~
8374 \SpecialChar ~
8375 \SpecialChar ~
8376 \SpecialChar ~
8377 \SpecialChar ~
8378  sdcdbsrc-goto-sdcdb\SpecialChar ~
8379 \SpecialChar ~
8380 \SpecialChar ~
8381 \SpecialChar ~
8382 \SpecialChar ~
8383 \SpecialChar ~
8384 \SpecialChar ~
8385 \SpecialChar ~
8386 \SpecialChar ~
8387 \SpecialChar ~
8388 Goto the SDCDB output buffer 
8389 \newline 
8390 ;; t\SpecialChar ~
8391 \SpecialChar ~
8392 \SpecialChar ~
8393 \SpecialChar ~
8394 \SpecialChar ~
8395 \SpecialChar ~
8396 \SpecialChar ~
8397 \SpecialChar ~
8398 \SpecialChar ~
8399 \SpecialChar ~
8400 \SpecialChar ~
8401 \SpecialChar ~
8402 \SpecialChar ~
8403 \SpecialChar ~
8404  sdcdbsrc-mode\SpecialChar ~
8405 \SpecialChar ~
8406 \SpecialChar ~
8407 \SpecialChar ~
8408 \SpecialChar ~
8409 \SpecialChar ~
8410 \SpecialChar ~
8411 \SpecialChar ~
8412 \SpecialChar ~
8413 \SpecialChar ~
8414 \SpecialChar ~
8415 \SpecialChar ~
8416 \SpecialChar ~
8417 \SpecialChar ~
8418 \SpecialChar ~
8419 \SpecialChar ~
8420 Toggles Sdcdbsrc mode (turns it off) 
8421 \newline 
8422 ;; 
8423 \newline 
8424 ;; C-c C-f\SpecialChar ~
8425 \SpecialChar ~
8426 \SpecialChar ~
8427 \SpecialChar ~
8428 \SpecialChar ~
8429 \SpecialChar ~
8430 \SpecialChar ~
8431 \SpecialChar ~
8432  sdcdb-finish-from-src\SpecialChar ~
8433 \SpecialChar ~
8434 \SpecialChar ~
8435 \SpecialChar ~
8436 \SpecialChar ~
8437 \SpecialChar ~
8438 \SpecialChar ~
8439 \SpecialChar ~
8440 SDCDB finish command 
8441 \newline 
8442 ;; 
8443 \newline 
8444 ;; C-x SPC\SpecialChar ~
8445 \SpecialChar ~
8446 \SpecialChar ~
8447 \SpecialChar ~
8448 \SpecialChar ~
8449 \SpecialChar ~
8450 \SpecialChar ~
8451 \SpecialChar ~
8452  sdcdb-break\SpecialChar ~
8453 \SpecialChar ~
8454 \SpecialChar ~
8455 \SpecialChar ~
8456 \SpecialChar ~
8457 \SpecialChar ~
8458 \SpecialChar ~
8459 \SpecialChar ~
8460 \SpecialChar ~
8461 \SpecialChar ~
8462 \SpecialChar ~
8463 \SpecialChar ~
8464 \SpecialChar ~
8465 \SpecialChar ~
8466 \SpecialChar ~
8467 \SpecialChar ~
8468 \SpecialChar ~
8469 \SpecialChar ~
8470 Set break for line with point 
8471 \newline 
8472 ;; ESC t\SpecialChar ~
8473 \SpecialChar ~
8474 \SpecialChar ~
8475 \SpecialChar ~
8476 \SpecialChar ~
8477 \SpecialChar ~
8478 \SpecialChar ~
8479 \SpecialChar ~
8480 \SpecialChar ~
8481 \SpecialChar ~
8482  sdcdbsrc-mode\SpecialChar ~
8483 \SpecialChar ~
8484 \SpecialChar ~
8485 \SpecialChar ~
8486 \SpecialChar ~
8487 \SpecialChar ~
8488 \SpecialChar ~
8489 \SpecialChar ~
8490 \SpecialChar ~
8491 \SpecialChar ~
8492 \SpecialChar ~
8493 \SpecialChar ~
8494 \SpecialChar ~
8495 \SpecialChar ~
8496 \SpecialChar ~
8497 \SpecialChar ~
8498 Toggle Sdcdbsrc mode 
8499 \newline 
8500 ;; ESC m\SpecialChar ~
8501 \SpecialChar ~
8502 \SpecialChar ~
8503 \SpecialChar ~
8504 \SpecialChar ~
8505 \SpecialChar ~
8506 \SpecialChar ~
8507 \SpecialChar ~
8508 \SpecialChar ~
8509 \SpecialChar ~
8510  sdcdbsrc-srcmode\SpecialChar ~
8511 \SpecialChar ~
8512 \SpecialChar ~
8513 \SpecialChar ~
8514 \SpecialChar ~
8515 \SpecialChar ~
8516 \SpecialChar ~
8517 \SpecialChar ~
8518 \SpecialChar ~
8519 \SpecialChar ~
8520 \SpecialChar ~
8521 \SpecialChar ~
8522  Toggle list mode 
8523 \newline 
8524 ;; 
8525 \family default 
8526
8527 \newline 
8528
8529 \layout Section
8530
8531 Other Processors
8532 \layout Subsection
8533
8534 The Z80 and gbz80 port
8535 \layout Standard
8536
8537 SDCC can target both the Zilog Z80 and the Nintendo Gameboy's Z80-like gbz80.
8538  The port is incomplete - long support is incomplete (mul, div and mod are
8539  unimplimented), and both float and bitfield support is missing.
8540  Apart from that the code generated is correct.
8541 \layout Standard
8542
8543 As always, the code is the authoritave reference - see z80/ralloc.c and z80/gen.c.
8544  The stack frame is similar to that generated by the IAR Z80 compiler.
8545  IX is used as the base pointer, HL is used as a temporary register, and
8546  BC and DE are available for holding varibles.
8547  IY is currently unusued.
8548  Return values are stored in HL.
8549  One bad side effect of using IX as the base pointer is that a functions
8550  stack frame is limited to 127 bytes - this will be fixed in a later version.
8551 \layout Section
8552
8553 Support
8554 \layout Standard
8555
8556 SDCC has grown to be a large project.
8557  The compiler alone (without the preprocessor, assembler and linker) is
8558  about 40,000 lines of code (blank stripped).
8559  The open source nature of this project is a key to its continued growth
8560  and support.
8561  You gain the benefit and support of many active software developers and
8562  end users.
8563  Is SDCC perfect? No, that's why we need your help.
8564  The developers take pride in fixing reported bugs.
8565  You can help by reporting the bugs and helping other SDCC users.
8566  There are lots of ways to contribute, and we encourage you to take part
8567  in making SDCC a great software package.
8568 \layout Subsection
8569
8570 Reporting Bugs
8571 \layout Standard
8572
8573 Send an email to the mailing list at 'user-sdcc@sdcc.sourceforge.net' or 'devel-sd
8574 cc@sdcc.sourceforge.net'.
8575  Bugs will be fixed ASAP.
8576  When reporting a bug, it is very useful to include a small test program
8577  which reproduces the problem.
8578  If you can isolate the problem by looking at the generated assembly code,
8579  this can be very helpful.
8580  Compiling your program with the --dumpall option can sometimes be useful
8581  in locating optimization problems.
8582 \layout Section
8583
8584 Acknowledgments
8585 \layout Standard
8586
8587 Sandeep Dutta (sandeep.dutta@usa.net) - SDCC, the compiler, MCS51 code generator,
8588  Debugger, AVR port
8589 \newline 
8590 Alan Baldwin (baldwin@shop-pdp.kent.edu) - Initial version of ASXXXX & ASLINK.
8591  
8592 \newline 
8593 John Hartman (jhartman@compuserve.com) - Porting ASXXX & ASLINK for 8051
8594 \newline 
8595 Dmitry S.
8596  Obukhov (dso@usa.net) - malloc & serial i/o routines.
8597  
8598 \newline 
8599 Daniel Drotos (drdani@mazsola.iit.uni-miskolc.hu) - for his Freeware simulator
8600 \newline 
8601 Malini Dutta(malini_dutta@hotmail.com) - my wife for her patience and support.
8602 \newline 
8603 Unknown - for the GNU C - preprocessor.
8604 \newline 
8605 Michael Hope - The Z80 and Z80GB port, 186 development
8606 \newline 
8607 Kevin Vigor - The DS390 port.
8608 \newline 
8609 Johan Knol - Lots of fixes and enhancements, DS390/TINI libs.
8610 \newline 
8611 Scott Datallo - The PIC port.
8612 \newline 
8613
8614 \newline 
8615
8616 \emph on 
8617 Thanks to all the other volunteer developers who have helped with coding,
8618  testing, web-page creation, distribution sets, etc.
8619  You know who you are :-)
8620 \emph default 
8621
8622 \newline 
8623
8624 \layout Standard
8625
8626 This document was initially written by Sandeep Dutta
8627 \layout Standard
8628
8629 All product names mentioned herein may be trademarks of their respective
8630  companies.
8631  
8632 \layout Standard
8633
8634
8635 \begin_inset LatexCommand \printindex{}
8636
8637 \end_inset 
8638
8639
8640 \the_end