several additions at various places
[fw/sdcc] / doc / sdccman.lyx
1 #LyX 1.3 created this file. For more info see http://www.lyx.org/
2 \lyxformat 221
3 \textclass article
4 \begin_preamble
5 \usepackage[
6   pdftitle={SDCC Compiler User Guide},
7   pdfauthor={SDCC development team},
8   pdfsubject={installation, user manual},
9   pdfkeywords={8032, 8051, ansi, c, compiler, CPU, DS390, 
10                embedded, GPL, manual, mcs51, PIC, small, Z80},
11   colorlinks=true,
12   linkcolor=blue] {hyperref}
13 \date{}
14 \end_preamble
15 \language english
16 \inputencoding default
17 \fontscheme pslatex
18 \graphics default
19 \paperfontsize default
20 \spacing single 
21 \papersize letterpaper
22 \paperpackage a4
23 \use_geometry 1
24 \use_amsmath 0
25 \use_natbib 0
26 \use_numerical_citations 0
27 \paperorientation portrait
28 \leftmargin 30mm
29 \topmargin 10mm
30 \rightmargin 25mm
31 \bottommargin 15mm
32 \secnumdepth 3
33 \tocdepth 3
34 \paragraph_separation indent
35 \defskip medskip
36 \quotes_language swedish
37 \quotes_times 2
38 \papercolumns 1
39 \papersides 1
40 \paperpagestyle fancy
41
42 \layout Comment
43
44 Please note: double dashed longoptions (e.g.
45  --version) are written this way: -
46 \begin_inset ERT
47 status Collapsed
48
49 \layout Standard
50
51 \backslash 
52 /
53 \end_inset 
54
55 -
56 \layout Comment
57
58 Two resp.
59  three consecutive dashes simply result in a long resp.
60  extra long dash.
61 \layout Comment
62
63 Architecture specific stuff (like memory models, code examples) should maybe
64  go
65 \layout Comment
66
67 into seperate sections/chapters/appendices (it is hard to document PIC or
68  Z80 in 
69 \layout Comment
70
71 a 8051 centered document)
72 \layout Title
73
74 SDCC Compiler User Guide
75 \layout Comment
76
77 The strings enclosed in $ are automatically updated by cvs:
78 \layout Standard
79 \align center 
80
81 \size footnotesize 
82 $Date$
83 \layout Standard
84 \align center 
85
86 \size footnotesize 
87 $Revision$
88 \layout Standard
89
90
91 \begin_inset LatexCommand \tableofcontents{}
92
93 \end_inset 
94
95
96 \layout Section
97 \pagebreak_top 
98 Introduction
99 \layout Subsection
100
101 About SDCC
102 \layout Standard
103
104
105 \series bold 
106 SDCC
107 \series default 
108  is a Freeware, retargettable, optimizing ANSI-C compiler by 
109 \series bold 
110 Sandeep Dutta
111 \series default 
112  designed for 8 bit Microprocessors.
113  The current version targets Intel MCS51 based Microprocessors (8031, 8032,
114  8051, 8052
115 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052 CPU}
116
117 \end_inset 
118
119 , etc), Zilog Z80 based MCUs, and the Dallas DS80C390 variant.
120  It can be retargetted for other microprocessors, support for Microchip
121  PIC, Atmel AVR is under development.
122  The entire source code for the compiler is distributed under GPL.
123  SDCC uses ASXXXX & ASLINK, a Freeware, retargettable assembler & linker.
124  SDCC has extensive language extensions suitable for utilizing various microcont
125 rollers and underlying hardware effectively.
126  
127 \newline 
128
129 \newline 
130 In addition to the MCU specific optimizations SDCC also does a host of standard
131  optimizations like:
132 \layout Itemize
133
134 global sub expression elimination, 
135 \layout Itemize
136
137 loop optimizations (loop invariant, strength reduction of induction variables
138  and loop reversing), 
139 \layout Itemize
140
141 constant folding & propagation, 
142 \layout Itemize
143
144 copy propagation, 
145 \layout Itemize
146
147 dead code elimination 
148 \layout Itemize
149
150 jump tables for 
151 \emph on 
152 switch
153 \emph default 
154  statements.
155 \layout Standard
156
157 For the back-end SDCC uses a global register allocation scheme which should
158  be well suited for other 8 bit MCUs.
159  
160 \newline 
161
162 \newline 
163 The peep hole optimizer uses a rule based substitution mechanism which is
164  MCU independent.
165  
166 \newline 
167
168 \newline 
169 Supported data-types are:
170 \layout Itemize
171
172 char (8 bits, 1 byte), 
173 \layout Itemize
174
175 short and int (16 bits, 2 bytes), 
176 \layout Itemize
177
178 long (32 bit, 4 bytes)
179 \layout Itemize
180
181 float (4 byte IEEE).
182  
183 \layout Standard
184
185 The compiler also allows 
186 \emph on 
187 inline assembler code
188 \emph default 
189  to be embedded anywhere in a function.
190  In addition, routines developed in assembly can also be called.
191 \newline 
192
193 \newline 
194 SDCC also provides an option (-
195 \begin_inset ERT
196 status Collapsed
197
198 \layout Standard
199
200 \backslash 
201 /
202 \end_inset 
203
204 -cyclomatic) to report the relative complexity of a function.
205  These functions can then be further optimized, or hand coded in assembly
206  if needed.
207  
208 \newline 
209
210 \newline 
211 SDCC also comes with a companion source level debugger SDCDB, the debugger
212  currently uses ucSim a freeware simulator for 8051 and other micro-controllers.
213  
214 \newline 
215
216 \newline 
217 The latest version can be downloaded from 
218 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
219
220 \end_inset 
221
222 .
223
224 \series bold 
225  
226 \series default 
227 \emph on 
228 Please note: the compiler will probably always be some steps ahead of this
229  documentation
230 \series bold 
231 \emph default 
232
233 \begin_inset LatexCommand \index{Status of documentation}
234
235 \end_inset 
236
237
238 \begin_inset Foot
239 collapsed false
240
241 \layout Standard
242
243 Obviously this has pros and cons
244 \end_inset 
245
246 .
247 \layout Subsection
248
249 Open Source
250 \layout Standard
251
252 All packages used in this compiler system are 
253 \emph on 
254 opensource
255 \emph default 
256  and 
257 \emph on 
258 freeware
259 \emph default 
260 ; source code for all the sub-packages (pre-processor, assemblers, linkers
261  etc) is distributed with the package.
262  This documentation is maintained using a freeware word processor (LyX).
263 \newline 
264 This program is free software; you can redistribute it and/or modify it
265  under the terms of the GNU General Public License
266 \begin_inset LatexCommand \index{GNU General Public License, GPL}
267
268 \end_inset 
269
270  as published by the Free Software Foundation; either version 2, or (at
271  your option) any later version.
272  This program is distributed in the hope that it will be useful, but WITHOUT
273  ANY WARRANTY; without even the implied warranty
274 \begin_inset LatexCommand \index{warranty}
275
276 \end_inset 
277
278  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
279  See the GNU General Public License for more details.
280  You should have received a copy of the GNU General Public License along
281  with this program; if not, write to the Free Software Foundation, 59 Temple
282  Place - Suite 330, Boston, MA 02111-1307, USA.
283  In other words, you are welcome to use, share and improve this program.
284  You are forbidden to forbid anyone else to use, share and improve what
285  you give them.
286  Help stamp out software-hoarding! 
287 \layout Subsection
288
289 Typographic conventions
290 \begin_inset LatexCommand \index{Typographic conventions}
291
292 \end_inset 
293
294
295 \layout Standard
296
297 Throughout this manual, we will use the following convention.
298  Commands you have to type in are printed in 
299 \family sans 
300 \series bold 
301 "sans serif"
302 \series default 
303 .
304
305 \family default 
306  Code samples are printed in 
307 \family typewriter 
308 typewriter font.
309
310 \family default 
311  Interesting items and new terms are printed in 
312 \emph on 
313 italic.
314 \layout Subsection
315
316 Compatibility with previous versions
317 \layout Standard
318
319 This version has numerous bug fixes compared with the previous version.
320  But we also introduced some incompatibilities with older versions.
321  Not just for the fun of it, but to make the compiler more stable, efficient
322  and ANSI compliant
323 \begin_inset LatexCommand \index{ANSI-compliance}
324
325 \end_inset 
326
327 .
328  
329 \newline 
330
331 \layout Itemize
332
333 short is now equivalent to int (16 bits), it used to be equivalent to char
334  (8 bits) which is not ANSI compliant
335 \layout Itemize
336
337 the default directory for gcc-builds where include, library and documentation
338  files are stored is now in /usr/local/share
339 \layout Itemize
340
341 char type parameters to vararg functions are casted to int unless explicitly
342  casted, e.g.: 
343 \newline 
344
345 \family typewriter 
346 \SpecialChar ~
347 \SpecialChar ~
348 char a=3;
349 \newline 
350 \SpecialChar ~
351 \SpecialChar ~
352 printf ("%d %c
353 \backslash 
354 n", a, (char)a);
355 \family default 
356
357 \newline 
358  will push a as an int and as a char resp.
359 \layout Itemize
360
361 option -
362 \begin_inset ERT
363 status Collapsed
364
365 \layout Standard
366
367 \backslash 
368 /
369 \end_inset 
370
371 -regextend has been removed
372 \layout Itemize
373
374 option -
375 \begin_inset ERT
376 status Collapsed
377
378 \layout Standard
379
380 \backslash 
381 /
382 \end_inset 
383
384 -noregparms has been removed
385 \layout Itemize
386
387 option -
388 \begin_inset ERT
389 status Collapsed
390
391 \layout Standard
392
393 \backslash 
394 /
395 \end_inset 
396
397 -stack-after-data has been removed
398 \layout Standard
399
400
401 \emph on 
402 <pending: more incompatibilities?>
403 \layout Subsection
404
405 System Requirements
406 \layout Standard
407
408 What do you need before you start installation of SDCC? A computer, and
409  a desire to compute.
410  The preferred method of installation is to compile SDCC from source using
411  GNU gcc and make.
412  For Windows some pre-compiled binary distributions are available for your
413  convenience.
414  You should have some experience with command line tools and compiler use.
415 \layout Subsection
416
417 Other Resources
418 \layout Standard
419
420 The SDCC home page at 
421 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
422
423 \end_inset 
424
425  is a great place to find distribution sets.
426  You can also find links to the user mailing lists that offer help or discuss
427  SDCC with other SDCC users.
428  Web links to other SDCC related sites can also be found here.
429  This document can be found in the DOC directory of the source package as
430  a text or HTML file.
431  Some of the other tools (simulator and assembler) included with SDCC contain
432  their own documentation and can be found in the source distribution.
433  If you want the latest unreleased software, the complete source package
434  is available directly by anonymous CVS on cvs.sdcc.sourceforge.net.
435 \layout Subsection
436
437 Wishes for the future
438 \layout Standard
439
440 There are (and always will be) some things that could be done.
441  Here are some I can think of:
442 \newline 
443
444 \layout Standard
445
446
447 \family typewriter 
448 char KernelFunction3(char p) at 0x340;
449 \newline 
450
451 \layout Standard
452
453
454 \family typewriter 
455 code banking
456 \begin_inset LatexCommand \index{code banking (not supported)}
457
458 \end_inset 
459
460  support for mcs51
461 \newline 
462
463 \newline 
464
465 \family default 
466 If you can think of some more, please see the chapter 9 about filing feature
467  requests
468 \begin_inset LatexCommand \index{Requesting features}
469
470 \end_inset 
471
472
473 \begin_inset LatexCommand \index{Feature request}
474
475 \end_inset 
476
477 .
478 \newline 
479
480 \layout Section
481 \pagebreak_top 
482 Installation
483 \begin_inset LatexCommand \index{Installation}
484
485 \end_inset 
486
487
488 \layout Standard
489
490 For most users it is sufficient to skip to either section 
491 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
492
493 \end_inset 
494
495  or section 
496 \begin_inset LatexCommand \ref{sub:Windows-Install}
497
498 \end_inset 
499
500 .
501  More detailled instructions follow below.
502 \layout Subsection
503
504 Configure Options
505 \begin_inset LatexCommand \index{Options SDCC configuration}
506
507 \end_inset 
508
509
510 \layout Standard
511
512 The install paths, search paths and other options are defined when running
513  'configure'.
514  The defaults can be overridden by:
515 \layout List
516 \labelwidthstring 00.00.0000
517
518 -
519 \begin_inset ERT
520 status Collapsed
521
522 \layout Standard
523
524 \backslash 
525 /
526 \end_inset 
527
528 -prefix see table below
529 \layout List
530 \labelwidthstring 00.00.0000
531
532 -
533 \begin_inset ERT
534 status Collapsed
535
536 \layout Standard
537
538 \backslash 
539 /
540 \end_inset 
541
542 -exec_prefix see table below
543 \layout List
544 \labelwidthstring 00.00.0000
545
546 -
547 \begin_inset ERT
548 status Collapsed
549
550 \layout Standard
551
552 \backslash 
553 /
554 \end_inset 
555
556 -bindir see table below
557 \layout List
558 \labelwidthstring 00.00.0000
559
560 -
561 \begin_inset ERT
562 status Collapsed
563
564 \layout Standard
565
566 \backslash 
567 /
568 \end_inset 
569
570 -datadir see table below
571 \layout List
572 \labelwidthstring 00.00.0000
573
574 docdir environment variable, see table below
575 \layout List
576 \labelwidthstring 00.00.0000
577
578 include_dir_suffix environment variable, see table below
579 \layout List
580 \labelwidthstring 00.00.0000
581
582 lib_dir_suffix environment variable, see table below
583 \layout List
584 \labelwidthstring 00.00.0000
585
586 sdccconf_h_dir_separator environment variable, either / or 
587 \backslash 
588
589 \backslash 
590  makes sense here.
591  This character will only be used in sdccconf.h; don't forget it's a C-header,
592  therefore a double-backslash is needed there.
593 \layout List
594 \labelwidthstring 00.00.0000
595
596 -
597 \begin_inset ERT
598 status Collapsed
599
600 \layout Standard
601
602 \backslash 
603 /
604 \end_inset 
605
606 -disable-mcs51-port Excludes the Intel mcs51 port
607 \layout List
608 \labelwidthstring 00.00.0000
609
610 -
611 \begin_inset ERT
612 status Collapsed
613
614 \layout Standard
615
616 \backslash 
617 /
618 \end_inset 
619
620 -disable-gbz80-port Excludes the Gameboy gbz80 port
621 \layout List
622 \labelwidthstring 00.00.0000
623
624 -
625 \begin_inset ERT
626 status Collapsed
627
628 \layout Standard
629
630 \backslash 
631 /
632 \end_inset 
633
634 -z80-port Excludes the z80 port
635 \layout List
636 \labelwidthstring 00.00.0000
637
638 -
639 \begin_inset ERT
640 status Collapsed
641
642 \layout Standard
643
644 \backslash 
645 /
646 \end_inset 
647
648 -disable-avr-port Excludes the AVR port
649 \layout List
650 \labelwidthstring 00.00.0000
651
652 -
653 \begin_inset ERT
654 status Collapsed
655
656 \layout Standard
657
658 \backslash 
659 /
660 \end_inset 
661
662 -disable-ds390-port Excludes the DS390 port
663 \layout List
664 \labelwidthstring 00.00.0000
665
666 -
667 \begin_inset ERT
668 status Collapsed
669
670 \layout Standard
671
672 \backslash 
673 /
674 \end_inset 
675
676 -disable-pic-port Excludes the PIC port
677 \layout List
678 \labelwidthstring 00.00.0000
679
680 -
681 \begin_inset ERT
682 status Collapsed
683
684 \layout Standard
685
686 \backslash 
687 /
688 \end_inset 
689
690 -disable-xa51-port Excludes the XA51 port
691 \layout List
692 \labelwidthstring 00.00.0000
693
694 -
695 \begin_inset ERT
696 status Collapsed
697
698 \layout Standard
699
700 \backslash 
701 /
702 \end_inset 
703
704 -disable-ucsim Disables configuring and building of ucsim
705 \layout List
706 \labelwidthstring 00.00.0000
707
708 -
709 \begin_inset ERT
710 status Collapsed
711
712 \layout Standard
713
714 \backslash 
715 /
716 \end_inset 
717
718 -disable-device-lib-build Disables automatically building device libraries
719 \layout List
720 \labelwidthstring 00.00.0000
721
722 -
723 \begin_inset ERT
724 status Collapsed
725
726 \layout Standard
727
728 \backslash 
729 /
730 \end_inset 
731
732 -disable-packihx Disables building packihx
733 \layout List
734 \labelwidthstring 00.00.0000
735
736 -
737 \begin_inset ERT
738 status Collapsed
739
740 \layout Standard
741
742 \backslash 
743 /
744 \end_inset 
745
746 -enable-libgc Use the Bohem memory allocator.
747  Lower runtime footprint.
748 \layout Standard
749
750 Furthermore the environment variables CC, CFLAGS, ...
751  the tools and their arguments can be influenced.
752  Please see `configure -
753 \begin_inset ERT
754 status Collapsed
755
756 \layout Standard
757
758 \backslash 
759 /
760 \end_inset 
761
762 -help` and the man/info pages of `configure` for details.
763 \newline 
764
765 \newline 
766 The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB,
767  STD_FP_LIB, STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_
768 NAME, SDCC_INCLUDE_NAME, SDCC_LIB_NAME are defined by `configure` too.
769  At the moment it's not possible to change the default settings (it was
770  simply never required.
771 \newline 
772
773 \newline 
774 These configure options are compiled into the binaries, and can only be
775  changed by rerunning 'configure' and recompiling SDCC.
776  The configure options are written in 
777 \emph on 
778 italics
779 \emph default 
780  to distinguish them from run time environment variables (see section search
781  paths).
782 \newline 
783
784 \newline 
785 The settings for 
786 \begin_inset Quotes sld
787 \end_inset 
788
789 Win32 builds
790 \begin_inset Quotes srd
791 \end_inset 
792
793  are used by the SDCC team to build the official Win32 binaries.
794  The SDCC team uses Mingw32 to build the official Windows binaries, because
795  it's
796 \layout Enumerate
797
798 open source, 
799 \layout Enumerate
800
801 a gcc compiler and last but not least
802 \layout Enumerate
803
804 the binaries can be built by cross compiling on Sourceforge's compile farm.
805 \layout Standard
806
807 See the examples, how to pass the Win32 settings to 'configure'.
808  The other Win32 builds using Borland, VC or whatever don't use 'configure',
809  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
810  for Win32.
811 \newline 
812
813 \newline 
814 These defaults are:
815 \newline 
816
817 \layout Standard
818 \align center 
819
820 \begin_inset  Tabular
821 <lyxtabular version="3" rows="8" columns="3">
822 <features>
823 <column alignment="block" valignment="top" leftline="true" width="0in">
824 <column alignment="block" valignment="top" leftline="true" width="0in">
825 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
826 <row topline="true" bottomline="true">
827 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
828 \begin_inset Text
829
830 \layout Standard
831
832 Variable
833 \end_inset 
834 </cell>
835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
836 \begin_inset Text
837
838 \layout Standard
839
840 default
841 \end_inset 
842 </cell>
843 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
844 \begin_inset Text
845
846 \layout Standard
847
848 Win32 builds
849 \end_inset 
850 </cell>
851 </row>
852 <row topline="true">
853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
854 \begin_inset Text
855
856 \layout Standard
857
858
859 \emph on 
860 PREFIX
861 \end_inset 
862 </cell>
863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
864 \begin_inset Text
865
866 \layout Standard
867
868 /usr/local
869 \end_inset 
870 </cell>
871 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
872 \begin_inset Text
873
874 \layout Standard
875
876
877 \backslash 
878 sdcc
879 \end_inset 
880 </cell>
881 </row>
882 <row topline="true">
883 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
884 \begin_inset Text
885
886 \layout Standard
887
888
889 \emph on 
890 EXEC_PREFIX
891 \end_inset 
892 </cell>
893 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
894 \begin_inset Text
895
896 \layout Standard
897
898
899 \emph on 
900 $PREFIX
901 \end_inset 
902 </cell>
903 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
904 \begin_inset Text
905
906 \layout Standard
907
908
909 \emph on 
910 $PREFIX
911 \end_inset 
912 </cell>
913 </row>
914 <row topline="true">
915 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
916 \begin_inset Text
917
918 \layout Standard
919
920
921 \emph on 
922 BINDIR
923 \end_inset 
924 </cell>
925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
926 \begin_inset Text
927
928 \layout Standard
929
930
931 \emph on 
932 $EXECPREFIX
933 \emph default 
934 /bin
935 \end_inset 
936 </cell>
937 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
938 \begin_inset Text
939
940 \layout Standard
941
942
943 \emph on 
944 $EXECPREFIX
945 \emph default 
946
947 \backslash 
948 bin
949 \end_inset 
950 </cell>
951 </row>
952 <row topline="true">
953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
954 \begin_inset Text
955
956 \layout Standard
957
958
959 \emph on 
960 DATADIR
961 \end_inset 
962 </cell>
963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
964 \begin_inset Text
965
966 \layout Standard
967
968
969 \emph on 
970 $PREFIX
971 \emph default 
972 /share
973 \end_inset 
974 </cell>
975 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
976 \begin_inset Text
977
978 \layout Standard
979
980
981 \emph on 
982 $PREFIX
983 \end_inset 
984 </cell>
985 </row>
986 <row topline="true">
987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
988 \begin_inset Text
989
990 \layout Standard
991
992
993 \emph on 
994 DOCDIR
995 \end_inset 
996 </cell>
997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
998 \begin_inset Text
999
1000 \layout Standard
1001
1002
1003 \emph on 
1004 $DATADIR
1005 \emph default 
1006 /sdcc/doc
1007 \end_inset 
1008 </cell>
1009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1010 \begin_inset Text
1011
1012 \layout Standard
1013
1014
1015 \emph on 
1016 $DATADIR
1017 \emph default 
1018
1019 \backslash 
1020 doc
1021 \end_inset 
1022 </cell>
1023 </row>
1024 <row topline="true">
1025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1026 \begin_inset Text
1027
1028 \layout Standard
1029
1030
1031 \emph on 
1032 INCLUDE_DIR_SUFFIX
1033 \end_inset 
1034 </cell>
1035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1036 \begin_inset Text
1037
1038 \layout Standard
1039
1040 sdcc/include
1041 \end_inset 
1042 </cell>
1043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1044 \begin_inset Text
1045
1046 \layout Standard
1047
1048 include
1049 \end_inset 
1050 </cell>
1051 </row>
1052 <row topline="true" bottomline="true">
1053 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1054 \begin_inset Text
1055
1056 \layout Standard
1057
1058
1059 \emph on 
1060 LIB_DIR_SUFFIX
1061 \end_inset 
1062 </cell>
1063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1064 \begin_inset Text
1065
1066 \layout Standard
1067
1068 sdcc/lib
1069 \end_inset 
1070 </cell>
1071 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1072 \begin_inset Text
1073
1074 \layout Standard
1075
1076 lib
1077 \end_inset 
1078 </cell>
1079 </row>
1080 </lyxtabular>
1081
1082 \end_inset 
1083
1084
1085 \newline 
1086
1087 \layout Standard
1088 \noindent 
1089 'configure' also computes relative paths.
1090  This is needed for full relocatability of a binary package and to complete
1091  search paths (see section search paths below):
1092 \newline 
1093  
1094 \layout Standard
1095 \align center 
1096
1097 \begin_inset  Tabular
1098 <lyxtabular version="3" rows="4" columns="3">
1099 <features>
1100 <column alignment="block" valignment="top" leftline="true" width="0in">
1101 <column alignment="block" valignment="top" leftline="true" width="0in">
1102 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1103 <row topline="true" bottomline="true">
1104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1105 \begin_inset Text
1106
1107 \layout Standard
1108
1109 Variable (computed)
1110 \end_inset 
1111 </cell>
1112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1113 \begin_inset Text
1114
1115 \layout Standard
1116
1117 default
1118 \end_inset 
1119 </cell>
1120 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1121 \begin_inset Text
1122
1123 \layout Standard
1124
1125 Win32 builds
1126 \end_inset 
1127 </cell>
1128 </row>
1129 <row topline="true" bottomline="true">
1130 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1131 \begin_inset Text
1132
1133 \layout Standard
1134
1135
1136 \emph on 
1137 BIN2DATA_DIR
1138 \end_inset 
1139 </cell>
1140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1141 \begin_inset Text
1142
1143 \layout Standard
1144
1145 ../share
1146 \end_inset 
1147 </cell>
1148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1149 \begin_inset Text
1150
1151 \layout Standard
1152
1153 ..
1154 \backslash 
1155
1156 \end_inset 
1157 </cell>
1158 </row>
1159 <row bottomline="true">
1160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1161 \begin_inset Text
1162
1163 \layout Standard
1164
1165
1166 \emph on 
1167 PREFIX2BIN_DIR
1168 \end_inset 
1169 </cell>
1170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1171 \begin_inset Text
1172
1173 \layout Standard
1174
1175 bin
1176 \end_inset 
1177 </cell>
1178 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1179 \begin_inset Text
1180
1181 \layout Standard
1182
1183 bin
1184 \end_inset 
1185 </cell>
1186 </row>
1187 <row bottomline="true">
1188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1189 \begin_inset Text
1190
1191 \layout Standard
1192
1193
1194 \emph on 
1195 PREFIX2DATA_DIR
1196 \end_inset 
1197 </cell>
1198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1199 \begin_inset Text
1200
1201 \layout Standard
1202
1203 share/sdcc
1204 \end_inset 
1205 </cell>
1206 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1207 \begin_inset Text
1208
1209 \layout Standard
1210
1211 \end_inset 
1212 </cell>
1213 </row>
1214 </lyxtabular>
1215
1216 \end_inset 
1217
1218
1219 \newline 
1220
1221 \layout Standard
1222 \noindent 
1223 Examples:
1224 \layout LyX-Code
1225
1226 ./configure
1227 \newline 
1228 ./configure -
1229 \begin_inset ERT
1230 status Collapsed
1231
1232 \layout Standard
1233
1234 \backslash 
1235 /
1236 \end_inset 
1237
1238 -prefix=
1239 \begin_inset Quotes srd
1240 \end_inset 
1241
1242 /usr/bin
1243 \begin_inset Quotes srd
1244 \end_inset 
1245
1246  -
1247 \begin_inset ERT
1248 status Collapsed
1249
1250 \layout Standard
1251
1252 \backslash 
1253 /
1254 \end_inset 
1255
1256 -datadir=
1257 \begin_inset Quotes srd
1258 \end_inset 
1259
1260 /usr/share
1261 \begin_inset Quotes srd
1262 \end_inset 
1263
1264
1265 \newline 
1266 ./configure -
1267 \begin_inset ERT
1268 status Collapsed
1269
1270 \layout Standard
1271
1272 \backslash 
1273 /
1274 \end_inset 
1275
1276 -disable-avr-port -
1277 \begin_inset ERT
1278 status Collapsed
1279
1280 \layout Standard
1281
1282 \backslash 
1283 /
1284 \end_inset 
1285
1286 -disable-xa51-port
1287 \layout Standard
1288
1289 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1290 32'):
1291 \layout LyX-Code
1292
1293 ./configure 
1294 \backslash 
1295
1296 \newline 
1297 CC=
1298 \begin_inset Quotes srd
1299 \end_inset 
1300
1301 i586-mingw32msvc-gcc
1302 \begin_inset Quotes srd
1303 \end_inset 
1304
1305  CXX=
1306 \begin_inset Quotes srd
1307 \end_inset 
1308
1309 i586-mingw32msvc-g++
1310 \begin_inset Quotes srd
1311 \end_inset 
1312
1313  
1314 \backslash 
1315  
1316 \newline 
1317 RANLIB=
1318 \begin_inset Quotes srd
1319 \end_inset 
1320
1321 i586-mingw32msvc-ranlib
1322 \begin_inset Quotes srd
1323 \end_inset 
1324
1325  
1326 \backslash 
1327
1328 \newline 
1329 STRIP=
1330 \begin_inset Quotes srd
1331 \end_inset 
1332
1333 i586-mingw32msvc-strip
1334 \begin_inset Quotes srd
1335 \end_inset 
1336
1337  
1338 \backslash 
1339
1340 \newline 
1341 -
1342 \begin_inset ERT
1343 status Collapsed
1344
1345 \layout Standard
1346
1347 \backslash 
1348 /
1349 \end_inset 
1350
1351 -prefix=
1352 \begin_inset Quotes srd
1353 \end_inset 
1354
1355 /sdcc
1356 \begin_inset Quotes srd
1357 \end_inset 
1358
1359  
1360 \backslash 
1361
1362 \newline 
1363 -
1364 \begin_inset ERT
1365 status Collapsed
1366
1367 \layout Standard
1368
1369 \backslash 
1370 /
1371 \end_inset 
1372
1373 -datadir=
1374 \begin_inset Quotes srd
1375 \end_inset 
1376
1377 /sdcc
1378 \begin_inset Quotes srd
1379 \end_inset 
1380
1381  
1382 \backslash 
1383
1384 \newline 
1385 docdir=
1386 \begin_inset Quotes srd
1387 \end_inset 
1388
1389 /sdcc/doc
1390 \begin_inset Quotes srd
1391 \end_inset 
1392
1393  
1394 \backslash 
1395
1396 \newline 
1397 include_dir_suffix=
1398 \begin_inset Quotes srd
1399 \end_inset 
1400
1401 include
1402 \begin_inset Quotes srd
1403 \end_inset 
1404
1405  
1406 \backslash 
1407
1408 \newline 
1409 lib_dir_suffix=
1410 \begin_inset Quotes srd
1411 \end_inset 
1412
1413 lib
1414 \begin_inset Quotes srd
1415 \end_inset 
1416
1417  
1418 \backslash 
1419
1420 \newline 
1421 sdccconf_h_dir_separator=
1422 \begin_inset Quotes srd
1423 \end_inset 
1424
1425
1426 \backslash 
1427
1428 \backslash 
1429
1430 \backslash 
1431
1432 \backslash 
1433
1434 \begin_inset Quotes srd
1435 \end_inset 
1436
1437  
1438 \backslash 
1439
1440 \newline 
1441 -
1442 \begin_inset ERT
1443 status Collapsed
1444
1445 \layout Standard
1446
1447 \backslash 
1448 /
1449 \end_inset 
1450
1451 -disable-device-lib-build
1452 \backslash 
1453
1454 \newline 
1455 -
1456 \begin_inset ERT
1457 status Collapsed
1458
1459 \layout Standard
1460
1461 \backslash 
1462 /
1463 \end_inset 
1464
1465 -disable-ucsim
1466 \backslash 
1467
1468 \newline 
1469 -
1470 \begin_inset ERT
1471 status Collapsed
1472
1473 \layout Standard
1474
1475 \backslash 
1476 /
1477 \end_inset 
1478
1479 -host=i586-mingw32msvc -
1480 \begin_inset ERT
1481 status Collapsed
1482
1483 \layout Standard
1484
1485 \backslash 
1486 /
1487 \end_inset 
1488
1489 -build=unknown-unknown-linux-gnu
1490 \layout Standard
1491
1492 To 
1493 \begin_inset Quotes sld
1494 \end_inset 
1495
1496 cross
1497 \begin_inset Quotes srd
1498 \end_inset 
1499
1500 compile on Cygwin for Mingw32(see also sdcc/support/scripts/sdcc_cygwin_mingw32)
1501 :
1502 \layout LyX-Code
1503
1504 ./configure -C 
1505 \backslash 
1506
1507 \newline 
1508 CFLAGS=
1509 \begin_inset Quotes srd
1510 \end_inset 
1511
1512 -mno-cygwin -O2
1513 \begin_inset Quotes srd
1514 \end_inset 
1515
1516  
1517 \backslash 
1518
1519 \newline 
1520 LDFLAGS=
1521 \begin_inset Quotes srd
1522 \end_inset 
1523
1524 -mno-cygwin
1525 \begin_inset Quotes srd
1526 \end_inset 
1527
1528  
1529 \backslash 
1530
1531 \newline 
1532 -
1533 \begin_inset ERT
1534 status Collapsed
1535
1536 \layout Standard
1537
1538 \backslash 
1539 /
1540 \end_inset 
1541
1542 -prefix=
1543 \begin_inset Quotes srd
1544 \end_inset 
1545
1546 /sdcc
1547 \begin_inset Quotes srd
1548 \end_inset 
1549
1550  
1551 \backslash 
1552
1553 \newline 
1554 -
1555 \begin_inset ERT
1556 status Collapsed
1557
1558 \layout Standard
1559
1560 \backslash 
1561 /
1562 \end_inset 
1563
1564 -datadir=
1565 \begin_inset Quotes srd
1566 \end_inset 
1567
1568 /sdcc
1569 \begin_inset Quotes srd
1570 \end_inset 
1571
1572  
1573 \backslash 
1574
1575 \newline 
1576 docdir=
1577 \begin_inset Quotes srd
1578 \end_inset 
1579
1580 /sdcc/doc
1581 \begin_inset Quotes srd
1582 \end_inset 
1583
1584  
1585 \backslash 
1586  
1587 \newline 
1588 include_dir_suffix=
1589 \begin_inset Quotes srd
1590 \end_inset 
1591
1592 include
1593 \begin_inset Quotes srd
1594 \end_inset 
1595
1596  
1597 \backslash 
1598
1599 \newline 
1600 lib_dir_suffix=
1601 \begin_inset Quotes srd
1602 \end_inset 
1603
1604 lib
1605 \begin_inset Quotes srd
1606 \end_inset 
1607
1608  
1609 \backslash 
1610
1611 \newline 
1612 sdccconf_h_dir_separator=
1613 \begin_inset Quotes srd
1614 \end_inset 
1615
1616
1617 \backslash 
1618
1619 \backslash 
1620
1621 \backslash 
1622
1623 \backslash 
1624
1625 \begin_inset Quotes srd
1626 \end_inset 
1627
1628  
1629 \backslash 
1630
1631 \newline 
1632 -
1633 \begin_inset ERT
1634 status Collapsed
1635
1636 \layout Standard
1637
1638 \backslash 
1639 /
1640 \end_inset 
1641
1642 -disable-ucsim
1643 \layout Standard
1644
1645 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
1646  The option '-
1647 \begin_inset ERT
1648 status Collapsed
1649
1650 \layout Standard
1651
1652 \backslash 
1653 /
1654 \end_inset 
1655
1656 -C' turns on caching, which gives a little bit extra speed.
1657  However if options are changed, it can be necessary to delete the config.cache
1658  file.
1659 \layout Subsection
1660
1661 Install paths
1662 \begin_inset LatexCommand \index{Install paths}
1663
1664 \end_inset 
1665
1666
1667 \layout Standard
1668 \added_space_top medskip \align center 
1669
1670 \begin_inset  Tabular
1671 <lyxtabular version="3" rows="5" columns="4">
1672 <features>
1673 <column alignment="center" valignment="top" leftline="true" width="0">
1674 <column alignment="center" valignment="top" leftline="true" width="0">
1675 <column alignment="center" valignment="top" leftline="true" width="0">
1676 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
1677 <row topline="true" bottomline="true">
1678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1679 \begin_inset Text
1680
1681 \layout Standard
1682
1683
1684 \series bold 
1685 Description
1686 \end_inset 
1687 </cell>
1688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1689 \begin_inset Text
1690
1691 \layout Standard
1692
1693
1694 \series bold 
1695 Path
1696 \end_inset 
1697 </cell>
1698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1699 \begin_inset Text
1700
1701 \layout Standard
1702
1703
1704 \series bold 
1705 Default
1706 \end_inset 
1707 </cell>
1708 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1709 \begin_inset Text
1710
1711 \layout Standard
1712
1713
1714 \series bold 
1715 Win32 builds
1716 \end_inset 
1717 </cell>
1718 </row>
1719 <row topline="true">
1720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1721 \begin_inset Text
1722
1723 \layout Standard
1724
1725 Binary files*
1726 \end_inset 
1727 </cell>
1728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1729 \begin_inset Text
1730
1731 \layout Standard
1732
1733
1734 \emph on 
1735 $EXEC_PREFIX
1736 \end_inset 
1737 </cell>
1738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1739 \begin_inset Text
1740
1741 \layout Standard
1742
1743 /usr/local/bin
1744 \end_inset 
1745 </cell>
1746 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1747 \begin_inset Text
1748
1749 \layout Standard
1750
1751
1752 \backslash 
1753 sdcc
1754 \backslash 
1755 bin
1756 \end_inset 
1757 </cell>
1758 </row>
1759 <row topline="true">
1760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1761 \begin_inset Text
1762
1763 \layout Standard
1764
1765 Include files
1766 \end_inset 
1767 </cell>
1768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1769 \begin_inset Text
1770
1771 \layout Standard
1772
1773
1774 \emph on 
1775 $DATADIR/ $INCLUDE_DIR_SUFFIX
1776 \end_inset 
1777 </cell>
1778 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1779 \begin_inset Text
1780
1781 \layout Standard
1782
1783 /usr/local/share/sdcc/include
1784 \end_inset 
1785 </cell>
1786 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1787 \begin_inset Text
1788
1789 \layout Standard
1790
1791
1792 \backslash 
1793 sdcc
1794 \backslash 
1795 include
1796 \end_inset 
1797 </cell>
1798 </row>
1799 <row topline="true">
1800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1801 \begin_inset Text
1802
1803 \layout Standard
1804
1805 Library file**
1806 \end_inset 
1807 </cell>
1808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1809 \begin_inset Text
1810
1811 \layout Standard
1812
1813
1814 \emph on 
1815 $DATADIR/$LIB_DIR_SUFFIX
1816 \end_inset 
1817 </cell>
1818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1819 \begin_inset Text
1820
1821 \layout Standard
1822
1823 /usr/local/share/sdcc/lib
1824 \end_inset 
1825 </cell>
1826 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1827 \begin_inset Text
1828
1829 \layout Standard
1830
1831
1832 \backslash 
1833 sdcc
1834 \backslash 
1835 lib
1836 \end_inset 
1837 </cell>
1838 </row>
1839 <row topline="true" bottomline="true">
1840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1841 \begin_inset Text
1842
1843 \layout Standard
1844
1845 Documentation
1846 \end_inset 
1847 </cell>
1848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1849 \begin_inset Text
1850
1851 \layout Standard
1852
1853
1854 \emph on 
1855 $DOCDIR
1856 \end_inset 
1857 </cell>
1858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1859 \begin_inset Text
1860
1861 \layout Standard
1862
1863 /usr/local/share/sdcc/doc
1864 \end_inset 
1865 </cell>
1866 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1867 \begin_inset Text
1868
1869 \layout Standard
1870
1871
1872 \backslash 
1873 sdcc
1874 \backslash 
1875 doc
1876 \end_inset 
1877 </cell>
1878 </row>
1879 </lyxtabular>
1880
1881 \end_inset 
1882
1883
1884 \layout Verse
1885
1886
1887 \size footnotesize 
1888 *compiler, preprocessor, assembler, and linker
1889 \newline 
1890 **the 
1891 \shape italic 
1892 model
1893 \shape default 
1894  is auto-appended by the compiler, e.g.
1895  small, large, z80, ds390 etc
1896 \layout Standard
1897 \noindent 
1898 The install paths can still be changed during `make install` with e.g.:
1899 \layout LyX-Code
1900
1901 make install prefix=$(HOME)/local/sdcc
1902 \layout Standard
1903
1904 Of course this doesn't change the search paths compiled into the binaries.
1905 \layout Subsection
1906
1907 Search Paths
1908 \begin_inset LatexCommand \index{Search path}
1909
1910 \end_inset 
1911
1912
1913 \layout Standard
1914
1915 Some search paths or parts of them are determined by configure variables
1916  (in 
1917 \emph on 
1918 italics
1919 \emph default 
1920 , see section above).
1921  Further search paths are determined by environment variables during runtime.
1922  
1923 \newline 
1924 The paths searched when running the compiler are as follows (the first catch
1925  wins):
1926 \newline 
1927
1928 \newline 
1929 1.
1930  Binary files (preprocessor, assembler and linker)
1931 \newline 
1932
1933 \layout Standard
1934 \align center 
1935
1936 \begin_inset  Tabular
1937 <lyxtabular version="3" rows="4" columns="3">
1938 <features>
1939 <column alignment="block" valignment="top" leftline="true" width="0in">
1940 <column alignment="block" valignment="top" leftline="true" width="0in">
1941 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1942 <row topline="true" bottomline="true">
1943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1944 \begin_inset Text
1945
1946 \layout Standard
1947
1948 Search path
1949 \end_inset 
1950 </cell>
1951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1952 \begin_inset Text
1953
1954 \layout Standard
1955
1956 default
1957 \end_inset 
1958 </cell>
1959 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1960 \begin_inset Text
1961
1962 \layout Standard
1963
1964 Win32 builds
1965 \end_inset 
1966 </cell>
1967 </row>
1968 <row topline="true">
1969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1970 \begin_inset Text
1971
1972 \layout Standard
1973
1974 $SDCC_HOME/
1975 \emph on 
1976 $PPREFIX2BIN_DIR
1977 \end_inset 
1978 </cell>
1979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1980 \begin_inset Text
1981
1982 \layout Standard
1983
1984 $SDCC_HOME/bin
1985 \end_inset 
1986 </cell>
1987 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1988 \begin_inset Text
1989
1990 \layout Standard
1991
1992 $SDCC_HOME
1993 \backslash 
1994 bin
1995 \end_inset 
1996 </cell>
1997 </row>
1998 <row topline="true">
1999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2000 \begin_inset Text
2001
2002 \layout Standard
2003
2004 Path of argv[0] (if available)
2005 \end_inset 
2006 </cell>
2007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2008 \begin_inset Text
2009
2010 \layout Standard
2011
2012 Path of argv[0]
2013 \end_inset 
2014 </cell>
2015 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2016 \begin_inset Text
2017
2018 \layout Standard
2019
2020 Path of argv[0]
2021 \end_inset 
2022 </cell>
2023 </row>
2024 <row topline="true" bottomline="true">
2025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2026 \begin_inset Text
2027
2028 \layout Standard
2029
2030 $PATH
2031 \end_inset 
2032 </cell>
2033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2034 \begin_inset Text
2035
2036 \layout Standard
2037
2038 $PATH
2039 \end_inset 
2040 </cell>
2041 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2042 \begin_inset Text
2043
2044 \layout Standard
2045
2046 $PATH
2047 \end_inset 
2048 </cell>
2049 </row>
2050 </lyxtabular>
2051
2052 \end_inset 
2053
2054  
2055 \newline 
2056
2057 \layout Standard
2058 \noindent 
2059 2.
2060  Include files
2061 \newline 
2062
2063 \layout Standard
2064 \align center 
2065
2066 \begin_inset  Tabular
2067 <lyxtabular version="3" rows="6" columns="3">
2068 <features>
2069 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2070 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2071 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2072 <row topline="true" bottomline="true">
2073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2074 \begin_inset Text
2075
2076 \layout Standard
2077
2078 Search path
2079 \end_inset 
2080 </cell>
2081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2082 \begin_inset Text
2083
2084 \layout Standard
2085
2086 default
2087 \end_inset 
2088 </cell>
2089 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2090 \begin_inset Text
2091
2092 \layout Standard
2093
2094 Win32 builds
2095 \end_inset 
2096 </cell>
2097 </row>
2098 <row topline="true">
2099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2100 \begin_inset Text
2101
2102 \layout Standard
2103
2104 -
2105 \begin_inset ERT
2106 status Collapsed
2107
2108 \layout Standard
2109
2110 \backslash 
2111 /
2112 \end_inset 
2113
2114 -I dir
2115 \end_inset 
2116 </cell>
2117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2118 \begin_inset Text
2119
2120 \layout Standard
2121
2122 -
2123 \begin_inset ERT
2124 status Collapsed
2125
2126 \layout Standard
2127
2128 \backslash 
2129 /
2130 \end_inset 
2131
2132 -I dir
2133 \end_inset 
2134 </cell>
2135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2136 \begin_inset Text
2137
2138 \layout Standard
2139
2140 -
2141 \begin_inset ERT
2142 status Collapsed
2143
2144 \layout Standard
2145
2146 \backslash 
2147 /
2148 \end_inset 
2149
2150 -I dir
2151 \end_inset 
2152 </cell>
2153 </row>
2154 <row topline="true">
2155 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2156 \begin_inset Text
2157
2158 \layout Standard
2159
2160 $SDCC_INCLUDE
2161 \end_inset 
2162 </cell>
2163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2164 \begin_inset Text
2165
2166 \layout Standard
2167
2168 $SDCC_INCLUDE
2169 \end_inset 
2170 </cell>
2171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2172 \begin_inset Text
2173
2174 \layout Standard
2175
2176 $SDCC_INCLUDE
2177 \end_inset 
2178 </cell>
2179 </row>
2180 <row topline="true">
2181 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2182 \begin_inset Text
2183
2184 \layout Standard
2185
2186 $SDCC_HOME/
2187 \newline 
2188
2189 \emph on 
2190 $PREFIX2DATA_DIR/
2191 \newline 
2192 $INCLUDE_DIR_SUFFIX
2193 \end_inset 
2194 </cell>
2195 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2196 \begin_inset Text
2197
2198 \layout Standard
2199
2200 $SDCC_ HOME/
2201 \newline 
2202 share/sdcc/
2203 \newline 
2204 include
2205 \end_inset 
2206 </cell>
2207 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2208 \begin_inset Text
2209
2210 \layout Standard
2211
2212 $SDCC_HOME
2213 \backslash 
2214 include
2215 \end_inset 
2216 </cell>
2217 </row>
2218 <row topline="true">
2219 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2220 \begin_inset Text
2221
2222 \layout Standard
2223
2224 path(argv[0])/
2225 \newline 
2226
2227 \emph on 
2228 $BIN2DATADIR/
2229 \emph default 
2230
2231 \newline 
2232
2233 \emph on 
2234 $INCLUDE_DIR_SUFFIX
2235 \end_inset 
2236 </cell>
2237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2238 \begin_inset Text
2239
2240 \layout Standard
2241
2242 path(argv[0])/
2243 \newline 
2244 ../sdcc/include
2245 \newline 
2246 \SpecialChar ~
2247 \SpecialChar ~
2248 \SpecialChar ~
2249 \SpecialChar ~
2250 \SpecialChar ~
2251 \SpecialChar ~
2252 \SpecialChar ~
2253 \SpecialChar ~
2254 \SpecialChar ~
2255 \SpecialChar ~
2256 \SpecialChar ~
2257 \SpecialChar ~
2258 \SpecialChar ~
2259 \SpecialChar ~
2260 \SpecialChar ~
2261 \SpecialChar ~
2262 \SpecialChar ~
2263 \SpecialChar ~
2264 \SpecialChar ~
2265 \SpecialChar ~
2266 \SpecialChar ~
2267 \SpecialChar ~
2268 \SpecialChar ~
2269 \SpecialChar ~
2270 \SpecialChar ~
2271 \SpecialChar ~
2272 \SpecialChar ~
2273 \SpecialChar ~
2274 \SpecialChar ~
2275 \SpecialChar ~
2276 \SpecialChar ~
2277 \SpecialChar ~
2278 \SpecialChar ~
2279 \SpecialChar ~
2280 \SpecialChar ~
2281 \SpecialChar ~
2282 \SpecialChar ~
2283 \SpecialChar ~
2284
2285 \end_inset 
2286 </cell>
2287 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2288 \begin_inset Text
2289
2290 \layout Standard
2291
2292 path(argv[0])
2293 \backslash 
2294 ..
2295 \backslash 
2296 include
2297 \end_inset 
2298 </cell>
2299 </row>
2300 <row topline="true" bottomline="true">
2301 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2302 \begin_inset Text
2303
2304 \layout Standard
2305
2306
2307 \emph on 
2308 $DATADIR/
2309 \emph default 
2310
2311 \newline 
2312
2313 \emph on 
2314 $INCLUDE_DIR_SUFFIX
2315 \end_inset 
2316 </cell>
2317 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2318 \begin_inset Text
2319
2320 \layout Standard
2321
2322 /usr/local/share/sdcc/
2323 \newline 
2324 include
2325 \end_inset 
2326 </cell>
2327 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2328 \begin_inset Text
2329
2330 \layout Standard
2331
2332 (not on Win32)
2333 \end_inset 
2334 </cell>
2335 </row>
2336 </lyxtabular>
2337
2338 \end_inset 
2339
2340  
2341 \newline 
2342
2343 \layout Standard
2344 \noindent 
2345 The option -
2346 \begin_inset ERT
2347 status Collapsed
2348
2349 \layout Standard
2350
2351 \backslash 
2352 /
2353 \end_inset 
2354
2355 -nostdinc disables the last two search paths.
2356 \newline 
2357
2358 \newline 
2359 3.
2360  Library files 
2361 \newline 
2362
2363 \layout Standard
2364
2365 With the exception of 
2366 \begin_inset Quotes sld
2367 \end_inset 
2368
2369 -
2370 \begin_inset ERT
2371 status Collapsed
2372
2373 \layout Standard
2374
2375 \backslash 
2376 /
2377 \end_inset 
2378
2379 -L dir
2380 \begin_inset Quotes srd
2381 \end_inset 
2382
2383  the 
2384 \shape italic 
2385 model
2386 \shape default 
2387  is auto-appended by the compiler (e.g.
2388  small, large, z80, ds390 etc.).
2389  
2390 \newline 
2391
2392 \layout Standard
2393 \align center 
2394
2395 \begin_inset  Tabular
2396 <lyxtabular version="3" rows="6" columns="3">
2397 <features>
2398 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2399 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2400 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2401 <row topline="true" bottomline="true">
2402 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2403 \begin_inset Text
2404
2405 \layout Standard
2406
2407 Search path
2408 \end_inset 
2409 </cell>
2410 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2411 \begin_inset Text
2412
2413 \layout Standard
2414
2415 default
2416 \end_inset 
2417 </cell>
2418 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2419 \begin_inset Text
2420
2421 \layout Standard
2422
2423 Win32 builds
2424 \end_inset 
2425 </cell>
2426 </row>
2427 <row topline="true">
2428 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2429 \begin_inset Text
2430
2431 \layout Standard
2432
2433 -
2434 \begin_inset ERT
2435 status Collapsed
2436
2437 \layout Standard
2438
2439 \backslash 
2440 /
2441 \end_inset 
2442
2443 -L dir
2444 \end_inset 
2445 </cell>
2446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2447 \begin_inset Text
2448
2449 \layout Standard
2450
2451 -
2452 \begin_inset ERT
2453 status Collapsed
2454
2455 \layout Standard
2456
2457 \backslash 
2458 /
2459 \end_inset 
2460
2461 -L dir
2462 \end_inset 
2463 </cell>
2464 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2465 \begin_inset Text
2466
2467 \layout Standard
2468
2469 -
2470 \begin_inset ERT
2471 status Collapsed
2472
2473 \layout Standard
2474
2475 \backslash 
2476 /
2477 \end_inset 
2478
2479 -L dir
2480 \end_inset 
2481 </cell>
2482 </row>
2483 <row topline="true">
2484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2485 \begin_inset Text
2486
2487 \layout Standard
2488
2489 $SDCC_LIB/
2490 \newline 
2491
2492 \emph on 
2493 <model>
2494 \end_inset 
2495 </cell>
2496 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2497 \begin_inset Text
2498
2499 \layout Standard
2500
2501 $SDCC_LIB/
2502 \newline 
2503
2504 \emph on 
2505 <model>
2506 \end_inset 
2507 </cell>
2508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2509 \begin_inset Text
2510
2511 \layout Standard
2512
2513 $SDCC_LIB
2514 \backslash 
2515
2516 \newline 
2517
2518 \emph on 
2519 <model>
2520 \end_inset 
2521 </cell>
2522 </row>
2523 <row topline="true">
2524 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2525 \begin_inset Text
2526
2527 \layout Standard
2528
2529 $SDCC_HOME/
2530 \newline 
2531
2532 \emph on 
2533 $PREFIX2DATA_DIR/
2534 \newline 
2535 $LIB_DIR_SUFFIX/<model>
2536 \end_inset 
2537 </cell>
2538 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2539 \begin_inset Text
2540
2541 \layout Standard
2542
2543 $SDCC_HOME/
2544 \newline 
2545 share/sdcc/
2546 \newline 
2547 lib/
2548 \emph on 
2549 <model>
2550 \end_inset 
2551 </cell>
2552 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2553 \begin_inset Text
2554
2555 \layout Standard
2556
2557 $SDCC_HOME
2558 \backslash 
2559 lib
2560 \backslash 
2561
2562 \emph on 
2563
2564 \newline 
2565 <model>
2566 \end_inset 
2567 </cell>
2568 </row>
2569 <row topline="true">
2570 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2571 \begin_inset Text
2572
2573 \layout Standard
2574
2575 path(argv[0])/
2576 \newline 
2577
2578 \emph on 
2579 $BIN2DATADIR/
2580 \emph default 
2581
2582 \newline 
2583
2584 \emph on 
2585 $LIB_DIR_SUFFIX/<model>
2586 \end_inset 
2587 </cell>
2588 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2589 \begin_inset Text
2590
2591 \layout Standard
2592
2593 path(argv[0])/
2594 \newline 
2595 ../sdcc/lib/
2596 \emph on 
2597 <model>
2598 \newline 
2599 \SpecialChar ~
2600 \SpecialChar ~
2601 \SpecialChar ~
2602 \SpecialChar ~
2603 \SpecialChar ~
2604 \SpecialChar ~
2605 \SpecialChar ~
2606 \SpecialChar ~
2607 \SpecialChar ~
2608 \SpecialChar ~
2609 \SpecialChar ~
2610 \SpecialChar ~
2611 \SpecialChar ~
2612 \SpecialChar ~
2613 \SpecialChar ~
2614 \SpecialChar ~
2615 \SpecialChar ~
2616 \SpecialChar ~
2617 \SpecialChar ~
2618 \SpecialChar ~
2619 \SpecialChar ~
2620 \SpecialChar ~
2621 \SpecialChar ~
2622 \SpecialChar ~
2623 \SpecialChar ~
2624 \SpecialChar ~
2625 \SpecialChar ~
2626 \SpecialChar ~
2627 \SpecialChar ~
2628 \SpecialChar ~
2629 \SpecialChar ~
2630 \SpecialChar ~
2631 \SpecialChar ~
2632 \SpecialChar ~
2633 \SpecialChar ~
2634 \SpecialChar ~
2635 \SpecialChar ~
2636 \SpecialChar ~
2637 \SpecialChar ~
2638
2639 \end_inset 
2640 </cell>
2641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2642 \begin_inset Text
2643
2644 \layout Standard
2645
2646 path(argv[0])
2647 \backslash 
2648
2649 \newline 
2650 ..
2651 \backslash 
2652 lib
2653 \backslash 
2654
2655 \emph on 
2656 <model>
2657 \newline 
2658 \SpecialChar ~
2659 \SpecialChar ~
2660 \SpecialChar ~
2661 \SpecialChar ~
2662 \SpecialChar ~
2663 \SpecialChar ~
2664 \SpecialChar ~
2665 \SpecialChar ~
2666 \SpecialChar ~
2667 \SpecialChar ~
2668 \SpecialChar ~
2669 \SpecialChar ~
2670 \SpecialChar ~
2671 \SpecialChar ~
2672 \SpecialChar ~
2673 \SpecialChar ~
2674 \SpecialChar ~
2675 \SpecialChar ~
2676 \SpecialChar ~
2677 \SpecialChar ~
2678 \SpecialChar ~
2679 \SpecialChar ~
2680 \SpecialChar ~
2681 \SpecialChar ~
2682 \SpecialChar ~
2683 \SpecialChar ~
2684 \SpecialChar ~
2685 \SpecialChar ~
2686 \SpecialChar ~
2687 \SpecialChar ~
2688 \SpecialChar ~
2689 \SpecialChar ~
2690 \SpecialChar ~
2691 \SpecialChar ~
2692 \SpecialChar ~
2693
2694 \end_inset 
2695 </cell>
2696 </row>
2697 <row topline="true" bottomline="true">
2698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2699 \begin_inset Text
2700
2701 \layout Standard
2702
2703
2704 \emph on 
2705 $DATADIR/
2706 \newline 
2707 $LIB_DIR_SUFFIX/<model>
2708 \end_inset 
2709 </cell>
2710 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2711 \begin_inset Text
2712
2713 \layout Standard
2714
2715 /usr/local/share/sdcc/
2716 \newline 
2717 lib/
2718 \emph on 
2719 <model>
2720 \end_inset 
2721 </cell>
2722 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2723 \begin_inset Text
2724
2725 \layout Standard
2726
2727 (not on Win32)
2728 \end_inset 
2729 </cell>
2730 </row>
2731 </lyxtabular>
2732
2733 \end_inset 
2734
2735
2736 \newline 
2737
2738 \layout Comment
2739
2740 Don't delete any of the stray spaces in the table above without checking
2741  the HTML output (last line)!
2742 \layout Standard
2743
2744 \SpecialChar ~
2745
2746 \newline 
2747 The option -
2748 \begin_inset ERT
2749 status Collapsed
2750
2751 \layout Standard
2752
2753 \backslash 
2754 /
2755 \end_inset 
2756
2757 -nostdlib disables the last two search paths.
2758 \layout Subsection
2759
2760 Building SDCC
2761 \begin_inset LatexCommand \index{Building SDCC}
2762
2763 \end_inset 
2764
2765
2766 \layout Subsubsection
2767
2768 Building SDCC on Linux
2769 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
2770
2771 \end_inset 
2772
2773
2774 \layout Enumerate
2775
2776
2777 \series medium 
2778 Download the source package
2779 \series default 
2780  either from the SDCC CVS repository or from the 
2781 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
2782
2783 \end_inset 
2784
2785
2786 \series medium 
2787 , it will be named something like sdcc
2788 \series default 
2789 .src
2790 \series medium 
2791 .t
2792 \series default 
2793 ar.
2794 \series medium 
2795 gz.
2796 \layout Enumerate
2797
2798
2799 \series medium 
2800 Bring up a command line terminal, such as xterm.
2801 \layout Enumerate
2802
2803
2804 \series medium 
2805 Unpack the file using a command like: 
2806 \family sans 
2807 \series bold 
2808 "tar -xzf sdcc.src.tar.gz
2809 \family default 
2810 \series default 
2811 "
2812 \series medium 
2813 , this will create a sub-directory called sdcc with all of the sources.
2814 \layout Enumerate
2815
2816 Change directory into the main SDCC directory, for example type: 
2817 \family sans 
2818 \series bold 
2819 "cd sdcc
2820 \series default 
2821 ".
2822 \layout Enumerate
2823
2824
2825 \series medium 
2826 Type 
2827 \family sans 
2828 \series bold 
2829 "./configure
2830 \family default 
2831 \series default 
2832 ".
2833  This configures the package for compilation on your system.
2834 \layout Enumerate
2835
2836
2837 \series medium 
2838 Type 
2839 \family sans 
2840 \series bold 
2841 "make
2842 \family default 
2843 \series default 
2844 "
2845 \series medium 
2846 .
2847
2848 \series default 
2849  All of the source packages will compile, this can take a while.
2850 \layout Enumerate
2851
2852
2853 \series medium 
2854 Type 
2855 \family sans 
2856 \series bold 
2857 "make install"
2858 \family default 
2859 \series default 
2860  as root
2861 \series medium 
2862 .
2863
2864 \series default 
2865  This copies the binary executables, the include files, the libraries and
2866  the documentation to the install directories.
2867 \layout Subsubsection
2868
2869 Building SDCC on OSX 2.x
2870 \layout Standard
2871
2872 Follow the instruction for Linux.
2873 \newline 
2874
2875 \newline 
2876 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
2877 )) fails to compile SDCC.
2878  Fortunately there's also gcc 2.9.x installed, which works fine.
2879  This compiler can be selected by running 'configure' with:
2880 \layout LyX-Code
2881
2882 ./configure CC=gcc2 CXX=g++2
2883 \layout Subsubsection
2884
2885 Cross compiling SDCC on Linux for Windows
2886 \layout Standard
2887
2888 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
2889  See section 'Configure Options'.
2890 \layout Subsubsection
2891
2892 Building SDCC on Windows 
2893 \layout Standard
2894
2895 With the exception of Cygwin the SDCC binaries uCsim and sdcdb can't be
2896  built on Windows.
2897  They use Unix-sockets, which are not available on Win32.
2898 \layout Subsubsection
2899
2900 Building SDCC using Cygwin and Mingw32
2901 \layout Standard
2902
2903 For building and installing a Cygwin executable follow the instructions
2904  for Linux.
2905 \newline 
2906
2907 \newline 
2908 On Cygwin a 
2909 \begin_inset Quotes sld
2910 \end_inset 
2911
2912 native
2913 \begin_inset Quotes srd
2914 \end_inset 
2915
2916  Win32-binary can be built, which will not need the Cygwin-DLL.
2917  For the necessary 'configure' options see section 'configure options' or
2918  the script 'sdcc/support/scripts/sdcc_cygwinmingw32'.
2919 \newline 
2920
2921 \newline 
2922 In order to install Cygwin on Windows download setup.exe from 
2923 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
2924
2925 \end_inset 
2926
2927 .
2928  Run it, set the 
2929 \begin_inset Quotes sld
2930 \end_inset 
2931
2932 default text file type
2933 \begin_inset Quotes srd
2934 \end_inset 
2935
2936  to 
2937 \begin_inset Quotes sld
2938 \end_inset 
2939
2940 unix
2941 \begin_inset Quotes srd
2942 \end_inset 
2943
2944  and download/install at least the following packages.
2945  Some packages are selected by default, others will be automatically selected
2946  because of dependencies with the manually selected packages.
2947  Never deselect these packages!
2948 \layout Itemize
2949
2950 flex
2951 \layout Itemize
2952
2953 bison
2954 \layout Itemize
2955
2956 gcc ; version 3.x is fine, no need to use the old 2.9x
2957 \layout Itemize
2958
2959 binutils ; selected with gcc
2960 \layout Itemize
2961
2962 make
2963 \layout Itemize
2964
2965 rxvt ; a nice console, which makes life much easier under windoze (see below)
2966 \layout Itemize
2967
2968 man ; not really needed for building SDCC, but you'll miss it sooner or
2969  later
2970 \layout Itemize
2971
2972 less ; not really needed for building SDCC, but you'll miss it sooner or
2973  later
2974 \layout Itemize
2975
2976 cvs ; only if you use CVS access
2977 \layout Standard
2978
2979 If you want to develop something you'll need:
2980 \layout Itemize
2981
2982 python ; for the regression tests
2983 \layout Itemize
2984
2985 gdb ; the gnu debugger, together with the nice GUI 
2986 \begin_inset Quotes sld
2987 \end_inset 
2988
2989 insight
2990 \begin_inset Quotes srd
2991 \end_inset 
2992
2993
2994 \layout Itemize
2995
2996 openssh ; to access the CF or commit changes
2997 \layout Itemize
2998
2999 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3000  use autoconf-stable!
3001 \layout Standard
3002
3003 rxvt is a nice console with history.
3004  Replace in your cygwin.bat the line
3005 \layout LyX-Code
3006
3007 bash -
3008 \begin_inset ERT
3009 status Collapsed
3010
3011 \layout Standard
3012
3013 \backslash 
3014 /
3015 \end_inset 
3016
3017 -login -i 
3018 \layout Standard
3019
3020 with (one line):
3021 \layout LyX-Code
3022
3023 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3024 \layout LyX-Code
3025
3026      -bg black -fg white -geometry 100x65 -e bash -
3027 \begin_inset ERT
3028 status Collapsed
3029
3030 \layout Standard
3031
3032 \backslash 
3033 /
3034 \end_inset 
3035
3036 -login
3037 \layout Standard
3038
3039 Text selected with the mouse is automatically copied to the clipboard, pasting
3040  works with shift-insert.
3041 \newline 
3042
3043 \newline 
3044 The other good tip is to make sure you have no //c/-style paths anywhere,
3045  use /cygdrive/c/ instead.
3046  Using // invokes a network lookup which is very slow.
3047  If you think 
3048 \begin_inset Quotes sld
3049 \end_inset 
3050
3051 cygdrive
3052 \begin_inset Quotes srd
3053 \end_inset 
3054
3055  is too long, you can change it with e.g.
3056 \layout LyX-Code
3057
3058 mount -s -u -c /mnt
3059 \layout Standard
3060
3061 SDCC sources use the unix line ending LF.
3062  Life is much easier, if you store the source tree on a drive which is mounted
3063  in binary mode.
3064  And use an editor which can handle LF-only line endings.
3065  Make sure not to commit files with windows line endings.
3066  The tabulator spacing used in the project is 8.
3067 \layout Subsubsection
3068
3069 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3070 \layout Standard
3071
3072
3073 \series medium 
3074 Download the source package
3075 \series default 
3076  either from the SDCC CVS repository or from the 
3077 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3078
3079 \end_inset 
3080
3081
3082 \series medium 
3083 , it will be named something like sdcc
3084 \series default 
3085 .src
3086 \series medium 
3087 .tgz.
3088
3089 \series default 
3090  SDCC is distributed with all the projects, workspaces, and files you need
3091  to build it using Visual C++ 6.0/NET (except for sdcdb.exe which currently
3092  doesn't build under MSVC).
3093  The workspace name is 'sdcc.dsw'.
3094  Please note that as it is now, all the executables are created in a folder
3095  called sdcc
3096 \backslash 
3097 bin_vc.
3098  Once built you need to copy the executables from sdcc
3099 \backslash 
3100 bin_vc to sdcc
3101 \backslash 
3102 bin before running SDCC.
3103  
3104 \newline 
3105
3106 \newline 
3107 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3108  flex.exe, and gawk.exe.
3109  One good place to get them is 
3110 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3111
3112 \end_inset 
3113
3114
3115 \newline 
3116
3117 \newline 
3118 Download the file UnxUtils
3119 \begin_inset LatexCommand \index{UnxUtils}
3120
3121 \end_inset 
3122
3123 .zip.
3124  Now you have to install the utilities and setup MSVC so it can locate the
3125  required programs.
3126  Here there are two alternatives (choose one!):
3127 \layout Enumerate
3128
3129 The easy way:
3130 \newline 
3131
3132 \newline 
3133 a) Extract UnxUtils.zip to your C:
3134 \backslash 
3135  hard disk PRESERVING the original paths, otherwise bison won't work.
3136  (If you are using WinZip make certain that 'Use folder names' is selected)
3137 \newline 
3138
3139 \newline 
3140 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3141  in 'Show directories for:' select 'Executable files', and in the directories
3142  window add a new path: 'C:
3143 \backslash 
3144 user
3145 \backslash 
3146 local
3147 \backslash 
3148 wbin', click ok.
3149 \newline 
3150
3151 \newline 
3152 (As a side effect, you get a bunch of Unix utilities that could be useful,
3153  such as diff and patch.)
3154 \layout Enumerate
3155
3156 A more compact way:
3157 \newline 
3158
3159 \newline 
3160 This one avoids extracting a bunch of files you may not use, but requires
3161  some extra work:
3162 \newline 
3163
3164 \newline 
3165 a) Create a directory were to put the tools needed, or use a directory already
3166  present.
3167  Say for example 'C:
3168 \backslash 
3169 util'.
3170 \newline 
3171
3172 \newline 
3173 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3174  to such directory WITHOUT preserving the original paths.
3175  (If you are using WinZip make certain that 'Use folder names' is not selected)
3176 \newline 
3177
3178 \newline 
3179 c) Rename bison.exe to '_bison.exe'.
3180 \newline 
3181
3182 \newline 
3183 d) Create a batch file 'bison.bat' in 'C:
3184 \backslash 
3185 util
3186 \backslash 
3187 ' and add these lines: 
3188 \newline 
3189 \SpecialChar ~
3190 \SpecialChar ~
3191 set BISON_SIMPLE=C:
3192 \backslash 
3193 util
3194 \backslash 
3195 bison.simple 
3196 \newline 
3197 \SpecialChar ~
3198 \SpecialChar ~
3199 set BISON_HAIRY=C:
3200 \backslash 
3201 util
3202 \backslash 
3203 bison.hairy
3204 \newline 
3205 \SpecialChar ~
3206 \SpecialChar ~
3207 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3208 \newline 
3209
3210 \newline 
3211 Steps 'c' and 'd' are needed because bison requires by default that the
3212  files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3213  '/usr/local/share/' I think.
3214  So it is necessary to tell bison where those files are located if they
3215  are not in such directory.
3216  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3217 \newline 
3218
3219 \newline 
3220 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3221  in 'Show directories for:' select 'Executable files', and in the directories
3222  window add a new path: 'c:
3223 \backslash 
3224 util', click ok.
3225  Note that you can use any other path instead of 'c:
3226 \backslash 
3227 util', even the path where the Visual C++ tools are, probably: 'C:
3228 \backslash 
3229 Program Files
3230 \backslash 
3231 Microsoft Visual Studio
3232 \backslash 
3233 Common
3234 \backslash 
3235 Tools'.
3236  So you don't have to execute step 'e' :)
3237 \layout Standard
3238
3239 That is it.
3240  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3241  the executables from sdcc
3242 \backslash 
3243 bin_vc to sdcc
3244 \backslash 
3245 bin, and you can compile using sdcc.
3246 \layout Subsubsection
3247
3248 Building SDCC Using Borland
3249 \layout Enumerate
3250
3251 From the sdcc directory, run the command "make -f Makefile.bcc".
3252  This should regenerate all the .exe files in the bin directory except for
3253  sdcdb.exe (which currently doesn't build under Borland C++).
3254 \layout Enumerate
3255
3256 If you modify any source files and need to rebuild, be aware that the dependenci
3257 es may not be correctly calculated.
3258  The safest option is to delete all .obj files and run the build again.
3259  From a Cygwin BASH prompt, this can easily be done with the command (be
3260  sure you are in the sdcc directory):
3261 \newline 
3262
3263 \newline 
3264
3265 \family sans 
3266 \series bold 
3267 find .
3268  
3269 \backslash 
3270 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
3271 \backslash 
3272 ) -print -exec rm {} 
3273 \backslash 
3274 ;
3275 \family default 
3276 \series default 
3277
3278 \newline 
3279
3280 \newline 
3281 or on Windows NT/2000/XP from the command prompt with the command:
3282 \newline 
3283
3284 \family sans 
3285 \series bold 
3286
3287 \newline 
3288 del /s *.obj *.lib *.rul
3289 \family default 
3290 \series default 
3291  from the sdcc directory.
3292 \layout Subsubsection
3293
3294 Windows Install Using a Binary Package
3295 \begin_inset LatexCommand \label{sub:Windows-Install}
3296
3297 \end_inset 
3298
3299
3300 \layout Enumerate
3301
3302 Download the binary package and unpack it using your favorite unpacking
3303  tool (gunzip, WinZip, etc).
3304  This should unpack to a group of sub-directories.
3305  An example directory structure after unpacking the mingw32 package is:
3306  c:
3307 \backslash 
3308 sdcc
3309 \backslash 
3310 bin for the executables, c:
3311 \backslash 
3312 sdcc
3313 \backslash 
3314 include and c:
3315 \backslash 
3316 sdcc
3317 \backslash 
3318 lib for the include and libraries.
3319 \layout Enumerate
3320
3321 Adjust your environment variable PATH to include the location of the bin
3322  directory or start sdcc using the full path.
3323 \layout Subsection
3324
3325 Building the Documentation
3326 \layout Standard
3327
3328 If the necessary tools are installed it is as easy as changing into the
3329  doc directory and typing 
3330 \family sans 
3331 \series bold 
3332
3333 \begin_inset Quotes srd
3334 \end_inset 
3335
3336 make
3337 \begin_inset Quotes srd
3338 \end_inset 
3339
3340
3341 \family default 
3342 \series default 
3343  there.
3344  If you want to avoid installing the tools you will have some success with
3345  a bootable Knoppix CD 
3346 \begin_inset LatexCommand \url{http://www.knopper.net}
3347
3348 \end_inset 
3349
3350 .
3351 \layout Subsection
3352
3353 Testing the SDCC Compiler
3354 \layout Standard
3355
3356 The first thing you should do after installing your SDCC compiler is to
3357  see if it runs.
3358  Type 
3359 \family sans 
3360 \series bold 
3361 "sdcc -
3362 \begin_inset ERT
3363 status Collapsed
3364
3365 \layout Standard
3366
3367 \backslash 
3368 /
3369 \end_inset 
3370
3371 -version"
3372 \begin_inset LatexCommand \index{version}
3373
3374 \end_inset 
3375
3376
3377 \family default 
3378 \series default 
3379  at the prompt, and the program should run and tell you the version.
3380  If it doesn't run, or gives a message about not finding sdcc program, then
3381  you need to check over your installation.
3382  Make sure that the sdcc bin directory is in your executable search path
3383  defined by the PATH environment setting (see the Trouble-shooting section
3384  for suggestions).
3385  Make sure that the sdcc program is in the bin folder, if not perhaps something
3386  did not install correctly.
3387 \newline 
3388
3389 \newline 
3390
3391 \series medium 
3392 SDCC 
3393 \series default 
3394 is commonly installed as described in section 
3395 \begin_inset Quotes sld
3396 \end_inset 
3397
3398 Install and search paths
3399 \begin_inset Quotes srd
3400 \end_inset 
3401
3402
3403 \newline 
3404
3405 \newline 
3406
3407 \series medium 
3408 Make sure the compiler works on a very simple example.
3409  Type in the following test.c program using your favorite 
3410 \series default 
3411 ASCII 
3412 \series medium 
3413 editor:
3414 \layout Verse
3415
3416
3417 \family typewriter 
3418 char test;
3419 \newline 
3420
3421 \newline 
3422 void main(void) {
3423 \newline 
3424 \SpecialChar ~
3425 \SpecialChar ~
3426 \SpecialChar ~
3427 \SpecialChar ~
3428 test=0;
3429 \newline 
3430 }
3431 \layout Standard
3432
3433
3434 \series medium 
3435 Compile this using the following command: 
3436 \family sans 
3437 \series bold 
3438 "sdcc -c test.c".
3439
3440 \family default 
3441 \series default 
3442  
3443 \series medium 
3444 If all goes well, the compiler will generate a test.asm and test.rel file.
3445  Congratulations, you've just compiled your first program with SDCC.
3446  We used the -c option to tell SDCC not to link the generated code, just
3447  to keep things simple for this step.
3448 \series default 
3449
3450 \newline 
3451
3452 \newline 
3453
3454 \series medium 
3455 The next step is to try it with the linker.
3456  Type in 
3457 \family sans 
3458 \series bold 
3459 "sdcc test.c
3460 \family default 
3461 \series default 
3462 "
3463 \series medium 
3464 .
3465  If all goes well the compiler will link with the libraries and produce
3466  a test.ihx output file.
3467  If this step fails
3468 \series default 
3469  
3470 \series medium 
3471 (no test.ihx, and the linker generates warnings), then the problem is most
3472  likely that sdcc cannot find the 
3473 \series default 
3474 /
3475 \series medium 
3476 usr/local/share/sdcc/lib directory
3477 \series default 
3478  
3479 \series medium 
3480 (see the Install trouble-shooting section for suggestions).
3481 \series default 
3482
3483 \newline 
3484
3485 \newline 
3486
3487 \series medium 
3488 The final test is to ensure sdcc can use the 
3489 \series default 
3490 standard
3491 \series medium 
3492  header files and libraries.
3493  Edit test.c and change it to the following:
3494 \layout Verse
3495
3496
3497 \family typewriter 
3498 #include <string.h>
3499 \newline 
3500
3501 \newline 
3502 char str1[10];
3503 \newline 
3504
3505 \newline 
3506 void main(void) {
3507 \newline 
3508 \SpecialChar ~
3509 \SpecialChar ~
3510 strcpy(str1, "testing");
3511 \newline 
3512 }
3513 \layout Standard
3514
3515
3516 \series medium 
3517 Compile this by typing 
3518 \family sans 
3519 \series bold 
3520 "sdcc test.c"
3521 \family default 
3522 \series medium 
3523 .
3524  This should generate a test.ihx output file, and it should give no warnings
3525  such as not finding the string.h file.
3526  If it cannot find the string.h file, then the problem is that sdcc cannot
3527  find the /usr/local/share/sdcc/include directory
3528 \series default 
3529  
3530 \series medium 
3531 (see the Install trouble-shooting section for suggestions).
3532
3533 \series default 
3534  Use option 
3535 \series bold 
3536 -
3537 \begin_inset ERT
3538 status Collapsed
3539
3540 \layout Standard
3541
3542 \backslash 
3543 /
3544 \end_inset 
3545
3546 -print-search-dirs
3547 \series default 
3548
3549 \begin_inset LatexCommand \index{-\/-print-search-dirs}
3550
3551 \end_inset 
3552
3553  to find exactly where SDCC is looking for the include and lib files.
3554 \layout Subsection
3555
3556 Install Trouble-shooting
3557 \begin_inset LatexCommand \index{Install trouble-shooting}
3558
3559 \end_inset 
3560
3561
3562 \layout Subsubsection
3563
3564 SDCC does not build correctly.
3565 \layout Standard
3566
3567 A thing to try is starting from scratch by unpacking the .tgz source package
3568  again in an empty directory.
3569  Configure it like:
3570 \newline 
3571
3572 \newline 
3573
3574 \family sans 
3575 \series bold 
3576 ./configure 2>&1 | tee configure.log
3577 \family default 
3578 \series default 
3579
3580 \newline 
3581
3582 \newline 
3583 and build it like:
3584 \newline 
3585
3586 \newline 
3587
3588 \family sans 
3589 \series bold 
3590 make 2>&1 | tee make.log
3591 \family default 
3592 \series default 
3593
3594 \newline 
3595
3596 \newline 
3597 If anything goes wrong, you can review the log files to locate the problem.
3598  Or a relevant part of this can be attached to an email that could be helpful
3599  when requesting help from the mailing list.
3600 \layout Subsubsection
3601
3602 What the 
3603 \begin_inset Quotes sld
3604 \end_inset 
3605
3606 ./configure
3607 \begin_inset Quotes srd
3608 \end_inset 
3609
3610  does
3611 \layout Standard
3612
3613 The 
3614 \begin_inset Quotes sld
3615 \end_inset 
3616
3617 ./configure
3618 \begin_inset Quotes srd
3619 \end_inset 
3620
3621  command is a script that analyzes your system and performs some configuration
3622  to ensure the source package compiles on your system.
3623  It will take a few minutes to run, and will compile a few tests to determine
3624  what compiler features are installed.
3625 \layout Subsubsection
3626
3627 What the 
3628 \begin_inset Quotes sld
3629 \end_inset 
3630
3631 make
3632 \begin_inset Quotes srd
3633 \end_inset 
3634
3635  does.
3636 \layout Standard
3637
3638 This runs the GNU make tool, which automatically compiles all the source
3639  packages into the final installed binary executables.
3640 \layout Subsubsection
3641
3642 What the 
3643 \begin_inset Quotes sld
3644 \end_inset 
3645
3646 make install
3647 \begin_inset Quotes erd
3648 \end_inset 
3649
3650  command does.
3651 \layout Standard
3652
3653 This will install the compiler, other executables libraries and include
3654  files into the appropriate directories.
3655  See section 
3656 \begin_inset Quotes sld
3657 \end_inset 
3658
3659 Install and Search PATHS
3660 \begin_inset Quotes srd
3661 \end_inset 
3662
3663 .
3664 \newline 
3665 On most systems you will need super-user privileges to do this.
3666 \layout Subsection
3667
3668 Components of SDCC
3669 \layout Standard
3670
3671 SDCC is not just a compiler, but a collection of tools by various developers.
3672  These include linkers, assemblers, simulators and other components.
3673  Here is a summary of some of the components.
3674  Note that the included simulator and assembler have separate documentation
3675  which you can find in the source package in their respective directories.
3676  As SDCC grows to include support for other processors, other packages from
3677  various developers are included and may have their own sets of documentation.
3678 \newline 
3679
3680 \newline 
3681 You might want to look at the files which are installed in <installdir>.
3682  At the time of this writing, we find the following programs for gcc-builds:
3683 \newline 
3684  
3685 \newline 
3686 In <installdir>/bin:
3687 \layout Itemize
3688
3689 sdcc - The compiler.
3690 \layout Itemize
3691
3692 sdcpp - The C preprocessor.
3693 \layout Itemize
3694
3695 asx8051 - The assembler for 8051 type processors.
3696 \layout Itemize
3697
3698 as-z80
3699 \series bold 
3700
3701 \series default 
3702 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
3703 \layout Itemize
3704
3705 aslink -The linker for 8051 type processors.
3706 \layout Itemize
3707
3708 link-z80
3709 \series bold 
3710
3711 \series default 
3712 link-gbz80 - The Z80 and GameBoy Z80 linkers.
3713 \layout Itemize
3714
3715 s51 - The ucSim 8051 simulator.
3716 \layout Itemize
3717
3718 sdcdb - The source debugger.
3719 \layout Itemize
3720
3721 packihx - A tool to pack (compress) Intel hex files.
3722 \layout Standard
3723
3724 In <installdir>/share/sdcc/include
3725 \layout Itemize
3726
3727 the include files
3728 \layout Standard
3729
3730 In <installdir>/share/sdcc/lib
3731 \layout Itemize
3732
3733 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
3734  relocatables.
3735 \layout Standard
3736
3737 In <installdir>/share/sdcc/doc
3738 \layout Itemize
3739
3740 the documentation
3741 \layout Standard
3742
3743 As development for other processors proceeds, this list will expand to include
3744  executables to support processors like AVR, PIC, etc.
3745 \layout Subsubsection
3746
3747 sdcc - The Compiler
3748 \layout Standard
3749
3750 This is the actual compiler, it in turn uses the c-preprocessor and invokes
3751  the assembler and linkage editor.
3752 \layout Subsubsection
3753
3754 sdcpp
3755 \begin_inset LatexCommand \index{sdcpp}
3756
3757 \end_inset 
3758
3759  - The C-Preprocessor
3760 \layout Standard
3761
3762 The preprocessor is a modified version of the GNU preprocessor.
3763  The C preprocessor is used to pull in #include sources, process #ifdef
3764  statements, #defines and so on.
3765 \layout Subsubsection
3766
3767 asx8051, as-z80, as-gbz80, aslink, link-z80, link-gbz80 - The Assemblers
3768  and Linkage Editors
3769 \layout Standard
3770
3771 This is retargettable assembler & linkage editor, it was developed by Alan
3772  Baldwin.
3773  John Hartman created the version for 8051, and I (Sandeep) have made some
3774  enhancements and bug fixes for it to work properly with SDCC.
3775 \layout Subsubsection
3776
3777 s51 - The Simulator
3778 \begin_inset LatexCommand \index{s51}
3779
3780 \end_inset 
3781
3782
3783 \layout Standard
3784
3785 S51 is a freeware, opensource simulator developed by Daniel Drotos (
3786 \begin_inset LatexCommand \url{mailto:drdani@mazsola.iit.uni-miskolc.hu}
3787
3788 \end_inset 
3789
3790 ).
3791  The simulator is built as part of the build process.
3792  For more information visit Daniel's web site at: 
3793 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
3794
3795 \end_inset 
3796
3797 .
3798  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
3799  XA51 family.
3800 \layout Subsubsection
3801
3802 sdcdb
3803 \begin_inset LatexCommand \index{sdcdb}
3804
3805 \end_inset 
3806
3807  - Source Level Debugger
3808 \layout Standard
3809
3810 Sdcdb is the companion source level debugger.
3811  The current version of the debugger uses Daniel's Simulator S51
3812 \begin_inset LatexCommand \index{s51}
3813
3814 \end_inset 
3815
3816 , but can be easily changed to use other simulators.
3817 \layout Section
3818 \pagebreak_top 
3819 Using SDCC
3820 \layout Subsection
3821
3822 Compiling
3823 \layout Subsubsection
3824
3825 Single Source File Projects
3826 \layout Standard
3827
3828 For single source file 8051 projects the process is very simple.
3829  Compile your programs with the following command 
3830 \family sans 
3831 \series bold 
3832 "sdcc sourcefile.c".
3833
3834 \family default 
3835 \series default 
3836  This will compile, assemble and link your source file.
3837  Output files are as follows
3838 \layout Itemize
3839
3840 sourcefile.asm
3841 \begin_inset LatexCommand \index{.asm}
3842
3843 \end_inset 
3844
3845  - Assembler source
3846 \begin_inset LatexCommand \index{Assembler source}
3847
3848 \end_inset 
3849
3850  file created by the compiler
3851 \layout Itemize
3852
3853 sourcefile.lst
3854 \begin_inset LatexCommand \index{.lst}
3855
3856 \end_inset 
3857
3858  - Assembler listing
3859 \begin_inset LatexCommand \index{Assembler listing}
3860
3861 \end_inset 
3862
3863  file created by the Assembler
3864 \layout Itemize
3865
3866 sourcefile.rst
3867 \begin_inset LatexCommand \index{.rst}
3868
3869 \end_inset 
3870
3871  - Assembler listing
3872 \begin_inset LatexCommand \index{Assembler listing}
3873
3874 \end_inset 
3875
3876  file updated with linkedit information, created by linkage editor
3877 \layout Itemize
3878
3879 sourcefile.sym
3880 \begin_inset LatexCommand \index{.sym}
3881
3882 \end_inset 
3883
3884  - symbol listing
3885 \begin_inset LatexCommand \index{Symbol listing}
3886
3887 \end_inset 
3888
3889  for the sourcefile, created by the assembler
3890 \layout Itemize
3891
3892 sourcefile.rel
3893 \begin_inset LatexCommand \index{.rel}
3894
3895 \end_inset 
3896
3897  - Object file
3898 \begin_inset LatexCommand \index{Object file}
3899
3900 \end_inset 
3901
3902  created by the assembler, input to Linkage editor
3903 \layout Itemize
3904
3905 sourcefile.map
3906 \begin_inset LatexCommand \index{.map}
3907
3908 \end_inset 
3909
3910  - The memory map
3911 \begin_inset LatexCommand \index{Memory map}
3912
3913 \end_inset 
3914
3915  for the load module, created by the Linker
3916 \layout Itemize
3917
3918 sourcefile.mem
3919 \begin_inset LatexCommand \index{.mem}
3920
3921 \end_inset 
3922
3923  - A file with a summary of the memory usage
3924 \layout Itemize
3925
3926 sourcefile.ihx
3927 \begin_inset LatexCommand \index{.ihx}
3928
3929 \end_inset 
3930
3931  - The load module in Intel hex format
3932 \begin_inset LatexCommand \index{Intel hex format}
3933
3934 \end_inset 
3935
3936  (you can select the Motorola S19 format
3937 \begin_inset LatexCommand \index{Motorola S19 format}
3938
3939 \end_inset 
3940
3941  with -
3942 \begin_inset ERT
3943 status Collapsed
3944
3945 \layout Standard
3946
3947 \backslash 
3948 /
3949 \end_inset 
3950
3951 -out-fmt-s19
3952 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
3953
3954 \end_inset 
3955
3956 .
3957  If you need another format you might want to use 
3958 \family sans 
3959 \shape italic 
3960 objdump
3961 \family default 
3962 \shape default 
3963
3964 \begin_inset LatexCommand \index{objdump}
3965
3966 \end_inset 
3967
3968  or
3969 \family sans 
3970 \shape italic 
3971  srecord
3972 \family default 
3973 \shape default 
3974
3975 \begin_inset LatexCommand \index{srecord}
3976
3977 \end_inset 
3978
3979 )
3980 \layout Itemize
3981
3982 sourcefile.adb
3983 \begin_inset LatexCommand \index{.adb}
3984
3985 \end_inset 
3986
3987  - An intermediate file containing debug information needed to create the
3988  .cdb file (with -
3989 \begin_inset ERT
3990 status Collapsed
3991
3992 \layout Standard
3993
3994 \backslash 
3995 /
3996 \end_inset 
3997
3998 -debug
3999 \begin_inset LatexCommand \index{-\/-debug}
4000
4001 \end_inset 
4002
4003
4004 \layout Itemize
4005
4006 sourcefile.cdb
4007 \begin_inset LatexCommand \index{.cdb}
4008
4009 \end_inset 
4010
4011  - An optional file (with -
4012 \begin_inset ERT
4013 status Collapsed
4014
4015 \layout Standard
4016
4017 \backslash 
4018 /
4019 \end_inset 
4020
4021 -debug) containing debug information
4022 \layout Itemize
4023
4024 sourcefile.
4025  - (no extension)
4026 \begin_inset LatexCommand \index{. (no extension)}
4027
4028 \end_inset 
4029
4030  An optional AOMF51
4031 \begin_inset LatexCommand \index{AOMF51}
4032
4033 \end_inset 
4034
4035  file containing debug information (with -
4036 \begin_inset ERT
4037 status Collapsed
4038
4039 \layout Standard
4040
4041 \backslash 
4042 /
4043 \end_inset 
4044
4045 -debug).
4046  This format is commonly used by third party tools (debuggers
4047 \begin_inset LatexCommand \index{Debugger}
4048
4049 \end_inset 
4050
4051 , simulators, emulators)
4052 \layout Itemize
4053
4054 sourcefile.dump*
4055 \begin_inset LatexCommand \index{.dump*}
4056
4057 \end_inset 
4058
4059  - Dump file to debug the compiler it self (with -
4060 \begin_inset ERT
4061 status Collapsed
4062
4063 \layout Standard
4064
4065 \backslash 
4066 /
4067 \end_inset 
4068
4069 -dumpall) (see section 
4070 \begin_inset Quotes sld
4071 \end_inset 
4072
4073 Anatomy of the compiler
4074 \begin_inset Quotes srd
4075 \end_inset 
4076
4077 ).
4078 \layout Subsubsection
4079
4080 Projects with Multiple Source Files
4081 \layout Standard
4082
4083 SDCC can compile only ONE file at a time.
4084  Let us for example assume that you have a project containing the following
4085  files:
4086 \newline 
4087
4088 \newline 
4089 foo1.c (contains some functions)
4090 \newline 
4091 foo2.c (contains some more functions)
4092 \newline 
4093 foomain.c (contains more functions and the function main)
4094 \newline 
4095
4096 \size footnotesize 
4097
4098 \newline 
4099
4100 \size default 
4101 The first two files will need to be compiled separately with the commands:
4102 \size footnotesize 
4103  
4104 \size default 
4105
4106 \newline 
4107
4108 \newline 
4109
4110 \family sans 
4111 \series bold 
4112 sdcc\SpecialChar ~
4113 -c\SpecialChar ~
4114 foo1.c
4115 \family default 
4116 \series default 
4117 \size footnotesize 
4118
4119 \newline 
4120
4121 \family sans 
4122 \series bold 
4123 \size default 
4124 sdcc\SpecialChar ~
4125 -c\SpecialChar ~
4126 foo2.c
4127 \family default 
4128 \series default 
4129
4130 \newline 
4131
4132 \newline 
4133 Then compile the source file containing the 
4134 \emph on 
4135 main()
4136 \emph default 
4137  function and link
4138 \begin_inset LatexCommand \index{Linker}
4139
4140 \end_inset 
4141
4142  the files together with the following command: 
4143 \newline 
4144
4145 \newline 
4146
4147 \family sans 
4148 \series bold 
4149 sdcc\SpecialChar ~
4150 foomain.c\SpecialChar ~
4151 foo1.rel\SpecialChar ~
4152 foo2.rel
4153 \family default 
4154 \series default 
4155
4156 \begin_inset LatexCommand \index{.rel}
4157
4158 \end_inset 
4159
4160
4161 \newline 
4162
4163 \newline 
4164 Alternatively, 
4165 \emph on 
4166 foomain.c 
4167 \emph default 
4168 can be separately compiled as well: 
4169 \family sans 
4170 \series bold 
4171
4172 \newline 
4173
4174 \newline 
4175 sdcc\SpecialChar ~
4176 -c\SpecialChar ~
4177 foomain.c
4178 \newline 
4179 sdcc foomain.rel foo1.rel foo2.rel
4180 \newline 
4181
4182 \newline 
4183
4184 \family default 
4185 \series default 
4186 The file containing the 
4187 \emph on 
4188 main()
4189 \emph default 
4190  function
4191 \emph on 
4192  
4193 \emph default 
4194 \noun on 
4195 must
4196 \noun default 
4197  be the 
4198 \noun on 
4199 first
4200 \noun default 
4201  file specified in the command line, since the linkage editor processes
4202  file in the order they are presented to it.
4203  The linker is invoked from sdcc using a script file with extension .lnk
4204 \begin_inset LatexCommand \index{.lnk}
4205
4206 \end_inset 
4207
4208 .
4209  You can view this file to troubleshoot linking problems such as those arising
4210  from missing libraries.
4211 \layout Subsubsection
4212
4213 Projects with Additional Libraries
4214 \begin_inset LatexCommand \index{Libraries}
4215
4216 \end_inset 
4217
4218
4219 \layout Standard
4220
4221 Some reusable routines may be compiled into a library, see the documentation
4222  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
4223  for how to create a 
4224 \emph on 
4225 .lib
4226 \begin_inset LatexCommand \index{.lib}
4227
4228 \end_inset 
4229
4230
4231 \emph default 
4232  library file.
4233  Libraries created in this manner can be included in the command line.
4234  Make sure you include the -L <library-path> option to tell the linker where
4235  to look for these files if they are not in the current directory.
4236  Here is an example, assuming you have the source file 
4237 \emph on 
4238 foomain.c
4239 \emph default 
4240  and a library
4241 \emph on 
4242  foolib.lib
4243 \emph default 
4244  in the directory 
4245 \emph on 
4246 mylib
4247 \emph default 
4248  (if that is not the same as your current project):
4249 \newline 
4250
4251 \newline 
4252
4253 \family sans 
4254 \series bold 
4255 sdcc foomain.c foolib.lib -L mylib
4256 \newline 
4257
4258 \newline 
4259
4260 \family default 
4261 \series default 
4262 Note here that
4263 \emph on 
4264  mylib
4265 \emph default 
4266  must be an absolute path name.
4267 \newline 
4268
4269 \newline 
4270 The most efficient way to use libraries is to keep separate modules in separate
4271  source files.
4272  The lib file now should name all the modules.rel
4273 \begin_inset LatexCommand \index{rel}
4274
4275 \end_inset 
4276
4277  files.
4278  For an example see the standard library file 
4279 \emph on 
4280 libsdcc.lib
4281 \emph default 
4282  in the directory <installdir>/share/lib/small.
4283 \layout Subsection
4284
4285 Command Line Options
4286 \begin_inset LatexCommand \index{Command Line Options}
4287
4288 \end_inset 
4289
4290
4291 \layout Subsubsection
4292
4293 Processor Selection Options
4294 \begin_inset LatexCommand \index{Options processor selection}
4295
4296 \end_inset 
4297
4298
4299 \begin_inset LatexCommand \index{Processor selection options}
4300
4301 \end_inset 
4302
4303
4304 \layout List
4305 \labelwidthstring 00.00.0000
4306
4307
4308 \series bold 
4309 -mmcs51
4310 \begin_inset LatexCommand \index{-mmcs51}
4311
4312 \end_inset 
4313
4314
4315 \series default 
4316  Generate code for the MCS51
4317 \begin_inset LatexCommand \index{MCS51}
4318
4319 \end_inset 
4320
4321  family of processors.
4322  This is the default processor target.
4323 \layout List
4324 \labelwidthstring 00.00.0000
4325
4326
4327 \series bold 
4328 -mds390
4329 \begin_inset LatexCommand \index{-mds390}
4330
4331 \end_inset 
4332
4333
4334 \series default 
4335  Generate code for the Dallas DS80C390
4336 \begin_inset LatexCommand \index{DS80C390}
4337
4338 \end_inset 
4339
4340  processor.
4341 \layout List
4342 \labelwidthstring 00.00.0000
4343
4344
4345 \series bold 
4346 -mds400
4347 \begin_inset LatexCommand \index{-mds400}
4348
4349 \end_inset 
4350
4351
4352 \series default 
4353  Generate code for the Dallas DS80C400
4354 \begin_inset LatexCommand \index{DS80C400}
4355
4356 \end_inset 
4357
4358  processor.
4359 \layout List
4360 \labelwidthstring 00.00.0000
4361
4362
4363 \series bold 
4364 -mz80
4365 \begin_inset LatexCommand \index{-mz80}
4366
4367 \end_inset 
4368
4369
4370 \series default 
4371  Generate code for the Zilog Z80
4372 \begin_inset LatexCommand \index{Z80}
4373
4374 \end_inset 
4375
4376  family of processors.
4377 \layout List
4378 \labelwidthstring 00.00.0000
4379
4380
4381 \series bold 
4382 -mgbz80
4383 \begin_inset LatexCommand \index{-mgbz80}
4384
4385 \end_inset 
4386
4387
4388 \series default 
4389  Generate code for the GameBoy Z80
4390 \begin_inset LatexCommand \index{GameBoy Z80}
4391
4392 \end_inset 
4393
4394  processor.
4395 \layout List
4396 \labelwidthstring 00.00.0000
4397
4398
4399 \series bold 
4400 -mavr
4401 \begin_inset LatexCommand \index{-mavr}
4402
4403 \end_inset 
4404
4405
4406 \series default 
4407  Generate code for the Atmel AVR
4408 \begin_inset LatexCommand \index{AVR}
4409
4410 \end_inset 
4411
4412  processor (In development, not complete).
4413  AVR users should probably have a look at avr-gcc 
4414 \begin_inset LatexCommand \url{ http://savannah.nongnu.org/download/avr-libc/snapshots/}
4415
4416 \end_inset 
4417
4418 .
4419 \layout Comment
4420
4421 I think it is fair to direct users there for now.
4422  Open source is also about avoiding unnecessary work .
4423  But I didn't find the 'official' link.
4424 \layout List
4425 \labelwidthstring 00.00.0000
4426
4427
4428 \series bold 
4429 -mpic14
4430 \begin_inset LatexCommand \index{-mpic14}
4431
4432 \end_inset 
4433
4434
4435 \series default 
4436  Generate code for the Microchip PIC 14
4437 \begin_inset LatexCommand \index{PIC14}
4438
4439 \end_inset 
4440
4441 -bit processors (p16f84 and variants).
4442 \layout Comment
4443
4444 p16f627 p16f628 p16f84 p16f873 p16f877?
4445 \layout List
4446 \labelwidthstring 00.00.0000
4447
4448
4449 \series bold 
4450 -mpic16
4451 \begin_inset LatexCommand \index{-mpic16}
4452
4453 \end_inset 
4454
4455
4456 \series default 
4457  Generate code for the Microchip PIC 16
4458 \begin_inset LatexCommand \index{PIC16}
4459
4460 \end_inset 
4461
4462 -bit processors (p18f452 and variants).
4463 \layout List
4464 \labelwidthstring 00.00.0000
4465
4466
4467 \series bold 
4468 -mtlcs900h
4469 \series default 
4470  Generate code for the Toshiba TLCS-900H
4471 \begin_inset LatexCommand \index{TLCS-900H}
4472
4473 \end_inset 
4474
4475  processor (In development, not complete).
4476 \layout List
4477 \labelwidthstring 00.00.0000
4478
4479
4480 \series bold 
4481 -mxa51
4482 \begin_inset LatexCommand \index{-mxa51}
4483
4484 \end_inset 
4485
4486
4487 \series default 
4488  Generate code for the Phillips XA51
4489 \begin_inset LatexCommand \index{XA51}
4490
4491 \end_inset 
4492
4493  processor (In development, not complete).
4494 \layout Subsubsection
4495
4496 Preprocessor Options
4497 \begin_inset LatexCommand \index{Options preprocessor}
4498
4499 \end_inset 
4500
4501
4502 \begin_inset LatexCommand \index{Preprocessor options}
4503
4504 \end_inset 
4505
4506
4507 \layout List
4508 \labelwidthstring 00.00.0000
4509
4510
4511 \series bold 
4512 -I<path>
4513 \begin_inset LatexCommand \index{-I<path>}
4514
4515 \end_inset 
4516
4517
4518 \series default 
4519  The additional location where the pre processor will look for <..h> or 
4520 \begin_inset Quotes eld
4521 \end_inset 
4522
4523 ..h
4524 \begin_inset Quotes erd
4525 \end_inset 
4526
4527  files.
4528 \layout List
4529 \labelwidthstring 00.00.0000
4530
4531
4532 \series bold 
4533 -D<macro[=value]>
4534 \begin_inset LatexCommand \index{-D<macro[=value]>}
4535
4536 \end_inset 
4537
4538
4539 \series default 
4540  Command line definition of macros.
4541  Passed to the preprocessor.
4542 \layout List
4543 \labelwidthstring 00.00.0000
4544
4545
4546 \series bold 
4547 -M
4548 \begin_inset LatexCommand \index{-M}
4549
4550 \end_inset 
4551
4552
4553 \series default 
4554  Tell the preprocessor to output a rule suitable for make describing the
4555  dependencies of each object file.
4556  For each source file, the preprocessor outputs one make-rule whose target
4557  is the object file name for that source file and whose dependencies are
4558  all the files `#include'd in it.
4559  This rule may be a single line or may be continued with `
4560 \backslash 
4561 '-newline if it is long.
4562  The list of rules is printed on standard output instead of the preprocessed
4563  C program.
4564  `-M' implies `-E
4565 \begin_inset LatexCommand \index{-E}
4566
4567 \end_inset 
4568
4569 '.
4570 \layout List
4571 \labelwidthstring 00.00.0000
4572
4573
4574 \series bold 
4575 -C
4576 \begin_inset LatexCommand \index{-C}
4577
4578 \end_inset 
4579
4580
4581 \series default 
4582  Tell the preprocessor not to discard comments.
4583  Used with the `-E' option.
4584 \layout List
4585 \labelwidthstring 00.00.0000
4586
4587
4588 \series bold 
4589 -MM
4590 \begin_inset LatexCommand \index{-MM}
4591
4592 \end_inset 
4593
4594
4595 \size large 
4596 \bar under 
4597  
4598 \series default 
4599 \size default 
4600 \bar default 
4601 Like `-M' but the output mentions only the user header files included with
4602  `#include 
4603 \begin_inset Quotes eld
4604 \end_inset 
4605
4606 file"'.
4607  System header files included with `#include <file>' are omitted.
4608 \layout List
4609 \labelwidthstring 00.00.0000
4610
4611
4612 \series bold 
4613 -Aquestion(answer)
4614 \begin_inset LatexCommand \index{-Aquestion(answer)}
4615
4616 \end_inset 
4617
4618
4619 \series default 
4620  Assert the answer answer for question, in case it is tested with a preprocessor
4621  conditional such as `#if #question(answer)'.
4622  `-A-' disables the standard assertions that normally describe the target
4623  machine.
4624 \layout List
4625 \labelwidthstring 00.00.0000
4626
4627
4628 \series bold 
4629 -Umacro
4630 \begin_inset LatexCommand \index{-Umacro}
4631
4632 \end_inset 
4633
4634
4635 \series default 
4636  Undefine macro macro.
4637  `-U' options are evaluated after all `-D' options, but before any `-include'
4638  and `-imacros' options.
4639 \layout List
4640 \labelwidthstring 00.00.0000
4641
4642
4643 \series bold 
4644 -dM
4645 \begin_inset LatexCommand \index{-dM}
4646
4647 \end_inset 
4648
4649
4650 \series default 
4651  Tell the preprocessor to output only a list of the macro definitions that
4652  are in effect at the end of preprocessing.
4653  Used with the `-E' option.
4654 \layout List
4655 \labelwidthstring 00.00.0000
4656
4657
4658 \series bold 
4659 -dD
4660 \begin_inset LatexCommand \index{-dD}
4661
4662 \end_inset 
4663
4664
4665 \series default 
4666  Tell the preprocessor to pass all macro definitions into the output, in
4667  their proper sequence in the rest of the output.
4668 \layout List
4669 \labelwidthstring 00.00.0000
4670
4671
4672 \series bold 
4673 -dN
4674 \begin_inset LatexCommand \index{-dN}
4675
4676 \end_inset 
4677
4678
4679 \size large 
4680 \bar under 
4681  
4682 \series default 
4683 \size default 
4684 \bar default 
4685 Like `-dD' except that the macro arguments and contents are omitted.
4686  Only `#define name' is included in the output.
4687 \layout Subsubsection
4688
4689 Linker Options
4690 \begin_inset LatexCommand \index{Options linker}
4691
4692 \end_inset 
4693
4694
4695 \begin_inset LatexCommand \index{Linker options}
4696
4697 \end_inset 
4698
4699
4700 \layout List
4701 \labelwidthstring 00.00.0000
4702
4703
4704 \series bold 
4705 -L\SpecialChar ~
4706 -
4707 \series default 
4708
4709 \begin_inset ERT
4710 status Collapsed
4711
4712 \layout Standard
4713
4714 \backslash 
4715 /
4716 \end_inset 
4717
4718
4719 \series bold 
4720 -lib-path
4721 \begin_inset LatexCommand \index{-\/-lib-path}
4722
4723 \end_inset 
4724
4725
4726 \begin_inset LatexCommand \index{-L -\/-lib-path}
4727
4728 \end_inset 
4729
4730
4731 \bar under 
4732  
4733 \series default 
4734 \bar default 
4735 <absolute path to additional libraries> This option is passed to the linkage
4736  editor's additional libraries
4737 \begin_inset LatexCommand \index{Libraries}
4738
4739 \end_inset 
4740
4741  search path.
4742  The path name must be absolute.
4743  Additional library files may be specified in the command line.
4744  See section Compiling programs for more details.
4745 \layout List
4746 \labelwidthstring 00.00.0000
4747
4748
4749 \series bold 
4750 -
4751 \begin_inset ERT
4752 status Collapsed
4753
4754 \layout Standard
4755
4756 \backslash 
4757 /
4758 \end_inset 
4759
4760 -xram-loc
4761 \series default 
4762
4763 \begin_inset LatexCommand \index{-\/-xram-loc}
4764
4765 \end_inset 
4766
4767 <Value> The start location of the external ram
4768 \begin_inset LatexCommand \index{xdata}
4769
4770 \end_inset 
4771
4772 , default value is 0.
4773  The value entered can be in Hexadecimal or Decimal format, e.g.: -
4774 \begin_inset ERT
4775 status Collapsed
4776
4777 \layout Standard
4778
4779 \backslash 
4780 /
4781 \end_inset 
4782
4783 -xram-loc 0x8000 or -
4784 \begin_inset ERT
4785 status Collapsed
4786
4787 \layout Standard
4788
4789 \backslash 
4790 /
4791 \end_inset 
4792
4793 -xram-loc 32768.
4794 \layout List
4795 \labelwidthstring 00.00.0000
4796
4797
4798 \series bold 
4799 -
4800 \begin_inset ERT
4801 status Collapsed
4802
4803 \layout Standard
4804
4805 \backslash 
4806 /
4807 \end_inset 
4808
4809 -code-loc
4810 \series default 
4811
4812 \begin_inset LatexCommand \index{-\/-code-loc}
4813
4814 \end_inset 
4815
4816 <Value> The start location of the code
4817 \begin_inset LatexCommand \index{code}
4818
4819 \end_inset 
4820
4821  segment, default value 0.
4822  Note when this option is used the interrupt vector table is also relocated
4823  to the given address.
4824  The value entered can be in Hexadecimal or Decimal format, e.g.: -
4825 \begin_inset ERT
4826 status Collapsed
4827
4828 \layout Standard
4829
4830 \backslash 
4831 /
4832 \end_inset 
4833
4834 -code-loc 0x8000 or -
4835 \begin_inset ERT
4836 status Collapsed
4837
4838 \layout Standard
4839
4840 \backslash 
4841 /
4842 \end_inset 
4843
4844 -code-loc 32768.
4845 \layout List
4846 \labelwidthstring 00.00.0000
4847
4848
4849 \series bold 
4850 -
4851 \begin_inset ERT
4852 status Collapsed
4853
4854 \layout Standard
4855
4856 \backslash 
4857 /
4858 \end_inset 
4859
4860 -stack-loc
4861 \series default 
4862
4863 \begin_inset LatexCommand \index{-\/-stack-loc}
4864
4865 \end_inset 
4866
4867 <Value> By default the stack
4868 \begin_inset LatexCommand \index{stack}
4869
4870 \end_inset 
4871
4872  is placed after the data segment.
4873  Using this option the stack can be placed anywhere in the internal memory
4874  space of the 8051.
4875  The value entered can be in Hexadecimal or Decimal format, e.g.
4876  -
4877 \begin_inset ERT
4878 status Collapsed
4879
4880 \layout Standard
4881
4882 \backslash 
4883 /
4884 \end_inset 
4885
4886 -stack-loc 0x20 or -
4887 \begin_inset ERT
4888 status Collapsed
4889
4890 \layout Standard
4891
4892 \backslash 
4893 /
4894 \end_inset 
4895
4896 -stack-loc 32.
4897  Since the sp register is incremented before a push or call, the initial
4898  sp will be set to one byte prior the provided value.
4899  The provided value should not overlap any other memory areas such as used
4900  register banks or the data segment and with enough space for the current
4901  application.
4902 \layout List
4903 \labelwidthstring 00.00.0000
4904
4905
4906 \series bold 
4907 -
4908 \begin_inset ERT
4909 status Collapsed
4910
4911 \layout Standard
4912
4913 \backslash 
4914 /
4915 \end_inset 
4916
4917 -data-loc
4918 \series default 
4919
4920 \begin_inset LatexCommand \index{-\/-data-loc}
4921
4922 \end_inset 
4923
4924 <Value> The start location of the internal ram data
4925 \begin_inset LatexCommand \index{data}
4926
4927 \end_inset 
4928
4929  segment.
4930  The value entered can be in Hexadecimal or Decimal format, eg.
4931  -
4932 \begin_inset ERT
4933 status Collapsed
4934
4935 \layout Standard
4936
4937 \backslash 
4938 /
4939 \end_inset 
4940
4941 -data-loc 0x20 or -
4942 \begin_inset ERT
4943 status Collapsed
4944
4945 \layout Standard
4946
4947 \backslash 
4948 /
4949 \end_inset 
4950
4951 -data-loc 32.
4952  (By default, the start location of the internal ram data segment  is set
4953  as low as possible in memory, taking into account the used register banks
4954  and the bit segment at address 0x20.
4955  For example if register banks 0 and 1 are used without bit variables, the
4956  data segment will be set, if -
4957 \begin_inset ERT
4958 status Collapsed
4959
4960 \layout Standard
4961
4962 \backslash 
4963 /
4964 \end_inset 
4965
4966 -data-loc is not used, to location 0x10.)
4967 \layout List
4968 \labelwidthstring 00.00.0000
4969
4970
4971 \series bold 
4972 -
4973 \begin_inset ERT
4974 status Collapsed
4975
4976 \layout Standard
4977
4978 \backslash 
4979 /
4980 \end_inset 
4981
4982 -idata-loc
4983 \series default 
4984
4985 \begin_inset LatexCommand \index{-\/-idata-loc}
4986
4987 \end_inset 
4988
4989 <Value> The start location of the indirectly addressable internal ram
4990 \begin_inset LatexCommand \index{idata}
4991
4992 \end_inset 
4993
4994 , default value is 0x80.
4995  The value entered can be in Hexadecimal or Decimal format, eg.
4996  -
4997 \begin_inset ERT
4998 status Collapsed
4999
5000 \layout Standard
5001
5002 \backslash 
5003 /
5004 \end_inset 
5005
5006 -idata-loc 0x88 or -
5007 \begin_inset ERT
5008 status Collapsed
5009
5010 \layout Standard
5011
5012 \backslash 
5013 /
5014 \end_inset 
5015
5016 -idata-loc 136.
5017 \layout List
5018 \labelwidthstring 00.00.0000
5019
5020
5021 \series bold 
5022 -
5023 \begin_inset ERT
5024 status Collapsed
5025
5026 \layout Standard
5027
5028 \backslash 
5029 /
5030 \end_inset 
5031
5032 -out-fmt-ihx
5033 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
5034
5035 \end_inset 
5036
5037
5038 \bar under 
5039  
5040 \series default 
5041 \bar default 
5042 The linker output (final object code) is in Intel Hex format.
5043 \begin_inset LatexCommand \index{Intel hex format}
5044
5045 \end_inset 
5046
5047  (This is the default option).
5048 \layout List
5049 \labelwidthstring 00.00.0000
5050
5051
5052 \series bold 
5053 -
5054 \begin_inset ERT
5055 status Collapsed
5056
5057 \layout Standard
5058
5059 \backslash 
5060 /
5061 \end_inset 
5062
5063 -out-fmt-s19
5064 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5065
5066 \end_inset 
5067
5068
5069 \bar under 
5070  
5071 \series default 
5072 \bar default 
5073 The linker output (final object code) is in Motorola S19 format
5074 \begin_inset LatexCommand \index{Motorola S19 format}
5075
5076 \end_inset 
5077
5078 .
5079 \layout Subsubsection
5080
5081 MCS51 Options
5082 \begin_inset LatexCommand \index{Options MCS51}
5083
5084 \end_inset 
5085
5086
5087 \begin_inset LatexCommand \index{MCS51 options}
5088
5089 \end_inset 
5090
5091
5092 \layout List
5093 \labelwidthstring 00.00.0000
5094
5095
5096 \series bold 
5097 -
5098 \begin_inset ERT
5099 status Collapsed
5100
5101 \layout Standard
5102
5103 \backslash 
5104 /
5105 \end_inset 
5106
5107 -model-small
5108 \begin_inset LatexCommand \index{-\/-model-small}
5109
5110 \end_inset 
5111
5112
5113 \series default 
5114 \size large 
5115 \emph on 
5116  
5117 \size default 
5118 \emph default 
5119 Generate code for Small Model programs see section Memory Models for more
5120  details.
5121  This is the default model.
5122 \layout List
5123 \labelwidthstring 00.00.0000
5124
5125
5126 \series bold 
5127 -
5128 \begin_inset ERT
5129 status Collapsed
5130
5131 \layout Standard
5132
5133 \backslash 
5134 /
5135 \end_inset 
5136
5137 -model-large
5138 \begin_inset LatexCommand \index{-\/-model-large}
5139
5140 \end_inset 
5141
5142
5143 \series default 
5144  Generate code for Large model programs see section Memory Models for more
5145  details.
5146  If this option is used all source files in the project should be compiled
5147  with this option.
5148 \layout List
5149 \labelwidthstring 00.00.0000
5150
5151
5152 \series bold 
5153 -
5154 \begin_inset ERT
5155 status Collapsed
5156
5157 \layout Standard
5158
5159 \backslash 
5160 /
5161 \end_inset 
5162
5163 -xstack
5164 \begin_inset LatexCommand \index{-\/-xstack}
5165
5166 \end_inset 
5167
5168
5169 \series default 
5170  Uses a pseudo stack in the first 256 bytes in the external ram for allocating
5171  variables and passing parameters.
5172  See section on external stack for more details.
5173 \layout List
5174 \labelwidthstring 00.00.0000
5175
5176
5177 \series bold 
5178 -
5179 \begin_inset ERT
5180 status Collapsed
5181
5182 \layout Standard
5183
5184 \backslash 
5185 /
5186 \end_inset 
5187
5188 -iram-size
5189 \series default 
5190 <Value>
5191 \begin_inset LatexCommand \index{-\/-iram-size<Value>}
5192
5193 \end_inset 
5194
5195  Causes the linker to check if the internal ram usage is within limits of
5196  the given value.
5197 \layout List
5198 \labelwidthstring 00.00.0000
5199
5200
5201 \series bold 
5202 -
5203 \begin_inset ERT
5204 status Collapsed
5205
5206 \layout Standard
5207
5208 \backslash 
5209 /
5210 \end_inset 
5211
5212 -xram-size
5213 \series default 
5214 <Value>
5215 \begin_inset LatexCommand \index{-\/-xram-size<Value>}
5216
5217 \end_inset 
5218
5219  Causes the linker to check if the external ram usage is within limits of
5220  the given value.
5221 \layout Subsubsection
5222
5223 DS390 Options
5224 \begin_inset LatexCommand \index{Options DS390}
5225
5226 \end_inset 
5227
5228
5229 \begin_inset LatexCommand \index{DS390 options}
5230
5231 \end_inset 
5232
5233
5234 \layout List
5235 \labelwidthstring 00.00.0000
5236
5237
5238 \series bold 
5239 -
5240 \begin_inset ERT
5241 status Collapsed
5242
5243 \layout Standard
5244
5245 \backslash 
5246 /
5247 \end_inset 
5248
5249 -model-flat24
5250 \series default 
5251
5252 \begin_inset LatexCommand \index{-\/-model-flat24}
5253
5254 \end_inset 
5255
5256
5257 \size large 
5258 \emph on 
5259  
5260 \size default 
5261 \emph default 
5262 Generate 24-bit flat mode code.
5263  This is the one and only that the ds390 code generator supports right now
5264  and is default when using 
5265 \emph on 
5266 -mds390
5267 \emph default 
5268 .
5269  See section Memory Models for more details.
5270 \layout List
5271 \labelwidthstring 00.00.0000
5272
5273
5274 \series bold 
5275 -
5276 \begin_inset ERT
5277 status Collapsed
5278
5279 \layout Standard
5280
5281 \backslash 
5282 /
5283 \end_inset 
5284
5285 -stack-10bit
5286 \series default 
5287
5288 \begin_inset LatexCommand \index{-\/-stack-10bit}
5289
5290 \end_inset 
5291
5292  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
5293  This is the one and only that the ds390 code generator supports right now
5294  and is default when using 
5295 \emph on 
5296 -mds390
5297 \emph default 
5298 .
5299  In this mode, the stack is located in the lower 1K of the internal RAM,
5300  which is mapped to 0x400000.
5301  Note that the support is incomplete, since it still uses a single byte
5302  as the stack pointer.
5303  This means that only the lower 256 bytes of the potential 1K stack space
5304  will actually be used.
5305  However, this does allow you to reclaim the precious 256 bytes of low RAM
5306  for use for the DATA and IDATA segments.
5307  The compiler will not generate any code to put the processor into 10 bit
5308  stack mode.
5309  It is important to ensure that the processor is in this mode before calling
5310  any re-entrant functions compiled with this option.
5311  In principle, this should work with the 
5312 \emph on 
5313 -
5314 \begin_inset ERT
5315 status Collapsed
5316
5317 \layout Standard
5318
5319 \backslash 
5320 /
5321 \end_inset 
5322
5323 -stack-auto
5324 \begin_inset LatexCommand \index{-\/-stack-auto}
5325
5326 \end_inset 
5327
5328
5329 \emph default 
5330  option, but that has not been tested.
5331  It is incompatible with the 
5332 \emph on 
5333 -
5334 \begin_inset ERT
5335 status Collapsed
5336
5337 \layout Standard
5338
5339 \backslash 
5340 /
5341 \end_inset 
5342
5343 -xstack
5344 \begin_inset LatexCommand \index{-\/-xstack}
5345
5346 \end_inset 
5347
5348
5349 \emph default 
5350  option.
5351  It also only makes sense if the processor is in 24 bit contiguous addressing
5352  mode (see the 
5353 \emph on 
5354 -
5355 \begin_inset ERT
5356 status Collapsed
5357
5358 \layout Standard
5359
5360 \backslash 
5361 /
5362 \end_inset 
5363
5364 -model-flat24 option
5365 \emph default 
5366 ).
5367 \layout Subsubsection
5368
5369 Z80 Options
5370 \begin_inset LatexCommand \index{Options Z80}
5371
5372 \end_inset 
5373
5374
5375 \begin_inset LatexCommand \index{Z80 options}
5376
5377 \end_inset 
5378
5379
5380 \layout List
5381 \labelwidthstring 00.00.0000
5382
5383
5384 \series bold 
5385 -
5386 \begin_inset ERT
5387 status Collapsed
5388
5389 \layout Standard
5390
5391 \backslash 
5392 /
5393 \end_inset 
5394
5395 -callee-saves-bc
5396 \series default 
5397
5398 \begin_inset LatexCommand \index{-\/-callee-saves-bc}
5399
5400 \end_inset 
5401
5402
5403 \size large 
5404 \emph on 
5405  
5406 \size default 
5407 \emph default 
5408 Force a called function to always save BC.
5409 \layout List
5410 \labelwidthstring 00.00.0000
5411
5412
5413 \series bold 
5414 -
5415 \begin_inset ERT
5416 status Collapsed
5417
5418 \layout Standard
5419
5420 \backslash 
5421 /
5422 \end_inset 
5423
5424 -no-std-crt0
5425 \series default 
5426
5427 \begin_inset LatexCommand \index{-\/-no-std-crt0}
5428
5429 \end_inset 
5430
5431  When linking, skip the standard crt0.o object file.
5432  You must provide your own crt0.o for your system when linking.
5433  
5434 \layout Subsubsection
5435
5436 Optimization Options
5437 \begin_inset LatexCommand \index{Options optimization}
5438
5439 \end_inset 
5440
5441
5442 \begin_inset LatexCommand \index{Optimization options}
5443
5444 \end_inset 
5445
5446
5447 \layout List
5448 \labelwidthstring 00.00.0000
5449
5450
5451 \series bold 
5452 -
5453 \begin_inset ERT
5454 status Collapsed
5455
5456 \layout Standard
5457
5458 \backslash 
5459 /
5460 \end_inset 
5461
5462 -nogcse
5463 \begin_inset LatexCommand \index{-\/-nogcse}
5464
5465 \end_inset 
5466
5467
5468 \series default 
5469  Will not do global subexpression elimination, this option may be used when
5470  the compiler creates undesirably large stack/data spaces to store compiler
5471  temporaries.
5472  A warning message will be generated when this happens and the compiler
5473  will indicate the number of extra bytes it allocated.
5474  It recommended that this option NOT be used, #pragma\SpecialChar ~
5475 NOGCSE
5476 \begin_inset LatexCommand \index{\#pragma NOGCSE}
5477
5478 \end_inset 
5479
5480  can be used to turn off global subexpression elimination
5481 \begin_inset LatexCommand \index{Subexpression elimination}
5482
5483 \end_inset 
5484
5485  for a given function only.
5486 \layout List
5487 \labelwidthstring 00.00.0000
5488
5489
5490 \series bold 
5491 -
5492 \begin_inset ERT
5493 status Collapsed
5494
5495 \layout Standard
5496
5497 \backslash 
5498 /
5499 \end_inset 
5500
5501 -noinvariant
5502 \begin_inset LatexCommand \index{-\/-noinvariant}
5503
5504 \end_inset 
5505
5506
5507 \series default 
5508  Will not do loop invariant optimizations, this may be turned off for reasons
5509  explained for the previous option.
5510  For more details of loop optimizations performed see section Loop Invariants.It
5511  recommended that this option NOT be used, #pragma\SpecialChar ~
5512 NOINVARIANT
5513 \begin_inset LatexCommand \index{\#pragma NOINVARIANT}
5514
5515 \end_inset 
5516
5517  can be used to turn off invariant optimizations for a given function only.
5518 \layout List
5519 \labelwidthstring 00.00.0000
5520
5521
5522 \series bold 
5523 -
5524 \begin_inset ERT
5525 status Collapsed
5526
5527 \layout Standard
5528
5529 \backslash 
5530 /
5531 \end_inset 
5532
5533 -noinduction
5534 \begin_inset LatexCommand \index{-\/-noinduction}
5535
5536 \end_inset 
5537
5538
5539 \series default 
5540  Will not do loop induction optimizations, see section strength reduction
5541  for more details.It is recommended that this option is NOT used, #pragma\SpecialChar ~
5542 NOINDUCT
5543 ION
5544 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
5545
5546 \end_inset 
5547
5548  can be used to turn off induction optimizations for a given function only.
5549 \layout List
5550 \labelwidthstring 00.00.0000
5551
5552
5553 \series bold 
5554 -
5555 \begin_inset ERT
5556 status Collapsed
5557
5558 \layout Standard
5559
5560 \backslash 
5561 /
5562 \end_inset 
5563
5564 -nojtbound
5565 \begin_inset LatexCommand \index{-\/-nojtbound}
5566
5567 \end_inset 
5568
5569
5570 \size large 
5571 \bar under 
5572  
5573 \series default 
5574 \size default 
5575 \bar default 
5576  Will not generate boundary condition check when switch statements
5577 \begin_inset LatexCommand \index{switch statement}
5578
5579 \end_inset 
5580
5581  are implemented using jump-tables.
5582  See section Switch Statements for more details.
5583  It is recommended that this option is NOT used, #pragma\SpecialChar ~
5584 NOJTBOUND
5585 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
5586
5587 \end_inset 
5588
5589  can be used to turn off boundary checking for jump tables for a given function
5590  only.
5591 \layout List
5592 \labelwidthstring 00.00.0000
5593
5594
5595 \series bold 
5596 -
5597 \begin_inset ERT
5598 status Collapsed
5599
5600 \layout Standard
5601
5602 \backslash 
5603 /
5604 \end_inset 
5605
5606 -noloopreverse
5607 \begin_inset LatexCommand \index{-\/-noloopreverse}
5608
5609 \end_inset 
5610
5611
5612 \series default 
5613 \size large 
5614  
5615 \size default 
5616 Will not do loop reversal 
5617 \begin_inset LatexCommand \index{Loop reversing}
5618
5619 \end_inset 
5620
5621 optimization.
5622 \layout List
5623 \labelwidthstring 00.00.0000
5624
5625 -
5626 \begin_inset ERT
5627 status Collapsed
5628
5629 \layout Standard
5630
5631 \backslash 
5632 /
5633 \end_inset 
5634
5635 -
5636 \series bold 
5637 nolabelopt
5638 \series default 
5639  
5640 \begin_inset LatexCommand \index{-\/-nolabelopt }
5641
5642 \end_inset 
5643
5644 Will not optimize labels (makes the dumpfiles more readable).
5645 \layout List
5646 \labelwidthstring 00.00.0000
5647
5648
5649 \series bold 
5650 -
5651 \begin_inset ERT
5652 status Collapsed
5653
5654 \layout Standard
5655
5656 \backslash 
5657 /
5658 \end_inset 
5659
5660 -no-xinit-opt
5661 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
5662
5663 \end_inset 
5664
5665
5666 \series default 
5667  Will not memcpy initialized data from code space into xdata space.
5668  This saves a few bytes in code space if you don't have initialized data.
5669 \layout Subsubsection
5670
5671 Other Options
5672 \begin_inset LatexCommand \index{Options other}
5673
5674 \end_inset 
5675
5676
5677 \layout List
5678 \labelwidthstring 00.00.0000
5679
5680
5681 \series bold 
5682 -c\SpecialChar ~
5683 -
5684 \begin_inset ERT
5685 status Collapsed
5686
5687 \layout Standard
5688
5689 \backslash 
5690 /
5691 \end_inset 
5692
5693 -compile-only
5694 \begin_inset LatexCommand \index{-\/-compile-only}
5695
5696 \end_inset 
5697
5698
5699 \begin_inset LatexCommand \index{-c -\/-compile-only}
5700
5701 \end_inset 
5702
5703
5704 \series default 
5705  will compile and assemble the source, but will not call the linkage editor.
5706 \layout List
5707 \labelwidthstring 00.00.0000
5708
5709
5710 \series bold 
5711 -
5712 \series default 
5713
5714 \begin_inset ERT
5715 status Collapsed
5716
5717 \layout Standard
5718
5719 \backslash 
5720 /
5721 \end_inset 
5722
5723
5724 \series bold 
5725 -c1mode
5726 \begin_inset LatexCommand \index{-\/-c1mode}
5727
5728 \end_inset 
5729
5730
5731 \series default 
5732  reads the preprocessed source from standard input and compiles it.
5733  The file name for the assembler output must be specified using the -o option.
5734 \layout List
5735 \labelwidthstring 00.00.0000
5736
5737
5738 \series bold 
5739 -E
5740 \begin_inset LatexCommand \index{-E}
5741
5742 \end_inset 
5743
5744
5745 \series default 
5746  Run only the C preprocessor.
5747  Preprocess all the C source files specified and output the results to standard
5748  output.
5749 \layout List
5750 \labelwidthstring 00.00.0000
5751
5752
5753 \series bold 
5754 -o\SpecialChar ~
5755 <path/file>
5756 \begin_inset LatexCommand \index{-o <path/file>}
5757
5758 \end_inset 
5759
5760  
5761 \series default 
5762 The output path resp.
5763  file where everything will be placed.
5764  If the parameter is a path, it must have a trailing slash (or backslash
5765  for the Windows binaries) to be recognized as a path.
5766  
5767 \layout List
5768 \labelwidthstring 00.00.0000
5769
5770
5771 \series bold 
5772 -
5773 \begin_inset ERT
5774 status Collapsed
5775
5776 \layout Standard
5777
5778 \backslash 
5779 /
5780 \end_inset 
5781
5782 -stack-auto
5783 \begin_inset LatexCommand \index{-\/-stack-auto}
5784
5785 \end_inset 
5786
5787
5788 \series default 
5789 \size large 
5790 \emph on 
5791  
5792 \size default 
5793 \emph default 
5794 All functions in the source file will be compiled as 
5795 \emph on 
5796 reentrant
5797 \emph default 
5798
5799 \begin_inset LatexCommand \index{reentrant}
5800
5801 \end_inset 
5802
5803 , i.e.
5804  the parameters and local variables will be allocated on the stack
5805 \begin_inset LatexCommand \index{stack}
5806
5807 \end_inset 
5808
5809 .
5810  see section Parameters and Local Variables for more details.
5811  If this option is used all source files in the project should be compiled
5812  with this option.
5813  
5814 \layout List
5815 \labelwidthstring 00.00.0000
5816
5817
5818 \series bold 
5819 -
5820 \begin_inset ERT
5821 status Collapsed
5822
5823 \layout Standard
5824
5825 \backslash 
5826 /
5827 \end_inset 
5828
5829 -callee-saves
5830 \begin_inset LatexCommand \index{-\/-callee-saves}
5831
5832 \end_inset 
5833
5834  function1[,function2][,function3]....
5835
5836 \series default 
5837  The compiler by default uses a caller saves convention for register saving
5838  across function calls, however this can cause unnecessary register pushing
5839  & popping when calling small functions from larger functions.
5840  This option can be used to switch the register saving convention for the
5841  function names specified.
5842  The compiler will not save registers when calling these functions, no extra
5843  code will be generated at the entry & exit (function prologue
5844 \series bold 
5845
5846 \begin_inset LatexCommand \index{function prologue}
5847
5848 \end_inset 
5849
5850
5851 \series default 
5852  & epilogue
5853 \series bold 
5854
5855 \begin_inset LatexCommand \index{function epilogue}
5856
5857 \end_inset 
5858
5859
5860 \series default 
5861 ) for these functions to save & restore the registers used by these functions,
5862  this can SUBSTANTIALLY reduce code & improve run time performance of the
5863  generated code.
5864  In the future the compiler (with inter procedural analysis) will be able
5865  to determine the appropriate scheme to use for each function call.
5866  DO NOT use this option for built-in functions such as _mulint..., if this
5867  option is used for a library function the appropriate library function
5868  needs to be recompiled with the same option.
5869  If the project consists of multiple source files then all the source file
5870  should be compiled with the same -
5871 \begin_inset ERT
5872 status Collapsed
5873
5874 \layout Standard
5875
5876 \backslash 
5877 /
5878 \end_inset 
5879
5880 -callee-saves option string.
5881  Also see #pragma\SpecialChar ~
5882 CALLEE-SAVES
5883 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
5884
5885 \end_inset 
5886
5887 .
5888 \layout List
5889 \labelwidthstring 00.00.0000
5890
5891
5892 \series bold 
5893 -
5894 \begin_inset ERT
5895 status Collapsed
5896
5897 \layout Standard
5898
5899 \backslash 
5900 /
5901 \end_inset 
5902
5903 -debug
5904 \begin_inset LatexCommand \index{-\/-debug}
5905
5906 \end_inset 
5907
5908
5909 \bar under 
5910  
5911 \series default 
5912 \bar default 
5913 When this option is used the compiler will generate debug information, that
5914  can be used with the SDCDB.
5915  The debug information is collected in a file with .cdb extension.
5916  For more information see documentation for SDCDB.
5917 \layout List
5918 \labelwidthstring 00.00.0000
5919
5920
5921 \series bold 
5922 -S
5923 \begin_inset LatexCommand \index{-S}
5924
5925 \end_inset 
5926
5927
5928 \size large 
5929 \bar under 
5930  
5931 \series default 
5932 \size default 
5933 \bar default 
5934 Stop after the stage of compilation proper; do not assemble.
5935  The output is an assembler code file for the input file specified.
5936 \layout List
5937 \labelwidthstring 00.00.0000
5938
5939
5940 \series bold 
5941 -Wa_asmOption[,asmOption]
5942 \series default 
5943
5944 \begin_inset LatexCommand \index{-Wa\_asmOption[,asmOption]}
5945
5946 \end_inset 
5947
5948 ...
5949  Pass the asmOption to the assembler.
5950 \layout List
5951 \labelwidthstring 00.00.0000
5952
5953
5954 \series bold 
5955 -Wl_linkOption[,linkOption]
5956 \series default 
5957
5958 \begin_inset LatexCommand \index{-Wl\_linkOption[,linkOption]}
5959
5960 \end_inset 
5961
5962 ...
5963  Pass the linkOption to the linker.
5964 \layout List
5965 \labelwidthstring 00.00.0000
5966
5967
5968 \series bold 
5969 -
5970 \begin_inset ERT
5971 status Collapsed
5972
5973 \layout Standard
5974
5975 \backslash 
5976 /
5977 \end_inset 
5978
5979 -int-long-reent
5980 \begin_inset LatexCommand \index{-\/-int-long-reent}
5981
5982 \end_inset 
5983
5984
5985 \series default 
5986  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
5987  Note by default these libraries are compiled as non-reentrant.
5988  See section Installation for more details.
5989 \layout List
5990 \labelwidthstring 00.00.0000
5991
5992
5993 \series bold 
5994 -
5995 \begin_inset ERT
5996 status Collapsed
5997
5998 \layout Standard
5999
6000 \backslash 
6001 /
6002 \end_inset 
6003
6004 -cyclomatic
6005 \begin_inset LatexCommand \index{-\/-cyclomatic}
6006
6007 \end_inset 
6008
6009
6010 \bar under 
6011  
6012 \series default 
6013 \bar default 
6014 This option will cause the compiler to generate an information message for
6015  each function in the source file.
6016  The message contains some 
6017 \emph on 
6018 important
6019 \emph default 
6020  information about the function.
6021  The number of edges and nodes the compiler detected in the control flow
6022  graph of the function, and most importantly the 
6023 \emph on 
6024 cyclomatic complexity
6025 \begin_inset LatexCommand \index{Cyclomatic complexity}
6026
6027 \end_inset 
6028
6029
6030 \emph default 
6031  see section on Cyclomatic Complexity for more details.
6032 \layout List
6033 \labelwidthstring 00.00.0000
6034
6035
6036 \series bold 
6037 -
6038 \begin_inset ERT
6039 status Collapsed
6040
6041 \layout Standard
6042
6043 \backslash 
6044 /
6045 \end_inset 
6046
6047 -float-reent
6048 \begin_inset LatexCommand \index{-\/-float-reent}
6049
6050 \end_inset 
6051
6052
6053 \bar under 
6054  
6055 \series default 
6056 \bar default 
6057  Floating point library is compiled as reentrant
6058 \begin_inset LatexCommand \index{reentrant}
6059
6060 \end_inset 
6061
6062 .See section Installation for more details.
6063 \layout List
6064 \labelwidthstring 00.00.0000
6065
6066
6067 \series bold 
6068 -
6069 \begin_inset ERT
6070 status Collapsed
6071
6072 \layout Standard
6073
6074 \backslash 
6075 /
6076 \end_inset 
6077
6078 -nooverlay
6079 \begin_inset LatexCommand \index{-\/-nooverlay}
6080
6081 \end_inset 
6082
6083
6084 \series default 
6085   The compiler will not overlay parameters and local variables of any function,
6086  see section Parameters and local variables for more details.
6087 \layout List
6088 \labelwidthstring 00.00.0000
6089
6090
6091 \series bold 
6092 -
6093 \begin_inset ERT
6094 status Collapsed
6095
6096 \layout Standard
6097
6098 \backslash 
6099 /
6100 \end_inset 
6101
6102 -main-return
6103 \begin_inset LatexCommand \index{-\/-main-return}
6104
6105 \end_inset 
6106
6107
6108 \series default 
6109  This option can be used when the code generated is called by a monitor
6110  program.
6111  The compiler will generate a 'ret' upon return from the 'main'
6112 \begin_inset LatexCommand \index{main return}
6113
6114 \end_inset 
6115
6116  function.
6117  The default option is to lock up i.e.
6118  generate a 'ljmp '.
6119 \layout List
6120 \labelwidthstring 00.00.0000
6121
6122
6123 \series bold 
6124 -
6125 \begin_inset ERT
6126 status Collapsed
6127
6128 \layout Standard
6129
6130 \backslash 
6131 /
6132 \end_inset 
6133
6134 -peep-file
6135 \series default 
6136
6137 \begin_inset LatexCommand \index{-\/-peep-file}
6138
6139 \end_inset 
6140
6141 <filename> This option can be used to use additional rules to be used by
6142  the peep hole optimizer.
6143  See section Peep Hole optimizations for details on how to write these rules.
6144 \layout List
6145 \labelwidthstring 00.00.0000
6146
6147
6148 \series bold 
6149 -
6150 \begin_inset ERT
6151 status Collapsed
6152
6153 \layout Standard
6154
6155 \backslash 
6156 /
6157 \end_inset 
6158
6159 -no-peep
6160 \begin_inset LatexCommand \index{-\/-no-peep}
6161
6162 \end_inset 
6163
6164
6165 \series default 
6166   Disable peep-hole optimization.
6167 \layout List
6168 \labelwidthstring 00.00.0000
6169
6170
6171 \series bold 
6172 -
6173 \begin_inset ERT
6174 status Collapsed
6175
6176 \layout Standard
6177
6178 \backslash 
6179 /
6180 \end_inset 
6181
6182 -peep-asm
6183 \begin_inset LatexCommand \index{-\/-peep-asm}
6184
6185 \end_inset 
6186
6187
6188 \series default 
6189   Pass the inline assembler code through the peep hole optimizer.
6190  This can cause unexpected changes to inline assembler code, please go through
6191  the peephole optimizer
6192 \begin_inset LatexCommand \index{Peephole optimizer}
6193
6194 \end_inset 
6195
6196  rules defined in the source file tree '<target>/peeph.def' before using
6197  this option.
6198 \layout List
6199 \labelwidthstring 00.00.0000
6200
6201
6202 \series bold 
6203 -
6204 \begin_inset ERT
6205 status Collapsed
6206
6207 \layout Standard
6208
6209 \backslash 
6210 /
6211 \end_inset 
6212
6213 -code-size
6214 \series default 
6215 <Value>
6216 \begin_inset LatexCommand \index{-\/-code-size<Value>}
6217
6218 \end_inset 
6219
6220  Causes the linker to check if the code usage is within limits of the given
6221  value.
6222 \layout List
6223 \labelwidthstring 00.00.0000
6224
6225
6226 \series bold 
6227 -
6228 \begin_inset ERT
6229 status Collapsed
6230
6231 \layout Standard
6232
6233 \backslash 
6234 /
6235 \end_inset 
6236
6237 -nostdincl
6238 \begin_inset LatexCommand \index{-\/-nostdincl}
6239
6240 \end_inset 
6241
6242
6243 \series default 
6244  This will prevent the compiler from passing on the default include path
6245  to the preprocessor.
6246 \layout List
6247 \labelwidthstring 00.00.0000
6248
6249
6250 \series bold 
6251 -
6252 \begin_inset ERT
6253 status Collapsed
6254
6255 \layout Standard
6256
6257 \backslash 
6258 /
6259 \end_inset 
6260
6261 -nostdlib
6262 \begin_inset LatexCommand \index{-\/-nostdlib}
6263
6264 \end_inset 
6265
6266
6267 \series default 
6268  This will prevent the compiler from passing on the default library
6269 \begin_inset LatexCommand \index{Libraries}
6270
6271 \end_inset 
6272
6273  path to the linker.
6274 \layout List
6275 \labelwidthstring 00.00.0000
6276
6277
6278 \series bold 
6279 -
6280 \begin_inset ERT
6281 status Collapsed
6282
6283 \layout Standard
6284
6285 \backslash 
6286 /
6287 \end_inset 
6288
6289 -verbose
6290 \begin_inset LatexCommand \index{-\/-verbose}
6291
6292 \end_inset 
6293
6294
6295 \series default 
6296  Shows the various actions the compiler is performing.
6297 \layout List
6298 \labelwidthstring 00.00.0000
6299
6300
6301 \series bold 
6302 -V
6303 \begin_inset LatexCommand \index{-V}
6304
6305 \end_inset 
6306
6307
6308 \series default 
6309  Shows the actual commands the compiler is executing.
6310 \layout List
6311 \labelwidthstring 00.00.0000
6312
6313
6314 \series bold 
6315 -
6316 \begin_inset ERT
6317 status Collapsed
6318
6319 \layout Standard
6320
6321 \backslash 
6322 /
6323 \end_inset 
6324
6325 -no-c-code-in-asm
6326 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
6327
6328 \end_inset 
6329
6330
6331 \series default 
6332  Hides your ugly and inefficient c-code from the asm file, so you can always
6333  blame the compiler :).
6334 \layout List
6335 \labelwidthstring 00.00.0000
6336
6337
6338 \series bold 
6339 -
6340 \begin_inset ERT
6341 status Collapsed
6342
6343 \layout Standard
6344
6345 \backslash 
6346 /
6347 \end_inset 
6348
6349 -i-code-in-asm
6350 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
6351
6352 \end_inset 
6353
6354
6355 \series default 
6356  Include i-codes in the asm file.
6357  Sounds like noise but is most helpful for debugging the compiler itself.
6358 \layout List
6359 \labelwidthstring 00.00.0000
6360
6361
6362 \series bold 
6363 -
6364 \begin_inset ERT
6365 status Collapsed
6366
6367 \layout Standard
6368
6369 \backslash 
6370 /
6371 \end_inset 
6372
6373 -less-pedantic
6374 \begin_inset LatexCommand \index{-\/-less-pedantic}
6375
6376 \end_inset 
6377
6378
6379 \series default 
6380  Disable some of the more pedantic warnings (jwk burps: please be more specific
6381  here, please!)
6382 \layout List
6383 \labelwidthstring 00.00.0000
6384
6385
6386 \series bold 
6387 -
6388 \begin_inset ERT
6389 status Collapsed
6390
6391 \layout Standard
6392
6393 \backslash 
6394 /
6395 \end_inset 
6396
6397 -print-search-dirs
6398 \begin_inset LatexCommand \index{-\/-print-search-dirs}
6399
6400 \end_inset 
6401
6402
6403 \series default 
6404  Display the directories in the compiler's search path
6405 \layout List
6406 \labelwidthstring 00.00.0000
6407
6408
6409 \series bold 
6410 -
6411 \begin_inset ERT
6412 status Collapsed
6413
6414 \layout Standard
6415
6416 \backslash 
6417 /
6418 \end_inset 
6419
6420 -vc
6421 \begin_inset LatexCommand \index{-\/-vc}
6422
6423 \end_inset 
6424
6425
6426 \series default 
6427  Display errors and warnings using MSVC style, so you can use SDCC with
6428  visual studio
6429 \layout List
6430 \labelwidthstring 00.00.0000
6431
6432
6433 \series bold 
6434 -
6435 \begin_inset ERT
6436 status Collapsed
6437
6438 \layout Standard
6439
6440 \backslash 
6441 /
6442 \end_inset 
6443
6444 -use-stderr
6445 \begin_inset LatexCommand \index{-\/-use-stdout}
6446
6447 \end_inset 
6448
6449
6450 \series default 
6451  Send errors and warnings to stdout instead of stderr
6452 \layout Subsubsection
6453
6454 Intermediate Dump Options
6455 \begin_inset LatexCommand \index{Options intermediate dump}
6456
6457 \end_inset 
6458
6459
6460 \begin_inset LatexCommand \index{Intermediate dump options}
6461
6462 \end_inset 
6463
6464
6465 \layout Standard
6466
6467 The following options are provided for the purpose of retargetting and debugging
6468  the compiler.
6469  These provided a means to dump the intermediate code (iCode
6470 \begin_inset LatexCommand \index{iCode}
6471
6472 \end_inset 
6473
6474 ) generated by the compiler in human readable form at various stages of
6475  the compilation process.
6476  
6477 \layout List
6478 \labelwidthstring 00.00.0000
6479
6480
6481 \series bold 
6482 -
6483 \begin_inset ERT
6484 status Collapsed
6485
6486 \layout Standard
6487
6488 \backslash 
6489 /
6490 \end_inset 
6491
6492 -dumpraw
6493 \begin_inset LatexCommand \index{-\/-dumpraw}
6494
6495 \end_inset 
6496
6497
6498 \series default 
6499  This option will cause the compiler to dump the intermediate code into
6500  a file of named 
6501 \emph on 
6502 <source filename>.dumpraw
6503 \emph default 
6504  just after the intermediate code has been generated for a function, i.e.
6505  before any optimizations are done.
6506  The basic blocks
6507 \begin_inset LatexCommand \index{Basic blocks}
6508
6509 \end_inset 
6510
6511  at this stage ordered in the depth first number, so they may not be in
6512  sequence of execution.
6513 \layout List
6514 \labelwidthstring 00.00.0000
6515
6516
6517 \series bold 
6518 -
6519 \begin_inset ERT
6520 status Collapsed
6521
6522 \layout Standard
6523
6524 \backslash 
6525 /
6526 \end_inset 
6527
6528 -dumpgcse
6529 \begin_inset LatexCommand \index{-\/-dumpgcse}
6530
6531 \end_inset 
6532
6533
6534 \series default 
6535  Will create a dump of iCode's, after global subexpression elimination
6536 \begin_inset LatexCommand \index{Global subexpression elimination}
6537
6538 \end_inset 
6539
6540 , into a file named 
6541 \emph on 
6542 <source filename>.dumpgcse.
6543 \layout List
6544 \labelwidthstring 00.00.0000
6545
6546
6547 \series bold 
6548 -
6549 \begin_inset ERT
6550 status Collapsed
6551
6552 \layout Standard
6553
6554 \backslash 
6555 /
6556 \end_inset 
6557
6558 -dumpdeadcode
6559 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
6560
6561 \end_inset 
6562
6563
6564 \series default 
6565  Will create a dump of iCode's, after deadcode elimination
6566 \begin_inset LatexCommand \index{Dead-code elimination}
6567
6568 \end_inset 
6569
6570 , into a file named 
6571 \emph on 
6572 <source filename>.dumpdeadcode.
6573 \layout List
6574 \labelwidthstring 00.00.0000
6575
6576
6577 \series bold 
6578 -
6579 \begin_inset ERT
6580 status Collapsed
6581
6582 \layout Standard
6583
6584 \backslash 
6585 /
6586 \end_inset 
6587
6588 -dumploop
6589 \begin_inset LatexCommand \index{-\/-dumploop}
6590
6591 \end_inset 
6592
6593
6594 \series default 
6595 \size large 
6596  
6597 \size default 
6598 Will create a dump of iCode's, after loop optimizations
6599 \begin_inset LatexCommand \index{Loop optimization}
6600
6601 \end_inset 
6602
6603 , into a file named 
6604 \emph on 
6605 <source filename>.dumploop.
6606 \layout List
6607 \labelwidthstring 00.00.0000
6608
6609
6610 \series bold 
6611 -
6612 \begin_inset ERT
6613 status Collapsed
6614
6615 \layout Standard
6616
6617 \backslash 
6618 /
6619 \end_inset 
6620
6621 -dumprange
6622 \begin_inset LatexCommand \index{-\/-dumprange}
6623
6624 \end_inset 
6625
6626
6627 \series default 
6628 \size large 
6629  
6630 \size default 
6631 Will create a dump of iCode's, after live range analysis
6632 \begin_inset LatexCommand \index{Live range analysis}
6633
6634 \end_inset 
6635
6636 , into a file named 
6637 \emph on 
6638 <source filename>.dumprange.
6639 \layout List
6640 \labelwidthstring 00.00.0000
6641
6642
6643 \series bold 
6644 -
6645 \begin_inset ERT
6646 status Collapsed
6647
6648 \layout Standard
6649
6650 \backslash 
6651 /
6652 \end_inset 
6653
6654 -dumlrange
6655 \begin_inset LatexCommand \index{-\/-dumlrange}
6656
6657 \end_inset 
6658
6659
6660 \series default 
6661  Will dump the life ranges
6662 \begin_inset LatexCommand \index{Live range analysis}
6663
6664 \end_inset 
6665
6666  for all symbols.
6667 \layout List
6668 \labelwidthstring 00.00.0000
6669
6670
6671 \series bold 
6672 -
6673 \begin_inset ERT
6674 status Collapsed
6675
6676 \layout Standard
6677
6678 \backslash 
6679 /
6680 \end_inset 
6681
6682 -dumpregassign
6683 \begin_inset LatexCommand \index{-\/-dumpregassign}
6684
6685 \end_inset 
6686
6687
6688 \bar under 
6689  
6690 \series default 
6691 \bar default 
6692 Will create a dump of iCode's, after register assignment
6693 \begin_inset LatexCommand \index{Register assignment}
6694
6695 \end_inset 
6696
6697 , into a file named 
6698 \emph on 
6699 <source filename>.dumprassgn.
6700 \layout List
6701 \labelwidthstring 00.00.0000
6702
6703
6704 \series bold 
6705 -
6706 \begin_inset ERT
6707 status Collapsed
6708
6709 \layout Standard
6710
6711 \backslash 
6712 /
6713 \end_inset 
6714
6715 -dumplrange
6716 \begin_inset LatexCommand \index{-\/-dumplrange}
6717
6718 \end_inset 
6719
6720
6721 \series default 
6722  Will create a dump of the live ranges of iTemp's
6723 \layout List
6724 \labelwidthstring 00.00.0000
6725
6726
6727 \series bold 
6728 -
6729 \begin_inset ERT
6730 status Collapsed
6731
6732 \layout Standard
6733
6734 \backslash 
6735 /
6736 \end_inset 
6737
6738 -dumpall
6739 \begin_inset LatexCommand \index{-\/-dumpall}
6740
6741 \end_inset 
6742
6743
6744 \size large 
6745 \bar under 
6746  
6747 \series default 
6748 \size default 
6749 \bar default 
6750 Will cause all the above mentioned dumps to be created.
6751 \layout Subsection
6752
6753 Environment variables
6754 \begin_inset LatexCommand \index{Environment variables}
6755
6756 \end_inset 
6757
6758
6759 \layout Standard
6760
6761 SDCC recognizes the following environment variables:
6762 \layout List
6763 \labelwidthstring 00.00.0000
6764
6765
6766 \series bold 
6767 SDCC_LEAVE_SIGNALS
6768 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
6769
6770 \end_inset 
6771
6772
6773 \series default 
6774  SDCC installs a signal handler
6775 \begin_inset LatexCommand \index{signal handler}
6776
6777 \end_inset 
6778
6779  to be able to delete temporary files after an user break (^C) or an exception.
6780  If this environment variable is set, SDCC won't install the signal handler
6781  in order to be able to debug SDCC.
6782 \layout List
6783 \labelwidthstring 00.00.0000
6784
6785
6786 \series bold 
6787 TMP,\SpecialChar ~
6788 TEMP,\SpecialChar ~
6789 TMPDIR
6790 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
6791
6792 \end_inset 
6793
6794
6795 \series default 
6796  Path, where temporary files will be created.
6797  The order of the variables is the search order.
6798  In a standard *nix environment these variables are not set, and there's
6799  no need to set them.
6800  On Windows it's recommended to set one of them.
6801 \layout List
6802 \labelwidthstring 00.00.0000
6803
6804
6805 \series bold 
6806 SDCC_HOME
6807 \begin_inset LatexCommand \index{SDCC\_HOME}
6808
6809 \end_inset 
6810
6811
6812 \series default 
6813  Path, see 
6814 \begin_inset Quotes sld
6815 \end_inset 
6816
6817 2.3 Install and search paths
6818 \begin_inset Quotes srd
6819 \end_inset 
6820
6821 .
6822 \layout List
6823 \labelwidthstring 00.00.0000
6824
6825
6826 \series bold 
6827 SDCC_INCLUDE
6828 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
6829
6830 \end_inset 
6831
6832
6833 \series default 
6834  Path, see 
6835 \begin_inset Quotes sld
6836 \end_inset 
6837
6838 2.3 Install and search paths
6839 \begin_inset Quotes srd
6840 \end_inset 
6841
6842 .
6843 \layout List
6844 \labelwidthstring 00.00.0000
6845
6846
6847 \series bold 
6848 SDCC_LIB
6849 \begin_inset LatexCommand \index{SDCC\_LIB}
6850
6851 \end_inset 
6852
6853
6854 \series default 
6855  Path, see 
6856 \begin_inset Quotes sld
6857 \end_inset 
6858
6859 2.3 Install and search paths
6860 \begin_inset Quotes srd
6861 \end_inset 
6862
6863 .
6864 \layout Standard
6865
6866 There are some more environment variables recognized by SDCC, but these
6867  are solely used for debugging purposes.
6868  They can change or disappear very quickly, and will never be documented.
6869 \layout Subsection
6870
6871 MCS51/DS390 Storage Class
6872 \begin_inset LatexCommand \index{Storage class}
6873
6874 \end_inset 
6875
6876  Language Extensions
6877 \layout Standard
6878
6879 In addition to the ANSI storage classes SDCC allows the following MCS51
6880  specific storage classes.
6881 \layout Subsubsection
6882
6883 data
6884 \begin_inset LatexCommand \index{data}
6885
6886 \end_inset 
6887
6888
6889 \layout Standard
6890
6891 This is the 
6892 \series bold 
6893 default
6894 \series default 
6895  storage class for Small Memory model.
6896  Variables declared with this storage class will be allocated in the directly
6897  addressable portion of the internal RAM of a 8051, e.g.:
6898 \layout Verse
6899
6900
6901 \family typewriter 
6902 data unsigned char test_data;
6903 \layout Standard
6904
6905 Writing 0x01 to this variable generates the assembly code:
6906 \layout Verse
6907
6908
6909 \family typewriter 
6910 75*00 01\SpecialChar ~
6911 \SpecialChar ~
6912 \SpecialChar ~
6913 mov\SpecialChar ~
6914 \SpecialChar ~
6915 _test_data,#0x01 
6916 \layout Subsubsection
6917
6918 xdata
6919 \begin_inset LatexCommand \index{xdata}
6920
6921 \end_inset 
6922
6923
6924 \layout Standard
6925
6926 Variables declared with this storage class will be placed in the external
6927  RAM.
6928  This is the 
6929 \series bold 
6930 default
6931 \series default 
6932  storage class for Large Memory model, e.g.:
6933 \layout Verse
6934
6935
6936 \family typewriter 
6937 xdata unsigned char test_xdata;
6938 \layout Standard
6939
6940 Writing 0x01 to this variable generates the assembly code:
6941 \layout Verse
6942
6943
6944 \family typewriter 
6945 90s00r00\SpecialChar ~
6946 \SpecialChar ~
6947 \SpecialChar ~
6948 mov\SpecialChar ~
6949 \SpecialChar ~
6950 dptr,#_test_xdata 
6951 \newline 
6952 74\SpecialChar ~
6953 01\SpecialChar ~
6954 \SpecialChar ~
6955 \SpecialChar ~
6956 \SpecialChar ~
6957 \SpecialChar ~
6958 \SpecialChar ~
6959 mov\SpecialChar ~
6960 \SpecialChar ~
6961 a,#0x01 
6962 \newline 
6963 F0\SpecialChar ~
6964 \SpecialChar ~
6965 \SpecialChar ~
6966 \SpecialChar ~
6967 \SpecialChar ~
6968 \SpecialChar ~
6969 \SpecialChar ~
6970 \SpecialChar ~
6971 \SpecialChar ~
6972 movx\SpecialChar ~
6973 @dptr,a 
6974 \layout Subsubsection
6975
6976 idata
6977 \begin_inset LatexCommand \index{idata}
6978
6979 \end_inset 
6980
6981
6982 \layout Standard
6983
6984 Variables declared with this storage class will be allocated into the indirectly
6985  addressable portion of the internal ram of a 8051, e.g.:
6986 \layout Verse
6987
6988
6989 \family typewriter 
6990 idata unsigned char test_idata;
6991 \layout Standard
6992
6993 Writing 0x01 to this variable generates the assembly code:
6994 \layout Verse
6995
6996
6997 \family typewriter 
6998 78r00\SpecialChar ~
6999 \SpecialChar ~
7000 \SpecialChar ~
7001 \SpecialChar ~
7002 \SpecialChar ~
7003 \SpecialChar ~
7004 \SpecialChar ~
7005 mov\SpecialChar ~
7006 \SpecialChar ~
7007 r0,#_test_idata
7008 \newline 
7009 76\SpecialChar ~
7010 01\SpecialChar ~
7011 \SpecialChar ~
7012 \SpecialChar ~
7013 \SpecialChar ~
7014 \SpecialChar ~
7015 \SpecialChar ~
7016 \SpecialChar ~
7017 mov\SpecialChar ~
7018 \SpecialChar ~
7019 @r0,#0x01 
7020 \layout Subsubsection
7021
7022 pdata
7023 \begin_inset LatexCommand \index{pdata}
7024
7025 \end_inset 
7026
7027
7028 \layout Standard
7029
7030 Paged xdata access is currently not as straightforward as using the other
7031  addressing modes of a 8051.
7032  The following example writes 0x01 to the address pointed to.
7033  Please note, pdata access physically accesses xdata memory.
7034  The high byte of the address is determined by port P2 (or in case of some
7035  8051 variants by a separate Special Function Register).
7036 \layout Verse
7037
7038
7039 \family typewriter 
7040 pdata unsigned char *test_pdata_ptr;
7041 \newline 
7042
7043 \newline 
7044 void main() 
7045 \newline 
7046
7047 \newline 
7048 \SpecialChar ~
7049 \SpecialChar ~
7050 \SpecialChar ~
7051 \SpecialChar ~
7052 test_pdata_ptr = (pdata *)0xfe; 
7053 \newline 
7054 \SpecialChar ~
7055 \SpecialChar ~
7056 \SpecialChar ~
7057 \SpecialChar ~
7058 *test_pdata_ptr = 1; 
7059 \newline 
7060
7061 \layout Standard
7062
7063 Generates the assembly code:
7064 \layout Verse
7065
7066
7067 \family typewriter 
7068 75*01 FE\SpecialChar ~
7069 \SpecialChar ~
7070 \SpecialChar ~
7071 mov\SpecialChar ~
7072  _test_pdata_ptr,#0xFE
7073 \newline 
7074 78 FE\SpecialChar ~
7075 \SpecialChar ~
7076 \SpecialChar ~
7077 \SpecialChar ~
7078 \SpecialChar ~
7079 \SpecialChar ~
7080 mov\SpecialChar ~
7081  r0,#0xFE 
7082 \newline 
7083 74 01\SpecialChar ~
7084 \SpecialChar ~
7085 \SpecialChar ~
7086 \SpecialChar ~
7087 \SpecialChar ~
7088 \SpecialChar ~
7089 mov\SpecialChar ~
7090  a,#0x01
7091 \newline 
7092 F2\SpecialChar ~
7093 \SpecialChar ~
7094 \SpecialChar ~
7095 \SpecialChar ~
7096 \SpecialChar ~
7097 \SpecialChar ~
7098 \SpecialChar ~
7099 \SpecialChar ~
7100 \SpecialChar ~
7101 movx @r0,a 
7102 \layout Standard
7103
7104 Be extremely carefull if you use pdata together with the -
7105 \begin_inset ERT
7106 status Collapsed
7107
7108 \layout Standard
7109
7110 \backslash 
7111 /
7112 \end_inset 
7113
7114 -xstack
7115 \begin_inset LatexCommand \index{-\/-xstack}
7116
7117 \end_inset 
7118
7119  option.
7120 \layout Subsubsection
7121
7122 code
7123 \begin_inset LatexCommand \index{code}
7124
7125 \end_inset 
7126
7127
7128 \layout Standard
7129
7130 'Variables' declared with this storage class will be placed in the code
7131  memory:
7132 \layout Verse
7133
7134
7135 \family typewriter 
7136 code unsigned char test_code;
7137 \layout Standard
7138
7139 Read access to this variable generates the assembly code:
7140 \layout Verse
7141
7142
7143 \family typewriter 
7144 90s00r6F\SpecialChar ~
7145 \SpecialChar ~
7146 \SpecialChar ~
7147 mov dptr,#_test_code
7148 \newline 
7149 E4\SpecialChar ~
7150 \SpecialChar ~
7151 \SpecialChar ~
7152 \SpecialChar ~
7153 \SpecialChar ~
7154 \SpecialChar ~
7155 \SpecialChar ~
7156 \SpecialChar ~
7157 \SpecialChar ~
7158 clr a
7159 \newline 
7160 93\SpecialChar ~
7161 \SpecialChar ~
7162 \SpecialChar ~
7163 \SpecialChar ~
7164 \SpecialChar ~
7165 \SpecialChar ~
7166 \SpecialChar ~
7167 \SpecialChar ~
7168 \SpecialChar ~
7169 movc a,@a+dptr 
7170 \layout Subsubsection
7171
7172 bit
7173 \begin_inset LatexCommand \index{bit}
7174
7175 \end_inset 
7176
7177
7178 \layout Standard
7179
7180 This is a data-type and a storage class specifier.
7181  When a variable is declared as a bit, it is allocated into the bit addressable
7182  memory of 8051, e.g.:
7183 \layout Verse
7184
7185
7186 \family typewriter 
7187 bit test_bit;
7188 \layout Standard
7189
7190 Writing 1 to this variable generates the assembly code:
7191 \layout Verse
7192
7193
7194 \family typewriter 
7195 D2*00\SpecialChar ~
7196 \SpecialChar ~
7197 \SpecialChar ~
7198 \SpecialChar ~
7199 \SpecialChar ~
7200 \SpecialChar ~
7201 \SpecialChar ~
7202 setb\SpecialChar ~
7203 _test_bit
7204 \layout Subsubsection
7205
7206 sfr
7207 \begin_inset LatexCommand \index{sfr}
7208
7209 \end_inset 
7210
7211  / sbit
7212 \begin_inset LatexCommand \index{sbit}
7213
7214 \end_inset 
7215
7216
7217 \layout Standard
7218
7219 Like the bit keyword, 
7220 \emph on 
7221 sfr / sbit 
7222 \emph default 
7223 signifies both a data-type and storage class, they are used to describe
7224  the special function registers and special bit variables of a 8051, eg:
7225 \layout Verse
7226
7227
7228 \family typewriter 
7229 sfr at
7230 \begin_inset LatexCommand \index{at}
7231
7232 \end_inset 
7233
7234  0x80 P0;\SpecialChar ~
7235  /* special function register P0 at location 0x80 */
7236 \newline 
7237 sbit at 0xd7 CY; /* CY (Carry Flag
7238 \begin_inset LatexCommand \index{Flags}
7239
7240 \end_inset 
7241
7242
7243 \begin_inset LatexCommand \index{Carry flag}
7244
7245 \end_inset 
7246
7247 ) */
7248 \layout Subsection
7249
7250 Pointers
7251 \begin_inset LatexCommand \index{Pointers}
7252
7253 \end_inset 
7254
7255
7256 \layout Standard
7257
7258 SDCC allows (via language extensions) pointers to explicitly point to any
7259  of the memory spaces
7260 \begin_inset LatexCommand \index{Memory model}
7261
7262 \end_inset 
7263
7264  of the 8051.
7265  In addition to the explicit pointers, the compiler uses (by default) generic
7266  pointers which can be used to point to any of the memory spaces.
7267 \newline 
7268
7269 \newline 
7270 Pointer declaration examples:
7271 \layout Verse
7272
7273
7274 \family typewriter 
7275 /* pointer physically in xternal ram pointing to object in internal ram
7276  */ 
7277 \newline 
7278 data unsigned char * xdata p;
7279 \newline 
7280
7281 \newline 
7282 /* pointer physically in code rom pointing to data in xdata space */ 
7283 \newline 
7284 xdata unsigned char * code p;
7285 \newline 
7286
7287 \newline 
7288 /* pointer physically in code space pointing to data in code space */ 
7289 \newline 
7290 code unsigned char * code p;
7291 \newline 
7292
7293 \newline 
7294 /* the following is a generic pointer physically located in xdata space
7295  */
7296 \newline 
7297 char * xdata p;
7298 \layout Standard
7299
7300 Well you get the idea.
7301  
7302 \newline 
7303
7304 \newline 
7305 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
7306 \emph on 
7307 generic
7308 \emph default 
7309  pointers.
7310  
7311 \size small 
7312
7313 \newline 
7314
7315 \newline 
7316
7317 \size default 
7318 The highest order byte of the 
7319 \emph on 
7320 generic
7321 \emph default 
7322  pointers contains the data space information.
7323  Assembler support routines are called whenever data is stored or retrieved
7324  using 
7325 \emph on 
7326 generic
7327 \emph default 
7328  pointers.
7329  These are useful for developing reusable library
7330 \begin_inset LatexCommand \index{Libraries}
7331
7332 \end_inset 
7333
7334  routines.
7335  Explicitly specifying the pointer type will generate the most efficient
7336  code.
7337 \layout Subsection
7338
7339 Parameters
7340 \begin_inset LatexCommand \index{Parameters}
7341
7342 \end_inset 
7343
7344  & Local Variables
7345 \begin_inset LatexCommand \index{Local variable}
7346
7347 \end_inset 
7348
7349
7350 \layout Standard
7351
7352 Automatic (local) variables and parameters to functions can either be placed
7353  on the stack or in data-space.
7354  The default action of the compiler is to place these variables in the internal
7355  RAM (for small model) or external RAM (for large model).
7356  This in fact makes them 
7357 \emph on 
7358 static
7359 \begin_inset LatexCommand \index{static}
7360
7361 \end_inset 
7362
7363
7364 \emph default 
7365  so by default functions are non-reentrant
7366 \begin_inset LatexCommand \index{reentrant}
7367
7368 \end_inset 
7369
7370 .
7371 \newline 
7372
7373 \newline 
7374 They can be placed on the stack
7375 \begin_inset LatexCommand \index{stack}
7376
7377 \end_inset 
7378
7379  either by using the
7380 \emph on 
7381  -
7382 \begin_inset ERT
7383 status Collapsed
7384
7385 \layout Standard
7386
7387 \backslash 
7388 /
7389 \end_inset 
7390
7391 -stack-auto
7392 \begin_inset LatexCommand \index{-\/-stack-auto}
7393
7394 \end_inset 
7395
7396
7397 \emph default 
7398  option or by using the 
7399 \emph on 
7400 reentrant
7401 \begin_inset LatexCommand \index{reentrant}
7402
7403 \end_inset 
7404
7405
7406 \emph default 
7407  keyword in the function declaration, e.g.:
7408 \layout Verse
7409
7410
7411 \family typewriter 
7412 unsigned char foo(char i) reentrant 
7413 \newline 
7414
7415 \newline 
7416 \SpecialChar ~
7417 \SpecialChar ~
7418 \SpecialChar ~
7419 \SpecialChar ~
7420 ...
7421  
7422 \newline 
7423 }
7424 \layout Standard
7425
7426 Since stack space on 8051 is limited, the 
7427 \emph on 
7428 reentrant 
7429 \emph default 
7430 keyword or the
7431 \emph on 
7432  -
7433 \begin_inset ERT
7434 status Collapsed
7435
7436 \layout Standard
7437
7438 \backslash 
7439 /
7440 \end_inset 
7441
7442 -stack-auto
7443 \emph default 
7444  option should be used sparingly.
7445  Note that the reentrant keyword just means that the parameters & local
7446  variables will be allocated to the stack, it 
7447 \emph on 
7448 does not
7449 \emph default 
7450  mean that the function is register bank independent.
7451 \newline 
7452
7453 \newline 
7454 Local variables can be assigned storage classes and absolute
7455 \begin_inset LatexCommand \index{Absolute addressing}
7456
7457 \end_inset 
7458
7459  addresses, e.g.: 
7460 \layout Verse
7461
7462
7463 \family typewriter 
7464 unsigned char foo() 
7465 \newline 
7466 {
7467 \newline 
7468 \SpecialChar ~
7469 \SpecialChar ~
7470 \SpecialChar ~
7471 \SpecialChar ~
7472 xdata unsigned char i;
7473 \newline 
7474 \SpecialChar ~
7475 \SpecialChar ~
7476 \SpecialChar ~
7477 \SpecialChar ~
7478 bit bvar;
7479 \newline 
7480 \SpecialChar ~
7481 \SpecialChar ~
7482 \SpecialChar ~
7483 \SpecialChar ~
7484 data at 0x31 unsigned char j;
7485 \newline 
7486 \SpecialChar ~
7487 \SpecialChar ~
7488 \SpecialChar ~
7489 \SpecialChar ~
7490 ...
7491  
7492 \newline 
7493 }
7494 \layout Standard
7495
7496 In the above example the variable 
7497 \emph on 
7498 i
7499 \emph default 
7500  will be allocated in the external ram, 
7501 \emph on 
7502 bvar
7503 \emph default 
7504  in bit addressable space and
7505 \emph on 
7506  j
7507 \emph default 
7508  in internal ram.
7509  When compiled with 
7510 \emph on 
7511 -
7512 \begin_inset ERT
7513 status Collapsed
7514
7515 \layout Standard
7516
7517 \backslash 
7518 /
7519 \end_inset 
7520
7521 -stack-auto
7522 \emph default 
7523  or when a function is declared as 
7524 \emph on 
7525 reentrant
7526 \emph default 
7527  this should only be done for static variables.
7528 \layout Standard
7529
7530 Parameters however are not allowed any storage class, (storage classes for
7531  parameters will be ignored), their allocation is governed by the memory
7532  model in use, and the reentrancy options.
7533 \layout Subsection
7534
7535 Overlaying
7536 \begin_inset LatexCommand \label{sub:Overlaying}
7537
7538 \end_inset 
7539
7540
7541 \begin_inset LatexCommand \index{Overlaying}
7542
7543 \end_inset 
7544
7545
7546 \layout Standard
7547
7548 For non-reentrant
7549 \begin_inset LatexCommand \index{reentrant}
7550
7551 \end_inset 
7552
7553  functions SDCC will try to reduce internal ram space usage by overlaying
7554  parameters and local variables of a function (if possible).
7555  Parameters and local variables of a function will be allocated to an overlayabl
7556 e segment if the function has 
7557 \emph on 
7558 no other function calls and the function is non-reentrant and the memory
7559  model
7560 \begin_inset LatexCommand \index{Memory model}
7561
7562 \end_inset 
7563
7564  is small.
7565
7566 \emph default 
7567  If an explicit storage class
7568 \begin_inset LatexCommand \index{Storage class}
7569
7570 \end_inset 
7571
7572  is specified for a local variable, it will NOT be overlayed.
7573 \layout Standard
7574
7575 Note that the compiler (not the linkage editor) makes the decision for overlayin
7576 g the data items.
7577  Functions that are called from an interrupt service routine should be preceded
7578  by a #pragma\SpecialChar ~
7579 NOOVERLAY
7580 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
7581
7582 \end_inset 
7583
7584  if they are not reentrant.
7585 \layout Standard
7586
7587 Also note that the compiler does not do any processing of inline
7588 \begin_inset LatexCommand \index{inline}
7589
7590 \end_inset 
7591
7592  assembler code, so the compiler might incorrectly assign local variables
7593  and parameters of a function into the overlay segment if the inline assembler
7594  code calls other c-functions that might use the overlay.
7595  In that case the #pragma\SpecialChar ~
7596 NOOVERLAY should be used.
7597 \layout Standard
7598
7599 Parameters and Local variables of functions that contain 16 or 32 bit multiplica
7600 tion
7601 \begin_inset LatexCommand \index{Multiplication}
7602
7603 \end_inset 
7604
7605  or division
7606 \begin_inset LatexCommand \index{Division}
7607
7608 \end_inset 
7609
7610  will NOT be overlayed since these are implemented using external functions,
7611  e.g.:
7612 \layout Verse
7613
7614
7615 \family typewriter 
7616 #pragma SAVE 
7617 \newline 
7618 #pragma NOOVERLAY
7619 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
7620
7621 \end_inset 
7622
7623  
7624 \newline 
7625 void set_error(unsigned char errcd) 
7626 \newline 
7627 {
7628 \newline 
7629 \SpecialChar ~
7630 \SpecialChar ~
7631 \SpecialChar ~
7632 \SpecialChar ~
7633 P3 = errcd;
7634 \newline 
7635
7636 \newline 
7637 #pragma RESTORE 
7638 \newline 
7639
7640 \newline 
7641 void some_isr () interrupt
7642 \begin_inset LatexCommand \index{interrupt}
7643
7644 \end_inset 
7645
7646  2
7647 \newline 
7648 {
7649 \newline 
7650 \SpecialChar ~
7651 \SpecialChar ~
7652 \SpecialChar ~
7653 \SpecialChar ~
7654 ...
7655 \newline 
7656 \SpecialChar ~
7657 \SpecialChar ~
7658 \SpecialChar ~
7659 \SpecialChar ~
7660 set_error(10);
7661 \newline 
7662 \SpecialChar ~
7663 \SpecialChar ~
7664 \SpecialChar ~
7665 \SpecialChar ~
7666 ...
7667  
7668 \newline 
7669 }
7670 \layout Standard
7671
7672 In the above example the parameter 
7673 \emph on 
7674 errcd
7675 \emph default 
7676  for the function 
7677 \emph on 
7678 set_error
7679 \emph default 
7680  would be assigned to the overlayable segment if the #pragma\SpecialChar ~
7681 NOOVERLAY was
7682  not present, this could cause unpredictable runtime behavior when called
7683  from an ISR.
7684  The #pragma\SpecialChar ~
7685 NOOVERLAY ensures that the parameters and local variables for
7686  the function are NOT overlayed.
7687 \layout Subsection
7688
7689 Interrupt Service Routines
7690 \layout Standard
7691
7692 SDCC allows interrupt service routines to be coded in C, with some extended
7693  keywords.
7694 \layout Verse
7695
7696
7697 \family typewriter 
7698 void timer_isr (void) interrupt 1 using 1 
7699 \newline 
7700
7701 \newline 
7702 \SpecialChar ~
7703 \SpecialChar ~
7704 \SpecialChar ~
7705 \SpecialChar ~
7706 ...
7707  
7708 \newline 
7709 }
7710 \layout Standard
7711
7712 The optional number following the 
7713 \emph on 
7714 interrupt
7715 \begin_inset LatexCommand \index{interrupt}
7716
7717 \end_inset 
7718
7719
7720 \emph default 
7721  keyword is the interrupt number this routine will service.
7722  When present, the compiler will insert a call to this routine in the interrupt
7723  vector table for the interrupt number specified.
7724  The 
7725 \emph on 
7726 using
7727 \emph default 
7728  keyword can be used to tell the compiler to use the specified register
7729  bank (8051 specific) when generating code for this function.
7730  Note that when some function is called from an interrupt service routine
7731  it should be preceded by a #pragma\SpecialChar ~
7732 NOOVERLAY
7733 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
7734
7735 \end_inset 
7736
7737  if it is not reentrant.
7738  Furthermore nonreentrant functions should not be called from the main program
7739  while the interrupt service routine might be active.
7740  If the interrupt service routines changes variables which are accessed
7741  by other functions these variables should be declared 
7742 \emph on 
7743 volatile
7744 \emph default 
7745
7746 \begin_inset LatexCommand \index{volatile}
7747
7748 \end_inset 
7749
7750 .
7751  
7752 \layout Standard
7753
7754 A special note here, int (16 bit) and long (32 bit) integer division
7755 \begin_inset LatexCommand \index{Division}
7756
7757 \end_inset 
7758
7759 , multiplication
7760 \begin_inset LatexCommand \index{Multiplication}
7761
7762 \end_inset 
7763
7764  & modulus
7765 \begin_inset LatexCommand \index{Modulus}
7766
7767 \end_inset 
7768
7769  operations are implemented using external support routines developed in
7770  ANSI-C, if an interrupt service routine needs to do any of these operations
7771  then the support routines (as mentioned in a following section) will have
7772  to be recompiled using the
7773 \emph on 
7774  -
7775 \begin_inset ERT
7776 status Collapsed
7777
7778 \layout Standard
7779
7780 \backslash 
7781 /
7782 \end_inset 
7783
7784 -stack-auto
7785 \begin_inset LatexCommand \index{-\/-stack-auto}
7786
7787 \end_inset 
7788
7789
7790 \emph default 
7791  option and the source file will need to be compiled using the 
7792 \emph on 
7793 -
7794 \begin_inset ERT
7795 status Collapsed
7796
7797 \layout Standard
7798
7799 \backslash 
7800 /
7801 \end_inset 
7802
7803 -int-long-ren
7804 \emph default 
7805 t
7806 \begin_inset LatexCommand \index{-\/-int-long-rent}
7807
7808 \end_inset 
7809
7810  compiler option.
7811 \layout Standard
7812
7813 If you have multiple source files in your project, interrupt service routines
7814  can be present in any of them, but a prototype of the isr MUST be present
7815  or included in the file that contains the function 
7816 \emph on 
7817 main
7818 \emph default 
7819 .
7820 \layout Standard
7821
7822 Interrupt numbers and the corresponding address & descriptions for the Standard
7823  8051/8052 are listed below.
7824  SDCC will automatically adjust the interrupt vector table to the maximum
7825  interrupt number specified.
7826 \newline 
7827
7828 \layout Standard
7829 \align center 
7830
7831 \begin_inset  Tabular
7832 <lyxtabular version="3" rows="7" columns="3">
7833 <features>
7834 <column alignment="center" valignment="top" leftline="true" width="0in">
7835 <column alignment="center" valignment="top" leftline="true" width="0in">
7836 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0in">
7837 <row topline="true" bottomline="true">
7838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7839 \begin_inset Text
7840
7841 \layout Standard
7842
7843 Interrupt #
7844 \end_inset 
7845 </cell>
7846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7847 \begin_inset Text
7848
7849 \layout Standard
7850
7851 Description
7852 \end_inset 
7853 </cell>
7854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7855 \begin_inset Text
7856
7857 \layout Standard
7858
7859 Vector Address
7860 \end_inset 
7861 </cell>
7862 </row>
7863 <row topline="true">
7864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7865 \begin_inset Text
7866
7867 \layout Standard
7868
7869 0
7870 \end_inset 
7871 </cell>
7872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7873 \begin_inset Text
7874
7875 \layout Standard
7876
7877 External 0
7878 \end_inset 
7879 </cell>
7880 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7881 \begin_inset Text
7882
7883 \layout Standard
7884
7885 0x0003
7886 \end_inset 
7887 </cell>
7888 </row>
7889 <row topline="true">
7890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7891 \begin_inset Text
7892
7893 \layout Standard
7894
7895 1
7896 \end_inset 
7897 </cell>
7898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7899 \begin_inset Text
7900
7901 \layout Standard
7902
7903 Timer 0
7904 \end_inset 
7905 </cell>
7906 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7907 \begin_inset Text
7908
7909 \layout Standard
7910
7911 0x000B
7912 \end_inset 
7913 </cell>
7914 </row>
7915 <row topline="true">
7916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7917 \begin_inset Text
7918
7919 \layout Standard
7920
7921 2
7922 \end_inset 
7923 </cell>
7924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7925 \begin_inset Text
7926
7927 \layout Standard
7928
7929 External 1
7930 \end_inset 
7931 </cell>
7932 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7933 \begin_inset Text
7934
7935 \layout Standard
7936
7937 0x0013
7938 \end_inset 
7939 </cell>
7940 </row>
7941 <row topline="true">
7942 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7943 \begin_inset Text
7944
7945 \layout Standard
7946
7947 3
7948 \end_inset 
7949 </cell>
7950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7951 \begin_inset Text
7952
7953 \layout Standard
7954
7955 Timer 1
7956 \end_inset 
7957 </cell>
7958 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7959 \begin_inset Text
7960
7961 \layout Standard
7962
7963 0x001B
7964 \end_inset 
7965 </cell>
7966 </row>
7967 <row topline="true">
7968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7969 \begin_inset Text
7970
7971 \layout Standard
7972
7973 4
7974 \end_inset 
7975 </cell>
7976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7977 \begin_inset Text
7978
7979 \layout Standard
7980
7981 Serial
7982 \end_inset 
7983 </cell>
7984 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7985 \begin_inset Text
7986
7987 \layout Standard
7988
7989 0x0023
7990 \end_inset 
7991 </cell>
7992 </row>
7993 <row topline="true" bottomline="true">
7994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7995 \begin_inset Text
7996
7997 \layout Standard
7998
7999 5
8000 \end_inset 
8001 </cell>
8002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8003 \begin_inset Text
8004
8005 \layout Standard
8006
8007 Timer 2 (8052)
8008 \end_inset 
8009 </cell>
8010 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8011 \begin_inset Text
8012
8013 \layout Standard
8014
8015 0x002B
8016 \end_inset 
8017 </cell>
8018 </row>
8019 </lyxtabular>
8020
8021 \end_inset 
8022
8023
8024 \newline 
8025
8026 \layout Standard
8027
8028 If the interrupt service routine is defined without 
8029 \emph on 
8030 using
8031 \begin_inset LatexCommand \index{using}
8032
8033 \end_inset 
8034
8035
8036 \emph default 
8037  a register bank or with register bank 0 (using 0), the compiler will save
8038  the registers used by itself on the stack upon entry and restore them at
8039  exit, however if such an interrupt service routine calls another function
8040  then the entire register bank will be saved on the stack.
8041  This scheme may be advantageous for small interrupt service routines which
8042  have low register usage.
8043 \layout Standard
8044
8045 If the interrupt service routine is defined to be using a specific register
8046  bank then only 
8047 \emph on 
8048 a, b & dptr
8049 \emph default 
8050  are save and restored, if such an interrupt service routine calls another
8051  function (using another register bank) then the entire register bank of
8052  the called function will be saved on the stack.
8053  This scheme is recommended for larger interrupt service routines.
8054 \layout Standard
8055
8056 Calling other functions from an interrupt service routine is not recommended,
8057  avoid it if possible.
8058 \newline 
8059 For some pitfalls see section 
8060 \begin_inset LatexCommand \ref{sub:Overlaying}
8061
8062 \end_inset 
8063
8064 about Overlaying and section 
8065 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
8066
8067 \end_inset 
8068
8069 about Functions using private banks.
8070 \newline 
8071
8072 \layout Subsection
8073
8074 Critical Functions
8075 \layout Standard
8076
8077
8078 \shape italic 
8079 <TODO: this isn't implemented at all!>
8080 \shape default 
8081
8082 \newline 
8083
8084 \newline 
8085 A special keyword may be associated with a function declaring it as 
8086 \emph on 
8087 critical
8088 \emph default 
8089 .
8090  SDCC will generate code to disable all interrupts upon entry to a critical
8091  function and enable them back before returning.
8092  Note that nesting critical functions may cause unpredictable results.
8093 \layout Verse
8094
8095
8096 \family typewriter 
8097 int foo () critical 
8098 \newline 
8099
8100 \newline 
8101 \SpecialChar ~
8102 \SpecialChar ~
8103 \SpecialChar ~
8104 \SpecialChar ~
8105 ...
8106  
8107 \newline 
8108 \SpecialChar ~
8109 \SpecialChar ~
8110 \SpecialChar ~
8111 \SpecialChar ~
8112 ...
8113  
8114 \newline 
8115 }
8116 \layout Standard
8117
8118 The critical attribute maybe used with other attributes like 
8119 \emph on 
8120 reentrant.
8121 \layout Subsection
8122
8123 Naked Functions
8124 \begin_inset LatexCommand \label{sub:Naked-Functions}
8125
8126 \end_inset 
8127
8128
8129 \begin_inset LatexCommand \index{Naked functions}
8130
8131 \end_inset 
8132
8133
8134 \layout Standard
8135
8136 A special keyword may be associated with a function declaring it as 
8137 \emph on 
8138 _naked
8139 \begin_inset LatexCommand \index{\_naked}
8140
8141 \end_inset 
8142
8143 .
8144  
8145 \emph default 
8146 The 
8147 \emph on 
8148 _naked
8149 \emph default 
8150  function modifier attribute prevents the compiler from generating prologue
8151 \begin_inset LatexCommand \index{function prologue}
8152
8153 \end_inset 
8154
8155  and epilogue
8156 \begin_inset LatexCommand \index{function epilogue}
8157
8158 \end_inset 
8159
8160  code for that function.
8161  This means that the user is entirely responsible for such things as saving
8162  any registers that may need to be preserved, selecting the proper register
8163  bank, generating the 
8164 \emph on 
8165 return
8166 \emph default 
8167  instruction at the end, etc.
8168  Practically, this means that the contents of the function must be written
8169  in inline assembler.
8170  This is particularly useful for interrupt functions, which can have a large
8171  (and often unnecessary) prologue/epilogue.
8172  For example, compare the code generated by these two functions:
8173 \layout Verse
8174
8175
8176 \family typewriter 
8177 volatile
8178 \begin_inset LatexCommand \index{volatile}
8179
8180 \end_inset 
8181
8182  data unsigned char counter;
8183 \newline 
8184
8185 \newline 
8186 void simpleInterrupt(void) interrupt
8187 \begin_inset LatexCommand \index{interrupt}
8188
8189 \end_inset 
8190
8191  1
8192 \newline 
8193 {
8194 \newline 
8195 \SpecialChar ~
8196 \SpecialChar ~
8197 \SpecialChar ~
8198 \SpecialChar ~
8199 counter++;
8200 \newline 
8201 }
8202 \newline 
8203
8204 \newline 
8205 void nakedInterrupt(void) interrupt 2 _naked
8206 \newline 
8207 {
8208 \newline 
8209 \SpecialChar ~
8210 \SpecialChar ~
8211 \SpecialChar ~
8212 \SpecialChar ~
8213 _asm
8214 \begin_inset LatexCommand \index{\_asm}
8215
8216 \end_inset 
8217
8218
8219 \newline 
8220 \SpecialChar ~
8221 \SpecialChar ~
8222 \SpecialChar ~
8223 \SpecialChar ~
8224 \SpecialChar ~
8225 \SpecialChar ~
8226 inc\SpecialChar ~
8227 \SpecialChar ~
8228 \SpecialChar ~
8229 \SpecialChar ~
8230 \SpecialChar ~
8231 _counter
8232 \newline 
8233 \SpecialChar ~
8234 \SpecialChar ~
8235 \SpecialChar ~
8236 \SpecialChar ~
8237 \SpecialChar ~
8238 \SpecialChar ~
8239 reti\SpecialChar ~
8240 \SpecialChar ~
8241 \SpecialChar ~
8242 \SpecialChar ~
8243 ; MUST explicitly include ret or reti in _naked function.
8244 \newline 
8245 \SpecialChar ~
8246 \SpecialChar ~
8247 \SpecialChar ~
8248 \SpecialChar ~
8249 _endasm
8250 \begin_inset LatexCommand \index{\_endasm}
8251
8252 \end_inset 
8253
8254 ;
8255 \newline 
8256 }
8257 \layout Standard
8258
8259 For an 8051 target, the generated simpleInterrupt looks like:
8260 \layout Verse
8261
8262
8263 \family typewriter 
8264 _simpleInterrupt:
8265 \newline 
8266 \SpecialChar ~
8267 \SpecialChar ~
8268 \SpecialChar ~
8269 \SpecialChar ~
8270 push\SpecialChar ~
8271 \SpecialChar ~
8272 \SpecialChar ~
8273 \SpecialChar ~
8274 acc
8275 \newline 
8276 \SpecialChar ~
8277 \SpecialChar ~
8278 \SpecialChar ~
8279 \SpecialChar ~
8280 push\SpecialChar ~
8281 \SpecialChar ~
8282 \SpecialChar ~
8283 \SpecialChar ~
8284 b
8285 \newline 
8286 \SpecialChar ~
8287 \SpecialChar ~
8288 \SpecialChar ~
8289 \SpecialChar ~
8290 push\SpecialChar ~
8291 \SpecialChar ~
8292 \SpecialChar ~
8293 \SpecialChar ~
8294 dpl
8295 \newline 
8296 \SpecialChar ~
8297 \SpecialChar ~
8298 \SpecialChar ~
8299 \SpecialChar ~
8300 push\SpecialChar ~
8301 \SpecialChar ~
8302 \SpecialChar ~
8303 \SpecialChar ~
8304 dph
8305 \newline 
8306 \SpecialChar ~
8307 \SpecialChar ~
8308 \SpecialChar ~
8309 \SpecialChar ~
8310 push\SpecialChar ~
8311 \SpecialChar ~
8312 \SpecialChar ~
8313 \SpecialChar ~
8314 psw
8315 \newline 
8316 \SpecialChar ~
8317 \SpecialChar ~
8318 \SpecialChar ~
8319 \SpecialChar ~
8320 mov\SpecialChar ~
8321 \SpecialChar ~
8322 \SpecialChar ~
8323 \SpecialChar ~
8324 \SpecialChar ~
8325 psw,#0x00
8326 \newline 
8327 \SpecialChar ~
8328 \SpecialChar ~
8329 \SpecialChar ~
8330 \SpecialChar ~
8331 inc\SpecialChar ~
8332 \SpecialChar ~
8333 \SpecialChar ~
8334 \SpecialChar ~
8335 \SpecialChar ~
8336 _counter
8337 \newline 
8338 \SpecialChar ~
8339 \SpecialChar ~
8340 \SpecialChar ~
8341 \SpecialChar ~
8342 pop\SpecialChar ~
8343 \SpecialChar ~
8344 \SpecialChar ~
8345 \SpecialChar ~
8346 \SpecialChar ~
8347 psw
8348 \newline 
8349 \SpecialChar ~
8350 \SpecialChar ~
8351 \SpecialChar ~
8352 \SpecialChar ~
8353 pop\SpecialChar ~
8354 \SpecialChar ~
8355 \SpecialChar ~
8356 \SpecialChar ~
8357 \SpecialChar ~
8358 dph
8359 \newline 
8360 \SpecialChar ~
8361 \SpecialChar ~
8362 \SpecialChar ~
8363 \SpecialChar ~
8364 pop\SpecialChar ~
8365 \SpecialChar ~
8366 \SpecialChar ~
8367 \SpecialChar ~
8368 \SpecialChar ~
8369 dpl
8370 \newline 
8371 \SpecialChar ~
8372 \SpecialChar ~
8373 \SpecialChar ~
8374 \SpecialChar ~
8375 pop\SpecialChar ~
8376 \SpecialChar ~
8377 \SpecialChar ~
8378 \SpecialChar ~
8379 \SpecialChar ~
8380 b
8381 \newline 
8382 \SpecialChar ~
8383 \SpecialChar ~
8384 \SpecialChar ~
8385 \SpecialChar ~
8386 pop\SpecialChar ~
8387 \SpecialChar ~
8388 \SpecialChar ~
8389 \SpecialChar ~
8390 \SpecialChar ~
8391 acc
8392 \newline 
8393 \SpecialChar ~
8394 \SpecialChar ~
8395 \SpecialChar ~
8396 \SpecialChar ~
8397 reti
8398 \layout Standard
8399
8400 whereas nakedInterrupt looks like:
8401 \layout Verse
8402
8403
8404 \family typewriter 
8405 _nakedInterrupt:
8406 \newline 
8407 \SpecialChar ~
8408 \SpecialChar ~
8409 \SpecialChar ~
8410 \SpecialChar ~
8411 inc\SpecialChar ~
8412 \SpecialChar ~
8413 \SpecialChar ~
8414 \SpecialChar ~
8415 _counter
8416 \newline 
8417 \SpecialChar ~
8418 \SpecialChar ~
8419 \SpecialChar ~
8420 \SpecialChar ~
8421 reti\SpecialChar ~
8422 \SpecialChar ~
8423 \SpecialChar ~
8424 ; MUST explicitly include ret or reti in _naked function.
8425 \layout Standard
8426
8427 The #pragma directive EXCLUDE
8428 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
8429
8430 \end_inset 
8431
8432  also allows to reduce pushing & popping the registers.
8433 \layout Standard
8434
8435 While there is nothing preventing you from writing C code inside a _naked
8436  function, there are many ways to shoot yourself in the foot doing this,
8437  and it is recommended that you stick to inline assembler.
8438 \layout Subsection
8439
8440 Functions using private banks
8441 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
8442
8443 \end_inset 
8444
8445
8446 \begin_inset LatexCommand \index{bank}
8447
8448 \end_inset 
8449
8450
8451 \layout Standard
8452
8453 The 
8454 \emph on 
8455 using
8456 \begin_inset LatexCommand \index{using}
8457
8458 \end_inset 
8459
8460
8461 \emph default 
8462  attribute (which tells the compiler to use a register bank other than the
8463  default bank zero) should only be applied to 
8464 \emph on 
8465 interrupt
8466 \begin_inset LatexCommand \index{interrupt}
8467
8468 \end_inset 
8469
8470
8471 \emph default 
8472  functions (see note 1 below).
8473  This will in most circumstances make the generated ISR code more efficient
8474  since it will not have to save registers on the stack.
8475 \layout Standard
8476
8477 The 
8478 \emph on 
8479 using
8480 \emph default 
8481  attribute will have no effect on the generated code for a 
8482 \emph on 
8483 non-interrupt
8484 \emph default 
8485  function (but may occasionally be useful anyway
8486 \begin_inset Foot
8487 collapsed false
8488
8489 \layout Standard
8490
8491 possible exception: if a function is called ONLY from 'interrupt' functions
8492  using a particular bank, it can be declared with the same 'using' attribute
8493  as the calling 'interrupt' functions.
8494  For instance, if you have several ISRs using bank one, and all of them
8495  call memcpy(), it might make sense to create a specialized version of memcpy()
8496  'using 1', since this would prevent the ISR from having to save bank zero
8497  to the stack on entry and switch to bank zero before calling the function
8498 \end_inset 
8499
8500 ).
8501 \newline 
8502
8503 \emph on 
8504 (pending: I don't think this has been done yet)
8505 \layout Standard
8506
8507 An 
8508 \emph on 
8509 interrupt
8510 \emph default 
8511  function using a non-zero bank will assume that it can trash that register
8512  bank, and will not save it.
8513  Since high-priority interrupts
8514 \begin_inset LatexCommand \index{interrupt priority}
8515
8516 \end_inset 
8517
8518  can interrupt low-priority ones on the 8051 and friends, this means that
8519  if a high-priority ISR 
8520 \emph on 
8521 using
8522 \emph default 
8523  a particular bank occurs while processing a low-priority ISR 
8524 \emph on 
8525 using
8526 \emph default 
8527  the same bank, terrible and bad things can happen.
8528  To prevent this, no single register bank should be 
8529 \emph on 
8530 used
8531 \emph default 
8532  by both a high priority and a low priority ISR.
8533  This is probably most easily done by having all high priority ISRs use
8534  one bank and all low priority ISRs use another.
8535  If you have an ISR which can change priority at runtime, you're on your
8536  own: I suggest using the default bank zero and taking the small performance
8537  hit.
8538 \layout Standard
8539
8540 It is most efficient if your ISR calls no other functions.
8541  If your ISR must call other functions, it is most efficient if those functions
8542  use the same bank as the ISR (see note 1 below); the next best is if the
8543  called functions use bank zero.
8544  It is very inefficient to call a function using a different, non-zero bank
8545  from an ISR.
8546  
8547 \layout Subsection
8548
8549 Absolute Addressing
8550 \begin_inset LatexCommand \index{Absolute addressing}
8551
8552 \end_inset 
8553
8554
8555 \layout Standard
8556
8557 Data items can be assigned an absolute address with the 
8558 \emph on 
8559 at
8560 \begin_inset LatexCommand \index{at}
8561
8562 \end_inset 
8563
8564  <address>
8565 \emph default 
8566  keyword, in addition to a storage class, e.g.:
8567 \layout Verse
8568
8569
8570 \family typewriter 
8571 xdata
8572 \begin_inset LatexCommand \index{xdata}
8573
8574 \end_inset 
8575
8576  at
8577 \begin_inset LatexCommand \index{at}
8578
8579 \end_inset 
8580
8581  0x7ffe unsigned int chksum;
8582 \layout Standard
8583
8584 In the above example the variable chksum will located at 0x7ffe and 0x7fff
8585  of the external ram.
8586  The compiler does not actually reserve any space for variables declared
8587  in this way (they are implemented with an equate in the assembler).
8588  Thus it is left to the programmer to make sure there are no overlaps with
8589  other variables that are declared without the absolute address.
8590  The assembler listing file (.lst
8591 \begin_inset LatexCommand \index{.lst}
8592
8593 \end_inset 
8594
8595 ) and the linker output files (.rst
8596 \begin_inset LatexCommand \index{.rst}
8597
8598 \end_inset 
8599
8600 ) and (.map
8601 \begin_inset LatexCommand \index{.map}
8602
8603 \end_inset 
8604
8605 ) are good places to look for such overlaps.
8606 \layout Standard
8607
8608 In case of memory mapped I/O devices the keyword 
8609 \emph on 
8610 volatile
8611 \emph default 
8612  should be used to tell the compiler that accesses might not be optimized
8613  away:
8614 \layout Verse
8615
8616
8617 \family typewriter 
8618 volatile
8619 \begin_inset LatexCommand \index{volatile}
8620
8621 \end_inset 
8622
8623  xdata
8624 \begin_inset LatexCommand \index{xdata}
8625
8626 \end_inset 
8627
8628  at
8629 \begin_inset LatexCommand \index{at}
8630
8631 \end_inset 
8632
8633  0x8000 unsigned char PORTA_8255;
8634 \layout Standard
8635
8636 Absolute address can be specified for variables in all storage classes,
8637  e.g.:
8638 \layout Verse
8639
8640
8641 \family typewriter 
8642 bit
8643 \begin_inset LatexCommand \index{bit}
8644
8645 \end_inset 
8646
8647  at
8648 \begin_inset LatexCommand \index{at}
8649
8650 \end_inset 
8651
8652  0x02 bvar;
8653 \layout Standard
8654
8655 The above example will allocate the variable at offset 0x02 in the bit-addressab
8656 le space.
8657  There is no real advantage to assigning absolute addresses to variables
8658  in this manner, unless you want strict control over all the variables allocated.
8659  One possible use would be to write hardware portable code.
8660  For example, if you have a routine that uses one or more of the microcontroller
8661  I/O pins, and such pins are different for two different hardwares, you
8662  can declare the I/O pins in your routine using:
8663 \layout Verse
8664
8665
8666 \family typewriter 
8667 extern bit SDI;
8668 \newline 
8669 extern bit SCLK;
8670 \newline 
8671 extern bit CPOL;
8672 \newline 
8673
8674 \newline 
8675 void DS1306_put(unsigned char value)
8676 \newline 
8677 {
8678 \newline 
8679 \SpecialChar ~
8680 \SpecialChar ~
8681 \SpecialChar ~
8682 \SpecialChar ~
8683 unsigned char mask=0x80;
8684 \newline 
8685
8686 \newline 
8687 \SpecialChar ~
8688 \SpecialChar ~
8689 \SpecialChar ~
8690 \SpecialChar ~
8691 while(mask)
8692 \newline 
8693 \SpecialChar ~
8694 \SpecialChar ~
8695 \SpecialChar ~
8696 \SpecialChar ~
8697 {
8698 \newline 
8699 \SpecialChar ~
8700 \SpecialChar ~
8701 \SpecialChar ~
8702 \SpecialChar ~
8703 \SpecialChar ~
8704 \SpecialChar ~
8705 \SpecialChar ~
8706 \SpecialChar ~
8707 SDI=(value & mask)?1:0;
8708 \newline 
8709 \SpecialChar ~
8710 \SpecialChar ~
8711 \SpecialChar ~
8712 \SpecialChar ~
8713 \SpecialChar ~
8714 \SpecialChar ~
8715 \SpecialChar ~
8716 \SpecialChar ~
8717 SCLK=!CPOL;
8718 \newline 
8719 \SpecialChar ~
8720 \SpecialChar ~
8721 \SpecialChar ~
8722 \SpecialChar ~
8723 \SpecialChar ~
8724 \SpecialChar ~
8725 \SpecialChar ~
8726 \SpecialChar ~
8727 SCLK=CPOL;
8728 \newline 
8729 \SpecialChar ~
8730 \SpecialChar ~
8731 \SpecialChar ~
8732 \SpecialChar ~
8733 \SpecialChar ~
8734 \SpecialChar ~
8735 \SpecialChar ~
8736 \SpecialChar ~
8737 mask/=2;
8738 \newline 
8739 \SpecialChar ~
8740 \SpecialChar ~
8741 \SpecialChar ~
8742 \SpecialChar ~
8743 }
8744 \newline 
8745 }
8746 \layout Standard
8747
8748 Then, someplace in the code for the first hardware you would use
8749 \layout Verse
8750
8751
8752 \family typewriter 
8753 bit at 0x80 SDI;\SpecialChar ~
8754 \SpecialChar ~
8755 \SpecialChar ~
8756 \SpecialChar ~
8757 /* I/O port 0, bit 0 */
8758 \newline 
8759 bit at 0x81 SCLK;\SpecialChar ~
8760 \SpecialChar ~
8761 \SpecialChar ~
8762 /* I/O port 0, bit 1 */
8763 \newline 
8764 bit CPOL;\SpecialChar ~
8765 \SpecialChar ~
8766 \SpecialChar ~
8767 \SpecialChar ~
8768 \SpecialChar ~
8769 \SpecialChar ~
8770 \SpecialChar ~
8771 \SpecialChar ~
8772 \SpecialChar ~
8773 \SpecialChar ~
8774 \SpecialChar ~
8775 /* This is a variable, let the linker allocate this one */
8776 \layout Standard
8777
8778 Similarly, for the second hardware you would use
8779 \layout Verse
8780
8781
8782 \family typewriter 
8783 bit at 0x83 SDI;\SpecialChar ~
8784 \SpecialChar ~
8785 \SpecialChar ~
8786 \SpecialChar ~
8787 /* I/O port 0, bit 3 */
8788 \newline 
8789 bit at 0x91 SCLK;\SpecialChar ~
8790 \SpecialChar ~
8791 \SpecialChar ~
8792 /* I/O port 1, bit 1 */
8793 \newline 
8794 bit CPOL;\SpecialChar ~
8795 \SpecialChar ~
8796 \SpecialChar ~
8797 \SpecialChar ~
8798 \SpecialChar ~
8799 \SpecialChar ~
8800 \SpecialChar ~
8801 \SpecialChar ~
8802 \SpecialChar ~
8803 \SpecialChar ~
8804 \SpecialChar ~
8805 /* This is a variable, let the linker allocate this one */
8806 \layout Standard
8807
8808 and you can use the same hardware dependent routine without changes, as
8809  for example in a library.
8810  This is somehow similar to sbit, but only one absolute address has to be
8811  specified in the whole project.
8812 \layout Subsection
8813
8814 Startup Code
8815 \begin_inset LatexCommand \index{Startup code}
8816
8817 \end_inset 
8818
8819
8820 \layout Standard
8821
8822 The compiler inserts a call to the C routine 
8823 \emph on 
8824 _sdcc_external_startup()
8825 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
8826
8827 \end_inset 
8828
8829
8830 \series bold 
8831 \emph default 
8832  
8833 \series default 
8834 at the start of the CODE area.
8835  This routine is in the runtime library
8836 \begin_inset LatexCommand \index{Runtime library}
8837
8838 \end_inset 
8839
8840 .
8841  By default this routine returns 0, if this routine returns a non-zero value,
8842  the static & global variable initialization will be skipped and the function
8843  main will be invoked.
8844  Otherwise static & global variables will be initialized before the function
8845  main is invoked.
8846  You could add a 
8847 \emph on 
8848 _sdcc_external_startup()
8849 \emph default 
8850  routine to your program to override the default if you need to setup hardware
8851  or perform some other critical operation prior to static & global variable
8852  initialization.
8853  See also the compiler option 
8854 \emph on 
8855 -
8856 \begin_inset ERT
8857 status Collapsed
8858
8859 \layout Standard
8860
8861 \backslash 
8862 /
8863 \end_inset 
8864
8865 -no-xinit
8866 \emph default 
8867 -
8868 \emph on 
8869 opt
8870 \emph default 
8871
8872 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
8873
8874 \end_inset 
8875
8876 .
8877 \layout Subsection
8878
8879 Inline Assembler Code
8880 \begin_inset LatexCommand \index{Assembler routines}
8881
8882 \end_inset 
8883
8884
8885 \layout Standard
8886
8887 SDCC allows the use of in-line assembler with a few restriction as regards
8888  labels.
8889  All labels defined within inline assembler code 
8890 \emph on 
8891 has to be
8892 \emph default 
8893  of the form 
8894 \emph on 
8895 nnnnn$
8896 \emph default 
8897  where nnnn is a number less than 100 (which implies a limit of utmost 100
8898  inline assembler labels 
8899 \emph on 
8900 per function
8901 \emph default 
8902 \noun on 
8903 )
8904 \noun default 
8905 .
8906  It is strongly recommended that each assembly instruction (including labels)
8907  be placed in a separate line (as the example shows).
8908  When the -
8909 \begin_inset ERT
8910 status Collapsed
8911
8912 \layout Standard
8913
8914 \backslash 
8915 /
8916 \end_inset 
8917
8918 -
8919 \emph on 
8920 peep-asm
8921 \begin_inset LatexCommand \index{-\/-peep-asm}
8922
8923 \end_inset 
8924
8925
8926 \emph default 
8927  command line option is used, the inline assembler code will be passed through
8928  the peephole optimizer
8929 \begin_inset LatexCommand \index{Peephole optimizer}
8930
8931 \end_inset 
8932
8933 .
8934  This might cause some unexpected changes in the inline assembler code.
8935  Please go through the peephole optimizer rules defined in file 
8936 \emph on 
8937 SDCCpeeph.def
8938 \emph default 
8939  carefully before using this option.
8940 \layout Verse
8941
8942
8943 \family typewriter 
8944 _asm
8945 \begin_inset LatexCommand \index{\_asm}
8946
8947 \end_inset 
8948
8949  
8950 \newline 
8951 \SpecialChar ~
8952 \SpecialChar ~
8953 \SpecialChar ~
8954 \SpecialChar ~
8955 mov\SpecialChar ~
8956 \SpecialChar ~
8957 \SpecialChar ~
8958 \SpecialChar ~
8959 \SpecialChar ~
8960 b,#10 
8961 \newline 
8962 00001$: 
8963 \newline 
8964 \SpecialChar ~
8965 \SpecialChar ~
8966 \SpecialChar ~
8967 \SpecialChar ~
8968 djnz\SpecialChar ~
8969 \SpecialChar ~
8970 \SpecialChar ~
8971 \SpecialChar ~
8972 b,00001$ 
8973 \newline 
8974 _endasm
8975 \begin_inset LatexCommand \index{\_endasm}
8976
8977 \end_inset 
8978
8979  ;
8980 \layout Standard
8981
8982 The inline assembler code can contain any valid code understood by the assembler
8983 , this includes any assembler directives and comment lines.
8984  The compiler does not do any validation of the code within the 
8985 \family typewriter 
8986 _asm ...
8987  _endasm;
8988 \family default 
8989  keyword pair.
8990  
8991 \newline 
8992
8993 \newline 
8994 Inline assembler code cannot reference any C-Labels, however it can reference
8995  labels
8996 \begin_inset LatexCommand \index{Labels}
8997
8998 \end_inset 
8999
9000  defined by the inline assembler, e.g.:
9001 \layout Verse
9002
9003
9004 \family typewriter 
9005 foo() { 
9006 \newline 
9007 \SpecialChar ~
9008 \SpecialChar ~
9009 \SpecialChar ~
9010 \SpecialChar ~
9011 /* some c code */ 
9012 \newline 
9013 \SpecialChar ~
9014 \SpecialChar ~
9015 \SpecialChar ~
9016 \SpecialChar ~
9017 _asm 
9018 \newline 
9019 \SpecialChar ~
9020 \SpecialChar ~
9021 \SpecialChar ~
9022 \SpecialChar ~
9023 \SpecialChar ~
9024 \SpecialChar ~
9025 ; some assembler code 
9026 \newline 
9027 \SpecialChar ~
9028 \SpecialChar ~
9029 \SpecialChar ~
9030 \SpecialChar ~
9031 \SpecialChar ~
9032 \SpecialChar ~
9033 ljmp $0003 
9034 \newline 
9035 \SpecialChar ~
9036 \SpecialChar ~
9037 \SpecialChar ~
9038 \SpecialChar ~
9039 _endasm; 
9040 \newline 
9041 \SpecialChar ~
9042 \SpecialChar ~
9043 \SpecialChar ~
9044 \SpecialChar ~
9045 /* some more c code */ 
9046 \newline 
9047 clabel:\SpecialChar ~
9048 \SpecialChar ~
9049 /* inline assembler cannot reference this label */ 
9050 \newline 
9051 \SpecialChar ~
9052 \SpecialChar ~
9053 \SpecialChar ~
9054 \SpecialChar ~
9055 _asm
9056 \newline 
9057 \SpecialChar ~
9058 \SpecialChar ~
9059 \SpecialChar ~
9060 \SpecialChar ~
9061 $0003: ;label (can be reference by inline assembler only) 
9062 \newline 
9063 \SpecialChar ~
9064 \SpecialChar ~
9065 \SpecialChar ~
9066 \SpecialChar ~
9067 _endasm ; 
9068 \newline 
9069 \SpecialChar ~
9070 \SpecialChar ~
9071 \SpecialChar ~
9072 \SpecialChar ~
9073 /* some more c code */
9074 \newline 
9075 }
9076 \layout Standard
9077
9078 In other words inline assembly code can access labels defined in inline
9079  assembly within the scope of the function.
9080  The same goes the other way, ie.
9081  labels defines in inline assembly CANNOT be accessed by C statements.
9082 \layout Standard
9083
9084 An example acessing a C variable is in section 
9085 \begin_inset LatexCommand \ref{sub:Naked-Functions}
9086
9087 \end_inset 
9088
9089 .
9090 \layout Subsection
9091
9092 int (16 bit)
9093 \begin_inset LatexCommand \index{int (16 bit)}
9094
9095 \end_inset 
9096
9097  and long (32 bit)
9098 \begin_inset LatexCommand \index{long (32 bit)}
9099
9100 \end_inset 
9101
9102  Support
9103 \layout Standard
9104
9105 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
9106  multiplication and modulus operations are implemented by support routines.
9107  These support routines are all developed in ANSI-C to facilitate porting
9108  to other MCUs, although some model specific assembler optimizations are
9109  used.
9110  The following files contain the described routines, all of them can be
9111  found in <installdir>/share/sdcc/lib.
9112 \newline 
9113
9114 \layout Standard
9115 \align center 
9116
9117 \begin_inset  Tabular
9118 <lyxtabular version="3" rows="11" columns="2">
9119 <features>
9120 <column alignment="center" valignment="top" leftline="true" width="0">
9121 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
9122 <row topline="true" bottomline="true">
9123 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9124 \begin_inset Text
9125
9126 \layout Standard
9127
9128
9129 \series bold 
9130 Function
9131 \end_inset 
9132 </cell>
9133 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9134 \begin_inset Text
9135
9136 \layout Standard
9137
9138
9139 \series bold 
9140 Description
9141 \end_inset 
9142 </cell>
9143 </row>
9144 <row topline="true">
9145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9146 \begin_inset Text
9147
9148 \layout Standard
9149
9150 _mulint.c 
9151 \end_inset 
9152 </cell>
9153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9154 \begin_inset Text
9155
9156 \layout Standard
9157
9158 16 bit multiplication
9159 \end_inset 
9160 </cell>
9161 </row>
9162 <row topline="true">
9163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9164 \begin_inset Text
9165
9166 \layout Standard
9167
9168 _divsint.c 
9169 \end_inset 
9170 </cell>
9171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9172 \begin_inset Text
9173
9174 \layout Standard
9175
9176  signed 16 bit division (calls _divuint)
9177 \end_inset 
9178 </cell>
9179 </row>
9180 <row topline="true">
9181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9182 \begin_inset Text
9183
9184 \layout Standard
9185
9186 _divuint.c 
9187 \end_inset 
9188 </cell>
9189 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9190 \begin_inset Text
9191
9192 \layout Standard
9193
9194  unsigned 16 bit division
9195 \end_inset 
9196 </cell>
9197 </row>
9198 <row topline="true">
9199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9200 \begin_inset Text
9201
9202 \layout Standard
9203
9204 _modsint.c
9205 \end_inset 
9206 </cell>
9207 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9208 \begin_inset Text
9209
9210 \layout Standard
9211
9212 signed 16 bit modulus (calls _moduint)
9213 \end_inset 
9214 </cell>
9215 </row>
9216 <row topline="true">
9217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9218 \begin_inset Text
9219
9220 \layout Standard
9221
9222 _moduint.c
9223 \end_inset 
9224 </cell>
9225 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9226 \begin_inset Text
9227
9228 \layout Standard
9229
9230 unsigned 16 bit modulus
9231 \end_inset 
9232 </cell>
9233 </row>
9234 <row topline="true">
9235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9236 \begin_inset Text
9237
9238 \layout Standard
9239
9240 _mullong.c
9241 \end_inset 
9242 </cell>
9243 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9244 \begin_inset Text
9245
9246 \layout Standard
9247
9248 32 bit multiplication
9249 \end_inset 
9250 </cell>
9251 </row>
9252 <row topline="true">
9253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9254 \begin_inset Text
9255
9256 \layout Standard
9257
9258 _divslong.c 
9259 \end_inset 
9260 </cell>
9261 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9262 \begin_inset Text
9263
9264 \layout Standard
9265
9266  signed 32 division (calls _divulong)
9267 \end_inset 
9268 </cell>
9269 </row>
9270 <row topline="true">
9271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9272 \begin_inset Text
9273
9274 \layout Standard
9275
9276 _divulong.c 
9277 \end_inset 
9278 </cell>
9279 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9280 \begin_inset Text
9281
9282 \layout Standard
9283
9284 unsigned 32 division
9285 \end_inset 
9286 </cell>
9287 </row>
9288 <row topline="true">
9289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9290 \begin_inset Text
9291
9292 \layout Standard
9293
9294 _modslong.c
9295 \end_inset 
9296 </cell>
9297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9298 \begin_inset Text
9299
9300 \layout Standard
9301
9302  signed 32 bit modulus (calls _modulong)
9303 \end_inset 
9304 </cell>
9305 </row>
9306 <row topline="true" bottomline="true">
9307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9308 \begin_inset Text
9309
9310 \layout Standard
9311
9312 _modulong.c
9313 \end_inset 
9314 </cell>
9315 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9316 \begin_inset Text
9317
9318 \layout Standard
9319
9320 unsigned 32 bit modulus
9321 \end_inset 
9322 </cell>
9323 </row>
9324 </lyxtabular>
9325
9326 \end_inset 
9327
9328
9329 \newline 
9330
9331 \layout Standard
9332
9333 Since they are compiled as 
9334 \emph on 
9335 non-reentrant
9336 \emph default 
9337
9338 \begin_inset LatexCommand \index{reentrant}
9339
9340 \end_inset 
9341
9342 , interrupt
9343 \begin_inset LatexCommand \index{interrupt}
9344
9345 \end_inset 
9346
9347  service routines should not do any of the above operations.
9348  If this is unavoidable then the above routines will need to be compiled
9349  with the 
9350 \emph on 
9351 -
9352 \begin_inset ERT
9353 status Collapsed
9354
9355 \layout Standard
9356
9357 \backslash 
9358 /
9359 \end_inset 
9360
9361 -stack-auto
9362 \begin_inset LatexCommand \index{-\/-stack-auto}
9363
9364 \end_inset 
9365
9366
9367 \emph default 
9368  option, after which the source program will have to be compiled with 
9369 \emph on 
9370 -
9371 \begin_inset ERT
9372 status Collapsed
9373
9374 \layout Standard
9375
9376 \backslash 
9377 /
9378 \end_inset 
9379
9380 -int-long-rent
9381 \begin_inset LatexCommand \index{-\/-int-long-rent}
9382
9383 \end_inset 
9384
9385
9386 \emph default 
9387  option.
9388  Notice that you don't have to call this routines directly.
9389  The compiler will use them automatically every time a integer operation
9390  is required.
9391 \layout Subsection
9392
9393 Floating Point Support
9394 \begin_inset LatexCommand \index{Floating point support}
9395
9396 \end_inset 
9397
9398
9399 \layout Standard
9400
9401 SDCC supports IEEE (single precision 4 bytes) floating point numbers.The
9402  floating point support routines are derived from gcc's floatlib.c and consists
9403  of the following routines:
9404 \newline 
9405
9406 \layout Standard
9407 \align center 
9408
9409 \size footnotesize 
9410
9411 \begin_inset  Tabular
9412 <lyxtabular version="3" rows="17" columns="2">
9413 <features>
9414 <column alignment="center" valignment="top" leftline="true" width="0">
9415 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
9416 <row topline="true" bottomline="true">
9417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9418 \begin_inset Text
9419
9420 \layout Standard
9421
9422
9423 \family roman 
9424 \series medium 
9425 \shape up 
9426 \size normal 
9427 \emph off 
9428 \bar no 
9429 \noun off 
9430 \color none
9431 Function 
9432 \end_inset 
9433 </cell>
9434 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9435 \begin_inset Text
9436
9437 \layout Standard
9438
9439 Description
9440 \end_inset 
9441 </cell>
9442 </row>
9443 <row topline="true">
9444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9445 \begin_inset Text
9446
9447 \layout Standard
9448
9449
9450 \family roman 
9451 \series medium 
9452 \shape up 
9453 \size normal 
9454 \emph off 
9455 \bar no 
9456 \noun off 
9457 \color none
9458 _fsadd.c
9459 \end_inset 
9460 </cell>
9461 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9462 \begin_inset Text
9463
9464 \layout Standard
9465
9466
9467 \family roman 
9468 \series medium 
9469 \shape up 
9470 \size normal 
9471 \emph off 
9472 \bar no 
9473 \noun off 
9474 \color none
9475 add floating point numbers
9476 \end_inset 
9477 </cell>
9478 </row>
9479 <row topline="true">
9480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9481 \begin_inset Text
9482
9483 \layout Standard
9484
9485
9486 \family roman 
9487 \series medium 
9488 \shape up 
9489 \size normal 
9490 \emph off 
9491 \bar no 
9492 \noun off 
9493 \color none
9494 _fssub.c 
9495 \end_inset 
9496 </cell>
9497 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9498 \begin_inset Text
9499
9500 \layout Standard
9501
9502
9503 \family roman 
9504 \series medium 
9505 \shape up 
9506 \size normal 
9507 \emph off 
9508 \bar no 
9509 \noun off 
9510 \color none
9511 subtract floating point numbers 
9512 \end_inset 
9513 </cell>
9514 </row>
9515 <row topline="true">
9516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9517 \begin_inset Text
9518
9519 \layout Standard
9520
9521
9522 \family roman 
9523 \series medium 
9524 \shape up 
9525 \size normal 
9526 \emph off 
9527 \bar no 
9528 \noun off 
9529 \color none
9530 _fsdiv.c 
9531 \end_inset 
9532 </cell>
9533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9534 \begin_inset Text
9535
9536 \layout Standard
9537
9538
9539 \family roman 
9540 \series medium 
9541 \shape up 
9542 \size normal 
9543 \emph off 
9544 \bar no 
9545 \noun off 
9546 \color none
9547 divide floating point numbers 
9548 \end_inset 
9549 </cell>
9550 </row>
9551 <row topline="true">
9552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9553 \begin_inset Text
9554
9555 \layout Standard
9556
9557
9558 \family roman 
9559 \series medium 
9560 \shape up 
9561 \size normal 
9562 \emph off 
9563 \bar no 
9564 \noun off 
9565 \color none
9566 _fsmul.c 
9567 \end_inset 
9568 </cell>
9569 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9570 \begin_inset Text
9571
9572 \layout Standard
9573
9574
9575 \family roman 
9576 \series medium 
9577 \shape up 
9578 \size normal 
9579 \emph off 
9580 \bar no 
9581 \noun off 
9582 \color none
9583 multiply floating point numbers 
9584 \end_inset 
9585 </cell>
9586 </row>
9587 <row topline="true">
9588 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9589 \begin_inset Text
9590
9591 \layout Standard
9592
9593
9594 \family roman 
9595 \series medium 
9596 \shape up 
9597 \size normal 
9598 \emph off 
9599 \bar no 
9600 \noun off 
9601 \color none
9602 _fs2uchar.c
9603 \end_inset 
9604 </cell>
9605 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9606 \begin_inset Text
9607
9608 \layout Standard
9609
9610
9611 \family roman 
9612 \series medium 
9613 \shape up 
9614 \size normal 
9615 \emph off 
9616 \bar no 
9617 \noun off 
9618 \color none
9619 convert floating point to unsigned char
9620 \end_inset 
9621 </cell>
9622 </row>
9623 <row topline="true">
9624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9625 \begin_inset Text
9626
9627 \layout Standard
9628
9629
9630 \family roman 
9631 \series medium 
9632 \shape up 
9633 \size normal 
9634 \emph off 
9635 \bar no 
9636 \noun off 
9637 \color none
9638 _fs2char.c
9639 \end_inset 
9640 </cell>
9641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9642 \begin_inset Text
9643
9644 \layout Standard
9645
9646
9647 \family roman 
9648 \series medium 
9649 \shape up 
9650 \size normal 
9651 \emph off 
9652 \bar no 
9653 \noun off 
9654 \color none
9655 convert floating point to signed char
9656 \end_inset 
9657 </cell>
9658 </row>
9659 <row topline="true">
9660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9661 \begin_inset Text
9662
9663 \layout Standard
9664
9665
9666 \family roman 
9667 \series medium 
9668 \shape up 
9669 \size normal 
9670 \emph off 
9671 \bar no 
9672 \noun off 
9673 \color none
9674 _fs2uint.c
9675 \end_inset 
9676 </cell>
9677 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9678 \begin_inset Text
9679
9680 \layout Standard
9681
9682
9683 \family roman 
9684 \series medium 
9685 \shape up 
9686 \size normal 
9687 \emph off 
9688 \bar no 
9689 \noun off 
9690 \color none
9691 convert floating point to unsigned int
9692 \end_inset 
9693 </cell>
9694 </row>
9695 <row topline="true">
9696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9697 \begin_inset Text
9698
9699 \layout Standard
9700
9701
9702 \family roman 
9703 \series medium 
9704 \shape up 
9705 \size normal 
9706 \emph off 
9707 \bar no 
9708 \noun off 
9709 \color none
9710 _fs2int.c
9711 \end_inset 
9712 </cell>
9713 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9714 \begin_inset Text
9715
9716 \layout Standard
9717
9718
9719 \family roman 
9720 \series medium 
9721 \shape up 
9722 \size normal 
9723 \emph off 
9724 \bar no 
9725 \noun off 
9726 \color none
9727 convert floating point to signed int
9728 \end_inset 
9729 </cell>
9730 </row>
9731 <row topline="true">
9732 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9733 \begin_inset Text
9734
9735 \layout Standard
9736
9737
9738 \family roman 
9739 \series medium 
9740 \shape up 
9741 \size normal 
9742 \emph off 
9743 \bar no 
9744 \noun off 
9745 \color none
9746 _fs2ulong.
9747 \family default 
9748 \series default 
9749 \shape default 
9750 \size default 
9751 \emph default 
9752 \bar default 
9753 \noun default 
9754 \color default
9755 c
9756 \end_inset 
9757 </cell>
9758 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9759 \begin_inset Text
9760
9761 \layout Standard
9762
9763
9764 \family roman 
9765 \series medium 
9766 \shape up 
9767 \size normal 
9768 \emph off 
9769 \bar no 
9770 \noun off 
9771 \color none
9772 convert floating point to unsigned long
9773 \end_inset 
9774 </cell>
9775 </row>
9776 <row topline="true">
9777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9778 \begin_inset Text
9779
9780 \layout Standard
9781
9782
9783 \family roman 
9784 \series medium 
9785 \shape up 
9786 \size normal 
9787 \emph off 
9788 \bar no 
9789 \noun off 
9790 \color none
9791 _fs2long.c
9792 \end_inset 
9793 </cell>
9794 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9795 \begin_inset Text
9796
9797 \layout Standard
9798
9799
9800 \family roman 
9801 \series medium 
9802 \shape up 
9803 \size normal 
9804 \emph off 
9805 \bar no 
9806 \noun off 
9807 \color none
9808 convert floating point to signed long
9809 \end_inset 
9810 </cell>
9811 </row>
9812 <row topline="true">
9813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9814 \begin_inset Text
9815
9816 \layout Standard
9817
9818
9819 \family roman 
9820 \series medium 
9821 \shape up 
9822 \size normal 
9823 \emph off 
9824 \bar no 
9825 \noun off 
9826 \color none
9827 _uchar2fs.c
9828 \end_inset 
9829 </cell>
9830 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9831 \begin_inset Text
9832
9833 \layout Standard
9834
9835
9836 \family roman 
9837 \series medium 
9838 \shape up 
9839 \size normal 
9840 \emph off 
9841 \bar no 
9842 \noun off 
9843 \color none
9844 convert unsigned char to floating point
9845 \end_inset 
9846 </cell>
9847 </row>
9848 <row topline="true">
9849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9850 \begin_inset Text
9851
9852 \layout Standard
9853
9854
9855 \family roman 
9856 \series medium 
9857 \shape up 
9858 \size normal 
9859 \emph off 
9860 \bar no 
9861 \noun off 
9862 \color none
9863 _char2fs.c
9864 \end_inset 
9865 </cell>
9866 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9867 \begin_inset Text
9868
9869 \layout Standard
9870
9871
9872 \family roman 
9873 \series medium 
9874 \shape up 
9875 \size normal 
9876 \emph off 
9877 \bar no 
9878 \noun off 
9879 \color none
9880 convert char to floating point number
9881 \end_inset 
9882 </cell>
9883 </row>
9884 <row topline="true">
9885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9886 \begin_inset Text
9887
9888 \layout Standard
9889
9890
9891 \family roman 
9892 \series medium 
9893 \shape up 
9894 \size normal 
9895 \emph off 
9896 \bar no 
9897 \noun off 
9898 \color none
9899 _uint2fs.c
9900 \end_inset 
9901 </cell>
9902 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9903 \begin_inset Text
9904
9905 \layout Standard
9906
9907
9908 \family roman 
9909 \series medium 
9910 \shape up 
9911 \size normal 
9912 \emph off 
9913 \bar no 
9914 \noun off 
9915 \color none
9916 convert unsigned int to floating point
9917 \end_inset 
9918 </cell>
9919 </row>
9920 <row topline="true">
9921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9922 \begin_inset Text
9923
9924 \layout Standard
9925
9926
9927 \family roman 
9928 \series medium 
9929 \shape up 
9930 \size normal 
9931 \emph off 
9932 \bar no 
9933 \noun off 
9934 \color none
9935 _int2fs.c
9936 \end_inset 
9937 </cell>
9938 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9939 \begin_inset Text
9940
9941 \layout Standard
9942
9943
9944 \family roman 
9945 \series medium 
9946 \shape up 
9947 \size normal 
9948 \emph off 
9949 \bar no 
9950 \noun off 
9951 \color none
9952 convert int to floating point numbers
9953 \end_inset 
9954 </cell>
9955 </row>
9956 <row topline="true">
9957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9958 \begin_inset Text
9959
9960 \layout Standard
9961
9962
9963 \family roman 
9964 \series medium 
9965 \shape up 
9966 \size normal 
9967 \emph off 
9968 \bar no 
9969 \noun off 
9970 \color none
9971 _ulong2fs.c
9972 \end_inset 
9973 </cell>
9974 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9975 \begin_inset Text
9976
9977 \layout Standard
9978
9979
9980 \family roman 
9981 \series medium 
9982 \shape up 
9983 \size normal 
9984 \emph off 
9985 \bar no 
9986 \noun off 
9987 \color none
9988 convert unsigned long to floating point number
9989 \end_inset 
9990 </cell>
9991 </row>
9992 <row topline="true" bottomline="true">
9993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9994 \begin_inset Text
9995
9996 \layout Standard
9997
9998
9999 \family roman 
10000 \series medium 
10001 \shape up 
10002 \size normal 
10003 \emph off 
10004 \bar no 
10005 \noun off 
10006 \color none
10007 _long2fs.c
10008 \end_inset 
10009 </cell>
10010 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10011 \begin_inset Text
10012
10013 \layout Standard
10014
10015
10016 \family roman 
10017 \series medium 
10018 \shape up 
10019 \size normal 
10020 \emph off 
10021 \bar no 
10022 \noun off 
10023 \color none
10024 convert long to floating point number
10025 \end_inset 
10026 </cell>
10027 </row>
10028 </lyxtabular>
10029
10030 \end_inset 
10031
10032
10033 \newline 
10034
10035 \layout Standard
10036
10037 Note if all these routines are used simultaneously the data space might
10038  overflow.
10039  For serious floating point usage it is strongly recommended that the large
10040  model be used.
10041  Also notice that you don't have to call this routines directly.
10042  The compiler will use them automatically every time a floating point operation
10043  is required.
10044 \layout Subsection
10045
10046 MCS51 Memory Models
10047 \begin_inset LatexCommand \index{Memory model}
10048
10049 \end_inset 
10050
10051
10052 \begin_inset LatexCommand \index{MCS51 memory}
10053
10054 \end_inset 
10055
10056
10057 \layout Standard
10058
10059 SDCC allows two memory models for MCS51 code, 
10060 \shape slanted 
10061 small
10062 \shape default 
10063  and 
10064 \shape slanted 
10065 large
10066 \shape default 
10067 .
10068  Modules compiled with different memory models should 
10069 \emph on 
10070 never
10071 \emph default 
10072  be combined together or the results would be unpredictable.
10073  The library routines supplied with the compiler are compiled as both small
10074  and large.
10075  The compiled library modules are contained in separate directories as small
10076  and large so that you can link to either set.
10077  
10078 \layout Standard
10079
10080 When the large model is used all variables declared without a storage class
10081  will be allocated into the external ram, this includes all parameters and
10082  local variables (for non-reentrant
10083 \begin_inset LatexCommand \index{reentrant}
10084
10085 \end_inset 
10086
10087  functions).
10088  When the small model is used variables without storage class are allocated
10089  in the internal ram.
10090 \layout Standard
10091
10092 Judicious usage of the processor specific storage classes
10093 \begin_inset LatexCommand \index{Storage class}
10094
10095 \end_inset 
10096
10097  and the 'reentrant' function type will yield much more efficient code,
10098  than using the large model.
10099  Several optimizations are disabled when the program is compiled using the
10100  large model, it is therefore strongly recommended that the small model
10101  be used unless absolutely required.
10102 \layout Subsection
10103
10104 DS390 Memory Models
10105 \begin_inset LatexCommand \index{Memory model}
10106
10107 \end_inset 
10108
10109
10110 \begin_inset LatexCommand \index{DS390 memory model}
10111
10112 \end_inset 
10113
10114
10115 \layout Standard
10116
10117 The only model supported is Flat 24
10118 \begin_inset LatexCommand \index{Flat 24 (memory model)}
10119
10120 \end_inset 
10121
10122 .
10123  This generates code for the 24 bit contiguous addressing mode of the Dallas
10124  DS80C390 part.
10125  In this mode, up to four meg of external RAM or code space can be directly
10126  addressed.
10127  See the data sheets at www.dalsemi.com for further information on this part.
10128 \newline 
10129
10130 \newline 
10131 Note that the compiler does not generate any code to place the processor
10132  into 24 bitmode (although 
10133 \emph on 
10134 tinibios
10135 \emph default 
10136  in the ds390 libraries will do that for you).
10137  If you don't use 
10138 \emph on 
10139 tinibios
10140 \emph default 
10141
10142 \begin_inset LatexCommand \index{Tinibios (DS390)}
10143
10144 \end_inset 
10145
10146 , the boot loader or similar code must ensure that the processor is in 24
10147  bit contiguous addressing mode before calling the SDCC startup code.
10148 \newline 
10149
10150 \newline 
10151 Like the 
10152 \emph on 
10153 -
10154 \begin_inset ERT
10155 status Collapsed
10156
10157 \layout Standard
10158
10159 \backslash 
10160 /
10161 \end_inset 
10162
10163 -model-large
10164 \emph default 
10165  option, variables will by default be placed into the XDATA segment.
10166  
10167 \newline 
10168
10169 \newline 
10170 Segments may be placed anywhere in the 4 meg address space using the usual
10171  -
10172 \begin_inset ERT
10173 status Collapsed
10174
10175 \layout Standard
10176
10177 \backslash 
10178 /
10179 \end_inset 
10180
10181 -*-loc options.
10182  Note that if any segments are located above 64K, the -r flag must be passed
10183  to the linker to generate the proper segment relocations, and the Intel
10184  HEX output format must be used.
10185  The -r flag can be passed to the linker by using the option 
10186 \emph on 
10187 -Wl-r
10188 \emph default 
10189  on the sdcc command line.
10190  However, currently the linker can not handle code segments > 64k.
10191 \layout Subsection
10192
10193 Defines Created by the Compiler
10194 \begin_inset LatexCommand \index{Defines created by the compiler}
10195
10196 \end_inset 
10197
10198
10199 \layout Standard
10200
10201 The compiler creates the following #defines
10202 \begin_inset LatexCommand \index{\#defines}
10203
10204 \end_inset 
10205
10206 :
10207 \newline 
10208
10209 \layout Standard
10210
10211
10212 \begin_inset  Tabular
10213 <lyxtabular version="3" rows="10" columns="2">
10214 <features>
10215 <column alignment="center" valignment="top" leftline="true" width="0">
10216 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
10217 <row topline="true" bottomline="true">
10218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10219 \begin_inset Text
10220
10221 \layout Standard
10222
10223
10224 \series bold 
10225 #define
10226 \end_inset 
10227 </cell>
10228 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10229 \begin_inset Text
10230
10231 \layout Standard
10232
10233
10234 \series bold 
10235 Description
10236 \end_inset 
10237 </cell>
10238 </row>
10239 <row topline="true">
10240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10241 \begin_inset Text
10242
10243 \layout Standard
10244
10245 SDCC
10246 \begin_inset LatexCommand \index{SDCC}
10247
10248 \end_inset 
10249
10250  
10251 \end_inset 
10252 </cell>
10253 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10254 \begin_inset Text
10255
10256 \layout Standard
10257
10258 this Symbol is always defined
10259 \end_inset 
10260 </cell>
10261 </row>
10262 <row topline="true">
10263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10264 \begin_inset Text
10265
10266 \layout Standard
10267
10268 SDCC_mcs51
10269 \begin_inset LatexCommand \index{SDCC\_mcs51}
10270
10271 \end_inset 
10272
10273  or SDCC_ds390
10274 \begin_inset LatexCommand \index{SDCC\_ds390}
10275
10276 \end_inset 
10277
10278  or SDCC_z80
10279 \begin_inset LatexCommand \index{SDCC\_z80}
10280
10281 \end_inset 
10282
10283 , etc
10284 \end_inset 
10285 </cell>
10286 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10287 \begin_inset Text
10288
10289 \layout Standard
10290
10291 depending on the model used (e.g.: -mds390
10292 \end_inset 
10293 </cell>
10294 </row>
10295 <row topline="true">
10296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10297 \begin_inset Text
10298
10299 \layout Standard
10300
10301 __mcs51
10302 \begin_inset LatexCommand \index{\_\_mcs51}
10303
10304 \end_inset 
10305
10306  or __ds390
10307 \begin_inset LatexCommand \index{\_\_ds390}
10308
10309 \end_inset 
10310
10311  or __z80
10312 \begin_inset LatexCommand \index{\_\_z80}
10313
10314 \end_inset 
10315
10316 , etc
10317 \end_inset 
10318 </cell>
10319 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10320 \begin_inset Text
10321
10322 \layout Standard
10323
10324 depending on the model used (e.g.
10325  -mz80)
10326 \end_inset 
10327 </cell>
10328 </row>
10329 <row topline="true">
10330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10331 \begin_inset Text
10332
10333 \layout Standard
10334
10335 SDCC_STACK_AUTO
10336 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
10337
10338 \end_inset 
10339
10340
10341 \end_inset 
10342 </cell>
10343 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10344 \begin_inset Text
10345
10346 \layout Standard
10347
10348 when 
10349 \emph on 
10350 -
10351 \begin_inset ERT
10352 status Collapsed
10353
10354 \layout Standard
10355
10356 \backslash 
10357 /
10358 \end_inset 
10359
10360 -stack-auto
10361 \emph default 
10362  option is used
10363 \end_inset 
10364 </cell>
10365 </row>
10366 <row topline="true">
10367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10368 \begin_inset Text
10369
10370 \layout Standard
10371
10372 SDCC_MODEL_SMALL
10373 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
10374
10375 \end_inset 
10376
10377
10378 \end_inset 
10379 </cell>
10380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10381 \begin_inset Text
10382
10383 \layout Standard
10384
10385 when 
10386 \emph on 
10387 -
10388 \begin_inset ERT
10389 status Collapsed
10390
10391 \layout Standard
10392
10393 \backslash 
10394 /
10395 \end_inset 
10396
10397 -model-small
10398 \emph default 
10399  is used
10400 \end_inset 
10401 </cell>
10402 </row>
10403 <row topline="true">
10404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10405 \begin_inset Text
10406
10407 \layout Standard
10408
10409 SDCC_MODEL_LARGE
10410 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
10411
10412 \end_inset 
10413
10414
10415 \end_inset 
10416 </cell>
10417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10418 \begin_inset Text
10419
10420 \layout Standard
10421
10422 when 
10423 \emph on 
10424 -
10425 \begin_inset ERT
10426 status Collapsed
10427
10428 \layout Standard
10429
10430 \backslash 
10431 /
10432 \end_inset 
10433
10434 -model-large
10435 \emph default 
10436  is used
10437 \end_inset 
10438 </cell>
10439 </row>
10440 <row topline="true">
10441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10442 \begin_inset Text
10443
10444 \layout Standard
10445
10446 SDCC_USE_XSTACK
10447 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
10448
10449 \end_inset 
10450
10451
10452 \end_inset 
10453 </cell>
10454 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10455 \begin_inset Text
10456
10457 \layout Standard
10458
10459 when 
10460 \emph on 
10461 -
10462 \begin_inset ERT
10463 status Collapsed
10464
10465 \layout Standard
10466
10467 \backslash 
10468 /
10469 \end_inset 
10470
10471 -xstack
10472 \emph default 
10473  option is used
10474 \end_inset 
10475 </cell>
10476 </row>
10477 <row topline="true">
10478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10479 \begin_inset Text
10480
10481 \layout Standard
10482
10483 SDCC_STACK_TENBIT
10484 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
10485
10486 \end_inset 
10487
10488  
10489 \end_inset 
10490 </cell>
10491 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10492 \begin_inset Text
10493
10494 \layout Standard
10495
10496 when 
10497 \emph on 
10498 -mds390
10499 \emph default 
10500  is used
10501 \end_inset 
10502 </cell>
10503 </row>
10504 <row topline="true" bottomline="true">
10505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10506 \begin_inset Text
10507
10508 \layout Standard
10509
10510 SDCC_MODEL_FLAT24
10511 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
10512
10513 \end_inset 
10514
10515
10516 \end_inset 
10517 </cell>
10518 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10519 \begin_inset Text
10520
10521 \layout Standard
10522
10523 when 
10524 \emph on 
10525 -mds390
10526 \emph default 
10527  is used
10528 \end_inset 
10529 </cell>
10530 </row>
10531 </lyxtabular>
10532
10533 \end_inset 
10534
10535
10536 \newline 
10537
10538 \layout Subsection
10539
10540 Redirecting output on Windows Shells
10541 \layout Standard
10542
10543 By default SDCC writes it's error messages to 
10544 \begin_inset Quotes sld
10545 \end_inset 
10546
10547 standard error
10548 \begin_inset Quotes srd
10549 \end_inset 
10550
10551 .
10552  To force all messages to 
10553 \begin_inset Quotes sld
10554 \end_inset 
10555
10556 standard output
10557 \begin_inset Quotes srd
10558 \end_inset 
10559
10560  use 
10561 \series bold 
10562 -
10563 \series default 
10564 \emph on 
10565
10566 \begin_inset ERT
10567 status Collapsed
10568
10569 \layout Standard
10570
10571 \backslash 
10572 /
10573 \end_inset 
10574
10575
10576 \series bold 
10577 \emph default 
10578 -
10579 \series default 
10580 use-stdout
10581 \begin_inset LatexCommand \index{-\/-use-stdout}
10582
10583 \end_inset 
10584
10585 .
10586  Aditionaly, if you happen to have visual studio installed in your windows
10587  machine, you can use it to compile your sources using a custom build and
10588  the SDCC -
10589 \emph on 
10590
10591 \begin_inset ERT
10592 status Collapsed
10593
10594 \layout Standard
10595
10596 \backslash 
10597 /
10598 \end_inset 
10599
10600
10601 \emph default 
10602 -vc
10603 \begin_inset LatexCommand \index{-\/-vc}
10604
10605 \end_inset 
10606
10607  option.
10608  Something like this should work:
10609 \newline 
10610
10611 \newline 
10612
10613 \series bold 
10614 c:
10615 \backslash 
10616 sdcc
10617 \backslash 
10618 bin
10619 \backslash 
10620 sdcc.exe -
10621 \series default 
10622 \emph on 
10623
10624 \begin_inset ERT
10625 status Collapsed
10626
10627 \layout Standard
10628
10629 \backslash 
10630 /
10631 \end_inset 
10632
10633
10634 \series bold 
10635 \emph default 
10636 -vc -
10637 \series default 
10638 \emph on 
10639
10640 \begin_inset ERT
10641 status Collapsed
10642
10643 \layout Standard
10644
10645 \backslash 
10646 /
10647 \end_inset 
10648
10649
10650 \series bold 
10651 \emph default 
10652 -model-large -c $(InputPath)
10653 \layout Section
10654 \pagebreak_top 
10655 SDCC Technical Data
10656 \layout Subsection
10657
10658 Optimizations
10659 \begin_inset LatexCommand \index{Optimizations}
10660
10661 \end_inset 
10662
10663
10664 \layout Standard
10665
10666 SDCC performs a host of standard optimizations in addition to some MCU specific
10667  optimizations.
10668  
10669 \layout Subsubsection
10670
10671 Sub-expression Elimination
10672 \begin_inset LatexCommand \index{Subexpression elimination}
10673
10674 \end_inset 
10675
10676
10677 \layout Standard
10678
10679 The compiler does local and global common subexpression elimination, e.g.:
10680  
10681 \layout Verse
10682
10683
10684 \family typewriter 
10685 i = x + y + 1; 
10686 \newline 
10687 j = x + y;
10688 \layout Standard
10689
10690 will be translated to
10691 \layout Verse
10692
10693
10694 \family typewriter 
10695 iTemp = x + y; 
10696 \newline 
10697 i = iTemp + 1; 
10698 \newline 
10699 j = iTemp;
10700 \layout Standard
10701
10702 Some subexpressions are not as obvious as the above example, e.g.:
10703 \layout Verse
10704
10705
10706 \family typewriter 
10707 a->b[i].c = 10; 
10708 \newline 
10709 a->b[i].d = 11;
10710 \layout Standard
10711
10712 In this case the address arithmetic a->b[i] will be computed only once;
10713  the equivalent code in C would be.
10714 \layout Verse
10715
10716
10717 \family typewriter 
10718 iTemp = a->b[i]; 
10719 \newline 
10720 iTemp.c = 10; 
10721 \newline 
10722 iTemp.d = 11;
10723 \layout Standard
10724
10725 The compiler will try to keep these temporary variables in registers.
10726 \layout Subsubsection
10727
10728 Dead-Code Elimination
10729 \begin_inset LatexCommand \index{Dead-code elimination}
10730
10731 \end_inset 
10732
10733
10734 \layout Verse
10735
10736
10737 \family typewriter 
10738 int global;
10739 \newline 
10740
10741 \newline 
10742 void f () { 
10743 \newline 
10744 \SpecialChar ~
10745 \SpecialChar ~
10746 int i; 
10747 \newline 
10748 \SpecialChar ~
10749 \SpecialChar ~
10750 i = 1; \SpecialChar ~
10751 \SpecialChar ~
10752 \SpecialChar ~
10753 \SpecialChar ~
10754 \SpecialChar ~
10755 /* dead store */ 
10756 \newline 
10757 \SpecialChar ~
10758 \SpecialChar ~
10759 global = 1;\SpecialChar ~
10760 /* dead store */ 
10761 \newline 
10762 \SpecialChar ~
10763 \SpecialChar ~
10764 global = 2; 
10765 \newline 
10766 \SpecialChar ~
10767 \SpecialChar ~
10768 return; 
10769 \newline 
10770 \SpecialChar ~
10771 \SpecialChar ~
10772 global = 3;\SpecialChar ~
10773 /* unreachable */ 
10774 \newline 
10775 }
10776 \layout Standard
10777
10778 will be changed to
10779 \layout Verse
10780
10781
10782 \family typewriter 
10783 int global;
10784 \newline 
10785
10786 \newline 
10787 void f () {
10788 \newline 
10789 \SpecialChar ~
10790 \SpecialChar ~
10791 global = 2; 
10792 \newline 
10793 \SpecialChar ~
10794 \SpecialChar ~
10795 return; 
10796 \newline 
10797 }
10798 \layout Subsubsection
10799
10800 Copy-Propagation
10801 \begin_inset LatexCommand \index{Copy propagation}
10802
10803 \end_inset 
10804
10805
10806 \layout Verse
10807
10808
10809 \family typewriter 
10810 int f() { 
10811 \newline 
10812 \SpecialChar ~
10813 \SpecialChar ~
10814 int i, j; 
10815 \newline 
10816 \SpecialChar ~
10817 \SpecialChar ~
10818 i = 10; 
10819 \newline 
10820 \SpecialChar ~
10821 \SpecialChar ~
10822 j = i; 
10823 \newline 
10824 \SpecialChar ~
10825 \SpecialChar ~
10826 return j; 
10827 \newline 
10828 }
10829 \layout Standard
10830
10831 will be changed to 
10832 \layout Verse
10833
10834
10835 \family typewriter 
10836 int f() { 
10837 \newline 
10838 \SpecialChar ~
10839 \SpecialChar ~
10840 int i, j; 
10841 \newline 
10842 \SpecialChar ~
10843 \SpecialChar ~
10844 i = 10; 
10845 \newline 
10846 \SpecialChar ~
10847 \SpecialChar ~
10848 j = 10; 
10849 \newline 
10850 \SpecialChar ~
10851 \SpecialChar ~
10852 return 10; 
10853 \newline 
10854 }
10855 \layout Standard
10856
10857 Note: the dead stores created by this copy propagation will be eliminated
10858  by dead-code elimination.
10859 \layout Subsubsection
10860
10861 Loop Optimizations
10862 \begin_inset LatexCommand \index{Loop optimization}
10863
10864 \end_inset 
10865
10866
10867 \layout Standard
10868
10869 Two types of loop optimizations are done by SDCC loop invariant lifting
10870  and strength reduction of loop induction variables.
10871  In addition to the strength reduction the optimizer marks the induction
10872  variables and the register allocator tries to keep the induction variables
10873  in registers for the duration of the loop.
10874  Because of this preference of the register allocator
10875 \begin_inset LatexCommand \index{Register allocation}
10876
10877 \end_inset 
10878
10879 , loop induction optimization causes an increase in register pressure, which
10880  may cause unwanted spilling of other temporary variables into the stack
10881 \begin_inset LatexCommand \index{stack}
10882
10883 \end_inset 
10884
10885  / data space.
10886  The compiler will generate a warning message when it is forced to allocate
10887  extra space either on the stack or data space.
10888  If this extra space allocation is undesirable then induction optimization
10889  can be eliminated either for the entire source file (with -
10890 \begin_inset ERT
10891 status Collapsed
10892
10893 \layout Standard
10894
10895 \backslash 
10896 /
10897 \end_inset 
10898
10899 -noinduction option) or for a given function only using #pragma\SpecialChar ~
10900 NOINDUCTION
10901 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
10902
10903 \end_inset 
10904
10905 .
10906 \newline 
10907
10908 \newline 
10909 Loop Invariant:
10910 \layout Verse
10911
10912
10913 \family typewriter 
10914 for (i = 0 ; i < 100 ; i ++) 
10915 \newline 
10916 \SpecialChar ~
10917 \SpecialChar ~
10918 \SpecialChar ~
10919 \SpecialChar ~
10920 f += k + l;
10921 \layout Standard
10922
10923 changed to
10924 \layout Verse
10925
10926
10927 \family typewriter 
10928 itemp = k + l; 
10929 \newline 
10930 for (i = 0; i < 100; i++) 
10931 \newline 
10932 \SpecialChar ~
10933 \SpecialChar ~
10934 \SpecialChar ~
10935 \SpecialChar ~
10936 f += itemp;
10937 \layout Standard
10938
10939 As mentioned previously some loop invariants are not as apparent, all static
10940  address computations are also moved out of the loop.
10941 \newline 
10942
10943 \newline 
10944 Strength Reduction
10945 \begin_inset LatexCommand \index{Strength reduction}
10946
10947 \end_inset 
10948
10949 , this optimization substitutes an expression by a cheaper expression:
10950 \layout Verse
10951
10952
10953 \family typewriter 
10954 for (i=0;i < 100; i++)
10955 \newline 
10956 \SpecialChar ~
10957 \SpecialChar ~
10958 \SpecialChar ~
10959 \SpecialChar ~
10960 ar[i*5] = i*3;
10961 \layout Standard
10962
10963 changed to
10964 \layout Verse
10965
10966
10967 \family typewriter 
10968 itemp1 = 0; 
10969 \newline 
10970 itemp2 = 0; 
10971 \newline 
10972 for (i=0;i< 100;i++) { 
10973 \newline 
10974 \SpecialChar ~
10975 \SpecialChar ~
10976 \SpecialChar ~
10977 \SpecialChar ~
10978 ar[itemp1] = itemp2; 
10979 \newline 
10980 \SpecialChar ~
10981 \SpecialChar ~
10982 \SpecialChar ~
10983 \SpecialChar ~
10984 itemp1 += 5; 
10985 \newline 
10986 \SpecialChar ~
10987 \SpecialChar ~
10988 \SpecialChar ~
10989 \SpecialChar ~
10990 itemp2 += 3; 
10991 \newline 
10992 }
10993 \layout Standard
10994
10995 The more expensive multiplication
10996 \begin_inset LatexCommand \index{Multiplication}
10997
10998 \end_inset 
10999
11000  is changed to a less expensive addition.
11001 \layout Subsubsection
11002
11003 Loop Reversing
11004 \begin_inset LatexCommand \index{Loop reversing}
11005
11006 \end_inset 
11007
11008
11009 \layout Standard
11010
11011 This optimization is done to reduce the overhead of checking loop boundaries
11012  for every iteration.
11013  Some simple loops can be reversed and implemented using a 
11014 \begin_inset Quotes eld
11015 \end_inset 
11016
11017 decrement and jump if not zero
11018 \begin_inset Quotes erd
11019 \end_inset 
11020
11021  instruction.
11022  SDCC checks for the following criterion to determine if a loop is reversible
11023  (note: more sophisticated compilers use data-dependency analysis to make
11024  this determination, SDCC uses a more simple minded analysis).
11025 \layout Itemize
11026
11027 The 'for' loop is of the form 
11028 \newline 
11029
11030 \newline 
11031
11032 \family typewriter 
11033 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
11034  += 1])
11035 \newline 
11036 \SpecialChar ~
11037 \SpecialChar ~
11038 \SpecialChar ~
11039 \SpecialChar ~
11040 <for body>
11041 \layout Itemize
11042
11043 The <for body> does not contain 
11044 \begin_inset Quotes eld
11045 \end_inset 
11046
11047 continue
11048 \begin_inset Quotes erd
11049 \end_inset 
11050
11051  or 'break
11052 \begin_inset Quotes erd
11053 \end_inset 
11054
11055 .
11056 \layout Itemize
11057
11058 All goto's are contained within the loop.
11059 \layout Itemize
11060
11061 No function calls within the loop.
11062 \layout Itemize
11063
11064 The loop control variable <sym> is not assigned any value within the loop
11065 \layout Itemize
11066
11067 The loop control variable does NOT participate in any arithmetic operation
11068  within the loop.
11069 \layout Itemize
11070
11071 There are NO switch statements in the loop.
11072 \layout Subsubsection
11073
11074 Algebraic Simplifications
11075 \layout Standard
11076
11077 SDCC does numerous algebraic simplifications, the following is a small sub-set
11078  of these optimizations.
11079 \layout Verse
11080
11081
11082 \family typewriter 
11083 i = j + 0 ; /* changed to */ i = j; 
11084 \newline 
11085 i /= 2;\SpecialChar ~
11086 \SpecialChar ~
11087 \SpecialChar ~
11088 \SpecialChar ~
11089  /* changed to */ i >>= 1; 
11090 \newline 
11091 i = j - j ; /* changed to */ i = 0; 
11092 \newline 
11093 i = j / 1 ; /* changed to */ i = j;
11094 \layout Standard
11095
11096 Note the subexpressions
11097 \begin_inset LatexCommand \index{Subexpression}
11098
11099 \end_inset 
11100
11101  given above are generally introduced by macro expansions or as a result
11102  of copy/constant propagation.
11103 \layout Subsubsection
11104
11105 'switch' Statements
11106 \begin_inset LatexCommand \index{switch statement}
11107
11108 \end_inset 
11109
11110
11111 \layout Standard
11112
11113 SDCC changes switch statements to jump tables
11114 \begin_inset LatexCommand \index{jump tables}
11115
11116 \end_inset 
11117
11118  when the following conditions are true.
11119  
11120 \layout Itemize
11121
11122 The case labels are in numerical sequence, the labels need not be in order,
11123  and the starting number need not be one or zero.
11124 \begin_deeper 
11125 \layout Verse
11126
11127
11128 \family typewriter 
11129 switch(i) {\SpecialChar ~
11130 \SpecialChar ~
11131 \SpecialChar ~
11132 \SpecialChar ~
11133 \SpecialChar ~
11134 \SpecialChar ~
11135 \SpecialChar ~
11136 \SpecialChar ~
11137 \SpecialChar ~
11138 \SpecialChar ~
11139 \SpecialChar ~
11140 \SpecialChar ~
11141 \SpecialChar ~
11142 \SpecialChar ~
11143 \SpecialChar ~
11144 \SpecialChar ~
11145 \SpecialChar ~
11146 \SpecialChar ~
11147 \SpecialChar ~
11148 \SpecialChar ~
11149 \SpecialChar ~
11150 \SpecialChar ~
11151 \SpecialChar ~
11152 \SpecialChar ~
11153 \SpecialChar ~
11154 \SpecialChar ~
11155 switch (i) { 
11156 \newline 
11157 \SpecialChar ~
11158 \SpecialChar ~
11159 \SpecialChar ~
11160 case 4: ...\SpecialChar ~
11161 \SpecialChar ~
11162 \SpecialChar ~
11163 \SpecialChar ~
11164 \SpecialChar ~
11165 \SpecialChar ~
11166 \SpecialChar ~
11167 \SpecialChar ~
11168 \SpecialChar ~
11169 \SpecialChar ~
11170 \SpecialChar ~
11171 \SpecialChar ~
11172 \SpecialChar ~
11173 \SpecialChar ~
11174 \SpecialChar ~
11175 \SpecialChar ~
11176 \SpecialChar ~
11177 \SpecialChar ~
11178 \SpecialChar ~
11179 \SpecialChar ~
11180 \SpecialChar ~
11181 \SpecialChar ~
11182 \SpecialChar ~
11183 \SpecialChar ~
11184 \SpecialChar ~
11185 \SpecialChar ~
11186 case 0: ...
11187  
11188 \newline 
11189 \SpecialChar ~
11190 \SpecialChar ~
11191 \SpecialChar ~
11192 case 5: ...\SpecialChar ~
11193 \SpecialChar ~
11194 \SpecialChar ~
11195 \SpecialChar ~
11196 \SpecialChar ~
11197 \SpecialChar ~
11198 \SpecialChar ~
11199 \SpecialChar ~
11200 \SpecialChar ~
11201 \SpecialChar ~
11202 \SpecialChar ~
11203 \SpecialChar ~
11204 \SpecialChar ~
11205 \SpecialChar ~
11206 \SpecialChar ~
11207 \SpecialChar ~
11208 \SpecialChar ~
11209 \SpecialChar ~
11210 \SpecialChar ~
11211 \SpecialChar ~
11212 \SpecialChar ~
11213 \SpecialChar ~
11214 \SpecialChar ~
11215 \SpecialChar ~
11216 \SpecialChar ~
11217 \SpecialChar ~
11218 case 1: ...
11219  
11220 \newline 
11221 \SpecialChar ~
11222 \SpecialChar ~
11223 \SpecialChar ~
11224 case 3: ...\SpecialChar ~
11225 \SpecialChar ~
11226 \SpecialChar ~
11227 \SpecialChar ~
11228 \SpecialChar ~
11229 \SpecialChar ~
11230 \SpecialChar ~
11231 \SpecialChar ~
11232 \SpecialChar ~
11233 \SpecialChar ~
11234 \SpecialChar ~
11235 \SpecialChar ~
11236 \SpecialChar ~
11237 \SpecialChar ~
11238 \SpecialChar ~
11239 \SpecialChar ~
11240 \SpecialChar ~
11241 \SpecialChar ~
11242 \SpecialChar ~
11243 \SpecialChar ~
11244 \SpecialChar ~
11245 \SpecialChar ~
11246 \SpecialChar ~
11247 \SpecialChar ~
11248 \SpecialChar ~
11249 \SpecialChar ~
11250 case 2: ...
11251  
11252 \newline 
11253 \SpecialChar ~
11254 \SpecialChar ~
11255 \SpecialChar ~
11256 case 6: ...\SpecialChar ~
11257 \SpecialChar ~
11258 \SpecialChar ~
11259 \SpecialChar ~
11260 \SpecialChar ~
11261 \SpecialChar ~
11262 \SpecialChar ~
11263 \SpecialChar ~
11264 \SpecialChar ~
11265 \SpecialChar ~
11266 \SpecialChar ~
11267 \SpecialChar ~
11268 \SpecialChar ~
11269 \SpecialChar ~
11270 \SpecialChar ~
11271 \SpecialChar ~
11272 \SpecialChar ~
11273 \SpecialChar ~
11274 \SpecialChar ~
11275 \SpecialChar ~
11276 \SpecialChar ~
11277 \SpecialChar ~
11278 \SpecialChar ~
11279 \SpecialChar ~
11280 \SpecialChar ~
11281 \SpecialChar ~
11282 case 3: ...
11283  
11284 \newline 
11285 }\SpecialChar ~
11286 \SpecialChar ~
11287 \SpecialChar ~
11288 \SpecialChar ~
11289 \SpecialChar ~
11290 \SpecialChar ~
11291 \SpecialChar ~
11292 \SpecialChar ~
11293 \SpecialChar ~
11294 \SpecialChar ~
11295 \SpecialChar ~
11296 \SpecialChar ~
11297 \SpecialChar ~
11298 \SpecialChar ~
11299 \SpecialChar ~
11300 \SpecialChar ~
11301 \SpecialChar ~
11302 \SpecialChar ~
11303 \SpecialChar ~
11304 \SpecialChar ~
11305 \SpecialChar ~
11306 \SpecialChar ~
11307 \SpecialChar ~
11308 \SpecialChar ~
11309 \SpecialChar ~
11310 \SpecialChar ~
11311 \SpecialChar ~
11312 \SpecialChar ~
11313 \SpecialChar ~
11314 \SpecialChar ~
11315 \SpecialChar ~
11316 \SpecialChar ~
11317 \SpecialChar ~
11318 \SpecialChar ~
11319 \SpecialChar ~
11320 \SpecialChar ~
11321 }
11322 \layout Standard
11323
11324 Both the above switch statements will be implemented using a jump-table.
11325  The example to the right side is slightly more efficient as the check for
11326  the lower bound of the jump-table is not needed.
11327 \end_deeper 
11328 \layout Itemize
11329
11330 The number of case labels is at least three, since it takes two conditional
11331  statements to handle the boundary conditions.
11332 \layout Itemize
11333
11334 The number of case labels is less than 84, since each label takes 3 bytes
11335  and a jump-table can be utmost 256 bytes long.
11336 \layout Standard
11337
11338 Switch statements which have gaps in the numeric sequence or those that
11339  have more that 84 case labels can be split into more than one switch statement
11340  for efficient code generation, e.g.:
11341 \layout Verse
11342
11343
11344 \family typewriter 
11345 switch (i) { 
11346 \newline 
11347 \SpecialChar ~
11348 \SpecialChar ~
11349 case 1: ...
11350  
11351 \newline 
11352 \SpecialChar ~
11353 \SpecialChar ~
11354 case 2: ...
11355  
11356 \newline 
11357 \SpecialChar ~
11358 \SpecialChar ~
11359 case 3: ...
11360  
11361 \newline 
11362 \SpecialChar ~
11363 \SpecialChar ~
11364 case 4: ...
11365  
11366 \newline 
11367 \SpecialChar ~
11368 \SpecialChar ~
11369 case 9: ...
11370  
11371 \newline 
11372 \SpecialChar ~
11373 \SpecialChar ~
11374 case 10: ...
11375  
11376 \newline 
11377 \SpecialChar ~
11378 \SpecialChar ~
11379 case 11: ...
11380  
11381 \newline 
11382 \SpecialChar ~
11383 \SpecialChar ~
11384 case 12: ...
11385  
11386 \newline 
11387 }
11388 \layout Standard
11389
11390 If the above switch statement is broken down into two switch statements
11391 \layout Verse
11392
11393
11394 \family typewriter 
11395 switch (i) { 
11396 \newline 
11397 \SpecialChar ~
11398 \SpecialChar ~
11399 case 1: ...
11400  
11401 \newline 
11402 \SpecialChar ~
11403 \SpecialChar ~
11404 case 2: ...
11405  
11406 \newline 
11407 \SpecialChar ~
11408 \SpecialChar ~
11409 case 3: ...
11410  
11411 \newline 
11412 \SpecialChar ~
11413 \SpecialChar ~
11414 case 4: ...
11415  
11416 \newline 
11417 }
11418 \layout Standard
11419
11420 and
11421 \layout Verse
11422
11423
11424 \family typewriter 
11425 switch (i) { 
11426 \newline 
11427 \SpecialChar ~
11428 \SpecialChar ~
11429 case 9: \SpecialChar ~
11430 ...
11431  
11432 \newline 
11433 \SpecialChar ~
11434 \SpecialChar ~
11435 case 10: ...
11436  
11437 \newline 
11438 \SpecialChar ~
11439 \SpecialChar ~
11440 case 11: ...
11441  
11442 \newline 
11443 \SpecialChar ~
11444 \SpecialChar ~
11445 case 12:\SpecialChar ~
11446 ...
11447  
11448 \newline 
11449 }
11450 \layout Standard
11451
11452 then both the switch statements will be implemented using jump-tables whereas
11453  the unmodified switch statement will not be.
11454  You might also consider dummy cases 0 and 5 to 8 in this example.
11455  The pragma NOJTBOUND
11456 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
11457
11458 \end_inset 
11459
11460  can be used to turn off checking the 
11461 \emph on 
11462 j
11463 \emph default 
11464 ump 
11465 \emph on 
11466 t
11467 \emph default 
11468 able 
11469 \emph on 
11470 bound
11471 \emph default 
11472 aries.
11473 \layout Subsubsection
11474
11475 Bit-shifting Operations
11476 \begin_inset LatexCommand \index{Bit shifting}
11477
11478 \end_inset 
11479
11480 .
11481 \layout Standard
11482
11483 Bit shifting is one of the most frequently used operation in embedded programmin
11484 g.
11485  SDCC tries to implement bit-shift operations in the most efficient way
11486  possible, e.g.:
11487 \layout Verse
11488
11489
11490 \family typewriter 
11491 unsigned char i;
11492 \newline 
11493 ...
11494  
11495 \newline 
11496 i >>= 4; 
11497 \newline 
11498 ...
11499 \layout Standard
11500
11501 generates the following code:
11502 \layout Verse
11503
11504
11505 \family typewriter 
11506 mov a,_i 
11507 \newline 
11508 swap a 
11509 \newline 
11510 anl a,#0x0f 
11511 \newline 
11512 mov _i,a
11513 \layout Standard
11514
11515 In general SDCC will never setup a loop if the shift count is known.
11516  Another example:
11517 \layout Verse
11518
11519
11520 \family typewriter 
11521 unsigned int i; 
11522 \newline 
11523 ...
11524  
11525 \newline 
11526 i >>= 9; 
11527 \newline 
11528 ...
11529 \layout Standard
11530
11531 will generate:
11532 \layout Verse
11533
11534
11535 \family typewriter 
11536 mov\SpecialChar ~
11537 \SpecialChar ~
11538 a,(_i + 1) 
11539 \newline 
11540 mov\SpecialChar ~
11541 \SpecialChar ~
11542 (_i + 1),#0x00 
11543 \newline 
11544 clr\SpecialChar ~
11545 \SpecialChar ~
11546
11547 \newline 
11548 rrc\SpecialChar ~
11549 \SpecialChar ~
11550
11551 \newline 
11552 mov\SpecialChar ~
11553 \SpecialChar ~
11554 _i,a
11555 \layout Standard
11556
11557 Note that SDCC stores numbers in little-endian format (i.e.
11558  lowest order first).
11559 \layout Subsubsection
11560
11561 Bit-rotation
11562 \begin_inset LatexCommand \index{Bit rotation}
11563
11564 \end_inset 
11565
11566
11567 \layout Standard
11568
11569 A special case of the bit-shift operation is bit rotation, SDCC recognizes
11570  the following expression to be a left bit-rotation:
11571 \layout Verse
11572
11573
11574 \family typewriter 
11575 unsigned char i; 
11576 \newline 
11577 ...
11578  
11579 \newline 
11580 i = ((i << 1) | (i >> 7)); 
11581 \family default 
11582
11583 \newline 
11584
11585 \family typewriter 
11586 ...
11587 \layout Standard
11588
11589 will generate the following code:
11590 \layout Verse
11591
11592
11593 \family typewriter 
11594 mov\SpecialChar ~
11595 \SpecialChar ~
11596 a,_i 
11597 \newline 
11598 rl\SpecialChar ~
11599 \SpecialChar ~
11600 \SpecialChar ~
11601
11602 \newline 
11603 mov\SpecialChar ~
11604 \SpecialChar ~
11605 _i,a
11606 \layout Standard
11607
11608 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
11609 ns of this case will also be recognized as bit-rotation, i.e.: 
11610 \layout Verse
11611
11612
11613 \family typewriter 
11614 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
11615 \layout Subsubsection
11616
11617 Highest Order Bit
11618 \begin_inset LatexCommand \index{Highest Order Bit}
11619
11620 \end_inset 
11621
11622
11623 \layout Standard
11624
11625 It is frequently required to obtain the highest order bit of an integral
11626  type (long, int, short or char types).
11627  SDCC recognizes the following expression to yield the highest order bit
11628  and generates optimized code for it, e.g.:
11629 \layout Verse
11630
11631
11632 \family typewriter 
11633 unsigned int gint; 
11634 \newline 
11635
11636 \newline 
11637 foo () { 
11638 \newline 
11639 \SpecialChar ~
11640 \SpecialChar ~
11641 unsigned char hob; 
11642 \newline 
11643 \SpecialChar ~
11644 \SpecialChar ~
11645 ...
11646  
11647 \newline 
11648 \SpecialChar ~
11649 \SpecialChar ~
11650 hob = (gint >> 15) & 1; 
11651 \newline 
11652 \SpecialChar ~
11653 \SpecialChar ~
11654 ..
11655  
11656 \newline 
11657 }
11658 \layout Standard
11659
11660 will generate the following code:
11661 \layout Verse
11662
11663
11664 \family typewriter 
11665 \SpecialChar ~
11666 \SpecialChar ~
11667 \SpecialChar ~
11668 \SpecialChar ~
11669 \SpecialChar ~
11670 \SpecialChar ~
11671 \SpecialChar ~
11672 \SpecialChar ~
11673 \SpecialChar ~
11674 \SpecialChar ~
11675 \SpecialChar ~
11676 \SpecialChar ~
11677 \SpecialChar ~
11678 \SpecialChar ~
11679 \SpecialChar ~
11680 \SpecialChar ~
11681 \SpecialChar ~
11682 \SpecialChar ~
11683 \SpecialChar ~
11684 \SpecialChar ~
11685 \SpecialChar ~
11686 \SpecialChar ~
11687 \SpecialChar ~
11688 \SpecialChar ~
11689 \SpecialChar ~
11690  61 ;\SpecialChar ~
11691  hob.c 7 
11692 \newline 
11693 000A E5*01\SpecialChar ~
11694 \SpecialChar ~
11695 \SpecialChar ~
11696 \SpecialChar ~
11697 \SpecialChar ~
11698 \SpecialChar ~
11699 \SpecialChar ~
11700 \SpecialChar ~
11701 \SpecialChar ~
11702 \SpecialChar ~
11703 \SpecialChar ~
11704 \SpecialChar ~
11705 \SpecialChar ~
11706 \SpecialChar ~
11707 \SpecialChar ~
11708  62\SpecialChar ~
11709 \SpecialChar ~
11710 \SpecialChar ~
11711 \SpecialChar ~
11712 \SpecialChar ~
11713 \SpecialChar ~
11714 \SpecialChar ~
11715 \SpecialChar ~
11716  mov\SpecialChar ~
11717 \SpecialChar ~
11718  a,(_gint + 1) 
11719 \newline 
11720 000C 23\SpecialChar ~
11721 \SpecialChar ~
11722 \SpecialChar ~
11723 \SpecialChar ~
11724 \SpecialChar ~
11725 \SpecialChar ~
11726 \SpecialChar ~
11727 \SpecialChar ~
11728 \SpecialChar ~
11729 \SpecialChar ~
11730 \SpecialChar ~
11731 \SpecialChar ~
11732 \SpecialChar ~
11733 \SpecialChar ~
11734 \SpecialChar ~
11735 \SpecialChar ~
11736 \SpecialChar ~
11737 \SpecialChar ~
11738  63\SpecialChar ~
11739 \SpecialChar ~
11740 \SpecialChar ~
11741 \SpecialChar ~
11742 \SpecialChar ~
11743 \SpecialChar ~
11744 \SpecialChar ~
11745 \SpecialChar ~
11746  rl\SpecialChar ~
11747 \SpecialChar ~
11748 \SpecialChar ~
11749  a 
11750 \newline 
11751 000D 54 01\SpecialChar ~
11752 \SpecialChar ~
11753 \SpecialChar ~
11754 \SpecialChar ~
11755 \SpecialChar ~
11756 \SpecialChar ~
11757 \SpecialChar ~
11758 \SpecialChar ~
11759 \SpecialChar ~
11760 \SpecialChar ~
11761 \SpecialChar ~
11762 \SpecialChar ~
11763 \SpecialChar ~
11764 \SpecialChar ~
11765 \SpecialChar ~
11766  64\SpecialChar ~
11767 \SpecialChar ~
11768 \SpecialChar ~
11769 \SpecialChar ~
11770 \SpecialChar ~
11771 \SpecialChar ~
11772 \SpecialChar ~
11773 \SpecialChar ~
11774  anl\SpecialChar ~
11775 \SpecialChar ~
11776  a,#0x01 
11777 \newline 
11778 000F F5*02\SpecialChar ~
11779 \SpecialChar ~
11780 \SpecialChar ~
11781 \SpecialChar ~
11782 \SpecialChar ~
11783 \SpecialChar ~
11784 \SpecialChar ~
11785 \SpecialChar ~
11786 \SpecialChar ~
11787 \SpecialChar ~
11788 \SpecialChar ~
11789 \SpecialChar ~
11790 \SpecialChar ~
11791 \SpecialChar ~
11792 \SpecialChar ~
11793  65\SpecialChar ~
11794 \SpecialChar ~
11795 \SpecialChar ~
11796 \SpecialChar ~
11797 \SpecialChar ~
11798 \SpecialChar ~
11799 \SpecialChar ~
11800 \SpecialChar ~
11801  mov\SpecialChar ~
11802 \SpecialChar ~
11803  _foo_hob_1_1,a
11804 \layout Standard
11805
11806 Variations of this case however will 
11807 \emph on 
11808 not
11809 \emph default 
11810  be recognized.
11811  It is a standard C expression, so I heartily recommend this be the only
11812  way to get the highest order bit, (it is portable).
11813  Of course it will be recognized even if it is embedded in other expressions,
11814  e.g.:
11815 \layout Verse
11816
11817
11818 \family typewriter 
11819 xyz = gint + ((gint >> 15) & 1);
11820 \layout Standard
11821
11822 will still be recognized.
11823 \layout Subsubsection
11824
11825 Peephole Optimizer
11826 \begin_inset LatexCommand \index{Peephole optimizer}
11827
11828 \end_inset 
11829
11830
11831 \layout Standard
11832
11833 The compiler uses a rule based, pattern matching and re-writing mechanism
11834  for peep-hole optimization.
11835  It is inspired by 
11836 \emph on 
11837 copt
11838 \emph default 
11839  a peep-hole optimizer by Christopher W.
11840  Fraser (cwfraser@microsoft.com).
11841  A default set of rules are compiled into the compiler, additional rules
11842  may be added with the 
11843 \emph on 
11844 -
11845 \begin_inset ERT
11846 status Collapsed
11847
11848 \layout Standard
11849
11850 \backslash 
11851 /
11852 \end_inset 
11853
11854 -peep-file
11855 \begin_inset LatexCommand \index{-\/-peep-file}
11856
11857 \end_inset 
11858
11859  <filename>
11860 \emph default 
11861  option.
11862  The rule language is best illustrated with examples.
11863 \layout Verse
11864
11865
11866 \family typewriter 
11867 replace { 
11868 \newline 
11869 \SpecialChar ~
11870 \SpecialChar ~
11871 mov %1,a 
11872 \newline 
11873 \SpecialChar ~
11874 \SpecialChar ~
11875 mov a,%1
11876 \newline 
11877 } by {
11878 \newline 
11879 \SpecialChar ~
11880 \SpecialChar ~
11881 mov %1,a
11882 \newline 
11883 }
11884 \layout Standard
11885
11886 The above rule will change the following assembly
11887 \begin_inset LatexCommand \index{Assembler routines}
11888
11889 \end_inset 
11890
11891  sequence:
11892 \layout Verse
11893
11894
11895 \family typewriter 
11896 mov r1,a 
11897 \newline 
11898 mov a,r1
11899 \layout Standard
11900
11901 to
11902 \layout Verse
11903
11904
11905 \family typewriter 
11906 mov r1,a
11907 \layout Standard
11908
11909 Note: All occurrences of a 
11910 \emph on 
11911 %n
11912 \emph default 
11913  (pattern variable) must denote the same string.
11914  With the above rule, the assembly sequence:
11915 \layout Verse
11916
11917
11918 \family typewriter 
11919 mov r1,a 
11920 \newline 
11921 mov a,r2
11922 \layout Standard
11923
11924 will remain unmodified.
11925 \newline 
11926
11927 \newline 
11928 Other special case optimizations may be added by the user (via 
11929 \emph on 
11930 -
11931 \begin_inset ERT
11932 status Collapsed
11933
11934 \layout Standard
11935
11936 \backslash 
11937 /
11938 \end_inset 
11939
11940 -peep-file option
11941 \emph default 
11942 ).
11943  E.g.
11944  some variants of the 8051 MCU allow only 
11945 \family typewriter 
11946 ajmp
11947 \family default 
11948  and 
11949 \family typewriter 
11950 acall
11951 \family default 
11952 .
11953  The following two rules will change all 
11954 \family typewriter 
11955 ljmp
11956 \family default 
11957  and 
11958 \family typewriter 
11959 lcall
11960 \family default 
11961  to 
11962 \family typewriter 
11963 ajmp
11964 \family default 
11965  and 
11966 \family typewriter 
11967 acall
11968 \layout Verse
11969
11970
11971 \family typewriter 
11972 replace { lcall %1 } by { acall %1 } 
11973 \newline 
11974 replace { ljmp %1 } by { ajmp %1 }
11975 \layout Standard
11976
11977 The 
11978 \emph on 
11979 inline-assembler code
11980 \emph default 
11981  is also passed through the peep hole optimizer, thus the peephole optimizer
11982  can also be used as an assembly level macro expander.
11983  The rules themselves are MCU dependent whereas the rule language infra-structur
11984 e is MCU independent.
11985  Peephole optimization rules for other MCU can be easily programmed using
11986  the rule language.
11987 \newline 
11988
11989 \newline 
11990 The syntax for a rule is as follows:
11991 \layout Verse
11992
11993
11994 \family typewriter 
11995 rule := replace [ restart ] '{' <assembly sequence> '
11996 \backslash 
11997 n' 
11998 \newline 
11999 \SpecialChar ~
12000  \SpecialChar ~
12001  \SpecialChar ~
12002  \SpecialChar ~
12003  \SpecialChar ~
12004  \SpecialChar ~
12005  \SpecialChar ~
12006  \SpecialChar ~
12007  \SpecialChar ~
12008  \SpecialChar ~
12009  \SpecialChar ~
12010  \SpecialChar ~
12011  \SpecialChar ~
12012  \SpecialChar ~
12013  '}' by '{' '
12014 \backslash 
12015 n' 
12016 \newline 
12017 \SpecialChar ~
12018  \SpecialChar ~
12019  \SpecialChar ~
12020  \SpecialChar ~
12021  \SpecialChar ~
12022  \SpecialChar ~
12023  \SpecialChar ~
12024  \SpecialChar ~
12025  \SpecialChar ~
12026  \SpecialChar ~
12027  \SpecialChar ~
12028  \SpecialChar ~
12029  \SpecialChar ~
12030  \SpecialChar ~
12031  \SpecialChar ~
12032  \SpecialChar ~
12033  <assembly sequence> '
12034 \backslash 
12035 n' 
12036 \newline 
12037 \SpecialChar ~
12038  \SpecialChar ~
12039  \SpecialChar ~
12040  \SpecialChar ~
12041  \SpecialChar ~
12042  \SpecialChar ~
12043  \SpecialChar ~
12044  \SpecialChar ~
12045  \SpecialChar ~
12046  \SpecialChar ~
12047  \SpecialChar ~
12048  \SpecialChar ~
12049  \SpecialChar ~
12050  \SpecialChar ~
12051  '}' [if <functionName> ] '
12052 \backslash 
12053 n' 
12054 \layout Standard
12055
12056 <assembly sequence> := assembly instruction (each instruction including
12057  labels must be on a separate line).
12058 \newline 
12059
12060 \newline 
12061 The optimizer will apply to the rules one by one from the top in the sequence
12062  of their appearance, it will terminate when all rules are exhausted.
12063  If the 'restart' option is specified, then the optimizer will start matching
12064  the rules again from the top, this option for a rule is expensive (performance)
12065 , it is intended to be used in situations where a transformation will trigger
12066  the same rule again.
12067  An example of this (not a good one, it has side effects) is the following
12068  rule:
12069 \layout Verse
12070
12071
12072 \family typewriter 
12073 replace restart { 
12074 \newline 
12075 \SpecialChar ~
12076 \SpecialChar ~
12077 pop %1 
12078 \newline 
12079 \SpecialChar ~
12080 \SpecialChar ~
12081 push %1 } by { 
12082 \newline 
12083 \SpecialChar ~
12084 \SpecialChar ~
12085 ; nop 
12086 \newline 
12087 }
12088 \layout Standard
12089
12090 Note that the replace pattern cannot be a blank, but can be a comment line.
12091  Without the 'restart' option only the inner most 'pop' 'push' pair would
12092  be eliminated, i.e.:
12093 \layout Verse
12094
12095
12096 \family typewriter 
12097 pop ar1 
12098 \newline 
12099 pop ar2 
12100 \newline 
12101 push ar2 
12102 \newline 
12103 push ar1
12104 \layout Standard
12105
12106 would result in:
12107 \layout Verse
12108
12109
12110 \family typewriter 
12111 pop ar1 
12112 \newline 
12113 ; nop 
12114 \newline 
12115 push ar1
12116 \layout Standard
12117
12118
12119 \emph on 
12120 with
12121 \emph default 
12122  the restart option the rule will be applied again to the resulting code
12123  and then all the pop-push pairs will be eliminated to yield:
12124 \layout Verse
12125
12126
12127 \family typewriter 
12128 ; nop 
12129 \newline 
12130 ; nop
12131 \layout Standard
12132
12133 A conditional function can be attached to a rule.
12134  Attaching rules are somewhat more involved, let me illustrate this with
12135  an example.
12136 \layout Verse
12137
12138
12139 \family typewriter 
12140 replace { 
12141 \newline 
12142 \SpecialChar ~
12143  \SpecialChar ~
12144  \SpecialChar ~
12145 ljmp %5 
12146 \newline 
12147 %2:
12148 \newline 
12149 } by { 
12150 \newline 
12151 \SpecialChar ~
12152  \SpecialChar ~
12153  \SpecialChar ~
12154 sjmp %5 
12155 \newline 
12156 %2:
12157 \newline 
12158 } if labelInRange
12159 \layout Standard
12160
12161 The optimizer does a look-up of a function name table defined in function
12162  
12163 \emph on 
12164 callFuncByName
12165 \emph default 
12166  in the source file SDCCpeeph.c, with the name 
12167 \emph on 
12168 labelInRange
12169 \emph default 
12170 .
12171  If it finds a corresponding entry the function is called.
12172  Note there can be no parameters specified for these functions, in this
12173  case the use of 
12174 \emph on 
12175 %5
12176 \emph default 
12177  is crucial, since the function 
12178 \emph on 
12179 labelInRange
12180 \emph default 
12181  expects to find the label in that particular variable (the hash table containin
12182 g the variable bindings is passed as a parameter).
12183  If you want to code more such functions, take a close look at the function
12184  labelInRange and the calling mechanism in source file SDCCpeeph.c.
12185  Currently implemented are 
12186 \emph on 
12187 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
12188  24bitMode, portIsDS390, 24bitModeAndPortDS390 
12189 \emph default 
12190 and
12191 \emph on 
12192  notVolatile
12193 \emph default 
12194 .
12195 \layout Standard
12196
12197 I know this whole thing is a little kludgey, but maybe some day we will
12198  have some better means.
12199  If you are looking at this file, you will see the default rules that are
12200  compiled into the compiler, you can add your own rules in the default set
12201  there if you get tired of specifying the -
12202 \begin_inset ERT
12203 status Collapsed
12204
12205 \layout Standard
12206
12207 \backslash 
12208 /
12209 \end_inset 
12210
12211 -peep-file option.
12212 \layout Subsection
12213
12214 Pragmas
12215 \begin_inset LatexCommand \index{Pragmas}
12216
12217 \end_inset 
12218
12219
12220 \layout Standard
12221
12222 SDCC supports the following #pragma directives.
12223 \layout Itemize
12224
12225 SAVE
12226 \begin_inset LatexCommand \index{\#pragma SAVE}
12227
12228 \end_inset 
12229
12230  - this will save all current options to the SAVE/RESTORE stack.
12231  See RESTORE.
12232 \layout Itemize
12233
12234 RESTORE
12235 \begin_inset LatexCommand \index{\#pragma RESTORE}
12236
12237 \end_inset 
12238
12239  - will restore saved options from the last save.
12240  SAVEs & RESTOREs can be nested.
12241  SDCC uses a SAVE/RESTORE stack: SAVE pushes current options to the stack,
12242  RESTORE pulls current options from the stack.
12243  See SAVE.
12244 \layout Itemize
12245
12246 NOGCSE
12247 \begin_inset LatexCommand \index{\#pragma NOGCSE}
12248
12249 \end_inset 
12250
12251  - will stop global common subexpression elimination.
12252 \layout Itemize
12253
12254 NOINDUCTION
12255 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
12256
12257 \end_inset 
12258
12259  - will stop loop induction optimizations.
12260 \layout Itemize
12261
12262 NOJTBOUND
12263 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
12264
12265 \end_inset 
12266
12267  - will not generate code for boundary value checking, when switch statements
12268  are turned into jump-tables (dangerous).
12269  
12270 \layout Itemize
12271
12272 NOOVERLAY
12273 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
12274
12275 \end_inset 
12276
12277  - the compiler will not overlay the parameters and local variables of a
12278  function.
12279 \layout Itemize
12280
12281 LESS_PEDANTIC
12282 \begin_inset LatexCommand \index{\#pragma LESS\_PEDANTIC}
12283
12284 \end_inset 
12285
12286  - the compiler will not warn you anymore for obvious mistakes, you'r on
12287  your own now ;-(
12288 \layout Itemize
12289
12290 NOLOOPREVERSE
12291 \begin_inset LatexCommand \index{\#pragma NOLOOPREVERSE}
12292
12293 \end_inset 
12294
12295  - Will not do loop reversal optimization
12296 \layout Itemize
12297
12298 EXCLUDE
12299 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
12300
12301 \end_inset 
12302
12303  NONE | {acc[,b[,dpl[,dph]]] - The exclude pragma disables generation of
12304  pair of push/pop
12305 \begin_inset LatexCommand \index{push/pop}
12306
12307 \end_inset 
12308
12309  instruction in ISR function (using interrupt
12310 \begin_inset LatexCommand \index{interrupt}
12311
12312 \end_inset 
12313
12314  keyword).
12315  The directive should be placed immediately before the ISR function definition
12316  and it affects ALL ISR functions following it.
12317  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
12318 EXCLUDE\SpecialChar ~
12319 none
12320 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
12321
12322 \end_inset 
12323
12324 .
12325 \layout Itemize
12326
12327 NOIV
12328 \begin_inset LatexCommand \index{\#pragma NOIV}
12329
12330 \end_inset 
12331
12332  - Do not generate interrupt vector table entries for all ISR functions
12333  defined after the pragma.
12334  This is useful in cases where the interrupt vector table must be defined
12335  manually, or when there is a secondary, manually defined interrupt vector
12336  table (e.g.
12337  for the autovector feature of the Cypress EZ-USB FX2).
12338 \layout Itemize
12339
12340 CALLEE-SAVES
12341 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
12342
12343 \end_inset 
12344
12345
12346 \begin_inset LatexCommand \index{function prologue}
12347
12348 \end_inset 
12349
12350  function1[,function2[,function3...]] - The compiler by default uses a caller
12351  saves convention for register saving across function calls, however this
12352  can cause unnecessary register pushing & popping when calling small functions
12353  from larger functions.
12354  This option can be used to switch off the register saving convention for
12355  the function names specified.
12356  The compiler will not save registers when calling these functions, extra
12357  code need to be manually inserted at the entry & exit for these functions
12358  to save & restore the registers used by these functions, this can SUBSTANTIALLY
12359  reduce code & improve run time performance of the generated code.
12360  In the future the compiler (with inter procedural analysis) may be able
12361  to determine the appropriate scheme to use for each function call.
12362  If -
12363 \begin_inset ERT
12364 status Collapsed
12365
12366 \layout Standard
12367
12368 \backslash 
12369 /
12370 \end_inset 
12371
12372 -callee-saves command line option is used, the function names specified
12373  in #pragma\SpecialChar ~
12374 CALLEE-SAVES
12375 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
12376
12377 \end_inset 
12378
12379  is appended to the list of functions specified in the command line.
12380 \layout Standard
12381
12382 The pragma's are intended to be used to turn-off certain optimizations which
12383  might cause the compiler to generate extra stack / data space to store
12384  compiler generated temporary variables.
12385  This usually happens in large functions.
12386  Pragma directives should be used as shown in the following example, they
12387  are used to control options & optimizations for a given function; pragmas
12388  should be placed before and/or after a function, placing pragma's inside
12389  a function body could have unpredictable results.
12390 \layout Verse
12391
12392
12393 \family typewriter 
12394 #pragma SAVE
12395 \begin_inset LatexCommand \index{\#pragma SAVE}
12396
12397 \end_inset 
12398
12399  \SpecialChar ~
12400 \SpecialChar ~
12401 \SpecialChar ~
12402 \SpecialChar ~
12403 \SpecialChar ~
12404 \SpecialChar ~
12405 \SpecialChar ~
12406 /* save the current settings */ 
12407 \newline 
12408 #pragma NOGCSE
12409 \begin_inset LatexCommand \index{\#pragma NOGCSE}
12410
12411 \end_inset 
12412
12413  \SpecialChar ~
12414 \SpecialChar ~
12415 \SpecialChar ~
12416 \SpecialChar ~
12417 \SpecialChar ~
12418 /* turnoff global subexpression elimination */ 
12419 \newline 
12420 #pragma NOINDUCTION
12421 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
12422
12423 \end_inset 
12424
12425  /* turn off induction optimizations */ 
12426 \newline 
12427 int foo () 
12428 \newline 
12429
12430 \newline 
12431 \SpecialChar ~
12432  \SpecialChar ~
12433  ...
12434  
12435 \newline 
12436 \SpecialChar ~
12437  \SpecialChar ~
12438  /* large code */ 
12439 \newline 
12440 \SpecialChar ~
12441  \SpecialChar ~
12442  ...
12443  
12444 \newline 
12445
12446 \newline 
12447 #pragma RESTORE
12448 \begin_inset LatexCommand \index{\#pragma RESTORE}
12449
12450 \end_inset 
12451
12452  /* turn the optimizations back on */
12453 \layout Standard
12454
12455 The compiler will generate a warning message when extra space is allocated.
12456  It is strongly recommended that the SAVE and RESTORE pragma's be used when
12457  changing options for a function.
12458 \layout Subsection
12459
12460 Library Routines
12461 \emph on 
12462  
12463 \layout Standard
12464
12465
12466 \emph on 
12467 <pending: this is messy and incomplete>
12468 \emph default 
12469  
12470 \layout Enumerate
12471
12472 Compiler support routines (_gptrget, _mulint etc)
12473 \layout Enumerate
12474
12475 Stdclib functions (puts, printf, strcat etc)
12476 \layout Enumerate
12477
12478 Math functions (sin, pow, sqrt etc)
12479 \layout Standard
12480
12481 Libraries included in SDCC should have a license at least as liberal as
12482  the GNU Lesser General Public License
12483 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
12484
12485 \end_inset 
12486
12487  
12488 \emph on 
12489 LGPL
12490 \emph default 
12491 .
12492 \layout Comment
12493
12494 license statements for the libraries are missing.
12495  sdcc/device/lib/ser_ir.c f.e.
12496  comes with a GPL (as opposed to LGPL) License - this will not be liberal
12497  enough for many embedded programmers.
12498 \layout Subsection
12499
12500 Interfacing with Assembly Routines
12501 \begin_inset LatexCommand \index{Assembler routines}
12502
12503 \end_inset 
12504
12505
12506 \layout Subsubsection
12507
12508 Global Registers used for Parameter Passing
12509 \begin_inset LatexCommand \index{Parameter passing}
12510
12511 \end_inset 
12512
12513
12514 \layout Standard
12515
12516 The compiler always uses the global registers 
12517 \emph on 
12518 DPL, DPH
12519 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
12520
12521 \end_inset 
12522
12523 , B
12524 \begin_inset LatexCommand \index{B (register)}
12525
12526 \end_inset 
12527
12528  
12529 \emph default 
12530 and
12531 \emph on 
12532  ACC
12533 \begin_inset LatexCommand \index{ACC}
12534
12535 \end_inset 
12536
12537
12538 \emph default 
12539  to pass the first parameter to a routine.
12540  The second parameter onwards is either allocated on the stack (for reentrant
12541  routines or if -
12542 \begin_inset ERT
12543 status Collapsed
12544
12545 \layout Standard
12546
12547 \backslash 
12548 /
12549 \end_inset 
12550
12551 -stack-auto is used) or in data / xdata memory (depending on the memory
12552  model).
12553  
12554 \layout Subsubsection
12555
12556 Assembler Routine(non-reentrant
12557 \begin_inset LatexCommand \index{reentrant}
12558
12559 \end_inset 
12560
12561 )
12562 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
12563
12564 \end_inset 
12565
12566
12567 \layout Standard
12568
12569 In the following example the function c_func calls an assembler routine
12570  asm_func, which takes two parameters.
12571 \layout Verse
12572
12573
12574 \family typewriter 
12575 extern int asm_func(unsigned char, unsigned char);
12576 \newline 
12577
12578 \newline 
12579 int c_func (unsigned char i, unsigned char j)
12580 \newline 
12581 {
12582 \newline 
12583 \SpecialChar ~
12584 \SpecialChar ~
12585 \SpecialChar ~
12586 \SpecialChar ~
12587 return asm_func(i,j);
12588 \newline 
12589 }
12590 \newline 
12591
12592 \newline 
12593 int main()
12594 \newline 
12595 {
12596 \newline 
12597 \SpecialChar ~
12598 \SpecialChar ~
12599 \SpecialChar ~
12600 \SpecialChar ~
12601 return c_func(10,9);
12602 \newline 
12603 }
12604 \layout Standard
12605
12606 The corresponding assembler function is:
12607 \layout Verse
12608
12609
12610 \family typewriter 
12611 .globl _asm_func_PARM_2 
12612 \newline 
12613 \SpecialChar ~
12614 \SpecialChar ~
12615 \SpecialChar ~
12616 \SpecialChar ~
12617 \SpecialChar ~
12618 \SpecialChar ~
12619 \SpecialChar ~
12620 \SpecialChar ~
12621 .globl _asm_func 
12622 \newline 
12623 \SpecialChar ~
12624 \SpecialChar ~
12625 \SpecialChar ~
12626 \SpecialChar ~
12627 \SpecialChar ~
12628 \SpecialChar ~
12629 \SpecialChar ~
12630 \SpecialChar ~
12631 .area OSEG 
12632 \newline 
12633 _asm_func_PARM_2:
12634 \newline 
12635 \SpecialChar ~
12636 \SpecialChar ~
12637 \SpecialChar ~
12638 \SpecialChar ~
12639 \SpecialChar ~
12640 \SpecialChar ~
12641 \SpecialChar ~
12642 \SpecialChar ~
12643 .ds     1 
12644 \newline 
12645 \SpecialChar ~
12646 \SpecialChar ~
12647 \SpecialChar ~
12648 \SpecialChar ~
12649 \SpecialChar ~
12650 \SpecialChar ~
12651 \SpecialChar ~
12652 \SpecialChar ~
12653 .area CSEG 
12654 \newline 
12655 _asm_func: 
12656 \newline 
12657 \SpecialChar ~
12658 \SpecialChar ~
12659 \SpecialChar ~
12660 \SpecialChar ~
12661 \SpecialChar ~
12662 \SpecialChar ~
12663 \SpecialChar ~
12664 \SpecialChar ~
12665 mov    a,dpl 
12666 \newline 
12667 \SpecialChar ~
12668 \SpecialChar ~
12669 \SpecialChar ~
12670 \SpecialChar ~
12671 \SpecialChar ~
12672 \SpecialChar ~
12673 \SpecialChar ~
12674 \SpecialChar ~
12675 add    a,_asm_func_PARM_2 
12676 \newline 
12677 \SpecialChar ~
12678 \SpecialChar ~
12679 \SpecialChar ~
12680 \SpecialChar ~
12681 \SpecialChar ~
12682 \SpecialChar ~
12683 \SpecialChar ~
12684 \SpecialChar ~
12685 mov    dpl,a 
12686 \newline 
12687 \SpecialChar ~
12688 \SpecialChar ~
12689 \SpecialChar ~
12690 \SpecialChar ~
12691 \SpecialChar ~
12692 \SpecialChar ~
12693 \SpecialChar ~
12694 \SpecialChar ~
12695 mov\SpecialChar ~
12696 \SpecialChar ~
12697 \SpecialChar ~
12698 \SpecialChar ~
12699 dpl
12700 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
12701
12702 \end_inset 
12703
12704 ,#0x00 
12705 \newline 
12706 \SpecialChar ~
12707 \SpecialChar ~
12708 \SpecialChar ~
12709 \SpecialChar ~
12710 \SpecialChar ~
12711 \SpecialChar ~
12712 \SpecialChar ~
12713 \SpecialChar ~
12714 ret
12715 \layout Standard
12716
12717 Note here that the return values are placed in 'dpl' - One byte return value,
12718  'dpl' LSB & 'dph' MSB for two byte values.
12719  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
12720 b' & 'acc' for four byte values.
12721 \layout Standard
12722
12723 The parameter naming convention is _<function_name>_PARM_<n>, where n is
12724  the parameter number starting from 1, and counting from the left.
12725  The first parameter is passed in 
12726 \begin_inset Quotes eld
12727 \end_inset 
12728
12729 dpl
12730 \begin_inset Quotes erd
12731 \end_inset 
12732
12733  for One bye parameter, 
12734 \begin_inset Quotes eld
12735 \end_inset 
12736
12737 dptr
12738 \begin_inset Quotes erd
12739 \end_inset 
12740
12741  if two bytes, 
12742 \begin_inset Quotes eld
12743 \end_inset 
12744
12745 b,dptr
12746 \begin_inset Quotes erd
12747 \end_inset 
12748
12749  for three bytes and 
12750 \begin_inset Quotes eld
12751 \end_inset 
12752
12753 acc,b,dptr
12754 \begin_inset Quotes erd
12755 \end_inset 
12756
12757  for four bytes, the variable name for the second parameter will be _<function_n
12758 ame>_PARM_2.
12759 \newline 
12760
12761 \newline 
12762 Assemble the assembler routine with the following command:
12763 \newline 
12764
12765 \newline 
12766
12767 \family sans 
12768 \series bold 
12769 asx8051 -losg asmfunc.asm
12770 \newline 
12771
12772 \newline 
12773
12774 \family default 
12775 \series default 
12776 Then compile and link the assembler routine to the C source file with the
12777  following command:
12778 \newline 
12779
12780 \newline 
12781
12782 \family sans 
12783 \series bold 
12784 sdcc cfunc.c asmfunc.rel
12785 \layout Subsubsection
12786
12787 Assembler Routine(reentrant
12788 \begin_inset LatexCommand \index{reentrant}
12789
12790 \end_inset 
12791
12792 )
12793 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
12794
12795 \end_inset 
12796
12797
12798 \layout Standard
12799
12800 In this case the second parameter onwards will be passed on the stack, the
12801  parameters are pushed from right to left i.e.
12802  after the call the left most parameter will be on the top of the stack.
12803  Here is an example:
12804 \layout Verse
12805
12806
12807 \family typewriter 
12808 extern int asm_func(unsigned char, unsigned char);
12809 \newline 
12810
12811 \newline 
12812 int c_func (unsigned char i, unsigned char j) reentrant 
12813 \newline 
12814
12815 \newline 
12816 \SpecialChar ~
12817 \SpecialChar ~
12818 \SpecialChar ~
12819 \SpecialChar ~
12820 return asm_func(i,j); 
12821 \newline 
12822
12823 \newline 
12824
12825 \newline 
12826 int main() 
12827 \newline 
12828
12829 \newline 
12830 \SpecialChar ~
12831 \SpecialChar ~
12832 \SpecialChar ~
12833 \SpecialChar ~
12834 return c_func(10,9); 
12835 \newline 
12836 }
12837 \layout Standard
12838
12839 The corresponding assembler routine is:
12840 \layout Verse
12841
12842
12843 \family typewriter 
12844 .globl _asm_func 
12845 \newline 
12846 _asm_func: 
12847 \newline 
12848 \SpecialChar ~
12849 \SpecialChar ~
12850 \SpecialChar ~
12851 \SpecialChar ~
12852 push  _bp 
12853 \newline 
12854 \SpecialChar ~
12855 \SpecialChar ~
12856 \SpecialChar ~
12857 \SpecialChar ~
12858 mov _bp,sp 
12859 \newline 
12860 \SpecialChar ~
12861 \SpecialChar ~
12862 \SpecialChar ~
12863 \SpecialChar ~
12864 mov  r2,dpl
12865 \newline 
12866 \SpecialChar ~
12867 \SpecialChar ~
12868 \SpecialChar ~
12869 \SpecialChar ~
12870 mov  a,_bp 
12871 \newline 
12872 \SpecialChar ~
12873 \SpecialChar ~
12874 \SpecialChar ~
12875 \SpecialChar ~
12876 clr  c 
12877 \newline 
12878 \SpecialChar ~
12879 \SpecialChar ~
12880 \SpecialChar ~
12881 \SpecialChar ~
12882 add  a,#0xfd 
12883 \newline 
12884 \SpecialChar ~
12885 \SpecialChar ~
12886 \SpecialChar ~
12887 \SpecialChar ~
12888 mov  r0,a 
12889 \newline 
12890 \SpecialChar ~
12891 \SpecialChar ~
12892 \SpecialChar ~
12893 \SpecialChar ~
12894 add  a,#0xfc
12895 \newline 
12896 \SpecialChar ~
12897 \SpecialChar ~
12898 \SpecialChar ~
12899 \SpecialChar ~
12900 mov  r1,a 
12901 \newline 
12902 \SpecialChar ~
12903 \SpecialChar ~
12904 \SpecialChar ~
12905 \SpecialChar ~
12906 mov  a,@r0 
12907 \newline 
12908 \SpecialChar ~
12909 \SpecialChar ~
12910 \SpecialChar ~
12911 \SpecialChar ~
12912 add  a,r2
12913 \newline 
12914 \SpecialChar ~
12915 \SpecialChar ~
12916 \SpecialChar ~
12917 \SpecialChar ~
12918 mov  dpl,a 
12919 \newline 
12920 \SpecialChar ~
12921 \SpecialChar ~
12922 \SpecialChar ~
12923 \SpecialChar ~
12924 mov  dph,#0x00 
12925 \newline 
12926 \SpecialChar ~
12927 \SpecialChar ~
12928 \SpecialChar ~
12929 \SpecialChar ~
12930 mov  sp,_bp 
12931 \newline 
12932 \SpecialChar ~
12933 \SpecialChar ~
12934 \SpecialChar ~
12935 \SpecialChar ~
12936 pop  _bp 
12937 \newline 
12938 \SpecialChar ~
12939 \SpecialChar ~
12940 \SpecialChar ~
12941 \SpecialChar ~
12942 ret
12943 \layout Standard
12944
12945 The compiling and linking procedure remains the same, however note the extra
12946  entry & exit linkage required for the assembler code, _bp is the stack
12947  frame pointer and is used to compute the offset into the stack for parameters
12948  and local variables.
12949 \layout Subsection
12950
12951 External Stack
12952 \begin_inset LatexCommand \label{sub:External-Stack}
12953
12954 \end_inset 
12955
12956
12957 \begin_inset LatexCommand \index{stack}
12958
12959 \end_inset 
12960
12961
12962 \begin_inset LatexCommand \index{External stack}
12963
12964 \end_inset 
12965
12966
12967 \layout Standard
12968
12969 The external stack is located at the start of the external ram segment,
12970  and is 256 bytes in size.
12971  When -
12972 \begin_inset ERT
12973 status Collapsed
12974
12975 \layout Standard
12976
12977 \backslash 
12978 /
12979 \end_inset 
12980
12981 -xstack option is used to compile the program, the parameters and local
12982  variables of all reentrant functions are allocated in this area.
12983  This option is provided for programs with large stack space requirements.
12984  When used with the -
12985 \begin_inset ERT
12986 status Collapsed
12987
12988 \layout Standard
12989
12990 \backslash 
12991 /
12992 \end_inset 
12993
12994 -stack-auto option, all parameters and local variables are allocated on
12995  the external stack (note support libraries will need to be recompiled with
12996  the same options).
12997 \layout Standard
12998
12999 The compiler outputs the higher order address byte of the external ram segment
13000  into PORT P2, therefore when using the External Stack option, this port
13001  MAY NOT be used by the application program.
13002 \layout Subsection
13003
13004 ANSI-Compliance
13005 \begin_inset LatexCommand \index{ANSI-compliance}
13006
13007 \end_inset 
13008
13009
13010 \layout Standard
13011
13012 Deviations from the compliance:
13013 \layout Itemize
13014
13015 functions are not always reentrant.
13016 \layout Itemize
13017
13018 structures cannot be assigned values directly, cannot be passed as function
13019  parameters or assigned to each other and cannot be a return value from
13020  a function, e.g.:
13021 \begin_deeper 
13022 \layout Verse
13023
13024
13025 \family typewriter 
13026 struct s { ...
13027  }; 
13028 \newline 
13029 struct s s1, s2; 
13030 \newline 
13031 foo() 
13032 \newline 
13033
13034 \newline 
13035 \SpecialChar ~
13036 \SpecialChar ~
13037 \SpecialChar ~
13038 \SpecialChar ~
13039 ...
13040  
13041 \newline 
13042 \SpecialChar ~
13043 \SpecialChar ~
13044 \SpecialChar ~
13045 \SpecialChar ~
13046 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
13047 \newline 
13048 \SpecialChar ~
13049 \SpecialChar ~
13050 \SpecialChar ~
13051 \SpecialChar ~
13052 ...
13053  
13054 \newline 
13055 }
13056 \newline 
13057 struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
13058  */
13059 \newline 
13060
13061 \newline 
13062 \SpecialChar ~
13063 \SpecialChar ~
13064 \SpecialChar ~
13065 \SpecialChar ~
13066 struct s rets; 
13067 \newline 
13068 \SpecialChar ~
13069 \SpecialChar ~
13070 \SpecialChar ~
13071 \SpecialChar ~
13072 ...
13073  
13074 \newline 
13075 \SpecialChar ~
13076 \SpecialChar ~
13077 \SpecialChar ~
13078 \SpecialChar ~
13079 return rets;/* is invalid in SDCC although allowed in ANSI */ 
13080 \newline 
13081 }
13082 \end_deeper 
13083 \layout Itemize
13084
13085 'long long
13086 \begin_inset LatexCommand \index{long long (not supported)}
13087
13088 \end_inset 
13089
13090 ' (64 bit integers
13091 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
13092
13093 \end_inset 
13094
13095 ) not supported.
13096 \layout Itemize
13097
13098 'double
13099 \begin_inset LatexCommand \index{double (not supported)}
13100
13101 \end_inset 
13102
13103 ' precision floating point 
13104 \begin_inset LatexCommand \index{Floating point support}
13105
13106 \end_inset 
13107
13108 not supported.
13109 \layout Itemize
13110
13111 No support for setjmp and longjmp (for now).
13112 \layout Itemize
13113
13114 Old K&R style
13115 \begin_inset LatexCommand \index{K\&R style}
13116
13117 \end_inset 
13118
13119  function declarations are NOT allowed.
13120 \begin_deeper 
13121 \layout Verse
13122
13123
13124 \family typewriter 
13125 foo(i,j) /* this old style of function declarations */ 
13126 \newline 
13127 int i,j; /* are valid in ANSI but not valid in SDCC */ 
13128 \newline 
13129
13130 \newline 
13131 \SpecialChar ~
13132 \SpecialChar ~
13133 \SpecialChar ~
13134 \SpecialChar ~
13135 ...
13136  
13137 \newline 
13138 }
13139 \end_deeper 
13140 \layout Itemize
13141
13142 functions declared as pointers must be dereferenced during the call.
13143 \begin_deeper 
13144 \layout Verse
13145
13146
13147 \family typewriter 
13148 int (*foo)();
13149 \newline 
13150 ...
13151  
13152 \newline 
13153 /* has to be called like this */ 
13154 \newline 
13155 (*foo)(); /* ANSI standard allows calls to be made like 'foo()' */
13156 \end_deeper 
13157 \layout Subsection
13158
13159 Cyclomatic Complexity
13160 \begin_inset LatexCommand \index{Cyclomatic complexity}
13161
13162 \end_inset 
13163
13164
13165 \layout Standard
13166
13167 Cyclomatic complexity of a function is defined as the number of independent
13168  paths the program can take during execution of the function.
13169  This is an important number since it defines the number test cases you
13170  have to generate to validate the function.
13171  The accepted industry standard for complexity number is 10, if the cyclomatic
13172  complexity reported by SDCC exceeds 10 you should think about simplification
13173  of the function logic.
13174  Note that the complexity level is not related to the number of lines of
13175  code in a function.
13176  Large functions can have low complexity, and small functions can have large
13177  complexity levels.
13178  
13179 \newline 
13180
13181 \newline 
13182 SDCC uses the following formula to compute the complexity:
13183 \newline 
13184
13185 \layout Standard
13186
13187 complexity = (number of edges in control flow graph) - (number of nodes
13188  in control flow graph) + 2;
13189 \newline 
13190
13191 \newline 
13192 Having said that the industry standard is 10, you should be aware that in
13193  some cases it be may unavoidable to have a complexity level of less than
13194  10.
13195  For example if you have switch statement with more than 10 case labels,
13196  each case label adds one to the complexity level.
13197  The complexity level is by no means an absolute measure of the algorithmic
13198  complexity of the function, it does however provide a good starting point
13199  for which functions you might look at for further optimization.
13200 \layout Section
13201 \pagebreak_top 
13202 TIPS
13203 \layout Standard
13204
13205 Here are a few guidelines that will help the compiler generate more efficient
13206  code, some of the tips are specific to this compiler others are generally
13207  good programming practice.
13208 \layout Itemize
13209
13210 Use the smallest data type to represent your data-value.
13211  If it is known in advance that the value is going to be less than 256 then
13212  use an 'unsigned char' instead of a 'short' or 'int'.
13213 \layout Itemize
13214
13215 Use unsigned when it is known in advance that the value is not going to
13216  be negative.
13217  This helps especially if you are doing division or multiplication.
13218 \layout Itemize
13219
13220 NEVER jump into a LOOP.
13221 \layout Itemize
13222
13223 Declare the variables to be local whenever possible, especially loop control
13224  variables (induction).
13225 \layout Itemize
13226
13227 Since the compiler does not always do implicit integral promotion, the programme
13228 r should do an explicit cast when integral promotion is required.
13229 \layout Itemize
13230
13231 Reducing the size of division, multiplication & modulus operations can reduce
13232  code size substantially.
13233  Take the following code for example.
13234 \begin_deeper 
13235 \layout Verse
13236
13237
13238 \family typewriter 
13239 foobar(unsigned int p1, unsigned char ch)
13240 \newline 
13241 {
13242 \newline 
13243 \SpecialChar ~
13244 \SpecialChar ~
13245 \SpecialChar ~
13246 \SpecialChar ~
13247 unsigned char ch1 = p1 % ch ;
13248 \newline 
13249 \SpecialChar ~
13250 \SpecialChar ~
13251 \SpecialChar ~
13252 \SpecialChar ~
13253 ....
13254 \newline 
13255 }
13256 \layout Standard
13257
13258 For the modulus operation the variable ch will be promoted to unsigned int
13259  first then the modulus operation will be performed (this will lead to a
13260  call to support routine _moduint()), and the result will be casted to a
13261  char.
13262  If the code is changed to 
13263 \layout Verse
13264
13265
13266 \family typewriter 
13267 foobar(unsigned int p1, unsigned char ch)
13268 \newline 
13269 {
13270 \newline 
13271 \SpecialChar ~
13272 \SpecialChar ~
13273 \SpecialChar ~
13274 \SpecialChar ~
13275 unsigned char ch1 = (unsigned char)p1 % ch ;
13276 \newline 
13277 \SpecialChar ~
13278 \SpecialChar ~
13279 \SpecialChar ~
13280 \SpecialChar ~
13281 ....
13282 \newline 
13283 }
13284 \layout Standard
13285
13286 It would substantially reduce the code generated (future versions of the
13287  compiler will be smart enough to detect such optimization opportunities).
13288 \end_deeper 
13289 \layout Itemize
13290
13291 Have a look at the assembly listing to get a 
13292 \begin_inset Quotes sld
13293 \end_inset 
13294
13295 feeling
13296 \begin_inset Quotes srd
13297 \end_inset 
13298
13299  for the code generation.
13300 \layout Subsection
13301
13302 Notes on MCS51 memory
13303 \begin_inset LatexCommand \index{MCS51 memory}
13304
13305 \end_inset 
13306
13307  layout
13308 \layout Standard
13309
13310 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
13311  RAM memory which is structured as follows
13312 \newline 
13313
13314 \newline 
13315 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
13316  
13317 \newline 
13318 - Bytes 20-2F - 16 bytes to hold 128 bit variables and, 
13319 \newline 
13320 - Bytes 30-7F - 80 bytes for general purpose use.
13321 \newline 
13322
13323 \layout Standard
13324
13325 Additionally some members of the MCS51 family may have up to 128 bytes of
13326  additional, indirectly addressable, internal RAM memory (
13327 \emph on 
13328 idata
13329 \emph default 
13330 ).
13331  Furthermore, some chips may have some built in external memory (
13332 \emph on 
13333 xdata
13334 \emph default 
13335 ) which should not be confused with the internal, directly addressable RAM
13336  memory (
13337 \emph on 
13338 data
13339 \emph default 
13340 ).
13341  Sometimes this built in 
13342 \emph on 
13343 xdata
13344 \emph default 
13345  memory has to be activated before using it (you can probably find this
13346  information on the datasheet of the microcontroller your are using).
13347 \layout Standard
13348
13349 Normally SDCC will only use the first bank
13350 \begin_inset LatexCommand \index{bank}
13351
13352 \end_inset 
13353
13354  of registers (register bank 0), but it is possible to specify that other
13355  banks of registers should be used in interrupt
13356 \begin_inset LatexCommand \index{interrupt}
13357
13358 \end_inset 
13359
13360  routines.
13361  By default, the compiler will place the stack after the last byte of allocated
13362  memory for variables.
13363  For example, if the first 2 banks of registers are used, and only four
13364  bytes are used for 
13365 \emph on 
13366 data
13367 \emph default 
13368  variables, it will position the base of the internal stack at address 20
13369  (0x14).
13370  This implies that as the stack
13371 \begin_inset LatexCommand \index{stack}
13372
13373 \end_inset 
13374
13375  grows, it will use up the remaining register banks, and the 16 bytes used
13376  by the 128 bit variables, and 80 bytes for general purpose use.
13377  If any bit variables are used, the data variables will be placed after
13378  the byte holding the last bit variable.
13379  For example, if register banks 0 and 1 are used, and there are 9 bit variables
13380  (two bytes used), 
13381 \emph on 
13382 data
13383 \emph default 
13384  variables will be placed starting at address 0x22.
13385  You can also use -
13386 \begin_inset ERT
13387 status Collapsed
13388
13389 \layout Standard
13390
13391 \backslash 
13392 /
13393 \end_inset 
13394
13395 -data-loc
13396 \begin_inset LatexCommand \index{-\/-data-loc}
13397
13398 \end_inset 
13399
13400  to specify the start address of the 
13401 \emph on 
13402 data
13403 \emph default 
13404  and -
13405 \begin_inset ERT
13406 status Collapsed
13407
13408 \layout Standard
13409
13410 \backslash 
13411 /
13412 \end_inset 
13413
13414 -iram-size to specify the size of the total internal RAM (
13415 \emph on 
13416 data
13417 \emph default 
13418 +
13419 \emph on 
13420 idata
13421 \emph default 
13422 ).
13423  
13424 \layout Standard
13425
13426 By default the 8051 linker will place the stack after the last byte of data
13427  variables.
13428  Option -
13429 \begin_inset ERT
13430 status Collapsed
13431
13432 \layout Standard
13433
13434 \backslash 
13435 /
13436 \end_inset 
13437
13438 -stack-loc
13439 \begin_inset LatexCommand \index{-\/-stack-loc}
13440
13441 \end_inset 
13442
13443  allows you to specify the start of the stack, i.e.
13444  you could start it after any data in the general purpose area.
13445  If your microcontroller has additional indirectly addressable internal
13446  RAM (
13447 \emph on 
13448 idata
13449 \emph default 
13450 ) you can place the stack on it.
13451  You may also need to use -
13452 \begin_inset ERT
13453 status Collapsed
13454
13455 \layout Standard
13456
13457 \backslash 
13458 /
13459 \end_inset 
13460
13461 -xdata-loc
13462 \begin_inset LatexCommand \index{-\/-data-loc}
13463
13464 \end_inset 
13465
13466  to set the start address of the external RAM (
13467 \emph on 
13468 xdata
13469 \emph default 
13470 ) and -
13471 \begin_inset ERT
13472 status Collapsed
13473
13474 \layout Standard
13475
13476 \backslash 
13477 /
13478 \end_inset 
13479
13480 -xram-size
13481 \begin_inset LatexCommand \index{-\/-data-loc}
13482
13483 \end_inset 
13484
13485  to specify its size.
13486  Same goes for the code memory, using -
13487 \begin_inset ERT
13488 status Collapsed
13489
13490 \layout Standard
13491
13492 \backslash 
13493 /
13494 \end_inset 
13495
13496 -code-loc
13497 \begin_inset LatexCommand \index{-\/-data-loc}
13498
13499 \end_inset 
13500
13501  and -
13502 \begin_inset ERT
13503 status Collapsed
13504
13505 \layout Standard
13506
13507 \backslash 
13508 /
13509 \end_inset 
13510
13511 -code-size
13512 \begin_inset LatexCommand \index{-\/-data-loc}
13513
13514 \end_inset 
13515
13516 .
13517  If in doubt, don't specify any options and see if the resulting memory
13518  layout is appropriate, then you can adjust it.
13519 \layout Standard
13520
13521 The 8051 linker generates two files with memory allocation information.
13522  The first, with extension .map shows all the variables and segments.
13523  The second with extension .mem shows the final memory layout.
13524  The linker will complaint either if memory segments overlap, there is not
13525  enough memory, or there is not enough space for stack.
13526  If you get any linking warnings and/or errors related to stack or segments
13527  allocation, take a look at either the .map or .mem files to find out what
13528  the problem is.
13529  The .mem file may even suggest a solution to the problem.
13530 \layout Subsection
13531
13532 Tools
13533 \begin_inset LatexCommand \index{Tools}
13534
13535 \end_inset 
13536
13537  included in the distribution
13538 \layout Standard
13539 \align center 
13540
13541 \begin_inset  Tabular
13542 <lyxtabular version="3" rows="12" columns="3">
13543 <features>
13544 <column alignment="center" valignment="top" leftline="true" width="0pt">
13545 <column alignment="center" valignment="top" leftline="true" width="0pt">
13546 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
13547 <row topline="true" bottomline="true">
13548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13549 \begin_inset Text
13550
13551 \layout Standard
13552
13553 Name
13554 \end_inset 
13555 </cell>
13556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13557 \begin_inset Text
13558
13559 \layout Standard
13560
13561 Purpose
13562 \end_inset 
13563 </cell>
13564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13565 \begin_inset Text
13566
13567 \layout Standard
13568
13569 Directory
13570 \end_inset 
13571 </cell>
13572 </row>
13573 <row topline="true">
13574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13575 \begin_inset Text
13576
13577 \layout Standard
13578
13579 uCsim
13580 \end_inset 
13581 </cell>
13582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13583 \begin_inset Text
13584
13585 \layout Standard
13586
13587 Simulator for various architectures
13588 \end_inset 
13589 </cell>
13590 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13591 \begin_inset Text
13592
13593 \layout Standard
13594
13595 sdcc/sim/ucsim
13596 \end_inset 
13597 </cell>
13598 </row>
13599 <row topline="true">
13600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13601 \begin_inset Text
13602
13603 \layout Standard
13604
13605 keil2sdcc.pl
13606 \end_inset 
13607 </cell>
13608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13609 \begin_inset Text
13610
13611 \layout Standard
13612
13613 header file conversion
13614 \end_inset 
13615 </cell>
13616 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13617 \begin_inset Text
13618
13619 \layout Standard
13620
13621 sdcc/support/scripts
13622 \end_inset 
13623 </cell>
13624 </row>
13625 <row topline="true">
13626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13627 \begin_inset Text
13628
13629 \layout Standard
13630
13631 mh2h.c
13632 \end_inset 
13633 </cell>
13634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13635 \begin_inset Text
13636
13637 \layout Standard
13638
13639 header file conversion
13640 \end_inset 
13641 </cell>
13642 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13643 \begin_inset Text
13644
13645 \layout Standard
13646
13647 sdcc/support/scripts
13648 \end_inset 
13649 </cell>
13650 </row>
13651 <row topline="true">
13652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13653 \begin_inset Text
13654
13655 \layout Standard
13656
13657 as-gbz80
13658 \end_inset 
13659 </cell>
13660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13661 \begin_inset Text
13662
13663 \layout Standard
13664
13665 Assembler
13666 \end_inset 
13667 </cell>
13668 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13669 \begin_inset Text
13670
13671 \layout Standard
13672
13673
13674 \family roman 
13675 \series medium 
13676 \shape up 
13677 \size normal 
13678 \emph off 
13679 \bar no 
13680 \noun off 
13681 \color none
13682 sdcc/bin
13683 \end_inset 
13684 </cell>
13685 </row>
13686 <row topline="true">
13687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13688 \begin_inset Text
13689
13690 \layout Standard
13691
13692 as-z80
13693 \end_inset 
13694 </cell>
13695 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13696 \begin_inset Text
13697
13698 \layout Standard
13699
13700 Assembler
13701 \end_inset 
13702 </cell>
13703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13704 \begin_inset Text
13705
13706 \layout Standard
13707
13708
13709 \family roman 
13710 \series medium 
13711 \shape up 
13712 \size normal 
13713 \emph off 
13714 \bar no 
13715 \noun off 
13716 \color none
13717 sdcc/bin
13718 \end_inset 
13719 </cell>
13720 </row>
13721 <row topline="true">
13722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13723 \begin_inset Text
13724
13725 \layout Standard
13726
13727 asx8051
13728 \end_inset 
13729 </cell>
13730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13731 \begin_inset Text
13732
13733 \layout Standard
13734
13735 Assembler
13736 \end_inset 
13737 </cell>
13738 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13739 \begin_inset Text
13740
13741 \layout Standard
13742
13743
13744 \family roman 
13745 \series medium 
13746 \shape up 
13747 \size normal 
13748 \emph off 
13749 \bar no 
13750 \noun off 
13751 \color none
13752 sdcc/bin
13753 \end_inset 
13754 </cell>
13755 </row>
13756 <row topline="true">
13757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13758 \begin_inset Text
13759
13760 \layout Standard
13761
13762 sdcdb
13763 \end_inset 
13764 </cell>
13765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13766 \begin_inset Text
13767
13768 \layout Standard
13769
13770 Simulator
13771 \end_inset 
13772 </cell>
13773 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13774 \begin_inset Text
13775
13776 \layout Standard
13777
13778
13779 \family roman 
13780 \series medium 
13781 \shape up 
13782 \size normal 
13783 \emph off 
13784 \bar no 
13785 \noun off 
13786 \color none
13787 sdcc/bin
13788 \end_inset 
13789 </cell>
13790 </row>
13791 <row topline="true">
13792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13793 \begin_inset Text
13794
13795 \layout Standard
13796
13797 aslink
13798 \end_inset 
13799 </cell>
13800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13801 \begin_inset Text
13802
13803 \layout Standard
13804
13805 Linker
13806 \end_inset 
13807 </cell>
13808 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13809 \begin_inset Text
13810
13811 \layout Standard
13812
13813
13814 \family roman 
13815 \series medium 
13816 \shape up 
13817 \size normal 
13818 \emph off 
13819 \bar no 
13820 \noun off 
13821 \color none
13822 sdcc/bin
13823 \end_inset 
13824 </cell>
13825 </row>
13826 <row topline="true">
13827 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13828 \begin_inset Text
13829
13830 \layout Standard
13831
13832 link-z80
13833 \end_inset 
13834 </cell>
13835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13836 \begin_inset Text
13837
13838 \layout Standard
13839
13840 Linker
13841 \end_inset 
13842 </cell>
13843 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13844 \begin_inset Text
13845
13846 \layout Standard
13847
13848
13849 \family roman 
13850 \series medium 
13851 \shape up 
13852 \size normal 
13853 \emph off 
13854 \bar no 
13855 \noun off 
13856 \color none
13857 sdcc/bin
13858 \end_inset 
13859 </cell>
13860 </row>
13861 <row topline="true">
13862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13863 \begin_inset Text
13864
13865 \layout Standard
13866
13867 link-gbz80
13868 \end_inset 
13869 </cell>
13870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13871 \begin_inset Text
13872
13873 \layout Standard
13874
13875 Linker
13876 \end_inset 
13877 </cell>
13878 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13879 \begin_inset Text
13880
13881 \layout Standard
13882
13883
13884 \family roman 
13885 \series medium 
13886 \shape up 
13887 \size normal 
13888 \emph off 
13889 \bar no 
13890 \noun off 
13891 \color none
13892 sdcc/bin
13893 \end_inset 
13894 </cell>
13895 </row>
13896 <row topline="true" bottomline="true">
13897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13898 \begin_inset Text
13899
13900 \layout Standard
13901
13902 packihx
13903 \end_inset 
13904 </cell>
13905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13906 \begin_inset Text
13907
13908 \layout Standard
13909
13910 ihx packer
13911 \end_inset 
13912 </cell>
13913 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13914 \begin_inset Text
13915
13916 \layout Standard
13917
13918
13919 \family roman 
13920 \series medium 
13921 \shape up 
13922 \size normal 
13923 \emph off 
13924 \bar no 
13925 \noun off 
13926 \color none
13927 sdcc/bin
13928 \end_inset 
13929 </cell>
13930 </row>
13931 </lyxtabular>
13932
13933 \end_inset 
13934
13935
13936 \newline 
13937
13938 \layout Subsection
13939
13940 Related open source tools
13941 \begin_inset LatexCommand \index{Related tools}
13942
13943 \end_inset 
13944
13945
13946 \layout Standard
13947 \align center 
13948
13949 \begin_inset  Tabular
13950 <lyxtabular version="3" rows="8" columns="3">
13951 <features>
13952 <column alignment="center" valignment="top" leftline="true" width="0pt">
13953 <column alignment="block" valignment="top" leftline="true" width="30line%">
13954 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
13955 <row topline="true" bottomline="true">
13956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13957 \begin_inset Text
13958
13959 \layout Standard
13960
13961 Name
13962 \end_inset 
13963 </cell>
13964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13965 \begin_inset Text
13966
13967 \layout Standard
13968
13969 Purpose
13970 \end_inset 
13971 </cell>
13972 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13973 \begin_inset Text
13974
13975 \layout Standard
13976
13977 Where to get
13978 \end_inset 
13979 </cell>
13980 </row>
13981 <row topline="true">
13982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13983 \begin_inset Text
13984
13985 \layout Standard
13986
13987 gpsim
13988 \begin_inset LatexCommand \index{gpsim}
13989
13990 \end_inset 
13991
13992
13993 \end_inset 
13994 </cell>
13995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13996 \begin_inset Text
13997
13998 \layout Standard
13999
14000 PIC simulator
14001 \end_inset 
14002 </cell>
14003 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14004 \begin_inset Text
14005
14006 \layout Standard
14007
14008
14009 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
14010
14011 \end_inset 
14012
14013
14014 \end_inset 
14015 </cell>
14016 </row>
14017 <row topline="true">
14018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14019 \begin_inset Text
14020
14021 \layout Standard
14022
14023 flP5
14024 \end_inset 
14025 </cell>
14026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14027 \begin_inset Text
14028
14029 \layout Standard
14030
14031 PIC programmer
14032 \end_inset 
14033 </cell>
14034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14035 \begin_inset Text
14036
14037 \layout Standard
14038
14039
14040 \begin_inset LatexCommand \url{http://digilander.libero.it/fbradasc/FLP5.html}
14041
14042 \end_inset 
14043
14044
14045 \end_inset 
14046 </cell>
14047 </row>
14048 <row topline="true">
14049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14050 \begin_inset Text
14051
14052 \layout Standard
14053
14054 srecord
14055 \begin_inset LatexCommand \index{srecord}
14056
14057 \end_inset 
14058
14059
14060 \end_inset 
14061 </cell>
14062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14063 \begin_inset Text
14064
14065 \layout Standard
14066
14067 Object file conversion, checksumming, ...
14068 \end_inset 
14069 </cell>
14070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14071 \begin_inset Text
14072
14073 \layout Standard
14074
14075
14076 \begin_inset LatexCommand \url{http://srecord.sourceforge.net/}
14077
14078 \end_inset 
14079
14080
14081 \end_inset 
14082 </cell>
14083 </row>
14084 <row topline="true">
14085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14086 \begin_inset Text
14087
14088 \layout Standard
14089
14090 objdump
14091 \begin_inset LatexCommand \index{objdump}
14092
14093 \end_inset 
14094
14095
14096 \end_inset 
14097 </cell>
14098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14099 \begin_inset Text
14100
14101 \layout Standard
14102
14103 Object file conversion, ...
14104 \end_inset 
14105 </cell>
14106 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14107 \begin_inset Text
14108
14109 \layout Standard
14110
14111 Part of binutils (should be there anyway)
14112 \end_inset 
14113 </cell>
14114 </row>
14115 <row topline="true">
14116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14117 \begin_inset Text
14118
14119 \layout Standard
14120
14121 doxygen
14122 \begin_inset LatexCommand \index{doxygen}
14123
14124 \end_inset 
14125
14126
14127 \end_inset 
14128 </cell>
14129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14130 \begin_inset Text
14131
14132 \layout Standard
14133
14134 Source code documentation system
14135 \end_inset 
14136 </cell>
14137 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14138 \begin_inset Text
14139
14140 \layout Standard
14141
14142
14143 \begin_inset LatexCommand \url{http://www.doxygen.org}
14144
14145 \end_inset 
14146
14147
14148 \end_inset 
14149 </cell>
14150 </row>
14151 <row topline="true">
14152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14153 \begin_inset Text
14154
14155 \layout Standard
14156
14157 splint
14158 \begin_inset LatexCommand \index{splint}
14159
14160 \end_inset 
14161
14162
14163 \end_inset 
14164 </cell>
14165 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14166 \begin_inset Text
14167
14168 \layout Standard
14169
14170 Statically checks c sources
14171 \end_inset 
14172 </cell>
14173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14174 \begin_inset Text
14175
14176 \layout Standard
14177
14178
14179 \begin_inset LatexCommand \url{http://www.splint.org}
14180
14181 \end_inset 
14182
14183
14184 \end_inset 
14185 </cell>
14186 </row>
14187 <row topline="true" bottomline="true">
14188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14189 \begin_inset Text
14190
14191 \layout Standard
14192
14193 ddd
14194 \begin_inset LatexCommand \index{ddd}
14195
14196 \end_inset 
14197
14198
14199 \end_inset 
14200 </cell>
14201 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14202 \begin_inset Text
14203
14204 \layout Standard
14205
14206 Debugger, serves nicely as GUI to sdcdb
14207 \begin_inset LatexCommand \index{sdcdb}
14208
14209 \end_inset 
14210
14211  (Unix only)
14212 \end_inset 
14213 </cell>
14214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14215 \begin_inset Text
14216
14217 \layout Standard
14218
14219
14220 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
14221
14222 \end_inset 
14223
14224
14225 \end_inset 
14226 </cell>
14227 </row>
14228 </lyxtabular>
14229
14230 \end_inset 
14231
14232
14233 \newline 
14234
14235 \layout Subsection
14236
14237 Related documentation / recommended reading
14238 \layout Standard
14239 \align center 
14240
14241 \begin_inset  Tabular
14242 <lyxtabular version="3" rows="5" columns="3">
14243 <features>
14244 <column alignment="center" valignment="top" leftline="true" width="0pt">
14245 <column alignment="block" valignment="top" leftline="true" width="30line%">
14246 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
14247 <row topline="true" bottomline="true">
14248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14249 \begin_inset Text
14250
14251 \layout Standard
14252
14253 Name
14254 \end_inset 
14255 </cell>
14256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14257 \begin_inset Text
14258
14259 \layout Standard
14260
14261 Subject / Title
14262 \end_inset 
14263 </cell>
14264 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14265 \begin_inset Text
14266
14267 \layout Standard
14268
14269 Where to get
14270 \end_inset 
14271 </cell>
14272 </row>
14273 <row topline="true">
14274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14275 \begin_inset Text
14276
14277 \layout Standard
14278
14279 S.
14280  S.
14281  Muchnick
14282 \end_inset 
14283 </cell>
14284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14285 \begin_inset Text
14286
14287 \layout Standard
14288
14289 Advanced Compiler Design and Implementation
14290 \end_inset 
14291 </cell>
14292 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14293 \begin_inset Text
14294
14295 \layout Standard
14296
14297 bookstore
14298 \end_inset 
14299 </cell>
14300 </row>
14301 <row topline="true">
14302 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14303 \begin_inset Text
14304
14305 \layout Standard
14306
14307
14308 \family roman 
14309 \series medium 
14310 \shape up 
14311 \size normal 
14312 \emph off 
14313 \bar no 
14314 \noun off 
14315 \color none
14316 c-refcard.pdf
14317 \end_inset 
14318 </cell>
14319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14320 \begin_inset Text
14321
14322 \layout Standard
14323
14324 C Reference Card
14325 \begin_inset LatexCommand \index{C Reference card}
14326
14327 \end_inset 
14328
14329 , 2 pages
14330 \end_inset 
14331 </cell>
14332 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14333 \begin_inset Text
14334
14335 \layout Standard
14336
14337
14338 \begin_inset LatexCommand \url{http://www.refcards.com/about/c.html}
14339
14340 \end_inset 
14341
14342
14343 \end_inset 
14344 </cell>
14345 </row>
14346 <row topline="true">
14347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14348 \begin_inset Text
14349
14350 \layout Standard
14351
14352 test_suite_spec.pdf
14353 \end_inset 
14354 </cell>
14355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14356 \begin_inset Text
14357
14358 \layout Standard
14359
14360 sdcc regression test
14361 \begin_inset LatexCommand \index{Regression test}
14362
14363 \end_inset 
14364
14365
14366 \end_inset 
14367 </cell>
14368 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14369 \begin_inset Text
14370
14371 \layout Standard
14372
14373 sdcc/doc
14374 \end_inset 
14375 </cell>
14376 </row>
14377 <row topline="true" bottomline="true">
14378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14379 \begin_inset Text
14380
14381 \layout Standard
14382
14383
14384 \family roman 
14385 \series medium 
14386 \shape up 
14387 \size normal 
14388 \emph off 
14389 \bar no 
14390 \noun off 
14391 \color none
14392 cdbfileformat.pd
14393 \family default 
14394 \series default 
14395 \shape default 
14396 \size default 
14397 \emph default 
14398 \bar default 
14399 \noun default 
14400 \color default
14401 f
14402 \end_inset 
14403 </cell>
14404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14405 \begin_inset Text
14406
14407 \layout Standard
14408
14409 sdcc internal documentation
14410 \end_inset 
14411 </cell>
14412 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14413 \begin_inset Text
14414
14415 \layout Standard
14416
14417 sdcc/doc
14418 \end_inset 
14419 </cell>
14420 </row>
14421 </lyxtabular>
14422
14423 \end_inset 
14424
14425
14426 \newline 
14427
14428 \layout Section
14429 \pagebreak_top 
14430 Retargetting for other MCUs.
14431 \layout Standard
14432
14433 The issues for retargetting the compiler are far too numerous to be covered
14434  by this document.
14435  What follows is a brief description of each of the seven phases of the
14436  compiler and its MCU dependency.
14437 \layout Itemize
14438
14439 Parsing the source and building the annotated parse tree.
14440  This phase is largely MCU independent (except for the language extensions).
14441  Syntax & semantic checks are also done in this phase, along with some initial
14442  optimizations like back patching labels and the pattern matching optimizations
14443  like bit-rotation etc.
14444 \layout Itemize
14445
14446 The second phase involves generating an intermediate code which can be easy
14447  manipulated during the later phases.
14448  This phase is entirely MCU independent.
14449  The intermediate code generation assumes the target machine has unlimited
14450  number of registers, and designates them with the name iTemp.
14451  The compiler can be made to dump a human readable form of the code generated
14452  by using the -
14453 \begin_inset ERT
14454 status Collapsed
14455
14456 \layout Standard
14457
14458 \backslash 
14459 /
14460 \end_inset 
14461
14462 -dumpraw option.
14463 \layout Itemize
14464
14465 This phase does the bulk of the standard optimizations and is also MCU independe
14466 nt.
14467  This phase can be broken down into several sub-phases:
14468 \newline 
14469
14470 \newline 
14471 Break down intermediate code (iCode) into basic blocks.
14472 \newline 
14473 Do control flow & data flow analysis on the basic blocks.
14474 \newline 
14475 Do local common subexpression elimination, then global subexpression elimination
14476 \newline 
14477 Dead code elimination
14478 \newline 
14479 Loop optimizations
14480 \newline 
14481 If loop optimizations caused any changes then do 'global subexpression eliminati
14482 on' and 'dead code elimination' again.
14483 \layout Itemize
14484
14485 This phase determines the live-ranges; by live range I mean those iTemp
14486  variables defined by the compiler that still survive after all the optimization
14487 s.
14488  Live range analysis
14489 \begin_inset LatexCommand \index{Live range analysis}
14490
14491 \end_inset 
14492
14493  is essential for register allocation, since these computation determines
14494  which of these iTemps will be assigned to registers, and for how long.
14495 \layout Itemize
14496
14497 Phase five is register allocation.
14498  There are two parts to this process.
14499 \newline 
14500
14501 \newline 
14502 The first part I call 'register packing' (for lack of a better term).
14503  In this case several MCU specific expression folding is done to reduce
14504  register pressure.
14505 \newline 
14506
14507 \newline 
14508 The second part is more MCU independent and deals with allocating registers
14509  to the remaining live ranges.
14510  A lot of MCU specific code does creep into this phase because of the limited
14511  number of index registers available in the 8051.
14512 \layout Itemize
14513
14514 The Code generation phase is (unhappily), entirely MCU dependent and very
14515  little (if any at all) of this code can be reused for other MCU.
14516  However the scheme for allocating a homogenized assembler operand for each
14517  iCode operand may be reused.
14518 \layout Itemize
14519
14520 As mentioned in the optimization section the peep-hole optimizer is rule
14521  based system, which can reprogrammed for other MCUs.
14522 \layout Section
14523 \pagebreak_top 
14524 SDCDB
14525 \begin_inset LatexCommand \index{sdcdb}
14526
14527 \end_inset 
14528
14529  - Source Level Debugger
14530 \begin_inset LatexCommand \index{Debugger}
14531
14532 \end_inset 
14533
14534
14535 \layout Standard
14536
14537 SDCC is distributed with a source level debugger.
14538  The debugger uses a command line interface, the command repertoire of the
14539  debugger has been kept as close to gdb
14540 \begin_inset LatexCommand \index{gdb}
14541
14542 \end_inset 
14543
14544  (the GNU debugger) as possible.
14545  The configuration and build process is part of the standard compiler installati
14546 on, which also builds and installs the debugger in the target directory
14547  specified during configuration.
14548  The debugger allows you debug BOTH at the C source and at the ASM source
14549  level.
14550  Sdcdb is available on Unix platforms only.
14551 \layout Subsection
14552
14553 Compiling for Debugging
14554 \layout Standard
14555
14556 The \SpecialChar \-
14557 \SpecialChar \-
14558 debug option must be specified for all files for which debug information
14559  is to be generated.
14560  The complier generates a .adb file for each of these files.
14561  The linker creates the .cdb file from the .adb files and the address information.
14562  This .cdb is used by the debugger.
14563 \layout Subsection
14564
14565 How the Debugger Works
14566 \layout Standard
14567
14568 When the -
14569 \begin_inset ERT
14570 status Collapsed
14571
14572 \layout Standard
14573
14574 \backslash 
14575 /
14576 \end_inset 
14577
14578 -debug option is specified the compiler generates extra symbol information
14579  some of which are put into the the assembler source and some are put into
14580  the .adb file.
14581   Then the linker creates the .cdb file from the individual .adb files with
14582  the address information for the symbols.
14583  The debugger reads the symbolic information generated by the compiler &
14584  the address information generated by the linker.
14585  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
14586  execution is controlled by the debugger.
14587  When a command is issued for the debugger, it translates it into appropriate
14588  commands for the simulator.
14589 \layout Subsection
14590
14591 Starting the Debugger
14592 \layout Standard
14593
14594 The debugger can be started using the following command line.
14595  (Assume the file you are debugging has the file name foo).
14596 \newline 
14597
14598 \newline 
14599
14600 \family sans 
14601 \series bold 
14602 sdcdb foo
14603 \newline 
14604
14605 \family default 
14606 \series default 
14607
14608 \newline 
14609 The debugger will look for the following files.
14610 \layout Itemize
14611
14612 foo.c - the source file.
14613 \layout Itemize
14614
14615 foo.cdb - the debugger symbol information file.
14616 \layout Itemize
14617
14618 foo.ihx - the Intel hex format
14619 \begin_inset LatexCommand \index{Intel hex format}
14620
14621 \end_inset 
14622
14623  object file.
14624 \layout Subsection
14625
14626 Command Line Options.
14627 \layout Itemize
14628
14629 -
14630 \begin_inset ERT
14631 status Collapsed
14632
14633 \layout Standard
14634
14635 \backslash 
14636 /
14637 \end_inset 
14638
14639 -directory=<source file directory> this option can used to specify the directory
14640  search list.
14641  The debugger will look into the directory list specified for source, cdb
14642  & ihx files.
14643  The items in the directory list must be separated by ':', e.g.
14644  if the source files can be in the directories /home/src1 and /home/src2,
14645  the -
14646 \begin_inset ERT
14647 status Collapsed
14648
14649 \layout Standard
14650
14651 \backslash 
14652 /
14653 \end_inset 
14654
14655 -directory option should be -
14656 \begin_inset ERT
14657 status Collapsed
14658
14659 \layout Standard
14660
14661 \backslash 
14662 /
14663 \end_inset 
14664
14665 -directory=/home/src1:/home/src2.
14666  Note there can be no spaces in the option.
14667  
14668 \layout Itemize
14669
14670 -cd <directory> - change to the <directory>.
14671 \layout Itemize
14672
14673 -fullname - used by GUI front ends.
14674 \layout Itemize
14675
14676 -cpu <cpu-type> - this argument is passed to the simulator please see the
14677  simulator docs for details.
14678 \layout Itemize
14679
14680 -X <Clock frequency > this options is passed to the simulator please see
14681  the simulator docs for details.
14682 \layout Itemize
14683
14684 -s <serial port file> passed to simulator see the simulator docs for details.
14685 \layout Itemize
14686
14687 -S <serial in,out> passed to simulator see the simulator docs for details.
14688 \layout Subsection
14689
14690 Debugger Commands.
14691 \layout Standard
14692
14693 As mention earlier the command interface for the debugger has been deliberately
14694  kept as close the GNU debugger gdb, as possible.
14695  This will help the integration with existing graphical user interfaces
14696  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
14697 \layout Subsubsection
14698
14699 break [line | file:line | function | file:function]
14700 \layout Standard
14701
14702 Set breakpoint at specified line or function:
14703 \newline 
14704
14705 \newline 
14706
14707 \family sans 
14708 \series bold 
14709 sdcdb>break 100 
14710 \newline 
14711 sdcdb>break foo.c:100
14712 \newline 
14713 sdcdb>break funcfoo
14714 \newline 
14715 sdcdb>break foo.c:funcfoo
14716 \layout Subsubsection
14717
14718 clear [line | file:line | function | file:function ]
14719 \layout Standard
14720
14721 Clear breakpoint at specified line or function:
14722 \newline 
14723
14724 \newline 
14725
14726 \family sans 
14727 \series bold 
14728 sdcdb>clear 100
14729 \newline 
14730 sdcdb>clear foo.c:100
14731 \newline 
14732 sdcdb>clear funcfoo
14733 \newline 
14734 sdcdb>clear foo.c:funcfoo
14735 \layout Subsubsection
14736
14737 continue
14738 \layout Standard
14739
14740 Continue program being debugged, after breakpoint.
14741 \layout Subsubsection
14742
14743 finish
14744 \layout Standard
14745
14746 Execute till the end of the current function.
14747 \layout Subsubsection
14748
14749 delete [n]
14750 \layout Standard
14751
14752 Delete breakpoint number 'n'.
14753  If used without any option clear ALL user defined break points.
14754 \layout Subsubsection
14755
14756 info [break | stack | frame | registers ]
14757 \layout Itemize
14758
14759 info break - list all breakpoints
14760 \layout Itemize
14761
14762 info stack - show the function call stack.
14763 \layout Itemize
14764
14765 info frame - show information about the current execution frame.
14766 \layout Itemize
14767
14768 info registers - show content of all registers.
14769 \layout Subsubsection
14770
14771 step
14772 \layout Standard
14773
14774 Step program until it reaches a different source line.
14775 \layout Subsubsection
14776
14777 next
14778 \layout Standard
14779
14780 Step program, proceeding through subroutine calls.
14781 \layout Subsubsection
14782
14783 run
14784 \layout Standard
14785
14786 Start debugged program.
14787 \layout Subsubsection
14788
14789 ptype variable 
14790 \layout Standard
14791
14792 Print type information of the variable.
14793 \layout Subsubsection
14794
14795 print variable
14796 \layout Standard
14797
14798 print value of variable.
14799 \layout Subsubsection
14800
14801 file filename
14802 \layout Standard
14803
14804 load the given file name.
14805  Note this is an alternate method of loading file for debugging.
14806 \layout Subsubsection
14807
14808 frame
14809 \layout Standard
14810
14811 print information about current frame.
14812 \layout Subsubsection
14813
14814 set srcmode
14815 \layout Standard
14816
14817 Toggle between C source & assembly source.
14818 \layout Subsubsection
14819
14820 ! simulator command
14821 \layout Standard
14822
14823 Send the string following '!' to the simulator, the simulator response is
14824  displayed.
14825  Note the debugger does not interpret the command being sent to the simulator,
14826  so if a command like 'go' is sent the debugger can loose its execution
14827  context and may display incorrect values.
14828 \layout Subsubsection
14829
14830 quit.
14831 \layout Standard
14832
14833 "Watch me now.
14834  Iam going Down.
14835  My name is Bobby Brown"
14836 \layout Subsection
14837
14838 Interfacing with XEmacs
14839 \begin_inset LatexCommand \index{XEmacs}
14840
14841 \end_inset 
14842
14843
14844 \begin_inset LatexCommand \index{Emacs}
14845
14846 \end_inset 
14847
14848 .
14849 \layout Standard
14850
14851 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
14852  sdcdb.el and sdcdbsrc.el.
14853  These two files can be found in the $(prefix)/bin directory after the installat
14854 ion is complete.
14855  These files need to be loaded into XEmacs for the interface to work.
14856  This can be done at XEmacs startup time by inserting the following into
14857  your '.xemacs' file (which can be found in your HOME directory): 
14858 \newline 
14859
14860 \newline 
14861
14862 \family typewriter 
14863 (load-file sdcdbsrc.el) 
14864 \family default 
14865
14866 \newline 
14867
14868 \newline 
14869 .xemacs is a lisp file so the () around the command is REQUIRED.
14870  The files can also be loaded dynamically while XEmacs is running, set the
14871  environment variable 'EMACSLOADPATH' to the installation bin directory
14872  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
14873  To start the interface enter the following command: 
14874 \newline 
14875
14876 \newline 
14877
14878 \family sans 
14879 \series bold 
14880 ESC-x sdcdbsrc
14881 \family default 
14882 \series default 
14883
14884 \newline 
14885
14886 \newline 
14887 You will prompted to enter the file name to be debugged.
14888  
14889 \newline 
14890
14891 \newline 
14892 The command line options that are passed to the simulator directly are bound
14893  to default values in the file sdcdbsrc.el.
14894  The variables are listed below, these values maybe changed as required.
14895 \layout Itemize
14896
14897 sdcdbsrc-cpu-type '51
14898 \layout Itemize
14899
14900 sdcdbsrc-frequency '11059200
14901 \layout Itemize
14902
14903 sdcdbsrc-serial nil
14904 \layout Standard
14905
14906 The following is a list of key mapping for the debugger interface.
14907 \layout Standard
14908
14909 \SpecialChar ~
14910
14911 \family typewriter 
14912
14913 \newline 
14914 ;; Current Listing :: 
14915 \newline 
14916 ;;key\SpecialChar ~
14917 \SpecialChar ~
14918 \SpecialChar ~
14919 \SpecialChar ~
14920 \SpecialChar ~
14921 \SpecialChar ~
14922 \SpecialChar ~
14923 \SpecialChar ~
14924 \SpecialChar ~
14925 \SpecialChar ~
14926 \SpecialChar ~
14927 \SpecialChar ~
14928 \SpecialChar ~
14929 \SpecialChar ~
14930 \SpecialChar ~
14931 binding\SpecialChar ~
14932 \SpecialChar ~
14933 \SpecialChar ~
14934 \SpecialChar ~
14935 \SpecialChar ~
14936 \SpecialChar ~
14937 \SpecialChar ~
14938 \SpecialChar ~
14939 \SpecialChar ~
14940 \SpecialChar ~
14941 \SpecialChar ~
14942 \SpecialChar ~
14943 \SpecialChar ~
14944 \SpecialChar ~
14945 \SpecialChar ~
14946 \SpecialChar ~
14947 \SpecialChar ~
14948 \SpecialChar ~
14949 \SpecialChar ~
14950 \SpecialChar ~
14951 \SpecialChar ~
14952 \SpecialChar ~
14953 Comment 
14954 \newline 
14955 ;;---\SpecialChar ~
14956 \SpecialChar ~
14957 \SpecialChar ~
14958 \SpecialChar ~
14959 \SpecialChar ~
14960 \SpecialChar ~
14961 \SpecialChar ~
14962 \SpecialChar ~
14963 \SpecialChar ~
14964 \SpecialChar ~
14965 \SpecialChar ~
14966 \SpecialChar ~
14967 \SpecialChar ~
14968 \SpecialChar ~
14969 \SpecialChar ~
14970 ------\SpecialChar ~
14971 \SpecialChar ~
14972 \SpecialChar ~
14973 \SpecialChar ~
14974 \SpecialChar ~
14975 \SpecialChar ~
14976 \SpecialChar ~
14977 \SpecialChar ~
14978 \SpecialChar ~
14979 \SpecialChar ~
14980 \SpecialChar ~
14981 \SpecialChar ~
14982 \SpecialChar ~
14983 \SpecialChar ~
14984 \SpecialChar ~
14985 \SpecialChar ~
14986 \SpecialChar ~
14987 \SpecialChar ~
14988 \SpecialChar ~
14989 \SpecialChar ~
14990 \SpecialChar ~
14991 \SpecialChar ~
14992 --------
14993 \newline 
14994 ;; 
14995 \newline 
14996 ;; n\SpecialChar ~
14997 \SpecialChar ~
14998 \SpecialChar ~
14999 \SpecialChar ~
15000 \SpecialChar ~
15001 \SpecialChar ~
15002 \SpecialChar ~
15003 \SpecialChar ~
15004 \SpecialChar ~
15005 \SpecialChar ~
15006 \SpecialChar ~
15007 \SpecialChar ~
15008 \SpecialChar ~
15009 \SpecialChar ~
15010  sdcdb-next-from-src\SpecialChar ~
15011 \SpecialChar ~
15012 \SpecialChar ~
15013 \SpecialChar ~
15014 \SpecialChar ~
15015 \SpecialChar ~
15016 \SpecialChar ~
15017 \SpecialChar ~
15018 \SpecialChar ~
15019 \SpecialChar ~
15020 SDCDB next command 
15021 \newline 
15022 ;; b\SpecialChar ~
15023 \SpecialChar ~
15024 \SpecialChar ~
15025 \SpecialChar ~
15026 \SpecialChar ~
15027 \SpecialChar ~
15028 \SpecialChar ~
15029 \SpecialChar ~
15030 \SpecialChar ~
15031 \SpecialChar ~
15032 \SpecialChar ~
15033 \SpecialChar ~
15034 \SpecialChar ~
15035 \SpecialChar ~
15036  sdcdb-back-from-src\SpecialChar ~
15037 \SpecialChar ~
15038 \SpecialChar ~
15039 \SpecialChar ~
15040 \SpecialChar ~
15041 \SpecialChar ~
15042 \SpecialChar ~
15043 \SpecialChar ~
15044 \SpecialChar ~
15045 \SpecialChar ~
15046 SDCDB back command 
15047 \newline 
15048 ;; c\SpecialChar ~
15049 \SpecialChar ~
15050 \SpecialChar ~
15051 \SpecialChar ~
15052 \SpecialChar ~
15053 \SpecialChar ~
15054 \SpecialChar ~
15055 \SpecialChar ~
15056 \SpecialChar ~
15057 \SpecialChar ~
15058 \SpecialChar ~
15059 \SpecialChar ~
15060 \SpecialChar ~
15061 \SpecialChar ~
15062  sdcdb-cont-from-src\SpecialChar ~
15063 \SpecialChar ~
15064 \SpecialChar ~
15065 \SpecialChar ~
15066 \SpecialChar ~
15067 \SpecialChar ~
15068 \SpecialChar ~
15069 \SpecialChar ~
15070 \SpecialChar ~
15071 \SpecialChar ~
15072 SDCDB continue command
15073 \newline 
15074 ;; s\SpecialChar ~
15075 \SpecialChar ~
15076 \SpecialChar ~
15077 \SpecialChar ~
15078 \SpecialChar ~
15079 \SpecialChar ~
15080 \SpecialChar ~
15081 \SpecialChar ~
15082 \SpecialChar ~
15083 \SpecialChar ~
15084 \SpecialChar ~
15085 \SpecialChar ~
15086 \SpecialChar ~
15087 \SpecialChar ~
15088  sdcdb-step-from-src\SpecialChar ~
15089 \SpecialChar ~
15090 \SpecialChar ~
15091 \SpecialChar ~
15092 \SpecialChar ~
15093 \SpecialChar ~
15094 \SpecialChar ~
15095 \SpecialChar ~
15096 \SpecialChar ~
15097 \SpecialChar ~
15098 SDCDB step command 
15099 \newline 
15100 ;; ?\SpecialChar ~
15101 \SpecialChar ~
15102 \SpecialChar ~
15103 \SpecialChar ~
15104 \SpecialChar ~
15105 \SpecialChar ~
15106 \SpecialChar ~
15107 \SpecialChar ~
15108 \SpecialChar ~
15109 \SpecialChar ~
15110 \SpecialChar ~
15111 \SpecialChar ~
15112 \SpecialChar ~
15113 \SpecialChar ~
15114  sdcdb-whatis-c-sexp\SpecialChar ~
15115 \SpecialChar ~
15116 \SpecialChar ~
15117 \SpecialChar ~
15118 \SpecialChar ~
15119 \SpecialChar ~
15120 \SpecialChar ~
15121 \SpecialChar ~
15122 \SpecialChar ~
15123 \SpecialChar ~
15124 SDCDB ptypecommand for data at 
15125 \newline 
15126 ;;\SpecialChar ~
15127 \SpecialChar ~
15128 \SpecialChar ~
15129 \SpecialChar ~
15130 \SpecialChar ~
15131 \SpecialChar ~
15132 \SpecialChar ~
15133 \SpecialChar ~
15134 \SpecialChar ~
15135 \SpecialChar ~
15136 \SpecialChar ~
15137 \SpecialChar ~
15138 \SpecialChar ~
15139 \SpecialChar ~
15140 \SpecialChar ~
15141 \SpecialChar ~
15142 \SpecialChar ~
15143 \SpecialChar ~
15144 \SpecialChar ~
15145 \SpecialChar ~
15146 \SpecialChar ~
15147 \SpecialChar ~
15148 \SpecialChar ~
15149 \SpecialChar ~
15150 \SpecialChar ~
15151 \SpecialChar ~
15152 \SpecialChar ~
15153 \SpecialChar ~
15154 \SpecialChar ~
15155 \SpecialChar ~
15156 \SpecialChar ~
15157 \SpecialChar ~
15158 \SpecialChar ~
15159 \SpecialChar ~
15160 \SpecialChar ~
15161 \SpecialChar ~
15162 \SpecialChar ~
15163 \SpecialChar ~
15164 \SpecialChar ~
15165 \SpecialChar ~
15166 \SpecialChar ~
15167 \SpecialChar ~
15168 \SpecialChar ~
15169 \SpecialChar ~
15170 \SpecialChar ~
15171 \SpecialChar ~
15172  buffer point 
15173 \newline 
15174 ;; x\SpecialChar ~
15175 \SpecialChar ~
15176 \SpecialChar ~
15177 \SpecialChar ~
15178 \SpecialChar ~
15179 \SpecialChar ~
15180 \SpecialChar ~
15181 \SpecialChar ~
15182 \SpecialChar ~
15183 \SpecialChar ~
15184 \SpecialChar ~
15185 \SpecialChar ~
15186 \SpecialChar ~
15187 \SpecialChar ~
15188  sdcdbsrc-delete\SpecialChar ~
15189 \SpecialChar ~
15190 \SpecialChar ~
15191 \SpecialChar ~
15192 \SpecialChar ~
15193 \SpecialChar ~
15194 \SpecialChar ~
15195 \SpecialChar ~
15196 \SpecialChar ~
15197 \SpecialChar ~
15198 \SpecialChar ~
15199 \SpecialChar ~
15200 \SpecialChar ~
15201 \SpecialChar ~
15202 SDCDB Delete all breakpoints if no arg 
15203 \newline 
15204 ;;\SpecialChar ~
15205 \SpecialChar ~
15206 \SpecialChar ~
15207 \SpecialChar ~
15208 \SpecialChar ~
15209 \SpecialChar ~
15210 \SpecialChar ~
15211 \SpecialChar ~
15212 \SpecialChar ~
15213 \SpecialChar ~
15214 \SpecialChar ~
15215 \SpecialChar ~
15216 \SpecialChar ~
15217 \SpecialChar ~
15218 \SpecialChar ~
15219 \SpecialChar ~
15220 \SpecialChar ~
15221 \SpecialChar ~
15222 \SpecialChar ~
15223 \SpecialChar ~
15224 \SpecialChar ~
15225 \SpecialChar ~
15226 \SpecialChar ~
15227 \SpecialChar ~
15228 \SpecialChar ~
15229 \SpecialChar ~
15230 \SpecialChar ~
15231 \SpecialChar ~
15232 \SpecialChar ~
15233 \SpecialChar ~
15234 \SpecialChar ~
15235 \SpecialChar ~
15236 \SpecialChar ~
15237 \SpecialChar ~
15238 \SpecialChar ~
15239 \SpecialChar ~
15240 \SpecialChar ~
15241 \SpecialChar ~
15242 \SpecialChar ~
15243 \SpecialChar ~
15244 \SpecialChar ~
15245 \SpecialChar ~
15246 \SpecialChar ~
15247 \SpecialChar ~
15248 \SpecialChar ~
15249 \SpecialChar ~
15250 given or delete arg (C-u arg x) 
15251 \newline 
15252 ;; m\SpecialChar ~
15253 \SpecialChar ~
15254 \SpecialChar ~
15255 \SpecialChar ~
15256 \SpecialChar ~
15257 \SpecialChar ~
15258 \SpecialChar ~
15259 \SpecialChar ~
15260 \SpecialChar ~
15261 \SpecialChar ~
15262 \SpecialChar ~
15263 \SpecialChar ~
15264 \SpecialChar ~
15265 \SpecialChar ~
15266  sdcdbsrc-frame\SpecialChar ~
15267 \SpecialChar ~
15268 \SpecialChar ~
15269 \SpecialChar ~
15270 \SpecialChar ~
15271 \SpecialChar ~
15272 \SpecialChar ~
15273 \SpecialChar ~
15274 \SpecialChar ~
15275 \SpecialChar ~
15276 \SpecialChar ~
15277 \SpecialChar ~
15278 \SpecialChar ~
15279 \SpecialChar ~
15280 \SpecialChar ~
15281 SDCDB Display current frame if no arg, 
15282 \newline 
15283 ;;\SpecialChar ~
15284 \SpecialChar ~
15285 \SpecialChar ~
15286 \SpecialChar ~
15287 \SpecialChar ~
15288 \SpecialChar ~
15289 \SpecialChar ~
15290 \SpecialChar ~
15291 \SpecialChar ~
15292 \SpecialChar ~
15293 \SpecialChar ~
15294 \SpecialChar ~
15295 \SpecialChar ~
15296 \SpecialChar ~
15297 \SpecialChar ~
15298 \SpecialChar ~
15299 \SpecialChar ~
15300 \SpecialChar ~
15301 \SpecialChar ~
15302 \SpecialChar ~
15303 \SpecialChar ~
15304 \SpecialChar ~
15305 \SpecialChar ~
15306 \SpecialChar ~
15307 \SpecialChar ~
15308 \SpecialChar ~
15309 \SpecialChar ~
15310 \SpecialChar ~
15311 \SpecialChar ~
15312 \SpecialChar ~
15313 \SpecialChar ~
15314 \SpecialChar ~
15315 \SpecialChar ~
15316 \SpecialChar ~
15317 \SpecialChar ~
15318 \SpecialChar ~
15319 \SpecialChar ~
15320 \SpecialChar ~
15321 \SpecialChar ~
15322 \SpecialChar ~
15323 \SpecialChar ~
15324 \SpecialChar ~
15325 \SpecialChar ~
15326 \SpecialChar ~
15327 \SpecialChar ~
15328 \SpecialChar ~
15329 \SpecialChar ~
15330 given or display frame arg 
15331 \newline 
15332 ;;\SpecialChar ~
15333 \SpecialChar ~
15334 \SpecialChar ~
15335 \SpecialChar ~
15336 \SpecialChar ~
15337 \SpecialChar ~
15338 \SpecialChar ~
15339 \SpecialChar ~
15340 \SpecialChar ~
15341 \SpecialChar ~
15342 \SpecialChar ~
15343 \SpecialChar ~
15344 \SpecialChar ~
15345 \SpecialChar ~
15346 \SpecialChar ~
15347 \SpecialChar ~
15348 \SpecialChar ~
15349 \SpecialChar ~
15350 \SpecialChar ~
15351 \SpecialChar ~
15352 \SpecialChar ~
15353 \SpecialChar ~
15354 \SpecialChar ~
15355 \SpecialChar ~
15356 \SpecialChar ~
15357 \SpecialChar ~
15358 \SpecialChar ~
15359 \SpecialChar ~
15360 \SpecialChar ~
15361 \SpecialChar ~
15362 \SpecialChar ~
15363 \SpecialChar ~
15364 \SpecialChar ~
15365 \SpecialChar ~
15366 \SpecialChar ~
15367 \SpecialChar ~
15368 \SpecialChar ~
15369 \SpecialChar ~
15370 \SpecialChar ~
15371 \SpecialChar ~
15372 \SpecialChar ~
15373 \SpecialChar ~
15374 \SpecialChar ~
15375 \SpecialChar ~
15376 \SpecialChar ~
15377 \SpecialChar ~
15378 \SpecialChar ~
15379 buffer point 
15380 \newline 
15381 ;; !\SpecialChar ~
15382 \SpecialChar ~
15383 \SpecialChar ~
15384 \SpecialChar ~
15385 \SpecialChar ~
15386 \SpecialChar ~
15387 \SpecialChar ~
15388 \SpecialChar ~
15389 \SpecialChar ~
15390 \SpecialChar ~
15391 \SpecialChar ~
15392 \SpecialChar ~
15393 \SpecialChar ~
15394 \SpecialChar ~
15395  sdcdbsrc-goto-sdcdb\SpecialChar ~
15396 \SpecialChar ~
15397 \SpecialChar ~
15398 \SpecialChar ~
15399 \SpecialChar ~
15400 \SpecialChar ~
15401 \SpecialChar ~
15402 \SpecialChar ~
15403 \SpecialChar ~
15404 \SpecialChar ~
15405 Goto the SDCDB output buffer 
15406 \newline 
15407 ;; p\SpecialChar ~
15408 \SpecialChar ~
15409 \SpecialChar ~
15410 \SpecialChar ~
15411 \SpecialChar ~
15412 \SpecialChar ~
15413 \SpecialChar ~
15414 \SpecialChar ~
15415 \SpecialChar ~
15416 \SpecialChar ~
15417 \SpecialChar ~
15418 \SpecialChar ~
15419 \SpecialChar ~
15420 \SpecialChar ~
15421  sdcdb-print-c-sexp\SpecialChar ~
15422 \SpecialChar ~
15423 \SpecialChar ~
15424 \SpecialChar ~
15425 \SpecialChar ~
15426 \SpecialChar ~
15427 \SpecialChar ~
15428 \SpecialChar ~
15429 \SpecialChar ~
15430 \SpecialChar ~
15431 \SpecialChar ~
15432 SDCDB print command for data at 
15433 \newline 
15434 ;;\SpecialChar ~
15435 \SpecialChar ~
15436 \SpecialChar ~
15437 \SpecialChar ~
15438 \SpecialChar ~
15439 \SpecialChar ~
15440 \SpecialChar ~
15441 \SpecialChar ~
15442 \SpecialChar ~
15443 \SpecialChar ~
15444 \SpecialChar ~
15445 \SpecialChar ~
15446 \SpecialChar ~
15447 \SpecialChar ~
15448 \SpecialChar ~
15449 \SpecialChar ~
15450 \SpecialChar ~
15451 \SpecialChar ~
15452 \SpecialChar ~
15453 \SpecialChar ~
15454 \SpecialChar ~
15455 \SpecialChar ~
15456 \SpecialChar ~
15457 \SpecialChar ~
15458 \SpecialChar ~
15459 \SpecialChar ~
15460 \SpecialChar ~
15461 \SpecialChar ~
15462 \SpecialChar ~
15463 \SpecialChar ~
15464 \SpecialChar ~
15465 \SpecialChar ~
15466 \SpecialChar ~
15467 \SpecialChar ~
15468 \SpecialChar ~
15469 \SpecialChar ~
15470 \SpecialChar ~
15471 \SpecialChar ~
15472 \SpecialChar ~
15473 \SpecialChar ~
15474 \SpecialChar ~
15475 \SpecialChar ~
15476 \SpecialChar ~
15477 \SpecialChar ~
15478 \SpecialChar ~
15479 \SpecialChar ~
15480  buffer point 
15481 \newline 
15482 ;; g\SpecialChar ~
15483 \SpecialChar ~
15484 \SpecialChar ~
15485 \SpecialChar ~
15486 \SpecialChar ~
15487 \SpecialChar ~
15488 \SpecialChar ~
15489 \SpecialChar ~
15490 \SpecialChar ~
15491 \SpecialChar ~
15492 \SpecialChar ~
15493 \SpecialChar ~
15494 \SpecialChar ~
15495 \SpecialChar ~
15496  sdcdbsrc-goto-sdcdb\SpecialChar ~
15497 \SpecialChar ~
15498 \SpecialChar ~
15499 \SpecialChar ~
15500 \SpecialChar ~
15501 \SpecialChar ~
15502 \SpecialChar ~
15503 \SpecialChar ~
15504 \SpecialChar ~
15505 \SpecialChar ~
15506 Goto the SDCDB output buffer 
15507 \newline 
15508 ;; t\SpecialChar ~
15509 \SpecialChar ~
15510 \SpecialChar ~
15511 \SpecialChar ~
15512 \SpecialChar ~
15513 \SpecialChar ~
15514 \SpecialChar ~
15515 \SpecialChar ~
15516 \SpecialChar ~
15517 \SpecialChar ~
15518 \SpecialChar ~
15519 \SpecialChar ~
15520 \SpecialChar ~
15521 \SpecialChar ~
15522  sdcdbsrc-mode\SpecialChar ~
15523 \SpecialChar ~
15524 \SpecialChar ~
15525 \SpecialChar ~
15526 \SpecialChar ~
15527 \SpecialChar ~
15528 \SpecialChar ~
15529 \SpecialChar ~
15530 \SpecialChar ~
15531 \SpecialChar ~
15532 \SpecialChar ~
15533 \SpecialChar ~
15534 \SpecialChar ~
15535 \SpecialChar ~
15536 \SpecialChar ~
15537 \SpecialChar ~
15538 Toggles Sdcdbsrc mode (turns it off) 
15539 \newline 
15540 ;; 
15541 \newline 
15542 ;; C-c C-f\SpecialChar ~
15543 \SpecialChar ~
15544 \SpecialChar ~
15545 \SpecialChar ~
15546 \SpecialChar ~
15547 \SpecialChar ~
15548 \SpecialChar ~
15549 \SpecialChar ~
15550  sdcdb-finish-from-src\SpecialChar ~
15551 \SpecialChar ~
15552 \SpecialChar ~
15553 \SpecialChar ~
15554 \SpecialChar ~
15555 \SpecialChar ~
15556 \SpecialChar ~
15557 \SpecialChar ~
15558 SDCDB finish command 
15559 \newline 
15560 ;; 
15561 \newline 
15562 ;; C-x SPC\SpecialChar ~
15563 \SpecialChar ~
15564 \SpecialChar ~
15565 \SpecialChar ~
15566 \SpecialChar ~
15567 \SpecialChar ~
15568 \SpecialChar ~
15569 \SpecialChar ~
15570  sdcdb-break\SpecialChar ~
15571 \SpecialChar ~
15572 \SpecialChar ~
15573 \SpecialChar ~
15574 \SpecialChar ~
15575 \SpecialChar ~
15576 \SpecialChar ~
15577 \SpecialChar ~
15578 \SpecialChar ~
15579 \SpecialChar ~
15580 \SpecialChar ~
15581 \SpecialChar ~
15582 \SpecialChar ~
15583 \SpecialChar ~
15584 \SpecialChar ~
15585 \SpecialChar ~
15586 \SpecialChar ~
15587 \SpecialChar ~
15588 Set break for line with point 
15589 \newline 
15590 ;; ESC t\SpecialChar ~
15591 \SpecialChar ~
15592 \SpecialChar ~
15593 \SpecialChar ~
15594 \SpecialChar ~
15595 \SpecialChar ~
15596 \SpecialChar ~
15597 \SpecialChar ~
15598 \SpecialChar ~
15599 \SpecialChar ~
15600  sdcdbsrc-mode\SpecialChar ~
15601 \SpecialChar ~
15602 \SpecialChar ~
15603 \SpecialChar ~
15604 \SpecialChar ~
15605 \SpecialChar ~
15606 \SpecialChar ~
15607 \SpecialChar ~
15608 \SpecialChar ~
15609 \SpecialChar ~
15610 \SpecialChar ~
15611 \SpecialChar ~
15612 \SpecialChar ~
15613 \SpecialChar ~
15614 \SpecialChar ~
15615 \SpecialChar ~
15616 Toggle Sdcdbsrc mode 
15617 \newline 
15618 ;; ESC m\SpecialChar ~
15619 \SpecialChar ~
15620 \SpecialChar ~
15621 \SpecialChar ~
15622 \SpecialChar ~
15623 \SpecialChar ~
15624 \SpecialChar ~
15625 \SpecialChar ~
15626 \SpecialChar ~
15627 \SpecialChar ~
15628  sdcdbsrc-srcmode\SpecialChar ~
15629 \SpecialChar ~
15630 \SpecialChar ~
15631 \SpecialChar ~
15632 \SpecialChar ~
15633 \SpecialChar ~
15634 \SpecialChar ~
15635 \SpecialChar ~
15636 \SpecialChar ~
15637 \SpecialChar ~
15638 \SpecialChar ~
15639 \SpecialChar ~
15640  Toggle list mode 
15641 \newline 
15642 ;; 
15643 \family default 
15644
15645 \newline 
15646
15647 \layout Section
15648
15649 Other Processors
15650 \layout Subsection
15651
15652 The Z80 and gbz80 port
15653 \layout Standard
15654
15655 SDCC can target both the Zilog 
15656 \begin_inset LatexCommand \index{Z80}
15657
15658 \end_inset 
15659
15660  and the Nintendo Gameboy's Z80-like gbz80
15661 \begin_inset LatexCommand \index{GameBoy Z80}
15662
15663 \end_inset 
15664
15665 .
15666  The port is incomplete - long support is incomplete (mul, div and mod are
15667  unimplemented), and both float and bitfield support is missing.
15668  Apart from that the code generated is correct.
15669 \layout Standard
15670
15671 As always, the code is the authoritative reference - see z80/ralloc.c and
15672  z80/gen.c.
15673  The stack frame is similar to that generated by the IAR Z80 compiler.
15674  IX is used as the base pointer, HL is used as a temporary register, and
15675  BC and DE are available for holding variables.
15676  IY is currently unused.
15677  Return values are stored in HL.
15678  One bad side effect of using IX as the base pointer is that a functions
15679  stack frame is limited to 127 bytes - this will be fixed in a later version.
15680 \layout Section
15681 \pagebreak_top 
15682 Support
15683 \begin_inset LatexCommand \index{Support}
15684
15685 \end_inset 
15686
15687
15688 \layout Standard
15689
15690 SDCC has grown to be a large project.
15691  The compiler alone (without the preprocessor, assembler and linker) is
15692  about 40,000 lines of code (blank stripped).
15693  The open source nature of this project is a key to its continued growth
15694  and support.
15695  You gain the benefit and support of many active software developers and
15696  end users.
15697  Is SDCC perfect? No, that's why we need your help.
15698  The developers take pride in fixing reported bugs.
15699  You can help by reporting the bugs and helping other SDCC users.
15700  There are lots of ways to contribute, and we encourage you to take part
15701  in making SDCC a great software package.
15702  
15703 \layout Standard
15704
15705 The SDCC project is hosted on the sdcc sourceforge site at 
15706 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
15707
15708 \end_inset 
15709
15710 .
15711  You'll find the complete set of mailing lists
15712 \begin_inset LatexCommand \index{Mailing list}
15713
15714 \end_inset 
15715
15716 , forums, bug reporting system, patch submission
15717 \begin_inset LatexCommand \index{Patch submission}
15718
15719 \end_inset 
15720
15721  system, download
15722 \begin_inset LatexCommand \index{download}
15723
15724 \end_inset 
15725
15726  area and cvs code repository
15727 \begin_inset LatexCommand \index{cvs code repository}
15728
15729 \end_inset 
15730
15731  there.
15732 \layout Subsection
15733
15734 Reporting Bugs
15735 \begin_inset LatexCommand \index{Bugs}
15736
15737 \end_inset 
15738
15739
15740 \begin_inset LatexCommand \index{Reporting bugs}
15741
15742 \end_inset 
15743
15744
15745 \layout Standard
15746
15747 The recommended way of reporting bugs is using the infrastructure of the
15748  sourceforge site.
15749  You can follow the status of bug reports there and have an overview about
15750  the known bugs.
15751 \layout Standard
15752
15753 Bug reports are automatically forwarded to the developer mailing list and
15754  will be fixed ASAP.
15755  When reporting a bug, it is very useful to include a small test program
15756  (the smaller the better) which reproduces the problem.
15757  If you can isolate the problem by looking at the generated assembly code,
15758  this can be very helpful.
15759  Compiling your program with the -
15760 \begin_inset ERT
15761 status Collapsed
15762
15763 \layout Standard
15764
15765 \backslash 
15766 /
15767 \end_inset 
15768
15769 -dumpall
15770 \begin_inset LatexCommand \index{-\/-dumpall}
15771
15772 \end_inset 
15773
15774  option can sometimes be useful in locating optimization problems.
15775  When reporting a bug please maker sure you:
15776 \layout Enumerate
15777
15778 Attach the code you are compiling with SDCC.
15779  
15780 \layout Enumerate
15781
15782 Specify the exact command you use to run SDCC, or attach your Makefile.
15783  
15784 \layout Enumerate
15785
15786 Specify the SDCC version (type "sdcc -v"), your platform, and operating
15787  system.
15788  
15789 \layout Enumerate
15790
15791 Provide an exact copy of any error message or incorrect output.
15792  
15793 \layout Enumerate
15794
15795 Put something meaningful in the subject of your message.
15796 \layout Standard
15797
15798 Please attempt to include these 5 important parts, as applicable, in all
15799  requests for support or when reporting any problems or bugs with SDCC.
15800  Though this will make your message lengthy, it will greatly improve your
15801  chance that SDCC users and developers will be able to help you.
15802  Some SDCC developers are frustrated by bug reports without code provided
15803  that they can use to reproduce and ultimately fix the problem, so please
15804  be sure to provide sample code if you are reporting a bug! 
15805 \layout Standard
15806
15807 Please have a short check that you are using a recent version of SDCC and
15808  the bug is not yet known.
15809  This is the link for reporting bugs: 
15810 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
15811
15812 \end_inset 
15813
15814 .
15815 \layout Subsection
15816
15817 Requesting Features
15818 \begin_inset LatexCommand \index{Feature request}
15819
15820 \end_inset 
15821
15822
15823 \begin_inset LatexCommand \index{Requesting features}
15824
15825 \end_inset 
15826
15827
15828 \layout Standard
15829
15830 Like bug reports feature requests are forwarded to the developer mailing
15831  list.
15832  This is the link for requesting features: 
15833 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
15834
15835 \end_inset 
15836
15837 .
15838 \layout Subsection
15839
15840 Getting Help
15841 \layout Standard
15842
15843 These links should take you directly to the 
15844 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
15845
15846 \end_inset 
15847
15848
15849 \begin_inset Foot
15850 collapsed false
15851
15852 \layout Standard
15853
15854 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
15855  automated messages (mid 2003)
15856 \end_inset 
15857
15858  and the 
15859 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
15860
15861 \end_inset 
15862
15863 , lists and forums are archived so if you are lucky someone already had
15864  a similar problem.
15865 \layout Subsection
15866
15867 ChangeLog
15868 \begin_inset LatexCommand \index{Changelog}
15869
15870 \end_inset 
15871
15872
15873 \layout Standard
15874
15875 You can follow the status of the cvs version
15876 \begin_inset LatexCommand \index{version}
15877
15878 \end_inset 
15879
15880  of SDCC by watching the file 
15881 \begin_inset LatexCommand \htmlurl[ChangeLog]{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/sdcc/sdcc/ChangeLog?rev=HEAD&content-type=text/plain}
15882
15883 \end_inset 
15884
15885  in the cvs-repository.
15886 \layout Subsection
15887
15888 Release policy
15889 \begin_inset LatexCommand \index{Release policy}
15890
15891 \end_inset 
15892
15893
15894 \layout Standard
15895
15896 Historically there often were long delays between official releases and
15897  the sourceforge download area tends to get not updated at all.
15898  Current excuses might refer to problems with live range analysis, but if
15899  this is fixed, the next problem rising is that another excuse will have
15900  to be found.
15901  Kidding aside, we have to get better there! On the other hand there are
15902  daily snapshots available at 
15903 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
15904
15905 \end_inset 
15906
15907 , and you can always built the very last version (hopefully with many bugs
15908  fixed, and features added) from the source code available at 
15909 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
15910
15911 \end_inset 
15912
15913 .
15914 \layout Subsection
15915
15916 Examples
15917 \begin_inset LatexCommand \index{Examples}
15918
15919 \end_inset 
15920
15921
15922 \layout Standard
15923
15924 You'll find some small examples in the directory sdcc/device/examples/
15925 \layout Comment
15926
15927 Maybe we should include some links to real world applications.
15928  Preferably pointer to pointers (one for each architecture) so this stays
15929  manageable here?
15930 \layout Subsection
15931
15932 Quality control
15933 \begin_inset LatexCommand \index{Quality control}
15934
15935 \end_inset 
15936
15937
15938 \layout Standard
15939
15940 The compiler is passed through nightly compile and build checks.
15941  The so called 
15942 \shape italic 
15943 regression tests
15944 \shape default 
15945
15946 \begin_inset LatexCommand \index{Regression test}
15947
15948 \end_inset 
15949
15950  check that SDCC itself compiles flawlessly on several platforms and checks
15951  the quality of the code generated by SDCC by running the code through simulator
15952 s.
15953  There is a separate document 
15954 \shape italic 
15955 test_suite.pdf
15956 \begin_inset LatexCommand \index{Test suite}
15957
15958 \end_inset 
15959
15960
15961 \shape default 
15962  about this.
15963 \layout Standard
15964
15965 You'll find the test code in the directory 
15966 \shape italic 
15967 sdcc/support/regression
15968 \shape default 
15969 .
15970  You can run these tests manually by running 
15971 \family sans 
15972 make
15973 \family default 
15974  in this directory (or f.e.
15975  
15976 \family sans 
15977 make test-mcs51
15978 \family default 
15979  if you don't want to run the complete tests).
15980  The test code might also be interesting if you want to look for examples
15981 \begin_inset LatexCommand \index{Examples}
15982
15983 \end_inset 
15984
15985  checking corner cases of SDCC or if you plan to submit patches
15986 \begin_inset LatexCommand \index{Patch submission}
15987
15988 \end_inset 
15989
15990 .
15991 \layout Standard
15992
15993 The pic port uses a different set of regression tests, you'll find them
15994  in the directory 
15995 \shape italic 
15996 sdcc/src/regression
15997 \shape default 
15998 .
15999 \layout Section
16000 \pagebreak_top 
16001 Compiler internals
16002 \begin_inset LatexCommand \index{Compiler internals}
16003
16004 \end_inset 
16005
16006
16007 \layout Subsection
16008
16009 The anatomy of the compiler
16010 \layout Standard
16011
16012
16013 \shape italic 
16014 This is an excerpt from an article published in Circuit Cellar Magazine
16015  in august 2000.
16016  It's a little outdated (the compiler is much more efficient now and user/develo
16017 per friendly), but pretty well exposes the guts of it all.
16018 \shape default 
16019
16020 \newline 
16021
16022 \newline 
16023 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
16024  It is fairly easy to retarget for other 8-bit MCU.
16025  Here we take a look at some of the internals of the compiler.
16026  
16027 \layout Paragraph*
16028
16029 Parsing
16030 \begin_inset LatexCommand \index{Parsing}
16031
16032 \end_inset 
16033
16034  
16035 \layout Standard
16036
16037 Parsing the input source file and creating an AST (Annotated Syntax Tree
16038 \begin_inset LatexCommand \index{Annotated syntax tree}
16039
16040 \end_inset 
16041
16042 ).
16043  This phase also involves propagating types (annotating each node of the
16044  parse tree with type information) and semantic analysis.
16045  There are some MCU specific parsing rules.
16046  For example the storage classes, the extended storage classes are MCU specific
16047  while there may be a xdata storage class for 8051 there is no such storage
16048  class for z80 or Atmel AVR.
16049  SDCC allows MCU specific storage class extensions, i.e.
16050  xdata will be treated as a storage class specifier when parsing 8051 C
16051  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
16052  C code.
16053 \layout Paragraph*
16054
16055 Generating iCode
16056 \begin_inset LatexCommand \index{iCode}
16057
16058 \end_inset 
16059
16060
16061 \layout Standard
16062
16063 Intermediate code generation.
16064  In this phase the AST is broken down into three-operand form (iCode).
16065  These three operand forms are represented as doubly linked lists.
16066  ICode is the term given to the intermediate form generated by the compiler.
16067  ICode example section shows some examples of iCode generated for some simple
16068  C source functions.
16069 \layout Paragraph*
16070
16071 Optimizations
16072 \begin_inset LatexCommand \index{Optimizations}
16073
16074 \end_inset 
16075
16076 .
16077 \layout Standard
16078
16079 Bulk of the target independent optimizations is performed in this phase.
16080  The optimizations include constant propagation, common sub-expression eliminati
16081 on, loop invariant code movement, strength reduction of loop induction variables
16082  and dead-code elimination.
16083 \layout Paragraph*
16084
16085 Live range analysis
16086 \begin_inset LatexCommand \index{Live range analysis}
16087
16088 \end_inset 
16089
16090
16091 \layout Standard
16092
16093 During intermediate code generation phase, the compiler assumes the target
16094  machine has infinite number of registers and generates a lot of temporary
16095  variables.
16096  The live range computation determines the lifetime of each of these compiler-ge
16097 nerated temporaries.
16098  A picture speaks a thousand words.
16099  ICode example sections show the live range annotations for each of the
16100  operand.
16101  It is important to note here, each iCode is assigned a number in the order
16102  of its execution in the function.
16103  The live ranges are computed in terms of these numbers.
16104  The from number is the number of the iCode which first defines the operand
16105  and the to number signifies the iCode which uses this operand last.
16106 \layout Paragraph*
16107
16108 Register Allocation
16109 \begin_inset LatexCommand \index{Register allocation}
16110
16111 \end_inset 
16112
16113
16114 \layout Standard
16115
16116 The register allocation determines the type and number of registers needed
16117  by each operand.
16118  In most MCUs only a few registers can be used for indirect addressing.
16119  In case of 8051 for example the registers R0 & R1 can be used to indirectly
16120  address the internal ram and DPTR to indirectly address the external ram.
16121  The compiler will try to allocate the appropriate register to pointer variables
16122  if it can.
16123  ICode example section shows the operands annotated with the registers assigned
16124  to them.
16125  The compiler will try to keep operands in registers as much as possible;
16126  there are several schemes the compiler uses to do achieve this.
16127  When the compiler runs out of registers the compiler will check to see
16128  if there are any live operands which is not used or defined in the current
16129  basic block being processed, if there are any found then it will push that
16130  operand and use the registers in this block, the operand will then be popped
16131  at the end of the basic block.
16132  
16133 \layout Standard
16134
16135 There are other MCU specific considerations in this phase.
16136  Some MCUs have an accumulator; very short-lived operands could be assigned
16137  to the accumulator instead of general-purpose register.
16138 \layout Paragraph*
16139
16140 Code generation
16141 \layout Standard
16142
16143 Figure II gives a table of iCode operations supported by the compiler.
16144  The code generation involves translating these operations into corresponding
16145  assembly code for the processor.
16146  This sounds overly simple but that is the essence of code generation.
16147  Some of the iCode operations are generated on a MCU specific manner for
16148  example, the z80 port does not use registers to pass parameters so the
16149  SEND and RECV iCode operations will not be generated, and it also does
16150  not support JUMPTABLES.
16151  
16152 \newline 
16153
16154 \series bold 
16155 \shape italic 
16156 \color red
16157 <Where is Figure II ?>
16158 \layout Paragraph*
16159
16160 ICode Example
16161 \begin_inset LatexCommand \index{iCode}
16162
16163 \end_inset 
16164
16165
16166 \layout Standard
16167
16168 This section shows some details of iCode.
16169  The example C code does not do anything useful; it is used as an example
16170  to illustrate the intermediate code generated by the compiler.
16171 \layout Verse
16172
16173
16174 \family typewriter 
16175 1.\SpecialChar ~
16176 xdata int * p;
16177 \newline 
16178 2.\SpecialChar ~
16179 int gint;
16180 \newline 
16181 3.\SpecialChar ~
16182 /* This function does nothing useful.
16183  It is used
16184 \newline 
16185 4.\SpecialChar ~
16186 \SpecialChar ~
16187 \SpecialChar ~
16188 \SpecialChar ~
16189 for the purpose of explaining iCode */
16190 \newline 
16191 5.\SpecialChar ~
16192 short function (data int *x)
16193 \newline 
16194 6.\SpecialChar ~
16195 {
16196 \newline 
16197 7.\SpecialChar ~
16198 \SpecialChar ~
16199 \SpecialChar ~
16200 short i=10; /* dead initialization eliminated */
16201 \newline 
16202 8.\SpecialChar ~
16203 \SpecialChar ~
16204 \SpecialChar ~
16205 short sum=10; /* dead initialization eliminated */
16206 \newline 
16207 9.\SpecialChar ~
16208 \SpecialChar ~
16209 \SpecialChar ~
16210 short mul;
16211 \newline 
16212 10.\SpecialChar ~
16213 \SpecialChar ~
16214 int j ;
16215 \newline 
16216 11.\SpecialChar ~
16217 \SpecialChar ~
16218 while (*x) *x++ = *p++; 
16219 \newline 
16220 12.\SpecialChar ~
16221 \SpecialChar ~
16222 \SpecialChar ~
16223 \SpecialChar ~
16224 sum = 0 ; 
16225 \newline 
16226 13.\SpecialChar ~
16227 \SpecialChar ~
16228 mul = 0;
16229 \newline 
16230 14.\SpecialChar ~
16231 \SpecialChar ~
16232 /* compiler detects i,j to be induction variables */
16233 \newline 
16234 15.\SpecialChar ~
16235 \SpecialChar ~
16236 for (i = 0, j = 10 ; i < 10 ; i++, j
16237 \family default 
16238 -
16239 \begin_inset ERT
16240 status Collapsed
16241
16242 \layout Standard
16243
16244 \backslash 
16245 /
16246 \end_inset 
16247
16248 -
16249 \family typewriter 
16250 ) {
16251 \newline 
16252 16.\SpecialChar ~
16253 \SpecialChar ~
16254 \SpecialChar ~
16255 \SpecialChar ~
16256 sum += i;
16257 \newline 
16258 17.\SpecialChar ~
16259 \SpecialChar ~
16260 \SpecialChar ~
16261 \SpecialChar ~
16262 mul += i * 3; /* this multiplication remains */
16263 \newline 
16264 18.\SpecialChar ~
16265 \SpecialChar ~
16266 \SpecialChar ~
16267 \SpecialChar ~
16268 gint += j * 3;/* this multiplication changed to addition */
16269 \newline 
16270 19.\SpecialChar ~
16271 \SpecialChar ~
16272 }
16273 \newline 
16274 20.\SpecialChar ~
16275 \SpecialChar ~
16276 return sum+mul;
16277 \newline 
16278 21.\SpecialChar ~
16279 }
16280 \layout Standard
16281
16282 In addition to the operands each iCode contains information about the filename
16283  and line it corresponds to in the source file.
16284  The first field in the listing should be interpreted as follows:
16285 \newline 
16286
16287 \shape italic 
16288 \size footnotesize 
16289 Filename(linenumber: iCode Execution sequence number : ICode hash table
16290  key : loop depth of the iCode).
16291 \shape default 
16292 \size default 
16293
16294 \newline 
16295 Then follows the human readable form of the ICode operation.
16296  Each operand of this triplet form can be of three basic types a) compiler
16297  generated temporary b) user defined variable c) a constant value.
16298  Note that local variables and parameters are replaced by compiler generated
16299  temporaries.
16300  Live ranges
16301 \begin_inset LatexCommand \index{Live range analysis}
16302
16303 \end_inset 
16304
16305  are computed only for temporaries (i.e.
16306  live ranges are not computed for global variables).
16307  Registers
16308 \begin_inset LatexCommand \index{Register allocation}
16309
16310 \end_inset 
16311
16312  are allocated for temporaries only.
16313  Operands are formatted in the following manner:
16314 \newline 
16315
16316 \shape italic 
16317 \size footnotesize 
16318 Operand Name [lr live-from : live-to ] { type information } [ registers
16319  allocated ].
16320 \shape default 
16321 \size default 
16322
16323 \newline 
16324 As mentioned earlier the live ranges are computed in terms of the execution
16325  sequence number of the iCodes, for example 
16326 \newline 
16327 the iTemp0 is live from (i.e.
16328  first defined in iCode with execution sequence number 3, and is last used
16329  in the iCode with sequence number 5).
16330  For induction variables such as iTemp21 the live range computation extends
16331  the lifetime from the start to the end of the loop.
16332 \newline 
16333 The register allocator used the live range information to allocate registers,
16334  the same registers may be used for different temporaries if their live
16335  ranges do not overlap, for example r0 is allocated to both iTemp6 and to
16336  iTemp17 since their live ranges do not overlap.
16337  In addition the allocator also takes into consideration the type and usage
16338  of a temporary, for example itemp6 is a pointer to near space and is used
16339  as to fetch data from (i.e.
16340  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer registers (r0).
16341  Some short lived temporaries are allocated to special registers which have
16342  meaning to the code generator e.g.
16343  iTemp13 is allocated to a pseudo register CC which tells the back end that
16344  the temporary is used only for a conditional jump the code generation makes
16345  use of this information to optimize a compare and jump ICode.
16346 \newline 
16347 There are several loop optimizations
16348 \begin_inset LatexCommand \index{Loop optimization}
16349
16350 \end_inset 
16351
16352  performed by the compiler.
16353  It can detect induction variables iTemp21(i) and iTemp23(j).
16354  Also note the compiler does selective strength reduction
16355 \begin_inset LatexCommand \index{Strength reduction}
16356
16357 \end_inset 
16358
16359 , i.e.
16360  the multiplication of an induction variable in line 18 (gint = j * 3) is
16361  changed to addition, a new temporary iTemp17 is allocated and assigned
16362  a initial value, a constant 3 is then added for each iteration of the loop.
16363  The compiler does not change the multiplication
16364 \begin_inset LatexCommand \index{Multiplication}
16365
16366 \end_inset 
16367
16368  in line 17 however since the processor does support an 8 * 8 bit multiplication.
16369 \newline 
16370 Note the dead code elimination
16371 \begin_inset LatexCommand \index{Dead-code elimination}
16372
16373 \end_inset 
16374
16375  optimization eliminated the dead assignments in line 7 & 8 to I and sum
16376  respectively.
16377 \newline 
16378
16379 \layout Standard
16380
16381
16382 \size footnotesize 
16383 Sample.c (5:1:0:0) _entry($9) :
16384 \layout Standard
16385
16386
16387 \size footnotesize 
16388 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
16389 \layout Standard
16390
16391
16392 \size footnotesize 
16393 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
16394 \layout Standard
16395
16396
16397 \size footnotesize 
16398 Sample.c(11:4:53:0) preHeaderLbl0($11) :
16399 \layout Standard
16400
16401
16402 \size footnotesize 
16403 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
16404  * int}[r2]
16405 \layout Standard
16406
16407
16408 \size footnotesize 
16409 Sample.c(11:6:5:1) _whilecontinue_0($1) :
16410 \layout Standard
16411
16412
16413 \size footnotesize 
16414 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
16415  int}[r0]]
16416 \layout Standard
16417
16418
16419 \size footnotesize 
16420 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
16421 \layout Standard
16422
16423
16424 \size footnotesize 
16425 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
16426  * int}
16427 \layout Standard
16428
16429
16430 \size footnotesize 
16431 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
16432  {short}
16433 \layout Standard
16434
16435
16436 \size footnotesize 
16437 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
16438  * int}[DPTR]]
16439 \layout Standard
16440
16441
16442 \size footnotesize 
16443 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
16444 }[r2 r3]
16445 \layout Standard
16446
16447
16448 \size footnotesize 
16449 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
16450  * int}[r0] + 0x2 {short}
16451 \layout Standard
16452
16453
16454 \size footnotesize 
16455 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
16456 \layout Standard
16457
16458
16459 \size footnotesize 
16460 Sample.c(11:17:21:0)_whilebreak_0($3) :
16461 \layout Standard
16462
16463
16464 \size footnotesize 
16465 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
16466 \layout Standard
16467
16468
16469 \size footnotesize 
16470 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
16471 \layout Standard
16472
16473
16474 \size footnotesize 
16475 Sample.c(15:20:54:0)preHeaderLbl1($13) :
16476 \layout Standard
16477
16478
16479 \size footnotesize 
16480 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
16481 \layout Standard
16482
16483
16484 \size footnotesize 
16485 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
16486 \layout Standard
16487
16488
16489 \size footnotesize 
16490 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
16491 \layout Standard
16492
16493
16494 \size footnotesize 
16495 Sample.c(15:24:26:1)_forcond_0($4) :
16496 \layout Standard
16497
16498
16499 \size footnotesize 
16500 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
16501  < 0xa {short}
16502 \layout Standard
16503
16504
16505 \size footnotesize 
16506 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
16507 \layout Standard
16508
16509
16510 \size footnotesize 
16511 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
16512  + ITemp21 [lr21:38]{short}[r4]
16513 \layout Standard
16514
16515
16516 \size footnotesize 
16517 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
16518  * 0x3 {short}
16519 \layout Standard
16520
16521
16522 \size footnotesize 
16523 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
16524  + iTemp15 [lr29:30]{short}[r1]
16525 \layout Standard
16526
16527
16528 \size footnotesize 
16529 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
16530  r0]- 0x3 {short}
16531 \layout Standard
16532
16533
16534 \size footnotesize 
16535 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
16536 int}[r7 r0]
16537 \layout Standard
16538
16539
16540 \size footnotesize 
16541 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
16542  + 0x1 {short}
16543 \layout Standard
16544
16545
16546 \size footnotesize 
16547 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
16548  r6]- 0x1 {short}
16549 \layout Standard
16550
16551
16552 \size footnotesize 
16553 Sample.c(19:38:47:1) goto _forcond_0($4)
16554 \layout Standard
16555
16556
16557 \size footnotesize 
16558 Sample.c(19:39:48:0)_forbreak_0($7) :
16559 \layout Standard
16560
16561
16562 \size footnotesize 
16563 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
16564  + ITemp11 [lr19:40]{short}[r3]
16565 \layout Standard
16566
16567
16568 \size footnotesize 
16569 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
16570 \layout Standard
16571
16572
16573 \size footnotesize 
16574 Sample.c(20:42:51:0)_return($8) :
16575 \layout Standard
16576
16577
16578 \size footnotesize 
16579 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
16580 \size default 
16581
16582 \newline 
16583
16584 \newline 
16585 Finally the code generated for this function:
16586 \newline 
16587
16588 \layout Standard
16589
16590
16591 \size footnotesize 
16592 .area DSEG (DATA)
16593 \layout Standard
16594
16595
16596 \size footnotesize 
16597 _p::
16598 \layout Standard
16599
16600
16601 \size footnotesize 
16602 \SpecialChar ~
16603 \SpecialChar ~
16604 .ds 2
16605 \layout Standard
16606
16607
16608 \size footnotesize 
16609 _gint::
16610 \layout Standard
16611
16612
16613 \size footnotesize 
16614 \SpecialChar ~
16615 \SpecialChar ~
16616 .ds 2
16617 \layout Standard
16618
16619
16620 \size footnotesize 
16621 ; sample.c 5
16622 \layout Standard
16623
16624
16625 \size footnotesize 
16626 ; ----------------------------------------------
16627 \layout Standard
16628
16629
16630 \size footnotesize 
16631 ; function function
16632 \layout Standard
16633
16634
16635 \size footnotesize 
16636 ; ----------------------------------------------
16637 \layout Standard
16638
16639
16640 \size footnotesize 
16641 _function:
16642 \layout Standard
16643
16644
16645 \size footnotesize 
16646 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
16647 \layout Standard
16648
16649
16650 \size footnotesize 
16651 \SpecialChar ~
16652 \SpecialChar ~
16653 mov r2,dpl
16654 \layout Standard
16655
16656
16657 \size footnotesize 
16658 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
16659 \layout Standard
16660
16661
16662 \size footnotesize 
16663 \SpecialChar ~
16664 \SpecialChar ~
16665 mov ar0,r2
16666 \layout Standard
16667
16668
16669 \size footnotesize 
16670 ;_whilecontinue_0($1) :
16671 \layout Standard
16672
16673
16674 \size footnotesize 
16675 00101$:
16676 \layout Standard
16677
16678
16679 \size footnotesize 
16680 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
16681 \layout Standard
16682
16683
16684 \size footnotesize 
16685 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
16686 \layout Standard
16687
16688
16689 \size footnotesize 
16690 \SpecialChar ~
16691 \SpecialChar ~
16692 mov ar2,@r0
16693 \layout Standard
16694
16695
16696 \size footnotesize 
16697 \SpecialChar ~
16698 \SpecialChar ~
16699 inc r0
16700 \layout Standard
16701
16702
16703 \size footnotesize 
16704 \SpecialChar ~
16705 \SpecialChar ~
16706 mov ar3,@r0
16707 \layout Standard
16708
16709
16710 \size footnotesize 
16711 \SpecialChar ~
16712 \SpecialChar ~
16713 dec r0
16714 \layout Standard
16715
16716
16717 \size footnotesize 
16718 \SpecialChar ~
16719 \SpecialChar ~
16720 mov a,r2
16721 \layout Standard
16722
16723
16724 \size footnotesize 
16725 \SpecialChar ~
16726 \SpecialChar ~
16727 orl a,r3
16728 \layout Standard
16729
16730
16731 \size footnotesize 
16732 \SpecialChar ~
16733 \SpecialChar ~
16734 jz 00103$
16735 \layout Standard
16736
16737
16738 \size footnotesize 
16739 00114$:
16740 \layout Standard
16741
16742
16743 \size footnotesize 
16744 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
16745 \layout Standard
16746
16747
16748 \size footnotesize 
16749 \SpecialChar ~
16750 \SpecialChar ~
16751 mov dpl,_p
16752 \layout Standard
16753
16754
16755 \size footnotesize 
16756 \SpecialChar ~
16757 \SpecialChar ~
16758 mov dph,(_p + 1)
16759 \layout Standard
16760
16761
16762 \size footnotesize 
16763 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
16764 \layout Standard
16765
16766
16767 \size footnotesize 
16768 \SpecialChar ~
16769 \SpecialChar ~
16770 mov a,#0x02
16771 \layout Standard
16772
16773
16774 \size footnotesize 
16775 \SpecialChar ~
16776 \SpecialChar ~
16777 add a,_p
16778 \layout Standard
16779
16780
16781 \size footnotesize 
16782 \SpecialChar ~
16783 \SpecialChar ~
16784 mov _p,a
16785 \layout Standard
16786
16787
16788 \size footnotesize 
16789 \SpecialChar ~
16790 \SpecialChar ~
16791 clr a
16792 \layout Standard
16793
16794
16795 \size footnotesize 
16796 \SpecialChar ~
16797 \SpecialChar ~
16798 addc a,(_p + 1)
16799 \layout Standard
16800
16801
16802 \size footnotesize 
16803 \SpecialChar ~
16804 \SpecialChar ~
16805 mov (_p + 1),a
16806 \layout Standard
16807
16808
16809 \size footnotesize 
16810 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
16811 \layout Standard
16812
16813
16814 \size footnotesize 
16815 \SpecialChar ~
16816 \SpecialChar ~
16817 movx a,@dptr
16818 \layout Standard
16819
16820
16821 \size footnotesize 
16822 \SpecialChar ~
16823 \SpecialChar ~
16824 mov r2,a
16825 \layout Standard
16826
16827
16828 \size footnotesize 
16829 \SpecialChar ~
16830 \SpecialChar ~
16831 inc dptr
16832 \layout Standard
16833
16834
16835 \size footnotesize 
16836 \SpecialChar ~
16837 \SpecialChar ~
16838 movx a,@dptr
16839 \layout Standard
16840
16841
16842 \size footnotesize 
16843 \SpecialChar ~
16844 \SpecialChar ~
16845 mov r3,a
16846 \layout Standard
16847
16848
16849 \size footnotesize 
16850 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
16851 \layout Standard
16852
16853
16854 \size footnotesize 
16855 \SpecialChar ~
16856 \SpecialChar ~
16857 mov @r0,ar2
16858 \layout Standard
16859
16860
16861 \size footnotesize 
16862 \SpecialChar ~
16863 \SpecialChar ~
16864 inc r0
16865 \layout Standard
16866
16867
16868 \size footnotesize 
16869 \SpecialChar ~
16870 \SpecialChar ~
16871 mov @r0,ar3
16872 \layout Standard
16873
16874
16875 \size footnotesize 
16876 ; iTemp6 [lr5:16]{_near * int}[r0] = 
16877 \layout Standard
16878
16879
16880 \size footnotesize 
16881 ; iTemp6 [lr5:16]{_near * int}[r0] + 
16882 \layout Standard
16883
16884
16885 \size footnotesize 
16886 ; 0x2 {short}
16887 \layout Standard
16888
16889
16890 \size footnotesize 
16891 \SpecialChar ~
16892 \SpecialChar ~
16893 inc r0
16894 \layout Standard
16895
16896
16897 \size footnotesize 
16898 ; goto _whilecontinue_0($1)
16899 \layout Standard
16900
16901
16902 \size footnotesize 
16903 \SpecialChar ~
16904 \SpecialChar ~
16905 sjmp 00101$
16906 \layout Standard
16907
16908
16909 \size footnotesize 
16910 ; _whilebreak_0($3) :
16911 \layout Standard
16912
16913
16914 \size footnotesize 
16915 00103$:
16916 \layout Standard
16917
16918
16919 \size footnotesize 
16920 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
16921 \layout Standard
16922
16923
16924 \size footnotesize 
16925 \SpecialChar ~
16926 \SpecialChar ~
16927 mov r2,#0x00
16928 \layout Standard
16929
16930
16931 \size footnotesize 
16932 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
16933 \layout Standard
16934
16935
16936 \size footnotesize 
16937 \SpecialChar ~
16938 \SpecialChar ~
16939 mov r3,#0x00
16940 \layout Standard
16941
16942
16943 \size footnotesize 
16944 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
16945 \layout Standard
16946
16947
16948 \size footnotesize 
16949 \SpecialChar ~
16950 \SpecialChar ~
16951 mov r4,#0x00
16952 \layout Standard
16953
16954
16955 \size footnotesize 
16956 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
16957 \layout Standard
16958
16959
16960 \size footnotesize 
16961 \SpecialChar ~
16962 \SpecialChar ~
16963 mov r5,#0x0A
16964 \layout Standard
16965
16966
16967 \size footnotesize 
16968 \SpecialChar ~
16969 \SpecialChar ~
16970 mov r6,#0x00
16971 \layout Standard
16972
16973
16974 \size footnotesize 
16975 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
16976 \layout Standard
16977
16978
16979 \size footnotesize 
16980 \SpecialChar ~
16981 \SpecialChar ~
16982 mov r7,#0x1E
16983 \layout Standard
16984
16985
16986 \size footnotesize 
16987 \SpecialChar ~
16988 \SpecialChar ~
16989 mov r0,#0x00
16990 \layout Standard
16991
16992
16993 \size footnotesize 
16994 ; _forcond_0($4) :
16995 \layout Standard
16996
16997
16998 \size footnotesize 
16999 00104$:
17000 \layout Standard
17001
17002
17003 \size footnotesize 
17004 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
17005 \layout Standard
17006
17007
17008 \size footnotesize 
17009 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
17010 \layout Standard
17011
17012
17013 \size footnotesize 
17014 \SpecialChar ~
17015 \SpecialChar ~
17016 clr c
17017 \layout Standard
17018
17019
17020 \size footnotesize 
17021 \SpecialChar ~
17022 \SpecialChar ~
17023 mov a,r4
17024 \layout Standard
17025
17026
17027 \size footnotesize 
17028 \SpecialChar ~
17029 \SpecialChar ~
17030 xrl a,#0x80
17031 \layout Standard
17032
17033
17034 \size footnotesize 
17035 \SpecialChar ~
17036 \SpecialChar ~
17037 subb a,#0x8a
17038 \layout Standard
17039
17040
17041 \size footnotesize 
17042 \SpecialChar ~
17043 \SpecialChar ~
17044 jnc 00107$
17045 \layout Standard
17046
17047
17048 \size footnotesize 
17049 00115$:
17050 \layout Standard
17051
17052
17053 \size footnotesize 
17054 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
17055 \layout Standard
17056
17057
17058 \size footnotesize 
17059 ; iTemp21 [lr21:38]{short}[r4]
17060 \layout Standard
17061
17062
17063 \size footnotesize 
17064 \SpecialChar ~
17065 \SpecialChar ~
17066 mov a,r4
17067 \layout Standard
17068
17069
17070 \size footnotesize 
17071 \SpecialChar ~
17072 \SpecialChar ~
17073 add a,r2
17074 \layout Standard
17075
17076
17077 \size footnotesize 
17078 \SpecialChar ~
17079 \SpecialChar ~
17080 mov r2,a
17081 \layout Standard
17082
17083
17084 \size footnotesize 
17085 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
17086 \layout Standard
17087
17088
17089 \size footnotesize 
17090 \SpecialChar ~
17091 \SpecialChar ~
17092 mov b,#0x03
17093 \layout Standard
17094
17095
17096 \size footnotesize 
17097 \SpecialChar ~
17098 \SpecialChar ~
17099 mov a,r4
17100 \layout Standard
17101
17102
17103 \size footnotesize 
17104 \SpecialChar ~
17105 \SpecialChar ~
17106 mul ab
17107 \layout Standard
17108
17109
17110 \size footnotesize 
17111 \SpecialChar ~
17112 \SpecialChar ~
17113 mov r1,a
17114 \layout Standard
17115
17116
17117 \size footnotesize 
17118 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
17119 \layout Standard
17120
17121
17122 \size footnotesize 
17123 ; iTemp15 [lr29:30]{short}[r1]
17124 \layout Standard
17125
17126
17127 \size footnotesize 
17128 \SpecialChar ~
17129 \SpecialChar ~
17130 add a,r3
17131 \layout Standard
17132
17133
17134 \size footnotesize 
17135 \SpecialChar ~
17136 \SpecialChar ~
17137 mov r3,a
17138 \layout Standard
17139
17140
17141 \size footnotesize 
17142 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
17143 \layout Standard
17144
17145
17146 \size footnotesize 
17147 \SpecialChar ~
17148 \SpecialChar ~
17149 mov a,r7
17150 \layout Standard
17151
17152
17153 \size footnotesize 
17154 \SpecialChar ~
17155 \SpecialChar ~
17156 add a,#0xfd
17157 \layout Standard
17158
17159
17160 \size footnotesize 
17161 \SpecialChar ~
17162 \SpecialChar ~
17163 mov r7,a
17164 \layout Standard
17165
17166
17167 \size footnotesize 
17168 \SpecialChar ~
17169 \SpecialChar ~
17170 mov a,r0
17171 \layout Standard
17172
17173
17174 \size footnotesize 
17175 \SpecialChar ~
17176 \SpecialChar ~
17177 addc a,#0xff
17178 \layout Standard
17179
17180
17181 \size footnotesize 
17182 \SpecialChar ~
17183 \SpecialChar ~
17184 mov r0,a
17185 \layout Standard
17186
17187
17188 \size footnotesize 
17189 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
17190 \layout Standard
17191
17192
17193 \size footnotesize 
17194 \SpecialChar ~
17195 \SpecialChar ~
17196 mov a,r7
17197 \layout Standard
17198
17199
17200 \size footnotesize 
17201 \SpecialChar ~
17202 \SpecialChar ~
17203 add a,_gint
17204 \layout Standard
17205
17206
17207 \size footnotesize 
17208 \SpecialChar ~
17209 \SpecialChar ~
17210 mov _gint,a
17211 \layout Standard
17212
17213
17214 \size footnotesize 
17215 \SpecialChar ~
17216 \SpecialChar ~
17217 mov a,r0
17218 \layout Standard
17219
17220
17221 \size footnotesize 
17222 \SpecialChar ~
17223 \SpecialChar ~
17224 addc a,(_gint + 1)
17225 \layout Standard
17226
17227
17228 \size footnotesize 
17229 \SpecialChar ~
17230 \SpecialChar ~
17231 mov (_gint + 1),a
17232 \layout Standard
17233
17234
17235 \size footnotesize 
17236 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
17237 \layout Standard
17238
17239
17240 \size footnotesize 
17241 \SpecialChar ~
17242 \SpecialChar ~
17243 inc r4
17244 \layout Standard
17245
17246
17247 \size footnotesize 
17248 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
17249 \layout Standard
17250
17251
17252 \size footnotesize 
17253 \SpecialChar ~
17254 \SpecialChar ~
17255 dec r5
17256 \layout Standard
17257
17258
17259 \size footnotesize 
17260 \SpecialChar ~
17261 \SpecialChar ~
17262 cjne r5,#0xff,00104$
17263 \layout Standard
17264
17265
17266 \size footnotesize 
17267 \SpecialChar ~
17268 \SpecialChar ~
17269 dec r6
17270 \layout Standard
17271
17272
17273 \size footnotesize 
17274 ; goto _forcond_0($4)
17275 \layout Standard
17276
17277
17278 \size footnotesize 
17279 \SpecialChar ~
17280 \SpecialChar ~
17281 sjmp 00104$
17282 \layout Standard
17283
17284
17285 \size footnotesize 
17286 ; _forbreak_0($7) :
17287 \layout Standard
17288
17289
17290 \size footnotesize 
17291 00107$:
17292 \layout Standard
17293
17294
17295 \size footnotesize 
17296 ; ret iTemp24 [lr40:41]{short}
17297 \layout Standard
17298
17299
17300 \size footnotesize 
17301 \SpecialChar ~
17302 \SpecialChar ~
17303 mov a,r3
17304 \layout Standard
17305
17306
17307 \size footnotesize 
17308 \SpecialChar ~
17309 \SpecialChar ~
17310 add a,r2
17311 \layout Standard
17312
17313
17314 \size footnotesize 
17315 \SpecialChar ~
17316 \SpecialChar ~
17317 mov dpl,a
17318 \layout Standard
17319
17320
17321 \size footnotesize 
17322 ; _return($8) :
17323 \layout Standard
17324
17325
17326 \size footnotesize 
17327 00108$:
17328 \layout Standard
17329
17330
17331 \size footnotesize 
17332 \SpecialChar ~
17333 \SpecialChar ~
17334 ret
17335 \newline 
17336
17337 \layout Subsection
17338
17339 A few words about basic block successors, predecessors and dominators
17340 \layout Standard
17341
17342 Successors are basic blocks
17343 \begin_inset LatexCommand \index{Basic blocks}
17344
17345 \end_inset 
17346
17347  that might execute after this basic block.
17348 \newline 
17349 Predecessors are basic blocks that might execute before reaching this basic
17350  block.
17351 \newline 
17352 Dominators are basic blocks that WILL execute before reaching this basic
17353  block.
17354 \newline 
17355
17356 \layout Standard
17357
17358 [basic block 1]
17359 \layout Standard
17360
17361 if (something)
17362 \layout Standard
17363
17364 \SpecialChar ~
17365 \SpecialChar ~
17366 \SpecialChar ~
17367 \SpecialChar ~
17368 [basic block 2]
17369 \layout Standard
17370
17371 else
17372 \layout Standard
17373
17374 \SpecialChar ~
17375 \SpecialChar ~
17376 \SpecialChar ~
17377 \SpecialChar ~
17378 [basic block 3]
17379 \layout Standard
17380
17381 [basic block 4]
17382 \newline 
17383
17384 \layout Standard
17385
17386 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
17387 \layout Standard
17388
17389 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
17390 \layout Standard
17391
17392 c) domVect of [BB4] = BB1 ...
17393  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
17394  was executed.
17395 \layout Section
17396
17397 Acknowledgments
17398 \layout Standard
17399
17400
17401 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
17402
17403 \end_inset 
17404
17405
17406 \newline 
17407
17408 \newline 
17409
17410 \emph on 
17411 Thanks to all the other volunteer developers who have helped with coding,
17412  testing, web-page creation, distribution sets, etc.
17413  You know who you are :-)
17414 \emph default 
17415
17416 \newline 
17417
17418 \layout Standard
17419
17420 This document was initially written by Sandeep Dutta
17421 \layout Standard
17422
17423 All product names mentioned herein may be trademarks
17424 \begin_inset LatexCommand \index{Trademarks}
17425
17426 \end_inset 
17427
17428  of their respective companies.
17429  
17430 \layout Section
17431
17432 Alphabetical index
17433 \layout Standard
17434
17435 To avoid confusion, the installation and building options for sdcc itself
17436  (chapter 2) are not part of the index.
17437 \layout Standard
17438
17439
17440 \begin_inset LatexCommand \printindex{}
17441
17442 \end_inset 
17443
17444
17445 \the_end