doc/sdccman.lyx: added section 3.14 about sdcclib
[fw/sdcc] / doc / sdccman.lyx
1 #LyX 1.3 created this file. For more info see http://www.lyx.org/
2 \lyxformat 221
3 \textclass book
4 \begin_preamble
5 \usepackage[
6   pdftitle={SDCC Compiler User Guide},
7   pdfauthor={SDCC development team},
8   pdfsubject={installation, user manual},
9   pdfkeywords={8032, 8051, ansi, c, compiler, CPU, DS390, 
10                embedded, GPL, HC08, manual, mcs51, PIC, Z80},
11   colorlinks=true,
12   linkcolor=blue] {hyperref}
13 %
14 \sloppy
15 \tolerance=500          
16 \emergencystretch=30pt 
17 %
18 \date{}
19 \end_preamble
20 \language english
21 \inputencoding default
22 \fontscheme pslatex
23 \graphics default
24 \paperfontsize default
25 \spacing single 
26 \papersize letterpaper
27 \paperpackage a4
28 \use_geometry 1
29 \use_amsmath 0
30 \use_natbib 0
31 \use_numerical_citations 0
32 \paperorientation portrait
33 \leftmargin 30mm
34 \topmargin 20mm
35 \rightmargin 25mm
36 \bottommargin 20mm
37 \secnumdepth 3
38 \tocdepth 3
39 \paragraph_separation indent
40 \defskip medskip
41 \quotes_language swedish
42 \quotes_times 2
43 \papercolumns 1
44 \papersides 1
45 \paperpagestyle fancy
46
47 \layout Comment
48
49 Please note: double dashed longoptions (e.g.
50  --version) are written this way: -
51 \begin_inset ERT
52 status Collapsed
53
54 \layout Standard
55
56 \backslash 
57 /
58 \end_inset 
59
60 -
61 \layout Comment
62
63 Two resp.
64  three consecutive dashes simply result in a long resp.
65  extra long dash.
66 \layout Comment
67
68 Architecture specific stuff (like memory models, code examples) should maybe
69  later go
70 \layout Comment
71
72 into seperate sections/chapters/appendices (it is hard to document PIC or
73  Z80 in 
74 \layout Comment
75
76 a 8051 centered document) - for now simply add.
77 \layout Title
78
79 SDCC Compiler User Guide
80 \layout Date
81
82
83 \size normal 
84 SDCC 2.3.8
85 \size footnotesize 
86
87 \newline 
88 $Date$ 
89 \newline 
90 $Revision$
91 \layout Comment
92
93 The above strings enclosed in $ are automatically updated by cvs
94 \layout Standard
95
96
97 \begin_inset LatexCommand \tableofcontents{}
98
99 \end_inset 
100
101
102 \layout Chapter
103
104 Introduction
105 \layout Section
106
107 About SDCC
108 \layout Standard
109
110
111 \series bold 
112 SDCC
113 \series default 
114  (
115 \emph on 
116 S
117 \emph default 
118 mall 
119 \emph on 
120 D
121 \emph default 
122 evice 
123 \emph on 
124 C
125 \emph default 
126  
127 \emph on 
128 C
129 \emph default 
130 ompiler) is a Freeware, retargettable, optimizing ANSI-C compiler by 
131 \series bold 
132 Sandeep Dutta
133 \series default 
134  designed for 8 bit Microprocessors.
135  The current version targets Intel MCS51 based Microprocessors (8031, 8032,
136  8051, 8052
137 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
138
139 \end_inset 
140
141 , etc.), Dallas DS80C390 variants, Motorola HC08 and Zilog Z80 based MCUs.
142  It can be retargetted for other microprocessors, support for Microchip
143  PIC, Atmel AVR is under development.
144  The entire source code for the compiler is distributed under GPL.
145  SDCC uses ASXXXX & ASLINK, a Freeware, retargettable assembler & linker.
146  SDCC has extensive language extensions suitable for utilizing various microcont
147 rollers and underlying hardware effectively.
148  
149 \newline 
150
151 \newline 
152 In addition to the MCU specific optimizations SDCC also does a host of standard
153  optimizations like:
154 \layout Itemize
155
156 global sub expression elimination, 
157 \layout Itemize
158
159 loop optimizations (loop invariant, strength reduction of induction variables
160  and loop reversing), 
161 \layout Itemize
162
163 constant folding & propagation, 
164 \layout Itemize
165
166 copy propagation, 
167 \layout Itemize
168
169 dead code elimination 
170 \layout Itemize
171
172 jump tables for 
173 \emph on 
174 switch
175 \emph default 
176  statements.
177 \layout Standard
178
179 For the back-end SDCC uses a global register allocation scheme which should
180  be well suited for other 8 bit MCUs.
181  
182 \newline 
183
184 \newline 
185 The peep hole optimizer uses a rule based substitution mechanism which is
186  MCU independent.
187  
188 \newline 
189
190 \newline 
191 Supported data-types are:
192 \layout Itemize
193
194 char (8 bits, 1 byte), 
195 \layout Itemize
196
197 short and int (16 bits, 2 bytes), 
198 \layout Itemize
199
200 long (32 bit, 4 bytes)
201 \layout Itemize
202
203 float (4 byte IEEE).
204  
205 \layout Standard
206
207 The compiler also allows 
208 \emph on 
209 inline assembler code
210 \emph default 
211  to be embedded anywhere in a function.
212  In addition, routines developed in assembly can also be called.
213 \newline 
214
215 \newline 
216 SDCC also provides an option (-
217 \begin_inset ERT
218 status Collapsed
219
220 \layout Standard
221
222 \backslash 
223 /
224 \end_inset 
225
226 -cyclomatic) to report the relative complexity of a function.
227  These functions can then be further optimized, or hand coded in assembly
228  if needed.
229  
230 \newline 
231
232 \newline 
233 SDCC also comes with a companion source level debugger SDCDB, the debugger
234  currently uses ucSim a freeware simulator for 8051 and other micro-controllers.
235  
236 \newline 
237
238 \newline 
239 The latest version can be downloaded from 
240 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
241
242 \end_inset 
243
244 .
245
246 \series bold 
247  
248 \series default 
249 \emph on 
250 Please note: the compiler will probably always be some steps ahead of this
251  documentation
252 \series bold 
253 \emph default 
254
255 \begin_inset LatexCommand \index{Status of documentation}
256
257 \end_inset 
258
259
260 \begin_inset Foot
261 collapsed false
262
263 \layout Standard
264
265 Obviously this has pros and cons
266 \end_inset 
267
268 .
269 \layout Section
270
271 Open Source
272 \layout Standard
273
274 All packages used in this compiler system are 
275 \emph on 
276 opensource
277 \emph default 
278  and 
279 \emph on 
280 freeware
281 \emph default 
282 ; source code for all the sub-packages (pre-processor, assemblers, linkers
283  etc) is distributed with the package.
284  This documentation is maintained using a freeware word processor (LyX).
285 \newline 
286 This program is free software; you can redistribute it and/or modify it
287  under the terms of the GNU General Public License
288 \begin_inset LatexCommand \index{GNU General Public License, GPL}
289
290 \end_inset 
291
292  as published by the Free Software Foundation; either version 2, or (at
293  your option) any later version.
294  This program is distributed in the hope that it will be useful, but WITHOUT
295  ANY WARRANTY; without even the implied warranty
296 \begin_inset LatexCommand \index{warranty}
297
298 \end_inset 
299
300  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
301  See the GNU General Public License for more details.
302  You should have received a copy of the GNU General Public License along
303  with this program; if not, write to the Free Software Foundation, 59 Temple
304  Place - Suite 330, Boston, MA 02111-1307, USA.
305  In other words, you are welcome to use, share and improve this program.
306  You are forbidden to forbid anyone else to use, share and improve what
307  you give them.
308  Help stamp out software-hoarding! 
309 \layout Section
310
311 Typographic conventions
312 \begin_inset LatexCommand \index{Typographic conventions}
313
314 \end_inset 
315
316
317 \layout Standard
318
319 Throughout this manual, we will use the following convention.
320  Commands you have to type in are printed in 
321 \family sans 
322 \series bold 
323 "sans serif"
324 \series default 
325 .
326
327 \family default 
328  Code samples are printed in 
329 \family typewriter 
330 typewriter font.
331
332 \family default 
333  Interesting items and new terms are printed in 
334 \emph on 
335 italic.
336 \layout Section
337
338 Compatibility with previous versions
339 \layout Standard
340
341 This version has numerous bug fixes compared with the previous version.
342  But we also introduced some incompatibilities with older versions.
343  Not just for the fun of it, but to make the compiler more stable, efficient
344  and ANSI compliant
345 \begin_inset LatexCommand \index{ANSI-compliance}
346
347 \end_inset 
348
349  (see section 
350 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
351
352 \end_inset 
353
354  for ANSI-Compliance).
355  
356 \newline 
357
358 \layout Itemize
359
360 short is now equivalent to int (16 bits), it used to be equivalent to char
361  (8 bits) which is not ANSI compliant
362 \layout Itemize
363
364 the default directory for gcc-builds where include, library and documentation
365  files are stored is now in /usr/local/share
366 \layout Itemize
367
368 char type parameters to vararg functions are casted to int unless explicitly
369  casted, e.g.: 
370 \newline 
371
372 \family typewriter 
373 \SpecialChar ~
374 \SpecialChar ~
375 char a=3;
376 \newline 
377 \SpecialChar ~
378 \SpecialChar ~
379 printf ("%d %c
380 \backslash 
381 n", a, (char)a);
382 \family default 
383
384 \newline 
385  will push a as an int and as a char resp.
386 \layout Itemize
387
388 option -
389 \begin_inset ERT
390 status Collapsed
391
392 \layout Standard
393
394 \backslash 
395 /
396 \end_inset 
397
398 -regextend has been removed
399 \layout Itemize
400
401 option -
402 \begin_inset ERT
403 status Collapsed
404
405 \layout Standard
406
407 \backslash 
408 /
409 \end_inset 
410
411 -noregparms has been removed
412 \layout Itemize
413
414 option -
415 \begin_inset ERT
416 status Collapsed
417
418 \layout Standard
419
420 \backslash 
421 /
422 \end_inset 
423
424 -stack-after-data has been removed
425 \layout Standard
426
427
428 \emph on 
429 <pending: more incompatibilities?>
430 \layout Section
431
432 System Requirements
433 \layout Standard
434
435 What do you need before you start installation of SDCC? A computer, and
436  a desire to compute.
437  The preferred method of installation is to compile SDCC from source using
438  GNU gcc and make.
439  For Windows some pre-compiled binary distributions are available for your
440  convenience.
441  You should have some experience with command line tools and compiler use.
442 \layout Section
443
444 Other Resources
445 \layout Standard
446
447 The SDCC home page at 
448 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
449
450 \end_inset 
451
452  is a great place to find distribution sets.
453  You can also find links to the user mailing lists that offer help or discuss
454  SDCC with other SDCC users.
455  Web links to other SDCC related sites can also be found here.
456  This document can be found in the DOC directory of the source package as
457  a text or HTML file.
458  Some of the other tools (simulator and assembler) included with SDCC contain
459  their own documentation and can be found in the source distribution.
460  If you want the latest unreleased software, the complete source package
461  is available directly by anonymous CVS on cvs.sdcc.sourceforge.net.
462 \layout Section
463
464 Wishes for the future
465 \layout Standard
466
467 There are (and always will be) some things that could be done.
468  Here are some I can think of:
469 \newline 
470
471 \layout Standard
472
473
474 \family typewriter 
475 char KernelFunction3(char p) at 0x340;
476 \newline 
477
478 \layout Standard
479
480
481 \family typewriter 
482 code banking
483 \begin_inset LatexCommand \index{code banking (not supported)}
484
485 \end_inset 
486
487  support for mcs51
488 \newline 
489
490 \newline 
491
492 \family default 
493 If you can think of some more, please see the section 
494 \begin_inset LatexCommand \ref{sub:Requesting-Features}
495
496 \end_inset 
497
498  about filing feature requests
499 \begin_inset LatexCommand \index{Requesting features}
500
501 \end_inset 
502
503
504 \begin_inset LatexCommand \index{Feature request}
505
506 \end_inset 
507
508 .
509 \newline 
510
511 \layout Chapter
512
513 Installing SDCC
514 \begin_inset LatexCommand \index{Installation}
515
516 \end_inset 
517
518
519 \layout Standard
520
521 For most users it is sufficient to skip to either section 
522 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
523
524 \end_inset 
525
526  or section 
527 \begin_inset LatexCommand \ref{sub:Windows-Install}
528
529 \end_inset 
530
531 .
532  More detailled instructions follow below.
533 \layout Section
534
535 Configure Options
536 \begin_inset LatexCommand \index{Options SDCC configuration}
537
538 \end_inset 
539
540
541 \layout Standard
542
543 The install paths, search paths and other options are defined when running
544  'configure'.
545  The defaults can be overridden by:
546 \layout List
547 \labelwidthstring 00.00.0000
548
549 -
550 \begin_inset ERT
551 status Collapsed
552
553 \layout Standard
554
555 \backslash 
556 /
557 \end_inset 
558
559 -prefix see table below
560 \layout List
561 \labelwidthstring 00.00.0000
562
563 -
564 \begin_inset ERT
565 status Collapsed
566
567 \layout Standard
568
569 \backslash 
570 /
571 \end_inset 
572
573 -exec_prefix see table below
574 \layout List
575 \labelwidthstring 00.00.0000
576
577 -
578 \begin_inset ERT
579 status Collapsed
580
581 \layout Standard
582
583 \backslash 
584 /
585 \end_inset 
586
587 -bindir see table below
588 \layout List
589 \labelwidthstring 00.00.0000
590
591 -
592 \begin_inset ERT
593 status Collapsed
594
595 \layout Standard
596
597 \backslash 
598 /
599 \end_inset 
600
601 -datadir see table below
602 \layout List
603 \labelwidthstring 00.00.0000
604
605 docdir environment variable, see table below
606 \layout List
607 \labelwidthstring 00.00.0000
608
609 include_dir_suffix environment variable, see table below
610 \layout List
611 \labelwidthstring 00.00.0000
612
613 lib_dir_suffix environment variable, see table below
614 \layout List
615 \labelwidthstring 00.00.0000
616
617 sdccconf_h_dir_separator environment variable, either / or 
618 \backslash 
619
620 \backslash 
621  makes sense here.
622  This character will only be used in sdccconf.h; don't forget it's a C-header,
623  therefore a double-backslash is needed there.
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-mcs51-port Excludes the Intel mcs51 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-gbz80-port Excludes the Gameboy gbz80 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-z80-port Excludes the z80 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-avr-port Excludes the AVR port
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-ds390-port Excludes the DS390 port
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-hc08-port Excludes the HC08 port
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 -disable-pic-port Excludes the PIC port
722 \layout List
723 \labelwidthstring 00.00.0000
724
725 -
726 \begin_inset ERT
727 status Collapsed
728
729 \layout Standard
730
731 \backslash 
732 /
733 \end_inset 
734
735 -disable-xa51-port Excludes the XA51 port
736 \layout List
737 \labelwidthstring 00.00.0000
738
739 -
740 \begin_inset ERT
741 status Collapsed
742
743 \layout Standard
744
745 \backslash 
746 /
747 \end_inset 
748
749 -disable-ucsim Disables configuring and building of ucsim
750 \layout List
751 \labelwidthstring 00.00.0000
752
753 -
754 \begin_inset ERT
755 status Collapsed
756
757 \layout Standard
758
759 \backslash 
760 /
761 \end_inset 
762
763 -disable-device-lib-build Disables automatically building device libraries
764 \layout List
765 \labelwidthstring 00.00.0000
766
767 -
768 \begin_inset ERT
769 status Collapsed
770
771 \layout Standard
772
773 \backslash 
774 /
775 \end_inset 
776
777 -disable-packihx Disables building packihx
778 \layout List
779 \labelwidthstring 00.00.0000
780
781 -
782 \begin_inset ERT
783 status Collapsed
784
785 \layout Standard
786
787 \backslash 
788 /
789 \end_inset 
790
791 -enable-libgc Use the Bohem memory allocator.
792  Lower runtime footprint.
793 \layout Standard
794
795 Furthermore the environment variables CC, CFLAGS, ...
796  the tools and their arguments can be influenced.
797  Please see `configure -
798 \begin_inset ERT
799 status Collapsed
800
801 \layout Standard
802
803 \backslash 
804 /
805 \end_inset 
806
807 -help` and the man/info pages of `configure` for details.
808 \newline 
809
810 \newline 
811 The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB,
812  STD_FP_LIB, STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_
813 NAME, SDCC_INCLUDE_NAME, SDCC_LIB_NAME are defined by `configure` too.
814  At the moment it's not possible to change the default settings (it was
815  simply never required).
816 \newline 
817
818 \newline 
819 These configure options are compiled into the binaries, and can only be
820  changed by rerunning 'configure' and recompiling SDCC.
821  The configure options are written in 
822 \emph on 
823 italics
824 \emph default 
825  to distinguish them from run time environment variables (see section search
826  paths).
827 \newline 
828
829 \newline 
830 The settings for 
831 \begin_inset Quotes sld
832 \end_inset 
833
834 Win32 builds
835 \begin_inset Quotes srd
836 \end_inset 
837
838  are used by the SDCC team to build the official Win32 binaries.
839  The SDCC team uses Mingw32 to build the official Windows binaries, because
840  it's
841 \layout Enumerate
842
843 open source, 
844 \layout Enumerate
845
846 a gcc compiler and last but not least
847 \layout Enumerate
848
849 the binaries can be built by cross compiling on Sourceforge's compile farm.
850 \layout Standard
851
852 See the examples, how to pass the Win32 settings to 'configure'.
853  The other Win32 builds using Borland, VC or whatever don't use 'configure',
854  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
855  for Win32.
856 \newline 
857
858 \newline 
859 These defaults are:
860 \newline 
861
862 \layout Standard
863 \align center 
864
865 \begin_inset  Tabular
866 <lyxtabular version="3" rows="8" columns="3">
867 <features>
868 <column alignment="block" valignment="top" leftline="true" width="0in">
869 <column alignment="block" valignment="top" leftline="true" width="0in">
870 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
871 <row topline="true" bottomline="true">
872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
873 \begin_inset Text
874
875 \layout Standard
876
877 Variable
878 \end_inset 
879 </cell>
880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
881 \begin_inset Text
882
883 \layout Standard
884
885 default
886 \end_inset 
887 </cell>
888 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
889 \begin_inset Text
890
891 \layout Standard
892
893 Win32 builds
894 \end_inset 
895 </cell>
896 </row>
897 <row topline="true">
898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
899 \begin_inset Text
900
901 \layout Standard
902
903
904 \emph on 
905 PREFIX
906 \end_inset 
907 </cell>
908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
909 \begin_inset Text
910
911 \layout Standard
912
913 /usr/local
914 \end_inset 
915 </cell>
916 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
917 \begin_inset Text
918
919 \layout Standard
920
921
922 \backslash 
923 sdcc
924 \end_inset 
925 </cell>
926 </row>
927 <row topline="true">
928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
929 \begin_inset Text
930
931 \layout Standard
932
933
934 \emph on 
935 EXEC_PREFIX
936 \end_inset 
937 </cell>
938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
939 \begin_inset Text
940
941 \layout Standard
942
943
944 \emph on 
945 $PREFIX
946 \end_inset 
947 </cell>
948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
949 \begin_inset Text
950
951 \layout Standard
952
953
954 \emph on 
955 $PREFIX
956 \end_inset 
957 </cell>
958 </row>
959 <row topline="true">
960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
961 \begin_inset Text
962
963 \layout Standard
964
965
966 \emph on 
967 BINDIR
968 \end_inset 
969 </cell>
970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
971 \begin_inset Text
972
973 \layout Standard
974
975
976 \emph on 
977 $EXECPREFIX
978 \emph default 
979 /bin
980 \end_inset 
981 </cell>
982 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
983 \begin_inset Text
984
985 \layout Standard
986
987
988 \emph on 
989 $EXECPREFIX
990 \emph default 
991
992 \backslash 
993 bin
994 \end_inset 
995 </cell>
996 </row>
997 <row topline="true">
998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
999 \begin_inset Text
1000
1001 \layout Standard
1002
1003
1004 \emph on 
1005 DATADIR
1006 \end_inset 
1007 </cell>
1008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1009 \begin_inset Text
1010
1011 \layout Standard
1012
1013
1014 \emph on 
1015 $PREFIX
1016 \emph default 
1017 /share
1018 \end_inset 
1019 </cell>
1020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1021 \begin_inset Text
1022
1023 \layout Standard
1024
1025
1026 \emph on 
1027 $PREFIX
1028 \end_inset 
1029 </cell>
1030 </row>
1031 <row topline="true">
1032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1033 \begin_inset Text
1034
1035 \layout Standard
1036
1037
1038 \emph on 
1039 DOCDIR
1040 \end_inset 
1041 </cell>
1042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1043 \begin_inset Text
1044
1045 \layout Standard
1046
1047
1048 \emph on 
1049 $DATADIR
1050 \emph default 
1051 /sdcc/doc
1052 \end_inset 
1053 </cell>
1054 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1055 \begin_inset Text
1056
1057 \layout Standard
1058
1059
1060 \emph on 
1061 $DATADIR
1062 \emph default 
1063
1064 \backslash 
1065 doc
1066 \end_inset 
1067 </cell>
1068 </row>
1069 <row topline="true">
1070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1071 \begin_inset Text
1072
1073 \layout Standard
1074
1075
1076 \emph on 
1077 INCLUDE_DIR_SUFFIX
1078 \end_inset 
1079 </cell>
1080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1081 \begin_inset Text
1082
1083 \layout Standard
1084
1085 sdcc/include
1086 \end_inset 
1087 </cell>
1088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1089 \begin_inset Text
1090
1091 \layout Standard
1092
1093 include
1094 \end_inset 
1095 </cell>
1096 </row>
1097 <row topline="true" bottomline="true">
1098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1099 \begin_inset Text
1100
1101 \layout Standard
1102
1103
1104 \emph on 
1105 LIB_DIR_SUFFIX
1106 \end_inset 
1107 </cell>
1108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1109 \begin_inset Text
1110
1111 \layout Standard
1112
1113 sdcc/lib
1114 \end_inset 
1115 </cell>
1116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1117 \begin_inset Text
1118
1119 \layout Standard
1120
1121 lib
1122 \end_inset 
1123 </cell>
1124 </row>
1125 </lyxtabular>
1126
1127 \end_inset 
1128
1129
1130 \newline 
1131
1132 \layout Standard
1133 \noindent 
1134 'configure' also computes relative paths.
1135  This is needed for full relocatability of a binary package and to complete
1136  search paths (see section search paths below):
1137 \newline 
1138  
1139 \layout Standard
1140 \align center 
1141
1142 \begin_inset  Tabular
1143 <lyxtabular version="3" rows="4" columns="3">
1144 <features>
1145 <column alignment="block" valignment="top" leftline="true" width="0in">
1146 <column alignment="block" valignment="top" leftline="true" width="0in">
1147 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1148 <row topline="true" bottomline="true">
1149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1150 \begin_inset Text
1151
1152 \layout Standard
1153
1154 Variable (computed)
1155 \end_inset 
1156 </cell>
1157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1158 \begin_inset Text
1159
1160 \layout Standard
1161
1162 default
1163 \end_inset 
1164 </cell>
1165 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1166 \begin_inset Text
1167
1168 \layout Standard
1169
1170 Win32 builds
1171 \end_inset 
1172 </cell>
1173 </row>
1174 <row topline="true" bottomline="true">
1175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1176 \begin_inset Text
1177
1178 \layout Standard
1179
1180
1181 \emph on 
1182 BIN2DATA_DIR
1183 \end_inset 
1184 </cell>
1185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1186 \begin_inset Text
1187
1188 \layout Standard
1189
1190 ../share
1191 \end_inset 
1192 </cell>
1193 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1194 \begin_inset Text
1195
1196 \layout Standard
1197
1198 ..
1199 \end_inset 
1200 </cell>
1201 </row>
1202 <row bottomline="true">
1203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1204 \begin_inset Text
1205
1206 \layout Standard
1207
1208
1209 \emph on 
1210 PREFIX2BIN_DIR
1211 \end_inset 
1212 </cell>
1213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1214 \begin_inset Text
1215
1216 \layout Standard
1217
1218 bin
1219 \end_inset 
1220 </cell>
1221 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1222 \begin_inset Text
1223
1224 \layout Standard
1225
1226 bin
1227 \end_inset 
1228 </cell>
1229 </row>
1230 <row bottomline="true">
1231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1232 \begin_inset Text
1233
1234 \layout Standard
1235
1236
1237 \emph on 
1238 PREFIX2DATA_DIR
1239 \end_inset 
1240 </cell>
1241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1242 \begin_inset Text
1243
1244 \layout Standard
1245
1246 share/sdcc
1247 \end_inset 
1248 </cell>
1249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1250 \begin_inset Text
1251
1252 \layout Standard
1253
1254 \end_inset 
1255 </cell>
1256 </row>
1257 </lyxtabular>
1258
1259 \end_inset 
1260
1261
1262 \newline 
1263
1264 \layout Standard
1265 \noindent 
1266 Examples:
1267 \layout LyX-Code
1268
1269 ./configure
1270 \newline 
1271 ./configure -
1272 \begin_inset ERT
1273 status Collapsed
1274
1275 \layout Standard
1276
1277 \backslash 
1278 /
1279 \end_inset 
1280
1281 -prefix=
1282 \begin_inset Quotes srd
1283 \end_inset 
1284
1285 /usr/bin
1286 \begin_inset Quotes srd
1287 \end_inset 
1288
1289  -
1290 \begin_inset ERT
1291 status Collapsed
1292
1293 \layout Standard
1294
1295 \backslash 
1296 /
1297 \end_inset 
1298
1299 -datadir=
1300 \begin_inset Quotes srd
1301 \end_inset 
1302
1303 /usr/share
1304 \begin_inset Quotes srd
1305 \end_inset 
1306
1307
1308 \newline 
1309 ./configure -
1310 \begin_inset ERT
1311 status Collapsed
1312
1313 \layout Standard
1314
1315 \backslash 
1316 /
1317 \end_inset 
1318
1319 -disable-avr-port -
1320 \begin_inset ERT
1321 status Collapsed
1322
1323 \layout Standard
1324
1325 \backslash 
1326 /
1327 \end_inset 
1328
1329 -disable-xa51-port
1330 \layout Standard
1331
1332 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1333 32'):
1334 \layout LyX-Code
1335
1336 ./configure 
1337 \backslash 
1338
1339 \newline 
1340 CC=
1341 \begin_inset Quotes srd
1342 \end_inset 
1343
1344 i586-mingw32msvc-gcc
1345 \begin_inset Quotes srd
1346 \end_inset 
1347
1348  CXX=
1349 \begin_inset Quotes srd
1350 \end_inset 
1351
1352 i586-mingw32msvc-g++
1353 \begin_inset Quotes srd
1354 \end_inset 
1355
1356  
1357 \backslash 
1358  
1359 \newline 
1360 RANLIB=
1361 \begin_inset Quotes srd
1362 \end_inset 
1363
1364 i586-mingw32msvc-ranlib
1365 \begin_inset Quotes srd
1366 \end_inset 
1367
1368  
1369 \backslash 
1370
1371 \newline 
1372 STRIP=
1373 \begin_inset Quotes srd
1374 \end_inset 
1375
1376 i586-mingw32msvc-strip
1377 \begin_inset Quotes srd
1378 \end_inset 
1379
1380  
1381 \backslash 
1382
1383 \newline 
1384 -
1385 \begin_inset ERT
1386 status Collapsed
1387
1388 \layout Standard
1389
1390 \backslash 
1391 /
1392 \end_inset 
1393
1394 -prefix=
1395 \begin_inset Quotes srd
1396 \end_inset 
1397
1398 /sdcc
1399 \begin_inset Quotes srd
1400 \end_inset 
1401
1402  
1403 \backslash 
1404
1405 \newline 
1406 -
1407 \begin_inset ERT
1408 status Collapsed
1409
1410 \layout Standard
1411
1412 \backslash 
1413 /
1414 \end_inset 
1415
1416 -datadir=
1417 \begin_inset Quotes srd
1418 \end_inset 
1419
1420 /sdcc
1421 \begin_inset Quotes srd
1422 \end_inset 
1423
1424  
1425 \backslash 
1426
1427 \newline 
1428 docdir=
1429 \begin_inset Quotes srd
1430 \end_inset 
1431
1432 /sdcc/doc
1433 \begin_inset Quotes srd
1434 \end_inset 
1435
1436  
1437 \backslash 
1438
1439 \newline 
1440 include_dir_suffix=
1441 \begin_inset Quotes srd
1442 \end_inset 
1443
1444 include
1445 \begin_inset Quotes srd
1446 \end_inset 
1447
1448  
1449 \backslash 
1450
1451 \newline 
1452 lib_dir_suffix=
1453 \begin_inset Quotes srd
1454 \end_inset 
1455
1456 lib
1457 \begin_inset Quotes srd
1458 \end_inset 
1459
1460  
1461 \backslash 
1462
1463 \newline 
1464 sdccconf_h_dir_separator=
1465 \begin_inset Quotes srd
1466 \end_inset 
1467
1468
1469 \backslash 
1470
1471 \backslash 
1472
1473 \backslash 
1474
1475 \backslash 
1476
1477 \begin_inset Quotes srd
1478 \end_inset 
1479
1480  
1481 \backslash 
1482
1483 \newline 
1484 -
1485 \begin_inset ERT
1486 status Collapsed
1487
1488 \layout Standard
1489
1490 \backslash 
1491 /
1492 \end_inset 
1493
1494 -disable-device-lib-build
1495 \backslash 
1496
1497 \newline 
1498 -
1499 \begin_inset ERT
1500 status Collapsed
1501
1502 \layout Standard
1503
1504 \backslash 
1505 /
1506 \end_inset 
1507
1508 -disable-ucsim
1509 \backslash 
1510
1511 \newline 
1512 -
1513 \begin_inset ERT
1514 status Collapsed
1515
1516 \layout Standard
1517
1518 \backslash 
1519 /
1520 \end_inset 
1521
1522 -host=i586-mingw32msvc -
1523 \begin_inset ERT
1524 status Collapsed
1525
1526 \layout Standard
1527
1528 \backslash 
1529 /
1530 \end_inset 
1531
1532 -build=unknown-unknown-linux-gnu
1533 \layout Standard
1534
1535 To 
1536 \begin_inset Quotes sld
1537 \end_inset 
1538
1539 cross
1540 \begin_inset Quotes srd
1541 \end_inset 
1542
1543 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
1544 ):
1545 \layout LyX-Code
1546
1547 ./configure -C 
1548 \backslash 
1549
1550 \newline 
1551 CFLAGS=
1552 \begin_inset Quotes srd
1553 \end_inset 
1554
1555 -mno-cygwin -O2
1556 \begin_inset Quotes srd
1557 \end_inset 
1558
1559  
1560 \backslash 
1561
1562 \newline 
1563 LDFLAGS=
1564 \begin_inset Quotes srd
1565 \end_inset 
1566
1567 -mno-cygwin
1568 \begin_inset Quotes srd
1569 \end_inset 
1570
1571  
1572 \backslash 
1573
1574 \newline 
1575 -
1576 \begin_inset ERT
1577 status Collapsed
1578
1579 \layout Standard
1580
1581 \backslash 
1582 /
1583 \end_inset 
1584
1585 -prefix=
1586 \begin_inset Quotes srd
1587 \end_inset 
1588
1589 /sdcc
1590 \begin_inset Quotes srd
1591 \end_inset 
1592
1593  
1594 \backslash 
1595
1596 \newline 
1597 -
1598 \begin_inset ERT
1599 status Collapsed
1600
1601 \layout Standard
1602
1603 \backslash 
1604 /
1605 \end_inset 
1606
1607 -datadir=
1608 \begin_inset Quotes srd
1609 \end_inset 
1610
1611 /sdcc
1612 \begin_inset Quotes srd
1613 \end_inset 
1614
1615  
1616 \backslash 
1617
1618 \newline 
1619 docdir=
1620 \begin_inset Quotes srd
1621 \end_inset 
1622
1623 /sdcc/doc
1624 \begin_inset Quotes srd
1625 \end_inset 
1626
1627  
1628 \backslash 
1629  
1630 \newline 
1631 include_dir_suffix=
1632 \begin_inset Quotes srd
1633 \end_inset 
1634
1635 include
1636 \begin_inset Quotes srd
1637 \end_inset 
1638
1639  
1640 \backslash 
1641
1642 \newline 
1643 lib_dir_suffix=
1644 \begin_inset Quotes srd
1645 \end_inset 
1646
1647 lib
1648 \begin_inset Quotes srd
1649 \end_inset 
1650
1651  
1652 \backslash 
1653
1654 \newline 
1655 sdccconf_h_dir_separator=
1656 \begin_inset Quotes srd
1657 \end_inset 
1658
1659
1660 \backslash 
1661
1662 \backslash 
1663
1664 \backslash 
1665
1666 \backslash 
1667
1668 \begin_inset Quotes srd
1669 \end_inset 
1670
1671  
1672 \backslash 
1673
1674 \newline 
1675 -
1676 \begin_inset ERT
1677 status Collapsed
1678
1679 \layout Standard
1680
1681 \backslash 
1682 /
1683 \end_inset 
1684
1685 -disable-ucsim
1686 \layout Standard
1687
1688 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
1689  The option '-
1690 \begin_inset ERT
1691 status Collapsed
1692
1693 \layout Standard
1694
1695 \backslash 
1696 /
1697 \end_inset 
1698
1699 -C' turns on caching, which gives a little bit extra speed.
1700  However if options are changed, it can be necessary to delete the config.cache
1701  file.
1702 \layout Section
1703
1704 Install paths
1705 \begin_inset LatexCommand \label{sub:Install-paths}
1706
1707 \end_inset 
1708
1709
1710 \begin_inset LatexCommand \index{Install paths}
1711
1712 \end_inset 
1713
1714
1715 \layout Standard
1716 \added_space_top medskip \align center 
1717
1718 \begin_inset  Tabular
1719 <lyxtabular version="3" rows="5" columns="4">
1720 <features>
1721 <column alignment="center" valignment="top" leftline="true" width="0(null)">
1722 <column alignment="center" valignment="top" leftline="true" width="0(null)">
1723 <column alignment="center" valignment="top" leftline="true" width="0(null)">
1724 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
1725 <row topline="true" bottomline="true">
1726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1727 \begin_inset Text
1728
1729 \layout Standard
1730
1731
1732 \series bold 
1733 Description
1734 \end_inset 
1735 </cell>
1736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1737 \begin_inset Text
1738
1739 \layout Standard
1740
1741
1742 \series bold 
1743 Path
1744 \end_inset 
1745 </cell>
1746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1747 \begin_inset Text
1748
1749 \layout Standard
1750
1751
1752 \series bold 
1753 Default
1754 \end_inset 
1755 </cell>
1756 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1757 \begin_inset Text
1758
1759 \layout Standard
1760
1761
1762 \series bold 
1763 Win32 builds
1764 \end_inset 
1765 </cell>
1766 </row>
1767 <row topline="true">
1768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1769 \begin_inset Text
1770
1771 \layout Standard
1772
1773 Binary files*
1774 \end_inset 
1775 </cell>
1776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1777 \begin_inset Text
1778
1779 \layout Standard
1780
1781
1782 \emph on 
1783 $EXEC_PREFIX
1784 \end_inset 
1785 </cell>
1786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1787 \begin_inset Text
1788
1789 \layout Standard
1790
1791 /usr/local/bin
1792 \end_inset 
1793 </cell>
1794 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1795 \begin_inset Text
1796
1797 \layout Standard
1798
1799
1800 \backslash 
1801 sdcc
1802 \backslash 
1803 bin
1804 \end_inset 
1805 </cell>
1806 </row>
1807 <row topline="true">
1808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1809 \begin_inset Text
1810
1811 \layout Standard
1812
1813 Include files
1814 \end_inset 
1815 </cell>
1816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1817 \begin_inset Text
1818
1819 \layout Standard
1820
1821
1822 \emph on 
1823 $DATADIR/ $INCLUDE_DIR_SUFFIX
1824 \end_inset 
1825 </cell>
1826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1827 \begin_inset Text
1828
1829 \layout Standard
1830
1831 /usr/local/share/sdcc/include
1832 \end_inset 
1833 </cell>
1834 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1835 \begin_inset Text
1836
1837 \layout Standard
1838
1839
1840 \backslash 
1841 sdcc
1842 \backslash 
1843 include
1844 \end_inset 
1845 </cell>
1846 </row>
1847 <row topline="true">
1848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1849 \begin_inset Text
1850
1851 \layout Standard
1852
1853 Library file**
1854 \end_inset 
1855 </cell>
1856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1857 \begin_inset Text
1858
1859 \layout Standard
1860
1861
1862 \emph on 
1863 $DATADIR/$LIB_DIR_SUFFIX
1864 \end_inset 
1865 </cell>
1866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1867 \begin_inset Text
1868
1869 \layout Standard
1870
1871 /usr/local/share/sdcc/lib
1872 \end_inset 
1873 </cell>
1874 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1875 \begin_inset Text
1876
1877 \layout Standard
1878
1879
1880 \backslash 
1881 sdcc
1882 \backslash 
1883 lib
1884 \end_inset 
1885 </cell>
1886 </row>
1887 <row topline="true" bottomline="true">
1888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1889 \begin_inset Text
1890
1891 \layout Standard
1892
1893 Documentation
1894 \end_inset 
1895 </cell>
1896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1897 \begin_inset Text
1898
1899 \layout Standard
1900
1901
1902 \emph on 
1903 $DOCDIR
1904 \end_inset 
1905 </cell>
1906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1907 \begin_inset Text
1908
1909 \layout Standard
1910
1911 /usr/local/share/sdcc/doc
1912 \end_inset 
1913 </cell>
1914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1915 \begin_inset Text
1916
1917 \layout Standard
1918
1919
1920 \backslash 
1921 sdcc
1922 \backslash 
1923 doc
1924 \end_inset 
1925 </cell>
1926 </row>
1927 </lyxtabular>
1928
1929 \end_inset 
1930
1931
1932 \layout Verse
1933
1934
1935 \size footnotesize 
1936 *compiler, preprocessor, assembler, and linker
1937 \newline 
1938 **the 
1939 \shape italic 
1940 model
1941 \shape default 
1942  is auto-appended by the compiler, e.g.
1943  small, large, z80, ds390 etc
1944 \layout Standard
1945 \noindent 
1946 The install paths can still be changed during `make install` with e.g.:
1947 \layout LyX-Code
1948
1949 make install prefix=$(HOME)/local/sdcc
1950 \layout Standard
1951
1952 Of course this doesn't change the search paths compiled into the binaries.
1953 \layout Section
1954
1955 Search Paths
1956 \begin_inset LatexCommand \label{sub:Search-Paths}
1957
1958 \end_inset 
1959
1960
1961 \begin_inset LatexCommand \index{Search path}
1962
1963 \end_inset 
1964
1965
1966 \layout Standard
1967
1968 Some search paths or parts of them are determined by configure variables
1969  (in 
1970 \emph on 
1971 italics
1972 \emph default 
1973 , see section above).
1974  Further search paths are determined by environment variables during runtime.
1975  
1976 \newline 
1977 The paths searched when running the compiler are as follows (the first catch
1978  wins):
1979 \newline 
1980
1981 \newline 
1982 1.
1983  Binary files (preprocessor, assembler and linker)
1984 \newline 
1985
1986 \layout Standard
1987 \align center 
1988
1989 \begin_inset  Tabular
1990 <lyxtabular version="3" rows="4" columns="3">
1991 <features>
1992 <column alignment="block" valignment="top" leftline="true" width="0in">
1993 <column alignment="block" valignment="top" leftline="true" width="0in">
1994 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1995 <row topline="true" bottomline="true">
1996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1997 \begin_inset Text
1998
1999 \layout Standard
2000
2001 Search path
2002 \end_inset 
2003 </cell>
2004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2005 \begin_inset Text
2006
2007 \layout Standard
2008
2009 default
2010 \end_inset 
2011 </cell>
2012 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2013 \begin_inset Text
2014
2015 \layout Standard
2016
2017 Win32 builds
2018 \end_inset 
2019 </cell>
2020 </row>
2021 <row topline="true">
2022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2023 \begin_inset Text
2024
2025 \layout Standard
2026
2027 $SDCC_HOME/
2028 \emph on 
2029 $PPREFIX2BIN_DIR
2030 \end_inset 
2031 </cell>
2032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2033 \begin_inset Text
2034
2035 \layout Standard
2036
2037 $SDCC_HOME/bin
2038 \end_inset 
2039 </cell>
2040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2041 \begin_inset Text
2042
2043 \layout Standard
2044
2045 $SDCC_HOME
2046 \backslash 
2047 bin
2048 \end_inset 
2049 </cell>
2050 </row>
2051 <row topline="true">
2052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2053 \begin_inset Text
2054
2055 \layout Standard
2056
2057 Path of argv[0] (if available)
2058 \end_inset 
2059 </cell>
2060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2061 \begin_inset Text
2062
2063 \layout Standard
2064
2065 Path of argv[0]
2066 \end_inset 
2067 </cell>
2068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2069 \begin_inset Text
2070
2071 \layout Standard
2072
2073 Path of argv[0]
2074 \end_inset 
2075 </cell>
2076 </row>
2077 <row topline="true" bottomline="true">
2078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2079 \begin_inset Text
2080
2081 \layout Standard
2082
2083 $PATH
2084 \end_inset 
2085 </cell>
2086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2087 \begin_inset Text
2088
2089 \layout Standard
2090
2091 $PATH
2092 \end_inset 
2093 </cell>
2094 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2095 \begin_inset Text
2096
2097 \layout Standard
2098
2099 $PATH
2100 \end_inset 
2101 </cell>
2102 </row>
2103 </lyxtabular>
2104
2105 \end_inset 
2106
2107  
2108 \newline 
2109
2110 \layout Standard
2111 \noindent 
2112 2.
2113  Include files
2114 \newline 
2115
2116 \layout Standard
2117 \align center 
2118
2119 \begin_inset  Tabular
2120 <lyxtabular version="3" rows="6" columns="3">
2121 <features>
2122 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2123 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2124 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2125 <row topline="true" bottomline="true">
2126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2127 \begin_inset Text
2128
2129 \layout Standard
2130
2131 Search path
2132 \end_inset 
2133 </cell>
2134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2135 \begin_inset Text
2136
2137 \layout Standard
2138
2139 default
2140 \end_inset 
2141 </cell>
2142 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2143 \begin_inset Text
2144
2145 \layout Standard
2146
2147 Win32 builds
2148 \end_inset 
2149 </cell>
2150 </row>
2151 <row topline="true">
2152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2153 \begin_inset Text
2154
2155 \layout Standard
2156
2157 -
2158 \begin_inset ERT
2159 status Collapsed
2160
2161 \layout Standard
2162
2163 \backslash 
2164 /
2165 \end_inset 
2166
2167 -I dir
2168 \end_inset 
2169 </cell>
2170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2171 \begin_inset Text
2172
2173 \layout Standard
2174
2175 -
2176 \begin_inset ERT
2177 status Collapsed
2178
2179 \layout Standard
2180
2181 \backslash 
2182 /
2183 \end_inset 
2184
2185 -I dir
2186 \end_inset 
2187 </cell>
2188 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2189 \begin_inset Text
2190
2191 \layout Standard
2192
2193 -
2194 \begin_inset ERT
2195 status Collapsed
2196
2197 \layout Standard
2198
2199 \backslash 
2200 /
2201 \end_inset 
2202
2203 -I dir
2204 \end_inset 
2205 </cell>
2206 </row>
2207 <row topline="true">
2208 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2209 \begin_inset Text
2210
2211 \layout Standard
2212
2213 $SDCC_INCLUDE
2214 \end_inset 
2215 </cell>
2216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2217 \begin_inset Text
2218
2219 \layout Standard
2220
2221 $SDCC_INCLUDE
2222 \end_inset 
2223 </cell>
2224 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2225 \begin_inset Text
2226
2227 \layout Standard
2228
2229 $SDCC_INCLUDE
2230 \end_inset 
2231 </cell>
2232 </row>
2233 <row topline="true">
2234 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2235 \begin_inset Text
2236
2237 \layout Standard
2238
2239 $SDCC_HOME/
2240 \newline 
2241
2242 \emph on 
2243 $PREFIX2DATA_DIR/
2244 \newline 
2245 $INCLUDE_DIR_SUFFIX
2246 \end_inset 
2247 </cell>
2248 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2249 \begin_inset Text
2250
2251 \layout Standard
2252
2253 $SDCC_ HOME/
2254 \newline 
2255 share/sdcc/
2256 \newline 
2257 include
2258 \end_inset 
2259 </cell>
2260 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2261 \begin_inset Text
2262
2263 \layout Standard
2264
2265 $SDCC_HOME
2266 \backslash 
2267 include
2268 \end_inset 
2269 </cell>
2270 </row>
2271 <row topline="true">
2272 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2273 \begin_inset Text
2274
2275 \layout Standard
2276
2277 path(argv[0])/
2278 \newline 
2279
2280 \emph on 
2281 $BIN2DATADIR/
2282 \emph default 
2283
2284 \newline 
2285
2286 \emph on 
2287 $INCLUDE_DIR_SUFFIX
2288 \end_inset 
2289 </cell>
2290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2291 \begin_inset Text
2292
2293 \layout Standard
2294
2295 path(argv[0])/
2296 \newline 
2297 ../sdcc/include
2298 \newline 
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 \SpecialChar ~
2337
2338 \end_inset 
2339 </cell>
2340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2341 \begin_inset Text
2342
2343 \layout Standard
2344
2345 path(argv[0])
2346 \backslash 
2347 ..
2348 \backslash 
2349 include
2350 \end_inset 
2351 </cell>
2352 </row>
2353 <row topline="true" bottomline="true">
2354 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2355 \begin_inset Text
2356
2357 \layout Standard
2358
2359
2360 \emph on 
2361 $DATADIR/
2362 \emph default 
2363
2364 \newline 
2365
2366 \emph on 
2367 $INCLUDE_DIR_SUFFIX
2368 \end_inset 
2369 </cell>
2370 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2371 \begin_inset Text
2372
2373 \layout Standard
2374
2375 /usr/local/share/sdcc/
2376 \newline 
2377 include
2378 \end_inset 
2379 </cell>
2380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2381 \begin_inset Text
2382
2383 \layout Standard
2384
2385 (not on Win32)
2386 \end_inset 
2387 </cell>
2388 </row>
2389 </lyxtabular>
2390
2391 \end_inset 
2392
2393  
2394 \newline 
2395
2396 \layout Standard
2397 \noindent 
2398 The option -
2399 \begin_inset ERT
2400 status Collapsed
2401
2402 \layout Standard
2403
2404 \backslash 
2405 /
2406 \end_inset 
2407
2408 -nostdinc disables the last two search paths.
2409 \newline 
2410
2411 \newline 
2412 3.
2413  Library files 
2414 \newline 
2415
2416 \layout Standard
2417
2418 With the exception of 
2419 \begin_inset Quotes sld
2420 \end_inset 
2421
2422 -
2423 \begin_inset ERT
2424 status Collapsed
2425
2426 \layout Standard
2427
2428 \backslash 
2429 /
2430 \end_inset 
2431
2432 -L dir
2433 \begin_inset Quotes srd
2434 \end_inset 
2435
2436  the 
2437 \shape italic 
2438 model
2439 \shape default 
2440  is auto-appended by the compiler (e.g.
2441  small, large, z80, ds390 etc.).
2442  
2443 \newline 
2444
2445 \layout Standard
2446 \align center 
2447
2448 \begin_inset  Tabular
2449 <lyxtabular version="3" rows="6" columns="3">
2450 <features>
2451 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2452 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2453 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2454 <row topline="true" bottomline="true">
2455 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2456 \begin_inset Text
2457
2458 \layout Standard
2459
2460 Search path
2461 \end_inset 
2462 </cell>
2463 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2464 \begin_inset Text
2465
2466 \layout Standard
2467
2468 default
2469 \end_inset 
2470 </cell>
2471 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2472 \begin_inset Text
2473
2474 \layout Standard
2475
2476 Win32 builds
2477 \end_inset 
2478 </cell>
2479 </row>
2480 <row topline="true">
2481 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2482 \begin_inset Text
2483
2484 \layout Standard
2485
2486 -
2487 \begin_inset ERT
2488 status Collapsed
2489
2490 \layout Standard
2491
2492 \backslash 
2493 /
2494 \end_inset 
2495
2496 -L dir
2497 \end_inset 
2498 </cell>
2499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2500 \begin_inset Text
2501
2502 \layout Standard
2503
2504 -
2505 \begin_inset ERT
2506 status Collapsed
2507
2508 \layout Standard
2509
2510 \backslash 
2511 /
2512 \end_inset 
2513
2514 -L dir
2515 \end_inset 
2516 </cell>
2517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2518 \begin_inset Text
2519
2520 \layout Standard
2521
2522 -
2523 \begin_inset ERT
2524 status Collapsed
2525
2526 \layout Standard
2527
2528 \backslash 
2529 /
2530 \end_inset 
2531
2532 -L dir
2533 \end_inset 
2534 </cell>
2535 </row>
2536 <row topline="true">
2537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2538 \begin_inset Text
2539
2540 \layout Standard
2541
2542 $SDCC_LIB/
2543 \newline 
2544
2545 \emph on 
2546 <model>
2547 \end_inset 
2548 </cell>
2549 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2550 \begin_inset Text
2551
2552 \layout Standard
2553
2554 $SDCC_LIB/
2555 \newline 
2556
2557 \emph on 
2558 <model>
2559 \end_inset 
2560 </cell>
2561 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2562 \begin_inset Text
2563
2564 \layout Standard
2565
2566 $SDCC_LIB
2567 \backslash 
2568
2569 \newline 
2570
2571 \emph on 
2572 <model>
2573 \end_inset 
2574 </cell>
2575 </row>
2576 <row topline="true">
2577 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2578 \begin_inset Text
2579
2580 \layout Standard
2581
2582 $SDCC_HOME/
2583 \newline 
2584
2585 \emph on 
2586 $PREFIX2DATA_DIR/
2587 \newline 
2588 $LIB_DIR_SUFFIX/<model>
2589 \end_inset 
2590 </cell>
2591 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2592 \begin_inset Text
2593
2594 \layout Standard
2595
2596 $SDCC_HOME/
2597 \newline 
2598 share/sdcc/
2599 \newline 
2600 lib/
2601 \emph on 
2602 <model>
2603 \end_inset 
2604 </cell>
2605 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2606 \begin_inset Text
2607
2608 \layout Standard
2609
2610 $SDCC_HOME
2611 \backslash 
2612 lib
2613 \backslash 
2614
2615 \emph on 
2616
2617 \newline 
2618 <model>
2619 \end_inset 
2620 </cell>
2621 </row>
2622 <row topline="true">
2623 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2624 \begin_inset Text
2625
2626 \layout Standard
2627
2628 path(argv[0])/
2629 \newline 
2630
2631 \emph on 
2632 $BIN2DATADIR/
2633 \emph default 
2634
2635 \newline 
2636
2637 \emph on 
2638 $LIB_DIR_SUFFIX/<model>
2639 \end_inset 
2640 </cell>
2641 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2642 \begin_inset Text
2643
2644 \layout Standard
2645
2646 path(argv[0])/
2647 \newline 
2648 ../sdcc/lib/
2649 \emph on 
2650 <model>
2651 \newline 
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 \SpecialChar ~
2684 \SpecialChar ~
2685 \SpecialChar ~
2686 \SpecialChar ~
2687 \SpecialChar ~
2688 \SpecialChar ~
2689 \SpecialChar ~
2690 \SpecialChar ~
2691
2692 \end_inset 
2693 </cell>
2694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2695 \begin_inset Text
2696
2697 \layout Standard
2698
2699 path(argv[0])
2700 \backslash 
2701
2702 \newline 
2703 ..
2704 \backslash 
2705 lib
2706 \backslash 
2707
2708 \emph on 
2709 <model>
2710 \newline 
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 \SpecialChar ~
2739 \SpecialChar ~
2740 \SpecialChar ~
2741 \SpecialChar ~
2742 \SpecialChar ~
2743 \SpecialChar ~
2744 \SpecialChar ~
2745 \SpecialChar ~
2746
2747 \end_inset 
2748 </cell>
2749 </row>
2750 <row topline="true" bottomline="true">
2751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2752 \begin_inset Text
2753
2754 \layout Standard
2755
2756
2757 \emph on 
2758 $DATADIR/
2759 \newline 
2760 $LIB_DIR_SUFFIX/<model>
2761 \end_inset 
2762 </cell>
2763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2764 \begin_inset Text
2765
2766 \layout Standard
2767
2768 /usr/local/share/sdcc/
2769 \newline 
2770 lib/
2771 \emph on 
2772 <model>
2773 \end_inset 
2774 </cell>
2775 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2776 \begin_inset Text
2777
2778 \layout Standard
2779
2780 (not on Win32)
2781 \end_inset 
2782 </cell>
2783 </row>
2784 </lyxtabular>
2785
2786 \end_inset 
2787
2788
2789 \newline 
2790
2791 \layout Comment
2792
2793 Don't delete any of the stray spaces in the table above without checking
2794  the HTML output (last line)!
2795 \layout Standard
2796
2797 \SpecialChar ~
2798
2799 \newline 
2800 The option -
2801 \begin_inset ERT
2802 status Collapsed
2803
2804 \layout Standard
2805
2806 \backslash 
2807 /
2808 \end_inset 
2809
2810 -nostdlib disables the last two search paths.
2811 \layout Section
2812
2813 Building SDCC
2814 \begin_inset LatexCommand \index{Building SDCC}
2815
2816 \end_inset 
2817
2818
2819 \layout Subsection
2820
2821 Building SDCC on Linux
2822 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
2823
2824 \end_inset 
2825
2826
2827 \layout Enumerate
2828
2829
2830 \series medium 
2831 Download the source package
2832 \series default 
2833  either from the SDCC CVS repository or from the nightly snapshots
2834 \series medium 
2835 , it will be named something like sdcc
2836 \series default 
2837 .src
2838 \series medium 
2839 .t
2840 \series default 
2841 ar.
2842 \series medium 
2843 gz
2844 \series default 
2845  
2846 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
2847
2848 \end_inset 
2849
2850 .
2851 \layout Enumerate
2852
2853
2854 \series medium 
2855 Bring up a command line terminal, such as xterm.
2856 \layout Enumerate
2857
2858
2859 \series medium 
2860 Unpack the file using a command like: 
2861 \family sans 
2862 \series bold 
2863 "tar -xvzf sdcc.src.tar.gz
2864 \family default 
2865 \series default 
2866 "
2867 \series medium 
2868 , this will create a sub-directory called sdcc with all of the sources.
2869 \layout Enumerate
2870
2871 Change directory into the main SDCC directory, for example type: 
2872 \family sans 
2873 \series bold 
2874 "cd sdcc
2875 \series default 
2876 ".
2877 \layout Enumerate
2878
2879
2880 \series medium 
2881 Type 
2882 \family sans 
2883 \series bold 
2884 "./configure
2885 \family default 
2886 \series default 
2887 ".
2888  This configures the package for compilation on your system.
2889 \layout Enumerate
2890
2891
2892 \series medium 
2893 Type 
2894 \family sans 
2895 \series bold 
2896 "make
2897 \family default 
2898 \series default 
2899 "
2900 \series medium 
2901 .
2902
2903 \series default 
2904  All of the source packages will compile, this can take a while.
2905 \layout Enumerate
2906
2907
2908 \series medium 
2909 Type 
2910 \family sans 
2911 \series bold 
2912 "make install"
2913 \family default 
2914 \series default 
2915  as root
2916 \series medium 
2917 .
2918
2919 \series default 
2920  This copies the binary executables, the include files, the libraries and
2921  the documentation to the install directories.
2922  Proceed with section 
2923 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
2924
2925 \end_inset 
2926
2927 .
2928 \layout Subsection
2929
2930 Building SDCC on OSX 2.x
2931 \layout Standard
2932
2933 Follow the instruction for Linux.
2934 \newline 
2935
2936 \newline 
2937 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
2938 )) fails to compile SDCC.
2939  Fortunately there's also gcc 2.9.x installed, which works fine.
2940  This compiler can be selected by running 'configure' with:
2941 \layout LyX-Code
2942
2943 ./configure CC=gcc2 CXX=g++2
2944 \layout Subsection
2945
2946 Cross compiling SDCC on Linux for Windows
2947 \layout Standard
2948
2949 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
2950  See section 'Configure Options'.
2951 \layout Subsection
2952
2953 Building SDCC on Windows 
2954 \layout Standard
2955
2956 With the exception of Cygwin the SDCC binaries uCsim and sdcdb can't be
2957  built on Windows.
2958  They use Unix-sockets, which are not available on Win32.
2959 \layout Subsection
2960
2961 Building SDCC using Cygwin and Mingw32
2962 \layout Standard
2963
2964 For building and installing a Cygwin executable follow the instructions
2965  for Linux.
2966 \newline 
2967
2968 \newline 
2969 On Cygwin a 
2970 \begin_inset Quotes sld
2971 \end_inset 
2972
2973 native
2974 \begin_inset Quotes srd
2975 \end_inset 
2976
2977  Win32-binary can be built, which will not need the Cygwin-DLL.
2978  For the necessary 'configure' options see section 'configure options' or
2979  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
2980 \newline 
2981
2982 \newline 
2983 In order to install Cygwin on Windows download setup.exe from 
2984 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
2985
2986 \end_inset 
2987
2988 .
2989  Run it, set the 
2990 \begin_inset Quotes sld
2991 \end_inset 
2992
2993 default text file type
2994 \begin_inset Quotes srd
2995 \end_inset 
2996
2997  to 
2998 \begin_inset Quotes sld
2999 \end_inset 
3000
3001 unix
3002 \begin_inset Quotes srd
3003 \end_inset 
3004
3005  and download/install at least the following packages.
3006  Some packages are selected by default, others will be automatically selected
3007  because of dependencies with the manually selected packages.
3008  Never deselect these packages!
3009 \layout Itemize
3010
3011 flex
3012 \layout Itemize
3013
3014 bison
3015 \layout Itemize
3016
3017 gcc ; version 3.x is fine, no need to use the old 2.9x
3018 \layout Itemize
3019
3020 binutils ; selected with gcc
3021 \layout Itemize
3022
3023 make
3024 \layout Itemize
3025
3026 rxvt ; a nice console, which makes life much easier under windoze (see below)
3027 \layout Itemize
3028
3029 man ; not really needed for building SDCC, but you'll miss it sooner or
3030  later
3031 \layout Itemize
3032
3033 less ; not really needed for building SDCC, but you'll miss it sooner or
3034  later
3035 \layout Itemize
3036
3037 cvs ; only if you use CVS access
3038 \layout Standard
3039
3040 If you want to develop something you'll need:
3041 \layout Itemize
3042
3043 python ; for the regression tests
3044 \layout Itemize
3045
3046 gdb ; the gnu debugger, together with the nice GUI 
3047 \begin_inset Quotes sld
3048 \end_inset 
3049
3050 insight
3051 \begin_inset Quotes srd
3052 \end_inset 
3053
3054
3055 \layout Itemize
3056
3057 openssh ; to access the CF or commit changes
3058 \layout Itemize
3059
3060 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3061  use autoconf-stable!
3062 \layout Standard
3063
3064 rxvt is a nice console with history.
3065  Replace in your cygwin.bat the line
3066 \layout LyX-Code
3067
3068 bash -
3069 \begin_inset ERT
3070 status Collapsed
3071
3072 \layout Standard
3073
3074 \backslash 
3075 /
3076 \end_inset 
3077
3078 -login -i 
3079 \layout Standard
3080
3081 with (one line):
3082 \layout LyX-Code
3083
3084 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3085 \layout LyX-Code
3086
3087      -bg black -fg white -geometry 100x65 -e bash -
3088 \begin_inset ERT
3089 status Collapsed
3090
3091 \layout Standard
3092
3093 \backslash 
3094 /
3095 \end_inset 
3096
3097 -login
3098 \layout Standard
3099
3100 Text selected with the mouse is automatically copied to the clipboard, pasting
3101  works with shift-insert.
3102 \newline 
3103
3104 \newline 
3105 The other good tip is to make sure you have no //c/-style paths anywhere,
3106  use /cygdrive/c/ instead.
3107  Using // invokes a network lookup which is very slow.
3108  If you think 
3109 \begin_inset Quotes sld
3110 \end_inset 
3111
3112 cygdrive
3113 \begin_inset Quotes srd
3114 \end_inset 
3115
3116  is too long, you can change it with e.g.
3117 \layout LyX-Code
3118
3119 mount -s -u -c /mnt
3120 \layout Standard
3121
3122 SDCC sources use the unix line ending LF.
3123  Life is much easier, if you store the source tree on a drive which is mounted
3124  in binary mode.
3125  And use an editor which can handle LF-only line endings.
3126  Make sure not to commit files with windows line endings.
3127  The tabulator spacing
3128 \begin_inset LatexCommand \index{tabulator spacing (8)}
3129
3130 \end_inset 
3131
3132  used in the project is 8.
3133 \layout Subsection
3134
3135 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3136 \layout Standard
3137
3138
3139 \series medium 
3140 Download the source package
3141 \series default 
3142  either from the SDCC CVS repository or from the 
3143 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3144
3145 \end_inset 
3146
3147
3148 \series medium 
3149 , it will be named something like sdcc
3150 \series default 
3151 .src
3152 \series medium 
3153 .tgz.
3154
3155 \series default 
3156  SDCC is distributed with all the projects, workspaces, and files you need
3157  to build it using Visual C++ 6.0/NET (except for sdcdb.exe which currently
3158  doesn't build under MSVC).
3159  The workspace name is 'sdcc.dsw'.
3160  Please note that as it is now, all the executables are created in a folder
3161  called sdcc
3162 \backslash 
3163 bin_vc.
3164  Once built you need to copy the executables from sdcc
3165 \backslash 
3166 bin_vc to sdcc
3167 \backslash 
3168 bin before running SDCC.
3169  
3170 \newline 
3171
3172 \newline 
3173 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3174  flex.exe, and gawk.exe.
3175  One good place to get them is 
3176 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3177
3178 \end_inset 
3179
3180
3181 \newline 
3182
3183 \newline 
3184 Download the file UnxUtils
3185 \begin_inset LatexCommand \index{UnxUtils}
3186
3187 \end_inset 
3188
3189 .zip.
3190  Now you have to install the utilities and setup MSVC so it can locate the
3191  required programs.
3192  Here there are two alternatives (choose one!):
3193 \layout Enumerate
3194
3195 The easy way:
3196 \newline 
3197
3198 \newline 
3199 a) Extract UnxUtils.zip to your C:
3200 \backslash 
3201  hard disk PRESERVING the original paths, otherwise bison won't work.
3202  (If you are using WinZip make certain that 'Use folder names' is selected)
3203 \newline 
3204
3205 \newline 
3206 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3207  in 'Show directories for:' select 'Executable files', and in the directories
3208  window add a new path: 'C:
3209 \backslash 
3210 user
3211 \backslash 
3212 local
3213 \backslash 
3214 wbin', click ok.
3215 \newline 
3216
3217 \newline 
3218 (As a side effect, you get a bunch of Unix utilities that could be useful,
3219  such as diff and patch.)
3220 \layout Enumerate
3221
3222 A more compact way:
3223 \newline 
3224
3225 \newline 
3226 This one avoids extracting a bunch of files you may not use, but requires
3227  some extra work:
3228 \newline 
3229
3230 \newline 
3231 a) Create a directory were to put the tools needed, or use a directory already
3232  present.
3233  Say for example 'C:
3234 \backslash 
3235 util'.
3236 \newline 
3237
3238 \newline 
3239 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3240  to such directory WITHOUT preserving the original paths.
3241  (If you are using WinZip make certain that 'Use folder names' is not selected)
3242 \newline 
3243
3244 \newline 
3245 c) Rename bison.exe to '_bison.exe'.
3246 \newline 
3247
3248 \newline 
3249 d) Create a batch file 'bison.bat' in 'C:
3250 \backslash 
3251 util
3252 \backslash 
3253 ' and add these lines: 
3254 \newline 
3255 \SpecialChar ~
3256 \SpecialChar ~
3257 set BISON_SIMPLE=C:
3258 \backslash 
3259 util
3260 \backslash 
3261 bison.simple 
3262 \newline 
3263 \SpecialChar ~
3264 \SpecialChar ~
3265 set BISON_HAIRY=C:
3266 \backslash 
3267 util
3268 \backslash 
3269 bison.hairy
3270 \newline 
3271 \SpecialChar ~
3272 \SpecialChar ~
3273 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3274 \newline 
3275
3276 \newline 
3277 Steps 'c' and 'd' are needed because bison requires by default that the
3278  files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3279  '/usr/local/share/' I think.
3280  So it is necessary to tell bison where those files are located if they
3281  are not in such directory.
3282  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3283 \newline 
3284
3285 \newline 
3286 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3287  in 'Show directories for:' select 'Executable files', and in the directories
3288  window add a new path: 'c:
3289 \backslash 
3290 util', click ok.
3291  Note that you can use any other path instead of 'c:
3292 \backslash 
3293 util', even the path where the Visual C++ tools are, probably: 'C:
3294 \backslash 
3295 Program Files
3296 \backslash 
3297 Microsoft Visual Studio
3298 \backslash 
3299 Common
3300 \backslash 
3301 Tools'.
3302  So you don't have to execute step 'e' :)
3303 \layout Standard
3304
3305 That is it.
3306  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3307  the executables from sdcc
3308 \backslash 
3309 bin_vc to sdcc
3310 \backslash 
3311 bin, and you can compile using SDCC.
3312 \layout Subsection
3313
3314 Building SDCC Using Borland
3315 \layout Enumerate
3316
3317 From the sdcc directory, run the command "make -f Makefile.bcc".
3318  This should regenerate all the .exe files in the bin directory except for
3319  sdcdb.exe (which currently doesn't build under Borland C++).
3320 \layout Enumerate
3321
3322 If you modify any source files and need to rebuild, be aware that the dependenci
3323 es may not be correctly calculated.
3324  The safest option is to delete all .obj files and run the build again.
3325  From a Cygwin BASH prompt, this can easily be done with the command (be
3326  sure you are in the sdcc directory):
3327 \newline 
3328
3329 \newline 
3330
3331 \family sans 
3332 \series bold 
3333 find .
3334  
3335 \backslash 
3336 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
3337 \backslash 
3338 ) -print -exec rm {} 
3339 \backslash 
3340 ;
3341 \family default 
3342 \series default 
3343
3344 \newline 
3345
3346 \newline 
3347 or on Windows NT/2000/XP from the command prompt with the command:
3348 \newline 
3349
3350 \family sans 
3351 \series bold 
3352
3353 \newline 
3354 del /s *.obj *.lib *.rul
3355 \family default 
3356 \series default 
3357  from the sdcc directory.
3358 \layout Subsection
3359
3360 Windows Install Using a Binary Package
3361 \begin_inset LatexCommand \label{sub:Windows-Install}
3362
3363 \end_inset 
3364
3365
3366 \layout Enumerate
3367
3368 Download the binary package from 
3369 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3370
3371 \end_inset 
3372
3373  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
3374  This should unpack to a group of sub-directories.
3375  An example directory structure after unpacking the mingw32 package is:
3376  c:
3377 \backslash 
3378 sdcc
3379 \backslash 
3380 bin for the executables, c:
3381 \backslash 
3382 sdcc
3383 \backslash 
3384 include and c:
3385 \backslash 
3386 sdcc
3387 \backslash 
3388 lib for the include and libraries.
3389 \layout Enumerate
3390
3391 Adjust your environment variable PATH to include the location of the bin
3392  directory or start sdcc using the full path.
3393 \layout Section
3394
3395 Building the Documentation
3396 \layout Standard
3397
3398 If the necessary tools (LyX, LaTeX, LaTeX2HTML) are installed it is as easy
3399  as changing into the doc directory and typing 
3400 \family sans 
3401 \series bold 
3402
3403 \begin_inset Quotes srd
3404 \end_inset 
3405
3406 make
3407 \begin_inset Quotes srd
3408 \end_inset 
3409
3410
3411 \family default 
3412 \series default 
3413  there.
3414  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
3415 x).
3416  Using LyX 
3417 \begin_inset LatexCommand \url{www.lyx.org}
3418
3419 \end_inset 
3420
3421  as editor this is straightforward.
3422  If you want to avoid installing the tools you will have some success with
3423  a bootable Knoppix CD 
3424 \begin_inset LatexCommand \url{http://www.knoppix.net}
3425
3426 \end_inset 
3427
3428 .
3429  Prebuilt documentation in html and pdf format is available from 
3430 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3431
3432 \end_inset 
3433
3434 .
3435 \layout Section
3436
3437 Reading the Documentation
3438 \layout Standard
3439
3440 Currently reading the document in pdf format is recommended, as for unknown
3441  reason the hyperlinks are working there whereas in the html version they
3442  are not
3443 \begin_inset Foot
3444 collapsed false
3445
3446 \layout Standard
3447
3448 If you should know why please drop us a note
3449 \end_inset 
3450
3451 .
3452  You'll find the pdf version at 
3453 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
3454
3455 \end_inset 
3456
3457 .
3458 \newline 
3459 This documentation is in some aspects different from a commercial documentation:
3460  
3461 \layout Itemize
3462
3463 It tries to document SDCC for several processor architectures in one document
3464  (commercially these probably would be separate documents/products).
3465  This document
3466 \begin_inset LatexCommand \index{Status of documentation}
3467
3468 \end_inset 
3469
3470  currently matches SDCC for mcs51 and DS390 best and does give too few informati
3471 on about f.e.
3472  Z80, PIC and HC08.
3473 \layout Itemize
3474
3475 There are many references pointing away from this documentation.
3476  Don't let this distract you.
3477  If there f.e.
3478  was a reference like 
3479 \begin_inset LatexCommand \url{www.opencores.org}
3480
3481 \end_inset 
3482
3483  together with a statement 
3484 \begin_inset Quotes sld
3485 \end_inset 
3486
3487 some processors which are targetted by SDCC can be implemented in a 
3488 \emph on 
3489 f
3490 \emph default 
3491 ield 
3492 \emph on 
3493 p
3494 \emph default 
3495 rogrammable 
3496 \emph on 
3497 g
3498 \emph default 
3499 ate 
3500 \emph on 
3501 a
3502 \emph default 
3503 rray
3504 \begin_inset LatexCommand \index{fpga (field programmable gate array)}
3505
3506 \end_inset 
3507
3508
3509 \begin_inset Quotes srd
3510 \end_inset 
3511
3512  we expect you to have a quick look there and come back.
3513  If you read this you are on the right track.
3514 \layout Itemize
3515
3516 Some sections attribute more space to problems, restrictions and warnings
3517  than to the solution.
3518 \layout Itemize
3519
3520 The installation section and the section about the debugger is intimidating.
3521 \layout Itemize
3522
3523 There are still lots of typos and there are more different writing styles
3524  than pictures.
3525 \layout Section
3526
3527 Testing the SDCC Compiler
3528 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
3529
3530 \end_inset 
3531
3532
3533 \layout Standard
3534
3535 The first thing you should do after installing your SDCC compiler is to
3536  see if it runs.
3537  Type 
3538 \family sans 
3539 \series bold 
3540 "sdcc -
3541 \begin_inset ERT
3542 status Collapsed
3543
3544 \layout Standard
3545
3546 \backslash 
3547 /
3548 \end_inset 
3549
3550 -version"
3551 \begin_inset LatexCommand \index{version}
3552
3553 \end_inset 
3554
3555
3556 \family default 
3557 \series default 
3558  at the prompt, and the program should run and tell you the version.
3559  If it doesn't run, or gives a message about not finding sdcc program, then
3560  you need to check over your installation.
3561  Make sure that the sdcc bin directory is in your executable search path
3562  defined by the PATH environment setting (
3563 \series medium 
3564 see 
3565 \series default 
3566 section 
3567 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3568
3569 \end_inset 
3570
3571 \SpecialChar ~
3572
3573 \series medium 
3574 Install trouble-shooting for suggestions
3575 \series default 
3576 ).
3577  Make sure that the sdcc program is in the bin folder, if not perhaps something
3578  did not install correctly.
3579 \newline 
3580
3581 \newline 
3582
3583 \series medium 
3584 SDCC 
3585 \series default 
3586 is commonly installed as described in section 
3587 \begin_inset Quotes sld
3588 \end_inset 
3589
3590 Install and search paths
3591 \begin_inset Quotes srd
3592 \end_inset 
3593
3594 .
3595 \newline 
3596
3597 \newline 
3598
3599 \series medium 
3600 Make sure the compiler works on a very simple example.
3601  Type in the following test.c program using your favorite 
3602 \series default 
3603 ASCII 
3604 \series medium 
3605 editor:
3606 \layout Verse
3607
3608
3609 \family typewriter 
3610 char test;
3611 \newline 
3612
3613 \newline 
3614 void main(void) {
3615 \newline 
3616 \SpecialChar ~
3617 \SpecialChar ~
3618 \SpecialChar ~
3619 \SpecialChar ~
3620 test=0;
3621 \newline 
3622 }
3623 \layout Standard
3624
3625
3626 \series medium 
3627 Compile this using the following command: 
3628 \family sans 
3629 \series bold 
3630 "sdcc -c test.c".
3631
3632 \family default 
3633 \series default 
3634  
3635 \series medium 
3636 If all goes well, the compiler will generate a test.asm and test.rel file.
3637  Congratulations, you've just compiled your first program with SDCC.
3638  We used the -c option to tell SDCC not to link the generated code, just
3639  to keep things simple for this step.
3640 \series default 
3641
3642 \newline 
3643
3644 \newline 
3645
3646 \series medium 
3647 The next step is to try it with the linker.
3648  Type in 
3649 \family sans 
3650 \series bold 
3651 "sdcc test.c
3652 \family default 
3653 \series default 
3654 "
3655 \series medium 
3656 .
3657  If all goes well the compiler will link with the libraries and produce
3658  a test.ihx output file.
3659  If this step fails
3660 \series default 
3661  
3662 \series medium 
3663 (no test.ihx, and the linker generates warnings), then the problem is most
3664  likely that 
3665 \series default 
3666 SDCC
3667 \series medium 
3668  cannot find the 
3669 \series default 
3670 /
3671 \series medium 
3672 usr/local/share/sdcc/lib directory
3673 \series default 
3674  
3675 \series medium 
3676 (see 
3677 \series default 
3678 section 
3679 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3680
3681 \end_inset 
3682
3683 \SpecialChar ~
3684
3685 \series medium 
3686 Install trouble-shooting for suggestions).
3687 \series default 
3688
3689 \newline 
3690
3691 \newline 
3692
3693 \series medium 
3694 The final test is to ensure 
3695 \series default 
3696 SDCC
3697 \series medium 
3698  can use the 
3699 \series default 
3700 standard
3701 \series medium 
3702  header files and libraries.
3703  Edit test.c and change it to the following:
3704 \layout Verse
3705
3706
3707 \family typewriter 
3708 #include <string.h>
3709 \newline 
3710
3711 \newline 
3712 char str1[10];
3713 \newline 
3714
3715 \newline 
3716 void main(void) {
3717 \newline 
3718 \SpecialChar ~
3719 \SpecialChar ~
3720 strcpy(str1, "testing");
3721 \newline 
3722 }
3723 \layout Standard
3724
3725
3726 \series medium 
3727 Compile this by typing 
3728 \family sans 
3729 \series bold 
3730 "sdcc test.c"
3731 \family default 
3732 \series medium 
3733 .
3734  This should generate a test.ihx output file, and it should give no warnings
3735  such as not finding the string.h file.
3736  If it cannot find the string.h file, then the problem is that 
3737 \series default 
3738 SDCC
3739 \series medium 
3740  cannot find the /usr/local/share/sdcc/include directory
3741 \series default 
3742  
3743 \series medium 
3744 (see the 
3745 \series default 
3746 section 
3747 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3748
3749 \end_inset 
3750
3751 \SpecialChar ~
3752
3753 \series medium 
3754 Install trouble-shooting section for suggestions).
3755
3756 \series default 
3757  Use option 
3758 \series bold 
3759 -
3760 \begin_inset ERT
3761 status Collapsed
3762
3763 \layout Standard
3764
3765 \backslash 
3766 /
3767 \end_inset 
3768
3769 -print-search-dirs
3770 \series default 
3771
3772 \begin_inset LatexCommand \index{-\/-print-search-dirs}
3773
3774 \end_inset 
3775
3776  to find exactly where SDCC is looking for the include and lib files.
3777 \layout Section
3778
3779 Install Trouble-shooting
3780 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
3781
3782 \end_inset 
3783
3784
3785 \begin_inset LatexCommand \index{Install trouble-shooting}
3786
3787 \end_inset 
3788
3789
3790 \layout Subsection
3791
3792 If SDCC does not build correctly
3793 \layout Standard
3794
3795 A thing to try is starting from scratch by unpacking the .tgz source package
3796  again in an empty directory.
3797  Configure it like:
3798 \newline 
3799
3800 \newline 
3801
3802 \family sans 
3803 \series bold 
3804 ./configure 2>&1 | tee configure.log
3805 \family default 
3806 \series default 
3807
3808 \newline 
3809
3810 \newline 
3811 and build it like:
3812 \newline 
3813
3814 \newline 
3815
3816 \family sans 
3817 \series bold 
3818 make 2>&1 | tee make.log
3819 \family default 
3820 \series default 
3821
3822 \newline 
3823
3824 \newline 
3825 If anything goes wrong, you can review the log files to locate the problem.
3826  Or a relevant part of this can be attached to an email that could be helpful
3827  when requesting help from the mailing list.
3828 \layout Subsection
3829
3830 What the 
3831 \begin_inset Quotes sld
3832 \end_inset 
3833
3834 ./configure
3835 \begin_inset Quotes srd
3836 \end_inset 
3837
3838  does
3839 \layout Standard
3840
3841 The 
3842 \begin_inset Quotes sld
3843 \end_inset 
3844
3845 ./configure
3846 \begin_inset Quotes srd
3847 \end_inset 
3848
3849  command is a script that analyzes your system and performs some configuration
3850  to ensure the source package compiles on your system.
3851  It will take a few minutes to run, and will compile a few tests to determine
3852  what compiler features are installed.
3853 \layout Subsection
3854
3855 What the 
3856 \begin_inset Quotes sld
3857 \end_inset 
3858
3859 make
3860 \begin_inset Quotes srd
3861 \end_inset 
3862
3863  does
3864 \layout Standard
3865
3866 This runs the GNU make tool, which automatically compiles all the source
3867  packages into the final installed binary executables.
3868 \layout Subsection
3869
3870 What the 
3871 \begin_inset Quotes sld
3872 \end_inset 
3873
3874 make install
3875 \begin_inset Quotes erd
3876 \end_inset 
3877
3878  command does.
3879 \layout Standard
3880
3881 This will install the compiler, other executables libraries and include
3882  files into the appropriate directories.
3883  See sections 
3884 \begin_inset LatexCommand \ref{sub:Install-paths}
3885
3886 \end_inset 
3887
3888 ,\SpecialChar ~
3889
3890 \begin_inset LatexCommand \ref{sub:Search-Paths}
3891
3892 \end_inset 
3893
3894 \SpecialChar ~
3895 about install and search paths.
3896 \newline 
3897 On most systems you will need super-user privileges to do this.
3898 \layout Section
3899
3900 Components of SDCC
3901 \layout Standard
3902
3903 SDCC is not just a compiler, but a collection of tools by various developers.
3904  These include linkers, assemblers, simulators and other components.
3905  Here is a summary of some of the components.
3906  Note that the included simulator and assembler have separate documentation
3907  which you can find in the source package in their respective directories.
3908  As SDCC grows to include support for other processors, other packages from
3909  various developers are included and may have their own sets of documentation.
3910 \newline 
3911
3912 \newline 
3913 You might want to look at the files which are installed in <installdir>.
3914  At the time of this writing, we find the following programs for gcc-builds:
3915 \newline 
3916  
3917 \newline 
3918 In <installdir>/bin:
3919 \layout Itemize
3920
3921 sdcc - The compiler.
3922 \layout Itemize
3923
3924 sdcpp - The C preprocessor.
3925 \layout Itemize
3926
3927 asx8051 - The assembler for 8051 type processors.
3928 \layout Itemize
3929
3930 as-z80
3931 \series bold 
3932
3933 \series default 
3934 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
3935 \layout Itemize
3936
3937 aslink -The linker for 8051 type processors.
3938 \layout Itemize
3939
3940 link-z80
3941 \series bold 
3942
3943 \series default 
3944 link-gbz80 - The Z80 and GameBoy Z80 linkers.
3945 \layout Itemize
3946
3947 s51 - The ucSim 8051 simulator.
3948 \layout Itemize
3949
3950 sdcdb - The source debugger.
3951 \layout Itemize
3952
3953 packihx - A tool to pack (compress) Intel hex files.
3954 \layout Standard
3955
3956 In <installdir>/share/sdcc/include
3957 \layout Itemize
3958
3959 the include files
3960 \layout Standard
3961
3962 In <installdir>/share/sdcc/lib
3963 \layout Itemize
3964
3965 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
3966  relocatables.
3967 \layout Standard
3968
3969 In <installdir>/share/sdcc/doc
3970 \layout Itemize
3971
3972 the documentation
3973 \layout Standard
3974
3975 As development for other processors proceeds, this list will expand to include
3976  executables to support processors like AVR, PIC, etc.
3977 \layout Subsection
3978
3979 sdcc - The Compiler
3980 \layout Standard
3981
3982 This is the actual compiler, it in turn uses the c-preprocessor and invokes
3983  the assembler and linkage editor.
3984 \layout Subsection
3985
3986 sdcpp - The C-Preprocessor
3987 \layout Standard
3988
3989 The preprocessor
3990 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
3991
3992 \end_inset 
3993
3994  is a modified version of the GNU preprocessor.
3995  The C preprocessor is used to pull in #include sources, process #ifdef
3996  statements, #defines and so on.
3997 \layout Subsection
3998
3999 as
4000 \emph on 
4001 xxxx
4002 \emph default 
4003 , aslink, link-
4004 \emph on 
4005 xxx
4006 \emph default 
4007  - The Assemblers and Linkage Editors
4008 \layout Standard
4009
4010 This is retargettable assembler & linkage editor, it was developed by Alan
4011  Baldwin.
4012  John Hartman created the version for 8051, and I (Sandeep) have made some
4013  enhancements and bug fixes for it to work properly with SDCC.
4014 \layout Subsection
4015
4016 s51 - The Simulator
4017 \layout Standard
4018
4019 S51
4020 \begin_inset LatexCommand \index{s51}
4021
4022 \end_inset 
4023
4024  is a freeware, opensource simulator developed by Daniel Drotos (
4025 \begin_inset LatexCommand \url{mailto:drdani@mazsola.iit.uni-miskolc.hu}
4026
4027 \end_inset 
4028
4029 ).
4030  The simulator is built as part of the build process.
4031  For more information visit Daniel's web site at: 
4032 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
4033
4034 \end_inset 
4035
4036 .
4037  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
4038  XA51 family.
4039 \layout Subsection
4040
4041 sdcdb - Source Level Debugger
4042 \layout Standard
4043
4044 Sdcdb
4045 \begin_inset LatexCommand \index{sdcdb (debugger)}
4046
4047 \end_inset 
4048
4049  is the companion source level debugger.
4050  More about sdcdb in section 
4051 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
4052
4053 \end_inset 
4054
4055 .
4056  The current version of the debugger uses Daniel's Simulator S51
4057 \begin_inset LatexCommand \index{s51}
4058
4059 \end_inset 
4060
4061 , but can be easily changed to use other simulators.
4062  
4063 \layout Chapter
4064
4065 Using SDCC
4066 \layout Section
4067
4068 Compiling
4069 \layout Subsection
4070
4071 Single Source File Projects
4072 \layout Standard
4073
4074 For single source file 8051 projects the process is very simple.
4075  Compile your programs with the following command 
4076 \family sans 
4077 \series bold 
4078 "sdcc sourcefile.c".
4079
4080 \family default 
4081 \series default 
4082  This will compile, assemble and link your source file.
4083  Output files are as follows:
4084 \layout Itemize
4085
4086 sourcefile.asm
4087 \begin_inset LatexCommand \index{<file>.asm}
4088
4089 \end_inset 
4090
4091  - Assembler source
4092 \begin_inset LatexCommand \index{Assembler source}
4093
4094 \end_inset 
4095
4096  file created by the compiler
4097 \layout Itemize
4098
4099 sourcefile.lst
4100 \begin_inset LatexCommand \index{<file>.lst}
4101
4102 \end_inset 
4103
4104  - Assembler listing
4105 \begin_inset LatexCommand \index{Assembler listing}
4106
4107 \end_inset 
4108
4109  file created by the Assembler
4110 \layout Itemize
4111
4112 sourcefile.rst
4113 \begin_inset LatexCommand \index{<file>.rst}
4114
4115 \end_inset 
4116
4117  - Assembler listing
4118 \begin_inset LatexCommand \index{Assembler listing}
4119
4120 \end_inset 
4121
4122  file updated with linkedit information, created by linkage editor
4123 \layout Itemize
4124
4125 sourcefile.sym
4126 \begin_inset LatexCommand \index{<file>.sym}
4127
4128 \end_inset 
4129
4130  - symbol listing
4131 \begin_inset LatexCommand \index{Symbol listing}
4132
4133 \end_inset 
4134
4135  for the sourcefile, created by the assembler
4136 \layout Itemize
4137
4138 sourcefile.rel
4139 \begin_inset LatexCommand \index{<file>.rel}
4140
4141 \end_inset 
4142
4143  or sourcefile.o
4144 \begin_inset LatexCommand \index{<file>.o}
4145
4146 \end_inset 
4147
4148  - Object file
4149 \begin_inset LatexCommand \index{Object file}
4150
4151 \end_inset 
4152
4153  created by the assembler, input to Linkage editor
4154 \layout Itemize
4155
4156 sourcefile.map
4157 \begin_inset LatexCommand \index{<file>.map}
4158
4159 \end_inset 
4160
4161  - The memory map
4162 \begin_inset LatexCommand \index{Memory map}
4163
4164 \end_inset 
4165
4166  for the load module, created by the Linker
4167 \layout Itemize
4168
4169 sourcefile.mem
4170 \begin_inset LatexCommand \index{<file>.mem}
4171
4172 \end_inset 
4173
4174  - A file with a summary of the memory usage
4175 \layout Itemize
4176
4177 sourcefile.ihx
4178 \begin_inset LatexCommand \index{<file>.ihx}
4179
4180 \end_inset 
4181
4182  - The load module in Intel hex format
4183 \begin_inset LatexCommand \index{Intel hex format}
4184
4185 \end_inset 
4186
4187  (you can select the Motorola S19 format
4188 \begin_inset LatexCommand \index{Motorola S19 format}
4189
4190 \end_inset 
4191
4192  with -
4193 \begin_inset ERT
4194 status Collapsed
4195
4196 \layout Standard
4197
4198 \backslash 
4199 /
4200 \end_inset 
4201
4202 -out-fmt-s19
4203 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
4204
4205 \end_inset 
4206
4207 .
4208  If you need another format you might want to use 
4209 \family sans 
4210 \shape italic 
4211 objdump
4212 \family default 
4213 \shape default 
4214
4215 \begin_inset LatexCommand \index{objdump (tool)}
4216
4217 \end_inset 
4218
4219  or
4220 \family sans 
4221 \shape italic 
4222  srecord
4223 \family default 
4224 \shape default 
4225
4226 \begin_inset LatexCommand \index{srecord (tool)}
4227
4228 \end_inset 
4229
4230 ).
4231  Both formats are documented in the the documentation of srecord
4232 \begin_inset LatexCommand \index{srecord (tool)}
4233
4234 \end_inset 
4235
4236
4237 \layout Itemize
4238
4239 sourcefile.adb
4240 \begin_inset LatexCommand \index{.adb}
4241
4242 \end_inset 
4243
4244  - An intermediate file containing debug information needed to create the
4245  .cdb file (with -
4246 \begin_inset ERT
4247 status Collapsed
4248
4249 \layout Standard
4250
4251 \backslash 
4252 /
4253 \end_inset 
4254
4255 -debug
4256 \begin_inset LatexCommand \index{-\/-debug}
4257
4258 \end_inset 
4259
4260
4261 \layout Itemize
4262
4263 sourcefile.cdb
4264 \begin_inset LatexCommand \index{<file>.cdb}
4265
4266 \end_inset 
4267
4268  - An optional file (with -
4269 \begin_inset ERT
4270 status Collapsed
4271
4272 \layout Standard
4273
4274 \backslash 
4275 /
4276 \end_inset 
4277
4278 -debug) containing debug information.
4279  The format is documented in cdbfileformat.pdf.
4280 \layout Itemize
4281
4282 sourcefile.
4283  - (no extension)
4284 \begin_inset LatexCommand \index{<file> (no extension)}
4285
4286 \end_inset 
4287
4288  An optional AOMF or AOMF51
4289 \begin_inset LatexCommand \index{AOMF, AOMF51}
4290
4291 \end_inset 
4292
4293  file containing debug information (generated with option -
4294 \begin_inset ERT
4295 status Collapsed
4296
4297 \layout Standard
4298
4299 \backslash 
4300 /
4301 \end_inset 
4302
4303 -debug).
4304  The (Intel)
4305 \emph on 
4306  a
4307 \emph default 
4308 bsolute 
4309 \emph on 
4310 o
4311 \emph default 
4312 bject 
4313 \emph on 
4314 m
4315 \emph default 
4316 odule 
4317 \emph on 
4318 f
4319 \emph default 
4320 ormat is commonly used by third party tools (debuggers
4321 \begin_inset LatexCommand \index{Debugger}
4322
4323 \end_inset 
4324
4325 , simulators, emulators)
4326 \layout Itemize
4327
4328 sourcefile.dump*
4329 \begin_inset LatexCommand \index{<file>.dump*}
4330
4331 \end_inset 
4332
4333  - Dump file to debug the compiler it self (generated with option -
4334 \begin_inset ERT
4335 status Collapsed
4336
4337 \layout Standard
4338
4339 \backslash 
4340 /
4341 \end_inset 
4342
4343 -dumpall) (see section 
4344 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
4345
4346 \end_inset 
4347
4348 \SpecialChar ~
4349  and section 
4350 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
4351
4352 \end_inset 
4353
4354 \SpecialChar ~
4355
4356 \begin_inset Quotes sld
4357 \end_inset 
4358
4359 Anatomy of the compiler
4360 \begin_inset Quotes srd
4361 \end_inset 
4362
4363 ).
4364 \layout Subsection
4365
4366 Projects with Multiple Source Files
4367 \layout Standard
4368
4369 SDCC can compile only ONE file at a time.
4370  Let us for example assume that you have a project containing the following
4371  files:
4372 \newline 
4373
4374 \newline 
4375 foo1.c (contains some functions)
4376 \newline 
4377 foo2.c (contains some more functions)
4378 \newline 
4379 foomain.c (contains more functions and the function main)
4380 \newline 
4381
4382 \size footnotesize 
4383
4384 \newline 
4385
4386 \size default 
4387 The first two files will need to be compiled separately with the commands:
4388 \size footnotesize 
4389  
4390 \size default 
4391
4392 \newline 
4393
4394 \newline 
4395
4396 \family sans 
4397 \series bold 
4398 sdcc\SpecialChar ~
4399 -c\SpecialChar ~
4400 foo1.c
4401 \family default 
4402 \series default 
4403 \size footnotesize 
4404
4405 \newline 
4406
4407 \family sans 
4408 \series bold 
4409 \size default 
4410 sdcc\SpecialChar ~
4411 -c\SpecialChar ~
4412 foo2.c
4413 \family default 
4414 \series default 
4415
4416 \newline 
4417
4418 \newline 
4419 Then compile the source file containing the 
4420 \emph on 
4421 main()
4422 \emph default 
4423  function and link
4424 \begin_inset LatexCommand \index{Linker}
4425
4426 \end_inset 
4427
4428  the files together with the following command: 
4429 \newline 
4430
4431 \newline 
4432
4433 \family sans 
4434 \series bold 
4435 sdcc\SpecialChar ~
4436 foomain.c\SpecialChar ~
4437 foo1.rel\SpecialChar ~
4438 foo2.rel
4439 \family default 
4440 \series default 
4441
4442 \begin_inset LatexCommand \index{<file>.rel}
4443
4444 \end_inset 
4445
4446
4447 \newline 
4448
4449 \newline 
4450 Alternatively, 
4451 \emph on 
4452 foomain.c 
4453 \emph default 
4454 can be separately compiled as well: 
4455 \family sans 
4456 \series bold 
4457
4458 \newline 
4459
4460 \newline 
4461 sdcc\SpecialChar ~
4462 -c\SpecialChar ~
4463 foomain.c
4464 \newline 
4465 sdcc foomain.rel foo1.rel foo2.rel
4466 \newline 
4467
4468 \newline 
4469
4470 \family default 
4471 \series default 
4472 The file containing the 
4473 \emph on 
4474 main()
4475 \emph default 
4476  function
4477 \emph on 
4478  
4479 \emph default 
4480 \noun on 
4481 must
4482 \noun default 
4483  be the 
4484 \noun on 
4485 first
4486 \noun default 
4487  file specified in the command line, since the linkage editor processes
4488  file in the order they are presented to it.
4489  The linker is invoked from SDCC using a script file with extension .lnk
4490 \begin_inset LatexCommand \index{.lnk}
4491
4492 \end_inset 
4493
4494 .
4495  You can view this file to troubleshoot linking problems such as those arising
4496  from missing libraries.
4497 \layout Subsection
4498
4499 Projects with Additional Libraries
4500 \begin_inset LatexCommand \index{Libraries}
4501
4502 \end_inset 
4503
4504
4505 \layout Standard
4506
4507 Some reusable routines may be compiled into a library, see the documentation
4508  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
4509  for how to create a 
4510 \emph on 
4511 .lib
4512 \begin_inset LatexCommand \index{.lib}
4513
4514 \end_inset 
4515
4516
4517 \emph default 
4518  library file.
4519  Libraries created in this manner can be included in the command line.
4520  Make sure you include the -L <library-path> option to tell the linker where
4521  to look for these files if they are not in the current directory.
4522  Here is an example, assuming you have the source file 
4523 \emph on 
4524 foomain.c
4525 \emph default 
4526  and a library
4527 \emph on 
4528  foolib.lib
4529 \emph default 
4530  in the directory 
4531 \emph on 
4532 mylib
4533 \emph default 
4534  (if that is not the same as your current project):
4535 \newline 
4536
4537 \newline 
4538
4539 \family sans 
4540 \series bold 
4541 sdcc foomain.c foolib.lib -L mylib
4542 \newline 
4543
4544 \newline 
4545
4546 \family default 
4547 \series default 
4548 Note here that
4549 \emph on 
4550  mylib
4551 \emph default 
4552  must be an absolute path name.
4553 \newline 
4554
4555 \newline 
4556 The most efficient way to use libraries is to keep separate modules in separate
4557  source files.
4558  The lib file now should name all the modules.rel
4559 \begin_inset LatexCommand \index{<file>.rel}
4560
4561 \end_inset 
4562
4563  files.
4564  For an example see the standard library file 
4565 \emph on 
4566 libsdcc.lib
4567 \emph default 
4568  in the directory <installdir>/share/lib/small.
4569 \layout Subsection
4570
4571 Using sdcclib to Create and Manage Libraries
4572 \begin_inset LatexCommand \index{sdcclib}
4573
4574 \end_inset 
4575
4576
4577 \layout Standard
4578
4579 Alternatively, instead of having a .rel file for each entry on the library
4580  file as described in the preceding section, sdcclib can be used to embed
4581  all the modules belonging to such library in the library file itself.
4582  This results in a larger library file, but it greatly reduces the number
4583  of disk files accessed by the linker.
4584   Additionally, the packed library file contains an index of all include
4585  modules and symbols that significantly speeds up the linking process.
4586  To display a list of options supported by sdcclib type:
4587 \newline 
4588
4589 \layout Standard
4590
4591
4592 \family sans 
4593 \series bold 
4594 sdcclib -?
4595 \begin_inset LatexCommand \index{sdcclib}
4596
4597 \end_inset 
4598
4599
4600 \newline 
4601
4602 \newline 
4603
4604 \family default 
4605 \series default 
4606 To create a new library file, start by compiling all the required modules.
4607  For example:
4608 \newline 
4609
4610 \layout Standard
4611
4612
4613 \series bold 
4614 sdcc -c _divsint.c
4615 \layout Standard
4616
4617
4618 \series bold 
4619 sdcc -c _divuint.c
4620 \layout Standard
4621
4622
4623 \series bold 
4624 sdcc -c _modsint.c
4625 \layout Standard
4626
4627
4628 \series bold 
4629 sdcc -c _moduint.c
4630 \layout Standard
4631
4632
4633 \series bold 
4634 sdcc -c _mulint.c
4635 \newline 
4636
4637 \layout Standard
4638
4639 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
4640  and _mulint.rel.
4641  The next step is to add the .rel files to the library file:
4642 \newline 
4643
4644 \layout Standard
4645
4646
4647 \series bold 
4648 sdcclib libint.lib _divsint.rel
4649 \begin_inset LatexCommand \index{sdcclib}
4650
4651 \end_inset 
4652
4653
4654 \layout Standard
4655
4656
4657 \series bold 
4658 sdcclib libint.lib _divuint.rel
4659 \layout Standard
4660
4661
4662 \series bold 
4663 sdcclib libint.lib _modsint.rel
4664 \layout Standard
4665
4666
4667 \series bold 
4668 sdcclib libint.lib _moduint.rel
4669 \layout Standard
4670
4671
4672 \series bold 
4673 sdcclib libint.lib _mulint.rel
4674 \series default 
4675
4676 \newline 
4677
4678 \layout Standard
4679
4680 If the file already exists in the library, it will be replaced.
4681  To see what modules and symbols are included in the library, options -s
4682  and -m are available.
4683  For example:
4684 \newline 
4685
4686 \newline 
4687
4688 \series bold 
4689 sdcclib -s libint.lib
4690 \begin_inset LatexCommand \index{sdcclib}
4691
4692 \end_inset 
4693
4694
4695 \newline 
4696 _divsint.rel:
4697 \layout Standard
4698
4699
4700 \series bold 
4701 __divsint_a_1_1
4702 \layout Standard
4703
4704
4705 \series bold 
4706 __divsint_PARM_2
4707 \layout Standard
4708
4709
4710 \series bold 
4711 __divsint
4712 \newline 
4713 _divuint.rel:
4714 \layout Standard
4715
4716
4717 \series bold 
4718 __divuint_a_1_1
4719 \layout Standard
4720
4721
4722 \series bold 
4723 __divuint_PARM_2
4724 \layout Standard
4725
4726
4727 \series bold 
4728 __divuint_reste_1_1
4729 \layout Standard
4730
4731
4732 \series bold 
4733 __divuint_count_1_1
4734 \layout Standard
4735
4736
4737 \series bold 
4738 __divuint
4739 \newline 
4740 _modsint.rel:
4741 \layout Standard
4742
4743
4744 \series bold 
4745 __modsint_a_1_1
4746 \layout Standard
4747
4748
4749 \series bold 
4750 __modsint_PARM_2
4751 \layout Standard
4752
4753
4754 \series bold 
4755 __modsint
4756 \newline 
4757 _moduint.rel:
4758 \layout Standard
4759
4760
4761 \series bold 
4762 __moduint_a_1_1
4763 \layout Standard
4764
4765
4766 \series bold 
4767 __moduint_PARM_2
4768 \layout Standard
4769
4770
4771 \series bold 
4772 __moduint_count_1_1
4773 \layout Standard
4774
4775
4776 \series bold 
4777 __moduint
4778 \newline 
4779 _mulint.rel:
4780 \layout Standard
4781
4782
4783 \series bold 
4784 __mulint_PARM_2
4785 \layout Standard
4786
4787
4788 \series bold 
4789 __mulint
4790 \newline 
4791
4792 \layout Standard
4793
4794 If the source files are compiled using --debug, the corresponding debug
4795  information file .adb will be include in the library file as well.
4796  The library files created with sdcclib are plain text files, so they can
4797  be viewed with a text editor.
4798  It is not recomended to modify a library file created with sdcclib using
4799  a text editor, as there are file indexes numbers located accross the file
4800  used by the linker to quickly locate the required module to link.
4801  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
4802  it can be safely deleted, since all the information required for linking
4803  is embedded in the library file itself.
4804  Library files created using sdcclib are used as described in the preceding
4805  sections.
4806 \layout Section
4807
4808 Command Line Options
4809 \begin_inset LatexCommand \index{Command Line Options}
4810
4811 \end_inset 
4812
4813
4814 \layout Subsection
4815
4816 Processor Selection Options
4817 \begin_inset LatexCommand \index{Options processor selection}
4818
4819 \end_inset 
4820
4821
4822 \begin_inset LatexCommand \index{Processor selection options}
4823
4824 \end_inset 
4825
4826
4827 \layout List
4828 \labelwidthstring 00.00.0000
4829
4830
4831 \series bold 
4832 -mmcs51
4833 \begin_inset LatexCommand \index{-mmcs51}
4834
4835 \end_inset 
4836
4837
4838 \series default 
4839  Generate code for the Intel MCS51
4840 \begin_inset LatexCommand \index{MCS51}
4841
4842 \end_inset 
4843
4844  family of processors.
4845  This is the default processor target.
4846 \layout List
4847 \labelwidthstring 00.00.0000
4848
4849
4850 \series bold 
4851 -mds390
4852 \begin_inset LatexCommand \index{-mds390}
4853
4854 \end_inset 
4855
4856
4857 \series default 
4858  Generate code for the Dallas DS80C390
4859 \begin_inset LatexCommand \index{DS80C390}
4860
4861 \end_inset 
4862
4863  processor.
4864 \layout List
4865 \labelwidthstring 00.00.0000
4866
4867
4868 \series bold 
4869 -mds400
4870 \begin_inset LatexCommand \index{-mds400}
4871
4872 \end_inset 
4873
4874
4875 \series default 
4876  Generate code for the Dallas DS80C400
4877 \begin_inset LatexCommand \index{DS80C400}
4878
4879 \end_inset 
4880
4881  processor.
4882 \layout List
4883 \labelwidthstring 00.00.0000
4884
4885
4886 \series bold 
4887 -mhc08
4888 \begin_inset LatexCommand \index{-mhc08}
4889
4890 \end_inset 
4891
4892
4893 \series default 
4894  Generate code for the Motorola HC08
4895 \begin_inset LatexCommand \index{HC08}
4896
4897 \end_inset 
4898
4899  family of processors (added Oct 2003).
4900 \layout List
4901 \labelwidthstring 00.00.0000
4902
4903
4904 \series bold 
4905 -mz80
4906 \begin_inset LatexCommand \index{-mz80}
4907
4908 \end_inset 
4909
4910
4911 \series default 
4912  Generate code for the Zilog Z80
4913 \begin_inset LatexCommand \index{Z80}
4914
4915 \end_inset 
4916
4917  family of processors.
4918 \layout List
4919 \labelwidthstring 00.00.0000
4920
4921
4922 \series bold 
4923 -mgbz80
4924 \begin_inset LatexCommand \index{-mgbz80}
4925
4926 \end_inset 
4927
4928
4929 \series default 
4930  Generate code for the GameBoy Z80
4931 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
4932
4933 \end_inset 
4934
4935  processor (Not actively maintained).
4936 \layout List
4937 \labelwidthstring 00.00.0000
4938
4939
4940 \series bold 
4941 -mavr
4942 \begin_inset LatexCommand \index{-mavr}
4943
4944 \end_inset 
4945
4946
4947 \series default 
4948  Generate code for the Atmel AVR
4949 \begin_inset LatexCommand \index{AVR}
4950
4951 \end_inset 
4952
4953  processor (In development, not complete).
4954  AVR users should probably have a look at avr-gcc 
4955 \begin_inset LatexCommand \url{ http://savannah.nongnu.org/download/avr-libc/snapshots/}
4956
4957 \end_inset 
4958
4959 .
4960 \layout Comment
4961
4962 I think it is fair to direct users there for now.
4963  Open source is also about avoiding unnecessary work .
4964  But I didn't find the 'official' link.
4965 \layout List
4966 \labelwidthstring 00.00.0000
4967
4968
4969 \series bold 
4970 -mpic14
4971 \begin_inset LatexCommand \index{-mpic14}
4972
4973 \end_inset 
4974
4975
4976 \series default 
4977  Generate code for the Microchip PIC 14
4978 \begin_inset LatexCommand \index{PIC14}
4979
4980 \end_inset 
4981
4982 -bit processors (p16f84 and variants.
4983  In development, not complete).
4984 \layout Comment
4985
4986 p16f627 p16f628 p16f84 p16f873 p16f877?
4987 \layout List
4988 \labelwidthstring 00.00.0000
4989
4990
4991 \series bold 
4992 -mpic16
4993 \begin_inset LatexCommand \index{-mpic16}
4994
4995 \end_inset 
4996
4997
4998 \series default 
4999  Generate code for the Microchip PIC 16
5000 \begin_inset LatexCommand \index{PIC16}
5001
5002 \end_inset 
5003
5004 -bit processors (p18f452 and variants.
5005  In development, not complete).
5006 \layout List
5007 \labelwidthstring 00.00.0000
5008
5009
5010 \series bold 
5011 -mtlcs900h
5012 \series default 
5013  Generate code for the Toshiba TLCS-900H
5014 \begin_inset LatexCommand \index{TLCS-900H}
5015
5016 \end_inset 
5017
5018  processor (Not maintained, not complete).
5019 \layout List
5020 \labelwidthstring 00.00.0000
5021
5022
5023 \series bold 
5024 -mxa51
5025 \begin_inset LatexCommand \index{-mxa51}
5026
5027 \end_inset 
5028
5029
5030 \series default 
5031  Generate code for the Phillips XA51
5032 \begin_inset LatexCommand \index{XA51}
5033
5034 \end_inset 
5035
5036  processor (Not maintained, not complete).
5037 \layout Subsection
5038
5039 Preprocessor Options
5040 \begin_inset LatexCommand \index{Options preprocessor}
5041
5042 \end_inset 
5043
5044
5045 \begin_inset LatexCommand \index{Preprocessor options}
5046
5047 \end_inset 
5048
5049
5050 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5051
5052 \end_inset 
5053
5054
5055 \layout List
5056 \labelwidthstring 00.00.0000
5057
5058
5059 \series bold 
5060 -I<path>
5061 \begin_inset LatexCommand \index{-I<path>}
5062
5063 \end_inset 
5064
5065
5066 \series default 
5067  The additional location where the pre processor will look for <..h> or 
5068 \begin_inset Quotes eld
5069 \end_inset 
5070
5071 ..h
5072 \begin_inset Quotes erd
5073 \end_inset 
5074
5075  files.
5076 \layout List
5077 \labelwidthstring 00.00.0000
5078
5079
5080 \series bold 
5081 -D<macro[=value]>
5082 \begin_inset LatexCommand \index{-D<macro[=value]>}
5083
5084 \end_inset 
5085
5086
5087 \series default 
5088  Command line definition of macros.
5089  Passed to the preprocessor.
5090 \layout List
5091 \labelwidthstring 00.00.0000
5092
5093
5094 \series bold 
5095 -M
5096 \begin_inset LatexCommand \index{-M}
5097
5098 \end_inset 
5099
5100
5101 \series default 
5102  Tell the preprocessor to output a rule suitable for make describing the
5103  dependencies of each object file.
5104  For each source file, the preprocessor outputs one make-rule whose target
5105  is the object file name for that source file and whose dependencies are
5106  all the files `#include'd in it.
5107  This rule may be a single line or may be continued with `
5108 \backslash 
5109 '-newline if it is long.
5110  The list of rules is printed on standard output instead of the preprocessed
5111  C program.
5112  `-M' implies `-E
5113 \begin_inset LatexCommand \index{-E}
5114
5115 \end_inset 
5116
5117 '.
5118 \layout List
5119 \labelwidthstring 00.00.0000
5120
5121
5122 \series bold 
5123 -C
5124 \begin_inset LatexCommand \index{-C}
5125
5126 \end_inset 
5127
5128
5129 \series default 
5130  Tell the preprocessor not to discard comments.
5131  Used with the `-E' option.
5132 \layout List
5133 \labelwidthstring 00.00.0000
5134
5135
5136 \series bold 
5137 -MM
5138 \begin_inset LatexCommand \index{-MM}
5139
5140 \end_inset 
5141
5142
5143 \size large 
5144 \bar under 
5145  
5146 \series default 
5147 \size default 
5148 \bar default 
5149 Like `-M' but the output mentions only the user header files included with
5150  `#include 
5151 \begin_inset Quotes eld
5152 \end_inset 
5153
5154 file"'.
5155  System header files included with `#include <file>' are omitted.
5156 \layout List
5157 \labelwidthstring 00.00.0000
5158
5159
5160 \series bold 
5161 -Aquestion(answer)
5162 \begin_inset LatexCommand \index{-Aquestion(answer)}
5163
5164 \end_inset 
5165
5166
5167 \series default 
5168  Assert the answer answer for question, in case it is tested with a preprocessor
5169  conditional such as `#if #question(answer)'.
5170  `-A-' disables the standard assertions that normally describe the target
5171  machine.
5172 \layout List
5173 \labelwidthstring 00.00.0000
5174
5175
5176 \series bold 
5177 -Umacro
5178 \begin_inset LatexCommand \index{-Umacro}
5179
5180 \end_inset 
5181
5182
5183 \series default 
5184  Undefine macro macro.
5185  `-U' options are evaluated after all `-D' options, but before any `-include'
5186  and `-imacros' options.
5187 \layout List
5188 \labelwidthstring 00.00.0000
5189
5190
5191 \series bold 
5192 -dM
5193 \begin_inset LatexCommand \index{-dM}
5194
5195 \end_inset 
5196
5197
5198 \series default 
5199  Tell the preprocessor to output only a list of the macro definitions that
5200  are in effect at the end of preprocessing.
5201  Used with the `-E' option.
5202 \layout List
5203 \labelwidthstring 00.00.0000
5204
5205
5206 \series bold 
5207 -dD
5208 \begin_inset LatexCommand \index{-dD}
5209
5210 \end_inset 
5211
5212
5213 \series default 
5214  Tell the preprocessor to pass all macro definitions into the output, in
5215  their proper sequence in the rest of the output.
5216 \layout List
5217 \labelwidthstring 00.00.0000
5218
5219
5220 \series bold 
5221 -dN
5222 \begin_inset LatexCommand \index{-dN}
5223
5224 \end_inset 
5225
5226
5227 \size large 
5228 \bar under 
5229  
5230 \series default 
5231 \size default 
5232 \bar default 
5233 Like `-dD' except that the macro arguments and contents are omitted.
5234  Only `#define name' is included in the output.
5235 \layout List
5236 \labelwidthstring 00.00.0000
5237
5238
5239 \series bold 
5240 -Wp\SpecialChar ~
5241 preprocessorOption[,preprocessorOption]
5242 \series default 
5243
5244 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
5245
5246 \end_inset 
5247
5248 ...
5249  Pass the preprocessorOption to the preprocessor 
5250 \family typewriter 
5251 sdcpp
5252 \family default 
5253
5254 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5255
5256 \end_inset 
5257
5258 .
5259  SDCC uses an adapted version of the preprocessor cpp of the GNU Compiler
5260  Collection (gcc), if you need more dedicated options please refer to the
5261  documentation at 
5262 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
5263
5264 \end_inset 
5265
5266 .
5267 \layout Subsection
5268
5269 Linker Options
5270 \begin_inset LatexCommand \index{Options linker}
5271
5272 \end_inset 
5273
5274
5275 \begin_inset LatexCommand \index{Linker options}
5276
5277 \end_inset 
5278
5279
5280 \layout List
5281 \labelwidthstring 00.00.0000
5282
5283
5284 \series bold 
5285 -L\SpecialChar ~
5286 -
5287 \series default 
5288
5289 \begin_inset ERT
5290 status Collapsed
5291
5292 \layout Standard
5293
5294 \backslash 
5295 /
5296 \end_inset 
5297
5298
5299 \series bold 
5300 -lib-path
5301 \begin_inset LatexCommand \index{-\/-lib-path <path>}
5302
5303 \end_inset 
5304
5305
5306 \begin_inset LatexCommand \index{-L -\/-lib-path}
5307
5308 \end_inset 
5309
5310
5311 \series default 
5312 \SpecialChar ~
5313 <absolute path to additional libraries> This option is passed to the linkage
5314  editor's additional libraries
5315 \begin_inset LatexCommand \index{Libraries}
5316
5317 \end_inset 
5318
5319  search path.
5320  The path name must be absolute.
5321  Additional library files may be specified in the command line.
5322  See section Compiling programs for more details.
5323 \layout List
5324 \labelwidthstring 00.00.0000
5325
5326
5327 \series bold 
5328 -
5329 \begin_inset ERT
5330 status Collapsed
5331
5332 \layout Standard
5333
5334 \backslash 
5335 /
5336 \end_inset 
5337
5338 -xram-loc
5339 \series default 
5340
5341 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
5342
5343 \end_inset 
5344
5345 \SpecialChar ~
5346 <Value> The start location of the external ram
5347 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
5348
5349 \end_inset 
5350
5351 , default value is 0.
5352  The value entered can be in Hexadecimal or Decimal format, e.g.: -
5353 \begin_inset ERT
5354 status Collapsed
5355
5356 \layout Standard
5357
5358 \backslash 
5359 /
5360 \end_inset 
5361
5362 -xram-loc 0x8000 or -
5363 \begin_inset ERT
5364 status Collapsed
5365
5366 \layout Standard
5367
5368 \backslash 
5369 /
5370 \end_inset 
5371
5372 -xram-loc 32768.
5373 \layout List
5374 \labelwidthstring 00.00.0000
5375
5376
5377 \series bold 
5378 -
5379 \begin_inset ERT
5380 status Collapsed
5381
5382 \layout Standard
5383
5384 \backslash 
5385 /
5386 \end_inset 
5387
5388 -code-loc
5389 \series default 
5390
5391 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
5392
5393 \end_inset 
5394
5395 \SpecialChar ~
5396 <Value> The start location of the code
5397 \begin_inset LatexCommand \index{code}
5398
5399 \end_inset 
5400
5401  segment, default value 0.
5402  Note when this option is used the interrupt vector table is also relocated
5403  to the given address.
5404  The value entered can be in Hexadecimal or Decimal format, e.g.: -
5405 \begin_inset ERT
5406 status Collapsed
5407
5408 \layout Standard
5409
5410 \backslash 
5411 /
5412 \end_inset 
5413
5414 -code-loc 0x8000 or -
5415 \begin_inset ERT
5416 status Collapsed
5417
5418 \layout Standard
5419
5420 \backslash 
5421 /
5422 \end_inset 
5423
5424 -code-loc 32768.
5425 \layout List
5426 \labelwidthstring 00.00.0000
5427
5428
5429 \series bold 
5430 -
5431 \begin_inset ERT
5432 status Collapsed
5433
5434 \layout Standard
5435
5436 \backslash 
5437 /
5438 \end_inset 
5439
5440 -stack-loc
5441 \series default 
5442
5443 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
5444
5445 \end_inset 
5446
5447 \SpecialChar ~
5448 <Value> By default the stack
5449 \begin_inset LatexCommand \index{stack}
5450
5451 \end_inset 
5452
5453  is placed after the data segment.
5454  Using this option the stack can be placed anywhere in the internal memory
5455  space of the 8051.
5456  The value entered can be in Hexadecimal or Decimal format, e.g.
5457  -
5458 \begin_inset ERT
5459 status Collapsed
5460
5461 \layout Standard
5462
5463 \backslash 
5464 /
5465 \end_inset 
5466
5467 -stack-loc 0x20 or -
5468 \begin_inset ERT
5469 status Collapsed
5470
5471 \layout Standard
5472
5473 \backslash 
5474 /
5475 \end_inset 
5476
5477 -stack-loc 32.
5478  Since the sp register is incremented before a push or call, the initial
5479  sp will be set to one byte prior the provided value.
5480  The provided value should not overlap any other memory areas such as used
5481  register banks or the data segment and with enough space for the current
5482  application.
5483 \layout List
5484 \labelwidthstring 00.00.0000
5485
5486
5487 \series bold 
5488 -
5489 \begin_inset ERT
5490 status Collapsed
5491
5492 \layout Standard
5493
5494 \backslash 
5495 /
5496 \end_inset 
5497
5498 -data-loc
5499 \series default 
5500
5501 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
5502
5503 \end_inset 
5504
5505 \SpecialChar ~
5506 <Value> The start location of the internal ram data
5507 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
5508
5509 \end_inset 
5510
5511  segment.
5512  The value entered can be in Hexadecimal or Decimal format, eg.
5513  -
5514 \begin_inset ERT
5515 status Collapsed
5516
5517 \layout Standard
5518
5519 \backslash 
5520 /
5521 \end_inset 
5522
5523 -data-loc 0x20 or -
5524 \begin_inset ERT
5525 status Collapsed
5526
5527 \layout Standard
5528
5529 \backslash 
5530 /
5531 \end_inset 
5532
5533 -data-loc 32.
5534  (By default, the start location of the internal ram data segment  is set
5535  as low as possible in memory, taking into account the used register banks
5536  and the bit segment at address 0x20.
5537  For example if register banks 0 and 1 are used without bit variables, the
5538  data segment will be set, if -
5539 \begin_inset ERT
5540 status Collapsed
5541
5542 \layout Standard
5543
5544 \backslash 
5545 /
5546 \end_inset 
5547
5548 -data-loc is not used, to location 0x10.)
5549 \layout List
5550 \labelwidthstring 00.00.0000
5551
5552
5553 \series bold 
5554 -
5555 \begin_inset ERT
5556 status Collapsed
5557
5558 \layout Standard
5559
5560 \backslash 
5561 /
5562 \end_inset 
5563
5564 -idata-loc
5565 \series default 
5566
5567 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
5568
5569 \end_inset 
5570
5571 \SpecialChar ~
5572 <Value> The start location of the indirectly addressable internal ram
5573 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
5574
5575 \end_inset 
5576
5577  of the 8051, default value is 0x80.
5578  The value entered can be in Hexadecimal or Decimal format, eg.
5579  -
5580 \begin_inset ERT
5581 status Collapsed
5582
5583 \layout Standard
5584
5585 \backslash 
5586 /
5587 \end_inset 
5588
5589 -idata-loc 0x88 or -
5590 \begin_inset ERT
5591 status Collapsed
5592
5593 \layout Standard
5594
5595 \backslash 
5596 /
5597 \end_inset 
5598
5599 -idata-loc 136.
5600 \layout List
5601 \labelwidthstring 00.00.0000
5602
5603
5604 \series bold 
5605 -
5606 \begin_inset ERT
5607 status Collapsed
5608
5609 \layout Standard
5610
5611 \backslash 
5612 /
5613 \end_inset 
5614
5615 -bit-loc
5616 \series default 
5617 \SpecialChar ~
5618 <Value> The start location of the bit
5619 \begin_inset LatexCommand \index{bit}
5620
5621 \end_inset 
5622
5623  addressable internal ram of the 8051.
5624  This is 
5625 \emph on 
5626 not
5627 \emph default 
5628  implemented yet.
5629  Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
5630 -bBSEG=<Value>.
5631 \layout List
5632 \labelwidthstring 00.00.0000
5633
5634
5635 \series bold 
5636 -
5637 \begin_inset ERT
5638 status Collapsed
5639
5640 \layout Standard
5641
5642 \backslash 
5643 /
5644 \end_inset 
5645
5646 -out-fmt-ihx
5647 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
5648
5649 \end_inset 
5650
5651
5652 \bar under 
5653  
5654 \series default 
5655 \bar default 
5656 The linker output (final object code) is in Intel Hex format.
5657 \begin_inset LatexCommand \index{Intel hex format}
5658
5659 \end_inset 
5660
5661  This is the default option.
5662  The format itself is documented in the documentation of srecord
5663 \begin_inset LatexCommand \index{srecord (tool)}
5664
5665 \end_inset 
5666
5667 .
5668 \layout List
5669 \labelwidthstring 00.00.0000
5670
5671
5672 \series bold 
5673 -
5674 \begin_inset ERT
5675 status Collapsed
5676
5677 \layout Standard
5678
5679 \backslash 
5680 /
5681 \end_inset 
5682
5683 -out-fmt-s19
5684 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5685
5686 \end_inset 
5687
5688
5689 \bar under 
5690  
5691 \series default 
5692 \bar default 
5693 The linker output (final object code) is in Motorola S19 format
5694 \begin_inset LatexCommand \index{Motorola S19 format}
5695
5696 \end_inset 
5697
5698 .
5699  The format itself is documented in the documentation of srecord.
5700 \layout List
5701 \labelwidthstring 00.00.0000
5702
5703
5704 \series bold 
5705 -Wl\SpecialChar ~
5706 linkOption[,linkOption]
5707 \series default 
5708
5709 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
5710
5711 \end_inset 
5712
5713 ...
5714  Pass the linkOption to the linker.
5715  See file sdcc/as/doc/asxhtm.html for more on linker options.
5716 \layout Subsection
5717
5718 MCS51 Options
5719 \begin_inset LatexCommand \index{Options MCS51}
5720
5721 \end_inset 
5722
5723
5724 \begin_inset LatexCommand \index{MCS51 options}
5725
5726 \end_inset 
5727
5728
5729 \layout List
5730 \labelwidthstring 00.00.0000
5731
5732
5733 \series bold 
5734 -
5735 \begin_inset ERT
5736 status Collapsed
5737
5738 \layout Standard
5739
5740 \backslash 
5741 /
5742 \end_inset 
5743
5744 -model-small
5745 \begin_inset LatexCommand \index{-\/-model-small}
5746
5747 \end_inset 
5748
5749
5750 \series default 
5751 \size large 
5752 \emph on 
5753  
5754 \size default 
5755 \emph default 
5756 Generate code for Small Model programs, see section Memory Models for more
5757  details.
5758  This is the default model.
5759 \layout List
5760 \labelwidthstring 00.00.0000
5761
5762
5763 \series bold 
5764 -
5765 \begin_inset ERT
5766 status Collapsed
5767
5768 \layout Standard
5769
5770 \backslash 
5771 /
5772 \end_inset 
5773
5774 -model-large
5775 \begin_inset LatexCommand \index{-\/-model-large}
5776
5777 \end_inset 
5778
5779
5780 \series default 
5781  Generate code for Large model programs, see section Memory Models for more
5782  details.
5783  If this option is used all source files in the project have to be compiled
5784  with this option.
5785 \layout List
5786 \labelwidthstring 00.00.0000
5787
5788
5789 \series bold 
5790 -
5791 \begin_inset ERT
5792 status Collapsed
5793
5794 \layout Standard
5795
5796 \backslash 
5797 /
5798 \end_inset 
5799
5800 -xstack
5801 \begin_inset LatexCommand \index{-\/-xstack}
5802
5803 \end_inset 
5804
5805
5806 \series default 
5807  Uses a pseudo stack in the first 256 bytes in the external ram for allocating
5808  variables and passing parameters.
5809  See section 
5810 \begin_inset LatexCommand \ref{sub:External-Stack}
5811
5812 \end_inset 
5813
5814 \SpecialChar ~
5815  External Stack for more details.
5816 \layout List
5817 \labelwidthstring 00.00.0000
5818
5819
5820 \series bold 
5821 -
5822 \begin_inset ERT
5823 status Collapsed
5824
5825 \layout Standard
5826
5827 \backslash 
5828 /
5829 \end_inset 
5830
5831 -iram-size
5832 \series default 
5833 \SpecialChar ~
5834 <Value>
5835 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
5836
5837 \end_inset 
5838
5839  Causes the linker to check if the internal ram usage is within limits of
5840  the given value.
5841 \layout List
5842 \labelwidthstring 00.00.0000
5843
5844
5845 \series bold 
5846 -
5847 \begin_inset ERT
5848 status Collapsed
5849
5850 \layout Standard
5851
5852 \backslash 
5853 /
5854 \end_inset 
5855
5856 -xram-size
5857 \series default 
5858 \SpecialChar ~
5859 <Value>
5860 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
5861
5862 \end_inset 
5863
5864  Causes the linker to check if the external ram usage is within limits of
5865  the given value.
5866 \layout List
5867 \labelwidthstring 00.00.0000
5868
5869
5870 \series bold 
5871 -
5872 \begin_inset ERT
5873 status Collapsed
5874
5875 \layout Standard
5876
5877 \backslash 
5878 /
5879 \end_inset 
5880
5881 -code-size
5882 \series default 
5883 \SpecialChar ~
5884 <Value>
5885 \begin_inset LatexCommand \index{-\/-code-size <Value>}
5886
5887 \end_inset 
5888
5889  Causes the linker to check if the code memory usage is within limits of
5890  the given value.
5891 \layout Subsection
5892
5893 DS390 / DS400 Options
5894 \begin_inset LatexCommand \index{Options DS390}
5895
5896 \end_inset 
5897
5898
5899 \begin_inset LatexCommand \index{DS390 options}
5900
5901 \end_inset 
5902
5903
5904 \layout List
5905 \labelwidthstring 00.00.0000
5906
5907
5908 \series bold 
5909 -
5910 \begin_inset ERT
5911 status Collapsed
5912
5913 \layout Standard
5914
5915 \backslash 
5916 /
5917 \end_inset 
5918
5919 -model-flat24
5920 \series default 
5921
5922 \begin_inset LatexCommand \index{-\/-model-flat24}
5923
5924 \end_inset 
5925
5926
5927 \size large 
5928 \emph on 
5929  
5930 \size default 
5931 \emph default 
5932 Generate 24-bit flat mode code.
5933  This is the one and only that the ds390 code generator supports right now
5934  and is default when using 
5935 \emph on 
5936 -mds390
5937 \emph default 
5938 .
5939  See section Memory Models for more details.
5940 \layout List
5941 \labelwidthstring 00.00.0000
5942
5943
5944 \series bold 
5945 -
5946 \begin_inset ERT
5947 status Collapsed
5948
5949 \layout Standard
5950
5951 \backslash 
5952 /
5953 \end_inset 
5954
5955 -protect-sp-update
5956 \begin_inset LatexCommand \index{-\/-protect-sp-update}
5957
5958 \end_inset 
5959
5960
5961 \series default 
5962  disable interrupts during ESP:SP updates.
5963 \layout List
5964 \labelwidthstring 00.00.0000
5965
5966
5967 \series bold 
5968 -
5969 \begin_inset ERT
5970 status Collapsed
5971
5972 \layout Standard
5973
5974 \backslash 
5975 /
5976 \end_inset 
5977
5978 -stack-10bit
5979 \series default 
5980
5981 \begin_inset LatexCommand \index{-\/-stack-10bit}
5982
5983 \end_inset 
5984
5985  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
5986  This is the one and only that the ds390 code generator supports right now
5987  and is default when using 
5988 \emph on 
5989 -mds390
5990 \emph default 
5991 .
5992  In this mode, the stack is located in the lower 1K of the internal RAM,
5993  which is mapped to 0x400000.
5994  Note that the support is incomplete, since it still uses a single byte
5995  as the stack pointer.
5996  This means that only the lower 256 bytes of the potential 1K stack space
5997  will actually be used.
5998  However, this does allow you to reclaim the precious 256 bytes of low RAM
5999  for use for the DATA and IDATA segments.
6000  The compiler will not generate any code to put the processor into 10 bit
6001  stack mode.
6002  It is important to ensure that the processor is in this mode before calling
6003  any re-entrant functions compiled with this option.
6004  In principle, this should work with the 
6005 \emph on 
6006 -
6007 \begin_inset ERT
6008 status Collapsed
6009
6010 \layout Standard
6011
6012 \backslash 
6013 /
6014 \end_inset 
6015
6016 -stack-auto
6017 \begin_inset LatexCommand \index{-\/-stack-auto}
6018
6019 \end_inset 
6020
6021
6022 \emph default 
6023  option, but that has not been tested.
6024  It is incompatible with the 
6025 \emph on 
6026 -
6027 \begin_inset ERT
6028 status Collapsed
6029
6030 \layout Standard
6031
6032 \backslash 
6033 /
6034 \end_inset 
6035
6036 -xstack
6037 \begin_inset LatexCommand \index{-\/-xstack}
6038
6039 \end_inset 
6040
6041
6042 \emph default 
6043  option.
6044  It also only makes sense if the processor is in 24 bit contiguous addressing
6045  mode (see the 
6046 \emph on 
6047 -
6048 \begin_inset ERT
6049 status Collapsed
6050
6051 \layout Standard
6052
6053 \backslash 
6054 /
6055 \end_inset 
6056
6057 -model-flat24 option
6058 \emph default 
6059 ).
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 -stack-probe
6076 \begin_inset LatexCommand \index{-\/-stack-probe}
6077
6078 \end_inset 
6079
6080
6081 \series default 
6082  insert call to function __stack_probe at each function prologue.
6083 \layout List
6084 \labelwidthstring 00.00.0000
6085
6086
6087 \series bold 
6088 -
6089 \begin_inset ERT
6090 status Collapsed
6091
6092 \layout Standard
6093
6094 \backslash 
6095 /
6096 \end_inset 
6097
6098 -tini-libid
6099 \begin_inset LatexCommand \index{-\/-tini-libid}
6100
6101 \end_inset 
6102
6103
6104 \series default 
6105  <nnnn> LibraryID used in -mTININative.
6106  
6107 \layout List
6108 \labelwidthstring 00.00.0000
6109
6110
6111 \series bold 
6112 -
6113 \begin_inset ERT
6114 status Collapsed
6115
6116 \layout Standard
6117
6118 \backslash 
6119 /
6120 \end_inset 
6121
6122 -use-accelerator
6123 \begin_inset LatexCommand \index{-\/-use-accelerator}
6124
6125 \end_inset 
6126
6127
6128 \series default 
6129  generate code for DS390 Arithmetic Accelerator.
6130  
6131 \layout Subsection
6132
6133 PIC Options
6134 \begin_inset LatexCommand \index{Options PIC}
6135
6136 \end_inset 
6137
6138
6139 \begin_inset LatexCommand \index{PIC options}
6140
6141 \end_inset 
6142
6143
6144 \layout List
6145 \labelwidthstring 00.00.0000
6146
6147
6148 \series bold 
6149 -
6150 \begin_inset ERT
6151 status Collapsed
6152
6153 \layout Standard
6154
6155 \backslash 
6156 /
6157 \end_inset 
6158
6159 -gen-banksel
6160 \begin_inset LatexCommand \index{-\/-gen-banksel}
6161
6162 \end_inset 
6163
6164
6165 \series default 
6166  enable the generation of banksel assembler directives in the PIC16
6167 \begin_inset LatexCommand \index{PIC16}
6168
6169 \end_inset 
6170
6171  port.
6172 \layout Subsection
6173
6174 Z80 Options
6175 \begin_inset LatexCommand \index{Options Z80}
6176
6177 \end_inset 
6178
6179
6180 \begin_inset LatexCommand \index{Z80 options}
6181
6182 \end_inset 
6183
6184
6185 \layout List
6186 \labelwidthstring 00.00.0000
6187
6188
6189 \series bold 
6190 -
6191 \begin_inset ERT
6192 status Collapsed
6193
6194 \layout Standard
6195
6196 \backslash 
6197 /
6198 \end_inset 
6199
6200 -callee-saves-bc
6201 \series default 
6202
6203 \begin_inset LatexCommand \index{-\/-callee-saves-bc}
6204
6205 \end_inset 
6206
6207
6208 \size large 
6209 \emph on 
6210  
6211 \size default 
6212 \emph default 
6213 Force a called function to always save BC.
6214 \layout List
6215 \labelwidthstring 00.00.0000
6216
6217
6218 \series bold 
6219 -
6220 \begin_inset ERT
6221 status Collapsed
6222
6223 \layout Standard
6224
6225 \backslash 
6226 /
6227 \end_inset 
6228
6229 -no-std-crt0
6230 \series default 
6231
6232 \begin_inset LatexCommand \index{-\/-no-std-crt0}
6233
6234 \end_inset 
6235
6236  When linking, skip the standard crt0.o object file.
6237  You must provide your own crt0.o for your system when linking.
6238  
6239 \layout Subsection
6240
6241 Optimization Options
6242 \begin_inset LatexCommand \index{Options optimization}
6243
6244 \end_inset 
6245
6246
6247 \begin_inset LatexCommand \index{Optimization options}
6248
6249 \end_inset 
6250
6251
6252 \layout List
6253 \labelwidthstring 00.00.0000
6254
6255
6256 \series bold 
6257 -
6258 \begin_inset ERT
6259 status Collapsed
6260
6261 \layout Standard
6262
6263 \backslash 
6264 /
6265 \end_inset 
6266
6267 -nogcse
6268 \begin_inset LatexCommand \index{-\/-nogcse}
6269
6270 \end_inset 
6271
6272
6273 \series default 
6274  Will not do global subexpression elimination, this option may be used when
6275  the compiler creates undesirably large stack/data spaces to store compiler
6276  temporaries.
6277  A warning message will be generated when this happens and the compiler
6278  will indicate the number of extra bytes it allocated.
6279  It is recommended that this option NOT be used, #pragma\SpecialChar ~
6280 nogcse
6281 \begin_inset LatexCommand \index{\#pragma nogcse}
6282
6283 \end_inset 
6284
6285  can be used to turn off global subexpression elimination
6286 \begin_inset LatexCommand \index{Subexpression elimination}
6287
6288 \end_inset 
6289
6290  for a given function only.
6291 \layout List
6292 \labelwidthstring 00.00.0000
6293
6294
6295 \series bold 
6296 -
6297 \begin_inset ERT
6298 status Collapsed
6299
6300 \layout Standard
6301
6302 \backslash 
6303 /
6304 \end_inset 
6305
6306 -noinvariant
6307 \begin_inset LatexCommand \index{-\/-noinvariant}
6308
6309 \end_inset 
6310
6311
6312 \series default 
6313  Will not do loop invariant optimizations, this may be turned off for reasons
6314  explained for the previous option.
6315  For more details of loop optimizations performed see section Loop Invariants.
6316  It is recommended that this option NOT be used, #pragma\SpecialChar ~
6317 noinvariant
6318 \begin_inset LatexCommand \index{\#pragma noinvariant}
6319
6320 \end_inset 
6321
6322  can be used to turn off invariant optimizations for a given function only.
6323 \layout List
6324 \labelwidthstring 00.00.0000
6325
6326
6327 \series bold 
6328 -
6329 \begin_inset ERT
6330 status Collapsed
6331
6332 \layout Standard
6333
6334 \backslash 
6335 /
6336 \end_inset 
6337
6338 -noinduction
6339 \begin_inset LatexCommand \index{-\/-noinduction}
6340
6341 \end_inset 
6342
6343
6344 \series default 
6345  Will not do loop induction optimizations, see section strength reduction
6346  for more details.
6347  It is recommended that this option is NOT used, #pragma\SpecialChar ~
6348 noinduction
6349 \begin_inset LatexCommand \index{\#pragma noinduction}
6350
6351 \end_inset 
6352
6353  can be used to turn off induction optimizations for a given function only.
6354 \layout List
6355 \labelwidthstring 00.00.0000
6356
6357
6358 \series bold 
6359 -
6360 \begin_inset ERT
6361 status Collapsed
6362
6363 \layout Standard
6364
6365 \backslash 
6366 /
6367 \end_inset 
6368
6369 -nojtbound
6370 \begin_inset LatexCommand \index{-\/-nojtbound}
6371
6372 \end_inset 
6373
6374
6375 \size large 
6376 \bar under 
6377  
6378 \series default 
6379 \size default 
6380 \bar default 
6381  Will not generate boundary condition check when switch statements
6382 \begin_inset LatexCommand \index{switch statement}
6383
6384 \end_inset 
6385
6386  are implemented using jump-tables.
6387  See section 
6388 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
6389
6390 \end_inset 
6391
6392 \SpecialChar ~
6393 Switch Statements for more details.
6394  It is recommended that this option is NOT used, #pragma\SpecialChar ~
6395 nojtbound
6396 \begin_inset LatexCommand \index{\#pragma nojtbound}
6397
6398 \end_inset 
6399
6400  can be used to turn off boundary checking for jump tables for a given function
6401  only.
6402 \layout List
6403 \labelwidthstring 00.00.0000
6404
6405
6406 \series bold 
6407 -
6408 \begin_inset ERT
6409 status Collapsed
6410
6411 \layout Standard
6412
6413 \backslash 
6414 /
6415 \end_inset 
6416
6417 -noloopreverse
6418 \begin_inset LatexCommand \index{-\/-noloopreverse}
6419
6420 \end_inset 
6421
6422
6423 \series default 
6424 \size large 
6425  
6426 \size default 
6427 Will not do loop reversal 
6428 \begin_inset LatexCommand \index{Loop reversing}
6429
6430 \end_inset 
6431
6432 optimization.
6433 \layout List
6434 \labelwidthstring 00.00.0000
6435
6436 -
6437 \begin_inset ERT
6438 status Collapsed
6439
6440 \layout Standard
6441
6442 \backslash 
6443 /
6444 \end_inset 
6445
6446 -
6447 \series bold 
6448 nolabelopt
6449 \series default 
6450  
6451 \begin_inset LatexCommand \index{-\/-nolabelopt }
6452
6453 \end_inset 
6454
6455 Will not optimize labels (makes the dumpfiles more readable).
6456 \layout List
6457 \labelwidthstring 00.00.0000
6458
6459
6460 \series bold 
6461 -
6462 \begin_inset ERT
6463 status Collapsed
6464
6465 \layout Standard
6466
6467 \backslash 
6468 /
6469 \end_inset 
6470
6471 -no-xinit-opt
6472 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
6473
6474 \end_inset 
6475
6476
6477 \series default 
6478  Will not memcpy initialized data from code space into xdata space.
6479  This saves a few bytes in code space if you don't have initialized data.
6480 \layout List
6481 \labelwidthstring 00.00.0000
6482
6483
6484 \series bold 
6485 -
6486 \begin_inset ERT
6487 status Collapsed
6488
6489 \layout Standard
6490
6491 \backslash 
6492 /
6493 \end_inset 
6494
6495 -nooverlay
6496 \begin_inset LatexCommand \index{-\/-nooverlay}
6497
6498 \end_inset 
6499
6500
6501 \series default 
6502   The compiler will not overlay parameters and local variables of any function,
6503  see section Parameters and local variables for more details.
6504 \layout List
6505 \labelwidthstring 00.00.0000
6506
6507
6508 \series bold 
6509 -
6510 \begin_inset ERT
6511 status Collapsed
6512
6513 \layout Standard
6514
6515 \backslash 
6516 /
6517 \end_inset 
6518
6519 -no-peep
6520 \begin_inset LatexCommand \index{-\/-no-peep}
6521
6522 \end_inset 
6523
6524
6525 \series default 
6526  Disable peep-hole optimization.
6527 \layout List
6528 \labelwidthstring 00.00.0000
6529
6530
6531 \series bold 
6532 -
6533 \begin_inset ERT
6534 status Collapsed
6535
6536 \layout Standard
6537
6538 \backslash 
6539 /
6540 \end_inset 
6541
6542 -peep-file
6543 \series default 
6544
6545 \begin_inset LatexCommand \index{-\/-peep-file}
6546
6547 \end_inset 
6548
6549 \SpecialChar ~
6550 <filename> This option can be used to use additional rules to be used by
6551  the peep hole optimizer.
6552  See section 
6553 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
6554
6555 \end_inset 
6556
6557 \SpecialChar ~
6558 Peep Hole optimizations for details on how to write these rules.
6559 \layout List
6560 \labelwidthstring 00.00.0000
6561
6562
6563 \series bold 
6564 -
6565 \begin_inset ERT
6566 status Collapsed
6567
6568 \layout Standard
6569
6570 \backslash 
6571 /
6572 \end_inset 
6573
6574 -peep-asm
6575 \begin_inset LatexCommand \index{-\/-peep-asm}
6576
6577 \end_inset 
6578
6579
6580 \series default 
6581   Pass the inline assembler code through the peep hole optimizer.
6582  This can cause unexpected changes to inline assembler code, please go through
6583  the peephole optimizer
6584 \begin_inset LatexCommand \index{Peephole optimizer}
6585
6586 \end_inset 
6587
6588  rules defined in the source file tree '<target>/peeph.def' before using
6589  this option.
6590 \layout Subsection
6591
6592 Other Options
6593 \begin_inset LatexCommand \index{Options other}
6594
6595 \end_inset 
6596
6597
6598 \layout List
6599 \labelwidthstring 00.00.0000
6600
6601
6602 \series bold 
6603 -c\SpecialChar ~
6604 -
6605 \begin_inset ERT
6606 status Collapsed
6607
6608 \layout Standard
6609
6610 \backslash 
6611 /
6612 \end_inset 
6613
6614 -compile-only
6615 \begin_inset LatexCommand \index{-\/-compile-only}
6616
6617 \end_inset 
6618
6619
6620 \begin_inset LatexCommand \index{-c -\/-compile-only}
6621
6622 \end_inset 
6623
6624
6625 \series default 
6626  will compile and assemble the source, but will not call the linkage editor.
6627 \layout List
6628 \labelwidthstring 00.00.0000
6629
6630
6631 \series bold 
6632 -
6633 \series default 
6634
6635 \begin_inset ERT
6636 status Collapsed
6637
6638 \layout Standard
6639
6640 \backslash 
6641 /
6642 \end_inset 
6643
6644
6645 \series bold 
6646 -c1mode
6647 \begin_inset LatexCommand \index{-\/-c1mode}
6648
6649 \end_inset 
6650
6651
6652 \series default 
6653  reads the preprocessed source from standard input and compiles it.
6654  The file name for the assembler output must be specified using the -o option.
6655 \layout List
6656 \labelwidthstring 00.00.0000
6657
6658
6659 \series bold 
6660 -E
6661 \begin_inset LatexCommand \index{-E}
6662
6663 \end_inset 
6664
6665
6666 \series default 
6667  Run only the C preprocessor.
6668  Preprocess all the C source files specified and output the results to standard
6669  output.
6670 \layout List
6671 \labelwidthstring 00.00.0000
6672
6673
6674 \series bold 
6675 -o\SpecialChar ~
6676 <path/file>
6677 \begin_inset LatexCommand \index{-o <path/file>}
6678
6679 \end_inset 
6680
6681  
6682 \series default 
6683 The output path resp.
6684  file where everything will be placed.
6685  If the parameter is a path, it must have a trailing slash (or backslash
6686  for the Windows binaries) to be recognized as a path.
6687  
6688 \layout List
6689 \labelwidthstring 00.00.0000
6690
6691
6692 \series bold 
6693 -
6694 \begin_inset ERT
6695 status Collapsed
6696
6697 \layout Standard
6698
6699 \backslash 
6700 /
6701 \end_inset 
6702
6703 -stack-auto
6704 \begin_inset LatexCommand \index{-\/-stack-auto}
6705
6706 \end_inset 
6707
6708
6709 \series default 
6710 \size large 
6711 \emph on 
6712  
6713 \size default 
6714 \emph default 
6715 All functions in the source file will be compiled as 
6716 \emph on 
6717 reentrant
6718 \emph default 
6719
6720 \begin_inset LatexCommand \index{reentrant}
6721
6722 \end_inset 
6723
6724 , i.e.
6725  the parameters and local variables will be allocated on the stack
6726 \begin_inset LatexCommand \index{stack}
6727
6728 \end_inset 
6729
6730 .
6731  see section Parameters and Local Variables for more details.
6732  If this option is used all source files in the project should be compiled
6733  with this option.
6734  
6735 \layout List
6736 \labelwidthstring 00.00.0000
6737
6738
6739 \series bold 
6740 -
6741 \begin_inset ERT
6742 status Collapsed
6743
6744 \layout Standard
6745
6746 \backslash 
6747 /
6748 \end_inset 
6749
6750 -callee-saves
6751 \begin_inset LatexCommand \index{-\/-callee-saves}
6752
6753 \end_inset 
6754
6755  function1[,function2][,function3]....
6756
6757 \series default 
6758  The compiler by default uses a caller saves convention for register saving
6759  across function calls, however this can cause unnecessary register pushing
6760  & popping when calling small functions from larger functions.
6761  This option can be used to switch the register saving convention for the
6762  function names specified.
6763  The compiler will not save registers when calling these functions, no extra
6764  code will be generated at the entry & exit (function prologue
6765 \series bold 
6766
6767 \begin_inset LatexCommand \index{function prologue}
6768
6769 \end_inset 
6770
6771
6772 \series default 
6773  & epilogue
6774 \series bold 
6775
6776 \begin_inset LatexCommand \index{function epilogue}
6777
6778 \end_inset 
6779
6780
6781 \series default 
6782 ) for these functions to save & restore the registers used by these functions,
6783  this can SUBSTANTIALLY reduce code & improve run time performance of the
6784  generated code.
6785  In the future the compiler (with inter procedural analysis) will be able
6786  to determine the appropriate scheme to use for each function call.
6787  DO NOT use this option for built-in functions such as _mulint..., if this
6788  option is used for a library function the appropriate library function
6789  needs to be recompiled with the same option.
6790  If the project consists of multiple source files then all the source file
6791  should be compiled with the same -
6792 \begin_inset ERT
6793 status Collapsed
6794
6795 \layout Standard
6796
6797 \backslash 
6798 /
6799 \end_inset 
6800
6801 -callee-saves option string.
6802  Also see #pragma\SpecialChar ~
6803 callee_saves
6804 \begin_inset LatexCommand \index{\#pragma callee\_saves}
6805
6806 \end_inset 
6807
6808 .
6809 \layout List
6810 \labelwidthstring 00.00.0000
6811
6812
6813 \series bold 
6814 -
6815 \begin_inset ERT
6816 status Collapsed
6817
6818 \layout Standard
6819
6820 \backslash 
6821 /
6822 \end_inset 
6823
6824 -debug
6825 \begin_inset LatexCommand \index{-\/-debug}
6826
6827 \end_inset 
6828
6829
6830 \bar under 
6831  
6832 \series default 
6833 \bar default 
6834 When this option is used the compiler will generate debug information.
6835  The debug information collected in a file with .cdb extension can be used
6836  with the SDCDB.
6837  For more information see documentation for SDCDB.
6838  Another file with no extension contains debug information in AOMF or AOMF51
6839 \begin_inset LatexCommand \index{AOMF, AOMF51}
6840
6841 \end_inset 
6842
6843  format which is commonly used by third party tools.
6844 \layout List
6845 \labelwidthstring 00.00.0000
6846
6847
6848 \series bold 
6849 -S
6850 \begin_inset LatexCommand \index{-S}
6851
6852 \end_inset 
6853
6854
6855 \size large 
6856 \bar under 
6857  
6858 \series default 
6859 \size default 
6860 \bar default 
6861 Stop after the stage of compilation proper; do not assemble.
6862  The output is an assembler code file for the input file specified.
6863 \layout List
6864 \labelwidthstring 00.00.0000
6865
6866
6867 \series bold 
6868 -
6869 \begin_inset ERT
6870 status Collapsed
6871
6872 \layout Standard
6873
6874 \backslash 
6875 /
6876 \end_inset 
6877
6878 -int-long-reent
6879 \begin_inset LatexCommand \index{-\/-int-long-reent}
6880
6881 \end_inset 
6882
6883
6884 \series default 
6885  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
6886  Note by default these libraries are compiled as non-reentrant.
6887  See section Installation for more details.
6888 \layout List
6889 \labelwidthstring 00.00.0000
6890
6891
6892 \series bold 
6893 -
6894 \begin_inset ERT
6895 status Collapsed
6896
6897 \layout Standard
6898
6899 \backslash 
6900 /
6901 \end_inset 
6902
6903 -cyclomatic
6904 \begin_inset LatexCommand \index{-\/-cyclomatic}
6905
6906 \end_inset 
6907
6908
6909 \bar under 
6910  
6911 \series default 
6912 \bar default 
6913 This option will cause the compiler to generate an information message for
6914  each function in the source file.
6915  The message contains some 
6916 \emph on 
6917 important
6918 \emph default 
6919  information about the function.
6920  The number of edges and nodes the compiler detected in the control flow
6921  graph of the function, and most importantly the 
6922 \emph on 
6923 cyclomatic complexity
6924 \begin_inset LatexCommand \index{Cyclomatic complexity}
6925
6926 \end_inset 
6927
6928
6929 \emph default 
6930  see section on Cyclomatic Complexity for more details.
6931 \layout List
6932 \labelwidthstring 00.00.0000
6933
6934
6935 \series bold 
6936 -
6937 \begin_inset ERT
6938 status Collapsed
6939
6940 \layout Standard
6941
6942 \backslash 
6943 /
6944 \end_inset 
6945
6946 -float-reent
6947 \begin_inset LatexCommand \index{-\/-float-reent}
6948
6949 \end_inset 
6950
6951
6952 \series default 
6953  Floating point library is compiled as reentrant
6954 \begin_inset LatexCommand \index{reentrant}
6955
6956 \end_inset 
6957
6958 .
6959  See section Installation for more details.
6960 \layout List
6961 \labelwidthstring 00.00.0000
6962
6963
6964 \series bold 
6965 -
6966 \begin_inset ERT
6967 status Collapsed
6968
6969 \layout Standard
6970
6971 \backslash 
6972 /
6973 \end_inset 
6974
6975 -main-return
6976 \begin_inset LatexCommand \index{-\/-main-return}
6977
6978 \end_inset 
6979
6980
6981 \series default 
6982  This option can be used when the code generated is called by a monitor
6983  program.
6984  The compiler will generate a 'ret' upon return from the 'main'
6985 \begin_inset LatexCommand \index{main return}
6986
6987 \end_inset 
6988
6989  function.
6990  The default setting is to lock up i.e.
6991  generate a '
6992 \family typewriter 
6993 sjmp .
6994 \family default 
6995 '.
6996 \layout List
6997 \labelwidthstring 00.00.0000
6998
6999
7000 \series bold 
7001 -
7002 \begin_inset ERT
7003 status Collapsed
7004
7005 \layout Standard
7006
7007 \backslash 
7008 /
7009 \end_inset 
7010
7011 -nostdincl
7012 \begin_inset LatexCommand \index{-\/-nostdincl}
7013
7014 \end_inset 
7015
7016
7017 \series default 
7018  This will prevent the compiler from passing on the default include path
7019  to the preprocessor.
7020 \layout List
7021 \labelwidthstring 00.00.0000
7022
7023
7024 \series bold 
7025 -
7026 \begin_inset ERT
7027 status Collapsed
7028
7029 \layout Standard
7030
7031 \backslash 
7032 /
7033 \end_inset 
7034
7035 -nostdlib
7036 \begin_inset LatexCommand \index{-\/-nostdlib}
7037
7038 \end_inset 
7039
7040
7041 \series default 
7042  This will prevent the compiler from passing on the default library
7043 \begin_inset LatexCommand \index{Libraries}
7044
7045 \end_inset 
7046
7047  path to the linker.
7048 \layout List
7049 \labelwidthstring 00.00.0000
7050
7051
7052 \series bold 
7053 -
7054 \begin_inset ERT
7055 status Collapsed
7056
7057 \layout Standard
7058
7059 \backslash 
7060 /
7061 \end_inset 
7062
7063 -verbose
7064 \begin_inset LatexCommand \index{-\/-verbose}
7065
7066 \end_inset 
7067
7068
7069 \series default 
7070  Shows the various actions the compiler is performing.
7071 \layout List
7072 \labelwidthstring 00.00.0000
7073
7074
7075 \series bold 
7076 -V
7077 \begin_inset LatexCommand \index{-V}
7078
7079 \end_inset 
7080
7081
7082 \series default 
7083  Shows the actual commands the compiler is executing.
7084 \layout List
7085 \labelwidthstring 00.00.0000
7086
7087
7088 \series bold 
7089 -
7090 \begin_inset ERT
7091 status Collapsed
7092
7093 \layout Standard
7094
7095 \backslash 
7096 /
7097 \end_inset 
7098
7099 -no-c-code-in-asm
7100 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
7101
7102 \end_inset 
7103
7104
7105 \series default 
7106  Hides your ugly and inefficient c-code from the asm file, so you can always
7107  blame the compiler :).
7108 \layout List
7109 \labelwidthstring 00.00.0000
7110
7111
7112 \series bold 
7113 -
7114 \begin_inset ERT
7115 status Collapsed
7116
7117 \layout Standard
7118
7119 \backslash 
7120 /
7121 \end_inset 
7122
7123 -i-code-in-asm
7124 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
7125
7126 \end_inset 
7127
7128
7129 \series default 
7130  Include i-codes in the asm file.
7131  Sounds like noise but is most helpful for debugging the compiler itself.
7132 \layout List
7133 \labelwidthstring 00.00.0000
7134
7135
7136 \series bold 
7137 -
7138 \begin_inset ERT
7139 status Collapsed
7140
7141 \layout Standard
7142
7143 \backslash 
7144 /
7145 \end_inset 
7146
7147 -less-pedantic
7148 \begin_inset LatexCommand \index{-\/-less-pedantic}
7149
7150 \end_inset 
7151
7152
7153 \series default 
7154  Disable some of the more pedantic warnings
7155 \begin_inset LatexCommand \index{Warnings}
7156
7157 \end_inset 
7158
7159  (jwk burps: please be more specific here, please!).
7160  If you want rather more than less warnings you should consider using a
7161  separate tool dedicated to syntax checking like splint 
7162 \begin_inset LatexCommand \url{www.splint.org}
7163
7164 \end_inset 
7165
7166 .
7167 \layout List
7168 \labelwidthstring 00.00.0000
7169
7170
7171 \series bold 
7172 -
7173 \begin_inset ERT
7174 status Collapsed
7175
7176 \layout Standard
7177
7178 \backslash 
7179 /
7180 \end_inset 
7181
7182 -print-search-dirs
7183 \begin_inset LatexCommand \index{-\/-print-search-dirs}
7184
7185 \end_inset 
7186
7187
7188 \series default 
7189  Display the directories in the compiler's search path
7190 \layout List
7191 \labelwidthstring 00.00.0000
7192
7193
7194 \series bold 
7195 -
7196 \begin_inset ERT
7197 status Collapsed
7198
7199 \layout Standard
7200
7201 \backslash 
7202 /
7203 \end_inset 
7204
7205 -vc
7206 \begin_inset LatexCommand \index{-\/-vc}
7207
7208 \end_inset 
7209
7210
7211 \series default 
7212  Display errors and warnings using MSVC style, so you can use SDCC with
7213  visual studio.
7214 \layout List
7215 \labelwidthstring 00.00.0000
7216
7217
7218 \series bold 
7219 -
7220 \begin_inset ERT
7221 status Collapsed
7222
7223 \layout Standard
7224
7225 \backslash 
7226 /
7227 \end_inset 
7228
7229 -use-stdout
7230 \begin_inset LatexCommand \index{-\/-use-stdout}
7231
7232 \end_inset 
7233
7234
7235 \series default 
7236  Send errors and warnings to stdout instead of stderr.
7237 \layout List
7238 \labelwidthstring 00.00.0000
7239
7240
7241 \series bold 
7242 -Wa\SpecialChar ~
7243 asmOption[,asmOption]
7244 \series default 
7245
7246 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
7247
7248 \end_inset 
7249
7250 ...
7251  Pass the asmOption to the assembler
7252 \begin_inset LatexCommand \index{Options assembler}
7253
7254 \end_inset 
7255
7256
7257 \begin_inset LatexCommand \index{Assembler options}
7258
7259 \end_inset 
7260
7261 .
7262  See file sdcc/as/doc/asxhtm.html for assembler options.
7263 \layout Subsection
7264
7265 Intermediate Dump Options
7266 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
7267
7268 \end_inset 
7269
7270
7271 \begin_inset LatexCommand \index{Options intermediate dump}
7272
7273 \end_inset 
7274
7275
7276 \begin_inset LatexCommand \index{Intermediate dump options}
7277
7278 \end_inset 
7279
7280
7281 \layout Standard
7282
7283 The following options are provided for the purpose of retargetting and debugging
7284  the compiler.
7285  These provided a means to dump the intermediate code (iCode
7286 \begin_inset LatexCommand \index{iCode}
7287
7288 \end_inset 
7289
7290 ) generated by the compiler in human readable form at various stages of
7291  the compilation process.
7292  More on iCodes see chapter 
7293 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
7294
7295 \end_inset 
7296
7297  
7298 \begin_inset Quotes srd
7299 \end_inset 
7300
7301 The anatomy of the compiler
7302 \begin_inset Quotes srd
7303 \end_inset 
7304
7305 .
7306 \layout List
7307 \labelwidthstring 00.00.0000
7308
7309
7310 \series bold 
7311 -
7312 \begin_inset ERT
7313 status Collapsed
7314
7315 \layout Standard
7316
7317 \backslash 
7318 /
7319 \end_inset 
7320
7321 -dumpraw
7322 \begin_inset LatexCommand \index{-\/-dumpraw}
7323
7324 \end_inset 
7325
7326
7327 \series default 
7328  This option will cause the compiler to dump the intermediate code into
7329  a file of named 
7330 \emph on 
7331 <source filename>.dumpraw
7332 \emph default 
7333  just after the intermediate code has been generated for a function, i.e.
7334  before any optimizations are done.
7335  The basic blocks
7336 \begin_inset LatexCommand \index{Basic blocks}
7337
7338 \end_inset 
7339
7340  at this stage ordered in the depth first number, so they may not be in
7341  sequence of execution.
7342 \layout List
7343 \labelwidthstring 00.00.0000
7344
7345
7346 \series bold 
7347 -
7348 \begin_inset ERT
7349 status Collapsed
7350
7351 \layout Standard
7352
7353 \backslash 
7354 /
7355 \end_inset 
7356
7357 -dumpgcse
7358 \begin_inset LatexCommand \index{-\/-dumpgcse}
7359
7360 \end_inset 
7361
7362
7363 \series default 
7364  Will create a dump of iCode's, after global subexpression elimination
7365 \begin_inset LatexCommand \index{Global subexpression elimination}
7366
7367 \end_inset 
7368
7369 , into a file named 
7370 \emph on 
7371 <source filename>.dumpgcse.
7372 \layout List
7373 \labelwidthstring 00.00.0000
7374
7375
7376 \series bold 
7377 -
7378 \begin_inset ERT
7379 status Collapsed
7380
7381 \layout Standard
7382
7383 \backslash 
7384 /
7385 \end_inset 
7386
7387 -dumpdeadcode
7388 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
7389
7390 \end_inset 
7391
7392
7393 \series default 
7394  Will create a dump of iCode's, after deadcode elimination
7395 \begin_inset LatexCommand \index{Dead-code elimination}
7396
7397 \end_inset 
7398
7399 , into a file named 
7400 \emph on 
7401 <source filename>.dumpdeadcode.
7402 \layout List
7403 \labelwidthstring 00.00.0000
7404
7405
7406 \series bold 
7407 -
7408 \begin_inset ERT
7409 status Collapsed
7410
7411 \layout Standard
7412
7413 \backslash 
7414 /
7415 \end_inset 
7416
7417 -dumploop
7418 \begin_inset LatexCommand \index{-\/-dumploop}
7419
7420 \end_inset 
7421
7422
7423 \series default 
7424 \size large 
7425  
7426 \size default 
7427 Will create a dump of iCode's, after loop optimizations
7428 \begin_inset LatexCommand \index{Loop optimization}
7429
7430 \end_inset 
7431
7432 , into a file named 
7433 \emph on 
7434 <source filename>.dumploop.
7435 \layout List
7436 \labelwidthstring 00.00.0000
7437
7438
7439 \series bold 
7440 -
7441 \begin_inset ERT
7442 status Collapsed
7443
7444 \layout Standard
7445
7446 \backslash 
7447 /
7448 \end_inset 
7449
7450 -dumprange
7451 \begin_inset LatexCommand \index{-\/-dumprange}
7452
7453 \end_inset 
7454
7455
7456 \series default 
7457 \size large 
7458  
7459 \size default 
7460 Will create a dump of iCode's, after live range analysis
7461 \begin_inset LatexCommand \index{Live range analysis}
7462
7463 \end_inset 
7464
7465 , into a file named 
7466 \emph on 
7467 <source filename>.dumprange.
7468 \layout List
7469 \labelwidthstring 00.00.0000
7470
7471
7472 \series bold 
7473 -
7474 \begin_inset ERT
7475 status Collapsed
7476
7477 \layout Standard
7478
7479 \backslash 
7480 /
7481 \end_inset 
7482
7483 -dumlrange
7484 \begin_inset LatexCommand \index{-\/-dumlrange}
7485
7486 \end_inset 
7487
7488
7489 \series default 
7490  Will dump the life ranges
7491 \begin_inset LatexCommand \index{Live range analysis}
7492
7493 \end_inset 
7494
7495  for all symbols.
7496 \layout List
7497 \labelwidthstring 00.00.0000
7498
7499
7500 \series bold 
7501 -
7502 \begin_inset ERT
7503 status Collapsed
7504
7505 \layout Standard
7506
7507 \backslash 
7508 /
7509 \end_inset 
7510
7511 -dumpregassign
7512 \begin_inset LatexCommand \index{-\/-dumpregassign}
7513
7514 \end_inset 
7515
7516
7517 \bar under 
7518  
7519 \series default 
7520 \bar default 
7521 Will create a dump of iCode's, after register assignment
7522 \begin_inset LatexCommand \index{Register assignment}
7523
7524 \end_inset 
7525
7526 , into a file named 
7527 \emph on 
7528 <source filename>.dumprassgn.
7529 \layout List
7530 \labelwidthstring 00.00.0000
7531
7532
7533 \series bold 
7534 -
7535 \begin_inset ERT
7536 status Collapsed
7537
7538 \layout Standard
7539
7540 \backslash 
7541 /
7542 \end_inset 
7543
7544 -dumplrange
7545 \begin_inset LatexCommand \index{-\/-dumplrange}
7546
7547 \end_inset 
7548
7549
7550 \series default 
7551  Will create a dump of the live ranges of iTemp's
7552 \layout List
7553 \labelwidthstring 00.00.0000
7554
7555
7556 \series bold 
7557 -
7558 \begin_inset ERT
7559 status Collapsed
7560
7561 \layout Standard
7562
7563 \backslash 
7564 /
7565 \end_inset 
7566
7567 -dumpall
7568 \begin_inset LatexCommand \index{-\/-dumpall}
7569
7570 \end_inset 
7571
7572
7573 \size large 
7574 \bar under 
7575  
7576 \series default 
7577 \size default 
7578 \bar default 
7579 Will cause all the above mentioned dumps to be created.
7580 \layout Subsection
7581
7582 Redirecting output on Windows Shells
7583 \layout Standard
7584
7585 By default SDCC writes it's error messages to 
7586 \begin_inset Quotes sld
7587 \end_inset 
7588
7589 standard error
7590 \begin_inset Quotes srd
7591 \end_inset 
7592
7593 .
7594  To force all messages to 
7595 \begin_inset Quotes sld
7596 \end_inset 
7597
7598 standard output
7599 \begin_inset Quotes srd
7600 \end_inset 
7601
7602  use 
7603 \series bold 
7604 -
7605 \series default 
7606 \emph on 
7607
7608 \begin_inset ERT
7609 status Collapsed
7610
7611 \layout Standard
7612
7613 \backslash 
7614 /
7615 \end_inset 
7616
7617
7618 \series bold 
7619 \emph default 
7620 -
7621 \series default 
7622 use-stdout
7623 \begin_inset LatexCommand \index{-\/-use-stdout}
7624
7625 \end_inset 
7626
7627 .
7628  Additionally, if you happen to have visual studio installed in your windows
7629  machine, you can use it to compile your sources using a custom build and
7630  the SDCC -
7631 \emph on 
7632
7633 \begin_inset ERT
7634 status Collapsed
7635
7636 \layout Standard
7637
7638 \backslash 
7639 /
7640 \end_inset 
7641
7642
7643 \emph default 
7644 -vc
7645 \begin_inset LatexCommand \index{-\/-vc}
7646
7647 \end_inset 
7648
7649  option.
7650  Something like this should work:
7651 \newline 
7652
7653 \newline 
7654
7655 \series bold 
7656 c:
7657 \backslash 
7658 sdcc
7659 \backslash 
7660 bin
7661 \backslash 
7662 sdcc.exe -
7663 \series default 
7664 \emph on 
7665
7666 \begin_inset ERT
7667 status Collapsed
7668
7669 \layout Standard
7670
7671 \backslash 
7672 /
7673 \end_inset 
7674
7675
7676 \series bold 
7677 \emph default 
7678 -vc -
7679 \series default 
7680 \emph on 
7681
7682 \begin_inset ERT
7683 status Collapsed
7684
7685 \layout Standard
7686
7687 \backslash 
7688 /
7689 \end_inset 
7690
7691
7692 \series bold 
7693 \emph default 
7694 -model-large -c $(InputPath)
7695 \layout Section
7696
7697 Environment variables
7698 \begin_inset LatexCommand \index{Environment variables}
7699
7700 \end_inset 
7701
7702
7703 \layout Standard
7704
7705 SDCC recognizes the following environment variables:
7706 \layout List
7707 \labelwidthstring 00.00.0000
7708
7709
7710 \series bold 
7711 SDCC_LEAVE_SIGNALS
7712 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
7713
7714 \end_inset 
7715
7716
7717 \series default 
7718  SDCC installs a signal handler
7719 \begin_inset LatexCommand \index{signal handler}
7720
7721 \end_inset 
7722
7723  to be able to delete temporary files after an user break (^C) or an exception.
7724  If this environment variable is set, SDCC won't install the signal handler
7725  in order to be able to debug SDCC.
7726 \layout List
7727 \labelwidthstring 00.00.0000
7728
7729
7730 \series bold 
7731 TMP,\SpecialChar ~
7732 TEMP,\SpecialChar ~
7733 TMPDIR
7734 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
7735
7736 \end_inset 
7737
7738
7739 \series default 
7740  Path, where temporary files will be created.
7741  The order of the variables is the search order.
7742  In a standard *nix environment these variables are not set, and there's
7743  no need to set them.
7744  On Windows it's recommended to set one of them.
7745 \layout List
7746 \labelwidthstring 00.00.0000
7747
7748
7749 \series bold 
7750 SDCC_HOME
7751 \begin_inset LatexCommand \index{SDCC\_HOME}
7752
7753 \end_inset 
7754
7755
7756 \series default 
7757  Path, see section 
7758 \begin_inset LatexCommand \ref{sub:Install-paths}
7759
7760 \end_inset 
7761
7762 \SpecialChar ~
7763
7764 \begin_inset Quotes sld
7765 \end_inset 
7766
7767  Install Paths
7768 \begin_inset Quotes srd
7769 \end_inset 
7770
7771 .
7772 \layout List
7773 \labelwidthstring 00.00.0000
7774
7775
7776 \series bold 
7777 SDCC_INCLUDE
7778 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
7779
7780 \end_inset 
7781
7782
7783 \series default 
7784  Path, see section 
7785 \begin_inset LatexCommand \ref{sub:Search-Paths}
7786
7787 \end_inset 
7788
7789 \SpecialChar ~
7790
7791 \begin_inset Quotes sld
7792 \end_inset 
7793
7794 Search Paths
7795 \begin_inset Quotes srd
7796 \end_inset 
7797
7798 .
7799 \layout List
7800 \labelwidthstring 00.00.0000
7801
7802
7803 \series bold 
7804 SDCC_LIB
7805 \begin_inset LatexCommand \index{SDCC\_LIB}
7806
7807 \end_inset 
7808
7809
7810 \series default 
7811  Path, see section 
7812 \begin_inset LatexCommand \ref{sub:Search-Paths}
7813
7814 \end_inset 
7815
7816 \SpecialChar ~
7817
7818 \begin_inset Quotes sld
7819 \end_inset 
7820
7821 Search Paths
7822 \begin_inset Quotes srd
7823 \end_inset 
7824
7825 ..
7826 \layout Standard
7827
7828 There are some more environment variables recognized by SDCC, but these
7829  are solely used for debugging purposes.
7830  They can change or disappear very quickly, and will never be documented.
7831 \layout Section
7832
7833 Storage Class Language Extensions
7834 \layout Subsection
7835
7836 MCS51/DS390 Storage Class
7837 \begin_inset LatexCommand \index{Storage class}
7838
7839 \end_inset 
7840
7841  Language Extensions
7842 \layout Standard
7843
7844 In addition to the ANSI storage classes SDCC allows the following MCS51
7845  specific storage classes:
7846 \layout Subsubsection
7847
7848 data
7849 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7850
7851 \end_inset 
7852
7853  / near
7854 \begin_inset LatexCommand \index{near (storage class)}
7855
7856 \end_inset 
7857
7858
7859 \layout Standard
7860
7861 This is the 
7862 \series bold 
7863 default
7864 \series default 
7865  storage class for the Small Memory model (
7866 \emph on 
7867 data
7868 \emph default 
7869  and 
7870 \emph on 
7871 near
7872 \emph default 
7873  can be used synonymously).
7874  Variables declared with this storage class will be allocated in the directly
7875  addressable portion of the internal RAM of a 8051, e.g.:
7876 \layout Verse
7877
7878
7879 \family typewriter 
7880 data unsigned char test_data;
7881 \layout Standard
7882
7883 Writing 0x01 to this variable generates the assembly code:
7884 \layout Verse
7885
7886
7887 \family typewriter 
7888 75*00 01\SpecialChar ~
7889 \SpecialChar ~
7890 \SpecialChar ~
7891 mov\SpecialChar ~
7892 \SpecialChar ~
7893 _test_data,#0x01 
7894 \layout Subsubsection
7895
7896 xdata
7897 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7898
7899 \end_inset 
7900
7901  / far
7902 \begin_inset LatexCommand \index{far (storage class)}
7903
7904 \end_inset 
7905
7906
7907 \layout Standard
7908
7909 Variables declared with this storage class will be placed in the external
7910  RAM.
7911  This is the 
7912 \series bold 
7913 default
7914 \series default 
7915  storage class for the Large Memory model, e.g.:
7916 \layout Verse
7917
7918
7919 \family typewriter 
7920 xdata unsigned char test_xdata;
7921 \layout Standard
7922
7923 Writing 0x01 to this variable generates the assembly code:
7924 \layout Verse
7925
7926
7927 \family typewriter 
7928 90s00r00\SpecialChar ~
7929 \SpecialChar ~
7930 \SpecialChar ~
7931 mov\SpecialChar ~
7932 \SpecialChar ~
7933 dptr,#_test_xdata 
7934 \newline 
7935 74\SpecialChar ~
7936 01\SpecialChar ~
7937 \SpecialChar ~
7938 \SpecialChar ~
7939 \SpecialChar ~
7940 \SpecialChar ~
7941 \SpecialChar ~
7942 mov\SpecialChar ~
7943 \SpecialChar ~
7944 a,#0x01 
7945 \newline 
7946 F0\SpecialChar ~
7947 \SpecialChar ~
7948 \SpecialChar ~
7949 \SpecialChar ~
7950 \SpecialChar ~
7951 \SpecialChar ~
7952 \SpecialChar ~
7953 \SpecialChar ~
7954 \SpecialChar ~
7955 movx\SpecialChar ~
7956 @dptr,a 
7957 \layout Subsubsection
7958
7959 idata
7960 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7961
7962 \end_inset 
7963
7964
7965 \layout Standard
7966
7967 Variables declared with this storage class will be allocated into the indirectly
7968  addressable portion of the internal ram of a 8051, e.g.:
7969 \layout Verse
7970
7971
7972 \family typewriter 
7973 idata unsigned char test_idata;
7974 \layout Standard
7975
7976 Writing 0x01 to this variable generates the assembly code:
7977 \layout Verse
7978
7979
7980 \family typewriter 
7981 78r00\SpecialChar ~
7982 \SpecialChar ~
7983 \SpecialChar ~
7984 \SpecialChar ~
7985 \SpecialChar ~
7986 \SpecialChar ~
7987 \SpecialChar ~
7988 mov\SpecialChar ~
7989 \SpecialChar ~
7990 r0,#_test_idata
7991 \newline 
7992 76\SpecialChar ~
7993 01\SpecialChar ~
7994 \SpecialChar ~
7995 \SpecialChar ~
7996 \SpecialChar ~
7997 \SpecialChar ~
7998 \SpecialChar ~
7999 \SpecialChar ~
8000 mov\SpecialChar ~
8001 \SpecialChar ~
8002 @r0,#0x01
8003 \layout Standard
8004
8005 Please note, the first 128 byte of idata physically access the same RAM
8006  as the data memory.
8007  The original 8051 had 128 byte idata memory, nowadays most devices have
8008  256 byte idata memory.
8009  The stack
8010 \begin_inset LatexCommand \index{stack}
8011
8012 \end_inset 
8013
8014  is located in idata memory.
8015 \layout Subsubsection
8016
8017 pdata
8018 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8019
8020 \end_inset 
8021
8022
8023 \layout Standard
8024
8025 Paged xdata access is currently not as straightforward as using the other
8026  addressing modes of a 8051.
8027  The following example writes 0x01 to the address pointed to.
8028  Please note, pdata access physically accesses xdata memory.
8029  The high byte of the address is determined by port P2 
8030 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
8031
8032 \end_inset 
8033
8034 (or in case of some 8051 variants by a separate Special Function Register,
8035  see section 
8036 \begin_inset LatexCommand \ref{sub:MCS51-variants}
8037
8038 \end_inset 
8039
8040 ).
8041 \layout Verse
8042
8043
8044 \family typewriter 
8045 pdata unsigned char *test_pdata_ptr;
8046 \newline 
8047
8048 \newline 
8049 void main() 
8050 \newline 
8051
8052 \newline 
8053 \SpecialChar ~
8054 \SpecialChar ~
8055 \SpecialChar ~
8056 \SpecialChar ~
8057 test_pdata_ptr = (pdata *)0xfe; 
8058 \newline 
8059 \SpecialChar ~
8060 \SpecialChar ~
8061 \SpecialChar ~
8062 \SpecialChar ~
8063 *test_pdata_ptr = 1; 
8064 \newline 
8065
8066 \layout Standard
8067
8068 Generates the assembly code:
8069 \layout Verse
8070
8071
8072 \family typewriter 
8073 75*01 FE\SpecialChar ~
8074 \SpecialChar ~
8075 \SpecialChar ~
8076 mov\SpecialChar ~
8077  _test_pdata_ptr,#0xFE
8078 \newline 
8079 78 FE\SpecialChar ~
8080 \SpecialChar ~
8081 \SpecialChar ~
8082 \SpecialChar ~
8083 \SpecialChar ~
8084 \SpecialChar ~
8085 mov\SpecialChar ~
8086  r0,#0xFE 
8087 \newline 
8088 74 01\SpecialChar ~
8089 \SpecialChar ~
8090 \SpecialChar ~
8091 \SpecialChar ~
8092 \SpecialChar ~
8093 \SpecialChar ~
8094 mov\SpecialChar ~
8095  a,#0x01
8096 \newline 
8097 F2\SpecialChar ~
8098 \SpecialChar ~
8099 \SpecialChar ~
8100 \SpecialChar ~
8101 \SpecialChar ~
8102 \SpecialChar ~
8103 \SpecialChar ~
8104 \SpecialChar ~
8105 \SpecialChar ~
8106 movx @r0,a 
8107 \layout Standard
8108
8109 Be extremely carefull if you use pdata together with the -
8110 \begin_inset ERT
8111 status Collapsed
8112
8113 \layout Standard
8114
8115 \backslash 
8116 /
8117 \end_inset 
8118
8119 -xstack
8120 \begin_inset LatexCommand \index{-\/-xstack}
8121
8122 \end_inset 
8123
8124  option.
8125 \layout Subsubsection
8126
8127 code
8128 \begin_inset LatexCommand \index{code}
8129
8130 \end_inset 
8131
8132
8133 \layout Standard
8134
8135 'Variables' declared with this storage class will be placed in the code
8136  memory:
8137 \layout Verse
8138
8139
8140 \family typewriter 
8141 code unsigned char test_code;
8142 \layout Standard
8143
8144 Read access to this variable generates the assembly code:
8145 \layout Verse
8146
8147
8148 \family typewriter 
8149 90s00r6F\SpecialChar ~
8150 \SpecialChar ~
8151 \SpecialChar ~
8152 mov dptr,#_test_code
8153 \newline 
8154 E4\SpecialChar ~
8155 \SpecialChar ~
8156 \SpecialChar ~
8157 \SpecialChar ~
8158 \SpecialChar ~
8159 \SpecialChar ~
8160 \SpecialChar ~
8161 \SpecialChar ~
8162 \SpecialChar ~
8163 clr a
8164 \newline 
8165 93\SpecialChar ~
8166 \SpecialChar ~
8167 \SpecialChar ~
8168 \SpecialChar ~
8169 \SpecialChar ~
8170 \SpecialChar ~
8171 \SpecialChar ~
8172 \SpecialChar ~
8173 \SpecialChar ~
8174 movc a,@a+dptr 
8175 \layout Standard
8176
8177
8178 \family typewriter 
8179 char
8180 \family default 
8181  indexed arrays of characters in code memory can be accessed efficiently:
8182 \layout Verse
8183
8184
8185 \family typewriter 
8186 code char test_array[] = {'c','h','e','a','p'}; 
8187 \layout Standard
8188
8189 Read access to this array using an 8-bit unsigned index generates the assembly
8190  code:
8191 \layout Verse
8192
8193
8194 \family typewriter 
8195 E5*00\SpecialChar ~
8196 \SpecialChar ~
8197 \SpecialChar ~
8198 \SpecialChar ~
8199 \SpecialChar ~
8200 \SpecialChar ~
8201 mov a,_index 
8202 \layout Verse
8203
8204
8205 \family typewriter 
8206 90s00r41\SpecialChar ~
8207 \SpecialChar ~
8208 \SpecialChar ~
8209 mov dptr,#_test_array
8210 \layout Verse
8211
8212
8213 \family typewriter 
8214 93\SpecialChar ~
8215 \SpecialChar ~
8216 \SpecialChar ~
8217 \SpecialChar ~
8218 \SpecialChar ~
8219 \SpecialChar ~
8220 \SpecialChar ~
8221 \SpecialChar ~
8222 \SpecialChar ~
8223 movc a,@a+dptr 
8224 \layout Subsubsection
8225
8226 bit
8227 \begin_inset LatexCommand \index{bit}
8228
8229 \end_inset 
8230
8231
8232 \layout Standard
8233
8234 This is a data-type and a storage class specifier.
8235  When a variable is declared as a bit, it is allocated into the bit addressable
8236  memory of 8051, e.g.:
8237 \layout Verse
8238
8239
8240 \family typewriter 
8241 bit test_bit;
8242 \layout Standard
8243
8244 Writing 1 to this variable generates the assembly code:
8245 \layout Verse
8246
8247
8248 \family typewriter 
8249 D2*00\SpecialChar ~
8250 \SpecialChar ~
8251 \SpecialChar ~
8252 \SpecialChar ~
8253 \SpecialChar ~
8254 \SpecialChar ~
8255 \SpecialChar ~
8256 setb\SpecialChar ~
8257 _test_bit
8258 \layout Standard
8259
8260 The bit addressable memory consists of 128 bits which are located from 0x20
8261  to 0x2f in data memory.
8262  
8263 \layout Standard
8264
8265 Apart from this 8051 specific storage class most architectures support ANSI-C
8266  bitfields
8267 \begin_inset LatexCommand \index{bitfields}
8268
8269 \end_inset 
8270
8271  
8272 \begin_inset Foot
8273 collapsed false
8274
8275 \layout Standard
8276
8277 Not really meant as examples, but nevertheless showing what bitfields are
8278  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
8279 \end_inset 
8280
8281 .
8282 \layout Subsubsection
8283
8284 sfr
8285 \begin_inset LatexCommand \index{sfr}
8286
8287 \end_inset 
8288
8289  / sbit
8290 \begin_inset LatexCommand \index{sbit}
8291
8292 \end_inset 
8293
8294
8295 \layout Standard
8296
8297 Like the bit keyword, 
8298 \emph on 
8299 sfr / sbit 
8300 \emph default 
8301 signifies both a data-type and storage class, they are used to describe
8302  the 
8303 \emph on 
8304 s
8305 \emph default 
8306 pecial 
8307 \emph on 
8308 f
8309 \emph default 
8310 unction 
8311 \emph on 
8312 r
8313 \emph default 
8314 egisters and 
8315 \emph on 
8316 s
8317 \emph default 
8318 pecial 
8319 \emph on 
8320 bit
8321 \emph default 
8322  variables of a 8051, eg:
8323 \layout Verse
8324
8325
8326 \family typewriter 
8327 sfr at
8328 \begin_inset LatexCommand \index{at}
8329
8330 \end_inset 
8331
8332  0x80 P0;\SpecialChar ~
8333  /* special function register P0 at location 0x80 */
8334 \newline 
8335 sbit at 0xd7 CY; /* CY (Carry Flag
8336 \begin_inset LatexCommand \index{Flags}
8337
8338 \end_inset 
8339
8340
8341 \begin_inset LatexCommand \index{Carry flag}
8342
8343 \end_inset 
8344
8345 ) */
8346 \layout Standard
8347
8348 Special function registers which are located on an address dividable by
8349  8 are bit-addressable, an
8350 \emph on 
8351  sbit
8352 \emph default 
8353  addresses a specific bit within these sfr.
8354 \layout Subsubsection
8355
8356 Pointers
8357 \begin_inset LatexCommand \index{Pointer}
8358
8359 \end_inset 
8360
8361  to MCS51/DS390 specific memory spaces
8362 \layout Standard
8363
8364 SDCC allows (via language extensions) pointers to explicitly point to any
8365  of the memory spaces
8366 \begin_inset LatexCommand \index{Memory model}
8367
8368 \end_inset 
8369
8370  of the 8051.
8371  In addition to the explicit pointers, the compiler uses (by default) generic
8372  pointers which can be used to point to any of the memory spaces.
8373 \newline 
8374
8375 \newline 
8376 Pointer declaration examples:
8377 \layout Verse
8378
8379
8380 \family typewriter 
8381 /* pointer physically in internal ram pointing to object in external ram
8382  */ 
8383 \newline 
8384 xdata unsigned char * data p;
8385 \newline 
8386
8387 \newline 
8388 /* pointer physically in external ram pointing to object in internal ram
8389  */ 
8390 \newline 
8391 data unsigned char * xdata p;
8392 \newline 
8393
8394 \newline 
8395 /* pointer physically in code rom pointing to data in xdata space */ 
8396 \newline 
8397 xdata unsigned char * code p;
8398 \newline 
8399
8400 \newline 
8401 /* pointer physically in code space pointing to data in code space */ 
8402 \newline 
8403 code unsigned char * code p;
8404 \newline 
8405
8406 \newline 
8407 /* the following is a generic pointer physically located in xdata space
8408  */
8409 \newline 
8410 char * xdata p;
8411 \layout Standard
8412
8413 Well you get the idea.
8414  
8415 \newline 
8416
8417 \newline 
8418 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
8419 \emph on 
8420 generic
8421 \emph default 
8422  pointers.
8423  
8424 \size small 
8425
8426 \newline 
8427
8428 \newline 
8429
8430 \size default 
8431 The highest order byte of the 
8432 \emph on 
8433 generic
8434 \emph default 
8435  pointers contains the data space information.
8436  Assembler support routines are called whenever data is stored or retrieved
8437  using 
8438 \emph on 
8439 generic
8440 \emph default 
8441  pointers.
8442  These are useful for developing reusable library
8443 \begin_inset LatexCommand \index{Libraries}
8444
8445 \end_inset 
8446
8447  routines.
8448  Explicitly specifying the pointer type will generate the most efficient
8449  code.
8450 \layout Subsubsection
8451
8452 Notes on MCS51 memory
8453 \begin_inset LatexCommand \index{MCS51 memory}
8454
8455 \end_inset 
8456
8457  layout
8458 \layout Standard
8459
8460 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
8461  RAM memory which is structured as follows:
8462 \newline 
8463
8464 \newline 
8465 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
8466  
8467 \newline 
8468 - Bytes 20-2F - 16 bytes to hold 128 bit
8469 \begin_inset LatexCommand \index{bit}
8470
8471 \end_inset 
8472
8473  variables and, 
8474 \newline 
8475 - Bytes 30-7F - 80 bytes for general purpose use.
8476 \newline 
8477
8478 \layout Standard
8479
8480 Additionally some members of the MCS51 family may have up to 128 bytes of
8481  additional, indirectly addressable, internal RAM memory (
8482 \emph on 
8483 idata
8484 \emph default 
8485
8486 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
8487
8488 \end_inset 
8489
8490 ).
8491  Furthermore, some chips may have some built in external memory (
8492 \emph on 
8493 xdata
8494 \emph default 
8495
8496 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
8497
8498 \end_inset 
8499
8500 ) which should not be confused with the internal, directly addressable RAM
8501  memory (
8502 \emph on 
8503 data
8504 \emph default 
8505
8506 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
8507
8508 \end_inset 
8509
8510 ).
8511  Sometimes this built in 
8512 \emph on 
8513 xdata
8514 \emph default 
8515  memory has to be activated before using it (you can probably find this
8516  information on the datasheet of the microcontroller your are using, see
8517  also section 
8518 \begin_inset LatexCommand \ref{sub:Startup-Code}
8519
8520 \end_inset 
8521
8522 \SpecialChar ~
8523 Startup-Code).
8524 \layout Standard
8525
8526 Normally SDCC will only use the first bank
8527 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
8528
8529 \end_inset 
8530
8531  of registers (register bank 0), but it is possible to specify that other
8532  banks of registers should be used in interrupt
8533 \begin_inset LatexCommand \index{interrupt}
8534
8535 \end_inset 
8536
8537  routines.
8538  By default, the compiler will place the stack after the last byte of allocated
8539  memory for variables.
8540  For example, if the first 2 banks of registers are used, and only four
8541  bytes are used for 
8542 \emph on 
8543 data
8544 \emph default 
8545  variables, it will position the base of the internal stack at address 20
8546  (0x14).
8547  This implies that as the stack
8548 \begin_inset LatexCommand \index{stack}
8549
8550 \end_inset 
8551
8552  grows, it will use up the remaining register banks, and the 16 bytes used
8553  by the 128 bit variables, and 80 bytes for general purpose use.
8554  If any bit variables are used, the data variables will be placed after
8555  the byte holding the last bit variable.
8556  For example, if register banks 0 and 1 are used, and there are 9 bit variables
8557  (two bytes used), 
8558 \emph on 
8559 data
8560 \emph default 
8561  variables will be placed starting at address 0x22.
8562  You can also use -
8563 \begin_inset ERT
8564 status Collapsed
8565
8566 \layout Standard
8567
8568 \backslash 
8569 /
8570 \end_inset 
8571
8572 -data-loc
8573 \begin_inset LatexCommand \index{-\/-data-loc<Value>}
8574
8575 \end_inset 
8576
8577  to specify the start address of the 
8578 \emph on 
8579 data
8580 \emph default 
8581  and -
8582 \begin_inset ERT
8583 status Collapsed
8584
8585 \layout Standard
8586
8587 \backslash 
8588 /
8589 \end_inset 
8590
8591 -iram-size to specify the size of the total internal RAM (
8592 \emph on 
8593 data
8594 \emph default 
8595 +
8596 \emph on 
8597 idata
8598 \emph default 
8599 ).
8600  
8601 \layout Standard
8602
8603 By default the 8051 linker will place the stack after the last byte of data
8604  variables.
8605  Option -
8606 \begin_inset ERT
8607 status Collapsed
8608
8609 \layout Standard
8610
8611 \backslash 
8612 /
8613 \end_inset 
8614
8615 -stack-loc
8616 \begin_inset LatexCommand \index{-\/-stack-loc<Value>}
8617
8618 \end_inset 
8619
8620  allows you to specify the start of the stack, i.e.
8621  you could start it after any data in the general purpose area.
8622  If your microcontroller has additional indirectly addressable internal
8623  RAM (
8624 \emph on 
8625 idata
8626 \emph default 
8627 ) you can place the stack on it.
8628  You may also need to use -
8629 \begin_inset ERT
8630 status Collapsed
8631
8632 \layout Standard
8633
8634 \backslash 
8635 /
8636 \end_inset 
8637
8638 -xdata-loc
8639 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
8640
8641 \end_inset 
8642
8643  to set the start address of the external RAM (
8644 \emph on 
8645 xdata
8646 \emph default 
8647 ) and -
8648 \begin_inset ERT
8649 status Collapsed
8650
8651 \layout Standard
8652
8653 \backslash 
8654 /
8655 \end_inset 
8656
8657 -xram-size
8658 \begin_inset LatexCommand \index{-\/-data-loc}
8659
8660 \end_inset 
8661
8662  to specify its size.
8663  Same goes for the code memory, using -
8664 \begin_inset ERT
8665 status Collapsed
8666
8667 \layout Standard
8668
8669 \backslash 
8670 /
8671 \end_inset 
8672
8673 -code-loc
8674 \begin_inset LatexCommand \index{-\/-data-loc}
8675
8676 \end_inset 
8677
8678  and -
8679 \begin_inset ERT
8680 status Collapsed
8681
8682 \layout Standard
8683
8684 \backslash 
8685 /
8686 \end_inset 
8687
8688 -code-size
8689 \begin_inset LatexCommand \index{-\/-data-loc}
8690
8691 \end_inset 
8692
8693 .
8694  If in doubt, don't specify any options and see if the resulting memory
8695  layout is appropriate, then you can adjust it.
8696 \layout Standard
8697
8698 The linker generates two files with memory allocation information.
8699  The first, with extension .map
8700 \begin_inset LatexCommand \index{<file>.map}
8701
8702 \end_inset 
8703
8704  shows all the variables and segments.
8705  The second with extension .mem
8706 \begin_inset LatexCommand \index{<file>.mem}
8707
8708 \end_inset 
8709
8710  shows the final memory layout.
8711  The linker will complain either if memory segments overlap, there is not
8712  enough memory, or there is not enough space for stack.
8713  If you get any linking warnings and/or errors related to stack or segments
8714  allocation, take a look at either the .map or .mem files to find out what
8715  the problem is.
8716  The .mem file may even suggest a solution to the problem.
8717 \layout Subsection
8718
8719 Z80/Z180 Storage Class
8720 \begin_inset LatexCommand \index{Storage class}
8721
8722 \end_inset 
8723
8724  Language Extensions
8725 \layout Subsubsection
8726
8727 sfr
8728 \begin_inset LatexCommand \index{sfr}
8729
8730 \end_inset 
8731
8732  (in/out to 8-bit addresses)
8733 \layout Standard
8734
8735 The Z80
8736 \begin_inset LatexCommand \index{Z80}
8737
8738 \end_inset 
8739
8740  family has separate address spaces for memory and 
8741 \emph on 
8742 i
8743 \emph default 
8744 nput/
8745 \emph on 
8746 o
8747 \emph default 
8748 utput memory.
8749  I/O memory
8750 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
8751
8752 \end_inset 
8753
8754  is accessed with special instructions, e.g.:
8755 \layout Verse
8756
8757
8758 \family typewriter 
8759 sfr at 0x78 IoPort;\SpecialChar ~
8760 \SpecialChar ~
8761 /* define a var in I/O space at 78h called IoPort */
8762  
8763 \layout Standard
8764
8765 Writing 0x01 to this variable generates the assembly code:
8766 \layout Verse
8767
8768
8769 \family typewriter 
8770 3E 01\SpecialChar ~
8771 \SpecialChar ~
8772 \SpecialChar ~
8773 \SpecialChar ~
8774 \SpecialChar ~
8775 \SpecialChar ~
8776 ld a,#0x01
8777 \newline 
8778 D3 78\SpecialChar ~
8779 \SpecialChar ~
8780 \SpecialChar ~
8781 \SpecialChar ~
8782 \SpecialChar ~
8783 \SpecialChar ~
8784 out (_IoPort),a 
8785 \layout Subsubsection
8786
8787 banked sfr
8788 \begin_inset LatexCommand \index{sfr}
8789
8790 \end_inset 
8791
8792  (in/out to 16-bit addresses)
8793 \layout Standard
8794
8795 The keyword 
8796 \emph on 
8797 banked
8798 \emph default 
8799  is used to support 16 bit addresses in I/O memory e.g.:
8800 \layout Verse
8801
8802
8803 \family typewriter 
8804 sfr banked at
8805 \begin_inset LatexCommand \index{at}
8806
8807 \end_inset 
8808
8809  0x123 IoPort; 
8810 \layout Standard
8811
8812 Writing 0x01 to this variable generates the assembly code:
8813 \layout Verse
8814
8815
8816 \family typewriter 
8817 01 23 01\SpecialChar ~
8818 \SpecialChar ~
8819 \SpecialChar ~
8820 ld bc,#_IoPort
8821 \newline 
8822 3E 01\SpecialChar ~
8823 \SpecialChar ~
8824 \SpecialChar ~
8825 \SpecialChar ~
8826 \SpecialChar ~
8827 \SpecialChar ~
8828 ld a,#0x01 
8829 \newline 
8830 ED 79\SpecialChar ~
8831 \SpecialChar ~
8832 \SpecialChar ~
8833 \SpecialChar ~
8834 \SpecialChar ~
8835 \SpecialChar ~
8836 out (c),a 
8837 \layout Subsubsection
8838
8839 sfr
8840 \begin_inset LatexCommand \index{sfr}
8841
8842 \end_inset 
8843
8844  (in0/out0 to 8 bit addresses on Z180
8845 \begin_inset LatexCommand \index{Z180}
8846
8847 \end_inset 
8848
8849 /HD64180
8850 \begin_inset LatexCommand \index{HD64180}
8851
8852 \end_inset 
8853
8854 )
8855 \layout Standard
8856
8857 The compiler option -
8858 \begin_inset ERT
8859 status Collapsed
8860
8861 \layout Standard
8862
8863 \backslash 
8864 /
8865 \end_inset 
8866
8867 -portmode=180 (80) and a compiler #pragma\SpecialChar ~
8868 portmode
8869 \begin_inset LatexCommand \index{\#pragma portmode}
8870
8871 \end_inset 
8872
8873 =z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
8874 ns 
8875 \family typewriter 
8876 in0/out0
8877 \family default 
8878  instead of 
8879 \family typewriter 
8880 in/out
8881 \family default 
8882 .
8883  If you include the file z180.h this will be set automatically.
8884 \layout Section
8885
8886 Absolute Addressing
8887 \begin_inset LatexCommand \index{Absolute addressing}
8888
8889 \end_inset 
8890
8891
8892 \layout Standard
8893
8894 Data items can be assigned an absolute address with the 
8895 \emph on 
8896 at
8897 \begin_inset LatexCommand \index{at}
8898
8899 \end_inset 
8900
8901  <address>
8902 \emph default 
8903  keyword, in addition to a storage class, e.g.:
8904 \layout Verse
8905
8906
8907 \family typewriter 
8908 xdata
8909 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
8910
8911 \end_inset 
8912
8913  at
8914 \begin_inset LatexCommand \index{at}
8915
8916 \end_inset 
8917
8918  0x7ffe unsigned int chksum;
8919 \layout Standard
8920
8921 In the above example the variable chksum will located at 0x7ffe and 0x7fff
8922  of the external ram.
8923  The compiler does 
8924 \emph on 
8925 not
8926 \emph default 
8927  reserve any space for variables declared in this way (they are implemented
8928  with an equate in the assembler).
8929  Thus it is left to the programmer to make sure there are no overlaps with
8930  other variables that are declared without the absolute address.
8931  The assembler listing file (.lst
8932 \begin_inset LatexCommand \index{<file>.lst}
8933
8934 \end_inset 
8935
8936 ) and the linker output files (.rst
8937 \begin_inset LatexCommand \index{<file>.rst}
8938
8939 \end_inset 
8940
8941 ) and (.map
8942 \begin_inset LatexCommand \index{<file>.map}
8943
8944 \end_inset 
8945
8946 ) are good places to look for such overlaps.
8947  Variables with an absolute address are 
8948 \emph on 
8949 not
8950 \emph default 
8951  initialized
8952 \begin_inset LatexCommand \index{Variable initialization}
8953
8954 \end_inset 
8955
8956 .
8957 \layout Standard
8958
8959 In case of memory mapped I/O devices the keyword 
8960 \emph on 
8961 volatile
8962 \emph default 
8963  should be used to tell the compiler that accesses might not be optimized
8964  away:
8965 \layout Verse
8966
8967
8968 \family typewriter 
8969 volatile
8970 \begin_inset LatexCommand \index{volatile}
8971
8972 \end_inset 
8973
8974  xdata
8975 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
8976
8977 \end_inset 
8978
8979  at
8980 \begin_inset LatexCommand \index{at}
8981
8982 \end_inset 
8983
8984  0x8000 unsigned char PORTA_8255;
8985 \layout Standard
8986
8987 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
8988 r) array
8989 \family typewriter 
8990 \size footnotesize 
8991
8992 \begin_inset LatexCommand \index{Aligned array}
8993
8994 \end_inset 
8995
8996
8997 \family default 
8998 \size default 
8999  starts at a block (256 byte) boundary
9000 \begin_inset LatexCommand \index{block boundary}
9001
9002 \end_inset 
9003
9004  (section 
9005 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
9006
9007 \end_inset 
9008
9009  has an example).
9010 \newline 
9011 Absolute addresses can be specified for variables in all storage classes,
9012  e.g.:
9013 \layout Verse
9014
9015
9016 \family typewriter 
9017 bit
9018 \begin_inset LatexCommand \index{bit}
9019
9020 \end_inset 
9021
9022  at
9023 \begin_inset LatexCommand \index{at}
9024
9025 \end_inset 
9026
9027  0x02 bvar;
9028 \layout Standard
9029
9030 The above example will allocate the variable at offset 0x02 in the bit-addressab
9031 le space.
9032  There is no real advantage to assigning absolute addresses to variables
9033  in this manner, unless you want strict control over all the variables allocated.
9034  One possible use would be to write hardware portable code.
9035  For example, if you have a routine that uses one or more of the microcontroller
9036  I/O pins, and such pins are different for two different hardwares, you
9037  can declare the I/O pins in your routine using:
9038 \layout Verse
9039
9040
9041 \family typewriter 
9042 extern volatile bit SDI;
9043 \newline 
9044 extern volatile bit SCLK;
9045 \newline 
9046 extern volatile bit CPOL;
9047 \newline 
9048
9049 \newline 
9050 void DS1306_put(unsigned char value)
9051 \newline 
9052 {
9053 \newline 
9054 \SpecialChar ~
9055 \SpecialChar ~
9056 \SpecialChar ~
9057 \SpecialChar ~
9058 unsigned char mask=0x80;
9059 \newline 
9060
9061 \newline 
9062 \SpecialChar ~
9063 \SpecialChar ~
9064 \SpecialChar ~
9065 \SpecialChar ~
9066 while(mask)
9067 \newline 
9068 \SpecialChar ~
9069 \SpecialChar ~
9070 \SpecialChar ~
9071 \SpecialChar ~
9072 {
9073 \newline 
9074 \SpecialChar ~
9075 \SpecialChar ~
9076 \SpecialChar ~
9077 \SpecialChar ~
9078 \SpecialChar ~
9079 \SpecialChar ~
9080 \SpecialChar ~
9081 \SpecialChar ~
9082 SDI=(value & mask)?1:0;
9083 \newline 
9084 \SpecialChar ~
9085 \SpecialChar ~
9086 \SpecialChar ~
9087 \SpecialChar ~
9088 \SpecialChar ~
9089 \SpecialChar ~
9090 \SpecialChar ~
9091 \SpecialChar ~
9092 SCLK=!CPOL;
9093 \newline 
9094 \SpecialChar ~
9095 \SpecialChar ~
9096 \SpecialChar ~
9097 \SpecialChar ~
9098 \SpecialChar ~
9099 \SpecialChar ~
9100 \SpecialChar ~
9101 \SpecialChar ~
9102 SCLK=CPOL;
9103 \newline 
9104 \SpecialChar ~
9105 \SpecialChar ~
9106 \SpecialChar ~
9107 \SpecialChar ~
9108 \SpecialChar ~
9109 \SpecialChar ~
9110 \SpecialChar ~
9111 \SpecialChar ~
9112 mask/=2;
9113 \newline 
9114 \SpecialChar ~
9115 \SpecialChar ~
9116 \SpecialChar ~
9117 \SpecialChar ~
9118 }
9119 \newline 
9120 }
9121 \layout Standard
9122
9123 Then, someplace in the code for the first hardware you would use
9124 \layout Verse
9125
9126
9127 \family typewriter 
9128 bit at 0x80 SDI;\SpecialChar ~
9129 \SpecialChar ~
9130 \SpecialChar ~
9131 \SpecialChar ~
9132 /* I/O port 0, bit 0 */
9133 \newline 
9134 bit at 0x81 SCLK;\SpecialChar ~
9135 \SpecialChar ~
9136 \SpecialChar ~
9137 /* I/O port 0, bit 1 */
9138 \newline 
9139 bit CPOL;\SpecialChar ~
9140 \SpecialChar ~
9141 \SpecialChar ~
9142 \SpecialChar ~
9143 \SpecialChar ~
9144 \SpecialChar ~
9145 \SpecialChar ~
9146 \SpecialChar ~
9147 \SpecialChar ~
9148 \SpecialChar ~
9149 \SpecialChar ~
9150 /* This is a variable, let the linker allocate this one */
9151 \layout Standard
9152
9153 Similarly, for the second hardware you would use
9154 \layout Verse
9155
9156
9157 \family typewriter 
9158 bit at 0x83 SDI;\SpecialChar ~
9159 \SpecialChar ~
9160 \SpecialChar ~
9161 \SpecialChar ~
9162 /* I/O port 0, bit 3 */
9163 \newline 
9164 bit at 0x91 SCLK;\SpecialChar ~
9165 \SpecialChar ~
9166 \SpecialChar ~
9167 /* I/O port 1, bit 1 */
9168 \newline 
9169 bit
9170 \begin_inset LatexCommand \index{bit}
9171
9172 \end_inset 
9173
9174  CPOL;\SpecialChar ~
9175 \SpecialChar ~
9176 \SpecialChar ~
9177 \SpecialChar ~
9178 \SpecialChar ~
9179 \SpecialChar ~
9180 \SpecialChar ~
9181 \SpecialChar ~
9182 \SpecialChar ~
9183 \SpecialChar ~
9184 \SpecialChar ~
9185 /* This is a variable, let the linker allocate this one */
9186 \layout Standard
9187
9188 and you can use the same hardware dependent routine without changes, as
9189  for example in a library.
9190  This is somehow similar to sbit, but only one absolute address has to be
9191  specified in the whole project.
9192 \layout Section
9193
9194 Parameters
9195 \begin_inset LatexCommand \index{Parameters}
9196
9197 \end_inset 
9198
9199
9200 \begin_inset LatexCommand \index{function parameter}
9201
9202 \end_inset 
9203
9204  & Local Variables
9205 \begin_inset LatexCommand \index{local variables}
9206
9207 \end_inset 
9208
9209
9210 \layout Standard
9211
9212 Automatic (local) variables and parameters to functions can either be placed
9213  on the stack or in data-space.
9214  The default action of the compiler is to place these variables in the internal
9215  RAM (for small model) or external RAM (for large model).
9216  This in fact makes them similar to 
9217 \emph on 
9218 static
9219 \begin_inset LatexCommand \index{static}
9220
9221 \end_inset 
9222
9223
9224 \emph default 
9225  so by default functions are non-reentrant
9226 \begin_inset LatexCommand \index{reentrant}
9227
9228 \end_inset 
9229
9230 .
9231  
9232 \newline 
9233
9234 \newline 
9235 They can be placed on the stack
9236 \begin_inset LatexCommand \index{stack}
9237
9238 \end_inset 
9239
9240  either by using the
9241 \emph on 
9242  -
9243 \begin_inset ERT
9244 status Collapsed
9245
9246 \layout Standard
9247
9248 \backslash 
9249 /
9250 \end_inset 
9251
9252 -stack-auto
9253 \begin_inset LatexCommand \index{-\/-stack-auto}
9254
9255 \end_inset 
9256
9257
9258 \emph default 
9259  option or by using the 
9260 \emph on 
9261 reentrant
9262 \begin_inset LatexCommand \index{reentrant}
9263
9264 \end_inset 
9265
9266
9267 \emph default 
9268  keyword in the function declaration, e.g.:
9269 \layout Verse
9270
9271
9272 \family typewriter 
9273 unsigned char foo(char i) reentrant 
9274 \newline 
9275
9276 \newline 
9277 \SpecialChar ~
9278 \SpecialChar ~
9279 \SpecialChar ~
9280 \SpecialChar ~
9281 ...
9282  
9283 \newline 
9284 }
9285 \layout Standard
9286
9287 Since stack space on 8051 is limited, the 
9288 \emph on 
9289 reentrant 
9290 \emph default 
9291 keyword or the
9292 \emph on 
9293  -
9294 \begin_inset ERT
9295 status Collapsed
9296
9297 \layout Standard
9298
9299 \backslash 
9300 /
9301 \end_inset 
9302
9303 -stack-auto
9304 \emph default 
9305  option should be used sparingly.
9306  Note that the reentrant keyword just means that the parameters & local
9307  variables will be allocated to the stack, it 
9308 \emph on 
9309 does not
9310 \emph default 
9311  mean that the function is register bank
9312 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
9313
9314 \end_inset 
9315
9316  independent.
9317 \newline 
9318
9319 \newline 
9320 Local variables
9321 \begin_inset LatexCommand \index{local variables}
9322
9323 \end_inset 
9324
9325  can be assigned storage classes and absolute
9326 \begin_inset LatexCommand \index{Absolute addressing}
9327
9328 \end_inset 
9329
9330  addresses, e.g.: 
9331 \layout Verse
9332
9333
9334 \family typewriter 
9335 unsigned char foo() 
9336 \newline 
9337 {
9338 \newline 
9339 \SpecialChar ~
9340 \SpecialChar ~
9341 \SpecialChar ~
9342 \SpecialChar ~
9343 xdata unsigned char i;
9344 \newline 
9345 \SpecialChar ~
9346 \SpecialChar ~
9347 \SpecialChar ~
9348 \SpecialChar ~
9349 bit bvar;
9350 \newline 
9351 \SpecialChar ~
9352 \SpecialChar ~
9353 \SpecialChar ~
9354 \SpecialChar ~
9355 data at
9356 \begin_inset LatexCommand \index{at}
9357
9358 \end_inset 
9359
9360  0x31 unsigned char j;
9361 \newline 
9362 \SpecialChar ~
9363 \SpecialChar ~
9364 \SpecialChar ~
9365 \SpecialChar ~
9366 ...
9367  
9368 \newline 
9369 }
9370 \layout Standard
9371
9372 In the above example the variable 
9373 \emph on 
9374 i
9375 \emph default 
9376  will be allocated in the external ram, 
9377 \emph on 
9378 bvar
9379 \emph default 
9380  in bit addressable space and
9381 \emph on 
9382  j
9383 \emph default 
9384  in internal ram.
9385  When compiled with 
9386 \emph on 
9387 -
9388 \begin_inset ERT
9389 status Collapsed
9390
9391 \layout Standard
9392
9393 \backslash 
9394 /
9395 \end_inset 
9396
9397 -stack-auto
9398 \emph default 
9399  or when a function is declared as 
9400 \emph on 
9401 reentrant
9402 \emph default 
9403  this should only be done for static variables.
9404 \layout Standard
9405
9406 Parameters
9407 \begin_inset LatexCommand \index{function parameter}
9408
9409 \end_inset 
9410
9411  however are not allowed any storage class
9412 \begin_inset LatexCommand \index{Storage class}
9413
9414 \end_inset 
9415
9416 , (storage classes for parameters will be ignored), their allocation is
9417  governed by the memory model in use, and the reentrancy options.
9418 \layout Section
9419
9420 Overlaying
9421 \begin_inset LatexCommand \label{sub:Overlaying}
9422
9423 \end_inset 
9424
9425
9426 \begin_inset LatexCommand \index{Overlaying}
9427
9428 \end_inset 
9429
9430
9431 \layout Standard
9432
9433 For non-reentrant
9434 \begin_inset LatexCommand \index{reentrant}
9435
9436 \end_inset 
9437
9438  functions SDCC will try to reduce internal ram space usage by overlaying
9439  parameters and local variables of a function (if possible).
9440  Parameters and local variables
9441 \begin_inset LatexCommand \index{local variables}
9442
9443 \end_inset 
9444
9445  of a function will be allocated to an overlayable segment if the function
9446  has 
9447 \emph on 
9448 no other function calls and the function is non-reentrant and the memory
9449  model
9450 \begin_inset LatexCommand \index{Memory model}
9451
9452 \end_inset 
9453
9454  is small.
9455
9456 \emph default 
9457  If an explicit storage class
9458 \begin_inset LatexCommand \index{Storage class}
9459
9460 \end_inset 
9461
9462  is specified for a local variable, it will NOT be overlayed.
9463 \layout Standard
9464
9465 Note that the compiler (not the linkage editor) makes the decision for overlayin
9466 g the data items.
9467  Functions that are called from an interrupt service routine should be preceded
9468  by a #pragma\SpecialChar ~
9469 nooverlay
9470 \begin_inset LatexCommand \index{\#pragma nooverlay}
9471
9472 \end_inset 
9473
9474  if they are not reentrant.
9475 \layout Standard
9476
9477 Also note that the compiler does not do any processing of inline assembler
9478  code, so the compiler might incorrectly assign local variables and parameters
9479  of a function into the overlay segment if the inline assembler code calls
9480  other c-functions that might use the overlay.
9481  In that case the #pragma\SpecialChar ~
9482 nooverlay should be used.
9483 \layout Standard
9484
9485 Parameters and local variables of functions that contain 16 or 32 bit multiplica
9486 tion
9487 \begin_inset LatexCommand \index{Multiplication}
9488
9489 \end_inset 
9490
9491  or division
9492 \begin_inset LatexCommand \index{Division}
9493
9494 \end_inset 
9495
9496  will NOT be overlayed since these are implemented using external functions,
9497  e.g.:
9498 \layout Verse
9499
9500
9501 \family typewriter 
9502 #pragma save 
9503 \newline 
9504 #pragma nooverlay
9505 \begin_inset LatexCommand \index{\#pragma nooverlay}
9506
9507 \end_inset 
9508
9509  
9510 \newline 
9511 void set_error(unsigned char errcd) 
9512 \newline 
9513 {
9514 \newline 
9515 \SpecialChar ~
9516 \SpecialChar ~
9517 \SpecialChar ~
9518 \SpecialChar ~
9519 P3 = errcd;
9520 \newline 
9521
9522 \newline 
9523 #pragma restore 
9524 \newline 
9525
9526 \newline 
9527 void some_isr () interrupt
9528 \begin_inset LatexCommand \index{interrupt}
9529
9530 \end_inset 
9531
9532  2
9533 \newline 
9534 {
9535 \newline 
9536 \SpecialChar ~
9537 \SpecialChar ~
9538 \SpecialChar ~
9539 \SpecialChar ~
9540 ...
9541 \newline 
9542 \SpecialChar ~
9543 \SpecialChar ~
9544 \SpecialChar ~
9545 \SpecialChar ~
9546 set_error(10);
9547 \newline 
9548 \SpecialChar ~
9549 \SpecialChar ~
9550 \SpecialChar ~
9551 \SpecialChar ~
9552 ...
9553  
9554 \newline 
9555 }
9556 \layout Standard
9557
9558 In the above example the parameter 
9559 \emph on 
9560 errcd
9561 \emph default 
9562  for the function 
9563 \emph on 
9564 set_error
9565 \emph default 
9566  would be assigned to the overlayable segment if the #pragma\SpecialChar ~
9567 nooverlay was
9568  not present, this could cause unpredictable runtime behavior when called
9569  from an interrupt service routine.
9570  The #pragma\SpecialChar ~
9571 nooverlay ensures that the parameters and local variables for
9572  the function are NOT overlayed.
9573 \layout Section
9574
9575 Interrupt Service Routines
9576 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
9577
9578 \end_inset 
9579
9580
9581 \layout Standard
9582
9583 SDCC allows 
9584 \emph on 
9585 i
9586 \emph default 
9587 nterrupt 
9588 \emph on 
9589 s
9590 \emph default 
9591 ervice 
9592 \emph on 
9593 r
9594 \emph default 
9595 outines to be coded in C, with some extended keywords.
9596 \layout Verse
9597
9598
9599 \family typewriter 
9600 void timer_isr (void) interrupt 1 using 1 
9601 \newline 
9602
9603 \newline 
9604 \SpecialChar ~
9605 \SpecialChar ~
9606 \SpecialChar ~
9607 \SpecialChar ~
9608 ...
9609  
9610 \newline 
9611 }
9612 \layout Standard
9613
9614 The optional number following the 
9615 \emph on 
9616 interrupt
9617 \begin_inset LatexCommand \index{interrupt}
9618
9619 \end_inset 
9620
9621
9622 \emph default 
9623  keyword is the interrupt number this routine will service.
9624  When present, the compiler will insert a call to this routine in the interrupt
9625  vector table for the interrupt number specified.
9626  If you have multiple source files in your project, interrupt service routines
9627  can be present in any of them, but a prototype of the isr MUST be present
9628  or included in the file that contains the function 
9629 \emph on 
9630 main
9631 \emph default 
9632 .
9633  The 
9634 \emph on 
9635 using
9636 \emph default 
9637  keyword can be used to tell the compiler to use the specified register
9638  bank (8051 specific) when generating code for this function.
9639  
9640 \newline 
9641
9642 \layout Standard
9643
9644 Interrupt numbers and the corresponding address & descriptions for the Standard
9645  8051/8052 are listed below.
9646  SDCC will automatically adjust the interrupt vector table to the maximum
9647  interrupt number specified.
9648 \newline 
9649
9650 \layout Standard
9651 \align center 
9652
9653 \begin_inset  Tabular
9654 <lyxtabular version="3" rows="7" columns="3">
9655 <features>
9656 <column alignment="center" valignment="top" leftline="true" width="0in">
9657 <column alignment="center" valignment="top" leftline="true" width="0in">
9658 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0in">
9659 <row topline="true" bottomline="true">
9660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9661 \begin_inset Text
9662
9663 \layout Standard
9664
9665 Interrupt #
9666 \end_inset 
9667 </cell>
9668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9669 \begin_inset Text
9670
9671 \layout Standard
9672
9673 Description
9674 \end_inset 
9675 </cell>
9676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9677 \begin_inset Text
9678
9679 \layout Standard
9680
9681 Vector Address
9682 \end_inset 
9683 </cell>
9684 </row>
9685 <row topline="true">
9686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9687 \begin_inset Text
9688
9689 \layout Standard
9690
9691 0
9692 \end_inset 
9693 </cell>
9694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9695 \begin_inset Text
9696
9697 \layout Standard
9698
9699 External 0
9700 \end_inset 
9701 </cell>
9702 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9703 \begin_inset Text
9704
9705 \layout Standard
9706
9707 0x0003
9708 \end_inset 
9709 </cell>
9710 </row>
9711 <row topline="true">
9712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9713 \begin_inset Text
9714
9715 \layout Standard
9716
9717 1
9718 \end_inset 
9719 </cell>
9720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9721 \begin_inset Text
9722
9723 \layout Standard
9724
9725 Timer 0
9726 \end_inset 
9727 </cell>
9728 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9729 \begin_inset Text
9730
9731 \layout Standard
9732
9733 0x000B
9734 \end_inset 
9735 </cell>
9736 </row>
9737 <row topline="true">
9738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9739 \begin_inset Text
9740
9741 \layout Standard
9742
9743 2
9744 \end_inset 
9745 </cell>
9746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9747 \begin_inset Text
9748
9749 \layout Standard
9750
9751 External 1
9752 \end_inset 
9753 </cell>
9754 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9755 \begin_inset Text
9756
9757 \layout Standard
9758
9759 0x0013
9760 \end_inset 
9761 </cell>
9762 </row>
9763 <row topline="true">
9764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9765 \begin_inset Text
9766
9767 \layout Standard
9768
9769 3
9770 \end_inset 
9771 </cell>
9772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9773 \begin_inset Text
9774
9775 \layout Standard
9776
9777 Timer 1
9778 \end_inset 
9779 </cell>
9780 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9781 \begin_inset Text
9782
9783 \layout Standard
9784
9785 0x001B
9786 \end_inset 
9787 </cell>
9788 </row>
9789 <row topline="true">
9790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9791 \begin_inset Text
9792
9793 \layout Standard
9794
9795 4
9796 \end_inset 
9797 </cell>
9798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9799 \begin_inset Text
9800
9801 \layout Standard
9802
9803 Serial
9804 \end_inset 
9805 </cell>
9806 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9807 \begin_inset Text
9808
9809 \layout Standard
9810
9811 0x0023
9812 \end_inset 
9813 </cell>
9814 </row>
9815 <row topline="true" bottomline="true">
9816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9817 \begin_inset Text
9818
9819 \layout Standard
9820
9821 5
9822 \end_inset 
9823 </cell>
9824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9825 \begin_inset Text
9826
9827 \layout Standard
9828
9829 Timer 2 (8052)
9830 \end_inset 
9831 </cell>
9832 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9833 \begin_inset Text
9834
9835 \layout Standard
9836
9837 0x002B
9838 \end_inset 
9839 </cell>
9840 </row>
9841 </lyxtabular>
9842
9843 \end_inset 
9844
9845
9846 \newline 
9847
9848 \layout Standard
9849
9850 If the interrupt service routine is defined without 
9851 \emph on 
9852 using
9853 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
9854
9855 \end_inset 
9856
9857
9858 \emph default 
9859  a register bank or with register bank 0 (
9860 \emph on 
9861 using
9862 \emph default 
9863  0), the compiler will save the registers used by itself on the stack upon
9864  entry and restore them at exit, however if such an interrupt service routine
9865  calls another function then the entire register bank will be saved on the
9866  stack.
9867  This scheme may be advantageous for small interrupt service routines which
9868  have low register usage.
9869 \layout Standard
9870
9871 If the interrupt service routine is defined to be using a specific register
9872  bank then only 
9873 \emph on 
9874 a, b, dptr
9875 \emph default 
9876  & psw are saved and restored, if such an interrupt service routine calls
9877  another function (using another register bank) then the entire register
9878  bank of the called function will be saved on the stack.
9879  This scheme is recommended for larger interrupt service routines.
9880 \layout Standard
9881
9882 Interrupt service routines open the door for some very interesting bugs:
9883  
9884 \layout Standard
9885
9886 If the interrupt service routines changes variables which are accessed by
9887  other functions these variables should be declared 
9888 \emph on 
9889 volatile
9890 \emph default 
9891
9892 \begin_inset LatexCommand \index{volatile}
9893
9894 \end_inset 
9895
9896 .
9897  
9898 \layout Standard
9899
9900 If the access to these variables is not 
9901 \emph on 
9902 atomic
9903 \begin_inset LatexCommand \index{atomic access}
9904
9905 \end_inset 
9906
9907
9908 \emph default 
9909  (i.e.
9910  the processor needs more than one instruction for the access and could
9911  be interrupted while accessing the variable) the interrupt must disabled
9912  during the access to avoid inconsistent data.
9913  Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
9914  and should be protected by disabling interrupts.
9915  You're not automatically on the safe side if you use 8 bit variables though.
9916  We need an example here: f.e.
9917  on the 8051 the harmless looking 
9918 \begin_inset Quotes srd
9919 \end_inset 
9920
9921
9922 \family typewriter 
9923 flags\SpecialChar ~
9924 |=\SpecialChar ~
9925 0x80;
9926 \family default 
9927
9928 \begin_inset Quotes sld
9929 \end_inset 
9930
9931  is not atomic if 
9932 \family typewriter 
9933 flags
9934 \family default 
9935  resides in xdata.
9936  Setting 
9937 \begin_inset Quotes srd
9938 \end_inset 
9939
9940
9941 \family typewriter 
9942 flags\SpecialChar ~
9943 |=\SpecialChar ~
9944 0x40;
9945 \family default 
9946
9947 \begin_inset Quotes sld
9948 \end_inset 
9949
9950  from within an interrupt routine might get lost if the interrupt occurs
9951  at the wrong time.
9952  
9953 \begin_inset Quotes sld
9954 \end_inset 
9955
9956
9957 \family typewriter 
9958 counter\SpecialChar ~
9959 +=\SpecialChar ~
9960 8;
9961 \family default 
9962
9963 \begin_inset Quotes srd
9964 \end_inset 
9965
9966  is not atomic on the 8051 even if 
9967 \family typewriter 
9968 counter
9969 \family default 
9970  is located in data memory.
9971  Bugs like these are hard to reproduce and can cause a lot of trouble.
9972  
9973 \layout Standard
9974
9975 A special note here, int (16 bit) and long (32 bit) integer division
9976 \begin_inset LatexCommand \index{Division}
9977
9978 \end_inset 
9979
9980 , multiplication
9981 \begin_inset LatexCommand \index{Multiplication}
9982
9983 \end_inset 
9984
9985  & modulus
9986 \begin_inset LatexCommand \index{Modulus}
9987
9988 \end_inset 
9989
9990  and floating-point
9991 \begin_inset LatexCommand \index{Floating point support}
9992
9993 \end_inset 
9994
9995  operations are implemented using external support routines developed in
9996  ANSI-C.
9997  If an interrupt service routine needs to do any of these operations then
9998  the support routines (as mentioned in a following section) will have to
9999  be recompiled using the
10000 \emph on 
10001  -
10002 \begin_inset ERT
10003 status Collapsed
10004
10005 \layout Standard
10006
10007 \backslash 
10008 /
10009 \end_inset 
10010
10011 -stack-auto
10012 \begin_inset LatexCommand \index{-\/-stack-auto}
10013
10014 \end_inset 
10015
10016
10017 \emph default 
10018  option and the source file will need to be compiled using the 
10019 \emph on 
10020 -
10021 \begin_inset ERT
10022 status Collapsed
10023
10024 \layout Standard
10025
10026 \backslash 
10027 /
10028 \end_inset 
10029
10030 -int-long-reent
10031 \emph default 
10032
10033 \begin_inset LatexCommand \index{-\/-int-long-reent}
10034
10035 \end_inset 
10036
10037  compiler option.
10038 \layout Standard
10039
10040 Calling other functions from an interrupt service routine is not recommended,
10041  avoid it if possible.
10042  Note that when some function is called from an interrupt service routine
10043  it should be preceded by a #pragma\SpecialChar ~
10044 nooverlay
10045 \begin_inset LatexCommand \index{\#pragma nooverlay}
10046
10047 \end_inset 
10048
10049  if it is not reentrant.
10050  Furthermore nonreentrant functions should not be called from the main program
10051  while the interrupt service routine might be active.
10052  
10053 \newline 
10054
10055 \newline 
10056 Also see section 
10057 \begin_inset LatexCommand \ref{sub:Overlaying}
10058
10059 \end_inset 
10060
10061 \SpecialChar ~
10062 about Overlaying and section 
10063 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
10064
10065 \end_inset 
10066
10067 \SpecialChar ~
10068 about Functions using private register banks.
10069 \layout Section
10070
10071 Enabling and Disabling Interrupts
10072 \layout Subsection
10073
10074 Critical Functions and Critical Statements
10075 \layout Standard
10076
10077 A special keyword may be associated with a block or a function declaring
10078  it as 
10079 \emph on 
10080 critical
10081 \emph default 
10082 .
10083  SDCC will generate code to disable all interrupts
10084 \begin_inset LatexCommand \index{interrupt}
10085
10086 \end_inset 
10087
10088  upon entry to a critical function and restore the interrupt enable to the
10089  previous state before returning.
10090  Nesting critical functions will need one additional byte on the stack
10091 \begin_inset LatexCommand \index{stack}
10092
10093 \end_inset 
10094
10095  for each call.
10096 \layout Verse
10097
10098
10099 \family typewriter 
10100 int foo () critical
10101 \begin_inset LatexCommand \index{critical}
10102
10103 \end_inset 
10104
10105  
10106 \newline 
10107
10108 \newline 
10109 \SpecialChar ~
10110 \SpecialChar ~
10111 \SpecialChar ~
10112 \SpecialChar ~
10113 ...
10114  
10115 \newline 
10116 \SpecialChar ~
10117 \SpecialChar ~
10118 \SpecialChar ~
10119 \SpecialChar ~
10120 ...
10121  
10122 \newline 
10123 }
10124 \layout Standard
10125
10126 The critical attribute maybe used with other attributes like 
10127 \emph on 
10128 reentrant.
10129 \emph default 
10130
10131 \newline 
10132 The keyword 
10133 \emph on 
10134 critical
10135 \emph default 
10136  may also be used to disable interrupts more locally:
10137 \layout Verse
10138
10139
10140 \family typewriter 
10141 critical{ i++; }
10142 \layout Standard
10143
10144 More than one statement could have been included in the block.
10145 \layout Subsection
10146
10147 Enabling and Disabling Interrupts directly
10148 \layout Standard
10149
10150 Interrupts
10151 \begin_inset LatexCommand \index{interrupt}
10152
10153 \end_inset 
10154
10155  can also be disabled and enabled directly (8051):
10156 \layout Verse
10157
10158
10159 \family typewriter 
10160 EA = 0;\SpecialChar ~
10161 \SpecialChar ~
10162 \SpecialChar ~
10163 \SpecialChar ~
10164 \SpecialChar ~
10165 \SpecialChar ~
10166 \SpecialChar ~
10167 \SpecialChar ~
10168 \SpecialChar ~
10169 \SpecialChar ~
10170 \SpecialChar ~
10171 \SpecialChar ~
10172 or:\SpecialChar ~
10173 \SpecialChar ~
10174 \SpecialChar ~
10175 \SpecialChar ~
10176 \SpecialChar ~
10177 \SpecialChar ~
10178 \SpecialChar ~
10179 \SpecialChar ~
10180 \SpecialChar ~
10181 \SpecialChar ~
10182 \SpecialChar ~
10183 EA_SAVE = EA;
10184 \layout Verse
10185
10186
10187 \family typewriter 
10188 ...\SpecialChar ~
10189 \SpecialChar ~
10190 \SpecialChar ~
10191 \SpecialChar ~
10192 \SpecialChar ~
10193 \SpecialChar ~
10194 \SpecialChar ~
10195 \SpecialChar ~
10196 \SpecialChar ~
10197 \SpecialChar ~
10198 \SpecialChar ~
10199 \SpecialChar ~
10200 \SpecialChar ~
10201 \SpecialChar ~
10202 \SpecialChar ~
10203 \SpecialChar ~
10204 \SpecialChar ~
10205 \SpecialChar ~
10206 \SpecialChar ~
10207 \SpecialChar ~
10208 \SpecialChar ~
10209 \SpecialChar ~
10210 \SpecialChar ~
10211 \SpecialChar ~
10212 \SpecialChar ~
10213 \SpecialChar ~
10214 \SpecialChar ~
10215 \SpecialChar ~
10216 \SpecialChar ~
10217 \SpecialChar ~
10218 EA = 0;
10219 \layout Verse
10220
10221
10222 \family typewriter 
10223 EA = 1;\SpecialChar ~
10224 \SpecialChar ~
10225 \SpecialChar ~
10226 \SpecialChar ~
10227 \SpecialChar ~
10228 \SpecialChar ~
10229 \SpecialChar ~
10230 \SpecialChar ~
10231 \SpecialChar ~
10232 \SpecialChar ~
10233 \SpecialChar ~
10234 \SpecialChar ~
10235 \SpecialChar ~
10236 \SpecialChar ~
10237 \SpecialChar ~
10238 \SpecialChar ~
10239 \SpecialChar ~
10240 \SpecialChar ~
10241 \SpecialChar ~
10242 \SpecialChar ~
10243 \SpecialChar ~
10244 \SpecialChar ~
10245 \SpecialChar ~
10246 \SpecialChar ~
10247 \SpecialChar ~
10248 \SpecialChar ~
10249 ...
10250 \layout Verse
10251
10252
10253 \family typewriter 
10254 \SpecialChar ~
10255 \SpecialChar ~
10256 \SpecialChar ~
10257 \SpecialChar ~
10258 \SpecialChar ~
10259 \SpecialChar ~
10260 \SpecialChar ~
10261 \SpecialChar ~
10262 \SpecialChar ~
10263 \SpecialChar ~
10264 \SpecialChar ~
10265 \SpecialChar ~
10266 \SpecialChar ~
10267 \SpecialChar ~
10268 \SpecialChar ~
10269 \SpecialChar ~
10270 \SpecialChar ~
10271 \SpecialChar ~
10272 \SpecialChar ~
10273 \SpecialChar ~
10274 \SpecialChar ~
10275 \SpecialChar ~
10276 \SpecialChar ~
10277 \SpecialChar ~
10278 \SpecialChar ~
10279 \SpecialChar ~
10280 \SpecialChar ~
10281 \SpecialChar ~
10282 \SpecialChar ~
10283 \SpecialChar ~
10284 \SpecialChar ~
10285 \SpecialChar ~
10286 \SpecialChar ~
10287 EA = EA_SAVE;
10288 \layout Standard
10289
10290 On other architectures which have seperate opcodes for enabling and disabling
10291  interrupts you might want to make use of defines with inline assembly
10292 \begin_inset LatexCommand \index{Assembler routines}
10293
10294 \end_inset 
10295
10296  (HC08):
10297 \layout Verse
10298
10299
10300 \family typewriter 
10301 #define CLI _asm
10302 \begin_inset LatexCommand \index{\_asm}
10303
10304 \end_inset 
10305
10306 \SpecialChar ~
10307 \SpecialChar ~
10308 cli\SpecialChar ~
10309 \SpecialChar ~
10310 _endasm
10311 \begin_inset LatexCommand \index{\_endasm}
10312
10313 \end_inset 
10314
10315
10316 \layout Verse
10317
10318
10319 \family typewriter 
10320 #define SEI _asm\SpecialChar ~
10321 \SpecialChar ~
10322 sei\SpecialChar ~
10323 \SpecialChar ~
10324 _endasm; 
10325 \layout Verse
10326
10327
10328 \family typewriter 
10329 ...
10330 \layout Standard
10331
10332 Note: it is sometimes sufficient to disable only a specific interrupt source
10333  like f.e.
10334  a timer or serial interrupt by manipulating an 
10335 \emph on 
10336 interrupt mask
10337 \begin_inset LatexCommand \index{interrupt mask}
10338
10339 \end_inset 
10340
10341
10342 \emph default 
10343  register.
10344  
10345 \layout Standard
10346
10347 Usually the time during which interrupts are disabled should be kept as
10348  short as possible.
10349  This minimizes both 
10350 \emph on 
10351 interrupt latency
10352 \emph default 
10353
10354 \begin_inset LatexCommand \index{interrupt latency}
10355
10356 \end_inset 
10357
10358  (the time between the occurrence of the interrupt and the execution of
10359  the first code in the interrupt routine) and 
10360 \emph on 
10361 interrupt jitter
10362 \emph default 
10363
10364 \begin_inset LatexCommand \index{interrupt jitter}
10365
10366 \end_inset 
10367
10368  (the difference between the shortest and the longest interrupt latency).
10369  These really are something different, f.e.
10370  a serial interrupt has to be served before its buffer overruns so it cares
10371  for the maximum interrupt latency, whereas it does not care about jitter.
10372  On a loudspeaker driven via a digital to analog converter which is fed
10373  by an interrupt a latency of a few milliseconds might be tolerable, whereas
10374  a much smaller jitter will be very audible.
10375 \layout Standard
10376
10377 You can reenable interrupts within an interrupt routine and on some architecture
10378 s you can make use of two (or more) levels of 
10379 \emph on 
10380 interrupt priorities
10381 \emph default 
10382
10383 \begin_inset LatexCommand \index{interrupt priority}
10384
10385 \end_inset 
10386
10387 .
10388  On some architectures which don't support interrupt priorities these can
10389  be implemented by manipulating the interrupt mask and reenabling interrupts
10390  within the interrupt routine.
10391  Don't add complexity unless you have to.
10392  
10393 \layout Section
10394
10395 Functions using private register banks
10396 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
10397
10398 \end_inset 
10399
10400  (mcs51/ds390)
10401 \layout Standard
10402
10403 Some architectures have support for quickly changing register sets.
10404  SDCC supports this feature with the 
10405 \emph on 
10406 using
10407 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10408
10409 \end_inset 
10410
10411
10412 \emph default 
10413  attribute (which tells the compiler to use a register bank
10414 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10415
10416 \end_inset 
10417
10418  other than the default bank zero).
10419  It should only be applied to 
10420 \emph on 
10421 interrupt
10422 \begin_inset LatexCommand \index{interrupt}
10423
10424 \end_inset 
10425
10426
10427 \emph default 
10428  functions (see footnote below).
10429  This will in most circumstances make the generated ISR code more efficient
10430  since it will not have to save registers on the stack.
10431 \layout Standard
10432
10433 The 
10434 \emph on 
10435 using
10436 \emph default 
10437  attribute will have no effect on the generated code for a 
10438 \emph on 
10439 non-interrupt
10440 \emph default 
10441  function (but may occasionally be useful anyway
10442 \begin_inset Foot
10443 collapsed false
10444
10445 \layout Standard
10446
10447 possible exception: if a function is called ONLY from 'interrupt' functions
10448  using a particular bank, it can be declared with the same 'using' attribute
10449  as the calling 'interrupt' functions.
10450  For instance, if you have several ISRs using bank one, and all of them
10451  call memcpy(), it might make sense to create a specialized version of memcpy()
10452  'using 1', since this would prevent the ISR from having to save bank zero
10453  to the stack on entry and switch to bank zero before calling the function
10454 \end_inset 
10455
10456 ).
10457 \newline 
10458
10459 \emph on 
10460 (pending: I don't think this has been done yet)
10461 \layout Standard
10462
10463 An 
10464 \emph on 
10465 interrupt
10466 \emph default 
10467  function using a non-zero bank will assume that it can trash that register
10468  bank, and will not save it.
10469  Since high-priority interrupts
10470 \begin_inset LatexCommand \index{interrupt priority}
10471
10472 \end_inset 
10473
10474  can interrupt low-priority ones on the 8051 and friends, this means that
10475  if a high-priority ISR 
10476 \emph on 
10477 using
10478 \emph default 
10479  a particular bank occurs while processing a low-priority ISR 
10480 \emph on 
10481 using
10482 \emph default 
10483  the same bank, terrible and bad things can happen.
10484  To prevent this, no single register bank should be 
10485 \emph on 
10486 used
10487 \emph default 
10488  by both a high priority and a low priority ISR.
10489  This is probably most easily done by having all high priority ISRs use
10490  one bank and all low priority ISRs use another.
10491  If you have an ISR which can change priority at runtime, you're on your
10492  own: I suggest using the default bank zero and taking the small performance
10493  hit.
10494 \layout Standard
10495
10496 It is most efficient if your ISR calls no other functions.
10497  If your ISR must call other functions, it is most efficient if those functions
10498  use the same bank as the ISR (see note 1 below); the next best is if the
10499  called functions use bank zero.
10500  It is very inefficient to call a function using a different, non-zero bank
10501  from an ISR.
10502  
10503 \layout Section
10504
10505 Startup Code
10506 \begin_inset LatexCommand \label{sub:Startup-Code}
10507
10508 \end_inset 
10509
10510
10511 \begin_inset LatexCommand \index{Startup code}
10512
10513 \end_inset 
10514
10515
10516 \layout Subsection
10517
10518 MCS51/DS390 Startup Code
10519 \layout Standard
10520
10521 The compiler inserts a call to the C routine 
10522 \emph on 
10523 _sdcc_external_startup()
10524 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
10525
10526 \end_inset 
10527
10528
10529 \series bold 
10530 \emph default 
10531  
10532 \series default 
10533 at the start of the CODE area.
10534  This routine is in the runtime library
10535 \begin_inset LatexCommand \index{Runtime library}
10536
10537 \end_inset 
10538
10539 .
10540  By default this routine returns 0, if this routine returns a non-zero value,
10541  the static & global variable initialization will be skipped and the function
10542  main will be invoked.
10543  Otherwise static & global variables will be initialized before the function
10544  main is invoked.
10545  You could add a 
10546 \emph on 
10547 _sdcc_external_startup()
10548 \emph default 
10549  routine to your program to override the default if you need to setup hardware
10550  or perform some other critical operation prior to static & global variable
10551  initialization.
10552  On some mcs51 variants xdata has to be explicitly enabled before it can
10553  be accessed, this is the place to do it.
10554  See also the compiler option 
10555 \emph on 
10556 -
10557 \begin_inset ERT
10558 status Collapsed
10559
10560 \layout Standard
10561
10562 \backslash 
10563 /
10564 \end_inset 
10565
10566 -no-xinit
10567 \emph default 
10568 -
10569 \emph on 
10570 opt
10571 \emph default 
10572
10573 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
10574
10575 \end_inset 
10576
10577  and section 
10578 \begin_inset LatexCommand \ref{sub:MCS51-variants}
10579
10580 \end_inset 
10581
10582 \SpecialChar ~
10583 about MCS51-variants.
10584 \layout Subsection
10585
10586 HC08 Startup Code
10587 \layout Standard
10588
10589 The HC08 startup code follows the same scheme as the MCS51 startup code.
10590 \layout Subsection
10591
10592 Z80 Startup Code
10593 \layout Standard
10594
10595 On the Z80 the startup code is inserted by linking with crt0.o which is generated
10596  from sdcc/device/lib/z80/crt0.s.
10597  If you need a different startup code you can use the compiler option 
10598 \emph on 
10599 -
10600 \series bold 
10601 \emph default 
10602
10603 \begin_inset ERT
10604 status Collapsed
10605
10606 \layout Standard
10607
10608 \backslash 
10609 /
10610 \end_inset 
10611
10612
10613 \series default 
10614 \emph on 
10615 -no-std-crt0
10616 \emph default 
10617
10618 \begin_inset LatexCommand \index{-\/-no-std-crt0}
10619
10620 \end_inset 
10621
10622  and provide your own crt0.o.
10623  
10624 \layout Section
10625
10626 Inline Assembler Code
10627 \begin_inset LatexCommand \index{Assembler routines}
10628
10629 \end_inset 
10630
10631
10632 \layout Subsection
10633
10634 A Step by Step Introduction
10635 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
10636
10637 \end_inset 
10638
10639
10640 \layout Standard
10641
10642 Starting from a small snippet of c-code this example shows for the MCS51
10643  how to use inline assembly, access variables, a function parameter and
10644  an array in xdata memory.
10645  The example uses an MCS51 here but is easily adapted for other architectures.
10646  This is a buffer routine which should be optimized:
10647 \layout Verse
10648
10649
10650 \family typewriter 
10651 \size footnotesize 
10652 unsigned char far
10653 \begin_inset LatexCommand \index{far (storage class)}
10654
10655 \end_inset 
10656
10657  at
10658 \begin_inset LatexCommand \index{at}
10659
10660 \end_inset 
10661
10662  0x7f00 buf[0x100];
10663 \begin_inset LatexCommand \index{Aligned array}
10664
10665 \end_inset 
10666
10667
10668 \newline 
10669 unsigned char head,tail;
10670 \newline 
10671
10672 \newline 
10673 void to_buffer( unsigned char c ) 
10674 \newline 
10675 {
10676 \newline 
10677 \SpecialChar ~
10678 \SpecialChar ~
10679 \SpecialChar ~
10680 \SpecialChar ~
10681 if( head != tail-1 ) 
10682 \newline 
10683 \SpecialChar ~
10684 \SpecialChar ~
10685 \SpecialChar ~
10686 \SpecialChar ~
10687 \SpecialChar ~
10688 \SpecialChar ~
10689 \SpecialChar ~
10690 \SpecialChar ~
10691 buf[ head++ ] = c; 
10692 \newline 
10693
10694 \layout Standard
10695
10696 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
10697  then a corresponding buffer.asm file is generated.
10698  We define a new function 
10699 \family typewriter 
10700 to_buffer_asm()
10701 \family default 
10702  in file buffer.c in which we cut and paste the generated code, removing
10703  unwanted comments and some ':'.
10704  Then add 
10705 \begin_inset Quotes sld
10706 \end_inset 
10707
10708 _asm
10709 \begin_inset Quotes srd
10710 \end_inset 
10711
10712  and 
10713 \begin_inset Quotes sld
10714 \end_inset 
10715
10716 _endasm;
10717 \begin_inset Quotes srd
10718 \end_inset 
10719
10720  to the beginning and the end of the function body:
10721 \layout Verse
10722
10723
10724 \family typewriter 
10725 \size footnotesize 
10726 /* With a cut and paste from the .asm file, we have something to start with.
10727 \newline 
10728 \SpecialChar ~
10729 \SpecialChar ~
10730 \SpecialChar ~
10731 The function is not yet OK! (registers aren't saved) */ 
10732 \newline 
10733 void to_buffer_asm( unsigned char c ) 
10734 \newline 
10735
10736 \newline 
10737 \SpecialChar ~
10738 \SpecialChar ~
10739 \SpecialChar ~
10740 \SpecialChar ~
10741 _asm
10742 \begin_inset LatexCommand \index{\_asm}
10743
10744 \end_inset 
10745
10746
10747 \newline 
10748 \SpecialChar ~
10749 \SpecialChar ~
10750 \SpecialChar ~
10751 \SpecialChar ~
10752 mov\SpecialChar ~
10753 \SpecialChar ~
10754 r2,dpl 
10755 \newline 
10756 ;buffer.c if( head != tail-1 ) 
10757 \newline 
10758 \SpecialChar ~
10759 \SpecialChar ~
10760 \SpecialChar ~
10761 \SpecialChar ~
10762 mov\SpecialChar ~
10763 \SpecialChar ~
10764 a,_tail 
10765 \newline 
10766 \SpecialChar ~
10767 \SpecialChar ~
10768 \SpecialChar ~
10769 \SpecialChar ~
10770 dec\SpecialChar ~
10771 \SpecialChar ~
10772
10773 \newline 
10774 \SpecialChar ~
10775 \SpecialChar ~
10776 \SpecialChar ~
10777 \SpecialChar ~
10778 mov\SpecialChar ~
10779 \SpecialChar ~
10780 r3,a 
10781 \newline 
10782 \SpecialChar ~
10783 \SpecialChar ~
10784 \SpecialChar ~
10785 \SpecialChar ~
10786 mov\SpecialChar ~
10787 \SpecialChar ~
10788 a,_head 
10789 \newline 
10790 \SpecialChar ~
10791 \SpecialChar ~
10792 \SpecialChar ~
10793 \SpecialChar ~
10794 cjne a,ar3,00106$ 
10795 \newline 
10796 \SpecialChar ~
10797 \SpecialChar ~
10798 \SpecialChar ~
10799 \SpecialChar ~
10800 ret
10801 \newline 
10802 00106$: 
10803 \newline 
10804 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
10805 \begin_inset LatexCommand \index{Aligned array}
10806
10807 \end_inset 
10808
10809
10810 \newline 
10811 \SpecialChar ~
10812 \SpecialChar ~
10813 \SpecialChar ~
10814 \SpecialChar ~
10815 mov\SpecialChar ~
10816 \SpecialChar ~
10817 r3,_head 
10818 \newline 
10819 \SpecialChar ~
10820 \SpecialChar ~
10821 \SpecialChar ~
10822 \SpecialChar ~
10823 inc\SpecialChar ~
10824 \SpecialChar ~
10825 _head 
10826 \newline 
10827 \SpecialChar ~
10828 \SpecialChar ~
10829 \SpecialChar ~
10830 \SpecialChar ~
10831 mov\SpecialChar ~
10832 \SpecialChar ~
10833 dpl,r3 
10834 \newline 
10835 \SpecialChar ~
10836 \SpecialChar ~
10837 \SpecialChar ~
10838 \SpecialChar ~
10839 mov\SpecialChar ~
10840 \SpecialChar ~
10841 dph,#(_buf >> 8) 
10842 \newline 
10843 \SpecialChar ~
10844 \SpecialChar ~
10845 \SpecialChar ~
10846 \SpecialChar ~
10847 mov\SpecialChar ~
10848 \SpecialChar ~
10849 a,r2 
10850 \newline 
10851 \SpecialChar ~
10852 \SpecialChar ~
10853 \SpecialChar ~
10854 \SpecialChar ~
10855 movx @dptr,a 
10856 \newline 
10857 00103$: 
10858 \newline 
10859 \SpecialChar ~
10860 \SpecialChar ~
10861 \SpecialChar ~
10862 \SpecialChar ~
10863 ret
10864 \newline 
10865 \SpecialChar ~
10866 \SpecialChar ~
10867 \SpecialChar ~
10868 \SpecialChar ~
10869 _endasm;
10870 \newline 
10871
10872 \layout Standard
10873
10874 The new file buffer.c should compile with only one warning about the unreferenced
10875  function argument 'c'.
10876  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
10877  (1) and finally have:
10878 \layout Verse
10879
10880
10881 \family typewriter 
10882 \size footnotesize 
10883 unsigned char far at 0x7f00 buf[0x100];
10884 \newline 
10885 unsigned char head,tail;
10886 \newline 
10887 #define USE_ASSEMBLY (1)
10888 \newline 
10889
10890 \newline 
10891 #if USE_ASSEMBLY
10892 \newline 
10893
10894 \newline 
10895 void to_buffer( unsigned char c )
10896 \newline 
10897 {
10898 \newline 
10899 \SpecialChar ~
10900 \SpecialChar ~
10901 \SpecialChar ~
10902 \SpecialChar ~
10903 if( head != tail-1 )
10904 \newline 
10905 \SpecialChar ~
10906 \SpecialChar ~
10907 \SpecialChar ~
10908 \SpecialChar ~
10909 \SpecialChar ~
10910 \SpecialChar ~
10911 \SpecialChar ~
10912 \SpecialChar ~
10913 buf[ head++ ] = c;
10914 \newline 
10915 }
10916 \newline 
10917
10918 \newline 
10919 #else
10920 \newline 
10921
10922 \newline 
10923 void to_buffer( unsigned char c )
10924 \newline 
10925 {
10926 \newline 
10927 \SpecialChar ~
10928 \SpecialChar ~
10929 \SpecialChar ~
10930 \SpecialChar ~
10931 c; // to avoid warning: unreferenced function argument
10932 \newline 
10933 \SpecialChar ~
10934 \SpecialChar ~
10935 \SpecialChar ~
10936 \SpecialChar ~
10937 _asm
10938 \begin_inset LatexCommand \index{\_asm}
10939
10940 \end_inset 
10941
10942
10943 \newline 
10944 \SpecialChar ~
10945 \SpecialChar ~
10946 \SpecialChar ~
10947 \SpecialChar ~
10948 \SpecialChar ~
10949 \SpecialChar ~
10950 \SpecialChar ~
10951 \SpecialChar ~
10952 ; save used registers here.
10953  
10954 \newline 
10955 \SpecialChar ~
10956 \SpecialChar ~
10957 \SpecialChar ~
10958 \SpecialChar ~
10959 \SpecialChar ~
10960 \SpecialChar ~
10961 \SpecialChar ~
10962 \SpecialChar ~
10963 ; If we were still using r2,r3 we would have to push them here.
10964  
10965 \newline 
10966 ; if( head != tail-1 )
10967 \newline 
10968 \SpecialChar ~
10969 \SpecialChar ~
10970 \SpecialChar ~
10971 \SpecialChar ~
10972 \SpecialChar ~
10973 \SpecialChar ~
10974 \SpecialChar ~
10975 \SpecialChar ~
10976 mov\SpecialChar ~
10977  a,_tail
10978 \newline 
10979 \SpecialChar ~
10980 \SpecialChar ~
10981 \SpecialChar ~
10982 \SpecialChar ~
10983 \SpecialChar ~
10984 \SpecialChar ~
10985 \SpecialChar ~
10986 \SpecialChar ~
10987 dec\SpecialChar ~
10988  a
10989 \newline 
10990 \SpecialChar ~
10991 \SpecialChar ~
10992 \SpecialChar ~
10993 \SpecialChar ~
10994 \SpecialChar ~
10995 \SpecialChar ~
10996 \SpecialChar ~
10997 \SpecialChar ~
10998 xrl\SpecialChar ~
10999  a,_head
11000 \newline 
11001 \SpecialChar ~
11002 \SpecialChar ~
11003 \SpecialChar ~
11004 \SpecialChar ~
11005 \SpecialChar ~
11006 \SpecialChar ~
11007 \SpecialChar ~
11008 \SpecialChar ~
11009 ; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
11010 \newline 
11011 \SpecialChar ~
11012 \SpecialChar ~
11013 \SpecialChar ~
11014 \SpecialChar ~
11015 \SpecialChar ~
11016 \SpecialChar ~
11017 \SpecialChar ~
11018 \SpecialChar ~
11019 jz\SpecialChar ~
11020 \SpecialChar ~
11021  t_b_end$
11022 \newline 
11023 \SpecialChar ~
11024 \SpecialChar ~
11025 \SpecialChar ~
11026 \SpecialChar ~
11027 \SpecialChar ~
11028 \SpecialChar ~
11029 \SpecialChar ~
11030 \SpecialChar ~
11031 ;
11032 \newline 
11033 ; buf[ head++ ] = c;
11034 \newline 
11035 \SpecialChar ~
11036 \SpecialChar ~
11037 \SpecialChar ~
11038 \SpecialChar ~
11039 \SpecialChar ~
11040 \SpecialChar ~
11041 \SpecialChar ~
11042 \SpecialChar ~
11043 mov\SpecialChar ~
11044  a,dpl \SpecialChar ~
11045 \SpecialChar ~
11046 \SpecialChar ~
11047 \SpecialChar ~
11048 \SpecialChar ~
11049 \SpecialChar ~
11050 \SpecialChar ~
11051 ; dpl holds lower byte of function argument
11052 \newline 
11053 \SpecialChar ~
11054 \SpecialChar ~
11055 \SpecialChar ~
11056 \SpecialChar ~
11057 \SpecialChar ~
11058 \SpecialChar ~
11059 \SpecialChar ~
11060 \SpecialChar ~
11061 mov\SpecialChar ~
11062  dpl,_head \SpecialChar ~
11063 \SpecialChar ~
11064 \SpecialChar ~
11065 ; buf is 0x100 byte aligned so head can be used directly
11066 \newline 
11067 \SpecialChar ~
11068 \SpecialChar ~
11069 \SpecialChar ~
11070 \SpecialChar ~
11071 \SpecialChar ~
11072 \SpecialChar ~
11073 \SpecialChar ~
11074 \SpecialChar ~
11075 mov\SpecialChar ~
11076  dph,#(_buf>>8)
11077 \newline 
11078 \SpecialChar ~
11079 \SpecialChar ~
11080 \SpecialChar ~
11081 \SpecialChar ~
11082 \SpecialChar ~
11083 \SpecialChar ~
11084 \SpecialChar ~
11085 \SpecialChar ~
11086 movx @dptr,a
11087 \newline 
11088 \SpecialChar ~
11089 \SpecialChar ~
11090 \SpecialChar ~
11091 \SpecialChar ~
11092 \SpecialChar ~
11093 \SpecialChar ~
11094 \SpecialChar ~
11095 \SpecialChar ~
11096 inc \SpecialChar ~
11097 _head
11098 \newline 
11099 \SpecialChar ~
11100 \SpecialChar ~
11101 \SpecialChar ~
11102 \SpecialChar ~
11103 \SpecialChar ~
11104 \SpecialChar ~
11105 \SpecialChar ~
11106 \SpecialChar ~
11107 ; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)
11108 \newline 
11109 t_b_end$:
11110 \newline 
11111 \SpecialChar ~
11112 \SpecialChar ~
11113 \SpecialChar ~
11114 \SpecialChar ~
11115 \SpecialChar ~
11116 \SpecialChar ~
11117 \SpecialChar ~
11118 \SpecialChar ~
11119 ; restore used registers here 
11120 \newline 
11121 \SpecialChar ~
11122 \SpecialChar ~
11123 \SpecialChar ~
11124 \SpecialChar ~
11125 _endasm;
11126 \newline 
11127 }
11128 \newline 
11129 #endif
11130 \layout Standard
11131
11132 The inline assembler code can contain any valid code understood by the assembler
11133 , this includes any assembler directives and comment lines
11134 \begin_inset Foot
11135 collapsed false
11136
11137 \layout Standard
11138
11139 The assembler does not like some characters like ':' or ''' in comments.
11140  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
11141 \end_inset 
11142
11143 .
11144  The compiler does not do any validation of the code within the 
11145 \family typewriter 
11146 _asm
11147 \begin_inset LatexCommand \index{\_asm}
11148
11149 \end_inset 
11150
11151  ...
11152  _endasm;
11153 \family default 
11154  keyword pair.
11155  Specifically it will not know which registers are used and thus register
11156  pushing/popping
11157 \begin_inset LatexCommand \index{push/pop}
11158
11159 \end_inset 
11160
11161  has to be done manually.
11162  
11163 \layout Standard
11164
11165 It is recommended that each assembly instruction (including labels) be placed
11166  in a separate line (as the example shows).
11167  When the -
11168 \begin_inset ERT
11169 status Collapsed
11170
11171 \layout Standard
11172
11173 \backslash 
11174 /
11175 \end_inset 
11176
11177 -
11178 \emph on 
11179 peep-asm
11180 \begin_inset LatexCommand \index{-\/-peep-asm}
11181
11182 \end_inset 
11183
11184
11185 \emph default 
11186  command line option is used, the inline assembler code will be passed through
11187  the peephole optimizer
11188 \begin_inset LatexCommand \index{Peephole optimizer}
11189
11190 \end_inset 
11191
11192 .
11193  There are only a few (if any) cases where this option makes sense, it might
11194  cause some unexpected changes in the inline assembler code.
11195  Please go through the peephole optimizer rules defined in file 
11196 \emph on 
11197 SDCCpeeph.def
11198 \emph default 
11199  before using this option.
11200 \layout Subsection
11201
11202 Naked Functions
11203 \begin_inset LatexCommand \label{sub:Naked-Functions}
11204
11205 \end_inset 
11206
11207
11208 \begin_inset LatexCommand \index{Naked functions}
11209
11210 \end_inset 
11211
11212
11213 \layout Standard
11214
11215 A special keyword may be associated with a function declaring it as 
11216 \emph on 
11217 _naked
11218 \begin_inset LatexCommand \index{\_naked}
11219
11220 \end_inset 
11221
11222 .
11223  
11224 \emph default 
11225 The 
11226 \emph on 
11227 _naked
11228 \emph default 
11229  function modifier attribute prevents the compiler from generating prologue
11230 \begin_inset LatexCommand \index{function prologue}
11231
11232 \end_inset 
11233
11234  and epilogue
11235 \begin_inset LatexCommand \index{function epilogue}
11236
11237 \end_inset 
11238
11239  code for that function.
11240  This means that the user is entirely responsible for such things as saving
11241  any registers that may need to be preserved, selecting the proper register
11242  bank, generating the 
11243 \emph on 
11244 return
11245 \emph default 
11246  instruction at the end, etc.
11247  Practically, this means that the contents of the function must be written
11248  in inline assembler.
11249  This is particularly useful for interrupt functions, which can have a large
11250  (and often unnecessary) prologue/epilogue.
11251  For example, compare the code generated by these two functions:
11252 \layout Verse
11253
11254
11255 \family typewriter 
11256 volatile
11257 \begin_inset LatexCommand \index{volatile}
11258
11259 \end_inset 
11260
11261  data unsigned char counter;
11262 \newline 
11263
11264 \newline 
11265 void simpleInterrupt(void) interrupt
11266 \begin_inset LatexCommand \index{interrupt}
11267
11268 \end_inset 
11269
11270  1
11271 \newline 
11272 {
11273 \newline 
11274 \SpecialChar ~
11275 \SpecialChar ~
11276 \SpecialChar ~
11277 \SpecialChar ~
11278 counter++;
11279 \newline 
11280 }
11281 \newline 
11282
11283 \newline 
11284 void nakedInterrupt(void) interrupt 2 _naked
11285 \newline 
11286 {
11287 \newline 
11288 \SpecialChar ~
11289 \SpecialChar ~
11290 \SpecialChar ~
11291 \SpecialChar ~
11292 _asm
11293 \begin_inset LatexCommand \index{\_asm}
11294
11295 \end_inset 
11296
11297
11298 \newline 
11299 \SpecialChar ~
11300 \SpecialChar ~
11301 \SpecialChar ~
11302 \SpecialChar ~
11303 \SpecialChar ~
11304 \SpecialChar ~
11305 inc\SpecialChar ~
11306 \SpecialChar ~
11307 \SpecialChar ~
11308 \SpecialChar ~
11309 \SpecialChar ~
11310 _counter ; does not change flags, no need to save psw
11311 \newline 
11312 \SpecialChar ~
11313 \SpecialChar ~
11314 \SpecialChar ~
11315 \SpecialChar ~
11316 \SpecialChar ~
11317 \SpecialChar ~
11318 reti\SpecialChar ~
11319 \SpecialChar ~
11320 \SpecialChar ~
11321 \SpecialChar ~
11322 ; MUST explicitly include ret or reti in _naked function.
11323 \newline 
11324 \SpecialChar ~
11325 \SpecialChar ~
11326 \SpecialChar ~
11327 \SpecialChar ~
11328 _endasm
11329 \begin_inset LatexCommand \index{\_endasm}
11330
11331 \end_inset 
11332
11333 ;
11334 \newline 
11335 }
11336 \layout Standard
11337
11338 For an 8051 target, the generated simpleInterrupt looks like:
11339 \layout Verse
11340
11341
11342 \family typewriter 
11343 _simpleInterrupt:
11344 \newline 
11345 \SpecialChar ~
11346 \SpecialChar ~
11347 \SpecialChar ~
11348 \SpecialChar ~
11349 push\SpecialChar ~
11350 \SpecialChar ~
11351 \SpecialChar ~
11352 \SpecialChar ~
11353 acc
11354 \newline 
11355 \SpecialChar ~
11356 \SpecialChar ~
11357 \SpecialChar ~
11358 \SpecialChar ~
11359 push\SpecialChar ~
11360 \SpecialChar ~
11361 \SpecialChar ~
11362 \SpecialChar ~
11363 b
11364 \newline 
11365 \SpecialChar ~
11366 \SpecialChar ~
11367 \SpecialChar ~
11368 \SpecialChar ~
11369 push\SpecialChar ~
11370 \SpecialChar ~
11371 \SpecialChar ~
11372 \SpecialChar ~
11373 dpl
11374 \newline 
11375 \SpecialChar ~
11376 \SpecialChar ~
11377 \SpecialChar ~
11378 \SpecialChar ~
11379 push\SpecialChar ~
11380 \SpecialChar ~
11381 \SpecialChar ~
11382 \SpecialChar ~
11383 dph
11384 \newline 
11385 \SpecialChar ~
11386 \SpecialChar ~
11387 \SpecialChar ~
11388 \SpecialChar ~
11389 push\SpecialChar ~
11390 \SpecialChar ~
11391 \SpecialChar ~
11392 \SpecialChar ~
11393 psw
11394 \newline 
11395 \SpecialChar ~
11396 \SpecialChar ~
11397 \SpecialChar ~
11398 \SpecialChar ~
11399 mov\SpecialChar ~
11400 \SpecialChar ~
11401 \SpecialChar ~
11402 \SpecialChar ~
11403 \SpecialChar ~
11404 psw,#0x00
11405 \newline 
11406 \SpecialChar ~
11407 \SpecialChar ~
11408 \SpecialChar ~
11409 \SpecialChar ~
11410 inc\SpecialChar ~
11411 \SpecialChar ~
11412 \SpecialChar ~
11413 \SpecialChar ~
11414 \SpecialChar ~
11415 _counter
11416 \newline 
11417 \SpecialChar ~
11418 \SpecialChar ~
11419 \SpecialChar ~
11420 \SpecialChar ~
11421 pop\SpecialChar ~
11422 \SpecialChar ~
11423 \SpecialChar ~
11424 \SpecialChar ~
11425 \SpecialChar ~
11426 psw
11427 \newline 
11428 \SpecialChar ~
11429 \SpecialChar ~
11430 \SpecialChar ~
11431 \SpecialChar ~
11432 pop\SpecialChar ~
11433 \SpecialChar ~
11434 \SpecialChar ~
11435 \SpecialChar ~
11436 \SpecialChar ~
11437 dph
11438 \newline 
11439 \SpecialChar ~
11440 \SpecialChar ~
11441 \SpecialChar ~
11442 \SpecialChar ~
11443 pop\SpecialChar ~
11444 \SpecialChar ~
11445 \SpecialChar ~
11446 \SpecialChar ~
11447 \SpecialChar ~
11448 dpl
11449 \newline 
11450 \SpecialChar ~
11451 \SpecialChar ~
11452 \SpecialChar ~
11453 \SpecialChar ~
11454 pop\SpecialChar ~
11455 \SpecialChar ~
11456 \SpecialChar ~
11457 \SpecialChar ~
11458 \SpecialChar ~
11459 b
11460 \newline 
11461 \SpecialChar ~
11462 \SpecialChar ~
11463 \SpecialChar ~
11464 \SpecialChar ~
11465 pop\SpecialChar ~
11466 \SpecialChar ~
11467 \SpecialChar ~
11468 \SpecialChar ~
11469 \SpecialChar ~
11470 acc
11471 \newline 
11472 \SpecialChar ~
11473 \SpecialChar ~
11474 \SpecialChar ~
11475 \SpecialChar ~
11476 reti
11477 \layout Standard
11478
11479 whereas nakedInterrupt looks like:
11480 \layout Verse
11481
11482
11483 \family typewriter 
11484 _nakedInterrupt:
11485 \newline 
11486 \SpecialChar ~
11487 \SpecialChar ~
11488 \SpecialChar ~
11489 \SpecialChar ~
11490 inc\SpecialChar ~
11491 \SpecialChar ~
11492 \SpecialChar ~
11493 \SpecialChar ~
11494 _counter ; does not change flags, no need to save psw
11495 \newline 
11496 \SpecialChar ~
11497 \SpecialChar ~
11498 \SpecialChar ~
11499 \SpecialChar ~
11500 reti\SpecialChar ~
11501 \SpecialChar ~
11502 \SpecialChar ~
11503 \SpecialChar ~
11504 \SpecialChar ~
11505 \SpecialChar ~
11506 \SpecialChar ~
11507 \SpecialChar ~
11508 \SpecialChar ~
11509 \SpecialChar ~
11510 \SpecialChar ~
11511 \SpecialChar ~
11512 ; MUST explicitly include ret or reti in _naked function
11513 \layout Standard
11514
11515 The related directive #pragma exclude
11516 \begin_inset LatexCommand \index{\#pragma exclude}
11517
11518 \end_inset 
11519
11520  allows a more fine grained control over pushing & popping
11521 \begin_inset LatexCommand \index{push/pop}
11522
11523 \end_inset 
11524
11525  the registers.
11526 \layout Standard
11527
11528 While there is nothing preventing you from writing C code inside a 
11529 \family typewriter 
11530 _naked
11531 \family default 
11532  function, there are many ways to shoot yourself in the foot doing this,
11533  and it is recommended that you stick to inline assembler.
11534 \layout Subsection
11535
11536 Use of Labels within Inline Assembler
11537 \layout Standard
11538
11539 SDCC allows the use of in-line assembler with a few restrictions regarding
11540  labels.
11541  In older versions of the compiler all labels defined within inline assembler
11542  code 
11543 \emph on 
11544 had to be
11545 \emph default 
11546  of the form 
11547 \emph on 
11548 nnnnn$
11549 \emph default 
11550  where nnnn is a number less than 100 (which implies a limit of utmost 100
11551  inline assembler labels 
11552 \emph on 
11553 per function
11554 \emph default 
11555 \noun on 
11556 )
11557 \noun default 
11558 .
11559  
11560 \layout Verse
11561
11562
11563 \family typewriter 
11564 _asm
11565 \begin_inset LatexCommand \index{\_asm}
11566
11567 \end_inset 
11568
11569  
11570 \newline 
11571 \SpecialChar ~
11572 \SpecialChar ~
11573 \SpecialChar ~
11574 \SpecialChar ~
11575 mov\SpecialChar ~
11576 \SpecialChar ~
11577 \SpecialChar ~
11578 \SpecialChar ~
11579 \SpecialChar ~
11580 b,#10 
11581 \newline 
11582 00001$: 
11583 \newline 
11584 \SpecialChar ~
11585 \SpecialChar ~
11586 \SpecialChar ~
11587 \SpecialChar ~
11588 djnz\SpecialChar ~
11589 \SpecialChar ~
11590 \SpecialChar ~
11591 \SpecialChar ~
11592 b,00001$ 
11593 \newline 
11594 _endasm
11595 \begin_inset LatexCommand \index{\_endasm}
11596
11597 \end_inset 
11598
11599  ;
11600 \layout Standard
11601
11602 Inline assembler code cannot reference any C-Labels, however it can reference
11603  labels
11604 \begin_inset LatexCommand \index{Labels}
11605
11606 \end_inset 
11607
11608  defined by the inline assembler, e.g.:
11609 \layout Verse
11610
11611
11612 \family typewriter 
11613 foo() { 
11614 \newline 
11615 \SpecialChar ~
11616 \SpecialChar ~
11617 \SpecialChar ~
11618 \SpecialChar ~
11619 /* some c code */ 
11620 \newline 
11621 \SpecialChar ~
11622 \SpecialChar ~
11623 \SpecialChar ~
11624 \SpecialChar ~
11625 _asm 
11626 \newline 
11627 \SpecialChar ~
11628 \SpecialChar ~
11629 \SpecialChar ~
11630 \SpecialChar ~
11631 \SpecialChar ~
11632 \SpecialChar ~
11633 ; some assembler code 
11634 \newline 
11635 \SpecialChar ~
11636 \SpecialChar ~
11637 \SpecialChar ~
11638 \SpecialChar ~
11639 \SpecialChar ~
11640 \SpecialChar ~
11641 ljmp $0003 
11642 \newline 
11643 \SpecialChar ~
11644 \SpecialChar ~
11645 \SpecialChar ~
11646 \SpecialChar ~
11647 _endasm; 
11648 \newline 
11649 \SpecialChar ~
11650 \SpecialChar ~
11651 \SpecialChar ~
11652 \SpecialChar ~
11653 /* some more c code */ 
11654 \newline 
11655 clabel:\SpecialChar ~
11656 \SpecialChar ~
11657 /* inline assembler cannot reference this label */ 
11658 \newline 
11659 \SpecialChar ~
11660 \SpecialChar ~
11661 \SpecialChar ~
11662 \SpecialChar ~
11663 _asm
11664 \newline 
11665 \SpecialChar ~
11666 \SpecialChar ~
11667 \SpecialChar ~
11668 \SpecialChar ~
11669 $0003: ;label (can be referenced by inline assembler only) 
11670 \newline 
11671 \SpecialChar ~
11672 \SpecialChar ~
11673 \SpecialChar ~
11674 \SpecialChar ~
11675 _endasm ; 
11676 \newline 
11677 \SpecialChar ~
11678 \SpecialChar ~
11679 \SpecialChar ~
11680 \SpecialChar ~
11681 /* some more c code */
11682 \newline 
11683 }
11684 \layout Standard
11685
11686 In other words inline assembly code can access labels defined in inline
11687  assembly within the scope of the function.
11688  The same goes the other way, i.e.
11689  labels defines in inline assembly can not be accessed by C statements.
11690 \layout Section
11691
11692 Interfacing with Assembler Code
11693 \begin_inset LatexCommand \index{Assembler routines}
11694
11695 \end_inset 
11696
11697
11698 \layout Subsection
11699
11700 Global Registers used for Parameter Passing
11701 \begin_inset LatexCommand \index{Parameter passing}
11702
11703 \end_inset 
11704
11705
11706 \layout Standard
11707
11708 The compiler always uses the global registers 
11709 \emph on 
11710 DPL, DPH
11711 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
11712
11713 \end_inset 
11714
11715
11716 \begin_inset LatexCommand \index{DPTR}
11717
11718 \end_inset 
11719
11720 , B
11721 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
11722
11723 \end_inset 
11724
11725  
11726 \emph default 
11727 and
11728 \emph on 
11729  ACC
11730 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
11731
11732 \end_inset 
11733
11734
11735 \emph default 
11736  to pass the first parameter to a routine.
11737  The second parameter onwards is either allocated on the stack (for reentrant
11738  routines or if -
11739 \begin_inset ERT
11740 status Collapsed
11741
11742 \layout Standard
11743
11744 \backslash 
11745 /
11746 \end_inset 
11747
11748 -stack-auto is used) or in data / xdata memory (depending on the memory
11749  model).
11750  
11751 \layout Subsection
11752
11753 Assembler Routine (non-reentrant)
11754 \layout Standard
11755
11756 In the following example
11757 \begin_inset LatexCommand \index{reentrant}
11758
11759 \end_inset 
11760
11761
11762 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
11763
11764 \end_inset 
11765
11766  the function c_func calls an assembler routine asm_func, which takes two
11767  parameters
11768 \begin_inset LatexCommand \index{function parameter}
11769
11770 \end_inset 
11771
11772 .
11773 \layout Verse
11774
11775
11776 \family typewriter 
11777 extern int asm_func(unsigned char, unsigned char);
11778 \newline 
11779
11780 \newline 
11781 int c_func (unsigned char i, unsigned char j)
11782 \newline 
11783 {
11784 \newline 
11785 \SpecialChar ~
11786 \SpecialChar ~
11787 \SpecialChar ~
11788 \SpecialChar ~
11789 return asm_func(i,j);
11790 \newline 
11791 }
11792 \newline 
11793
11794 \newline 
11795 int main()
11796 \newline 
11797 {
11798 \newline 
11799 \SpecialChar ~
11800 \SpecialChar ~
11801 \SpecialChar ~
11802 \SpecialChar ~
11803 return c_func(10,9);
11804 \newline 
11805 }
11806 \layout Standard
11807
11808 The corresponding assembler function is:
11809 \layout Verse
11810
11811
11812 \family typewriter 
11813 .globl _asm_func_PARM_2 
11814 \newline 
11815 \SpecialChar ~
11816 \SpecialChar ~
11817 \SpecialChar ~
11818 \SpecialChar ~
11819 \SpecialChar ~
11820 \SpecialChar ~
11821 \SpecialChar ~
11822 \SpecialChar ~
11823 .globl _asm_func 
11824 \newline 
11825 \SpecialChar ~
11826 \SpecialChar ~
11827 \SpecialChar ~
11828 \SpecialChar ~
11829 \SpecialChar ~
11830 \SpecialChar ~
11831 \SpecialChar ~
11832 \SpecialChar ~
11833 .area OSEG 
11834 \newline 
11835 _asm_func_PARM_2:
11836 \newline 
11837 \SpecialChar ~
11838 \SpecialChar ~
11839 \SpecialChar ~
11840 \SpecialChar ~
11841 \SpecialChar ~
11842 \SpecialChar ~
11843 \SpecialChar ~
11844 \SpecialChar ~
11845 .ds    1 
11846 \newline 
11847 \SpecialChar ~
11848 \SpecialChar ~
11849 \SpecialChar ~
11850 \SpecialChar ~
11851 \SpecialChar ~
11852 \SpecialChar ~
11853 \SpecialChar ~
11854 \SpecialChar ~
11855 .area CSEG 
11856 \newline 
11857 _asm_func: 
11858 \newline 
11859 \SpecialChar ~
11860 \SpecialChar ~
11861 \SpecialChar ~
11862 \SpecialChar ~
11863 \SpecialChar ~
11864 \SpecialChar ~
11865 \SpecialChar ~
11866 \SpecialChar ~
11867 mov\SpecialChar ~
11868 \SpecialChar ~
11869 \SpecialChar ~
11870 \SpecialChar ~
11871 a,dpl 
11872 \newline 
11873 \SpecialChar ~
11874 \SpecialChar ~
11875 \SpecialChar ~
11876 \SpecialChar ~
11877 \SpecialChar ~
11878 \SpecialChar ~
11879 \SpecialChar ~
11880 \SpecialChar ~
11881 add\SpecialChar ~
11882 \SpecialChar ~
11883 \SpecialChar ~
11884 \SpecialChar ~
11885 a,_asm_func_PARM_2 
11886 \newline 
11887 \SpecialChar ~
11888 \SpecialChar ~
11889 \SpecialChar ~
11890 \SpecialChar ~
11891 \SpecialChar ~
11892 \SpecialChar ~
11893 \SpecialChar ~
11894 \SpecialChar ~
11895 mov\SpecialChar ~
11896 \SpecialChar ~
11897 \SpecialChar ~
11898 \SpecialChar ~
11899 dpl,a 
11900 \newline 
11901 \SpecialChar ~
11902 \SpecialChar ~
11903 \SpecialChar ~
11904 \SpecialChar ~
11905 \SpecialChar ~
11906 \SpecialChar ~
11907 \SpecialChar ~
11908 \SpecialChar ~
11909 mov\SpecialChar ~
11910 \SpecialChar ~
11911 \SpecialChar ~
11912 \SpecialChar ~
11913 dph
11914 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
11915
11916 \end_inset 
11917
11918 ,#0x00 
11919 \newline 
11920 \SpecialChar ~
11921 \SpecialChar ~
11922 \SpecialChar ~
11923 \SpecialChar ~
11924 \SpecialChar ~
11925 \SpecialChar ~
11926 \SpecialChar ~
11927 \SpecialChar ~
11928 ret
11929 \layout Standard
11930
11931 Note here that the return values
11932 \begin_inset LatexCommand \index{return value}
11933
11934 \end_inset 
11935
11936  are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
11937  two byte values.
11938  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
11939 b' & 'acc' for four byte values.
11940 \layout Standard
11941
11942 The parameter naming convention is _<function_name>_PARM_<n>, where n is
11943  the parameter number starting from 1, and counting from the left.
11944  The first parameter is passed in 
11945 \begin_inset Quotes eld
11946 \end_inset 
11947
11948 dpl
11949 \begin_inset Quotes erd
11950 \end_inset 
11951
11952  for a one byte parameter, 
11953 \begin_inset Quotes eld
11954 \end_inset 
11955
11956 dptr
11957 \begin_inset Quotes erd
11958 \end_inset 
11959
11960  for two bytes, 
11961 \begin_inset Quotes eld
11962 \end_inset 
11963
11964 b,dptr
11965 \begin_inset Quotes erd
11966 \end_inset 
11967
11968  for three bytes and 
11969 \begin_inset Quotes eld
11970 \end_inset 
11971
11972 acc,b,dptr
11973 \begin_inset Quotes erd
11974 \end_inset 
11975
11976  for a four bytes parameter.
11977  The variable name for the second parameter will be _<function_name>_PARM_2.
11978 \newline 
11979
11980 \newline 
11981 Assemble the assembler routine with the following command:
11982 \newline 
11983
11984 \newline 
11985
11986 \family sans 
11987 \series bold 
11988 asx8051 -losg asmfunc.asm
11989 \newline 
11990
11991 \newline 
11992
11993 \family default 
11994 \series default 
11995 Then compile and link the assembler routine to the C source file with the
11996  following command:
11997 \newline 
11998
11999 \newline 
12000
12001 \family sans 
12002 \series bold 
12003 sdcc cfunc.c asmfunc.rel
12004 \layout Subsection
12005
12006 Assembler Routine (reentrant)
12007 \layout Standard
12008
12009 In this case
12010 \begin_inset LatexCommand \index{reentrant}
12011
12012 \end_inset 
12013
12014
12015 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
12016
12017 \end_inset 
12018
12019  the second parameter
12020 \begin_inset LatexCommand \index{function parameter}
12021
12022 \end_inset 
12023
12024  onwards will be passed on the stack, the parameters are pushed from right
12025  to left i.e.
12026  after the call the leftmost parameter will be on the top of the stack.
12027  Here is an example:
12028 \layout Verse
12029
12030
12031 \family typewriter 
12032 extern int asm_func(unsigned char, unsigned char);
12033 \newline 
12034
12035 \newline 
12036 int c_func (unsigned char i, unsigned char j) reentrant 
12037 \newline 
12038
12039 \newline 
12040 \SpecialChar ~
12041 \SpecialChar ~
12042 \SpecialChar ~
12043 \SpecialChar ~
12044 return asm_func(i,j); 
12045 \newline 
12046
12047 \newline 
12048
12049 \newline 
12050 int main() 
12051 \newline 
12052
12053 \newline 
12054 \SpecialChar ~
12055 \SpecialChar ~
12056 \SpecialChar ~
12057 \SpecialChar ~
12058 return c_func(10,9); 
12059 \newline 
12060 }
12061 \layout Standard
12062
12063 The corresponding assembler routine is:
12064 \layout Verse
12065
12066
12067 \family typewriter 
12068 .globl _asm_func 
12069 \newline 
12070 _asm_func: 
12071 \newline 
12072 \SpecialChar ~
12073 \SpecialChar ~
12074 \SpecialChar ~
12075 \SpecialChar ~
12076 push  _bp 
12077 \newline 
12078 \SpecialChar ~
12079 \SpecialChar ~
12080 \SpecialChar ~
12081 \SpecialChar ~
12082 mov _bp,sp 
12083 \newline 
12084 \SpecialChar ~
12085 \SpecialChar ~
12086 \SpecialChar ~
12087 \SpecialChar ~
12088 mov r2,dpl
12089 \newline 
12090 \SpecialChar ~
12091 \SpecialChar ~
12092 \SpecialChar ~
12093 \SpecialChar ~
12094 mov a,_bp 
12095 \newline 
12096 \SpecialChar ~
12097 \SpecialChar ~
12098 \SpecialChar ~
12099 \SpecialChar ~
12100 add a,#0xfd 
12101 \newline 
12102 \SpecialChar ~
12103 \SpecialChar ~
12104 \SpecialChar ~
12105 \SpecialChar ~
12106 mov r0,a 
12107 \newline 
12108 \SpecialChar ~
12109 \SpecialChar ~
12110 \SpecialChar ~
12111 \SpecialChar ~
12112 add  a,#0xfc ;?
12113 \newline 
12114 \SpecialChar ~
12115 \SpecialChar ~
12116 \SpecialChar ~
12117 \SpecialChar ~
12118 mov  r1,a 
12119 \newline 
12120 \SpecialChar ~
12121 \SpecialChar ~
12122 \SpecialChar ~
12123 \SpecialChar ~
12124 mov  a,@r0 
12125 \newline 
12126 \SpecialChar ~
12127 \SpecialChar ~
12128 \SpecialChar ~
12129 \SpecialChar ~
12130 add  a,r2 ;?
12131 \newline 
12132 \SpecialChar ~
12133 \SpecialChar ~
12134 \SpecialChar ~
12135 \SpecialChar ~
12136 mov  dpl,a 
12137 \newline 
12138 \SpecialChar ~
12139 \SpecialChar ~
12140 \SpecialChar ~
12141 \SpecialChar ~
12142 mov  dph,#0x00 
12143 \newline 
12144 \SpecialChar ~
12145 \SpecialChar ~
12146 \SpecialChar ~
12147 \SpecialChar ~
12148 mov  sp,_bp 
12149 \newline 
12150 \SpecialChar ~
12151 \SpecialChar ~
12152 \SpecialChar ~
12153 \SpecialChar ~
12154 pop  _bp 
12155 \newline 
12156 \SpecialChar ~
12157 \SpecialChar ~
12158 \SpecialChar ~
12159 \SpecialChar ~
12160 ret
12161 \layout Standard
12162
12163 The compiling and linking procedure remains the same, however note the extra
12164  entry & exit linkage required for the assembler code, _bp is the stack
12165  frame pointer and is used to compute the offset into the stack for parameters
12166  and local variables.
12167 \layout Section
12168
12169 int (16 bit)
12170 \begin_inset LatexCommand \index{int (16 bit)}
12171
12172 \end_inset 
12173
12174  and long (32 bit)
12175 \begin_inset LatexCommand \index{long (32 bit)}
12176
12177 \end_inset 
12178
12179  Support
12180 \layout Standard
12181
12182 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
12183  multiplication and modulus operations are implemented by support routines.
12184  These support routines are all developed in ANSI-C to facilitate porting
12185  to other MCUs, although some model specific assembler optimizations are
12186  used.
12187  The following files contain the described routines, all of them can be
12188  found in <installdir>/share/sdcc/lib.
12189 \newline 
12190
12191 \layout Standard
12192 \align center 
12193
12194 \begin_inset  Tabular
12195 <lyxtabular version="3" rows="11" columns="2">
12196 <features>
12197 <column alignment="center" valignment="top" leftline="true" width="0(null)">
12198 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
12199 <row topline="true" bottomline="true">
12200 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12201 \begin_inset Text
12202
12203 \layout Standard
12204
12205
12206 \series bold 
12207 Function
12208 \end_inset 
12209 </cell>
12210 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12211 \begin_inset Text
12212
12213 \layout Standard
12214
12215
12216 \series bold 
12217 Description
12218 \end_inset 
12219 </cell>
12220 </row>
12221 <row topline="true">
12222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12223 \begin_inset Text
12224
12225 \layout Standard
12226
12227 _mulint.c 
12228 \end_inset 
12229 </cell>
12230 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12231 \begin_inset Text
12232
12233 \layout Standard
12234
12235 16 bit multiplication
12236 \end_inset 
12237 </cell>
12238 </row>
12239 <row topline="true">
12240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12241 \begin_inset Text
12242
12243 \layout Standard
12244
12245 _divsint.c 
12246 \end_inset 
12247 </cell>
12248 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12249 \begin_inset Text
12250
12251 \layout Standard
12252
12253  signed 16 bit division (calls _divuint)
12254 \end_inset 
12255 </cell>
12256 </row>
12257 <row topline="true">
12258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12259 \begin_inset Text
12260
12261 \layout Standard
12262
12263 _divuint.c 
12264 \end_inset 
12265 </cell>
12266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12267 \begin_inset Text
12268
12269 \layout Standard
12270
12271  unsigned 16 bit division
12272 \end_inset 
12273 </cell>
12274 </row>
12275 <row topline="true">
12276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12277 \begin_inset Text
12278
12279 \layout Standard
12280
12281 _modsint.c
12282 \end_inset 
12283 </cell>
12284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12285 \begin_inset Text
12286
12287 \layout Standard
12288
12289 signed 16 bit modulus (calls _moduint)
12290 \end_inset 
12291 </cell>
12292 </row>
12293 <row topline="true">
12294 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12295 \begin_inset Text
12296
12297 \layout Standard
12298
12299 _moduint.c
12300 \end_inset 
12301 </cell>
12302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12303 \begin_inset Text
12304
12305 \layout Standard
12306
12307 unsigned 16 bit modulus
12308 \end_inset 
12309 </cell>
12310 </row>
12311 <row topline="true">
12312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12313 \begin_inset Text
12314
12315 \layout Standard
12316
12317 _mullong.c
12318 \end_inset 
12319 </cell>
12320 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12321 \begin_inset Text
12322
12323 \layout Standard
12324
12325 32 bit multiplication
12326 \end_inset 
12327 </cell>
12328 </row>
12329 <row topline="true">
12330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12331 \begin_inset Text
12332
12333 \layout Standard
12334
12335 _divslong.c 
12336 \end_inset 
12337 </cell>
12338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12339 \begin_inset Text
12340
12341 \layout Standard
12342
12343  signed 32 division (calls _divulong)
12344 \end_inset 
12345 </cell>
12346 </row>
12347 <row topline="true">
12348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12349 \begin_inset Text
12350
12351 \layout Standard
12352
12353 _divulong.c 
12354 \end_inset 
12355 </cell>
12356 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12357 \begin_inset Text
12358
12359 \layout Standard
12360
12361 unsigned 32 division
12362 \end_inset 
12363 </cell>
12364 </row>
12365 <row topline="true">
12366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12367 \begin_inset Text
12368
12369 \layout Standard
12370
12371 _modslong.c
12372 \end_inset 
12373 </cell>
12374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12375 \begin_inset Text
12376
12377 \layout Standard
12378
12379  signed 32 bit modulus (calls _modulong)
12380 \end_inset 
12381 </cell>
12382 </row>
12383 <row topline="true" bottomline="true">
12384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12385 \begin_inset Text
12386
12387 \layout Standard
12388
12389 _modulong.c
12390 \end_inset 
12391 </cell>
12392 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12393 \begin_inset Text
12394
12395 \layout Standard
12396
12397 unsigned 32 bit modulus
12398 \end_inset 
12399 </cell>
12400 </row>
12401 </lyxtabular>
12402
12403 \end_inset 
12404
12405
12406 \newline 
12407
12408 \layout Standard
12409
12410 Since they are compiled as 
12411 \emph on 
12412 non-reentrant
12413 \emph default 
12414
12415 \begin_inset LatexCommand \index{reentrant}
12416
12417 \end_inset 
12418
12419 , interrupt
12420 \begin_inset LatexCommand \index{interrupt}
12421
12422 \end_inset 
12423
12424  service routines should not do any of the above operations.
12425  If this is unavoidable then the above routines will need to be compiled
12426  with the 
12427 \emph on 
12428 -
12429 \begin_inset ERT
12430 status Collapsed
12431
12432 \layout Standard
12433
12434 \backslash 
12435 /
12436 \end_inset 
12437
12438 -stack-auto
12439 \begin_inset LatexCommand \index{-\/-stack-auto}
12440
12441 \end_inset 
12442
12443
12444 \emph default 
12445  option, after which the source program will have to be compiled with 
12446 \emph on 
12447 -
12448 \begin_inset ERT
12449 status Collapsed
12450
12451 \layout Standard
12452
12453 \backslash 
12454 /
12455 \end_inset 
12456
12457 -int-long-reent
12458 \begin_inset LatexCommand \index{-\/-int-long-reent}
12459
12460 \end_inset 
12461
12462
12463 \emph default 
12464  option.
12465  Notice that you don't have to call these routines directly.
12466  The compiler will use them automatically every time an integer operation
12467  is required.
12468 \layout Section
12469
12470 Floating Point Support
12471 \begin_inset LatexCommand \index{Floating point support}
12472
12473 \end_inset 
12474
12475
12476 \layout Standard
12477
12478 SDCC supports IEEE (single precision 4 bytes) floating point numbers.The
12479  floating point support routines are derived from gcc's floatlib.c and consist
12480  of the following routines:
12481 \newline 
12482
12483 \layout Standard
12484 \align center 
12485
12486 \size footnotesize 
12487
12488 \begin_inset  Tabular
12489 <lyxtabular version="3" rows="17" columns="2">
12490 <features>
12491 <column alignment="center" valignment="top" leftline="true" width="0(null)">
12492 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
12493 <row topline="true" bottomline="true">
12494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12495 \begin_inset Text
12496
12497 \layout Standard
12498
12499
12500 \family roman 
12501 \series medium 
12502 \shape up 
12503 \size normal 
12504 \emph off 
12505 \bar no 
12506 \noun off 
12507 \color none
12508 Function 
12509 \end_inset 
12510 </cell>
12511 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12512 \begin_inset Text
12513
12514 \layout Standard
12515
12516 Description
12517 \end_inset 
12518 </cell>
12519 </row>
12520 <row topline="true">
12521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12522 \begin_inset Text
12523
12524 \layout Standard
12525
12526
12527 \family roman 
12528 \series medium 
12529 \shape up 
12530 \size normal 
12531 \emph off 
12532 \bar no 
12533 \noun off 
12534 \color none
12535 _fsadd.c
12536 \end_inset 
12537 </cell>
12538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12539 \begin_inset Text
12540
12541 \layout Standard
12542
12543
12544 \family roman 
12545 \series medium 
12546 \shape up 
12547 \size normal 
12548 \emph off 
12549 \bar no 
12550 \noun off 
12551 \color none
12552 add floating point numbers
12553 \end_inset 
12554 </cell>
12555 </row>
12556 <row topline="true">
12557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12558 \begin_inset Text
12559
12560 \layout Standard
12561
12562
12563 \family roman 
12564 \series medium 
12565 \shape up 
12566 \size normal 
12567 \emph off 
12568 \bar no 
12569 \noun off 
12570 \color none
12571 _fssub.c 
12572 \end_inset 
12573 </cell>
12574 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12575 \begin_inset Text
12576
12577 \layout Standard
12578
12579
12580 \family roman 
12581 \series medium 
12582 \shape up 
12583 \size normal 
12584 \emph off 
12585 \bar no 
12586 \noun off 
12587 \color none
12588 subtract floating point numbers 
12589 \end_inset 
12590 </cell>
12591 </row>
12592 <row topline="true">
12593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12594 \begin_inset Text
12595
12596 \layout Standard
12597
12598
12599 \family roman 
12600 \series medium 
12601 \shape up 
12602 \size normal 
12603 \emph off 
12604 \bar no 
12605 \noun off 
12606 \color none
12607 _fsdiv.c 
12608 \end_inset 
12609 </cell>
12610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12611 \begin_inset Text
12612
12613 \layout Standard
12614
12615
12616 \family roman 
12617 \series medium 
12618 \shape up 
12619 \size normal 
12620 \emph off 
12621 \bar no 
12622 \noun off 
12623 \color none
12624 divide floating point numbers 
12625 \end_inset 
12626 </cell>
12627 </row>
12628 <row topline="true">
12629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12630 \begin_inset Text
12631
12632 \layout Standard
12633
12634
12635 \family roman 
12636 \series medium 
12637 \shape up 
12638 \size normal 
12639 \emph off 
12640 \bar no 
12641 \noun off 
12642 \color none
12643 _fsmul.c 
12644 \end_inset 
12645 </cell>
12646 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12647 \begin_inset Text
12648
12649 \layout Standard
12650
12651
12652 \family roman 
12653 \series medium 
12654 \shape up 
12655 \size normal 
12656 \emph off 
12657 \bar no 
12658 \noun off 
12659 \color none
12660 multiply floating point numbers 
12661 \end_inset 
12662 </cell>
12663 </row>
12664 <row topline="true">
12665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12666 \begin_inset Text
12667
12668 \layout Standard
12669
12670
12671 \family roman 
12672 \series medium 
12673 \shape up 
12674 \size normal 
12675 \emph off 
12676 \bar no 
12677 \noun off 
12678 \color none
12679 _fs2uchar.c
12680 \end_inset 
12681 </cell>
12682 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12683 \begin_inset Text
12684
12685 \layout Standard
12686
12687
12688 \family roman 
12689 \series medium 
12690 \shape up 
12691 \size normal 
12692 \emph off 
12693 \bar no 
12694 \noun off 
12695 \color none
12696 convert floating point to unsigned char
12697 \end_inset 
12698 </cell>
12699 </row>
12700 <row topline="true">
12701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12702 \begin_inset Text
12703
12704 \layout Standard
12705
12706
12707 \family roman 
12708 \series medium 
12709 \shape up 
12710 \size normal 
12711 \emph off 
12712 \bar no 
12713 \noun off 
12714 \color none
12715 _fs2char.c
12716 \end_inset 
12717 </cell>
12718 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12719 \begin_inset Text
12720
12721 \layout Standard
12722
12723
12724 \family roman 
12725 \series medium 
12726 \shape up 
12727 \size normal 
12728 \emph off 
12729 \bar no 
12730 \noun off 
12731 \color none
12732 convert floating point to signed char
12733 \end_inset 
12734 </cell>
12735 </row>
12736 <row topline="true">
12737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12738 \begin_inset Text
12739
12740 \layout Standard
12741
12742
12743 \family roman 
12744 \series medium 
12745 \shape up 
12746 \size normal 
12747 \emph off 
12748 \bar no 
12749 \noun off 
12750 \color none
12751 _fs2uint.c
12752 \end_inset 
12753 </cell>
12754 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12755 \begin_inset Text
12756
12757 \layout Standard
12758
12759
12760 \family roman 
12761 \series medium 
12762 \shape up 
12763 \size normal 
12764 \emph off 
12765 \bar no 
12766 \noun off 
12767 \color none
12768 convert floating point to unsigned int
12769 \end_inset 
12770 </cell>
12771 </row>
12772 <row topline="true">
12773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12774 \begin_inset Text
12775
12776 \layout Standard
12777
12778
12779 \family roman 
12780 \series medium 
12781 \shape up 
12782 \size normal 
12783 \emph off 
12784 \bar no 
12785 \noun off 
12786 \color none
12787 _fs2int.c
12788 \end_inset 
12789 </cell>
12790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12791 \begin_inset Text
12792
12793 \layout Standard
12794
12795
12796 \family roman 
12797 \series medium 
12798 \shape up 
12799 \size normal 
12800 \emph off 
12801 \bar no 
12802 \noun off 
12803 \color none
12804 convert floating point to signed int
12805 \end_inset 
12806 </cell>
12807 </row>
12808 <row topline="true">
12809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12810 \begin_inset Text
12811
12812 \layout Standard
12813
12814
12815 \family roman 
12816 \series medium 
12817 \shape up 
12818 \size normal 
12819 \emph off 
12820 \bar no 
12821 \noun off 
12822 \color none
12823 _fs2ulong.
12824 \family default 
12825 \series default 
12826 \shape default 
12827 \size default 
12828 \emph default 
12829 \bar default 
12830 \noun default 
12831 \color default
12832 c
12833 \end_inset 
12834 </cell>
12835 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12836 \begin_inset Text
12837
12838 \layout Standard
12839
12840
12841 \family roman 
12842 \series medium 
12843 \shape up 
12844 \size normal 
12845 \emph off 
12846 \bar no 
12847 \noun off 
12848 \color none
12849 convert floating point to unsigned long
12850 \end_inset 
12851 </cell>
12852 </row>
12853 <row topline="true">
12854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12855 \begin_inset Text
12856
12857 \layout Standard
12858
12859
12860 \family roman 
12861 \series medium 
12862 \shape up 
12863 \size normal 
12864 \emph off 
12865 \bar no 
12866 \noun off 
12867 \color none
12868 _fs2long.c
12869 \end_inset 
12870 </cell>
12871 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12872 \begin_inset Text
12873
12874 \layout Standard
12875
12876
12877 \family roman 
12878 \series medium 
12879 \shape up 
12880 \size normal 
12881 \emph off 
12882 \bar no 
12883 \noun off 
12884 \color none
12885 convert floating point to signed long
12886 \end_inset 
12887 </cell>
12888 </row>
12889 <row topline="true">
12890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12891 \begin_inset Text
12892
12893 \layout Standard
12894
12895
12896 \family roman 
12897 \series medium 
12898 \shape up 
12899 \size normal 
12900 \emph off 
12901 \bar no 
12902 \noun off 
12903 \color none
12904 _uchar2fs.c
12905 \end_inset 
12906 </cell>
12907 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12908 \begin_inset Text
12909
12910 \layout Standard
12911
12912
12913 \family roman 
12914 \series medium 
12915 \shape up 
12916 \size normal 
12917 \emph off 
12918 \bar no 
12919 \noun off 
12920 \color none
12921 convert unsigned char to floating point
12922 \end_inset 
12923 </cell>
12924 </row>
12925 <row topline="true">
12926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12927 \begin_inset Text
12928
12929 \layout Standard
12930
12931
12932 \family roman 
12933 \series medium 
12934 \shape up 
12935 \size normal 
12936 \emph off 
12937 \bar no 
12938 \noun off 
12939 \color none
12940 _char2fs.c
12941 \end_inset 
12942 </cell>
12943 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12944 \begin_inset Text
12945
12946 \layout Standard
12947
12948
12949 \family roman 
12950 \series medium 
12951 \shape up 
12952 \size normal 
12953 \emph off 
12954 \bar no 
12955 \noun off 
12956 \color none
12957 convert char to floating point number
12958 \end_inset 
12959 </cell>
12960 </row>
12961 <row topline="true">
12962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12963 \begin_inset Text
12964
12965 \layout Standard
12966
12967
12968 \family roman 
12969 \series medium 
12970 \shape up 
12971 \size normal 
12972 \emph off 
12973 \bar no 
12974 \noun off 
12975 \color none
12976 _uint2fs.c
12977 \end_inset 
12978 </cell>
12979 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12980 \begin_inset Text
12981
12982 \layout Standard
12983
12984
12985 \family roman 
12986 \series medium 
12987 \shape up 
12988 \size normal 
12989 \emph off 
12990 \bar no 
12991 \noun off 
12992 \color none
12993 convert unsigned int to floating point
12994 \end_inset 
12995 </cell>
12996 </row>
12997 <row topline="true">
12998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12999 \begin_inset Text
13000
13001 \layout Standard
13002
13003
13004 \family roman 
13005 \series medium 
13006 \shape up 
13007 \size normal 
13008 \emph off 
13009 \bar no 
13010 \noun off 
13011 \color none
13012 _int2fs.c
13013 \end_inset 
13014 </cell>
13015 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13016 \begin_inset Text
13017
13018 \layout Standard
13019
13020
13021 \family roman 
13022 \series medium 
13023 \shape up 
13024 \size normal 
13025 \emph off 
13026 \bar no 
13027 \noun off 
13028 \color none
13029 convert int to floating point numbers
13030 \end_inset 
13031 </cell>
13032 </row>
13033 <row topline="true">
13034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13035 \begin_inset Text
13036
13037 \layout Standard
13038
13039
13040 \family roman 
13041 \series medium 
13042 \shape up 
13043 \size normal 
13044 \emph off 
13045 \bar no 
13046 \noun off 
13047 \color none
13048 _ulong2fs.c
13049 \end_inset 
13050 </cell>
13051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13052 \begin_inset Text
13053
13054 \layout Standard
13055
13056
13057 \family roman 
13058 \series medium 
13059 \shape up 
13060 \size normal 
13061 \emph off 
13062 \bar no 
13063 \noun off 
13064 \color none
13065 convert unsigned long to floating point number
13066 \end_inset 
13067 </cell>
13068 </row>
13069 <row topline="true" bottomline="true">
13070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13071 \begin_inset Text
13072
13073 \layout Standard
13074
13075
13076 \family roman 
13077 \series medium 
13078 \shape up 
13079 \size normal 
13080 \emph off 
13081 \bar no 
13082 \noun off 
13083 \color none
13084 _long2fs.c
13085 \end_inset 
13086 </cell>
13087 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13088 \begin_inset Text
13089
13090 \layout Standard
13091
13092
13093 \family roman 
13094 \series medium 
13095 \shape up 
13096 \size normal 
13097 \emph off 
13098 \bar no 
13099 \noun off 
13100 \color none
13101 convert long to floating point number
13102 \end_inset 
13103 </cell>
13104 </row>
13105 </lyxtabular>
13106
13107 \end_inset 
13108
13109
13110 \newline 
13111
13112 \layout Standard
13113
13114 These support routines are developed in ANSI-C so there is room for space
13115  and speed improvement.
13116  Note if all these routines are used simultaneously the data space might
13117  overflow.
13118  For serious floating point usage it is recommended that the large model
13119  be used.
13120  Also notice that you don't have to call this routines directly.
13121  The compiler will use them automatically every time a floating point operation
13122  is required.
13123 \layout Section
13124
13125 Library Routines
13126 \begin_inset LatexCommand \index{Libraries}
13127
13128 \end_inset 
13129
13130
13131 \layout Standard
13132
13133
13134 \emph on 
13135 <pending: this is messy and incomplete - a little more information is in
13136  sdcc/doc/libdoc.txt
13137 \emph default 
13138  >
13139 \layout Subsection
13140
13141 Compiler support routines (_gptrget, _mulint etc.)
13142 \layout Subsection
13143
13144 Stdclib functions (puts, printf, strcat etc.)
13145 \layout Subsubsection
13146
13147 <stdio.h>
13148 \layout Standard
13149
13150
13151 \begin_inset LatexCommand \index{<stdio.h>}
13152
13153 \end_inset 
13154
13155 As usual on embedded systems you have to provide your own 
13156 \family typewriter 
13157 getchar()
13158 \begin_inset LatexCommand \index{getchar()}
13159
13160 \end_inset 
13161
13162  
13163 \family default 
13164 and 
13165 \family typewriter 
13166 putchar()
13167 \begin_inset LatexCommand \index{putchar()}
13168
13169 \end_inset 
13170
13171
13172 \family default 
13173  routines.
13174  SDCC does not know whether the system connects to a serial line with or
13175  without handshake, LCD, keyboard or other device.
13176  You'll find examples for serial routines f.e.
13177  in sdcc/device/lib.
13178 \layout Standard
13179
13180 If you're short on memory you might want to use 
13181 \family typewriter 
13182 printf_small()
13183 \family default 
13184  
13185 \emph on 
13186 instead
13187 \emph default 
13188  of
13189 \family typewriter 
13190  printf()
13191 \begin_inset LatexCommand \index{printf()}
13192
13193 \end_inset 
13194
13195 .
13196
13197 \family default 
13198  For the mcs51 there is an assembly version 
13199 \family typewriter 
13200 printf_fast()
13201 \family default 
13202  which should fit the requirements of many embedded systems (by unsetting
13203  #defines it can be customized to 
13204 \emph on 
13205 not
13206 \emph default 
13207  support long variables and field widths).
13208 \layout Subsection
13209
13210 Math functions (sin, pow, sqrt etc.)
13211 \layout Subsection
13212
13213 Other libraries
13214 \layout Standard
13215
13216 Libraries
13217 \begin_inset LatexCommand \index{Libraries}
13218
13219 \end_inset 
13220
13221  included in SDCC should have a license at least as liberal as the GNU Lesser
13222  General Public License
13223 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
13224
13225 \end_inset 
13226
13227  
13228 \emph on 
13229 LGPL
13230 \emph default 
13231 .
13232 \layout Comment
13233
13234 license statements for the libraries are missing.
13235  sdcc/device/lib/ser_ir.c
13236 \layout Comment
13237
13238 or _decdptr f.e.
13239  come with a GPL (as opposed to LGPL) License - this will not be liberal
13240  enough for many embedded programmers.
13241 \layout Standard
13242
13243 If you have ported some library or want to share experience about some code
13244  which f.e.
13245  falls into any of these categories Busses (I
13246 \begin_inset Formula $^{\textrm{2}}$
13247 \end_inset 
13248
13249 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
13250  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
13251  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
13252 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
13253
13254 \end_inset 
13255
13256 \SpecialChar ~
13257 would certainly like to hear about it.
13258  Programmers coding for embedded systems are not especially famous for being
13259  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
13260 e these references are very valuable.
13261  Let's help to create a climate where information is shared.
13262 \layout Section
13263
13264 Memory Models
13265 \layout Subsection
13266
13267 MCS51 Memory Models
13268 \begin_inset LatexCommand \index{Memory model}
13269
13270 \end_inset 
13271
13272
13273 \begin_inset LatexCommand \index{MCS51 memory model}
13274
13275 \end_inset 
13276
13277
13278 \layout Subsubsection
13279
13280 Small and Large
13281 \layout Standard
13282
13283 SDCC allows two memory models for MCS51 code, 
13284 \shape slanted 
13285 small
13286 \shape default 
13287  and 
13288 \shape slanted 
13289 large
13290 \shape default 
13291 .
13292  Modules compiled with different memory models should 
13293 \emph on 
13294 never
13295 \emph default 
13296  be combined together or the results would be unpredictable.
13297  The library routines supplied with the compiler are compiled as both small
13298  and large.
13299  The compiled library modules are contained in separate directories as small
13300  and large so that you can link to either set.
13301  
13302 \layout Standard
13303
13304 When the large model is used all variables declared without a storage class
13305  will be allocated into the external ram, this includes all parameters and
13306  local variables (for non-reentrant
13307 \begin_inset LatexCommand \index{reentrant}
13308
13309 \end_inset 
13310
13311  functions).
13312  When the small model is used variables without storage class are allocated
13313  in the internal ram.
13314 \layout Standard
13315
13316 Judicious usage of the processor specific storage classes
13317 \begin_inset LatexCommand \index{Storage class}
13318
13319 \end_inset 
13320
13321  and the 'reentrant' function type will yield much more efficient code,
13322  than using the large model.
13323  Several optimizations are disabled when the program is compiled using the
13324  large model, it is therefore recommended that the small model be used unless
13325  absolutely required.
13326 \layout Subsubsection
13327
13328 External Stack
13329 \begin_inset LatexCommand \label{sub:External-Stack}
13330
13331 \end_inset 
13332
13333
13334 \begin_inset LatexCommand \index{stack}
13335
13336 \end_inset 
13337
13338
13339 \begin_inset LatexCommand \index{External stack (mcs51)}
13340
13341 \end_inset 
13342
13343
13344 \layout Standard
13345
13346 The external stack (-
13347 \begin_inset ERT
13348 status Collapsed
13349
13350 \layout Standard
13351
13352 \backslash 
13353 /
13354 \end_inset 
13355
13356 -xstack option
13357 \begin_inset LatexCommand \index{-\/-xstack}
13358
13359 \end_inset 
13360
13361 ) is located in pdata
13362 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
13363
13364 \end_inset 
13365
13366  memory (usually at the start of the external ram segment) and is 256 bytes
13367  in size.
13368  When -
13369 \begin_inset ERT
13370 status Collapsed
13371
13372 \layout Standard
13373
13374 \backslash 
13375 /
13376 \end_inset 
13377
13378 -xstack option is used to compile the program, the parameters and local
13379  variables
13380 \begin_inset LatexCommand \index{local variables}
13381
13382 \end_inset 
13383
13384  of all reentrant functions are allocated in this area.
13385  This option is provided for programs with large stack space requirements.
13386  When used with the -
13387 \begin_inset ERT
13388 status Collapsed
13389
13390 \layout Standard
13391
13392 \backslash 
13393 /
13394 \end_inset 
13395
13396 -stack-auto
13397 \begin_inset LatexCommand \index{-\/-stack-auto}
13398
13399 \end_inset 
13400
13401  option, all parameters and local variables are allocated on the external
13402  stack (note: support libraries will need to be recompiled with the same
13403  options).
13404 \layout Standard
13405
13406 The compiler outputs the higher order address byte of the external ram segment
13407  into port P2
13408 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
13409
13410 \end_inset 
13411
13412  (see also section 
13413 \begin_inset LatexCommand \ref{sub:MCS51-variants}
13414
13415 \end_inset 
13416
13417 ), therefore when using the External Stack option, this port 
13418 \emph on 
13419 may not
13420 \emph default 
13421  be used by the application program.
13422 \layout Subsection
13423
13424 DS390 Memory Model
13425 \begin_inset LatexCommand \index{Memory model}
13426
13427 \end_inset 
13428
13429
13430 \begin_inset LatexCommand \index{DS390 memory model}
13431
13432 \end_inset 
13433
13434
13435 \layout Standard
13436
13437 The only model supported is Flat 24
13438 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
13439
13440 \end_inset 
13441
13442 .
13443  This generates code for the 24 bit contiguous addressing mode of the Dallas
13444  DS80C390 part.
13445  In this mode, up to four meg of external RAM or code space can be directly
13446  addressed.
13447  See the data sheets at www.dalsemi.com for further information on this part.
13448 \newline 
13449
13450 \newline 
13451 Note that the compiler does not generate any code to place the processor
13452  into 24 bitmode (although 
13453 \emph on 
13454 tinibios
13455 \emph default 
13456  in the ds390 libraries will do that for you).
13457  If you don't use 
13458 \emph on 
13459 tinibios
13460 \emph default 
13461
13462 \begin_inset LatexCommand \index{Tinibios (DS390)}
13463
13464 \end_inset 
13465
13466 , the boot loader or similar code must ensure that the processor is in 24
13467  bit contiguous addressing mode before calling the SDCC startup code.
13468 \newline 
13469
13470 \newline 
13471 Like the 
13472 \emph on 
13473 -
13474 \begin_inset ERT
13475 status Collapsed
13476
13477 \layout Standard
13478
13479 \backslash 
13480 /
13481 \end_inset 
13482
13483 -model-large
13484 \emph default 
13485  option, variables will by default be placed into the XDATA segment.
13486  
13487 \newline 
13488
13489 \newline 
13490 Segments may be placed anywhere in the 4 meg address space using the usual
13491  -
13492 \begin_inset ERT
13493 status Collapsed
13494
13495 \layout Standard
13496
13497 \backslash 
13498 /
13499 \end_inset 
13500
13501 -*-loc options.
13502  Note that if any segments are located above 64K, the -r flag must be passed
13503  to the linker to generate the proper segment relocations, and the Intel
13504  HEX output format must be used.
13505  The -r flag can be passed to the linker by using the option 
13506 \emph on 
13507 -Wl-r
13508 \emph default 
13509  on the SDCC command line.
13510  However, currently the linker can not handle code segments > 64k.
13511 \layout Section
13512
13513 Pragmas
13514 \begin_inset LatexCommand \index{Pragmas}
13515
13516 \end_inset 
13517
13518
13519 \layout Standard
13520
13521 SDCC supports the following #pragma directives:
13522 \layout Itemize
13523
13524 save
13525 \begin_inset LatexCommand \index{\#pragma save}
13526
13527 \end_inset 
13528
13529  - this will save all current options to the save/restore stack.
13530  See restore.
13531 \layout Itemize
13532
13533 restore
13534 \begin_inset LatexCommand \index{\#pragma restore}
13535
13536 \end_inset 
13537
13538  - will restore saved options from the last save.
13539  saves & restores can be nested.
13540  SDCC uses a save/restore stack: save pushes current options to the stack,
13541  restore pulls current options from the stack.
13542  See save.
13543 \layout Itemize
13544
13545 nogcse
13546 \begin_inset LatexCommand \index{\#pragma nogcse}
13547
13548 \end_inset 
13549
13550  - will stop global common subexpression elimination.
13551 \layout Itemize
13552
13553 noinduction
13554 \begin_inset LatexCommand \index{\#pragma noinduction}
13555
13556 \end_inset 
13557
13558  - will stop loop induction optimizations.
13559 \layout Itemize
13560
13561 nojtbound
13562 \begin_inset LatexCommand \index{\#pragma nojtbound}
13563
13564 \end_inset 
13565
13566  - will not generate code for boundary value checking, when switch statements
13567  are turned into jump-tables (dangerous).
13568  For more details see section 
13569 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
13570
13571 \end_inset 
13572
13573 .
13574 \layout Itemize
13575
13576 nooverlay
13577 \begin_inset LatexCommand \index{\#pragma nooverlay}
13578
13579 \end_inset 
13580
13581  - the compiler will not overlay the parameters and local variables of a
13582  function.
13583 \layout Itemize
13584
13585 less_pedantic
13586 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
13587
13588 \end_inset 
13589
13590  - the compiler will not warn you anymore for obvious mistakes, you'r on
13591  your own now ;-(
13592 \layout Itemize
13593
13594 noloopreverse
13595 \begin_inset LatexCommand \index{\#pragma noloopreverse}
13596
13597 \end_inset 
13598
13599  - Will not do loop reversal optimization
13600 \layout Itemize
13601
13602 exclude
13603 \begin_inset LatexCommand \index{\#pragma exclude}
13604
13605 \end_inset 
13606
13607  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables generation of
13608  pair of push/pop
13609 \begin_inset LatexCommand \index{push/pop}
13610
13611 \end_inset 
13612
13613  instruction in ISR function (using interrupt
13614 \begin_inset LatexCommand \index{interrupt}
13615
13616 \end_inset 
13617
13618  keyword).
13619  The directive should be placed immediately before the ISR function definition
13620  and it affects ALL ISR functions following it.
13621  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
13622 exclude\SpecialChar ~
13623 none
13624 \begin_inset LatexCommand \index{\#pragma exclude}
13625
13626 \end_inset 
13627
13628 .
13629 \layout Itemize
13630
13631 noiv
13632 \begin_inset LatexCommand \index{\#pragma noiv}
13633
13634 \end_inset 
13635
13636  - Do not generate interrupt
13637 \begin_inset LatexCommand \index{interrupt}
13638
13639 \end_inset 
13640
13641  vector table entries for all ISR functions defined after the pragma.
13642  This is useful in cases where the interrupt vector table must be defined
13643  manually, or when there is a secondary, manually defined interrupt vector
13644  table (e.g.
13645  for the autovector feature of the Cypress EZ-USB FX2).
13646  More elegantly this can be achieved by obmitting the optional interrupt
13647  number after the interrupt keyword, see section 
13648 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
13649
13650 \end_inset 
13651
13652 \SpecialChar ~
13653 about interrupts.
13654 \layout Itemize
13655
13656 callee_saves
13657 \begin_inset LatexCommand \index{\#pragma callee\_saves}
13658
13659 \end_inset 
13660
13661
13662 \begin_inset LatexCommand \index{function prologue}
13663
13664 \end_inset 
13665
13666  function1[,function2[,function3...]] - The compiler by default uses a caller
13667  saves convention for register saving across function calls, however this
13668  can cause unnecessary register pushing & popping
13669 \begin_inset LatexCommand \index{push/pop}
13670
13671 \end_inset 
13672
13673  when calling small functions from larger functions.
13674  This option can be used to switch off the register saving convention for
13675  the function names specified.
13676  The compiler will not save registers when calling these functions, extra
13677  code need to be manually inserted at the entry & exit for these functions
13678  to save & restore the registers used by these functions, this can SUBSTANTIALLY
13679  reduce code & improve run time performance of the generated code.
13680  In the future the compiler (with inter procedural analysis) may be able
13681  to determine the appropriate scheme to use for each function call.
13682  If -
13683 \begin_inset ERT
13684 status Collapsed
13685
13686 \layout Standard
13687
13688 \backslash 
13689 /
13690 \end_inset 
13691
13692 -callee-saves command line option is used, the function names specified
13693  in #pragma\SpecialChar ~
13694 callee_saves
13695 \begin_inset LatexCommand \index{\#pragma callee\_saves}
13696
13697 \end_inset 
13698
13699  is appended to the list of functions specified in the command line.
13700 \layout Standard
13701
13702 SDCPP supports the following #pragma directives:
13703 \layout Itemize
13704
13705 preproc_asm
13706 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
13707
13708 \end_inset 
13709
13710  (+ | -) - switch _asm _endasm block preprocessing on / off.
13711  Default is on.
13712 \layout Standard
13713
13714 The pragma's are intended to be used to turn-on or off certain optimizations
13715  which might cause the compiler to generate extra stack / data space to
13716  store compiler generated temporary variables.
13717  This usually happens in large functions.
13718  Pragma directives should be used as shown in the following example, they
13719  are used to control options & optimizations for a given function; pragmas
13720  should be placed before and/or after a function, placing pragma's inside
13721  a function body could have unpredictable results.
13722 \layout Verse
13723
13724
13725 \family typewriter 
13726 #pragma save
13727 \begin_inset LatexCommand \index{\#pragma save}
13728
13729 \end_inset 
13730
13731  \SpecialChar ~
13732 \SpecialChar ~
13733 \SpecialChar ~
13734 \SpecialChar ~
13735 \SpecialChar ~
13736 \SpecialChar ~
13737 \SpecialChar ~
13738 /* save the current settings */ 
13739 \newline 
13740 #pragma nogcse
13741 \begin_inset LatexCommand \index{\#pragma nogcse}
13742
13743 \end_inset 
13744
13745  \SpecialChar ~
13746 \SpecialChar ~
13747 \SpecialChar ~
13748 \SpecialChar ~
13749 \SpecialChar ~
13750 /* turnoff global subexpression elimination */ 
13751 \newline 
13752 #pragma noinduction
13753 \begin_inset LatexCommand \index{\#pragma noinduction}
13754
13755 \end_inset 
13756
13757  /* turn off induction optimizations */ 
13758 \newline 
13759 int foo () 
13760 \newline 
13761
13762 \newline 
13763 \SpecialChar ~
13764  \SpecialChar ~
13765  ...
13766  
13767 \newline 
13768 \SpecialChar ~
13769  \SpecialChar ~
13770  /* large code */ 
13771 \newline 
13772 \SpecialChar ~
13773  \SpecialChar ~
13774  ...
13775  
13776 \newline 
13777
13778 \newline 
13779 #pragma restore
13780 \begin_inset LatexCommand \index{\#pragma restore}
13781
13782 \end_inset 
13783
13784  /* turn the optimizations back on */
13785 \layout Standard
13786
13787 The compiler will generate a warning message when extra space is allocated.
13788  It is strongly recommended that the save and restore pragma's be used when
13789  changing options for a function.
13790 \layout Section
13791
13792 Defines Created by the Compiler
13793 \layout Standard
13794
13795 The compiler creates the following #defines
13796 \begin_inset LatexCommand \index{\#defines}
13797
13798 \end_inset 
13799
13800
13801 \begin_inset LatexCommand \index{Defines created by the compiler}
13802
13803 \end_inset 
13804
13805 :
13806 \newline 
13807
13808 \layout Standard
13809
13810
13811 \begin_inset  Tabular
13812 <lyxtabular version="3" rows="10" columns="2">
13813 <features>
13814 <column alignment="center" valignment="top" leftline="true" width="0(null)">
13815 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
13816 <row topline="true" bottomline="true">
13817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13818 \begin_inset Text
13819
13820 \layout Standard
13821
13822
13823 \series bold 
13824 #define
13825 \end_inset 
13826 </cell>
13827 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13828 \begin_inset Text
13829
13830 \layout Standard
13831
13832
13833 \series bold 
13834 Description
13835 \end_inset 
13836 </cell>
13837 </row>
13838 <row topline="true">
13839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13840 \begin_inset Text
13841
13842 \layout Standard
13843
13844 SDCC
13845 \begin_inset LatexCommand \index{SDCC}
13846
13847 \end_inset 
13848
13849  
13850 \end_inset 
13851 </cell>
13852 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13853 \begin_inset Text
13854
13855 \layout Standard
13856
13857 this Symbol is always defined
13858 \end_inset 
13859 </cell>
13860 </row>
13861 <row topline="true">
13862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13863 \begin_inset Text
13864
13865 \layout Standard
13866
13867 SDCC_mcs51
13868 \begin_inset LatexCommand \index{SDCC\_mcs51}
13869
13870 \end_inset 
13871
13872  or SDCC_ds390
13873 \begin_inset LatexCommand \index{SDCC\_ds390}
13874
13875 \end_inset 
13876
13877  or SDCC_z80
13878 \begin_inset LatexCommand \index{SDCC\_z80}
13879
13880 \end_inset 
13881
13882 , etc
13883 \end_inset 
13884 </cell>
13885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13886 \begin_inset Text
13887
13888 \layout Standard
13889
13890 depending on the model used (e.g.: -mds390
13891 \end_inset 
13892 </cell>
13893 </row>
13894 <row topline="true">
13895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13896 \begin_inset Text
13897
13898 \layout Standard
13899
13900 __mcs51
13901 \begin_inset LatexCommand \index{\_\_mcs51}
13902
13903 \end_inset 
13904
13905 , __ds390
13906 \begin_inset LatexCommand \index{\_\_ds390}
13907
13908 \end_inset 
13909
13910 , __hc08
13911 \begin_inset LatexCommand \index{\_\_hc08}
13912
13913 \end_inset 
13914
13915 , __z80
13916 \begin_inset LatexCommand \index{\_\_z80}
13917
13918 \end_inset 
13919
13920 , etc
13921 \end_inset 
13922 </cell>
13923 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13924 \begin_inset Text
13925
13926 \layout Standard
13927
13928 depending on the model used (e.g.
13929  -mz80)
13930 \end_inset 
13931 </cell>
13932 </row>
13933 <row topline="true">
13934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13935 \begin_inset Text
13936
13937 \layout Standard
13938
13939 SDCC_STACK_AUTO
13940 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
13941
13942 \end_inset 
13943
13944
13945 \end_inset 
13946 </cell>
13947 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13948 \begin_inset Text
13949
13950 \layout Standard
13951
13952 when 
13953 \emph on 
13954 -
13955 \begin_inset ERT
13956 status Collapsed
13957
13958 \layout Standard
13959
13960 \backslash 
13961 /
13962 \end_inset 
13963
13964 -stack-auto
13965 \emph default 
13966  option is used
13967 \end_inset 
13968 </cell>
13969 </row>
13970 <row topline="true">
13971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13972 \begin_inset Text
13973
13974 \layout Standard
13975
13976 SDCC_MODEL_SMALL
13977 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
13978
13979 \end_inset 
13980
13981
13982 \end_inset 
13983 </cell>
13984 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13985 \begin_inset Text
13986
13987 \layout Standard
13988
13989 when 
13990 \emph on 
13991 -
13992 \begin_inset ERT
13993 status Collapsed
13994
13995 \layout Standard
13996
13997 \backslash 
13998 /
13999 \end_inset 
14000
14001 -model-small
14002 \emph default 
14003  is used
14004 \end_inset 
14005 </cell>
14006 </row>
14007 <row topline="true">
14008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14009 \begin_inset Text
14010
14011 \layout Standard
14012
14013 SDCC_MODEL_LARGE
14014 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
14015
14016 \end_inset 
14017
14018
14019 \end_inset 
14020 </cell>
14021 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14022 \begin_inset Text
14023
14024 \layout Standard
14025
14026 when 
14027 \emph on 
14028 -
14029 \begin_inset ERT
14030 status Collapsed
14031
14032 \layout Standard
14033
14034 \backslash 
14035 /
14036 \end_inset 
14037
14038 -model-large
14039 \emph default 
14040  is used
14041 \end_inset 
14042 </cell>
14043 </row>
14044 <row topline="true">
14045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14046 \begin_inset Text
14047
14048 \layout Standard
14049
14050 SDCC_USE_XSTACK
14051 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
14052
14053 \end_inset 
14054
14055
14056 \end_inset 
14057 </cell>
14058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14059 \begin_inset Text
14060
14061 \layout Standard
14062
14063 when 
14064 \emph on 
14065 -
14066 \begin_inset ERT
14067 status Collapsed
14068
14069 \layout Standard
14070
14071 \backslash 
14072 /
14073 \end_inset 
14074
14075 -xstack
14076 \emph default 
14077  option is used
14078 \end_inset 
14079 </cell>
14080 </row>
14081 <row topline="true">
14082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14083 \begin_inset Text
14084
14085 \layout Standard
14086
14087 SDCC_STACK_TENBIT
14088 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
14089
14090 \end_inset 
14091
14092  
14093 \end_inset 
14094 </cell>
14095 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14096 \begin_inset Text
14097
14098 \layout Standard
14099
14100 when 
14101 \emph on 
14102 -mds390
14103 \emph default 
14104  is used
14105 \end_inset 
14106 </cell>
14107 </row>
14108 <row topline="true" bottomline="true">
14109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14110 \begin_inset Text
14111
14112 \layout Standard
14113
14114 SDCC_MODEL_FLAT24
14115 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
14116
14117 \end_inset 
14118
14119
14120 \end_inset 
14121 </cell>
14122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14123 \begin_inset Text
14124
14125 \layout Standard
14126
14127 when 
14128 \emph on 
14129 -mds390
14130 \emph default 
14131  is used
14132 \end_inset 
14133 </cell>
14134 </row>
14135 </lyxtabular>
14136
14137 \end_inset 
14138
14139
14140 \newline 
14141
14142 \layout Chapter
14143
14144 Debugging with SDCDB
14145 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
14146
14147 \end_inset 
14148
14149
14150 \begin_inset LatexCommand \index{sdcdb (debugger)}
14151
14152 \end_inset 
14153
14154  
14155 \layout Standard
14156
14157 SDCC is distributed with a source level debugger
14158 \begin_inset LatexCommand \index{Debugger}
14159
14160 \end_inset 
14161
14162 .
14163  The debugger uses a command line interface, the command repertoire of the
14164  debugger has been kept as close to gdb
14165 \begin_inset LatexCommand \index{gdb}
14166
14167 \end_inset 
14168
14169  (the GNU debugger) as possible.
14170  The configuration and build process is part of the standard compiler installati
14171 on, which also builds and installs the debugger in the target directory
14172  specified during configuration.
14173  The debugger allows you debug BOTH at the C source and at the ASM source
14174  level.
14175  Sdcdb is available on Unix platforms only.
14176 \layout Section
14177
14178 Compiling for Debugging
14179 \layout Standard
14180
14181 The \SpecialChar \-
14182 \SpecialChar \-
14183 debug option must be specified for all files for which debug information
14184  is to be generated.
14185  The complier generates a .adb file for each of these files.
14186  The linker creates the .cdb file from the .adb files and the address information.
14187  This .cdb is used by the debugger.
14188 \layout Section
14189
14190 How the Debugger Works
14191 \layout Standard
14192
14193 When the -
14194 \begin_inset ERT
14195 status Collapsed
14196
14197 \layout Standard
14198
14199 \backslash 
14200 /
14201 \end_inset 
14202
14203 -debug option is specified the compiler generates extra symbol information
14204  some of which are put into the assembler source and some are put into the
14205  .adb file.
14206   Then the linker creates the .cdb file from the individual .adb files with
14207  the address information for the symbols.
14208  The debugger reads the symbolic information generated by the compiler &
14209  the address information generated by the linker.
14210  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
14211  execution is controlled by the debugger.
14212  When a command is issued for the debugger, it translates it into appropriate
14213  commands for the simulator.
14214 \layout Section
14215
14216 Starting the Debugger
14217 \layout Standard
14218
14219 The debugger can be started using the following command line.
14220  (Assume the file you are debugging has the file name foo).
14221 \newline 
14222
14223 \newline 
14224
14225 \family sans 
14226 \series bold 
14227 sdcdb foo
14228 \newline 
14229
14230 \family default 
14231 \series default 
14232
14233 \newline 
14234 The debugger will look for the following files.
14235 \layout Itemize
14236
14237 foo.c - the source file.
14238 \layout Itemize
14239
14240 foo.cdb - the debugger symbol information file.
14241 \layout Itemize
14242
14243 foo.ihx - the Intel hex format
14244 \begin_inset LatexCommand \index{Intel hex format}
14245
14246 \end_inset 
14247
14248  object file.
14249 \layout Section
14250
14251 Command Line Options.
14252 \layout Itemize
14253
14254 -
14255 \begin_inset ERT
14256 status Collapsed
14257
14258 \layout Standard
14259
14260 \backslash 
14261 /
14262 \end_inset 
14263
14264 -directory=<source file directory> this option can used to specify the directory
14265  search list.
14266  The debugger will look into the directory list specified for source, cdb
14267  & ihx files.
14268  The items in the directory list must be separated by ':', e.g.
14269  if the source files can be in the directories /home/src1 and /home/src2,
14270  the -
14271 \begin_inset ERT
14272 status Collapsed
14273
14274 \layout Standard
14275
14276 \backslash 
14277 /
14278 \end_inset 
14279
14280 -directory option should be -
14281 \begin_inset ERT
14282 status Collapsed
14283
14284 \layout Standard
14285
14286 \backslash 
14287 /
14288 \end_inset 
14289
14290 -directory=/home/src1:/home/src2.
14291  Note there can be no spaces in the option.
14292  
14293 \layout Itemize
14294
14295 -cd <directory> - change to the <directory>.
14296 \layout Itemize
14297
14298 -fullname - used by GUI front ends.
14299 \layout Itemize
14300
14301 -cpu <cpu-type> - this argument is passed to the simulator please see the
14302  simulator docs for details.
14303 \layout Itemize
14304
14305 -X <Clock frequency > this options is passed to the simulator please see
14306  the simulator docs for details.
14307 \layout Itemize
14308
14309 -s <serial port file> passed to simulator see the simulator docs for details.
14310 \layout Itemize
14311
14312 -S <serial in,out> passed to simulator see the simulator docs for details.
14313 \layout Itemize
14314
14315 -k <port number> passed to simulator see the simulator docs for details.
14316 \layout Section
14317
14318 Debugger Commands.
14319 \layout Standard
14320
14321 As mentioned earlier the command interface for the debugger has been deliberatel
14322 y kept as close the GNU debugger gdb, as possible.
14323  This will help the integration with existing graphical user interfaces
14324  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
14325  If you use a graphical user interface for the debugger you can skip the
14326  next sections.
14327 \layout Subsubsection*
14328
14329 break [line | file:line | function | file:function]
14330 \layout Standard
14331
14332 Set breakpoint at specified line or function:
14333 \newline 
14334
14335 \newline 
14336
14337 \family sans 
14338 \series bold 
14339 sdcdb>break 100 
14340 \newline 
14341 sdcdb>break foo.c:100
14342 \newline 
14343 sdcdb>break funcfoo
14344 \newline 
14345 sdcdb>break foo.c:funcfoo
14346 \layout Subsubsection*
14347
14348 clear [line | file:line | function | file:function ]
14349 \layout Standard
14350
14351 Clear breakpoint at specified line or function:
14352 \newline 
14353
14354 \newline 
14355
14356 \family sans 
14357 \series bold 
14358 sdcdb>clear 100
14359 \newline 
14360 sdcdb>clear foo.c:100
14361 \newline 
14362 sdcdb>clear funcfoo
14363 \newline 
14364 sdcdb>clear foo.c:funcfoo
14365 \layout Subsubsection*
14366
14367 continue
14368 \layout Standard
14369
14370 Continue program being debugged, after breakpoint.
14371 \layout Subsubsection*
14372
14373 finish
14374 \layout Standard
14375
14376 Execute till the end of the current function.
14377 \layout Subsubsection*
14378
14379 delete [n]
14380 \layout Standard
14381
14382 Delete breakpoint number 'n'.
14383  If used without any option clear ALL user defined break points.
14384 \layout Subsubsection*
14385
14386 info [break | stack | frame | registers ]
14387 \layout Itemize
14388
14389 info break - list all breakpoints
14390 \layout Itemize
14391
14392 info stack - show the function call stack.
14393 \layout Itemize
14394
14395 info frame - show information about the current execution frame.
14396 \layout Itemize
14397
14398 info registers - show content of all registers.
14399 \layout Subsubsection*
14400
14401 step
14402 \layout Standard
14403
14404 Step program until it reaches a different source line.
14405  Note: pressing <return> repeats the last command.
14406 \layout Subsubsection*
14407
14408 next
14409 \layout Standard
14410
14411 Step program, proceeding through subroutine calls.
14412 \layout Subsubsection*
14413
14414 run
14415 \layout Standard
14416
14417 Start debugged program.
14418 \layout Subsubsection*
14419
14420 ptype variable 
14421 \layout Standard
14422
14423 Print type information of the variable.
14424 \layout Subsubsection*
14425
14426 print variable
14427 \layout Standard
14428
14429 print value of variable.
14430 \layout Subsubsection*
14431
14432 file filename
14433 \layout Standard
14434
14435 load the given file name.
14436  Note this is an alternate method of loading file for debugging.
14437 \layout Subsubsection*
14438
14439 frame
14440 \layout Standard
14441
14442 print information about current frame.
14443 \layout Subsubsection*
14444
14445 set srcmode
14446 \layout Standard
14447
14448 Toggle between C source & assembly source.
14449 \layout Subsubsection*
14450
14451 ! simulator command
14452 \layout Standard
14453
14454 Send the string following '!' to the simulator, the simulator response is
14455  displayed.
14456  Note the debugger does not interpret the command being sent to the simulator,
14457  so if a command like 'go' is sent the debugger can loose its execution
14458  context and may display incorrect values.
14459 \layout Subsubsection*
14460
14461 quit
14462 \layout Standard
14463
14464 "Watch me now.
14465  Iam going Down.
14466  My name is Bobby Brown"
14467 \layout Section
14468
14469 Interfacing with XEmacs
14470 \begin_inset LatexCommand \index{XEmacs}
14471
14472 \end_inset 
14473
14474
14475 \begin_inset LatexCommand \index{Emacs}
14476
14477 \end_inset 
14478
14479 .
14480 \layout Standard
14481
14482 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
14483  sdcdb.el and sdcdbsrc.el.
14484  These two files can be found in the $(prefix)/bin directory after the installat
14485 ion is complete.
14486  These files need to be loaded into XEmacs for the interface to work.
14487  This can be done at XEmacs startup time by inserting the following into
14488  your '.xemacs' file (which can be found in your HOME directory): 
14489 \newline 
14490
14491 \newline 
14492
14493 \family typewriter 
14494 (load-file sdcdbsrc.el) 
14495 \family default 
14496
14497 \newline 
14498
14499 \newline 
14500 .xemacs is a lisp file so the () around the command is REQUIRED.
14501  The files can also be loaded dynamically while XEmacs is running, set the
14502  environment variable 'EMACSLOADPATH' to the installation bin directory
14503  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
14504  To start the interface enter the following command: 
14505 \newline 
14506
14507 \newline 
14508
14509 \family sans 
14510 \series bold 
14511 ESC-x sdcdbsrc
14512 \family default 
14513 \series default 
14514
14515 \newline 
14516
14517 \newline 
14518 You will prompted to enter the file name to be debugged.
14519  
14520 \newline 
14521
14522 \newline 
14523 The command line options that are passed to the simulator directly are bound
14524  to default values in the file sdcdbsrc.el.
14525  The variables are listed below, these values maybe changed as required.
14526 \layout Itemize
14527
14528 sdcdbsrc-cpu-type '51
14529 \layout Itemize
14530
14531 sdcdbsrc-frequency '11059200
14532 \layout Itemize
14533
14534 sdcdbsrc-serial nil
14535 \layout Standard
14536
14537 The following is a list of key mapping for the debugger interface.
14538 \layout Standard
14539
14540 \SpecialChar ~
14541
14542 \family typewriter 
14543
14544 \newline 
14545 ;; Current Listing :: 
14546 \newline 
14547 ;;key\SpecialChar ~
14548 \SpecialChar ~
14549 \SpecialChar ~
14550 \SpecialChar ~
14551 \SpecialChar ~
14552 \SpecialChar ~
14553 \SpecialChar ~
14554 \SpecialChar ~
14555 \SpecialChar ~
14556 \SpecialChar ~
14557 \SpecialChar ~
14558 \SpecialChar ~
14559 \SpecialChar ~
14560 \SpecialChar ~
14561 \SpecialChar ~
14562 binding\SpecialChar ~
14563 \SpecialChar ~
14564 \SpecialChar ~
14565 \SpecialChar ~
14566 \SpecialChar ~
14567 \SpecialChar ~
14568 \SpecialChar ~
14569 \SpecialChar ~
14570 \SpecialChar ~
14571 \SpecialChar ~
14572 \SpecialChar ~
14573 \SpecialChar ~
14574 \SpecialChar ~
14575 \SpecialChar ~
14576 \SpecialChar ~
14577 \SpecialChar ~
14578 \SpecialChar ~
14579 \SpecialChar ~
14580 \SpecialChar ~
14581 \SpecialChar ~
14582 \SpecialChar ~
14583 \SpecialChar ~
14584 Comment 
14585 \newline 
14586 ;;---\SpecialChar ~
14587 \SpecialChar ~
14588 \SpecialChar ~
14589 \SpecialChar ~
14590 \SpecialChar ~
14591 \SpecialChar ~
14592 \SpecialChar ~
14593 \SpecialChar ~
14594 \SpecialChar ~
14595 \SpecialChar ~
14596 \SpecialChar ~
14597 \SpecialChar ~
14598 \SpecialChar ~
14599 \SpecialChar ~
14600 \SpecialChar ~
14601 ------\SpecialChar ~
14602 \SpecialChar ~
14603 \SpecialChar ~
14604 \SpecialChar ~
14605 \SpecialChar ~
14606 \SpecialChar ~
14607 \SpecialChar ~
14608 \SpecialChar ~
14609 \SpecialChar ~
14610 \SpecialChar ~
14611 \SpecialChar ~
14612 \SpecialChar ~
14613 \SpecialChar ~
14614 \SpecialChar ~
14615 \SpecialChar ~
14616 \SpecialChar ~
14617 \SpecialChar ~
14618 \SpecialChar ~
14619 \SpecialChar ~
14620 \SpecialChar ~
14621 \SpecialChar ~
14622 \SpecialChar ~
14623 --------
14624 \newline 
14625 ;; 
14626 \newline 
14627 ;; n\SpecialChar ~
14628 \SpecialChar ~
14629 \SpecialChar ~
14630 \SpecialChar ~
14631 \SpecialChar ~
14632 \SpecialChar ~
14633 \SpecialChar ~
14634 \SpecialChar ~
14635 \SpecialChar ~
14636 \SpecialChar ~
14637 \SpecialChar ~
14638 \SpecialChar ~
14639 \SpecialChar ~
14640 \SpecialChar ~
14641  sdcdb-next-from-src\SpecialChar ~
14642 \SpecialChar ~
14643 \SpecialChar ~
14644 \SpecialChar ~
14645 \SpecialChar ~
14646 \SpecialChar ~
14647 \SpecialChar ~
14648 \SpecialChar ~
14649 \SpecialChar ~
14650 \SpecialChar ~
14651 SDCDB next command 
14652 \newline 
14653 ;; b\SpecialChar ~
14654 \SpecialChar ~
14655 \SpecialChar ~
14656 \SpecialChar ~
14657 \SpecialChar ~
14658 \SpecialChar ~
14659 \SpecialChar ~
14660 \SpecialChar ~
14661 \SpecialChar ~
14662 \SpecialChar ~
14663 \SpecialChar ~
14664 \SpecialChar ~
14665 \SpecialChar ~
14666 \SpecialChar ~
14667  sdcdb-back-from-src\SpecialChar ~
14668 \SpecialChar ~
14669 \SpecialChar ~
14670 \SpecialChar ~
14671 \SpecialChar ~
14672 \SpecialChar ~
14673 \SpecialChar ~
14674 \SpecialChar ~
14675 \SpecialChar ~
14676 \SpecialChar ~
14677 SDCDB back command 
14678 \newline 
14679 ;; c\SpecialChar ~
14680 \SpecialChar ~
14681 \SpecialChar ~
14682 \SpecialChar ~
14683 \SpecialChar ~
14684 \SpecialChar ~
14685 \SpecialChar ~
14686 \SpecialChar ~
14687 \SpecialChar ~
14688 \SpecialChar ~
14689 \SpecialChar ~
14690 \SpecialChar ~
14691 \SpecialChar ~
14692 \SpecialChar ~
14693  sdcdb-cont-from-src\SpecialChar ~
14694 \SpecialChar ~
14695 \SpecialChar ~
14696 \SpecialChar ~
14697 \SpecialChar ~
14698 \SpecialChar ~
14699 \SpecialChar ~
14700 \SpecialChar ~
14701 \SpecialChar ~
14702 \SpecialChar ~
14703 SDCDB continue command
14704 \newline 
14705 ;; s\SpecialChar ~
14706 \SpecialChar ~
14707 \SpecialChar ~
14708 \SpecialChar ~
14709 \SpecialChar ~
14710 \SpecialChar ~
14711 \SpecialChar ~
14712 \SpecialChar ~
14713 \SpecialChar ~
14714 \SpecialChar ~
14715 \SpecialChar ~
14716 \SpecialChar ~
14717 \SpecialChar ~
14718 \SpecialChar ~
14719  sdcdb-step-from-src\SpecialChar ~
14720 \SpecialChar ~
14721 \SpecialChar ~
14722 \SpecialChar ~
14723 \SpecialChar ~
14724 \SpecialChar ~
14725 \SpecialChar ~
14726 \SpecialChar ~
14727 \SpecialChar ~
14728 \SpecialChar ~
14729 SDCDB step command 
14730 \newline 
14731 ;; ?\SpecialChar ~
14732 \SpecialChar ~
14733 \SpecialChar ~
14734 \SpecialChar ~
14735 \SpecialChar ~
14736 \SpecialChar ~
14737 \SpecialChar ~
14738 \SpecialChar ~
14739 \SpecialChar ~
14740 \SpecialChar ~
14741 \SpecialChar ~
14742 \SpecialChar ~
14743 \SpecialChar ~
14744 \SpecialChar ~
14745  sdcdb-whatis-c-sexp\SpecialChar ~
14746 \SpecialChar ~
14747 \SpecialChar ~
14748 \SpecialChar ~
14749 \SpecialChar ~
14750 \SpecialChar ~
14751 \SpecialChar ~
14752 \SpecialChar ~
14753 \SpecialChar ~
14754 \SpecialChar ~
14755 SDCDB ptypecommand for data at 
14756 \newline 
14757 ;;\SpecialChar ~
14758 \SpecialChar ~
14759 \SpecialChar ~
14760 \SpecialChar ~
14761 \SpecialChar ~
14762 \SpecialChar ~
14763 \SpecialChar ~
14764 \SpecialChar ~
14765 \SpecialChar ~
14766 \SpecialChar ~
14767 \SpecialChar ~
14768 \SpecialChar ~
14769 \SpecialChar ~
14770 \SpecialChar ~
14771 \SpecialChar ~
14772 \SpecialChar ~
14773 \SpecialChar ~
14774 \SpecialChar ~
14775 \SpecialChar ~
14776 \SpecialChar ~
14777 \SpecialChar ~
14778 \SpecialChar ~
14779 \SpecialChar ~
14780 \SpecialChar ~
14781 \SpecialChar ~
14782 \SpecialChar ~
14783 \SpecialChar ~
14784 \SpecialChar ~
14785 \SpecialChar ~
14786 \SpecialChar ~
14787 \SpecialChar ~
14788 \SpecialChar ~
14789 \SpecialChar ~
14790 \SpecialChar ~
14791 \SpecialChar ~
14792 \SpecialChar ~
14793 \SpecialChar ~
14794 \SpecialChar ~
14795 \SpecialChar ~
14796 \SpecialChar ~
14797 \SpecialChar ~
14798 \SpecialChar ~
14799 \SpecialChar ~
14800 \SpecialChar ~
14801 \SpecialChar ~
14802 \SpecialChar ~
14803  buffer point 
14804 \newline 
14805 ;; x\SpecialChar ~
14806 \SpecialChar ~
14807 \SpecialChar ~
14808 \SpecialChar ~
14809 \SpecialChar ~
14810 \SpecialChar ~
14811 \SpecialChar ~
14812 \SpecialChar ~
14813 \SpecialChar ~
14814 \SpecialChar ~
14815 \SpecialChar ~
14816 \SpecialChar ~
14817 \SpecialChar ~
14818 \SpecialChar ~
14819  sdcdbsrc-delete\SpecialChar ~
14820 \SpecialChar ~
14821 \SpecialChar ~
14822 \SpecialChar ~
14823 \SpecialChar ~
14824 \SpecialChar ~
14825 \SpecialChar ~
14826 \SpecialChar ~
14827 \SpecialChar ~
14828 \SpecialChar ~
14829 \SpecialChar ~
14830 \SpecialChar ~
14831 \SpecialChar ~
14832 \SpecialChar ~
14833 SDCDB Delete all breakpoints if no arg 
14834 \newline 
14835 ;;\SpecialChar ~
14836 \SpecialChar ~
14837 \SpecialChar ~
14838 \SpecialChar ~
14839 \SpecialChar ~
14840 \SpecialChar ~
14841 \SpecialChar ~
14842 \SpecialChar ~
14843 \SpecialChar ~
14844 \SpecialChar ~
14845 \SpecialChar ~
14846 \SpecialChar ~
14847 \SpecialChar ~
14848 \SpecialChar ~
14849 \SpecialChar ~
14850 \SpecialChar ~
14851 \SpecialChar ~
14852 \SpecialChar ~
14853 \SpecialChar ~
14854 \SpecialChar ~
14855 \SpecialChar ~
14856 \SpecialChar ~
14857 \SpecialChar ~
14858 \SpecialChar ~
14859 \SpecialChar ~
14860 \SpecialChar ~
14861 \SpecialChar ~
14862 \SpecialChar ~
14863 \SpecialChar ~
14864 \SpecialChar ~
14865 \SpecialChar ~
14866 \SpecialChar ~
14867 \SpecialChar ~
14868 \SpecialChar ~
14869 \SpecialChar ~
14870 \SpecialChar ~
14871 \SpecialChar ~
14872 \SpecialChar ~
14873 \SpecialChar ~
14874 \SpecialChar ~
14875 \SpecialChar ~
14876 \SpecialChar ~
14877 \SpecialChar ~
14878 \SpecialChar ~
14879 \SpecialChar ~
14880 \SpecialChar ~
14881 given or delete arg (C-u arg x) 
14882 \newline 
14883 ;; m\SpecialChar ~
14884 \SpecialChar ~
14885 \SpecialChar ~
14886 \SpecialChar ~
14887 \SpecialChar ~
14888 \SpecialChar ~
14889 \SpecialChar ~
14890 \SpecialChar ~
14891 \SpecialChar ~
14892 \SpecialChar ~
14893 \SpecialChar ~
14894 \SpecialChar ~
14895 \SpecialChar ~
14896 \SpecialChar ~
14897  sdcdbsrc-frame\SpecialChar ~
14898 \SpecialChar ~
14899 \SpecialChar ~
14900 \SpecialChar ~
14901 \SpecialChar ~
14902 \SpecialChar ~
14903 \SpecialChar ~
14904 \SpecialChar ~
14905 \SpecialChar ~
14906 \SpecialChar ~
14907 \SpecialChar ~
14908 \SpecialChar ~
14909 \SpecialChar ~
14910 \SpecialChar ~
14911 \SpecialChar ~
14912 SDCDB Display current frame if no arg, 
14913 \newline 
14914 ;;\SpecialChar ~
14915 \SpecialChar ~
14916 \SpecialChar ~
14917 \SpecialChar ~
14918 \SpecialChar ~
14919 \SpecialChar ~
14920 \SpecialChar ~
14921 \SpecialChar ~
14922 \SpecialChar ~
14923 \SpecialChar ~
14924 \SpecialChar ~
14925 \SpecialChar ~
14926 \SpecialChar ~
14927 \SpecialChar ~
14928 \SpecialChar ~
14929 \SpecialChar ~
14930 \SpecialChar ~
14931 \SpecialChar ~
14932 \SpecialChar ~
14933 \SpecialChar ~
14934 \SpecialChar ~
14935 \SpecialChar ~
14936 \SpecialChar ~
14937 \SpecialChar ~
14938 \SpecialChar ~
14939 \SpecialChar ~
14940 \SpecialChar ~
14941 \SpecialChar ~
14942 \SpecialChar ~
14943 \SpecialChar ~
14944 \SpecialChar ~
14945 \SpecialChar ~
14946 \SpecialChar ~
14947 \SpecialChar ~
14948 \SpecialChar ~
14949 \SpecialChar ~
14950 \SpecialChar ~
14951 \SpecialChar ~
14952 \SpecialChar ~
14953 \SpecialChar ~
14954 \SpecialChar ~
14955 \SpecialChar ~
14956 \SpecialChar ~
14957 \SpecialChar ~
14958 \SpecialChar ~
14959 \SpecialChar ~
14960 \SpecialChar ~
14961 given or display frame arg 
14962 \newline 
14963 ;;\SpecialChar ~
14964 \SpecialChar ~
14965 \SpecialChar ~
14966 \SpecialChar ~
14967 \SpecialChar ~
14968 \SpecialChar ~
14969 \SpecialChar ~
14970 \SpecialChar ~
14971 \SpecialChar ~
14972 \SpecialChar ~
14973 \SpecialChar ~
14974 \SpecialChar ~
14975 \SpecialChar ~
14976 \SpecialChar ~
14977 \SpecialChar ~
14978 \SpecialChar ~
14979 \SpecialChar ~
14980 \SpecialChar ~
14981 \SpecialChar ~
14982 \SpecialChar ~
14983 \SpecialChar ~
14984 \SpecialChar ~
14985 \SpecialChar ~
14986 \SpecialChar ~
14987 \SpecialChar ~
14988 \SpecialChar ~
14989 \SpecialChar ~
14990 \SpecialChar ~
14991 \SpecialChar ~
14992 \SpecialChar ~
14993 \SpecialChar ~
14994 \SpecialChar ~
14995 \SpecialChar ~
14996 \SpecialChar ~
14997 \SpecialChar ~
14998 \SpecialChar ~
14999 \SpecialChar ~
15000 \SpecialChar ~
15001 \SpecialChar ~
15002 \SpecialChar ~
15003 \SpecialChar ~
15004 \SpecialChar ~
15005 \SpecialChar ~
15006 \SpecialChar ~
15007 \SpecialChar ~
15008 \SpecialChar ~
15009 \SpecialChar ~
15010 buffer point 
15011 \newline 
15012 ;; !\SpecialChar ~
15013 \SpecialChar ~
15014 \SpecialChar ~
15015 \SpecialChar ~
15016 \SpecialChar ~
15017 \SpecialChar ~
15018 \SpecialChar ~
15019 \SpecialChar ~
15020 \SpecialChar ~
15021 \SpecialChar ~
15022 \SpecialChar ~
15023 \SpecialChar ~
15024 \SpecialChar ~
15025 \SpecialChar ~
15026  sdcdbsrc-goto-sdcdb\SpecialChar ~
15027 \SpecialChar ~
15028 \SpecialChar ~
15029 \SpecialChar ~
15030 \SpecialChar ~
15031 \SpecialChar ~
15032 \SpecialChar ~
15033 \SpecialChar ~
15034 \SpecialChar ~
15035 \SpecialChar ~
15036 Goto the SDCDB output buffer 
15037 \newline 
15038 ;; p\SpecialChar ~
15039 \SpecialChar ~
15040 \SpecialChar ~
15041 \SpecialChar ~
15042 \SpecialChar ~
15043 \SpecialChar ~
15044 \SpecialChar ~
15045 \SpecialChar ~
15046 \SpecialChar ~
15047 \SpecialChar ~
15048 \SpecialChar ~
15049 \SpecialChar ~
15050 \SpecialChar ~
15051 \SpecialChar ~
15052  sdcdb-print-c-sexp\SpecialChar ~
15053 \SpecialChar ~
15054 \SpecialChar ~
15055 \SpecialChar ~
15056 \SpecialChar ~
15057 \SpecialChar ~
15058 \SpecialChar ~
15059 \SpecialChar ~
15060 \SpecialChar ~
15061 \SpecialChar ~
15062 \SpecialChar ~
15063 SDCDB print command for data at 
15064 \newline 
15065 ;;\SpecialChar ~
15066 \SpecialChar ~
15067 \SpecialChar ~
15068 \SpecialChar ~
15069 \SpecialChar ~
15070 \SpecialChar ~
15071 \SpecialChar ~
15072 \SpecialChar ~
15073 \SpecialChar ~
15074 \SpecialChar ~
15075 \SpecialChar ~
15076 \SpecialChar ~
15077 \SpecialChar ~
15078 \SpecialChar ~
15079 \SpecialChar ~
15080 \SpecialChar ~
15081 \SpecialChar ~
15082 \SpecialChar ~
15083 \SpecialChar ~
15084 \SpecialChar ~
15085 \SpecialChar ~
15086 \SpecialChar ~
15087 \SpecialChar ~
15088 \SpecialChar ~
15089 \SpecialChar ~
15090 \SpecialChar ~
15091 \SpecialChar ~
15092 \SpecialChar ~
15093 \SpecialChar ~
15094 \SpecialChar ~
15095 \SpecialChar ~
15096 \SpecialChar ~
15097 \SpecialChar ~
15098 \SpecialChar ~
15099 \SpecialChar ~
15100 \SpecialChar ~
15101 \SpecialChar ~
15102 \SpecialChar ~
15103 \SpecialChar ~
15104 \SpecialChar ~
15105 \SpecialChar ~
15106 \SpecialChar ~
15107 \SpecialChar ~
15108 \SpecialChar ~
15109 \SpecialChar ~
15110 \SpecialChar ~
15111  buffer point 
15112 \newline 
15113 ;; g\SpecialChar ~
15114 \SpecialChar ~
15115 \SpecialChar ~
15116 \SpecialChar ~
15117 \SpecialChar ~
15118 \SpecialChar ~
15119 \SpecialChar ~
15120 \SpecialChar ~
15121 \SpecialChar ~
15122 \SpecialChar ~
15123 \SpecialChar ~
15124 \SpecialChar ~
15125 \SpecialChar ~
15126 \SpecialChar ~
15127  sdcdbsrc-goto-sdcdb\SpecialChar ~
15128 \SpecialChar ~
15129 \SpecialChar ~
15130 \SpecialChar ~
15131 \SpecialChar ~
15132 \SpecialChar ~
15133 \SpecialChar ~
15134 \SpecialChar ~
15135 \SpecialChar ~
15136 \SpecialChar ~
15137 Goto the SDCDB output buffer 
15138 \newline 
15139 ;; t\SpecialChar ~
15140 \SpecialChar ~
15141 \SpecialChar ~
15142 \SpecialChar ~
15143 \SpecialChar ~
15144 \SpecialChar ~
15145 \SpecialChar ~
15146 \SpecialChar ~
15147 \SpecialChar ~
15148 \SpecialChar ~
15149 \SpecialChar ~
15150 \SpecialChar ~
15151 \SpecialChar ~
15152 \SpecialChar ~
15153  sdcdbsrc-mode\SpecialChar ~
15154 \SpecialChar ~
15155 \SpecialChar ~
15156 \SpecialChar ~
15157 \SpecialChar ~
15158 \SpecialChar ~
15159 \SpecialChar ~
15160 \SpecialChar ~
15161 \SpecialChar ~
15162 \SpecialChar ~
15163 \SpecialChar ~
15164 \SpecialChar ~
15165 \SpecialChar ~
15166 \SpecialChar ~
15167 \SpecialChar ~
15168 \SpecialChar ~
15169 Toggles Sdcdbsrc mode (turns it off) 
15170 \newline 
15171 ;; 
15172 \newline 
15173 ;; C-c C-f\SpecialChar ~
15174 \SpecialChar ~
15175 \SpecialChar ~
15176 \SpecialChar ~
15177 \SpecialChar ~
15178 \SpecialChar ~
15179 \SpecialChar ~
15180 \SpecialChar ~
15181  sdcdb-finish-from-src\SpecialChar ~
15182 \SpecialChar ~
15183 \SpecialChar ~
15184 \SpecialChar ~
15185 \SpecialChar ~
15186 \SpecialChar ~
15187 \SpecialChar ~
15188 \SpecialChar ~
15189 SDCDB finish command 
15190 \newline 
15191 ;; 
15192 \newline 
15193 ;; C-x SPC\SpecialChar ~
15194 \SpecialChar ~
15195 \SpecialChar ~
15196 \SpecialChar ~
15197 \SpecialChar ~
15198 \SpecialChar ~
15199 \SpecialChar ~
15200 \SpecialChar ~
15201  sdcdb-break\SpecialChar ~
15202 \SpecialChar ~
15203 \SpecialChar ~
15204 \SpecialChar ~
15205 \SpecialChar ~
15206 \SpecialChar ~
15207 \SpecialChar ~
15208 \SpecialChar ~
15209 \SpecialChar ~
15210 \SpecialChar ~
15211 \SpecialChar ~
15212 \SpecialChar ~
15213 \SpecialChar ~
15214 \SpecialChar ~
15215 \SpecialChar ~
15216 \SpecialChar ~
15217 \SpecialChar ~
15218 \SpecialChar ~
15219 Set break for line with point 
15220 \newline 
15221 ;; ESC t\SpecialChar ~
15222 \SpecialChar ~
15223 \SpecialChar ~
15224 \SpecialChar ~
15225 \SpecialChar ~
15226 \SpecialChar ~
15227 \SpecialChar ~
15228 \SpecialChar ~
15229 \SpecialChar ~
15230 \SpecialChar ~
15231  sdcdbsrc-mode\SpecialChar ~
15232 \SpecialChar ~
15233 \SpecialChar ~
15234 \SpecialChar ~
15235 \SpecialChar ~
15236 \SpecialChar ~
15237 \SpecialChar ~
15238 \SpecialChar ~
15239 \SpecialChar ~
15240 \SpecialChar ~
15241 \SpecialChar ~
15242 \SpecialChar ~
15243 \SpecialChar ~
15244 \SpecialChar ~
15245 \SpecialChar ~
15246 \SpecialChar ~
15247 Toggle Sdcdbsrc mode 
15248 \newline 
15249 ;; ESC m\SpecialChar ~
15250 \SpecialChar ~
15251 \SpecialChar ~
15252 \SpecialChar ~
15253 \SpecialChar ~
15254 \SpecialChar ~
15255 \SpecialChar ~
15256 \SpecialChar ~
15257 \SpecialChar ~
15258 \SpecialChar ~
15259  sdcdbsrc-srcmode\SpecialChar ~
15260 \SpecialChar ~
15261 \SpecialChar ~
15262 \SpecialChar ~
15263 \SpecialChar ~
15264 \SpecialChar ~
15265 \SpecialChar ~
15266 \SpecialChar ~
15267 \SpecialChar ~
15268 \SpecialChar ~
15269 \SpecialChar ~
15270 \SpecialChar ~
15271  Toggle list mode 
15272 \newline 
15273 ;; 
15274 \newline 
15275
15276 \layout Chapter
15277 \pagebreak_top 
15278 TIPS
15279 \layout Standard
15280
15281 Here are a few guidelines that will help the compiler generate more efficient
15282  code, some of the tips are specific to this compiler others are generally
15283  good programming practice.
15284 \layout Itemize
15285
15286 Use the smallest data type to represent your data-value.
15287  If it is known in advance that the value is going to be less than 256 then
15288  use an 'unsigned char' instead of a 'short' or 'int'.
15289  Please note, that ANSI C requires both signed and unsigned chars to be
15290  promoted to 'signed int' before doing any operation.
15291  This promotion can be omitted, if the result is the same.
15292  The effect of the promotion rules together with the sign-extension is often
15293  supprising:
15294 \begin_deeper 
15295 \layout Verse
15296
15297
15298 \family typewriter 
15299 unsigned char uc = 0xfe;
15300 \newline 
15301 if (uc * uc < 0) /* this is true! */
15302 \newline 
15303 {
15304 \newline 
15305 \SpecialChar ~
15306 \SpecialChar ~
15307 \SpecialChar ~
15308 \SpecialChar ~
15309 ....
15310 \newline 
15311 }
15312 \layout Standard
15313
15314
15315 \family typewriter 
15316 uc * uc
15317 \family default 
15318  is evaluated as 
15319 \family typewriter 
15320 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
15321 \family default 
15322 .
15323  
15324 \newline 
15325 Another one:
15326 \layout Verse
15327
15328
15329 \family typewriter 
15330 (unsigned char) -12 / (signed char) -3 = ...
15331 \layout Standard
15332
15333 No, the result is not 4:
15334 \layout Verse
15335
15336
15337 \family typewriter 
15338 (int) (unsigned char) -12 / (int) (signed char) -3 =
15339 \newline 
15340 (int) (unsigned char) 0xf4 / (int) (signed char) 0xfd =
15341 \newline 
15342 (int) 0x00f4 / (int) 0xfffd =
15343 \newline 
15344 (int) 0x00f4 / (int) 0xfffd =
15345 \newline 
15346 (int) 244 / (int) -3 =
15347 \newline 
15348 (int) -81 = (int) 0xffaf;
15349 \layout Standard
15350
15351 Don't complain, that gcc gives you a different result.
15352  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
15353  Therefore the results are different.
15354 \newline 
15355 From 
15356 \begin_inset Quotes sld
15357 \end_inset 
15358
15359 comp.lang.c FAQ
15360 \begin_inset Quotes srd
15361 \end_inset 
15362
15363 :
15364 \layout Quote
15365
15366 If well-defined overflow characteristics are important and negative values
15367  are not, or if you want to steer clear of sign-extension problems when
15368  manipulating bits or bytes, use one of the corresponding unsigned types.
15369  (Beware when mixing signed and unsigned values in expressions, though.)
15370 \newline 
15371 Although character types (especially unsigned char) can be used as "tiny"
15372  integers, doing so is sometimes more trouble than it's worth, due to unpredicta
15373 ble sign extension and increased code size.
15374 \end_deeper 
15375 \layout Itemize
15376
15377 Use unsigned when it is known in advance that the value is not going to
15378  be negative.
15379  This helps especially if you are doing division or multiplication, bit-shifting
15380  or are using an array index.
15381 \layout Itemize
15382
15383 NEVER jump into a LOOP.
15384 \layout Itemize
15385
15386 Declare the variables to be local
15387 \begin_inset LatexCommand \index{local variables}
15388
15389 \end_inset 
15390
15391  whenever possible, especially loop control variables (induction).
15392 \layout Itemize
15393
15394 Since the compiler does not always do implicit integral promotion, the programme
15395 r should do an explicit cast when integral promotion is required.
15396 \layout Itemize
15397
15398 Reducing the size of division, multiplication & modulus operations can reduce
15399  code size substantially.
15400  Take the following code for example.
15401 \begin_deeper 
15402 \layout Verse
15403
15404
15405 \family typewriter 
15406 foobar(unsigned int p1, unsigned char ch)
15407 \newline 
15408 {
15409 \newline 
15410 \SpecialChar ~
15411 \SpecialChar ~
15412 \SpecialChar ~
15413 \SpecialChar ~
15414 unsigned char ch1 = p1 % ch ;
15415 \newline 
15416 \SpecialChar ~
15417 \SpecialChar ~
15418 \SpecialChar ~
15419 \SpecialChar ~
15420 ....
15421 \newline 
15422 }
15423 \layout Standard
15424
15425 For the modulus operation the variable ch will be promoted to unsigned int
15426  first then the modulus operation will be performed (this will lead to a
15427  call to support routine _moduint()), and the result will be casted to a
15428  char.
15429  If the code is changed to 
15430 \layout Verse
15431
15432
15433 \family typewriter 
15434 foobar(unsigned int p1, unsigned char ch)
15435 \newline 
15436 {
15437 \newline 
15438 \SpecialChar ~
15439 \SpecialChar ~
15440 \SpecialChar ~
15441 \SpecialChar ~
15442 unsigned char ch1 = (unsigned char)p1 % ch ;
15443 \newline 
15444 \SpecialChar ~
15445 \SpecialChar ~
15446 \SpecialChar ~
15447 \SpecialChar ~
15448 ....
15449 \newline 
15450 }
15451 \layout Standard
15452
15453 It would substantially reduce the code generated (future versions of the
15454  compiler will be smart enough to detect such optimization opportunities).
15455 \end_deeper 
15456 \layout Itemize
15457
15458 Have a look at the assembly listing to get a 
15459 \begin_inset Quotes sld
15460 \end_inset 
15461
15462 feeling
15463 \begin_inset Quotes srd
15464 \end_inset 
15465
15466  for the code generation.
15467 \layout Section
15468
15469 Tools
15470 \begin_inset LatexCommand \index{Tools}
15471
15472 \end_inset 
15473
15474  included in the distribution
15475 \layout Standard
15476 \align center 
15477
15478 \begin_inset  Tabular
15479 <lyxtabular version="3" rows="12" columns="3">
15480 <features>
15481 <column alignment="center" valignment="top" leftline="true" width="0pt">
15482 <column alignment="center" valignment="top" leftline="true" width="0pt">
15483 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
15484 <row topline="true" bottomline="true">
15485 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15486 \begin_inset Text
15487
15488 \layout Standard
15489
15490 Name
15491 \end_inset 
15492 </cell>
15493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15494 \begin_inset Text
15495
15496 \layout Standard
15497
15498 Purpose
15499 \end_inset 
15500 </cell>
15501 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15502 \begin_inset Text
15503
15504 \layout Standard
15505
15506 Directory
15507 \end_inset 
15508 </cell>
15509 </row>
15510 <row topline="true">
15511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15512 \begin_inset Text
15513
15514 \layout Standard
15515
15516 uCsim
15517 \end_inset 
15518 </cell>
15519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15520 \begin_inset Text
15521
15522 \layout Standard
15523
15524 Simulator for various architectures
15525 \end_inset 
15526 </cell>
15527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15528 \begin_inset Text
15529
15530 \layout Standard
15531
15532 sdcc/sim/ucsim
15533 \end_inset 
15534 </cell>
15535 </row>
15536 <row topline="true">
15537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15538 \begin_inset Text
15539
15540 \layout Standard
15541
15542 keil2sdcc.pl
15543 \end_inset 
15544 </cell>
15545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15546 \begin_inset Text
15547
15548 \layout Standard
15549
15550 header file conversion
15551 \end_inset 
15552 </cell>
15553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15554 \begin_inset Text
15555
15556 \layout Standard
15557
15558 sdcc/support/scripts
15559 \end_inset 
15560 </cell>
15561 </row>
15562 <row topline="true">
15563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15564 \begin_inset Text
15565
15566 \layout Standard
15567
15568 mh2h.c
15569 \end_inset 
15570 </cell>
15571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15572 \begin_inset Text
15573
15574 \layout Standard
15575
15576 header file conversion
15577 \end_inset 
15578 </cell>
15579 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15580 \begin_inset Text
15581
15582 \layout Standard
15583
15584 sdcc/support/scripts
15585 \end_inset 
15586 </cell>
15587 </row>
15588 <row topline="true">
15589 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15590 \begin_inset Text
15591
15592 \layout Standard
15593
15594 as-gbz80
15595 \end_inset 
15596 </cell>
15597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15598 \begin_inset Text
15599
15600 \layout Standard
15601
15602 Assembler
15603 \end_inset 
15604 </cell>
15605 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15606 \begin_inset Text
15607
15608 \layout Standard
15609
15610
15611 \family roman 
15612 \series medium 
15613 \shape up 
15614 \size normal 
15615 \emph off 
15616 \bar no 
15617 \noun off 
15618 \color none
15619 sdcc/bin
15620 \end_inset 
15621 </cell>
15622 </row>
15623 <row topline="true">
15624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15625 \begin_inset Text
15626
15627 \layout Standard
15628
15629 as-z80
15630 \end_inset 
15631 </cell>
15632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15633 \begin_inset Text
15634
15635 \layout Standard
15636
15637 Assembler
15638 \end_inset 
15639 </cell>
15640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15641 \begin_inset Text
15642
15643 \layout Standard
15644
15645
15646 \family roman 
15647 \series medium 
15648 \shape up 
15649 \size normal 
15650 \emph off 
15651 \bar no 
15652 \noun off 
15653 \color none
15654 sdcc/bin
15655 \end_inset 
15656 </cell>
15657 </row>
15658 <row topline="true">
15659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15660 \begin_inset Text
15661
15662 \layout Standard
15663
15664 asx8051
15665 \end_inset 
15666 </cell>
15667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15668 \begin_inset Text
15669
15670 \layout Standard
15671
15672 Assembler
15673 \end_inset 
15674 </cell>
15675 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15676 \begin_inset Text
15677
15678 \layout Standard
15679
15680
15681 \family roman 
15682 \series medium 
15683 \shape up 
15684 \size normal 
15685 \emph off 
15686 \bar no 
15687 \noun off 
15688 \color none
15689 sdcc/bin
15690 \end_inset 
15691 </cell>
15692 </row>
15693 <row topline="true">
15694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15695 \begin_inset Text
15696
15697 \layout Standard
15698
15699 sdcdb
15700 \end_inset 
15701 </cell>
15702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15703 \begin_inset Text
15704
15705 \layout Standard
15706
15707 Simulator
15708 \end_inset 
15709 </cell>
15710 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15711 \begin_inset Text
15712
15713 \layout Standard
15714
15715
15716 \family roman 
15717 \series medium 
15718 \shape up 
15719 \size normal 
15720 \emph off 
15721 \bar no 
15722 \noun off 
15723 \color none
15724 sdcc/bin
15725 \end_inset 
15726 </cell>
15727 </row>
15728 <row topline="true">
15729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15730 \begin_inset Text
15731
15732 \layout Standard
15733
15734 aslink
15735 \end_inset 
15736 </cell>
15737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15738 \begin_inset Text
15739
15740 \layout Standard
15741
15742 Linker
15743 \end_inset 
15744 </cell>
15745 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15746 \begin_inset Text
15747
15748 \layout Standard
15749
15750
15751 \family roman 
15752 \series medium 
15753 \shape up 
15754 \size normal 
15755 \emph off 
15756 \bar no 
15757 \noun off 
15758 \color none
15759 sdcc/bin
15760 \end_inset 
15761 </cell>
15762 </row>
15763 <row topline="true">
15764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15765 \begin_inset Text
15766
15767 \layout Standard
15768
15769 link-z80
15770 \end_inset 
15771 </cell>
15772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15773 \begin_inset Text
15774
15775 \layout Standard
15776
15777 Linker
15778 \end_inset 
15779 </cell>
15780 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15781 \begin_inset Text
15782
15783 \layout Standard
15784
15785
15786 \family roman 
15787 \series medium 
15788 \shape up 
15789 \size normal 
15790 \emph off 
15791 \bar no 
15792 \noun off 
15793 \color none
15794 sdcc/bin
15795 \end_inset 
15796 </cell>
15797 </row>
15798 <row topline="true">
15799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15800 \begin_inset Text
15801
15802 \layout Standard
15803
15804 link-gbz80
15805 \end_inset 
15806 </cell>
15807 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15808 \begin_inset Text
15809
15810 \layout Standard
15811
15812 Linker
15813 \end_inset 
15814 </cell>
15815 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15816 \begin_inset Text
15817
15818 \layout Standard
15819
15820
15821 \family roman 
15822 \series medium 
15823 \shape up 
15824 \size normal 
15825 \emph off 
15826 \bar no 
15827 \noun off 
15828 \color none
15829 sdcc/bin
15830 \end_inset 
15831 </cell>
15832 </row>
15833 <row topline="true" bottomline="true">
15834 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15835 \begin_inset Text
15836
15837 \layout Standard
15838
15839 packihx
15840 \end_inset 
15841 </cell>
15842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15843 \begin_inset Text
15844
15845 \layout Standard
15846
15847 ihx packer
15848 \end_inset 
15849 </cell>
15850 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15851 \begin_inset Text
15852
15853 \layout Standard
15854
15855
15856 \family roman 
15857 \series medium 
15858 \shape up 
15859 \size normal 
15860 \emph off 
15861 \bar no 
15862 \noun off 
15863 \color none
15864 sdcc/bin
15865 \end_inset 
15866 </cell>
15867 </row>
15868 </lyxtabular>
15869
15870 \end_inset 
15871
15872
15873 \newline 
15874
15875 \layout Section
15876
15877 Documentation
15878 \begin_inset LatexCommand \index{Documentation}
15879
15880 \end_inset 
15881
15882  included in the distribution
15883 \layout Standard
15884 \align center 
15885
15886 \begin_inset  Tabular
15887 <lyxtabular version="3" rows="10" columns="2">
15888 <features>
15889 <column alignment="left" valignment="top" leftline="true" width="0(null)">
15890 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
15891 <row topline="true" bottomline="true">
15892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15893 \begin_inset Text
15894
15895 \layout Standard
15896
15897 Subject / Title
15898 \end_inset 
15899 </cell>
15900 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15901 \begin_inset Text
15902
15903 \layout Standard
15904
15905 Where to get / filename
15906 \end_inset 
15907 </cell>
15908 </row>
15909 <row topline="true">
15910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15911 \begin_inset Text
15912
15913 \layout Standard
15914
15915 SDCC Compiler User Guide
15916 \end_inset 
15917 </cell>
15918 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15919 \begin_inset Text
15920
15921 \layout Standard
15922
15923 You're reading it right now
15924 \end_inset 
15925 </cell>
15926 </row>
15927 <row topline="true">
15928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15929 \begin_inset Text
15930
15931 \layout Standard
15932
15933 Changelog of SDCC
15934 \end_inset 
15935 </cell>
15936 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15937 \begin_inset Text
15938
15939 \layout Standard
15940
15941 sdcc/Changelog
15942 \end_inset 
15943 </cell>
15944 </row>
15945 <row topline="true">
15946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15947 \begin_inset Text
15948
15949 \layout Standard
15950
15951 ASXXXX Assemblers and ASLINK Relocating Linker
15952 \end_inset 
15953 </cell>
15954 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15955 \begin_inset Text
15956
15957 \layout Standard
15958
15959 sdcc/as/doc/asxhtm.html
15960 \end_inset 
15961 </cell>
15962 </row>
15963 <row topline="true">
15964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15965 \begin_inset Text
15966
15967 \layout Standard
15968
15969 SDCC regression test
15970 \begin_inset LatexCommand \index{Regression test}
15971
15972 \end_inset 
15973
15974
15975 \end_inset 
15976 </cell>
15977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15978 \begin_inset Text
15979
15980 \layout Standard
15981
15982 sdcc/doc/test_suite_spec.pdf
15983 \end_inset 
15984 </cell>
15985 </row>
15986 <row topline="true">
15987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15988 \begin_inset Text
15989
15990 \layout Standard
15991
15992 Various notes
15993 \end_inset 
15994 </cell>
15995 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15996 \begin_inset Text
15997
15998 \layout Standard
15999
16000 sdcc/doc/*
16001 \end_inset 
16002 </cell>
16003 </row>
16004 <row topline="true">
16005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16006 \begin_inset Text
16007
16008 \layout Standard
16009
16010 Notes on debugging with sdcdb
16011 \begin_inset LatexCommand \index{sdcdb (debugger)}
16012
16013 \end_inset 
16014
16015
16016 \end_inset 
16017 </cell>
16018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16019 \begin_inset Text
16020
16021 \layout Standard
16022
16023 sdcc/debugger/README
16024 \end_inset 
16025 </cell>
16026 </row>
16027 <row topline="true">
16028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16029 \begin_inset Text
16030
16031 \layout Standard
16032
16033 Software simulator for microcontrollers
16034 \end_inset 
16035 </cell>
16036 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16037 \begin_inset Text
16038
16039 \layout Standard
16040
16041
16042 \family roman 
16043 \series medium 
16044 \shape up 
16045 \size normal 
16046 \emph off 
16047 \bar no 
16048 \noun off 
16049 \color none
16050 sdcc/sim/ucsim/doc
16051 \family default 
16052 \series default 
16053 \shape default 
16054 \size default 
16055 \emph default 
16056 \bar default 
16057 \noun default 
16058 \color default
16059 /index.html
16060 \end_inset 
16061 </cell>
16062 </row>
16063 <row topline="true">
16064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16065 \begin_inset Text
16066
16067 \layout Standard
16068
16069 Temporary notes on the pic16
16070 \begin_inset LatexCommand \index{PIC16}
16071
16072 \end_inset 
16073
16074  port
16075 \end_inset 
16076 </cell>
16077 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16078 \begin_inset Text
16079
16080 \layout Standard
16081
16082 sdcc/src/pic16/NOTES
16083 \end_inset 
16084 </cell>
16085 </row>
16086 <row topline="true" bottomline="true">
16087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16088 \begin_inset Text
16089
16090 \layout Standard
16091
16092 SDCC internal documentation (debugging file format)
16093 \end_inset 
16094 </cell>
16095 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16096 \begin_inset Text
16097
16098 \layout Standard
16099
16100 sdcc/doc/
16101 \family roman 
16102 \series medium 
16103 \shape up 
16104 \size normal 
16105 \emph off 
16106 \bar no 
16107 \noun off 
16108 \color none
16109 cdbfileformat.pd
16110 \family default 
16111 \series default 
16112 \shape default 
16113 \size default 
16114 \emph default 
16115 \bar default 
16116 \noun default 
16117 \color default
16118 f
16119 \end_inset 
16120 </cell>
16121 </row>
16122 </lyxtabular>
16123
16124 \end_inset 
16125
16126
16127 \newline 
16128
16129 \layout Section
16130
16131 Related open source tools
16132 \begin_inset LatexCommand \index{Related tools}
16133
16134 \end_inset 
16135
16136
16137 \layout Standard
16138 \align center 
16139
16140 \begin_inset  Tabular
16141 <lyxtabular version="3" rows="10" columns="3">
16142 <features>
16143 <column alignment="center" valignment="top" leftline="true" width="0pt">
16144 <column alignment="block" valignment="top" leftline="true" width="30line%">
16145 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
16146 <row topline="true" bottomline="true">
16147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16148 \begin_inset Text
16149
16150 \layout Standard
16151
16152 Name
16153 \end_inset 
16154 </cell>
16155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16156 \begin_inset Text
16157
16158 \layout Standard
16159
16160 Purpose
16161 \end_inset 
16162 </cell>
16163 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16164 \begin_inset Text
16165
16166 \layout Standard
16167
16168 Where to get
16169 \end_inset 
16170 </cell>
16171 </row>
16172 <row topline="true">
16173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16174 \begin_inset Text
16175
16176 \layout Standard
16177
16178 gpsim
16179 \begin_inset LatexCommand \index{gpsim (PIC simulator)}
16180
16181 \end_inset 
16182
16183
16184 \end_inset 
16185 </cell>
16186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16187 \begin_inset Text
16188
16189 \layout Standard
16190
16191 PIC simulator
16192 \end_inset 
16193 </cell>
16194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16195 \begin_inset Text
16196
16197 \layout Standard
16198
16199
16200 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
16201
16202 \end_inset 
16203
16204
16205 \end_inset 
16206 </cell>
16207 </row>
16208 <row topline="true">
16209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16210 \begin_inset Text
16211
16212 \layout Standard
16213
16214 flP5
16215 \end_inset 
16216 </cell>
16217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16218 \begin_inset Text
16219
16220 \layout Standard
16221
16222 PIC programmer
16223 \end_inset 
16224 </cell>
16225 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16226 \begin_inset Text
16227
16228 \layout Standard
16229
16230
16231 \begin_inset LatexCommand \url{http://digilander.libero.it/fbradasc/FLP5.html}
16232
16233 \end_inset 
16234
16235
16236 \end_inset 
16237 </cell>
16238 </row>
16239 <row topline="true">
16240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16241 \begin_inset Text
16242
16243 \layout Standard
16244
16245 indent
16246 \begin_inset LatexCommand \index{indent (source formatting tool)}
16247
16248 \end_inset 
16249
16250
16251 \end_inset 
16252 </cell>
16253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16254 \begin_inset Text
16255
16256 \layout Standard
16257
16258 Formats C source - Master of the white spaces
16259 \end_inset 
16260 </cell>
16261 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16262 \begin_inset Text
16263
16264 \layout Standard
16265
16266
16267 \begin_inset LatexCommand \url{http://home.hccnet.nl/d.ingamells/beautify.html}
16268
16269 \end_inset 
16270
16271
16272 \end_inset 
16273 </cell>
16274 </row>
16275 <row topline="true">
16276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16277 \begin_inset Text
16278
16279 \layout Standard
16280
16281 srecord
16282 \begin_inset LatexCommand \index{srecord (tool)}
16283
16284 \end_inset 
16285
16286
16287 \end_inset 
16288 </cell>
16289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16290 \begin_inset Text
16291
16292 \layout Standard
16293
16294 Object file conversion, checksumming, ...
16295 \end_inset 
16296 </cell>
16297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16298 \begin_inset Text
16299
16300 \layout Standard
16301
16302
16303 \begin_inset LatexCommand \url{http://srecord.sourceforge.net/}
16304
16305 \end_inset 
16306
16307
16308 \end_inset 
16309 </cell>
16310 </row>
16311 <row topline="true">
16312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16313 \begin_inset Text
16314
16315 \layout Standard
16316
16317 objdump
16318 \begin_inset LatexCommand \index{objdump (tool)}
16319
16320 \end_inset 
16321
16322
16323 \end_inset 
16324 </cell>
16325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16326 \begin_inset Text
16327
16328 \layout Standard
16329
16330 Object file conversion, ...
16331 \end_inset 
16332 </cell>
16333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16334 \begin_inset Text
16335
16336 \layout Standard
16337
16338 Part of binutils (should be there anyway)
16339 \end_inset 
16340 </cell>
16341 </row>
16342 <row topline="true">
16343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16344 \begin_inset Text
16345
16346 \layout Standard
16347
16348 doxygen
16349 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
16350
16351 \end_inset 
16352
16353
16354 \end_inset 
16355 </cell>
16356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16357 \begin_inset Text
16358
16359 \layout Standard
16360
16361 Source code documentation system
16362 \end_inset 
16363 </cell>
16364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16365 \begin_inset Text
16366
16367 \layout Standard
16368
16369
16370 \begin_inset LatexCommand \url{http://www.doxygen.org}
16371
16372 \end_inset 
16373
16374
16375 \end_inset 
16376 </cell>
16377 </row>
16378 <row topline="true">
16379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16380 \begin_inset Text
16381
16382 \layout Standard
16383
16384 kdevelop
16385 \end_inset 
16386 </cell>
16387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16388 \begin_inset Text
16389
16390 \layout Standard
16391
16392 IDE (has anyone tried integrating SDCC & sdcdb? Unix only)
16393 \end_inset 
16394 </cell>
16395 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16396 \begin_inset Text
16397
16398 \layout Standard
16399
16400
16401 \begin_inset LatexCommand \url{http://www.kdevelop.org}
16402
16403 \end_inset 
16404
16405
16406 \end_inset 
16407 </cell>
16408 </row>
16409 <row topline="true">
16410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16411 \begin_inset Text
16412
16413 \layout Standard
16414
16415 splint
16416 \begin_inset LatexCommand \index{splint (syntax checking tool)}
16417
16418 \end_inset 
16419
16420
16421 \end_inset 
16422 </cell>
16423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16424 \begin_inset Text
16425
16426 \layout Standard
16427
16428 Statically checks c sources
16429 \end_inset 
16430 </cell>
16431 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16432 \begin_inset Text
16433
16434 \layout Standard
16435
16436
16437 \begin_inset LatexCommand \url{http://www.splint.org}
16438
16439 \end_inset 
16440
16441
16442 \end_inset 
16443 </cell>
16444 </row>
16445 <row topline="true" bottomline="true">
16446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16447 \begin_inset Text
16448
16449 \layout Standard
16450
16451 ddd
16452 \begin_inset LatexCommand \index{ddd (debugger)}
16453
16454 \end_inset 
16455
16456
16457 \end_inset 
16458 </cell>
16459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16460 \begin_inset Text
16461
16462 \layout Standard
16463
16464 Debugger, serves nicely as GUI to sdcdb
16465 \begin_inset LatexCommand \index{sdcdb (debugger)}
16466
16467 \end_inset 
16468
16469  (Unix only)
16470 \end_inset 
16471 </cell>
16472 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16473 \begin_inset Text
16474
16475 \layout Standard
16476
16477
16478 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
16479
16480 \end_inset 
16481
16482
16483 \end_inset 
16484 </cell>
16485 </row>
16486 </lyxtabular>
16487
16488 \end_inset 
16489
16490
16491 \newline 
16492
16493 \layout Section
16494
16495 Related documentation / recommended reading
16496 \layout Standard
16497 \align center 
16498
16499 \begin_inset  Tabular
16500 <lyxtabular version="3" rows="4" columns="3">
16501 <features>
16502 <column alignment="center" valignment="top" leftline="true" width="0pt">
16503 <column alignment="block" valignment="top" leftline="true" width="30line%">
16504 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
16505 <row topline="true" bottomline="true">
16506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16507 \begin_inset Text
16508
16509 \layout Standard
16510
16511 Name
16512 \end_inset 
16513 </cell>
16514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16515 \begin_inset Text
16516
16517 \layout Standard
16518
16519 Subject / Title
16520 \end_inset 
16521 </cell>
16522 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16523 \begin_inset Text
16524
16525 \layout Standard
16526
16527 Where to get
16528 \end_inset 
16529 </cell>
16530 </row>
16531 <row topline="true">
16532 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16533 \begin_inset Text
16534
16535 \layout Standard
16536
16537
16538 \family roman 
16539 \series medium 
16540 \shape up 
16541 \size normal 
16542 \emph off 
16543 \bar no 
16544 \noun off 
16545 \color none
16546 c-refcard.pdf
16547 \end_inset 
16548 </cell>
16549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16550 \begin_inset Text
16551
16552 \layout Standard
16553
16554 C Reference Card
16555 \begin_inset LatexCommand \index{C Reference card}
16556
16557 \end_inset 
16558
16559 , 2 pages
16560 \end_inset 
16561 </cell>
16562 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16563 \begin_inset Text
16564
16565 \layout Standard
16566
16567
16568 \begin_inset LatexCommand \url{http://www.refcards.com/about/c.html}
16569
16570 \end_inset 
16571
16572
16573 \end_inset 
16574 </cell>
16575 </row>
16576 <row topline="true">
16577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16578 \begin_inset Text
16579
16580 \layout Standard
16581
16582 c-faq
16583 \end_inset 
16584 </cell>
16585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16586 \begin_inset Text
16587
16588 \layout Standard
16589
16590 C-FAQ-list
16591 \end_inset 
16592 </cell>
16593 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16594 \begin_inset Text
16595
16596 \layout Standard
16597
16598
16599 \begin_inset LatexCommand \url{http://www.eskimo.com/~scs/C-faq/top.html}
16600
16601 \end_inset 
16602
16603
16604 \end_inset 
16605 </cell>
16606 </row>
16607 <row topline="true" bottomline="true">
16608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16609 \begin_inset Text
16610
16611 \layout Standard
16612
16613 S.
16614  S.
16615  Muchnick
16616 \end_inset 
16617 </cell>
16618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16619 \begin_inset Text
16620
16621 \layout Standard
16622
16623 Advanced Compiler Design and Implementation
16624 \end_inset 
16625 </cell>
16626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16627 \begin_inset Text
16628
16629 \layout Standard
16630
16631 bookstore (very dedicated, probably read other books first)
16632 \end_inset 
16633 </cell>
16634 </row>
16635 </lyxtabular>
16636
16637 \end_inset 
16638
16639
16640 \newline 
16641
16642 \layout Section
16643
16644 Some Questions
16645 \layout Standard
16646
16647 Some questions answered, some pointers given - it might be time to in turn
16648  ask 
16649 \emph on 
16650 you
16651 \emph default 
16652  some questions: 
16653 \layout Itemize
16654
16655 can you solve your project with the selected microcontroller? Would you
16656  find out early or rather late that your target is too small/slow/whatever?
16657  Can you switch to a slightly better device if it doesn't fit?
16658 \layout Itemize
16659
16660 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
16661  and/or another programming language be more adequate? Would an operating
16662  system on the target device help?
16663 \layout Itemize
16664
16665 if you solved the problem, will the marketing department be happy?
16666 \layout Itemize
16667
16668 if the marketing department is happy, will customers be happy?
16669 \layout Itemize
16670
16671 if you're the project manager, marketing department and maybe even the customer
16672  in one person, have you tried to see the project from the outside?
16673 \layout Itemize
16674
16675 is the project done if you think it is done? Or is just that other interface/pro
16676 tocol/feature/configuration/option missing? How about website, manual(s),
16677  internationalization, packaging, labels, electromagnetic compatability/interfer
16678 ence, documentation for production, production test software, update mechanism,
16679  patent issues?
16680 \layout Itemize
16681
16682 is your project adequately positioned in that magic triangle: fame, fortune,
16683  fun?
16684 \layout Standard
16685
16686 Maybe not all answers to these questions are known and some answers may
16687  even be 
16688 \emph on 
16689 no
16690 \emph default 
16691 , nevertheless knowing these questions may help you to avoid burnout
16692 \begin_inset Foot
16693 collapsed false
16694
16695 \layout Standard
16696
16697 burnout is bad for electronic devices, programmers and motorcycle tyres
16698 \end_inset 
16699
16700 .
16701  Chances are you didn't want to hear some of them...
16702 \layout Chapter
16703
16704 Support
16705 \begin_inset LatexCommand \index{Support}
16706
16707 \end_inset 
16708
16709
16710 \layout Standard
16711
16712 SDCC has grown to be a large project.
16713  The compiler alone (without the preprocessor, assembler and linker) is
16714  well over 100,000 lines of code (blank stripped).
16715  The open source nature of this project is a key to its continued growth
16716  and support.
16717  You gain the benefit and support of many active software developers and
16718  end users.
16719  Is SDCC perfect? No, that's why we need your help.
16720  The developers take pride in fixing reported bugs.
16721  You can help by reporting the bugs and helping other SDCC users.
16722  There are lots of ways to contribute, and we encourage you to take part
16723  in making SDCC a great software package.
16724  
16725 \layout Standard
16726
16727 The SDCC project is hosted on the SDCC sourceforge site at 
16728 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
16729
16730 \end_inset 
16731
16732 .
16733  You'll find the complete set of mailing lists
16734 \begin_inset LatexCommand \index{Mailing list}
16735
16736 \end_inset 
16737
16738 , forums, bug reporting system, patch submission
16739 \begin_inset LatexCommand \index{Patch submission}
16740
16741 \end_inset 
16742
16743  system, download
16744 \begin_inset LatexCommand \index{download}
16745
16746 \end_inset 
16747
16748  area and cvs code repository
16749 \begin_inset LatexCommand \index{cvs code repository}
16750
16751 \end_inset 
16752
16753  there.
16754 \layout Section
16755
16756 Reporting Bugs
16757 \begin_inset LatexCommand \index{Bug reporting}
16758
16759 \end_inset 
16760
16761
16762 \begin_inset LatexCommand \index{Reporting bugs}
16763
16764 \end_inset 
16765
16766
16767 \layout Standard
16768
16769 The recommended way of reporting bugs is using the infrastructure of the
16770  sourceforge site.
16771  You can follow the status of bug reports there and have an overview about
16772  the known bugs.
16773 \layout Standard
16774
16775 Bug reports are automatically forwarded to the developer mailing list and
16776  will be fixed ASAP.
16777  When reporting a bug, it is very useful to include a small test program
16778  (the smaller the better) which reproduces the problem.
16779  If you can isolate the problem by looking at the generated assembly code,
16780  this can be very helpful.
16781  Compiling your program with the -
16782 \begin_inset ERT
16783 status Collapsed
16784
16785 \layout Standard
16786
16787 \backslash 
16788 /
16789 \end_inset 
16790
16791 -dumpall
16792 \begin_inset LatexCommand \index{-\/-dumpall}
16793
16794 \end_inset 
16795
16796  option can sometimes be useful in locating optimization problems.
16797  When reporting a bug please maker sure you:
16798 \layout Enumerate
16799
16800 Attach the code you are compiling with SDCC.
16801  
16802 \layout Enumerate
16803
16804 Specify the exact command you use to run SDCC, or attach your Makefile.
16805  
16806 \layout Enumerate
16807
16808 Specify the SDCC version (type "
16809 \family sans 
16810 \series bold 
16811 sdcc -v
16812 \family default 
16813 \series default 
16814 "), your platform, and operating system.
16815  
16816 \layout Enumerate
16817
16818 Provide an exact copy of any error message or incorrect output.
16819  
16820 \layout Enumerate
16821
16822 Put something meaningful in the subject of your message.
16823 \layout Standard
16824
16825 Please attempt to include these 5 important parts, as applicable, in all
16826  requests for support or when reporting any problems or bugs with SDCC.
16827  Though this will make your message lengthy, it will greatly improve your
16828  chance that SDCC users and developers will be able to help you.
16829  Some SDCC developers are frustrated by bug reports without code provided
16830  that they can use to reproduce and ultimately fix the problem, so please
16831  be sure to provide sample code if you are reporting a bug! 
16832 \layout Standard
16833
16834 Please have a short check that you are using a recent version of SDCC and
16835  the bug is not yet known.
16836  This is the link for reporting bugs: 
16837 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
16838
16839 \end_inset 
16840
16841 .
16842 \layout Section
16843
16844 Requesting Features
16845 \begin_inset LatexCommand \label{sub:Requesting-Features}
16846
16847 \end_inset 
16848
16849
16850 \begin_inset LatexCommand \index{Feature request}
16851
16852 \end_inset 
16853
16854
16855 \begin_inset LatexCommand \index{Requesting features}
16856
16857 \end_inset 
16858
16859
16860 \layout Standard
16861
16862 Like bug reports feature requests are forwarded to the developer mailing
16863  list.
16864  This is the link for requesting features: 
16865 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
16866
16867 \end_inset 
16868
16869 .
16870 \layout Section
16871
16872 Submitting patches
16873 \layout Standard
16874
16875 Like bug reports contributed patches are forwarded to the developer mailing
16876  list.
16877  This is the link for submitting patches
16878 \begin_inset LatexCommand \index{Patch submission}
16879
16880 \end_inset 
16881
16882
16883 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
16884
16885 \end_inset 
16886
16887 .
16888 \layout Standard
16889
16890 You need to specify some parameters to the 
16891 \family typewriter 
16892 diff
16893 \family default 
16894  command for the patches to be useful.
16895  If you modified more than one file a patch created f.e.
16896  with 
16897 \family sans 
16898 \series bold 
16899
16900 \begin_inset Quotes sld
16901 \end_inset 
16902
16903 diff -Naur unmodified_directory modified_directory >my_changes.patch
16904 \begin_inset Quotes srd
16905 \end_inset 
16906
16907
16908 \family default 
16909 \series default 
16910  will be fine, otherwise 
16911 \family sans 
16912 \series bold 
16913
16914 \begin_inset Quotes sld
16915 \end_inset 
16916
16917 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
16918 \begin_inset Quotes srd
16919 \end_inset 
16920
16921
16922 \series default 
16923  
16924 \family default 
16925 will do.
16926 \layout Section
16927
16928 Getting Help
16929 \layout Standard
16930
16931 These links should take you directly to the 
16932 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
16933
16934 \end_inset 
16935
16936
16937 \begin_inset Foot
16938 collapsed false
16939
16940 \layout Standard
16941
16942 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
16943  automated messages (mid 2003)
16944 \end_inset 
16945
16946  and the 
16947 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
16948
16949 \end_inset 
16950
16951 , lists and forums are archived and searchable so if you are lucky someone
16952  already had a similar problem.
16953 \layout Section
16954
16955 ChangeLog
16956 \layout Standard
16957
16958 You can follow the status of the cvs version
16959 \begin_inset LatexCommand \index{version}
16960
16961 \end_inset 
16962
16963  of SDCC by watching the Changelog
16964 \begin_inset LatexCommand \index{Changelog}
16965
16966 \end_inset 
16967
16968  in the cvs-repository
16969 \newline 
16970
16971 \size footnotesize 
16972
16973 \begin_inset LatexCommand \htmlurl{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/sdcc/sdcc/ChangeLog?rev=HEAD&content-type=text/plain}
16974
16975 \end_inset 
16976
16977 .
16978 \layout Section
16979
16980 Release policy
16981 \begin_inset LatexCommand \index{Release policy}
16982
16983 \end_inset 
16984
16985
16986 \layout Standard
16987
16988 Historically there often were long delays between official releases and
16989  the sourceforge download area tends to get not updated at all.
16990  Excuses in the past might have referred to problems with live range analysis,
16991  but as this was fixed a while ago, the current problem is that another
16992  excuse has to be found.
16993  Kidding aside, we have to get better there! On the other hand there are
16994  daily snapshots available at 
16995 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
16996
16997 \end_inset 
16998
16999 , and you can always build the very last version (hopefully with many bugs
17000  fixed, and features added) from the source code available at 
17001 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
17002
17003 \end_inset 
17004
17005 .
17006 \layout Section
17007
17008 Examples
17009 \begin_inset LatexCommand \index{Examples}
17010
17011 \end_inset 
17012
17013
17014 \layout Standard
17015
17016 You'll find some small examples in the directory 
17017 \emph on 
17018 sdcc/device/examples/.
17019  
17020 \emph default 
17021 More examples and libraries are available at
17022 \emph on 
17023  The SDCC Open Knowledge Resource 
17024 \begin_inset LatexCommand \url{http://www.qsl.net/dl9sec/SDCC_OKR.html}
17025
17026 \end_inset 
17027
17028  
17029 \emph default 
17030 web site or at 
17031 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
17032
17033 \end_inset 
17034
17035 .
17036 \layout Comment
17037
17038 I did insert a reference to Paul's web site here although it seems rather
17039  dedicated to a specific 8032 board (I think it's okay because it f.e.
17040  shows LCD/Harddisc interface and has a free 8051 monitor.
17041  Independent 8032 board vendors face hard competition of heavily subsidized
17042  development boards anyway).
17043 \layout Comment
17044
17045 Maybe we should include some links to real world applications.
17046  Preferably pointer to pointers (one for each architecture) so this stays
17047  manageable here?
17048 \layout Section
17049
17050 Quality control
17051 \begin_inset LatexCommand \index{Quality control}
17052
17053 \end_inset 
17054
17055
17056 \layout Standard
17057
17058 The compiler is passed through nightly compile and build checks.
17059  The so called 
17060 \shape italic 
17061 regression tests
17062 \shape default 
17063
17064 \begin_inset LatexCommand \index{Regression test}
17065
17066 \end_inset 
17067
17068  check that SDCC itself compiles flawlessly on several platforms and checks
17069  the quality of the code generated by SDCC by running the code through simulator
17070 s.
17071  There is a separate document 
17072 \shape italic 
17073 test_suite.pdf
17074 \begin_inset LatexCommand \index{Test suite}
17075
17076 \end_inset 
17077
17078
17079 \shape default 
17080  about this.
17081 \layout Standard
17082
17083 You'll find the test code in the directory 
17084 \shape italic 
17085 sdcc/support/regression
17086 \shape default 
17087 .
17088  You can run these tests manually by running 
17089 \family sans 
17090 make
17091 \family default 
17092  in this directory (or f.e.
17093  
17094 \family sans 
17095 \series bold 
17096
17097 \begin_inset Quotes sld
17098 \end_inset 
17099
17100 make test-mcs51
17101 \begin_inset Quotes srd
17102 \end_inset 
17103
17104
17105 \family default 
17106 \series default 
17107  if you don't want to run the complete tests).
17108  The test code might also be interesting if you want to look for examples
17109 \begin_inset LatexCommand \index{Examples}
17110
17111 \end_inset 
17112
17113  checking corner cases of SDCC or if you plan to submit patches
17114 \begin_inset LatexCommand \index{Patch submission}
17115
17116 \end_inset 
17117
17118 .
17119 \layout Standard
17120
17121 The pic port uses a different set of regression tests, you'll find them
17122  in the directory 
17123 \shape italic 
17124 sdcc/src/regression
17125 \shape default 
17126 .
17127 \layout Chapter
17128 \pagebreak_top 
17129 SDCC Technical Data
17130 \layout Section
17131
17132 Optimizations
17133 \begin_inset LatexCommand \index{Optimizations}
17134
17135 \end_inset 
17136
17137
17138 \layout Standard
17139
17140 SDCC performs a host of standard optimizations in addition to some MCU specific
17141  optimizations.
17142  
17143 \layout Subsection
17144
17145 Sub-expression Elimination
17146 \begin_inset LatexCommand \index{Subexpression elimination}
17147
17148 \end_inset 
17149
17150
17151 \layout Standard
17152
17153 The compiler does local and 
17154 \emph on 
17155 g
17156 \emph default 
17157 lobal 
17158 \emph on 
17159 c
17160 \emph default 
17161 ommon 
17162 \emph on 
17163 s
17164 \emph default 
17165 ubexpression 
17166 \emph on 
17167 e
17168 \emph default 
17169 limination, e.g.: 
17170 \layout Verse
17171
17172
17173 \family typewriter 
17174 i = x + y + 1; 
17175 \newline 
17176 j = x + y;
17177 \layout Standard
17178
17179 will be translated to
17180 \layout Verse
17181
17182
17183 \family typewriter 
17184 iTemp = x + y; 
17185 \newline 
17186 i = iTemp + 1; 
17187 \newline 
17188 j = iTemp;
17189 \layout Standard
17190
17191 Some subexpressions are not as obvious as the above example, e.g.:
17192 \layout Verse
17193
17194
17195 \family typewriter 
17196 a->b[i].c = 10; 
17197 \newline 
17198 a->b[i].d = 11;
17199 \layout Standard
17200
17201 In this case the address arithmetic a->b[i] will be computed only once;
17202  the equivalent code in C would be.
17203 \layout Verse
17204
17205
17206 \family typewriter 
17207 iTemp = a->b[i]; 
17208 \newline 
17209 iTemp.c = 10; 
17210 \newline 
17211 iTemp.d = 11;
17212 \layout Standard
17213
17214 The compiler will try to keep these temporary variables in registers.
17215 \layout Subsection
17216
17217 Dead-Code Elimination
17218 \begin_inset LatexCommand \index{Dead-code elimination}
17219
17220 \end_inset 
17221
17222
17223 \layout Verse
17224
17225
17226 \family typewriter 
17227 int global;
17228 \newline 
17229
17230 \newline 
17231 void f () { 
17232 \newline 
17233 \SpecialChar ~
17234 \SpecialChar ~
17235 int i; 
17236 \newline 
17237 \SpecialChar ~
17238 \SpecialChar ~
17239 i = 1; \SpecialChar ~
17240 \SpecialChar ~
17241 \SpecialChar ~
17242 \SpecialChar ~
17243 \SpecialChar ~
17244 /* dead store */ 
17245 \newline 
17246 \SpecialChar ~
17247 \SpecialChar ~
17248 global = 1;\SpecialChar ~
17249 /* dead store */ 
17250 \newline 
17251 \SpecialChar ~
17252 \SpecialChar ~
17253 global = 2; 
17254 \newline 
17255 \SpecialChar ~
17256 \SpecialChar ~
17257 return; 
17258 \newline 
17259 \SpecialChar ~
17260 \SpecialChar ~
17261 global = 3;\SpecialChar ~
17262 /* unreachable */ 
17263 \newline 
17264 }
17265 \layout Standard
17266
17267 will be changed to
17268 \layout Verse
17269
17270
17271 \family typewriter 
17272 int global;
17273 \newline 
17274
17275 \newline 
17276 void f () {
17277 \newline 
17278 \SpecialChar ~
17279 \SpecialChar ~
17280 global = 2; 
17281 \newline 
17282 \SpecialChar ~
17283 \SpecialChar ~
17284 return; 
17285 \newline 
17286 }
17287 \layout Subsection
17288
17289 Copy-Propagation
17290 \begin_inset LatexCommand \index{Copy propagation}
17291
17292 \end_inset 
17293
17294
17295 \layout Verse
17296
17297
17298 \family typewriter 
17299 int f() { 
17300 \newline 
17301 \SpecialChar ~
17302 \SpecialChar ~
17303 int i, j; 
17304 \newline 
17305 \SpecialChar ~
17306 \SpecialChar ~
17307 i = 10; 
17308 \newline 
17309 \SpecialChar ~
17310 \SpecialChar ~
17311 j = i; 
17312 \newline 
17313 \SpecialChar ~
17314 \SpecialChar ~
17315 return j; 
17316 \newline 
17317 }
17318 \layout Standard
17319
17320 will be changed to 
17321 \layout Verse
17322
17323
17324 \family typewriter 
17325 int f() { 
17326 \newline 
17327 \SpecialChar ~
17328 \SpecialChar ~
17329 int i, j; 
17330 \newline 
17331 \SpecialChar ~
17332 \SpecialChar ~
17333 i = 10; 
17334 \newline 
17335 \SpecialChar ~
17336 \SpecialChar ~
17337 j = 10; 
17338 \newline 
17339 \SpecialChar ~
17340 \SpecialChar ~
17341 return 10; 
17342 \newline 
17343 }
17344 \layout Standard
17345
17346 Note: the dead stores created by this copy propagation will be eliminated
17347  by dead-code elimination.
17348 \layout Subsection
17349
17350 Loop Optimizations
17351 \begin_inset LatexCommand \index{Loop optimization}
17352
17353 \end_inset 
17354
17355
17356 \layout Standard
17357
17358 Two types of loop optimizations are done by SDCC loop invariant lifting
17359  and strength reduction of loop induction variables.
17360  In addition to the strength reduction the optimizer marks the induction
17361  variables and the register allocator tries to keep the induction variables
17362  in registers for the duration of the loop.
17363  Because of this preference of the register allocator
17364 \begin_inset LatexCommand \index{Register allocation}
17365
17366 \end_inset 
17367
17368 , loop induction optimization causes an increase in register pressure, which
17369  may cause unwanted spilling of other temporary variables into the stack
17370 \begin_inset LatexCommand \index{stack}
17371
17372 \end_inset 
17373
17374  / data space.
17375  The compiler will generate a warning message when it is forced to allocate
17376  extra space either on the stack or data space.
17377  If this extra space allocation is undesirable then induction optimization
17378  can be eliminated either for the entire source file (with -
17379 \begin_inset ERT
17380 status Collapsed
17381
17382 \layout Standard
17383
17384 \backslash 
17385 /
17386 \end_inset 
17387
17388 -noinduction option) or for a given function only using #pragma\SpecialChar ~
17389 noinduction
17390 \begin_inset LatexCommand \index{\#pragma noinduction}
17391
17392 \end_inset 
17393
17394 .
17395 \newline 
17396
17397 \newline 
17398 Loop Invariant:
17399 \layout Verse
17400
17401
17402 \family typewriter 
17403 for (i = 0 ; i < 100 ; i ++) 
17404 \newline 
17405 \SpecialChar ~
17406 \SpecialChar ~
17407 \SpecialChar ~
17408 \SpecialChar ~
17409 f += k + l;
17410 \layout Standard
17411
17412 changed to
17413 \layout Verse
17414
17415
17416 \family typewriter 
17417 itemp = k + l; 
17418 \newline 
17419 for (i = 0; i < 100; i++) 
17420 \newline 
17421 \SpecialChar ~
17422 \SpecialChar ~
17423 \SpecialChar ~
17424 \SpecialChar ~
17425 f += itemp;
17426 \layout Standard
17427
17428 As mentioned previously some loop invariants are not as apparent, all static
17429  address computations are also moved out of the loop.
17430 \newline 
17431
17432 \newline 
17433 Strength Reduction
17434 \begin_inset LatexCommand \index{Strength reduction}
17435
17436 \end_inset 
17437
17438 , this optimization substitutes an expression by a cheaper expression:
17439 \layout Verse
17440
17441
17442 \family typewriter 
17443 for (i=0;i < 100; i++)
17444 \newline 
17445 \SpecialChar ~
17446 \SpecialChar ~
17447 \SpecialChar ~
17448 \SpecialChar ~
17449 ar[i*5] = i*3;
17450 \layout Standard
17451
17452 changed to
17453 \layout Verse
17454
17455
17456 \family typewriter 
17457 itemp1 = 0; 
17458 \newline 
17459 itemp2 = 0; 
17460 \newline 
17461 for (i=0;i< 100;i++) { 
17462 \newline 
17463 \SpecialChar ~
17464 \SpecialChar ~
17465 \SpecialChar ~
17466 \SpecialChar ~
17467 ar[itemp1] = itemp2; 
17468 \newline 
17469 \SpecialChar ~
17470 \SpecialChar ~
17471 \SpecialChar ~
17472 \SpecialChar ~
17473 itemp1 += 5; 
17474 \newline 
17475 \SpecialChar ~
17476 \SpecialChar ~
17477 \SpecialChar ~
17478 \SpecialChar ~
17479 itemp2 += 3; 
17480 \newline 
17481 }
17482 \layout Standard
17483
17484 The more expensive multiplication
17485 \begin_inset LatexCommand \index{Multiplication}
17486
17487 \end_inset 
17488
17489  is changed to a less expensive addition.
17490 \layout Subsection
17491
17492 Loop Reversing
17493 \begin_inset LatexCommand \index{Loop reversing}
17494
17495 \end_inset 
17496
17497
17498 \layout Standard
17499
17500 This optimization is done to reduce the overhead of checking loop boundaries
17501  for every iteration.
17502  Some simple loops can be reversed and implemented using a 
17503 \begin_inset Quotes eld
17504 \end_inset 
17505
17506 decrement and jump if not zero
17507 \begin_inset Quotes erd
17508 \end_inset 
17509
17510  instruction.
17511  SDCC checks for the following criterion to determine if a loop is reversible
17512  (note: more sophisticated compilers use data-dependency analysis to make
17513  this determination, SDCC uses a more simple minded analysis).
17514 \layout Itemize
17515
17516 The 'for' loop is of the form 
17517 \newline 
17518
17519 \newline 
17520
17521 \family typewriter 
17522 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
17523  += 1])
17524 \newline 
17525 \SpecialChar ~
17526 \SpecialChar ~
17527 \SpecialChar ~
17528 \SpecialChar ~
17529 <for body>
17530 \layout Itemize
17531
17532 The <for body> does not contain 
17533 \begin_inset Quotes eld
17534 \end_inset 
17535
17536 continue
17537 \begin_inset Quotes erd
17538 \end_inset 
17539
17540  or 'break
17541 \begin_inset Quotes erd
17542 \end_inset 
17543
17544 .
17545 \layout Itemize
17546
17547 All goto's are contained within the loop.
17548 \layout Itemize
17549
17550 No function calls within the loop.
17551 \layout Itemize
17552
17553 The loop control variable <sym> is not assigned any value within the loop
17554 \layout Itemize
17555
17556 The loop control variable does NOT participate in any arithmetic operation
17557  within the loop.
17558 \layout Itemize
17559
17560 There are NO switch statements in the loop.
17561 \layout Subsection
17562
17563 Algebraic Simplifications
17564 \layout Standard
17565
17566 SDCC does numerous algebraic simplifications, the following is a small sub-set
17567  of these optimizations.
17568 \layout Verse
17569
17570
17571 \family typewriter 
17572 i = j + 0;\SpecialChar ~
17573 \SpecialChar ~
17574 \SpecialChar ~
17575 \SpecialChar ~
17576  /* changed to: */\SpecialChar ~
17577 \SpecialChar ~
17578 \SpecialChar ~
17579 \SpecialChar ~
17580  i = j; 
17581 \newline 
17582 i /= 2;\SpecialChar ~
17583 \SpecialChar ~
17584 \SpecialChar ~
17585 \SpecialChar ~
17586 \SpecialChar ~
17587 \SpecialChar ~
17588 \SpecialChar ~
17589  /* changed to: */\SpecialChar ~
17590 \SpecialChar ~
17591 \SpecialChar ~
17592 \SpecialChar ~
17593  i >>= 1; 
17594 \newline 
17595 i = j - j;\SpecialChar ~
17596 \SpecialChar ~
17597 \SpecialChar ~
17598 \SpecialChar ~
17599  /* changed to: */\SpecialChar ~
17600 \SpecialChar ~
17601 \SpecialChar ~
17602 \SpecialChar ~
17603  i = 0; 
17604 \newline 
17605 i = j / 1;\SpecialChar ~
17606 \SpecialChar ~
17607 \SpecialChar ~
17608 \SpecialChar ~
17609  /* changed to: */\SpecialChar ~
17610 \SpecialChar ~
17611 \SpecialChar ~
17612 \SpecialChar ~
17613  i = j;
17614 \layout Standard
17615
17616 Note the subexpressions
17617 \begin_inset LatexCommand \index{Subexpression}
17618
17619 \end_inset 
17620
17621  given above are generally introduced by macro expansions or as a result
17622  of copy/constant propagation.
17623 \layout Subsection
17624
17625 'switch' Statements
17626 \begin_inset LatexCommand \label{sub:'switch'-Statements}
17627
17628 \end_inset 
17629
17630
17631 \begin_inset LatexCommand \index{switch statement}
17632
17633 \end_inset 
17634
17635
17636 \layout Standard
17637
17638 SDCC changes switch statements to jump tables
17639 \begin_inset LatexCommand \index{jump tables}
17640
17641 \end_inset 
17642
17643  when the following conditions are true.
17644  
17645 \layout Itemize
17646
17647 The case labels are in numerical sequence, the labels need not be in order,
17648  and the starting number need not be one or zero.
17649 \begin_deeper 
17650 \layout Verse
17651
17652
17653 \family typewriter 
17654 switch(i) {\SpecialChar ~
17655 \SpecialChar ~
17656 \SpecialChar ~
17657 \SpecialChar ~
17658 \SpecialChar ~
17659 \SpecialChar ~
17660 \SpecialChar ~
17661 \SpecialChar ~
17662 \SpecialChar ~
17663 \SpecialChar ~
17664 \SpecialChar ~
17665 \SpecialChar ~
17666 \SpecialChar ~
17667 \SpecialChar ~
17668 \SpecialChar ~
17669 \SpecialChar ~
17670 \SpecialChar ~
17671 \SpecialChar ~
17672 \SpecialChar ~
17673 \SpecialChar ~
17674 \SpecialChar ~
17675 \SpecialChar ~
17676 \SpecialChar ~
17677 \SpecialChar ~
17678 \SpecialChar ~
17679 \SpecialChar ~
17680 switch (i) { 
17681 \newline 
17682 \SpecialChar ~
17683 \SpecialChar ~
17684 \SpecialChar ~
17685 case 4: ...\SpecialChar ~
17686 \SpecialChar ~
17687 \SpecialChar ~
17688 \SpecialChar ~
17689 \SpecialChar ~
17690 \SpecialChar ~
17691 \SpecialChar ~
17692 \SpecialChar ~
17693 \SpecialChar ~
17694 \SpecialChar ~
17695 \SpecialChar ~
17696 \SpecialChar ~
17697 \SpecialChar ~
17698 \SpecialChar ~
17699 \SpecialChar ~
17700 \SpecialChar ~
17701 \SpecialChar ~
17702 \SpecialChar ~
17703 \SpecialChar ~
17704 \SpecialChar ~
17705 \SpecialChar ~
17706 \SpecialChar ~
17707 \SpecialChar ~
17708 \SpecialChar ~
17709 \SpecialChar ~
17710 \SpecialChar ~
17711 case 0: ...
17712  
17713 \newline 
17714 \SpecialChar ~
17715 \SpecialChar ~
17716 \SpecialChar ~
17717 case 5: ...\SpecialChar ~
17718 \SpecialChar ~
17719 \SpecialChar ~
17720 \SpecialChar ~
17721 \SpecialChar ~
17722 \SpecialChar ~
17723 \SpecialChar ~
17724 \SpecialChar ~
17725 \SpecialChar ~
17726 \SpecialChar ~
17727 \SpecialChar ~
17728 \SpecialChar ~
17729 \SpecialChar ~
17730 \SpecialChar ~
17731 \SpecialChar ~
17732 \SpecialChar ~
17733 \SpecialChar ~
17734 \SpecialChar ~
17735 \SpecialChar ~
17736 \SpecialChar ~
17737 \SpecialChar ~
17738 \SpecialChar ~
17739 \SpecialChar ~
17740 \SpecialChar ~
17741 \SpecialChar ~
17742 \SpecialChar ~
17743 case 1: ...
17744  
17745 \newline 
17746 \SpecialChar ~
17747 \SpecialChar ~
17748 \SpecialChar ~
17749 case 3: ...\SpecialChar ~
17750 \SpecialChar ~
17751 \SpecialChar ~
17752 \SpecialChar ~
17753 \SpecialChar ~
17754 \SpecialChar ~
17755 \SpecialChar ~
17756 \SpecialChar ~
17757 \SpecialChar ~
17758 \SpecialChar ~
17759 \SpecialChar ~
17760 \SpecialChar ~
17761 \SpecialChar ~
17762 \SpecialChar ~
17763 \SpecialChar ~
17764 \SpecialChar ~
17765 \SpecialChar ~
17766 \SpecialChar ~
17767 \SpecialChar ~
17768 \SpecialChar ~
17769 \SpecialChar ~
17770 \SpecialChar ~
17771 \SpecialChar ~
17772 \SpecialChar ~
17773 \SpecialChar ~
17774 \SpecialChar ~
17775 case 2: ...
17776  
17777 \newline 
17778 \SpecialChar ~
17779 \SpecialChar ~
17780 \SpecialChar ~
17781 case 6: ...\SpecialChar ~
17782 \SpecialChar ~
17783 \SpecialChar ~
17784 \SpecialChar ~
17785 \SpecialChar ~
17786 \SpecialChar ~
17787 \SpecialChar ~
17788 \SpecialChar ~
17789 \SpecialChar ~
17790 \SpecialChar ~
17791 \SpecialChar ~
17792 \SpecialChar ~
17793 \SpecialChar ~
17794 \SpecialChar ~
17795 \SpecialChar ~
17796 \SpecialChar ~
17797 \SpecialChar ~
17798 \SpecialChar ~
17799 \SpecialChar ~
17800 \SpecialChar ~
17801 \SpecialChar ~
17802 \SpecialChar ~
17803 \SpecialChar ~
17804 \SpecialChar ~
17805 \SpecialChar ~
17806 \SpecialChar ~
17807 case 3: ...
17808  
17809 \newline 
17810 }\SpecialChar ~
17811 \SpecialChar ~
17812 \SpecialChar ~
17813 \SpecialChar ~
17814 \SpecialChar ~
17815 \SpecialChar ~
17816 \SpecialChar ~
17817 \SpecialChar ~
17818 \SpecialChar ~
17819 \SpecialChar ~
17820 \SpecialChar ~
17821 \SpecialChar ~
17822 \SpecialChar ~
17823 \SpecialChar ~
17824 \SpecialChar ~
17825 \SpecialChar ~
17826 \SpecialChar ~
17827 \SpecialChar ~
17828 \SpecialChar ~
17829 \SpecialChar ~
17830 \SpecialChar ~
17831 \SpecialChar ~
17832 \SpecialChar ~
17833 \SpecialChar ~
17834 \SpecialChar ~
17835 \SpecialChar ~
17836 \SpecialChar ~
17837 \SpecialChar ~
17838 \SpecialChar ~
17839 \SpecialChar ~
17840 \SpecialChar ~
17841 \SpecialChar ~
17842 \SpecialChar ~
17843 \SpecialChar ~
17844 \SpecialChar ~
17845 \SpecialChar ~
17846 }
17847 \layout Standard
17848
17849 Both the above switch statements will be implemented using a jump-table.
17850  The example to the right side is slightly more efficient as the check for
17851  the lower boundary of the jump-table is not needed.
17852 \end_deeper 
17853 \layout Itemize
17854
17855 The number of case labels is at least three, since it takes two conditional
17856  statements to handle the boundary conditions.
17857 \layout Itemize
17858
17859 The number of case labels is less than 84, since each label takes 3 bytes
17860  and a jump-table can be utmost 256 bytes long.
17861 \layout Standard
17862
17863 Switch statements which have gaps in the numeric sequence or those that
17864  have more that 84 case labels can be split into more than one switch statement
17865  for efficient code generation, e.g.:
17866 \layout Verse
17867
17868
17869 \family typewriter 
17870 switch (i) { 
17871 \newline 
17872 \SpecialChar ~
17873 \SpecialChar ~
17874 case 1: ...
17875  
17876 \newline 
17877 \SpecialChar ~
17878 \SpecialChar ~
17879 case 2: ...
17880  
17881 \newline 
17882 \SpecialChar ~
17883 \SpecialChar ~
17884 case 3: ...
17885  
17886 \newline 
17887 \SpecialChar ~
17888 \SpecialChar ~
17889 case 4: ...
17890  
17891 \newline 
17892 \SpecialChar ~
17893 \SpecialChar ~
17894 case 9: ...
17895  
17896 \newline 
17897 \SpecialChar ~
17898 \SpecialChar ~
17899 case 10: ...
17900  
17901 \newline 
17902 \SpecialChar ~
17903 \SpecialChar ~
17904 case 11: ...
17905  
17906 \newline 
17907 \SpecialChar ~
17908 \SpecialChar ~
17909 case 12: ...
17910  
17911 \newline 
17912 }
17913 \layout Standard
17914
17915 If the above switch statement is broken down into two switch statements
17916 \layout Verse
17917
17918
17919 \family typewriter 
17920 switch (i) { 
17921 \newline 
17922 \SpecialChar ~
17923 \SpecialChar ~
17924 case 1: ...
17925  
17926 \newline 
17927 \SpecialChar ~
17928 \SpecialChar ~
17929 case 2: ...
17930  
17931 \newline 
17932 \SpecialChar ~
17933 \SpecialChar ~
17934 case 3: ...
17935  
17936 \newline 
17937 \SpecialChar ~
17938 \SpecialChar ~
17939 case 4: ...
17940  
17941 \newline 
17942 }
17943 \layout Standard
17944
17945 and
17946 \layout Verse
17947
17948
17949 \family typewriter 
17950 switch (i) { 
17951 \newline 
17952 \SpecialChar ~
17953 \SpecialChar ~
17954 case 9:\SpecialChar ~
17955 \SpecialChar ~
17956 ...
17957  
17958 \newline 
17959 \SpecialChar ~
17960 \SpecialChar ~
17961 case 10:\SpecialChar ~
17962 ...
17963  
17964 \newline 
17965 \SpecialChar ~
17966 \SpecialChar ~
17967 case 11:\SpecialChar ~
17968 ...
17969  
17970 \newline 
17971 \SpecialChar ~
17972 \SpecialChar ~
17973 case 12:\SpecialChar ~
17974 ...
17975  
17976 \newline 
17977 }
17978 \layout Standard
17979
17980 then both the switch statements will be implemented using jump-tables whereas
17981  the unmodified switch statement will not be.
17982  You might also consider inserting dummy cases 0 and 5 to 8 in this example.
17983  
17984 \newline 
17985 The pragma nojtbound
17986 \begin_inset LatexCommand \index{\#pragma nojtbound}
17987
17988 \end_inset 
17989
17990  can be used to turn off checking the 
17991 \emph on 
17992 j
17993 \emph default 
17994 ump 
17995 \emph on 
17996 t
17997 \emph default 
17998 able 
17999 \emph on 
18000 bound
18001 \emph default 
18002 aries.
18003  It has no effect if a default label is supplied.
18004  Use of this pragma is dangerous: if the switch argument is not matched
18005  by a case statement the processor will happily jump into Nirvana.
18006 \layout Subsection
18007
18008 Bit-shifting Operations
18009 \begin_inset LatexCommand \index{Bit shifting}
18010
18011 \end_inset 
18012
18013 .
18014 \layout Standard
18015
18016 Bit shifting is one of the most frequently used operation in embedded programmin
18017 g.
18018  SDCC tries to implement bit-shift operations in the most efficient way
18019  possible, e.g.:
18020 \layout Verse
18021
18022
18023 \family typewriter 
18024 unsigned char i;
18025 \newline 
18026 ...
18027  
18028 \newline 
18029 i >>= 4; 
18030 \newline 
18031 ...
18032 \layout Standard
18033
18034 generates the following code:
18035 \layout Verse
18036
18037
18038 \family typewriter 
18039 mov\SpecialChar ~
18040  a,_i 
18041 \newline 
18042 swap a 
18043 \newline 
18044 anl\SpecialChar ~
18045  a,#0x0f 
18046 \newline 
18047 mov\SpecialChar ~
18048  _i,a
18049 \layout Standard
18050
18051 In general SDCC will never setup a loop if the shift count is known.
18052  Another example:
18053 \layout Verse
18054
18055
18056 \family typewriter 
18057 unsigned int i; 
18058 \newline 
18059 ...
18060  
18061 \newline 
18062 i >>= 9; 
18063 \newline 
18064 ...
18065 \layout Standard
18066
18067 will generate:
18068 \layout Verse
18069
18070
18071 \family typewriter 
18072 mov\SpecialChar ~
18073 \SpecialChar ~
18074 a,(_i + 1) 
18075 \newline 
18076 mov\SpecialChar ~
18077 \SpecialChar ~
18078 (_i + 1),#0x00 
18079 \newline 
18080 clr\SpecialChar ~
18081 \SpecialChar ~
18082
18083 \newline 
18084 rrc\SpecialChar ~
18085 \SpecialChar ~
18086
18087 \newline 
18088 mov\SpecialChar ~
18089 \SpecialChar ~
18090 _i,a
18091 \layout Subsection
18092
18093 Bit-rotation
18094 \begin_inset LatexCommand \index{Bit rotation}
18095
18096 \end_inset 
18097
18098
18099 \layout Standard
18100
18101 A special case of the bit-shift operation is bit rotation
18102 \begin_inset LatexCommand \index{rotating bits}
18103
18104 \end_inset 
18105
18106 , SDCC recognizes the following expression to be a left bit-rotation:
18107 \layout Verse
18108
18109
18110 \family typewriter 
18111 \series bold 
18112 unsigned
18113 \series default 
18114 \SpecialChar ~
18115 \SpecialChar ~
18116 char i;\SpecialChar ~
18117 \SpecialChar ~
18118 \SpecialChar ~
18119 \SpecialChar ~
18120 \SpecialChar ~
18121 \SpecialChar ~
18122 \SpecialChar ~
18123 \SpecialChar ~
18124 \SpecialChar ~
18125 \SpecialChar ~
18126 \SpecialChar ~
18127 /* unsigned is needed for rotation */ 
18128 \newline 
18129 ...
18130  
18131 \newline 
18132 i = ((i << 1) | (i >> 7)); 
18133 \family default 
18134
18135 \newline 
18136
18137 \family typewriter 
18138 ...
18139 \layout Standard
18140
18141 will generate the following code:
18142 \layout Verse
18143
18144
18145 \family typewriter 
18146 mov\SpecialChar ~
18147 \SpecialChar ~
18148 a,_i 
18149 \newline 
18150 rl\SpecialChar ~
18151 \SpecialChar ~
18152 \SpecialChar ~
18153
18154 \newline 
18155 mov\SpecialChar ~
18156 \SpecialChar ~
18157 _i,a
18158 \layout Standard
18159
18160 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
18161 ns of this case will also be recognized as bit-rotation, i.e.: 
18162 \layout Verse
18163
18164
18165 \family typewriter 
18166 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
18167 \layout Subsection
18168
18169 Nibble and Byte Swapping
18170 \layout Standard
18171
18172 Other special cases of the bit-shift operations are nibble or byte swapping
18173 \begin_inset LatexCommand \index{swapping nibbles/bytes}
18174
18175 \end_inset 
18176
18177 , SDCC recognizes the following expressions:
18178 \layout Verse
18179
18180
18181 \family typewriter 
18182 \series bold 
18183 unsigned
18184 \series default 
18185 \SpecialChar ~
18186 \SpecialChar ~
18187 char i; 
18188 \newline 
18189
18190 \series bold 
18191 unsigned
18192 \series default 
18193 \SpecialChar ~
18194 \SpecialChar ~
18195 int j; 
18196 \newline 
18197 ...
18198  
18199 \newline 
18200 i = ((i << 4) | (i >> 4)); 
18201 \family default 
18202
18203 \newline 
18204
18205 \family typewriter 
18206 j = ((j << 8) | (j >> 8)); 
18207 \layout Standard
18208
18209 and generates a swap instruction for the nibble swapping
18210 \begin_inset LatexCommand \index{Nibble swapping}
18211
18212 \end_inset 
18213
18214  or move instructions for the byte swapping
18215 \begin_inset LatexCommand \index{Byte swapping}
18216
18217 \end_inset 
18218
18219 .
18220  The 
18221 \begin_inset Quotes sld
18222 \end_inset 
18223
18224 j
18225 \begin_inset Quotes srd
18226 \end_inset 
18227
18228  example can be used to convert from little to big-endian or vice versa.
18229  If you want to change the endianness of a 
18230 \emph on 
18231 signed
18232 \emph default 
18233  integer you have to cast to 
18234 \family typewriter 
18235 (unsigned int)
18236 \family default 
18237  first.
18238 \layout Standard
18239
18240 Note that SDCC stores numbers in little-endian
18241 \begin_inset Foot
18242 collapsed false
18243
18244 \layout Standard
18245
18246 Usually 8-bit processors don't care much about endianness.
18247  This is not the case for the standard 8051 which only has an instruction
18248  to increment its 
18249 \emph on 
18250 dptr
18251 \emph default 
18252
18253 \begin_inset LatexCommand \index{DPTR}
18254
18255 \end_inset 
18256
18257 -datapointer
18258 \emph on 
18259  
18260 \emph default 
18261 so little-endian is the more efficient byte order.
18262 \end_inset 
18263
18264
18265 \begin_inset LatexCommand \index{little-endian}
18266
18267 \end_inset 
18268
18269
18270 \begin_inset LatexCommand \index{Endianness}
18271
18272 \end_inset 
18273
18274  format (i.e.
18275  lowest order first).
18276 \layout Subsection
18277
18278 Highest Order Bit
18279 \begin_inset LatexCommand \index{Highest Order Bit}
18280
18281 \end_inset 
18282
18283
18284 \layout Standard
18285
18286 It is frequently required to obtain the highest order bit of an integral
18287  type (long, int, short or char types).
18288  SDCC recognizes the following expression to yield the highest order bit
18289  and generates optimized code for it, e.g.:
18290 \layout Verse
18291
18292
18293 \family typewriter 
18294 unsigned int gint; 
18295 \newline 
18296
18297 \newline 
18298 foo () { 
18299 \newline 
18300 \SpecialChar ~
18301 \SpecialChar ~
18302 unsigned char hob; 
18303 \newline 
18304 \SpecialChar ~
18305 \SpecialChar ~
18306 ...
18307  
18308 \newline 
18309 \SpecialChar ~
18310 \SpecialChar ~
18311 hob = (gint >> 15) & 1; 
18312 \newline 
18313 \SpecialChar ~
18314 \SpecialChar ~
18315 ..
18316  
18317 \newline 
18318 }
18319 \layout Standard
18320
18321 will generate the following code:
18322 \layout Verse
18323
18324
18325 \family typewriter 
18326 \SpecialChar ~
18327 \SpecialChar ~
18328 \SpecialChar ~
18329 \SpecialChar ~
18330 \SpecialChar ~
18331 \SpecialChar ~
18332 \SpecialChar ~
18333 \SpecialChar ~
18334 \SpecialChar ~
18335 \SpecialChar ~
18336 \SpecialChar ~
18337 \SpecialChar ~
18338 \SpecialChar ~
18339 \SpecialChar ~
18340 \SpecialChar ~
18341 \SpecialChar ~
18342 \SpecialChar ~
18343 \SpecialChar ~
18344 \SpecialChar ~
18345 \SpecialChar ~
18346 \SpecialChar ~
18347 \SpecialChar ~
18348 \SpecialChar ~
18349 \SpecialChar ~
18350 \SpecialChar ~
18351  61 ;\SpecialChar ~
18352  hob.c 7 
18353 \newline 
18354 000A E5*01\SpecialChar ~
18355 \SpecialChar ~
18356 \SpecialChar ~
18357 \SpecialChar ~
18358 \SpecialChar ~
18359 \SpecialChar ~
18360 \SpecialChar ~
18361 \SpecialChar ~
18362 \SpecialChar ~
18363 \SpecialChar ~
18364 \SpecialChar ~
18365 \SpecialChar ~
18366 \SpecialChar ~
18367 \SpecialChar ~
18368 \SpecialChar ~
18369  62\SpecialChar ~
18370 \SpecialChar ~
18371 \SpecialChar ~
18372 \SpecialChar ~
18373 \SpecialChar ~
18374 \SpecialChar ~
18375 \SpecialChar ~
18376 \SpecialChar ~
18377  mov\SpecialChar ~
18378 \SpecialChar ~
18379  a,(_gint + 1) 
18380 \newline 
18381 000C 23\SpecialChar ~
18382 \SpecialChar ~
18383 \SpecialChar ~
18384 \SpecialChar ~
18385 \SpecialChar ~
18386 \SpecialChar ~
18387 \SpecialChar ~
18388 \SpecialChar ~
18389 \SpecialChar ~
18390 \SpecialChar ~
18391 \SpecialChar ~
18392 \SpecialChar ~
18393 \SpecialChar ~
18394 \SpecialChar ~
18395 \SpecialChar ~
18396 \SpecialChar ~
18397 \SpecialChar ~
18398 \SpecialChar ~
18399  63\SpecialChar ~
18400 \SpecialChar ~
18401 \SpecialChar ~
18402 \SpecialChar ~
18403 \SpecialChar ~
18404 \SpecialChar ~
18405 \SpecialChar ~
18406 \SpecialChar ~
18407  rl\SpecialChar ~
18408 \SpecialChar ~
18409 \SpecialChar ~
18410  a 
18411 \newline 
18412 000D 54 01\SpecialChar ~
18413 \SpecialChar ~
18414 \SpecialChar ~
18415 \SpecialChar ~
18416 \SpecialChar ~
18417 \SpecialChar ~
18418 \SpecialChar ~
18419 \SpecialChar ~
18420 \SpecialChar ~
18421 \SpecialChar ~
18422 \SpecialChar ~
18423 \SpecialChar ~
18424 \SpecialChar ~
18425 \SpecialChar ~
18426 \SpecialChar ~
18427  64\SpecialChar ~
18428 \SpecialChar ~
18429 \SpecialChar ~
18430 \SpecialChar ~
18431 \SpecialChar ~
18432 \SpecialChar ~
18433 \SpecialChar ~
18434 \SpecialChar ~
18435  anl\SpecialChar ~
18436 \SpecialChar ~
18437  a,#0x01 
18438 \newline 
18439 000F F5*02\SpecialChar ~
18440 \SpecialChar ~
18441 \SpecialChar ~
18442 \SpecialChar ~
18443 \SpecialChar ~
18444 \SpecialChar ~
18445 \SpecialChar ~
18446 \SpecialChar ~
18447 \SpecialChar ~
18448 \SpecialChar ~
18449 \SpecialChar ~
18450 \SpecialChar ~
18451 \SpecialChar ~
18452 \SpecialChar ~
18453 \SpecialChar ~
18454  65\SpecialChar ~
18455 \SpecialChar ~
18456 \SpecialChar ~
18457 \SpecialChar ~
18458 \SpecialChar ~
18459 \SpecialChar ~
18460 \SpecialChar ~
18461 \SpecialChar ~
18462  mov\SpecialChar ~
18463 \SpecialChar ~
18464  _foo_hob_1_1,a
18465 \layout Standard
18466
18467 Variations of this case however will 
18468 \emph on 
18469 not
18470 \emph default 
18471  be recognized.
18472  It is a standard C expression, so I heartily recommend this be the only
18473  way to get the highest order bit, (it is portable).
18474  Of course it will be recognized even if it is embedded in other expressions,
18475  e.g.:
18476 \layout Verse
18477
18478
18479 \family typewriter 
18480 xyz = gint + ((gint >> 15) & 1);
18481 \layout Standard
18482
18483 will still be recognized.
18484 \layout Subsection
18485
18486 Peephole Optimizer
18487 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
18488
18489 \end_inset 
18490
18491
18492 \begin_inset LatexCommand \index{Peephole optimizer}
18493
18494 \end_inset 
18495
18496
18497 \layout Standard
18498
18499 The compiler uses a rule based, pattern matching and re-writing mechanism
18500  for peep-hole optimization.
18501  It is inspired by 
18502 \emph on 
18503 copt
18504 \emph default 
18505  a peep-hole optimizer by Christopher W.
18506  Fraser (cwfraser@microsoft.com).
18507  A default set of rules are compiled into the compiler, additional rules
18508  may be added with the 
18509 \emph on 
18510 -
18511 \begin_inset ERT
18512 status Collapsed
18513
18514 \layout Standard
18515
18516 \backslash 
18517 /
18518 \end_inset 
18519
18520 -peep-file
18521 \begin_inset LatexCommand \index{-\/-peep-file}
18522
18523 \end_inset 
18524
18525  <filename>
18526 \emph default 
18527  option.
18528  The rule language is best illustrated with examples.
18529 \layout Verse
18530
18531
18532 \family typewriter 
18533 replace { 
18534 \newline 
18535 \SpecialChar ~
18536 \SpecialChar ~
18537 mov %1,a 
18538 \newline 
18539 \SpecialChar ~
18540 \SpecialChar ~
18541 mov a,%1
18542 \newline 
18543 } by {
18544 \newline 
18545 \SpecialChar ~
18546 \SpecialChar ~
18547 mov %1,a
18548 \newline 
18549 }
18550 \layout Standard
18551
18552 The above rule will change the following assembly
18553 \begin_inset LatexCommand \index{Assembler routines}
18554
18555 \end_inset 
18556
18557  sequence:
18558 \layout Verse
18559
18560
18561 \family typewriter 
18562 mov r1,a 
18563 \newline 
18564 mov a,r1
18565 \layout Standard
18566
18567 to
18568 \layout Verse
18569
18570
18571 \family typewriter 
18572 mov r1,a
18573 \layout Standard
18574
18575 Note: All occurrences of a 
18576 \emph on 
18577 %n
18578 \emph default 
18579  (pattern variable) must denote the same string.
18580  With the above rule, the assembly sequence:
18581 \layout Verse
18582
18583
18584 \family typewriter 
18585 mov r1,a 
18586 \newline 
18587 mov a,r2
18588 \layout Standard
18589
18590 will remain unmodified.
18591 \newline 
18592
18593 \newline 
18594 Other special case optimizations may be added by the user (via 
18595 \emph on 
18596 -
18597 \begin_inset ERT
18598 status Collapsed
18599
18600 \layout Standard
18601
18602 \backslash 
18603 /
18604 \end_inset 
18605
18606 -peep-file option
18607 \emph default 
18608 ).
18609  E.g.
18610  some variants of the 8051 MCU allow only 
18611 \family typewriter 
18612 ajmp
18613 \family default 
18614  and 
18615 \family typewriter 
18616 acall
18617 \family default 
18618 .
18619  The following two rules will change all 
18620 \family typewriter 
18621 ljmp
18622 \family default 
18623  and 
18624 \family typewriter 
18625 lcall
18626 \family default 
18627  to 
18628 \family typewriter 
18629 ajmp
18630 \family default 
18631  and 
18632 \family typewriter 
18633 acall
18634 \layout Verse
18635
18636
18637 \family typewriter 
18638 replace { lcall %1 } by { acall %1 } 
18639 \newline 
18640 replace { ljmp %1 } by { ajmp %1 }
18641 \layout Standard
18642
18643 The 
18644 \emph on 
18645 inline-assembler code
18646 \emph default 
18647  is also passed through the peep hole optimizer, thus the peephole optimizer
18648  can also be used as an assembly level macro expander.
18649  The rules themselves are MCU dependent whereas the rule language infra-structur
18650 e is MCU independent.
18651  Peephole optimization rules for other MCU can be easily programmed using
18652  the rule language.
18653 \newline 
18654
18655 \newline 
18656 The syntax for a rule is as follows:
18657 \layout Verse
18658
18659
18660 \family typewriter 
18661 rule := replace [ restart ] '{' <assembly sequence> '
18662 \backslash 
18663 n' 
18664 \newline 
18665 \SpecialChar ~
18666  \SpecialChar ~
18667  \SpecialChar ~
18668  \SpecialChar ~
18669  \SpecialChar ~
18670  \SpecialChar ~
18671  \SpecialChar ~
18672  \SpecialChar ~
18673  \SpecialChar ~
18674  \SpecialChar ~
18675  \SpecialChar ~
18676  \SpecialChar ~
18677  \SpecialChar ~
18678  \SpecialChar ~
18679  '}' by '{' '
18680 \backslash 
18681 n' 
18682 \newline 
18683 \SpecialChar ~
18684  \SpecialChar ~
18685  \SpecialChar ~
18686  \SpecialChar ~
18687  \SpecialChar ~
18688  \SpecialChar ~
18689  \SpecialChar ~
18690  \SpecialChar ~
18691  \SpecialChar ~
18692  \SpecialChar ~
18693  \SpecialChar ~
18694  \SpecialChar ~
18695  \SpecialChar ~
18696  \SpecialChar ~
18697  \SpecialChar ~
18698  \SpecialChar ~
18699  <assembly sequence> '
18700 \backslash 
18701 n' 
18702 \newline 
18703 \SpecialChar ~
18704  \SpecialChar ~
18705  \SpecialChar ~
18706  \SpecialChar ~
18707  \SpecialChar ~
18708  \SpecialChar ~
18709  \SpecialChar ~
18710  \SpecialChar ~
18711  \SpecialChar ~
18712  \SpecialChar ~
18713  \SpecialChar ~
18714  \SpecialChar ~
18715  \SpecialChar ~
18716  \SpecialChar ~
18717  '}' [if <functionName> ] '
18718 \backslash 
18719 n' 
18720 \layout Standard
18721
18722 <assembly sequence> := assembly instruction (each instruction including
18723  labels must be on a separate line).
18724 \newline 
18725
18726 \newline 
18727 The optimizer will apply to the rules one by one from the top in the sequence
18728  of their appearance, it will terminate when all rules are exhausted.
18729  If the 'restart' option is specified, then the optimizer will start matching
18730  the rules again from the top, this option for a rule is expensive (performance)
18731 , it is intended to be used in situations where a transformation will trigger
18732  the same rule again.
18733  An example of this (not a good one, it has side effects) is the following
18734  rule:
18735 \layout Verse
18736
18737
18738 \family typewriter 
18739 replace restart { 
18740 \newline 
18741 \SpecialChar ~
18742 \SpecialChar ~
18743 pop %1 
18744 \newline 
18745 \SpecialChar ~
18746 \SpecialChar ~
18747 push %1 } by { 
18748 \newline 
18749 \SpecialChar ~
18750 \SpecialChar ~
18751 ; nop 
18752 \newline 
18753 }
18754 \layout Standard
18755
18756 Note that the replace pattern cannot be a blank, but can be a comment line.
18757  Without the 'restart' option only the innermost 'pop' 'push' pair would
18758  be eliminated, i.e.:
18759 \layout Verse
18760
18761
18762 \family typewriter 
18763 pop ar1 
18764 \newline 
18765 pop ar2 
18766 \newline 
18767 push ar2 
18768 \newline 
18769 push ar1
18770 \layout Standard
18771
18772 would result in:
18773 \layout Verse
18774
18775
18776 \family typewriter 
18777 pop ar1 
18778 \newline 
18779 ; nop 
18780 \newline 
18781 push ar1
18782 \layout Standard
18783
18784
18785 \emph on 
18786 with
18787 \emph default 
18788  the restart option the rule will be applied again to the resulting code
18789  and then all the pop-push pairs will be eliminated to yield:
18790 \layout Verse
18791
18792
18793 \family typewriter 
18794 ; nop 
18795 \newline 
18796 ; nop
18797 \layout Standard
18798
18799 A conditional function can be attached to a rule.
18800  Attaching rules are somewhat more involved, let me illustrate this with
18801  an example.
18802 \layout Verse
18803
18804
18805 \family typewriter 
18806 replace { 
18807 \newline 
18808 \SpecialChar ~
18809  \SpecialChar ~
18810  \SpecialChar ~
18811 ljmp %5 
18812 \newline 
18813 %2:
18814 \newline 
18815 } by { 
18816 \newline 
18817 \SpecialChar ~
18818  \SpecialChar ~
18819  \SpecialChar ~
18820 sjmp %5 
18821 \newline 
18822 %2:
18823 \newline 
18824 } if labelInRange
18825 \layout Standard
18826
18827 The optimizer does a look-up of a function name table defined in function
18828  
18829 \emph on 
18830 callFuncByName
18831 \emph default 
18832  in the source file SDCCpeeph.c, with the name 
18833 \emph on 
18834 labelInRange
18835 \emph default 
18836 .
18837  If it finds a corresponding entry the function is called.
18838  Note there can be no parameters specified for these functions, in this
18839  case the use of 
18840 \emph on 
18841 %5
18842 \emph default 
18843  is crucial, since the function 
18844 \emph on 
18845 labelInRange
18846 \emph default 
18847  expects to find the label in that particular variable (the hash table containin
18848 g the variable bindings is passed as a parameter).
18849  If you want to code more such functions, take a close look at the function
18850  labelInRange and the calling mechanism in source file SDCCpeeph.c.
18851  Currently implemented are 
18852 \emph on 
18853 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
18854  24bitMode, portIsDS390, 24bitModeAndPortDS390 
18855 \emph default 
18856 and
18857 \emph on 
18858  notVolatile
18859 \emph default 
18860 .
18861 \layout Standard
18862
18863 I know this whole thing is a little kludgey, but maybe some day we will
18864  have some better means.
18865  If you are looking at this file, you will see the default rules that are
18866  compiled into the compiler, you can add your own rules in the default set
18867  there if you get tired of specifying the -
18868 \begin_inset ERT
18869 status Collapsed
18870
18871 \layout Standard
18872
18873 \backslash 
18874 /
18875 \end_inset 
18876
18877 -peep-file option.
18878 \layout Section
18879
18880 ANSI-Compliance
18881 \begin_inset LatexCommand \index{ANSI-compliance}
18882
18883 \end_inset 
18884
18885
18886 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
18887
18888 \end_inset 
18889
18890
18891 \layout Standard
18892
18893 Deviations from the compliance:
18894 \layout Itemize
18895
18896 functions are not always reentrant
18897 \begin_inset LatexCommand \index{reentrant}
18898
18899 \end_inset 
18900
18901 .
18902 \layout Itemize
18903
18904 structures cannot be assigned values directly, cannot be passed as function
18905  parameters or assigned to each other and cannot be a return value from
18906  a function, e.g.:
18907 \begin_deeper 
18908 \layout Verse
18909
18910
18911 \family typewriter 
18912 struct s { ...
18913  }; 
18914 \newline 
18915 struct s s1, s2; 
18916 \newline 
18917 foo() 
18918 \newline 
18919
18920 \newline 
18921 \SpecialChar ~
18922 \SpecialChar ~
18923 \SpecialChar ~
18924 \SpecialChar ~
18925 ...
18926  
18927 \newline 
18928 \SpecialChar ~
18929 \SpecialChar ~
18930 \SpecialChar ~
18931 \SpecialChar ~
18932 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
18933 \newline 
18934 \SpecialChar ~
18935 \SpecialChar ~
18936 \SpecialChar ~
18937 \SpecialChar ~
18938 ...
18939  
18940 \newline 
18941 }
18942 \newline 
18943 struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
18944  */
18945 \newline 
18946
18947 \newline 
18948 \SpecialChar ~
18949 \SpecialChar ~
18950 \SpecialChar ~
18951 \SpecialChar ~
18952 struct s rets; 
18953 \newline 
18954 \SpecialChar ~
18955 \SpecialChar ~
18956 \SpecialChar ~
18957 \SpecialChar ~
18958 ...
18959  
18960 \newline 
18961 \SpecialChar ~
18962 \SpecialChar ~
18963 \SpecialChar ~
18964 \SpecialChar ~
18965 return rets;/* is invalid in SDCC although allowed in ANSI */ 
18966 \newline 
18967 }
18968 \end_deeper 
18969 \layout Itemize
18970
18971 'long long
18972 \begin_inset LatexCommand \index{long long (not supported)}
18973
18974 \end_inset 
18975
18976 ' (64 bit integers
18977 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
18978
18979 \end_inset 
18980
18981 ) not supported.
18982 \layout Itemize
18983
18984 'double
18985 \begin_inset LatexCommand \index{double (not supported)}
18986
18987 \end_inset 
18988
18989 ' precision floating point 
18990 \begin_inset LatexCommand \index{Floating point support}
18991
18992 \end_inset 
18993
18994 not supported.
18995 \layout Itemize
18996
18997 No support for setjmp
18998 \begin_inset LatexCommand \index{setjmp (not supported)}
18999
19000 \end_inset 
19001
19002  and longjmp
19003 \begin_inset LatexCommand \index{longjmp (not supported)}
19004
19005 \end_inset 
19006
19007  (for now).
19008 \layout Itemize
19009
19010 Old K&R style
19011 \begin_inset LatexCommand \index{K\&R style}
19012
19013 \end_inset 
19014
19015  function declarations are NOT allowed.
19016 \begin_deeper 
19017 \layout Verse
19018
19019
19020 \family typewriter 
19021 foo(i,j) /* this old style of function declarations */ 
19022 \newline 
19023 int i,j; /* are valid in ANSI but not valid in SDCC */ 
19024 \newline 
19025
19026 \newline 
19027 \SpecialChar ~
19028 \SpecialChar ~
19029 \SpecialChar ~
19030 \SpecialChar ~
19031 ...
19032  
19033 \newline 
19034 }
19035 \end_deeper 
19036 \layout Itemize
19037
19038 functions declared as pointers
19039 \begin_inset LatexCommand \index{Pointer (to function)}
19040
19041 \end_inset 
19042
19043
19044 \begin_inset LatexCommand \index{function pointers}
19045
19046 \end_inset 
19047
19048  must be dereferenced during the call.
19049 \begin_deeper 
19050 \layout Verse
19051
19052
19053 \family typewriter 
19054 int (*foo)();
19055 \newline 
19056 ...
19057  
19058 \newline 
19059 /* has to be called like this */ 
19060 \newline 
19061 (*foo)(); /* ANSI standard allows calls to be made like 'foo()' */
19062 \end_deeper 
19063 \layout Section
19064
19065 Cyclomatic Complexity
19066 \begin_inset LatexCommand \index{Cyclomatic complexity}
19067
19068 \end_inset 
19069
19070
19071 \layout Standard
19072
19073 Cyclomatic complexity of a function is defined as the number of independent
19074  paths the program can take during execution of the function.
19075  This is an important number since it defines the number test cases you
19076  have to generate to validate the function.
19077  The accepted industry standard for complexity number is 10, if the cyclomatic
19078  complexity reported by SDCC exceeds 10 you should think about simplification
19079  of the function logic.
19080  Note that the complexity level is not related to the number of lines of
19081  code in a function.
19082  Large functions can have low complexity, and small functions can have large
19083  complexity levels.
19084  
19085 \newline 
19086
19087 \newline 
19088 SDCC uses the following formula to compute the complexity:
19089 \newline 
19090
19091 \layout Standard
19092
19093 complexity = (number of edges in control flow graph) - (number of nodes
19094  in control flow graph) + 2;
19095 \newline 
19096
19097 \newline 
19098 Having said that the industry standard is 10, you should be aware that in
19099  some cases it be may unavoidable to have a complexity level of less than
19100  10.
19101  For example if you have switch statement with more than 10 case labels,
19102  each case label adds one to the complexity level.
19103  The complexity level is by no means an absolute measure of the algorithmic
19104  complexity of the function, it does however provide a good starting point
19105  for which functions you might look at for further optimization.
19106 \layout Section
19107
19108 Notes on supported Processors
19109 \layout Subsection
19110
19111 MCS51 variants
19112 \begin_inset LatexCommand \label{sub:MCS51-variants}
19113
19114 \end_inset 
19115
19116
19117 \begin_inset LatexCommand \index{MCS51 variants}
19118
19119 \end_inset 
19120
19121
19122 \layout Standard
19123
19124 MCS51 processors are available from many vendors and come in many different
19125  flavours.
19126  While they might differ considerably in respect to Special Function Registers
19127  the core MCS51 is usually not modified or is kept compatible.
19128  
19129 \layout Subsubsection*
19130
19131 pdata access by SFR 
19132 \layout Standard
19133
19134 With the upcome of devices with internal xdata and flash memory devices
19135  using port P2
19136 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
19137
19138 \end_inset 
19139
19140  as dedicated I/O port is becoming more popular.
19141  Switching the high byte for pdata
19142 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
19143
19144 \end_inset 
19145
19146  access which was formerly done by port P2 is then achieved by a Special
19147  Function Register
19148 \begin_inset LatexCommand \index{sfr}
19149
19150 \end_inset 
19151
19152 .
19153  In well-established MCS51 tradition the address of this 
19154 \emph on 
19155 sfr
19156 \emph default 
19157  is where the chip designers decided to put it.
19158  Needless to say that they didn't agree on a common name either.
19159  As pdata addressing is used in the startup code for the initialization
19160  of xdata variables a separate startup code should be used as described
19161  in section 
19162 \begin_inset LatexCommand \ref{sub:Startup-Code}
19163
19164 \end_inset 
19165
19166 .
19167 \layout Subsubsection*
19168
19169 Other Features available by SFR
19170 \layout Standard
19171
19172 Some MCS51 variants offer features like Double DPTR
19173 \begin_inset LatexCommand \index{DPTR}
19174
19175 \end_inset 
19176
19177 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
19178  These are currently not used for the MCS51 port.
19179  If you absolutely need them you can fall back to inline assembly or submit
19180  a patch to SDCC.
19181 \layout Subsection
19182
19183 The Z80 and gbz80 port
19184 \layout Standard
19185
19186 SDCC can target both the Zilog 
19187 \begin_inset LatexCommand \index{Z80}
19188
19189 \end_inset 
19190
19191  and the Nintendo Gameboy's Z80-like gbz80
19192 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
19193
19194 \end_inset 
19195
19196 .
19197  The Z80 port is passed through the same 
19198 \emph on 
19199 regressions tests
19200 \begin_inset LatexCommand \index{Regression test}
19201
19202 \end_inset 
19203
19204
19205 \emph default 
19206  as the MCS51 and DS390 ports, so floating point support, support for long
19207  variables and bitfield support is fine.
19208  See mailing lists and forums about interrupt routines.
19209 \layout Standard
19210
19211 As always, the code is the authoritative reference - see z80/ralloc.c and
19212  z80/gen.c.
19213  The stack
19214 \begin_inset LatexCommand \index{stack}
19215
19216 \end_inset 
19217
19218  frame is similar to that generated by the IAR Z80 compiler.
19219  IX is used as the base pointer, HL is used as a temporary register, and
19220  BC and DE are available for holding variables.
19221  IY is currently unused.
19222  Return values
19223 \begin_inset LatexCommand \index{return value}
19224
19225 \end_inset 
19226
19227  are stored in HL.
19228  One bad side effect of using IX as the base pointer is that a functions
19229  stack frame is limited to 127 bytes - this will be fixed in a later version.
19230 \layout Subsection
19231
19232 The HC08 port
19233 \layout Standard
19234
19235 The port to the Motorola HC08
19236 \begin_inset LatexCommand \index{HC08}
19237
19238 \end_inset 
19239
19240  family has been added in October 2003, thank you Erik!
19241 \layout Subsection
19242
19243 The PIC14 port
19244 \layout Standard
19245
19246 The 14bit PIC
19247 \begin_inset LatexCommand \index{PIC14}
19248
19249 \end_inset 
19250
19251  port still requires a major effort from the development community.
19252  However it can work for very simple code.
19253 \newline 
19254
19255 \newline 
19256
19257 \bar under 
19258 C code and 14bit PIC code page
19259 \begin_inset LatexCommand \index{code page (pic14)}
19260
19261 \end_inset 
19262
19263  and RAM banks
19264 \bar default 
19265
19266 \begin_inset LatexCommand \index{RAM bank (pic14)}
19267
19268 \end_inset 
19269
19270
19271 \newline 
19272 The linker organizes allocation for the code page and RAM banks.
19273  It does not have intimate knowledge of the code flow.
19274  It will put all the code section of a single asm file into a single code
19275  page.
19276  In order to make use of multiple code pages, separate asm files must be
19277  used.
19278  The compiler treats all functions of a single C file as being in the same
19279  code page unless it is non static.
19280  The compiler treats all local variables of a single C file as being in
19281  the same RAM bank unless it is an extern.
19282 \newline 
19283
19284 \newline 
19285 To get the best follow these guide lines:
19286 \layout Enumerate
19287
19288 make local functions static, as non static functions require code page selection
19289  overhead.
19290 \layout Enumerate
19291
19292 Make local variables static as extern variables require RAM bank selection
19293  overhead.
19294 \layout Enumerate
19295
19296 For devices that have multiple code pages it is more efficient to use the
19297  same number of files as pages, i.e.
19298  for the 16F877 use 4 separate files and i.e.
19299  for the 16F874 use 2 separate files.
19300  This way the linker can put the code for each file into different code
19301  pages and the compiler can allocate reusable variables more efficiently
19302  and there's less page selection overhead.
19303  And as for any 8 bit micro (especially for PIC 14 as they have a very simple
19304  instruction set) use 'unsigned char' whereever possible instead of 'int'.
19305 \layout Standard
19306
19307
19308 \bar under 
19309 Creating a device include file 
19310 \bar default 
19311
19312 \newline 
19313 For generating a device include file use the support perl script inc2h.pl
19314  kept in directory support/script.
19315 \newline 
19316
19317 \newline 
19318
19319 \bar under 
19320 Interrupt code
19321 \bar default 
19322
19323 \newline 
19324 For the interrupt function, use the keyword 'interrupt'
19325 \begin_inset LatexCommand \index{interrupt}
19326
19327 \end_inset 
19328
19329  with level number of 0 (PIC14 only has 1 interrupt so this number is only
19330  there to avoid a syntax error - it ought to be fixed).
19331  E.g.:
19332 \layout Verse
19333
19334
19335 \family typewriter 
19336 void Intr(void) interrupt 0
19337 \newline 
19338 {
19339 \newline 
19340 \SpecialChar ~
19341 \SpecialChar ~
19342 T0IF = 0; /* Clear timer interrupt */
19343 \newline 
19344 }
19345 \layout Standard
19346
19347
19348 \bar under 
19349 Linking and assembling
19350 \bar default 
19351
19352 \newline 
19353 For assembling you can use either GPUTILS' gpasm.exe or MPLAB's mpasmwin.exe.
19354  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
19355  If you use MPLAB and an interrupt function then the linker script file
19356  vectors section will need to be enlarged to link with mplink.
19357 \newline 
19358
19359 \newline 
19360 Here is a 
19361 \family typewriter 
19362 Makefile
19363 \family default 
19364  using GPUTILS:
19365 \layout Verse
19366
19367
19368 \family typewriter 
19369 .c.o:
19370 \newline 
19371 \SpecialChar ~
19372 \SpecialChar ~
19373 \SpecialChar ~
19374 \SpecialChar ~
19375 \SpecialChar ~
19376 \SpecialChar ~
19377 \SpecialChar ~
19378 \SpecialChar ~
19379 sdcc -S -V -mpic14 -p16F877 $< 
19380 \newline 
19381 \SpecialChar ~
19382 \SpecialChar ~
19383 \SpecialChar ~
19384 \SpecialChar ~
19385 \SpecialChar ~
19386 \SpecialChar ~
19387 \SpecialChar ~
19388 \SpecialChar ~
19389 gpasm -c $*.asm
19390 \newline 
19391
19392 \newline 
19393 $(PRJ).hex: $(OBJS) 
19394 \newline 
19395 \SpecialChar ~
19396 \SpecialChar ~
19397 \SpecialChar ~
19398 \SpecialChar ~
19399 \SpecialChar ~
19400 \SpecialChar ~
19401 \SpecialChar ~
19402 \SpecialChar ~
19403 gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS)
19404 \layout Standard
19405
19406 Here is a 
19407 \family typewriter 
19408 Makefile
19409 \family default 
19410  using MPLAB:
19411 \layout Verse
19412
19413
19414 \family typewriter 
19415 .c.o: 
19416 \newline 
19417 \SpecialChar ~
19418 \SpecialChar ~
19419 \SpecialChar ~
19420 \SpecialChar ~
19421 \SpecialChar ~
19422 \SpecialChar ~
19423 \SpecialChar ~
19424 \SpecialChar ~
19425 sdcc -S -V -mpic14 -p16F877 $< 
19426 \newline 
19427 \SpecialChar ~
19428 \SpecialChar ~
19429 \SpecialChar ~
19430 \SpecialChar ~
19431 \SpecialChar ~
19432 \SpecialChar ~
19433 \SpecialChar ~
19434 \SpecialChar ~
19435 mpasmwin /q /o $*.asm
19436 \newline 
19437
19438 \newline 
19439 $(PRJ).hex: $(OBJS) 
19440 \newline 
19441 \SpecialChar ~
19442 \SpecialChar ~
19443 \SpecialChar ~
19444 \SpecialChar ~
19445 \SpecialChar ~
19446 \SpecialChar ~
19447 \SpecialChar ~
19448 \SpecialChar ~
19449 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS)
19450 \layout Subsection
19451
19452 The PIC16
19453 \begin_inset LatexCommand \index{PIC16}
19454
19455 \end_inset 
19456
19457  port
19458 \layout Standard
19459
19460 You'll find some additional notes about this port in the file src/pic16/NOTES.
19461 \layout Section
19462
19463 Retargetting for other Processors
19464 \layout Standard
19465
19466 The issues for retargetting the compiler are far too numerous to be covered
19467  by this document.
19468  What follows is a brief description of each of the seven phases of the
19469  compiler and its MCU dependency.
19470 \layout Itemize
19471
19472 Parsing the source and building the annotated parse tree.
19473  This phase is largely MCU independent (except for the language extensions).
19474  Syntax & semantic checks are also done in this phase, along with some initial
19475  optimizations like back patching labels and the pattern matching optimizations
19476  like bit-rotation etc.
19477 \layout Itemize
19478
19479 The second phase involves generating an intermediate code which can be easy
19480  manipulated during the later phases.
19481  This phase is entirely MCU independent.
19482  The intermediate code generation assumes the target machine has unlimited
19483  number of registers, and designates them with the name iTemp.
19484  The compiler can be made to dump a human readable form of the code generated
19485  by using the -
19486 \begin_inset ERT
19487 status Collapsed
19488
19489 \layout Standard
19490
19491 \backslash 
19492 /
19493 \end_inset 
19494
19495 -dumpraw option.
19496 \layout Itemize
19497
19498 This phase does the bulk of the standard optimizations and is also MCU independe
19499 nt.
19500  This phase can be broken down into several sub-phases:
19501 \newline 
19502
19503 \newline 
19504 Break down intermediate code (iCode) into basic blocks.
19505 \newline 
19506 Do control flow & data flow analysis on the basic blocks.
19507 \newline 
19508 Do local common subexpression elimination, then global subexpression elimination
19509 \newline 
19510 Dead code elimination
19511 \newline 
19512 Loop optimizations
19513 \newline 
19514 If loop optimizations caused any changes then do 'global subexpression eliminati
19515 on' and 'dead code elimination' again.
19516 \layout Itemize
19517
19518 This phase determines the live-ranges; by live range I mean those iTemp
19519  variables defined by the compiler that still survive after all the optimization
19520 s.
19521  Live range analysis
19522 \begin_inset LatexCommand \index{Live range analysis}
19523
19524 \end_inset 
19525
19526  is essential for register allocation, since these computation determines
19527  which of these iTemps will be assigned to registers, and for how long.
19528 \layout Itemize
19529
19530 Phase five is register allocation.
19531  There are two parts to this process.
19532 \newline 
19533
19534 \newline 
19535 The first part I call 'register packing' (for lack of a better term).
19536  In this case several MCU specific expression folding is done to reduce
19537  register pressure.
19538 \newline 
19539
19540 \newline 
19541 The second part is more MCU independent and deals with allocating registers
19542  to the remaining live ranges.
19543  A lot of MCU specific code does creep into this phase because of the limited
19544  number of index registers available in the 8051.
19545 \layout Itemize
19546
19547 The Code generation phase is (unhappily), entirely MCU dependent and very
19548  little (if any at all) of this code can be reused for other MCU.
19549  However the scheme for allocating a homogenized assembler operand for each
19550  iCode operand may be reused.
19551 \layout Itemize
19552
19553 As mentioned in the optimization section the peep-hole optimizer is rule
19554  based system, which can reprogrammed for other MCUs.
19555 \layout Chapter
19556
19557 Compiler internals
19558 \begin_inset LatexCommand \index{Compiler internals}
19559
19560 \end_inset 
19561
19562
19563 \layout Section
19564
19565 The anatomy of the compiler
19566 \begin_inset LatexCommand \label{sub:The-anatomy-of}
19567
19568 \end_inset 
19569
19570
19571 \layout Standard
19572
19573
19574 \shape italic 
19575 This is an excerpt from an article published in Circuit Cellar Magazine
19576  in august 2000.
19577  It's a little outdated (the compiler is much more efficient now and user/develo
19578 per friendly), but pretty well exposes the guts of it all.
19579 \shape default 
19580
19581 \newline 
19582
19583 \newline 
19584 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
19585  It is fairly easy to retarget for other 8-bit MCU.
19586  Here we take a look at some of the internals of the compiler.
19587  
19588 \layout Paragraph*
19589
19590 Parsing
19591 \begin_inset LatexCommand \index{Parsing}
19592
19593 \end_inset 
19594
19595  
19596 \layout Standard
19597
19598 Parsing the input source file and creating an AST (Annotated Syntax Tree
19599 \begin_inset LatexCommand \index{Annotated syntax tree}
19600
19601 \end_inset 
19602
19603 ).
19604  This phase also involves propagating types (annotating each node of the
19605  parse tree with type information) and semantic analysis.
19606  There are some MCU specific parsing rules.
19607  For example the storage classes, the extended storage classes are MCU specific
19608  while there may be a xdata storage class for 8051 there is no such storage
19609  class for z80 or Atmel AVR.
19610  SDCC allows MCU specific storage class extensions, i.e.
19611  xdata will be treated as a storage class specifier when parsing 8051 C
19612  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
19613  C code.
19614 \layout Paragraph*
19615
19616 Generating iCode
19617 \begin_inset LatexCommand \index{iCode}
19618
19619 \end_inset 
19620
19621
19622 \layout Standard
19623
19624 Intermediate code generation.
19625  In this phase the AST is broken down into three-operand form (iCode).
19626  These three operand forms are represented as doubly linked lists.
19627  ICode is the term given to the intermediate form generated by the compiler.
19628  ICode example section shows some examples of iCode generated for some simple
19629  C source functions.
19630 \layout Paragraph*
19631
19632 Optimizations
19633 \begin_inset LatexCommand \index{Optimizations}
19634
19635 \end_inset 
19636
19637 .
19638 \layout Standard
19639
19640 Bulk of the target independent optimizations is performed in this phase.
19641  The optimizations include constant propagation, common sub-expression eliminati
19642 on, loop invariant code movement, strength reduction of loop induction variables
19643  and dead-code elimination.
19644 \layout Paragraph*
19645
19646 Live range analysis
19647 \begin_inset LatexCommand \index{Live range analysis}
19648
19649 \end_inset 
19650
19651
19652 \layout Standard
19653
19654 During intermediate code generation phase, the compiler assumes the target
19655  machine has infinite number of registers and generates a lot of temporary
19656  variables.
19657  The live range computation determines the lifetime of each of these compiler-ge
19658 nerated temporaries.
19659  A picture speaks a thousand words.
19660  ICode example sections show the live range annotations for each of the
19661  operand.
19662  It is important to note here, each iCode is assigned a number in the order
19663  of its execution in the function.
19664  The live ranges are computed in terms of these numbers.
19665  The from number is the number of the iCode which first defines the operand
19666  and the to number signifies the iCode which uses this operand last.
19667 \layout Paragraph*
19668
19669 Register Allocation
19670 \begin_inset LatexCommand \index{Register allocation}
19671
19672 \end_inset 
19673
19674
19675 \layout Standard
19676
19677 The register allocation determines the type and number of registers needed
19678  by each operand.
19679  In most MCUs only a few registers can be used for indirect addressing.
19680  In case of 8051 for example the registers R0 & R1 can be used to indirectly
19681  address the internal ram and DPTR to indirectly address the external ram.
19682  The compiler will try to allocate the appropriate register to pointer variables
19683  if it can.
19684  ICode example section shows the operands annotated with the registers assigned
19685  to them.
19686  The compiler will try to keep operands in registers as much as possible;
19687  there are several schemes the compiler uses to do achieve this.
19688  When the compiler runs out of registers the compiler will check to see
19689  if there are any live operands which is not used or defined in the current
19690  basic block being processed, if there are any found then it will push that
19691  operand and use the registers in this block, the operand will then be popped
19692  at the end of the basic block.
19693  
19694 \layout Standard
19695
19696 There are other MCU specific considerations in this phase.
19697  Some MCUs have an accumulator; very short-lived operands could be assigned
19698  to the accumulator instead of a general-purpose register.
19699 \layout Paragraph*
19700
19701 Code generation
19702 \layout Standard
19703
19704 Figure II gives a table of iCode operations supported by the compiler.
19705  The code generation involves translating these operations into corresponding
19706  assembly code for the processor.
19707  This sounds overly simple but that is the essence of code generation.
19708  Some of the iCode operations are generated on a MCU specific manner for
19709  example, the z80 port does not use registers to pass parameters so the
19710  SEND and RECV iCode operations will not be generated, and it also does
19711  not support JUMPTABLES.
19712  
19713 \newline 
19714
19715 \series bold 
19716 \shape italic 
19717 \color red
19718 <Where is Figure II ?>
19719 \layout Paragraph*
19720
19721 ICode Example
19722 \begin_inset LatexCommand \index{iCode}
19723
19724 \end_inset 
19725
19726
19727 \layout Standard
19728
19729 This section shows some details of iCode.
19730  The example C code does not do anything useful; it is used as an example
19731  to illustrate the intermediate code generated by the compiler.
19732 \layout Verse
19733
19734
19735 \family typewriter 
19736 1.\SpecialChar ~
19737 xdata int * p;
19738 \newline 
19739 2.\SpecialChar ~
19740 int gint;
19741 \newline 
19742 3.\SpecialChar ~
19743 /* This function does nothing useful.
19744  It is used
19745 \newline 
19746 4.\SpecialChar ~
19747 \SpecialChar ~
19748 \SpecialChar ~
19749 \SpecialChar ~
19750 for the purpose of explaining iCode */
19751 \newline 
19752 5.\SpecialChar ~
19753 short function (data int *x)
19754 \newline 
19755 6.\SpecialChar ~
19756 {
19757 \newline 
19758 7.\SpecialChar ~
19759 \SpecialChar ~
19760 \SpecialChar ~
19761 short i=10; \SpecialChar ~
19762 \SpecialChar ~
19763 /* dead initialization eliminated */
19764 \newline 
19765 8.\SpecialChar ~
19766 \SpecialChar ~
19767 \SpecialChar ~
19768 short sum=10; /* dead initialization eliminated */
19769 \newline 
19770 9.\SpecialChar ~
19771 \SpecialChar ~
19772 \SpecialChar ~
19773 short mul;
19774 \newline 
19775 10.\SpecialChar ~
19776 \SpecialChar ~
19777 int j ;
19778 \newline 
19779 11.\SpecialChar ~
19780 \SpecialChar ~
19781 while (*x) *x++ = *p++; 
19782 \newline 
19783 12.\SpecialChar ~
19784 \SpecialChar ~
19785 \SpecialChar ~
19786 \SpecialChar ~
19787 sum = 0 ; 
19788 \newline 
19789 13.\SpecialChar ~
19790 \SpecialChar ~
19791 mul = 0;
19792 \newline 
19793 14.\SpecialChar ~
19794 \SpecialChar ~
19795 /* compiler detects i,j to be induction variables */
19796 \newline 
19797 15.\SpecialChar ~
19798 \SpecialChar ~
19799 for (i = 0, j = 10 ; i < 10 ; i++, j
19800 \family default 
19801 -
19802 \begin_inset ERT
19803 status Collapsed
19804
19805 \layout Standard
19806
19807 \backslash 
19808 /
19809 \end_inset 
19810
19811 -
19812 \family typewriter 
19813 ) {
19814 \newline 
19815 16.\SpecialChar ~
19816 \SpecialChar ~
19817 \SpecialChar ~
19818 \SpecialChar ~
19819 sum += i;
19820 \newline 
19821 17.\SpecialChar ~
19822 \SpecialChar ~
19823 \SpecialChar ~
19824 \SpecialChar ~
19825 mul += i * 3; \SpecialChar ~
19826 \SpecialChar ~
19827 /* this multiplication remains */
19828 \newline 
19829 18.\SpecialChar ~
19830 \SpecialChar ~
19831 \SpecialChar ~
19832 \SpecialChar ~
19833 gint += j * 3;\SpecialChar ~
19834 \SpecialChar ~
19835 /* this multiplication changed to addition */
19836 \newline 
19837 19.\SpecialChar ~
19838 \SpecialChar ~
19839 }
19840 \newline 
19841 20.\SpecialChar ~
19842 \SpecialChar ~
19843 return sum+mul;
19844 \newline 
19845 21.\SpecialChar ~
19846 }
19847 \layout Standard
19848
19849 In addition to the operands each iCode contains information about the filename
19850  and line it corresponds to in the source file.
19851  The first field in the listing should be interpreted as follows:
19852 \newline 
19853
19854 \shape italic 
19855 \size footnotesize 
19856 Filename(linenumber: iCode Execution sequence number : ICode hash table
19857  key : loop depth of the iCode).
19858 \shape default 
19859 \size default 
19860
19861 \newline 
19862 Then follows the human readable form of the ICode operation.
19863  Each operand of this triplet form can be of three basic types a) compiler
19864  generated temporary b) user defined variable c) a constant value.
19865  Note that local variables and parameters are replaced by compiler generated
19866  temporaries.
19867  Live ranges
19868 \begin_inset LatexCommand \index{Live range analysis}
19869
19870 \end_inset 
19871
19872  are computed only for temporaries (i.e.
19873  live ranges are not computed for global variables).
19874  Registers
19875 \begin_inset LatexCommand \index{Register allocation}
19876
19877 \end_inset 
19878
19879  are allocated for temporaries only.
19880  Operands are formatted in the following manner:
19881 \newline 
19882
19883 \shape italic 
19884 \size footnotesize 
19885 Operand Name [lr live-from : live-to ] { type information } [ registers
19886  allocated ].
19887 \shape default 
19888 \size default 
19889
19890 \newline 
19891 As mentioned earlier the live ranges are computed in terms of the execution
19892  sequence number of the iCodes, for example 
19893 \newline 
19894 the iTemp0 is live from (i.e.
19895  first defined in iCode with execution sequence number 3, and is last used
19896  in the iCode with sequence number 5).
19897  For induction variables such as iTemp21 the live range computation extends
19898  the lifetime from the start to the end of the loop.
19899 \newline 
19900 The register allocator used the live range information to allocate registers,
19901  the same registers may be used for different temporaries if their live
19902  ranges do not overlap, for example r0 is allocated to both iTemp6 and to
19903  iTemp17 since their live ranges do not overlap.
19904  In addition the allocator also takes into consideration the type and usage
19905  of a temporary, for example itemp6 is a pointer to near space and is used
19906  as to fetch data from (i.e.
19907  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
19908  Some short lived temporaries are allocated to special registers which have
19909  meaning to the code generator e.g.
19910  iTemp13 is allocated to a pseudo register CC which tells the back end that
19911  the temporary is used only for a conditional jump the code generation makes
19912  use of this information to optimize a compare and jump ICode.
19913 \newline 
19914 There are several loop optimizations
19915 \begin_inset LatexCommand \index{Loop optimization}
19916
19917 \end_inset 
19918
19919  performed by the compiler.
19920  It can detect induction variables iTemp21(i) and iTemp23(j).
19921  Also note the compiler does selective strength reduction
19922 \begin_inset LatexCommand \index{Strength reduction}
19923
19924 \end_inset 
19925
19926 , i.e.
19927  the multiplication of an induction variable in line 18 (gint = j * 3) is
19928  changed to addition, a new temporary iTemp17 is allocated and assigned
19929  a initial value, a constant 3 is then added for each iteration of the loop.
19930  The compiler does not change the multiplication
19931 \begin_inset LatexCommand \index{Multiplication}
19932
19933 \end_inset 
19934
19935  in line 17 however since the processor does support an 8 * 8 bit multiplication.
19936 \newline 
19937 Note the dead code elimination
19938 \begin_inset LatexCommand \index{Dead-code elimination}
19939
19940 \end_inset 
19941
19942  optimization eliminated the dead assignments in line 7 & 8 to I and sum
19943  respectively.
19944 \newline 
19945
19946 \layout Standard
19947
19948
19949 \size footnotesize 
19950 Sample.c (5:1:0:0) _entry($9) :
19951 \layout Standard
19952
19953
19954 \size footnotesize 
19955 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
19956 \layout Standard
19957
19958
19959 \size footnotesize 
19960 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
19961 \layout Standard
19962
19963
19964 \size footnotesize 
19965 Sample.c(11:4:53:0) preHeaderLbl0($11) :
19966 \layout Standard
19967
19968
19969 \size footnotesize 
19970 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
19971  * int}[r2]
19972 \layout Standard
19973
19974
19975 \size footnotesize 
19976 Sample.c(11:6:5:1) _whilecontinue_0($1) :
19977 \layout Standard
19978
19979
19980 \size footnotesize 
19981 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
19982  int}[r0]]
19983 \layout Standard
19984
19985
19986 \size footnotesize 
19987 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
19988 \layout Standard
19989
19990
19991 \size footnotesize 
19992 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
19993  * int}
19994 \layout Standard
19995
19996
19997 \size footnotesize 
19998 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
19999  {short}
20000 \layout Standard
20001
20002
20003 \size footnotesize 
20004 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
20005  * int}[DPTR]]
20006 \layout Standard
20007
20008
20009 \size footnotesize 
20010 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
20011 }[r2 r3]
20012 \layout Standard
20013
20014
20015 \size footnotesize 
20016 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
20017  * int}[r0] + 0x2 {short}
20018 \layout Standard
20019
20020
20021 \size footnotesize 
20022 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
20023 \layout Standard
20024
20025
20026 \size footnotesize 
20027 Sample.c(11:17:21:0)_whilebreak_0($3) :
20028 \layout Standard
20029
20030
20031 \size footnotesize 
20032 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
20033 \layout Standard
20034
20035
20036 \size footnotesize 
20037 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
20038 \layout Standard
20039
20040
20041 \size footnotesize 
20042 Sample.c(15:20:54:0)preHeaderLbl1($13) :
20043 \layout Standard
20044
20045
20046 \size footnotesize 
20047 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
20048 \layout Standard
20049
20050
20051 \size footnotesize 
20052 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
20053 \layout Standard
20054
20055
20056 \size footnotesize 
20057 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
20058 \layout Standard
20059
20060
20061 \size footnotesize 
20062 Sample.c(15:24:26:1)_forcond_0($4) :
20063 \layout Standard
20064
20065
20066 \size footnotesize 
20067 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
20068  < 0xa {short}
20069 \layout Standard
20070
20071
20072 \size footnotesize 
20073 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
20074 \layout Standard
20075
20076
20077 \size footnotesize 
20078 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
20079  + ITemp21 [lr21:38]{short}[r4]
20080 \layout Standard
20081
20082
20083 \size footnotesize 
20084 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
20085  * 0x3 {short}
20086 \layout Standard
20087
20088
20089 \size footnotesize 
20090 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
20091  + iTemp15 [lr29:30]{short}[r1]
20092 \layout Standard
20093
20094
20095 \size footnotesize 
20096 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
20097  r0]- 0x3 {short}
20098 \layout Standard
20099
20100
20101 \size footnotesize 
20102 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
20103 int}[r7 r0]
20104 \layout Standard
20105
20106
20107 \size footnotesize 
20108 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
20109  + 0x1 {short}
20110 \layout Standard
20111
20112
20113 \size footnotesize 
20114 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
20115  r6]- 0x1 {short}
20116 \layout Standard
20117
20118
20119 \size footnotesize 
20120 Sample.c(19:38:47:1) goto _forcond_0($4)
20121 \layout Standard
20122
20123
20124 \size footnotesize 
20125 Sample.c(19:39:48:0)_forbreak_0($7) :
20126 \layout Standard
20127
20128
20129 \size footnotesize 
20130 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
20131  + ITemp11 [lr19:40]{short}[r3]
20132 \layout Standard
20133
20134
20135 \size footnotesize 
20136 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
20137 \layout Standard
20138
20139
20140 \size footnotesize 
20141 Sample.c(20:42:51:0)_return($8) :
20142 \layout Standard
20143
20144
20145 \size footnotesize 
20146 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
20147 \size default 
20148
20149 \newline 
20150
20151 \newline 
20152 Finally the code generated for this function:
20153 \newline 
20154
20155 \layout Standard
20156
20157
20158 \size footnotesize 
20159 .area DSEG (DATA)
20160 \layout Standard
20161
20162
20163 \size footnotesize 
20164 _p::
20165 \layout Standard
20166
20167
20168 \size footnotesize 
20169 \SpecialChar ~
20170 \SpecialChar ~
20171 .ds 2
20172 \layout Standard
20173
20174
20175 \size footnotesize 
20176 _gint::
20177 \layout Standard
20178
20179
20180 \size footnotesize 
20181 \SpecialChar ~
20182 \SpecialChar ~
20183 .ds 2
20184 \layout Standard
20185
20186
20187 \size footnotesize 
20188 ; sample.c 5
20189 \layout Standard
20190
20191
20192 \size footnotesize 
20193 ; ----------------------------------------------
20194 \layout Standard
20195
20196
20197 \size footnotesize 
20198 ; function function
20199 \layout Standard
20200
20201
20202 \size footnotesize 
20203 ; ----------------------------------------------
20204 \layout Standard
20205
20206
20207 \size footnotesize 
20208 _function:
20209 \layout Standard
20210
20211
20212 \size footnotesize 
20213 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
20214 \layout Standard
20215
20216
20217 \size footnotesize 
20218 \SpecialChar ~
20219 \SpecialChar ~
20220 mov r2,dpl
20221 \layout Standard
20222
20223
20224 \size footnotesize 
20225 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
20226 \layout Standard
20227
20228
20229 \size footnotesize 
20230 \SpecialChar ~
20231 \SpecialChar ~
20232 mov ar0,r2
20233 \layout Standard
20234
20235
20236 \size footnotesize 
20237 ;_whilecontinue_0($1) :
20238 \layout Standard
20239
20240
20241 \size footnotesize 
20242 00101$:
20243 \layout Standard
20244
20245
20246 \size footnotesize 
20247 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
20248 \layout Standard
20249
20250
20251 \size footnotesize 
20252 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
20253 \layout Standard
20254
20255
20256 \size footnotesize 
20257 \SpecialChar ~
20258 \SpecialChar ~
20259 mov ar2,@r0
20260 \layout Standard
20261
20262
20263 \size footnotesize 
20264 \SpecialChar ~
20265 \SpecialChar ~
20266 inc r0
20267 \layout Standard
20268
20269
20270 \size footnotesize 
20271 \SpecialChar ~
20272 \SpecialChar ~
20273 mov ar3,@r0
20274 \layout Standard
20275
20276
20277 \size footnotesize 
20278 \SpecialChar ~
20279 \SpecialChar ~
20280 dec r0
20281 \layout Standard
20282
20283
20284 \size footnotesize 
20285 \SpecialChar ~
20286 \SpecialChar ~
20287 mov a,r2
20288 \layout Standard
20289
20290
20291 \size footnotesize 
20292 \SpecialChar ~
20293 \SpecialChar ~
20294 orl a,r3
20295 \layout Standard
20296
20297
20298 \size footnotesize 
20299 \SpecialChar ~
20300 \SpecialChar ~
20301 jz 00103$
20302 \layout Standard
20303
20304
20305 \size footnotesize 
20306 00114$:
20307 \layout Standard
20308
20309
20310 \size footnotesize 
20311 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
20312 \layout Standard
20313
20314
20315 \size footnotesize 
20316 \SpecialChar ~
20317 \SpecialChar ~
20318 mov dpl,_p
20319 \layout Standard
20320
20321
20322 \size footnotesize 
20323 \SpecialChar ~
20324 \SpecialChar ~
20325 mov dph,(_p + 1)
20326 \layout Standard
20327
20328
20329 \size footnotesize 
20330 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
20331 \layout Standard
20332
20333
20334 \size footnotesize 
20335 \SpecialChar ~
20336 \SpecialChar ~
20337 mov a,#0x02
20338 \layout Standard
20339
20340
20341 \size footnotesize 
20342 \SpecialChar ~
20343 \SpecialChar ~
20344 add a,_p
20345 \layout Standard
20346
20347
20348 \size footnotesize 
20349 \SpecialChar ~
20350 \SpecialChar ~
20351 mov _p,a
20352 \layout Standard
20353
20354
20355 \size footnotesize 
20356 \SpecialChar ~
20357 \SpecialChar ~
20358 clr a
20359 \layout Standard
20360
20361
20362 \size footnotesize 
20363 \SpecialChar ~
20364 \SpecialChar ~
20365 addc a,(_p + 1)
20366 \layout Standard
20367
20368
20369 \size footnotesize 
20370 \SpecialChar ~
20371 \SpecialChar ~
20372 mov (_p + 1),a
20373 \layout Standard
20374
20375
20376 \size footnotesize 
20377 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
20378 \layout Standard
20379
20380
20381 \size footnotesize 
20382 \SpecialChar ~
20383 \SpecialChar ~
20384 movx a,@dptr
20385 \layout Standard
20386
20387
20388 \size footnotesize 
20389 \SpecialChar ~
20390 \SpecialChar ~
20391 mov r2,a
20392 \layout Standard
20393
20394
20395 \size footnotesize 
20396 \SpecialChar ~
20397 \SpecialChar ~
20398 inc dptr
20399 \layout Standard
20400
20401
20402 \size footnotesize 
20403 \SpecialChar ~
20404 \SpecialChar ~
20405 movx a,@dptr
20406 \layout Standard
20407
20408
20409 \size footnotesize 
20410 \SpecialChar ~
20411 \SpecialChar ~
20412 mov r3,a
20413 \layout Standard
20414
20415
20416 \size footnotesize 
20417 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
20418 \layout Standard
20419
20420
20421 \size footnotesize 
20422 \SpecialChar ~
20423 \SpecialChar ~
20424 mov @r0,ar2
20425 \layout Standard
20426
20427
20428 \size footnotesize 
20429 \SpecialChar ~
20430 \SpecialChar ~
20431 inc r0
20432 \layout Standard
20433
20434
20435 \size footnotesize 
20436 \SpecialChar ~
20437 \SpecialChar ~
20438 mov @r0,ar3
20439 \layout Standard
20440
20441
20442 \size footnotesize 
20443 ; iTemp6 [lr5:16]{_near * int}[r0] = 
20444 \layout Standard
20445
20446
20447 \size footnotesize 
20448 ; iTemp6 [lr5:16]{_near * int}[r0] + 
20449 \layout Standard
20450
20451
20452 \size footnotesize 
20453 ; 0x2 {short}
20454 \layout Standard
20455
20456
20457 \size footnotesize 
20458 \SpecialChar ~
20459 \SpecialChar ~
20460 inc r0
20461 \layout Standard
20462
20463
20464 \size footnotesize 
20465 ; goto _whilecontinue_0($1)
20466 \layout Standard
20467
20468
20469 \size footnotesize 
20470 \SpecialChar ~
20471 \SpecialChar ~
20472 sjmp 00101$
20473 \layout Standard
20474
20475
20476 \size footnotesize 
20477 ; _whilebreak_0($3) :
20478 \layout Standard
20479
20480
20481 \size footnotesize 
20482 00103$:
20483 \layout Standard
20484
20485
20486 \size footnotesize 
20487 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
20488 \layout Standard
20489
20490
20491 \size footnotesize 
20492 \SpecialChar ~
20493 \SpecialChar ~
20494 mov r2,#0x00
20495 \layout Standard
20496
20497
20498 \size footnotesize 
20499 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
20500 \layout Standard
20501
20502
20503 \size footnotesize 
20504 \SpecialChar ~
20505 \SpecialChar ~
20506 mov r3,#0x00
20507 \layout Standard
20508
20509
20510 \size footnotesize 
20511 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
20512 \layout Standard
20513
20514
20515 \size footnotesize 
20516 \SpecialChar ~
20517 \SpecialChar ~
20518 mov r4,#0x00
20519 \layout Standard
20520
20521
20522 \size footnotesize 
20523 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
20524 \layout Standard
20525
20526
20527 \size footnotesize 
20528 \SpecialChar ~
20529 \SpecialChar ~
20530 mov r5,#0x0A
20531 \layout Standard
20532
20533
20534 \size footnotesize 
20535 \SpecialChar ~
20536 \SpecialChar ~
20537 mov r6,#0x00
20538 \layout Standard
20539
20540
20541 \size footnotesize 
20542 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
20543 \layout Standard
20544
20545
20546 \size footnotesize 
20547 \SpecialChar ~
20548 \SpecialChar ~
20549 mov r7,#0x1E
20550 \layout Standard
20551
20552
20553 \size footnotesize 
20554 \SpecialChar ~
20555 \SpecialChar ~
20556 mov r0,#0x00
20557 \layout Standard
20558
20559
20560 \size footnotesize 
20561 ; _forcond_0($4) :
20562 \layout Standard
20563
20564
20565 \size footnotesize 
20566 00104$:
20567 \layout Standard
20568
20569
20570 \size footnotesize 
20571 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
20572 \layout Standard
20573
20574
20575 \size footnotesize 
20576 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
20577 \layout Standard
20578
20579
20580 \size footnotesize 
20581 \SpecialChar ~
20582 \SpecialChar ~
20583 clr c
20584 \layout Standard
20585
20586
20587 \size footnotesize 
20588 \SpecialChar ~
20589 \SpecialChar ~
20590 mov a,r4
20591 \layout Standard
20592
20593
20594 \size footnotesize 
20595 \SpecialChar ~
20596 \SpecialChar ~
20597 xrl a,#0x80
20598 \layout Standard
20599
20600
20601 \size footnotesize 
20602 \SpecialChar ~
20603 \SpecialChar ~
20604 subb a,#0x8a
20605 \layout Standard
20606
20607
20608 \size footnotesize 
20609 \SpecialChar ~
20610 \SpecialChar ~
20611 jnc 00107$
20612 \layout Standard
20613
20614
20615 \size footnotesize 
20616 00115$:
20617 \layout Standard
20618
20619
20620 \size footnotesize 
20621 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
20622 \layout Standard
20623
20624
20625 \size footnotesize 
20626 ; iTemp21 [lr21:38]{short}[r4]
20627 \layout Standard
20628
20629
20630 \size footnotesize 
20631 \SpecialChar ~
20632 \SpecialChar ~
20633 mov a,r4
20634 \layout Standard
20635
20636
20637 \size footnotesize 
20638 \SpecialChar ~
20639 \SpecialChar ~
20640 add a,r2
20641 \layout Standard
20642
20643
20644 \size footnotesize 
20645 \SpecialChar ~
20646 \SpecialChar ~
20647 mov r2,a
20648 \layout Standard
20649
20650
20651 \size footnotesize 
20652 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
20653 \layout Standard
20654
20655
20656 \size footnotesize 
20657 \SpecialChar ~
20658 \SpecialChar ~
20659 mov b,#0x03
20660 \layout Standard
20661
20662
20663 \size footnotesize 
20664 \SpecialChar ~
20665 \SpecialChar ~
20666 mov a,r4
20667 \layout Standard
20668
20669
20670 \size footnotesize 
20671 \SpecialChar ~
20672 \SpecialChar ~
20673 mul ab
20674 \layout Standard
20675
20676
20677 \size footnotesize 
20678 \SpecialChar ~
20679 \SpecialChar ~
20680 mov r1,a
20681 \layout Standard
20682
20683
20684 \size footnotesize 
20685 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
20686 \layout Standard
20687
20688
20689 \size footnotesize 
20690 ; iTemp15 [lr29:30]{short}[r1]
20691 \layout Standard
20692
20693
20694 \size footnotesize 
20695 \SpecialChar ~
20696 \SpecialChar ~
20697 add a,r3
20698 \layout Standard
20699
20700
20701 \size footnotesize 
20702 \SpecialChar ~
20703 \SpecialChar ~
20704 mov r3,a
20705 \layout Standard
20706
20707
20708 \size footnotesize 
20709 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
20710 \layout Standard
20711
20712
20713 \size footnotesize 
20714 \SpecialChar ~
20715 \SpecialChar ~
20716 mov a,r7
20717 \layout Standard
20718
20719
20720 \size footnotesize 
20721 \SpecialChar ~
20722 \SpecialChar ~
20723 add a,#0xfd
20724 \layout Standard
20725
20726
20727 \size footnotesize 
20728 \SpecialChar ~
20729 \SpecialChar ~
20730 mov r7,a
20731 \layout Standard
20732
20733
20734 \size footnotesize 
20735 \SpecialChar ~
20736 \SpecialChar ~
20737 mov a,r0
20738 \layout Standard
20739
20740
20741 \size footnotesize 
20742 \SpecialChar ~
20743 \SpecialChar ~
20744 addc a,#0xff
20745 \layout Standard
20746
20747
20748 \size footnotesize 
20749 \SpecialChar ~
20750 \SpecialChar ~
20751 mov r0,a
20752 \layout Standard
20753
20754
20755 \size footnotesize 
20756 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
20757 \layout Standard
20758
20759
20760 \size footnotesize 
20761 \SpecialChar ~
20762 \SpecialChar ~
20763 mov a,r7
20764 \layout Standard
20765
20766
20767 \size footnotesize 
20768 \SpecialChar ~
20769 \SpecialChar ~
20770 add a,_gint
20771 \layout Standard
20772
20773
20774 \size footnotesize 
20775 \SpecialChar ~
20776 \SpecialChar ~
20777 mov _gint,a
20778 \layout Standard
20779
20780
20781 \size footnotesize 
20782 \SpecialChar ~
20783 \SpecialChar ~
20784 mov a,r0
20785 \layout Standard
20786
20787
20788 \size footnotesize 
20789 \SpecialChar ~
20790 \SpecialChar ~
20791 addc a,(_gint + 1)
20792 \layout Standard
20793
20794
20795 \size footnotesize 
20796 \SpecialChar ~
20797 \SpecialChar ~
20798 mov (_gint + 1),a
20799 \layout Standard
20800
20801
20802 \size footnotesize 
20803 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
20804 \layout Standard
20805
20806
20807 \size footnotesize 
20808 \SpecialChar ~
20809 \SpecialChar ~
20810 inc r4
20811 \layout Standard
20812
20813
20814 \size footnotesize 
20815 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
20816 \layout Standard
20817
20818
20819 \size footnotesize 
20820 \SpecialChar ~
20821 \SpecialChar ~
20822 dec r5
20823 \layout Standard
20824
20825
20826 \size footnotesize 
20827 \SpecialChar ~
20828 \SpecialChar ~
20829 cjne r5,#0xff,00104$
20830 \layout Standard
20831
20832
20833 \size footnotesize 
20834 \SpecialChar ~
20835 \SpecialChar ~
20836 dec r6
20837 \layout Standard
20838
20839
20840 \size footnotesize 
20841 ; goto _forcond_0($4)
20842 \layout Standard
20843
20844
20845 \size footnotesize 
20846 \SpecialChar ~
20847 \SpecialChar ~
20848 sjmp 00104$
20849 \layout Standard
20850
20851
20852 \size footnotesize 
20853 ; _forbreak_0($7) :
20854 \layout Standard
20855
20856
20857 \size footnotesize 
20858 00107$:
20859 \layout Standard
20860
20861
20862 \size footnotesize 
20863 ; ret iTemp24 [lr40:41]{short}
20864 \layout Standard
20865
20866
20867 \size footnotesize 
20868 \SpecialChar ~
20869 \SpecialChar ~
20870 mov a,r3
20871 \layout Standard
20872
20873
20874 \size footnotesize 
20875 \SpecialChar ~
20876 \SpecialChar ~
20877 add a,r2
20878 \layout Standard
20879
20880
20881 \size footnotesize 
20882 \SpecialChar ~
20883 \SpecialChar ~
20884 mov dpl,a
20885 \layout Standard
20886
20887
20888 \size footnotesize 
20889 ; _return($8) :
20890 \layout Standard
20891
20892
20893 \size footnotesize 
20894 00108$:
20895 \layout Standard
20896
20897
20898 \size footnotesize 
20899 \SpecialChar ~
20900 \SpecialChar ~
20901 ret
20902 \newline 
20903
20904 \layout Section
20905
20906 A few words about basic block successors, predecessors and dominators
20907 \layout Standard
20908
20909 Successors are basic blocks
20910 \begin_inset LatexCommand \index{Basic blocks}
20911
20912 \end_inset 
20913
20914  that might execute after this basic block.
20915 \newline 
20916 Predecessors are basic blocks that might execute before reaching this basic
20917  block.
20918 \newline 
20919 Dominators are basic blocks that WILL execute before reaching this basic
20920  block.
20921 \newline 
20922
20923 \layout Standard
20924
20925 [basic block 1]
20926 \layout Standard
20927
20928 if (something)
20929 \layout Standard
20930
20931 \SpecialChar ~
20932 \SpecialChar ~
20933 \SpecialChar ~
20934 \SpecialChar ~
20935 [basic block 2]
20936 \layout Standard
20937
20938 else
20939 \layout Standard
20940
20941 \SpecialChar ~
20942 \SpecialChar ~
20943 \SpecialChar ~
20944 \SpecialChar ~
20945 [basic block 3]
20946 \layout Standard
20947
20948 [basic block 4]
20949 \newline 
20950
20951 \layout Standard
20952
20953 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
20954 \layout Standard
20955
20956 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
20957 \layout Standard
20958
20959 c) domVect of [BB4] = BB1 ...
20960  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
20961  was executed.
20962 \layout Chapter
20963
20964 Acknowledgments
20965 \layout Standard
20966
20967
20968 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
20969
20970 \end_inset 
20971
20972
20973 \newline 
20974
20975 \newline 
20976
20977 \emph on 
20978 Thanks to all the other volunteer developers who have helped with coding,
20979  testing, web-page creation, distribution sets, etc.
20980  You know who you are :-)
20981 \emph default 
20982
20983 \newline 
20984
20985 \layout Standard
20986
20987 This document was initially written by Sandeep Dutta
20988 \layout Standard
20989
20990 All product names mentioned herein may be trademarks
20991 \begin_inset LatexCommand \index{Trademarks}
20992
20993 \end_inset 
20994
20995  of their respective companies.
20996  
20997 \layout Section*
20998
20999 Alphabetical index
21000 \layout Standard
21001
21002 To avoid confusion, the installation and building options for SDCC itself
21003  (chapter 2) are not part of the index.
21004 \layout Standard
21005
21006
21007 \begin_inset LatexCommand \printindex{}
21008
21009 \end_inset 
21010
21011
21012 \the_end