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