* doc/sdccman.lyx: new pragma NOIV by Johannes Stezenbach <js@convergence.de>
[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.
1846  The value entered can be in Hexadecimal or Decimal format, eg.
1847  ---data-loc 0x20 or ---data-loc 32.
1848  (By default, the start location of the internal ram data segment  is set
1849  as low as possible in memory, taking into account the used register banks
1850  and the bit segment at address 0x20.
1851  For example if register banks 0 and 1 are used without bit variables, the
1852  data segment will be set, if ---data-loc is not used, to location 0x10.)
1853 \layout List
1854 \labelwidthstring 00.00.0000
1855
1856
1857 \series bold 
1858 ---idata-loc
1859 \series default 
1860 <Value> The start location of the indirectly addressable internal ram, default
1861  value is 0x80.
1862  The value entered can be in Hexadecimal or Decimal format, eg.
1863  ---idata-loc 0x88 or ---idata-loc 136.
1864 \layout List
1865 \labelwidthstring 00.00.0000
1866
1867
1868 \series bold 
1869 ---out-fmt-ihx
1870 \bar under 
1871  
1872 \series default 
1873 \bar default 
1874 The linker output (final object code) is in Intel Hex format.
1875  (This is the default option).
1876 \layout List
1877 \labelwidthstring 00.00.0000
1878
1879
1880 \series bold 
1881 ---out-fmt-s19
1882 \bar under 
1883  
1884 \series default 
1885 \bar default 
1886 The linker output (final object code) is in Motorola S19 format.
1887 \layout Subsubsection
1888
1889 MCS51 Options
1890 \layout List
1891 \labelwidthstring 00.00.0000
1892
1893
1894 \series bold 
1895 ---model-large
1896 \series default 
1897  Generate code for Large model programs see section Memory Models for more
1898  details.
1899  If this option is used all source files in the project should be compiled
1900  with this option.
1901  In addition the standard library routines are compiled with small model,
1902  they will need to be recompiled.
1903 \layout List
1904 \labelwidthstring 00.00.0000
1905
1906
1907 \series bold 
1908 ---model-small
1909 \series default 
1910 \size large 
1911 \emph on 
1912  
1913 \size default 
1914 \emph default 
1915 Generate code for Small Model programs see section Memory Models for more
1916  details.
1917  This is the default model.
1918 \layout Subsubsection
1919
1920 DS390 Options
1921 \layout List
1922 \labelwidthstring 00.00.0000
1923
1924
1925 \series bold 
1926 ---model-flat24
1927 \series default 
1928 \size large 
1929 \emph on 
1930  
1931 \size default 
1932 \emph default 
1933 Generate 24-bit flat mode code.
1934  This is the one and only that the ds390 code generator supports right now
1935  and is default when using 
1936 \emph on 
1937 -mds390
1938 \emph default 
1939 .
1940  See section Memory Models for more details.
1941 \layout List
1942 \labelwidthstring 00.00.0000
1943
1944
1945 \series bold 
1946 ---stack-10bit
1947 \series default 
1948  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
1949  This is the one and only that the ds390 code generator supports right now
1950  and is default when using 
1951 \emph on 
1952 -mds390
1953 \emph default 
1954 .
1955  In this mode, the stack is located in the lower 1K of the internal RAM,
1956  which is mapped to 0x400000.
1957  Note that the support is incomplete, since it still uses a single byte
1958  as the stack pointer.
1959  This means that only the lower 256 bytes of the potential 1K stack space
1960  will actually be used.
1961  However, this does allow you to reclaim the precious 256 bytes of low RAM
1962  for use for the DATA and IDATA segments.
1963  The compiler will not generate any code to put the processor into 10 bit
1964  stack mode.
1965  It is important to ensure that the processor is in this mode before calling
1966  any re-entrant functions compiled with this option.
1967  In principle, this should work with the 
1968 \emph on 
1969 ---stack-auto
1970 \emph default 
1971  option, but that has not been tested.
1972  It is incompatible with the 
1973 \emph on 
1974 ---xstack
1975 \emph default 
1976  option.
1977  It also only makes sense if the processor is in 24 bit contiguous addressing
1978  mode (see the 
1979 \emph on 
1980 ---model-flat24 option
1981 \emph default 
1982 ).
1983 \layout Subsubsection
1984
1985 Optimization Options
1986 \layout List
1987 \labelwidthstring 00.00.0000
1988
1989
1990 \series bold 
1991 ---nogcse
1992 \series default 
1993  Will not do global subexpression elimination, this option may be used when
1994  the compiler creates undesirably large stack/data spaces to store compiler
1995  temporaries.
1996  A warning message will be generated when this happens and the compiler
1997  will indicate the number of extra bytes it allocated.
1998  It recommended that this option NOT be used, #pragma\SpecialChar ~
1999 NOGCSE can be used
2000  to turn off global subexpression elimination for a given function only.
2001 \layout List
2002 \labelwidthstring 00.00.0000
2003
2004
2005 \series bold 
2006 ---noinvariant
2007 \series default 
2008  Will not do loop invariant optimizations, this may be turned off for reasons
2009  explained for the previous option.
2010  For more details of loop optimizations performed see section Loop Invariants.It
2011  recommended that this option NOT be used, #pragma\SpecialChar ~
2012 NOINVARIANT can be used
2013  to turn off invariant optimizations for a given function only.
2014 \layout List
2015 \labelwidthstring 00.00.0000
2016
2017
2018 \series bold 
2019 ---noinduction
2020 \series default 
2021  Will not do loop induction optimizations, see section strength reduction
2022  for more details.It is recommended that this option is NOT used, #pragma\SpecialChar ~
2023 NOINDUCT
2024 ION can be used to turn off induction optimizations for a given function
2025  only.
2026 \layout List
2027 \labelwidthstring 00.00.0000
2028
2029
2030 \series bold 
2031 ---nojtbound
2032 \size large 
2033 \bar under 
2034  
2035 \series default 
2036 \size default 
2037 \bar default 
2038  Will not generate boundary condition check when switch statements are implement
2039 ed using jump-tables.
2040  See section Switch Statements for more details.
2041  It is recommended that this option is NOT used, #pragma\SpecialChar ~
2042 NOJTBOUND can be
2043  used to turn off boundary checking for jump tables for a given function
2044  only.
2045 \layout List
2046 \labelwidthstring 00.00.0000
2047
2048
2049 \series bold 
2050 ---noloopreverse
2051 \series default 
2052 \size large 
2053  
2054 \size default 
2055 Will not do loop reversal optimization.
2056 \layout List
2057 \labelwidthstring 00.00.0000
2058
2059
2060 \series bold 
2061 ---no-xinit-opt
2062 \series default 
2063  This will disable the memcpy of initialized data in far space from code
2064  space
2065 \layout Subsubsection
2066
2067 Other Options
2068 \layout List
2069 \labelwidthstring 00.00.0000
2070
2071
2072 \series bold 
2073 -c\SpecialChar ~
2074 ---compile-only
2075 \series default 
2076  will compile and assemble the source, but will not call the linkage editor.
2077 \layout List
2078 \labelwidthstring 00.00.0000
2079
2080
2081 \series bold 
2082 -E
2083 \series default 
2084  Run only the C preprocessor.
2085  Preprocess all the C source files specified and output the results to standard
2086  output.
2087 \layout List
2088 \labelwidthstring 00.00.0000
2089
2090
2091 \series bold 
2092 ---stack-auto
2093 \series default 
2094 \size large 
2095 \emph on 
2096  
2097 \size default 
2098 \emph default 
2099 All functions in the source file will be compiled as 
2100 \emph on 
2101 reentrant
2102 \emph default 
2103 , i.e.
2104  the parameters and local variables will be allocated on the stack.
2105  see section Parameters and Local Variables for more details.
2106  If this option is used all source files in the project should be compiled
2107  with this option.
2108  
2109 \layout List
2110 \labelwidthstring 00.00.0000
2111
2112
2113 \series bold 
2114 ---xstack
2115 \series default 
2116  Uses a pseudo stack in the first 256 bytes in the external ram for allocating
2117  variables and passing parameters.
2118  See section on external stack for more details.
2119 \layout List
2120 \labelwidthstring 00.00.0000
2121
2122
2123 \series bold 
2124 ---callee-saves function1[,function2][,function3]....
2125
2126 \series default 
2127  The compiler by default uses a caller saves convention for register saving
2128  across function calls, however this can cause unneccessary register pushing
2129  & popping when calling small functions from larger functions.
2130  This option can be used to switch the register saving convention for the
2131  function names specified.
2132  The compiler will not save registers when calling these functions, no extra
2133  code will be generated at the entry & exit for these functions to save
2134  & restore the registers used by these functions, this can SUBSTANTIALLY
2135  reduce code & improve run time performance of the generated code.
2136  In the future the compiler (with interprocedural analysis) will be able
2137  to determine the appropriate scheme to use for each function call.
2138  DO NOT use this option for built-in functions such as _muluint..., if this
2139  option is used for a library function the appropriate library function
2140  needs to be recompiled with the same option.
2141  If the project consists of multiple source files then all the source file
2142  should be compiled with the same ---callee-saves option string.
2143  Also see #pragma\SpecialChar ~
2144 CALLEE-SAVES.
2145 \layout List
2146 \labelwidthstring 00.00.0000
2147
2148
2149 \series bold 
2150 ---debug
2151 \bar under 
2152  
2153 \series default 
2154 \bar default 
2155 When this option is used the compiler will generate debug information, that
2156  can be used with the SDCDB.
2157  The debug information is collected in a file with .cdb extension.
2158  For more information see documentation for SDCDB.
2159 \layout List
2160 \labelwidthstring 00.00.0000
2161
2162
2163 \series bold 
2164 ---peep-file
2165 \series default 
2166 <filename> This option can be used to use additional rules to be used by
2167  the peep hole optimizer.
2168  See section Peep Hole optimizations for details on how to write these rules.
2169 \layout List
2170 \labelwidthstring 00.00.0000
2171
2172
2173 \series bold 
2174 -S
2175 \size large 
2176 \bar under 
2177  
2178 \series default 
2179 \size default 
2180 \bar default 
2181 Stop after the stage of compilation proper; do not assemble.
2182  The output is an assembler code file for the input file specified.
2183 \layout List
2184 \labelwidthstring 00.00.0000
2185
2186
2187 \series bold 
2188 -Wa_asmOption[,asmOption]
2189 \series default 
2190 ...
2191  Pass the asmOption to the assembler.
2192 \layout List
2193 \labelwidthstring 00.00.0000
2194
2195
2196 \series bold 
2197 -Wl_linkOption[,linkOption]
2198 \series default 
2199 ...
2200  Pass the linkOption to the linker.
2201 \layout List
2202 \labelwidthstring 00.00.0000
2203
2204
2205 \series bold 
2206 ---int-long-reent
2207 \series default 
2208 \size large 
2209  
2210 \size default 
2211  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
2212  Note by default these libraries are compiled as non-reentrant.
2213  See section Installation for more details.
2214 \layout List
2215 \labelwidthstring 00.00.0000
2216
2217
2218 \series bold 
2219 ---cyclomatic
2220 \bar under 
2221  
2222 \series default 
2223 \bar default 
2224 This option will cause the compiler to generate an information message for
2225  each function in the source file.
2226  The message contains some 
2227 \emph on 
2228 important
2229 \emph default 
2230  information about the function.
2231  The number of edges and nodes the compiler detected in the control flow
2232  graph of the function, and most importantly the 
2233 \emph on 
2234 cyclomatic complexity
2235 \emph default 
2236  see section on Cyclomatic Complexity for more details.
2237 \layout List
2238 \labelwidthstring 00.00.0000
2239
2240
2241 \series bold 
2242 ---float-reent
2243 \bar under 
2244  
2245 \series default 
2246 \bar default 
2247  Floating point library is compiled as reentrant.See section Installation
2248  for more details.
2249 \layout List
2250 \labelwidthstring 00.00.0000
2251
2252
2253 \series bold 
2254 ---nooverlay
2255 \series default 
2256   The compiler will not overlay parameters and local variables of any function,
2257  see section Parameters and local variables for more details.
2258 \layout List
2259 \labelwidthstring 00.00.0000
2260
2261
2262 \series bold 
2263 ---main-return
2264 \series default 
2265  This option can be used when the code generated is called by a monitor
2266  program.
2267  The compiler will generate a 'ret' upon return from the 'main' function.
2268  The default option is to lock up i.e.
2269  generate a 'ljmp '.
2270 \layout List
2271 \labelwidthstring 00.00.0000
2272
2273
2274 \series bold 
2275 ---no-peep
2276 \series default 
2277   Disable peep-hole optimization.
2278 \layout List
2279 \labelwidthstring 00.00.0000
2280
2281
2282 \series bold 
2283 ---peep-asm
2284 \series default 
2285   Pass the inline assembler code through the peep hole optimizer.
2286  This can cause unexpected changes to inline assembler code, please go through
2287  the peephole optimizer rules defined in the source file tree '<target>/peeph.def
2288 ' before using this option.
2289 \layout List
2290 \labelwidthstring 00.00.0000
2291
2292
2293 \series bold 
2294 ---iram-size
2295 \series default 
2296 <Value> Causes the linker to check if the internal ram usage is within limits
2297  of the given value.
2298 \layout List
2299 \labelwidthstring 00.00.0000
2300
2301
2302 \series bold 
2303 ---xram-size
2304 \series default 
2305 <Value> Causes the linker to check if the external ram usage is within limits
2306  of the given value.
2307 \layout List
2308 \labelwidthstring 00.00.0000
2309
2310
2311 \series bold 
2312 ---code-size
2313 \series default 
2314 <Value> Causes the linker to check if the code usage is within limits of
2315  the given value.
2316 \layout List
2317 \labelwidthstring 00.00.0000
2318
2319
2320 \series bold 
2321 ---nostdincl
2322 \series default 
2323  This will prevent the compiler from passing on the default include path
2324  to the preprocessor.
2325 \layout List
2326 \labelwidthstring 00.00.0000
2327
2328
2329 \series bold 
2330 ---nostdlib
2331 \series default 
2332  This will prevent the compiler from passing on the default library path
2333  to the linker.
2334 \layout List
2335 \labelwidthstring 00.00.0000
2336
2337
2338 \series bold 
2339 ---verbose
2340 \series default 
2341  Shows the various actions the compiler is performing.
2342 \layout List
2343 \labelwidthstring 00.00.0000
2344
2345
2346 \series bold 
2347 -V
2348 \series default 
2349  Shows the actual commands the compiler is executing.
2350 \layout Subsubsection
2351
2352 Intermediate Dump Options
2353 \layout Standard
2354
2355 The following options are provided for the purpose of retargetting and debugging
2356  the compiler.
2357  These provided a means to dump the intermediate code (iCode) generated
2358  by the compiler in human readable form at various stages of the compilation
2359  process.
2360  
2361 \layout List
2362 \labelwidthstring 00.00.0000
2363
2364
2365 \series bold 
2366 ---dumpraw
2367 \series default 
2368  This option will cause the compiler to dump the intermediate code into
2369  a file of named 
2370 \emph on 
2371 <source filename>.dumpraw
2372 \emph default 
2373  just after the intermediate code has been generated for a function, i.e.
2374  before any optimizations are done.
2375  The basic blocks at this stage ordered in the depth first number, so they
2376  may not be in sequence of execution.
2377 \layout List
2378 \labelwidthstring 00.00.0000
2379
2380
2381 \series bold 
2382 ---dumpgcse
2383 \series default 
2384  Will create a dump of iCode's, after global subexpression elimination,
2385  into a file named 
2386 \emph on 
2387 <source filename>.dumpgcse.
2388 \layout List
2389 \labelwidthstring 00.00.0000
2390
2391
2392 \series bold 
2393 ---dumpdeadcode
2394 \series default 
2395  Will create a dump of iCode's, after deadcode elimination, into a file
2396  named 
2397 \emph on 
2398 <source filename>.dumpdeadcode.
2399 \layout List
2400 \labelwidthstring 00.00.0000
2401
2402
2403 \series bold 
2404 ---dumploop
2405 \series default 
2406 \size large 
2407  
2408 \size default 
2409 Will create a dump of iCode's, after loop optimizations, into a file named
2410  
2411 \emph on 
2412 <source filename>.dumploop.
2413 \layout List
2414 \labelwidthstring 00.00.0000
2415
2416
2417 \series bold 
2418 ---dumprange
2419 \series default 
2420 \size large 
2421  
2422 \size default 
2423 Will create a dump of iCode's, after live range analysis, into a file named
2424  
2425 \emph on 
2426 <source filename>.dumprange.
2427 \layout List
2428 \labelwidthstring 00.00.0000
2429
2430
2431 \series bold 
2432 ---dumlrange
2433 \series default 
2434  Will dump the life ranges for all symbols.
2435 \layout List
2436 \labelwidthstring 00.00.0000
2437
2438
2439 \series bold 
2440 ---dumpregassign
2441 \bar under 
2442  
2443 \series default 
2444 \bar default 
2445 Will create a dump of iCode's, after register assignment, into a file named
2446  
2447 \emph on 
2448 <source filename>.dumprassgn.
2449 \layout List
2450 \labelwidthstring 00.00.0000
2451
2452
2453 \series bold 
2454 ---dumplrange
2455 \series default 
2456  Will create a dump of the live ranges of iTemp's
2457 \layout List
2458 \labelwidthstring 00.00.0000
2459
2460
2461 \series bold 
2462 ---dumpall
2463 \size large 
2464 \bar under 
2465  
2466 \series default 
2467 \size default 
2468 \bar default 
2469 Will cause all the above mentioned dumps to be created.
2470 \layout Subsection
2471
2472 MCS51/DS390 Storage Class Language Extensions
2473 \layout Standard
2474
2475 In addition to the ANSI storage classes SDCC allows the following MCS51
2476  specific storage classes.
2477 \layout Subsubsection
2478
2479 xdata
2480 \layout Standard
2481
2482 Variables declared with this storage class will be placed in the extern
2483  RAM.
2484  This is the 
2485 \series bold 
2486 default
2487 \series default 
2488  storage class for Large Memory model, e.g.:
2489 \newline 
2490
2491 \newline 
2492
2493 \family typewriter 
2494 xdata unsigned char xduc;
2495 \layout Subsubsection
2496
2497 data
2498 \layout Standard
2499
2500 This is the 
2501 \series bold 
2502 default
2503 \series default 
2504  storage class for Small Memory model.
2505  Variables declared with this storage class will be allocated in the internal
2506  RAM, e.g.:
2507 \newline 
2508
2509 \newline 
2510
2511 \family typewriter 
2512 data int iramdata;
2513 \layout Subsubsection
2514
2515 idata
2516 \layout Standard
2517
2518 Variables declared with this storage class will be allocated into the indirectly
2519  addressable portion of the internal ram of a 8051, e.g.:
2520 \newline 
2521
2522 \newline 
2523
2524 \family typewriter 
2525 idata int idi;
2526 \layout Subsubsection
2527
2528 bit
2529 \layout Standard
2530
2531 This is a data-type and a storage class specifier.
2532  When a variable is declared as a bit, it is allocated into the bit addressable
2533  memory of 8051, e.g.:
2534 \newline 
2535
2536 \newline 
2537
2538 \family typewriter 
2539 bit iFlag;
2540 \layout Subsubsection
2541
2542 sfr / sbit
2543 \layout Standard
2544
2545 Like the bit keyword, 
2546 \emph on 
2547 sfr / sbit 
2548 \emph default 
2549 signifies both a data-type and storage class, they are used to describe
2550  the special function registers and special bit variables of a 8051, eg:
2551 \newline 
2552
2553 \newline 
2554
2555 \family typewriter 
2556 sfr at 0x80 P0; /* special function register P0 at location 0x80 */
2557 \newline 
2558 sbit at 0xd7 CY; /* CY (Carry Flag) */
2559 \layout Subsection
2560
2561 Pointers
2562 \layout Standard
2563
2564 SDCC allows (via language extensions) pointers to explicitly point to any
2565  of the memory spaces of the 8051.
2566  In addition to the explicit pointers, the compiler uses (by default) generic
2567  pointers which can be used to point to any of the memory spaces.
2568 \newline 
2569
2570 \newline 
2571 Pointer declaration examples:
2572 \newline 
2573
2574 \size small 
2575
2576 \newline 
2577
2578 \family typewriter 
2579 \size default 
2580 /* pointer physically in xternal ram pointing to object in internal ram
2581  */ 
2582 \newline 
2583 data unsigned char * xdata p;
2584 \newline 
2585
2586 \newline 
2587 /* pointer physically in code rom pointing to data in xdata space */ 
2588 \newline 
2589 xdata unsigned char * code p;
2590 \newline 
2591
2592 \newline 
2593 /* pointer physically in code space pointing to data in code space */ 
2594 \newline 
2595 code unsigned char * code p;
2596 \newline 
2597
2598 \newline 
2599 /* the folowing is a generic pointer physically located in xdata space */
2600 \newline 
2601 char * xdata p;
2602 \family default 
2603 \size small 
2604
2605 \newline 
2606
2607 \newline 
2608
2609 \size default 
2610 Well you get the idea.
2611  
2612 \newline 
2613
2614 \newline 
2615 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
2616 \emph on 
2617 generic
2618 \emph default 
2619  pointers.
2620  
2621 \size small 
2622
2623 \newline 
2624
2625 \newline 
2626
2627 \size default 
2628 The highest order byte of the 
2629 \emph on 
2630 generic
2631 \emph default 
2632  pointers contains the data space information.
2633  Assembler support routines are called whenever data is stored or retrieved
2634  using 
2635 \emph on 
2636 generic
2637 \emph default 
2638  pointers.
2639  These are useful for developing reusable library routines.
2640  Explicitly specifying the pointer type will generate the most efficient
2641  code.
2642 \layout Subsection
2643
2644 Parameters & Local Variables
2645 \layout Standard
2646
2647 Automatic (local) variables and parameters to functions can either be placed
2648  on the stack or in data-space.
2649  The default action of the compiler is to place these variables in the internal
2650  RAM (for small model) or external RAM (for large model).
2651  This in fact makes them 
2652 \emph on 
2653 static
2654 \emph default 
2655  so by default functions are non-reentrant.
2656 \newline 
2657
2658 \newline 
2659 They can be placed on the stack either by using the
2660 \emph on 
2661  ---stack-auto
2662 \emph default 
2663  option or by using the 
2664 \emph on 
2665 reentrant
2666 \emph default 
2667  keyword in the function declaration, e.g.:
2668 \newline 
2669
2670 \size small 
2671
2672 \newline 
2673
2674 \family typewriter 
2675 \size default 
2676 unsigned char foo(char i) reentrant 
2677 \newline 
2678
2679 \newline 
2680 ...
2681  
2682 \newline 
2683 }
2684 \newline 
2685
2686 \family default 
2687
2688 \newline 
2689 Since stack space on 8051 is limited, the 
2690 \emph on 
2691 reentrant 
2692 \emph default 
2693 keyword or the
2694 \emph on 
2695  ---stack-auto
2696 \emph default 
2697  option should be used sparingly.
2698  Note that the reentrant keyword just means that the parameters & local
2699  variables will be allocated to the stack, it 
2700 \emph on 
2701 does not
2702 \emph default 
2703  mean that the function is register bank independent.
2704 \newline 
2705
2706 \newline 
2707 Local variables can be assigned storage classes and absolute addresses,
2708  e.g.: 
2709 \newline 
2710
2711 \newline 
2712
2713 \family typewriter 
2714 unsigned char foo() {
2715 \newline 
2716 \SpecialChar ~
2717 \SpecialChar ~
2718 \SpecialChar ~
2719 \SpecialChar ~
2720 xdata unsigned char i;
2721 \newline 
2722 \SpecialChar ~
2723 \SpecialChar ~
2724 \SpecialChar ~
2725 \SpecialChar ~
2726 bit bvar;
2727 \newline 
2728 \SpecialChar ~
2729 \SpecialChar ~
2730 \SpecialChar ~
2731 \SpecialChar ~
2732 data at 0x31 unsiged char j;
2733 \newline 
2734 \SpecialChar ~
2735 \SpecialChar ~
2736 \SpecialChar ~
2737 \SpecialChar ~
2738 ...
2739  
2740 \newline 
2741 }
2742 \newline 
2743
2744 \newline 
2745
2746 \family default 
2747 In the above example the variable 
2748 \emph on 
2749 i
2750 \emph default 
2751  will be allocated in the external ram, 
2752 \emph on 
2753 bvar
2754 \emph default 
2755  in bit addressable space and
2756 \emph on 
2757  j
2758 \emph default 
2759  in internal ram.
2760  When compiled with 
2761 \emph on 
2762 ---stack-auto
2763 \emph default 
2764  or when a function is declared as 
2765 \emph on 
2766 reentrant
2767 \emph default 
2768  this should only be done for static variables.
2769 \layout Standard
2770
2771 Parameters however are not allowed any storage class, (storage classes for
2772  parameters will be ignored), their allocation is governed by the memory
2773  model in use, and the reentrancy options.
2774 \layout Subsection
2775
2776 Overlaying
2777 \layout Standard
2778
2779 For non-reentrant functions SDCC will try to reduce internal ram space usage
2780  by overlaying parameters and local variables of a function (if possible).
2781  Parameters and local variables of a function will be allocated to an overlayabl
2782 e segment if the function has 
2783 \emph on 
2784 no other function calls and the function is non-reentrant and the memory
2785  model is small.
2786
2787 \emph default 
2788  If an explicit storage class is specified for a local variable, it will
2789  NOT be overlayed.
2790 \layout Standard
2791
2792 Note that the compiler (not the linkage editor) makes the decision for overlayin
2793 g the data items.
2794  Functions that are called from an interrupt service routine should be preceded
2795  by a #pragma\SpecialChar ~
2796 NOOVERLAY if they are not reentrant.
2797 \layout Standard
2798
2799 Also note that the compiler does not do any processing of inline assembler
2800  code, so the compiler might incorrectly assign local variables and parameters
2801  of a function into the overlay segment if the inline assembler code calls
2802  other c-functions that might use the overlay.
2803  In that case the #pragma\SpecialChar ~
2804 NOOVERLAY should be used.
2805 \layout Standard
2806
2807 Parameters and Local variables of functions that contain 16 or 32 bit multiplica
2808 tion or division will NOT be overlayed since these are implemented using
2809  external functions, e.g.:
2810 \newline 
2811
2812 \newline 
2813
2814 \family typewriter 
2815 #pragma SAVE 
2816 \newline 
2817 #pragma NOOVERLAY 
2818 \newline 
2819 void set_error(unsigned char errcd) 
2820 \newline 
2821 {
2822 \newline 
2823 \SpecialChar ~
2824 \SpecialChar ~
2825 \SpecialChar ~
2826 \SpecialChar ~
2827 P3 = errcd;
2828 \newline 
2829
2830 \newline 
2831 #pragma RESTORE 
2832 \newline 
2833
2834 \newline 
2835 void some_isr () interrupt 2 using 1 
2836 \newline 
2837 {
2838 \newline 
2839 \SpecialChar ~
2840 \SpecialChar ~
2841 \SpecialChar ~
2842 \SpecialChar ~
2843 ...
2844 \newline 
2845 \SpecialChar ~
2846 \SpecialChar ~
2847 \SpecialChar ~
2848 \SpecialChar ~
2849 set_error(10);
2850 \newline 
2851 \SpecialChar ~
2852 \SpecialChar ~
2853 \SpecialChar ~
2854 \SpecialChar ~
2855 ...
2856  
2857 \newline 
2858 }
2859 \newline 
2860
2861 \newline 
2862
2863 \family default 
2864 In the above example the parameter 
2865 \emph on 
2866 errcd
2867 \emph default 
2868  for the function 
2869 \emph on 
2870 set_error
2871 \emph default 
2872  would be assigned to the overlayable segment if the #pragma\SpecialChar ~
2873 NOOVERLAY was
2874  not present, this could cause unpredictable runtime behavior when called
2875  from an ISR.
2876  The #pragma\SpecialChar ~
2877 NOOVERLAY ensures that the parameters and local variables for
2878  the function are NOT overlayed.
2879 \layout Subsection
2880
2881 Interrupt Service Routines
2882 \layout Standard
2883
2884 SDCC allows interrupt service routines to be coded in C, with some extended
2885  keywords.
2886 \newline 
2887
2888 \newline 
2889
2890 \family typewriter 
2891 void timer_isr (void) interrupt 2 using 1 
2892 \newline 
2893
2894 \newline 
2895 ..
2896  
2897 \newline 
2898 }
2899 \newline 
2900
2901 \newline 
2902
2903 \family default 
2904 The number following the 
2905 \emph on 
2906 interrupt
2907 \emph default 
2908  keyword is the interrupt number this routine will service.
2909  The compiler will insert a call to this routine in the interrupt vector
2910  table for the interrupt number specified.
2911  The 
2912 \emph on 
2913 using
2914 \emph default 
2915  keyword is used to tell the compiler to use the specified register bank
2916  (8051 specific) when generating code for this function.
2917  Note that when some function is called from an interrupt service routine
2918  it should be preceded by a #pragma\SpecialChar ~
2919 NOOVERLAY if it is not reentrant.
2920  A special note here, int (16 bit) and long (32 bit) integer division, multiplic
2921 ation & modulus operations are implemented using external support routines
2922  developed in ANSI-C, if an interrupt service routine needs to do any of
2923  these operations then the support routines (as mentioned in a following
2924  section) will have to be recompiled using the
2925 \emph on 
2926  ---stack-auto
2927 \emph default 
2928  option and the source file will need to be compiled using the 
2929 \emph on 
2930 ---int-long-ren
2931 \emph default 
2932 t compiler option.
2933 \layout Standard
2934
2935 If you have multiple source files in your project, interrupt service routines
2936  can be present in any of them, but a prototype of the isr MUST be present
2937  or included in the file that contains the function 
2938 \emph on 
2939 main
2940 \emph default 
2941 .
2942 \layout Standard
2943
2944 Interrupt Numbers and the corresponding address & descriptions for the Standard
2945  8051 are listed below.
2946  SDCC will automatically adjust the interrupt vector table to the maximum
2947  interrupt number specified.
2948 \newline 
2949
2950 \layout Standard
2951
2952
2953 \begin_inset  Tabular
2954 <lyxtabular version="3" rows="6" columns="3">
2955 <features>
2956 <column alignment="center" valignment="top" leftline="true" width="0(null)">
2957 <column alignment="center" valignment="top" leftline="true" width="0(null)">
2958 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
2959 <row topline="true" bottomline="true">
2960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2961 \begin_inset Text
2962
2963 \layout Standard
2964
2965 Interrupt #
2966 \end_inset 
2967 </cell>
2968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2969 \begin_inset Text
2970
2971 \layout Standard
2972
2973 Description
2974 \end_inset 
2975 </cell>
2976 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2977 \begin_inset Text
2978
2979 \layout Standard
2980
2981 Vector Address
2982 \end_inset 
2983 </cell>
2984 </row>
2985 <row topline="true">
2986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2987 \begin_inset Text
2988
2989 \layout Standard
2990
2991 0
2992 \end_inset 
2993 </cell>
2994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2995 \begin_inset Text
2996
2997 \layout Standard
2998
2999 External 0
3000 \end_inset 
3001 </cell>
3002 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3003 \begin_inset Text
3004
3005 \layout Standard
3006
3007 0x0003
3008 \end_inset 
3009 </cell>
3010 </row>
3011 <row topline="true">
3012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3013 \begin_inset Text
3014
3015 \layout Standard
3016
3017 1
3018 \end_inset 
3019 </cell>
3020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3021 \begin_inset Text
3022
3023 \layout Standard
3024
3025 Timer 0
3026 \end_inset 
3027 </cell>
3028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3029 \begin_inset Text
3030
3031 \layout Standard
3032
3033 0x000B
3034 \end_inset 
3035 </cell>
3036 </row>
3037 <row topline="true">
3038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3039 \begin_inset Text
3040
3041 \layout Standard
3042
3043 2
3044 \end_inset 
3045 </cell>
3046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3047 \begin_inset Text
3048
3049 \layout Standard
3050
3051 External 1
3052 \end_inset 
3053 </cell>
3054 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3055 \begin_inset Text
3056
3057 \layout Standard
3058
3059 0x0013
3060 \end_inset 
3061 </cell>
3062 </row>
3063 <row topline="true">
3064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3065 \begin_inset Text
3066
3067 \layout Standard
3068
3069 3
3070 \end_inset 
3071 </cell>
3072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3073 \begin_inset Text
3074
3075 \layout Standard
3076
3077 Timer 1
3078 \end_inset 
3079 </cell>
3080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3081 \begin_inset Text
3082
3083 \layout Standard
3084
3085 0x001B
3086 \end_inset 
3087 </cell>
3088 </row>
3089 <row topline="true" bottomline="true">
3090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3091 \begin_inset Text
3092
3093 \layout Standard
3094
3095 4
3096 \end_inset 
3097 </cell>
3098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3099 \begin_inset Text
3100
3101 \layout Standard
3102
3103 Serial
3104 \end_inset 
3105 </cell>
3106 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3107 \begin_inset Text
3108
3109 \layout Standard
3110
3111 0x0023
3112 \end_inset 
3113 </cell>
3114 </row>
3115 </lyxtabular>
3116
3117 \end_inset 
3118
3119
3120 \newline 
3121
3122 \newline 
3123 If the interrupt service routine is defined without 
3124 \emph on 
3125 using
3126 \emph default 
3127  a register bank or with register bank 0 (using 0), the compiler will save
3128  the registers used by itself on the stack upon entry and restore them at
3129  exit, however if such an interrupt service routine calls another function
3130  then the entire register bank will be saved on the stack.
3131  This scheme may be advantageous for small interrupt service routines which
3132  have low register usage.
3133 \layout Standard
3134
3135 If the interrupt service routine is defined to be using a specific register
3136  bank then only 
3137 \emph on 
3138 a, b & dptr
3139 \emph default 
3140  are save and restored, if such an interrupt service routine calls another
3141  function (using another register bank) then the entire register bank of
3142  the called function will be saved on the stack.
3143  This scheme is recommended for larger interrupt service routines.
3144 \layout Standard
3145
3146 Calling other functions from an interrupt service routine is not recommended,
3147  avoid it if possible.
3148 \newline 
3149
3150 \newline 
3151 Also see the _naked modifier.
3152 \layout Subsection
3153
3154 Critical Functions
3155 \layout Standard
3156
3157
3158 \shape italic 
3159 <TODO: this isn't implemented at all!>
3160 \shape default 
3161
3162 \newline 
3163
3164 \newline 
3165 A special keyword may be associated with a function declaring it as 
3166 \emph on 
3167 critical
3168 \emph default 
3169 .
3170  SDCC will generate code to disable all interrupts upon entry to a critical
3171  function and enable them back before returning.
3172  Note that nesting critical functions may cause unpredictable results.
3173 \newline 
3174
3175 \size small 
3176
3177 \newline 
3178
3179 \family typewriter 
3180 \size default 
3181 int foo () critical 
3182 \newline 
3183
3184 \newline 
3185 ...
3186  
3187 \newline 
3188 ...
3189  
3190 \newline 
3191 }
3192 \newline 
3193
3194 \family default 
3195
3196 \newline 
3197 The critical attribute maybe used with other attributes like 
3198 \emph on 
3199 reentrant.
3200 \layout Subsection
3201
3202 Naked Functions
3203 \layout Standard
3204
3205 A special keyword may be associated with a function declaring it as 
3206 \emph on 
3207 _naked.
3208  
3209 \emph default 
3210 The 
3211 \emph on 
3212 _naked
3213 \emph default 
3214  function modifier attribute prevents the compiler from generating prologue
3215  and epilogue code for that function.
3216  This means that the user is entirely responsible for such things as saving
3217  any registers that may need to be preserved, selecting the proper register
3218  bank, generating the 
3219 \emph on 
3220 return
3221 \emph default 
3222  instruction at the end, etc.
3223  Practically, this means that the contents of the function must be written
3224  in inline assembler.
3225  This is particularly useful for interrupt functions, which can have a large
3226  (and often unnecessary) prologue/epilogue.
3227  For example, compare the code generated by these two functions:
3228 \newline 
3229
3230 \newline 
3231
3232 \family typewriter 
3233 data unsigned char counter;
3234 \newline 
3235 void simpleInterrupt(void) interrupt 1
3236 \newline 
3237 {
3238 \newline 
3239 \SpecialChar ~
3240 \SpecialChar ~
3241 \SpecialChar ~
3242 \SpecialChar ~
3243 counter++;
3244 \newline 
3245 }
3246 \newline 
3247
3248 \newline 
3249 void nakedInterrupt(void) interrupt 2 _naked
3250 \newline 
3251 {
3252 \newline 
3253 \SpecialChar ~
3254 \SpecialChar ~
3255 \SpecialChar ~
3256 \SpecialChar ~
3257 _asm
3258 \newline 
3259 \SpecialChar ~
3260 \SpecialChar ~
3261 \SpecialChar ~
3262 \SpecialChar ~
3263 \SpecialChar ~
3264 \SpecialChar ~
3265 inc\SpecialChar ~
3266 \SpecialChar ~
3267 \SpecialChar ~
3268 \SpecialChar ~
3269 \SpecialChar ~
3270 _counter
3271 \newline 
3272 \SpecialChar ~
3273 \SpecialChar ~
3274 \SpecialChar ~
3275 \SpecialChar ~
3276 \SpecialChar ~
3277 \SpecialChar ~
3278 reti\SpecialChar ~
3279 \SpecialChar ~
3280 \SpecialChar ~
3281 \SpecialChar ~
3282 ; MUST explicitly include ret in _naked function.
3283 \newline 
3284 \SpecialChar ~
3285 \SpecialChar ~
3286 \SpecialChar ~
3287 \SpecialChar ~
3288 _endasm;
3289 \newline 
3290 }
3291 \family default 
3292
3293 \newline 
3294
3295 \newline 
3296 For an 8051 target, the generated simpleInterrupt looks like:
3297 \newline 
3298
3299 \newline 
3300
3301 \family typewriter 
3302 _simpleIterrupt:
3303 \newline 
3304 \SpecialChar ~
3305 \SpecialChar ~
3306 \SpecialChar ~
3307 \SpecialChar ~
3308 push\SpecialChar ~
3309 \SpecialChar ~
3310 \SpecialChar ~
3311 \SpecialChar ~
3312 acc
3313 \newline 
3314 \SpecialChar ~
3315 \SpecialChar ~
3316 \SpecialChar ~
3317 \SpecialChar ~
3318 push\SpecialChar ~
3319 \SpecialChar ~
3320 \SpecialChar ~
3321 \SpecialChar ~
3322 b
3323 \newline 
3324 \SpecialChar ~
3325 \SpecialChar ~
3326 \SpecialChar ~
3327 \SpecialChar ~
3328 push\SpecialChar ~
3329 \SpecialChar ~
3330 \SpecialChar ~
3331 \SpecialChar ~
3332 dpl
3333 \newline 
3334 \SpecialChar ~
3335 \SpecialChar ~
3336 \SpecialChar ~
3337 \SpecialChar ~
3338 push\SpecialChar ~
3339 \SpecialChar ~
3340 \SpecialChar ~
3341 \SpecialChar ~
3342 dph
3343 \newline 
3344 \SpecialChar ~
3345 \SpecialChar ~
3346 \SpecialChar ~
3347 \SpecialChar ~
3348 push\SpecialChar ~
3349 \SpecialChar ~
3350 \SpecialChar ~
3351 \SpecialChar ~
3352 psw
3353 \newline 
3354 \SpecialChar ~
3355 \SpecialChar ~
3356 \SpecialChar ~
3357 \SpecialChar ~
3358 mov\SpecialChar ~
3359 \SpecialChar ~
3360 \SpecialChar ~
3361 \SpecialChar ~
3362 \SpecialChar ~
3363 psw,#0x00
3364 \newline 
3365 \SpecialChar ~
3366 \SpecialChar ~
3367 \SpecialChar ~
3368 \SpecialChar ~
3369 inc\SpecialChar ~
3370 \SpecialChar ~
3371 \SpecialChar ~
3372 \SpecialChar ~
3373 \SpecialChar ~
3374 _counter
3375 \newline 
3376 \SpecialChar ~
3377 \SpecialChar ~
3378 \SpecialChar ~
3379 \SpecialChar ~
3380 pop\SpecialChar ~
3381 \SpecialChar ~
3382 \SpecialChar ~
3383 \SpecialChar ~
3384 \SpecialChar ~
3385 psw
3386 \newline 
3387 \SpecialChar ~
3388 \SpecialChar ~
3389 \SpecialChar ~
3390 \SpecialChar ~
3391 pop\SpecialChar ~
3392 \SpecialChar ~
3393 \SpecialChar ~
3394 \SpecialChar ~
3395 \SpecialChar ~
3396 dph
3397 \newline 
3398 \SpecialChar ~
3399 \SpecialChar ~
3400 \SpecialChar ~
3401 \SpecialChar ~
3402 pop\SpecialChar ~
3403 \SpecialChar ~
3404 \SpecialChar ~
3405 \SpecialChar ~
3406 \SpecialChar ~
3407 dpl
3408 \newline 
3409 \SpecialChar ~
3410 \SpecialChar ~
3411 \SpecialChar ~
3412 \SpecialChar ~
3413 pop\SpecialChar ~
3414 \SpecialChar ~
3415 \SpecialChar ~
3416 \SpecialChar ~
3417 \SpecialChar ~
3418 b
3419 \newline 
3420 \SpecialChar ~
3421 \SpecialChar ~
3422 \SpecialChar ~
3423 \SpecialChar ~
3424 pop\SpecialChar ~
3425 \SpecialChar ~
3426 \SpecialChar ~
3427 \SpecialChar ~
3428 \SpecialChar ~
3429 acc
3430 \newline 
3431 \SpecialChar ~
3432 \SpecialChar ~
3433 \SpecialChar ~
3434 \SpecialChar ~
3435 reti
3436 \family default 
3437
3438 \newline 
3439
3440 \newline 
3441 whereas nakedInterrupt looks like:
3442 \newline 
3443
3444 \newline 
3445
3446 \family typewriter 
3447 _nakedInterrupt:
3448 \newline 
3449 \SpecialChar ~
3450 \SpecialChar ~
3451 \SpecialChar ~
3452 \SpecialChar ~
3453 inc\SpecialChar ~
3454 \SpecialChar ~
3455 \SpecialChar ~
3456 \SpecialChar ~
3457 _counter
3458 \newline 
3459 \SpecialChar ~
3460 \SpecialChar ~
3461 \SpecialChar ~
3462 \SpecialChar ~
3463 reti\SpecialChar ~
3464 \SpecialChar ~
3465 \SpecialChar ~
3466 ; MUST explicitly include ret(i) in _naked function.
3467 \family default 
3468
3469 \newline 
3470
3471 \newline 
3472 While there is nothing preventing you from writing C code inside a _naked
3473  function, there are many ways to shoot yourself in the foot doing this,
3474  and it is recommended that you stick to inline assembler.
3475 \layout Subsection
3476
3477 Functions using private banks
3478 \layout Standard
3479
3480 The 
3481 \emph on 
3482 using
3483 \emph default 
3484  attribute (which tells the compiler to use a register bank other than the
3485  default bank zero) should only be applied to 
3486 \emph on 
3487 interrupt
3488 \emph default 
3489  functions (see note 1 below).
3490  This will in most circumstances make the generated ISR code more efficient
3491  since it will not have to save registers on the stack.
3492 \layout Standard
3493
3494 The 
3495 \emph on 
3496 using
3497 \emph default 
3498  attribute will have no effect on the generated code for a 
3499 \emph on 
3500 non-interrupt
3501 \emph default 
3502  function (but may occasionally be useful anyway
3503 \begin_inset Foot
3504 collapsed true
3505
3506 \layout Standard
3507
3508 possible exception: if a function is called ONLY from 'interrupt' functions
3509  using a particular bank, it can be declared with the same 'using' attribute
3510  as the calling 'interrupt' functions.
3511  For instance, if you have several ISRs using bank one, and all of them
3512  call memcpy(), it might make sense to create a specialized version of memcpy()
3513  'using 1', since this would prevent the ISR from having to save bank zero
3514  to the stack on entry and switch to bank zero before calling the function
3515 \end_inset 
3516
3517 ).
3518 \newline 
3519
3520 \emph on 
3521 (pending: I don't think this has been done yet)
3522 \layout Standard
3523
3524 An 
3525 \emph on 
3526 interrupt
3527 \emph default 
3528  function using a non-zero bank will assume that it can trash that register
3529  bank, and will not save it.
3530  Since high-priority interrupts can interrupt low-priority ones on the 8051
3531  and friends, this means that if a high-priority ISR 
3532 \emph on 
3533 using
3534 \emph default 
3535  a particular bank occurs while processing a low-priority ISR 
3536 \emph on 
3537 using
3538 \emph default 
3539  the same bank, terrible and bad things can happen.
3540  To prevent this, no single register bank should be 
3541 \emph on 
3542 used
3543 \emph default 
3544  by both a high priority and a low priority ISR.
3545  This is probably most easily done by having all high priority ISRs use
3546  one bank and all low priority ISRs use another.
3547  If you have an ISR which can change priority at runtime, you're on your
3548  own: I suggest using the default bank zero and taking the small performance
3549  hit.
3550 \layout Standard
3551
3552 It is most efficient if your ISR calls no other functions.
3553  If your ISR must call other functions, it is most efficient if those functions
3554  use the same bank as the ISR (see note 1 below); the next best is if the
3555  called functions use bank zero.
3556  It is very inefficient to call a function using a different, non-zero bank
3557  from an ISR.
3558  
3559 \layout Subsection
3560
3561 Absolute Addressing
3562 \layout Standard
3563
3564 Data items can be assigned an absolute address with the 
3565 \emph on 
3566 at <address>
3567 \emph default 
3568  keyword, in addition to a storage class, e.g.:
3569 \newline 
3570
3571 \newline 
3572
3573 \family typewriter 
3574 xdata at 0x8000 unsigned char PORTA_8255 ;
3575 \newline 
3576
3577 \family default 
3578
3579 \newline 
3580 In the above example the PORTA_8255 will be allocated to the location 0x8000
3581  of the external ram.
3582  Note that this feature is provided to give the programmer access to 
3583 \emph on 
3584 memory mapped
3585 \emph default 
3586  devices attached to the controller.
3587  The compiler does not actually reserve any space for variables declared
3588  in this way (they are implemented with an equate in the assembler).
3589  Thus it is left to the programmer to make sure there are no overlaps with
3590  other variables that are declared without the absolute address.
3591  The assembler listing file (.lst) and the linker output files (.rst) and
3592  (.map) are a good places to look for such overlaps.
3593 \newline 
3594
3595 \newline 
3596 Absolute address can be specified for variables in all storage classes,
3597  e.g.:
3598 \newline 
3599
3600 \newline 
3601
3602 \family typewriter 
3603 bit at 0x02 bvar;
3604 \newline 
3605
3606 \newline 
3607
3608 \family default 
3609 The above example will allocate the variable at offset 0x02 in the bit-addressab
3610 le space.
3611  There is no real advantage to assigning absolute addresses to variables
3612  in this manner, unless you want strict control over all the variables allocated.
3613 \layout Subsection
3614
3615 Startup Code
3616 \layout Standard
3617
3618 The compiler inserts a call to the C routine 
3619 \emph on 
3620 _sdcc__external__startup()
3621 \series bold 
3622 \emph default 
3623  
3624 \series default 
3625 at the start of the CODE area.
3626  This routine is in the runtime library.
3627  By default this routine returns 0, if this routine returns a non-zero value,
3628  the static & global variable initialization will be skipped and the function
3629  main will be invoked Other wise static & global variables will be initialized
3630  before the function main is invoked.
3631  You could add a 
3632 \emph on 
3633 _sdcc__external__startup()
3634 \emph default 
3635  routine to your program to override the default if you need to setup hardware
3636  or perform some other critical operation prior to static & global variable
3637  initialization.
3638 \layout Subsection
3639
3640 Inline Assembler Code
3641 \layout Standard
3642
3643 SDCC allows the use of in-line assembler with a few restriction as regards
3644  labels.
3645  All labels defined within inline assembler code 
3646 \emph on 
3647 has to be
3648 \emph default 
3649  of the form 
3650 \emph on 
3651 nnnnn$
3652 \emph default 
3653  where nnnn is a number less than 100 (which implies a limit of utmost 100
3654  inline assembler labels 
3655 \emph on 
3656 per function
3657 \emph default 
3658 \noun on 
3659 )
3660 \noun default 
3661 .
3662  It is strongly recommended that each assembly instruction (including labels)
3663  be placed in a separate line (as the example shows).
3664  When the 
3665 \emph on 
3666 ---peep-asm
3667 \emph default 
3668  command line option is used, the inline assembler code will be passed through
3669  the peephole optimizer.
3670  This might cause some unexpected changes in the inline assembler code.
3671  Please go throught the peephole optimizer rules defined in file 
3672 \emph on 
3673 SDCCpeeph.def
3674 \emph default 
3675  carefully before using this option.
3676 \newline 
3677
3678 \newline 
3679
3680 \family typewriter 
3681 _asm 
3682 \newline 
3683 \SpecialChar ~
3684 \SpecialChar ~
3685 \SpecialChar ~
3686 \SpecialChar ~
3687 mov\SpecialChar ~
3688 \SpecialChar ~
3689 \SpecialChar ~
3690 \SpecialChar ~
3691 \SpecialChar ~
3692 b,#10 
3693 \newline 
3694 00001$: 
3695 \newline 
3696 \SpecialChar ~
3697 \SpecialChar ~
3698 \SpecialChar ~
3699 \SpecialChar ~
3700 djnz\SpecialChar ~
3701 \SpecialChar ~
3702 \SpecialChar ~
3703 \SpecialChar ~
3704 b,00001$ 
3705 \newline 
3706 _endasm ;
3707 \family default 
3708 \size small 
3709
3710 \newline 
3711
3712 \newline 
3713
3714 \size default 
3715 The inline assembler code can contain any valid code understood by the assembler
3716 , this includes any assembler directives and comment lines.
3717  The compiler does not do any validation of the code within the 
3718 \family typewriter 
3719 _asm ...
3720  _endasm;
3721 \family default 
3722  keyword pair.
3723  
3724 \newline 
3725
3726 \newline 
3727 Inline assembler code cannot reference any C-Labels, however it can reference
3728  labels defined by the inline assembler, e.g.:
3729 \newline 
3730
3731 \newline 
3732
3733 \family typewriter 
3734 foo() { 
3735 \newline 
3736 \SpecialChar ~
3737 \SpecialChar ~
3738 \SpecialChar ~
3739 \SpecialChar ~
3740 /* some c code */ 
3741 \newline 
3742 \SpecialChar ~
3743 \SpecialChar ~
3744 \SpecialChar ~
3745 \SpecialChar ~
3746 _asm 
3747 \newline 
3748 \SpecialChar ~
3749 \SpecialChar ~
3750 \SpecialChar ~
3751 \SpecialChar ~
3752 \SpecialChar ~
3753 \SpecialChar ~
3754 ; some assembler code 
3755 \newline 
3756 \SpecialChar ~
3757 \SpecialChar ~
3758 \SpecialChar ~
3759 \SpecialChar ~
3760 \SpecialChar ~
3761 \SpecialChar ~
3762 ljmp $0003 
3763 \newline 
3764 \SpecialChar ~
3765 \SpecialChar ~
3766 \SpecialChar ~
3767 \SpecialChar ~
3768 _endasm; 
3769 \newline 
3770 \SpecialChar ~
3771 \SpecialChar ~
3772 \SpecialChar ~
3773 \SpecialChar ~
3774 /* some more c code */ 
3775 \newline 
3776 clabel:\SpecialChar ~
3777 \SpecialChar ~
3778 /* inline assembler cannot reference this label */ 
3779 \newline 
3780 \SpecialChar ~
3781 \SpecialChar ~
3782 \SpecialChar ~
3783 \SpecialChar ~
3784 _asm
3785 \newline 
3786 \SpecialChar ~
3787 \SpecialChar ~
3788 \SpecialChar ~
3789 \SpecialChar ~
3790 $0003: ;label (can be reference by inline assembler only) 
3791 \newline 
3792 \SpecialChar ~
3793 \SpecialChar ~
3794 \SpecialChar ~
3795 \SpecialChar ~
3796 _endasm ; 
3797 \newline 
3798 \SpecialChar ~
3799 \SpecialChar ~
3800 \SpecialChar ~
3801 \SpecialChar ~
3802 /* some more c code */
3803 \newline 
3804 }
3805 \newline 
3806
3807 \newline 
3808
3809 \family default 
3810 In other words inline assembly code can access labels defined in inline
3811  assembly within the scope of the funtion.
3812  
3813 \layout Standard
3814
3815 The same goes the other way, ie.
3816  labels defines in inline assembly CANNOT be accessed by C statements.
3817 \layout Subsection
3818
3819 int(16 bit) and long (32 bit) Support
3820 \layout Standard
3821
3822 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
3823  multiplication and modulus operations are implemented by support routines.
3824  These support routines are all developed in ANSI-C to facilitate porting
3825  to other MCUs, although some model specific assembler optimations are used.
3826  The following files contain the described routine, all of them can be found
3827  in <installdir>/share/sdcc/lib.
3828 \newline 
3829
3830 \newline 
3831
3832 \emph on 
3833 <pending: tabularise this>
3834 \emph default 
3835
3836 \newline 
3837
3838 \newline 
3839 _mulsint.c - signed 16 bit multiplication (calls _muluint)
3840 \newline 
3841 _muluint.c - unsigned 16 bit multiplication
3842 \newline 
3843 _divsint.c - signed 16 bit division (calls _divuint)
3844 \newline 
3845 _divuint.c - unsigned 16 bit division
3846 \newline 
3847 _modsint.c - signed 16 bit modulus (call _moduint)
3848 \newline 
3849 _moduint.c - unsigned 16 bit modulus
3850 \newline 
3851 _mulslong.c - signed 32 bit multiplication (calls _mululong)
3852 \newline 
3853 _mululong.c - unsigned32 bit multiplication
3854 \newline 
3855 _divslong.c - signed 32 division (calls _divulong)
3856 \newline 
3857 _divulong.c - unsigned 32 division
3858 \newline 
3859 _modslong.c - signed 32 bit modulus (calls _modulong)
3860 \newline 
3861 _modulong.c - unsigned 32 bit modulus 
3862 \size footnotesize 
3863
3864 \newline 
3865
3866 \newline 
3867
3868 \size default 
3869 Since they are compiled as 
3870 \emph on 
3871 non-reentrant
3872 \emph default 
3873 , interrupt service routines should not do any of the above operations.
3874  If this is unavoidable then the above routines will need to be compiled
3875  with the 
3876 \emph on 
3877 ---stack-auto
3878 \emph default 
3879  option, after which the source program will have to be compiled with 
3880 \emph on 
3881 ---int-long-rent
3882 \emph default 
3883  option.
3884 \layout Subsection
3885
3886 Floating Point Support
3887 \layout Standard
3888
3889 SDCC supports IEEE (single precision 4bytes) floating point numbers.The floating
3890  point support routines are derived from gcc's floatlib.c and consists of
3891  the following routines:
3892 \newline 
3893
3894 \newline 
3895
3896 \emph on 
3897 <pending: tabularise this>
3898 \emph default 
3899
3900 \newline 
3901
3902 \newline 
3903 _fsadd.c - add floating point numbers
3904 \newline 
3905 _fssub.c - subtract floating point numbers
3906 \newline 
3907 _fsdiv.c - divide floating point numbers
3908 \newline 
3909 _fsmul.c - multiply floating point numbers
3910 \newline 
3911 _fs2uchar.c - convert floating point to unsigned char
3912 \newline 
3913 _fs2char.c - convert floating point to signed char
3914 \newline 
3915 _fs2uint.c - convert floating point to unsigned int
3916 \newline 
3917 _fs2int.c - convert floating point to signed int
3918 \newline 
3919 _fs2ulong.c - convert floating point to unsigned long
3920 \newline 
3921 _fs2long.c - convert floating point to signed long
3922 \newline 
3923 _uchar2fs.c - convert unsigned char to floating point
3924 \newline 
3925 _char2fs.c - convert char to floating point number
3926 \newline 
3927 _uint2fs.c - convert unsigned int to floating point
3928 \newline 
3929 _int2fs.c - convert int to floating point numbers
3930 \newline 
3931 _ulong2fs.c - convert unsigned long to floating point number
3932 \newline 
3933 _long2fs.c - convert long to floating point number
3934 \size footnotesize 
3935
3936 \newline 
3937
3938 \newline 
3939
3940 \size default 
3941 Note if all these routines are used simultaneously the data space might
3942  overflow.
3943  For serious floating point usage it is strongly recommended that the large
3944  model be used.
3945 \layout Subsection
3946
3947 MCS51 Memory Models
3948 \layout Standard
3949
3950 SDCC allows two memory models for MCS51 code, small and large.
3951  Modules compiled with different memory models should 
3952 \emph on 
3953 never
3954 \emph default 
3955  be combined together or the results would be unpredictable.
3956  The library routines supplied with the compiler are compiled as both small
3957  and large.
3958  The compiled library modules are contained in seperate directories as small
3959  and large so that you can link to either set.
3960  
3961 \layout Standard
3962
3963 When the large model is used all variables declared without a storage class
3964  will be allocated into the external ram, this includes all parameters and
3965  local variables (for non-reentrant functions).
3966  When the small model is used variables without storage class are allocated
3967  in the internal ram.
3968 \layout Standard
3969
3970 Judicious usage of the processor specific storage classes and the 'reentrant'
3971  function type will yield much more efficient code, than using the large
3972  model.
3973  Several optimizations are disabled when the program is compiled using the
3974  large model, it is therefore strongly recommdended that the small model
3975  be used unless absolutely required.
3976 \layout Subsection
3977
3978 DS390 Memory Models
3979 \layout Standard
3980
3981 The only model supported is Flat 24.
3982  This generates code for the 24 bit contiguous addressing mode of the Dallas
3983  DS80C390 part.
3984  In this mode, up to four meg of external RAM or code space can be directly
3985  addressed.
3986  See the data sheets at www.dalsemi.com for further information on this part.
3987 \newline 
3988
3989 \newline 
3990 In older versions of the compiler, this option was used with the MCS51 code
3991  generator (
3992 \emph on 
3993 -mmcs51
3994 \emph default 
3995 ).
3996  Now, however, the '390 has it's own code generator, selected by the 
3997 \emph on 
3998 -mds390
3999 \emph default 
4000  switch.
4001  
4002 \newline 
4003
4004 \newline 
4005 Note that the compiler does not generate any code to place the processor
4006  into 24 bitmode (although 
4007 \emph on 
4008 tinibios
4009 \emph default 
4010  in the ds390 libraries will do that for you).
4011  If you don't use 
4012 \emph on 
4013 tinibios
4014 \emph default 
4015 , the boot loader or similar code must ensure that the processor is in 24
4016  bit contiguous addressing mode before calling the SDCC startup code.
4017 \newline 
4018
4019 \newline 
4020 Like the 
4021 \emph on 
4022 ---model-large
4023 \emph default 
4024  option, variables will by default be placed into the XDATA segment.
4025  
4026 \newline 
4027
4028 \newline 
4029 Segments may be placed anywhere in the 4 meg address space using the usual
4030  ---*-loc options.
4031  Note that if any segments are located above 64K, the -r flag must be passed
4032  to the linker to generate the proper segment relocations, and the Intel
4033  HEX output format must be used.
4034  The -r flag can be passed to the linker by using the option 
4035 \emph on 
4036 -Wl-r
4037 \emph default 
4038  on the sdcc command line.
4039  However, currently the linker can not handle code segments > 64k.
4040 \layout Subsection
4041
4042 Defines Created by the Compiler
4043 \layout Standard
4044
4045 The compiler creates the following #defines.
4046 \layout Itemize
4047
4048 SDCC - this Symbol is always defined.
4049 \layout Itemize
4050
4051 SDCC_mcs51 or SDCC_ds390 or SDCC_z80, etc - depending on the model used
4052  (e.g.: -mds390)
4053 \layout Itemize
4054
4055 __mcs51 or __ds390 or __z80, etc - depending on the model used (e.g.
4056  -mz80)
4057 \layout Itemize
4058
4059 SDCC_STACK_AUTO - this symbol is defined when 
4060 \emph on 
4061 ---stack-auto
4062 \emph default 
4063  option is used.
4064 \layout Itemize
4065
4066 SDCC_MODEL_SMALL - when 
4067 \emph on 
4068 ---model-small
4069 \emph default 
4070  is used.
4071 \layout Itemize
4072
4073 SDCC_MODEL_LARGE - when 
4074 \emph on 
4075 ---model-large
4076 \emph default 
4077  is used.
4078 \layout Itemize
4079
4080 SDCC_USE_XSTACK - when 
4081 \emph on 
4082 ---xstack
4083 \emph default 
4084  option is used.
4085 \layout Itemize
4086
4087 SDCC_STACK_TENBIT - when 
4088 \emph on 
4089 -mds390
4090 \emph default 
4091  is used
4092 \layout Itemize
4093
4094 SDCC_MODEL_FLAT24 - when 
4095 \emph on 
4096 -mds390
4097 \emph default 
4098  is used
4099 \layout Section
4100
4101 SDCC Technical Data
4102 \layout Subsection
4103
4104 Optimizations
4105 \layout Standard
4106
4107 SDCC performs a host of standard optimizations in addition to some MCU specific
4108  optimizations.
4109  
4110 \layout Subsubsection
4111
4112 Sub-expression Elimination
4113 \layout Standard
4114
4115 The compiler does local and global common subexpression elimination, e.g.:
4116  
4117 \newline 
4118
4119 \newline 
4120
4121 \family typewriter 
4122 i = x + y + 1; 
4123 \newline 
4124 j = x + y;
4125 \family default 
4126
4127 \newline 
4128
4129 \newline 
4130 will be translated to
4131 \newline 
4132
4133 \newline 
4134
4135 \family typewriter 
4136 iTemp = x + y 
4137 \newline 
4138 i = iTemp + 1 
4139 \newline 
4140 j = iTemp
4141 \newline 
4142
4143 \family default 
4144
4145 \newline 
4146 Some subexpressions are not as obvious as the above example, e.g.:
4147 \newline 
4148
4149 \newline 
4150
4151 \family typewriter 
4152 a->b[i].c = 10; 
4153 \newline 
4154 a->b[i].d = 11;
4155 \family default 
4156
4157 \newline 
4158
4159 \newline 
4160 In this case the address arithmetic a->b[i] will be computed only once;
4161  the equivalent code in C would be.
4162 \newline 
4163
4164 \newline 
4165
4166 \family typewriter 
4167 iTemp = a->b[i]; 
4168 \newline 
4169 iTemp.c = 10; 
4170 \newline 
4171 iTemp.d = 11;
4172 \family default 
4173
4174 \newline 
4175
4176 \newline 
4177 The compiler will try to keep these temporary variables in registers.
4178 \layout Subsubsection
4179
4180 Dead-Code Elimination
4181 \layout Standard
4182
4183
4184 \family typewriter 
4185 int global; 
4186 \newline 
4187 void f () { 
4188 \newline 
4189 \SpecialChar ~
4190 \SpecialChar ~
4191 int i; 
4192 \newline 
4193 \SpecialChar ~
4194 \SpecialChar ~
4195 i = 1; \SpecialChar ~
4196 /* dead store */ 
4197 \newline 
4198 \SpecialChar ~
4199 \SpecialChar ~
4200 global = 1;\SpecialChar ~
4201 /* dead store */ 
4202 \newline 
4203 \SpecialChar ~
4204 \SpecialChar ~
4205 global = 2; 
4206 \newline 
4207 \SpecialChar ~
4208 \SpecialChar ~
4209 return; 
4210 \newline 
4211 \SpecialChar ~
4212 \SpecialChar ~
4213 global = 3;\SpecialChar ~
4214 /* unreachable */ 
4215 \newline 
4216 }
4217 \family default 
4218
4219 \newline 
4220
4221 \newline 
4222 will be changed to
4223 \newline 
4224
4225 \newline 
4226
4227 \family typewriter 
4228 int global; void f () 
4229 \newline 
4230 {
4231 \newline 
4232 \SpecialChar ~
4233 \SpecialChar ~
4234 global = 2; 
4235 \newline 
4236 \SpecialChar ~
4237 \SpecialChar ~
4238 return; 
4239 \newline 
4240 }
4241 \layout Subsubsection
4242
4243 Copy-Propagation
4244 \layout Standard
4245
4246
4247 \family typewriter 
4248 int f() { 
4249 \newline 
4250 \SpecialChar ~
4251 \SpecialChar ~
4252 int i, j; 
4253 \newline 
4254 \SpecialChar ~
4255 \SpecialChar ~
4256 i = 10; 
4257 \newline 
4258 \SpecialChar ~
4259 \SpecialChar ~
4260 j = i; 
4261 \newline 
4262 \SpecialChar ~
4263 \SpecialChar ~
4264 return j; 
4265 \newline 
4266 }
4267 \family default 
4268
4269 \newline 
4270
4271 \newline 
4272 will be changed to 
4273 \newline 
4274
4275 \newline 
4276
4277 \family typewriter 
4278 int f() { 
4279 \newline 
4280 \SpecialChar ~
4281  \SpecialChar ~
4282  int i,j; 
4283 \newline 
4284 \SpecialChar ~
4285  \SpecialChar ~
4286  i = 10; 
4287 \newline 
4288 \SpecialChar ~
4289  \SpecialChar ~
4290  j = 10; 
4291 \newline 
4292 \SpecialChar ~
4293  \SpecialChar ~
4294  return 10; 
4295 \newline 
4296 }
4297 \newline 
4298
4299 \newline 
4300
4301 \family default 
4302 Note: the dead stores created by this copy propagation will be eliminated
4303  by dead-code elimination.
4304 \layout Subsubsection
4305
4306 Loop Optimizations
4307 \layout Standard
4308
4309 Two types of loop optimizations are done by SDCC loop invariant lifting
4310  and strength reduction of loop induction variables.
4311  In addition to the strength reduction the optimizer marks the induction
4312  variables and the register allocator tries to keep the induction variables
4313  in registers for the duration of the loop.
4314  Because of this preference of the register allocator, loop induction optimizati
4315 on causes an increase in register pressure, which may cause unwanted spilling
4316  of other temporary variables into the stack / data space.
4317  The compiler will generate a warning message when it is forced to allocate
4318  extra space either on the stack or data space.
4319  If this extra space allocation is undesirable then induction optimization
4320  can be eliminated either for the entire source file (with ---noinduction
4321  option) or for a given function only using #pragma\SpecialChar ~
4322 NOINDUCTION.
4323 \newline 
4324
4325 \newline 
4326 Loop Invariant:
4327 \newline 
4328
4329 \newline 
4330
4331 \family typewriter 
4332 for (i = 0 ; i < 100 ; i ++) 
4333 \newline 
4334  \SpecialChar ~
4335  \SpecialChar ~
4336 f += k + l;
4337 \family default 
4338
4339 \newline 
4340
4341 \newline 
4342 changed to
4343 \newline 
4344
4345 \newline 
4346
4347 \family typewriter 
4348 itemp = k + l; 
4349 \newline 
4350 for (i = 0; i < 100; i++) 
4351 \newline 
4352 \SpecialChar ~
4353 \SpecialChar ~
4354 f += itemp;
4355 \family default 
4356
4357 \newline 
4358
4359 \newline 
4360 As mentioned previously some loop invariants are not as apparent, all static
4361  address computations are also moved out of the loop.
4362 \newline 
4363
4364 \newline 
4365 Strength Reduction, this optimization substitutes an expression by a cheaper
4366  expression:
4367 \newline 
4368
4369 \newline 
4370
4371 \family typewriter 
4372 for (i=0;i < 100; i++)
4373 \newline 
4374 \SpecialChar ~
4375 \SpecialChar ~
4376 ar[i*5] = i*3;
4377 \family default 
4378
4379 \newline 
4380
4381 \newline 
4382 changed to
4383 \newline 
4384
4385 \newline 
4386
4387 \family typewriter 
4388 itemp1 = 0; 
4389 \newline 
4390 itemp2 = 0; 
4391 \newline 
4392 for (i=0;i< 100;i++) { 
4393 \newline 
4394  \SpecialChar ~
4395  \SpecialChar ~
4396 ar[itemp1] = itemp2; 
4397 \newline 
4398  \SpecialChar ~
4399  \SpecialChar ~
4400 itemp1 += 5; 
4401 \newline 
4402  \SpecialChar ~
4403  \SpecialChar ~
4404 itemp2 += 3; 
4405 \newline 
4406 }
4407 \family default 
4408
4409 \newline 
4410
4411 \newline 
4412 The more expensive multiplication is changed to a less expensive addition.
4413 \layout Subsubsection
4414
4415 Loop Reversing
4416 \layout Standard
4417
4418 This optimization is done to reduce the overhead of checking loop boundaries
4419  for every iteration.
4420  Some simple loops can be reversed and implemented using a 
4421 \begin_inset Quotes eld
4422 \end_inset 
4423
4424 decrement and jump if not zero
4425 \begin_inset Quotes erd
4426 \end_inset 
4427
4428  instruction.
4429  SDCC checks for the following criterion to determine if a loop is reversible
4430  (note: more sophisticated compilers use data-dependency analysis to make
4431  this determination, SDCC uses a more simple minded analysis).
4432 \layout Itemize
4433
4434 The 'for' loop is of the form 
4435 \newline 
4436
4437 \newline 
4438
4439 \family typewriter 
4440 for (<symbol> = <expression> ; <sym> [< | <=] <expression> ; [<sym>++ |
4441  <sym> += 1])
4442 \newline 
4443 \SpecialChar ~
4444 \SpecialChar ~
4445 \SpecialChar ~
4446 \SpecialChar ~
4447 <for body>
4448 \layout Itemize
4449
4450 The <for body> does not contain 
4451 \begin_inset Quotes eld
4452 \end_inset 
4453
4454 continue
4455 \begin_inset Quotes erd
4456 \end_inset 
4457
4458  or 'break
4459 \begin_inset Quotes erd
4460 \end_inset 
4461
4462 .
4463 \layout Itemize
4464
4465 All goto's are contained within the loop.
4466 \layout Itemize
4467
4468 No function calls within the loop.
4469 \layout Itemize
4470
4471 The loop control variable <sym> is not assigned any value within the loop
4472 \layout Itemize
4473
4474 The loop control variable does NOT participate in any arithmetic operation
4475  within the loop.
4476 \layout Itemize
4477
4478 There are NO switch statements in the loop.
4479 \layout Subsubsection
4480
4481 Algebraic Simplifications
4482 \layout Standard
4483
4484 SDCC does numerous algebraic simplifications, the following is a small sub-set
4485  of these optimizations.
4486 \newline 
4487
4488 \newline 
4489
4490 \family typewriter 
4491 i = j + 0 ; /* changed to */ i = j; 
4492 \newline 
4493 i /= 2; /* changed to */ i >>= 1; 
4494 \newline 
4495 i = j - j ; /* changed to */ i = 0; 
4496 \newline 
4497 i = j / 1 ; /* changed to */ i = j;
4498 \family default 
4499
4500 \newline 
4501
4502 \newline 
4503 Note the subexpressions given above are generally introduced by macro expansions
4504  or as a result of copy/constant propagation.
4505 \layout Subsubsection
4506
4507 'switch' Statements
4508 \layout Standard
4509
4510 SDCC changes switch statements to jump tables when the following conditions
4511  are true.
4512  
4513 \layout Itemize
4514
4515 The case labels are in numerical sequence, the labels need not be in order,
4516  and the starting number need not be one or zero.
4517 \newline 
4518
4519 \newline 
4520
4521 \family typewriter 
4522 switch(i) {\SpecialChar ~
4523  \SpecialChar ~
4524  \SpecialChar ~
4525  \SpecialChar ~
4526  \SpecialChar ~
4527  \SpecialChar ~
4528  \SpecialChar ~
4529  \SpecialChar ~
4530  \SpecialChar ~
4531  \SpecialChar ~
4532  \SpecialChar ~
4533  \SpecialChar ~
4534  \SpecialChar ~
4535 switch (i) { 
4536 \newline 
4537 case 4:...
4538  \SpecialChar ~
4539  \SpecialChar ~
4540  \SpecialChar ~
4541  \SpecialChar ~
4542  \SpecialChar ~
4543  \SpecialChar ~
4544  \SpecialChar ~
4545  \SpecialChar ~
4546  \SpecialChar ~
4547  \SpecialChar ~
4548  \SpecialChar ~
4549  \SpecialChar ~
4550  \SpecialChar ~
4551 case 1: ...
4552  
4553 \newline 
4554 case 5:...
4555  \SpecialChar ~
4556  \SpecialChar ~
4557  \SpecialChar ~
4558  \SpecialChar ~
4559  \SpecialChar ~
4560  \SpecialChar ~
4561  \SpecialChar ~
4562  \SpecialChar ~
4563  \SpecialChar ~
4564  \SpecialChar ~
4565  \SpecialChar ~
4566  \SpecialChar ~
4567  \SpecialChar ~
4568 case 2: ...
4569  
4570 \newline 
4571 case 3:...
4572  \SpecialChar ~
4573  \SpecialChar ~
4574  \SpecialChar ~
4575  \SpecialChar ~
4576  \SpecialChar ~
4577  \SpecialChar ~
4578  \SpecialChar ~
4579  \SpecialChar ~
4580  \SpecialChar ~
4581  \SpecialChar ~
4582  \SpecialChar ~
4583  \SpecialChar ~
4584  \SpecialChar ~
4585 case 3: ...
4586  
4587 \newline 
4588 case 6:...
4589  \SpecialChar ~
4590  \SpecialChar ~
4591  \SpecialChar ~
4592  \SpecialChar ~
4593  \SpecialChar ~
4594  \SpecialChar ~
4595  \SpecialChar ~
4596  \SpecialChar ~
4597  \SpecialChar ~
4598  \SpecialChar ~
4599  \SpecialChar ~
4600  \SpecialChar ~
4601  \SpecialChar ~
4602 case 4: ...
4603  
4604 \newline 
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  \SpecialChar ~
4620  \SpecialChar ~
4621  \SpecialChar ~
4622  \SpecialChar ~
4623 }
4624 \newline 
4625
4626 \newline 
4627
4628 \family default 
4629 Both the above switch statements will be implemented using a jump-table.
4630 \layout Itemize
4631
4632 The number of case labels is at least three, since it takes two conditional
4633  statements to handle the boundary conditions.
4634 \layout Itemize
4635
4636 The number of case labels is less than 84, since each label takes 3 bytes
4637  and a jump-table can be utmost 256 bytes long.
4638  
4639 \layout Standard
4640
4641 Switch statements which have gaps in the numeric sequence or those that
4642  have more that 84 case labels can be split into more than one switch statement
4643  for efficient code generation, e.g.:
4644 \newline 
4645
4646 \newline 
4647
4648 \family typewriter 
4649 switch (i) { 
4650 \newline 
4651 case 1: ...
4652  
4653 \newline 
4654 case 2: ...
4655  
4656 \newline 
4657 case 3: ...
4658  
4659 \newline 
4660 case 4: ...
4661  
4662 \newline 
4663 case 9: ...
4664  
4665 \newline 
4666 case 10: ...
4667  
4668 \newline 
4669 case 11: ...
4670  
4671 \newline 
4672 case 12: ...
4673  
4674 \newline 
4675 }
4676 \family default 
4677
4678 \newline 
4679
4680 \newline 
4681 If the above switch statement is broken down into two switch statements
4682 \newline 
4683
4684 \newline 
4685
4686 \family typewriter 
4687 switch (i) { 
4688 \newline 
4689 case 1: ...
4690  
4691 \newline 
4692 case 2: ...
4693  
4694 \newline 
4695 case 3: ...
4696  
4697 \newline 
4698 case 4: ...
4699  
4700 \newline 
4701 }
4702 \newline 
4703
4704 \newline 
4705
4706 \family default 
4707 and
4708 \family typewriter 
4709
4710 \newline 
4711
4712 \newline 
4713 switch (i) { 
4714 \newline 
4715 case 9: \SpecialChar ~
4716 ...
4717  
4718 \newline 
4719 case 10: ...
4720  
4721 \newline 
4722 case 11: ...
4723  
4724 \newline 
4725 case 12:\SpecialChar ~
4726 ...
4727  
4728 \newline 
4729 }
4730 \newline 
4731
4732 \newline 
4733
4734 \family default 
4735 then both the switch statements will be implemented using jump-tables whereas
4736  the unmodified switch statement will not be.
4737 \layout Subsubsection
4738
4739 Bit-shifting Operations.
4740 \layout Standard
4741
4742 Bit shifting is one of the most frequently used operation in embedded programmin
4743 g.
4744  SDCC tries to implement bit-shift operations in the most efficient way
4745  possible, e.g.:
4746 \newline 
4747
4748 \family typewriter 
4749
4750 \newline 
4751 unsigned char i;
4752 \newline 
4753 ...
4754  
4755 \newline 
4756 i>>= 4; 
4757 \newline 
4758 ...
4759 \newline 
4760
4761 \family default 
4762
4763 \newline 
4764 generates the following code:
4765 \newline 
4766
4767 \family typewriter 
4768
4769 \newline 
4770 mov a,_i 
4771 \newline 
4772 swap a 
4773 \newline 
4774 anl a,#0x0f 
4775 \newline 
4776 mov _i,a
4777 \family default 
4778
4779 \newline 
4780
4781 \newline 
4782 In general SDCC will never setup a loop if the shift count is known.
4783  Another example:
4784 \newline 
4785
4786 \newline 
4787
4788 \family typewriter 
4789 unsigned int i; 
4790 \newline 
4791 ...
4792  
4793 \newline 
4794 i >>= 9; 
4795 \newline 
4796 ...
4797 \family default 
4798
4799 \newline 
4800
4801 \newline 
4802 will generate:
4803 \newline 
4804
4805 \newline 
4806
4807 \family typewriter 
4808 mov a,(_i + 1) 
4809 \newline 
4810 mov (_i + 1),#0x00 
4811 \newline 
4812 clr c 
4813 \newline 
4814 rrc a 
4815 \newline 
4816 mov _i,a
4817 \family default 
4818
4819 \newline 
4820
4821 \newline 
4822 Note that SDCC stores numbers in little-endian format (i.e.
4823  lowest order first).
4824 \layout Subsubsection
4825
4826 Bit-rotation
4827 \layout Standard
4828
4829 A special case of the bit-shift operation is bit rotation, SDCC recognizes
4830  the following expression to be a left bit-rotation:
4831 \newline 
4832
4833 \newline 
4834
4835 \family typewriter 
4836 unsigned char i; 
4837 \newline 
4838 ...
4839  
4840 \newline 
4841 i = ((i << 1) | (i >> 7)); 
4842 \family default 
4843
4844 \newline 
4845 ...
4846 \newline 
4847
4848 \newline 
4849 will generate the following code:
4850 \newline 
4851
4852 \newline 
4853
4854 \family typewriter 
4855 mov a,_i 
4856 \newline 
4857 rl a 
4858 \newline 
4859 mov _i,a
4860 \family default 
4861
4862 \newline 
4863
4864 \newline 
4865 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
4866 ns of this case will also be recognized as bit-rotation, i.e.: 
4867 \newline 
4868
4869 \newline 
4870
4871 \family typewriter 
4872 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
4873 \layout Subsubsection
4874
4875 Highest Order Bit
4876 \layout Standard
4877
4878 It is frequently required to obtain the highest order bit of an integral
4879  type (long, int, short or char types).
4880  SDCC recognizes the following expression to yield the highest order bit
4881  and generates optimized code for it, e.g.:
4882 \newline 
4883
4884 \newline 
4885  
4886 \family typewriter 
4887 unsigned int gint; 
4888 \newline 
4889
4890 \newline 
4891 foo () { 
4892 \newline 
4893 unsigned char hob; 
4894 \newline 
4895 \SpecialChar ~
4896 \SpecialChar ~
4897 ...
4898  
4899 \newline 
4900 \SpecialChar ~
4901 \SpecialChar ~
4902 hob = (gint >> 15) & 1; 
4903 \newline 
4904 \SpecialChar ~
4905 \SpecialChar ~
4906 ..
4907  
4908 \newline 
4909 }
4910 \family default 
4911
4912 \newline 
4913
4914 \newline 
4915 will generate the following code:
4916 \newline 
4917
4918 \family typewriter 
4919
4920 \newline 
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 \SpecialChar ~
4946 \SpecialChar ~
4947 \SpecialChar ~
4948 \SpecialChar ~
4949  61 ;\SpecialChar ~
4950  hob.c 7 
4951 \newline 
4952 \SpecialChar ~
4953 \SpecialChar ~
4954  000A E5*01\SpecialChar ~
4955 \SpecialChar ~
4956 \SpecialChar ~
4957 \SpecialChar ~
4958 \SpecialChar ~
4959 \SpecialChar ~
4960 \SpecialChar ~
4961 \SpecialChar ~
4962 \SpecialChar ~
4963 \SpecialChar ~
4964 \SpecialChar ~
4965 \SpecialChar ~
4966 \SpecialChar ~
4967 \SpecialChar ~
4968 \SpecialChar ~
4969  62\SpecialChar ~
4970 \SpecialChar ~
4971 \SpecialChar ~
4972 \SpecialChar ~
4973 \SpecialChar ~
4974 \SpecialChar ~
4975 \SpecialChar ~
4976 \SpecialChar ~
4977  mov\SpecialChar ~
4978  a,(_gint + 1) 
4979 \newline 
4980 \SpecialChar ~
4981 \SpecialChar ~
4982  000C 33\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 \SpecialChar ~
4997 \SpecialChar ~
4998 \SpecialChar ~
4999 \SpecialChar ~
5000  63\SpecialChar ~
5001 \SpecialChar ~
5002 \SpecialChar ~
5003 \SpecialChar ~
5004 \SpecialChar ~
5005 \SpecialChar ~
5006 \SpecialChar ~
5007 \SpecialChar ~
5008  rlc\SpecialChar ~
5009  a 
5010 \newline 
5011 \SpecialChar ~
5012 \SpecialChar ~
5013  000D E4\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 \SpecialChar ~
5028 \SpecialChar ~
5029 \SpecialChar ~
5030 \SpecialChar ~
5031  64\SpecialChar ~
5032 \SpecialChar ~
5033 \SpecialChar ~
5034 \SpecialChar ~
5035 \SpecialChar ~
5036 \SpecialChar ~
5037 \SpecialChar ~
5038 \SpecialChar ~
5039  clr\SpecialChar ~
5040  a 
5041 \newline 
5042 \SpecialChar ~
5043 \SpecialChar ~
5044  000E 13\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 \SpecialChar ~
5059 \SpecialChar ~
5060 \SpecialChar ~
5061 \SpecialChar ~
5062  65\SpecialChar ~
5063 \SpecialChar ~
5064 \SpecialChar ~
5065 \SpecialChar ~
5066 \SpecialChar ~
5067 \SpecialChar ~
5068 \SpecialChar ~
5069 \SpecialChar ~
5070  rrc\SpecialChar ~
5071  a 
5072 \newline 
5073 \SpecialChar ~
5074 \SpecialChar ~
5075  000F F5*02\SpecialChar ~
5076 \SpecialChar ~
5077 \SpecialChar ~
5078 \SpecialChar ~
5079 \SpecialChar ~
5080 \SpecialChar ~
5081 \SpecialChar ~
5082 \SpecialChar ~
5083 \SpecialChar ~
5084 \SpecialChar ~
5085 \SpecialChar ~
5086 \SpecialChar ~
5087 \SpecialChar ~
5088 \SpecialChar ~
5089 \SpecialChar ~
5090  66\SpecialChar ~
5091 \SpecialChar ~
5092 \SpecialChar ~
5093 \SpecialChar ~
5094 \SpecialChar ~
5095 \SpecialChar ~
5096 \SpecialChar ~
5097 \SpecialChar ~
5098  mov\SpecialChar ~
5099  _foo_hob_1_1,a
5100 \newline 
5101
5102 \newline 
5103
5104 \family default 
5105 Variations of this case however will 
5106 \emph on 
5107 not
5108 \emph default 
5109  be recognized.
5110  It is a standard C expression, so I heartily recommend this be the only
5111  way to get the highest order bit, (it is portable).
5112  Of course it will be recognized even if it is embedded in other expressions,
5113  e.g.:
5114 \newline 
5115
5116 \newline 
5117
5118 \family typewriter 
5119 xyz = gint + ((gint >> 15) & 1);
5120 \family default 
5121
5122 \newline 
5123
5124 \newline 
5125 will still be recognized.
5126 \layout Subsubsection
5127
5128 Peep-hole Optimizer
5129 \layout Standard
5130
5131 The compiler uses a rule based, pattern matching and re-writing mechanism
5132  for peep-hole optimization.
5133  It is inspired by 
5134 \emph on 
5135 copt
5136 \emph default 
5137  a peep-hole optimizer by Christopher W.
5138  Fraser (cwfraser@microsoft.com).
5139  A default set of rules are compiled into the compiler, additional rules
5140  may be added with the 
5141 \emph on 
5142 ---peep-file <filename>
5143 \emph default 
5144  option.
5145  The rule language is best illustrated with examples.
5146 \newline 
5147
5148 \newline 
5149
5150 \family typewriter 
5151 replace { 
5152 \newline 
5153 \SpecialChar ~
5154 \SpecialChar ~
5155 mov %1,a 
5156 \newline 
5157 \SpecialChar ~
5158 \SpecialChar ~
5159 mov a,%1
5160 \newline 
5161 } by {
5162 \newline 
5163 \SpecialChar ~
5164 \SpecialChar ~
5165 mov %1,a
5166 \newline 
5167 }
5168 \family default 
5169
5170 \newline 
5171
5172 \newline 
5173 The above rule will change the following assembly sequence:
5174 \newline 
5175
5176 \newline 
5177
5178 \family typewriter 
5179 \SpecialChar ~
5180 \SpecialChar ~
5181 mov r1,a 
5182 \newline 
5183 \SpecialChar ~
5184 \SpecialChar ~
5185 mov a,r1
5186 \family default 
5187
5188 \newline 
5189
5190 \newline 
5191 to
5192 \newline 
5193
5194 \newline 
5195
5196 \family typewriter 
5197 mov r1,a
5198 \family default 
5199
5200 \newline 
5201
5202 \newline 
5203 Note: All occurrences of a 
5204 \emph on 
5205 %n
5206 \emph default 
5207  (pattern variable) must denote the same string.
5208  With the above rule, the assembly sequence:
5209 \newline 
5210
5211 \newline 
5212
5213 \family typewriter 
5214 \SpecialChar ~
5215 \SpecialChar ~
5216 mov r1,a 
5217 \newline 
5218 \SpecialChar ~
5219 \SpecialChar ~
5220 mov a,r2
5221 \family default 
5222
5223 \newline 
5224
5225 \newline 
5226 will remain unmodified.
5227 \newline 
5228
5229 \newline 
5230 Other special case optimizations may be added by the user (via 
5231 \emph on 
5232 ---peep-file option
5233 \emph default 
5234 ).
5235  E.g.
5236  some variants of the 8051 MCU allow only 
5237 \family typewriter 
5238 ajmp
5239 \family default 
5240  and 
5241 \family typewriter 
5242 acall
5243 \family default 
5244 .
5245  The following two rules will change all 
5246 \family typewriter 
5247 ljmp
5248 \family default 
5249  and 
5250 \family typewriter 
5251 lcall
5252 \family default 
5253  to 
5254 \family typewriter 
5255 ajmp
5256 \family default 
5257  and 
5258 \family typewriter 
5259 acall
5260 \family default 
5261
5262 \newline 
5263
5264 \newline 
5265
5266 \family typewriter 
5267 replace { lcall %1 } by { acall %1 } 
5268 \newline 
5269 replace { ljmp %1 } by { ajmp %1 }
5270 \family default 
5271
5272 \newline 
5273
5274 \newline 
5275 The 
5276 \emph on 
5277 inline-assembler code
5278 \emph default 
5279  is also passed through the peep hole optimizer, thus the peephole optimizer
5280  can also be used as an assembly level macro expander.
5281  The rules themselves are MCU dependent whereas the rule language infra-structur
5282 e is MCU independent.
5283  Peephole optimization rules for other MCU can be easily programmed using
5284  the rule language.
5285 \newline 
5286
5287 \newline 
5288 The syntax for a rule is as follows:
5289 \newline 
5290
5291 \newline 
5292
5293 \family typewriter 
5294 rule := replace [ restart ] '{' <assembly sequence> '
5295 \backslash 
5296 n' 
5297 \newline 
5298 \SpecialChar ~
5299  \SpecialChar ~
5300  \SpecialChar ~
5301  \SpecialChar ~
5302  \SpecialChar ~
5303  \SpecialChar ~
5304  \SpecialChar ~
5305  \SpecialChar ~
5306  \SpecialChar ~
5307  \SpecialChar ~
5308  \SpecialChar ~
5309  \SpecialChar ~
5310  \SpecialChar ~
5311  \SpecialChar ~
5312  '}' by '{' '
5313 \backslash 
5314 n' 
5315 \newline 
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  \SpecialChar ~
5329  \SpecialChar ~
5330  \SpecialChar ~
5331  \SpecialChar ~
5332  <assembly sequence> '
5333 \backslash 
5334 n' 
5335 \newline 
5336 \SpecialChar ~
5337  \SpecialChar ~
5338  \SpecialChar ~
5339  \SpecialChar ~
5340  \SpecialChar ~
5341  \SpecialChar ~
5342  \SpecialChar ~
5343  \SpecialChar ~
5344  \SpecialChar ~
5345  \SpecialChar ~
5346  \SpecialChar ~
5347  \SpecialChar ~
5348  \SpecialChar ~
5349  \SpecialChar ~
5350  '}' [if <functionName> ] '
5351 \backslash 
5352 n' 
5353 \newline 
5354
5355 \family default 
5356
5357 \newline 
5358 <assembly sequence> := assembly instruction (each instruction including
5359  labels must be on a separate line).
5360 \newline 
5361
5362 \newline 
5363 The optimizer will apply to the rules one by one from the top in the sequence
5364  of their appearance, it will terminate when all rules are exhausted.
5365  If the 'restart' option is specified, then the optimizer will start matching
5366  the rules again from the top, this option for a rule is expensive (performance)
5367 , it is intended to be used in situations where a transformation will trigger
5368  the same rule again.
5369  An example of this (not a good one, it has side effects) is the following
5370  rule:
5371 \newline 
5372
5373 \newline 
5374
5375 \family typewriter 
5376 replace restart { 
5377 \newline 
5378 \SpecialChar ~
5379 \SpecialChar ~
5380 pop %1 
5381 \newline 
5382 \SpecialChar ~
5383 \SpecialChar ~
5384 push %1 } by { 
5385 \newline 
5386 \SpecialChar ~
5387 \SpecialChar ~
5388 ; nop 
5389 \newline 
5390 }
5391 \family default 
5392
5393 \newline 
5394
5395 \newline 
5396 Note that the replace pattern cannot be a blank, but can be a comment line.
5397  Without the 'restart' option only the inner most 'pop' 'push' pair would
5398  be eliminated, i.e.:
5399 \newline 
5400
5401 \newline 
5402
5403 \family typewriter 
5404 \SpecialChar ~
5405 \SpecialChar ~
5406 pop ar1 
5407 \newline 
5408 \SpecialChar ~
5409 \SpecialChar ~
5410 pop ar2 
5411 \newline 
5412 \SpecialChar ~
5413 \SpecialChar ~
5414 push ar2 
5415 \newline 
5416 \SpecialChar ~
5417 \SpecialChar ~
5418 push ar1
5419 \family default 
5420
5421 \newline 
5422
5423 \newline 
5424 would result in:
5425 \newline 
5426
5427 \newline 
5428
5429 \family typewriter 
5430 \SpecialChar ~
5431 \SpecialChar ~
5432 pop ar1 
5433 \newline 
5434 \SpecialChar ~
5435 \SpecialChar ~
5436 ; nop 
5437 \newline 
5438 \SpecialChar ~
5439 \SpecialChar ~
5440 push ar1
5441 \family default 
5442
5443 \newline 
5444
5445 \newline 
5446
5447 \emph on 
5448 with
5449 \emph default 
5450  the restart option the rule will be applied again to the resulting code
5451  and then all the pop-push pairs will be eliminated to yield:
5452 \newline 
5453
5454 \newline 
5455
5456 \family typewriter 
5457 \SpecialChar ~
5458 \SpecialChar ~
5459 ; nop 
5460 \newline 
5461 \SpecialChar ~
5462 \SpecialChar ~
5463 ; nop
5464 \family default 
5465
5466 \newline 
5467
5468 \newline 
5469 A conditional function can be attached to a rule.
5470  Attaching rules are somewhat more involved, let me illustrate this with
5471  an example.
5472 \newline 
5473
5474 \newline 
5475
5476 \family typewriter 
5477 replace { 
5478 \newline 
5479 \SpecialChar ~
5480  \SpecialChar ~
5481  \SpecialChar ~
5482 ljmp %5 
5483 \newline 
5484 %2:
5485 \newline 
5486 } by { 
5487 \newline 
5488 \SpecialChar ~
5489  \SpecialChar ~
5490  \SpecialChar ~
5491 sjmp %5 
5492 \newline 
5493 %2:
5494 \newline 
5495 } if labelInRange
5496 \family default 
5497
5498 \newline 
5499
5500 \newline 
5501 The optimizer does a look-up of a function name table defined in function
5502  
5503 \emph on 
5504 callFuncByName
5505 \emph default 
5506  in the source file SDCCpeeph.c, with the name 
5507 \emph on 
5508 labelInRange
5509 \emph default 
5510 .
5511  If it finds a corresponding entry the function is called.
5512  Note there can be no parameters specified for these functions, in this
5513  case the use of 
5514 \emph on 
5515 %5
5516 \emph default 
5517  is crucial, since the function 
5518 \emph on 
5519 labelInRange
5520 \emph default 
5521  expects to find the label in that particular variable (the hash table containin
5522 g the variable bindings is passed as a parameter).
5523  If you want to code more such functions, take a close look at the function
5524  labelInRange and the calling mechanism in source file SDCCpeeph.c.
5525  I know this whole thing is a little kludgey, but maybe some day we will
5526  have some better means.
5527  If you are looking at this file, you will also see the default rules that
5528  are compiled into the compiler, you can add your own rules in the default
5529  set there if you get tired of specifying the ---peep-file option.
5530 \layout Subsection
5531
5532 Pragmas
5533 \layout Standard
5534
5535 SDCC supports the following #pragma directives.
5536  This directives are applicable only at a function level.
5537 \layout Itemize
5538
5539 SAVE - this will save all the current options.
5540 \layout Itemize
5541
5542 RESTORE - will restore the saved options from the last save.
5543  Note that SAVES & RESTOREs cannot be nested.
5544  SDCC uses the same buffer to save the options each time a SAVE is called.
5545 \layout Itemize
5546
5547 NOGCSE - will stop global subexpression elimination.
5548 \layout Itemize
5549
5550 NOINDUCTION - will stop loop induction optimizations.
5551 \layout Itemize
5552
5553 NOJTBOUND - will not generate code for boundary value checking, when switch
5554  statements are turned into jump-tables.
5555 \layout Itemize
5556
5557 NOOVERLAY - the compiler will not overlay the parameters and local variables
5558  of a function.
5559 \layout Itemize
5560
5561 NOLOOPREVERSE - Will not do loop reversal optimization
5562 \layout Itemize
5563
5564 EXCLUDE NONE | {acc[,b[,dpl[,dph]]] - The exclude pragma disables generation
5565  of pair of push/pop instruction in ISR function (using interrupt keyword).
5566  The directive should be placed immediately before the ISR function definition
5567  and it affects ALL ISR functions following it.
5568  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
5569 EXCLUDE\SpecialChar ~
5570 none.
5571 \layout Itemize
5572
5573 NOIV - Do not generate interrupt vector table entries for all ISR functions
5574  defined after the pragma. This is useful in cases where the interrupt
5575  vector table must be defined manually, or when there is a secondary, manually
5576  defined interrupt vector table (e.g. for the autovector feature of the Cypress
5577  EZ-USB FX2).
5578 \layout Itemize
5579
5580 CALLEE-SAVES function1[,function2[,function3...]] - The compiler by default
5581  uses a caller saves convention for register saving across function calls,
5582  however this can cause unneccessary register pushing & popping when calling
5583  small functions from larger functions.
5584  This option can be used to switch the register saving convention for the
5585  function names specified.
5586  The compiler will not save registers when calling these functions, extra
5587  code will be generated at the entry & exit for these functions to save
5588  & restore the registers used by these functions, this can SUBSTANTIALLY
5589  reduce code & improve run time performance of the generated code.
5590  In future the compiler (with interprocedural analysis) will be able to
5591  determine the appropriate scheme to use for each function call.
5592  If ---callee-saves command line option is used, the function names specified
5593  in #pragma\SpecialChar ~
5594 CALLEE-SAVES is appended to the list of functions specified inthe
5595  command line.
5596 \layout Standard
5597
5598 The pragma's are intended to be used to turn-off certain optimizations which
5599  might cause the compiler to generate extra stack / data space to store
5600  compiler generated temporary variables.
5601  This usually happens in large functions.
5602  Pragma directives should be used as shown in the following example, they
5603  are used to control options & optimizations for a given function; pragmas
5604  should be placed before and/or after a function, placing pragma's inside
5605  a function body could have unpredictable results.
5606 \newline 
5607
5608 \newline 
5609
5610 \family typewriter 
5611 #pragma SAVE /* save the current settings */ 
5612 \newline 
5613 #pragma NOGCSE /* turnoff global subexpression elimination */ 
5614 \newline 
5615 #pragma NOINDUCTION /* turn off induction optimizations */ 
5616 \newline 
5617 int foo () 
5618 \newline 
5619
5620 \newline 
5621 \SpecialChar ~
5622  \SpecialChar ~
5623  ...
5624  
5625 \newline 
5626 \SpecialChar ~
5627  \SpecialChar ~
5628  /* large code */ 
5629 \newline 
5630 \SpecialChar ~
5631  \SpecialChar ~
5632  ...
5633  
5634 \newline 
5635
5636 \newline 
5637 #pragma RESTORE /* turn the optimizations back on */
5638 \family default 
5639
5640 \newline 
5641
5642 \newline 
5643 The compiler will generate a warning message when extra space is allocated.
5644  It is strongly recommended that the SAVE and RESTORE pragma's be used when
5645  changing options for a function.
5646 \layout Subsection
5647
5648
5649 \emph on 
5650 <pending: this is messy and incomplete>
5651 \emph default 
5652  Library Routines
5653 \layout Enumerate
5654
5655 Compiler support routines (_gptrget, _mulint etc)
5656 \layout Enumerate
5657
5658 Stdclib functions (puts, printf, strcat etc)
5659 \layout Enumerate
5660
5661 Math functions (sin, pow, sqrt etc)
5662 \layout Subsection
5663
5664 Interfacing with Assembly Routines
5665 \layout Subsubsection
5666
5667 Global Registers used for Parameter Passing
5668 \layout Standard
5669
5670 The compiler always uses the global registers 
5671 \emph on 
5672 DPL,DPH,B 
5673 \emph default 
5674 and
5675 \emph on 
5676  ACC
5677 \emph default 
5678  to pass the first parameter to a routine.
5679  The second parameter onwards is either allocated on the stack (for reentrant
5680  routines or if ---stack-auto is used) or in the internal / external ram
5681  (depending on the memory model).
5682  
5683 \layout Subsubsection
5684
5685 Assembler Routine(non-reentrant)
5686 \layout Standard
5687
5688 In the following example the function cfunc calls an assembler routine asm_func,
5689  which takes two parameters.
5690 \newline 
5691
5692 \newline 
5693
5694 \family typewriter 
5695 extern int asm_func(unsigned char, unsigned char);
5696 \newline 
5697
5698 \newline 
5699 int c_func (unsigned char i, unsigned char j)
5700 \newline 
5701 {
5702 \newline 
5703 \SpecialChar ~
5704 \SpecialChar ~
5705 \SpecialChar ~
5706 \SpecialChar ~
5707 return asm_func(i,j);
5708 \newline 
5709 }
5710 \newline 
5711
5712 \newline 
5713 int main()
5714 \newline 
5715 {
5716 \newline 
5717 \SpecialChar ~
5718 \SpecialChar ~
5719 \SpecialChar ~
5720 \SpecialChar ~
5721 return c_func(10,9);
5722 \newline 
5723 }
5724 \newline 
5725
5726 \newline 
5727
5728 \family default 
5729 The corresponding assembler function is:
5730 \newline 
5731
5732 \newline 
5733
5734 \family typewriter 
5735 .globl _asm_func_PARM_2 
5736 \newline 
5737 \SpecialChar ~
5738 \SpecialChar ~
5739 \SpecialChar ~
5740 \SpecialChar ~
5741 \SpecialChar ~
5742 \SpecialChar ~
5743 \SpecialChar ~
5744 \SpecialChar ~
5745 .globl _asm_func 
5746 \newline 
5747 \SpecialChar ~
5748 \SpecialChar ~
5749 \SpecialChar ~
5750 \SpecialChar ~
5751 \SpecialChar ~
5752 \SpecialChar ~
5753 \SpecialChar ~
5754 \SpecialChar ~
5755 .area OSEG 
5756 \newline 
5757 _asm_func_PARM_2:
5758 \newline 
5759 \SpecialChar ~
5760 \SpecialChar ~
5761 \SpecialChar ~
5762 \SpecialChar ~
5763 \SpecialChar ~
5764 \SpecialChar ~
5765 \SpecialChar ~
5766 \SpecialChar ~
5767 .ds      1 
5768 \newline 
5769 \SpecialChar ~
5770 \SpecialChar ~
5771 \SpecialChar ~
5772 \SpecialChar ~
5773 \SpecialChar ~
5774 \SpecialChar ~
5775 \SpecialChar ~
5776 \SpecialChar ~
5777 .area CSEG 
5778 \newline 
5779 _asm_func: 
5780 \newline 
5781 \SpecialChar ~
5782 \SpecialChar ~
5783 \SpecialChar ~
5784 \SpecialChar ~
5785 \SpecialChar ~
5786 \SpecialChar ~
5787 \SpecialChar ~
5788 \SpecialChar ~
5789 mov     a,dpl 
5790 \newline 
5791 \SpecialChar ~
5792 \SpecialChar ~
5793 \SpecialChar ~
5794 \SpecialChar ~
5795 \SpecialChar ~
5796 \SpecialChar ~
5797 \SpecialChar ~
5798 \SpecialChar ~
5799 add     a,_asm_func_PARM_2 
5800 \newline 
5801 \SpecialChar ~
5802 \SpecialChar ~
5803 \SpecialChar ~
5804 \SpecialChar ~
5805 \SpecialChar ~
5806 \SpecialChar ~
5807 \SpecialChar ~
5808 \SpecialChar ~
5809 mov     dpl,a 
5810 \newline 
5811 \SpecialChar ~
5812 \SpecialChar ~
5813 \SpecialChar ~
5814 \SpecialChar ~
5815 \SpecialChar ~
5816 \SpecialChar ~
5817 \SpecialChar ~
5818 \SpecialChar ~
5819 mov     dpl,#0x00 
5820 \newline 
5821 \SpecialChar ~
5822 \SpecialChar ~
5823 \SpecialChar ~
5824 \SpecialChar ~
5825 \SpecialChar ~
5826 \SpecialChar ~
5827 \SpecialChar ~
5828 \SpecialChar ~
5829 ret
5830 \newline 
5831
5832 \newline 
5833
5834 \family default 
5835 Note here that the return values are placed in 'dpl' - One byte return value,
5836  'dpl' LSB & 'dph' MSB for two byte values.
5837  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
5838 b' & 'acc' for four byte values.
5839 \layout Standard
5840
5841 The parameter naming convention is _<function_name>_PARM_<n>, where n is
5842  the parameter number starting from 1, and counting from the left.
5843  The first parameter is passed in 
5844 \begin_inset Quotes eld
5845 \end_inset 
5846
5847 dpl
5848 \begin_inset Quotes erd
5849 \end_inset 
5850
5851  for One bye parameter, 
5852 \begin_inset Quotes eld
5853 \end_inset 
5854
5855 dptr
5856 \begin_inset Quotes erd
5857 \end_inset 
5858
5859  if two bytes, 
5860 \begin_inset Quotes eld
5861 \end_inset 
5862
5863 b,dptr
5864 \begin_inset Quotes erd
5865 \end_inset 
5866
5867  for three bytes and 
5868 \begin_inset Quotes eld
5869 \end_inset 
5870
5871 acc,b,dptr
5872 \begin_inset Quotes erd
5873 \end_inset 
5874
5875  for four bytes, the varible name for the second parameter will be _<function_na
5876 me>_PARM_2.
5877 \newline 
5878
5879 \newline 
5880 Assemble the assembler routine with the following command:
5881 \newline 
5882
5883 \newline 
5884
5885 \family sans 
5886 \series bold 
5887 asx8051 -losg asmfunc.asm
5888 \newline 
5889
5890 \newline 
5891
5892 \family default 
5893 \series default 
5894 Then compile and link the assembler routine to the C source file with the
5895  following command:
5896 \newline 
5897
5898 \newline 
5899
5900 \family sans 
5901 \series bold 
5902 sdcc cfunc.c asmfunc.rel
5903 \layout Subsubsection
5904
5905 Assembler Routine(reentrant)
5906 \layout Standard
5907
5908 In this case the second parameter onwards will be passed on the stack, the
5909  parameters are pushed from right to left i.e.
5910  after the call the left most parameter will be on the top of the stack.
5911  Here is an example:
5912 \newline 
5913
5914 \newline 
5915
5916 \family typewriter 
5917 extern int asm_func(unsigned char, unsigned char);
5918 \newline 
5919
5920 \newline 
5921 int c_func (unsigned char i, unsigned char j) reentrant 
5922 \newline 
5923
5924 \newline 
5925 \SpecialChar ~
5926 \SpecialChar ~
5927 \SpecialChar ~
5928 \SpecialChar ~
5929 return asm_func(i,j); 
5930 \newline 
5931
5932 \newline 
5933
5934 \newline 
5935 int main() 
5936 \newline 
5937
5938 \newline 
5939 \SpecialChar ~
5940 \SpecialChar ~
5941 \SpecialChar ~
5942 \SpecialChar ~
5943 return c_func(10,9); 
5944 \newline 
5945 }
5946 \newline 
5947
5948 \family default 
5949
5950 \newline 
5951 The corresponding assembler routine is:
5952 \newline 
5953
5954 \newline 
5955
5956 \family typewriter 
5957 .globl _asm_func 
5958 \newline 
5959 _asm_func: 
5960 \newline 
5961 \SpecialChar ~
5962 \SpecialChar ~
5963 \SpecialChar ~
5964 \SpecialChar ~
5965 push  _bp 
5966 \newline 
5967 \SpecialChar ~
5968 \SpecialChar ~
5969 \SpecialChar ~
5970 \SpecialChar ~
5971 mov  _bp,sp 
5972 \newline 
5973 \SpecialChar ~
5974 \SpecialChar ~
5975 \SpecialChar ~
5976 \SpecialChar ~
5977 mov  r2,dpl
5978 \newline 
5979 \SpecialChar ~
5980 \SpecialChar ~
5981 \SpecialChar ~
5982 \SpecialChar ~
5983 mov  a,_bp 
5984 \newline 
5985 \SpecialChar ~
5986 \SpecialChar ~
5987 \SpecialChar ~
5988 \SpecialChar ~
5989 clr  c 
5990 \newline 
5991 \SpecialChar ~
5992 \SpecialChar ~
5993 \SpecialChar ~
5994 \SpecialChar ~
5995 add  a,#0xfd 
5996 \newline 
5997 \SpecialChar ~
5998 \SpecialChar ~
5999 \SpecialChar ~
6000 \SpecialChar ~
6001 mov  r0,a 
6002 \newline 
6003 \SpecialChar ~
6004 \SpecialChar ~
6005 \SpecialChar ~
6006 \SpecialChar ~
6007 add  a,#0xfc
6008 \newline 
6009 \SpecialChar ~
6010 \SpecialChar ~
6011 \SpecialChar ~
6012 \SpecialChar ~
6013 mov  r1,a 
6014 \newline 
6015 \SpecialChar ~
6016 \SpecialChar ~
6017 \SpecialChar ~
6018 \SpecialChar ~
6019 mov  a,@r0 
6020 \newline 
6021 \SpecialChar ~
6022 \SpecialChar ~
6023 \SpecialChar ~
6024 \SpecialChar ~
6025 add  a,r2
6026 \newline 
6027 \SpecialChar ~
6028 \SpecialChar ~
6029 \SpecialChar ~
6030 \SpecialChar ~
6031 mov  dpl,a 
6032 \newline 
6033 \SpecialChar ~
6034 \SpecialChar ~
6035 \SpecialChar ~
6036 \SpecialChar ~
6037 mov  dph,#0x00 
6038 \newline 
6039 \SpecialChar ~
6040 \SpecialChar ~
6041 \SpecialChar ~
6042 \SpecialChar ~
6043 mov  sp,_bp 
6044 \newline 
6045 \SpecialChar ~
6046 \SpecialChar ~
6047 \SpecialChar ~
6048 \SpecialChar ~
6049 pop  _bp 
6050 \newline 
6051 \SpecialChar ~
6052 \SpecialChar ~
6053 \SpecialChar ~
6054 \SpecialChar ~
6055 ret
6056 \newline 
6057
6058 \newline 
6059
6060 \family default 
6061 The compiling and linking procedure remains the same, however note the extra
6062  entry & exit linkage required for the assembler code, _bp is the stack
6063  frame pointer and is used to compute the offset into the stack for parameters
6064  and local variables.
6065 \layout Subsection
6066
6067 External Stack
6068 \layout Standard
6069
6070 The external stack is located at the start of the external ram segment,
6071  and is 256 bytes in size.
6072  When ---xstack option is used to compile the program, the parameters and
6073  local variables of all reentrant functions are allocated in this area.
6074  This option is provided for programs with large stack space requirements.
6075  When used with the ---stack-auto option, all parameters and local variables
6076  are allocated on the external stack (note support libraries will need to
6077  be recompiled with the same options).
6078 \layout Standard
6079
6080 The compiler outputs the higher order address byte of the external ram segment
6081  into PORT P2, therefore when using the External Stack option, this port
6082  MAY NOT be used by the application program.
6083 \layout Subsection
6084
6085 ANSI-Compliance
6086 \layout Standard
6087
6088 Deviations from the compliancy.
6089 \layout Itemize
6090
6091 functions are not always reentrant.
6092 \layout Itemize
6093
6094 structures cannot be assigned values directly, cannot be passed as function
6095  parameters or assigned to each other and cannot be a return value from
6096  a function, e.g.:
6097 \family typewriter 
6098
6099 \newline 
6100
6101 \newline 
6102 struct s { ...
6103  }; 
6104 \newline 
6105 struct s s1, s2; 
6106 \newline 
6107 foo() 
6108 \newline 
6109
6110 \newline 
6111 \SpecialChar ~
6112 \SpecialChar ~
6113 \SpecialChar ~
6114 \SpecialChar ~
6115 ...
6116  
6117 \newline 
6118 \SpecialChar ~
6119 \SpecialChar ~
6120 \SpecialChar ~
6121 \SpecialChar ~
6122 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
6123 \newline 
6124 \SpecialChar ~
6125 \SpecialChar ~
6126 \SpecialChar ~
6127 \SpecialChar ~
6128 ...
6129  
6130 \newline 
6131 }
6132 \newline 
6133 struct s foo1 (struct s parms) /* is invalid in SDCC although allowed in
6134  ANSI */ 
6135 \newline 
6136
6137 \newline 
6138 \SpecialChar ~
6139 \SpecialChar ~
6140 \SpecialChar ~
6141 \SpecialChar ~
6142 struct s rets; 
6143 \newline 
6144 \SpecialChar ~
6145 \SpecialChar ~
6146 \SpecialChar ~
6147 \SpecialChar ~
6148 ...
6149  
6150 \newline 
6151 \SpecialChar ~
6152 \SpecialChar ~
6153 \SpecialChar ~
6154 \SpecialChar ~
6155 return rets;/* is invalid in SDCC although allowed in ANSI */ 
6156 \newline 
6157 }
6158 \layout Itemize
6159
6160 'long long' (64 bit integers) not supported.
6161 \layout Itemize
6162
6163 'double' precision floating point not supported.
6164 \layout Itemize
6165
6166 No support for setjmp and longjmp (for now).
6167 \layout Itemize
6168
6169 Old K&R style function declarations are NOT allowed.
6170 \newline 
6171
6172 \family typewriter 
6173
6174 \newline 
6175 foo(i,j) /* this old style of function declarations */ 
6176 \newline 
6177 int i,j; /* are valid in ANSI but not valid in SDCC */ 
6178 \newline 
6179
6180 \newline 
6181 \SpecialChar ~
6182 \SpecialChar ~
6183 \SpecialChar ~
6184 \SpecialChar ~
6185 ...
6186  
6187 \newline 
6188 }
6189 \layout Itemize
6190
6191 functions declared as pointers must be dereferenced during the call.
6192 \newline 
6193
6194 \family typewriter 
6195
6196 \newline 
6197 int (*foo)();
6198 \newline 
6199 ...
6200  
6201 \newline 
6202 /* has to be called like this */ 
6203 \newline 
6204 (*foo)(); /* ansi standard allows calls to be made like 'foo()' */
6205 \layout Subsection
6206
6207 Cyclomatic Complexity
6208 \layout Standard
6209
6210 Cyclomatic complexity of a function is defined as the number of independent
6211  paths the program can take during execution of the function.
6212  This is an important number since it defines the number test cases you
6213  have to generate to validate the function.
6214  The accepted industry standard for complexity number is 10, if the cyclomatic
6215  complexity reported by SDCC exceeds 10 you should think about simplification
6216  of the function logic.
6217  Note that the complexity level is not related to the number of lines of
6218  code in a function.
6219  Large functions can have low complexity, and small functions can have large
6220  complexity levels.
6221  
6222 \newline 
6223
6224 \newline 
6225 SDCC uses the following formula to compute the complexity:
6226 \newline 
6227
6228 \layout Standard
6229
6230 complexity = (number of edges in control flow graph) - (number of nodes
6231  in control flow graph) + 2;
6232 \newline 
6233
6234 \newline 
6235 Having said that the industry standard is 10, you should be aware that in
6236  some cases it be may unavoidable to have a complexity level of less than
6237  10.
6238  For example if you have switch statement with more than 10 case labels,
6239  each case label adds one to the complexity level.
6240  The complexity level is by no means an absolute measure of the algorithmic
6241  complexity of the function, it does however provide a good starting point
6242  for which functions you might look at for further optimization.
6243 \layout Section
6244
6245 TIPS
6246 \layout Standard
6247
6248 Here are a few guidelines that will help the compiler generate more efficient
6249  code, some of the tips are specific to this compiler others are generally
6250  good programming practice.
6251 \layout Itemize
6252
6253 Use the smallest data type to represent your data-value.
6254  If it is known in advance that the value is going to be less than 256 then
6255  use a 'char' instead of a 'short' or 'int'.
6256 \layout Itemize
6257
6258 Use unsigned when it is known in advance that the value is not going to
6259  be negative.
6260  This helps especially if you are doing division or multiplication.
6261 \layout Itemize
6262
6263 NEVER jump into a LOOP.
6264 \layout Itemize
6265
6266 Declare the variables to be local whenever possible, especially loop control
6267  variables (induction).
6268 \layout Itemize
6269
6270 Since the compiler does not do implicit integral promotion, the programmer
6271  should do an explicit cast when integral promotion is required.
6272 \layout Itemize
6273
6274 Reducing the size of division, multiplication & modulus operations can reduce
6275  code size substantially.
6276  Take the following code for example.
6277 \family typewriter 
6278
6279 \newline 
6280
6281 \newline 
6282 foobar(unsigned int p1, unsigned char ch)
6283 \newline 
6284 {
6285 \newline 
6286     unsigned char ch1 = p1 % ch ;
6287 \newline 
6288     ....
6289     
6290 \newline 
6291 }
6292 \newline 
6293
6294 \family default 
6295
6296 \newline 
6297 For the modulus operation the variable ch will be promoted to unsigned int
6298  first then the modulus operation will be performed (this will lead to a
6299  call to support routine _moduint()), and the result will be casted to a
6300  char.
6301  If the code is changed to 
6302 \newline 
6303
6304 \family typewriter 
6305
6306 \newline 
6307 foobar(unsigned int p1, unsigned char ch)
6308 \newline 
6309 {
6310 \newline 
6311     unsigned char ch1 = (unsigned char)p1 % ch ;
6312 \newline 
6313     ....
6314     
6315 \newline 
6316 }
6317 \newline 
6318
6319 \family default 
6320
6321 \newline 
6322 It would substantially reduce the code generated (future versions of the
6323  compiler will be smart enough to detect such optimization oppurtunities).
6324 \layout Subsection
6325
6326 Notes on MCS51 memory layout
6327 \layout Standard
6328
6329 The 8051 family of micro controller have a minimum of 128 bytes of internal
6330  memory which is structured as follows
6331 \newline 
6332
6333 \newline 
6334 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R7 to R7
6335  
6336 \newline 
6337 - Bytes 20-2F - 16 bytes to hold 128 bit variables and 
6338 \newline 
6339 - Bytes 30-7F - 60 bytes for general purpose use.
6340 \newline 
6341
6342 \newline 
6343 Normally the SDCC compiler will only utilise the first bank of registers,
6344  but it is possible to specify that other banks of registers should be used
6345  in interrupt routines.
6346  By default, the compiler will place the stack after the last bank of used
6347  registers, i.e.
6348  if the first 2 banks of registers are used, it will position the base of
6349  the internal stack at address 16 (0X10).
6350  This implies that as the stack grows, it will use up the remaining register
6351  banks, and the 16 bytes used by the 128 bit variables, and 60 bytes for
6352  general purpose use.
6353 \layout Standard
6354
6355 By default, the compiler uses the 60 general purpose bytes to hold "near
6356  data".
6357  The compiler/optimiser may also declare some Local Variables in this area
6358  to hold local data.
6359  
6360 \layout Standard
6361
6362 If any of the 128 bit variables are used, or near data is being used then
6363  care needs to be taken to ensure that the stack does not grow so much that
6364  it starts to over write either your bit variables or "near data".
6365  There is no runtime checking to prevent this from happening.
6366 \layout Standard
6367
6368 The amount of stack being used is affected by the use of the "internal stack"
6369  to save registers before a subroutine call is made (---stack-auto will
6370  declare parameters and local variables on the stack) and the number of
6371  nested subroutines.
6372 \layout Standard
6373
6374 If you detect that the stack is over writing you data, then the following
6375  can be done.
6376  ---xstack will cause an external stack to be used for saving registers
6377  and (if ---stack-auto is being used) storing parameters and local variables.
6378  However this will produce more code which will be slower to execute.
6379  
6380 \layout Standard
6381
6382 ---stack-loc will allow you specify the start of the stack, i.e.
6383  you could start it after any data in the general purpose area.
6384  However this may waste the memory not used by the register banks and if
6385  the size of the "near data" increases, it may creep into the bottom of
6386  the stack.
6387 \layout Standard
6388
6389 ---stack-after-data, similar to the ---stack-loc, but it automatically places
6390  the stack after the end of the "near data".
6391  Again this could waste any spare register space.
6392 \layout Standard
6393
6394 ---data-loc allows you to specify the start address of the near data.
6395  This could be used to move the "near data" further away from the stack
6396  giving it more room to grow.
6397  This will only work if no bit variables are being used and the stack can
6398  grow to use the bit variable space.
6399 \newline 
6400
6401 \newline 
6402 Conclusion.
6403 \newline 
6404
6405 \newline 
6406 If you find that the stack is over writing your bit variables or "near data"
6407  then the approach which best utilised the internal memory is to position
6408  the "near data" after the last bank of used registers or, if you use bit
6409  variables, after the last bit variable by using the ---data-loc, e.g.
6410  if two register banks are being used and no bit variables, ---data-loc
6411  16, and use the ---stack-after-data option.
6412 \layout Standard
6413
6414 If bit variables are being used, another method would be to try and squeeze
6415  the data area in the unused register banks if it will fit, and start the
6416  stack after the last bit variable.
6417 \layout Section
6418
6419 Retargetting for other MCUs.
6420 \layout Standard
6421
6422 The issues for retargetting the compiler are far too numerous to be covered
6423  by this document.
6424  What follows is a brief description of each of the seven phases of the
6425  compiler and its MCU dependency.
6426 \layout Itemize
6427
6428 Parsing the source and building the annotated parse tree.
6429  This phase is largely MCU independent (except for the language extensions).
6430  Syntax & semantic checks are also done in this phase, along with some initial
6431  optimizations like back patching labels and the pattern matching optimizations
6432  like bit-rotation etc.
6433 \layout Itemize
6434
6435 The second phase involves generating an intermediate code which can be easy
6436  manipulated during the later phases.
6437  This phase is entirely MCU independent.
6438  The intermediate code generation assumes the target machine has unlimited
6439  number of registers, and designates them with the name iTemp.
6440  The compiler can be made to dump a human readable form of the code generated
6441  by using the ---dumpraw option.
6442 \layout Itemize
6443
6444 This phase does the bulk of the standard optimizations and is also MCU independe
6445 nt.
6446  This phase can be broken down into several sub-phases:
6447 \newline 
6448
6449 \newline 
6450 Break down intermediate code (iCode) into basic blocks.
6451 \newline 
6452 Do control flow & data flow analysis on the basic blocks.
6453 \newline 
6454 Do local common subexpression elimination, then global subexpression elimination
6455 \newline 
6456 Dead code elimination
6457 \newline 
6458 Loop optimizations
6459 \newline 
6460 If loop optimizations caused any changes then do 'global subexpression eliminati
6461 on' and 'dead code elimination' again.
6462 \layout Itemize
6463
6464 This phase determines the live-ranges; by live range I mean those iTemp
6465  variables defined by the compiler that still survive after all the optimization
6466 s.
6467  Live range analysis is essential for register allocation, since these computati
6468 on determines which of these iTemps will be assigned to registers, and for
6469  how long.
6470 \layout Itemize
6471
6472 Phase five is register allocation.
6473  There are two parts to this process.
6474 \newline 
6475
6476 \newline 
6477 The first part I call 'register packing' (for lack of a better term).
6478  In this case several MCU specific expression folding is done to reduce
6479  register pressure.
6480 \newline 
6481
6482 \newline 
6483 The second part is more MCU independent and deals with allocating registers
6484  to the remaining live ranges.
6485  A lot of MCU specific code does creep into this phase because of the limited
6486  number of index registers available in the 8051.
6487 \layout Itemize
6488
6489 The Code generation phase is (unhappily), entirely MCU dependent and very
6490  little (if any at all) of this code can be reused for other MCU.
6491  However the scheme for allocating a homogenized assembler operand for each
6492  iCode operand may be reused.
6493 \layout Itemize
6494
6495 As mentioned in the optimization section the peep-hole optimizer is rule
6496  based system, which can reprogrammed for other MCUs.
6497 \layout Section
6498
6499 SDCDB - Source Level Debugger
6500 \layout Standard
6501
6502 SDCC is distributed with a source level debugger.
6503  The debugger uses a command line interface, the command repertoire of the
6504  debugger has been kept as close to gdb (the GNU debugger) as possible.
6505  The configuration and build process is part of the standard compiler installati
6506 on, which also builds and installs the debugger in the target directory
6507  specified during configuration.
6508  The debugger allows you debug BOTH at the C source and at the ASM source
6509  level.
6510 \layout Subsection
6511
6512 Compiling for Debugging
6513 \layout Standard
6514
6515 The \SpecialChar \-
6516 \SpecialChar \-
6517 debug option must be specified for all files for which debug information
6518  is to be generated.
6519  The complier generates a .cdb file for each of these files.
6520  The linker updates the .cdb file with the address information.
6521  This .cdb is used by the debugger.
6522 \layout Subsection
6523
6524 How the Debugger Works
6525 \layout Standard
6526
6527 When the ---debug option is specified the compiler generates extra symbol
6528  information some of which are put into the the assembler source and some
6529  are put into the .cdb file, the linker updates the .cdb file with the address
6530  information for the symbols.
6531  The debugger reads the symbolic information generated by the compiler &
6532  the address information generated by the linker.
6533  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
6534  execution is controlled by the debugger.
6535  When a command is issued for the debugger, it translates it into appropriate
6536  commands for the simulator.
6537 \layout Subsection
6538
6539 Starting the Debugger
6540 \layout Standard
6541
6542 The debugger can be started using the following command line.
6543  (Assume the file you are debugging has the file name foo).
6544 \newline 
6545
6546 \newline 
6547
6548 \family sans 
6549 \series bold 
6550 sdcdb foo
6551 \newline 
6552
6553 \family default 
6554 \series default 
6555
6556 \newline 
6557 The debugger will look for the following files.
6558 \layout Itemize
6559
6560 foo.c - the source file.
6561 \layout Itemize
6562
6563 foo.cdb - the debugger symbol information file.
6564 \layout Itemize
6565
6566 foo.ihx - the intel hex format object file.
6567 \layout Subsection
6568
6569 Command Line Options.
6570 \layout Itemize
6571
6572 ---directory=<source file directory> this option can used to specify the
6573  directory search list.
6574  The debugger will look into the directory list specified for source, cdb
6575  & ihx files.
6576  The items in the directory list must be separated by ':', e.g.
6577  if the source files can be in the directories /home/src1 and /home/src2,
6578  the ---directory option should be ---directory=/home/src1:/home/src2.
6579  Note there can be no spaces in the option.
6580  
6581 \layout Itemize
6582
6583 -cd <directory> - change to the <directory>.
6584 \layout Itemize
6585
6586 -fullname - used by GUI front ends.
6587 \layout Itemize
6588
6589 -cpu <cpu-type> - this argument is passed to the simulator please see the
6590  simulator docs for details.
6591 \layout Itemize
6592
6593 -X <Clock frequency > this options is passed to the simulator please see
6594  the simulator docs for details.
6595 \layout Itemize
6596
6597 -s <serial port file> passed to simulator see the simulator docs for details.
6598 \layout Itemize
6599
6600 -S <serial in,out> passed to simulator see the simulator docs for details.
6601 \layout Subsection
6602
6603 Debugger Commands.
6604 \layout Standard
6605
6606 As mention earlier the command interface for the debugger has been deliberately
6607  kept as close the GNU debugger gdb, as possible.
6608  This will help the integration with existing graphical user interfaces
6609  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
6610 \layout Subsubsection
6611
6612 break [line | file:line | function | file:function]
6613 \layout Standard
6614
6615 Set breakpoint at specified line or function:
6616 \newline 
6617
6618 \newline 
6619
6620 \family sans 
6621 \series bold 
6622 sdcdb>break 100 
6623 \newline 
6624 sdcdb>break foo.c:100
6625 \newline 
6626 sdcdb>break funcfoo
6627 \newline 
6628 sdcdb>break foo.c:funcfoo
6629 \layout Subsubsection
6630
6631 clear [line | file:line | function | file:function ]
6632 \layout Standard
6633
6634 Clear breakpoint at specified line or function:
6635 \newline 
6636
6637 \newline 
6638
6639 \family sans 
6640 \series bold 
6641 sdcdb>clear 100
6642 \newline 
6643 sdcdb>clear foo.c:100
6644 \newline 
6645 sdcdb>clear funcfoo
6646 \newline 
6647 sdcdb>clear foo.c:funcfoo
6648 \layout Subsubsection
6649
6650 continue
6651 \layout Standard
6652
6653 Continue program being debugged, after breakpoint.
6654 \layout Subsubsection
6655
6656 finish
6657 \layout Standard
6658
6659 Execute till the end of the current function.
6660 \layout Subsubsection
6661
6662 delete [n]
6663 \layout Standard
6664
6665 Delete breakpoint number 'n'.
6666  If used without any option clear ALL user defined break points.
6667 \layout Subsubsection
6668
6669 info [break | stack | frame | registers ]
6670 \layout Itemize
6671
6672 info break - list all breakpoints
6673 \layout Itemize
6674
6675 info stack - show the function call stack.
6676 \layout Itemize
6677
6678 info frame - show information about the current execution frame.
6679 \layout Itemize
6680
6681 info registers - show content of all registers.
6682 \layout Subsubsection
6683
6684 step
6685 \layout Standard
6686
6687 Step program until it reaches a different source line.
6688 \layout Subsubsection
6689
6690 next
6691 \layout Standard
6692
6693 Step program, proceeding through subroutine calls.
6694 \layout Subsubsection
6695
6696 run
6697 \layout Standard
6698
6699 Start debugged program.
6700 \layout Subsubsection
6701
6702 ptype variable 
6703 \layout Standard
6704
6705 Print type information of the variable.
6706 \layout Subsubsection
6707
6708 print variable
6709 \layout Standard
6710
6711 print value of variable.
6712 \layout Subsubsection
6713
6714 file filename
6715 \layout Standard
6716
6717 load the given file name.
6718  Note this is an alternate method of loading file for debugging.
6719 \layout Subsubsection
6720
6721 frame
6722 \layout Standard
6723
6724 print information about current frame.
6725 \layout Subsubsection
6726
6727 set srcmode
6728 \layout Standard
6729
6730 Toggle between C source & assembly source.
6731 \layout Subsubsection
6732
6733 ! simulator command
6734 \layout Standard
6735
6736 Send the string following '!' to the simulator, the simulator response is
6737  displayed.
6738  Note the debugger does not interpret the command being sent to the simulator,
6739  so if a command like 'go' is sent the debugger can loose its execution
6740  context and may display incorrect values.
6741 \layout Subsubsection
6742
6743 quit.
6744 \layout Standard
6745
6746 "Watch me now.
6747  Iam going Down.
6748  My name is Bobby Brown"
6749 \layout Subsection
6750
6751 Interfacing with XEmacs.
6752 \layout Standard
6753
6754 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
6755  sdcdb.el and sdcdbsrc.el.
6756  These two files can be found in the $(prefix)/bin directory after the installat
6757 ion is complete.
6758  These files need to be loaded into XEmacs for the interface to work.
6759  This can be done at XEmacs startup time by inserting the following into
6760  your '.xemacs' file (which can be found in your HOME directory): 
6761 \newline 
6762
6763 \newline 
6764
6765 \family typewriter 
6766 (load-file sdcdbsrc.el) 
6767 \family default 
6768
6769 \newline 
6770
6771 \newline 
6772 .xemacs is a lisp file so the () around the command is REQUIRED.
6773  The files can also be loaded dynamically while XEmacs is running, set the
6774  environment variable 'EMACSLOADPATH' to the installation bin directory
6775  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
6776  To start the interface enter the following command: 
6777 \newline 
6778
6779 \newline 
6780
6781 \family sans 
6782 \series bold 
6783 ESC-x sdcdbsrc
6784 \family default 
6785 \series default 
6786
6787 \newline 
6788
6789 \newline 
6790 You will prompted to enter the file name to be debugged.
6791  
6792 \newline 
6793
6794 \newline 
6795 The command line options that are passed to the simulator directly are bound
6796  to default values in the file sdcdbsrc.el.
6797  The variables are listed below, these values maybe changed as required.
6798 \layout Itemize
6799
6800 sdcdbsrc-cpu-type '51
6801 \layout Itemize
6802
6803 sdcdbsrc-frequency '11059200
6804 \layout Itemize
6805
6806 sdcdbsrc-serial nil
6807 \layout Standard
6808
6809 The following is a list of key mapping for the debugger interface.
6810 \layout Standard
6811
6812 \SpecialChar ~
6813
6814 \family typewriter 
6815
6816 \newline 
6817 ;; Current Listing :: 
6818 \newline 
6819 ;;key\SpecialChar ~
6820 \SpecialChar ~
6821 \SpecialChar ~
6822 \SpecialChar ~
6823 \SpecialChar ~
6824 \SpecialChar ~
6825 \SpecialChar ~
6826 \SpecialChar ~
6827 \SpecialChar ~
6828 \SpecialChar ~
6829 \SpecialChar ~
6830 \SpecialChar ~
6831 \SpecialChar ~
6832 \SpecialChar ~
6833 \SpecialChar ~
6834 binding\SpecialChar ~
6835 \SpecialChar ~
6836 \SpecialChar ~
6837 \SpecialChar ~
6838 \SpecialChar ~
6839 \SpecialChar ~
6840 \SpecialChar ~
6841 \SpecialChar ~
6842 \SpecialChar ~
6843 \SpecialChar ~
6844 \SpecialChar ~
6845 \SpecialChar ~
6846 \SpecialChar ~
6847 \SpecialChar ~
6848 \SpecialChar ~
6849 \SpecialChar ~
6850 \SpecialChar ~
6851 \SpecialChar ~
6852 \SpecialChar ~
6853 \SpecialChar ~
6854 \SpecialChar ~
6855 \SpecialChar ~
6856 Comment 
6857 \newline 
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 \SpecialChar ~
6885 \SpecialChar ~
6886 \SpecialChar ~
6887 \SpecialChar ~
6888 \SpecialChar ~
6889 \SpecialChar ~
6890 \SpecialChar ~
6891 \SpecialChar ~
6892 \SpecialChar ~
6893 \SpecialChar ~
6894 \SpecialChar ~
6895 -------- 
6896 \newline 
6897 ;; 
6898 \newline 
6899 ;; n\SpecialChar ~
6900 \SpecialChar ~
6901 \SpecialChar ~
6902 \SpecialChar ~
6903 \SpecialChar ~
6904 \SpecialChar ~
6905 \SpecialChar ~
6906 \SpecialChar ~
6907 \SpecialChar ~
6908 \SpecialChar ~
6909 \SpecialChar ~
6910 \SpecialChar ~
6911 \SpecialChar ~
6912 \SpecialChar ~
6913  sdcdb-next-from-src\SpecialChar ~
6914 \SpecialChar ~
6915 \SpecialChar ~
6916 \SpecialChar ~
6917 \SpecialChar ~
6918 \SpecialChar ~
6919 \SpecialChar ~
6920 \SpecialChar ~
6921 \SpecialChar ~
6922 \SpecialChar ~
6923 SDCDB next command 
6924 \newline 
6925 ;; b\SpecialChar ~
6926 \SpecialChar ~
6927 \SpecialChar ~
6928 \SpecialChar ~
6929 \SpecialChar ~
6930 \SpecialChar ~
6931 \SpecialChar ~
6932 \SpecialChar ~
6933 \SpecialChar ~
6934 \SpecialChar ~
6935 \SpecialChar ~
6936 \SpecialChar ~
6937 \SpecialChar ~
6938 \SpecialChar ~
6939  sdcdb-back-from-src\SpecialChar ~
6940 \SpecialChar ~
6941 \SpecialChar ~
6942 \SpecialChar ~
6943 \SpecialChar ~
6944 \SpecialChar ~
6945 \SpecialChar ~
6946 \SpecialChar ~
6947 \SpecialChar ~
6948 \SpecialChar ~
6949 SDCDB back command 
6950 \newline 
6951 ;; c\SpecialChar ~
6952 \SpecialChar ~
6953 \SpecialChar ~
6954 \SpecialChar ~
6955 \SpecialChar ~
6956 \SpecialChar ~
6957 \SpecialChar ~
6958 \SpecialChar ~
6959 \SpecialChar ~
6960 \SpecialChar ~
6961 \SpecialChar ~
6962 \SpecialChar ~
6963 \SpecialChar ~
6964 \SpecialChar ~
6965  sdcdb-cont-from-src\SpecialChar ~
6966 \SpecialChar ~
6967 \SpecialChar ~
6968 \SpecialChar ~
6969 \SpecialChar ~
6970 \SpecialChar ~
6971 \SpecialChar ~
6972 \SpecialChar ~
6973 \SpecialChar ~
6974 \SpecialChar ~
6975 SDCDB continue command
6976 \newline 
6977 ;; s\SpecialChar ~
6978 \SpecialChar ~
6979 \SpecialChar ~
6980 \SpecialChar ~
6981 \SpecialChar ~
6982 \SpecialChar ~
6983 \SpecialChar ~
6984 \SpecialChar ~
6985 \SpecialChar ~
6986 \SpecialChar ~
6987 \SpecialChar ~
6988 \SpecialChar ~
6989 \SpecialChar ~
6990 \SpecialChar ~
6991  sdcdb-step-from-src\SpecialChar ~
6992 \SpecialChar ~
6993 \SpecialChar ~
6994 \SpecialChar ~
6995 \SpecialChar ~
6996 \SpecialChar ~
6997 \SpecialChar ~
6998 \SpecialChar ~
6999 \SpecialChar ~
7000 \SpecialChar ~
7001 SDCDB step command 
7002 \newline 
7003 ;; ?\SpecialChar ~
7004 \SpecialChar ~
7005 \SpecialChar ~
7006 \SpecialChar ~
7007 \SpecialChar ~
7008 \SpecialChar ~
7009 \SpecialChar ~
7010 \SpecialChar ~
7011 \SpecialChar ~
7012 \SpecialChar ~
7013 \SpecialChar ~
7014 \SpecialChar ~
7015 \SpecialChar ~
7016 \SpecialChar ~
7017  sdcdb-whatis-c-sexp\SpecialChar ~
7018 \SpecialChar ~
7019 \SpecialChar ~
7020 \SpecialChar ~
7021 \SpecialChar ~
7022 \SpecialChar ~
7023 \SpecialChar ~
7024 \SpecialChar ~
7025 \SpecialChar ~
7026 \SpecialChar ~
7027 SDCDB ptypecommand for data at 
7028 \newline 
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 \SpecialChar ~
7065 \SpecialChar ~
7066 \SpecialChar ~
7067 \SpecialChar ~
7068 \SpecialChar ~
7069 \SpecialChar ~
7070 \SpecialChar ~
7071 \SpecialChar ~
7072 \SpecialChar ~
7073 \SpecialChar ~
7074 \SpecialChar ~
7075  buffer point 
7076 \newline 
7077 ;; x\SpecialChar ~
7078 \SpecialChar ~
7079 \SpecialChar ~
7080 \SpecialChar ~
7081 \SpecialChar ~
7082 \SpecialChar ~
7083 \SpecialChar ~
7084 \SpecialChar ~
7085 \SpecialChar ~
7086 \SpecialChar ~
7087 \SpecialChar ~
7088 \SpecialChar ~
7089 \SpecialChar ~
7090 \SpecialChar ~
7091  sdcdbsrc-delete\SpecialChar ~
7092 \SpecialChar ~
7093 \SpecialChar ~
7094 \SpecialChar ~
7095 \SpecialChar ~
7096 \SpecialChar ~
7097 \SpecialChar ~
7098 \SpecialChar ~
7099 \SpecialChar ~
7100 \SpecialChar ~
7101 \SpecialChar ~
7102 \SpecialChar ~
7103 \SpecialChar ~
7104 \SpecialChar ~
7105 SDCDB Delete all breakpoints if no arg 
7106 \newline 
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 \SpecialChar ~
7143 \SpecialChar ~
7144 \SpecialChar ~
7145 \SpecialChar ~
7146 \SpecialChar ~
7147 \SpecialChar ~
7148 \SpecialChar ~
7149 \SpecialChar ~
7150 \SpecialChar ~
7151 \SpecialChar ~
7152 \SpecialChar ~
7153 given or delete arg (C-u arg x) 
7154 \newline 
7155 ;; m\SpecialChar ~
7156 \SpecialChar ~
7157 \SpecialChar ~
7158 \SpecialChar ~
7159 \SpecialChar ~
7160 \SpecialChar ~
7161 \SpecialChar ~
7162 \SpecialChar ~
7163 \SpecialChar ~
7164 \SpecialChar ~
7165 \SpecialChar ~
7166 \SpecialChar ~
7167 \SpecialChar ~
7168 \SpecialChar ~
7169  sdcdbsrc-frame\SpecialChar ~
7170 \SpecialChar ~
7171 \SpecialChar ~
7172 \SpecialChar ~
7173 \SpecialChar ~
7174 \SpecialChar ~
7175 \SpecialChar ~
7176 \SpecialChar ~
7177 \SpecialChar ~
7178 \SpecialChar ~
7179 \SpecialChar ~
7180 \SpecialChar ~
7181 \SpecialChar ~
7182 \SpecialChar ~
7183 \SpecialChar ~
7184 SDCDB Display current frame if no arg, 
7185 \newline 
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 \SpecialChar ~
7223 \SpecialChar ~
7224 \SpecialChar ~
7225 \SpecialChar ~
7226 \SpecialChar ~
7227 \SpecialChar ~
7228 \SpecialChar ~
7229 \SpecialChar ~
7230 \SpecialChar ~
7231 \SpecialChar ~
7232 \SpecialChar ~
7233 given or display frame arg 
7234 \newline 
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 \SpecialChar ~
7272 \SpecialChar ~
7273 \SpecialChar ~
7274 \SpecialChar ~
7275 \SpecialChar ~
7276 \SpecialChar ~
7277 \SpecialChar ~
7278 \SpecialChar ~
7279 \SpecialChar ~
7280 \SpecialChar ~
7281 \SpecialChar ~
7282 buffer point 
7283 \newline 
7284 ;; !\SpecialChar ~
7285 \SpecialChar ~
7286 \SpecialChar ~
7287 \SpecialChar ~
7288 \SpecialChar ~
7289 \SpecialChar ~
7290 \SpecialChar ~
7291 \SpecialChar ~
7292 \SpecialChar ~
7293 \SpecialChar ~
7294 \SpecialChar ~
7295 \SpecialChar ~
7296 \SpecialChar ~
7297 \SpecialChar ~
7298  sdcdbsrc-goto-sdcdb\SpecialChar ~
7299 \SpecialChar ~
7300 \SpecialChar ~
7301 \SpecialChar ~
7302 \SpecialChar ~
7303 \SpecialChar ~
7304 \SpecialChar ~
7305 \SpecialChar ~
7306 \SpecialChar ~
7307 \SpecialChar ~
7308 Goto the SDCDB output buffer 
7309 \newline 
7310 ;; p\SpecialChar ~
7311 \SpecialChar ~
7312 \SpecialChar ~
7313 \SpecialChar ~
7314 \SpecialChar ~
7315 \SpecialChar ~
7316 \SpecialChar ~
7317 \SpecialChar ~
7318 \SpecialChar ~
7319 \SpecialChar ~
7320 \SpecialChar ~
7321 \SpecialChar ~
7322 \SpecialChar ~
7323 \SpecialChar ~
7324  sdcdb-print-c-sexp\SpecialChar ~
7325 \SpecialChar ~
7326 \SpecialChar ~
7327 \SpecialChar ~
7328 \SpecialChar ~
7329 \SpecialChar ~
7330 \SpecialChar ~
7331 \SpecialChar ~
7332 \SpecialChar ~
7333 \SpecialChar ~
7334 \SpecialChar ~
7335 SDCDB print command for data at 
7336 \newline 
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 \SpecialChar ~
7373 \SpecialChar ~
7374 \SpecialChar ~
7375 \SpecialChar ~
7376 \SpecialChar ~
7377 \SpecialChar ~
7378 \SpecialChar ~
7379 \SpecialChar ~
7380 \SpecialChar ~
7381 \SpecialChar ~
7382 \SpecialChar ~
7383  buffer point 
7384 \newline 
7385 ;; g\SpecialChar ~
7386 \SpecialChar ~
7387 \SpecialChar ~
7388 \SpecialChar ~
7389 \SpecialChar ~
7390 \SpecialChar ~
7391 \SpecialChar ~
7392 \SpecialChar ~
7393 \SpecialChar ~
7394 \SpecialChar ~
7395 \SpecialChar ~
7396 \SpecialChar ~
7397 \SpecialChar ~
7398 \SpecialChar ~
7399  sdcdbsrc-goto-sdcdb\SpecialChar ~
7400 \SpecialChar ~
7401 \SpecialChar ~
7402 \SpecialChar ~
7403 \SpecialChar ~
7404 \SpecialChar ~
7405 \SpecialChar ~
7406 \SpecialChar ~
7407 \SpecialChar ~
7408 \SpecialChar ~
7409 Goto the SDCDB output buffer 
7410 \newline 
7411 ;; t\SpecialChar ~
7412 \SpecialChar ~
7413 \SpecialChar ~
7414 \SpecialChar ~
7415 \SpecialChar ~
7416 \SpecialChar ~
7417 \SpecialChar ~
7418 \SpecialChar ~
7419 \SpecialChar ~
7420 \SpecialChar ~
7421 \SpecialChar ~
7422 \SpecialChar ~
7423 \SpecialChar ~
7424 \SpecialChar ~
7425  sdcdbsrc-mode\SpecialChar ~
7426 \SpecialChar ~
7427 \SpecialChar ~
7428 \SpecialChar ~
7429 \SpecialChar ~
7430 \SpecialChar ~
7431 \SpecialChar ~
7432 \SpecialChar ~
7433 \SpecialChar ~
7434 \SpecialChar ~
7435 \SpecialChar ~
7436 \SpecialChar ~
7437 \SpecialChar ~
7438 \SpecialChar ~
7439 \SpecialChar ~
7440 \SpecialChar ~
7441 Toggles Sdcdbsrc mode (turns it off) 
7442 \newline 
7443 ;; 
7444 \newline 
7445 ;; C-c C-f\SpecialChar ~
7446 \SpecialChar ~
7447 \SpecialChar ~
7448 \SpecialChar ~
7449 \SpecialChar ~
7450 \SpecialChar ~
7451 \SpecialChar ~
7452 \SpecialChar ~
7453  sdcdb-finish-from-src\SpecialChar ~
7454 \SpecialChar ~
7455 \SpecialChar ~
7456 \SpecialChar ~
7457 \SpecialChar ~
7458 \SpecialChar ~
7459 \SpecialChar ~
7460 \SpecialChar ~
7461 SDCDB finish command 
7462 \newline 
7463 ;; 
7464 \newline 
7465 ;; C-x SPC\SpecialChar ~
7466 \SpecialChar ~
7467 \SpecialChar ~
7468 \SpecialChar ~
7469 \SpecialChar ~
7470 \SpecialChar ~
7471 \SpecialChar ~
7472 \SpecialChar ~
7473  sdcdb-break\SpecialChar ~
7474 \SpecialChar ~
7475 \SpecialChar ~
7476 \SpecialChar ~
7477 \SpecialChar ~
7478 \SpecialChar ~
7479 \SpecialChar ~
7480 \SpecialChar ~
7481 \SpecialChar ~
7482 \SpecialChar ~
7483 \SpecialChar ~
7484 \SpecialChar ~
7485 \SpecialChar ~
7486 \SpecialChar ~
7487 \SpecialChar ~
7488 \SpecialChar ~
7489 \SpecialChar ~
7490 \SpecialChar ~
7491 Set break for line with point 
7492 \newline 
7493 ;; ESC t\SpecialChar ~
7494 \SpecialChar ~
7495 \SpecialChar ~
7496 \SpecialChar ~
7497 \SpecialChar ~
7498 \SpecialChar ~
7499 \SpecialChar ~
7500 \SpecialChar ~
7501 \SpecialChar ~
7502 \SpecialChar ~
7503  sdcdbsrc-mode\SpecialChar ~
7504 \SpecialChar ~
7505 \SpecialChar ~
7506 \SpecialChar ~
7507 \SpecialChar ~
7508 \SpecialChar ~
7509 \SpecialChar ~
7510 \SpecialChar ~
7511 \SpecialChar ~
7512 \SpecialChar ~
7513 \SpecialChar ~
7514 \SpecialChar ~
7515 \SpecialChar ~
7516 \SpecialChar ~
7517 \SpecialChar ~
7518 \SpecialChar ~
7519 Toggle Sdcdbsrc mode 
7520 \newline 
7521 ;; ESC m\SpecialChar ~
7522 \SpecialChar ~
7523 \SpecialChar ~
7524 \SpecialChar ~
7525 \SpecialChar ~
7526 \SpecialChar ~
7527 \SpecialChar ~
7528 \SpecialChar ~
7529 \SpecialChar ~
7530 \SpecialChar ~
7531  sdcdbsrc-srcmode\SpecialChar ~
7532 \SpecialChar ~
7533 \SpecialChar ~
7534 \SpecialChar ~
7535 \SpecialChar ~
7536 \SpecialChar ~
7537 \SpecialChar ~
7538 \SpecialChar ~
7539 \SpecialChar ~
7540 \SpecialChar ~
7541 \SpecialChar ~
7542 \SpecialChar ~
7543  Toggle list mode 
7544 \newline 
7545 ;; 
7546 \family default 
7547
7548 \newline 
7549
7550 \layout Section
7551
7552 Other Processors
7553 \layout Subsection
7554
7555 The Z80 and gbz80 port
7556 \layout Standard
7557
7558 SDCC can target both the Zilog Z80 and the Nintendo Gameboy's Z80-like gbz80.
7559  The port is incomplete - long support is incomplete (mul, div and mod are
7560  unimplimented), and both float and bitfield support is missing.
7561  Apart from that the code generated is correct.
7562 \layout Standard
7563
7564 As always, the code is the authoritave reference - see z80/ralloc.c and z80/gen.c.
7565  The stack frame is similar to that generated by the IAR Z80 compiler.
7566  IX is used as the base pointer, HL is used as a temporary register, and
7567  BC and DE are available for holding varibles.
7568  IY is currently unusued.
7569  Return values are stored in HL.
7570  One bad side effect of using IX as the base pointer is that a functions
7571  stack frame is limited to 127 bytes - this will be fixed in a later version.
7572 \layout Section
7573
7574 Support
7575 \layout Standard
7576
7577 SDCC has grown to be a large project.
7578  The compiler alone (without the preprocessor, assembler and linker) is
7579  about 40,000 lines of code (blank stripped).
7580  The open source nature of this project is a key to its continued growth
7581  and support.
7582  You gain the benefit and support of many active software developers and
7583  end users.
7584  Is SDCC perfect? No, that's why we need your help.
7585  The developers take pride in fixing reported bugs.
7586  You can help by reporting the bugs and helping other SDCC users.
7587  There are lots of ways to contribute, and we encourage you to take part
7588  in making SDCC a great software package.
7589 \layout Subsection
7590
7591 Reporting Bugs
7592 \layout Standard
7593
7594 Send an email to the mailing list at 'user-sdcc@sdcc.sourceforge.net' or 'devel-sd
7595 cc@sdcc.sourceforge.net'.
7596  Bugs will be fixed ASAP.
7597  When reporting a bug, it is very useful to include a small test program
7598  which reproduces the problem.
7599  If you can isolate the problem by looking at the generated assembly code,
7600  this can be very helpful.
7601  Compiling your program with the ---dumpall option can sometimes be useful
7602  in locating optimization problems.
7603 \layout Section
7604
7605 The anatomy of the compiler
7606 \layout Standard
7607
7608
7609 \shape italic 
7610 This is an excerpt from an atricle published in Circuit Cellar MagaZine
7611  in august 2000.
7612  It's a little outdated (the compiler is much more efficient now and user/devell
7613 oper friendly), but pretty well exposes the guts of it all.
7614 \shape default 
7615
7616 \newline 
7617
7618 \newline 
7619 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
7620  It is fairly easy to retarget for other 8-bit MCU.
7621  Here we take a look at some of the internals of the compiler.
7622  
7623 \layout Paragraph*
7624
7625 Parsing 
7626 \layout Standard
7627
7628 Parsing the input source file and creating an AST (Annotated Syntax Tree).
7629  This phase also involves propagating types (annotating each node of the
7630  parse tree with type information) and semantic analysis.
7631  There are some MCU specific parsing rules.
7632  For example the storage classes, the extended storage classes are MCU specific
7633  while there may be a xdata storage class for 8051 there is no such storage
7634  class for z80 or Atmel AVR.
7635  SDCC allows MCU specific storage class extensions, i.e.
7636  xdata will be treated as a storage class specifier when parsing 8051 C
7637  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
7638  C code.
7639 \layout Paragraph*
7640
7641 Generating iCode
7642 \layout Standard
7643
7644 Intermediate code generation.
7645  In this phase the AST is broken down into three-operand form (iCode).
7646  These three operand forms are represented as doubly linked lists.
7647  ICode is the term given to the intermediate form generated by the compiler.
7648  ICode example section shows some examples of iCode generated for some simple
7649  C source functions.
7650 \layout Paragraph*
7651
7652 Optimizations.
7653 \layout Standard
7654
7655 Bulk of the target independent optimizations is performed in this phase.
7656  The optimizations include constant propagation, common sub-expression eliminati
7657 on, loop invariant code movement, strength reduction of loop induction variables
7658  and dead-code elimination.
7659 \layout Paragraph*
7660
7661 Live range analysis
7662 \layout Standard
7663
7664 During intermediate code generation phase, the compiler assumes the target
7665  machine has infinite number of registers and generates a lot of temporary
7666  variables.
7667  The live range computation determines the lifetime of each of these compiler-ge
7668 nerated temporaries.
7669  A picture speaks a thousand words.
7670  ICode example sections show the live range annotations for each of the
7671  operand.
7672  It is important to note here, each iCode is assigned a number in the order
7673  of its execution in the function.
7674  The live ranges are computed in terms of these numbers.
7675  The from number is the number of the iCode which first defines the operand
7676  and the to number signifies the iCode which uses this operand last.
7677 \layout Paragraph*
7678
7679 Register Allocation
7680 \layout Standard
7681
7682 The register allocation determines the type and number of registers needed
7683  by each operand.
7684  In most MCUs only a few registers can be used for indirect addressing.
7685  In case of 8051 for example the registers R0 & R1 can be used to indirectly
7686  address the internal ram and DPTR to indirectly address the external ram.
7687  The compiler will try to allocate the appropriate register to pointer variables
7688  if it can.
7689  ICode example section shows the operands annotated with the registers assigned
7690  to them.
7691  The compiler will try to keep operands in registers as much as possible;
7692  there are several schemes the compiler uses to do achieve this.
7693  When the compiler runs out of registers the compiler will check to see
7694  if there are any live operands which is not used or defined in the current
7695  basic block being processed, if there are any found then it will push that
7696  operand and use the registers in this block, the operand will then be popped
7697  at the end of the basic block.
7698  
7699 \layout Standard
7700
7701 There are other MCU specific considerations in this phase.
7702  Some MCUs have an accumulator; very short-lived operands could be assigned
7703  to the accumulator instead of general-purpose register.
7704 \layout Paragraph*
7705
7706 Code generation
7707 \layout Standard
7708
7709 Figure II gives a table of iCode operations supported by the compiler.
7710  The code generation involves translating these operations into corresponding
7711  assembly code for the processor.
7712  This sounds overly simple but that is the essence of code generation.
7713  Some of the iCode operations are generated on a MCU specific manner for
7714  example, the z80 port does not use registers to pass parameters so the
7715  SEND and RECV iCode operations will not be generated, and it also does
7716  not support JUMPTABLES.
7717  
7718 \newline 
7719
7720 \series bold 
7721 \shape italic 
7722 \color red
7723 <Where is Figure II ?>
7724 \layout Paragraph*
7725
7726 ICode Example
7727 \layout Standard
7728
7729 This section shows some details of iCode.
7730  The example C code does not do anything useful; it is used as an example
7731  to illustrate the intermediate code generated by the compiler.
7732 \newline 
7733
7734 \newline 
7735
7736 \family typewriter 
7737 1.\SpecialChar ~
7738 xdata int * p;
7739 \newline 
7740 2.\SpecialChar ~
7741 int gint;
7742 \newline 
7743 3.\SpecialChar ~
7744 /* This function does nothing useful.
7745  It is used
7746 \newline 
7747 4.\SpecialChar ~
7748 \SpecialChar ~
7749 \SpecialChar ~
7750 \SpecialChar ~
7751 for the purpose of explaining iCode */
7752 \newline 
7753 5.\SpecialChar ~
7754 short function (data int *x)
7755 \newline 
7756 6.\SpecialChar ~
7757 {
7758 \newline 
7759 7.\SpecialChar ~
7760 \SpecialChar ~
7761 \SpecialChar ~
7762 short i=10; /* dead initialization eliminated */
7763 \newline 
7764 8.\SpecialChar ~
7765 \SpecialChar ~
7766 \SpecialChar ~
7767 short sum=10; /* dead initialization eliminated */
7768 \newline 
7769 9.\SpecialChar ~
7770 \SpecialChar ~
7771 \SpecialChar ~
7772 short mul;
7773 \newline 
7774 10.\SpecialChar ~
7775 \SpecialChar ~
7776 int j ;
7777 \newline 
7778 11.\SpecialChar ~
7779 \SpecialChar ~
7780 while (*x) *x++ = *p++; 
7781 \newline 
7782 12.\SpecialChar ~
7783 \SpecialChar ~
7784 \SpecialChar ~
7785 \SpecialChar ~
7786 sum = 0 ; 
7787 \newline 
7788 13.\SpecialChar ~
7789 \SpecialChar ~
7790 mul = 0;
7791 \newline 
7792 14.\SpecialChar ~
7793 \SpecialChar ~
7794 /* compiler detects i,j to be induction variables */
7795 \newline 
7796 15.\SpecialChar ~
7797 \SpecialChar ~
7798 for (i = 0, j = 10 ; i < 10 ; i++, j---) {
7799 \newline 
7800 16.\SpecialChar ~
7801 \SpecialChar ~
7802 \SpecialChar ~
7803 \SpecialChar ~
7804 sum += i;
7805 \newline 
7806 17.\SpecialChar ~
7807 \SpecialChar ~
7808 \SpecialChar ~
7809 \SpecialChar ~
7810 mul += i * 3; /* this multiplication remains */
7811 \newline 
7812 18.\SpecialChar ~
7813 \SpecialChar ~
7814 \SpecialChar ~
7815 \SpecialChar ~
7816 gint += j * 3;/* this multiplication changed to addition */
7817 \newline 
7818 19.\SpecialChar ~
7819 \SpecialChar ~
7820 }
7821 \newline 
7822 20.\SpecialChar ~
7823 \SpecialChar ~
7824 return sum+mul;
7825 \newline 
7826 21.\SpecialChar ~
7827 }
7828 \newline 
7829
7830 \newline 
7831
7832 \family default 
7833 In addition to the operands each iCode contains information about the filename
7834  and line it corresponds to in the source file.
7835  The first field in the listing should be interpreted as follows:
7836 \newline 
7837
7838 \shape italic 
7839 \size footnotesize 
7840 Filename(linenumber: iCode Execution sequence number : ICode hash table
7841  key : loop depth of the iCode).
7842 \shape default 
7843 \size default 
7844
7845 \newline 
7846 Then follows the human readable form of the ICode operation.
7847  Each operand of this triplet form can be of three basic types a) compiler
7848  generated temporary b) user defined variable c) a constant value.
7849  Note that local variables and parameters are replaced by compiler generated
7850  temporaries.
7851  Live ranges are computed only for temporaries (i.e.
7852  live ranges are not computed for global variables).
7853  Registers are allocated for temporaries only.
7854  Operands are formatted in the following manner:
7855 \newline 
7856
7857 \shape italic 
7858 \size footnotesize 
7859 Operand Name [lr live-from : live-to ] { type information } [ registers
7860  allocated ].
7861 \shape default 
7862 \size default 
7863
7864 \newline 
7865 As mentioned earlier the live ranges are computed in terms of the execution
7866  sequence number of the iCodes, for example 
7867 \newline 
7868 the iTemp0 is live from (i.e.
7869  first defined in iCode with execution sequence number 3, and is last used
7870  in the iCode with sequence number 5).
7871  For induction variables such as iTemp21 the live range computation extends
7872  the lifetime from the start to the end of the loop.
7873 \newline 
7874 The register allocator used the live range information to allocate registers,
7875  the same registers may be used for different temporaries if their live
7876  ranges do not overlap, for example r0 is allocated to both iTemp6 and to
7877  iTemp17 since their live ranges do not overlap.
7878  In addition the allocator also takes into consideration the type and usage
7879  of a temporary, for example itemp6 is a pointer to near space and is used
7880  as to fetch data from (i.e.
7881  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer registers (r0).
7882  Some short lived temporaries are allocated to special registers which have
7883  meaning to the code generator e.g.
7884  iTemp13 is allocated to a pseudo register CC which tells the back end that
7885  the temporary is used only for a conditional jump the code generation makes
7886  use of this information to optimize a compare and jump ICode.
7887 \newline 
7888 There are several loop optimizations performed by the compiler.
7889  It can detect induction variables iTemp21(i) and iTemp23(j).
7890  Also note the compiler does selective strength reduction, i.e.
7891  the multiplication of an induction variable in line 18 (gint = j * 3) is
7892  changed to addition, a new temporary iTemp17 is allocated and assigned
7893  a initial value, a constant 3 is then added for each iteration of the loop.
7894  The compiler does not change the multiplication in line 17 however since
7895  the processor does support an 8 * 8 bit multiplication.
7896 \newline 
7897 Note the dead code elimination optimization eliminated the dead assignments
7898  in line 7 & 8 to I and sum respectively.
7899 \newline 
7900
7901 \layout Standard
7902
7903
7904 \size footnotesize 
7905 Sample.c (5:1:0:0) _entry($9) :
7906 \layout Standard
7907
7908
7909 \size footnotesize 
7910 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
7911 \layout Standard
7912
7913
7914 \size footnotesize 
7915 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
7916 \layout Standard
7917
7918
7919 \size footnotesize 
7920 Sample.c(11:4:53:0) preHeaderLbl0($11) :
7921 \layout Standard
7922
7923
7924 \size footnotesize 
7925 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
7926  * int}[r2]
7927 \layout Standard
7928
7929
7930 \size footnotesize 
7931 Sample.c(11:6:5:1) _whilecontinue_0($1) :
7932 \layout Standard
7933
7934
7935 \size footnotesize 
7936 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
7937  int}[r0]]
7938 \layout Standard
7939
7940
7941 \size footnotesize 
7942 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
7943 \layout Standard
7944
7945
7946 \size footnotesize 
7947 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
7948  * int}
7949 \layout Standard
7950
7951
7952 \size footnotesize 
7953 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
7954  {short}
7955 \layout Standard
7956
7957
7958 \size footnotesize 
7959 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
7960  * int}[DPTR]]
7961 \layout Standard
7962
7963
7964 \size footnotesize 
7965 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
7966 }[r2 r3]
7967 \layout Standard
7968
7969
7970 \size footnotesize 
7971 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
7972  * int}[r0] + 
7973 \layout Standard
7974
7975
7976 \size footnotesize 
7977 0x2 {short}
7978 \layout Standard
7979
7980
7981 \size footnotesize 
7982 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
7983 \layout Standard
7984
7985
7986 \size footnotesize 
7987 Sample.c(11:17:21:0)_whilebreak_0($3) :
7988 \layout Standard
7989
7990
7991 \size footnotesize 
7992 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
7993 \layout Standard
7994
7995
7996 \size footnotesize 
7997 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
7998 \layout Standard
7999
8000
8001 \size footnotesize 
8002 Sample.c(15:20:54:0)preHeaderLbl1($13) :
8003 \layout Standard
8004
8005
8006 \size footnotesize 
8007 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
8008 \layout Standard
8009
8010
8011 \size footnotesize 
8012 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
8013 \layout Standard
8014
8015
8016 \size footnotesize 
8017 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
8018 \layout Standard
8019
8020
8021 \size footnotesize 
8022 Sample.c(15:24:26:1)_forcond_0($4) :
8023 \layout Standard
8024
8025
8026 \size footnotesize 
8027 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
8028  < 0xa {short}
8029 \layout Standard
8030
8031
8032 \size footnotesize 
8033 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
8034 \layout Standard
8035
8036
8037 \size footnotesize 
8038 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
8039  + 
8040 \layout Standard
8041
8042
8043 \size footnotesize 
8044 ITemp21 [lr21:38]{short}[r4]
8045 \layout Standard
8046
8047
8048 \size footnotesize 
8049 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
8050  * 0x3 {short}
8051 \layout Standard
8052
8053
8054 \size footnotesize 
8055 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
8056  + 
8057 \layout Standard
8058
8059
8060 \size footnotesize 
8061 iTemp15 [lr29:30]{short}[r1]
8062 \layout Standard
8063
8064
8065 \size footnotesize 
8066 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
8067  r0]- 0x3 {short}
8068 \layout Standard
8069
8070
8071 \size footnotesize 
8072 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
8073 int}[r7 r0]
8074 \layout Standard
8075
8076
8077 \size footnotesize 
8078 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
8079  + 0x1 {short}
8080 \layout Standard
8081
8082
8083 \size footnotesize 
8084 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
8085  r6]- 0x1 {short}
8086 \layout Standard
8087
8088
8089 \size footnotesize 
8090 Sample.c(19:38:47:1) goto _forcond_0($4)
8091 \layout Standard
8092
8093
8094 \size footnotesize 
8095 Sample.c(19:39:48:0)_forbreak_0($7) :
8096 \layout Standard
8097
8098
8099 \size footnotesize 
8100 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
8101  + 
8102 \layout Standard
8103
8104
8105 \size footnotesize 
8106 ITemp11 [lr19:40]{short}[r3]
8107 \layout Standard
8108
8109
8110 \size footnotesize 
8111 sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
8112 \layout Standard
8113
8114
8115 \size footnotesize 
8116 sample.c(20:42:51:0)_return($8) :
8117 \layout Standard
8118
8119
8120 \size footnotesize 
8121 sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
8122 \size default 
8123
8124 \newline 
8125
8126 \newline 
8127 Finally the code generated for this function:
8128 \newline 
8129
8130 \layout Standard
8131
8132
8133 \size footnotesize 
8134 .area DSEG (DATA)
8135 \layout Standard
8136
8137
8138 \size footnotesize 
8139 _p::
8140 \layout Standard
8141
8142
8143 \size footnotesize 
8144 \SpecialChar ~
8145 \SpecialChar ~
8146 .ds 2
8147 \layout Standard
8148
8149
8150 \size footnotesize 
8151 _gint::
8152 \layout Standard
8153
8154
8155 \size footnotesize 
8156 \SpecialChar ~
8157 \SpecialChar ~
8158 .ds 2
8159 \layout Standard
8160
8161
8162 \size footnotesize 
8163 ; sample.c 5
8164 \layout Standard
8165
8166
8167 \size footnotesize 
8168 ; ----------------------------------------------
8169 \layout Standard
8170
8171
8172 \size footnotesize 
8173 ; function function
8174 \layout Standard
8175
8176
8177 \size footnotesize 
8178 ; ----------------------------------------------
8179 \layout Standard
8180
8181
8182 \size footnotesize 
8183 _function:
8184 \layout Standard
8185
8186
8187 \size footnotesize 
8188 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
8189 \layout Standard
8190
8191
8192 \size footnotesize 
8193 \SpecialChar ~
8194 \SpecialChar ~
8195 mov r2,dpl
8196 \layout Standard
8197
8198
8199 \size footnotesize 
8200 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
8201 \layout Standard
8202
8203
8204 \size footnotesize 
8205 \SpecialChar ~
8206 \SpecialChar ~
8207 mov ar0,r2
8208 \layout Standard
8209
8210
8211 \size footnotesize 
8212 ;_whilecontinue_0($1) :
8213 \layout Standard
8214
8215
8216 \size footnotesize 
8217 00101$:
8218 \layout Standard
8219
8220
8221 \size footnotesize 
8222 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
8223 \layout Standard
8224
8225
8226 \size footnotesize 
8227 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
8228 \layout Standard
8229
8230
8231 \size footnotesize 
8232 \SpecialChar ~
8233 \SpecialChar ~
8234 mov ar2,@r0
8235 \layout Standard
8236
8237
8238 \size footnotesize 
8239 \SpecialChar ~
8240 \SpecialChar ~
8241 inc r0
8242 \layout Standard
8243
8244
8245 \size footnotesize 
8246 \SpecialChar ~
8247 \SpecialChar ~
8248 mov ar3,@r0
8249 \layout Standard
8250
8251
8252 \size footnotesize 
8253 \SpecialChar ~
8254 \SpecialChar ~
8255 dec r0
8256 \layout Standard
8257
8258
8259 \size footnotesize 
8260 \SpecialChar ~
8261 \SpecialChar ~
8262 mov a,r2
8263 \layout Standard
8264
8265
8266 \size footnotesize 
8267 \SpecialChar ~
8268 \SpecialChar ~
8269 orl a,r3
8270 \layout Standard
8271
8272
8273 \size footnotesize 
8274 \SpecialChar ~
8275 \SpecialChar ~
8276 jz 00103$
8277 \layout Standard
8278
8279
8280 \size footnotesize 
8281 00114$:
8282 \layout Standard
8283
8284
8285 \size footnotesize 
8286 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
8287 \layout Standard
8288
8289
8290 \size footnotesize 
8291 \SpecialChar ~
8292 \SpecialChar ~
8293 mov dpl,_p
8294 \layout Standard
8295
8296
8297 \size footnotesize 
8298 \SpecialChar ~
8299 \SpecialChar ~
8300 mov dph,(_p + 1)
8301 \layout Standard
8302
8303
8304 \size footnotesize 
8305 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
8306 \layout Standard
8307
8308
8309 \size footnotesize 
8310 \SpecialChar ~
8311 \SpecialChar ~
8312 mov a,#0x02
8313 \layout Standard
8314
8315
8316 \size footnotesize 
8317 \SpecialChar ~
8318 \SpecialChar ~
8319 add a,_p
8320 \layout Standard
8321
8322
8323 \size footnotesize 
8324 \SpecialChar ~
8325 \SpecialChar ~
8326 mov _p,a
8327 \layout Standard
8328
8329
8330 \size footnotesize 
8331 \SpecialChar ~
8332 \SpecialChar ~
8333 clr a
8334 \layout Standard
8335
8336
8337 \size footnotesize 
8338 \SpecialChar ~
8339 \SpecialChar ~
8340 addc a,(_p + 1)
8341 \layout Standard
8342
8343
8344 \size footnotesize 
8345 \SpecialChar ~
8346 \SpecialChar ~
8347 mov (_p + 1),a
8348 \layout Standard
8349
8350
8351 \size footnotesize 
8352 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
8353 \layout Standard
8354
8355
8356 \size footnotesize 
8357 \SpecialChar ~
8358 \SpecialChar ~
8359 movx a,@dptr
8360 \layout Standard
8361
8362
8363 \size footnotesize 
8364 \SpecialChar ~
8365 \SpecialChar ~
8366 mov r2,a
8367 \layout Standard
8368
8369
8370 \size footnotesize 
8371 \SpecialChar ~
8372 \SpecialChar ~
8373 inc dptr
8374 \layout Standard
8375
8376
8377 \size footnotesize 
8378 \SpecialChar ~
8379 \SpecialChar ~
8380 movx a,@dptr
8381 \layout Standard
8382
8383
8384 \size footnotesize 
8385 \SpecialChar ~
8386 \SpecialChar ~
8387 mov r3,a
8388 \layout Standard
8389
8390
8391 \size footnotesize 
8392 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
8393 \layout Standard
8394
8395
8396 \size footnotesize 
8397 \SpecialChar ~
8398 \SpecialChar ~
8399 mov @r0,ar2
8400 \layout Standard
8401
8402
8403 \size footnotesize 
8404 \SpecialChar ~
8405 \SpecialChar ~
8406 inc r0
8407 \layout Standard
8408
8409
8410 \size footnotesize 
8411 \SpecialChar ~
8412 \SpecialChar ~
8413 mov @r0,ar3
8414 \layout Standard
8415
8416
8417 \size footnotesize 
8418 ; iTemp6 [lr5:16]{_near * int}[r0] = 
8419 \layout Standard
8420
8421
8422 \size footnotesize 
8423 ; iTemp6 [lr5:16]{_near * int}[r0] + 
8424 \layout Standard
8425
8426
8427 \size footnotesize 
8428 ; 0x2 {short}
8429 \layout Standard
8430
8431
8432 \size footnotesize 
8433 \SpecialChar ~
8434 \SpecialChar ~
8435 inc r0
8436 \layout Standard
8437
8438
8439 \size footnotesize 
8440 ; goto _whilecontinue_0($1)
8441 \layout Standard
8442
8443
8444 \size footnotesize 
8445 \SpecialChar ~
8446 \SpecialChar ~
8447 sjmp 00101$
8448 \layout Standard
8449
8450
8451 \size footnotesize 
8452 ; _whilebreak_0($3) :
8453 \layout Standard
8454
8455
8456 \size footnotesize 
8457 00103$:
8458 \layout Standard
8459
8460
8461 \size footnotesize 
8462 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
8463 \layout Standard
8464
8465
8466 \size footnotesize 
8467 \SpecialChar ~
8468 \SpecialChar ~
8469 mov r2,#0x00
8470 \layout Standard
8471
8472
8473 \size footnotesize 
8474 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
8475 \layout Standard
8476
8477
8478 \size footnotesize 
8479 \SpecialChar ~
8480 \SpecialChar ~
8481 mov r3,#0x00
8482 \layout Standard
8483
8484
8485 \size footnotesize 
8486 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
8487 \layout Standard
8488
8489
8490 \size footnotesize 
8491 \SpecialChar ~
8492 \SpecialChar ~
8493 mov r4,#0x00
8494 \layout Standard
8495
8496
8497 \size footnotesize 
8498 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
8499 \layout Standard
8500
8501
8502 \size footnotesize 
8503 \SpecialChar ~
8504 \SpecialChar ~
8505 mov r5,#0x0A
8506 \layout Standard
8507
8508
8509 \size footnotesize 
8510 \SpecialChar ~
8511 \SpecialChar ~
8512 mov r6,#0x00
8513 \layout Standard
8514
8515
8516 \size footnotesize 
8517 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
8518 \layout Standard
8519
8520
8521 \size footnotesize 
8522 \SpecialChar ~
8523 \SpecialChar ~
8524 mov r7,#0x1E
8525 \layout Standard
8526
8527
8528 \size footnotesize 
8529 \SpecialChar ~
8530 \SpecialChar ~
8531 mov r0,#0x00
8532 \layout Standard
8533
8534
8535 \size footnotesize 
8536 ; _forcond_0($4) :
8537 \layout Standard
8538
8539
8540 \size footnotesize 
8541 00104$:
8542 \layout Standard
8543
8544
8545 \size footnotesize 
8546 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
8547 \layout Standard
8548
8549
8550 \size footnotesize 
8551 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
8552 \layout Standard
8553
8554
8555 \size footnotesize 
8556 \SpecialChar ~
8557 \SpecialChar ~
8558 clr c
8559 \layout Standard
8560
8561
8562 \size footnotesize 
8563 \SpecialChar ~
8564 \SpecialChar ~
8565 mov a,r4
8566 \layout Standard
8567
8568
8569 \size footnotesize 
8570 \SpecialChar ~
8571 \SpecialChar ~
8572 xrl a,#0x80
8573 \layout Standard
8574
8575
8576 \size footnotesize 
8577 \SpecialChar ~
8578 \SpecialChar ~
8579 subb a,#0x8a
8580 \layout Standard
8581
8582
8583 \size footnotesize 
8584 \SpecialChar ~
8585 \SpecialChar ~
8586 jnc 00107$
8587 \layout Standard
8588
8589
8590 \size footnotesize 
8591 00115$:
8592 \layout Standard
8593
8594
8595 \size footnotesize 
8596 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
8597 \layout Standard
8598
8599
8600 \size footnotesize 
8601 ; iTemp21 [lr21:38]{short}[r4]
8602 \layout Standard
8603
8604
8605 \size footnotesize 
8606 \SpecialChar ~
8607 \SpecialChar ~
8608 mov a,r4
8609 \layout Standard
8610
8611
8612 \size footnotesize 
8613 \SpecialChar ~
8614 \SpecialChar ~
8615 add a,r2
8616 \layout Standard
8617
8618
8619 \size footnotesize 
8620 \SpecialChar ~
8621 \SpecialChar ~
8622 mov r2,a
8623 \layout Standard
8624
8625
8626 \size footnotesize 
8627 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
8628 \layout Standard
8629
8630
8631 \size footnotesize 
8632 \SpecialChar ~
8633 \SpecialChar ~
8634 mov b,#0x03
8635 \layout Standard
8636
8637
8638 \size footnotesize 
8639 \SpecialChar ~
8640 \SpecialChar ~
8641 mov a,r4
8642 \layout Standard
8643
8644
8645 \size footnotesize 
8646 \SpecialChar ~
8647 \SpecialChar ~
8648 mul ab
8649 \layout Standard
8650
8651
8652 \size footnotesize 
8653 \SpecialChar ~
8654 \SpecialChar ~
8655 mov r1,a
8656 \layout Standard
8657
8658
8659 \size footnotesize 
8660 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
8661 \layout Standard
8662
8663
8664 \size footnotesize 
8665 ; iTemp15 [lr29:30]{short}[r1]
8666 \layout Standard
8667
8668
8669 \size footnotesize 
8670 \SpecialChar ~
8671 \SpecialChar ~
8672 add a,r3
8673 \layout Standard
8674
8675
8676 \size footnotesize 
8677 \SpecialChar ~
8678 \SpecialChar ~
8679 mov r3,a
8680 \layout Standard
8681
8682
8683 \size footnotesize 
8684 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
8685 \layout Standard
8686
8687
8688 \size footnotesize 
8689 \SpecialChar ~
8690 \SpecialChar ~
8691 mov a,r7
8692 \layout Standard
8693
8694
8695 \size footnotesize 
8696 \SpecialChar ~
8697 \SpecialChar ~
8698 add a,#0xfd
8699 \layout Standard
8700
8701
8702 \size footnotesize 
8703 \SpecialChar ~
8704 \SpecialChar ~
8705 mov r7,a
8706 \layout Standard
8707
8708
8709 \size footnotesize 
8710 \SpecialChar ~
8711 \SpecialChar ~
8712 mov a,r0
8713 \layout Standard
8714
8715
8716 \size footnotesize 
8717 \SpecialChar ~
8718 \SpecialChar ~
8719 addc a,#0xff
8720 \layout Standard
8721
8722
8723 \size footnotesize 
8724 \SpecialChar ~
8725 \SpecialChar ~
8726 mov r0,a
8727 \layout Standard
8728
8729
8730 \size footnotesize 
8731 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
8732 \layout Standard
8733
8734
8735 \size footnotesize 
8736 \SpecialChar ~
8737 \SpecialChar ~
8738 mov a,r7
8739 \layout Standard
8740
8741
8742 \size footnotesize 
8743 \SpecialChar ~
8744 \SpecialChar ~
8745 add a,_gint
8746 \layout Standard
8747
8748
8749 \size footnotesize 
8750 \SpecialChar ~
8751 \SpecialChar ~
8752 mov _gint,a
8753 \layout Standard
8754
8755
8756 \size footnotesize 
8757 \SpecialChar ~
8758 \SpecialChar ~
8759 mov a,r0
8760 \layout Standard
8761
8762
8763 \size footnotesize 
8764 \SpecialChar ~
8765 \SpecialChar ~
8766 addc a,(_gint + 1)
8767 \layout Standard
8768
8769
8770 \size footnotesize 
8771 \SpecialChar ~
8772 \SpecialChar ~
8773 mov (_gint + 1),a
8774 \layout Standard
8775
8776
8777 \size footnotesize 
8778 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
8779 \layout Standard
8780
8781
8782 \size footnotesize 
8783 \SpecialChar ~
8784 \SpecialChar ~
8785 inc r4
8786 \layout Standard
8787
8788
8789 \size footnotesize 
8790 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
8791 \layout Standard
8792
8793
8794 \size footnotesize 
8795 \SpecialChar ~
8796 \SpecialChar ~
8797 dec r5
8798 \layout Standard
8799
8800
8801 \size footnotesize 
8802 \SpecialChar ~
8803 \SpecialChar ~
8804 cjne r5,#0xff,00104$
8805 \layout Standard
8806
8807
8808 \size footnotesize 
8809 \SpecialChar ~
8810 \SpecialChar ~
8811 dec r6
8812 \layout Standard
8813
8814
8815 \size footnotesize 
8816 ; goto _forcond_0($4)
8817 \layout Standard
8818
8819
8820 \size footnotesize 
8821 \SpecialChar ~
8822 \SpecialChar ~
8823 sjmp 00104$
8824 \layout Standard
8825
8826
8827 \size footnotesize 
8828 ; _forbreak_0($7) :
8829 \layout Standard
8830
8831
8832 \size footnotesize 
8833 00107$:
8834 \layout Standard
8835
8836
8837 \size footnotesize 
8838 ; ret iTemp24 [lr40:41]{short}
8839 \layout Standard
8840
8841
8842 \size footnotesize 
8843 \SpecialChar ~
8844 \SpecialChar ~
8845 mov a,r3
8846 \layout Standard
8847
8848
8849 \size footnotesize 
8850 \SpecialChar ~
8851 \SpecialChar ~
8852 add a,r2
8853 \layout Standard
8854
8855
8856 \size footnotesize 
8857 \SpecialChar ~
8858 \SpecialChar ~
8859 mov dpl,a
8860 \layout Standard
8861
8862
8863 \size footnotesize 
8864 ; _return($8) :
8865 \layout Standard
8866
8867
8868 \size footnotesize 
8869 00108$:
8870 \layout Standard
8871
8872
8873 \size footnotesize 
8874 \SpecialChar ~
8875 \SpecialChar ~
8876 ret
8877 \size default 
8878
8879 \newline 
8880
8881 \layout Section
8882
8883 Acknowledgments
8884 \layout Standard
8885
8886
8887 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
8888
8889 \end_inset 
8890
8891
8892 \newline 
8893
8894 \newline 
8895
8896 \emph on 
8897 Thanks to all the other volunteer developers who have helped with coding,
8898  testing, web-page creation, distribution sets, etc.
8899  You know who you are :-)
8900 \emph default 
8901
8902 \newline 
8903
8904 \layout Standard
8905
8906 This document was initially written by Sandeep Dutta
8907 \layout Standard
8908
8909 All product names mentioned herein may be trademarks of their respective
8910  companies.
8911  
8912 \layout Standard
8913
8914
8915 \begin_inset LatexCommand \printindex{}
8916
8917 \end_inset 
8918
8919
8920 \the_end