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