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