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