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