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