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