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