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