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