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