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