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