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