Section install and search path fixed
[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  Looks like noise but is most helpfull for debugging the compiler itself.
3452 \layout Subsubsection
3453
3454 Intermediate Dump Options
3455 \layout Standard
3456
3457 The following options are provided for the purpose of retargetting and debugging
3458  the compiler.
3459  These provided a means to dump the intermediate code (iCode) generated
3460  by the compiler in human readable form at various stages of the compilation
3461  process.
3462  
3463 \layout List
3464 \labelwidthstring 00.00.0000
3465
3466
3467 \series bold 
3468 ---dumpraw
3469 \series default 
3470  This option will cause the compiler to dump the intermediate code into
3471  a file of named 
3472 \emph on 
3473 <source filename>.dumpraw
3474 \emph default 
3475  just after the intermediate code has been generated for a function, i.e.
3476  before any optimizations are done.
3477  The basic blocks at this stage ordered in the depth first number, so they
3478  may not be in sequence of execution.
3479 \layout List
3480 \labelwidthstring 00.00.0000
3481
3482
3483 \series bold 
3484 ---dumpgcse
3485 \series default 
3486  Will create a dump of iCode's, after global subexpression elimination,
3487  into a file named 
3488 \emph on 
3489 <source filename>.dumpgcse.
3490 \layout List
3491 \labelwidthstring 00.00.0000
3492
3493
3494 \series bold 
3495 ---dumpdeadcode
3496 \series default 
3497  Will create a dump of iCode's, after deadcode elimination, into a file
3498  named 
3499 \emph on 
3500 <source filename>.dumpdeadcode.
3501 \layout List
3502 \labelwidthstring 00.00.0000
3503
3504
3505 \series bold 
3506 ---dumploop
3507 \series default 
3508 \size large 
3509  
3510 \size default 
3511 Will create a dump of iCode's, after loop optimizations, into a file named
3512  
3513 \emph on 
3514 <source filename>.dumploop.
3515 \layout List
3516 \labelwidthstring 00.00.0000
3517
3518
3519 \series bold 
3520 ---dumprange
3521 \series default 
3522 \size large 
3523  
3524 \size default 
3525 Will create a dump of iCode's, after live range analysis, into a file named
3526  
3527 \emph on 
3528 <source filename>.dumprange.
3529 \layout List
3530 \labelwidthstring 00.00.0000
3531
3532
3533 \series bold 
3534 ---dumlrange
3535 \series default 
3536  Will dump the life ranges for all symbols.
3537 \layout List
3538 \labelwidthstring 00.00.0000
3539
3540
3541 \series bold 
3542 ---dumpregassign
3543 \bar under 
3544  
3545 \series default 
3546 \bar default 
3547 Will create a dump of iCode's, after register assignment, into a file named
3548  
3549 \emph on 
3550 <source filename>.dumprassgn.
3551 \layout List
3552 \labelwidthstring 00.00.0000
3553
3554
3555 \series bold 
3556 ---dumplrange
3557 \series default 
3558  Will create a dump of the live ranges of iTemp's
3559 \layout List
3560 \labelwidthstring 00.00.0000
3561
3562
3563 \series bold 
3564 ---dumpall
3565 \size large 
3566 \bar under 
3567  
3568 \series default 
3569 \size default 
3570 \bar default 
3571 Will cause all the above mentioned dumps to be created.
3572 \layout Subsection
3573
3574 Environment variables
3575 \layout Standard
3576
3577 SDCC recognizes the following environment variables:
3578 \layout List
3579 \labelwidthstring 00.00.0000
3580
3581
3582 \series bold 
3583 SDCC_LEAVE_SIGNALS
3584 \series default 
3585  SDCC installs a signal handler to be able to delete temporary files after
3586  an user break (^C) or an exception.
3587  If this environment variable is set, SDCC won't install the signal handler
3588  in order to be able to debug SDCC.
3589 \layout List
3590 \labelwidthstring 00.00.0000
3591
3592
3593 \series bold 
3594 TMP,\SpecialChar ~
3595 TEMP,\SpecialChar ~
3596 TMPDIR
3597 \series default 
3598  Path, where temporary files will be created.
3599  The order of the variables is the search order.
3600  In a standard *nix environment these variables are not set, and there's
3601  no need to set them.
3602  On Windows it's recommended to set one of them.
3603 \layout List
3604 \labelwidthstring 00.00.0000
3605
3606
3607 \series bold 
3608 (coming\SpecialChar ~
3609 soon:\SpecialChar ~
3610 SDCC_BIN_PATH)
3611 \series default 
3612  Path, see 
3613 \begin_inset Quotes sld
3614 \end_inset 
3615
3616 2.1 Install and search paths
3617 \begin_inset Quotes srd
3618 \end_inset 
3619
3620 .
3621 \layout List
3622 \labelwidthstring 00.00.0000
3623
3624
3625 \series bold 
3626 (coming\SpecialChar ~
3627 soon:\SpecialChar ~
3628 SDCC_INCLUDE_PATH)
3629 \series default 
3630  Path, see 
3631 \begin_inset Quotes sld
3632 \end_inset 
3633
3634 2.1 Install and search paths
3635 \begin_inset Quotes srd
3636 \end_inset 
3637
3638 .
3639 \layout List
3640 \labelwidthstring 00.00.0000
3641
3642
3643 \series bold 
3644 (coming\SpecialChar ~
3645 soon:\SpecialChar ~
3646 SDCC_LIB_PATH)
3647 \series default 
3648  Path, see 
3649 \begin_inset Quotes sld
3650 \end_inset 
3651
3652 2.1 Install and search paths
3653 \begin_inset Quotes srd
3654 \end_inset 
3655
3656 .
3657 \layout List
3658 \labelwidthstring 00.00.0000
3659
3660
3661 \series bold 
3662 SDCCDIR\SpecialChar ~
3663 (soon\SpecialChar ~
3664 replaced\SpecialChar ~
3665 by:\SpecialChar ~
3666 SDCCPATH)
3667 \series default 
3668  Path, see 
3669 \begin_inset Quotes sld
3670 \end_inset 
3671
3672 2.1 Install and search paths
3673 \begin_inset Quotes srd
3674 \end_inset 
3675
3676 .
3677 \layout Standard
3678
3679 There are some more environment variables recognized by SDCC, but these
3680  are solely used for debugging purposes.
3681  They can change or disappear very quickly, and will never be documentated.
3682 \layout Subsection
3683
3684 MCS51/DS390 Storage Class Language Extensions
3685 \layout Standard
3686
3687 In addition to the ANSI storage classes SDCC allows the following MCS51
3688  specific storage classes.
3689 \layout Subsubsection
3690
3691 xdata
3692 \layout Standard
3693
3694 Variables declared with this storage class will be placed in the extern
3695  RAM.
3696  This is the 
3697 \series bold 
3698 default
3699 \series default 
3700  storage class for Large Memory model, e.g.:
3701 \newline 
3702
3703 \newline 
3704
3705 \family typewriter 
3706 xdata unsigned char xduc;
3707 \layout Subsubsection
3708
3709 data
3710 \layout Standard
3711
3712 This is the 
3713 \series bold 
3714 default
3715 \series default 
3716  storage class for Small Memory model.
3717  Variables declared with this storage class will be allocated in the internal
3718  RAM, e.g.:
3719 \newline 
3720
3721 \newline 
3722
3723 \family typewriter 
3724 data int iramdata;
3725 \layout Subsubsection
3726
3727 idata
3728 \layout Standard
3729
3730 Variables declared with this storage class will be allocated into the indirectly
3731  addressable portion of the internal ram of a 8051, e.g.:
3732 \newline 
3733
3734 \newline 
3735
3736 \family typewriter 
3737 idata int idi;
3738 \layout Subsubsection
3739
3740 bit
3741 \layout Standard
3742
3743 This is a data-type and a storage class specifier.
3744  When a variable is declared as a bit, it is allocated into the bit addressable
3745  memory of 8051, e.g.:
3746 \newline 
3747
3748 \newline 
3749
3750 \family typewriter 
3751 bit iFlag;
3752 \layout Subsubsection
3753
3754 sfr / sbit
3755 \layout Standard
3756
3757 Like the bit keyword, 
3758 \emph on 
3759 sfr / sbit 
3760 \emph default 
3761 signifies both a data-type and storage class, they are used to describe
3762  the special function registers and special bit variables of a 8051, eg:
3763 \newline 
3764
3765 \newline 
3766
3767 \family typewriter 
3768 sfr at 0x80 P0; /* special function register P0 at location 0x80 */
3769 \newline 
3770 sbit at 0xd7 CY; /* CY (Carry Flag) */
3771 \layout Subsection
3772
3773 Pointers
3774 \layout Standard
3775
3776 SDCC allows (via language extensions) pointers to explicitly point to any
3777  of the memory spaces of the 8051.
3778  In addition to the explicit pointers, the compiler uses (by default) generic
3779  pointers which can be used to point to any of the memory spaces.
3780 \newline 
3781
3782 \newline 
3783 Pointer declaration examples:
3784 \newline 
3785
3786 \size small 
3787
3788 \newline 
3789
3790 \family typewriter 
3791 \size default 
3792 /* pointer physically in xternal ram pointing to object in internal ram
3793  */ 
3794 \newline 
3795 data unsigned char * xdata p;
3796 \newline 
3797
3798 \newline 
3799 /* pointer physically in code rom pointing to data in xdata space */ 
3800 \newline 
3801 xdata unsigned char * code p;
3802 \newline 
3803
3804 \newline 
3805 /* pointer physically in code space pointing to data in code space */ 
3806 \newline 
3807 code unsigned char * code p;
3808 \newline 
3809
3810 \newline 
3811 /* the folowing is a generic pointer physically located in xdata space */
3812 \newline 
3813 char * xdata p;
3814 \family default 
3815 \size small 
3816
3817 \newline 
3818
3819 \newline 
3820
3821 \size default 
3822 Well you get the idea.
3823  
3824 \newline 
3825
3826 \newline 
3827 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
3828 \emph on 
3829 generic
3830 \emph default 
3831  pointers.
3832  
3833 \size small 
3834
3835 \newline 
3836
3837 \newline 
3838
3839 \size default 
3840 The highest order byte of the 
3841 \emph on 
3842 generic
3843 \emph default 
3844  pointers contains the data space information.
3845  Assembler support routines are called whenever data is stored or retrieved
3846  using 
3847 \emph on 
3848 generic
3849 \emph default 
3850  pointers.
3851  These are useful for developing reusable library routines.
3852  Explicitly specifying the pointer type will generate the most efficient
3853  code.
3854 \layout Subsection
3855
3856 Parameters & Local Variables
3857 \layout Standard
3858
3859 Automatic (local) variables and parameters to functions can either be placed
3860  on the stack or in data-space.
3861  The default action of the compiler is to place these variables in the internal
3862  RAM (for small model) or external RAM (for large model).
3863  This in fact makes them 
3864 \emph on 
3865 static
3866 \emph default 
3867  so by default functions are non-reentrant.
3868 \newline 
3869
3870 \newline 
3871 They can be placed on the stack either by using the
3872 \emph on 
3873  ---stack-auto
3874 \emph default 
3875  option or by using the 
3876 \emph on 
3877 reentrant
3878 \emph default 
3879  keyword in the function declaration, e.g.:
3880 \newline 
3881
3882 \size small 
3883
3884 \newline 
3885
3886 \family typewriter 
3887 \size default 
3888 unsigned char foo(char i) reentrant 
3889 \newline 
3890
3891 \newline 
3892 ...
3893  
3894 \newline 
3895 }
3896 \newline 
3897
3898 \family default 
3899
3900 \newline 
3901 Since stack space on 8051 is limited, the 
3902 \emph on 
3903 reentrant 
3904 \emph default 
3905 keyword or the
3906 \emph on 
3907  ---stack-auto
3908 \emph default 
3909  option should be used sparingly.
3910  Note that the reentrant keyword just means that the parameters & local
3911  variables will be allocated to the stack, it 
3912 \emph on 
3913 does not
3914 \emph default 
3915  mean that the function is register bank independent.
3916 \newline 
3917
3918 \newline 
3919 Local variables can be assigned storage classes and absolute addresses,
3920  e.g.: 
3921 \newline 
3922
3923 \newline 
3924
3925 \family typewriter 
3926 unsigned char foo() {
3927 \newline 
3928 \SpecialChar ~
3929 \SpecialChar ~
3930 \SpecialChar ~
3931 \SpecialChar ~
3932 xdata unsigned char i;
3933 \newline 
3934 \SpecialChar ~
3935 \SpecialChar ~
3936 \SpecialChar ~
3937 \SpecialChar ~
3938 bit bvar;
3939 \newline 
3940 \SpecialChar ~
3941 \SpecialChar ~
3942 \SpecialChar ~
3943 \SpecialChar ~
3944 data at 0x31 unsiged char j;
3945 \newline 
3946 \SpecialChar ~
3947 \SpecialChar ~
3948 \SpecialChar ~
3949 \SpecialChar ~
3950 ...
3951  
3952 \newline 
3953 }
3954 \newline 
3955
3956 \newline 
3957
3958 \family default 
3959 In the above example the variable 
3960 \emph on 
3961 i
3962 \emph default 
3963  will be allocated in the external ram, 
3964 \emph on 
3965 bvar
3966 \emph default 
3967  in bit addressable space and
3968 \emph on 
3969  j
3970 \emph default 
3971  in internal ram.
3972  When compiled with 
3973 \emph on 
3974 ---stack-auto
3975 \emph default 
3976  or when a function is declared as 
3977 \emph on 
3978 reentrant
3979 \emph default 
3980  this should only be done for static variables.
3981 \layout Standard
3982
3983 Parameters however are not allowed any storage class, (storage classes for
3984  parameters will be ignored), their allocation is governed by the memory
3985  model in use, and the reentrancy options.
3986 \layout Subsection
3987
3988 Overlaying
3989 \layout Standard
3990
3991 For non-reentrant functions SDCC will try to reduce internal ram space usage
3992  by overlaying parameters and local variables of a function (if possible).
3993  Parameters and local variables of a function will be allocated to an overlayabl
3994 e segment if the function has 
3995 \emph on 
3996 no other function calls and the function is non-reentrant and the memory
3997  model is small.
3998
3999 \emph default 
4000  If an explicit storage class is specified for a local variable, it will
4001  NOT be overlayed.
4002 \layout Standard
4003
4004 Note that the compiler (not the linkage editor) makes the decision for overlayin
4005 g the data items.
4006  Functions that are called from an interrupt service routine should be preceded
4007  by a #pragma\SpecialChar ~
4008 NOOVERLAY if they are not reentrant.
4009 \layout Standard
4010
4011 Also note that the compiler does not do any processing of inline assembler
4012  code, so the compiler might incorrectly assign local variables and parameters
4013  of a function into the overlay segment if the inline assembler code calls
4014  other c-functions that might use the overlay.
4015  In that case the #pragma\SpecialChar ~
4016 NOOVERLAY should be used.
4017 \layout Standard
4018
4019 Parameters and Local variables of functions that contain 16 or 32 bit multiplica
4020 tion or division will NOT be overlayed since these are implemented using
4021  external functions, e.g.:
4022 \newline 
4023
4024 \newline 
4025
4026 \family typewriter 
4027 #pragma SAVE 
4028 \newline 
4029 #pragma NOOVERLAY 
4030 \newline 
4031 void set_error(unsigned char errcd) 
4032 \newline 
4033 {
4034 \newline 
4035 \SpecialChar ~
4036 \SpecialChar ~
4037 \SpecialChar ~
4038 \SpecialChar ~
4039 P3 = errcd;
4040 \newline 
4041
4042 \newline 
4043 #pragma RESTORE 
4044 \newline 
4045
4046 \newline 
4047 void some_isr () interrupt 2 using 1 
4048 \newline 
4049 {
4050 \newline 
4051 \SpecialChar ~
4052 \SpecialChar ~
4053 \SpecialChar ~
4054 \SpecialChar ~
4055 ...
4056 \newline 
4057 \SpecialChar ~
4058 \SpecialChar ~
4059 \SpecialChar ~
4060 \SpecialChar ~
4061 set_error(10);
4062 \newline 
4063 \SpecialChar ~
4064 \SpecialChar ~
4065 \SpecialChar ~
4066 \SpecialChar ~
4067 ...
4068  
4069 \newline 
4070 }
4071 \newline 
4072
4073 \newline 
4074
4075 \family default 
4076 In the above example the parameter 
4077 \emph on 
4078 errcd
4079 \emph default 
4080  for the function 
4081 \emph on 
4082 set_error
4083 \emph default 
4084  would be assigned to the overlayable segment if the #pragma\SpecialChar ~
4085 NOOVERLAY was
4086  not present, this could cause unpredictable runtime behavior when called
4087  from an ISR.
4088  The #pragma\SpecialChar ~
4089 NOOVERLAY ensures that the parameters and local variables for
4090  the function are NOT overlayed.
4091 \layout Subsection
4092
4093 Interrupt Service Routines
4094 \layout Standard
4095
4096 SDCC allows interrupt service routines to be coded in C, with some extended
4097  keywords.
4098 \newline 
4099
4100 \newline 
4101
4102 \family typewriter 
4103 void timer_isr (void) interrupt 2 using 1 
4104 \newline 
4105
4106 \newline 
4107 ..
4108  
4109 \newline 
4110 }
4111 \newline 
4112
4113 \newline 
4114
4115 \family default 
4116 The number following the 
4117 \emph on 
4118 interrupt
4119 \emph default 
4120  keyword is the interrupt number this routine will service.
4121  The compiler will insert a call to this routine in the interrupt vector
4122  table for the interrupt number specified.
4123  The 
4124 \emph on 
4125 using
4126 \emph default 
4127  keyword is used to tell the compiler to use the specified register bank
4128  (8051 specific) when generating code for this function.
4129  Note that when some function is called from an interrupt service routine
4130  it should be preceded by a #pragma\SpecialChar ~
4131 NOOVERLAY if it is not reentrant.
4132  A special note here, int (16 bit) and long (32 bit) integer division, multiplic
4133 ation & modulus operations are implemented using external support routines
4134  developed in ANSI-C, if an interrupt service routine needs to do any of
4135  these operations then the support routines (as mentioned in a following
4136  section) will have to be recompiled using the
4137 \emph on 
4138  ---stack-auto
4139 \emph default 
4140  option and the source file will need to be compiled using the 
4141 \emph on 
4142 ---int-long-ren
4143 \emph default 
4144 t compiler option.
4145 \layout Standard
4146
4147 If you have multiple source files in your project, interrupt service routines
4148  can be present in any of them, but a prototype of the isr MUST be present
4149  or included in the file that contains the function 
4150 \emph on 
4151 main
4152 \emph default 
4153 .
4154 \layout Standard
4155
4156 Interrupt Numbers and the corresponding address & descriptions for the Standard
4157  8051 are listed below.
4158  SDCC will automatically adjust the interrupt vector table to the maximum
4159  interrupt number specified.
4160 \newline 
4161
4162 \layout Standard
4163
4164
4165 \begin_inset  Tabular
4166 <lyxtabular version="3" rows="6" columns="3">
4167 <features>
4168 <column alignment="center" valignment="top" leftline="true" width="0pt">
4169 <column alignment="center" valignment="top" leftline="true" width="0pt">
4170 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
4171 <row topline="true" bottomline="true">
4172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4173 \begin_inset Text
4174
4175 \layout Standard
4176
4177 Interrupt #
4178 \end_inset 
4179 </cell>
4180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4181 \begin_inset Text
4182
4183 \layout Standard
4184
4185 Description
4186 \end_inset 
4187 </cell>
4188 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4189 \begin_inset Text
4190
4191 \layout Standard
4192
4193 Vector Address
4194 \end_inset 
4195 </cell>
4196 </row>
4197 <row topline="true">
4198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4199 \begin_inset Text
4200
4201 \layout Standard
4202
4203 0
4204 \end_inset 
4205 </cell>
4206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4207 \begin_inset Text
4208
4209 \layout Standard
4210
4211 External 0
4212 \end_inset 
4213 </cell>
4214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4215 \begin_inset Text
4216
4217 \layout Standard
4218
4219 0x0003
4220 \end_inset 
4221 </cell>
4222 </row>
4223 <row topline="true">
4224 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4225 \begin_inset Text
4226
4227 \layout Standard
4228
4229 1
4230 \end_inset 
4231 </cell>
4232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4233 \begin_inset Text
4234
4235 \layout Standard
4236
4237 Timer 0
4238 \end_inset 
4239 </cell>
4240 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4241 \begin_inset Text
4242
4243 \layout Standard
4244
4245 0x000B
4246 \end_inset 
4247 </cell>
4248 </row>
4249 <row topline="true">
4250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4251 \begin_inset Text
4252
4253 \layout Standard
4254
4255 2
4256 \end_inset 
4257 </cell>
4258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4259 \begin_inset Text
4260
4261 \layout Standard
4262
4263 External 1
4264 \end_inset 
4265 </cell>
4266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4267 \begin_inset Text
4268
4269 \layout Standard
4270
4271 0x0013
4272 \end_inset 
4273 </cell>
4274 </row>
4275 <row topline="true">
4276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4277 \begin_inset Text
4278
4279 \layout Standard
4280
4281 3
4282 \end_inset 
4283 </cell>
4284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4285 \begin_inset Text
4286
4287 \layout Standard
4288
4289 Timer 1
4290 \end_inset 
4291 </cell>
4292 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4293 \begin_inset Text
4294
4295 \layout Standard
4296
4297 0x001B
4298 \end_inset 
4299 </cell>
4300 </row>
4301 <row topline="true" bottomline="true">
4302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4303 \begin_inset Text
4304
4305 \layout Standard
4306
4307 4
4308 \end_inset 
4309 </cell>
4310 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4311 \begin_inset Text
4312
4313 \layout Standard
4314
4315 Serial
4316 \end_inset 
4317 </cell>
4318 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4319 \begin_inset Text
4320
4321 \layout Standard
4322
4323 0x0023
4324 \end_inset 
4325 </cell>
4326 </row>
4327 </lyxtabular>
4328
4329 \end_inset 
4330
4331
4332 \newline 
4333
4334 \newline 
4335 If the interrupt service routine is defined without 
4336 \emph on 
4337 using
4338 \emph default 
4339  a register bank or with register bank 0 (using 0), the compiler will save
4340  the registers used by itself on the stack upon entry and restore them at
4341  exit, however if such an interrupt service routine calls another function
4342  then the entire register bank will be saved on the stack.
4343  This scheme may be advantageous for small interrupt service routines which
4344  have low register usage.
4345 \layout Standard
4346
4347 If the interrupt service routine is defined to be using a specific register
4348  bank then only 
4349 \emph on 
4350 a, b & dptr
4351 \emph default 
4352  are save and restored, if such an interrupt service routine calls another
4353  function (using another register bank) then the entire register bank of
4354  the called function will be saved on the stack.
4355  This scheme is recommended for larger interrupt service routines.
4356 \layout Standard
4357
4358 Calling other functions from an interrupt service routine is not recommended,
4359  avoid it if possible.
4360 \newline 
4361
4362 \newline 
4363 Also see the _naked modifier.
4364 \layout Subsection
4365
4366 Critical Functions
4367 \layout Standard
4368
4369
4370 \shape italic 
4371 <TODO: this isn't implemented at all!>
4372 \shape default 
4373
4374 \newline 
4375
4376 \newline 
4377 A special keyword may be associated with a function declaring it as 
4378 \emph on 
4379 critical
4380 \emph default 
4381 .
4382  SDCC will generate code to disable all interrupts upon entry to a critical
4383  function and enable them back before returning.
4384  Note that nesting critical functions may cause unpredictable results.
4385 \newline 
4386
4387 \size small 
4388
4389 \newline 
4390
4391 \family typewriter 
4392 \size default 
4393 int foo () critical 
4394 \newline 
4395
4396 \newline 
4397 ...
4398  
4399 \newline 
4400 ...
4401  
4402 \newline 
4403 }
4404 \newline 
4405
4406 \family default 
4407
4408 \newline 
4409 The critical attribute maybe used with other attributes like 
4410 \emph on 
4411 reentrant.
4412 \layout Subsection
4413
4414 Naked Functions
4415 \layout Standard
4416
4417 A special keyword may be associated with a function declaring it as 
4418 \emph on 
4419 _naked.
4420  
4421 \emph default 
4422 The 
4423 \emph on 
4424 _naked
4425 \emph default 
4426  function modifier attribute prevents the compiler from generating prologue
4427  and epilogue code for that function.
4428  This means that the user is entirely responsible for such things as saving
4429  any registers that may need to be preserved, selecting the proper register
4430  bank, generating the 
4431 \emph on 
4432 return
4433 \emph default 
4434  instruction at the end, etc.
4435  Practically, this means that the contents of the function must be written
4436  in inline assembler.
4437  This is particularly useful for interrupt functions, which can have a large
4438  (and often unnecessary) prologue/epilogue.
4439  For example, compare the code generated by these two functions:
4440 \newline 
4441
4442 \newline 
4443
4444 \family typewriter 
4445 data unsigned char counter;
4446 \newline 
4447 void simpleInterrupt(void) interrupt 1
4448 \newline 
4449 {
4450 \newline 
4451 \SpecialChar ~
4452 \SpecialChar ~
4453 \SpecialChar ~
4454 \SpecialChar ~
4455 counter++;
4456 \newline 
4457 }
4458 \newline 
4459
4460 \newline 
4461 void nakedInterrupt(void) interrupt 2 _naked
4462 \newline 
4463 {
4464 \newline 
4465 \SpecialChar ~
4466 \SpecialChar ~
4467 \SpecialChar ~
4468 \SpecialChar ~
4469 _asm
4470 \newline 
4471 \SpecialChar ~
4472 \SpecialChar ~
4473 \SpecialChar ~
4474 \SpecialChar ~
4475 \SpecialChar ~
4476 \SpecialChar ~
4477 inc\SpecialChar ~
4478 \SpecialChar ~
4479 \SpecialChar ~
4480 \SpecialChar ~
4481 \SpecialChar ~
4482 _counter
4483 \newline 
4484 \SpecialChar ~
4485 \SpecialChar ~
4486 \SpecialChar ~
4487 \SpecialChar ~
4488 \SpecialChar ~
4489 \SpecialChar ~
4490 reti\SpecialChar ~
4491 \SpecialChar ~
4492 \SpecialChar ~
4493 \SpecialChar ~
4494 ; MUST explicitly include ret in _naked function.
4495 \newline 
4496 \SpecialChar ~
4497 \SpecialChar ~
4498 \SpecialChar ~
4499 \SpecialChar ~
4500 _endasm;
4501 \newline 
4502 }
4503 \family default 
4504
4505 \newline 
4506
4507 \newline 
4508 For an 8051 target, the generated simpleInterrupt looks like:
4509 \newline 
4510
4511 \newline 
4512
4513 \family typewriter 
4514 _simpleIterrupt:
4515 \newline 
4516 \SpecialChar ~
4517 \SpecialChar ~
4518 \SpecialChar ~
4519 \SpecialChar ~
4520 push\SpecialChar ~
4521 \SpecialChar ~
4522 \SpecialChar ~
4523 \SpecialChar ~
4524 acc
4525 \newline 
4526 \SpecialChar ~
4527 \SpecialChar ~
4528 \SpecialChar ~
4529 \SpecialChar ~
4530 push\SpecialChar ~
4531 \SpecialChar ~
4532 \SpecialChar ~
4533 \SpecialChar ~
4534 b
4535 \newline 
4536 \SpecialChar ~
4537 \SpecialChar ~
4538 \SpecialChar ~
4539 \SpecialChar ~
4540 push\SpecialChar ~
4541 \SpecialChar ~
4542 \SpecialChar ~
4543 \SpecialChar ~
4544 dpl
4545 \newline 
4546 \SpecialChar ~
4547 \SpecialChar ~
4548 \SpecialChar ~
4549 \SpecialChar ~
4550 push\SpecialChar ~
4551 \SpecialChar ~
4552 \SpecialChar ~
4553 \SpecialChar ~
4554 dph
4555 \newline 
4556 \SpecialChar ~
4557 \SpecialChar ~
4558 \SpecialChar ~
4559 \SpecialChar ~
4560 push\SpecialChar ~
4561 \SpecialChar ~
4562 \SpecialChar ~
4563 \SpecialChar ~
4564 psw
4565 \newline 
4566 \SpecialChar ~
4567 \SpecialChar ~
4568 \SpecialChar ~
4569 \SpecialChar ~
4570 mov\SpecialChar ~
4571 \SpecialChar ~
4572 \SpecialChar ~
4573 \SpecialChar ~
4574 \SpecialChar ~
4575 psw,#0x00
4576 \newline 
4577 \SpecialChar ~
4578 \SpecialChar ~
4579 \SpecialChar ~
4580 \SpecialChar ~
4581 inc\SpecialChar ~
4582 \SpecialChar ~
4583 \SpecialChar ~
4584 \SpecialChar ~
4585 \SpecialChar ~
4586 _counter
4587 \newline 
4588 \SpecialChar ~
4589 \SpecialChar ~
4590 \SpecialChar ~
4591 \SpecialChar ~
4592 pop\SpecialChar ~
4593 \SpecialChar ~
4594 \SpecialChar ~
4595 \SpecialChar ~
4596 \SpecialChar ~
4597 psw
4598 \newline 
4599 \SpecialChar ~
4600 \SpecialChar ~
4601 \SpecialChar ~
4602 \SpecialChar ~
4603 pop\SpecialChar ~
4604 \SpecialChar ~
4605 \SpecialChar ~
4606 \SpecialChar ~
4607 \SpecialChar ~
4608 dph
4609 \newline 
4610 \SpecialChar ~
4611 \SpecialChar ~
4612 \SpecialChar ~
4613 \SpecialChar ~
4614 pop\SpecialChar ~
4615 \SpecialChar ~
4616 \SpecialChar ~
4617 \SpecialChar ~
4618 \SpecialChar ~
4619 dpl
4620 \newline 
4621 \SpecialChar ~
4622 \SpecialChar ~
4623 \SpecialChar ~
4624 \SpecialChar ~
4625 pop\SpecialChar ~
4626 \SpecialChar ~
4627 \SpecialChar ~
4628 \SpecialChar ~
4629 \SpecialChar ~
4630 b
4631 \newline 
4632 \SpecialChar ~
4633 \SpecialChar ~
4634 \SpecialChar ~
4635 \SpecialChar ~
4636 pop\SpecialChar ~
4637 \SpecialChar ~
4638 \SpecialChar ~
4639 \SpecialChar ~
4640 \SpecialChar ~
4641 acc
4642 \newline 
4643 \SpecialChar ~
4644 \SpecialChar ~
4645 \SpecialChar ~
4646 \SpecialChar ~
4647 reti
4648 \family default 
4649
4650 \newline 
4651
4652 \newline 
4653 whereas nakedInterrupt looks like:
4654 \newline 
4655
4656 \newline 
4657
4658 \family typewriter 
4659 _nakedInterrupt:
4660 \newline 
4661 \SpecialChar ~
4662 \SpecialChar ~
4663 \SpecialChar ~
4664 \SpecialChar ~
4665 inc\SpecialChar ~
4666 \SpecialChar ~
4667 \SpecialChar ~
4668 \SpecialChar ~
4669 _counter
4670 \newline 
4671 \SpecialChar ~
4672 \SpecialChar ~
4673 \SpecialChar ~
4674 \SpecialChar ~
4675 reti\SpecialChar ~
4676 \SpecialChar ~
4677 \SpecialChar ~
4678 ; MUST explicitly include ret(i) in _naked function.
4679 \family default 
4680
4681 \newline 
4682
4683 \newline 
4684 While there is nothing preventing you from writing C code inside a _naked
4685  function, there are many ways to shoot yourself in the foot doing this,
4686  and it is recommended that you stick to inline assembler.
4687 \layout Subsection
4688
4689 Functions using private banks
4690 \layout Standard
4691
4692 The 
4693 \emph on 
4694 using
4695 \emph default 
4696  attribute (which tells the compiler to use a register bank other than the
4697  default bank zero) should only be applied to 
4698 \emph on 
4699 interrupt
4700 \emph default 
4701  functions (see note 1 below).
4702  This will in most circumstances make the generated ISR code more efficient
4703  since it will not have to save registers on the stack.
4704 \layout Standard
4705
4706 The 
4707 \emph on 
4708 using
4709 \emph default 
4710  attribute will have no effect on the generated code for a 
4711 \emph on 
4712 non-interrupt
4713 \emph default 
4714  function (but may occasionally be useful anyway
4715 \begin_inset Foot
4716 collapsed true
4717
4718 \layout Standard
4719
4720 possible exception: if a function is called ONLY from 'interrupt' functions
4721  using a particular bank, it can be declared with the same 'using' attribute
4722  as the calling 'interrupt' functions.
4723  For instance, if you have several ISRs using bank one, and all of them
4724  call memcpy(), it might make sense to create a specialized version of memcpy()
4725  'using 1', since this would prevent the ISR from having to save bank zero
4726  to the stack on entry and switch to bank zero before calling the function
4727 \end_inset 
4728
4729 ).
4730 \newline 
4731
4732 \emph on 
4733 (pending: I don't think this has been done yet)
4734 \layout Standard
4735
4736 An 
4737 \emph on 
4738 interrupt
4739 \emph default 
4740  function using a non-zero bank will assume that it can trash that register
4741  bank, and will not save it.
4742  Since high-priority interrupts can interrupt low-priority ones on the 8051
4743  and friends, this means that if a high-priority ISR 
4744 \emph on 
4745 using
4746 \emph default 
4747  a particular bank occurs while processing a low-priority ISR 
4748 \emph on 
4749 using
4750 \emph default 
4751  the same bank, terrible and bad things can happen.
4752  To prevent this, no single register bank should be 
4753 \emph on 
4754 used
4755 \emph default 
4756  by both a high priority and a low priority ISR.
4757  This is probably most easily done by having all high priority ISRs use
4758  one bank and all low priority ISRs use another.
4759  If you have an ISR which can change priority at runtime, you're on your
4760  own: I suggest using the default bank zero and taking the small performance
4761  hit.
4762 \layout Standard
4763
4764 It is most efficient if your ISR calls no other functions.
4765  If your ISR must call other functions, it is most efficient if those functions
4766  use the same bank as the ISR (see note 1 below); the next best is if the
4767  called functions use bank zero.
4768  It is very inefficient to call a function using a different, non-zero bank
4769  from an ISR.
4770  
4771 \layout Subsection
4772
4773 Absolute Addressing
4774 \layout Standard
4775
4776 Data items can be assigned an absolute address with the 
4777 \emph on 
4778 at <address>
4779 \emph default 
4780  keyword, in addition to a storage class, e.g.:
4781 \newline 
4782
4783 \newline 
4784
4785 \family typewriter 
4786 xdata at 0x8000 unsigned char PORTA_8255 ;
4787 \newline 
4788
4789 \family default 
4790
4791 \newline 
4792 In the above example the PORTA_8255 will be allocated to the location 0x8000
4793  of the external ram.
4794  Note that this feature is provided to give the programmer access to 
4795 \emph on 
4796 memory mapped
4797 \emph default 
4798  devices attached to the controller.
4799  The compiler does not actually reserve any space for variables declared
4800  in this way (they are implemented with an equate in the assembler).
4801  Thus it is left to the programmer to make sure there are no overlaps with
4802  other variables that are declared without the absolute address.
4803  The assembler listing file (.lst) and the linker output files (.rst) and
4804  (.map) are a good places to look for such overlaps.
4805 \newline 
4806
4807 \newline 
4808 Absolute address can be specified for variables in all storage classes,
4809  e.g.:
4810 \newline 
4811
4812 \newline 
4813
4814 \family typewriter 
4815 bit at 0x02 bvar;
4816 \newline 
4817
4818 \newline 
4819
4820 \family default 
4821 The above example will allocate the variable at offset 0x02 in the bit-addressab
4822 le space.
4823  There is no real advantage to assigning absolute addresses to variables
4824  in this manner, unless you want strict control over all the variables allocated.
4825 \layout Subsection
4826
4827 Startup Code
4828 \layout Standard
4829
4830 The compiler inserts a call to the C routine 
4831 \emph on 
4832 _sdcc__external__startup()
4833 \series bold 
4834 \emph default 
4835  
4836 \series default 
4837 at the start of the CODE area.
4838  This routine is in the runtime library.
4839  By default this routine returns 0, if this routine returns a non-zero value,
4840  the static & global variable initialization will be skipped and the function
4841  main will be invoked Other wise static & global variables will be initialized
4842  before the function main is invoked.
4843  You could add a 
4844 \emph on 
4845 _sdcc__external__startup()
4846 \emph default 
4847  routine to your program to override the default if you need to setup hardware
4848  or perform some other critical operation prior to static & global variable
4849  initialization.
4850 \layout Subsection
4851
4852 Inline Assembler Code
4853 \layout Standard
4854
4855 SDCC allows the use of in-line assembler with a few restriction as regards
4856  labels.
4857  All labels defined within inline assembler code 
4858 \emph on 
4859 has to be
4860 \emph default 
4861  of the form 
4862 \emph on 
4863 nnnnn$
4864 \emph default 
4865  where nnnn is a number less than 100 (which implies a limit of utmost 100
4866  inline assembler labels 
4867 \emph on 
4868 per function
4869 \emph default 
4870 \noun on 
4871 )
4872 \noun default 
4873 .
4874  It is strongly recommended that each assembly instruction (including labels)
4875  be placed in a separate line (as the example shows).
4876  When the 
4877 \emph on 
4878 ---peep-asm
4879 \emph default 
4880  command line option is used, the inline assembler code will be passed through
4881  the peephole optimizer.
4882  This might cause some unexpected changes in the inline assembler code.
4883  Please go throught the peephole optimizer rules defined in file 
4884 \emph on 
4885 SDCCpeeph.def
4886 \emph default 
4887  carefully before using this option.
4888 \newline 
4889
4890 \newline 
4891
4892 \family typewriter 
4893 _asm 
4894 \newline 
4895 \SpecialChar ~
4896 \SpecialChar ~
4897 \SpecialChar ~
4898 \SpecialChar ~
4899 mov\SpecialChar ~
4900 \SpecialChar ~
4901 \SpecialChar ~
4902 \SpecialChar ~
4903 \SpecialChar ~
4904 b,#10 
4905 \newline 
4906 00001$: 
4907 \newline 
4908 \SpecialChar ~
4909 \SpecialChar ~
4910 \SpecialChar ~
4911 \SpecialChar ~
4912 djnz\SpecialChar ~
4913 \SpecialChar ~
4914 \SpecialChar ~
4915 \SpecialChar ~
4916 b,00001$ 
4917 \newline 
4918 _endasm ;
4919 \family default 
4920 \size small 
4921
4922 \newline 
4923
4924 \newline 
4925
4926 \size default 
4927 The inline assembler code can contain any valid code understood by the assembler
4928 , this includes any assembler directives and comment lines.
4929  The compiler does not do any validation of the code within the 
4930 \family typewriter 
4931 _asm ...
4932  _endasm;
4933 \family default 
4934  keyword pair.
4935  
4936 \newline 
4937
4938 \newline 
4939 Inline assembler code cannot reference any C-Labels, however it can reference
4940  labels defined by the inline assembler, e.g.:
4941 \newline 
4942
4943 \newline 
4944
4945 \family typewriter 
4946 foo() { 
4947 \newline 
4948 \SpecialChar ~
4949 \SpecialChar ~
4950 \SpecialChar ~
4951 \SpecialChar ~
4952 /* some c code */ 
4953 \newline 
4954 \SpecialChar ~
4955 \SpecialChar ~
4956 \SpecialChar ~
4957 \SpecialChar ~
4958 _asm 
4959 \newline 
4960 \SpecialChar ~
4961 \SpecialChar ~
4962 \SpecialChar ~
4963 \SpecialChar ~
4964 \SpecialChar ~
4965 \SpecialChar ~
4966 ; some assembler code 
4967 \newline 
4968 \SpecialChar ~
4969 \SpecialChar ~
4970 \SpecialChar ~
4971 \SpecialChar ~
4972 \SpecialChar ~
4973 \SpecialChar ~
4974 ljmp $0003 
4975 \newline 
4976 \SpecialChar ~
4977 \SpecialChar ~
4978 \SpecialChar ~
4979 \SpecialChar ~
4980 _endasm; 
4981 \newline 
4982 \SpecialChar ~
4983 \SpecialChar ~
4984 \SpecialChar ~
4985 \SpecialChar ~
4986 /* some more c code */ 
4987 \newline 
4988 clabel:\SpecialChar ~
4989 \SpecialChar ~
4990 /* inline assembler cannot reference this label */ 
4991 \newline 
4992 \SpecialChar ~
4993 \SpecialChar ~
4994 \SpecialChar ~
4995 \SpecialChar ~
4996 _asm
4997 \newline 
4998 \SpecialChar ~
4999 \SpecialChar ~
5000 \SpecialChar ~
5001 \SpecialChar ~
5002 $0003: ;label (can be reference by inline assembler only) 
5003 \newline 
5004 \SpecialChar ~
5005 \SpecialChar ~
5006 \SpecialChar ~
5007 \SpecialChar ~
5008 _endasm ; 
5009 \newline 
5010 \SpecialChar ~
5011 \SpecialChar ~
5012 \SpecialChar ~
5013 \SpecialChar ~
5014 /* some more c code */
5015 \newline 
5016 }
5017 \newline 
5018
5019 \newline 
5020
5021 \family default 
5022 In other words inline assembly code can access labels defined in inline
5023  assembly within the scope of the funtion.
5024  
5025 \layout Standard
5026
5027 The same goes the other way, ie.
5028  labels defines in inline assembly CANNOT be accessed by C statements.
5029 \layout Subsection
5030
5031 int (16 bit) and long (32 bit) Support
5032 \layout Standard
5033
5034 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
5035  multiplication and modulus operations are implemented by support routines.
5036  These support routines are all developed in ANSI-C to facilitate porting
5037  to other MCUs, although some model specific assembler optimations are used.
5038  The following files contain the described routine, all of them can be found
5039  in <installdir>/share/sdcc/lib.
5040 \newline 
5041
5042 \newline 
5043
5044 \emph on 
5045 <pending: tabularise this>
5046 \emph default 
5047
5048 \newline 
5049
5050 \newline 
5051 _mulsint.c - signed 16 bit multiplication (calls _muluint)
5052 \newline 
5053 _muluint.c - unsigned 16 bit multiplication
5054 \newline 
5055 _divsint.c - signed 16 bit division (calls _divuint)
5056 \newline 
5057 _divuint.c - unsigned 16 bit division
5058 \newline 
5059 _modsint.c - signed 16 bit modulus (call _moduint)
5060 \newline 
5061 _moduint.c - unsigned 16 bit modulus
5062 \newline 
5063 _mulslong.c - signed 32 bit multiplication (calls _mululong)
5064 \newline 
5065 _mululong.c - unsigned32 bit multiplication
5066 \newline 
5067 _divslong.c - signed 32 division (calls _divulong)
5068 \newline 
5069 _divulong.c - unsigned 32 division
5070 \newline 
5071 _modslong.c - signed 32 bit modulus (calls _modulong)
5072 \newline 
5073 _modulong.c - unsigned 32 bit modulus 
5074 \size footnotesize 
5075
5076 \newline 
5077
5078 \newline 
5079
5080 \size default 
5081 Since they are compiled as 
5082 \emph on 
5083 non-reentrant
5084 \emph default 
5085 , interrupt service routines should not do any of the above operations.
5086  If this is unavoidable then the above routines will need to be compiled
5087  with the 
5088 \emph on 
5089 ---stack-auto
5090 \emph default 
5091  option, after which the source program will have to be compiled with 
5092 \emph on 
5093 ---int-long-rent
5094 \emph default 
5095  option.
5096 \layout Subsection
5097
5098 Floating Point Support
5099 \layout Standard
5100
5101 SDCC supports IEEE (single precision 4bytes) floating point numbers.The floating
5102  point support routines are derived from gcc's floatlib.c and consists of
5103  the following routines:
5104 \newline 
5105
5106 \newline 
5107
5108 \emph on 
5109 <pending: tabularise this>
5110 \emph default 
5111
5112 \newline 
5113
5114 \newline 
5115 _fsadd.c - add floating point numbers
5116 \newline 
5117 _fssub.c - subtract floating point numbers
5118 \newline 
5119 _fsdiv.c - divide floating point numbers
5120 \newline 
5121 _fsmul.c - multiply floating point numbers
5122 \newline 
5123 _fs2uchar.c - convert floating point to unsigned char
5124 \newline 
5125 _fs2char.c - convert floating point to signed char
5126 \newline 
5127 _fs2uint.c - convert floating point to unsigned int
5128 \newline 
5129 _fs2int.c - convert floating point to signed int
5130 \newline 
5131 _fs2ulong.c - convert floating point to unsigned long
5132 \newline 
5133 _fs2long.c - convert floating point to signed long
5134 \newline 
5135 _uchar2fs.c - convert unsigned char to floating point
5136 \newline 
5137 _char2fs.c - convert char to floating point number
5138 \newline 
5139 _uint2fs.c - convert unsigned int to floating point
5140 \newline 
5141 _int2fs.c - convert int to floating point numbers
5142 \newline 
5143 _ulong2fs.c - convert unsigned long to floating point number
5144 \newline 
5145 _long2fs.c - convert long to floating point number
5146 \size footnotesize 
5147
5148 \newline 
5149
5150 \newline 
5151
5152 \size default 
5153 Note if all these routines are used simultaneously the data space might
5154  overflow.
5155  For serious floating point usage it is strongly recommended that the large
5156  model be used.
5157 \layout Subsection
5158
5159 MCS51 Memory Models
5160 \layout Standard
5161
5162 SDCC allows two memory models for MCS51 code, small and large.
5163  Modules compiled with different memory models should 
5164 \emph on 
5165 never
5166 \emph default 
5167  be combined together or the results would be unpredictable.
5168  The library routines supplied with the compiler are compiled as both small
5169  and large.
5170  The compiled library modules are contained in seperate directories as small
5171  and large so that you can link to either set.
5172  
5173 \layout Standard
5174
5175 When the large model is used all variables declared without a storage class
5176  will be allocated into the external ram, this includes all parameters and
5177  local variables (for non-reentrant functions).
5178  When the small model is used variables without storage class are allocated
5179  in the internal ram.
5180 \layout Standard
5181
5182 Judicious usage of the processor specific storage classes and the 'reentrant'
5183  function type will yield much more efficient code, than using the large
5184  model.
5185  Several optimizations are disabled when the program is compiled using the
5186  large model, it is therefore strongly recommdended that the small model
5187  be used unless absolutely required.
5188 \layout Subsection
5189
5190 DS390 Memory Models
5191 \layout Standard
5192
5193 The only model supported is Flat 24.
5194  This generates code for the 24 bit contiguous addressing mode of the Dallas
5195  DS80C390 part.
5196  In this mode, up to four meg of external RAM or code space can be directly
5197  addressed.
5198  See the data sheets at www.dalsemi.com for further information on this part.
5199 \newline 
5200
5201 \newline 
5202 In older versions of the compiler, this option was used with the MCS51 code
5203  generator (
5204 \emph on 
5205 -mmcs51
5206 \emph default 
5207 ).
5208  Now, however, the '390 has it's own code generator, selected by the 
5209 \emph on 
5210 -mds390
5211 \emph default 
5212  switch.
5213  
5214 \newline 
5215
5216 \newline 
5217 Note that the compiler does not generate any code to place the processor
5218  into 24 bitmode (although 
5219 \emph on 
5220 tinibios
5221 \emph default 
5222  in the ds390 libraries will do that for you).
5223  If you don't use 
5224 \emph on 
5225 tinibios
5226 \emph default 
5227 , the boot loader or similar code must ensure that the processor is in 24
5228  bit contiguous addressing mode before calling the SDCC startup code.
5229 \newline 
5230
5231 \newline 
5232 Like the 
5233 \emph on 
5234 ---model-large
5235 \emph default 
5236  option, variables will by default be placed into the XDATA segment.
5237  
5238 \newline 
5239
5240 \newline 
5241 Segments may be placed anywhere in the 4 meg address space using the usual
5242  ---*-loc options.
5243  Note that if any segments are located above 64K, the -r flag must be passed
5244  to the linker to generate the proper segment relocations, and the Intel
5245  HEX output format must be used.
5246  The -r flag can be passed to the linker by using the option 
5247 \emph on 
5248 -Wl-r
5249 \emph default 
5250  on the sdcc command line.
5251  However, currently the linker can not handle code segments > 64k.
5252 \layout Subsection
5253
5254 Defines Created by the Compiler
5255 \layout Standard
5256
5257 The compiler creates the following #defines.
5258 \layout Itemize
5259
5260 SDCC - this Symbol is always defined.
5261 \layout Itemize
5262
5263 SDCC_mcs51 or SDCC_ds390 or SDCC_z80, etc - depending on the model used
5264  (e.g.: -mds390)
5265 \layout Itemize
5266
5267 __mcs51 or __ds390 or __z80, etc - depending on the model used (e.g.
5268  -mz80)
5269 \layout Itemize
5270
5271 SDCC_STACK_AUTO - this symbol is defined when 
5272 \emph on 
5273 ---stack-auto
5274 \emph default 
5275  option is used.
5276 \layout Itemize
5277
5278 SDCC_MODEL_SMALL - when 
5279 \emph on 
5280 ---model-small
5281 \emph default 
5282  is used.
5283 \layout Itemize
5284
5285 SDCC_MODEL_LARGE - when 
5286 \emph on 
5287 ---model-large
5288 \emph default 
5289  is used.
5290 \layout Itemize
5291
5292 SDCC_USE_XSTACK - when 
5293 \emph on 
5294 ---xstack
5295 \emph default 
5296  option is used.
5297 \layout Itemize
5298
5299 SDCC_STACK_TENBIT - when 
5300 \emph on 
5301 -mds390
5302 \emph default 
5303  is used
5304 \layout Itemize
5305
5306 SDCC_MODEL_FLAT24 - when 
5307 \emph on 
5308 -mds390
5309 \emph default 
5310  is used
5311 \layout Section
5312
5313 SDCC Technical Data
5314 \layout Subsection
5315
5316 Optimizations
5317 \layout Standard
5318
5319 SDCC performs a host of standard optimizations in addition to some MCU specific
5320  optimizations.
5321  
5322 \layout Subsubsection
5323
5324 Sub-expression Elimination
5325 \layout Standard
5326
5327 The compiler does local and global common subexpression elimination, e.g.:
5328  
5329 \newline 
5330
5331 \newline 
5332
5333 \family typewriter 
5334 i = x + y + 1; 
5335 \newline 
5336 j = x + y;
5337 \family default 
5338
5339 \newline 
5340
5341 \newline 
5342 will be translated to
5343 \newline 
5344
5345 \newline 
5346
5347 \family typewriter 
5348 iTemp = x + y 
5349 \newline 
5350 i = iTemp + 1 
5351 \newline 
5352 j = iTemp
5353 \newline 
5354
5355 \family default 
5356
5357 \newline 
5358 Some subexpressions are not as obvious as the above example, e.g.:
5359 \newline 
5360
5361 \newline 
5362
5363 \family typewriter 
5364 a->b[i].c = 10; 
5365 \newline 
5366 a->b[i].d = 11;
5367 \family default 
5368
5369 \newline 
5370
5371 \newline 
5372 In this case the address arithmetic a->b[i] will be computed only once;
5373  the equivalent code in C would be.
5374 \newline 
5375
5376 \newline 
5377
5378 \family typewriter 
5379 iTemp = a->b[i]; 
5380 \newline 
5381 iTemp.c = 10; 
5382 \newline 
5383 iTemp.d = 11;
5384 \family default 
5385
5386 \newline 
5387
5388 \newline 
5389 The compiler will try to keep these temporary variables in registers.
5390 \layout Subsubsection
5391
5392 Dead-Code Elimination
5393 \layout Standard
5394
5395
5396 \family typewriter 
5397 int global; 
5398 \newline 
5399 void f () { 
5400 \newline 
5401 \SpecialChar ~
5402 \SpecialChar ~
5403 int i; 
5404 \newline 
5405 \SpecialChar ~
5406 \SpecialChar ~
5407 i = 1; \SpecialChar ~
5408 /* dead store */ 
5409 \newline 
5410 \SpecialChar ~
5411 \SpecialChar ~
5412 global = 1;\SpecialChar ~
5413 /* dead store */ 
5414 \newline 
5415 \SpecialChar ~
5416 \SpecialChar ~
5417 global = 2; 
5418 \newline 
5419 \SpecialChar ~
5420 \SpecialChar ~
5421 return; 
5422 \newline 
5423 \SpecialChar ~
5424 \SpecialChar ~
5425 global = 3;\SpecialChar ~
5426 /* unreachable */ 
5427 \newline 
5428 }
5429 \family default 
5430
5431 \newline 
5432
5433 \newline 
5434 will be changed to
5435 \newline 
5436
5437 \newline 
5438
5439 \family typewriter 
5440 int global; void f () 
5441 \newline 
5442 {
5443 \newline 
5444 \SpecialChar ~
5445 \SpecialChar ~
5446 global = 2; 
5447 \newline 
5448 \SpecialChar ~
5449 \SpecialChar ~
5450 return; 
5451 \newline 
5452 }
5453 \layout Subsubsection
5454
5455 Copy-Propagation
5456 \layout Standard
5457
5458
5459 \family typewriter 
5460 int f() { 
5461 \newline 
5462 \SpecialChar ~
5463 \SpecialChar ~
5464 int i, j; 
5465 \newline 
5466 \SpecialChar ~
5467 \SpecialChar ~
5468 i = 10; 
5469 \newline 
5470 \SpecialChar ~
5471 \SpecialChar ~
5472 j = i; 
5473 \newline 
5474 \SpecialChar ~
5475 \SpecialChar ~
5476 return j; 
5477 \newline 
5478 }
5479 \family default 
5480
5481 \newline 
5482
5483 \newline 
5484 will be changed to 
5485 \newline 
5486
5487 \newline 
5488
5489 \family typewriter 
5490 int f() { 
5491 \newline 
5492 \SpecialChar ~
5493  \SpecialChar ~
5494  int i,j; 
5495 \newline 
5496 \SpecialChar ~
5497  \SpecialChar ~
5498  i = 10; 
5499 \newline 
5500 \SpecialChar ~
5501  \SpecialChar ~
5502  j = 10; 
5503 \newline 
5504 \SpecialChar ~
5505  \SpecialChar ~
5506  return 10; 
5507 \newline 
5508 }
5509 \newline 
5510
5511 \newline 
5512
5513 \family default 
5514 Note: the dead stores created by this copy propagation will be eliminated
5515  by dead-code elimination.
5516 \layout Subsubsection
5517
5518 Loop Optimizations
5519 \layout Standard
5520
5521 Two types of loop optimizations are done by SDCC loop invariant lifting
5522  and strength reduction of loop induction variables.
5523  In addition to the strength reduction the optimizer marks the induction
5524  variables and the register allocator tries to keep the induction variables
5525  in registers for the duration of the loop.
5526  Because of this preference of the register allocator, loop induction optimizati
5527 on causes an increase in register pressure, which may cause unwanted spilling
5528  of other temporary variables into the stack / data space.
5529  The compiler will generate a warning message when it is forced to allocate
5530  extra space either on the stack or data space.
5531  If this extra space allocation is undesirable then induction optimization
5532  can be eliminated either for the entire source file (with ---noinduction
5533  option) or for a given function only using #pragma\SpecialChar ~
5534 NOINDUCTION.
5535 \newline 
5536
5537 \newline 
5538 Loop Invariant:
5539 \newline 
5540
5541 \newline 
5542
5543 \family typewriter 
5544 for (i = 0 ; i < 100 ; i ++) 
5545 \newline 
5546  \SpecialChar ~
5547  \SpecialChar ~
5548 f += k + l;
5549 \family default 
5550
5551 \newline 
5552
5553 \newline 
5554 changed to
5555 \newline 
5556
5557 \newline 
5558
5559 \family typewriter 
5560 itemp = k + l; 
5561 \newline 
5562 for (i = 0; i < 100; i++) 
5563 \newline 
5564 \SpecialChar ~
5565 \SpecialChar ~
5566 f += itemp;
5567 \family default 
5568
5569 \newline 
5570
5571 \newline 
5572 As mentioned previously some loop invariants are not as apparent, all static
5573  address computations are also moved out of the loop.
5574 \newline 
5575
5576 \newline 
5577 Strength Reduction, this optimization substitutes an expression by a cheaper
5578  expression:
5579 \newline 
5580
5581 \newline 
5582
5583 \family typewriter 
5584 for (i=0;i < 100; i++)
5585 \newline 
5586 \SpecialChar ~
5587 \SpecialChar ~
5588 ar[i*5] = i*3;
5589 \family default 
5590
5591 \newline 
5592
5593 \newline 
5594 changed to
5595 \newline 
5596
5597 \newline 
5598
5599 \family typewriter 
5600 itemp1 = 0; 
5601 \newline 
5602 itemp2 = 0; 
5603 \newline 
5604 for (i=0;i< 100;i++) { 
5605 \newline 
5606  \SpecialChar ~
5607  \SpecialChar ~
5608 ar[itemp1] = itemp2; 
5609 \newline 
5610  \SpecialChar ~
5611  \SpecialChar ~
5612 itemp1 += 5; 
5613 \newline 
5614  \SpecialChar ~
5615  \SpecialChar ~
5616 itemp2 += 3; 
5617 \newline 
5618 }
5619 \family default 
5620
5621 \newline 
5622
5623 \newline 
5624 The more expensive multiplication is changed to a less expensive addition.
5625 \layout Subsubsection
5626
5627 Loop Reversing
5628 \layout Standard
5629
5630 This optimization is done to reduce the overhead of checking loop boundaries
5631  for every iteration.
5632  Some simple loops can be reversed and implemented using a 
5633 \begin_inset Quotes eld
5634 \end_inset 
5635
5636 decrement and jump if not zero
5637 \begin_inset Quotes erd
5638 \end_inset 
5639
5640  instruction.
5641  SDCC checks for the following criterion to determine if a loop is reversible
5642  (note: more sophisticated compilers use data-dependency analysis to make
5643  this determination, SDCC uses a more simple minded analysis).
5644 \layout Itemize
5645
5646 The 'for' loop is of the form 
5647 \newline 
5648
5649 \newline 
5650
5651 \family typewriter 
5652 for (<symbol> = <expression> ; <sym> [< | <=] <expression> ; [<sym>++ |
5653  <sym> += 1])
5654 \newline 
5655 \SpecialChar ~
5656 \SpecialChar ~
5657 \SpecialChar ~
5658 \SpecialChar ~
5659 <for body>
5660 \layout Itemize
5661
5662 The <for body> does not contain 
5663 \begin_inset Quotes eld
5664 \end_inset 
5665
5666 continue
5667 \begin_inset Quotes erd
5668 \end_inset 
5669
5670  or 'break
5671 \begin_inset Quotes erd
5672 \end_inset 
5673
5674 .
5675 \layout Itemize
5676
5677 All goto's are contained within the loop.
5678 \layout Itemize
5679
5680 No function calls within the loop.
5681 \layout Itemize
5682
5683 The loop control variable <sym> is not assigned any value within the loop
5684 \layout Itemize
5685
5686 The loop control variable does NOT participate in any arithmetic operation
5687  within the loop.
5688 \layout Itemize
5689
5690 There are NO switch statements in the loop.
5691 \layout Subsubsection
5692
5693 Algebraic Simplifications
5694 \layout Standard
5695
5696 SDCC does numerous algebraic simplifications, the following is a small sub-set
5697  of these optimizations.
5698 \newline 
5699
5700 \newline 
5701
5702 \family typewriter 
5703 i = j + 0 ; /* changed to */ i = j; 
5704 \newline 
5705 i /= 2; /* changed to */ i >>= 1; 
5706 \newline 
5707 i = j - j ; /* changed to */ i = 0; 
5708 \newline 
5709 i = j / 1 ; /* changed to */ i = j;
5710 \family default 
5711
5712 \newline 
5713
5714 \newline 
5715 Note the subexpressions given above are generally introduced by macro expansions
5716  or as a result of copy/constant propagation.
5717 \layout Subsubsection
5718
5719 'switch' Statements
5720 \layout Standard
5721
5722 SDCC changes switch statements to jump tables when the following conditions
5723  are true.
5724  
5725 \layout Itemize
5726
5727 The case labels are in numerical sequence, the labels need not be in order,
5728  and the starting number need not be one or zero.
5729 \newline 
5730
5731 \newline 
5732
5733 \family typewriter 
5734 switch(i) {\SpecialChar ~
5735  \SpecialChar ~
5736  \SpecialChar ~
5737  \SpecialChar ~
5738  \SpecialChar ~
5739  \SpecialChar ~
5740  \SpecialChar ~
5741  \SpecialChar ~
5742  \SpecialChar ~
5743  \SpecialChar ~
5744  \SpecialChar ~
5745  \SpecialChar ~
5746  \SpecialChar ~
5747 switch (i) { 
5748 \newline 
5749 case 4:...
5750  \SpecialChar ~
5751  \SpecialChar ~
5752  \SpecialChar ~
5753  \SpecialChar ~
5754  \SpecialChar ~
5755  \SpecialChar ~
5756  \SpecialChar ~
5757  \SpecialChar ~
5758  \SpecialChar ~
5759  \SpecialChar ~
5760  \SpecialChar ~
5761  \SpecialChar ~
5762  \SpecialChar ~
5763 case 1: ...
5764  
5765 \newline 
5766 case 5:...
5767  \SpecialChar ~
5768  \SpecialChar ~
5769  \SpecialChar ~
5770  \SpecialChar ~
5771  \SpecialChar ~
5772  \SpecialChar ~
5773  \SpecialChar ~
5774  \SpecialChar ~
5775  \SpecialChar ~
5776  \SpecialChar ~
5777  \SpecialChar ~
5778  \SpecialChar ~
5779  \SpecialChar ~
5780 case 2: ...
5781  
5782 \newline 
5783 case 3:...
5784  \SpecialChar ~
5785  \SpecialChar ~
5786  \SpecialChar ~
5787  \SpecialChar ~
5788  \SpecialChar ~
5789  \SpecialChar ~
5790  \SpecialChar ~
5791  \SpecialChar ~
5792  \SpecialChar ~
5793  \SpecialChar ~
5794  \SpecialChar ~
5795  \SpecialChar ~
5796  \SpecialChar ~
5797 case 3: ...
5798  
5799 \newline 
5800 case 6:...
5801  \SpecialChar ~
5802  \SpecialChar ~
5803  \SpecialChar ~
5804  \SpecialChar ~
5805  \SpecialChar ~
5806  \SpecialChar ~
5807  \SpecialChar ~
5808  \SpecialChar ~
5809  \SpecialChar ~
5810  \SpecialChar ~
5811  \SpecialChar ~
5812  \SpecialChar ~
5813  \SpecialChar ~
5814 case 4: ...
5815  
5816 \newline 
5817 }\SpecialChar ~
5818  \SpecialChar ~
5819  \SpecialChar ~
5820  \SpecialChar ~
5821  \SpecialChar ~
5822  \SpecialChar ~
5823  \SpecialChar ~
5824  \SpecialChar ~
5825  \SpecialChar ~
5826  \SpecialChar ~
5827  \SpecialChar ~
5828  \SpecialChar ~
5829  \SpecialChar ~
5830  \SpecialChar ~
5831  \SpecialChar ~
5832  \SpecialChar ~
5833  \SpecialChar ~
5834  \SpecialChar ~
5835 }
5836 \newline 
5837
5838 \newline 
5839
5840 \family default 
5841 Both the above switch statements will be implemented using a jump-table.
5842 \layout Itemize
5843
5844 The number of case labels is at least three, since it takes two conditional
5845  statements to handle the boundary conditions.
5846 \layout Itemize
5847
5848 The number of case labels is less than 84, since each label takes 3 bytes
5849  and a jump-table can be utmost 256 bytes long.
5850  
5851 \layout Standard
5852
5853 Switch statements which have gaps in the numeric sequence or those that
5854  have more that 84 case labels can be split into more than one switch statement
5855  for efficient code generation, e.g.:
5856 \newline 
5857
5858 \newline 
5859
5860 \family typewriter 
5861 switch (i) { 
5862 \newline 
5863 case 1: ...
5864  
5865 \newline 
5866 case 2: ...
5867  
5868 \newline 
5869 case 3: ...
5870  
5871 \newline 
5872 case 4: ...
5873  
5874 \newline 
5875 case 9: ...
5876  
5877 \newline 
5878 case 10: ...
5879  
5880 \newline 
5881 case 11: ...
5882  
5883 \newline 
5884 case 12: ...
5885  
5886 \newline 
5887 }
5888 \family default 
5889
5890 \newline 
5891
5892 \newline 
5893 If the above switch statement is broken down into two switch statements
5894 \newline 
5895
5896 \newline 
5897
5898 \family typewriter 
5899 switch (i) { 
5900 \newline 
5901 case 1: ...
5902  
5903 \newline 
5904 case 2: ...
5905  
5906 \newline 
5907 case 3: ...
5908  
5909 \newline 
5910 case 4: ...
5911  
5912 \newline 
5913 }
5914 \newline 
5915
5916 \newline 
5917
5918 \family default 
5919 and
5920 \family typewriter 
5921
5922 \newline 
5923
5924 \newline 
5925 switch (i) { 
5926 \newline 
5927 case 9: \SpecialChar ~
5928 ...
5929  
5930 \newline 
5931 case 10: ...
5932  
5933 \newline 
5934 case 11: ...
5935  
5936 \newline 
5937 case 12:\SpecialChar ~
5938 ...
5939  
5940 \newline 
5941 }
5942 \newline 
5943
5944 \newline 
5945
5946 \family default 
5947 then both the switch statements will be implemented using jump-tables whereas
5948  the unmodified switch statement will not be.
5949 \layout Subsubsection
5950
5951 Bit-shifting Operations.
5952 \layout Standard
5953
5954 Bit shifting is one of the most frequently used operation in embedded programmin
5955 g.
5956  SDCC tries to implement bit-shift operations in the most efficient way
5957  possible, e.g.:
5958 \newline 
5959
5960 \family typewriter 
5961
5962 \newline 
5963 unsigned char i;
5964 \newline 
5965 ...
5966  
5967 \newline 
5968 i>>= 4; 
5969 \newline 
5970 ...
5971 \newline 
5972
5973 \family default 
5974
5975 \newline 
5976 generates the following code:
5977 \newline 
5978
5979 \family typewriter 
5980
5981 \newline 
5982 mov a,_i 
5983 \newline 
5984 swap a 
5985 \newline 
5986 anl a,#0x0f 
5987 \newline 
5988 mov _i,a
5989 \family default 
5990
5991 \newline 
5992
5993 \newline 
5994 In general SDCC will never setup a loop if the shift count is known.
5995  Another example:
5996 \newline 
5997
5998 \newline 
5999
6000 \family typewriter 
6001 unsigned int i; 
6002 \newline 
6003 ...
6004  
6005 \newline 
6006 i >>= 9; 
6007 \newline 
6008 ...
6009 \family default 
6010
6011 \newline 
6012
6013 \newline 
6014 will generate:
6015 \newline 
6016
6017 \newline 
6018
6019 \family typewriter 
6020 mov a,(_i + 1) 
6021 \newline 
6022 mov (_i + 1),#0x00 
6023 \newline 
6024 clr c 
6025 \newline 
6026 rrc a 
6027 \newline 
6028 mov _i,a
6029 \family default 
6030
6031 \newline 
6032
6033 \newline 
6034 Note that SDCC stores numbers in little-endian format (i.e.
6035  lowest order first).
6036 \layout Subsubsection
6037
6038 Bit-rotation
6039 \layout Standard
6040
6041 A special case of the bit-shift operation is bit rotation, SDCC recognizes
6042  the following expression to be a left bit-rotation:
6043 \newline 
6044
6045 \newline 
6046
6047 \family typewriter 
6048 unsigned char i; 
6049 \newline 
6050 ...
6051  
6052 \newline 
6053 i = ((i << 1) | (i >> 7)); 
6054 \family default 
6055
6056 \newline 
6057 ...
6058 \newline 
6059
6060 \newline 
6061 will generate the following code:
6062 \newline 
6063
6064 \newline 
6065
6066 \family typewriter 
6067 mov a,_i 
6068 \newline 
6069 rl a 
6070 \newline 
6071 mov _i,a
6072 \family default 
6073
6074 \newline 
6075
6076 \newline 
6077 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
6078 ns of this case will also be recognized as bit-rotation, i.e.: 
6079 \newline 
6080
6081 \newline 
6082
6083 \family typewriter 
6084 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
6085 \layout Subsubsection
6086
6087 Highest Order Bit
6088 \layout Standard
6089
6090 It is frequently required to obtain the highest order bit of an integral
6091  type (long, int, short or char types).
6092  SDCC recognizes the following expression to yield the highest order bit
6093  and generates optimized code for it, e.g.:
6094 \newline 
6095
6096 \newline 
6097  
6098 \family typewriter 
6099 unsigned int gint; 
6100 \newline 
6101
6102 \newline 
6103 foo () { 
6104 \newline 
6105 unsigned char hob; 
6106 \newline 
6107 \SpecialChar ~
6108 \SpecialChar ~
6109 ...
6110  
6111 \newline 
6112 \SpecialChar ~
6113 \SpecialChar ~
6114 hob = (gint >> 15) & 1; 
6115 \newline 
6116 \SpecialChar ~
6117 \SpecialChar ~
6118 ..
6119  
6120 \newline 
6121 }
6122 \family default 
6123
6124 \newline 
6125
6126 \newline 
6127 will generate the following code:
6128 \newline 
6129
6130 \family typewriter 
6131
6132 \newline 
6133 \SpecialChar ~
6134 \SpecialChar ~
6135 \SpecialChar ~
6136 \SpecialChar ~
6137 \SpecialChar ~
6138 \SpecialChar ~
6139 \SpecialChar ~
6140 \SpecialChar ~
6141 \SpecialChar ~
6142 \SpecialChar ~
6143 \SpecialChar ~
6144 \SpecialChar ~
6145 \SpecialChar ~
6146 \SpecialChar ~
6147 \SpecialChar ~
6148 \SpecialChar ~
6149 \SpecialChar ~
6150 \SpecialChar ~
6151 \SpecialChar ~
6152 \SpecialChar ~
6153 \SpecialChar ~
6154 \SpecialChar ~
6155 \SpecialChar ~
6156 \SpecialChar ~
6157 \SpecialChar ~
6158 \SpecialChar ~
6159 \SpecialChar ~
6160 \SpecialChar ~
6161  61 ;\SpecialChar ~
6162  hob.c 7 
6163 \newline 
6164 \SpecialChar ~
6165 \SpecialChar ~
6166  000A E5*01\SpecialChar ~
6167 \SpecialChar ~
6168 \SpecialChar ~
6169 \SpecialChar ~
6170 \SpecialChar ~
6171 \SpecialChar ~
6172 \SpecialChar ~
6173 \SpecialChar ~
6174 \SpecialChar ~
6175 \SpecialChar ~
6176 \SpecialChar ~
6177 \SpecialChar ~
6178 \SpecialChar ~
6179 \SpecialChar ~
6180 \SpecialChar ~
6181  62\SpecialChar ~
6182 \SpecialChar ~
6183 \SpecialChar ~
6184 \SpecialChar ~
6185 \SpecialChar ~
6186 \SpecialChar ~
6187 \SpecialChar ~
6188 \SpecialChar ~
6189  mov\SpecialChar ~
6190  a,(_gint + 1) 
6191 \newline 
6192 \SpecialChar ~
6193 \SpecialChar ~
6194  000C 33\SpecialChar ~
6195 \SpecialChar ~
6196 \SpecialChar ~
6197 \SpecialChar ~
6198 \SpecialChar ~
6199 \SpecialChar ~
6200 \SpecialChar ~
6201 \SpecialChar ~
6202 \SpecialChar ~
6203 \SpecialChar ~
6204 \SpecialChar ~
6205 \SpecialChar ~
6206 \SpecialChar ~
6207 \SpecialChar ~
6208 \SpecialChar ~
6209 \SpecialChar ~
6210 \SpecialChar ~
6211 \SpecialChar ~
6212  63\SpecialChar ~
6213 \SpecialChar ~
6214 \SpecialChar ~
6215 \SpecialChar ~
6216 \SpecialChar ~
6217 \SpecialChar ~
6218 \SpecialChar ~
6219 \SpecialChar ~
6220  rlc\SpecialChar ~
6221  a 
6222 \newline 
6223 \SpecialChar ~
6224 \SpecialChar ~
6225  000D E4\SpecialChar ~
6226 \SpecialChar ~
6227 \SpecialChar ~
6228 \SpecialChar ~
6229 \SpecialChar ~
6230 \SpecialChar ~
6231 \SpecialChar ~
6232 \SpecialChar ~
6233 \SpecialChar ~
6234 \SpecialChar ~
6235 \SpecialChar ~
6236 \SpecialChar ~
6237 \SpecialChar ~
6238 \SpecialChar ~
6239 \SpecialChar ~
6240 \SpecialChar ~
6241 \SpecialChar ~
6242 \SpecialChar ~
6243  64\SpecialChar ~
6244 \SpecialChar ~
6245 \SpecialChar ~
6246 \SpecialChar ~
6247 \SpecialChar ~
6248 \SpecialChar ~
6249 \SpecialChar ~
6250 \SpecialChar ~
6251  clr\SpecialChar ~
6252  a 
6253 \newline 
6254 \SpecialChar ~
6255 \SpecialChar ~
6256  000E 13\SpecialChar ~
6257 \SpecialChar ~
6258 \SpecialChar ~
6259 \SpecialChar ~
6260 \SpecialChar ~
6261 \SpecialChar ~
6262 \SpecialChar ~
6263 \SpecialChar ~
6264 \SpecialChar ~
6265 \SpecialChar ~
6266 \SpecialChar ~
6267 \SpecialChar ~
6268 \SpecialChar ~
6269 \SpecialChar ~
6270 \SpecialChar ~
6271 \SpecialChar ~
6272 \SpecialChar ~
6273 \SpecialChar ~
6274  65\SpecialChar ~
6275 \SpecialChar ~
6276 \SpecialChar ~
6277 \SpecialChar ~
6278 \SpecialChar ~
6279 \SpecialChar ~
6280 \SpecialChar ~
6281 \SpecialChar ~
6282  rrc\SpecialChar ~
6283  a 
6284 \newline 
6285 \SpecialChar ~
6286 \SpecialChar ~
6287  000F F5*02\SpecialChar ~
6288 \SpecialChar ~
6289 \SpecialChar ~
6290 \SpecialChar ~
6291 \SpecialChar ~
6292 \SpecialChar ~
6293 \SpecialChar ~
6294 \SpecialChar ~
6295 \SpecialChar ~
6296 \SpecialChar ~
6297 \SpecialChar ~
6298 \SpecialChar ~
6299 \SpecialChar ~
6300 \SpecialChar ~
6301 \SpecialChar ~
6302  66\SpecialChar ~
6303 \SpecialChar ~
6304 \SpecialChar ~
6305 \SpecialChar ~
6306 \SpecialChar ~
6307 \SpecialChar ~
6308 \SpecialChar ~
6309 \SpecialChar ~
6310  mov\SpecialChar ~
6311  _foo_hob_1_1,a
6312 \newline 
6313
6314 \newline 
6315
6316 \family default 
6317 Variations of this case however will 
6318 \emph on 
6319 not
6320 \emph default 
6321  be recognized.
6322  It is a standard C expression, so I heartily recommend this be the only
6323  way to get the highest order bit, (it is portable).
6324  Of course it will be recognized even if it is embedded in other expressions,
6325  e.g.:
6326 \newline 
6327
6328 \newline 
6329
6330 \family typewriter 
6331 xyz = gint + ((gint >> 15) & 1);
6332 \family default 
6333
6334 \newline 
6335
6336 \newline 
6337 will still be recognized.
6338 \layout Subsubsection
6339
6340 Peep-hole Optimizer
6341 \layout Standard
6342
6343 The compiler uses a rule based, pattern matching and re-writing mechanism
6344  for peep-hole optimization.
6345  It is inspired by 
6346 \emph on 
6347 copt
6348 \emph default 
6349  a peep-hole optimizer by Christopher W.
6350  Fraser (cwfraser@microsoft.com).
6351  A default set of rules are compiled into the compiler, additional rules
6352  may be added with the 
6353 \emph on 
6354 ---peep-file <filename>
6355 \emph default 
6356  option.
6357  The rule language is best illustrated with examples.
6358 \newline 
6359
6360 \newline 
6361
6362 \family typewriter 
6363 replace { 
6364 \newline 
6365 \SpecialChar ~
6366 \SpecialChar ~
6367 mov %1,a 
6368 \newline 
6369 \SpecialChar ~
6370 \SpecialChar ~
6371 mov a,%1
6372 \newline 
6373 } by {
6374 \newline 
6375 \SpecialChar ~
6376 \SpecialChar ~
6377 mov %1,a
6378 \newline 
6379 }
6380 \family default 
6381
6382 \newline 
6383
6384 \newline 
6385 The above rule will change the following assembly sequence:
6386 \newline 
6387
6388 \newline 
6389
6390 \family typewriter 
6391 \SpecialChar ~
6392 \SpecialChar ~
6393 mov r1,a 
6394 \newline 
6395 \SpecialChar ~
6396 \SpecialChar ~
6397 mov a,r1
6398 \family default 
6399
6400 \newline 
6401
6402 \newline 
6403 to
6404 \newline 
6405
6406 \newline 
6407
6408 \family typewriter 
6409 mov r1,a
6410 \family default 
6411
6412 \newline 
6413
6414 \newline 
6415 Note: All occurrences of a 
6416 \emph on 
6417 %n
6418 \emph default 
6419  (pattern variable) must denote the same string.
6420  With the above rule, the assembly sequence:
6421 \newline 
6422
6423 \newline 
6424
6425 \family typewriter 
6426 \SpecialChar ~
6427 \SpecialChar ~
6428 mov r1,a 
6429 \newline 
6430 \SpecialChar ~
6431 \SpecialChar ~
6432 mov a,r2
6433 \family default 
6434
6435 \newline 
6436
6437 \newline 
6438 will remain unmodified.
6439 \newline 
6440
6441 \newline 
6442 Other special case optimizations may be added by the user (via 
6443 \emph on 
6444 ---peep-file option
6445 \emph default 
6446 ).
6447  E.g.
6448  some variants of the 8051 MCU allow only 
6449 \family typewriter 
6450 ajmp
6451 \family default 
6452  and 
6453 \family typewriter 
6454 acall
6455 \family default 
6456 .
6457  The following two rules will change all 
6458 \family typewriter 
6459 ljmp
6460 \family default 
6461  and 
6462 \family typewriter 
6463 lcall
6464 \family default 
6465  to 
6466 \family typewriter 
6467 ajmp
6468 \family default 
6469  and 
6470 \family typewriter 
6471 acall
6472 \family default 
6473
6474 \newline 
6475
6476 \newline 
6477
6478 \family typewriter 
6479 replace { lcall %1 } by { acall %1 } 
6480 \newline 
6481 replace { ljmp %1 } by { ajmp %1 }
6482 \family default 
6483
6484 \newline 
6485
6486 \newline 
6487 The 
6488 \emph on 
6489 inline-assembler code
6490 \emph default 
6491  is also passed through the peep hole optimizer, thus the peephole optimizer
6492  can also be used as an assembly level macro expander.
6493  The rules themselves are MCU dependent whereas the rule language infra-structur
6494 e is MCU independent.
6495  Peephole optimization rules for other MCU can be easily programmed using
6496  the rule language.
6497 \newline 
6498
6499 \newline 
6500 The syntax for a rule is as follows:
6501 \newline 
6502
6503 \newline 
6504
6505 \family typewriter 
6506 rule := replace [ restart ] '{' <assembly sequence> '
6507 \backslash 
6508 n' 
6509 \newline 
6510 \SpecialChar ~
6511  \SpecialChar ~
6512  \SpecialChar ~
6513  \SpecialChar ~
6514  \SpecialChar ~
6515  \SpecialChar ~
6516  \SpecialChar ~
6517  \SpecialChar ~
6518  \SpecialChar ~
6519  \SpecialChar ~
6520  \SpecialChar ~
6521  \SpecialChar ~
6522  \SpecialChar ~
6523  \SpecialChar ~
6524  '}' by '{' '
6525 \backslash 
6526 n' 
6527 \newline 
6528 \SpecialChar ~
6529  \SpecialChar ~
6530  \SpecialChar ~
6531  \SpecialChar ~
6532  \SpecialChar ~
6533  \SpecialChar ~
6534  \SpecialChar ~
6535  \SpecialChar ~
6536  \SpecialChar ~
6537  \SpecialChar ~
6538  \SpecialChar ~
6539  \SpecialChar ~
6540  \SpecialChar ~
6541  \SpecialChar ~
6542  \SpecialChar ~
6543  \SpecialChar ~
6544  <assembly sequence> '
6545 \backslash 
6546 n' 
6547 \newline 
6548 \SpecialChar ~
6549  \SpecialChar ~
6550  \SpecialChar ~
6551  \SpecialChar ~
6552  \SpecialChar ~
6553  \SpecialChar ~
6554  \SpecialChar ~
6555  \SpecialChar ~
6556  \SpecialChar ~
6557  \SpecialChar ~
6558  \SpecialChar ~
6559  \SpecialChar ~
6560  \SpecialChar ~
6561  \SpecialChar ~
6562  '}' [if <functionName> ] '
6563 \backslash 
6564 n' 
6565 \newline 
6566
6567 \family default 
6568
6569 \newline 
6570 <assembly sequence> := assembly instruction (each instruction including
6571  labels must be on a separate line).
6572 \newline 
6573
6574 \newline 
6575 The optimizer will apply to the rules one by one from the top in the sequence
6576  of their appearance, it will terminate when all rules are exhausted.
6577  If the 'restart' option is specified, then the optimizer will start matching
6578  the rules again from the top, this option for a rule is expensive (performance)
6579 , it is intended to be used in situations where a transformation will trigger
6580  the same rule again.
6581  An example of this (not a good one, it has side effects) is the following
6582  rule:
6583 \newline 
6584
6585 \newline 
6586
6587 \family typewriter 
6588 replace restart { 
6589 \newline 
6590 \SpecialChar ~
6591 \SpecialChar ~
6592 pop %1 
6593 \newline 
6594 \SpecialChar ~
6595 \SpecialChar ~
6596 push %1 } by { 
6597 \newline 
6598 \SpecialChar ~
6599 \SpecialChar ~
6600 ; nop 
6601 \newline 
6602 }
6603 \family default 
6604
6605 \newline 
6606
6607 \newline 
6608 Note that the replace pattern cannot be a blank, but can be a comment line.
6609  Without the 'restart' option only the inner most 'pop' 'push' pair would
6610  be eliminated, i.e.:
6611 \newline 
6612
6613 \newline 
6614
6615 \family typewriter 
6616 \SpecialChar ~
6617 \SpecialChar ~
6618 pop ar1 
6619 \newline 
6620 \SpecialChar ~
6621 \SpecialChar ~
6622 pop ar2 
6623 \newline 
6624 \SpecialChar ~
6625 \SpecialChar ~
6626 push ar2 
6627 \newline 
6628 \SpecialChar ~
6629 \SpecialChar ~
6630 push ar1
6631 \family default 
6632
6633 \newline 
6634
6635 \newline 
6636 would result in:
6637 \newline 
6638
6639 \newline 
6640
6641 \family typewriter 
6642 \SpecialChar ~
6643 \SpecialChar ~
6644 pop ar1 
6645 \newline 
6646 \SpecialChar ~
6647 \SpecialChar ~
6648 ; nop 
6649 \newline 
6650 \SpecialChar ~
6651 \SpecialChar ~
6652 push ar1
6653 \family default 
6654
6655 \newline 
6656
6657 \newline 
6658
6659 \emph on 
6660 with
6661 \emph default 
6662  the restart option the rule will be applied again to the resulting code
6663  and then all the pop-push pairs will be eliminated to yield:
6664 \newline 
6665
6666 \newline 
6667
6668 \family typewriter 
6669 \SpecialChar ~
6670 \SpecialChar ~
6671 ; nop 
6672 \newline 
6673 \SpecialChar ~
6674 \SpecialChar ~
6675 ; nop
6676 \family default 
6677
6678 \newline 
6679
6680 \newline 
6681 A conditional function can be attached to a rule.
6682  Attaching rules are somewhat more involved, let me illustrate this with
6683  an example.
6684 \newline 
6685
6686 \newline 
6687
6688 \family typewriter 
6689 replace { 
6690 \newline 
6691 \SpecialChar ~
6692  \SpecialChar ~
6693  \SpecialChar ~
6694 ljmp %5 
6695 \newline 
6696 %2:
6697 \newline 
6698 } by { 
6699 \newline 
6700 \SpecialChar ~
6701  \SpecialChar ~
6702  \SpecialChar ~
6703 sjmp %5 
6704 \newline 
6705 %2:
6706 \newline 
6707 } if labelInRange
6708 \family default 
6709
6710 \newline 
6711
6712 \newline 
6713 The optimizer does a look-up of a function name table defined in function
6714  
6715 \emph on 
6716 callFuncByName
6717 \emph default 
6718  in the source file SDCCpeeph.c, with the name 
6719 \emph on 
6720 labelInRange
6721 \emph default 
6722 .
6723  If it finds a corresponding entry the function is called.
6724  Note there can be no parameters specified for these functions, in this
6725  case the use of 
6726 \emph on 
6727 %5
6728 \emph default 
6729  is crucial, since the function 
6730 \emph on 
6731 labelInRange
6732 \emph default 
6733  expects to find the label in that particular variable (the hash table containin
6734 g the variable bindings is passed as a parameter).
6735  If you want to code more such functions, take a close look at the function
6736  labelInRange and the calling mechanism in source file SDCCpeeph.c.
6737  I know this whole thing is a little kludgey, but maybe some day we will
6738  have some better means.
6739  If you are looking at this file, you will also see the default rules that
6740  are compiled into the compiler, you can add your own rules in the default
6741  set there if you get tired of specifying the ---peep-file option.
6742 \layout Subsection
6743
6744 Pragmas
6745 \layout Standard
6746
6747 SDCC supports the following #pragma directives.
6748  This directives are applicable only at a function level.
6749 \layout Itemize
6750
6751 SAVE - this will save all the current options.
6752 \layout Itemize
6753
6754 RESTORE - will restore the saved options from the last save.
6755  Note that SAVES & RESTOREs cannot be nested.
6756  SDCC uses the same buffer to save the options each time a SAVE is called.
6757 \layout Itemize
6758
6759 NOGCSE - will stop global subexpression elimination.
6760 \layout Itemize
6761
6762 NOINDUCTION - will stop loop induction optimizations.
6763 \layout Itemize
6764
6765 NOJTBOUND - will not generate code for boundary value checking, when switch
6766  statements are turned into jump-tables.
6767 \layout Itemize
6768
6769 NOOVERLAY - the compiler will not overlay the parameters and local variables
6770  of a function.
6771 \layout Itemize
6772
6773 NOLOOPREVERSE - Will not do loop reversal optimization
6774 \layout Itemize
6775
6776 EXCLUDE NONE | {acc[,b[,dpl[,dph]]] - The exclude pragma disables generation
6777  of pair of push/pop instruction in ISR function (using interrupt keyword).
6778  The directive should be placed immediately before the ISR function definition
6779  and it affects ALL ISR functions following it.
6780  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
6781 EXCLUDE\SpecialChar ~
6782 none.
6783 \layout Itemize
6784
6785 NOIV - Do not generate interrupt vector table entries for all ISR functions
6786  defined after the pragma.
6787  This is useful in cases where the interrupt vector table must be defined
6788  manually, or when there is a secondary, manually defined interrupt vector
6789  table (e.g.
6790  for the autovector feature of the Cypress EZ-USB FX2).
6791 \layout Itemize
6792
6793 CALLEE-SAVES function1[,function2[,function3...]] - The compiler by default
6794  uses a caller saves convention for register saving across function calls,
6795  however this can cause unneccessary register pushing & popping when calling
6796  small functions from larger functions.
6797  This option can be used to switch the register saving convention for the
6798  function names specified.
6799  The compiler will not save registers when calling these functions, extra
6800  code will be generated at the entry & exit for these functions to save
6801  & restore the registers used by these functions, this can SUBSTANTIALLY
6802  reduce code & improve run time performance of the generated code.
6803  In future the compiler (with interprocedural analysis) will be able to
6804  determine the appropriate scheme to use for each function call.
6805  If ---callee-saves command line option is used, the function names specified
6806  in #pragma\SpecialChar ~
6807 CALLEE-SAVES is appended to the list of functions specified inthe
6808  command line.
6809 \layout Standard
6810
6811 The pragma's are intended to be used to turn-off certain optimizations which
6812  might cause the compiler to generate extra stack / data space to store
6813  compiler generated temporary variables.
6814  This usually happens in large functions.
6815  Pragma directives should be used as shown in the following example, they
6816  are used to control options & optimizations for a given function; pragmas
6817  should be placed before and/or after a function, placing pragma's inside
6818  a function body could have unpredictable results.
6819 \newline 
6820
6821 \newline 
6822
6823 \family typewriter 
6824 #pragma SAVE /* save the current settings */ 
6825 \newline 
6826 #pragma NOGCSE /* turnoff global subexpression elimination */ 
6827 \newline 
6828 #pragma NOINDUCTION /* turn off induction optimizations */ 
6829 \newline 
6830 int foo () 
6831 \newline 
6832
6833 \newline 
6834 \SpecialChar ~
6835  \SpecialChar ~
6836  ...
6837  
6838 \newline 
6839 \SpecialChar ~
6840  \SpecialChar ~
6841  /* large code */ 
6842 \newline 
6843 \SpecialChar ~
6844  \SpecialChar ~
6845  ...
6846  
6847 \newline 
6848
6849 \newline 
6850 #pragma RESTORE /* turn the optimizations back on */
6851 \family default 
6852
6853 \newline 
6854
6855 \newline 
6856 The compiler will generate a warning message when extra space is allocated.
6857  It is strongly recommended that the SAVE and RESTORE pragma's be used when
6858  changing options for a function.
6859 \layout Subsection
6860
6861
6862 \emph on 
6863 <pending: this is messy and incomplete>
6864 \emph default 
6865  Library Routines
6866 \layout Enumerate
6867
6868 Compiler support routines (_gptrget, _mulint etc)
6869 \layout Enumerate
6870
6871 Stdclib functions (puts, printf, strcat etc)
6872 \layout Enumerate
6873
6874 Math functions (sin, pow, sqrt etc)
6875 \layout Subsection
6876
6877 Interfacing with Assembly Routines
6878 \layout Subsubsection
6879
6880 Global Registers used for Parameter Passing
6881 \layout Standard
6882
6883 The compiler always uses the global registers 
6884 \emph on 
6885 DPL,DPH,B 
6886 \emph default 
6887 and
6888 \emph on 
6889  ACC
6890 \emph default 
6891  to pass the first parameter to a routine.
6892  The second parameter onwards is either allocated on the stack (for reentrant
6893  routines or if ---stack-auto is used) or in the internal / external ram
6894  (depending on the memory model).
6895  
6896 \layout Subsubsection
6897
6898 Assembler Routine(non-reentrant)
6899 \layout Standard
6900
6901 In the following example the function cfunc calls an assembler routine asm_func,
6902  which takes two parameters.
6903 \newline 
6904
6905 \newline 
6906
6907 \family typewriter 
6908 extern int asm_func(unsigned char, unsigned char);
6909 \newline 
6910
6911 \newline 
6912 int c_func (unsigned char i, unsigned char j)
6913 \newline 
6914 {
6915 \newline 
6916 \SpecialChar ~
6917 \SpecialChar ~
6918 \SpecialChar ~
6919 \SpecialChar ~
6920 return asm_func(i,j);
6921 \newline 
6922 }
6923 \newline 
6924
6925 \newline 
6926 int main()
6927 \newline 
6928 {
6929 \newline 
6930 \SpecialChar ~
6931 \SpecialChar ~
6932 \SpecialChar ~
6933 \SpecialChar ~
6934 return c_func(10,9);
6935 \newline 
6936 }
6937 \newline 
6938
6939 \newline 
6940
6941 \family default 
6942 The corresponding assembler function is:
6943 \newline 
6944
6945 \newline 
6946
6947 \family typewriter 
6948 .globl _asm_func_PARM_2 
6949 \newline 
6950 \SpecialChar ~
6951 \SpecialChar ~
6952 \SpecialChar ~
6953 \SpecialChar ~
6954 \SpecialChar ~
6955 \SpecialChar ~
6956 \SpecialChar ~
6957 \SpecialChar ~
6958 .globl _asm_func 
6959 \newline 
6960 \SpecialChar ~
6961 \SpecialChar ~
6962 \SpecialChar ~
6963 \SpecialChar ~
6964 \SpecialChar ~
6965 \SpecialChar ~
6966 \SpecialChar ~
6967 \SpecialChar ~
6968 .area OSEG 
6969 \newline 
6970 _asm_func_PARM_2:
6971 \newline 
6972 \SpecialChar ~
6973 \SpecialChar ~
6974 \SpecialChar ~
6975 \SpecialChar ~
6976 \SpecialChar ~
6977 \SpecialChar ~
6978 \SpecialChar ~
6979 \SpecialChar ~
6980 .ds      1 
6981 \newline 
6982 \SpecialChar ~
6983 \SpecialChar ~
6984 \SpecialChar ~
6985 \SpecialChar ~
6986 \SpecialChar ~
6987 \SpecialChar ~
6988 \SpecialChar ~
6989 \SpecialChar ~
6990 .area CSEG 
6991 \newline 
6992 _asm_func: 
6993 \newline 
6994 \SpecialChar ~
6995 \SpecialChar ~
6996 \SpecialChar ~
6997 \SpecialChar ~
6998 \SpecialChar ~
6999 \SpecialChar ~
7000 \SpecialChar ~
7001 \SpecialChar ~
7002 mov     a,dpl 
7003 \newline 
7004 \SpecialChar ~
7005 \SpecialChar ~
7006 \SpecialChar ~
7007 \SpecialChar ~
7008 \SpecialChar ~
7009 \SpecialChar ~
7010 \SpecialChar ~
7011 \SpecialChar ~
7012 add     a,_asm_func_PARM_2 
7013 \newline 
7014 \SpecialChar ~
7015 \SpecialChar ~
7016 \SpecialChar ~
7017 \SpecialChar ~
7018 \SpecialChar ~
7019 \SpecialChar ~
7020 \SpecialChar ~
7021 \SpecialChar ~
7022 mov     dpl,a 
7023 \newline 
7024 \SpecialChar ~
7025 \SpecialChar ~
7026 \SpecialChar ~
7027 \SpecialChar ~
7028 \SpecialChar ~
7029 \SpecialChar ~
7030 \SpecialChar ~
7031 \SpecialChar ~
7032 mov     dpl,#0x00 
7033 \newline 
7034 \SpecialChar ~
7035 \SpecialChar ~
7036 \SpecialChar ~
7037 \SpecialChar ~
7038 \SpecialChar ~
7039 \SpecialChar ~
7040 \SpecialChar ~
7041 \SpecialChar ~
7042 ret
7043 \newline 
7044
7045 \newline 
7046
7047 \family default 
7048 Note here that the return values are placed in 'dpl' - One byte return value,
7049  'dpl' LSB & 'dph' MSB for two byte values.
7050  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
7051 b' & 'acc' for four byte values.
7052 \layout Standard
7053
7054 The parameter naming convention is _<function_name>_PARM_<n>, where n is
7055  the parameter number starting from 1, and counting from the left.
7056  The first parameter is passed in 
7057 \begin_inset Quotes eld
7058 \end_inset 
7059
7060 dpl
7061 \begin_inset Quotes erd
7062 \end_inset 
7063
7064  for One bye parameter, 
7065 \begin_inset Quotes eld
7066 \end_inset 
7067
7068 dptr
7069 \begin_inset Quotes erd
7070 \end_inset 
7071
7072  if two bytes, 
7073 \begin_inset Quotes eld
7074 \end_inset 
7075
7076 b,dptr
7077 \begin_inset Quotes erd
7078 \end_inset 
7079
7080  for three bytes and 
7081 \begin_inset Quotes eld
7082 \end_inset 
7083
7084 acc,b,dptr
7085 \begin_inset Quotes erd
7086 \end_inset 
7087
7088  for four bytes, the varible name for the second parameter will be _<function_na
7089 me>_PARM_2.
7090 \newline 
7091
7092 \newline 
7093 Assemble the assembler routine with the following command:
7094 \newline 
7095
7096 \newline 
7097
7098 \family sans 
7099 \series bold 
7100 asx8051 -losg asmfunc.asm
7101 \newline 
7102
7103 \newline 
7104
7105 \family default 
7106 \series default 
7107 Then compile and link the assembler routine to the C source file with the
7108  following command:
7109 \newline 
7110
7111 \newline 
7112
7113 \family sans 
7114 \series bold 
7115 sdcc cfunc.c asmfunc.rel
7116 \layout Subsubsection
7117
7118 Assembler Routine(reentrant)
7119 \layout Standard
7120
7121 In this case the second parameter onwards will be passed on the stack, the
7122  parameters are pushed from right to left i.e.
7123  after the call the left most parameter will be on the top of the stack.
7124  Here is an example:
7125 \newline 
7126
7127 \newline 
7128
7129 \family typewriter 
7130 extern int asm_func(unsigned char, unsigned char);
7131 \newline 
7132
7133 \newline 
7134 int c_func (unsigned char i, unsigned char j) reentrant 
7135 \newline 
7136
7137 \newline 
7138 \SpecialChar ~
7139 \SpecialChar ~
7140 \SpecialChar ~
7141 \SpecialChar ~
7142 return asm_func(i,j); 
7143 \newline 
7144
7145 \newline 
7146
7147 \newline 
7148 int main() 
7149 \newline 
7150
7151 \newline 
7152 \SpecialChar ~
7153 \SpecialChar ~
7154 \SpecialChar ~
7155 \SpecialChar ~
7156 return c_func(10,9); 
7157 \newline 
7158 }
7159 \newline 
7160
7161 \family default 
7162
7163 \newline 
7164 The corresponding assembler routine is:
7165 \newline 
7166
7167 \newline 
7168
7169 \family typewriter 
7170 .globl _asm_func 
7171 \newline 
7172 _asm_func: 
7173 \newline 
7174 \SpecialChar ~
7175 \SpecialChar ~
7176 \SpecialChar ~
7177 \SpecialChar ~
7178 push  _bp 
7179 \newline 
7180 \SpecialChar ~
7181 \SpecialChar ~
7182 \SpecialChar ~
7183 \SpecialChar ~
7184 mov  _bp,sp 
7185 \newline 
7186 \SpecialChar ~
7187 \SpecialChar ~
7188 \SpecialChar ~
7189 \SpecialChar ~
7190 mov  r2,dpl
7191 \newline 
7192 \SpecialChar ~
7193 \SpecialChar ~
7194 \SpecialChar ~
7195 \SpecialChar ~
7196 mov  a,_bp 
7197 \newline 
7198 \SpecialChar ~
7199 \SpecialChar ~
7200 \SpecialChar ~
7201 \SpecialChar ~
7202 clr  c 
7203 \newline 
7204 \SpecialChar ~
7205 \SpecialChar ~
7206 \SpecialChar ~
7207 \SpecialChar ~
7208 add  a,#0xfd 
7209 \newline 
7210 \SpecialChar ~
7211 \SpecialChar ~
7212 \SpecialChar ~
7213 \SpecialChar ~
7214 mov  r0,a 
7215 \newline 
7216 \SpecialChar ~
7217 \SpecialChar ~
7218 \SpecialChar ~
7219 \SpecialChar ~
7220 add  a,#0xfc
7221 \newline 
7222 \SpecialChar ~
7223 \SpecialChar ~
7224 \SpecialChar ~
7225 \SpecialChar ~
7226 mov  r1,a 
7227 \newline 
7228 \SpecialChar ~
7229 \SpecialChar ~
7230 \SpecialChar ~
7231 \SpecialChar ~
7232 mov  a,@r0 
7233 \newline 
7234 \SpecialChar ~
7235 \SpecialChar ~
7236 \SpecialChar ~
7237 \SpecialChar ~
7238 add  a,r2
7239 \newline 
7240 \SpecialChar ~
7241 \SpecialChar ~
7242 \SpecialChar ~
7243 \SpecialChar ~
7244 mov  dpl,a 
7245 \newline 
7246 \SpecialChar ~
7247 \SpecialChar ~
7248 \SpecialChar ~
7249 \SpecialChar ~
7250 mov  dph,#0x00 
7251 \newline 
7252 \SpecialChar ~
7253 \SpecialChar ~
7254 \SpecialChar ~
7255 \SpecialChar ~
7256 mov  sp,_bp 
7257 \newline 
7258 \SpecialChar ~
7259 \SpecialChar ~
7260 \SpecialChar ~
7261 \SpecialChar ~
7262 pop  _bp 
7263 \newline 
7264 \SpecialChar ~
7265 \SpecialChar ~
7266 \SpecialChar ~
7267 \SpecialChar ~
7268 ret
7269 \newline 
7270
7271 \newline 
7272
7273 \family default 
7274 The compiling and linking procedure remains the same, however note the extra
7275  entry & exit linkage required for the assembler code, _bp is the stack
7276  frame pointer and is used to compute the offset into the stack for parameters
7277  and local variables.
7278 \layout Subsection
7279
7280 External Stack
7281 \layout Standard
7282
7283 The external stack is located at the start of the external ram segment,
7284  and is 256 bytes in size.
7285  When ---xstack option is used to compile the program, the parameters and
7286  local variables of all reentrant functions are allocated in this area.
7287  This option is provided for programs with large stack space requirements.
7288  When used with the ---stack-auto option, all parameters and local variables
7289  are allocated on the external stack (note support libraries will need to
7290  be recompiled with the same options).
7291 \layout Standard
7292
7293 The compiler outputs the higher order address byte of the external ram segment
7294  into PORT P2, therefore when using the External Stack option, this port
7295  MAY NOT be used by the application program.
7296 \layout Subsection
7297
7298 ANSI-Compliance
7299 \layout Standard
7300
7301 Deviations from the compliancy.
7302 \layout Itemize
7303
7304 functions are not always reentrant.
7305 \layout Itemize
7306
7307 structures cannot be assigned values directly, cannot be passed as function
7308  parameters or assigned to each other and cannot be a return value from
7309  a function, e.g.:
7310 \family typewriter 
7311
7312 \newline 
7313
7314 \newline 
7315 struct s { ...
7316  }; 
7317 \newline 
7318 struct s s1, s2; 
7319 \newline 
7320 foo() 
7321 \newline 
7322
7323 \newline 
7324 \SpecialChar ~
7325 \SpecialChar ~
7326 \SpecialChar ~
7327 \SpecialChar ~
7328 ...
7329  
7330 \newline 
7331 \SpecialChar ~
7332 \SpecialChar ~
7333 \SpecialChar ~
7334 \SpecialChar ~
7335 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
7336 \newline 
7337 \SpecialChar ~
7338 \SpecialChar ~
7339 \SpecialChar ~
7340 \SpecialChar ~
7341 ...
7342  
7343 \newline 
7344 }
7345 \newline 
7346 struct s foo1 (struct s parms) /* is invalid in SDCC although allowed in
7347  ANSI */ 
7348 \newline 
7349
7350 \newline 
7351 \SpecialChar ~
7352 \SpecialChar ~
7353 \SpecialChar ~
7354 \SpecialChar ~
7355 struct s rets; 
7356 \newline 
7357 \SpecialChar ~
7358 \SpecialChar ~
7359 \SpecialChar ~
7360 \SpecialChar ~
7361 ...
7362  
7363 \newline 
7364 \SpecialChar ~
7365 \SpecialChar ~
7366 \SpecialChar ~
7367 \SpecialChar ~
7368 return rets;/* is invalid in SDCC although allowed in ANSI */ 
7369 \newline 
7370 }
7371 \layout Itemize
7372
7373 'long long' (64 bit integers) not supported.
7374 \layout Itemize
7375
7376 'double' precision floating point not supported.
7377 \layout Itemize
7378
7379 No support for setjmp and longjmp (for now).
7380 \layout Itemize
7381
7382 Old K&R style function declarations are NOT allowed.
7383 \newline 
7384
7385 \family typewriter 
7386
7387 \newline 
7388 foo(i,j) /* this old style of function declarations */ 
7389 \newline 
7390 int i,j; /* are valid in ANSI but not valid in SDCC */ 
7391 \newline 
7392
7393 \newline 
7394 \SpecialChar ~
7395 \SpecialChar ~
7396 \SpecialChar ~
7397 \SpecialChar ~
7398 ...
7399  
7400 \newline 
7401 }
7402 \layout Itemize
7403
7404 functions declared as pointers must be dereferenced during the call.
7405 \newline 
7406
7407 \family typewriter 
7408
7409 \newline 
7410 int (*foo)();
7411 \newline 
7412 ...
7413  
7414 \newline 
7415 /* has to be called like this */ 
7416 \newline 
7417 (*foo)(); /* ansi standard allows calls to be made like 'foo()' */
7418 \layout Subsection
7419
7420 Cyclomatic Complexity
7421 \layout Standard
7422
7423 Cyclomatic complexity of a function is defined as the number of independent
7424  paths the program can take during execution of the function.
7425  This is an important number since it defines the number test cases you
7426  have to generate to validate the function.
7427  The accepted industry standard for complexity number is 10, if the cyclomatic
7428  complexity reported by SDCC exceeds 10 you should think about simplification
7429  of the function logic.
7430  Note that the complexity level is not related to the number of lines of
7431  code in a function.
7432  Large functions can have low complexity, and small functions can have large
7433  complexity levels.
7434  
7435 \newline 
7436
7437 \newline 
7438 SDCC uses the following formula to compute the complexity:
7439 \newline 
7440
7441 \layout Standard
7442
7443 complexity = (number of edges in control flow graph) - (number of nodes
7444  in control flow graph) + 2;
7445 \newline 
7446
7447 \newline 
7448 Having said that the industry standard is 10, you should be aware that in
7449  some cases it be may unavoidable to have a complexity level of less than
7450  10.
7451  For example if you have switch statement with more than 10 case labels,
7452  each case label adds one to the complexity level.
7453  The complexity level is by no means an absolute measure of the algorithmic
7454  complexity of the function, it does however provide a good starting point
7455  for which functions you might look at for further optimization.
7456 \layout Section
7457
7458 TIPS
7459 \layout Standard
7460
7461 Here are a few guidelines that will help the compiler generate more efficient
7462  code, some of the tips are specific to this compiler others are generally
7463  good programming practice.
7464 \layout Itemize
7465
7466 Use the smallest data type to represent your data-value.
7467  If it is known in advance that the value is going to be less than 256 then
7468  use an 'unsigned char' instead of a 'short' or 'int'.
7469 \layout Itemize
7470
7471 Use unsigned when it is known in advance that the value is not going to
7472  be negative.
7473  This helps especially if you are doing division or multiplication.
7474 \layout Itemize
7475
7476 NEVER jump into a LOOP.
7477 \layout Itemize
7478
7479 Declare the variables to be local whenever possible, especially loop control
7480  variables (induction).
7481 \layout Itemize
7482
7483 Since the compiler does not always do implicit integral promotion, the programme
7484 r should do an explicit cast when integral promotion is required.
7485 \layout Itemize
7486
7487 Reducing the size of division, multiplication & modulus operations can reduce
7488  code size substantially.
7489  Take the following code for example.
7490 \family typewriter 
7491
7492 \newline 
7493
7494 \newline 
7495 foobar(unsigned int p1, unsigned char ch)
7496 \newline 
7497 {
7498 \newline 
7499     unsigned char ch1 = p1 % ch ;
7500 \newline 
7501     ....
7502     
7503 \newline 
7504 }
7505 \newline 
7506
7507 \family default 
7508
7509 \newline 
7510 For the modulus operation the variable ch will be promoted to unsigned int
7511  first then the modulus operation will be performed (this will lead to a
7512  call to support routine _moduint()), and the result will be casted to a
7513  char.
7514  If the code is changed to 
7515 \newline 
7516
7517 \family typewriter 
7518
7519 \newline 
7520 foobar(unsigned int p1, unsigned char ch)
7521 \newline 
7522 {
7523 \newline 
7524     unsigned char ch1 = (unsigned char)p1 % ch ;
7525 \newline 
7526     ....
7527     
7528 \newline 
7529 }
7530 \newline 
7531
7532 \family default 
7533
7534 \newline 
7535 It would substantially reduce the code generated (future versions of the
7536  compiler will be smart enough to detect such optimization oppurtunities).
7537 \layout Subsection
7538
7539 Notes on MCS51 memory layout
7540 \layout Standard
7541
7542 The 8051 family of micro controller have a minimum of 128 bytes of internal
7543  memory which is structured as follows
7544 \newline 
7545
7546 \newline 
7547 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R7 to R7
7548  
7549 \newline 
7550 - Bytes 20-2F - 16 bytes to hold 128 bit variables and 
7551 \newline 
7552 - Bytes 30-7F - 60 bytes for general purpose use.
7553 \newline 
7554
7555 \newline 
7556 Normally the SDCC compiler will only utilise the first bank of registers,
7557  but it is possible to specify that other banks of registers should be used
7558  in interrupt routines.
7559  By default, the compiler will place the stack after the last bank of used
7560  registers, i.e.
7561  if the first 2 banks of registers are used, it will position the base of
7562  the internal stack at address 16 (0X10).
7563  This implies that as the stack grows, it will use up the remaining register
7564  banks, and the 16 bytes used by the 128 bit variables, and 60 bytes for
7565  general purpose use.
7566 \layout Standard
7567
7568 By default, the compiler uses the 60 general purpose bytes to hold "near
7569  data".
7570  The compiler/optimiser may also declare some Local Variables in this area
7571  to hold local data.
7572  
7573 \layout Standard
7574
7575 If any of the 128 bit variables are used, or near data is being used then
7576  care needs to be taken to ensure that the stack does not grow so much that
7577  it starts to over write either your bit variables or "near data".
7578  There is no runtime checking to prevent this from happening.
7579 \layout Standard
7580
7581 The amount of stack being used is affected by the use of the "internal stack"
7582  to save registers before a subroutine call is made (---stack-auto will
7583  declare parameters and local variables on the stack) and the number of
7584  nested subroutines.
7585 \layout Standard
7586
7587 If you detect that the stack is over writing you data, then the following
7588  can be done.
7589  ---xstack will cause an external stack to be used for saving registers
7590  and (if ---stack-auto is being used) storing parameters and local variables.
7591  However this will produce more code which will be slower to execute.
7592  
7593 \layout Standard
7594
7595 ---stack-loc will allow you specify the start of the stack, i.e.
7596  you could start it after any data in the general purpose area.
7597  However this may waste the memory not used by the register banks and if
7598  the size of the "near data" increases, it may creep into the bottom of
7599  the stack.
7600 \layout Standard
7601
7602 ---stack-after-data, similar to the ---stack-loc, but it automatically places
7603  the stack after the end of the "near data".
7604  Again this could waste any spare register space.
7605 \layout Standard
7606
7607 ---data-loc allows you to specify the start address of the near data.
7608  This could be used to move the "near data" further away from the stack
7609  giving it more room to grow.
7610  This will only work if no bit variables are being used and the stack can
7611  grow to use the bit variable space.
7612 \newline 
7613
7614 \newline 
7615 Conclusion.
7616 \newline 
7617
7618 \newline 
7619 If you find that the stack is over writing your bit variables or "near data"
7620  then the approach which best utilised the internal memory is to position
7621  the "near data" after the last bank of used registers or, if you use bit
7622  variables, after the last bit variable by using the ---data-loc, e.g.
7623  if two register banks are being used and no bit variables, ---data-loc
7624  16, and use the ---stack-after-data option.
7625 \layout Standard
7626
7627 If bit variables are being used, another method would be to try and squeeze
7628  the data area in the unused register banks if it will fit, and start the
7629  stack after the last bit variable.
7630 \layout Section
7631
7632 Retargetting for other MCUs.
7633 \layout Standard
7634
7635 The issues for retargetting the compiler are far too numerous to be covered
7636  by this document.
7637  What follows is a brief description of each of the seven phases of the
7638  compiler and its MCU dependency.
7639 \layout Itemize
7640
7641 Parsing the source and building the annotated parse tree.
7642  This phase is largely MCU independent (except for the language extensions).
7643  Syntax & semantic checks are also done in this phase, along with some initial
7644  optimizations like back patching labels and the pattern matching optimizations
7645  like bit-rotation etc.
7646 \layout Itemize
7647
7648 The second phase involves generating an intermediate code which can be easy
7649  manipulated during the later phases.
7650  This phase is entirely MCU independent.
7651  The intermediate code generation assumes the target machine has unlimited
7652  number of registers, and designates them with the name iTemp.
7653  The compiler can be made to dump a human readable form of the code generated
7654  by using the ---dumpraw option.
7655 \layout Itemize
7656
7657 This phase does the bulk of the standard optimizations and is also MCU independe
7658 nt.
7659  This phase can be broken down into several sub-phases:
7660 \newline 
7661
7662 \newline 
7663 Break down intermediate code (iCode) into basic blocks.
7664 \newline 
7665 Do control flow & data flow analysis on the basic blocks.
7666 \newline 
7667 Do local common subexpression elimination, then global subexpression elimination
7668 \newline 
7669 Dead code elimination
7670 \newline 
7671 Loop optimizations
7672 \newline 
7673 If loop optimizations caused any changes then do 'global subexpression eliminati
7674 on' and 'dead code elimination' again.
7675 \layout Itemize
7676
7677 This phase determines the live-ranges; by live range I mean those iTemp
7678  variables defined by the compiler that still survive after all the optimization
7679 s.
7680  Live range analysis is essential for register allocation, since these computati
7681 on determines which of these iTemps will be assigned to registers, and for
7682  how long.
7683 \layout Itemize
7684
7685 Phase five is register allocation.
7686  There are two parts to this process.
7687 \newline 
7688
7689 \newline 
7690 The first part I call 'register packing' (for lack of a better term).
7691  In this case several MCU specific expression folding is done to reduce
7692  register pressure.
7693 \newline 
7694
7695 \newline 
7696 The second part is more MCU independent and deals with allocating registers
7697  to the remaining live ranges.
7698  A lot of MCU specific code does creep into this phase because of the limited
7699  number of index registers available in the 8051.
7700 \layout Itemize
7701
7702 The Code generation phase is (unhappily), entirely MCU dependent and very
7703  little (if any at all) of this code can be reused for other MCU.
7704  However the scheme for allocating a homogenized assembler operand for each
7705  iCode operand may be reused.
7706 \layout Itemize
7707
7708 As mentioned in the optimization section the peep-hole optimizer is rule
7709  based system, which can reprogrammed for other MCUs.
7710 \layout Section
7711
7712 SDCDB - Source Level Debugger
7713 \layout Standard
7714
7715 SDCC is distributed with a source level debugger.
7716  The debugger uses a command line interface, the command repertoire of the
7717  debugger has been kept as close to gdb (the GNU debugger) as possible.
7718  The configuration and build process is part of the standard compiler installati
7719 on, which also builds and installs the debugger in the target directory
7720  specified during configuration.
7721  The debugger allows you debug BOTH at the C source and at the ASM source
7722  level.
7723 \layout Subsection
7724
7725 Compiling for Debugging
7726 \layout Standard
7727
7728 The \SpecialChar \-
7729 \SpecialChar \-
7730 debug option must be specified for all files for which debug information
7731  is to be generated.
7732  The complier generates a .cdb file for each of these files.
7733  The linker updates the .cdb file with the address information.
7734  This .cdb is used by the debugger.
7735 \layout Subsection
7736
7737 How the Debugger Works
7738 \layout Standard
7739
7740 When the ---debug option is specified the compiler generates extra symbol
7741  information some of which are put into the the assembler source and some
7742  are put into the .cdb file, the linker updates the .cdb file with the address
7743  information for the symbols.
7744  The debugger reads the symbolic information generated by the compiler &
7745  the address information generated by the linker.
7746  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
7747  execution is controlled by the debugger.
7748  When a command is issued for the debugger, it translates it into appropriate
7749  commands for the simulator.
7750 \layout Subsection
7751
7752 Starting the Debugger
7753 \layout Standard
7754
7755 The debugger can be started using the following command line.
7756  (Assume the file you are debugging has the file name foo).
7757 \newline 
7758
7759 \newline 
7760
7761 \family sans 
7762 \series bold 
7763 sdcdb foo
7764 \newline 
7765
7766 \family default 
7767 \series default 
7768
7769 \newline 
7770 The debugger will look for the following files.
7771 \layout Itemize
7772
7773 foo.c - the source file.
7774 \layout Itemize
7775
7776 foo.cdb - the debugger symbol information file.
7777 \layout Itemize
7778
7779 foo.ihx - the intel hex format object file.
7780 \layout Subsection
7781
7782 Command Line Options.
7783 \layout Itemize
7784
7785 ---directory=<source file directory> this option can used to specify the
7786  directory search list.
7787  The debugger will look into the directory list specified for source, cdb
7788  & ihx files.
7789  The items in the directory list must be separated by ':', e.g.
7790  if the source files can be in the directories /home/src1 and /home/src2,
7791  the ---directory option should be ---directory=/home/src1:/home/src2.
7792  Note there can be no spaces in the option.
7793  
7794 \layout Itemize
7795
7796 -cd <directory> - change to the <directory>.
7797 \layout Itemize
7798
7799 -fullname - used by GUI front ends.
7800 \layout Itemize
7801
7802 -cpu <cpu-type> - this argument is passed to the simulator please see the
7803  simulator docs for details.
7804 \layout Itemize
7805
7806 -X <Clock frequency > this options is passed to the simulator please see
7807  the simulator docs for details.
7808 \layout Itemize
7809
7810 -s <serial port file> passed to simulator see the simulator docs for details.
7811 \layout Itemize
7812
7813 -S <serial in,out> passed to simulator see the simulator docs for details.
7814 \layout Subsection
7815
7816 Debugger Commands.
7817 \layout Standard
7818
7819 As mention earlier the command interface for the debugger has been deliberately
7820  kept as close the GNU debugger gdb, as possible.
7821  This will help the integration with existing graphical user interfaces
7822  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
7823 \layout Subsubsection
7824
7825 break [line | file:line | function | file:function]
7826 \layout Standard
7827
7828 Set breakpoint at specified line or function:
7829 \newline 
7830
7831 \newline 
7832
7833 \family sans 
7834 \series bold 
7835 sdcdb>break 100 
7836 \newline 
7837 sdcdb>break foo.c:100
7838 \newline 
7839 sdcdb>break funcfoo
7840 \newline 
7841 sdcdb>break foo.c:funcfoo
7842 \layout Subsubsection
7843
7844 clear [line | file:line | function | file:function ]
7845 \layout Standard
7846
7847 Clear breakpoint at specified line or function:
7848 \newline 
7849
7850 \newline 
7851
7852 \family sans 
7853 \series bold 
7854 sdcdb>clear 100
7855 \newline 
7856 sdcdb>clear foo.c:100
7857 \newline 
7858 sdcdb>clear funcfoo
7859 \newline 
7860 sdcdb>clear foo.c:funcfoo
7861 \layout Subsubsection
7862
7863 continue
7864 \layout Standard
7865
7866 Continue program being debugged, after breakpoint.
7867 \layout Subsubsection
7868
7869 finish
7870 \layout Standard
7871
7872 Execute till the end of the current function.
7873 \layout Subsubsection
7874
7875 delete [n]
7876 \layout Standard
7877
7878 Delete breakpoint number 'n'.
7879  If used without any option clear ALL user defined break points.
7880 \layout Subsubsection
7881
7882 info [break | stack | frame | registers ]
7883 \layout Itemize
7884
7885 info break - list all breakpoints
7886 \layout Itemize
7887
7888 info stack - show the function call stack.
7889 \layout Itemize
7890
7891 info frame - show information about the current execution frame.
7892 \layout Itemize
7893
7894 info registers - show content of all registers.
7895 \layout Subsubsection
7896
7897 step
7898 \layout Standard
7899
7900 Step program until it reaches a different source line.
7901 \layout Subsubsection
7902
7903 next
7904 \layout Standard
7905
7906 Step program, proceeding through subroutine calls.
7907 \layout Subsubsection
7908
7909 run
7910 \layout Standard
7911
7912 Start debugged program.
7913 \layout Subsubsection
7914
7915 ptype variable 
7916 \layout Standard
7917
7918 Print type information of the variable.
7919 \layout Subsubsection
7920
7921 print variable
7922 \layout Standard
7923
7924 print value of variable.
7925 \layout Subsubsection
7926
7927 file filename
7928 \layout Standard
7929
7930 load the given file name.
7931  Note this is an alternate method of loading file for debugging.
7932 \layout Subsubsection
7933
7934 frame
7935 \layout Standard
7936
7937 print information about current frame.
7938 \layout Subsubsection
7939
7940 set srcmode
7941 \layout Standard
7942
7943 Toggle between C source & assembly source.
7944 \layout Subsubsection
7945
7946 ! simulator command
7947 \layout Standard
7948
7949 Send the string following '!' to the simulator, the simulator response is
7950  displayed.
7951  Note the debugger does not interpret the command being sent to the simulator,
7952  so if a command like 'go' is sent the debugger can loose its execution
7953  context and may display incorrect values.
7954 \layout Subsubsection
7955
7956 quit.
7957 \layout Standard
7958
7959 "Watch me now.
7960  Iam going Down.
7961  My name is Bobby Brown"
7962 \layout Subsection
7963
7964 Interfacing with XEmacs.
7965 \layout Standard
7966
7967 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
7968  sdcdb.el and sdcdbsrc.el.
7969  These two files can be found in the $(prefix)/bin directory after the installat
7970 ion is complete.
7971  These files need to be loaded into XEmacs for the interface to work.
7972  This can be done at XEmacs startup time by inserting the following into
7973  your '.xemacs' file (which can be found in your HOME directory): 
7974 \newline 
7975
7976 \newline 
7977
7978 \family typewriter 
7979 (load-file sdcdbsrc.el) 
7980 \family default 
7981
7982 \newline 
7983
7984 \newline 
7985 .xemacs is a lisp file so the () around the command is REQUIRED.
7986  The files can also be loaded dynamically while XEmacs is running, set the
7987  environment variable 'EMACSLOADPATH' to the installation bin directory
7988  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
7989  To start the interface enter the following command: 
7990 \newline 
7991
7992 \newline 
7993
7994 \family sans 
7995 \series bold 
7996 ESC-x sdcdbsrc
7997 \family default 
7998 \series default 
7999
8000 \newline 
8001
8002 \newline 
8003 You will prompted to enter the file name to be debugged.
8004  
8005 \newline 
8006
8007 \newline 
8008 The command line options that are passed to the simulator directly are bound
8009  to default values in the file sdcdbsrc.el.
8010  The variables are listed below, these values maybe changed as required.
8011 \layout Itemize
8012
8013 sdcdbsrc-cpu-type '51
8014 \layout Itemize
8015
8016 sdcdbsrc-frequency '11059200
8017 \layout Itemize
8018
8019 sdcdbsrc-serial nil
8020 \layout Standard
8021
8022 The following is a list of key mapping for the debugger interface.
8023 \layout Standard
8024
8025 \SpecialChar ~
8026
8027 \family typewriter 
8028
8029 \newline 
8030 ;; Current Listing :: 
8031 \newline 
8032 ;;key\SpecialChar ~
8033 \SpecialChar ~
8034 \SpecialChar ~
8035 \SpecialChar ~
8036 \SpecialChar ~
8037 \SpecialChar ~
8038 \SpecialChar ~
8039 \SpecialChar ~
8040 \SpecialChar ~
8041 \SpecialChar ~
8042 \SpecialChar ~
8043 \SpecialChar ~
8044 \SpecialChar ~
8045 \SpecialChar ~
8046 \SpecialChar ~
8047 binding\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 \SpecialChar ~
8061 \SpecialChar ~
8062 \SpecialChar ~
8063 \SpecialChar ~
8064 \SpecialChar ~
8065 \SpecialChar ~
8066 \SpecialChar ~
8067 \SpecialChar ~
8068 \SpecialChar ~
8069 Comment 
8070 \newline 
8071 ;;---\SpecialChar ~
8072 \SpecialChar ~
8073 \SpecialChar ~
8074 \SpecialChar ~
8075 \SpecialChar ~
8076 \SpecialChar ~
8077 \SpecialChar ~
8078 \SpecialChar ~
8079 \SpecialChar ~
8080 \SpecialChar ~
8081 \SpecialChar ~
8082 \SpecialChar ~
8083 \SpecialChar ~
8084 \SpecialChar ~
8085 \SpecialChar ~
8086 ------\SpecialChar ~
8087 \SpecialChar ~
8088 \SpecialChar ~
8089 \SpecialChar ~
8090 \SpecialChar ~
8091 \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 -------- 
8109 \newline 
8110 ;; 
8111 \newline 
8112 ;; n\SpecialChar ~
8113 \SpecialChar ~
8114 \SpecialChar ~
8115 \SpecialChar ~
8116 \SpecialChar ~
8117 \SpecialChar ~
8118 \SpecialChar ~
8119 \SpecialChar ~
8120 \SpecialChar ~
8121 \SpecialChar ~
8122 \SpecialChar ~
8123 \SpecialChar ~
8124 \SpecialChar ~
8125 \SpecialChar ~
8126  sdcdb-next-from-src\SpecialChar ~
8127 \SpecialChar ~
8128 \SpecialChar ~
8129 \SpecialChar ~
8130 \SpecialChar ~
8131 \SpecialChar ~
8132 \SpecialChar ~
8133 \SpecialChar ~
8134 \SpecialChar ~
8135 \SpecialChar ~
8136 SDCDB next command 
8137 \newline 
8138 ;; b\SpecialChar ~
8139 \SpecialChar ~
8140 \SpecialChar ~
8141 \SpecialChar ~
8142 \SpecialChar ~
8143 \SpecialChar ~
8144 \SpecialChar ~
8145 \SpecialChar ~
8146 \SpecialChar ~
8147 \SpecialChar ~
8148 \SpecialChar ~
8149 \SpecialChar ~
8150 \SpecialChar ~
8151 \SpecialChar ~
8152  sdcdb-back-from-src\SpecialChar ~
8153 \SpecialChar ~
8154 \SpecialChar ~
8155 \SpecialChar ~
8156 \SpecialChar ~
8157 \SpecialChar ~
8158 \SpecialChar ~
8159 \SpecialChar ~
8160 \SpecialChar ~
8161 \SpecialChar ~
8162 SDCDB back command 
8163 \newline 
8164 ;; c\SpecialChar ~
8165 \SpecialChar ~
8166 \SpecialChar ~
8167 \SpecialChar ~
8168 \SpecialChar ~
8169 \SpecialChar ~
8170 \SpecialChar ~
8171 \SpecialChar ~
8172 \SpecialChar ~
8173 \SpecialChar ~
8174 \SpecialChar ~
8175 \SpecialChar ~
8176 \SpecialChar ~
8177 \SpecialChar ~
8178  sdcdb-cont-from-src\SpecialChar ~
8179 \SpecialChar ~
8180 \SpecialChar ~
8181 \SpecialChar ~
8182 \SpecialChar ~
8183 \SpecialChar ~
8184 \SpecialChar ~
8185 \SpecialChar ~
8186 \SpecialChar ~
8187 \SpecialChar ~
8188 SDCDB continue command
8189 \newline 
8190 ;; s\SpecialChar ~
8191 \SpecialChar ~
8192 \SpecialChar ~
8193 \SpecialChar ~
8194 \SpecialChar ~
8195 \SpecialChar ~
8196 \SpecialChar ~
8197 \SpecialChar ~
8198 \SpecialChar ~
8199 \SpecialChar ~
8200 \SpecialChar ~
8201 \SpecialChar ~
8202 \SpecialChar ~
8203 \SpecialChar ~
8204  sdcdb-step-from-src\SpecialChar ~
8205 \SpecialChar ~
8206 \SpecialChar ~
8207 \SpecialChar ~
8208 \SpecialChar ~
8209 \SpecialChar ~
8210 \SpecialChar ~
8211 \SpecialChar ~
8212 \SpecialChar ~
8213 \SpecialChar ~
8214 SDCDB step command 
8215 \newline 
8216 ;; ?\SpecialChar ~
8217 \SpecialChar ~
8218 \SpecialChar ~
8219 \SpecialChar ~
8220 \SpecialChar ~
8221 \SpecialChar ~
8222 \SpecialChar ~
8223 \SpecialChar ~
8224 \SpecialChar ~
8225 \SpecialChar ~
8226 \SpecialChar ~
8227 \SpecialChar ~
8228 \SpecialChar ~
8229 \SpecialChar ~
8230  sdcdb-whatis-c-sexp\SpecialChar ~
8231 \SpecialChar ~
8232 \SpecialChar ~
8233 \SpecialChar ~
8234 \SpecialChar ~
8235 \SpecialChar ~
8236 \SpecialChar ~
8237 \SpecialChar ~
8238 \SpecialChar ~
8239 \SpecialChar ~
8240 SDCDB ptypecommand for data at 
8241 \newline 
8242 ;;\SpecialChar ~
8243 \SpecialChar ~
8244 \SpecialChar ~
8245 \SpecialChar ~
8246 \SpecialChar ~
8247 \SpecialChar ~
8248 \SpecialChar ~
8249 \SpecialChar ~
8250 \SpecialChar ~
8251 \SpecialChar ~
8252 \SpecialChar ~
8253 \SpecialChar ~
8254 \SpecialChar ~
8255 \SpecialChar ~
8256 \SpecialChar ~
8257 \SpecialChar ~
8258 \SpecialChar ~
8259 \SpecialChar ~
8260 \SpecialChar ~
8261 \SpecialChar ~
8262 \SpecialChar ~
8263 \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  buffer point 
8289 \newline 
8290 ;; x\SpecialChar ~
8291 \SpecialChar ~
8292 \SpecialChar ~
8293 \SpecialChar ~
8294 \SpecialChar ~
8295 \SpecialChar ~
8296 \SpecialChar ~
8297 \SpecialChar ~
8298 \SpecialChar ~
8299 \SpecialChar ~
8300 \SpecialChar ~
8301 \SpecialChar ~
8302 \SpecialChar ~
8303 \SpecialChar ~
8304  sdcdbsrc-delete\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 \SpecialChar ~
8318 SDCDB Delete all breakpoints if no arg 
8319 \newline 
8320 ;;\SpecialChar ~
8321 \SpecialChar ~
8322 \SpecialChar ~
8323 \SpecialChar ~
8324 \SpecialChar ~
8325 \SpecialChar ~
8326 \SpecialChar ~
8327 \SpecialChar ~
8328 \SpecialChar ~
8329 \SpecialChar ~
8330 \SpecialChar ~
8331 \SpecialChar ~
8332 \SpecialChar ~
8333 \SpecialChar ~
8334 \SpecialChar ~
8335 \SpecialChar ~
8336 \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 given or delete arg (C-u arg x) 
8367 \newline 
8368 ;; m\SpecialChar ~
8369 \SpecialChar ~
8370 \SpecialChar ~
8371 \SpecialChar ~
8372 \SpecialChar ~
8373 \SpecialChar ~
8374 \SpecialChar ~
8375 \SpecialChar ~
8376 \SpecialChar ~
8377 \SpecialChar ~
8378 \SpecialChar ~
8379 \SpecialChar ~
8380 \SpecialChar ~
8381 \SpecialChar ~
8382  sdcdbsrc-frame\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 \SpecialChar ~
8396 \SpecialChar ~
8397 SDCDB Display current frame if no arg, 
8398 \newline 
8399 ;;\SpecialChar ~
8400 \SpecialChar ~
8401 \SpecialChar ~
8402 \SpecialChar ~
8403 \SpecialChar ~
8404 \SpecialChar ~
8405 \SpecialChar ~
8406 \SpecialChar ~
8407 \SpecialChar ~
8408 \SpecialChar ~
8409 \SpecialChar ~
8410 \SpecialChar ~
8411 \SpecialChar ~
8412 \SpecialChar ~
8413 \SpecialChar ~
8414 \SpecialChar ~
8415 \SpecialChar ~
8416 \SpecialChar ~
8417 \SpecialChar ~
8418 \SpecialChar ~
8419 \SpecialChar ~
8420 \SpecialChar ~
8421 \SpecialChar ~
8422 \SpecialChar ~
8423 \SpecialChar ~
8424 \SpecialChar ~
8425 \SpecialChar ~
8426 \SpecialChar ~
8427 \SpecialChar ~
8428 \SpecialChar ~
8429 \SpecialChar ~
8430 \SpecialChar ~
8431 \SpecialChar ~
8432 \SpecialChar ~
8433 \SpecialChar ~
8434 \SpecialChar ~
8435 \SpecialChar ~
8436 \SpecialChar ~
8437 \SpecialChar ~
8438 \SpecialChar ~
8439 \SpecialChar ~
8440 \SpecialChar ~
8441 \SpecialChar ~
8442 \SpecialChar ~
8443 \SpecialChar ~
8444 \SpecialChar ~
8445 \SpecialChar ~
8446 given or display frame arg 
8447 \newline 
8448 ;;\SpecialChar ~
8449 \SpecialChar ~
8450 \SpecialChar ~
8451 \SpecialChar ~
8452 \SpecialChar ~
8453 \SpecialChar ~
8454 \SpecialChar ~
8455 \SpecialChar ~
8456 \SpecialChar ~
8457 \SpecialChar ~
8458 \SpecialChar ~
8459 \SpecialChar ~
8460 \SpecialChar ~
8461 \SpecialChar ~
8462 \SpecialChar ~
8463 \SpecialChar ~
8464 \SpecialChar ~
8465 \SpecialChar ~
8466 \SpecialChar ~
8467 \SpecialChar ~
8468 \SpecialChar ~
8469 \SpecialChar ~
8470 \SpecialChar ~
8471 \SpecialChar ~
8472 \SpecialChar ~
8473 \SpecialChar ~
8474 \SpecialChar ~
8475 \SpecialChar ~
8476 \SpecialChar ~
8477 \SpecialChar ~
8478 \SpecialChar ~
8479 \SpecialChar ~
8480 \SpecialChar ~
8481 \SpecialChar ~
8482 \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 buffer point 
8496 \newline 
8497 ;; !\SpecialChar ~
8498 \SpecialChar ~
8499 \SpecialChar ~
8500 \SpecialChar ~
8501 \SpecialChar ~
8502 \SpecialChar ~
8503 \SpecialChar ~
8504 \SpecialChar ~
8505 \SpecialChar ~
8506 \SpecialChar ~
8507 \SpecialChar ~
8508 \SpecialChar ~
8509 \SpecialChar ~
8510 \SpecialChar ~
8511  sdcdbsrc-goto-sdcdb\SpecialChar ~
8512 \SpecialChar ~
8513 \SpecialChar ~
8514 \SpecialChar ~
8515 \SpecialChar ~
8516 \SpecialChar ~
8517 \SpecialChar ~
8518 \SpecialChar ~
8519 \SpecialChar ~
8520 \SpecialChar ~
8521 Goto the SDCDB output buffer 
8522 \newline 
8523 ;; p\SpecialChar ~
8524 \SpecialChar ~
8525 \SpecialChar ~
8526 \SpecialChar ~
8527 \SpecialChar ~
8528 \SpecialChar ~
8529 \SpecialChar ~
8530 \SpecialChar ~
8531 \SpecialChar ~
8532 \SpecialChar ~
8533 \SpecialChar ~
8534 \SpecialChar ~
8535 \SpecialChar ~
8536 \SpecialChar ~
8537  sdcdb-print-c-sexp\SpecialChar ~
8538 \SpecialChar ~
8539 \SpecialChar ~
8540 \SpecialChar ~
8541 \SpecialChar ~
8542 \SpecialChar ~
8543 \SpecialChar ~
8544 \SpecialChar ~
8545 \SpecialChar ~
8546 \SpecialChar ~
8547 \SpecialChar ~
8548 SDCDB print command for data at 
8549 \newline 
8550 ;;\SpecialChar ~
8551 \SpecialChar ~
8552 \SpecialChar ~
8553 \SpecialChar ~
8554 \SpecialChar ~
8555 \SpecialChar ~
8556 \SpecialChar ~
8557 \SpecialChar ~
8558 \SpecialChar ~
8559 \SpecialChar ~
8560 \SpecialChar ~
8561 \SpecialChar ~
8562 \SpecialChar ~
8563 \SpecialChar ~
8564 \SpecialChar ~
8565 \SpecialChar ~
8566 \SpecialChar ~
8567 \SpecialChar ~
8568 \SpecialChar ~
8569 \SpecialChar ~
8570 \SpecialChar ~
8571 \SpecialChar ~
8572 \SpecialChar ~
8573 \SpecialChar ~
8574 \SpecialChar ~
8575 \SpecialChar ~
8576 \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  buffer point 
8597 \newline 
8598 ;; g\SpecialChar ~
8599 \SpecialChar ~
8600 \SpecialChar ~
8601 \SpecialChar ~
8602 \SpecialChar ~
8603 \SpecialChar ~
8604 \SpecialChar ~
8605 \SpecialChar ~
8606 \SpecialChar ~
8607 \SpecialChar ~
8608 \SpecialChar ~
8609 \SpecialChar ~
8610 \SpecialChar ~
8611 \SpecialChar ~
8612  sdcdbsrc-goto-sdcdb\SpecialChar ~
8613 \SpecialChar ~
8614 \SpecialChar ~
8615 \SpecialChar ~
8616 \SpecialChar ~
8617 \SpecialChar ~
8618 \SpecialChar ~
8619 \SpecialChar ~
8620 \SpecialChar ~
8621 \SpecialChar ~
8622 Goto the SDCDB output buffer 
8623 \newline 
8624 ;; t\SpecialChar ~
8625 \SpecialChar ~
8626 \SpecialChar ~
8627 \SpecialChar ~
8628 \SpecialChar ~
8629 \SpecialChar ~
8630 \SpecialChar ~
8631 \SpecialChar ~
8632 \SpecialChar ~
8633 \SpecialChar ~
8634 \SpecialChar ~
8635 \SpecialChar ~
8636 \SpecialChar ~
8637 \SpecialChar ~
8638  sdcdbsrc-mode\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 \SpecialChar ~
8652 \SpecialChar ~
8653 \SpecialChar ~
8654 Toggles Sdcdbsrc mode (turns it off) 
8655 \newline 
8656 ;; 
8657 \newline 
8658 ;; C-c C-f\SpecialChar ~
8659 \SpecialChar ~
8660 \SpecialChar ~
8661 \SpecialChar ~
8662 \SpecialChar ~
8663 \SpecialChar ~
8664 \SpecialChar ~
8665 \SpecialChar ~
8666  sdcdb-finish-from-src\SpecialChar ~
8667 \SpecialChar ~
8668 \SpecialChar ~
8669 \SpecialChar ~
8670 \SpecialChar ~
8671 \SpecialChar ~
8672 \SpecialChar ~
8673 \SpecialChar ~
8674 SDCDB finish command 
8675 \newline 
8676 ;; 
8677 \newline 
8678 ;; C-x SPC\SpecialChar ~
8679 \SpecialChar ~
8680 \SpecialChar ~
8681 \SpecialChar ~
8682 \SpecialChar ~
8683 \SpecialChar ~
8684 \SpecialChar ~
8685 \SpecialChar ~
8686  sdcdb-break\SpecialChar ~
8687 \SpecialChar ~
8688 \SpecialChar ~
8689 \SpecialChar ~
8690 \SpecialChar ~
8691 \SpecialChar ~
8692 \SpecialChar ~
8693 \SpecialChar ~
8694 \SpecialChar ~
8695 \SpecialChar ~
8696 \SpecialChar ~
8697 \SpecialChar ~
8698 \SpecialChar ~
8699 \SpecialChar ~
8700 \SpecialChar ~
8701 \SpecialChar ~
8702 \SpecialChar ~
8703 \SpecialChar ~
8704 Set break for line with point 
8705 \newline 
8706 ;; ESC t\SpecialChar ~
8707 \SpecialChar ~
8708 \SpecialChar ~
8709 \SpecialChar ~
8710 \SpecialChar ~
8711 \SpecialChar ~
8712 \SpecialChar ~
8713 \SpecialChar ~
8714 \SpecialChar ~
8715 \SpecialChar ~
8716  sdcdbsrc-mode\SpecialChar ~
8717 \SpecialChar ~
8718 \SpecialChar ~
8719 \SpecialChar ~
8720 \SpecialChar ~
8721 \SpecialChar ~
8722 \SpecialChar ~
8723 \SpecialChar ~
8724 \SpecialChar ~
8725 \SpecialChar ~
8726 \SpecialChar ~
8727 \SpecialChar ~
8728 \SpecialChar ~
8729 \SpecialChar ~
8730 \SpecialChar ~
8731 \SpecialChar ~
8732 Toggle Sdcdbsrc mode 
8733 \newline 
8734 ;; ESC m\SpecialChar ~
8735 \SpecialChar ~
8736 \SpecialChar ~
8737 \SpecialChar ~
8738 \SpecialChar ~
8739 \SpecialChar ~
8740 \SpecialChar ~
8741 \SpecialChar ~
8742 \SpecialChar ~
8743 \SpecialChar ~
8744  sdcdbsrc-srcmode\SpecialChar ~
8745 \SpecialChar ~
8746 \SpecialChar ~
8747 \SpecialChar ~
8748 \SpecialChar ~
8749 \SpecialChar ~
8750 \SpecialChar ~
8751 \SpecialChar ~
8752 \SpecialChar ~
8753 \SpecialChar ~
8754 \SpecialChar ~
8755 \SpecialChar ~
8756  Toggle list mode 
8757 \newline 
8758 ;; 
8759 \family default 
8760
8761 \newline 
8762
8763 \layout Section
8764
8765 Other Processors
8766 \layout Subsection
8767
8768 The Z80 and gbz80 port
8769 \layout Standard
8770
8771 SDCC can target both the Zilog Z80 and the Nintendo Gameboy's Z80-like gbz80.
8772  The port is incomplete - long support is incomplete (mul, div and mod are
8773  unimplimented), and both float and bitfield support is missing.
8774  Apart from that the code generated is correct.
8775 \layout Standard
8776
8777 As always, the code is the authoritave reference - see z80/ralloc.c and z80/gen.c.
8778  The stack frame is similar to that generated by the IAR Z80 compiler.
8779  IX is used as the base pointer, HL is used as a temporary register, and
8780  BC and DE are available for holding varibles.
8781  IY is currently unusued.
8782  Return values are stored in HL.
8783  One bad side effect of using IX as the base pointer is that a functions
8784  stack frame is limited to 127 bytes - this will be fixed in a later version.
8785 \layout Section
8786
8787 Support
8788 \layout Standard
8789
8790 SDCC has grown to be a large project.
8791  The compiler alone (without the preprocessor, assembler and linker) is
8792  about 40,000 lines of code (blank stripped).
8793  The open source nature of this project is a key to its continued growth
8794  and support.
8795  You gain the benefit and support of many active software developers and
8796  end users.
8797  Is SDCC perfect? No, that's why we need your help.
8798  The developers take pride in fixing reported bugs.
8799  You can help by reporting the bugs and helping other SDCC users.
8800  There are lots of ways to contribute, and we encourage you to take part
8801  in making SDCC a great software package.
8802 \layout Subsection
8803
8804 Reporting Bugs
8805 \layout Standard
8806
8807 Send an email to the mailing list at 'user-sdcc@sdcc.sourceforge.net' or 'devel-sd
8808 cc@sdcc.sourceforge.net'.
8809  Bugs will be fixed ASAP.
8810  When reporting a bug, it is very useful to include a small test program
8811  which reproduces the problem.
8812  If you can isolate the problem by looking at the generated assembly code,
8813  this can be very helpful.
8814  Compiling your program with the ---dumpall option can sometimes be useful
8815  in locating optimization problems.
8816 \layout Section
8817
8818 Compiler internals
8819 \layout Subsection
8820
8821 The anatomy of the compiler
8822 \layout Standard
8823
8824
8825 \shape italic 
8826 This is an excerpt from an atricle published in Circuit Cellar MagaZine
8827  in august 2000.
8828  It's a little outdated (the compiler is much more efficient now and user/devell
8829 oper friendly), but pretty well exposes the guts of it all.
8830 \shape default 
8831
8832 \newline 
8833
8834 \newline 
8835 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
8836  It is fairly easy to retarget for other 8-bit MCU.
8837  Here we take a look at some of the internals of the compiler.
8838  
8839 \layout Paragraph*
8840
8841 Parsing 
8842 \layout Standard
8843
8844 Parsing the input source file and creating an AST (Annotated Syntax Tree).
8845  This phase also involves propagating types (annotating each node of the
8846  parse tree with type information) and semantic analysis.
8847  There are some MCU specific parsing rules.
8848  For example the storage classes, the extended storage classes are MCU specific
8849  while there may be a xdata storage class for 8051 there is no such storage
8850  class for z80 or Atmel AVR.
8851  SDCC allows MCU specific storage class extensions, i.e.
8852  xdata will be treated as a storage class specifier when parsing 8051 C
8853  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
8854  C code.
8855 \layout Paragraph*
8856
8857 Generating iCode
8858 \layout Standard
8859
8860 Intermediate code generation.
8861  In this phase the AST is broken down into three-operand form (iCode).
8862  These three operand forms are represented as doubly linked lists.
8863  ICode is the term given to the intermediate form generated by the compiler.
8864  ICode example section shows some examples of iCode generated for some simple
8865  C source functions.
8866 \layout Paragraph*
8867
8868 Optimizations.
8869 \layout Standard
8870
8871 Bulk of the target independent optimizations is performed in this phase.
8872  The optimizations include constant propagation, common sub-expression eliminati
8873 on, loop invariant code movement, strength reduction of loop induction variables
8874  and dead-code elimination.
8875 \layout Paragraph*
8876
8877 Live range analysis
8878 \layout Standard
8879
8880 During intermediate code generation phase, the compiler assumes the target
8881  machine has infinite number of registers and generates a lot of temporary
8882  variables.
8883  The live range computation determines the lifetime of each of these compiler-ge
8884 nerated temporaries.
8885  A picture speaks a thousand words.
8886  ICode example sections show the live range annotations for each of the
8887  operand.
8888  It is important to note here, each iCode is assigned a number in the order
8889  of its execution in the function.
8890  The live ranges are computed in terms of these numbers.
8891  The from number is the number of the iCode which first defines the operand
8892  and the to number signifies the iCode which uses this operand last.
8893 \layout Paragraph*
8894
8895 Register Allocation
8896 \layout Standard
8897
8898 The register allocation determines the type and number of registers needed
8899  by each operand.
8900  In most MCUs only a few registers can be used for indirect addressing.
8901  In case of 8051 for example the registers R0 & R1 can be used to indirectly
8902  address the internal ram and DPTR to indirectly address the external ram.
8903  The compiler will try to allocate the appropriate register to pointer variables
8904  if it can.
8905  ICode example section shows the operands annotated with the registers assigned
8906  to them.
8907  The compiler will try to keep operands in registers as much as possible;
8908  there are several schemes the compiler uses to do achieve this.
8909  When the compiler runs out of registers the compiler will check to see
8910  if there are any live operands which is not used or defined in the current
8911  basic block being processed, if there are any found then it will push that
8912  operand and use the registers in this block, the operand will then be popped
8913  at the end of the basic block.
8914  
8915 \layout Standard
8916
8917 There are other MCU specific considerations in this phase.
8918  Some MCUs have an accumulator; very short-lived operands could be assigned
8919  to the accumulator instead of general-purpose register.
8920 \layout Paragraph*
8921
8922 Code generation
8923 \layout Standard
8924
8925 Figure II gives a table of iCode operations supported by the compiler.
8926  The code generation involves translating these operations into corresponding
8927  assembly code for the processor.
8928  This sounds overly simple but that is the essence of code generation.
8929  Some of the iCode operations are generated on a MCU specific manner for
8930  example, the z80 port does not use registers to pass parameters so the
8931  SEND and RECV iCode operations will not be generated, and it also does
8932  not support JUMPTABLES.
8933  
8934 \newline 
8935
8936 \series bold 
8937 \shape italic 
8938 \color red
8939 <Where is Figure II ?>
8940 \layout Paragraph*
8941
8942 ICode Example
8943 \layout Standard
8944
8945 This section shows some details of iCode.
8946  The example C code does not do anything useful; it is used as an example
8947  to illustrate the intermediate code generated by the compiler.
8948 \newline 
8949
8950 \newline 
8951
8952 \family typewriter 
8953 1.\SpecialChar ~
8954 xdata int * p;
8955 \newline 
8956 2.\SpecialChar ~
8957 int gint;
8958 \newline 
8959 3.\SpecialChar ~
8960 /* This function does nothing useful.
8961  It is used
8962 \newline 
8963 4.\SpecialChar ~
8964 \SpecialChar ~
8965 \SpecialChar ~
8966 \SpecialChar ~
8967 for the purpose of explaining iCode */
8968 \newline 
8969 5.\SpecialChar ~
8970 short function (data int *x)
8971 \newline 
8972 6.\SpecialChar ~
8973 {
8974 \newline 
8975 7.\SpecialChar ~
8976 \SpecialChar ~
8977 \SpecialChar ~
8978 short i=10; /* dead initialization eliminated */
8979 \newline 
8980 8.\SpecialChar ~
8981 \SpecialChar ~
8982 \SpecialChar ~
8983 short sum=10; /* dead initialization eliminated */
8984 \newline 
8985 9.\SpecialChar ~
8986 \SpecialChar ~
8987 \SpecialChar ~
8988 short mul;
8989 \newline 
8990 10.\SpecialChar ~
8991 \SpecialChar ~
8992 int j ;
8993 \newline 
8994 11.\SpecialChar ~
8995 \SpecialChar ~
8996 while (*x) *x++ = *p++; 
8997 \newline 
8998 12.\SpecialChar ~
8999 \SpecialChar ~
9000 \SpecialChar ~
9001 \SpecialChar ~
9002 sum = 0 ; 
9003 \newline 
9004 13.\SpecialChar ~
9005 \SpecialChar ~
9006 mul = 0;
9007 \newline 
9008 14.\SpecialChar ~
9009 \SpecialChar ~
9010 /* compiler detects i,j to be induction variables */
9011 \newline 
9012 15.\SpecialChar ~
9013 \SpecialChar ~
9014 for (i = 0, j = 10 ; i < 10 ; i++, j---) {
9015 \newline 
9016 16.\SpecialChar ~
9017 \SpecialChar ~
9018 \SpecialChar ~
9019 \SpecialChar ~
9020 sum += i;
9021 \newline 
9022 17.\SpecialChar ~
9023 \SpecialChar ~
9024 \SpecialChar ~
9025 \SpecialChar ~
9026 mul += i * 3; /* this multiplication remains */
9027 \newline 
9028 18.\SpecialChar ~
9029 \SpecialChar ~
9030 \SpecialChar ~
9031 \SpecialChar ~
9032 gint += j * 3;/* this multiplication changed to addition */
9033 \newline 
9034 19.\SpecialChar ~
9035 \SpecialChar ~
9036 }
9037 \newline 
9038 20.\SpecialChar ~
9039 \SpecialChar ~
9040 return sum+mul;
9041 \newline 
9042 21.\SpecialChar ~
9043 }
9044 \newline 
9045
9046 \newline 
9047
9048 \family default 
9049 In addition to the operands each iCode contains information about the filename
9050  and line it corresponds to in the source file.
9051  The first field in the listing should be interpreted as follows:
9052 \newline 
9053
9054 \shape italic 
9055 \size footnotesize 
9056 Filename(linenumber: iCode Execution sequence number : ICode hash table
9057  key : loop depth of the iCode).
9058 \shape default 
9059 \size default 
9060
9061 \newline 
9062 Then follows the human readable form of the ICode operation.
9063  Each operand of this triplet form can be of three basic types a) compiler
9064  generated temporary b) user defined variable c) a constant value.
9065  Note that local variables and parameters are replaced by compiler generated
9066  temporaries.
9067  Live ranges are computed only for temporaries (i.e.
9068  live ranges are not computed for global variables).
9069  Registers are allocated for temporaries only.
9070  Operands are formatted in the following manner:
9071 \newline 
9072
9073 \shape italic 
9074 \size footnotesize 
9075 Operand Name [lr live-from : live-to ] { type information } [ registers
9076  allocated ].
9077 \shape default 
9078 \size default 
9079
9080 \newline 
9081 As mentioned earlier the live ranges are computed in terms of the execution
9082  sequence number of the iCodes, for example 
9083 \newline 
9084 the iTemp0 is live from (i.e.
9085  first defined in iCode with execution sequence number 3, and is last used
9086  in the iCode with sequence number 5).
9087  For induction variables such as iTemp21 the live range computation extends
9088  the lifetime from the start to the end of the loop.
9089 \newline 
9090 The register allocator used the live range information to allocate registers,
9091  the same registers may be used for different temporaries if their live
9092  ranges do not overlap, for example r0 is allocated to both iTemp6 and to
9093  iTemp17 since their live ranges do not overlap.
9094  In addition the allocator also takes into consideration the type and usage
9095  of a temporary, for example itemp6 is a pointer to near space and is used
9096  as to fetch data from (i.e.
9097  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer registers (r0).
9098  Some short lived temporaries are allocated to special registers which have
9099  meaning to the code generator e.g.
9100  iTemp13 is allocated to a pseudo register CC which tells the back end that
9101  the temporary is used only for a conditional jump the code generation makes
9102  use of this information to optimize a compare and jump ICode.
9103 \newline 
9104 There are several loop optimizations performed by the compiler.
9105  It can detect induction variables iTemp21(i) and iTemp23(j).
9106  Also note the compiler does selective strength reduction, i.e.
9107  the multiplication of an induction variable in line 18 (gint = j * 3) is
9108  changed to addition, a new temporary iTemp17 is allocated and assigned
9109  a initial value, a constant 3 is then added for each iteration of the loop.
9110  The compiler does not change the multiplication in line 17 however since
9111  the processor does support an 8 * 8 bit multiplication.
9112 \newline 
9113 Note the dead code elimination optimization eliminated the dead assignments
9114  in line 7 & 8 to I and sum respectively.
9115 \newline 
9116
9117 \layout Standard
9118
9119
9120 \size footnotesize 
9121 Sample.c (5:1:0:0) _entry($9) :
9122 \layout Standard
9123
9124
9125 \size footnotesize 
9126 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
9127 \layout Standard
9128
9129
9130 \size footnotesize 
9131 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
9132 \layout Standard
9133
9134
9135 \size footnotesize 
9136 Sample.c(11:4:53:0) preHeaderLbl0($11) :
9137 \layout Standard
9138
9139
9140 \size footnotesize 
9141 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
9142  * int}[r2]
9143 \layout Standard
9144
9145
9146 \size footnotesize 
9147 Sample.c(11:6:5:1) _whilecontinue_0($1) :
9148 \layout Standard
9149
9150
9151 \size footnotesize 
9152 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
9153  int}[r0]]
9154 \layout Standard
9155
9156
9157 \size footnotesize 
9158 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
9159 \layout Standard
9160
9161
9162 \size footnotesize 
9163 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
9164  * int}
9165 \layout Standard
9166
9167
9168 \size footnotesize 
9169 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
9170  {short}
9171 \layout Standard
9172
9173
9174 \size footnotesize 
9175 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
9176  * int}[DPTR]]
9177 \layout Standard
9178
9179
9180 \size footnotesize 
9181 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
9182 }[r2 r3]
9183 \layout Standard
9184
9185
9186 \size footnotesize 
9187 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
9188  * int}[r0] + 0x2 {short}
9189 \layout Standard
9190
9191
9192 \size footnotesize 
9193 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
9194 \layout Standard
9195
9196
9197 \size footnotesize 
9198 Sample.c(11:17:21:0)_whilebreak_0($3) :
9199 \layout Standard
9200
9201
9202 \size footnotesize 
9203 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
9204 \layout Standard
9205
9206
9207 \size footnotesize 
9208 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
9209 \layout Standard
9210
9211
9212 \size footnotesize 
9213 Sample.c(15:20:54:0)preHeaderLbl1($13) :
9214 \layout Standard
9215
9216
9217 \size footnotesize 
9218 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
9219 \layout Standard
9220
9221
9222 \size footnotesize 
9223 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
9224 \layout Standard
9225
9226
9227 \size footnotesize 
9228 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
9229 \layout Standard
9230
9231
9232 \size footnotesize 
9233 Sample.c(15:24:26:1)_forcond_0($4) :
9234 \layout Standard
9235
9236
9237 \size footnotesize 
9238 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
9239  < 0xa {short}
9240 \layout Standard
9241
9242
9243 \size footnotesize 
9244 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
9245 \layout Standard
9246
9247
9248 \size footnotesize 
9249 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
9250  + ITemp21 [lr21:38]{short}[r4]
9251 \layout Standard
9252
9253
9254 \size footnotesize 
9255 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
9256  * 0x3 {short}
9257 \layout Standard
9258
9259
9260 \size footnotesize 
9261 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
9262  + iTemp15 [lr29:30]{short}[r1]
9263 \layout Standard
9264
9265
9266 \size footnotesize 
9267 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
9268  r0]- 0x3 {short}
9269 \layout Standard
9270
9271
9272 \size footnotesize 
9273 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
9274 int}[r7 r0]
9275 \layout Standard
9276
9277
9278 \size footnotesize 
9279 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
9280  + 0x1 {short}
9281 \layout Standard
9282
9283
9284 \size footnotesize 
9285 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
9286  r6]- 0x1 {short}
9287 \layout Standard
9288
9289
9290 \size footnotesize 
9291 Sample.c(19:38:47:1) goto _forcond_0($4)
9292 \layout Standard
9293
9294
9295 \size footnotesize 
9296 Sample.c(19:39:48:0)_forbreak_0($7) :
9297 \layout Standard
9298
9299
9300 \size footnotesize 
9301 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
9302  + ITemp11 [lr19:40]{short}[r3]
9303 \layout Standard
9304
9305
9306 \size footnotesize 
9307 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
9308 \layout Standard
9309
9310
9311 \size footnotesize 
9312 Sample.c(20:42:51:0)_return($8) :
9313 \layout Standard
9314
9315
9316 \size footnotesize 
9317 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
9318 \size default 
9319
9320 \newline 
9321
9322 \newline 
9323 Finally the code generated for this function:
9324 \newline 
9325
9326 \layout Standard
9327
9328
9329 \size footnotesize 
9330 .area DSEG (DATA)
9331 \layout Standard
9332
9333
9334 \size footnotesize 
9335 _p::
9336 \layout Standard
9337
9338
9339 \size footnotesize 
9340 \SpecialChar ~
9341 \SpecialChar ~
9342 .ds 2
9343 \layout Standard
9344
9345
9346 \size footnotesize 
9347 _gint::
9348 \layout Standard
9349
9350
9351 \size footnotesize 
9352 \SpecialChar ~
9353 \SpecialChar ~
9354 .ds 2
9355 \layout Standard
9356
9357
9358 \size footnotesize 
9359 ; sample.c 5
9360 \layout Standard
9361
9362
9363 \size footnotesize 
9364 ; ----------------------------------------------
9365 \layout Standard
9366
9367
9368 \size footnotesize 
9369 ; function function
9370 \layout Standard
9371
9372
9373 \size footnotesize 
9374 ; ----------------------------------------------
9375 \layout Standard
9376
9377
9378 \size footnotesize 
9379 _function:
9380 \layout Standard
9381
9382
9383 \size footnotesize 
9384 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
9385 \layout Standard
9386
9387
9388 \size footnotesize 
9389 \SpecialChar ~
9390 \SpecialChar ~
9391 mov r2,dpl
9392 \layout Standard
9393
9394
9395 \size footnotesize 
9396 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
9397 \layout Standard
9398
9399
9400 \size footnotesize 
9401 \SpecialChar ~
9402 \SpecialChar ~
9403 mov ar0,r2
9404 \layout Standard
9405
9406
9407 \size footnotesize 
9408 ;_whilecontinue_0($1) :
9409 \layout Standard
9410
9411
9412 \size footnotesize 
9413 00101$:
9414 \layout Standard
9415
9416
9417 \size footnotesize 
9418 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
9419 \layout Standard
9420
9421
9422 \size footnotesize 
9423 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
9424 \layout Standard
9425
9426
9427 \size footnotesize 
9428 \SpecialChar ~
9429 \SpecialChar ~
9430 mov ar2,@r0
9431 \layout Standard
9432
9433
9434 \size footnotesize 
9435 \SpecialChar ~
9436 \SpecialChar ~
9437 inc r0
9438 \layout Standard
9439
9440
9441 \size footnotesize 
9442 \SpecialChar ~
9443 \SpecialChar ~
9444 mov ar3,@r0
9445 \layout Standard
9446
9447
9448 \size footnotesize 
9449 \SpecialChar ~
9450 \SpecialChar ~
9451 dec r0
9452 \layout Standard
9453
9454
9455 \size footnotesize 
9456 \SpecialChar ~
9457 \SpecialChar ~
9458 mov a,r2
9459 \layout Standard
9460
9461
9462 \size footnotesize 
9463 \SpecialChar ~
9464 \SpecialChar ~
9465 orl a,r3
9466 \layout Standard
9467
9468
9469 \size footnotesize 
9470 \SpecialChar ~
9471 \SpecialChar ~
9472 jz 00103$
9473 \layout Standard
9474
9475
9476 \size footnotesize 
9477 00114$:
9478 \layout Standard
9479
9480
9481 \size footnotesize 
9482 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
9483 \layout Standard
9484
9485
9486 \size footnotesize 
9487 \SpecialChar ~
9488 \SpecialChar ~
9489 mov dpl,_p
9490 \layout Standard
9491
9492
9493 \size footnotesize 
9494 \SpecialChar ~
9495 \SpecialChar ~
9496 mov dph,(_p + 1)
9497 \layout Standard
9498
9499
9500 \size footnotesize 
9501 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
9502 \layout Standard
9503
9504
9505 \size footnotesize 
9506 \SpecialChar ~
9507 \SpecialChar ~
9508 mov a,#0x02
9509 \layout Standard
9510
9511
9512 \size footnotesize 
9513 \SpecialChar ~
9514 \SpecialChar ~
9515 add a,_p
9516 \layout Standard
9517
9518
9519 \size footnotesize 
9520 \SpecialChar ~
9521 \SpecialChar ~
9522 mov _p,a
9523 \layout Standard
9524
9525
9526 \size footnotesize 
9527 \SpecialChar ~
9528 \SpecialChar ~
9529 clr a
9530 \layout Standard
9531
9532
9533 \size footnotesize 
9534 \SpecialChar ~
9535 \SpecialChar ~
9536 addc a,(_p + 1)
9537 \layout Standard
9538
9539
9540 \size footnotesize 
9541 \SpecialChar ~
9542 \SpecialChar ~
9543 mov (_p + 1),a
9544 \layout Standard
9545
9546
9547 \size footnotesize 
9548 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
9549 \layout Standard
9550
9551
9552 \size footnotesize 
9553 \SpecialChar ~
9554 \SpecialChar ~
9555 movx a,@dptr
9556 \layout Standard
9557
9558
9559 \size footnotesize 
9560 \SpecialChar ~
9561 \SpecialChar ~
9562 mov r2,a
9563 \layout Standard
9564
9565
9566 \size footnotesize 
9567 \SpecialChar ~
9568 \SpecialChar ~
9569 inc dptr
9570 \layout Standard
9571
9572
9573 \size footnotesize 
9574 \SpecialChar ~
9575 \SpecialChar ~
9576 movx a,@dptr
9577 \layout Standard
9578
9579
9580 \size footnotesize 
9581 \SpecialChar ~
9582 \SpecialChar ~
9583 mov r3,a
9584 \layout Standard
9585
9586
9587 \size footnotesize 
9588 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
9589 \layout Standard
9590
9591
9592 \size footnotesize 
9593 \SpecialChar ~
9594 \SpecialChar ~
9595 mov @r0,ar2
9596 \layout Standard
9597
9598
9599 \size footnotesize 
9600 \SpecialChar ~
9601 \SpecialChar ~
9602 inc r0
9603 \layout Standard
9604
9605
9606 \size footnotesize 
9607 \SpecialChar ~
9608 \SpecialChar ~
9609 mov @r0,ar3
9610 \layout Standard
9611
9612
9613 \size footnotesize 
9614 ; iTemp6 [lr5:16]{_near * int}[r0] = 
9615 \layout Standard
9616
9617
9618 \size footnotesize 
9619 ; iTemp6 [lr5:16]{_near * int}[r0] + 
9620 \layout Standard
9621
9622
9623 \size footnotesize 
9624 ; 0x2 {short}
9625 \layout Standard
9626
9627
9628 \size footnotesize 
9629 \SpecialChar ~
9630 \SpecialChar ~
9631 inc r0
9632 \layout Standard
9633
9634
9635 \size footnotesize 
9636 ; goto _whilecontinue_0($1)
9637 \layout Standard
9638
9639
9640 \size footnotesize 
9641 \SpecialChar ~
9642 \SpecialChar ~
9643 sjmp 00101$
9644 \layout Standard
9645
9646
9647 \size footnotesize 
9648 ; _whilebreak_0($3) :
9649 \layout Standard
9650
9651
9652 \size footnotesize 
9653 00103$:
9654 \layout Standard
9655
9656
9657 \size footnotesize 
9658 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
9659 \layout Standard
9660
9661
9662 \size footnotesize 
9663 \SpecialChar ~
9664 \SpecialChar ~
9665 mov r2,#0x00
9666 \layout Standard
9667
9668
9669 \size footnotesize 
9670 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
9671 \layout Standard
9672
9673
9674 \size footnotesize 
9675 \SpecialChar ~
9676 \SpecialChar ~
9677 mov r3,#0x00
9678 \layout Standard
9679
9680
9681 \size footnotesize 
9682 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
9683 \layout Standard
9684
9685
9686 \size footnotesize 
9687 \SpecialChar ~
9688 \SpecialChar ~
9689 mov r4,#0x00
9690 \layout Standard
9691
9692
9693 \size footnotesize 
9694 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
9695 \layout Standard
9696
9697
9698 \size footnotesize 
9699 \SpecialChar ~
9700 \SpecialChar ~
9701 mov r5,#0x0A
9702 \layout Standard
9703
9704
9705 \size footnotesize 
9706 \SpecialChar ~
9707 \SpecialChar ~
9708 mov r6,#0x00
9709 \layout Standard
9710
9711
9712 \size footnotesize 
9713 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
9714 \layout Standard
9715
9716
9717 \size footnotesize 
9718 \SpecialChar ~
9719 \SpecialChar ~
9720 mov r7,#0x1E
9721 \layout Standard
9722
9723
9724 \size footnotesize 
9725 \SpecialChar ~
9726 \SpecialChar ~
9727 mov r0,#0x00
9728 \layout Standard
9729
9730
9731 \size footnotesize 
9732 ; _forcond_0($4) :
9733 \layout Standard
9734
9735
9736 \size footnotesize 
9737 00104$:
9738 \layout Standard
9739
9740
9741 \size footnotesize 
9742 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
9743 \layout Standard
9744
9745
9746 \size footnotesize 
9747 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
9748 \layout Standard
9749
9750
9751 \size footnotesize 
9752 \SpecialChar ~
9753 \SpecialChar ~
9754 clr c
9755 \layout Standard
9756
9757
9758 \size footnotesize 
9759 \SpecialChar ~
9760 \SpecialChar ~
9761 mov a,r4
9762 \layout Standard
9763
9764
9765 \size footnotesize 
9766 \SpecialChar ~
9767 \SpecialChar ~
9768 xrl a,#0x80
9769 \layout Standard
9770
9771
9772 \size footnotesize 
9773 \SpecialChar ~
9774 \SpecialChar ~
9775 subb a,#0x8a
9776 \layout Standard
9777
9778
9779 \size footnotesize 
9780 \SpecialChar ~
9781 \SpecialChar ~
9782 jnc 00107$
9783 \layout Standard
9784
9785
9786 \size footnotesize 
9787 00115$:
9788 \layout Standard
9789
9790
9791 \size footnotesize 
9792 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
9793 \layout Standard
9794
9795
9796 \size footnotesize 
9797 ; iTemp21 [lr21:38]{short}[r4]
9798 \layout Standard
9799
9800
9801 \size footnotesize 
9802 \SpecialChar ~
9803 \SpecialChar ~
9804 mov a,r4
9805 \layout Standard
9806
9807
9808 \size footnotesize 
9809 \SpecialChar ~
9810 \SpecialChar ~
9811 add a,r2
9812 \layout Standard
9813
9814
9815 \size footnotesize 
9816 \SpecialChar ~
9817 \SpecialChar ~
9818 mov r2,a
9819 \layout Standard
9820
9821
9822 \size footnotesize 
9823 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
9824 \layout Standard
9825
9826
9827 \size footnotesize 
9828 \SpecialChar ~
9829 \SpecialChar ~
9830 mov b,#0x03
9831 \layout Standard
9832
9833
9834 \size footnotesize 
9835 \SpecialChar ~
9836 \SpecialChar ~
9837 mov a,r4
9838 \layout Standard
9839
9840
9841 \size footnotesize 
9842 \SpecialChar ~
9843 \SpecialChar ~
9844 mul ab
9845 \layout Standard
9846
9847
9848 \size footnotesize 
9849 \SpecialChar ~
9850 \SpecialChar ~
9851 mov r1,a
9852 \layout Standard
9853
9854
9855 \size footnotesize 
9856 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
9857 \layout Standard
9858
9859
9860 \size footnotesize 
9861 ; iTemp15 [lr29:30]{short}[r1]
9862 \layout Standard
9863
9864
9865 \size footnotesize 
9866 \SpecialChar ~
9867 \SpecialChar ~
9868 add a,r3
9869 \layout Standard
9870
9871
9872 \size footnotesize 
9873 \SpecialChar ~
9874 \SpecialChar ~
9875 mov r3,a
9876 \layout Standard
9877
9878
9879 \size footnotesize 
9880 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
9881 \layout Standard
9882
9883
9884 \size footnotesize 
9885 \SpecialChar ~
9886 \SpecialChar ~
9887 mov a,r7
9888 \layout Standard
9889
9890
9891 \size footnotesize 
9892 \SpecialChar ~
9893 \SpecialChar ~
9894 add a,#0xfd
9895 \layout Standard
9896
9897
9898 \size footnotesize 
9899 \SpecialChar ~
9900 \SpecialChar ~
9901 mov r7,a
9902 \layout Standard
9903
9904
9905 \size footnotesize 
9906 \SpecialChar ~
9907 \SpecialChar ~
9908 mov a,r0
9909 \layout Standard
9910
9911
9912 \size footnotesize 
9913 \SpecialChar ~
9914 \SpecialChar ~
9915 addc a,#0xff
9916 \layout Standard
9917
9918
9919 \size footnotesize 
9920 \SpecialChar ~
9921 \SpecialChar ~
9922 mov r0,a
9923 \layout Standard
9924
9925
9926 \size footnotesize 
9927 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
9928 \layout Standard
9929
9930
9931 \size footnotesize 
9932 \SpecialChar ~
9933 \SpecialChar ~
9934 mov a,r7
9935 \layout Standard
9936
9937
9938 \size footnotesize 
9939 \SpecialChar ~
9940 \SpecialChar ~
9941 add a,_gint
9942 \layout Standard
9943
9944
9945 \size footnotesize 
9946 \SpecialChar ~
9947 \SpecialChar ~
9948 mov _gint,a
9949 \layout Standard
9950
9951
9952 \size footnotesize 
9953 \SpecialChar ~
9954 \SpecialChar ~
9955 mov a,r0
9956 \layout Standard
9957
9958
9959 \size footnotesize 
9960 \SpecialChar ~
9961 \SpecialChar ~
9962 addc a,(_gint + 1)
9963 \layout Standard
9964
9965
9966 \size footnotesize 
9967 \SpecialChar ~
9968 \SpecialChar ~
9969 mov (_gint + 1),a
9970 \layout Standard
9971
9972
9973 \size footnotesize 
9974 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
9975 \layout Standard
9976
9977
9978 \size footnotesize 
9979 \SpecialChar ~
9980 \SpecialChar ~
9981 inc r4
9982 \layout Standard
9983
9984
9985 \size footnotesize 
9986 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
9987 \layout Standard
9988
9989
9990 \size footnotesize 
9991 \SpecialChar ~
9992 \SpecialChar ~
9993 dec r5
9994 \layout Standard
9995
9996
9997 \size footnotesize 
9998 \SpecialChar ~
9999 \SpecialChar ~
10000 cjne r5,#0xff,00104$
10001 \layout Standard
10002
10003
10004 \size footnotesize 
10005 \SpecialChar ~
10006 \SpecialChar ~
10007 dec r6
10008 \layout Standard
10009
10010
10011 \size footnotesize 
10012 ; goto _forcond_0($4)
10013 \layout Standard
10014
10015
10016 \size footnotesize 
10017 \SpecialChar ~
10018 \SpecialChar ~
10019 sjmp 00104$
10020 \layout Standard
10021
10022
10023 \size footnotesize 
10024 ; _forbreak_0($7) :
10025 \layout Standard
10026
10027
10028 \size footnotesize 
10029 00107$:
10030 \layout Standard
10031
10032
10033 \size footnotesize 
10034 ; ret iTemp24 [lr40:41]{short}
10035 \layout Standard
10036
10037
10038 \size footnotesize 
10039 \SpecialChar ~
10040 \SpecialChar ~
10041 mov a,r3
10042 \layout Standard
10043
10044
10045 \size footnotesize 
10046 \SpecialChar ~
10047 \SpecialChar ~
10048 add a,r2
10049 \layout Standard
10050
10051
10052 \size footnotesize 
10053 \SpecialChar ~
10054 \SpecialChar ~
10055 mov dpl,a
10056 \layout Standard
10057
10058
10059 \size footnotesize 
10060 ; _return($8) :
10061 \layout Standard
10062
10063
10064 \size footnotesize 
10065 00108$:
10066 \layout Standard
10067
10068
10069 \size footnotesize 
10070 \SpecialChar ~
10071 \SpecialChar ~
10072 ret
10073 \newline 
10074
10075 \layout Subsection
10076
10077 A few words about basic block successors, predecessors and dominators
10078 \layout Standard
10079
10080 Successors are basic blocks that might execute after this basic block.
10081 \newline 
10082 Predecessors are basic blocks that might execute before reaching this basic
10083  block.
10084 \newline 
10085 Dominators are basic blocks that WILL execute before reaching this basic
10086  block.
10087 \newline 
10088
10089 \layout Standard
10090
10091 [basic block 1]
10092 \layout Standard
10093
10094 if (something)
10095 \layout Standard
10096
10097 [basic block 2]
10098 \layout Standard
10099
10100 else
10101 \layout Standard
10102
10103 [basic block 3]
10104 \layout Standard
10105
10106 [basic block 4]
10107 \newline 
10108
10109 \layout Standard
10110
10111 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
10112 \layout Standard
10113
10114 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
10115 \layout Standard
10116
10117 c) domVect of [BB4] = BB1 ...
10118  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
10119  was executed.
10120 \layout Section
10121
10122 Acknowledgments
10123 \layout Standard
10124
10125
10126 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
10127
10128 \end_inset 
10129
10130
10131 \newline 
10132
10133 \newline 
10134
10135 \emph on 
10136 Thanks to all the other volunteer developers who have helped with coding,
10137  testing, web-page creation, distribution sets, etc.
10138  You know who you are :-)
10139 \emph default 
10140
10141 \newline 
10142
10143 \layout Standard
10144
10145 This document was initially written by Sandeep Dutta
10146 \layout Standard
10147
10148 All product names mentioned herein may be trademarks of their respective
10149  companies.
10150  
10151 \layout Standard
10152
10153
10154 \begin_inset LatexCommand \printindex{}
10155
10156 \end_inset 
10157
10158
10159 \the_end