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