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