* sim/ucsim/configure.in,
[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.4.0
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">
1722 <column alignment="center" valignment="top" leftline="true" width="0">
1723 <column alignment="center" valignment="top" leftline="true" width="0">
1724 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
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, PIC14, PIC16 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 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{<file>.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{<file>.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{<file>.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 List
5892 \labelwidthstring 00.00.0000
5893
5894
5895 \series bold 
5896 -
5897 \begin_inset ERT
5898 status Collapsed
5899
5900 \layout Standard
5901
5902 \backslash 
5903 /
5904 \end_inset 
5905
5906 -stack-size
5907 \series default 
5908 \SpecialChar ~
5909 <Value>
5910 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
5911
5912 \end_inset 
5913
5914  Causes the linker to check if there is at minimum <Value> bytes for stack.
5915 \layout List
5916 \labelwidthstring 00.00.0000
5917
5918
5919 \series bold 
5920 -
5921 \begin_inset ERT
5922 status Collapsed
5923
5924 \layout Standard
5925
5926 \backslash 
5927 /
5928 \end_inset 
5929
5930 -pack-iram
5931 \series default 
5932 \SpecialChar ~
5933
5934 \begin_inset LatexCommand \index{-\/-pack-iram}
5935
5936 \end_inset 
5937
5938  Causes the linker use unused register banks for data variables or stack.
5939 \layout Subsection
5940
5941 DS390 / DS400 Options
5942 \begin_inset LatexCommand \index{Options DS390}
5943
5944 \end_inset 
5945
5946
5947 \begin_inset LatexCommand \index{DS390 options}
5948
5949 \end_inset 
5950
5951
5952 \layout List
5953 \labelwidthstring 00.00.0000
5954
5955
5956 \series bold 
5957 -
5958 \begin_inset ERT
5959 status Collapsed
5960
5961 \layout Standard
5962
5963 \backslash 
5964 /
5965 \end_inset 
5966
5967 -model-flat24
5968 \series default 
5969
5970 \begin_inset LatexCommand \index{-\/-model-flat24}
5971
5972 \end_inset 
5973
5974
5975 \size large 
5976 \emph on 
5977  
5978 \size default 
5979 \emph default 
5980 Generate 24-bit flat mode code.
5981  This is the one and only that the ds390 code generator supports right now
5982  and is default when using 
5983 \emph on 
5984 -mds390
5985 \emph default 
5986 .
5987  See section Memory Models for more details.
5988 \layout List
5989 \labelwidthstring 00.00.0000
5990
5991
5992 \series bold 
5993 -
5994 \begin_inset ERT
5995 status Collapsed
5996
5997 \layout Standard
5998
5999 \backslash 
6000 /
6001 \end_inset 
6002
6003 -protect-sp-update
6004 \begin_inset LatexCommand \index{-\/-protect-sp-update}
6005
6006 \end_inset 
6007
6008
6009 \series default 
6010  disable interrupts during ESP:SP updates.
6011 \layout List
6012 \labelwidthstring 00.00.0000
6013
6014
6015 \series bold 
6016 -
6017 \begin_inset ERT
6018 status Collapsed
6019
6020 \layout Standard
6021
6022 \backslash 
6023 /
6024 \end_inset 
6025
6026 -stack-10bit
6027 \series default 
6028
6029 \begin_inset LatexCommand \index{-\/-stack-10bit}
6030
6031 \end_inset 
6032
6033  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
6034  This is the one and only that the ds390 code generator supports right now
6035  and is default when using 
6036 \emph on 
6037 -mds390
6038 \emph default 
6039 .
6040  In this mode, the stack is located in the lower 1K of the internal RAM,
6041  which is mapped to 0x400000.
6042  Note that the support is incomplete, since it still uses a single byte
6043  as the stack pointer.
6044  This means that only the lower 256 bytes of the potential 1K stack space
6045  will actually be used.
6046  However, this does allow you to reclaim the precious 256 bytes of low RAM
6047  for use for the DATA and IDATA segments.
6048  The compiler will not generate any code to put the processor into 10 bit
6049  stack mode.
6050  It is important to ensure that the processor is in this mode before calling
6051  any re-entrant functions compiled with this option.
6052  In principle, this should work with the 
6053 \emph on 
6054 -
6055 \begin_inset ERT
6056 status Collapsed
6057
6058 \layout Standard
6059
6060 \backslash 
6061 /
6062 \end_inset 
6063
6064 -stack-auto
6065 \begin_inset LatexCommand \index{-\/-stack-auto}
6066
6067 \end_inset 
6068
6069
6070 \emph default 
6071  option, but that has not been tested.
6072  It is incompatible with the 
6073 \emph on 
6074 -
6075 \begin_inset ERT
6076 status Collapsed
6077
6078 \layout Standard
6079
6080 \backslash 
6081 /
6082 \end_inset 
6083
6084 -xstack
6085 \begin_inset LatexCommand \index{-\/-xstack}
6086
6087 \end_inset 
6088
6089
6090 \emph default 
6091  option.
6092  It also only makes sense if the processor is in 24 bit contiguous addressing
6093  mode (see the 
6094 \emph on 
6095 -
6096 \begin_inset ERT
6097 status Collapsed
6098
6099 \layout Standard
6100
6101 \backslash 
6102 /
6103 \end_inset 
6104
6105 -model-flat24 option
6106 \emph default 
6107 ).
6108 \layout List
6109 \labelwidthstring 00.00.0000
6110
6111
6112 \series bold 
6113 -
6114 \begin_inset ERT
6115 status Collapsed
6116
6117 \layout Standard
6118
6119 \backslash 
6120 /
6121 \end_inset 
6122
6123 -stack-probe
6124 \begin_inset LatexCommand \index{-\/-stack-probe}
6125
6126 \end_inset 
6127
6128
6129 \series default 
6130  insert call to function __stack_probe at each function prologue.
6131 \layout List
6132 \labelwidthstring 00.00.0000
6133
6134
6135 \series bold 
6136 -
6137 \begin_inset ERT
6138 status Collapsed
6139
6140 \layout Standard
6141
6142 \backslash 
6143 /
6144 \end_inset 
6145
6146 -tini-libid
6147 \begin_inset LatexCommand \index{-\/-tini-libid}
6148
6149 \end_inset 
6150
6151
6152 \series default 
6153  <nnnn> LibraryID used in -mTININative.
6154  
6155 \layout List
6156 \labelwidthstring 00.00.0000
6157
6158
6159 \series bold 
6160 -
6161 \begin_inset ERT
6162 status Collapsed
6163
6164 \layout Standard
6165
6166 \backslash 
6167 /
6168 \end_inset 
6169
6170 -use-accelerator
6171 \begin_inset LatexCommand \index{-\/-use-accelerator}
6172
6173 \end_inset 
6174
6175
6176 \series default 
6177  generate code for DS390 Arithmetic Accelerator.
6178  
6179 \layout Subsection
6180
6181 Z80 Options
6182 \begin_inset LatexCommand \index{Options Z80}
6183
6184 \end_inset 
6185
6186
6187 \begin_inset LatexCommand \index{Z80 options}
6188
6189 \end_inset 
6190
6191
6192 \layout List
6193 \labelwidthstring 00.00.0000
6194
6195
6196 \series bold 
6197 -
6198 \begin_inset ERT
6199 status Collapsed
6200
6201 \layout Standard
6202
6203 \backslash 
6204 /
6205 \end_inset 
6206
6207 -callee-saves-bc
6208 \series default 
6209
6210 \begin_inset LatexCommand \index{-\/-callee-saves-bc}
6211
6212 \end_inset 
6213
6214
6215 \size large 
6216 \emph on 
6217  
6218 \size default 
6219 \emph default 
6220 Force a called function to always save BC.
6221 \layout List
6222 \labelwidthstring 00.00.0000
6223
6224
6225 \series bold 
6226 -
6227 \begin_inset ERT
6228 status Collapsed
6229
6230 \layout Standard
6231
6232 \backslash 
6233 /
6234 \end_inset 
6235
6236 -no-std-crt0
6237 \series default 
6238
6239 \begin_inset LatexCommand \index{-\/-no-std-crt0}
6240
6241 \end_inset 
6242
6243  When linking, skip the standard crt0.o object file.
6244  You must provide your own crt0.o for your system when linking.
6245  
6246 \layout Subsection
6247
6248 Optimization Options
6249 \begin_inset LatexCommand \index{Options optimization}
6250
6251 \end_inset 
6252
6253
6254 \begin_inset LatexCommand \index{Optimization options}
6255
6256 \end_inset 
6257
6258
6259 \layout List
6260 \labelwidthstring 00.00.0000
6261
6262
6263 \series bold 
6264 -
6265 \begin_inset ERT
6266 status Collapsed
6267
6268 \layout Standard
6269
6270 \backslash 
6271 /
6272 \end_inset 
6273
6274 -nogcse
6275 \begin_inset LatexCommand \index{-\/-nogcse}
6276
6277 \end_inset 
6278
6279
6280 \series default 
6281  Will not do global subexpression elimination, this option may be used when
6282  the compiler creates undesirably large stack/data spaces to store compiler
6283  temporaries.
6284  A warning message will be generated when this happens and the compiler
6285  will indicate the number of extra bytes it allocated.
6286  It is recommended that this option NOT be used, #pragma\SpecialChar ~
6287 nogcse
6288 \begin_inset LatexCommand \index{\#pragma nogcse}
6289
6290 \end_inset 
6291
6292  can be used to turn off global subexpression elimination
6293 \begin_inset LatexCommand \index{Subexpression elimination}
6294
6295 \end_inset 
6296
6297  for a given function only.
6298 \layout List
6299 \labelwidthstring 00.00.0000
6300
6301
6302 \series bold 
6303 -
6304 \begin_inset ERT
6305 status Collapsed
6306
6307 \layout Standard
6308
6309 \backslash 
6310 /
6311 \end_inset 
6312
6313 -noinvariant
6314 \begin_inset LatexCommand \index{-\/-noinvariant}
6315
6316 \end_inset 
6317
6318
6319 \series default 
6320  Will not do loop invariant optimizations, this may be turned off for reasons
6321  explained for the previous option.
6322  For more details of loop optimizations performed see section Loop Invariants.
6323  It is recommended that this option NOT be used, #pragma\SpecialChar ~
6324 noinvariant
6325 \begin_inset LatexCommand \index{\#pragma noinvariant}
6326
6327 \end_inset 
6328
6329  can be used to turn off invariant optimizations for a given function only.
6330 \layout List
6331 \labelwidthstring 00.00.0000
6332
6333
6334 \series bold 
6335 -
6336 \begin_inset ERT
6337 status Collapsed
6338
6339 \layout Standard
6340
6341 \backslash 
6342 /
6343 \end_inset 
6344
6345 -noinduction
6346 \begin_inset LatexCommand \index{-\/-noinduction}
6347
6348 \end_inset 
6349
6350
6351 \series default 
6352  Will not do loop induction optimizations, see section strength reduction
6353  for more details.
6354  It is recommended that this option is NOT used, #pragma\SpecialChar ~
6355 noinduction
6356 \begin_inset LatexCommand \index{\#pragma noinduction}
6357
6358 \end_inset 
6359
6360  can be used to turn off induction optimizations for a given function only.
6361 \layout List
6362 \labelwidthstring 00.00.0000
6363
6364
6365 \series bold 
6366 -
6367 \begin_inset ERT
6368 status Collapsed
6369
6370 \layout Standard
6371
6372 \backslash 
6373 /
6374 \end_inset 
6375
6376 -nojtbound
6377 \begin_inset LatexCommand \index{-\/-nojtbound}
6378
6379 \end_inset 
6380
6381
6382 \size large 
6383 \bar under 
6384  
6385 \series default 
6386 \size default 
6387 \bar default 
6388  Will not generate boundary condition check when switch statements
6389 \begin_inset LatexCommand \index{switch statement}
6390
6391 \end_inset 
6392
6393  are implemented using jump-tables.
6394  See section 
6395 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
6396
6397 \end_inset 
6398
6399 \SpecialChar ~
6400 Switch Statements for more details.
6401  It is recommended that this option is NOT used, #pragma\SpecialChar ~
6402 nojtbound
6403 \begin_inset LatexCommand \index{\#pragma nojtbound}
6404
6405 \end_inset 
6406
6407  can be used to turn off boundary checking for jump tables for a given function
6408  only.
6409 \layout List
6410 \labelwidthstring 00.00.0000
6411
6412
6413 \series bold 
6414 -
6415 \begin_inset ERT
6416 status Collapsed
6417
6418 \layout Standard
6419
6420 \backslash 
6421 /
6422 \end_inset 
6423
6424 -noloopreverse
6425 \begin_inset LatexCommand \index{-\/-noloopreverse}
6426
6427 \end_inset 
6428
6429
6430 \series default 
6431 \size large 
6432  
6433 \size default 
6434 Will not do loop reversal 
6435 \begin_inset LatexCommand \index{Loop reversing}
6436
6437 \end_inset 
6438
6439 optimization.
6440 \layout List
6441 \labelwidthstring 00.00.0000
6442
6443 -
6444 \begin_inset ERT
6445 status Collapsed
6446
6447 \layout Standard
6448
6449 \backslash 
6450 /
6451 \end_inset 
6452
6453 -
6454 \series bold 
6455 nolabelopt
6456 \series default 
6457  
6458 \begin_inset LatexCommand \index{-\/-nolabelopt }
6459
6460 \end_inset 
6461
6462 Will not optimize labels (makes the dumpfiles more readable).
6463 \layout List
6464 \labelwidthstring 00.00.0000
6465
6466
6467 \series bold 
6468 -
6469 \begin_inset ERT
6470 status Collapsed
6471
6472 \layout Standard
6473
6474 \backslash 
6475 /
6476 \end_inset 
6477
6478 -no-xinit-opt
6479 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
6480
6481 \end_inset 
6482
6483
6484 \series default 
6485  Will not memcpy initialized data from code space into xdata space.
6486  This saves a few bytes in code space if you don't have initialized data.
6487 \layout List
6488 \labelwidthstring 00.00.0000
6489
6490
6491 \series bold 
6492 -
6493 \begin_inset ERT
6494 status Collapsed
6495
6496 \layout Standard
6497
6498 \backslash 
6499 /
6500 \end_inset 
6501
6502 -nooverlay
6503 \begin_inset LatexCommand \index{-\/-nooverlay}
6504
6505 \end_inset 
6506
6507
6508 \series default 
6509   The compiler will not overlay parameters and local variables of any function,
6510  see section Parameters and local variables for more details.
6511 \layout List
6512 \labelwidthstring 00.00.0000
6513
6514
6515 \series bold 
6516 -
6517 \begin_inset ERT
6518 status Collapsed
6519
6520 \layout Standard
6521
6522 \backslash 
6523 /
6524 \end_inset 
6525
6526 -no-peep
6527 \begin_inset LatexCommand \index{-\/-no-peep}
6528
6529 \end_inset 
6530
6531
6532 \series default 
6533  Disable peep-hole optimization.
6534 \layout List
6535 \labelwidthstring 00.00.0000
6536
6537
6538 \series bold 
6539 -
6540 \begin_inset ERT
6541 status Collapsed
6542
6543 \layout Standard
6544
6545 \backslash 
6546 /
6547 \end_inset 
6548
6549 -peep-file
6550 \series default 
6551
6552 \begin_inset LatexCommand \index{-\/-peep-file}
6553
6554 \end_inset 
6555
6556 \SpecialChar ~
6557 <filename> This option can be used to use additional rules to be used by
6558  the peep hole optimizer.
6559  See section 
6560 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
6561
6562 \end_inset 
6563
6564 \SpecialChar ~
6565 Peep Hole optimizations for details on how to write these rules.
6566 \layout List
6567 \labelwidthstring 00.00.0000
6568
6569
6570 \series bold 
6571 -
6572 \begin_inset ERT
6573 status Collapsed
6574
6575 \layout Standard
6576
6577 \backslash 
6578 /
6579 \end_inset 
6580
6581 -peep-asm
6582 \begin_inset LatexCommand \index{-\/-peep-asm}
6583
6584 \end_inset 
6585
6586
6587 \series default 
6588   Pass the inline assembler code through the peep hole optimizer.
6589  This can cause unexpected changes to inline assembler code, please go through
6590  the peephole optimizer
6591 \begin_inset LatexCommand \index{Peephole optimizer}
6592
6593 \end_inset 
6594
6595  rules defined in the source file tree '<target>/peeph.def' before using
6596  this option.
6597 \layout Subsection
6598
6599 Other Options
6600 \begin_inset LatexCommand \index{Options other}
6601
6602 \end_inset 
6603
6604
6605 \layout List
6606 \labelwidthstring 00.00.0000
6607
6608
6609 \series bold 
6610 -c\SpecialChar ~
6611 -
6612 \begin_inset ERT
6613 status Collapsed
6614
6615 \layout Standard
6616
6617 \backslash 
6618 /
6619 \end_inset 
6620
6621 -compile-only
6622 \begin_inset LatexCommand \index{-\/-compile-only}
6623
6624 \end_inset 
6625
6626
6627 \begin_inset LatexCommand \index{-c -\/-compile-only}
6628
6629 \end_inset 
6630
6631
6632 \series default 
6633  will compile and assemble the source, but will not call the linkage editor.
6634 \layout List
6635 \labelwidthstring 00.00.0000
6636
6637
6638 \series bold 
6639 -
6640 \series default 
6641
6642 \begin_inset ERT
6643 status Collapsed
6644
6645 \layout Standard
6646
6647 \backslash 
6648 /
6649 \end_inset 
6650
6651
6652 \series bold 
6653 -c1mode
6654 \begin_inset LatexCommand \index{-\/-c1mode}
6655
6656 \end_inset 
6657
6658
6659 \series default 
6660  reads the preprocessed source from standard input and compiles it.
6661  The file name for the assembler output must be specified using the -o option.
6662 \layout List
6663 \labelwidthstring 00.00.0000
6664
6665
6666 \series bold 
6667 -E
6668 \begin_inset LatexCommand \index{-E}
6669
6670 \end_inset 
6671
6672
6673 \series default 
6674  Run only the C preprocessor.
6675  Preprocess all the C source files specified and output the results to standard
6676  output.
6677 \layout List
6678 \labelwidthstring 00.00.0000
6679
6680
6681 \series bold 
6682 -o\SpecialChar ~
6683 <path/file>
6684 \begin_inset LatexCommand \index{-o <path/file>}
6685
6686 \end_inset 
6687
6688  
6689 \series default 
6690 The output path resp.
6691  file where everything will be placed.
6692  If the parameter is a path, it must have a trailing slash (or backslash
6693  for the Windows binaries) to be recognized as a path.
6694  
6695 \layout List
6696 \labelwidthstring 00.00.0000
6697
6698
6699 \series bold 
6700 -
6701 \begin_inset ERT
6702 status Collapsed
6703
6704 \layout Standard
6705
6706 \backslash 
6707 /
6708 \end_inset 
6709
6710 -stack-auto
6711 \begin_inset LatexCommand \index{-\/-stack-auto}
6712
6713 \end_inset 
6714
6715
6716 \series default 
6717 \size large 
6718 \emph on 
6719  
6720 \size default 
6721 \emph default 
6722 All functions in the source file will be compiled as 
6723 \emph on 
6724 reentrant
6725 \emph default 
6726
6727 \begin_inset LatexCommand \index{reentrant}
6728
6729 \end_inset 
6730
6731 , i.e.
6732  the parameters and local variables will be allocated on the stack
6733 \begin_inset LatexCommand \index{stack}
6734
6735 \end_inset 
6736
6737 .
6738  see section Parameters and Local Variables for more details.
6739  If this option is used all source files in the project should be compiled
6740  with this option.
6741  
6742 \layout List
6743 \labelwidthstring 00.00.0000
6744
6745
6746 \series bold 
6747 -
6748 \begin_inset ERT
6749 status Collapsed
6750
6751 \layout Standard
6752
6753 \backslash 
6754 /
6755 \end_inset 
6756
6757 -callee-saves
6758 \begin_inset LatexCommand \index{-\/-callee-saves}
6759
6760 \end_inset 
6761
6762  function1[,function2][,function3]....
6763
6764 \series default 
6765  The compiler by default uses a caller saves convention for register saving
6766  across function calls, however this can cause unnecessary register pushing
6767  & popping when calling small functions from larger functions.
6768  This option can be used to switch the register saving convention for the
6769  function names specified.
6770  The compiler will not save registers when calling these functions, no extra
6771  code will be generated at the entry & exit (function prologue
6772 \series bold 
6773
6774 \begin_inset LatexCommand \index{function prologue}
6775
6776 \end_inset 
6777
6778
6779 \series default 
6780  & epilogue
6781 \series bold 
6782
6783 \begin_inset LatexCommand \index{function epilogue}
6784
6785 \end_inset 
6786
6787
6788 \series default 
6789 ) for these functions to save & restore the registers used by these functions,
6790  this can SUBSTANTIALLY reduce code & improve run time performance of the
6791  generated code.
6792  In the future the compiler (with inter procedural analysis) will be able
6793  to determine the appropriate scheme to use for each function call.
6794  DO NOT use this option for built-in functions such as _mulint..., if this
6795  option is used for a library function the appropriate library function
6796  needs to be recompiled with the same option.
6797  If the project consists of multiple source files then all the source file
6798  should be compiled with the same -
6799 \begin_inset ERT
6800 status Collapsed
6801
6802 \layout Standard
6803
6804 \backslash 
6805 /
6806 \end_inset 
6807
6808 -callee-saves option string.
6809  Also see #pragma\SpecialChar ~
6810 callee_saves
6811 \begin_inset LatexCommand \index{\#pragma callee\_saves}
6812
6813 \end_inset 
6814
6815 .
6816 \layout List
6817 \labelwidthstring 00.00.0000
6818
6819
6820 \series bold 
6821 -
6822 \begin_inset ERT
6823 status Collapsed
6824
6825 \layout Standard
6826
6827 \backslash 
6828 /
6829 \end_inset 
6830
6831 -debug
6832 \begin_inset LatexCommand \index{-\/-debug}
6833
6834 \end_inset 
6835
6836
6837 \bar under 
6838  
6839 \series default 
6840 \bar default 
6841 When this option is used the compiler will generate debug information.
6842  The debug information collected in a file with .cdb extension can be used
6843  with the SDCDB.
6844  For more information see documentation for SDCDB.
6845  Another file with no extension contains debug information in AOMF or AOMF51
6846 \begin_inset LatexCommand \index{AOMF, AOMF51}
6847
6848 \end_inset 
6849
6850  format which is commonly used by third party tools.
6851 \layout List
6852 \labelwidthstring 00.00.0000
6853
6854
6855 \series bold 
6856 -S
6857 \begin_inset LatexCommand \index{-S}
6858
6859 \end_inset 
6860
6861
6862 \size large 
6863 \bar under 
6864  
6865 \series default 
6866 \size default 
6867 \bar default 
6868 Stop after the stage of compilation proper; do not assemble.
6869  The output is an assembler code file for the input file specified.
6870 \layout List
6871 \labelwidthstring 00.00.0000
6872
6873
6874 \series bold 
6875 -
6876 \begin_inset ERT
6877 status Collapsed
6878
6879 \layout Standard
6880
6881 \backslash 
6882 /
6883 \end_inset 
6884
6885 -int-long-reent
6886 \begin_inset LatexCommand \index{-\/-int-long-reent}
6887
6888 \end_inset 
6889
6890
6891 \series default 
6892  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
6893  Note by default these libraries are compiled as non-reentrant.
6894  See section Installation for more details.
6895 \layout List
6896 \labelwidthstring 00.00.0000
6897
6898
6899 \series bold 
6900 -
6901 \begin_inset ERT
6902 status Collapsed
6903
6904 \layout Standard
6905
6906 \backslash 
6907 /
6908 \end_inset 
6909
6910 -cyclomatic
6911 \begin_inset LatexCommand \index{-\/-cyclomatic}
6912
6913 \end_inset 
6914
6915
6916 \bar under 
6917  
6918 \series default 
6919 \bar default 
6920 This option will cause the compiler to generate an information message for
6921  each function in the source file.
6922  The message contains some 
6923 \emph on 
6924 important
6925 \emph default 
6926  information about the function.
6927  The number of edges and nodes the compiler detected in the control flow
6928  graph of the function, and most importantly the 
6929 \emph on 
6930 cyclomatic complexity
6931 \begin_inset LatexCommand \index{Cyclomatic complexity}
6932
6933 \end_inset 
6934
6935
6936 \emph default 
6937  see section on Cyclomatic Complexity for more details.
6938 \layout List
6939 \labelwidthstring 00.00.0000
6940
6941
6942 \series bold 
6943 -
6944 \begin_inset ERT
6945 status Collapsed
6946
6947 \layout Standard
6948
6949 \backslash 
6950 /
6951 \end_inset 
6952
6953 -float-reent
6954 \begin_inset LatexCommand \index{-\/-float-reent}
6955
6956 \end_inset 
6957
6958
6959 \series default 
6960  Floating point library is compiled as reentrant
6961 \begin_inset LatexCommand \index{reentrant}
6962
6963 \end_inset 
6964
6965 .
6966  See section Installation for more details.
6967 \layout List
6968 \labelwidthstring 00.00.0000
6969
6970
6971 \series bold 
6972 -
6973 \begin_inset ERT
6974 status Collapsed
6975
6976 \layout Standard
6977
6978 \backslash 
6979 /
6980 \end_inset 
6981
6982 -main-return
6983 \begin_inset LatexCommand \index{-\/-main-return}
6984
6985 \end_inset 
6986
6987
6988 \series default 
6989  This option can be used when the code generated is called by a monitor
6990  program.
6991  The compiler will generate a 'ret' upon return from the 'main'
6992 \begin_inset LatexCommand \index{main return}
6993
6994 \end_inset 
6995
6996  function.
6997  The default setting is to lock up i.e.
6998  generate a '
6999 \family typewriter 
7000 sjmp .
7001 \family default 
7002 '.
7003 \layout List
7004 \labelwidthstring 00.00.0000
7005
7006
7007 \series bold 
7008 -
7009 \begin_inset ERT
7010 status Collapsed
7011
7012 \layout Standard
7013
7014 \backslash 
7015 /
7016 \end_inset 
7017
7018 -nostdincl
7019 \begin_inset LatexCommand \index{-\/-nostdincl}
7020
7021 \end_inset 
7022
7023
7024 \series default 
7025  This will prevent the compiler from passing on the default include path
7026  to the preprocessor.
7027 \layout List
7028 \labelwidthstring 00.00.0000
7029
7030
7031 \series bold 
7032 -
7033 \begin_inset ERT
7034 status Collapsed
7035
7036 \layout Standard
7037
7038 \backslash 
7039 /
7040 \end_inset 
7041
7042 -nostdlib
7043 \begin_inset LatexCommand \index{-\/-nostdlib}
7044
7045 \end_inset 
7046
7047
7048 \series default 
7049  This will prevent the compiler from passing on the default library
7050 \begin_inset LatexCommand \index{Libraries}
7051
7052 \end_inset 
7053
7054  path to the linker.
7055 \layout List
7056 \labelwidthstring 00.00.0000
7057
7058
7059 \series bold 
7060 -
7061 \begin_inset ERT
7062 status Collapsed
7063
7064 \layout Standard
7065
7066 \backslash 
7067 /
7068 \end_inset 
7069
7070 -verbose
7071 \begin_inset LatexCommand \index{-\/-verbose}
7072
7073 \end_inset 
7074
7075
7076 \series default 
7077  Shows the various actions the compiler is performing.
7078 \layout List
7079 \labelwidthstring 00.00.0000
7080
7081
7082 \series bold 
7083 -V
7084 \begin_inset LatexCommand \index{-V}
7085
7086 \end_inset 
7087
7088
7089 \series default 
7090  Shows the actual commands the compiler is executing.
7091 \layout List
7092 \labelwidthstring 00.00.0000
7093
7094
7095 \series bold 
7096 -
7097 \begin_inset ERT
7098 status Collapsed
7099
7100 \layout Standard
7101
7102 \backslash 
7103 /
7104 \end_inset 
7105
7106 -no-c-code-in-asm
7107 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
7108
7109 \end_inset 
7110
7111
7112 \series default 
7113  Hides your ugly and inefficient c-code from the asm file, so you can always
7114  blame the compiler :).
7115 \layout List
7116 \labelwidthstring 00.00.0000
7117
7118
7119 \series bold 
7120 -
7121 \begin_inset ERT
7122 status Collapsed
7123
7124 \layout Standard
7125
7126 \backslash 
7127 /
7128 \end_inset 
7129
7130 -i-code-in-asm
7131 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
7132
7133 \end_inset 
7134
7135
7136 \series default 
7137  Include i-codes in the asm file.
7138  Sounds like noise but is most helpful for debugging the compiler itself.
7139 \layout List
7140 \labelwidthstring 00.00.0000
7141
7142
7143 \series bold 
7144 -
7145 \begin_inset ERT
7146 status Collapsed
7147
7148 \layout Standard
7149
7150 \backslash 
7151 /
7152 \end_inset 
7153
7154 -less-pedantic
7155 \begin_inset LatexCommand \index{-\/-less-pedantic}
7156
7157 \end_inset 
7158
7159
7160 \series default 
7161  Disable some of the more pedantic warnings
7162 \begin_inset LatexCommand \index{Warnings}
7163
7164 \end_inset 
7165
7166  (jwk burps: please be more specific here, please!).
7167  If you want rather more than less warnings you should consider using a
7168  separate tool dedicated to syntax checking like splint 
7169 \begin_inset LatexCommand \url{www.splint.org}
7170
7171 \end_inset 
7172
7173 .
7174 \layout List
7175 \labelwidthstring 00.00.0000
7176
7177
7178 \series bold 
7179 -
7180 \begin_inset ERT
7181 status Collapsed
7182
7183 \layout Standard
7184
7185 \backslash 
7186 /
7187 \end_inset 
7188
7189 -print-search-dirs
7190 \begin_inset LatexCommand \index{-\/-print-search-dirs}
7191
7192 \end_inset 
7193
7194
7195 \series default 
7196  Display the directories in the compiler's search path
7197 \layout List
7198 \labelwidthstring 00.00.0000
7199
7200
7201 \series bold 
7202 -
7203 \begin_inset ERT
7204 status Collapsed
7205
7206 \layout Standard
7207
7208 \backslash 
7209 /
7210 \end_inset 
7211
7212 -vc
7213 \begin_inset LatexCommand \index{-\/-vc}
7214
7215 \end_inset 
7216
7217
7218 \series default 
7219  Display errors and warnings using MSVC style, so you can use SDCC with
7220  visual studio.
7221 \layout List
7222 \labelwidthstring 00.00.0000
7223
7224
7225 \series bold 
7226 -
7227 \begin_inset ERT
7228 status Collapsed
7229
7230 \layout Standard
7231
7232 \backslash 
7233 /
7234 \end_inset 
7235
7236 -use-stdout
7237 \begin_inset LatexCommand \index{-\/-use-stdout}
7238
7239 \end_inset 
7240
7241
7242 \series default 
7243  Send errors and warnings to stdout instead of stderr.
7244 \layout List
7245 \labelwidthstring 00.00.0000
7246
7247
7248 \series bold 
7249 -Wa\SpecialChar ~
7250 asmOption[,asmOption]
7251 \series default 
7252
7253 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
7254
7255 \end_inset 
7256
7257 ...
7258  Pass the asmOption to the assembler
7259 \begin_inset LatexCommand \index{Options assembler}
7260
7261 \end_inset 
7262
7263
7264 \begin_inset LatexCommand \index{Assembler options}
7265
7266 \end_inset 
7267
7268 .
7269  See file sdcc/as/doc/asxhtm.html for assembler options.
7270 \layout Subsection
7271
7272 Intermediate Dump Options
7273 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
7274
7275 \end_inset 
7276
7277
7278 \begin_inset LatexCommand \index{Options intermediate dump}
7279
7280 \end_inset 
7281
7282
7283 \begin_inset LatexCommand \index{Intermediate dump options}
7284
7285 \end_inset 
7286
7287
7288 \layout Standard
7289
7290 The following options are provided for the purpose of retargetting and debugging
7291  the compiler.
7292  These provided a means to dump the intermediate code (iCode
7293 \begin_inset LatexCommand \index{iCode}
7294
7295 \end_inset 
7296
7297 ) generated by the compiler in human readable form at various stages of
7298  the compilation process.
7299  More on iCodes see chapter 
7300 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
7301
7302 \end_inset 
7303
7304  
7305 \begin_inset Quotes srd
7306 \end_inset 
7307
7308 The anatomy of the compiler
7309 \begin_inset Quotes srd
7310 \end_inset 
7311
7312 .
7313 \layout List
7314 \labelwidthstring 00.00.0000
7315
7316
7317 \series bold 
7318 -
7319 \begin_inset ERT
7320 status Collapsed
7321
7322 \layout Standard
7323
7324 \backslash 
7325 /
7326 \end_inset 
7327
7328 -dumpraw
7329 \begin_inset LatexCommand \index{-\/-dumpraw}
7330
7331 \end_inset 
7332
7333
7334 \series default 
7335  This option will cause the compiler to dump the intermediate code into
7336  a file of named 
7337 \emph on 
7338 <source filename>.dumpraw
7339 \emph default 
7340  just after the intermediate code has been generated for a function, i.e.
7341  before any optimizations are done.
7342  The basic blocks
7343 \begin_inset LatexCommand \index{Basic blocks}
7344
7345 \end_inset 
7346
7347  at this stage ordered in the depth first number, so they may not be in
7348  sequence of execution.
7349 \layout List
7350 \labelwidthstring 00.00.0000
7351
7352
7353 \series bold 
7354 -
7355 \begin_inset ERT
7356 status Collapsed
7357
7358 \layout Standard
7359
7360 \backslash 
7361 /
7362 \end_inset 
7363
7364 -dumpgcse
7365 \begin_inset LatexCommand \index{-\/-dumpgcse}
7366
7367 \end_inset 
7368
7369
7370 \series default 
7371  Will create a dump of iCode's, after global subexpression elimination
7372 \begin_inset LatexCommand \index{Global subexpression elimination}
7373
7374 \end_inset 
7375
7376 , into a file named 
7377 \emph on 
7378 <source filename>.dumpgcse.
7379 \layout List
7380 \labelwidthstring 00.00.0000
7381
7382
7383 \series bold 
7384 -
7385 \begin_inset ERT
7386 status Collapsed
7387
7388 \layout Standard
7389
7390 \backslash 
7391 /
7392 \end_inset 
7393
7394 -dumpdeadcode
7395 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
7396
7397 \end_inset 
7398
7399
7400 \series default 
7401  Will create a dump of iCode's, after deadcode elimination
7402 \begin_inset LatexCommand \index{Dead-code elimination}
7403
7404 \end_inset 
7405
7406 , into a file named 
7407 \emph on 
7408 <source filename>.dumpdeadcode.
7409 \layout List
7410 \labelwidthstring 00.00.0000
7411
7412
7413 \series bold 
7414 -
7415 \begin_inset ERT
7416 status Collapsed
7417
7418 \layout Standard
7419
7420 \backslash 
7421 /
7422 \end_inset 
7423
7424 -dumploop
7425 \begin_inset LatexCommand \index{-\/-dumploop}
7426
7427 \end_inset 
7428
7429
7430 \series default 
7431 \size large 
7432  
7433 \size default 
7434 Will create a dump of iCode's, after loop optimizations
7435 \begin_inset LatexCommand \index{Loop optimization}
7436
7437 \end_inset 
7438
7439 , into a file named 
7440 \emph on 
7441 <source filename>.dumploop.
7442 \layout List
7443 \labelwidthstring 00.00.0000
7444
7445
7446 \series bold 
7447 -
7448 \begin_inset ERT
7449 status Collapsed
7450
7451 \layout Standard
7452
7453 \backslash 
7454 /
7455 \end_inset 
7456
7457 -dumprange
7458 \begin_inset LatexCommand \index{-\/-dumprange}
7459
7460 \end_inset 
7461
7462
7463 \series default 
7464 \size large 
7465  
7466 \size default 
7467 Will create a dump of iCode's, after live range analysis
7468 \begin_inset LatexCommand \index{Live range analysis}
7469
7470 \end_inset 
7471
7472 , into a file named 
7473 \emph on 
7474 <source filename>.dumprange.
7475 \layout List
7476 \labelwidthstring 00.00.0000
7477
7478
7479 \series bold 
7480 -
7481 \begin_inset ERT
7482 status Collapsed
7483
7484 \layout Standard
7485
7486 \backslash 
7487 /
7488 \end_inset 
7489
7490 -dumlrange
7491 \begin_inset LatexCommand \index{-\/-dumlrange}
7492
7493 \end_inset 
7494
7495
7496 \series default 
7497  Will dump the life ranges
7498 \begin_inset LatexCommand \index{Live range analysis}
7499
7500 \end_inset 
7501
7502  for all symbols.
7503 \layout List
7504 \labelwidthstring 00.00.0000
7505
7506
7507 \series bold 
7508 -
7509 \begin_inset ERT
7510 status Collapsed
7511
7512 \layout Standard
7513
7514 \backslash 
7515 /
7516 \end_inset 
7517
7518 -dumpregassign
7519 \begin_inset LatexCommand \index{-\/-dumpregassign}
7520
7521 \end_inset 
7522
7523
7524 \bar under 
7525  
7526 \series default 
7527 \bar default 
7528 Will create a dump of iCode's, after register assignment
7529 \begin_inset LatexCommand \index{Register assignment}
7530
7531 \end_inset 
7532
7533 , into a file named 
7534 \emph on 
7535 <source filename>.dumprassgn.
7536 \layout List
7537 \labelwidthstring 00.00.0000
7538
7539
7540 \series bold 
7541 -
7542 \begin_inset ERT
7543 status Collapsed
7544
7545 \layout Standard
7546
7547 \backslash 
7548 /
7549 \end_inset 
7550
7551 -dumplrange
7552 \begin_inset LatexCommand \index{-\/-dumplrange}
7553
7554 \end_inset 
7555
7556
7557 \series default 
7558  Will create a dump of the live ranges of iTemp's
7559 \layout List
7560 \labelwidthstring 00.00.0000
7561
7562
7563 \series bold 
7564 -
7565 \begin_inset ERT
7566 status Collapsed
7567
7568 \layout Standard
7569
7570 \backslash 
7571 /
7572 \end_inset 
7573
7574 -dumpall
7575 \begin_inset LatexCommand \index{-\/-dumpall}
7576
7577 \end_inset 
7578
7579
7580 \size large 
7581 \bar under 
7582  
7583 \series default 
7584 \size default 
7585 \bar default 
7586 Will cause all the above mentioned dumps to be created.
7587 \layout Subsection
7588
7589 Redirecting output on Windows Shells
7590 \layout Standard
7591
7592 By default SDCC writes it's error messages to 
7593 \begin_inset Quotes sld
7594 \end_inset 
7595
7596 standard error
7597 \begin_inset Quotes srd
7598 \end_inset 
7599
7600 .
7601  To force all messages to 
7602 \begin_inset Quotes sld
7603 \end_inset 
7604
7605 standard output
7606 \begin_inset Quotes srd
7607 \end_inset 
7608
7609  use 
7610 \series bold 
7611 -
7612 \series default 
7613 \emph on 
7614
7615 \begin_inset ERT
7616 status Collapsed
7617
7618 \layout Standard
7619
7620 \backslash 
7621 /
7622 \end_inset 
7623
7624
7625 \series bold 
7626 \emph default 
7627 -
7628 \series default 
7629 use-stdout
7630 \begin_inset LatexCommand \index{-\/-use-stdout}
7631
7632 \end_inset 
7633
7634 .
7635  Additionally, if you happen to have visual studio installed in your windows
7636  machine, you can use it to compile your sources using a custom build and
7637  the SDCC -
7638 \emph on 
7639
7640 \begin_inset ERT
7641 status Collapsed
7642
7643 \layout Standard
7644
7645 \backslash 
7646 /
7647 \end_inset 
7648
7649
7650 \emph default 
7651 -vc
7652 \begin_inset LatexCommand \index{-\/-vc}
7653
7654 \end_inset 
7655
7656  option.
7657  Something like this should work:
7658 \newline 
7659
7660 \newline 
7661
7662 \series bold 
7663 c:
7664 \backslash 
7665 sdcc
7666 \backslash 
7667 bin
7668 \backslash 
7669 sdcc.exe -
7670 \series default 
7671 \emph on 
7672
7673 \begin_inset ERT
7674 status Collapsed
7675
7676 \layout Standard
7677
7678 \backslash 
7679 /
7680 \end_inset 
7681
7682
7683 \series bold 
7684 \emph default 
7685 -vc -
7686 \series default 
7687 \emph on 
7688
7689 \begin_inset ERT
7690 status Collapsed
7691
7692 \layout Standard
7693
7694 \backslash 
7695 /
7696 \end_inset 
7697
7698
7699 \series bold 
7700 \emph default 
7701 -model-large -c $(InputPath)
7702 \layout Section
7703
7704 Environment variables
7705 \begin_inset LatexCommand \index{Environment variables}
7706
7707 \end_inset 
7708
7709
7710 \layout Standard
7711
7712 SDCC recognizes the following environment variables:
7713 \layout List
7714 \labelwidthstring 00.00.0000
7715
7716
7717 \series bold 
7718 SDCC_LEAVE_SIGNALS
7719 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
7720
7721 \end_inset 
7722
7723
7724 \series default 
7725  SDCC installs a signal handler
7726 \begin_inset LatexCommand \index{signal handler}
7727
7728 \end_inset 
7729
7730  to be able to delete temporary files after an user break (^C) or an exception.
7731  If this environment variable is set, SDCC won't install the signal handler
7732  in order to be able to debug SDCC.
7733 \layout List
7734 \labelwidthstring 00.00.0000
7735
7736
7737 \series bold 
7738 TMP,\SpecialChar ~
7739 TEMP,\SpecialChar ~
7740 TMPDIR
7741 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
7742
7743 \end_inset 
7744
7745
7746 \series default 
7747  Path, where temporary files will be created.
7748  The order of the variables is the search order.
7749  In a standard *nix environment these variables are not set, and there's
7750  no need to set them.
7751  On Windows it's recommended to set one of them.
7752 \layout List
7753 \labelwidthstring 00.00.0000
7754
7755
7756 \series bold 
7757 SDCC_HOME
7758 \begin_inset LatexCommand \index{SDCC\_HOME}
7759
7760 \end_inset 
7761
7762
7763 \series default 
7764  Path, see section 
7765 \begin_inset LatexCommand \ref{sub:Install-paths}
7766
7767 \end_inset 
7768
7769 \SpecialChar ~
7770
7771 \begin_inset Quotes sld
7772 \end_inset 
7773
7774  Install Paths
7775 \begin_inset Quotes srd
7776 \end_inset 
7777
7778 .
7779 \layout List
7780 \labelwidthstring 00.00.0000
7781
7782
7783 \series bold 
7784 SDCC_INCLUDE
7785 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
7786
7787 \end_inset 
7788
7789
7790 \series default 
7791  Path, see section 
7792 \begin_inset LatexCommand \ref{sub:Search-Paths}
7793
7794 \end_inset 
7795
7796 \SpecialChar ~
7797
7798 \begin_inset Quotes sld
7799 \end_inset 
7800
7801 Search Paths
7802 \begin_inset Quotes srd
7803 \end_inset 
7804
7805 .
7806 \layout List
7807 \labelwidthstring 00.00.0000
7808
7809
7810 \series bold 
7811 SDCC_LIB
7812 \begin_inset LatexCommand \index{SDCC\_LIB}
7813
7814 \end_inset 
7815
7816
7817 \series default 
7818  Path, see section 
7819 \begin_inset LatexCommand \ref{sub:Search-Paths}
7820
7821 \end_inset 
7822
7823 \SpecialChar ~
7824
7825 \begin_inset Quotes sld
7826 \end_inset 
7827
7828 Search Paths
7829 \begin_inset Quotes srd
7830 \end_inset 
7831
7832 ..
7833 \layout Standard
7834
7835 There are some more environment variables recognized by SDCC, but these
7836  are solely used for debugging purposes.
7837  They can change or disappear very quickly, and will never be documented.
7838 \layout Section
7839
7840 Storage Class Language Extensions
7841 \layout Subsection
7842
7843 MCS51/DS390 Storage Class
7844 \begin_inset LatexCommand \index{Storage class}
7845
7846 \end_inset 
7847
7848  Language Extensions
7849 \layout Standard
7850
7851 In addition to the ANSI storage classes SDCC allows the following MCS51
7852  specific storage classes:
7853 \layout Subsubsection
7854
7855 data
7856 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7857
7858 \end_inset 
7859
7860  / near
7861 \begin_inset LatexCommand \index{near (storage class)}
7862
7863 \end_inset 
7864
7865
7866 \layout Standard
7867
7868 This is the 
7869 \series bold 
7870 default
7871 \series default 
7872  storage class for the Small Memory model (
7873 \emph on 
7874 data
7875 \emph default 
7876  and 
7877 \emph on 
7878 near
7879 \emph default 
7880  can be used synonymously).
7881  Variables declared with this storage class will be allocated in the directly
7882  addressable portion of the internal RAM of a 8051, e.g.:
7883 \layout Verse
7884
7885
7886 \family typewriter 
7887 data unsigned char test_data;
7888 \layout Standard
7889
7890 Writing 0x01 to this variable generates the assembly code:
7891 \layout Verse
7892
7893
7894 \family typewriter 
7895 75*00 01\SpecialChar ~
7896 \SpecialChar ~
7897 \SpecialChar ~
7898 mov\SpecialChar ~
7899 \SpecialChar ~
7900 _test_data,#0x01 
7901 \layout Subsubsection
7902
7903 xdata
7904 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7905
7906 \end_inset 
7907
7908  / far
7909 \begin_inset LatexCommand \index{far (storage class)}
7910
7911 \end_inset 
7912
7913
7914 \layout Standard
7915
7916 Variables declared with this storage class will be placed in the external
7917  RAM.
7918  This is the 
7919 \series bold 
7920 default
7921 \series default 
7922  storage class for the Large Memory model, e.g.:
7923 \layout Verse
7924
7925
7926 \family typewriter 
7927 xdata unsigned char test_xdata;
7928 \layout Standard
7929
7930 Writing 0x01 to this variable generates the assembly code:
7931 \layout Verse
7932
7933
7934 \family typewriter 
7935 90s00r00\SpecialChar ~
7936 \SpecialChar ~
7937 \SpecialChar ~
7938 mov\SpecialChar ~
7939 \SpecialChar ~
7940 dptr,#_test_xdata 
7941 \newline 
7942 74\SpecialChar ~
7943 01\SpecialChar ~
7944 \SpecialChar ~
7945 \SpecialChar ~
7946 \SpecialChar ~
7947 \SpecialChar ~
7948 \SpecialChar ~
7949 mov\SpecialChar ~
7950 \SpecialChar ~
7951 a,#0x01 
7952 \newline 
7953 F0\SpecialChar ~
7954 \SpecialChar ~
7955 \SpecialChar ~
7956 \SpecialChar ~
7957 \SpecialChar ~
7958 \SpecialChar ~
7959 \SpecialChar ~
7960 \SpecialChar ~
7961 \SpecialChar ~
7962 movx\SpecialChar ~
7963 @dptr,a 
7964 \layout Subsubsection
7965
7966 idata
7967 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7968
7969 \end_inset 
7970
7971
7972 \layout Standard
7973
7974 Variables declared with this storage class will be allocated into the indirectly
7975  addressable portion of the internal ram of a 8051, e.g.:
7976 \layout Verse
7977
7978
7979 \family typewriter 
7980 idata unsigned char test_idata;
7981 \layout Standard
7982
7983 Writing 0x01 to this variable generates the assembly code:
7984 \layout Verse
7985
7986
7987 \family typewriter 
7988 78r00\SpecialChar ~
7989 \SpecialChar ~
7990 \SpecialChar ~
7991 \SpecialChar ~
7992 \SpecialChar ~
7993 \SpecialChar ~
7994 \SpecialChar ~
7995 mov\SpecialChar ~
7996 \SpecialChar ~
7997 r0,#_test_idata
7998 \newline 
7999 76\SpecialChar ~
8000 01\SpecialChar ~
8001 \SpecialChar ~
8002 \SpecialChar ~
8003 \SpecialChar ~
8004 \SpecialChar ~
8005 \SpecialChar ~
8006 \SpecialChar ~
8007 mov\SpecialChar ~
8008 \SpecialChar ~
8009 @r0,#0x01
8010 \layout Standard
8011
8012 Please note, the first 128 byte of idata physically access the same RAM
8013  as the data memory.
8014  The original 8051 had 128 byte idata memory, nowadays most devices have
8015  256 byte idata memory.
8016  The stack
8017 \begin_inset LatexCommand \index{stack}
8018
8019 \end_inset 
8020
8021  is located in idata memory.
8022 \layout Subsubsection
8023
8024 pdata
8025 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8026
8027 \end_inset 
8028
8029
8030 \layout Standard
8031
8032 Paged xdata access is currently not as straightforward as using the other
8033  addressing modes of a 8051.
8034  The following example writes 0x01 to the address pointed to.
8035  Please note, pdata access physically accesses xdata memory.
8036  The high byte of the address is determined by port P2 
8037 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
8038
8039 \end_inset 
8040
8041 (or in case of some 8051 variants by a separate Special Function Register,
8042  see section 
8043 \begin_inset LatexCommand \ref{sub:MCS51-variants}
8044
8045 \end_inset 
8046
8047 ).
8048 \layout Verse
8049
8050
8051 \family typewriter 
8052 pdata unsigned char *test_pdata_ptr;
8053 \newline 
8054
8055 \newline 
8056 void main() 
8057 \newline 
8058
8059 \newline 
8060 \SpecialChar ~
8061 \SpecialChar ~
8062 \SpecialChar ~
8063 \SpecialChar ~
8064 test_pdata_ptr = (pdata *)0xfe; 
8065 \newline 
8066 \SpecialChar ~
8067 \SpecialChar ~
8068 \SpecialChar ~
8069 \SpecialChar ~
8070 *test_pdata_ptr = 1; 
8071 \newline 
8072
8073 \layout Standard
8074
8075 Generates the assembly code:
8076 \layout Verse
8077
8078
8079 \family typewriter 
8080 75*01 FE\SpecialChar ~
8081 \SpecialChar ~
8082 \SpecialChar ~
8083 mov\SpecialChar ~
8084  _test_pdata_ptr,#0xFE
8085 \newline 
8086 78 FE\SpecialChar ~
8087 \SpecialChar ~
8088 \SpecialChar ~
8089 \SpecialChar ~
8090 \SpecialChar ~
8091 \SpecialChar ~
8092 mov\SpecialChar ~
8093  r0,#0xFE 
8094 \newline 
8095 74 01\SpecialChar ~
8096 \SpecialChar ~
8097 \SpecialChar ~
8098 \SpecialChar ~
8099 \SpecialChar ~
8100 \SpecialChar ~
8101 mov\SpecialChar ~
8102  a,#0x01
8103 \newline 
8104 F2\SpecialChar ~
8105 \SpecialChar ~
8106 \SpecialChar ~
8107 \SpecialChar ~
8108 \SpecialChar ~
8109 \SpecialChar ~
8110 \SpecialChar ~
8111 \SpecialChar ~
8112 \SpecialChar ~
8113 movx @r0,a 
8114 \layout Standard
8115
8116 Be extremely carefull if you use pdata together with the -
8117 \begin_inset ERT
8118 status Collapsed
8119
8120 \layout Standard
8121
8122 \backslash 
8123 /
8124 \end_inset 
8125
8126 -xstack
8127 \begin_inset LatexCommand \index{-\/-xstack}
8128
8129 \end_inset 
8130
8131  option.
8132 \layout Subsubsection
8133
8134 code
8135 \begin_inset LatexCommand \index{code}
8136
8137 \end_inset 
8138
8139
8140 \layout Standard
8141
8142 'Variables' declared with this storage class will be placed in the code
8143  memory:
8144 \layout Verse
8145
8146
8147 \family typewriter 
8148 code unsigned char test_code;
8149 \layout Standard
8150
8151 Read access to this variable generates the assembly code:
8152 \layout Verse
8153
8154
8155 \family typewriter 
8156 90s00r6F\SpecialChar ~
8157 \SpecialChar ~
8158 \SpecialChar ~
8159 mov dptr,#_test_code
8160 \newline 
8161 E4\SpecialChar ~
8162 \SpecialChar ~
8163 \SpecialChar ~
8164 \SpecialChar ~
8165 \SpecialChar ~
8166 \SpecialChar ~
8167 \SpecialChar ~
8168 \SpecialChar ~
8169 \SpecialChar ~
8170 clr a
8171 \newline 
8172 93\SpecialChar ~
8173 \SpecialChar ~
8174 \SpecialChar ~
8175 \SpecialChar ~
8176 \SpecialChar ~
8177 \SpecialChar ~
8178 \SpecialChar ~
8179 \SpecialChar ~
8180 \SpecialChar ~
8181 movc a,@a+dptr 
8182 \layout Standard
8183
8184
8185 \family typewriter 
8186 char
8187 \family default 
8188  indexed arrays of characters in code memory can be accessed efficiently:
8189 \layout Verse
8190
8191
8192 \family typewriter 
8193 code char test_array[] = {'c','h','e','a','p'}; 
8194 \layout Standard
8195
8196 Read access to this array using an 8-bit unsigned index generates the assembly
8197  code:
8198 \layout Verse
8199
8200
8201 \family typewriter 
8202 E5*00\SpecialChar ~
8203 \SpecialChar ~
8204 \SpecialChar ~
8205 \SpecialChar ~
8206 \SpecialChar ~
8207 \SpecialChar ~
8208 mov a,_index 
8209 \layout Verse
8210
8211
8212 \family typewriter 
8213 90s00r41\SpecialChar ~
8214 \SpecialChar ~
8215 \SpecialChar ~
8216 mov dptr,#_test_array
8217 \layout Verse
8218
8219
8220 \family typewriter 
8221 93\SpecialChar ~
8222 \SpecialChar ~
8223 \SpecialChar ~
8224 \SpecialChar ~
8225 \SpecialChar ~
8226 \SpecialChar ~
8227 \SpecialChar ~
8228 \SpecialChar ~
8229 \SpecialChar ~
8230 movc a,@a+dptr 
8231 \layout Subsubsection
8232
8233 bit
8234 \begin_inset LatexCommand \index{bit}
8235
8236 \end_inset 
8237
8238
8239 \layout Standard
8240
8241 This is a data-type and a storage class specifier.
8242  When a variable is declared as a bit, it is allocated into the bit addressable
8243  memory of 8051, e.g.:
8244 \layout Verse
8245
8246
8247 \family typewriter 
8248 bit test_bit;
8249 \layout Standard
8250
8251 Writing 1 to this variable generates the assembly code:
8252 \layout Verse
8253
8254
8255 \family typewriter 
8256 D2*00\SpecialChar ~
8257 \SpecialChar ~
8258 \SpecialChar ~
8259 \SpecialChar ~
8260 \SpecialChar ~
8261 \SpecialChar ~
8262 \SpecialChar ~
8263 setb\SpecialChar ~
8264 _test_bit
8265 \layout Standard
8266
8267 The bit addressable memory consists of 128 bits which are located from 0x20
8268  to 0x2f in data memory.
8269  
8270 \layout Standard
8271
8272 Apart from this 8051 specific storage class most architectures support ANSI-C
8273  bitfields
8274 \begin_inset LatexCommand \index{bitfields}
8275
8276 \end_inset 
8277
8278
8279 \newline 
8280
8281 \layout Standard
8282
8283 In accordance with ISO/IEC 9899 bits and bitfields without an explicit signed
8284  modifier are implemented as unsigned.
8285 \layout Standard
8286
8287
8288 \begin_inset Foot
8289 collapsed false
8290
8291 \layout Standard
8292
8293 Not really meant as examples, but nevertheless showing what bitfields are
8294  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
8295 \end_inset 
8296
8297 .
8298 \layout Subsubsection
8299
8300 sfr
8301 \begin_inset LatexCommand \index{sfr}
8302
8303 \end_inset 
8304
8305  / sbit
8306 \begin_inset LatexCommand \index{sbit}
8307
8308 \end_inset 
8309
8310
8311 \layout Standard
8312
8313 Like the bit keyword, 
8314 \emph on 
8315 sfr / sbit 
8316 \emph default 
8317 signifies both a data-type and storage class, they are used to describe
8318  the 
8319 \emph on 
8320 s
8321 \emph default 
8322 pecial 
8323 \emph on 
8324 f
8325 \emph default 
8326 unction 
8327 \emph on 
8328 r
8329 \emph default 
8330 egisters and 
8331 \emph on 
8332 s
8333 \emph default 
8334 pecial 
8335 \emph on 
8336 bit
8337 \emph default 
8338  variables of a 8051, eg:
8339 \layout Verse
8340
8341
8342 \family typewriter 
8343 sfr at
8344 \begin_inset LatexCommand \index{at}
8345
8346 \end_inset 
8347
8348  0x80 P0;\SpecialChar ~
8349  /* special function register P0 at location 0x80 */
8350 \newline 
8351 sbit at 0xd7 CY; /* CY (Carry Flag
8352 \begin_inset LatexCommand \index{Flags}
8353
8354 \end_inset 
8355
8356
8357 \begin_inset LatexCommand \index{Carry flag}
8358
8359 \end_inset 
8360
8361 ) */
8362 \layout Standard
8363
8364 Special function registers which are located on an address dividable by
8365  8 are bit-addressable, an
8366 \emph on 
8367  sbit
8368 \emph default 
8369  addresses a specific bit within these sfr.
8370 \layout Subsubsection
8371
8372 Pointers
8373 \begin_inset LatexCommand \index{Pointer}
8374
8375 \end_inset 
8376
8377  to MCS51/DS390 specific memory spaces
8378 \layout Standard
8379
8380 SDCC allows (via language extensions) pointers to explicitly point to any
8381  of the memory spaces
8382 \begin_inset LatexCommand \index{Memory model}
8383
8384 \end_inset 
8385
8386  of the 8051.
8387  In addition to the explicit pointers, the compiler uses (by default) generic
8388  pointers which can be used to point to any of the memory spaces.
8389 \newline 
8390
8391 \newline 
8392 Pointer declaration examples:
8393 \layout Verse
8394
8395
8396 \family typewriter 
8397 /* pointer physically in internal ram pointing to object in external ram
8398  */ 
8399 \newline 
8400 xdata unsigned char * data p;
8401 \newline 
8402
8403 \newline 
8404 /* pointer physically in external ram pointing to object in internal ram
8405  */ 
8406 \newline 
8407 data unsigned char * xdata p;
8408 \newline 
8409
8410 \newline 
8411 /* pointer physically in code rom pointing to data in xdata space */ 
8412 \newline 
8413 xdata unsigned char * code p;
8414 \newline 
8415
8416 \newline 
8417 /* pointer physically in code space pointing to data in code space */ 
8418 \newline 
8419 code unsigned char * code p;
8420 \newline 
8421
8422 \newline 
8423 /* the following is a generic pointer physically located in xdata space
8424  */
8425 \newline 
8426 char * xdata p;
8427 \layout Standard
8428
8429 Well you get the idea.
8430  
8431 \newline 
8432
8433 \newline 
8434 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
8435 \emph on 
8436 generic
8437 \emph default 
8438  pointers.
8439  
8440 \size small 
8441
8442 \newline 
8443
8444 \newline 
8445
8446 \size default 
8447 The highest order byte of the 
8448 \emph on 
8449 generic
8450 \emph default 
8451  pointers contains the data space information.
8452  Assembler support routines are called whenever data is stored or retrieved
8453  using 
8454 \emph on 
8455 generic
8456 \emph default 
8457  pointers.
8458  These are useful for developing reusable library
8459 \begin_inset LatexCommand \index{Libraries}
8460
8461 \end_inset 
8462
8463  routines.
8464  Explicitly specifying the pointer type will generate the most efficient
8465  code.
8466 \layout Subsubsection
8467
8468 Notes on MCS51 memory
8469 \begin_inset LatexCommand \index{MCS51 memory}
8470
8471 \end_inset 
8472
8473  layout
8474 \layout Standard
8475
8476 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
8477  RAM memory which is structured as follows:
8478 \newline 
8479
8480 \newline 
8481 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
8482  
8483 \newline 
8484 - Bytes 20-2F - 16 bytes to hold 128 bit
8485 \begin_inset LatexCommand \index{bit}
8486
8487 \end_inset 
8488
8489  variables and, 
8490 \newline 
8491 - Bytes 30-7F - 80 bytes for general purpose use.
8492 \newline 
8493
8494 \layout Standard
8495
8496 Additionally some members of the MCS51 family may have up to 128 bytes of
8497  additional, indirectly addressable, internal RAM memory (
8498 \emph on 
8499 idata
8500 \emph default 
8501
8502 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
8503
8504 \end_inset 
8505
8506 ).
8507  Furthermore, some chips may have some built in external memory (
8508 \emph on 
8509 xdata
8510 \emph default 
8511
8512 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
8513
8514 \end_inset 
8515
8516 ) which should not be confused with the internal, directly addressable RAM
8517  memory (
8518 \emph on 
8519 data
8520 \emph default 
8521
8522 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
8523
8524 \end_inset 
8525
8526 ).
8527  Sometimes this built in 
8528 \emph on 
8529 xdata
8530 \emph default 
8531  memory has to be activated before using it (you can probably find this
8532  information on the datasheet of the microcontroller your are using, see
8533  also section 
8534 \begin_inset LatexCommand \ref{sub:Startup-Code}
8535
8536 \end_inset 
8537
8538 \SpecialChar ~
8539 Startup-Code).
8540 \layout Standard
8541
8542 Normally SDCC will only use the first bank
8543 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
8544
8545 \end_inset 
8546
8547  of registers (register bank 0), but it is possible to specify that other
8548  banks of registers should be used in interrupt
8549 \begin_inset LatexCommand \index{interrupt}
8550
8551 \end_inset 
8552
8553  routines.
8554  By default, the compiler will place the stack after the last byte of allocated
8555  memory for variables.
8556  For example, if the first 2 banks of registers are used, and only four
8557  bytes are used for 
8558 \emph on 
8559 data
8560 \emph default 
8561  variables, it will position the base of the internal stack at address 20
8562  (0x14).
8563  This implies that as the stack
8564 \begin_inset LatexCommand \index{stack}
8565
8566 \end_inset 
8567
8568  grows, it will use up the remaining register banks, and the 16 bytes used
8569  by the 128 bit variables, and 80 bytes for general purpose use.
8570  If any bit variables are used, the data variables will be placed after
8571  the byte holding the last bit variable.
8572  For example, if register banks 0 and 1 are used, and there are 9 bit variables
8573  (two bytes used), 
8574 \emph on 
8575 data
8576 \emph default 
8577  variables will be placed starting at address 0x22.
8578  You can also use -
8579 \begin_inset ERT
8580 status Collapsed
8581
8582 \layout Standard
8583
8584 \backslash 
8585 /
8586 \end_inset 
8587
8588 -data-loc
8589 \begin_inset LatexCommand \index{-\/-data-loc<Value>}
8590
8591 \end_inset 
8592
8593  to specify the start address of the 
8594 \emph on 
8595 data
8596 \emph default 
8597  and -
8598 \begin_inset ERT
8599 status Collapsed
8600
8601 \layout Standard
8602
8603 \backslash 
8604 /
8605 \end_inset 
8606
8607 -iram-size to specify the size of the total internal RAM (
8608 \emph on 
8609 data
8610 \emph default 
8611 +
8612 \emph on 
8613 idata
8614 \emph default 
8615 ).
8616  
8617 \layout Standard
8618
8619 By default the 8051 linker will place the stack after the last byte of data
8620  variables.
8621  Option -
8622 \begin_inset ERT
8623 status Collapsed
8624
8625 \layout Standard
8626
8627 \backslash 
8628 /
8629 \end_inset 
8630
8631 -stack-loc
8632 \begin_inset LatexCommand \index{-\/-stack-loc<Value>}
8633
8634 \end_inset 
8635
8636  allows you to specify the start of the stack, i.e.
8637  you could start it after any data in the general purpose area.
8638  If your microcontroller has additional indirectly addressable internal
8639  RAM (
8640 \emph on 
8641 idata
8642 \emph default 
8643 ) you can place the stack on it.
8644  You may also need to use -
8645 \begin_inset ERT
8646 status Collapsed
8647
8648 \layout Standard
8649
8650 \backslash 
8651 /
8652 \end_inset 
8653
8654 -xdata-loc
8655 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
8656
8657 \end_inset 
8658
8659  to set the start address of the external RAM (
8660 \emph on 
8661 xdata
8662 \emph default 
8663 ) and -
8664 \begin_inset ERT
8665 status Collapsed
8666
8667 \layout Standard
8668
8669 \backslash 
8670 /
8671 \end_inset 
8672
8673 -xram-size
8674 \begin_inset LatexCommand \index{-\/-data-loc}
8675
8676 \end_inset 
8677
8678  to specify its size.
8679  Same goes for the code memory, using -
8680 \begin_inset ERT
8681 status Collapsed
8682
8683 \layout Standard
8684
8685 \backslash 
8686 /
8687 \end_inset 
8688
8689 -code-loc
8690 \begin_inset LatexCommand \index{-\/-data-loc}
8691
8692 \end_inset 
8693
8694  and -
8695 \begin_inset ERT
8696 status Collapsed
8697
8698 \layout Standard
8699
8700 \backslash 
8701 /
8702 \end_inset 
8703
8704 -code-size
8705 \begin_inset LatexCommand \index{-\/-data-loc}
8706
8707 \end_inset 
8708
8709 .
8710  If in doubt, don't specify any options and see if the resulting memory
8711  layout is appropriate, then you can adjust it.
8712 \layout Standard
8713
8714 The linker generates two files with memory allocation information.
8715  The first, with extension .map
8716 \begin_inset LatexCommand \index{<file>.map}
8717
8718 \end_inset 
8719
8720  shows all the variables and segments.
8721  The second with extension .mem
8722 \begin_inset LatexCommand \index{<file>.mem}
8723
8724 \end_inset 
8725
8726  shows the final memory layout.
8727  The linker will complain either if memory segments overlap, there is not
8728  enough memory, or there is not enough space for stack.
8729  If you get any linking warnings and/or errors related to stack or segments
8730  allocation, take a look at either the .map or .mem files to find out what
8731  the problem is.
8732  The .mem file may even suggest a solution to the problem.
8733 \layout Subsection
8734
8735 Z80/Z180 Storage Class
8736 \begin_inset LatexCommand \index{Storage class}
8737
8738 \end_inset 
8739
8740  Language Extensions
8741 \layout Subsubsection
8742
8743 sfr
8744 \begin_inset LatexCommand \index{sfr}
8745
8746 \end_inset 
8747
8748  (in/out to 8-bit addresses)
8749 \layout Standard
8750
8751 The Z80
8752 \begin_inset LatexCommand \index{Z80}
8753
8754 \end_inset 
8755
8756  family has separate address spaces for memory and 
8757 \emph on 
8758 i
8759 \emph default 
8760 nput/
8761 \emph on 
8762 o
8763 \emph default 
8764 utput memory.
8765  I/O memory
8766 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
8767
8768 \end_inset 
8769
8770  is accessed with special instructions, e.g.:
8771 \layout Verse
8772
8773
8774 \family typewriter 
8775 sfr at 0x78 IoPort;\SpecialChar ~
8776 \SpecialChar ~
8777 /* define a var in I/O space at 78h called IoPort */
8778  
8779 \layout Standard
8780
8781 Writing 0x01 to this variable generates the assembly code:
8782 \layout Verse
8783
8784
8785 \family typewriter 
8786 3E 01\SpecialChar ~
8787 \SpecialChar ~
8788 \SpecialChar ~
8789 \SpecialChar ~
8790 \SpecialChar ~
8791 \SpecialChar ~
8792 ld a,#0x01
8793 \newline 
8794 D3 78\SpecialChar ~
8795 \SpecialChar ~
8796 \SpecialChar ~
8797 \SpecialChar ~
8798 \SpecialChar ~
8799 \SpecialChar ~
8800 out (_IoPort),a 
8801 \layout Subsubsection
8802
8803 banked sfr
8804 \begin_inset LatexCommand \index{sfr}
8805
8806 \end_inset 
8807
8808  (in/out to 16-bit addresses)
8809 \layout Standard
8810
8811 The keyword 
8812 \emph on 
8813 banked
8814 \emph default 
8815  is used to support 16 bit addresses in I/O memory e.g.:
8816 \layout Verse
8817
8818
8819 \family typewriter 
8820 sfr banked at
8821 \begin_inset LatexCommand \index{at}
8822
8823 \end_inset 
8824
8825  0x123 IoPort; 
8826 \layout Standard
8827
8828 Writing 0x01 to this variable generates the assembly code:
8829 \layout Verse
8830
8831
8832 \family typewriter 
8833 01 23 01\SpecialChar ~
8834 \SpecialChar ~
8835 \SpecialChar ~
8836 ld bc,#_IoPort
8837 \newline 
8838 3E 01\SpecialChar ~
8839 \SpecialChar ~
8840 \SpecialChar ~
8841 \SpecialChar ~
8842 \SpecialChar ~
8843 \SpecialChar ~
8844 ld a,#0x01 
8845 \newline 
8846 ED 79\SpecialChar ~
8847 \SpecialChar ~
8848 \SpecialChar ~
8849 \SpecialChar ~
8850 \SpecialChar ~
8851 \SpecialChar ~
8852 out (c),a 
8853 \layout Subsubsection
8854
8855 sfr
8856 \begin_inset LatexCommand \index{sfr}
8857
8858 \end_inset 
8859
8860  (in0/out0 to 8 bit addresses on Z180
8861 \begin_inset LatexCommand \index{Z180}
8862
8863 \end_inset 
8864
8865 /HD64180
8866 \begin_inset LatexCommand \index{HD64180}
8867
8868 \end_inset 
8869
8870 )
8871 \layout Standard
8872
8873 The compiler option -
8874 \begin_inset ERT
8875 status Collapsed
8876
8877 \layout Standard
8878
8879 \backslash 
8880 /
8881 \end_inset 
8882
8883 -portmode=180 (80) and a compiler #pragma\SpecialChar ~
8884 portmode
8885 \begin_inset LatexCommand \index{\#pragma portmode}
8886
8887 \end_inset 
8888
8889 =z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
8890 ns 
8891 \family typewriter 
8892 in0/out0
8893 \family default 
8894  instead of 
8895 \family typewriter 
8896 in/out
8897 \family default 
8898 .
8899  If you include the file z180.h this will be set automatically.
8900 \layout Subsection
8901
8902 HC08 Storage Class
8903 \begin_inset LatexCommand \index{Storage class}
8904
8905 \end_inset 
8906
8907  Language Extensions
8908 \layout Subsubsection
8909
8910 data
8911 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
8912
8913 \end_inset 
8914
8915
8916 \layout Standard
8917
8918 The data storage class declares a variable that resides in the first 256
8919  bytes of memory (the direct page).
8920  The HC08 is most efficient at accessing variables (especially pointers)
8921  stored here.
8922 \layout Subsubsection
8923
8924 xdata
8925 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
8926
8927 \end_inset 
8928
8929
8930 \layout Standard
8931
8932 The xdata storage class declares a variable that can reside anywhere in
8933  memory.
8934  This is the default if no storage class is specified.
8935  
8936 \layout Section
8937
8938 Absolute Addressing
8939 \begin_inset LatexCommand \index{Absolute addressing}
8940
8941 \end_inset 
8942
8943
8944 \layout Standard
8945
8946 Data items can be assigned an absolute address with the 
8947 \emph on 
8948 at
8949 \begin_inset LatexCommand \index{at}
8950
8951 \end_inset 
8952
8953  <address>
8954 \emph default 
8955  keyword, in addition to a storage class, e.g.:
8956 \layout Verse
8957
8958
8959 \family typewriter 
8960 xdata
8961 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
8962
8963 \end_inset 
8964
8965  at
8966 \begin_inset LatexCommand \index{at}
8967
8968 \end_inset 
8969
8970  0x7ffe unsigned int chksum;
8971 \layout Standard
8972
8973 In the above example the variable chksum will located at 0x7ffe and 0x7fff
8974  of the external ram.
8975  The compiler does 
8976 \emph on 
8977 not
8978 \emph default 
8979  reserve any space for variables declared in this way (they are implemented
8980  with an equate in the assembler).
8981  Thus it is left to the programmer to make sure there are no overlaps with
8982  other variables that are declared without the absolute address.
8983  The assembler listing file (.lst
8984 \begin_inset LatexCommand \index{<file>.lst}
8985
8986 \end_inset 
8987
8988 ) and the linker output files (.rst
8989 \begin_inset LatexCommand \index{<file>.rst}
8990
8991 \end_inset 
8992
8993 ) and (.map
8994 \begin_inset LatexCommand \index{<file>.map}
8995
8996 \end_inset 
8997
8998 ) are good places to look for such overlaps.
8999  Variables with an absolute address are 
9000 \emph on 
9001 not
9002 \emph default 
9003  initialized
9004 \begin_inset LatexCommand \index{Variable initialization}
9005
9006 \end_inset 
9007
9008 .
9009 \layout Standard
9010
9011 In case of memory mapped I/O devices the keyword 
9012 \emph on 
9013 volatile
9014 \emph default 
9015  should be used to tell the compiler that accesses might not be optimized
9016  away:
9017 \layout Verse
9018
9019
9020 \family typewriter 
9021 volatile
9022 \begin_inset LatexCommand \index{volatile}
9023
9024 \end_inset 
9025
9026  xdata
9027 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9028
9029 \end_inset 
9030
9031  at
9032 \begin_inset LatexCommand \index{at}
9033
9034 \end_inset 
9035
9036  0x8000 unsigned char PORTA_8255;
9037 \layout Standard
9038
9039 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
9040 r) array
9041 \family typewriter 
9042 \size footnotesize 
9043
9044 \begin_inset LatexCommand \index{Aligned array}
9045
9046 \end_inset 
9047
9048
9049 \family default 
9050 \size default 
9051  starts at a block (256 byte) boundary
9052 \begin_inset LatexCommand \index{block boundary}
9053
9054 \end_inset 
9055
9056  (section 
9057 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
9058
9059 \end_inset 
9060
9061  has an example).
9062 \newline 
9063 Absolute addresses can be specified for variables in all storage classes,
9064  e.g.:
9065 \layout Verse
9066
9067
9068 \family typewriter 
9069 bit
9070 \begin_inset LatexCommand \index{bit}
9071
9072 \end_inset 
9073
9074  at
9075 \begin_inset LatexCommand \index{at}
9076
9077 \end_inset 
9078
9079  0x02 bvar;
9080 \layout Standard
9081
9082 The above example will allocate the variable at offset 0x02 in the bit-addressab
9083 le space.
9084  There is no real advantage to assigning absolute addresses to variables
9085  in this manner, unless you want strict control over all the variables allocated.
9086  One possible use would be to write hardware portable code.
9087  For example, if you have a routine that uses one or more of the microcontroller
9088  I/O pins, and such pins are different for two different hardwares, you
9089  can declare the I/O pins in your routine using:
9090 \layout Verse
9091
9092
9093 \family typewriter 
9094 extern volatile bit SDI;
9095 \newline 
9096 extern volatile bit SCLK;
9097 \newline 
9098 extern volatile bit CPOL;
9099 \newline 
9100
9101 \newline 
9102 void DS1306_put(unsigned char value)
9103 \newline 
9104 {
9105 \newline 
9106 \SpecialChar ~
9107 \SpecialChar ~
9108 \SpecialChar ~
9109 \SpecialChar ~
9110 unsigned char mask=0x80;
9111 \newline 
9112
9113 \newline 
9114 \SpecialChar ~
9115 \SpecialChar ~
9116 \SpecialChar ~
9117 \SpecialChar ~
9118 while(mask)
9119 \newline 
9120 \SpecialChar ~
9121 \SpecialChar ~
9122 \SpecialChar ~
9123 \SpecialChar ~
9124 {
9125 \newline 
9126 \SpecialChar ~
9127 \SpecialChar ~
9128 \SpecialChar ~
9129 \SpecialChar ~
9130 \SpecialChar ~
9131 \SpecialChar ~
9132 \SpecialChar ~
9133 \SpecialChar ~
9134 SDI=(value & mask)?1:0;
9135 \newline 
9136 \SpecialChar ~
9137 \SpecialChar ~
9138 \SpecialChar ~
9139 \SpecialChar ~
9140 \SpecialChar ~
9141 \SpecialChar ~
9142 \SpecialChar ~
9143 \SpecialChar ~
9144 SCLK=!CPOL;
9145 \newline 
9146 \SpecialChar ~
9147 \SpecialChar ~
9148 \SpecialChar ~
9149 \SpecialChar ~
9150 \SpecialChar ~
9151 \SpecialChar ~
9152 \SpecialChar ~
9153 \SpecialChar ~
9154 SCLK=CPOL;
9155 \newline 
9156 \SpecialChar ~
9157 \SpecialChar ~
9158 \SpecialChar ~
9159 \SpecialChar ~
9160 \SpecialChar ~
9161 \SpecialChar ~
9162 \SpecialChar ~
9163 \SpecialChar ~
9164 mask/=2;
9165 \newline 
9166 \SpecialChar ~
9167 \SpecialChar ~
9168 \SpecialChar ~
9169 \SpecialChar ~
9170 }
9171 \newline 
9172 }
9173 \layout Standard
9174
9175 Then, someplace in the code for the first hardware you would use
9176 \layout Verse
9177
9178
9179 \family typewriter 
9180 bit at 0x80 SDI;\SpecialChar ~
9181 \SpecialChar ~
9182 \SpecialChar ~
9183 \SpecialChar ~
9184 /* I/O port 0, bit 0 */
9185 \newline 
9186 bit at 0x81 SCLK;\SpecialChar ~
9187 \SpecialChar ~
9188 \SpecialChar ~
9189 /* I/O port 0, bit 1 */
9190 \newline 
9191 bit CPOL;\SpecialChar ~
9192 \SpecialChar ~
9193 \SpecialChar ~
9194 \SpecialChar ~
9195 \SpecialChar ~
9196 \SpecialChar ~
9197 \SpecialChar ~
9198 \SpecialChar ~
9199 \SpecialChar ~
9200 \SpecialChar ~
9201 \SpecialChar ~
9202 /* This is a variable, let the linker allocate this one */
9203 \layout Standard
9204
9205 Similarly, for the second hardware you would use
9206 \layout Verse
9207
9208
9209 \family typewriter 
9210 bit at 0x83 SDI;\SpecialChar ~
9211 \SpecialChar ~
9212 \SpecialChar ~
9213 \SpecialChar ~
9214 /* I/O port 0, bit 3 */
9215 \newline 
9216 bit at 0x91 SCLK;\SpecialChar ~
9217 \SpecialChar ~
9218 \SpecialChar ~
9219 /* I/O port 1, bit 1 */
9220 \newline 
9221 bit
9222 \begin_inset LatexCommand \index{bit}
9223
9224 \end_inset 
9225
9226  CPOL;\SpecialChar ~
9227 \SpecialChar ~
9228 \SpecialChar ~
9229 \SpecialChar ~
9230 \SpecialChar ~
9231 \SpecialChar ~
9232 \SpecialChar ~
9233 \SpecialChar ~
9234 \SpecialChar ~
9235 \SpecialChar ~
9236 \SpecialChar ~
9237 /* This is a variable, let the linker allocate this one */
9238 \layout Standard
9239
9240 and you can use the same hardware dependent routine without changes, as
9241  for example in a library.
9242  This is somehow similar to sbit, but only one absolute address has to be
9243  specified in the whole project.
9244 \layout Section
9245
9246 Parameters
9247 \begin_inset LatexCommand \index{Parameters}
9248
9249 \end_inset 
9250
9251
9252 \begin_inset LatexCommand \index{function parameter}
9253
9254 \end_inset 
9255
9256  & Local Variables
9257 \begin_inset LatexCommand \index{local variables}
9258
9259 \end_inset 
9260
9261
9262 \layout Standard
9263
9264 Automatic (local) variables and parameters to functions can either be placed
9265  on the stack or in data-space.
9266  The default action of the compiler is to place these variables in the internal
9267  RAM (for small model) or external RAM (for large model).
9268  This in fact makes them similar to 
9269 \emph on 
9270 static
9271 \begin_inset LatexCommand \index{static}
9272
9273 \end_inset 
9274
9275
9276 \emph default 
9277  so by default functions are non-reentrant
9278 \begin_inset LatexCommand \index{reentrant}
9279
9280 \end_inset 
9281
9282 .
9283  
9284 \newline 
9285
9286 \newline 
9287 They can be placed on the stack
9288 \begin_inset LatexCommand \index{stack}
9289
9290 \end_inset 
9291
9292  either by using the
9293 \emph on 
9294  -
9295 \begin_inset ERT
9296 status Collapsed
9297
9298 \layout Standard
9299
9300 \backslash 
9301 /
9302 \end_inset 
9303
9304 -stack-auto
9305 \begin_inset LatexCommand \index{-\/-stack-auto}
9306
9307 \end_inset 
9308
9309
9310 \emph default 
9311  option or by using the 
9312 \emph on 
9313 reentrant
9314 \begin_inset LatexCommand \index{reentrant}
9315
9316 \end_inset 
9317
9318
9319 \emph default 
9320  keyword in the function declaration, e.g.:
9321 \layout Verse
9322
9323
9324 \family typewriter 
9325 unsigned char foo(char i) reentrant 
9326 \newline 
9327
9328 \newline 
9329 \SpecialChar ~
9330 \SpecialChar ~
9331 \SpecialChar ~
9332 \SpecialChar ~
9333 ...
9334  
9335 \newline 
9336 }
9337 \layout Standard
9338
9339 Since stack space on 8051 is limited, the 
9340 \emph on 
9341 reentrant 
9342 \emph default 
9343 keyword or the
9344 \emph on 
9345  -
9346 \begin_inset ERT
9347 status Collapsed
9348
9349 \layout Standard
9350
9351 \backslash 
9352 /
9353 \end_inset 
9354
9355 -stack-auto
9356 \emph default 
9357  option should be used sparingly.
9358  Note that the reentrant keyword just means that the parameters & local
9359  variables will be allocated to the stack, it 
9360 \emph on 
9361 does not
9362 \emph default 
9363  mean that the function is register bank
9364 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
9365
9366 \end_inset 
9367
9368  independent.
9369 \newline 
9370
9371 \newline 
9372 Local variables
9373 \begin_inset LatexCommand \index{local variables}
9374
9375 \end_inset 
9376
9377  can be assigned storage classes and absolute
9378 \begin_inset LatexCommand \index{Absolute addressing}
9379
9380 \end_inset 
9381
9382  addresses, e.g.: 
9383 \layout Verse
9384
9385
9386 \family typewriter 
9387 unsigned char foo() 
9388 \newline 
9389 {
9390 \newline 
9391 \SpecialChar ~
9392 \SpecialChar ~
9393 \SpecialChar ~
9394 \SpecialChar ~
9395 xdata unsigned char i;
9396 \newline 
9397 \SpecialChar ~
9398 \SpecialChar ~
9399 \SpecialChar ~
9400 \SpecialChar ~
9401 bit bvar;
9402 \newline 
9403 \SpecialChar ~
9404 \SpecialChar ~
9405 \SpecialChar ~
9406 \SpecialChar ~
9407 data at
9408 \begin_inset LatexCommand \index{at}
9409
9410 \end_inset 
9411
9412  0x31 unsigned char j;
9413 \newline 
9414 \SpecialChar ~
9415 \SpecialChar ~
9416 \SpecialChar ~
9417 \SpecialChar ~
9418 ...
9419  
9420 \newline 
9421 }
9422 \layout Standard
9423
9424 In the above example the variable 
9425 \emph on 
9426 i
9427 \emph default 
9428  will be allocated in the external ram, 
9429 \emph on 
9430 bvar
9431 \emph default 
9432  in bit addressable space and
9433 \emph on 
9434  j
9435 \emph default 
9436  in internal ram.
9437  When compiled with 
9438 \emph on 
9439 -
9440 \begin_inset ERT
9441 status Collapsed
9442
9443 \layout Standard
9444
9445 \backslash 
9446 /
9447 \end_inset 
9448
9449 -stack-auto
9450 \emph default 
9451  or when a function is declared as 
9452 \emph on 
9453 reentrant
9454 \emph default 
9455  this should only be done for static variables.
9456 \layout Standard
9457
9458 Parameters
9459 \begin_inset LatexCommand \index{function parameter}
9460
9461 \end_inset 
9462
9463  however are not allowed any storage class
9464 \begin_inset LatexCommand \index{Storage class}
9465
9466 \end_inset 
9467
9468 , (storage classes for parameters will be ignored), their allocation is
9469  governed by the memory model in use, and the reentrancy options.
9470 \layout Section
9471
9472 Overlaying
9473 \begin_inset LatexCommand \label{sub:Overlaying}
9474
9475 \end_inset 
9476
9477
9478 \begin_inset LatexCommand \index{Overlaying}
9479
9480 \end_inset 
9481
9482
9483 \layout Standard
9484
9485 For non-reentrant
9486 \begin_inset LatexCommand \index{reentrant}
9487
9488 \end_inset 
9489
9490  functions SDCC will try to reduce internal ram space usage by overlaying
9491  parameters and local variables of a function (if possible).
9492  Parameters and local variables
9493 \begin_inset LatexCommand \index{local variables}
9494
9495 \end_inset 
9496
9497  of a function will be allocated to an overlayable segment if the function
9498  has 
9499 \emph on 
9500 no other function calls and the function is non-reentrant and the memory
9501  model
9502 \begin_inset LatexCommand \index{Memory model}
9503
9504 \end_inset 
9505
9506  is small.
9507
9508 \emph default 
9509  If an explicit storage class
9510 \begin_inset LatexCommand \index{Storage class}
9511
9512 \end_inset 
9513
9514  is specified for a local variable, it will NOT be overlayed.
9515 \layout Standard
9516
9517 Note that the compiler (not the linkage editor) makes the decision for overlayin
9518 g the data items.
9519  Functions that are called from an interrupt service routine should be preceded
9520  by a #pragma\SpecialChar ~
9521 nooverlay
9522 \begin_inset LatexCommand \index{\#pragma nooverlay}
9523
9524 \end_inset 
9525
9526  if they are not reentrant.
9527 \layout Standard
9528
9529 Also note that the compiler does not do any processing of inline assembler
9530  code, so the compiler might incorrectly assign local variables and parameters
9531  of a function into the overlay segment if the inline assembler code calls
9532  other c-functions that might use the overlay.
9533  In that case the #pragma\SpecialChar ~
9534 nooverlay should be used.
9535 \layout Standard
9536
9537 Parameters and local variables of functions that contain 16 or 32 bit multiplica
9538 tion
9539 \begin_inset LatexCommand \index{Multiplication}
9540
9541 \end_inset 
9542
9543  or division
9544 \begin_inset LatexCommand \index{Division}
9545
9546 \end_inset 
9547
9548  will NOT be overlayed since these are implemented using external functions,
9549  e.g.:
9550 \layout Verse
9551
9552
9553 \family typewriter 
9554 #pragma save 
9555 \newline 
9556 #pragma nooverlay
9557 \begin_inset LatexCommand \index{\#pragma nooverlay}
9558
9559 \end_inset 
9560
9561  
9562 \newline 
9563 void set_error(unsigned char errcd) 
9564 \newline 
9565 {
9566 \newline 
9567 \SpecialChar ~
9568 \SpecialChar ~
9569 \SpecialChar ~
9570 \SpecialChar ~
9571 P3 = errcd;
9572 \newline 
9573
9574 \newline 
9575 #pragma restore 
9576 \newline 
9577
9578 \newline 
9579 void some_isr () interrupt
9580 \begin_inset LatexCommand \index{interrupt}
9581
9582 \end_inset 
9583
9584  2
9585 \newline 
9586 {
9587 \newline 
9588 \SpecialChar ~
9589 \SpecialChar ~
9590 \SpecialChar ~
9591 \SpecialChar ~
9592 ...
9593 \newline 
9594 \SpecialChar ~
9595 \SpecialChar ~
9596 \SpecialChar ~
9597 \SpecialChar ~
9598 set_error(10);
9599 \newline 
9600 \SpecialChar ~
9601 \SpecialChar ~
9602 \SpecialChar ~
9603 \SpecialChar ~
9604 ...
9605  
9606 \newline 
9607 }
9608 \layout Standard
9609
9610 In the above example the parameter 
9611 \emph on 
9612 errcd
9613 \emph default 
9614  for the function 
9615 \emph on 
9616 set_error
9617 \emph default 
9618  would be assigned to the overlayable segment if the #pragma\SpecialChar ~
9619 nooverlay was
9620  not present, this could cause unpredictable runtime behavior when called
9621  from an interrupt service routine.
9622  The #pragma\SpecialChar ~
9623 nooverlay ensures that the parameters and local variables for
9624  the function are NOT overlayed.
9625 \layout Section
9626
9627 Interrupt Service Routines
9628 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
9629
9630 \end_inset 
9631
9632
9633 \layout Subsection
9634
9635 General Information
9636 \layout Standard
9637
9638 SDCC allows 
9639 \emph on 
9640 i
9641 \emph default 
9642 nterrupt 
9643 \emph on 
9644 s
9645 \emph default 
9646 ervice 
9647 \emph on 
9648 r
9649 \emph default 
9650 outines to be coded in C, with some extended keywords.
9651 \layout Verse
9652
9653
9654 \family typewriter 
9655 void timer_isr (void) interrupt 1 using 1 
9656 \newline 
9657
9658 \newline 
9659 \SpecialChar ~
9660 \SpecialChar ~
9661 \SpecialChar ~
9662 \SpecialChar ~
9663 ...
9664  
9665 \newline 
9666 }
9667 \layout Standard
9668
9669 The optional number following the 
9670 \emph on 
9671 interrupt
9672 \begin_inset LatexCommand \index{interrupt}
9673
9674 \end_inset 
9675
9676
9677 \emph default 
9678  keyword is the interrupt number this routine will service.
9679  When present, the compiler will insert a call to this routine in the interrupt
9680  vector table for the interrupt number specified.
9681  If you have multiple source files in your project, interrupt service routines
9682  can be present in any of them, but a prototype of the isr MUST be present
9683  or included in the file that contains the function 
9684 \emph on 
9685 main
9686 \emph default 
9687 .
9688  The 
9689 \emph on 
9690 using
9691 \emph default 
9692  keyword can be used to tell the compiler to use the specified register
9693  bank (8051 specific) when generating code for this function.
9694  
9695 \newline 
9696
9697 \layout Standard
9698
9699 Interrupt service routines open the door for some very interesting bugs:
9700  
9701 \layout Standard
9702
9703 If the interrupt service routines changes variables which are accessed by
9704  other functions these variables should be declared 
9705 \emph on 
9706 volatile
9707 \emph default 
9708
9709 \begin_inset LatexCommand \index{volatile}
9710
9711 \end_inset 
9712
9713 .
9714  
9715 \layout Standard
9716
9717 If the access to these variables is not 
9718 \emph on 
9719 atomic
9720 \begin_inset LatexCommand \index{atomic access}
9721
9722 \end_inset 
9723
9724
9725 \emph default 
9726  (i.e.
9727  the processor needs more than one instruction for the access and could
9728  be interrupted while accessing the variable) the interrupt must disabled
9729  during the access to avoid inconsistent data.
9730  Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
9731  and should be protected by disabling interrupts.
9732  You're not automatically on the safe side if you use 8 bit variables though.
9733  We need an example here: f.e.
9734  on the 8051 the harmless looking 
9735 \begin_inset Quotes srd
9736 \end_inset 
9737
9738
9739 \family typewriter 
9740 flags\SpecialChar ~
9741 |=\SpecialChar ~
9742 0x80;
9743 \family default 
9744
9745 \begin_inset Quotes sld
9746 \end_inset 
9747
9748  is not atomic if 
9749 \family typewriter 
9750 flags
9751 \family default 
9752  resides in xdata.
9753  Setting 
9754 \begin_inset Quotes srd
9755 \end_inset 
9756
9757
9758 \family typewriter 
9759 flags\SpecialChar ~
9760 |=\SpecialChar ~
9761 0x40;
9762 \family default 
9763
9764 \begin_inset Quotes sld
9765 \end_inset 
9766
9767  from within an interrupt routine might get lost if the interrupt occurs
9768  at the wrong time.
9769  
9770 \begin_inset Quotes sld
9771 \end_inset 
9772
9773
9774 \family typewriter 
9775 counter\SpecialChar ~
9776 +=\SpecialChar ~
9777 8;
9778 \family default 
9779
9780 \begin_inset Quotes srd
9781 \end_inset 
9782
9783  is not atomic on the 8051 even if 
9784 \family typewriter 
9785 counter
9786 \family default 
9787  is located in data memory.
9788  Bugs like these are hard to reproduce and can cause a lot of trouble.
9789  
9790 \layout Standard
9791
9792 A special note here, int (16 bit) and long (32 bit) integer division
9793 \begin_inset LatexCommand \index{Division}
9794
9795 \end_inset 
9796
9797 , multiplication
9798 \begin_inset LatexCommand \index{Multiplication}
9799
9800 \end_inset 
9801
9802  & modulus
9803 \begin_inset LatexCommand \index{Modulus}
9804
9805 \end_inset 
9806
9807  and floating-point
9808 \begin_inset LatexCommand \index{Floating point support}
9809
9810 \end_inset 
9811
9812  operations are implemented using external support routines developed in
9813  ANSI-C.
9814  If an interrupt service routine needs to do any of these operations then
9815  the support routines (as mentioned in a following section) will have to
9816  be recompiled using the
9817 \emph on 
9818  -
9819 \begin_inset ERT
9820 status Collapsed
9821
9822 \layout Standard
9823
9824 \backslash 
9825 /
9826 \end_inset 
9827
9828 -stack-auto
9829 \begin_inset LatexCommand \index{-\/-stack-auto}
9830
9831 \end_inset 
9832
9833
9834 \emph default 
9835  option and the source file will need to be compiled using the 
9836 \emph on 
9837 -
9838 \begin_inset ERT
9839 status Collapsed
9840
9841 \layout Standard
9842
9843 \backslash 
9844 /
9845 \end_inset 
9846
9847 -int-long-reent
9848 \emph default 
9849
9850 \begin_inset LatexCommand \index{-\/-int-long-reent}
9851
9852 \end_inset 
9853
9854  compiler option.
9855 \layout Standard
9856
9857 Calling other functions from an interrupt service routine is not recommended,
9858  avoid it if possible.
9859  Note that when some function is called from an interrupt service routine
9860  it should be preceded by a #pragma\SpecialChar ~
9861 nooverlay
9862 \begin_inset LatexCommand \index{\#pragma nooverlay}
9863
9864 \end_inset 
9865
9866  if it is not reentrant.
9867  Furthermore nonreentrant functions should not be called from the main program
9868  while the interrupt service routine might be active.
9869  
9870 \newline 
9871
9872 \newline 
9873 Also see section 
9874 \begin_inset LatexCommand \ref{sub:Overlaying}
9875
9876 \end_inset 
9877
9878 \SpecialChar ~
9879 about Overlaying and section 
9880 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
9881
9882 \end_inset 
9883
9884 \SpecialChar ~
9885 about Functions using private register banks.
9886 \layout Subsection
9887
9888 MCS51/DS390 Interrupt Service Routines
9889 \layout Standard
9890
9891 Interrupt numbers and the corresponding address & descriptions for the Standard
9892  8051/8052 are listed below.
9893  SDCC will automatically adjust the interrupt vector table to the maximum
9894  interrupt number specified.
9895 \newline 
9896
9897 \layout Standard
9898 \align center 
9899
9900 \begin_inset  Tabular
9901 <lyxtabular version="3" rows="7" columns="3">
9902 <features>
9903 <column alignment="center" valignment="top" leftline="true" width="0in">
9904 <column alignment="center" valignment="top" leftline="true" width="0in">
9905 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0in">
9906 <row topline="true" bottomline="true">
9907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9908 \begin_inset Text
9909
9910 \layout Standard
9911
9912 Interrupt #
9913 \end_inset 
9914 </cell>
9915 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9916 \begin_inset Text
9917
9918 \layout Standard
9919
9920 Description
9921 \end_inset 
9922 </cell>
9923 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9924 \begin_inset Text
9925
9926 \layout Standard
9927
9928 Vector Address
9929 \end_inset 
9930 </cell>
9931 </row>
9932 <row topline="true">
9933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9934 \begin_inset Text
9935
9936 \layout Standard
9937
9938 0
9939 \end_inset 
9940 </cell>
9941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9942 \begin_inset Text
9943
9944 \layout Standard
9945
9946 External 0
9947 \end_inset 
9948 </cell>
9949 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9950 \begin_inset Text
9951
9952 \layout Standard
9953
9954 0x0003
9955 \end_inset 
9956 </cell>
9957 </row>
9958 <row topline="true">
9959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9960 \begin_inset Text
9961
9962 \layout Standard
9963
9964 1
9965 \end_inset 
9966 </cell>
9967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9968 \begin_inset Text
9969
9970 \layout Standard
9971
9972 Timer 0
9973 \end_inset 
9974 </cell>
9975 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9976 \begin_inset Text
9977
9978 \layout Standard
9979
9980 0x000B
9981 \end_inset 
9982 </cell>
9983 </row>
9984 <row topline="true">
9985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9986 \begin_inset Text
9987
9988 \layout Standard
9989
9990 2
9991 \end_inset 
9992 </cell>
9993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9994 \begin_inset Text
9995
9996 \layout Standard
9997
9998 External 1
9999 \end_inset 
10000 </cell>
10001 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10002 \begin_inset Text
10003
10004 \layout Standard
10005
10006 0x0013
10007 \end_inset 
10008 </cell>
10009 </row>
10010 <row topline="true">
10011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10012 \begin_inset Text
10013
10014 \layout Standard
10015
10016 3
10017 \end_inset 
10018 </cell>
10019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10020 \begin_inset Text
10021
10022 \layout Standard
10023
10024 Timer 1
10025 \end_inset 
10026 </cell>
10027 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10028 \begin_inset Text
10029
10030 \layout Standard
10031
10032 0x001B
10033 \end_inset 
10034 </cell>
10035 </row>
10036 <row topline="true">
10037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10038 \begin_inset Text
10039
10040 \layout Standard
10041
10042 4
10043 \end_inset 
10044 </cell>
10045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10046 \begin_inset Text
10047
10048 \layout Standard
10049
10050 Serial
10051 \end_inset 
10052 </cell>
10053 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10054 \begin_inset Text
10055
10056 \layout Standard
10057
10058 0x0023
10059 \end_inset 
10060 </cell>
10061 </row>
10062 <row topline="true" bottomline="true">
10063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10064 \begin_inset Text
10065
10066 \layout Standard
10067
10068 5
10069 \end_inset 
10070 </cell>
10071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10072 \begin_inset Text
10073
10074 \layout Standard
10075
10076 Timer 2 (8052)
10077 \end_inset 
10078 </cell>
10079 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10080 \begin_inset Text
10081
10082 \layout Standard
10083
10084 0x002B
10085 \end_inset 
10086 </cell>
10087 </row>
10088 </lyxtabular>
10089
10090 \end_inset 
10091
10092
10093 \newline 
10094
10095 \layout Standard
10096
10097 If the interrupt service routine is defined without 
10098 \emph on 
10099 using
10100 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10101
10102 \end_inset 
10103
10104
10105 \emph default 
10106  a register bank or with register bank 0 (
10107 \emph on 
10108 using
10109 \emph default 
10110  0), the compiler will save the registers used by itself on the stack upon
10111  entry and restore them at exit, however if such an interrupt service routine
10112  calls another function then the entire register bank will be saved on the
10113  stack.
10114  This scheme may be advantageous for small interrupt service routines which
10115  have low register usage.
10116 \layout Standard
10117
10118 If the interrupt service routine is defined to be using a specific register
10119  bank then only 
10120 \emph on 
10121 a, b, dptr
10122 \emph default 
10123  & psw are saved and restored, if such an interrupt service routine calls
10124  another function (using another register bank) then the entire register
10125  bank of the called function will be saved on the stack.
10126  This scheme is recommended for larger interrupt service routines.
10127 \layout Subsection
10128
10129 HC08 Interrupt Service Routines
10130 \layout Standard
10131
10132 Since the number of interrupts available is chip specific and the interrupt
10133  vector table always ends at the last byte of memory, the interrupt numbers
10134  corresponds to the interrupt vectors in reverse order of address.
10135  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
10136  2 will use the interrupt vector at 0xfffa, and so on.
10137  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
10138  this way; instead see section 
10139 \begin_inset LatexCommand \ref{sub:Startup-Code}
10140
10141 \end_inset 
10142
10143  for details on customizing startup.
10144 \layout Section
10145
10146 Enabling and Disabling Interrupts
10147 \layout Subsection
10148
10149 Critical Functions and Critical Statements
10150 \layout Standard
10151
10152 A special keyword may be associated with a block or a function declaring
10153  it as 
10154 \emph on 
10155 critical
10156 \emph default 
10157 .
10158  SDCC will generate code to disable all interrupts
10159 \begin_inset LatexCommand \index{interrupt}
10160
10161 \end_inset 
10162
10163  upon entry to a critical function and restore the interrupt enable to the
10164  previous state before returning.
10165  Nesting critical functions will need one additional byte on the stack
10166 \begin_inset LatexCommand \index{stack}
10167
10168 \end_inset 
10169
10170  for each call.
10171 \layout Verse
10172
10173
10174 \family typewriter 
10175 int foo () critical
10176 \begin_inset LatexCommand \index{critical}
10177
10178 \end_inset 
10179
10180  
10181 \newline 
10182
10183 \newline 
10184 \SpecialChar ~
10185 \SpecialChar ~
10186 \SpecialChar ~
10187 \SpecialChar ~
10188 ...
10189  
10190 \newline 
10191 \SpecialChar ~
10192 \SpecialChar ~
10193 \SpecialChar ~
10194 \SpecialChar ~
10195 ...
10196  
10197 \newline 
10198 }
10199 \layout Standard
10200
10201 The critical attribute maybe used with other attributes like 
10202 \emph on 
10203 reentrant.
10204 \emph default 
10205
10206 \newline 
10207 The keyword 
10208 \emph on 
10209 critical
10210 \emph default 
10211  may also be used to disable interrupts more locally:
10212 \layout Verse
10213
10214
10215 \family typewriter 
10216 critical{ i++; }
10217 \layout Standard
10218
10219 More than one statement could have been included in the block.
10220 \layout Subsection
10221
10222 Enabling and Disabling Interrupts directly
10223 \layout Standard
10224
10225 Interrupts
10226 \begin_inset LatexCommand \index{interrupt}
10227
10228 \end_inset 
10229
10230  can also be disabled and enabled directly (8051):
10231 \layout Verse
10232
10233
10234 \family typewriter 
10235 EA = 0;\SpecialChar ~
10236 \SpecialChar ~
10237 \SpecialChar ~
10238 \SpecialChar ~
10239 \SpecialChar ~
10240 \SpecialChar ~
10241 \SpecialChar ~
10242 \SpecialChar ~
10243 \SpecialChar ~
10244 \SpecialChar ~
10245 \SpecialChar ~
10246 \SpecialChar ~
10247 or:\SpecialChar ~
10248 \SpecialChar ~
10249 \SpecialChar ~
10250 \SpecialChar ~
10251 \SpecialChar ~
10252 \SpecialChar ~
10253 \SpecialChar ~
10254 \SpecialChar ~
10255 \SpecialChar ~
10256 \SpecialChar ~
10257 \SpecialChar ~
10258 EA_SAVE = EA;
10259 \layout Verse
10260
10261
10262 \family typewriter 
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 \SpecialChar ~
10288 \SpecialChar ~
10289 \SpecialChar ~
10290 \SpecialChar ~
10291 \SpecialChar ~
10292 \SpecialChar ~
10293 EA = 0;
10294 \layout Verse
10295
10296
10297 \family typewriter 
10298 EA = 1;\SpecialChar ~
10299 \SpecialChar ~
10300 \SpecialChar ~
10301 \SpecialChar ~
10302 \SpecialChar ~
10303 \SpecialChar ~
10304 \SpecialChar ~
10305 \SpecialChar ~
10306 \SpecialChar ~
10307 \SpecialChar ~
10308 \SpecialChar ~
10309 \SpecialChar ~
10310 \SpecialChar ~
10311 \SpecialChar ~
10312 \SpecialChar ~
10313 \SpecialChar ~
10314 \SpecialChar ~
10315 \SpecialChar ~
10316 \SpecialChar ~
10317 \SpecialChar ~
10318 \SpecialChar ~
10319 \SpecialChar ~
10320 \SpecialChar ~
10321 \SpecialChar ~
10322 \SpecialChar ~
10323 \SpecialChar ~
10324 ...
10325 \layout Verse
10326
10327
10328 \family typewriter 
10329 \SpecialChar ~
10330 \SpecialChar ~
10331 \SpecialChar ~
10332 \SpecialChar ~
10333 \SpecialChar ~
10334 \SpecialChar ~
10335 \SpecialChar ~
10336 \SpecialChar ~
10337 \SpecialChar ~
10338 \SpecialChar ~
10339 \SpecialChar ~
10340 \SpecialChar ~
10341 \SpecialChar ~
10342 \SpecialChar ~
10343 \SpecialChar ~
10344 \SpecialChar ~
10345 \SpecialChar ~
10346 \SpecialChar ~
10347 \SpecialChar ~
10348 \SpecialChar ~
10349 \SpecialChar ~
10350 \SpecialChar ~
10351 \SpecialChar ~
10352 \SpecialChar ~
10353 \SpecialChar ~
10354 \SpecialChar ~
10355 \SpecialChar ~
10356 \SpecialChar ~
10357 \SpecialChar ~
10358 \SpecialChar ~
10359 \SpecialChar ~
10360 \SpecialChar ~
10361 \SpecialChar ~
10362 EA = EA_SAVE;
10363 \layout Standard
10364
10365 On other architectures which have seperate opcodes for enabling and disabling
10366  interrupts you might want to make use of defines with inline assembly
10367 \begin_inset LatexCommand \index{Assembler routines}
10368
10369 \end_inset 
10370
10371  (HC08):
10372 \layout Verse
10373
10374
10375 \family typewriter 
10376 #define CLI _asm
10377 \begin_inset LatexCommand \index{\_asm}
10378
10379 \end_inset 
10380
10381 \SpecialChar ~
10382 \SpecialChar ~
10383 cli\SpecialChar ~
10384 \SpecialChar ~
10385 _endasm
10386 \begin_inset LatexCommand \index{\_endasm}
10387
10388 \end_inset 
10389
10390
10391 \layout Verse
10392
10393
10394 \family typewriter 
10395 #define SEI _asm\SpecialChar ~
10396 \SpecialChar ~
10397 sei\SpecialChar ~
10398 \SpecialChar ~
10399 _endasm; 
10400 \layout Verse
10401
10402
10403 \family typewriter 
10404 ...
10405 \layout Standard
10406
10407 Note: it is sometimes sufficient to disable only a specific interrupt source
10408  like f.e.
10409  a timer or serial interrupt by manipulating an 
10410 \emph on 
10411 interrupt mask
10412 \begin_inset LatexCommand \index{interrupt mask}
10413
10414 \end_inset 
10415
10416
10417 \emph default 
10418  register.
10419  
10420 \layout Standard
10421
10422 Usually the time during which interrupts are disabled should be kept as
10423  short as possible.
10424  This minimizes both 
10425 \emph on 
10426 interrupt latency
10427 \emph default 
10428
10429 \begin_inset LatexCommand \index{interrupt latency}
10430
10431 \end_inset 
10432
10433  (the time between the occurrence of the interrupt and the execution of
10434  the first code in the interrupt routine) and 
10435 \emph on 
10436 interrupt jitter
10437 \emph default 
10438
10439 \begin_inset LatexCommand \index{interrupt jitter}
10440
10441 \end_inset 
10442
10443  (the difference between the shortest and the longest interrupt latency).
10444  These really are something different, f.e.
10445  a serial interrupt has to be served before its buffer overruns so it cares
10446  for the maximum interrupt latency, whereas it does not care about jitter.
10447  On a loudspeaker driven via a digital to analog converter which is fed
10448  by an interrupt a latency of a few milliseconds might be tolerable, whereas
10449  a much smaller jitter will be very audible.
10450 \layout Standard
10451
10452 You can reenable interrupts within an interrupt routine and on some architecture
10453 s you can make use of two (or more) levels of 
10454 \emph on 
10455 interrupt priorities
10456 \emph default 
10457
10458 \begin_inset LatexCommand \index{interrupt priority}
10459
10460 \end_inset 
10461
10462 .
10463  On some architectures which don't support interrupt priorities these can
10464  be implemented by manipulating the interrupt mask and reenabling interrupts
10465  within the interrupt routine.
10466  Don't add complexity unless you have to.
10467  
10468 \layout Section
10469
10470 Functions using private register banks
10471 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
10472
10473 \end_inset 
10474
10475  (mcs51/ds390)
10476 \layout Standard
10477
10478 Some architectures have support for quickly changing register sets.
10479  SDCC supports this feature with the 
10480 \emph on 
10481 using
10482 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10483
10484 \end_inset 
10485
10486
10487 \emph default 
10488  attribute (which tells the compiler to use a register bank
10489 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10490
10491 \end_inset 
10492
10493  other than the default bank zero).
10494  It should only be applied to 
10495 \emph on 
10496 interrupt
10497 \begin_inset LatexCommand \index{interrupt}
10498
10499 \end_inset 
10500
10501
10502 \emph default 
10503  functions (see footnote below).
10504  This will in most circumstances make the generated ISR code more efficient
10505  since it will not have to save registers on the stack.
10506 \layout Standard
10507
10508 The 
10509 \emph on 
10510 using
10511 \emph default 
10512  attribute will have no effect on the generated code for a 
10513 \emph on 
10514 non-interrupt
10515 \emph default 
10516  function (but may occasionally be useful anyway
10517 \begin_inset Foot
10518 collapsed false
10519
10520 \layout Standard
10521
10522 possible exception: if a function is called ONLY from 'interrupt' functions
10523  using a particular bank, it can be declared with the same 'using' attribute
10524  as the calling 'interrupt' functions.
10525  For instance, if you have several ISRs using bank one, and all of them
10526  call memcpy(), it might make sense to create a specialized version of memcpy()
10527  'using 1', since this would prevent the ISR from having to save bank zero
10528  to the stack on entry and switch to bank zero before calling the function
10529 \end_inset 
10530
10531 ).
10532 \newline 
10533
10534 \emph on 
10535 (pending: I don't think this has been done yet)
10536 \layout Standard
10537
10538 An 
10539 \emph on 
10540 interrupt
10541 \emph default 
10542  function using a non-zero bank will assume that it can trash that register
10543  bank, and will not save it.
10544  Since high-priority interrupts
10545 \begin_inset LatexCommand \index{interrupt priority}
10546
10547 \end_inset 
10548
10549  can interrupt low-priority ones on the 8051 and friends, this means that
10550  if a high-priority ISR 
10551 \emph on 
10552 using
10553 \emph default 
10554  a particular bank occurs while processing a low-priority ISR 
10555 \emph on 
10556 using
10557 \emph default 
10558  the same bank, terrible and bad things can happen.
10559  To prevent this, no single register bank should be 
10560 \emph on 
10561 used
10562 \emph default 
10563  by both a high priority and a low priority ISR.
10564  This is probably most easily done by having all high priority ISRs use
10565  one bank and all low priority ISRs use another.
10566  If you have an ISR which can change priority at runtime, you're on your
10567  own: I suggest using the default bank zero and taking the small performance
10568  hit.
10569 \layout Standard
10570
10571 It is most efficient if your ISR calls no other functions.
10572  If your ISR must call other functions, it is most efficient if those functions
10573  use the same bank as the ISR (see note 1 below); the next best is if the
10574  called functions use bank zero.
10575  It is very inefficient to call a function using a different, non-zero bank
10576  from an ISR.
10577  
10578 \layout Section
10579
10580 Startup Code
10581 \begin_inset LatexCommand \label{sub:Startup-Code}
10582
10583 \end_inset 
10584
10585
10586 \begin_inset LatexCommand \index{Startup code}
10587
10588 \end_inset 
10589
10590
10591 \layout Subsection
10592
10593 MCS51/DS390 Startup Code
10594 \layout Standard
10595
10596 The compiler inserts a call to the C routine 
10597 \emph on 
10598 _sdcc_external_startup()
10599 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
10600
10601 \end_inset 
10602
10603
10604 \series bold 
10605 \emph default 
10606  
10607 \series default 
10608 at the start of the CODE area.
10609  This routine is in the runtime library
10610 \begin_inset LatexCommand \index{Runtime library}
10611
10612 \end_inset 
10613
10614 .
10615  By default this routine returns 0, if this routine returns a non-zero value,
10616  the static & global variable initialization will be skipped and the function
10617  main will be invoked.
10618  Otherwise static & global variables will be initialized before the function
10619  main is invoked.
10620  You could add a 
10621 \emph on 
10622 _sdcc_external_startup()
10623 \emph default 
10624  routine to your program to override the default if you need to setup hardware
10625  or perform some other critical operation prior to static & global variable
10626  initialization.
10627  On some mcs51 variants xdata has to be explicitly enabled before it can
10628  be accessed, this is the place to do it.
10629  See also the compiler option 
10630 \emph on 
10631 -
10632 \begin_inset ERT
10633 status Collapsed
10634
10635 \layout Standard
10636
10637 \backslash 
10638 /
10639 \end_inset 
10640
10641 -no-xinit
10642 \emph default 
10643 -
10644 \emph on 
10645 opt
10646 \emph default 
10647
10648 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
10649
10650 \end_inset 
10651
10652  and section 
10653 \begin_inset LatexCommand \ref{sub:MCS51-variants}
10654
10655 \end_inset 
10656
10657 \SpecialChar ~
10658 about MCS51-variants.
10659 \layout Subsection
10660
10661 HC08 Startup Code
10662 \layout Standard
10663
10664 The HC08 startup code follows the same scheme as the MCS51 startup code.
10665 \layout Subsection
10666
10667 Z80 Startup Code
10668 \layout Standard
10669
10670 On the Z80 the startup code is inserted by linking with crt0.o which is generated
10671  from sdcc/device/lib/z80/crt0.s.
10672  If you need a different startup code you can use the compiler option 
10673 \emph on 
10674 -
10675 \series bold 
10676 \emph default 
10677
10678 \begin_inset ERT
10679 status Collapsed
10680
10681 \layout Standard
10682
10683 \backslash 
10684 /
10685 \end_inset 
10686
10687
10688 \series default 
10689 \emph on 
10690 -no-std-crt0
10691 \emph default 
10692
10693 \begin_inset LatexCommand \index{-\/-no-std-crt0}
10694
10695 \end_inset 
10696
10697  and provide your own crt0.o.
10698  
10699 \layout Section
10700
10701 Inline Assembler Code
10702 \begin_inset LatexCommand \index{Assembler routines}
10703
10704 \end_inset 
10705
10706
10707 \layout Subsection
10708
10709 A Step by Step Introduction
10710 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
10711
10712 \end_inset 
10713
10714
10715 \layout Standard
10716
10717 Starting from a small snippet of c-code this example shows for the MCS51
10718  how to use inline assembly, access variables, a function parameter and
10719  an array in xdata memory.
10720  The example uses an MCS51 here but is easily adapted for other architectures.
10721  This is a buffer routine which should be optimized:
10722 \layout Verse
10723
10724
10725 \family typewriter 
10726 \size footnotesize 
10727 unsigned char far
10728 \begin_inset LatexCommand \index{far (storage class)}
10729
10730 \end_inset 
10731
10732  at
10733 \begin_inset LatexCommand \index{at}
10734
10735 \end_inset 
10736
10737  0x7f00 buf[0x100];
10738 \begin_inset LatexCommand \index{Aligned array}
10739
10740 \end_inset 
10741
10742
10743 \newline 
10744 unsigned char head,tail;
10745 \newline 
10746
10747 \newline 
10748 void to_buffer( unsigned char c ) 
10749 \newline 
10750 {
10751 \newline 
10752 \SpecialChar ~
10753 \SpecialChar ~
10754 \SpecialChar ~
10755 \SpecialChar ~
10756 if( head != tail-1 ) 
10757 \newline 
10758 \SpecialChar ~
10759 \SpecialChar ~
10760 \SpecialChar ~
10761 \SpecialChar ~
10762 \SpecialChar ~
10763 \SpecialChar ~
10764 \SpecialChar ~
10765 \SpecialChar ~
10766 buf[ head++ ] = c; 
10767 \newline 
10768
10769 \layout Standard
10770
10771 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
10772  then a corresponding buffer.asm file is generated.
10773  We define a new function 
10774 \family typewriter 
10775 to_buffer_asm()
10776 \family default 
10777  in file buffer.c in which we cut and paste the generated code, removing
10778  unwanted comments and some ':'.
10779  Then add 
10780 \begin_inset Quotes sld
10781 \end_inset 
10782
10783 _asm
10784 \begin_inset Quotes srd
10785 \end_inset 
10786
10787  and 
10788 \begin_inset Quotes sld
10789 \end_inset 
10790
10791 _endasm;
10792 \begin_inset Quotes srd
10793 \end_inset 
10794
10795  to the beginning and the end of the function body:
10796 \layout Verse
10797
10798
10799 \family typewriter 
10800 \size footnotesize 
10801 /* With a cut and paste from the .asm file, we have something to start with.
10802 \newline 
10803 \SpecialChar ~
10804 \SpecialChar ~
10805 \SpecialChar ~
10806 The function is not yet OK! (registers aren't saved) */ 
10807 \newline 
10808 void to_buffer_asm( unsigned char c ) 
10809 \newline 
10810
10811 \newline 
10812 \SpecialChar ~
10813 \SpecialChar ~
10814 \SpecialChar ~
10815 \SpecialChar ~
10816 _asm
10817 \begin_inset LatexCommand \index{\_asm}
10818
10819 \end_inset 
10820
10821
10822 \newline 
10823 \SpecialChar ~
10824 \SpecialChar ~
10825 \SpecialChar ~
10826 \SpecialChar ~
10827 mov\SpecialChar ~
10828 \SpecialChar ~
10829 r2,dpl 
10830 \newline 
10831 ;buffer.c if( head != tail-1 ) 
10832 \newline 
10833 \SpecialChar ~
10834 \SpecialChar ~
10835 \SpecialChar ~
10836 \SpecialChar ~
10837 mov\SpecialChar ~
10838 \SpecialChar ~
10839 a,_tail 
10840 \newline 
10841 \SpecialChar ~
10842 \SpecialChar ~
10843 \SpecialChar ~
10844 \SpecialChar ~
10845 dec\SpecialChar ~
10846 \SpecialChar ~
10847
10848 \newline 
10849 \SpecialChar ~
10850 \SpecialChar ~
10851 \SpecialChar ~
10852 \SpecialChar ~
10853 mov\SpecialChar ~
10854 \SpecialChar ~
10855 r3,a 
10856 \newline 
10857 \SpecialChar ~
10858 \SpecialChar ~
10859 \SpecialChar ~
10860 \SpecialChar ~
10861 mov\SpecialChar ~
10862 \SpecialChar ~
10863 a,_head 
10864 \newline 
10865 \SpecialChar ~
10866 \SpecialChar ~
10867 \SpecialChar ~
10868 \SpecialChar ~
10869 cjne a,ar3,00106$ 
10870 \newline 
10871 \SpecialChar ~
10872 \SpecialChar ~
10873 \SpecialChar ~
10874 \SpecialChar ~
10875 ret
10876 \newline 
10877 00106$: 
10878 \newline 
10879 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
10880 \begin_inset LatexCommand \index{Aligned array}
10881
10882 \end_inset 
10883
10884
10885 \newline 
10886 \SpecialChar ~
10887 \SpecialChar ~
10888 \SpecialChar ~
10889 \SpecialChar ~
10890 mov\SpecialChar ~
10891 \SpecialChar ~
10892 r3,_head 
10893 \newline 
10894 \SpecialChar ~
10895 \SpecialChar ~
10896 \SpecialChar ~
10897 \SpecialChar ~
10898 inc\SpecialChar ~
10899 \SpecialChar ~
10900 _head 
10901 \newline 
10902 \SpecialChar ~
10903 \SpecialChar ~
10904 \SpecialChar ~
10905 \SpecialChar ~
10906 mov\SpecialChar ~
10907 \SpecialChar ~
10908 dpl,r3 
10909 \newline 
10910 \SpecialChar ~
10911 \SpecialChar ~
10912 \SpecialChar ~
10913 \SpecialChar ~
10914 mov\SpecialChar ~
10915 \SpecialChar ~
10916 dph,#(_buf >> 8) 
10917 \newline 
10918 \SpecialChar ~
10919 \SpecialChar ~
10920 \SpecialChar ~
10921 \SpecialChar ~
10922 mov\SpecialChar ~
10923 \SpecialChar ~
10924 a,r2 
10925 \newline 
10926 \SpecialChar ~
10927 \SpecialChar ~
10928 \SpecialChar ~
10929 \SpecialChar ~
10930 movx @dptr,a 
10931 \newline 
10932 00103$: 
10933 \newline 
10934 \SpecialChar ~
10935 \SpecialChar ~
10936 \SpecialChar ~
10937 \SpecialChar ~
10938 ret
10939 \newline 
10940 \SpecialChar ~
10941 \SpecialChar ~
10942 \SpecialChar ~
10943 \SpecialChar ~
10944 _endasm;
10945 \newline 
10946
10947 \layout Standard
10948
10949 The new file buffer.c should compile with only one warning about the unreferenced
10950  function argument 'c'.
10951  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
10952  (1) and finally have:
10953 \layout Verse
10954
10955
10956 \family typewriter 
10957 \size footnotesize 
10958 unsigned char far at 0x7f00 buf[0x100];
10959 \newline 
10960 unsigned char head,tail;
10961 \newline 
10962 #define USE_ASSEMBLY (1)
10963 \newline 
10964
10965 \newline 
10966 #if !USE_ASSEMBLY
10967 \newline 
10968
10969 \newline 
10970 void to_buffer( unsigned char c )
10971 \newline 
10972 {
10973 \newline 
10974 \SpecialChar ~
10975 \SpecialChar ~
10976 \SpecialChar ~
10977 \SpecialChar ~
10978 if( head != tail-1 )
10979 \newline 
10980 \SpecialChar ~
10981 \SpecialChar ~
10982 \SpecialChar ~
10983 \SpecialChar ~
10984 \SpecialChar ~
10985 \SpecialChar ~
10986 \SpecialChar ~
10987 \SpecialChar ~
10988 buf[ head++ ] = c;
10989 \newline 
10990 }
10991 \newline 
10992
10993 \newline 
10994 #else
10995 \newline 
10996
10997 \newline 
10998 void to_buffer( unsigned char c )
10999 \newline 
11000 {
11001 \newline 
11002 \SpecialChar ~
11003 \SpecialChar ~
11004 \SpecialChar ~
11005 \SpecialChar ~
11006 c; // to avoid warning: unreferenced function argument
11007 \newline 
11008 \SpecialChar ~
11009 \SpecialChar ~
11010 \SpecialChar ~
11011 \SpecialChar ~
11012 _asm
11013 \begin_inset LatexCommand \index{\_asm}
11014
11015 \end_inset 
11016
11017
11018 \newline 
11019 \SpecialChar ~
11020 \SpecialChar ~
11021 \SpecialChar ~
11022 \SpecialChar ~
11023 \SpecialChar ~
11024 \SpecialChar ~
11025 \SpecialChar ~
11026 \SpecialChar ~
11027 ; save used registers here.
11028  
11029 \newline 
11030 \SpecialChar ~
11031 \SpecialChar ~
11032 \SpecialChar ~
11033 \SpecialChar ~
11034 \SpecialChar ~
11035 \SpecialChar ~
11036 \SpecialChar ~
11037 \SpecialChar ~
11038 ; If we were still using r2,r3 we would have to push them here.
11039  
11040 \newline 
11041 ; if( head != tail-1 )
11042 \newline 
11043 \SpecialChar ~
11044 \SpecialChar ~
11045 \SpecialChar ~
11046 \SpecialChar ~
11047 \SpecialChar ~
11048 \SpecialChar ~
11049 \SpecialChar ~
11050 \SpecialChar ~
11051 mov\SpecialChar ~
11052  a,_tail
11053 \newline 
11054 \SpecialChar ~
11055 \SpecialChar ~
11056 \SpecialChar ~
11057 \SpecialChar ~
11058 \SpecialChar ~
11059 \SpecialChar ~
11060 \SpecialChar ~
11061 \SpecialChar ~
11062 dec\SpecialChar ~
11063  a
11064 \newline 
11065 \SpecialChar ~
11066 \SpecialChar ~
11067 \SpecialChar ~
11068 \SpecialChar ~
11069 \SpecialChar ~
11070 \SpecialChar ~
11071 \SpecialChar ~
11072 \SpecialChar ~
11073 xrl\SpecialChar ~
11074  a,_head
11075 \newline 
11076 \SpecialChar ~
11077 \SpecialChar ~
11078 \SpecialChar ~
11079 \SpecialChar ~
11080 \SpecialChar ~
11081 \SpecialChar ~
11082 \SpecialChar ~
11083 \SpecialChar ~
11084 ; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
11085 \newline 
11086 \SpecialChar ~
11087 \SpecialChar ~
11088 \SpecialChar ~
11089 \SpecialChar ~
11090 \SpecialChar ~
11091 \SpecialChar ~
11092 \SpecialChar ~
11093 \SpecialChar ~
11094 jz\SpecialChar ~
11095 \SpecialChar ~
11096  t_b_end$
11097 \newline 
11098 \SpecialChar ~
11099 \SpecialChar ~
11100 \SpecialChar ~
11101 \SpecialChar ~
11102 \SpecialChar ~
11103 \SpecialChar ~
11104 \SpecialChar ~
11105 \SpecialChar ~
11106 ;
11107 \newline 
11108 ; buf[ head++ ] = c;
11109 \newline 
11110 \SpecialChar ~
11111 \SpecialChar ~
11112 \SpecialChar ~
11113 \SpecialChar ~
11114 \SpecialChar ~
11115 \SpecialChar ~
11116 \SpecialChar ~
11117 \SpecialChar ~
11118 mov\SpecialChar ~
11119  a,dpl \SpecialChar ~
11120 \SpecialChar ~
11121 \SpecialChar ~
11122 \SpecialChar ~
11123 \SpecialChar ~
11124 \SpecialChar ~
11125 \SpecialChar ~
11126 ; dpl holds lower byte of function argument
11127 \newline 
11128 \SpecialChar ~
11129 \SpecialChar ~
11130 \SpecialChar ~
11131 \SpecialChar ~
11132 \SpecialChar ~
11133 \SpecialChar ~
11134 \SpecialChar ~
11135 \SpecialChar ~
11136 mov\SpecialChar ~
11137  dpl,_head \SpecialChar ~
11138 \SpecialChar ~
11139 \SpecialChar ~
11140 ; buf is 0x100 byte aligned so head can be used directly
11141 \newline 
11142 \SpecialChar ~
11143 \SpecialChar ~
11144 \SpecialChar ~
11145 \SpecialChar ~
11146 \SpecialChar ~
11147 \SpecialChar ~
11148 \SpecialChar ~
11149 \SpecialChar ~
11150 mov\SpecialChar ~
11151  dph,#(_buf>>8)
11152 \newline 
11153 \SpecialChar ~
11154 \SpecialChar ~
11155 \SpecialChar ~
11156 \SpecialChar ~
11157 \SpecialChar ~
11158 \SpecialChar ~
11159 \SpecialChar ~
11160 \SpecialChar ~
11161 movx @dptr,a
11162 \newline 
11163 \SpecialChar ~
11164 \SpecialChar ~
11165 \SpecialChar ~
11166 \SpecialChar ~
11167 \SpecialChar ~
11168 \SpecialChar ~
11169 \SpecialChar ~
11170 \SpecialChar ~
11171 inc \SpecialChar ~
11172 _head
11173 \newline 
11174 \SpecialChar ~
11175 \SpecialChar ~
11176 \SpecialChar ~
11177 \SpecialChar ~
11178 \SpecialChar ~
11179 \SpecialChar ~
11180 \SpecialChar ~
11181 \SpecialChar ~
11182 ; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)
11183 \newline 
11184 t_b_end$:
11185 \newline 
11186 \SpecialChar ~
11187 \SpecialChar ~
11188 \SpecialChar ~
11189 \SpecialChar ~
11190 \SpecialChar ~
11191 \SpecialChar ~
11192 \SpecialChar ~
11193 \SpecialChar ~
11194 ; restore used registers here 
11195 \newline 
11196 \SpecialChar ~
11197 \SpecialChar ~
11198 \SpecialChar ~
11199 \SpecialChar ~
11200 _endasm;
11201 \newline 
11202 }
11203 \newline 
11204 #endif
11205 \layout Standard
11206
11207 The inline assembler code can contain any valid code understood by the assembler
11208 , this includes any assembler directives and comment lines
11209 \begin_inset Foot
11210 collapsed false
11211
11212 \layout Standard
11213
11214 The assembler does not like some characters like ':' or ''' in comments.
11215  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
11216 \end_inset 
11217
11218 .
11219  The compiler does not do any validation of the code within the 
11220 \family typewriter 
11221 _asm
11222 \begin_inset LatexCommand \index{\_asm}
11223
11224 \end_inset 
11225
11226  ...
11227  _endasm;
11228 \family default 
11229  keyword pair.
11230  Specifically it will not know which registers are used and thus register
11231  pushing/popping
11232 \begin_inset LatexCommand \index{push/pop}
11233
11234 \end_inset 
11235
11236  has to be done manually.
11237  
11238 \layout Standard
11239
11240 It is recommended that each assembly instruction (including labels) be placed
11241  in a separate line (as the example shows).
11242  When the -
11243 \begin_inset ERT
11244 status Collapsed
11245
11246 \layout Standard
11247
11248 \backslash 
11249 /
11250 \end_inset 
11251
11252 -
11253 \emph on 
11254 peep-asm
11255 \begin_inset LatexCommand \index{-\/-peep-asm}
11256
11257 \end_inset 
11258
11259
11260 \emph default 
11261  command line option is used, the inline assembler code will be passed through
11262  the peephole optimizer
11263 \begin_inset LatexCommand \index{Peephole optimizer}
11264
11265 \end_inset 
11266
11267 .
11268  There are only a few (if any) cases where this option makes sense, it might
11269  cause some unexpected changes in the inline assembler code.
11270  Please go through the peephole optimizer rules defined in file 
11271 \emph on 
11272 SDCCpeeph.def
11273 \emph default 
11274  before using this option.
11275 \layout Subsection
11276
11277 Naked Functions
11278 \begin_inset LatexCommand \label{sub:Naked-Functions}
11279
11280 \end_inset 
11281
11282
11283 \begin_inset LatexCommand \index{Naked functions}
11284
11285 \end_inset 
11286
11287
11288 \layout Standard
11289
11290 A special keyword may be associated with a function declaring it as 
11291 \emph on 
11292 _naked
11293 \begin_inset LatexCommand \index{\_naked}
11294
11295 \end_inset 
11296
11297 .
11298  
11299 \emph default 
11300 The 
11301 \emph on 
11302 _naked
11303 \emph default 
11304  function modifier attribute prevents the compiler from generating prologue
11305 \begin_inset LatexCommand \index{function prologue}
11306
11307 \end_inset 
11308
11309  and epilogue
11310 \begin_inset LatexCommand \index{function epilogue}
11311
11312 \end_inset 
11313
11314  code for that function.
11315  This means that the user is entirely responsible for such things as saving
11316  any registers that may need to be preserved, selecting the proper register
11317  bank, generating the 
11318 \emph on 
11319 return
11320 \emph default 
11321  instruction at the end, etc.
11322  Practically, this means that the contents of the function must be written
11323  in inline assembler.
11324  This is particularly useful for interrupt functions, which can have a large
11325  (and often unnecessary) prologue/epilogue.
11326  For example, compare the code generated by these two functions:
11327 \layout Verse
11328
11329
11330 \family typewriter 
11331 volatile
11332 \begin_inset LatexCommand \index{volatile}
11333
11334 \end_inset 
11335
11336  data unsigned char counter;
11337 \newline 
11338
11339 \newline 
11340 void simpleInterrupt(void) interrupt
11341 \begin_inset LatexCommand \index{interrupt}
11342
11343 \end_inset 
11344
11345  1
11346 \newline 
11347 {
11348 \newline 
11349 \SpecialChar ~
11350 \SpecialChar ~
11351 \SpecialChar ~
11352 \SpecialChar ~
11353 counter++;
11354 \newline 
11355 }
11356 \newline 
11357
11358 \newline 
11359 void nakedInterrupt(void) interrupt 2 _naked
11360 \newline 
11361 {
11362 \newline 
11363 \SpecialChar ~
11364 \SpecialChar ~
11365 \SpecialChar ~
11366 \SpecialChar ~
11367 _asm
11368 \begin_inset LatexCommand \index{\_asm}
11369
11370 \end_inset 
11371
11372
11373 \newline 
11374 \SpecialChar ~
11375 \SpecialChar ~
11376 \SpecialChar ~
11377 \SpecialChar ~
11378 \SpecialChar ~
11379 \SpecialChar ~
11380 inc\SpecialChar ~
11381 \SpecialChar ~
11382 \SpecialChar ~
11383 \SpecialChar ~
11384 \SpecialChar ~
11385 _counter ; does not change flags, no need to save psw
11386 \newline 
11387 \SpecialChar ~
11388 \SpecialChar ~
11389 \SpecialChar ~
11390 \SpecialChar ~
11391 \SpecialChar ~
11392 \SpecialChar ~
11393 reti\SpecialChar ~
11394 \SpecialChar ~
11395 \SpecialChar ~
11396 \SpecialChar ~
11397 ; MUST explicitly include ret or reti in _naked function.
11398 \newline 
11399 \SpecialChar ~
11400 \SpecialChar ~
11401 \SpecialChar ~
11402 \SpecialChar ~
11403 _endasm
11404 \begin_inset LatexCommand \index{\_endasm}
11405
11406 \end_inset 
11407
11408 ;
11409 \newline 
11410 }
11411 \layout Standard
11412
11413 For an 8051 target, the generated simpleInterrupt looks like:
11414 \layout Verse
11415
11416
11417 \family typewriter 
11418 _simpleInterrupt:
11419 \newline 
11420 \SpecialChar ~
11421 \SpecialChar ~
11422 \SpecialChar ~
11423 \SpecialChar ~
11424 push\SpecialChar ~
11425 \SpecialChar ~
11426 \SpecialChar ~
11427 \SpecialChar ~
11428 acc
11429 \newline 
11430 \SpecialChar ~
11431 \SpecialChar ~
11432 \SpecialChar ~
11433 \SpecialChar ~
11434 push\SpecialChar ~
11435 \SpecialChar ~
11436 \SpecialChar ~
11437 \SpecialChar ~
11438 b
11439 \newline 
11440 \SpecialChar ~
11441 \SpecialChar ~
11442 \SpecialChar ~
11443 \SpecialChar ~
11444 push\SpecialChar ~
11445 \SpecialChar ~
11446 \SpecialChar ~
11447 \SpecialChar ~
11448 dpl
11449 \newline 
11450 \SpecialChar ~
11451 \SpecialChar ~
11452 \SpecialChar ~
11453 \SpecialChar ~
11454 push\SpecialChar ~
11455 \SpecialChar ~
11456 \SpecialChar ~
11457 \SpecialChar ~
11458 dph
11459 \newline 
11460 \SpecialChar ~
11461 \SpecialChar ~
11462 \SpecialChar ~
11463 \SpecialChar ~
11464 push\SpecialChar ~
11465 \SpecialChar ~
11466 \SpecialChar ~
11467 \SpecialChar ~
11468 psw
11469 \newline 
11470 \SpecialChar ~
11471 \SpecialChar ~
11472 \SpecialChar ~
11473 \SpecialChar ~
11474 mov\SpecialChar ~
11475 \SpecialChar ~
11476 \SpecialChar ~
11477 \SpecialChar ~
11478 \SpecialChar ~
11479 psw,#0x00
11480 \newline 
11481 \SpecialChar ~
11482 \SpecialChar ~
11483 \SpecialChar ~
11484 \SpecialChar ~
11485 inc\SpecialChar ~
11486 \SpecialChar ~
11487 \SpecialChar ~
11488 \SpecialChar ~
11489 \SpecialChar ~
11490 _counter
11491 \newline 
11492 \SpecialChar ~
11493 \SpecialChar ~
11494 \SpecialChar ~
11495 \SpecialChar ~
11496 pop\SpecialChar ~
11497 \SpecialChar ~
11498 \SpecialChar ~
11499 \SpecialChar ~
11500 \SpecialChar ~
11501 psw
11502 \newline 
11503 \SpecialChar ~
11504 \SpecialChar ~
11505 \SpecialChar ~
11506 \SpecialChar ~
11507 pop\SpecialChar ~
11508 \SpecialChar ~
11509 \SpecialChar ~
11510 \SpecialChar ~
11511 \SpecialChar ~
11512 dph
11513 \newline 
11514 \SpecialChar ~
11515 \SpecialChar ~
11516 \SpecialChar ~
11517 \SpecialChar ~
11518 pop\SpecialChar ~
11519 \SpecialChar ~
11520 \SpecialChar ~
11521 \SpecialChar ~
11522 \SpecialChar ~
11523 dpl
11524 \newline 
11525 \SpecialChar ~
11526 \SpecialChar ~
11527 \SpecialChar ~
11528 \SpecialChar ~
11529 pop\SpecialChar ~
11530 \SpecialChar ~
11531 \SpecialChar ~
11532 \SpecialChar ~
11533 \SpecialChar ~
11534 b
11535 \newline 
11536 \SpecialChar ~
11537 \SpecialChar ~
11538 \SpecialChar ~
11539 \SpecialChar ~
11540 pop\SpecialChar ~
11541 \SpecialChar ~
11542 \SpecialChar ~
11543 \SpecialChar ~
11544 \SpecialChar ~
11545 acc
11546 \newline 
11547 \SpecialChar ~
11548 \SpecialChar ~
11549 \SpecialChar ~
11550 \SpecialChar ~
11551 reti
11552 \layout Standard
11553
11554 whereas nakedInterrupt looks like:
11555 \layout Verse
11556
11557
11558 \family typewriter 
11559 _nakedInterrupt:
11560 \newline 
11561 \SpecialChar ~
11562 \SpecialChar ~
11563 \SpecialChar ~
11564 \SpecialChar ~
11565 inc\SpecialChar ~
11566 \SpecialChar ~
11567 \SpecialChar ~
11568 \SpecialChar ~
11569 _counter ; does not change flags, no need to save psw
11570 \newline 
11571 \SpecialChar ~
11572 \SpecialChar ~
11573 \SpecialChar ~
11574 \SpecialChar ~
11575 reti\SpecialChar ~
11576 \SpecialChar ~
11577 \SpecialChar ~
11578 \SpecialChar ~
11579 \SpecialChar ~
11580 \SpecialChar ~
11581 \SpecialChar ~
11582 \SpecialChar ~
11583 \SpecialChar ~
11584 \SpecialChar ~
11585 \SpecialChar ~
11586 \SpecialChar ~
11587 ; MUST explicitly include ret or reti in _naked function
11588 \layout Standard
11589
11590 The related directive #pragma exclude
11591 \begin_inset LatexCommand \index{\#pragma exclude}
11592
11593 \end_inset 
11594
11595  allows a more fine grained control over pushing & popping
11596 \begin_inset LatexCommand \index{push/pop}
11597
11598 \end_inset 
11599
11600  the registers.
11601 \layout Standard
11602
11603 While there is nothing preventing you from writing C code inside a 
11604 \family typewriter 
11605 _naked
11606 \family default 
11607  function, there are many ways to shoot yourself in the foot doing this,
11608  and it is recommended that you stick to inline assembler.
11609 \layout Subsection
11610
11611 Use of Labels within Inline Assembler
11612 \layout Standard
11613
11614 SDCC allows the use of in-line assembler with a few restrictions regarding
11615  labels.
11616  In older versions of the compiler all labels defined within inline assembler
11617  code 
11618 \emph on 
11619 had to be
11620 \emph default 
11621  of the form 
11622 \emph on 
11623 nnnnn$
11624 \emph default 
11625  where nnnn is a number less than 100 (which implies a limit of utmost 100
11626  inline assembler labels 
11627 \emph on 
11628 per function
11629 \emph default 
11630 \noun on 
11631 )
11632 \noun default 
11633 .
11634  
11635 \layout Verse
11636
11637
11638 \family typewriter 
11639 _asm
11640 \begin_inset LatexCommand \index{\_asm}
11641
11642 \end_inset 
11643
11644  
11645 \newline 
11646 \SpecialChar ~
11647 \SpecialChar ~
11648 \SpecialChar ~
11649 \SpecialChar ~
11650 mov\SpecialChar ~
11651 \SpecialChar ~
11652 \SpecialChar ~
11653 \SpecialChar ~
11654 \SpecialChar ~
11655 b,#10 
11656 \newline 
11657 00001$: 
11658 \newline 
11659 \SpecialChar ~
11660 \SpecialChar ~
11661 \SpecialChar ~
11662 \SpecialChar ~
11663 djnz\SpecialChar ~
11664 \SpecialChar ~
11665 \SpecialChar ~
11666 \SpecialChar ~
11667 b,00001$ 
11668 \newline 
11669 _endasm
11670 \begin_inset LatexCommand \index{\_endasm}
11671
11672 \end_inset 
11673
11674  ;
11675 \layout Standard
11676
11677 Inline assembler code cannot reference any C-Labels, however it can reference
11678  labels
11679 \begin_inset LatexCommand \index{Labels}
11680
11681 \end_inset 
11682
11683  defined by the inline assembler, e.g.:
11684 \layout Verse
11685
11686
11687 \family typewriter 
11688 foo() { 
11689 \newline 
11690 \SpecialChar ~
11691 \SpecialChar ~
11692 \SpecialChar ~
11693 \SpecialChar ~
11694 /* some c code */ 
11695 \newline 
11696 \SpecialChar ~
11697 \SpecialChar ~
11698 \SpecialChar ~
11699 \SpecialChar ~
11700 _asm 
11701 \newline 
11702 \SpecialChar ~
11703 \SpecialChar ~
11704 \SpecialChar ~
11705 \SpecialChar ~
11706 \SpecialChar ~
11707 \SpecialChar ~
11708 ; some assembler code 
11709 \newline 
11710 \SpecialChar ~
11711 \SpecialChar ~
11712 \SpecialChar ~
11713 \SpecialChar ~
11714 \SpecialChar ~
11715 \SpecialChar ~
11716 ljmp $0003 
11717 \newline 
11718 \SpecialChar ~
11719 \SpecialChar ~
11720 \SpecialChar ~
11721 \SpecialChar ~
11722 _endasm; 
11723 \newline 
11724 \SpecialChar ~
11725 \SpecialChar ~
11726 \SpecialChar ~
11727 \SpecialChar ~
11728 /* some more c code */ 
11729 \newline 
11730 clabel:\SpecialChar ~
11731 \SpecialChar ~
11732 /* inline assembler cannot reference this label */ 
11733 \newline 
11734 \SpecialChar ~
11735 \SpecialChar ~
11736 \SpecialChar ~
11737 \SpecialChar ~
11738 _asm
11739 \newline 
11740 \SpecialChar ~
11741 \SpecialChar ~
11742 \SpecialChar ~
11743 \SpecialChar ~
11744 $0003: ;label (can be referenced by inline assembler only) 
11745 \newline 
11746 \SpecialChar ~
11747 \SpecialChar ~
11748 \SpecialChar ~
11749 \SpecialChar ~
11750 _endasm ; 
11751 \newline 
11752 \SpecialChar ~
11753 \SpecialChar ~
11754 \SpecialChar ~
11755 \SpecialChar ~
11756 /* some more c code */
11757 \newline 
11758 }
11759 \layout Standard
11760
11761 In other words inline assembly code can access labels defined in inline
11762  assembly within the scope of the function.
11763  The same goes the other way, i.e.
11764  labels defines in inline assembly can not be accessed by C statements.
11765 \layout Section
11766
11767 Interfacing with Assembler Code
11768 \begin_inset LatexCommand \index{Assembler routines}
11769
11770 \end_inset 
11771
11772
11773 \layout Subsection
11774
11775 Global Registers used for Parameter Passing
11776 \begin_inset LatexCommand \index{Parameter passing}
11777
11778 \end_inset 
11779
11780
11781 \layout Standard
11782
11783 The compiler always uses the global registers 
11784 \emph on 
11785 DPL, DPH
11786 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
11787
11788 \end_inset 
11789
11790
11791 \begin_inset LatexCommand \index{DPTR}
11792
11793 \end_inset 
11794
11795 , B
11796 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
11797
11798 \end_inset 
11799
11800  
11801 \emph default 
11802 and
11803 \emph on 
11804  ACC
11805 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
11806
11807 \end_inset 
11808
11809
11810 \emph default 
11811  to pass the first parameter to a routine.
11812  The second parameter onwards is either allocated on the stack (for reentrant
11813  routines or if -
11814 \begin_inset ERT
11815 status Collapsed
11816
11817 \layout Standard
11818
11819 \backslash 
11820 /
11821 \end_inset 
11822
11823 -stack-auto is used) or in data / xdata memory (depending on the memory
11824  model).
11825  
11826 \layout Subsection
11827
11828 Assembler Routine (non-reentrant)
11829 \layout Standard
11830
11831 In the following example
11832 \begin_inset LatexCommand \index{reentrant}
11833
11834 \end_inset 
11835
11836
11837 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
11838
11839 \end_inset 
11840
11841  the function c_func calls an assembler routine asm_func, which takes two
11842  parameters
11843 \begin_inset LatexCommand \index{function parameter}
11844
11845 \end_inset 
11846
11847 .
11848 \layout Verse
11849
11850
11851 \family typewriter 
11852 extern int asm_func(unsigned char, unsigned char);
11853 \newline 
11854
11855 \newline 
11856 int c_func (unsigned char i, unsigned char j)
11857 \newline 
11858 {
11859 \newline 
11860 \SpecialChar ~
11861 \SpecialChar ~
11862 \SpecialChar ~
11863 \SpecialChar ~
11864 return asm_func(i,j);
11865 \newline 
11866 }
11867 \newline 
11868
11869 \newline 
11870 int main()
11871 \newline 
11872 {
11873 \newline 
11874 \SpecialChar ~
11875 \SpecialChar ~
11876 \SpecialChar ~
11877 \SpecialChar ~
11878 return c_func(10,9);
11879 \newline 
11880 }
11881 \layout Standard
11882
11883 The corresponding assembler function is:
11884 \layout Verse
11885
11886
11887 \family typewriter 
11888 .globl _asm_func_PARM_2 
11889 \newline 
11890 \SpecialChar ~
11891 \SpecialChar ~
11892 \SpecialChar ~
11893 \SpecialChar ~
11894 \SpecialChar ~
11895 \SpecialChar ~
11896 \SpecialChar ~
11897 \SpecialChar ~
11898 .globl _asm_func 
11899 \newline 
11900 \SpecialChar ~
11901 \SpecialChar ~
11902 \SpecialChar ~
11903 \SpecialChar ~
11904 \SpecialChar ~
11905 \SpecialChar ~
11906 \SpecialChar ~
11907 \SpecialChar ~
11908 .area OSEG 
11909 \newline 
11910 _asm_func_PARM_2:
11911 \newline 
11912 \SpecialChar ~
11913 \SpecialChar ~
11914 \SpecialChar ~
11915 \SpecialChar ~
11916 \SpecialChar ~
11917 \SpecialChar ~
11918 \SpecialChar ~
11919 \SpecialChar ~
11920 .ds    1 
11921 \newline 
11922 \SpecialChar ~
11923 \SpecialChar ~
11924 \SpecialChar ~
11925 \SpecialChar ~
11926 \SpecialChar ~
11927 \SpecialChar ~
11928 \SpecialChar ~
11929 \SpecialChar ~
11930 .area CSEG 
11931 \newline 
11932 _asm_func: 
11933 \newline 
11934 \SpecialChar ~
11935 \SpecialChar ~
11936 \SpecialChar ~
11937 \SpecialChar ~
11938 \SpecialChar ~
11939 \SpecialChar ~
11940 \SpecialChar ~
11941 \SpecialChar ~
11942 mov\SpecialChar ~
11943 \SpecialChar ~
11944 \SpecialChar ~
11945 \SpecialChar ~
11946 a,dpl 
11947 \newline 
11948 \SpecialChar ~
11949 \SpecialChar ~
11950 \SpecialChar ~
11951 \SpecialChar ~
11952 \SpecialChar ~
11953 \SpecialChar ~
11954 \SpecialChar ~
11955 \SpecialChar ~
11956 add\SpecialChar ~
11957 \SpecialChar ~
11958 \SpecialChar ~
11959 \SpecialChar ~
11960 a,_asm_func_PARM_2 
11961 \newline 
11962 \SpecialChar ~
11963 \SpecialChar ~
11964 \SpecialChar ~
11965 \SpecialChar ~
11966 \SpecialChar ~
11967 \SpecialChar ~
11968 \SpecialChar ~
11969 \SpecialChar ~
11970 mov\SpecialChar ~
11971 \SpecialChar ~
11972 \SpecialChar ~
11973 \SpecialChar ~
11974 dpl,a 
11975 \newline 
11976 \SpecialChar ~
11977 \SpecialChar ~
11978 \SpecialChar ~
11979 \SpecialChar ~
11980 \SpecialChar ~
11981 \SpecialChar ~
11982 \SpecialChar ~
11983 \SpecialChar ~
11984 mov\SpecialChar ~
11985 \SpecialChar ~
11986 \SpecialChar ~
11987 \SpecialChar ~
11988 dph
11989 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
11990
11991 \end_inset 
11992
11993 ,#0x00 
11994 \newline 
11995 \SpecialChar ~
11996 \SpecialChar ~
11997 \SpecialChar ~
11998 \SpecialChar ~
11999 \SpecialChar ~
12000 \SpecialChar ~
12001 \SpecialChar ~
12002 \SpecialChar ~
12003 ret
12004 \layout Standard
12005
12006 Note here that the return values
12007 \begin_inset LatexCommand \index{return value}
12008
12009 \end_inset 
12010
12011  are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
12012  two byte values.
12013  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
12014 b' & 'acc' for four byte values.
12015 \layout Standard
12016
12017 The parameter naming convention is _<function_name>_PARM_<n>, where n is
12018  the parameter number starting from 1, and counting from the left.
12019  The first parameter is passed in 
12020 \begin_inset Quotes eld
12021 \end_inset 
12022
12023 dpl
12024 \begin_inset Quotes erd
12025 \end_inset 
12026
12027  for a one byte parameter, 
12028 \begin_inset Quotes eld
12029 \end_inset 
12030
12031 dptr
12032 \begin_inset Quotes erd
12033 \end_inset 
12034
12035  for two bytes, 
12036 \begin_inset Quotes eld
12037 \end_inset 
12038
12039 b,dptr
12040 \begin_inset Quotes erd
12041 \end_inset 
12042
12043  for three bytes and 
12044 \begin_inset Quotes eld
12045 \end_inset 
12046
12047 acc,b,dptr
12048 \begin_inset Quotes erd
12049 \end_inset 
12050
12051  for a four bytes parameter.
12052  The variable name for the second parameter will be _<function_name>_PARM_2.
12053 \newline 
12054
12055 \newline 
12056 Assemble the assembler routine with the following command:
12057 \newline 
12058
12059 \newline 
12060
12061 \family sans 
12062 \series bold 
12063 asx8051 -losg asmfunc.asm
12064 \newline 
12065
12066 \newline 
12067
12068 \family default 
12069 \series default 
12070 Then compile and link the assembler routine to the C source file with the
12071  following command:
12072 \newline 
12073
12074 \newline 
12075
12076 \family sans 
12077 \series bold 
12078 sdcc cfunc.c asmfunc.rel
12079 \layout Subsection
12080
12081 Assembler Routine (reentrant)
12082 \layout Standard
12083
12084 In this case
12085 \begin_inset LatexCommand \index{reentrant}
12086
12087 \end_inset 
12088
12089
12090 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
12091
12092 \end_inset 
12093
12094  the second parameter
12095 \begin_inset LatexCommand \index{function parameter}
12096
12097 \end_inset 
12098
12099  onwards will be passed on the stack, the parameters are pushed from right
12100  to left i.e.
12101  after the call the leftmost parameter will be on the top of the stack.
12102  Here is an example:
12103 \layout Verse
12104
12105
12106 \family typewriter 
12107 extern int asm_func(unsigned char, unsigned char);
12108 \newline 
12109
12110 \newline 
12111 int c_func (unsigned char i, unsigned char j) reentrant 
12112 \newline 
12113
12114 \newline 
12115 \SpecialChar ~
12116 \SpecialChar ~
12117 \SpecialChar ~
12118 \SpecialChar ~
12119 return asm_func(i,j); 
12120 \newline 
12121
12122 \newline 
12123
12124 \newline 
12125 int main() 
12126 \newline 
12127
12128 \newline 
12129 \SpecialChar ~
12130 \SpecialChar ~
12131 \SpecialChar ~
12132 \SpecialChar ~
12133 return c_func(10,9); 
12134 \newline 
12135 }
12136 \layout Standard
12137
12138 The corresponding assembler routine is:
12139 \layout Verse
12140
12141
12142 \family typewriter 
12143 .globl _asm_func 
12144 \newline 
12145 _asm_func: 
12146 \newline 
12147 \SpecialChar ~
12148 \SpecialChar ~
12149 \SpecialChar ~
12150 \SpecialChar ~
12151 push  _bp 
12152 \newline 
12153 \SpecialChar ~
12154 \SpecialChar ~
12155 \SpecialChar ~
12156 \SpecialChar ~
12157 mov _bp,sp 
12158 \newline 
12159 \SpecialChar ~
12160 \SpecialChar ~
12161 \SpecialChar ~
12162 \SpecialChar ~
12163 mov r2,dpl
12164 \newline 
12165 \SpecialChar ~
12166 \SpecialChar ~
12167 \SpecialChar ~
12168 \SpecialChar ~
12169 mov a,_bp 
12170 \newline 
12171 \SpecialChar ~
12172 \SpecialChar ~
12173 \SpecialChar ~
12174 \SpecialChar ~
12175 add a,#0xfd 
12176 \newline 
12177 \SpecialChar ~
12178 \SpecialChar ~
12179 \SpecialChar ~
12180 \SpecialChar ~
12181 mov r0,a 
12182 \newline 
12183 \SpecialChar ~
12184 \SpecialChar ~
12185 \SpecialChar ~
12186 \SpecialChar ~
12187 add  a,#0xfc ;?
12188 \newline 
12189 \SpecialChar ~
12190 \SpecialChar ~
12191 \SpecialChar ~
12192 \SpecialChar ~
12193 mov  r1,a 
12194 \newline 
12195 \SpecialChar ~
12196 \SpecialChar ~
12197 \SpecialChar ~
12198 \SpecialChar ~
12199 mov  a,@r0 
12200 \newline 
12201 \SpecialChar ~
12202 \SpecialChar ~
12203 \SpecialChar ~
12204 \SpecialChar ~
12205 add  a,r2 ;?
12206 \newline 
12207 \SpecialChar ~
12208 \SpecialChar ~
12209 \SpecialChar ~
12210 \SpecialChar ~
12211 mov  dpl,a 
12212 \newline 
12213 \SpecialChar ~
12214 \SpecialChar ~
12215 \SpecialChar ~
12216 \SpecialChar ~
12217 mov  dph,#0x00 
12218 \newline 
12219 \SpecialChar ~
12220 \SpecialChar ~
12221 \SpecialChar ~
12222 \SpecialChar ~
12223 mov  sp,_bp 
12224 \newline 
12225 \SpecialChar ~
12226 \SpecialChar ~
12227 \SpecialChar ~
12228 \SpecialChar ~
12229 pop  _bp 
12230 \newline 
12231 \SpecialChar ~
12232 \SpecialChar ~
12233 \SpecialChar ~
12234 \SpecialChar ~
12235 ret
12236 \layout Standard
12237
12238 The compiling and linking procedure remains the same, however note the extra
12239  entry & exit linkage required for the assembler code, _bp is the stack
12240  frame pointer and is used to compute the offset into the stack for parameters
12241  and local variables.
12242 \layout Section
12243
12244 int (16 bit)
12245 \begin_inset LatexCommand \index{int (16 bit)}
12246
12247 \end_inset 
12248
12249  and long (32 bit)
12250 \begin_inset LatexCommand \index{long (32 bit)}
12251
12252 \end_inset 
12253
12254  Support
12255 \layout Standard
12256
12257 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
12258  multiplication and modulus operations are implemented by support routines.
12259  These support routines are all developed in ANSI-C to facilitate porting
12260  to other MCUs, although some model specific assembler optimizations are
12261  used.
12262  The following files contain the described routines, all of them can be
12263  found in <installdir>/share/sdcc/lib.
12264 \newline 
12265
12266 \layout Standard
12267 \align center 
12268
12269 \begin_inset  Tabular
12270 <lyxtabular version="3" rows="11" columns="2">
12271 <features>
12272 <column alignment="center" valignment="top" leftline="true" width="0">
12273 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
12274 <row topline="true" bottomline="true">
12275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12276 \begin_inset Text
12277
12278 \layout Standard
12279
12280
12281 \series bold 
12282 Function
12283 \end_inset 
12284 </cell>
12285 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12286 \begin_inset Text
12287
12288 \layout Standard
12289
12290
12291 \series bold 
12292 Description
12293 \end_inset 
12294 </cell>
12295 </row>
12296 <row topline="true">
12297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12298 \begin_inset Text
12299
12300 \layout Standard
12301
12302 _mulint.c 
12303 \end_inset 
12304 </cell>
12305 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12306 \begin_inset Text
12307
12308 \layout Standard
12309
12310 16 bit multiplication
12311 \end_inset 
12312 </cell>
12313 </row>
12314 <row topline="true">
12315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12316 \begin_inset Text
12317
12318 \layout Standard
12319
12320 _divsint.c 
12321 \end_inset 
12322 </cell>
12323 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12324 \begin_inset Text
12325
12326 \layout Standard
12327
12328  signed 16 bit division (calls _divuint)
12329 \end_inset 
12330 </cell>
12331 </row>
12332 <row topline="true">
12333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12334 \begin_inset Text
12335
12336 \layout Standard
12337
12338 _divuint.c 
12339 \end_inset 
12340 </cell>
12341 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12342 \begin_inset Text
12343
12344 \layout Standard
12345
12346  unsigned 16 bit division
12347 \end_inset 
12348 </cell>
12349 </row>
12350 <row topline="true">
12351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12352 \begin_inset Text
12353
12354 \layout Standard
12355
12356 _modsint.c
12357 \end_inset 
12358 </cell>
12359 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12360 \begin_inset Text
12361
12362 \layout Standard
12363
12364 signed 16 bit modulus (calls _moduint)
12365 \end_inset 
12366 </cell>
12367 </row>
12368 <row topline="true">
12369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12370 \begin_inset Text
12371
12372 \layout Standard
12373
12374 _moduint.c
12375 \end_inset 
12376 </cell>
12377 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12378 \begin_inset Text
12379
12380 \layout Standard
12381
12382 unsigned 16 bit modulus
12383 \end_inset 
12384 </cell>
12385 </row>
12386 <row topline="true">
12387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12388 \begin_inset Text
12389
12390 \layout Standard
12391
12392 _mullong.c
12393 \end_inset 
12394 </cell>
12395 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12396 \begin_inset Text
12397
12398 \layout Standard
12399
12400 32 bit multiplication
12401 \end_inset 
12402 </cell>
12403 </row>
12404 <row topline="true">
12405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12406 \begin_inset Text
12407
12408 \layout Standard
12409
12410 _divslong.c 
12411 \end_inset 
12412 </cell>
12413 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12414 \begin_inset Text
12415
12416 \layout Standard
12417
12418  signed 32 division (calls _divulong)
12419 \end_inset 
12420 </cell>
12421 </row>
12422 <row topline="true">
12423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12424 \begin_inset Text
12425
12426 \layout Standard
12427
12428 _divulong.c 
12429 \end_inset 
12430 </cell>
12431 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12432 \begin_inset Text
12433
12434 \layout Standard
12435
12436 unsigned 32 division
12437 \end_inset 
12438 </cell>
12439 </row>
12440 <row topline="true">
12441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12442 \begin_inset Text
12443
12444 \layout Standard
12445
12446 _modslong.c
12447 \end_inset 
12448 </cell>
12449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12450 \begin_inset Text
12451
12452 \layout Standard
12453
12454  signed 32 bit modulus (calls _modulong)
12455 \end_inset 
12456 </cell>
12457 </row>
12458 <row topline="true" bottomline="true">
12459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12460 \begin_inset Text
12461
12462 \layout Standard
12463
12464 _modulong.c
12465 \end_inset 
12466 </cell>
12467 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12468 \begin_inset Text
12469
12470 \layout Standard
12471
12472 unsigned 32 bit modulus
12473 \end_inset 
12474 </cell>
12475 </row>
12476 </lyxtabular>
12477
12478 \end_inset 
12479
12480
12481 \newline 
12482
12483 \layout Standard
12484
12485 Since they are compiled as 
12486 \emph on 
12487 non-reentrant
12488 \emph default 
12489
12490 \begin_inset LatexCommand \index{reentrant}
12491
12492 \end_inset 
12493
12494 , interrupt
12495 \begin_inset LatexCommand \index{interrupt}
12496
12497 \end_inset 
12498
12499  service routines should not do any of the above operations.
12500  If this is unavoidable then the above routines will need to be compiled
12501  with the 
12502 \emph on 
12503 -
12504 \begin_inset ERT
12505 status Collapsed
12506
12507 \layout Standard
12508
12509 \backslash 
12510 /
12511 \end_inset 
12512
12513 -stack-auto
12514 \begin_inset LatexCommand \index{-\/-stack-auto}
12515
12516 \end_inset 
12517
12518
12519 \emph default 
12520  option, after which the source program will have to be compiled with 
12521 \emph on 
12522 -
12523 \begin_inset ERT
12524 status Collapsed
12525
12526 \layout Standard
12527
12528 \backslash 
12529 /
12530 \end_inset 
12531
12532 -int-long-reent
12533 \begin_inset LatexCommand \index{-\/-int-long-reent}
12534
12535 \end_inset 
12536
12537
12538 \emph default 
12539  option.
12540  Notice that you don't have to call these routines directly.
12541  The compiler will use them automatically every time an integer operation
12542  is required.
12543 \layout Section
12544
12545 Floating Point Support
12546 \begin_inset LatexCommand \index{Floating point support}
12547
12548 \end_inset 
12549
12550
12551 \layout Standard
12552
12553 SDCC supports IEEE (single precision 4 bytes) floating point numbers.The
12554  floating point support routines are derived from gcc's floatlib.c and consist
12555  of the following routines:
12556 \newline 
12557
12558 \layout Standard
12559 \align center 
12560
12561 \size footnotesize 
12562
12563 \begin_inset  Tabular
12564 <lyxtabular version="3" rows="17" columns="2">
12565 <features>
12566 <column alignment="center" valignment="top" leftline="true" width="0">
12567 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
12568 <row topline="true" bottomline="true">
12569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12570 \begin_inset Text
12571
12572 \layout Standard
12573
12574
12575 \family roman 
12576 \series medium 
12577 \shape up 
12578 \size normal 
12579 \emph off 
12580 \bar no 
12581 \noun off 
12582 \color none
12583 Function 
12584 \end_inset 
12585 </cell>
12586 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12587 \begin_inset Text
12588
12589 \layout Standard
12590
12591 Description
12592 \end_inset 
12593 </cell>
12594 </row>
12595 <row topline="true">
12596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12597 \begin_inset Text
12598
12599 \layout Standard
12600
12601
12602 \family roman 
12603 \series medium 
12604 \shape up 
12605 \size normal 
12606 \emph off 
12607 \bar no 
12608 \noun off 
12609 \color none
12610 _fsadd.c
12611 \end_inset 
12612 </cell>
12613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12614 \begin_inset Text
12615
12616 \layout Standard
12617
12618
12619 \family roman 
12620 \series medium 
12621 \shape up 
12622 \size normal 
12623 \emph off 
12624 \bar no 
12625 \noun off 
12626 \color none
12627 add floating point numbers
12628 \end_inset 
12629 </cell>
12630 </row>
12631 <row topline="true">
12632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12633 \begin_inset Text
12634
12635 \layout Standard
12636
12637
12638 \family roman 
12639 \series medium 
12640 \shape up 
12641 \size normal 
12642 \emph off 
12643 \bar no 
12644 \noun off 
12645 \color none
12646 _fssub.c 
12647 \end_inset 
12648 </cell>
12649 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12650 \begin_inset Text
12651
12652 \layout Standard
12653
12654
12655 \family roman 
12656 \series medium 
12657 \shape up 
12658 \size normal 
12659 \emph off 
12660 \bar no 
12661 \noun off 
12662 \color none
12663 subtract floating point numbers 
12664 \end_inset 
12665 </cell>
12666 </row>
12667 <row topline="true">
12668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12669 \begin_inset Text
12670
12671 \layout Standard
12672
12673
12674 \family roman 
12675 \series medium 
12676 \shape up 
12677 \size normal 
12678 \emph off 
12679 \bar no 
12680 \noun off 
12681 \color none
12682 _fsdiv.c 
12683 \end_inset 
12684 </cell>
12685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12686 \begin_inset Text
12687
12688 \layout Standard
12689
12690
12691 \family roman 
12692 \series medium 
12693 \shape up 
12694 \size normal 
12695 \emph off 
12696 \bar no 
12697 \noun off 
12698 \color none
12699 divide floating point numbers 
12700 \end_inset 
12701 </cell>
12702 </row>
12703 <row topline="true">
12704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12705 \begin_inset Text
12706
12707 \layout Standard
12708
12709
12710 \family roman 
12711 \series medium 
12712 \shape up 
12713 \size normal 
12714 \emph off 
12715 \bar no 
12716 \noun off 
12717 \color none
12718 _fsmul.c 
12719 \end_inset 
12720 </cell>
12721 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12722 \begin_inset Text
12723
12724 \layout Standard
12725
12726
12727 \family roman 
12728 \series medium 
12729 \shape up 
12730 \size normal 
12731 \emph off 
12732 \bar no 
12733 \noun off 
12734 \color none
12735 multiply floating point numbers 
12736 \end_inset 
12737 </cell>
12738 </row>
12739 <row topline="true">
12740 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12741 \begin_inset Text
12742
12743 \layout Standard
12744
12745
12746 \family roman 
12747 \series medium 
12748 \shape up 
12749 \size normal 
12750 \emph off 
12751 \bar no 
12752 \noun off 
12753 \color none
12754 _fs2uchar.c
12755 \end_inset 
12756 </cell>
12757 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12758 \begin_inset Text
12759
12760 \layout Standard
12761
12762
12763 \family roman 
12764 \series medium 
12765 \shape up 
12766 \size normal 
12767 \emph off 
12768 \bar no 
12769 \noun off 
12770 \color none
12771 convert floating point to unsigned char
12772 \end_inset 
12773 </cell>
12774 </row>
12775 <row topline="true">
12776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12777 \begin_inset Text
12778
12779 \layout Standard
12780
12781
12782 \family roman 
12783 \series medium 
12784 \shape up 
12785 \size normal 
12786 \emph off 
12787 \bar no 
12788 \noun off 
12789 \color none
12790 _fs2char.c
12791 \end_inset 
12792 </cell>
12793 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12794 \begin_inset Text
12795
12796 \layout Standard
12797
12798
12799 \family roman 
12800 \series medium 
12801 \shape up 
12802 \size normal 
12803 \emph off 
12804 \bar no 
12805 \noun off 
12806 \color none
12807 convert floating point to signed char
12808 \end_inset 
12809 </cell>
12810 </row>
12811 <row topline="true">
12812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12813 \begin_inset Text
12814
12815 \layout Standard
12816
12817
12818 \family roman 
12819 \series medium 
12820 \shape up 
12821 \size normal 
12822 \emph off 
12823 \bar no 
12824 \noun off 
12825 \color none
12826 _fs2uint.c
12827 \end_inset 
12828 </cell>
12829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12830 \begin_inset Text
12831
12832 \layout Standard
12833
12834
12835 \family roman 
12836 \series medium 
12837 \shape up 
12838 \size normal 
12839 \emph off 
12840 \bar no 
12841 \noun off 
12842 \color none
12843 convert floating point to unsigned int
12844 \end_inset 
12845 </cell>
12846 </row>
12847 <row topline="true">
12848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12849 \begin_inset Text
12850
12851 \layout Standard
12852
12853
12854 \family roman 
12855 \series medium 
12856 \shape up 
12857 \size normal 
12858 \emph off 
12859 \bar no 
12860 \noun off 
12861 \color none
12862 _fs2int.c
12863 \end_inset 
12864 </cell>
12865 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12866 \begin_inset Text
12867
12868 \layout Standard
12869
12870
12871 \family roman 
12872 \series medium 
12873 \shape up 
12874 \size normal 
12875 \emph off 
12876 \bar no 
12877 \noun off 
12878 \color none
12879 convert floating point to signed int
12880 \end_inset 
12881 </cell>
12882 </row>
12883 <row topline="true">
12884 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12885 \begin_inset Text
12886
12887 \layout Standard
12888
12889
12890 \family roman 
12891 \series medium 
12892 \shape up 
12893 \size normal 
12894 \emph off 
12895 \bar no 
12896 \noun off 
12897 \color none
12898 _fs2ulong.
12899 \family default 
12900 \series default 
12901 \shape default 
12902 \size default 
12903 \emph default 
12904 \bar default 
12905 \noun default 
12906 \color default
12907 c
12908 \end_inset 
12909 </cell>
12910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12911 \begin_inset Text
12912
12913 \layout Standard
12914
12915
12916 \family roman 
12917 \series medium 
12918 \shape up 
12919 \size normal 
12920 \emph off 
12921 \bar no 
12922 \noun off 
12923 \color none
12924 convert floating point to unsigned long
12925 \end_inset 
12926 </cell>
12927 </row>
12928 <row topline="true">
12929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12930 \begin_inset Text
12931
12932 \layout Standard
12933
12934
12935 \family roman 
12936 \series medium 
12937 \shape up 
12938 \size normal 
12939 \emph off 
12940 \bar no 
12941 \noun off 
12942 \color none
12943 _fs2long.c
12944 \end_inset 
12945 </cell>
12946 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12947 \begin_inset Text
12948
12949 \layout Standard
12950
12951
12952 \family roman 
12953 \series medium 
12954 \shape up 
12955 \size normal 
12956 \emph off 
12957 \bar no 
12958 \noun off 
12959 \color none
12960 convert floating point to signed long
12961 \end_inset 
12962 </cell>
12963 </row>
12964 <row topline="true">
12965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12966 \begin_inset Text
12967
12968 \layout Standard
12969
12970
12971 \family roman 
12972 \series medium 
12973 \shape up 
12974 \size normal 
12975 \emph off 
12976 \bar no 
12977 \noun off 
12978 \color none
12979 _uchar2fs.c
12980 \end_inset 
12981 </cell>
12982 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12983 \begin_inset Text
12984
12985 \layout Standard
12986
12987
12988 \family roman 
12989 \series medium 
12990 \shape up 
12991 \size normal 
12992 \emph off 
12993 \bar no 
12994 \noun off 
12995 \color none
12996 convert unsigned char to floating point
12997 \end_inset 
12998 </cell>
12999 </row>
13000 <row topline="true">
13001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13002 \begin_inset Text
13003
13004 \layout Standard
13005
13006
13007 \family roman 
13008 \series medium 
13009 \shape up 
13010 \size normal 
13011 \emph off 
13012 \bar no 
13013 \noun off 
13014 \color none
13015 _char2fs.c
13016 \end_inset 
13017 </cell>
13018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13019 \begin_inset Text
13020
13021 \layout Standard
13022
13023
13024 \family roman 
13025 \series medium 
13026 \shape up 
13027 \size normal 
13028 \emph off 
13029 \bar no 
13030 \noun off 
13031 \color none
13032 convert char to floating point number
13033 \end_inset 
13034 </cell>
13035 </row>
13036 <row topline="true">
13037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13038 \begin_inset Text
13039
13040 \layout Standard
13041
13042
13043 \family roman 
13044 \series medium 
13045 \shape up 
13046 \size normal 
13047 \emph off 
13048 \bar no 
13049 \noun off 
13050 \color none
13051 _uint2fs.c
13052 \end_inset 
13053 </cell>
13054 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13055 \begin_inset Text
13056
13057 \layout Standard
13058
13059
13060 \family roman 
13061 \series medium 
13062 \shape up 
13063 \size normal 
13064 \emph off 
13065 \bar no 
13066 \noun off 
13067 \color none
13068 convert unsigned int to floating point
13069 \end_inset 
13070 </cell>
13071 </row>
13072 <row topline="true">
13073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13074 \begin_inset Text
13075
13076 \layout Standard
13077
13078
13079 \family roman 
13080 \series medium 
13081 \shape up 
13082 \size normal 
13083 \emph off 
13084 \bar no 
13085 \noun off 
13086 \color none
13087 _int2fs.c
13088 \end_inset 
13089 </cell>
13090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13091 \begin_inset Text
13092
13093 \layout Standard
13094
13095
13096 \family roman 
13097 \series medium 
13098 \shape up 
13099 \size normal 
13100 \emph off 
13101 \bar no 
13102 \noun off 
13103 \color none
13104 convert int to floating point numbers
13105 \end_inset 
13106 </cell>
13107 </row>
13108 <row topline="true">
13109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13110 \begin_inset Text
13111
13112 \layout Standard
13113
13114
13115 \family roman 
13116 \series medium 
13117 \shape up 
13118 \size normal 
13119 \emph off 
13120 \bar no 
13121 \noun off 
13122 \color none
13123 _ulong2fs.c
13124 \end_inset 
13125 </cell>
13126 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13127 \begin_inset Text
13128
13129 \layout Standard
13130
13131
13132 \family roman 
13133 \series medium 
13134 \shape up 
13135 \size normal 
13136 \emph off 
13137 \bar no 
13138 \noun off 
13139 \color none
13140 convert unsigned long to floating point number
13141 \end_inset 
13142 </cell>
13143 </row>
13144 <row topline="true" bottomline="true">
13145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13146 \begin_inset Text
13147
13148 \layout Standard
13149
13150
13151 \family roman 
13152 \series medium 
13153 \shape up 
13154 \size normal 
13155 \emph off 
13156 \bar no 
13157 \noun off 
13158 \color none
13159 _long2fs.c
13160 \end_inset 
13161 </cell>
13162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13163 \begin_inset Text
13164
13165 \layout Standard
13166
13167
13168 \family roman 
13169 \series medium 
13170 \shape up 
13171 \size normal 
13172 \emph off 
13173 \bar no 
13174 \noun off 
13175 \color none
13176 convert long to floating point number
13177 \end_inset 
13178 </cell>
13179 </row>
13180 </lyxtabular>
13181
13182 \end_inset 
13183
13184
13185 \newline 
13186
13187 \layout Standard
13188
13189 These support routines are developed in ANSI-C so there is room for space
13190  and speed improvement.
13191  Note if all these routines are used simultaneously the data space might
13192  overflow.
13193  For serious floating point usage it is recommended that the large model
13194  be used.
13195  Also notice that you don't have to call this routines directly.
13196  The compiler will use them automatically every time a floating point operation
13197  is required.
13198 \layout Section
13199
13200 Library Routines
13201 \begin_inset LatexCommand \index{Libraries}
13202
13203 \end_inset 
13204
13205
13206 \layout Standard
13207
13208
13209 \emph on 
13210 <pending: this is messy and incomplete - a little more information is in
13211  sdcc/doc/libdoc.txt
13212 \emph default 
13213  >
13214 \layout Subsection
13215
13216 Compiler support routines (_gptrget, _mulint etc.)
13217 \layout Subsection
13218
13219 Stdclib functions (puts, printf, strcat etc.)
13220 \layout Subsubsection
13221
13222 <stdio.h>
13223 \layout Standard
13224
13225
13226 \begin_inset LatexCommand \index{<stdio.h>}
13227
13228 \end_inset 
13229
13230 As usual on embedded systems you have to provide your own 
13231 \family typewriter 
13232 getchar()
13233 \begin_inset LatexCommand \index{getchar()}
13234
13235 \end_inset 
13236
13237  
13238 \family default 
13239 and 
13240 \family typewriter 
13241 putchar()
13242 \begin_inset LatexCommand \index{putchar()}
13243
13244 \end_inset 
13245
13246
13247 \family default 
13248  routines.
13249  SDCC does not know whether the system connects to a serial line with or
13250  without handshake, LCD, keyboard or other device.
13251  You'll find examples for serial routines f.e.
13252  in sdcc/device/lib.
13253 \layout Standard
13254
13255 If you're short on memory you might want to use 
13256 \family typewriter 
13257 printf_small()
13258 \family default 
13259  
13260 \emph on 
13261 instead
13262 \emph default 
13263  of
13264 \family typewriter 
13265  printf()
13266 \begin_inset LatexCommand \index{printf()}
13267
13268 \end_inset 
13269
13270 .
13271
13272 \family default 
13273  For the mcs51 there is an assembly version 
13274 \family typewriter 
13275 printf_fast()
13276 \family default 
13277  which should fit the requirements of many embedded systems (by unsetting
13278  #defines it can be customized to 
13279 \emph on 
13280 not
13281 \emph default 
13282  support long variables and field widths).
13283 \layout Subsection
13284
13285 Math functions (sin, pow, sqrt etc.)
13286 \layout Subsection
13287
13288 Other libraries
13289 \layout Standard
13290
13291 Libraries
13292 \begin_inset LatexCommand \index{Libraries}
13293
13294 \end_inset 
13295
13296  included in SDCC should have a license at least as liberal as the GNU Lesser
13297  General Public License
13298 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
13299
13300 \end_inset 
13301
13302  
13303 \emph on 
13304 LGPL
13305 \emph default 
13306 .
13307 \layout Comment
13308
13309 license statements for the libraries are missing.
13310  sdcc/device/lib/ser_ir.c
13311 \layout Comment
13312
13313 or _decdptr f.e.
13314  come with a GPL (as opposed to LGPL) License - this will not be liberal
13315  enough for many embedded programmers.
13316 \layout Standard
13317
13318 If you have ported some library or want to share experience about some code
13319  which f.e.
13320  falls into any of these categories Busses (I
13321 \begin_inset Formula $^{\textrm{2}}$
13322 \end_inset 
13323
13324 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
13325  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
13326  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
13327 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
13328
13329 \end_inset 
13330
13331 \SpecialChar ~
13332 would certainly like to hear about it.
13333  Programmers coding for embedded systems are not especially famous for being
13334  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
13335 e these references are very valuable.
13336  Let's help to create a climate where information is shared.
13337 \layout Section
13338
13339 Memory Models
13340 \layout Subsection
13341
13342 MCS51 Memory Models
13343 \begin_inset LatexCommand \index{Memory model}
13344
13345 \end_inset 
13346
13347
13348 \begin_inset LatexCommand \index{MCS51 memory model}
13349
13350 \end_inset 
13351
13352
13353 \layout Subsubsection
13354
13355 Small and Large
13356 \layout Standard
13357
13358 SDCC allows two memory models for MCS51 code, 
13359 \shape slanted 
13360 small
13361 \shape default 
13362  and 
13363 \shape slanted 
13364 large
13365 \shape default 
13366 .
13367  Modules compiled with different memory models should 
13368 \emph on 
13369 never
13370 \emph default 
13371  be combined together or the results would be unpredictable.
13372  The library routines supplied with the compiler are compiled as both small
13373  and large.
13374  The compiled library modules are contained in separate directories as small
13375  and large so that you can link to either set.
13376  
13377 \layout Standard
13378
13379 When the large model is used all variables declared without a storage class
13380  will be allocated into the external ram, this includes all parameters and
13381  local variables (for non-reentrant
13382 \begin_inset LatexCommand \index{reentrant}
13383
13384 \end_inset 
13385
13386  functions).
13387  When the small model is used variables without storage class are allocated
13388  in the internal ram.
13389 \layout Standard
13390
13391 Judicious usage of the processor specific storage classes
13392 \begin_inset LatexCommand \index{Storage class}
13393
13394 \end_inset 
13395
13396  and the 'reentrant' function type will yield much more efficient code,
13397  than using the large model.
13398  Several optimizations are disabled when the program is compiled using the
13399  large model, it is therefore recommended that the small model be used unless
13400  absolutely required.
13401 \layout Subsubsection
13402
13403 External Stack
13404 \begin_inset LatexCommand \label{sub:External-Stack}
13405
13406 \end_inset 
13407
13408
13409 \begin_inset LatexCommand \index{stack}
13410
13411 \end_inset 
13412
13413
13414 \begin_inset LatexCommand \index{External stack (mcs51)}
13415
13416 \end_inset 
13417
13418
13419 \layout Standard
13420
13421
13422 \series bold 
13423 Attention
13424 \series default 
13425 : this option wasn't maintained for a long time and is quite buggy.
13426  Small programs might work.
13427  You've been warned!
13428 \layout Standard
13429
13430 The external stack (-
13431 \begin_inset ERT
13432 status Collapsed
13433
13434 \layout Standard
13435
13436 \backslash 
13437 /
13438 \end_inset 
13439
13440 -xstack option
13441 \begin_inset LatexCommand \index{-\/-xstack}
13442
13443 \end_inset 
13444
13445 ) is located in pdata
13446 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
13447
13448 \end_inset 
13449
13450  memory (usually at the start of the external ram segment) and is 256 bytes
13451  in size.
13452  When -
13453 \begin_inset ERT
13454 status Collapsed
13455
13456 \layout Standard
13457
13458 \backslash 
13459 /
13460 \end_inset 
13461
13462 -xstack option is used to compile the program, the parameters and local
13463  variables
13464 \begin_inset LatexCommand \index{local variables}
13465
13466 \end_inset 
13467
13468  of all reentrant functions are allocated in this area.
13469  This option is provided for programs with large stack space requirements.
13470  When used with the -
13471 \begin_inset ERT
13472 status Collapsed
13473
13474 \layout Standard
13475
13476 \backslash 
13477 /
13478 \end_inset 
13479
13480 -stack-auto
13481 \begin_inset LatexCommand \index{-\/-stack-auto}
13482
13483 \end_inset 
13484
13485  option, all parameters and local variables are allocated on the external
13486  stack (note: support libraries will need to be recompiled with the same
13487  options).
13488 \layout Standard
13489
13490 The compiler outputs the higher order address byte of the external ram segment
13491  into port P2
13492 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
13493
13494 \end_inset 
13495
13496  (see also section 
13497 \begin_inset LatexCommand \ref{sub:MCS51-variants}
13498
13499 \end_inset 
13500
13501 ), therefore when using the External Stack option, this port 
13502 \emph on 
13503 may not
13504 \emph default 
13505  be used by the application program.
13506 \layout Subsection
13507
13508 DS390 Memory Model
13509 \begin_inset LatexCommand \index{Memory model}
13510
13511 \end_inset 
13512
13513
13514 \begin_inset LatexCommand \index{DS390 memory model}
13515
13516 \end_inset 
13517
13518
13519 \layout Standard
13520
13521 The only model supported is Flat 24
13522 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
13523
13524 \end_inset 
13525
13526 .
13527  This generates code for the 24 bit contiguous addressing mode of the Dallas
13528  DS80C390 part.
13529  In this mode, up to four meg of external RAM or code space can be directly
13530  addressed.
13531  See the data sheets at www.dalsemi.com for further information on this part.
13532 \newline 
13533
13534 \newline 
13535 Note that the compiler does not generate any code to place the processor
13536  into 24 bitmode (although 
13537 \emph on 
13538 tinibios
13539 \emph default 
13540  in the ds390 libraries will do that for you).
13541  If you don't use 
13542 \emph on 
13543 tinibios
13544 \emph default 
13545
13546 \begin_inset LatexCommand \index{Tinibios (DS390)}
13547
13548 \end_inset 
13549
13550 , the boot loader or similar code must ensure that the processor is in 24
13551  bit contiguous addressing mode before calling the SDCC startup code.
13552 \newline 
13553
13554 \newline 
13555 Like the 
13556 \emph on 
13557 -
13558 \begin_inset ERT
13559 status Collapsed
13560
13561 \layout Standard
13562
13563 \backslash 
13564 /
13565 \end_inset 
13566
13567 -model-large
13568 \emph default 
13569  option, variables will by default be placed into the XDATA segment.
13570  
13571 \newline 
13572
13573 \newline 
13574 Segments may be placed anywhere in the 4 meg address space using the usual
13575  -
13576 \begin_inset ERT
13577 status Collapsed
13578
13579 \layout Standard
13580
13581 \backslash 
13582 /
13583 \end_inset 
13584
13585 -*-loc options.
13586  Note that if any segments are located above 64K, the -r flag must be passed
13587  to the linker to generate the proper segment relocations, and the Intel
13588  HEX output format must be used.
13589  The -r flag can be passed to the linker by using the option 
13590 \emph on 
13591 -Wl-r
13592 \emph default 
13593  on the SDCC command line.
13594  However, currently the linker can not handle code segments > 64k.
13595 \layout Section
13596
13597 Pragmas
13598 \begin_inset LatexCommand \index{Pragmas}
13599
13600 \end_inset 
13601
13602
13603 \layout Standard
13604
13605 SDCC supports the following #pragma directives:
13606 \layout Itemize
13607
13608 save
13609 \begin_inset LatexCommand \index{\#pragma save}
13610
13611 \end_inset 
13612
13613  - this will save all current options to the save/restore stack.
13614  See restore.
13615 \layout Itemize
13616
13617 restore
13618 \begin_inset LatexCommand \index{\#pragma restore}
13619
13620 \end_inset 
13621
13622  - will restore saved options from the last save.
13623  saves & restores can be nested.
13624  SDCC uses a save/restore stack: save pushes current options to the stack,
13625  restore pulls current options from the stack.
13626  See save.
13627 \layout Itemize
13628
13629 nogcse
13630 \begin_inset LatexCommand \index{\#pragma nogcse}
13631
13632 \end_inset 
13633
13634  - will stop global common subexpression elimination.
13635 \layout Itemize
13636
13637 noinduction
13638 \begin_inset LatexCommand \index{\#pragma noinduction}
13639
13640 \end_inset 
13641
13642  - will stop loop induction optimizations.
13643 \layout Itemize
13644
13645 nojtbound
13646 \begin_inset LatexCommand \index{\#pragma nojtbound}
13647
13648 \end_inset 
13649
13650  - will not generate code for boundary value checking, when switch statements
13651  are turned into jump-tables (dangerous).
13652  For more details see section 
13653 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
13654
13655 \end_inset 
13656
13657 .
13658 \layout Itemize
13659
13660 nooverlay
13661 \begin_inset LatexCommand \index{\#pragma nooverlay}
13662
13663 \end_inset 
13664
13665  - the compiler will not overlay the parameters and local variables of a
13666  function.
13667 \layout Itemize
13668
13669 less_pedantic
13670 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
13671
13672 \end_inset 
13673
13674  - the compiler will not warn you anymore for obvious mistakes, you'r on
13675  your own now ;-(
13676 \layout Itemize
13677
13678 noloopreverse
13679 \begin_inset LatexCommand \index{\#pragma noloopreverse}
13680
13681 \end_inset 
13682
13683  - Will not do loop reversal optimization
13684 \layout Itemize
13685
13686 exclude
13687 \begin_inset LatexCommand \index{\#pragma exclude}
13688
13689 \end_inset 
13690
13691  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables generation of
13692  pair of push/pop
13693 \begin_inset LatexCommand \index{push/pop}
13694
13695 \end_inset 
13696
13697  instruction in ISR function (using interrupt
13698 \begin_inset LatexCommand \index{interrupt}
13699
13700 \end_inset 
13701
13702  keyword).
13703  The directive should be placed immediately before the ISR function definition
13704  and it affects ALL ISR functions following it.
13705  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
13706 exclude\SpecialChar ~
13707 none
13708 \begin_inset LatexCommand \index{\#pragma exclude}
13709
13710 \end_inset 
13711
13712 .
13713 \layout Itemize
13714
13715 noiv
13716 \begin_inset LatexCommand \index{\#pragma noiv}
13717
13718 \end_inset 
13719
13720  - Do not generate interrupt
13721 \begin_inset LatexCommand \index{interrupt}
13722
13723 \end_inset 
13724
13725  vector table entries for all ISR functions defined after the pragma.
13726  This is useful in cases where the interrupt vector table must be defined
13727  manually, or when there is a secondary, manually defined interrupt vector
13728  table (e.g.
13729  for the autovector feature of the Cypress EZ-USB FX2).
13730  More elegantly this can be achieved by obmitting the optional interrupt
13731  number after the interrupt keyword, see section 
13732 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
13733
13734 \end_inset 
13735
13736 \SpecialChar ~
13737 about interrupts.
13738 \layout Itemize
13739
13740 callee_saves
13741 \begin_inset LatexCommand \index{\#pragma callee\_saves}
13742
13743 \end_inset 
13744
13745
13746 \begin_inset LatexCommand \index{function prologue}
13747
13748 \end_inset 
13749
13750  function1[,function2[,function3...]] - The compiler by default uses a caller
13751  saves convention for register saving across function calls, however this
13752  can cause unnecessary register pushing & popping
13753 \begin_inset LatexCommand \index{push/pop}
13754
13755 \end_inset 
13756
13757  when calling small functions from larger functions.
13758  This option can be used to switch off the register saving convention for
13759  the function names specified.
13760  The compiler will not save registers when calling these functions, extra
13761  code need to be manually inserted at the entry & exit for these functions
13762  to save & restore the registers used by these functions, this can SUBSTANTIALLY
13763  reduce code & improve run time performance of the generated code.
13764  In the future the compiler (with inter procedural analysis) may be able
13765  to determine the appropriate scheme to use for each function call.
13766  If -
13767 \begin_inset ERT
13768 status Collapsed
13769
13770 \layout Standard
13771
13772 \backslash 
13773 /
13774 \end_inset 
13775
13776 -callee-saves command line option is used, the function names specified
13777  in #pragma\SpecialChar ~
13778 callee_saves
13779 \begin_inset LatexCommand \index{\#pragma callee\_saves}
13780
13781 \end_inset 
13782
13783  is appended to the list of functions specified in the command line.
13784 \layout Standard
13785
13786 SDCPP supports the following #pragma directives:
13787 \layout Itemize
13788
13789 preproc_asm
13790 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
13791
13792 \end_inset 
13793
13794  (+ | -) - switch _asm _endasm block preprocessing on / off.
13795  Default is on.
13796 \layout Standard
13797
13798 The pragma's are intended to be used to turn-on or off certain optimizations
13799  which might cause the compiler to generate extra stack / data space to
13800  store compiler generated temporary variables.
13801  This usually happens in large functions.
13802  Pragma directives should be used as shown in the following example, they
13803  are used to control options & optimizations for a given function; pragmas
13804  should be placed before and/or after a function, placing pragma's inside
13805  a function body could have unpredictable results.
13806 \layout Verse
13807
13808
13809 \family typewriter 
13810 #pragma save
13811 \begin_inset LatexCommand \index{\#pragma save}
13812
13813 \end_inset 
13814
13815  \SpecialChar ~
13816 \SpecialChar ~
13817 \SpecialChar ~
13818 \SpecialChar ~
13819 \SpecialChar ~
13820 \SpecialChar ~
13821 \SpecialChar ~
13822 /* save the current settings */ 
13823 \newline 
13824 #pragma nogcse
13825 \begin_inset LatexCommand \index{\#pragma nogcse}
13826
13827 \end_inset 
13828
13829  \SpecialChar ~
13830 \SpecialChar ~
13831 \SpecialChar ~
13832 \SpecialChar ~
13833 \SpecialChar ~
13834 /* turnoff global subexpression elimination */ 
13835 \newline 
13836 #pragma noinduction
13837 \begin_inset LatexCommand \index{\#pragma noinduction}
13838
13839 \end_inset 
13840
13841  /* turn off induction optimizations */ 
13842 \newline 
13843 int foo () 
13844 \newline 
13845
13846 \newline 
13847 \SpecialChar ~
13848  \SpecialChar ~
13849  ...
13850  
13851 \newline 
13852 \SpecialChar ~
13853  \SpecialChar ~
13854  /* large code */ 
13855 \newline 
13856 \SpecialChar ~
13857  \SpecialChar ~
13858  ...
13859  
13860 \newline 
13861
13862 \newline 
13863 #pragma restore
13864 \begin_inset LatexCommand \index{\#pragma restore}
13865
13866 \end_inset 
13867
13868  /* turn the optimizations back on */
13869 \layout Standard
13870
13871 The compiler will generate a warning message when extra space is allocated.
13872  It is strongly recommended that the save and restore pragma's be used when
13873  changing options for a function.
13874 \layout Section
13875
13876 Defines Created by the Compiler
13877 \layout Standard
13878
13879 The compiler creates the following #defines
13880 \begin_inset LatexCommand \index{\#defines}
13881
13882 \end_inset 
13883
13884
13885 \begin_inset LatexCommand \index{Defines created by the compiler}
13886
13887 \end_inset 
13888
13889 :
13890 \newline 
13891
13892 \layout Standard
13893
13894
13895 \begin_inset  Tabular
13896 <lyxtabular version="3" rows="10" columns="2">
13897 <features>
13898 <column alignment="center" valignment="top" leftline="true" width="0">
13899 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
13900 <row topline="true" bottomline="true">
13901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13902 \begin_inset Text
13903
13904 \layout Standard
13905
13906
13907 \series bold 
13908 #define
13909 \end_inset 
13910 </cell>
13911 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13912 \begin_inset Text
13913
13914 \layout Standard
13915
13916
13917 \series bold 
13918 Description
13919 \end_inset 
13920 </cell>
13921 </row>
13922 <row topline="true">
13923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13924 \begin_inset Text
13925
13926 \layout Standard
13927
13928 SDCC
13929 \begin_inset LatexCommand \index{SDCC}
13930
13931 \end_inset 
13932
13933  
13934 \end_inset 
13935 </cell>
13936 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13937 \begin_inset Text
13938
13939 \layout Standard
13940
13941 this Symbol is always defined
13942 \end_inset 
13943 </cell>
13944 </row>
13945 <row topline="true">
13946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13947 \begin_inset Text
13948
13949 \layout Standard
13950
13951 SDCC_mcs51
13952 \begin_inset LatexCommand \index{SDCC\_mcs51}
13953
13954 \end_inset 
13955
13956  or SDCC_ds390
13957 \begin_inset LatexCommand \index{SDCC\_ds390}
13958
13959 \end_inset 
13960
13961  or SDCC_z80
13962 \begin_inset LatexCommand \index{SDCC\_z80}
13963
13964 \end_inset 
13965
13966 , etc
13967 \end_inset 
13968 </cell>
13969 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13970 \begin_inset Text
13971
13972 \layout Standard
13973
13974 depending on the model used (e.g.: -mds390
13975 \end_inset 
13976 </cell>
13977 </row>
13978 <row topline="true">
13979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13980 \begin_inset Text
13981
13982 \layout Standard
13983
13984 __mcs51
13985 \begin_inset LatexCommand \index{\_\_mcs51}
13986
13987 \end_inset 
13988
13989 , __ds390
13990 \begin_inset LatexCommand \index{\_\_ds390}
13991
13992 \end_inset 
13993
13994 , __hc08
13995 \begin_inset LatexCommand \index{\_\_hc08}
13996
13997 \end_inset 
13998
13999 , __z80
14000 \begin_inset LatexCommand \index{\_\_z80}
14001
14002 \end_inset 
14003
14004 , etc
14005 \end_inset 
14006 </cell>
14007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14008 \begin_inset Text
14009
14010 \layout Standard
14011
14012 depending on the model used (e.g.
14013  -mz80)
14014 \end_inset 
14015 </cell>
14016 </row>
14017 <row topline="true">
14018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14019 \begin_inset Text
14020
14021 \layout Standard
14022
14023 SDCC_STACK_AUTO
14024 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
14025
14026 \end_inset 
14027
14028
14029 \end_inset 
14030 </cell>
14031 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14032 \begin_inset Text
14033
14034 \layout Standard
14035
14036 when 
14037 \emph on 
14038 -
14039 \begin_inset ERT
14040 status Collapsed
14041
14042 \layout Standard
14043
14044 \backslash 
14045 /
14046 \end_inset 
14047
14048 -stack-auto
14049 \emph default 
14050  option is used
14051 \end_inset 
14052 </cell>
14053 </row>
14054 <row topline="true">
14055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14056 \begin_inset Text
14057
14058 \layout Standard
14059
14060 SDCC_MODEL_SMALL
14061 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
14062
14063 \end_inset 
14064
14065
14066 \end_inset 
14067 </cell>
14068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14069 \begin_inset Text
14070
14071 \layout Standard
14072
14073 when 
14074 \emph on 
14075 -
14076 \begin_inset ERT
14077 status Collapsed
14078
14079 \layout Standard
14080
14081 \backslash 
14082 /
14083 \end_inset 
14084
14085 -model-small
14086 \emph default 
14087  is used
14088 \end_inset 
14089 </cell>
14090 </row>
14091 <row topline="true">
14092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14093 \begin_inset Text
14094
14095 \layout Standard
14096
14097 SDCC_MODEL_LARGE
14098 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
14099
14100 \end_inset 
14101
14102
14103 \end_inset 
14104 </cell>
14105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14106 \begin_inset Text
14107
14108 \layout Standard
14109
14110 when 
14111 \emph on 
14112 -
14113 \begin_inset ERT
14114 status Collapsed
14115
14116 \layout Standard
14117
14118 \backslash 
14119 /
14120 \end_inset 
14121
14122 -model-large
14123 \emph default 
14124  is used
14125 \end_inset 
14126 </cell>
14127 </row>
14128 <row topline="true">
14129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14130 \begin_inset Text
14131
14132 \layout Standard
14133
14134 SDCC_USE_XSTACK
14135 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
14136
14137 \end_inset 
14138
14139
14140 \end_inset 
14141 </cell>
14142 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14143 \begin_inset Text
14144
14145 \layout Standard
14146
14147 when 
14148 \emph on 
14149 -
14150 \begin_inset ERT
14151 status Collapsed
14152
14153 \layout Standard
14154
14155 \backslash 
14156 /
14157 \end_inset 
14158
14159 -xstack
14160 \emph default 
14161  option is used
14162 \end_inset 
14163 </cell>
14164 </row>
14165 <row topline="true">
14166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14167 \begin_inset Text
14168
14169 \layout Standard
14170
14171 SDCC_STACK_TENBIT
14172 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
14173
14174 \end_inset 
14175
14176  
14177 \end_inset 
14178 </cell>
14179 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14180 \begin_inset Text
14181
14182 \layout Standard
14183
14184 when 
14185 \emph on 
14186 -mds390
14187 \emph default 
14188  is used
14189 \end_inset 
14190 </cell>
14191 </row>
14192 <row topline="true" bottomline="true">
14193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14194 \begin_inset Text
14195
14196 \layout Standard
14197
14198 SDCC_MODEL_FLAT24
14199 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
14200
14201 \end_inset 
14202
14203
14204 \end_inset 
14205 </cell>
14206 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14207 \begin_inset Text
14208
14209 \layout Standard
14210
14211 when 
14212 \emph on 
14213 -mds390
14214 \emph default 
14215  is used
14216 \end_inset 
14217 </cell>
14218 </row>
14219 </lyxtabular>
14220
14221 \end_inset 
14222
14223
14224 \layout Chapter
14225
14226 Notes on supported Processors
14227 \layout Section
14228
14229 MCS51 variants
14230 \begin_inset LatexCommand \label{sub:MCS51-variants}
14231
14232 \end_inset 
14233
14234
14235 \begin_inset LatexCommand \index{MCS51 variants}
14236
14237 \end_inset 
14238
14239
14240 \layout Standard
14241
14242 MCS51 processors are available from many vendors and come in many different
14243  flavours.
14244  While they might differ considerably in respect to Special Function Registers
14245  the core MCS51 is usually not modified or is kept compatible.
14246  
14247 \layout Subsection
14248
14249 pdata access by SFR 
14250 \layout Standard
14251
14252 With the upcome of devices with internal xdata and flash memory devices
14253  using port P2
14254 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
14255
14256 \end_inset 
14257
14258  as dedicated I/O port is becoming more popular.
14259  Switching the high byte for pdata
14260 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
14261
14262 \end_inset 
14263
14264  access which was formerly done by port P2 is then achieved by a Special
14265  Function Register
14266 \begin_inset LatexCommand \index{sfr}
14267
14268 \end_inset 
14269
14270 .
14271  In well-established MCS51 tradition the address of this 
14272 \emph on 
14273 sfr
14274 \emph default 
14275  is where the chip designers decided to put it.
14276  Needless to say that they didn't agree on a common name either.
14277  As pdata addressing is used in the startup code for the initialization
14278  of xdata variables a separate startup code should be used as described
14279  in section 
14280 \begin_inset LatexCommand \ref{sub:Startup-Code}
14281
14282 \end_inset 
14283
14284 .
14285 \layout Subsection
14286
14287 Other Features available by SFR
14288 \layout Standard
14289
14290 Some MCS51 variants offer features like Double DPTR
14291 \begin_inset LatexCommand \index{DPTR}
14292
14293 \end_inset 
14294
14295 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
14296  These are currently not used for the MCS51 port.
14297  If you absolutely need them you can fall back to inline assembly or submit
14298  a patch to SDCC.
14299 \layout Section
14300
14301 The Z80 and gbz80 port
14302 \layout Standard
14303
14304 SDCC can target both the Zilog 
14305 \begin_inset LatexCommand \index{Z80}
14306
14307 \end_inset 
14308
14309  and the Nintendo Gameboy's Z80-like gbz80
14310 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
14311
14312 \end_inset 
14313
14314 .
14315  The Z80 port is passed through the same 
14316 \emph on 
14317 regressions tests
14318 \begin_inset LatexCommand \index{Regression test}
14319
14320 \end_inset 
14321
14322
14323 \emph default 
14324  as the MCS51 and DS390 ports, so floating point support, support for long
14325  variables and bitfield support is fine.
14326  See mailing lists and forums about interrupt routines.
14327 \layout Standard
14328
14329 As always, the code is the authoritative reference - see z80/ralloc.c and
14330  z80/gen.c.
14331  The stack
14332 \begin_inset LatexCommand \index{stack}
14333
14334 \end_inset 
14335
14336  frame is similar to that generated by the IAR Z80 compiler.
14337  IX is used as the base pointer, HL and IY are used as a temporary registers,
14338  and BC and DE are available for holding variables.
14339  Return values
14340 \begin_inset LatexCommand \index{return value}
14341
14342 \end_inset 
14343
14344  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
14345  bytes).
14346  The gbz80 port use the same set of registers for the return values, but
14347  in a different order of significance: E (one byte), DE (two bytes), or
14348  HLDE (four bytes).
14349 \layout Section
14350
14351 The HC08 port
14352 \layout Standard
14353
14354 The port to the Motorola HC08
14355 \begin_inset LatexCommand \index{HC08}
14356
14357 \end_inset 
14358
14359  family has been added in October 2003, and is still undergoing some basic
14360  development.
14361  The code generator is complete, but the register allocation is still quite
14362  unoptimized.
14363  Some of the SDCC's standard C library functions have embedded non-HC08
14364  inline assembly and so are not yet usable.
14365 \newline 
14366
14367 \newline 
14368
14369 \layout Section
14370
14371 The PIC14 port
14372 \layout Standard
14373
14374 The 14bit PIC
14375 \begin_inset LatexCommand \index{PIC14}
14376
14377 \end_inset 
14378
14379  port still requires a major effort from the development community.
14380  However it can work for very simple code.
14381 \layout Subsection
14382
14383 C code and 14bit PIC code page
14384 \begin_inset LatexCommand \index{code page (pic14)}
14385
14386 \end_inset 
14387
14388  and RAM banks
14389 \begin_inset LatexCommand \index{RAM bank (pic14)}
14390
14391 \end_inset 
14392
14393
14394 \layout Standard
14395
14396 The linker organizes allocation for the code page and RAM banks.
14397  It does not have intimate knowledge of the code flow.
14398  It will put all the code section of a single asm file into a single code
14399  page.
14400  In order to make use of multiple code pages, separate asm files must be
14401  used.
14402  The compiler treats all functions of a single C file as being in the same
14403  code page unless it is non static.
14404  The compiler treats all local variables of a single C file as being in
14405  the same RAM bank unless it is an extern.
14406 \newline 
14407
14408 \newline 
14409 To get the best follow these guide lines:
14410 \layout Enumerate
14411
14412 make local functions static, as non static functions require code page selection
14413  overhead.
14414 \layout Enumerate
14415
14416 Make local variables static as extern variables require RAM bank selection
14417  overhead.
14418 \layout Enumerate
14419
14420 For devices that have multiple code pages it is more efficient to use the
14421  same number of files as pages, i.e.
14422  for the 16F877 use 4 separate files and i.e.
14423  for the 16F874 use 2 separate files.
14424  This way the linker can put the code for each file into different code
14425  pages and the compiler can allocate reusable variables more efficiently
14426  and there's less page selection overhead.
14427  And as for any 8 bit micro (especially for PIC 14 as they have a very simple
14428  instruction set) use 'unsigned char' whereever possible instead of 'int'.
14429 \layout Subsection
14430
14431 Creating a device include file 
14432 \layout Standard
14433
14434 For generating a device include file use the support perl script inc2h.pl
14435  kept in directory support/script.
14436 \layout Subsection
14437
14438 Interrupt code
14439 \layout Standard
14440
14441 For the interrupt function, use the keyword 'interrupt'
14442 \begin_inset LatexCommand \index{interrupt}
14443
14444 \end_inset 
14445
14446  with level number of 0 (PIC14 only has 1 interrupt so this number is only
14447  there to avoid a syntax error - it ought to be fixed).
14448  E.g.:
14449 \layout Verse
14450
14451
14452 \family typewriter 
14453 void Intr(void) interrupt 0
14454 \newline 
14455 {
14456 \newline 
14457 \SpecialChar ~
14458 \SpecialChar ~
14459 T0IF = 0; /* Clear timer interrupt */
14460 \newline 
14461 }
14462 \layout Standard
14463
14464 Linking and assembling
14465 \newline 
14466 For assembling you can use either GPUTILS'
14467 \begin_inset LatexCommand \index{gputils (pic tools)}
14468
14469 \end_inset 
14470
14471  gpasm.exe or MPLAB's mpasmwin.exe.
14472  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
14473  If you use MPLAB and an interrupt function then the linker script file
14474  vectors section will need to be enlarged to link with mplink.
14475 \newline 
14476
14477 \newline 
14478 Here is a 
14479 \family typewriter 
14480 Makefile
14481 \family default 
14482  using GPUTILS:
14483 \layout Verse
14484
14485
14486 \family typewriter 
14487 .c.o:
14488 \newline 
14489 \SpecialChar ~
14490 \SpecialChar ~
14491 \SpecialChar ~
14492 \SpecialChar ~
14493 \SpecialChar ~
14494 \SpecialChar ~
14495 \SpecialChar ~
14496 \SpecialChar ~
14497 sdcc -S -V -mpic14 -p16F877 $< 
14498 \newline 
14499 \SpecialChar ~
14500 \SpecialChar ~
14501 \SpecialChar ~
14502 \SpecialChar ~
14503 \SpecialChar ~
14504 \SpecialChar ~
14505 \SpecialChar ~
14506 \SpecialChar ~
14507 gpasm -c $*.asm
14508 \newline 
14509
14510 \newline 
14511 $(PRJ).hex: $(OBJS) 
14512 \newline 
14513 \SpecialChar ~
14514 \SpecialChar ~
14515 \SpecialChar ~
14516 \SpecialChar ~
14517 \SpecialChar ~
14518 \SpecialChar ~
14519 \SpecialChar ~
14520 \SpecialChar ~
14521 gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS)
14522 \layout Standard
14523
14524 Here is a 
14525 \family typewriter 
14526 Makefile
14527 \family default 
14528  using MPLAB:
14529 \layout Verse
14530
14531
14532 \family typewriter 
14533 .c.o: 
14534 \newline 
14535 \SpecialChar ~
14536 \SpecialChar ~
14537 \SpecialChar ~
14538 \SpecialChar ~
14539 \SpecialChar ~
14540 \SpecialChar ~
14541 \SpecialChar ~
14542 \SpecialChar ~
14543 sdcc -S -V -mpic14 -p16F877 $< 
14544 \newline 
14545 \SpecialChar ~
14546 \SpecialChar ~
14547 \SpecialChar ~
14548 \SpecialChar ~
14549 \SpecialChar ~
14550 \SpecialChar ~
14551 \SpecialChar ~
14552 \SpecialChar ~
14553 mpasmwin /q /o $*.asm
14554 \newline 
14555
14556 \newline 
14557 $(PRJ).hex: $(OBJS) 
14558 \newline 
14559 \SpecialChar ~
14560 \SpecialChar ~
14561 \SpecialChar ~
14562 \SpecialChar ~
14563 \SpecialChar ~
14564 \SpecialChar ~
14565 \SpecialChar ~
14566 \SpecialChar ~
14567 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS)
14568 \layout Section
14569
14570 The PIC16
14571 \begin_inset LatexCommand \index{PIC16}
14572
14573 \end_inset 
14574
14575  port
14576 \layout Standard
14577
14578 The PIC16
14579 \begin_inset LatexCommand \index{PIC16}
14580
14581 \end_inset 
14582
14583  port is the portion of SDCC that is responsible to produce code for the
14584  Microchip
14585 \begin_inset LatexCommand \index{Microchip}
14586
14587 \end_inset 
14588
14589 (TM) microcontrollers with 16 bit core.
14590  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
14591 \layout Subsection
14592
14593 Global Options
14594 \layout Standard
14595
14596 PIC16 port supports the standard command line arguments as supposed, with
14597  the exception of certain cases that will be mentioned in the following
14598  list:
14599 \layout List
14600 \labelwidthstring 00.00.0000
14601
14602 -
14603 \begin_inset ERT
14604 status Collapsed
14605
14606 \layout Standard
14607
14608 \backslash 
14609 /
14610 \end_inset 
14611
14612 -stack-auto Auto variables that are function parameters, will be saved on
14613  stack by default.
14614  
14615 \emph on 
14616 There is no need to specify this in the command line.
14617 \layout List
14618 \labelwidthstring 00.00.0000
14619
14620 -
14621 \begin_inset ERT
14622 status Collapsed
14623
14624 \layout Standard
14625
14626 \backslash 
14627 /
14628 \end_inset 
14629
14630 -float-reent All floating point functions are reentrant by default.
14631  
14632 \emph on 
14633 There is no need to specifiy this in the command line.
14634 \layout List
14635 \labelwidthstring 00.00.0000
14636
14637 -
14638 \begin_inset ERT
14639 status Collapsed
14640
14641 \layout Standard
14642
14643 \backslash 
14644 /
14645 \end_inset 
14646
14647 -callee-saves See -
14648 \begin_inset ERT
14649 status Collapsed
14650
14651 \layout Standard
14652
14653 \backslash 
14654 /
14655 \end_inset 
14656
14657 -all-callee-saves
14658 \layout List
14659 \labelwidthstring 00.00.0000
14660
14661 -
14662 \begin_inset ERT
14663 status Collapsed
14664
14665 \layout Standard
14666
14667 \backslash 
14668 /
14669 \end_inset 
14670
14671 -all-callee-saves All function arguments are passed on stack by default.
14672  
14673 \emph on 
14674 There is no need to specify this in the command line.
14675 \layout List
14676 \labelwidthstring 00.00.0000
14677
14678 -
14679 \begin_inset ERT
14680 status Collapsed
14681
14682 \layout Standard
14683
14684 \backslash 
14685 /
14686 \end_inset 
14687
14688 -fommit-frame-pointer Frame pointer will be omitted when the function uses
14689  no local variables.
14690 \layout Subsection
14691
14692 Port Specific Options
14693 \layout Standard
14694
14695 The port specific options appear after the global options in the sdcc --help
14696  output.
14697 \layout Subsubsection
14698
14699 General Options
14700 \layout Standard
14701
14702 General options enable certain port features and optimizations.
14703 \layout List
14704 \labelwidthstring 00.00.0000
14705
14706 -
14707 \begin_inset ERT
14708 status Collapsed
14709
14710 \layout Standard
14711
14712 \backslash 
14713 /
14714 \end_inset 
14715
14716 -pgen-bank Instructs the port to insert BANKSEL directives before instructions
14717  that use the Bank Select Register (BSR).
14718 \layout List
14719 \labelwidthstring 00.00.0000
14720
14721 -
14722 \begin_inset ERT
14723 status Collapsed
14724
14725 \layout Standard
14726
14727 \backslash 
14728 /
14729 \end_inset 
14730
14731 -pomit-config-words Instructs the port to omit the generation of the configurati
14732 on words.
14733 \layout List
14734 \labelwidthstring 00.00.0000
14735
14736 -
14737 \begin_inset ERT
14738 status Collapsed
14739
14740 \layout Standard
14741
14742 \backslash 
14743 /
14744 \end_inset 
14745
14746 -pomit-ivt Instructs the port to omit the generation of the interrupt vectors
14747 \layout List
14748 \labelwidthstring 00.00.0000
14749
14750 -
14751 \begin_inset ERT
14752 status Collapsed
14753
14754 \layout Standard
14755
14756 \backslash 
14757 /
14758 \end_inset 
14759
14760 -pleave-reset-vector Used in conjuction with the previous command, instructs
14761  the port NOT to omit the reset vector.
14762 \layout List
14763 \labelwidthstring 00.00.0000
14764
14765 -
14766 \begin_inset ERT
14767 status Collapsed
14768
14769 \layout Standard
14770
14771 \backslash 
14772 /
14773 \end_inset 
14774
14775 -stack-model=[model] Used in conjuction with the command above.
14776  Defines the stack model to be used, valid stack models are : 
14777 \begin_deeper 
14778 \layout List
14779 \labelwidthstring 00.00.0000
14780
14781
14782 \emph on 
14783 small
14784 \emph default 
14785  Selects small stack model.
14786  8 bit stack and frame pointers.
14787  Supports 256 bytes stack size.
14788 \layout List
14789 \labelwidthstring 00.00.0000
14790
14791
14792 \emph on 
14793 large
14794 \emph default 
14795  Selects large stack model.
14796  16 bit stack and frame pointers.
14797  Supports 65536 bytes stack size.
14798 \end_deeper 
14799 \layout List
14800 \labelwidthstring 00.00.0000
14801
14802 -
14803 \begin_inset ERT
14804 status Collapsed
14805
14806 \layout Standard
14807
14808 \backslash 
14809 /
14810 \end_inset 
14811
14812 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
14813  unitialized data variables with [kword].
14814  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
14815 \layout Subsubsection
14816
14817 Debugging Options
14818 \layout Standard
14819
14820 Debugging options enable extra debugging information in the output files.
14821 \layout List
14822 \labelwidthstring 00.00.0000
14823
14824 -
14825 \begin_inset ERT
14826 status Collapsed
14827
14828 \layout Standard
14829
14830 \backslash 
14831 /
14832 \end_inset 
14833
14834 -debug-xtra Similar to --debug, but dumps more information.
14835 \layout List
14836 \labelwidthstring 00.00.0000
14837
14838 -
14839 \begin_inset ERT
14840 status Collapsed
14841
14842 \layout Standard
14843
14844 \backslash 
14845 /
14846 \end_inset 
14847
14848 -debug-ralloc Force register allocator to dump <source>.d file with debugging
14849  information.
14850  <source> is the name of the file compiled.
14851 \layout List
14852 \labelwidthstring 00.00.0000
14853
14854 -
14855 \begin_inset ERT
14856 status Collapsed
14857
14858 \layout Standard
14859
14860 \backslash 
14861 /
14862 \end_inset 
14863
14864 -pcode-verbose Enable pcode debugging information in translation.
14865 \layout Subsection
14866
14867 Preprocessor Macros
14868 \layout Standard
14869
14870 PIC16 port defines the following preprocessor macros while translating a
14871  source.
14872 \layout Standard
14873 \align center 
14874
14875 \begin_inset  Tabular
14876 <lyxtabular version="3" rows="2" columns="2">
14877 <features>
14878 <column alignment="center" valignment="top" leftline="true" width="0">
14879 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
14880 <row topline="true" bottomline="true">
14881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14882 \begin_inset Text
14883
14884 \layout Standard
14885
14886 Macro
14887 \end_inset 
14888 </cell>
14889 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14890 \begin_inset Text
14891
14892 \layout Standard
14893
14894 Description
14895 \end_inset 
14896 </cell>
14897 </row>
14898 <row topline="true" bottomline="true">
14899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14900 \begin_inset Text
14901
14902 \layout Standard
14903
14904 pic18fxxxx
14905 \end_inset 
14906 </cell>
14907 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14908 \begin_inset Text
14909
14910 \layout Standard
14911
14912 MCU Identification.
14913  
14914 \emph on 
14915 xxxx
14916 \emph default 
14917  is the microcontrol identification number, i.e.
14918  452, 6620, etc
14919 \end_inset 
14920 </cell>
14921 </row>
14922 </lyxtabular>
14923
14924 \end_inset 
14925
14926
14927 \layout Subsection
14928
14929 Directories
14930 \layout Standard
14931
14932 PIC16 port uses the following directories for searching header files and
14933  libraries.
14934 \layout Standard
14935 \align center 
14936
14937 \begin_inset  Tabular
14938 <lyxtabular version="3" rows="3" columns="4">
14939 <features>
14940 <column alignment="center" valignment="top" leftline="true" width="0">
14941 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
14942 <column alignment="center" valignment="top" width="0">
14943 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
14944 <row topline="true" bottomline="true">
14945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14946 \begin_inset Text
14947
14948 \layout Standard
14949
14950 Directory
14951 \end_inset 
14952 </cell>
14953 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14954 \begin_inset Text
14955
14956 \layout Standard
14957
14958 Description
14959 \end_inset 
14960 </cell>
14961 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14962 \begin_inset Text
14963
14964 \layout Standard
14965
14966 Target
14967 \end_inset 
14968 </cell>
14969 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14970 \begin_inset Text
14971
14972 \layout Standard
14973
14974 Command prefix
14975 \end_inset 
14976 </cell>
14977 </row>
14978 <row topline="true">
14979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14980 \begin_inset Text
14981
14982 \layout Standard
14983
14984 PREFIX/sdcc/include/pic16
14985 \end_inset 
14986 </cell>
14987 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14988 \begin_inset Text
14989
14990 \layout Standard
14991
14992 PIC16 specific headers
14993 \end_inset 
14994 </cell>
14995 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14996 \begin_inset Text
14997
14998 \layout Standard
14999
15000 Compiler
15001 \end_inset 
15002 </cell>
15003 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15004 \begin_inset Text
15005
15006 \layout Standard
15007
15008 -I
15009 \end_inset 
15010 </cell>
15011 </row>
15012 <row topline="true" bottomline="true">
15013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15014 \begin_inset Text
15015
15016 \layout Standard
15017
15018 PREFIX/sdcc/lib/pic16
15019 \end_inset 
15020 </cell>
15021 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15022 \begin_inset Text
15023
15024 \layout Standard
15025
15026 PIC16 specific libraries
15027 \end_inset 
15028 </cell>
15029 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15030 \begin_inset Text
15031
15032 \layout Standard
15033
15034 Linker
15035 \end_inset 
15036 </cell>
15037 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15038 \begin_inset Text
15039
15040 \layout Standard
15041
15042 -L
15043 \end_inset 
15044 </cell>
15045 </row>
15046 </lyxtabular>
15047
15048 \end_inset 
15049
15050
15051 \layout Subsection
15052
15053 Pragmas
15054 \layout Standard
15055
15056 PIC16 port currently supports the following pragmas:
15057 \layout List
15058 \labelwidthstring 00.00.0000
15059
15060 stack pragma stack forces the code generator to initialize the stack & frame
15061  pointers at a specific address.
15062  This is an adhoc solution since gplink does not support yet stack.
15063  When the gplink issue is resolved the pragma will be deprecated
15064 \begin_inset Foot
15065 collapsed true
15066
15067 \layout Standard
15068
15069
15070 \emph on 
15071 It is important to initialize the stack, otherwise strange things can happen.
15072  Stack is not initialized by default because there are some sources that
15073  do not require it.
15074  (like library sources)
15075 \end_inset 
15076
15077 .
15078 \newline 
15079 The stack pragma should be used only once in a project.
15080  Multiple pragmas may result in indeterminate behaviour of the program.
15081 \newline 
15082 If you omit setting the pragma the port emits a warning message before linking.
15083  If not initializing the stack is desired ignore the message.
15084 \layout LyX-Code
15085
15086 Example:
15087 \layout LyX-Code
15088
15089 \layout LyX-Code
15090
15091 /* initializes stack at RAM address 0x5ff*/
15092 \layout LyX-Code
15093
15094 #pragma stack 0x5ff
15095 \layout LyX-Code
15096
15097 \layout Subsection
15098
15099 Header Files
15100 \layout Standard
15101
15102 There is one main header file that can be included to the source files using
15103  the pic16 port.
15104  That file is the 
15105 \series bold 
15106 pic18fregs.h
15107 \series default 
15108 .
15109  This header file contains the definitions for the processor special registers,
15110  so it is necessery if the soruce accesses them.
15111  It can be included by adding the following line in the beginning of the
15112  file:
15113 \layout LyX-Code
15114
15115 #include <pic18fregs.h>
15116 \layout Standard
15117
15118 The specific microcontroller is selected within the pic18fregs.h automatically,
15119  so the same source can be used with a variety of devices.
15120 \layout Subsection
15121
15122 Libraries
15123 \layout Standard
15124
15125 The libraries that pic16 port depends on are the microcontroller device
15126  libraries which contain the symbol definitions for the microcontroller
15127  special function registers.
15128  These libraries have the format pic18fxxxx.lib, where 
15129 \emph on 
15130 xxxx
15131 \emph default 
15132  is the microcontroller identification number.
15133  The specific library is selected automatically by the compiler at link
15134  stage according to the selected device.
15135 \layout Standard
15136
15137 Libraries are created with gplib which is part of the gputils package 
15138 \begin_inset LatexCommand \url{http://gputils.sourceforge.net}
15139
15140 \end_inset 
15141
15142 .
15143 \layout Subsection
15144
15145 Memory Models
15146 \layout Standard
15147
15148 The following memory models are supported by PIC16 port:
15149 \layout Itemize
15150
15151 small model
15152 \layout Itemize
15153
15154 large model
15155 \layout Standard
15156
15157 Memory model affects the default size of pointers within the source.
15158  The sizes are shown in the next table:
15159 \layout Standard
15160 \align center 
15161
15162 \begin_inset  Tabular
15163 <lyxtabular version="3" rows="3" columns="3">
15164 <features>
15165 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15166 <column alignment="center" valignment="top" leftline="true" width="0">
15167 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15168 <row topline="true" bottomline="true">
15169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15170 \begin_inset Text
15171
15172 \layout Standard
15173
15174 Pointer sizes according to memory model
15175 \end_inset 
15176 </cell>
15177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15178 \begin_inset Text
15179
15180 \layout Standard
15181
15182 small model
15183 \end_inset 
15184 </cell>
15185 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15186 \begin_inset Text
15187
15188 \layout Standard
15189
15190 large model
15191 \end_inset 
15192 </cell>
15193 </row>
15194 <row topline="true" bottomline="true">
15195 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15196 \begin_inset Text
15197
15198 \layout Standard
15199
15200 code pointers
15201 \end_inset 
15202 </cell>
15203 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15204 \begin_inset Text
15205
15206 \layout Standard
15207
15208 16-bits
15209 \end_inset 
15210 </cell>
15211 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15212 \begin_inset Text
15213
15214 \layout Standard
15215
15216 24-bits
15217 \end_inset 
15218 </cell>
15219 </row>
15220 <row topline="true" bottomline="true">
15221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15222 \begin_inset Text
15223
15224 \layout Standard
15225
15226 data pointers
15227 \end_inset 
15228 </cell>
15229 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
15230 \begin_inset Text
15231
15232 \layout Standard
15233
15234 16-bits
15235 \end_inset 
15236 </cell>
15237 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15238 \begin_inset Text
15239
15240 \layout Standard
15241
15242 16-bits
15243 \end_inset 
15244 </cell>
15245 </row>
15246 </lyxtabular>
15247
15248 \end_inset 
15249
15250
15251 \layout Standard
15252
15253 It is advisable that all sources within a project are compiled with the
15254  same memory model.
15255  If one wants to override the default memory model, this can be done by
15256  declaring a pointer as 
15257 \series bold 
15258 far
15259 \series default 
15260  or 
15261 \series bold 
15262 near
15263 \series default 
15264 .
15265  Far selects large memory model's pointers, while near selects small memory
15266  model's pointers.
15267 \layout Standard
15268
15269 The standard device libraries (see 4.5.6) contain no reference to pointers,
15270  so they can be used with both memory models.
15271 \layout Subsection
15272
15273 Stack
15274 \layout Standard
15275
15276 The stack implementation for the PIC16 port uses two indirect registers,
15277  FSR1 and FSR2.
15278 \layout List
15279 \labelwidthstring 00.00.0000
15280
15281 FSR1 is assigned as stack pointer
15282 \layout List
15283 \labelwidthstring 00.00.0000
15284
15285 FSR2 is assigned as frame pointer
15286 \layout Standard
15287
15288 The following stack models are supported by PIC16 port
15289 \layout Itemize
15290
15291 small model
15292 \layout Itemize
15293
15294 large model
15295 \layout Standard
15296
15297
15298 \noun on 
15299 Small
15300 \noun default 
15301  model means that only the FSRxL byte is used to access stack and frame,
15302  while 
15303 \emph on 
15304 \noun on 
15305 large
15306 \emph default 
15307 \noun default 
15308  uses both FSRxL and FSRxH registers.
15309  The following table shows the stack/frame pointers sizes according to stack
15310  model and the maximum space they can address:
15311 \layout Standard
15312 \align center 
15313
15314 \begin_inset  Tabular
15315 <lyxtabular version="3" rows="3" columns="3">
15316 <features>
15317 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15318 <column alignment="center" valignment="top" leftline="true" width="0">
15319 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15320 <row topline="true" bottomline="true">
15321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15322 \begin_inset Text
15323
15324 \layout Standard
15325
15326 Stack & Frame pointer sizes according to stack model
15327 \end_inset 
15328 </cell>
15329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15330 \begin_inset Text
15331
15332 \layout Standard
15333
15334 small
15335 \end_inset 
15336 </cell>
15337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15338 \begin_inset Text
15339
15340 \layout Standard
15341
15342 large
15343 \end_inset 
15344 </cell>
15345 </row>
15346 <row topline="true">
15347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15348 \begin_inset Text
15349
15350 \layout Standard
15351
15352 Stack pointer FSR1
15353 \end_inset 
15354 </cell>
15355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15356 \begin_inset Text
15357
15358 \layout Standard
15359
15360 8-bits
15361 \end_inset 
15362 </cell>
15363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15364 \begin_inset Text
15365
15366 \layout Standard
15367
15368 16-bits
15369 \end_inset 
15370 </cell>
15371 </row>
15372 <row topline="true" bottomline="true">
15373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15374 \begin_inset Text
15375
15376 \layout Standard
15377
15378 Frame pointer FSR2
15379 \end_inset 
15380 </cell>
15381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15382 \begin_inset Text
15383
15384 \layout Standard
15385
15386 8-bits
15387 \end_inset 
15388 </cell>
15389 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15390 \begin_inset Text
15391
15392 \layout Standard
15393
15394 16-bits
15395 \end_inset 
15396 </cell>
15397 </row>
15398 </lyxtabular>
15399
15400 \end_inset 
15401
15402
15403 \layout Standard
15404
15405
15406 \series bold 
15407 Currently stack and frame pointers should be initialized explicit by the
15408  user at the desired Data RAM position (see 4.5.5 Pragma Stack).
15409  Uninitialized stack and frame pointers can result in unexpected behavior
15410  of the resulting binary.
15411 \layout Subsection
15412
15413 Function return values
15414 \layout Standard
15415
15416 Return values from functions are placed to the appropriate registers following
15417  a modified Microchip policy optimized for SDCC.
15418  The following table shows these registers:
15419 \layout Standard
15420 \align center 
15421
15422 \begin_inset  Tabular
15423 <lyxtabular version="3" rows="6" columns="2">
15424 <features>
15425 <column alignment="center" valignment="top" leftline="true" width="0">
15426 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15427 <row topline="true" bottomline="true">
15428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15429 \begin_inset Text
15430
15431 \layout Standard
15432
15433 size
15434 \end_inset 
15435 </cell>
15436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15437 \begin_inset Text
15438
15439 \layout Standard
15440
15441 destination register
15442 \end_inset 
15443 </cell>
15444 </row>
15445 <row topline="true">
15446 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15447 \begin_inset Text
15448
15449 \layout Standard
15450
15451 8 bits
15452 \end_inset 
15453 </cell>
15454 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15455 \begin_inset Text
15456
15457 \layout Standard
15458
15459 WREG
15460 \end_inset 
15461 </cell>
15462 </row>
15463 <row topline="true">
15464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15465 \begin_inset Text
15466
15467 \layout Standard
15468
15469 16 bits
15470 \end_inset 
15471 </cell>
15472 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15473 \begin_inset Text
15474
15475 \layout Standard
15476
15477 PRODL:WREG
15478 \end_inset 
15479 </cell>
15480 </row>
15481 <row topline="true">
15482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15483 \begin_inset Text
15484
15485 \layout Standard
15486
15487 24 bits
15488 \end_inset 
15489 </cell>
15490 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15491 \begin_inset Text
15492
15493 \layout Standard
15494
15495 PRODH:PRODL:WREG
15496 \end_inset 
15497 </cell>
15498 </row>
15499 <row topline="true">
15500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15501 \begin_inset Text
15502
15503 \layout Standard
15504
15505 32 bits
15506 \end_inset 
15507 </cell>
15508 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15509 \begin_inset Text
15510
15511 \layout Standard
15512
15513 FSR0L:PRODH:PRODL:WREG
15514 \end_inset 
15515 </cell>
15516 </row>
15517 <row topline="true" bottomline="true">
15518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15519 \begin_inset Text
15520
15521 \layout Standard
15522
15523 >32 bits
15524 \end_inset 
15525 </cell>
15526 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15527 \begin_inset Text
15528
15529 \layout Standard
15530
15531 on stack, FSR0 points to the beginning
15532 \end_inset 
15533 </cell>
15534 </row>
15535 </lyxtabular>
15536
15537 \end_inset 
15538
15539
15540 \layout Subsection
15541
15542 Interrupts
15543 \layout Standard
15544
15545 When entering an interrupt, currently the PIC16 port automatically saves
15546  the following registers:
15547 \layout Itemize
15548
15549 WREG
15550 \layout Itemize
15551
15552 STATUS
15553 \layout Itemize
15554
15555 BSR
15556 \layout Itemize
15557
15558 PROD (PRODL and PRODH)
15559 \layout Itemize
15560
15561 FSR0 (FSR0L and FSR0H)
15562 \layout Standard
15563
15564 These registers are restored upon return from the interrupt routine
15565 \begin_inset Foot
15566 collapsed false
15567
15568 \layout Standard
15569
15570 NOTE that when the _naked attribute is specified for an interrupt routine,
15571  then NO registers are stored or restored.
15572 \end_inset 
15573
15574 .
15575 \layout Chapter
15576
15577 Debugging with SDCDB
15578 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
15579
15580 \end_inset 
15581
15582
15583 \begin_inset LatexCommand \index{sdcdb (debugger)}
15584
15585 \end_inset 
15586
15587  
15588 \layout Standard
15589
15590 SDCC is distributed with a source level debugger
15591 \begin_inset LatexCommand \index{Debugger}
15592
15593 \end_inset 
15594
15595 .
15596  The debugger uses a command line interface, the command repertoire of the
15597  debugger has been kept as close to gdb
15598 \begin_inset LatexCommand \index{gdb}
15599
15600 \end_inset 
15601
15602  (the GNU debugger) as possible.
15603  The configuration and build process is part of the standard compiler installati
15604 on, which also builds and installs the debugger in the target directory
15605  specified during configuration.
15606  The debugger allows you debug BOTH at the C source and at the ASM source
15607  level.
15608  Sdcdb is available on Unix platforms only.
15609 \layout Section
15610
15611 Compiling for Debugging
15612 \layout Standard
15613
15614 The \SpecialChar \-
15615 \SpecialChar \-
15616 debug option must be specified for all files for which debug information
15617  is to be generated.
15618  The complier generates a .adb file for each of these files.
15619  The linker creates the .cdb
15620 \begin_inset LatexCommand \index{<file>.cdb}
15621
15622 \end_inset 
15623
15624  file from the .adb
15625 \begin_inset LatexCommand \index{<file>.adb}
15626
15627 \end_inset 
15628
15629  files and the address information.
15630  This .cdb is used by the debugger.
15631 \layout Section
15632
15633 How the Debugger Works
15634 \layout Standard
15635
15636 When the -
15637 \begin_inset ERT
15638 status Collapsed
15639
15640 \layout Standard
15641
15642 \backslash 
15643 /
15644 \end_inset 
15645
15646 -debug option is specified the compiler generates extra symbol information
15647  some of which are put into the assembler source and some are put into the
15648  .adb file.
15649   Then the linker creates the .cdb file from the individual .adb files with
15650  the address information for the symbols.
15651  The debugger reads the symbolic information generated by the compiler &
15652  the address information generated by the linker.
15653  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
15654  execution is controlled by the debugger.
15655  When a command is issued for the debugger, it translates it into appropriate
15656  commands for the simulator.
15657 \layout Section
15658
15659 Starting the Debugger
15660 \layout Standard
15661
15662 The debugger can be started using the following command line.
15663  (Assume the file you are debugging has the file name foo).
15664 \newline 
15665
15666 \newline 
15667
15668 \family sans 
15669 \series bold 
15670 sdcdb foo
15671 \newline 
15672
15673 \family default 
15674 \series default 
15675
15676 \newline 
15677 The debugger will look for the following files.
15678 \layout Itemize
15679
15680 foo.c - the source file.
15681 \layout Itemize
15682
15683 foo.cdb - the debugger symbol information file.
15684 \layout Itemize
15685
15686 foo.ihx - the Intel hex format
15687 \begin_inset LatexCommand \index{Intel hex format}
15688
15689 \end_inset 
15690
15691  object file.
15692 \layout Section
15693
15694 Command Line Options.
15695 \layout Itemize
15696
15697 -
15698 \begin_inset ERT
15699 status Collapsed
15700
15701 \layout Standard
15702
15703 \backslash 
15704 /
15705 \end_inset 
15706
15707 -directory=<source file directory> this option can used to specify the directory
15708  search list.
15709  The debugger will look into the directory list specified for source, cdb
15710  & ihx files.
15711  The items in the directory list must be separated by ':', e.g.
15712  if the source files can be in the directories /home/src1 and /home/src2,
15713  the -
15714 \begin_inset ERT
15715 status Collapsed
15716
15717 \layout Standard
15718
15719 \backslash 
15720 /
15721 \end_inset 
15722
15723 -directory option should be -
15724 \begin_inset ERT
15725 status Collapsed
15726
15727 \layout Standard
15728
15729 \backslash 
15730 /
15731 \end_inset 
15732
15733 -directory=/home/src1:/home/src2.
15734  Note there can be no spaces in the option.
15735  
15736 \layout Itemize
15737
15738 -cd <directory> - change to the <directory>.
15739 \layout Itemize
15740
15741 -fullname - used by GUI front ends.
15742 \layout Itemize
15743
15744 -cpu <cpu-type> - this argument is passed to the simulator please see the
15745  simulator docs for details.
15746 \layout Itemize
15747
15748 -X <Clock frequency > this options is passed to the simulator please see
15749  the simulator docs for details.
15750 \layout Itemize
15751
15752 -s <serial port file> passed to simulator see the simulator docs for details.
15753 \layout Itemize
15754
15755 -S <serial in,out> passed to simulator see the simulator docs for details.
15756 \layout Itemize
15757
15758 -k <port number> passed to simulator see the simulator docs for details.
15759 \layout Section
15760
15761 Debugger Commands.
15762 \layout Standard
15763
15764 As mentioned earlier the command interface for the debugger has been deliberatel
15765 y kept as close the GNU debugger gdb, as possible.
15766  This will help the integration with existing graphical user interfaces
15767  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
15768  If you use a graphical user interface for the debugger you can skip the
15769  next sections.
15770 \layout Subsubsection*
15771
15772 break [line | file:line | function | file:function]
15773 \layout Standard
15774
15775 Set breakpoint at specified line or function:
15776 \newline 
15777
15778 \newline 
15779
15780 \family sans 
15781 \series bold 
15782 sdcdb>break 100 
15783 \newline 
15784 sdcdb>break foo.c:100
15785 \newline 
15786 sdcdb>break funcfoo
15787 \newline 
15788 sdcdb>break foo.c:funcfoo
15789 \layout Subsubsection*
15790
15791 clear [line | file:line | function | file:function ]
15792 \layout Standard
15793
15794 Clear breakpoint at specified line or function:
15795 \newline 
15796
15797 \newline 
15798
15799 \family sans 
15800 \series bold 
15801 sdcdb>clear 100
15802 \newline 
15803 sdcdb>clear foo.c:100
15804 \newline 
15805 sdcdb>clear funcfoo
15806 \newline 
15807 sdcdb>clear foo.c:funcfoo
15808 \layout Subsubsection*
15809
15810 continue
15811 \layout Standard
15812
15813 Continue program being debugged, after breakpoint.
15814 \layout Subsubsection*
15815
15816 finish
15817 \layout Standard
15818
15819 Execute till the end of the current function.
15820 \layout Subsubsection*
15821
15822 delete [n]
15823 \layout Standard
15824
15825 Delete breakpoint number 'n'.
15826  If used without any option clear ALL user defined break points.
15827 \layout Subsubsection*
15828
15829 info [break | stack | frame | registers ]
15830 \layout Itemize
15831
15832 info break - list all breakpoints
15833 \layout Itemize
15834
15835 info stack - show the function call stack.
15836 \layout Itemize
15837
15838 info frame - show information about the current execution frame.
15839 \layout Itemize
15840
15841 info registers - show content of all registers.
15842 \layout Subsubsection*
15843
15844 step
15845 \layout Standard
15846
15847 Step program until it reaches a different source line.
15848  Note: pressing <return> repeats the last command.
15849 \layout Subsubsection*
15850
15851 next
15852 \layout Standard
15853
15854 Step program, proceeding through subroutine calls.
15855 \layout Subsubsection*
15856
15857 run
15858 \layout Standard
15859
15860 Start debugged program.
15861 \layout Subsubsection*
15862
15863 ptype variable 
15864 \layout Standard
15865
15866 Print type information of the variable.
15867 \layout Subsubsection*
15868
15869 print variable
15870 \layout Standard
15871
15872 print value of variable.
15873 \layout Subsubsection*
15874
15875 file filename
15876 \layout Standard
15877
15878 load the given file name.
15879  Note this is an alternate method of loading file for debugging.
15880 \layout Subsubsection*
15881
15882 frame
15883 \layout Standard
15884
15885 print information about current frame.
15886 \layout Subsubsection*
15887
15888 set srcmode
15889 \layout Standard
15890
15891 Toggle between C source & assembly source.
15892 \layout Subsubsection*
15893
15894 ! simulator command
15895 \layout Standard
15896
15897 Send the string following '!' to the simulator, the simulator response is
15898  displayed.
15899  Note the debugger does not interpret the command being sent to the simulator,
15900  so if a command like 'go' is sent the debugger can loose its execution
15901  context and may display incorrect values.
15902 \layout Subsubsection*
15903
15904 quit
15905 \layout Standard
15906
15907 "Watch me now.
15908  Iam going Down.
15909  My name is Bobby Brown"
15910 \layout Section
15911
15912 Interfacing with XEmacs
15913 \begin_inset LatexCommand \index{XEmacs}
15914
15915 \end_inset 
15916
15917
15918 \begin_inset LatexCommand \index{Emacs}
15919
15920 \end_inset 
15921
15922 .
15923 \layout Standard
15924
15925 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
15926  sdcdb.el and sdcdbsrc.el.
15927  These two files can be found in the $(prefix)/bin directory after the installat
15928 ion is complete.
15929  These files need to be loaded into XEmacs for the interface to work.
15930  This can be done at XEmacs startup time by inserting the following into
15931  your '.xemacs' file (which can be found in your HOME directory): 
15932 \newline 
15933
15934 \newline 
15935
15936 \family typewriter 
15937 (load-file sdcdbsrc.el) 
15938 \family default 
15939
15940 \newline 
15941
15942 \newline 
15943 .xemacs is a lisp file so the () around the command is REQUIRED.
15944  The files can also be loaded dynamically while XEmacs is running, set the
15945  environment variable 'EMACSLOADPATH' to the installation bin directory
15946  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
15947  To start the interface enter the following command: 
15948 \newline 
15949
15950 \newline 
15951
15952 \family sans 
15953 \series bold 
15954 ESC-x sdcdbsrc
15955 \family default 
15956 \series default 
15957
15958 \newline 
15959
15960 \newline 
15961 You will prompted to enter the file name to be debugged.
15962  
15963 \newline 
15964
15965 \newline 
15966 The command line options that are passed to the simulator directly are bound
15967  to default values in the file sdcdbsrc.el.
15968  The variables are listed below, these values maybe changed as required.
15969 \layout Itemize
15970
15971 sdcdbsrc-cpu-type '51
15972 \layout Itemize
15973
15974 sdcdbsrc-frequency '11059200
15975 \layout Itemize
15976
15977 sdcdbsrc-serial nil
15978 \layout Standard
15979
15980 The following is a list of key mapping for the debugger interface.
15981 \layout Standard
15982
15983 \SpecialChar ~
15984
15985 \family typewriter 
15986
15987 \newline 
15988 ;; Current Listing :: 
15989 \newline 
15990 ;;key\SpecialChar ~
15991 \SpecialChar ~
15992 \SpecialChar ~
15993 \SpecialChar ~
15994 \SpecialChar ~
15995 \SpecialChar ~
15996 \SpecialChar ~
15997 \SpecialChar ~
15998 \SpecialChar ~
15999 \SpecialChar ~
16000 \SpecialChar ~
16001 \SpecialChar ~
16002 \SpecialChar ~
16003 \SpecialChar ~
16004 \SpecialChar ~
16005 binding\SpecialChar ~
16006 \SpecialChar ~
16007 \SpecialChar ~
16008 \SpecialChar ~
16009 \SpecialChar ~
16010 \SpecialChar ~
16011 \SpecialChar ~
16012 \SpecialChar ~
16013 \SpecialChar ~
16014 \SpecialChar ~
16015 \SpecialChar ~
16016 \SpecialChar ~
16017 \SpecialChar ~
16018 \SpecialChar ~
16019 \SpecialChar ~
16020 \SpecialChar ~
16021 \SpecialChar ~
16022 \SpecialChar ~
16023 \SpecialChar ~
16024 \SpecialChar ~
16025 \SpecialChar ~
16026 \SpecialChar ~
16027 Comment 
16028 \newline 
16029 ;;---\SpecialChar ~
16030 \SpecialChar ~
16031 \SpecialChar ~
16032 \SpecialChar ~
16033 \SpecialChar ~
16034 \SpecialChar ~
16035 \SpecialChar ~
16036 \SpecialChar ~
16037 \SpecialChar ~
16038 \SpecialChar ~
16039 \SpecialChar ~
16040 \SpecialChar ~
16041 \SpecialChar ~
16042 \SpecialChar ~
16043 \SpecialChar ~
16044 ------\SpecialChar ~
16045 \SpecialChar ~
16046 \SpecialChar ~
16047 \SpecialChar ~
16048 \SpecialChar ~
16049 \SpecialChar ~
16050 \SpecialChar ~
16051 \SpecialChar ~
16052 \SpecialChar ~
16053 \SpecialChar ~
16054 \SpecialChar ~
16055 \SpecialChar ~
16056 \SpecialChar ~
16057 \SpecialChar ~
16058 \SpecialChar ~
16059 \SpecialChar ~
16060 \SpecialChar ~
16061 \SpecialChar ~
16062 \SpecialChar ~
16063 \SpecialChar ~
16064 \SpecialChar ~
16065 \SpecialChar ~
16066 --------
16067 \newline 
16068 ;; 
16069 \newline 
16070 ;; n\SpecialChar ~
16071 \SpecialChar ~
16072 \SpecialChar ~
16073 \SpecialChar ~
16074 \SpecialChar ~
16075 \SpecialChar ~
16076 \SpecialChar ~
16077 \SpecialChar ~
16078 \SpecialChar ~
16079 \SpecialChar ~
16080 \SpecialChar ~
16081 \SpecialChar ~
16082 \SpecialChar ~
16083 \SpecialChar ~
16084  sdcdb-next-from-src\SpecialChar ~
16085 \SpecialChar ~
16086 \SpecialChar ~
16087 \SpecialChar ~
16088 \SpecialChar ~
16089 \SpecialChar ~
16090 \SpecialChar ~
16091 \SpecialChar ~
16092 \SpecialChar ~
16093 \SpecialChar ~
16094 SDCDB next command 
16095 \newline 
16096 ;; b\SpecialChar ~
16097 \SpecialChar ~
16098 \SpecialChar ~
16099 \SpecialChar ~
16100 \SpecialChar ~
16101 \SpecialChar ~
16102 \SpecialChar ~
16103 \SpecialChar ~
16104 \SpecialChar ~
16105 \SpecialChar ~
16106 \SpecialChar ~
16107 \SpecialChar ~
16108 \SpecialChar ~
16109 \SpecialChar ~
16110  sdcdb-back-from-src\SpecialChar ~
16111 \SpecialChar ~
16112 \SpecialChar ~
16113 \SpecialChar ~
16114 \SpecialChar ~
16115 \SpecialChar ~
16116 \SpecialChar ~
16117 \SpecialChar ~
16118 \SpecialChar ~
16119 \SpecialChar ~
16120 SDCDB back command 
16121 \newline 
16122 ;; c\SpecialChar ~
16123 \SpecialChar ~
16124 \SpecialChar ~
16125 \SpecialChar ~
16126 \SpecialChar ~
16127 \SpecialChar ~
16128 \SpecialChar ~
16129 \SpecialChar ~
16130 \SpecialChar ~
16131 \SpecialChar ~
16132 \SpecialChar ~
16133 \SpecialChar ~
16134 \SpecialChar ~
16135 \SpecialChar ~
16136  sdcdb-cont-from-src\SpecialChar ~
16137 \SpecialChar ~
16138 \SpecialChar ~
16139 \SpecialChar ~
16140 \SpecialChar ~
16141 \SpecialChar ~
16142 \SpecialChar ~
16143 \SpecialChar ~
16144 \SpecialChar ~
16145 \SpecialChar ~
16146 SDCDB continue command
16147 \newline 
16148 ;; s\SpecialChar ~
16149 \SpecialChar ~
16150 \SpecialChar ~
16151 \SpecialChar ~
16152 \SpecialChar ~
16153 \SpecialChar ~
16154 \SpecialChar ~
16155 \SpecialChar ~
16156 \SpecialChar ~
16157 \SpecialChar ~
16158 \SpecialChar ~
16159 \SpecialChar ~
16160 \SpecialChar ~
16161 \SpecialChar ~
16162  sdcdb-step-from-src\SpecialChar ~
16163 \SpecialChar ~
16164 \SpecialChar ~
16165 \SpecialChar ~
16166 \SpecialChar ~
16167 \SpecialChar ~
16168 \SpecialChar ~
16169 \SpecialChar ~
16170 \SpecialChar ~
16171 \SpecialChar ~
16172 SDCDB step command 
16173 \newline 
16174 ;; ?\SpecialChar ~
16175 \SpecialChar ~
16176 \SpecialChar ~
16177 \SpecialChar ~
16178 \SpecialChar ~
16179 \SpecialChar ~
16180 \SpecialChar ~
16181 \SpecialChar ~
16182 \SpecialChar ~
16183 \SpecialChar ~
16184 \SpecialChar ~
16185 \SpecialChar ~
16186 \SpecialChar ~
16187 \SpecialChar ~
16188  sdcdb-whatis-c-sexp\SpecialChar ~
16189 \SpecialChar ~
16190 \SpecialChar ~
16191 \SpecialChar ~
16192 \SpecialChar ~
16193 \SpecialChar ~
16194 \SpecialChar ~
16195 \SpecialChar ~
16196 \SpecialChar ~
16197 \SpecialChar ~
16198 SDCDB ptypecommand for data at 
16199 \newline 
16200 ;;\SpecialChar ~
16201 \SpecialChar ~
16202 \SpecialChar ~
16203 \SpecialChar ~
16204 \SpecialChar ~
16205 \SpecialChar ~
16206 \SpecialChar ~
16207 \SpecialChar ~
16208 \SpecialChar ~
16209 \SpecialChar ~
16210 \SpecialChar ~
16211 \SpecialChar ~
16212 \SpecialChar ~
16213 \SpecialChar ~
16214 \SpecialChar ~
16215 \SpecialChar ~
16216 \SpecialChar ~
16217 \SpecialChar ~
16218 \SpecialChar ~
16219 \SpecialChar ~
16220 \SpecialChar ~
16221 \SpecialChar ~
16222 \SpecialChar ~
16223 \SpecialChar ~
16224 \SpecialChar ~
16225 \SpecialChar ~
16226 \SpecialChar ~
16227 \SpecialChar ~
16228 \SpecialChar ~
16229 \SpecialChar ~
16230 \SpecialChar ~
16231 \SpecialChar ~
16232 \SpecialChar ~
16233 \SpecialChar ~
16234 \SpecialChar ~
16235 \SpecialChar ~
16236 \SpecialChar ~
16237 \SpecialChar ~
16238 \SpecialChar ~
16239 \SpecialChar ~
16240 \SpecialChar ~
16241 \SpecialChar ~
16242 \SpecialChar ~
16243 \SpecialChar ~
16244 \SpecialChar ~
16245 \SpecialChar ~
16246  buffer point 
16247 \newline 
16248 ;; x\SpecialChar ~
16249 \SpecialChar ~
16250 \SpecialChar ~
16251 \SpecialChar ~
16252 \SpecialChar ~
16253 \SpecialChar ~
16254 \SpecialChar ~
16255 \SpecialChar ~
16256 \SpecialChar ~
16257 \SpecialChar ~
16258 \SpecialChar ~
16259 \SpecialChar ~
16260 \SpecialChar ~
16261 \SpecialChar ~
16262  sdcdbsrc-delete\SpecialChar ~
16263 \SpecialChar ~
16264 \SpecialChar ~
16265 \SpecialChar ~
16266 \SpecialChar ~
16267 \SpecialChar ~
16268 \SpecialChar ~
16269 \SpecialChar ~
16270 \SpecialChar ~
16271 \SpecialChar ~
16272 \SpecialChar ~
16273 \SpecialChar ~
16274 \SpecialChar ~
16275 \SpecialChar ~
16276 SDCDB Delete all breakpoints if no arg 
16277 \newline 
16278 ;;\SpecialChar ~
16279 \SpecialChar ~
16280 \SpecialChar ~
16281 \SpecialChar ~
16282 \SpecialChar ~
16283 \SpecialChar ~
16284 \SpecialChar ~
16285 \SpecialChar ~
16286 \SpecialChar ~
16287 \SpecialChar ~
16288 \SpecialChar ~
16289 \SpecialChar ~
16290 \SpecialChar ~
16291 \SpecialChar ~
16292 \SpecialChar ~
16293 \SpecialChar ~
16294 \SpecialChar ~
16295 \SpecialChar ~
16296 \SpecialChar ~
16297 \SpecialChar ~
16298 \SpecialChar ~
16299 \SpecialChar ~
16300 \SpecialChar ~
16301 \SpecialChar ~
16302 \SpecialChar ~
16303 \SpecialChar ~
16304 \SpecialChar ~
16305 \SpecialChar ~
16306 \SpecialChar ~
16307 \SpecialChar ~
16308 \SpecialChar ~
16309 \SpecialChar ~
16310 \SpecialChar ~
16311 \SpecialChar ~
16312 \SpecialChar ~
16313 \SpecialChar ~
16314 \SpecialChar ~
16315 \SpecialChar ~
16316 \SpecialChar ~
16317 \SpecialChar ~
16318 \SpecialChar ~
16319 \SpecialChar ~
16320 \SpecialChar ~
16321 \SpecialChar ~
16322 \SpecialChar ~
16323 \SpecialChar ~
16324 given or delete arg (C-u arg x) 
16325 \newline 
16326 ;; m\SpecialChar ~
16327 \SpecialChar ~
16328 \SpecialChar ~
16329 \SpecialChar ~
16330 \SpecialChar ~
16331 \SpecialChar ~
16332 \SpecialChar ~
16333 \SpecialChar ~
16334 \SpecialChar ~
16335 \SpecialChar ~
16336 \SpecialChar ~
16337 \SpecialChar ~
16338 \SpecialChar ~
16339 \SpecialChar ~
16340  sdcdbsrc-frame\SpecialChar ~
16341 \SpecialChar ~
16342 \SpecialChar ~
16343 \SpecialChar ~
16344 \SpecialChar ~
16345 \SpecialChar ~
16346 \SpecialChar ~
16347 \SpecialChar ~
16348 \SpecialChar ~
16349 \SpecialChar ~
16350 \SpecialChar ~
16351 \SpecialChar ~
16352 \SpecialChar ~
16353 \SpecialChar ~
16354 \SpecialChar ~
16355 SDCDB Display current frame if no arg, 
16356 \newline 
16357 ;;\SpecialChar ~
16358 \SpecialChar ~
16359 \SpecialChar ~
16360 \SpecialChar ~
16361 \SpecialChar ~
16362 \SpecialChar ~
16363 \SpecialChar ~
16364 \SpecialChar ~
16365 \SpecialChar ~
16366 \SpecialChar ~
16367 \SpecialChar ~
16368 \SpecialChar ~
16369 \SpecialChar ~
16370 \SpecialChar ~
16371 \SpecialChar ~
16372 \SpecialChar ~
16373 \SpecialChar ~
16374 \SpecialChar ~
16375 \SpecialChar ~
16376 \SpecialChar ~
16377 \SpecialChar ~
16378 \SpecialChar ~
16379 \SpecialChar ~
16380 \SpecialChar ~
16381 \SpecialChar ~
16382 \SpecialChar ~
16383 \SpecialChar ~
16384 \SpecialChar ~
16385 \SpecialChar ~
16386 \SpecialChar ~
16387 \SpecialChar ~
16388 \SpecialChar ~
16389 \SpecialChar ~
16390 \SpecialChar ~
16391 \SpecialChar ~
16392 \SpecialChar ~
16393 \SpecialChar ~
16394 \SpecialChar ~
16395 \SpecialChar ~
16396 \SpecialChar ~
16397 \SpecialChar ~
16398 \SpecialChar ~
16399 \SpecialChar ~
16400 \SpecialChar ~
16401 \SpecialChar ~
16402 \SpecialChar ~
16403 \SpecialChar ~
16404 given or display frame arg 
16405 \newline 
16406 ;;\SpecialChar ~
16407 \SpecialChar ~
16408 \SpecialChar ~
16409 \SpecialChar ~
16410 \SpecialChar ~
16411 \SpecialChar ~
16412 \SpecialChar ~
16413 \SpecialChar ~
16414 \SpecialChar ~
16415 \SpecialChar ~
16416 \SpecialChar ~
16417 \SpecialChar ~
16418 \SpecialChar ~
16419 \SpecialChar ~
16420 \SpecialChar ~
16421 \SpecialChar ~
16422 \SpecialChar ~
16423 \SpecialChar ~
16424 \SpecialChar ~
16425 \SpecialChar ~
16426 \SpecialChar ~
16427 \SpecialChar ~
16428 \SpecialChar ~
16429 \SpecialChar ~
16430 \SpecialChar ~
16431 \SpecialChar ~
16432 \SpecialChar ~
16433 \SpecialChar ~
16434 \SpecialChar ~
16435 \SpecialChar ~
16436 \SpecialChar ~
16437 \SpecialChar ~
16438 \SpecialChar ~
16439 \SpecialChar ~
16440 \SpecialChar ~
16441 \SpecialChar ~
16442 \SpecialChar ~
16443 \SpecialChar ~
16444 \SpecialChar ~
16445 \SpecialChar ~
16446 \SpecialChar ~
16447 \SpecialChar ~
16448 \SpecialChar ~
16449 \SpecialChar ~
16450 \SpecialChar ~
16451 \SpecialChar ~
16452 \SpecialChar ~
16453 buffer point 
16454 \newline 
16455 ;; !\SpecialChar ~
16456 \SpecialChar ~
16457 \SpecialChar ~
16458 \SpecialChar ~
16459 \SpecialChar ~
16460 \SpecialChar ~
16461 \SpecialChar ~
16462 \SpecialChar ~
16463 \SpecialChar ~
16464 \SpecialChar ~
16465 \SpecialChar ~
16466 \SpecialChar ~
16467 \SpecialChar ~
16468 \SpecialChar ~
16469  sdcdbsrc-goto-sdcdb\SpecialChar ~
16470 \SpecialChar ~
16471 \SpecialChar ~
16472 \SpecialChar ~
16473 \SpecialChar ~
16474 \SpecialChar ~
16475 \SpecialChar ~
16476 \SpecialChar ~
16477 \SpecialChar ~
16478 \SpecialChar ~
16479 Goto the SDCDB output buffer 
16480 \newline 
16481 ;; p\SpecialChar ~
16482 \SpecialChar ~
16483 \SpecialChar ~
16484 \SpecialChar ~
16485 \SpecialChar ~
16486 \SpecialChar ~
16487 \SpecialChar ~
16488 \SpecialChar ~
16489 \SpecialChar ~
16490 \SpecialChar ~
16491 \SpecialChar ~
16492 \SpecialChar ~
16493 \SpecialChar ~
16494 \SpecialChar ~
16495  sdcdb-print-c-sexp\SpecialChar ~
16496 \SpecialChar ~
16497 \SpecialChar ~
16498 \SpecialChar ~
16499 \SpecialChar ~
16500 \SpecialChar ~
16501 \SpecialChar ~
16502 \SpecialChar ~
16503 \SpecialChar ~
16504 \SpecialChar ~
16505 \SpecialChar ~
16506 SDCDB print command for data at 
16507 \newline 
16508 ;;\SpecialChar ~
16509 \SpecialChar ~
16510 \SpecialChar ~
16511 \SpecialChar ~
16512 \SpecialChar ~
16513 \SpecialChar ~
16514 \SpecialChar ~
16515 \SpecialChar ~
16516 \SpecialChar ~
16517 \SpecialChar ~
16518 \SpecialChar ~
16519 \SpecialChar ~
16520 \SpecialChar ~
16521 \SpecialChar ~
16522 \SpecialChar ~
16523 \SpecialChar ~
16524 \SpecialChar ~
16525 \SpecialChar ~
16526 \SpecialChar ~
16527 \SpecialChar ~
16528 \SpecialChar ~
16529 \SpecialChar ~
16530 \SpecialChar ~
16531 \SpecialChar ~
16532 \SpecialChar ~
16533 \SpecialChar ~
16534 \SpecialChar ~
16535 \SpecialChar ~
16536 \SpecialChar ~
16537 \SpecialChar ~
16538 \SpecialChar ~
16539 \SpecialChar ~
16540 \SpecialChar ~
16541 \SpecialChar ~
16542 \SpecialChar ~
16543 \SpecialChar ~
16544 \SpecialChar ~
16545 \SpecialChar ~
16546 \SpecialChar ~
16547 \SpecialChar ~
16548 \SpecialChar ~
16549 \SpecialChar ~
16550 \SpecialChar ~
16551 \SpecialChar ~
16552 \SpecialChar ~
16553 \SpecialChar ~
16554  buffer point 
16555 \newline 
16556 ;; g\SpecialChar ~
16557 \SpecialChar ~
16558 \SpecialChar ~
16559 \SpecialChar ~
16560 \SpecialChar ~
16561 \SpecialChar ~
16562 \SpecialChar ~
16563 \SpecialChar ~
16564 \SpecialChar ~
16565 \SpecialChar ~
16566 \SpecialChar ~
16567 \SpecialChar ~
16568 \SpecialChar ~
16569 \SpecialChar ~
16570  sdcdbsrc-goto-sdcdb\SpecialChar ~
16571 \SpecialChar ~
16572 \SpecialChar ~
16573 \SpecialChar ~
16574 \SpecialChar ~
16575 \SpecialChar ~
16576 \SpecialChar ~
16577 \SpecialChar ~
16578 \SpecialChar ~
16579 \SpecialChar ~
16580 Goto the SDCDB output buffer 
16581 \newline 
16582 ;; t\SpecialChar ~
16583 \SpecialChar ~
16584 \SpecialChar ~
16585 \SpecialChar ~
16586 \SpecialChar ~
16587 \SpecialChar ~
16588 \SpecialChar ~
16589 \SpecialChar ~
16590 \SpecialChar ~
16591 \SpecialChar ~
16592 \SpecialChar ~
16593 \SpecialChar ~
16594 \SpecialChar ~
16595 \SpecialChar ~
16596  sdcdbsrc-mode\SpecialChar ~
16597 \SpecialChar ~
16598 \SpecialChar ~
16599 \SpecialChar ~
16600 \SpecialChar ~
16601 \SpecialChar ~
16602 \SpecialChar ~
16603 \SpecialChar ~
16604 \SpecialChar ~
16605 \SpecialChar ~
16606 \SpecialChar ~
16607 \SpecialChar ~
16608 \SpecialChar ~
16609 \SpecialChar ~
16610 \SpecialChar ~
16611 \SpecialChar ~
16612 Toggles Sdcdbsrc mode (turns it off) 
16613 \newline 
16614 ;; 
16615 \newline 
16616 ;; C-c C-f\SpecialChar ~
16617 \SpecialChar ~
16618 \SpecialChar ~
16619 \SpecialChar ~
16620 \SpecialChar ~
16621 \SpecialChar ~
16622 \SpecialChar ~
16623 \SpecialChar ~
16624  sdcdb-finish-from-src\SpecialChar ~
16625 \SpecialChar ~
16626 \SpecialChar ~
16627 \SpecialChar ~
16628 \SpecialChar ~
16629 \SpecialChar ~
16630 \SpecialChar ~
16631 \SpecialChar ~
16632 SDCDB finish command 
16633 \newline 
16634 ;; 
16635 \newline 
16636 ;; C-x SPC\SpecialChar ~
16637 \SpecialChar ~
16638 \SpecialChar ~
16639 \SpecialChar ~
16640 \SpecialChar ~
16641 \SpecialChar ~
16642 \SpecialChar ~
16643 \SpecialChar ~
16644  sdcdb-break\SpecialChar ~
16645 \SpecialChar ~
16646 \SpecialChar ~
16647 \SpecialChar ~
16648 \SpecialChar ~
16649 \SpecialChar ~
16650 \SpecialChar ~
16651 \SpecialChar ~
16652 \SpecialChar ~
16653 \SpecialChar ~
16654 \SpecialChar ~
16655 \SpecialChar ~
16656 \SpecialChar ~
16657 \SpecialChar ~
16658 \SpecialChar ~
16659 \SpecialChar ~
16660 \SpecialChar ~
16661 \SpecialChar ~
16662 Set break for line with point 
16663 \newline 
16664 ;; ESC t\SpecialChar ~
16665 \SpecialChar ~
16666 \SpecialChar ~
16667 \SpecialChar ~
16668 \SpecialChar ~
16669 \SpecialChar ~
16670 \SpecialChar ~
16671 \SpecialChar ~
16672 \SpecialChar ~
16673 \SpecialChar ~
16674  sdcdbsrc-mode\SpecialChar ~
16675 \SpecialChar ~
16676 \SpecialChar ~
16677 \SpecialChar ~
16678 \SpecialChar ~
16679 \SpecialChar ~
16680 \SpecialChar ~
16681 \SpecialChar ~
16682 \SpecialChar ~
16683 \SpecialChar ~
16684 \SpecialChar ~
16685 \SpecialChar ~
16686 \SpecialChar ~
16687 \SpecialChar ~
16688 \SpecialChar ~
16689 \SpecialChar ~
16690 Toggle Sdcdbsrc mode 
16691 \newline 
16692 ;; ESC m\SpecialChar ~
16693 \SpecialChar ~
16694 \SpecialChar ~
16695 \SpecialChar ~
16696 \SpecialChar ~
16697 \SpecialChar ~
16698 \SpecialChar ~
16699 \SpecialChar ~
16700 \SpecialChar ~
16701 \SpecialChar ~
16702  sdcdbsrc-srcmode\SpecialChar ~
16703 \SpecialChar ~
16704 \SpecialChar ~
16705 \SpecialChar ~
16706 \SpecialChar ~
16707 \SpecialChar ~
16708 \SpecialChar ~
16709 \SpecialChar ~
16710 \SpecialChar ~
16711 \SpecialChar ~
16712 \SpecialChar ~
16713 \SpecialChar ~
16714  Toggle list mode 
16715 \newline 
16716 ;; 
16717 \newline 
16718
16719 \layout Chapter
16720 \pagebreak_top 
16721 TIPS
16722 \layout Standard
16723
16724 Here are a few guidelines that will help the compiler generate more efficient
16725  code, some of the tips are specific to this compiler others are generally
16726  good programming practice.
16727 \layout Itemize
16728
16729 Use the smallest data type to represent your data-value.
16730  If it is known in advance that the value is going to be less than 256 then
16731  use an 'unsigned char' instead of a 'short' or 'int'.
16732  Please note, that ANSI C requires both signed and unsigned chars to be
16733  promoted to 'signed int' before doing any operation.
16734  This promotion can be omitted, if the result is the same.
16735  The effect of the promotion rules together with the sign-extension is often
16736  supprising:
16737 \begin_deeper 
16738 \layout Verse
16739
16740
16741 \family typewriter 
16742 unsigned char uc = 0xfe;
16743 \newline 
16744 if (uc * uc < 0) /* this is true! */
16745 \newline 
16746 {
16747 \newline 
16748 \SpecialChar ~
16749 \SpecialChar ~
16750 \SpecialChar ~
16751 \SpecialChar ~
16752 ....
16753 \newline 
16754 }
16755 \layout Standard
16756
16757
16758 \family typewriter 
16759 uc * uc
16760 \family default 
16761  is evaluated as 
16762 \family typewriter 
16763 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
16764 \family default 
16765 .
16766  
16767 \newline 
16768 Another one:
16769 \layout Verse
16770
16771
16772 \family typewriter 
16773 (unsigned char) -12 / (signed char) -3 = ...
16774 \layout Standard
16775
16776 No, the result is not 4:
16777 \layout Verse
16778
16779
16780 \family typewriter 
16781 (int) (unsigned char) -12 / (int) (signed char) -3 =
16782 \newline 
16783 (int) (unsigned char) 0xf4 / (int) (signed char) 0xfd =
16784 \newline 
16785 (int) 0x00f4 / (int) 0xfffd =
16786 \newline 
16787 (int) 0x00f4 / (int) 0xfffd =
16788 \newline 
16789 (int) 244 / (int) -3 =
16790 \newline 
16791 (int) -81 = (int) 0xffaf;
16792 \layout Standard
16793
16794 Don't complain, that gcc gives you a different result.
16795  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
16796  Therefore the results are different.
16797 \newline 
16798 From 
16799 \begin_inset Quotes sld
16800 \end_inset 
16801
16802 comp.lang.c FAQ
16803 \begin_inset Quotes srd
16804 \end_inset 
16805
16806 :
16807 \layout Quote
16808
16809 If well-defined overflow characteristics are important and negative values
16810  are not, or if you want to steer clear of sign-extension problems when
16811  manipulating bits or bytes, use one of the corresponding unsigned types.
16812  (Beware when mixing signed and unsigned values in expressions, though.)
16813 \newline 
16814 Although character types (especially unsigned char) can be used as "tiny"
16815  integers, doing so is sometimes more trouble than it's worth, due to unpredicta
16816 ble sign extension and increased code size.
16817 \end_deeper 
16818 \layout Itemize
16819
16820 Use unsigned when it is known in advance that the value is not going to
16821  be negative.
16822  This helps especially if you are doing division or multiplication, bit-shifting
16823  or are using an array index.
16824 \layout Itemize
16825
16826 NEVER jump into a LOOP.
16827 \layout Itemize
16828
16829 Declare the variables to be local
16830 \begin_inset LatexCommand \index{local variables}
16831
16832 \end_inset 
16833
16834  whenever possible, especially loop control variables (induction).
16835 \layout Itemize
16836
16837 Since the compiler does not always do implicit integral promotion, the programme
16838 r should do an explicit cast when integral promotion is required.
16839 \layout Itemize
16840
16841 Reducing the size of division, multiplication & modulus operations can reduce
16842  code size substantially.
16843  Take the following code for example.
16844 \begin_deeper 
16845 \layout Verse
16846
16847
16848 \family typewriter 
16849 foobar(unsigned int p1, unsigned char ch)
16850 \newline 
16851 {
16852 \newline 
16853 \SpecialChar ~
16854 \SpecialChar ~
16855 \SpecialChar ~
16856 \SpecialChar ~
16857 unsigned char ch1 = p1 % ch ;
16858 \newline 
16859 \SpecialChar ~
16860 \SpecialChar ~
16861 \SpecialChar ~
16862 \SpecialChar ~
16863 ....
16864 \newline 
16865 }
16866 \layout Standard
16867
16868 For the modulus operation the variable ch will be promoted to unsigned int
16869  first then the modulus operation will be performed (this will lead to a
16870  call to support routine _moduint()), and the result will be casted to a
16871  char.
16872  If the code is changed to 
16873 \layout Verse
16874
16875
16876 \family typewriter 
16877 foobar(unsigned int p1, unsigned char ch)
16878 \newline 
16879 {
16880 \newline 
16881 \SpecialChar ~
16882 \SpecialChar ~
16883 \SpecialChar ~
16884 \SpecialChar ~
16885 unsigned char ch1 = (unsigned char)p1 % ch ;
16886 \newline 
16887 \SpecialChar ~
16888 \SpecialChar ~
16889 \SpecialChar ~
16890 \SpecialChar ~
16891 ....
16892 \newline 
16893 }
16894 \layout Standard
16895
16896 It would substantially reduce the code generated (future versions of the
16897  compiler will be smart enough to detect such optimization opportunities).
16898 \end_deeper 
16899 \layout Itemize
16900
16901 Have a look at the assembly listing to get a 
16902 \begin_inset Quotes sld
16903 \end_inset 
16904
16905 feeling
16906 \begin_inset Quotes srd
16907 \end_inset 
16908
16909  for the code generation.
16910 \layout Section
16911
16912 Tools
16913 \begin_inset LatexCommand \index{Tools}
16914
16915 \end_inset 
16916
16917  included in the distribution
16918 \layout Standard
16919 \align center 
16920
16921 \begin_inset  Tabular
16922 <lyxtabular version="3" rows="12" columns="3">
16923 <features>
16924 <column alignment="center" valignment="top" leftline="true" width="0pt">
16925 <column alignment="center" valignment="top" leftline="true" width="0pt">
16926 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
16927 <row topline="true" bottomline="true">
16928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16929 \begin_inset Text
16930
16931 \layout Standard
16932
16933 Name
16934 \end_inset 
16935 </cell>
16936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16937 \begin_inset Text
16938
16939 \layout Standard
16940
16941 Purpose
16942 \end_inset 
16943 </cell>
16944 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16945 \begin_inset Text
16946
16947 \layout Standard
16948
16949 Directory
16950 \end_inset 
16951 </cell>
16952 </row>
16953 <row topline="true">
16954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16955 \begin_inset Text
16956
16957 \layout Standard
16958
16959 uCsim
16960 \end_inset 
16961 </cell>
16962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16963 \begin_inset Text
16964
16965 \layout Standard
16966
16967 Simulator for various architectures
16968 \end_inset 
16969 </cell>
16970 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16971 \begin_inset Text
16972
16973 \layout Standard
16974
16975 sdcc/sim/ucsim
16976 \end_inset 
16977 </cell>
16978 </row>
16979 <row topline="true">
16980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16981 \begin_inset Text
16982
16983 \layout Standard
16984
16985 keil2sdcc.pl
16986 \end_inset 
16987 </cell>
16988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16989 \begin_inset Text
16990
16991 \layout Standard
16992
16993 header file conversion
16994 \end_inset 
16995 </cell>
16996 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16997 \begin_inset Text
16998
16999 \layout Standard
17000
17001 sdcc/support/scripts
17002 \end_inset 
17003 </cell>
17004 </row>
17005 <row topline="true">
17006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17007 \begin_inset Text
17008
17009 \layout Standard
17010
17011 mh2h.c
17012 \end_inset 
17013 </cell>
17014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17015 \begin_inset Text
17016
17017 \layout Standard
17018
17019 header file conversion
17020 \end_inset 
17021 </cell>
17022 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17023 \begin_inset Text
17024
17025 \layout Standard
17026
17027 sdcc/support/scripts
17028 \end_inset 
17029 </cell>
17030 </row>
17031 <row topline="true">
17032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17033 \begin_inset Text
17034
17035 \layout Standard
17036
17037 as-gbz80
17038 \end_inset 
17039 </cell>
17040 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17041 \begin_inset Text
17042
17043 \layout Standard
17044
17045 Assembler
17046 \end_inset 
17047 </cell>
17048 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17049 \begin_inset Text
17050
17051 \layout Standard
17052
17053
17054 \family roman 
17055 \series medium 
17056 \shape up 
17057 \size normal 
17058 \emph off 
17059 \bar no 
17060 \noun off 
17061 \color none
17062 sdcc/bin
17063 \end_inset 
17064 </cell>
17065 </row>
17066 <row topline="true">
17067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17068 \begin_inset Text
17069
17070 \layout Standard
17071
17072 as-z80
17073 \end_inset 
17074 </cell>
17075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17076 \begin_inset Text
17077
17078 \layout Standard
17079
17080 Assembler
17081 \end_inset 
17082 </cell>
17083 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17084 \begin_inset Text
17085
17086 \layout Standard
17087
17088
17089 \family roman 
17090 \series medium 
17091 \shape up 
17092 \size normal 
17093 \emph off 
17094 \bar no 
17095 \noun off 
17096 \color none
17097 sdcc/bin
17098 \end_inset 
17099 </cell>
17100 </row>
17101 <row topline="true">
17102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17103 \begin_inset Text
17104
17105 \layout Standard
17106
17107 asx8051
17108 \end_inset 
17109 </cell>
17110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17111 \begin_inset Text
17112
17113 \layout Standard
17114
17115 Assembler
17116 \end_inset 
17117 </cell>
17118 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17119 \begin_inset Text
17120
17121 \layout Standard
17122
17123
17124 \family roman 
17125 \series medium 
17126 \shape up 
17127 \size normal 
17128 \emph off 
17129 \bar no 
17130 \noun off 
17131 \color none
17132 sdcc/bin
17133 \end_inset 
17134 </cell>
17135 </row>
17136 <row topline="true">
17137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17138 \begin_inset Text
17139
17140 \layout Standard
17141
17142 sdcdb
17143 \end_inset 
17144 </cell>
17145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17146 \begin_inset Text
17147
17148 \layout Standard
17149
17150 Simulator
17151 \end_inset 
17152 </cell>
17153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17154 \begin_inset Text
17155
17156 \layout Standard
17157
17158
17159 \family roman 
17160 \series medium 
17161 \shape up 
17162 \size normal 
17163 \emph off 
17164 \bar no 
17165 \noun off 
17166 \color none
17167 sdcc/bin
17168 \end_inset 
17169 </cell>
17170 </row>
17171 <row topline="true">
17172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17173 \begin_inset Text
17174
17175 \layout Standard
17176
17177 aslink
17178 \end_inset 
17179 </cell>
17180 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17181 \begin_inset Text
17182
17183 \layout Standard
17184
17185 Linker
17186 \end_inset 
17187 </cell>
17188 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17189 \begin_inset Text
17190
17191 \layout Standard
17192
17193
17194 \family roman 
17195 \series medium 
17196 \shape up 
17197 \size normal 
17198 \emph off 
17199 \bar no 
17200 \noun off 
17201 \color none
17202 sdcc/bin
17203 \end_inset 
17204 </cell>
17205 </row>
17206 <row topline="true">
17207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17208 \begin_inset Text
17209
17210 \layout Standard
17211
17212 link-z80
17213 \end_inset 
17214 </cell>
17215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17216 \begin_inset Text
17217
17218 \layout Standard
17219
17220 Linker
17221 \end_inset 
17222 </cell>
17223 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17224 \begin_inset Text
17225
17226 \layout Standard
17227
17228
17229 \family roman 
17230 \series medium 
17231 \shape up 
17232 \size normal 
17233 \emph off 
17234 \bar no 
17235 \noun off 
17236 \color none
17237 sdcc/bin
17238 \end_inset 
17239 </cell>
17240 </row>
17241 <row topline="true">
17242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17243 \begin_inset Text
17244
17245 \layout Standard
17246
17247 link-gbz80
17248 \end_inset 
17249 </cell>
17250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17251 \begin_inset Text
17252
17253 \layout Standard
17254
17255 Linker
17256 \end_inset 
17257 </cell>
17258 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17259 \begin_inset Text
17260
17261 \layout Standard
17262
17263
17264 \family roman 
17265 \series medium 
17266 \shape up 
17267 \size normal 
17268 \emph off 
17269 \bar no 
17270 \noun off 
17271 \color none
17272 sdcc/bin
17273 \end_inset 
17274 </cell>
17275 </row>
17276 <row topline="true" bottomline="true">
17277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17278 \begin_inset Text
17279
17280 \layout Standard
17281
17282 packihx
17283 \end_inset 
17284 </cell>
17285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17286 \begin_inset Text
17287
17288 \layout Standard
17289
17290 ihx packer
17291 \end_inset 
17292 </cell>
17293 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17294 \begin_inset Text
17295
17296 \layout Standard
17297
17298
17299 \family roman 
17300 \series medium 
17301 \shape up 
17302 \size normal 
17303 \emph off 
17304 \bar no 
17305 \noun off 
17306 \color none
17307 sdcc/bin
17308 \end_inset 
17309 </cell>
17310 </row>
17311 </lyxtabular>
17312
17313 \end_inset 
17314
17315
17316 \newline 
17317
17318 \layout Section
17319
17320 Documentation
17321 \begin_inset LatexCommand \index{Documentation}
17322
17323 \end_inset 
17324
17325  included in the distribution
17326 \layout Standard
17327 \align center 
17328
17329 \begin_inset  Tabular
17330 <lyxtabular version="3" rows="10" columns="2">
17331 <features>
17332 <column alignment="left" valignment="top" leftline="true" width="0">
17333 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
17334 <row topline="true" bottomline="true">
17335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17336 \begin_inset Text
17337
17338 \layout Standard
17339
17340 Subject / Title
17341 \end_inset 
17342 </cell>
17343 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17344 \begin_inset Text
17345
17346 \layout Standard
17347
17348 Where to get / filename
17349 \end_inset 
17350 </cell>
17351 </row>
17352 <row topline="true">
17353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17354 \begin_inset Text
17355
17356 \layout Standard
17357
17358 SDCC Compiler User Guide
17359 \end_inset 
17360 </cell>
17361 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17362 \begin_inset Text
17363
17364 \layout Standard
17365
17366 You're reading it right now
17367 \end_inset 
17368 </cell>
17369 </row>
17370 <row topline="true">
17371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17372 \begin_inset Text
17373
17374 \layout Standard
17375
17376 Changelog of SDCC
17377 \end_inset 
17378 </cell>
17379 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17380 \begin_inset Text
17381
17382 \layout Standard
17383
17384 sdcc/Changelog
17385 \end_inset 
17386 </cell>
17387 </row>
17388 <row topline="true">
17389 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17390 \begin_inset Text
17391
17392 \layout Standard
17393
17394 ASXXXX Assemblers and ASLINK Relocating Linker
17395 \end_inset 
17396 </cell>
17397 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17398 \begin_inset Text
17399
17400 \layout Standard
17401
17402 sdcc/as/doc/asxhtm.html
17403 \end_inset 
17404 </cell>
17405 </row>
17406 <row topline="true">
17407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17408 \begin_inset Text
17409
17410 \layout Standard
17411
17412 SDCC regression test
17413 \begin_inset LatexCommand \index{Regression test}
17414
17415 \end_inset 
17416
17417
17418 \end_inset 
17419 </cell>
17420 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17421 \begin_inset Text
17422
17423 \layout Standard
17424
17425 sdcc/doc/test_suite_spec.pdf
17426 \end_inset 
17427 </cell>
17428 </row>
17429 <row topline="true">
17430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17431 \begin_inset Text
17432
17433 \layout Standard
17434
17435 Various notes
17436 \end_inset 
17437 </cell>
17438 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17439 \begin_inset Text
17440
17441 \layout Standard
17442
17443 sdcc/doc/*
17444 \end_inset 
17445 </cell>
17446 </row>
17447 <row topline="true">
17448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17449 \begin_inset Text
17450
17451 \layout Standard
17452
17453 Notes on debugging with sdcdb
17454 \begin_inset LatexCommand \index{sdcdb (debugger)}
17455
17456 \end_inset 
17457
17458
17459 \end_inset 
17460 </cell>
17461 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17462 \begin_inset Text
17463
17464 \layout Standard
17465
17466 sdcc/debugger/README
17467 \end_inset 
17468 </cell>
17469 </row>
17470 <row topline="true">
17471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17472 \begin_inset Text
17473
17474 \layout Standard
17475
17476 Software simulator for microcontrollers
17477 \end_inset 
17478 </cell>
17479 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17480 \begin_inset Text
17481
17482 \layout Standard
17483
17484
17485 \family roman 
17486 \series medium 
17487 \shape up 
17488 \size normal 
17489 \emph off 
17490 \bar no 
17491 \noun off 
17492 \color none
17493 sdcc/sim/ucsim/doc
17494 \family default 
17495 \series default 
17496 \shape default 
17497 \size default 
17498 \emph default 
17499 \bar default 
17500 \noun default 
17501 \color default
17502 /index.html
17503 \end_inset 
17504 </cell>
17505 </row>
17506 <row topline="true">
17507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17508 \begin_inset Text
17509
17510 \layout Standard
17511
17512 Temporary notes on the pic16
17513 \begin_inset LatexCommand \index{PIC16}
17514
17515 \end_inset 
17516
17517  port
17518 \end_inset 
17519 </cell>
17520 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17521 \begin_inset Text
17522
17523 \layout Standard
17524
17525 sdcc/src/pic16/NOTES
17526 \end_inset 
17527 </cell>
17528 </row>
17529 <row topline="true" bottomline="true">
17530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17531 \begin_inset Text
17532
17533 \layout Standard
17534
17535 SDCC internal documentation (debugging file format)
17536 \end_inset 
17537 </cell>
17538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17539 \begin_inset Text
17540
17541 \layout Standard
17542
17543 sdcc/doc/
17544 \family roman 
17545 \series medium 
17546 \shape up 
17547 \size normal 
17548 \emph off 
17549 \bar no 
17550 \noun off 
17551 \color none
17552 cdbfileformat.pd
17553 \family default 
17554 \series default 
17555 \shape default 
17556 \size default 
17557 \emph default 
17558 \bar default 
17559 \noun default 
17560 \color default
17561 f
17562 \end_inset 
17563 </cell>
17564 </row>
17565 </lyxtabular>
17566
17567 \end_inset 
17568
17569
17570 \newline 
17571
17572 \layout Section
17573
17574 Related open source tools
17575 \begin_inset LatexCommand \index{Related tools}
17576
17577 \end_inset 
17578
17579
17580 \layout Standard
17581 \align center 
17582
17583 \begin_inset  Tabular
17584 <lyxtabular version="3" rows="11" columns="3">
17585 <features>
17586 <column alignment="center" valignment="top" leftline="true" width="0pt">
17587 <column alignment="block" valignment="top" leftline="true" width="30line%">
17588 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
17589 <row topline="true" bottomline="true">
17590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17591 \begin_inset Text
17592
17593 \layout Standard
17594
17595 Name
17596 \end_inset 
17597 </cell>
17598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17599 \begin_inset Text
17600
17601 \layout Standard
17602
17603 Purpose
17604 \end_inset 
17605 </cell>
17606 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17607 \begin_inset Text
17608
17609 \layout Standard
17610
17611 Where to get
17612 \end_inset 
17613 </cell>
17614 </row>
17615 <row topline="true">
17616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17617 \begin_inset Text
17618
17619 \layout Standard
17620
17621 gpsim
17622 \begin_inset LatexCommand \index{gpsim (pic simulator)}
17623
17624 \end_inset 
17625
17626
17627 \end_inset 
17628 </cell>
17629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17630 \begin_inset Text
17631
17632 \layout Standard
17633
17634 PIC simulator
17635 \end_inset 
17636 </cell>
17637 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17638 \begin_inset Text
17639
17640 \layout Standard
17641
17642
17643 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
17644
17645 \end_inset 
17646
17647
17648 \end_inset 
17649 </cell>
17650 </row>
17651 <row topline="true">
17652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17653 \begin_inset Text
17654
17655 \layout Standard
17656
17657 gputils
17658 \begin_inset LatexCommand \index{gputils (pic tools)}
17659
17660 \end_inset 
17661
17662
17663 \end_inset 
17664 </cell>
17665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17666 \begin_inset Text
17667
17668 \layout Standard
17669
17670 GNU PIC utilities
17671 \end_inset 
17672 </cell>
17673 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17674 \begin_inset Text
17675
17676 \layout Standard
17677
17678
17679 \begin_inset LatexCommand \url{http://gputils.sourceforge.net/}
17680
17681 \end_inset 
17682
17683
17684 \end_inset 
17685 </cell>
17686 </row>
17687 <row topline="true">
17688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17689 \begin_inset Text
17690
17691 \layout Standard
17692
17693 flP5
17694 \end_inset 
17695 </cell>
17696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17697 \begin_inset Text
17698
17699 \layout Standard
17700
17701 PIC programmer
17702 \end_inset 
17703 </cell>
17704 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17705 \begin_inset Text
17706
17707 \layout Standard
17708
17709
17710 \begin_inset LatexCommand \url{http://digilander.libero.it/fbradasc/FLP5.html}
17711
17712 \end_inset 
17713
17714
17715 \end_inset 
17716 </cell>
17717 </row>
17718 <row topline="true">
17719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17720 \begin_inset Text
17721
17722 \layout Standard
17723
17724 indent
17725 \begin_inset LatexCommand \index{indent (source formatting tool)}
17726
17727 \end_inset 
17728
17729
17730 \end_inset 
17731 </cell>
17732 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17733 \begin_inset Text
17734
17735 \layout Standard
17736
17737 Formats C source - Master of the white spaces
17738 \end_inset 
17739 </cell>
17740 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17741 \begin_inset Text
17742
17743 \layout Standard
17744
17745
17746 \begin_inset LatexCommand \url{http://home.hccnet.nl/d.ingamells/beautify.html}
17747
17748 \end_inset 
17749
17750
17751 \end_inset 
17752 </cell>
17753 </row>
17754 <row topline="true">
17755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17756 \begin_inset Text
17757
17758 \layout Standard
17759
17760 srecord
17761 \begin_inset LatexCommand \index{srecord (tool)}
17762
17763 \end_inset 
17764
17765
17766 \end_inset 
17767 </cell>
17768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17769 \begin_inset Text
17770
17771 \layout Standard
17772
17773 Object file conversion, checksumming, ...
17774 \end_inset 
17775 </cell>
17776 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17777 \begin_inset Text
17778
17779 \layout Standard
17780
17781
17782 \begin_inset LatexCommand \url{http://srecord.sourceforge.net/}
17783
17784 \end_inset 
17785
17786
17787 \end_inset 
17788 </cell>
17789 </row>
17790 <row topline="true">
17791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17792 \begin_inset Text
17793
17794 \layout Standard
17795
17796 objdump
17797 \begin_inset LatexCommand \index{objdump (tool)}
17798
17799 \end_inset 
17800
17801
17802 \end_inset 
17803 </cell>
17804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17805 \begin_inset Text
17806
17807 \layout Standard
17808
17809 Object file conversion, ...
17810 \end_inset 
17811 </cell>
17812 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17813 \begin_inset Text
17814
17815 \layout Standard
17816
17817 Part of binutils (should be there anyway)
17818 \end_inset 
17819 </cell>
17820 </row>
17821 <row topline="true">
17822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17823 \begin_inset Text
17824
17825 \layout Standard
17826
17827 doxygen
17828 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
17829
17830 \end_inset 
17831
17832
17833 \end_inset 
17834 </cell>
17835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17836 \begin_inset Text
17837
17838 \layout Standard
17839
17840 Source code documentation system
17841 \end_inset 
17842 </cell>
17843 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17844 \begin_inset Text
17845
17846 \layout Standard
17847
17848
17849 \begin_inset LatexCommand \url{http://www.doxygen.org}
17850
17851 \end_inset 
17852
17853
17854 \end_inset 
17855 </cell>
17856 </row>
17857 <row topline="true">
17858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17859 \begin_inset Text
17860
17861 \layout Standard
17862
17863 kdevelop
17864 \end_inset 
17865 </cell>
17866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17867 \begin_inset Text
17868
17869 \layout Standard
17870
17871 IDE (has anyone tried integrating SDCC & sdcdb? Unix only)
17872 \end_inset 
17873 </cell>
17874 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17875 \begin_inset Text
17876
17877 \layout Standard
17878
17879
17880 \begin_inset LatexCommand \url{http://www.kdevelop.org}
17881
17882 \end_inset 
17883
17884
17885 \end_inset 
17886 </cell>
17887 </row>
17888 <row topline="true">
17889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17890 \begin_inset Text
17891
17892 \layout Standard
17893
17894 splint
17895 \begin_inset LatexCommand \index{splint (syntax checking tool)}
17896
17897 \end_inset 
17898
17899
17900 \end_inset 
17901 </cell>
17902 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17903 \begin_inset Text
17904
17905 \layout Standard
17906
17907 Statically checks c sources
17908 \end_inset 
17909 </cell>
17910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17911 \begin_inset Text
17912
17913 \layout Standard
17914
17915
17916 \begin_inset LatexCommand \url{http://www.splint.org}
17917
17918 \end_inset 
17919
17920
17921 \end_inset 
17922 </cell>
17923 </row>
17924 <row topline="true" bottomline="true">
17925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17926 \begin_inset Text
17927
17928 \layout Standard
17929
17930 ddd
17931 \begin_inset LatexCommand \index{ddd (debugger)}
17932
17933 \end_inset 
17934
17935
17936 \end_inset 
17937 </cell>
17938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17939 \begin_inset Text
17940
17941 \layout Standard
17942
17943 Debugger, serves nicely as GUI to sdcdb
17944 \begin_inset LatexCommand \index{sdcdb (debugger)}
17945
17946 \end_inset 
17947
17948  (Unix only)
17949 \end_inset 
17950 </cell>
17951 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17952 \begin_inset Text
17953
17954 \layout Standard
17955
17956
17957 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
17958
17959 \end_inset 
17960
17961
17962 \end_inset 
17963 </cell>
17964 </row>
17965 </lyxtabular>
17966
17967 \end_inset 
17968
17969
17970 \newline 
17971
17972 \layout Section
17973
17974 Related documentation / recommended reading
17975 \layout Standard
17976 \align center 
17977
17978 \begin_inset  Tabular
17979 <lyxtabular version="3" rows="6" columns="3">
17980 <features>
17981 <column alignment="center" valignment="top" leftline="true" width="0pt">
17982 <column alignment="block" valignment="top" leftline="true" width="30line%">
17983 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
17984 <row topline="true" bottomline="true">
17985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17986 \begin_inset Text
17987
17988 \layout Standard
17989
17990 Name
17991 \end_inset 
17992 </cell>
17993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17994 \begin_inset Text
17995
17996 \layout Standard
17997
17998 Subject / Title
17999 \end_inset 
18000 </cell>
18001 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18002 \begin_inset Text
18003
18004 \layout Standard
18005
18006 Where to get
18007 \end_inset 
18008 </cell>
18009 </row>
18010 <row topline="true">
18011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18012 \begin_inset Text
18013
18014 \layout Standard
18015
18016
18017 \family roman 
18018 \series medium 
18019 \shape up 
18020 \size normal 
18021 \emph off 
18022 \bar no 
18023 \noun off 
18024 \color none
18025 c-refcard.pdf
18026 \end_inset 
18027 </cell>
18028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18029 \begin_inset Text
18030
18031 \layout Standard
18032
18033 C Reference Card
18034 \begin_inset LatexCommand \index{C Reference card}
18035
18036 \end_inset 
18037
18038 , 2 pages
18039 \end_inset 
18040 </cell>
18041 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18042 \begin_inset Text
18043
18044 \layout Standard
18045
18046
18047 \begin_inset LatexCommand \url{http://www.refcards.com/about/c.html}
18048
18049 \end_inset 
18050
18051
18052 \end_inset 
18053 </cell>
18054 </row>
18055 <row topline="true">
18056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18057 \begin_inset Text
18058
18059 \layout Standard
18060
18061 c-faq
18062 \end_inset 
18063 </cell>
18064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18065 \begin_inset Text
18066
18067 \layout Standard
18068
18069 C-FAQ-list
18070 \end_inset 
18071 </cell>
18072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18073 \begin_inset Text
18074
18075 \layout Standard
18076
18077
18078 \begin_inset LatexCommand \url{http://www.eskimo.com/~scs/C-faq/top.html}
18079
18080 \end_inset 
18081
18082
18083 \end_inset 
18084 </cell>
18085 </row>
18086 <row topline="true">
18087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18088 \begin_inset Text
18089
18090 \layout Standard
18091
18092 \end_inset 
18093 </cell>
18094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18095 \begin_inset Text
18096
18097 \layout Standard
18098
18099 Latest datasheet of the target CPU
18100 \end_inset 
18101 </cell>
18102 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18103 \begin_inset Text
18104
18105 \layout Standard
18106
18107 vendor
18108 \end_inset 
18109 </cell>
18110 </row>
18111 <row topline="true">
18112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18113 \begin_inset Text
18114
18115 \layout Standard
18116
18117 \end_inset 
18118 </cell>
18119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18120 \begin_inset Text
18121
18122 \layout Standard
18123
18124 Revision history of datasheet
18125 \end_inset 
18126 </cell>
18127 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18128 \begin_inset Text
18129
18130 \layout Standard
18131
18132 vendor
18133 \end_inset 
18134 </cell>
18135 </row>
18136 <row topline="true" bottomline="true">
18137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18138 \begin_inset Text
18139
18140 \layout Standard
18141
18142 S.
18143  S.
18144  Muchnick
18145 \end_inset 
18146 </cell>
18147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18148 \begin_inset Text
18149
18150 \layout Standard
18151
18152 Advanced Compiler Design and Implementation
18153 \end_inset 
18154 </cell>
18155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18156 \begin_inset Text
18157
18158 \layout Standard
18159
18160 bookstore (very dedicated, probably read other books first)
18161 \end_inset 
18162 </cell>
18163 </row>
18164 </lyxtabular>
18165
18166 \end_inset 
18167
18168
18169 \newline 
18170
18171 \layout Section
18172
18173 Some Questions
18174 \layout Standard
18175
18176 Some questions answered, some pointers given - it might be time to in turn
18177  ask 
18178 \emph on 
18179 you
18180 \emph default 
18181  some questions: 
18182 \layout Itemize
18183
18184 can you solve your project with the selected microcontroller? Would you
18185  find out early or rather late that your target is too small/slow/whatever?
18186  Can you switch to a slightly better device if it doesn't fit?
18187 \layout Itemize
18188
18189 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
18190  and/or another programming language be more adequate? Would an operating
18191  system on the target device help?
18192 \layout Itemize
18193
18194 if you solved the problem, will the marketing department be happy?
18195 \layout Itemize
18196
18197 if the marketing department is happy, will customers be happy?
18198 \layout Itemize
18199
18200 if you're the project manager, marketing department and maybe even the customer
18201  in one person, have you tried to see the project from the outside?
18202 \layout Itemize
18203
18204 is the project done if you think it is done? Or is just that other interface/pro
18205 tocol/feature/configuration/option missing? How about website, manual(s),
18206  internationali(z|s)ation, packaging, labels, 2nd source for components,
18207  electromagnetic compatability/interference, documentation for production,
18208  production test software, update mechanism, patent issues?
18209 \layout Itemize
18210
18211 is your project adequately positioned in that magic triangle: fame, fortune,
18212  fun?
18213 \layout Standard
18214
18215 Maybe not all answers to these questions are known and some answers may
18216  even be 
18217 \emph on 
18218 no
18219 \emph default 
18220 , nevertheless knowing these questions may help you to avoid burnout
18221 \begin_inset Foot
18222 collapsed false
18223
18224 \layout Standard
18225
18226 burnout is bad for electronic devices, programmers and motorcycle tyres
18227 \end_inset 
18228
18229 .
18230  Chances are you didn't want to hear some of them...
18231 \layout Chapter
18232
18233 Support
18234 \begin_inset LatexCommand \index{Support}
18235
18236 \end_inset 
18237
18238
18239 \layout Standard
18240
18241 SDCC has grown to be a large project.
18242  The compiler alone (without the preprocessor, assembler and linker) is
18243  well over 100,000 lines of code (blank stripped).
18244  The open source nature of this project is a key to its continued growth
18245  and support.
18246  You gain the benefit and support of many active software developers and
18247  end users.
18248  Is SDCC perfect? No, that's why we need your help.
18249  The developers take pride in fixing reported bugs.
18250  You can help by reporting the bugs and helping other SDCC users.
18251  There are lots of ways to contribute, and we encourage you to take part
18252  in making SDCC a great software package.
18253  
18254 \layout Standard
18255
18256 The SDCC project is hosted on the SDCC sourceforge site at 
18257 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
18258
18259 \end_inset 
18260
18261 .
18262  You'll find the complete set of mailing lists
18263 \begin_inset LatexCommand \index{Mailing list}
18264
18265 \end_inset 
18266
18267 , forums, bug reporting system, patch submission
18268 \begin_inset LatexCommand \index{Patch submission}
18269
18270 \end_inset 
18271
18272  system, download
18273 \begin_inset LatexCommand \index{download}
18274
18275 \end_inset 
18276
18277  area and cvs code repository
18278 \begin_inset LatexCommand \index{cvs code repository}
18279
18280 \end_inset 
18281
18282  there.
18283 \layout Section
18284
18285 Reporting Bugs
18286 \begin_inset LatexCommand \index{Bug reporting}
18287
18288 \end_inset 
18289
18290
18291 \begin_inset LatexCommand \index{Reporting bugs}
18292
18293 \end_inset 
18294
18295
18296 \layout Standard
18297
18298 The recommended way of reporting bugs is using the infrastructure of the
18299  sourceforge site.
18300  You can follow the status of bug reports there and have an overview about
18301  the known bugs.
18302 \layout Standard
18303
18304 Bug reports are automatically forwarded to the developer mailing list and
18305  will be fixed ASAP.
18306  When reporting a bug, it is very useful to include a small test program
18307  (the smaller the better) which reproduces the problem.
18308  If you can isolate the problem by looking at the generated assembly code,
18309  this can be very helpful.
18310  Compiling your program with the -
18311 \begin_inset ERT
18312 status Collapsed
18313
18314 \layout Standard
18315
18316 \backslash 
18317 /
18318 \end_inset 
18319
18320 -dumpall
18321 \begin_inset LatexCommand \index{-\/-dumpall}
18322
18323 \end_inset 
18324
18325  option can sometimes be useful in locating optimization problems.
18326  When reporting a bug please maker sure you:
18327 \layout Enumerate
18328
18329 Attach the code you are compiling with SDCC.
18330  
18331 \layout Enumerate
18332
18333 Specify the exact command you use to run SDCC, or attach your Makefile.
18334  
18335 \layout Enumerate
18336
18337 Specify the SDCC version (type "
18338 \family sans 
18339 \series bold 
18340 sdcc -v
18341 \family default 
18342 \series default 
18343 "), your platform, and operating system.
18344  
18345 \layout Enumerate
18346
18347 Provide an exact copy of any error message or incorrect output.
18348  
18349 \layout Enumerate
18350
18351 Put something meaningful in the subject of your message.
18352 \layout Standard
18353
18354 Please attempt to include these 5 important parts, as applicable, in all
18355  requests for support or when reporting any problems or bugs with SDCC.
18356  Though this will make your message lengthy, it will greatly improve your
18357  chance that SDCC users and developers will be able to help you.
18358  Some SDCC developers are frustrated by bug reports without code provided
18359  that they can use to reproduce and ultimately fix the problem, so please
18360  be sure to provide sample code if you are reporting a bug! 
18361 \layout Standard
18362
18363 Please have a short check that you are using a recent version of SDCC and
18364  the bug is not yet known.
18365  This is the link for reporting bugs: 
18366 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
18367
18368 \end_inset 
18369
18370 .
18371 \layout Section
18372
18373 Requesting Features
18374 \begin_inset LatexCommand \label{sub:Requesting-Features}
18375
18376 \end_inset 
18377
18378
18379 \begin_inset LatexCommand \index{Feature request}
18380
18381 \end_inset 
18382
18383
18384 \begin_inset LatexCommand \index{Requesting features}
18385
18386 \end_inset 
18387
18388
18389 \layout Standard
18390
18391 Like bug reports feature requests are forwarded to the developer mailing
18392  list.
18393  This is the link for requesting features: 
18394 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
18395
18396 \end_inset 
18397
18398 .
18399 \layout Section
18400
18401 Submitting patches
18402 \layout Standard
18403
18404 Like bug reports contributed patches are forwarded to the developer mailing
18405  list.
18406  This is the link for submitting patches
18407 \begin_inset LatexCommand \index{Patch submission}
18408
18409 \end_inset 
18410
18411
18412 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
18413
18414 \end_inset 
18415
18416 .
18417 \layout Standard
18418
18419 You need to specify some parameters to the 
18420 \family typewriter 
18421 diff
18422 \family default 
18423  command for the patches to be useful.
18424  If you modified more than one file a patch created f.e.
18425  with 
18426 \family sans 
18427 \series bold 
18428
18429 \begin_inset Quotes sld
18430 \end_inset 
18431
18432 diff -Naur unmodified_directory modified_directory >my_changes.patch
18433 \begin_inset Quotes srd
18434 \end_inset 
18435
18436
18437 \family default 
18438 \series default 
18439  will be fine, otherwise 
18440 \family sans 
18441 \series bold 
18442
18443 \begin_inset Quotes sld
18444 \end_inset 
18445
18446 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
18447 \begin_inset Quotes srd
18448 \end_inset 
18449
18450
18451 \series default 
18452  
18453 \family default 
18454 will do.
18455 \layout Section
18456
18457 Getting Help
18458 \layout Standard
18459
18460 These links should take you directly to the 
18461 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
18462
18463 \end_inset 
18464
18465
18466 \begin_inset Foot
18467 collapsed false
18468
18469 \layout Standard
18470
18471 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
18472  automated messages (mid 2003)
18473 \end_inset 
18474
18475  and the 
18476 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
18477
18478 \end_inset 
18479
18480 , lists and forums are archived and searchable so if you are lucky someone
18481  already had a similar problem.
18482 \layout Section
18483
18484 ChangeLog
18485 \layout Standard
18486
18487 You can follow the status of the cvs version
18488 \begin_inset LatexCommand \index{version}
18489
18490 \end_inset 
18491
18492  of SDCC by watching the Changelog
18493 \begin_inset LatexCommand \index{Changelog}
18494
18495 \end_inset 
18496
18497  in the cvs-repository
18498 \newline 
18499
18500 \size footnotesize 
18501
18502 \begin_inset LatexCommand \htmlurl{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/sdcc/sdcc/ChangeLog?rev=HEAD&content-type=text/plain}
18503
18504 \end_inset 
18505
18506 .
18507 \layout Section
18508
18509 Release policy
18510 \begin_inset LatexCommand \index{Release policy}
18511
18512 \end_inset 
18513
18514
18515 \layout Standard
18516
18517 Historically there often were long delays between official releases and
18518  the sourceforge download area tends to get not updated at all.
18519  Excuses in the past might have referred to problems with live range analysis,
18520  but as this was fixed a while ago, the current problem is that another
18521  excuse has to be found.
18522  Kidding aside, we have to get better there! On the other hand there are
18523  daily snapshots available at 
18524 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
18525
18526 \end_inset 
18527
18528 , and you can always build the very last version (hopefully with many bugs
18529  fixed, and features added) from the source code available at 
18530 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
18531
18532 \end_inset 
18533
18534 .
18535 \layout Section
18536
18537 Examples
18538 \begin_inset LatexCommand \index{Examples}
18539
18540 \end_inset 
18541
18542
18543 \layout Standard
18544
18545 You'll find some small examples in the directory 
18546 \emph on 
18547 sdcc/device/examples/.
18548  
18549 \emph default 
18550 More examples and libraries are available at
18551 \emph on 
18552  The SDCC Open Knowledge Resource 
18553 \begin_inset LatexCommand \url{http://www.qsl.net/dl9sec/SDCC_OKR.html}
18554
18555 \end_inset 
18556
18557  
18558 \emph default 
18559 web site or at 
18560 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
18561
18562 \end_inset 
18563
18564 .
18565 \layout Comment
18566
18567 I did insert a reference to Paul's web site here although it seems rather
18568  dedicated to a specific 8032 board (I think it's okay because it f.e.
18569  shows LCD/Harddisc interface and has a free 8051 monitor.
18570  Independent 8032 board vendors face hard competition of heavily subsidized
18571  development boards anyway).
18572 \layout Comment
18573
18574 Maybe we should include some links to real world applications.
18575  Preferably pointer to pointers (one for each architecture) so this stays
18576  manageable here?
18577 \layout Section
18578
18579 Quality control
18580 \begin_inset LatexCommand \index{Quality control}
18581
18582 \end_inset 
18583
18584
18585 \layout Standard
18586
18587 The compiler is passed through nightly compile and build checks.
18588  The so called 
18589 \shape italic 
18590 regression tests
18591 \shape default 
18592
18593 \begin_inset LatexCommand \index{Regression test}
18594
18595 \end_inset 
18596
18597  check that SDCC itself compiles flawlessly on several platforms and checks
18598  the quality of the code generated by SDCC by running the code through simulator
18599 s.
18600  There is a separate document 
18601 \shape italic 
18602 test_suite.pdf
18603 \begin_inset LatexCommand \index{Test suite}
18604
18605 \end_inset 
18606
18607
18608 \shape default 
18609  about this.
18610 \layout Standard
18611
18612 You'll find the test code in the directory 
18613 \shape italic 
18614 sdcc/support/regression
18615 \shape default 
18616 .
18617  You can run these tests manually by running 
18618 \family sans 
18619 make
18620 \family default 
18621  in this directory (or f.e.
18622  
18623 \family sans 
18624 \series bold 
18625
18626 \begin_inset Quotes sld
18627 \end_inset 
18628
18629 make test-mcs51
18630 \begin_inset Quotes srd
18631 \end_inset 
18632
18633
18634 \family default 
18635 \series default 
18636  if you don't want to run the complete tests).
18637  The test code might also be interesting if you want to look for examples
18638 \begin_inset LatexCommand \index{Examples}
18639
18640 \end_inset 
18641
18642  checking corner cases of SDCC or if you plan to submit patches
18643 \begin_inset LatexCommand \index{Patch submission}
18644
18645 \end_inset 
18646
18647 .
18648 \layout Standard
18649
18650 The pic port uses a different set of regression tests, you'll find them
18651  in the directory 
18652 \shape italic 
18653 sdcc/src/regression
18654 \shape default 
18655 .
18656 \layout Chapter
18657 \pagebreak_top 
18658 SDCC Technical Data
18659 \layout Section
18660
18661 Optimizations
18662 \begin_inset LatexCommand \index{Optimizations}
18663
18664 \end_inset 
18665
18666
18667 \layout Standard
18668
18669 SDCC performs a host of standard optimizations in addition to some MCU specific
18670  optimizations.
18671  
18672 \layout Subsection
18673
18674 Sub-expression Elimination
18675 \begin_inset LatexCommand \index{Subexpression elimination}
18676
18677 \end_inset 
18678
18679
18680 \layout Standard
18681
18682 The compiler does local and 
18683 \emph on 
18684 g
18685 \emph default 
18686 lobal 
18687 \emph on 
18688 c
18689 \emph default 
18690 ommon 
18691 \emph on 
18692 s
18693 \emph default 
18694 ubexpression 
18695 \emph on 
18696 e
18697 \emph default 
18698 limination, e.g.: 
18699 \layout Verse
18700
18701
18702 \family typewriter 
18703 i = x + y + 1; 
18704 \newline 
18705 j = x + y;
18706 \layout Standard
18707
18708 will be translated to
18709 \layout Verse
18710
18711
18712 \family typewriter 
18713 iTemp = x + y; 
18714 \newline 
18715 i = iTemp + 1; 
18716 \newline 
18717 j = iTemp;
18718 \layout Standard
18719
18720 Some subexpressions are not as obvious as the above example, e.g.:
18721 \layout Verse
18722
18723
18724 \family typewriter 
18725 a->b[i].c = 10; 
18726 \newline 
18727 a->b[i].d = 11;
18728 \layout Standard
18729
18730 In this case the address arithmetic a->b[i] will be computed only once;
18731  the equivalent code in C would be.
18732 \layout Verse
18733
18734
18735 \family typewriter 
18736 iTemp = a->b[i]; 
18737 \newline 
18738 iTemp.c = 10; 
18739 \newline 
18740 iTemp.d = 11;
18741 \layout Standard
18742
18743 The compiler will try to keep these temporary variables in registers.
18744 \layout Subsection
18745
18746 Dead-Code Elimination
18747 \begin_inset LatexCommand \index{Dead-code elimination}
18748
18749 \end_inset 
18750
18751
18752 \layout Verse
18753
18754
18755 \family typewriter 
18756 int global;
18757 \newline 
18758
18759 \newline 
18760 void f () { 
18761 \newline 
18762 \SpecialChar ~
18763 \SpecialChar ~
18764 int i; 
18765 \newline 
18766 \SpecialChar ~
18767 \SpecialChar ~
18768 i = 1; \SpecialChar ~
18769 \SpecialChar ~
18770 \SpecialChar ~
18771 \SpecialChar ~
18772 \SpecialChar ~
18773 /* dead store */ 
18774 \newline 
18775 \SpecialChar ~
18776 \SpecialChar ~
18777 global = 1;\SpecialChar ~
18778 /* dead store */ 
18779 \newline 
18780 \SpecialChar ~
18781 \SpecialChar ~
18782 global = 2; 
18783 \newline 
18784 \SpecialChar ~
18785 \SpecialChar ~
18786 return; 
18787 \newline 
18788 \SpecialChar ~
18789 \SpecialChar ~
18790 global = 3;\SpecialChar ~
18791 /* unreachable */ 
18792 \newline 
18793 }
18794 \layout Standard
18795
18796 will be changed to
18797 \layout Verse
18798
18799
18800 \family typewriter 
18801 int global;
18802 \newline 
18803
18804 \newline 
18805 void f () {
18806 \newline 
18807 \SpecialChar ~
18808 \SpecialChar ~
18809 global = 2; 
18810 \newline 
18811 \SpecialChar ~
18812 \SpecialChar ~
18813 return; 
18814 \newline 
18815 }
18816 \layout Subsection
18817
18818 Copy-Propagation
18819 \begin_inset LatexCommand \index{Copy propagation}
18820
18821 \end_inset 
18822
18823
18824 \layout Verse
18825
18826
18827 \family typewriter 
18828 int f() { 
18829 \newline 
18830 \SpecialChar ~
18831 \SpecialChar ~
18832 int i, j; 
18833 \newline 
18834 \SpecialChar ~
18835 \SpecialChar ~
18836 i = 10; 
18837 \newline 
18838 \SpecialChar ~
18839 \SpecialChar ~
18840 j = i; 
18841 \newline 
18842 \SpecialChar ~
18843 \SpecialChar ~
18844 return j; 
18845 \newline 
18846 }
18847 \layout Standard
18848
18849 will be changed to 
18850 \layout Verse
18851
18852
18853 \family typewriter 
18854 int f() { 
18855 \newline 
18856 \SpecialChar ~
18857 \SpecialChar ~
18858 int i, j; 
18859 \newline 
18860 \SpecialChar ~
18861 \SpecialChar ~
18862 i = 10; 
18863 \newline 
18864 \SpecialChar ~
18865 \SpecialChar ~
18866 j = 10; 
18867 \newline 
18868 \SpecialChar ~
18869 \SpecialChar ~
18870 return 10; 
18871 \newline 
18872 }
18873 \layout Standard
18874
18875 Note: the dead stores created by this copy propagation will be eliminated
18876  by dead-code elimination.
18877 \layout Subsection
18878
18879 Loop Optimizations
18880 \begin_inset LatexCommand \index{Loop optimization}
18881
18882 \end_inset 
18883
18884
18885 \layout Standard
18886
18887 Two types of loop optimizations are done by SDCC loop invariant lifting
18888  and strength reduction of loop induction variables.
18889  In addition to the strength reduction the optimizer marks the induction
18890  variables and the register allocator tries to keep the induction variables
18891  in registers for the duration of the loop.
18892  Because of this preference of the register allocator
18893 \begin_inset LatexCommand \index{Register allocation}
18894
18895 \end_inset 
18896
18897 , loop induction optimization causes an increase in register pressure, which
18898  may cause unwanted spilling of other temporary variables into the stack
18899 \begin_inset LatexCommand \index{stack}
18900
18901 \end_inset 
18902
18903  / data space.
18904  The compiler will generate a warning message when it is forced to allocate
18905  extra space either on the stack or data space.
18906  If this extra space allocation is undesirable then induction optimization
18907  can be eliminated either for the entire source file (with -
18908 \begin_inset ERT
18909 status Collapsed
18910
18911 \layout Standard
18912
18913 \backslash 
18914 /
18915 \end_inset 
18916
18917 -noinduction option) or for a given function only using #pragma\SpecialChar ~
18918 noinduction
18919 \begin_inset LatexCommand \index{\#pragma noinduction}
18920
18921 \end_inset 
18922
18923 .
18924 \newline 
18925
18926 \newline 
18927 Loop Invariant:
18928 \layout Verse
18929
18930
18931 \family typewriter 
18932 for (i = 0 ; i < 100 ; i ++) 
18933 \newline 
18934 \SpecialChar ~
18935 \SpecialChar ~
18936 \SpecialChar ~
18937 \SpecialChar ~
18938 f += k + l;
18939 \layout Standard
18940
18941 changed to
18942 \layout Verse
18943
18944
18945 \family typewriter 
18946 itemp = k + l; 
18947 \newline 
18948 for (i = 0; i < 100; i++) 
18949 \newline 
18950 \SpecialChar ~
18951 \SpecialChar ~
18952 \SpecialChar ~
18953 \SpecialChar ~
18954 f += itemp;
18955 \layout Standard
18956
18957 As mentioned previously some loop invariants are not as apparent, all static
18958  address computations are also moved out of the loop.
18959 \newline 
18960
18961 \newline 
18962 Strength Reduction
18963 \begin_inset LatexCommand \index{Strength reduction}
18964
18965 \end_inset 
18966
18967 , this optimization substitutes an expression by a cheaper expression:
18968 \layout Verse
18969
18970
18971 \family typewriter 
18972 for (i=0;i < 100; i++)
18973 \newline 
18974 \SpecialChar ~
18975 \SpecialChar ~
18976 \SpecialChar ~
18977 \SpecialChar ~
18978 ar[i*5] = i*3;
18979 \layout Standard
18980
18981 changed to
18982 \layout Verse
18983
18984
18985 \family typewriter 
18986 itemp1 = 0; 
18987 \newline 
18988 itemp2 = 0; 
18989 \newline 
18990 for (i=0;i< 100;i++) { 
18991 \newline 
18992 \SpecialChar ~
18993 \SpecialChar ~
18994 \SpecialChar ~
18995 \SpecialChar ~
18996 ar[itemp1] = itemp2; 
18997 \newline 
18998 \SpecialChar ~
18999 \SpecialChar ~
19000 \SpecialChar ~
19001 \SpecialChar ~
19002 itemp1 += 5; 
19003 \newline 
19004 \SpecialChar ~
19005 \SpecialChar ~
19006 \SpecialChar ~
19007 \SpecialChar ~
19008 itemp2 += 3; 
19009 \newline 
19010 }
19011 \layout Standard
19012
19013 The more expensive multiplication
19014 \begin_inset LatexCommand \index{Multiplication}
19015
19016 \end_inset 
19017
19018  is changed to a less expensive addition.
19019 \layout Subsection
19020
19021 Loop Reversing
19022 \begin_inset LatexCommand \index{Loop reversing}
19023
19024 \end_inset 
19025
19026
19027 \layout Standard
19028
19029 This optimization is done to reduce the overhead of checking loop boundaries
19030  for every iteration.
19031  Some simple loops can be reversed and implemented using a 
19032 \begin_inset Quotes eld
19033 \end_inset 
19034
19035 decrement and jump if not zero
19036 \begin_inset Quotes erd
19037 \end_inset 
19038
19039  instruction.
19040  SDCC checks for the following criterion to determine if a loop is reversible
19041  (note: more sophisticated compilers use data-dependency analysis to make
19042  this determination, SDCC uses a more simple minded analysis).
19043 \layout Itemize
19044
19045 The 'for' loop is of the form 
19046 \newline 
19047
19048 \newline 
19049
19050 \family typewriter 
19051 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
19052  += 1])
19053 \newline 
19054 \SpecialChar ~
19055 \SpecialChar ~
19056 \SpecialChar ~
19057 \SpecialChar ~
19058 <for body>
19059 \layout Itemize
19060
19061 The <for body> does not contain 
19062 \begin_inset Quotes eld
19063 \end_inset 
19064
19065 continue
19066 \begin_inset Quotes erd
19067 \end_inset 
19068
19069  or 'break
19070 \begin_inset Quotes erd
19071 \end_inset 
19072
19073 .
19074 \layout Itemize
19075
19076 All goto's are contained within the loop.
19077 \layout Itemize
19078
19079 No function calls within the loop.
19080 \layout Itemize
19081
19082 The loop control variable <sym> is not assigned any value within the loop
19083 \layout Itemize
19084
19085 The loop control variable does NOT participate in any arithmetic operation
19086  within the loop.
19087 \layout Itemize
19088
19089 There are NO switch statements in the loop.
19090 \layout Subsection
19091
19092 Algebraic Simplifications
19093 \layout Standard
19094
19095 SDCC does numerous algebraic simplifications, the following is a small sub-set
19096  of these optimizations.
19097 \layout Verse
19098
19099
19100 \family typewriter 
19101 i = j + 0;\SpecialChar ~
19102 \SpecialChar ~
19103 \SpecialChar ~
19104 \SpecialChar ~
19105  /* changed to: */\SpecialChar ~
19106 \SpecialChar ~
19107 \SpecialChar ~
19108 \SpecialChar ~
19109  i = j; 
19110 \newline 
19111 i /= 2;\SpecialChar ~
19112 \SpecialChar ~
19113 \SpecialChar ~
19114 \SpecialChar ~
19115 \SpecialChar ~
19116 \SpecialChar ~
19117 \SpecialChar ~
19118  /* changed to: */\SpecialChar ~
19119 \SpecialChar ~
19120 \SpecialChar ~
19121 \SpecialChar ~
19122  i >>= 1; 
19123 \newline 
19124 i = j - j;\SpecialChar ~
19125 \SpecialChar ~
19126 \SpecialChar ~
19127 \SpecialChar ~
19128  /* changed to: */\SpecialChar ~
19129 \SpecialChar ~
19130 \SpecialChar ~
19131 \SpecialChar ~
19132  i = 0; 
19133 \newline 
19134 i = j / 1;\SpecialChar ~
19135 \SpecialChar ~
19136 \SpecialChar ~
19137 \SpecialChar ~
19138  /* changed to: */\SpecialChar ~
19139 \SpecialChar ~
19140 \SpecialChar ~
19141 \SpecialChar ~
19142  i = j;
19143 \layout Standard
19144
19145 Note the subexpressions
19146 \begin_inset LatexCommand \index{Subexpression}
19147
19148 \end_inset 
19149
19150  given above are generally introduced by macro expansions or as a result
19151  of copy/constant propagation.
19152 \layout Subsection
19153
19154 'switch' Statements
19155 \begin_inset LatexCommand \label{sub:'switch'-Statements}
19156
19157 \end_inset 
19158
19159
19160 \begin_inset LatexCommand \index{switch statement}
19161
19162 \end_inset 
19163
19164
19165 \layout Standard
19166
19167 SDCC changes switch statements to jump tables
19168 \begin_inset LatexCommand \index{jump tables}
19169
19170 \end_inset 
19171
19172  when the following conditions are true.
19173  
19174 \layout Itemize
19175
19176 The case labels are in numerical sequence, the labels need not be in order,
19177  and the starting number need not be one or zero.
19178 \begin_deeper 
19179 \layout Verse
19180
19181
19182 \family typewriter 
19183 switch(i) {\SpecialChar ~
19184 \SpecialChar ~
19185 \SpecialChar ~
19186 \SpecialChar ~
19187 \SpecialChar ~
19188 \SpecialChar ~
19189 \SpecialChar ~
19190 \SpecialChar ~
19191 \SpecialChar ~
19192 \SpecialChar ~
19193 \SpecialChar ~
19194 \SpecialChar ~
19195 \SpecialChar ~
19196 \SpecialChar ~
19197 \SpecialChar ~
19198 \SpecialChar ~
19199 \SpecialChar ~
19200 \SpecialChar ~
19201 \SpecialChar ~
19202 \SpecialChar ~
19203 \SpecialChar ~
19204 \SpecialChar ~
19205 \SpecialChar ~
19206 \SpecialChar ~
19207 \SpecialChar ~
19208 \SpecialChar ~
19209 switch (i) { 
19210 \newline 
19211 \SpecialChar ~
19212 \SpecialChar ~
19213 \SpecialChar ~
19214 case 4: ...\SpecialChar ~
19215 \SpecialChar ~
19216 \SpecialChar ~
19217 \SpecialChar ~
19218 \SpecialChar ~
19219 \SpecialChar ~
19220 \SpecialChar ~
19221 \SpecialChar ~
19222 \SpecialChar ~
19223 \SpecialChar ~
19224 \SpecialChar ~
19225 \SpecialChar ~
19226 \SpecialChar ~
19227 \SpecialChar ~
19228 \SpecialChar ~
19229 \SpecialChar ~
19230 \SpecialChar ~
19231 \SpecialChar ~
19232 \SpecialChar ~
19233 \SpecialChar ~
19234 \SpecialChar ~
19235 \SpecialChar ~
19236 \SpecialChar ~
19237 \SpecialChar ~
19238 \SpecialChar ~
19239 \SpecialChar ~
19240 case 0: ...
19241  
19242 \newline 
19243 \SpecialChar ~
19244 \SpecialChar ~
19245 \SpecialChar ~
19246 case 5: ...\SpecialChar ~
19247 \SpecialChar ~
19248 \SpecialChar ~
19249 \SpecialChar ~
19250 \SpecialChar ~
19251 \SpecialChar ~
19252 \SpecialChar ~
19253 \SpecialChar ~
19254 \SpecialChar ~
19255 \SpecialChar ~
19256 \SpecialChar ~
19257 \SpecialChar ~
19258 \SpecialChar ~
19259 \SpecialChar ~
19260 \SpecialChar ~
19261 \SpecialChar ~
19262 \SpecialChar ~
19263 \SpecialChar ~
19264 \SpecialChar ~
19265 \SpecialChar ~
19266 \SpecialChar ~
19267 \SpecialChar ~
19268 \SpecialChar ~
19269 \SpecialChar ~
19270 \SpecialChar ~
19271 \SpecialChar ~
19272 case 1: ...
19273  
19274 \newline 
19275 \SpecialChar ~
19276 \SpecialChar ~
19277 \SpecialChar ~
19278 case 3: ...\SpecialChar ~
19279 \SpecialChar ~
19280 \SpecialChar ~
19281 \SpecialChar ~
19282 \SpecialChar ~
19283 \SpecialChar ~
19284 \SpecialChar ~
19285 \SpecialChar ~
19286 \SpecialChar ~
19287 \SpecialChar ~
19288 \SpecialChar ~
19289 \SpecialChar ~
19290 \SpecialChar ~
19291 \SpecialChar ~
19292 \SpecialChar ~
19293 \SpecialChar ~
19294 \SpecialChar ~
19295 \SpecialChar ~
19296 \SpecialChar ~
19297 \SpecialChar ~
19298 \SpecialChar ~
19299 \SpecialChar ~
19300 \SpecialChar ~
19301 \SpecialChar ~
19302 \SpecialChar ~
19303 \SpecialChar ~
19304 case 2: ...
19305  
19306 \newline 
19307 \SpecialChar ~
19308 \SpecialChar ~
19309 \SpecialChar ~
19310 case 6: ...\SpecialChar ~
19311 \SpecialChar ~
19312 \SpecialChar ~
19313 \SpecialChar ~
19314 \SpecialChar ~
19315 \SpecialChar ~
19316 \SpecialChar ~
19317 \SpecialChar ~
19318 \SpecialChar ~
19319 \SpecialChar ~
19320 \SpecialChar ~
19321 \SpecialChar ~
19322 \SpecialChar ~
19323 \SpecialChar ~
19324 \SpecialChar ~
19325 \SpecialChar ~
19326 \SpecialChar ~
19327 \SpecialChar ~
19328 \SpecialChar ~
19329 \SpecialChar ~
19330 \SpecialChar ~
19331 \SpecialChar ~
19332 \SpecialChar ~
19333 \SpecialChar ~
19334 \SpecialChar ~
19335 \SpecialChar ~
19336 case 3: ...
19337  
19338 \newline 
19339 }\SpecialChar ~
19340 \SpecialChar ~
19341 \SpecialChar ~
19342 \SpecialChar ~
19343 \SpecialChar ~
19344 \SpecialChar ~
19345 \SpecialChar ~
19346 \SpecialChar ~
19347 \SpecialChar ~
19348 \SpecialChar ~
19349 \SpecialChar ~
19350 \SpecialChar ~
19351 \SpecialChar ~
19352 \SpecialChar ~
19353 \SpecialChar ~
19354 \SpecialChar ~
19355 \SpecialChar ~
19356 \SpecialChar ~
19357 \SpecialChar ~
19358 \SpecialChar ~
19359 \SpecialChar ~
19360 \SpecialChar ~
19361 \SpecialChar ~
19362 \SpecialChar ~
19363 \SpecialChar ~
19364 \SpecialChar ~
19365 \SpecialChar ~
19366 \SpecialChar ~
19367 \SpecialChar ~
19368 \SpecialChar ~
19369 \SpecialChar ~
19370 \SpecialChar ~
19371 \SpecialChar ~
19372 \SpecialChar ~
19373 \SpecialChar ~
19374 \SpecialChar ~
19375 }
19376 \layout Standard
19377
19378 Both the above switch statements will be implemented using a jump-table.
19379  The example to the right side is slightly more efficient as the check for
19380  the lower boundary of the jump-table is not needed.
19381 \end_deeper 
19382 \layout Itemize
19383
19384 The number of case labels is at least three, since it takes two conditional
19385  statements to handle the boundary conditions.
19386 \layout Itemize
19387
19388 The number of case labels is less than 84, since each label takes 3 bytes
19389  and a jump-table can be utmost 256 bytes long.
19390 \layout Standard
19391
19392 Switch statements which have gaps in the numeric sequence or those that
19393  have more that 84 case labels can be split into more than one switch statement
19394  for efficient code generation, e.g.:
19395 \layout Verse
19396
19397
19398 \family typewriter 
19399 switch (i) { 
19400 \newline 
19401 \SpecialChar ~
19402 \SpecialChar ~
19403 case 1: ...
19404  
19405 \newline 
19406 \SpecialChar ~
19407 \SpecialChar ~
19408 case 2: ...
19409  
19410 \newline 
19411 \SpecialChar ~
19412 \SpecialChar ~
19413 case 3: ...
19414  
19415 \newline 
19416 \SpecialChar ~
19417 \SpecialChar ~
19418 case 4: ...
19419  
19420 \newline 
19421 \SpecialChar ~
19422 \SpecialChar ~
19423 case 9: ...
19424  
19425 \newline 
19426 \SpecialChar ~
19427 \SpecialChar ~
19428 case 10: ...
19429  
19430 \newline 
19431 \SpecialChar ~
19432 \SpecialChar ~
19433 case 11: ...
19434  
19435 \newline 
19436 \SpecialChar ~
19437 \SpecialChar ~
19438 case 12: ...
19439  
19440 \newline 
19441 }
19442 \layout Standard
19443
19444 If the above switch statement is broken down into two switch statements
19445 \layout Verse
19446
19447
19448 \family typewriter 
19449 switch (i) { 
19450 \newline 
19451 \SpecialChar ~
19452 \SpecialChar ~
19453 case 1: ...
19454  
19455 \newline 
19456 \SpecialChar ~
19457 \SpecialChar ~
19458 case 2: ...
19459  
19460 \newline 
19461 \SpecialChar ~
19462 \SpecialChar ~
19463 case 3: ...
19464  
19465 \newline 
19466 \SpecialChar ~
19467 \SpecialChar ~
19468 case 4: ...
19469  
19470 \newline 
19471 }
19472 \layout Standard
19473
19474 and
19475 \layout Verse
19476
19477
19478 \family typewriter 
19479 switch (i) { 
19480 \newline 
19481 \SpecialChar ~
19482 \SpecialChar ~
19483 case 9:\SpecialChar ~
19484 \SpecialChar ~
19485 ...
19486  
19487 \newline 
19488 \SpecialChar ~
19489 \SpecialChar ~
19490 case 10:\SpecialChar ~
19491 ...
19492  
19493 \newline 
19494 \SpecialChar ~
19495 \SpecialChar ~
19496 case 11:\SpecialChar ~
19497 ...
19498  
19499 \newline 
19500 \SpecialChar ~
19501 \SpecialChar ~
19502 case 12:\SpecialChar ~
19503 ...
19504  
19505 \newline 
19506 }
19507 \layout Standard
19508
19509 then both the switch statements will be implemented using jump-tables whereas
19510  the unmodified switch statement will not be.
19511  You might also consider inserting dummy cases 0 and 5 to 8 in this example.
19512  
19513 \newline 
19514 The pragma nojtbound
19515 \begin_inset LatexCommand \index{\#pragma nojtbound}
19516
19517 \end_inset 
19518
19519  can be used to turn off checking the 
19520 \emph on 
19521 j
19522 \emph default 
19523 ump 
19524 \emph on 
19525 t
19526 \emph default 
19527 able 
19528 \emph on 
19529 bound
19530 \emph default 
19531 aries.
19532  It has no effect if a default label is supplied.
19533  Use of this pragma is dangerous: if the switch argument is not matched
19534  by a case statement the processor will happily jump into Nirvana.
19535 \layout Subsection
19536
19537 Bit-shifting Operations
19538 \begin_inset LatexCommand \index{Bit shifting}
19539
19540 \end_inset 
19541
19542 .
19543 \layout Standard
19544
19545 Bit shifting is one of the most frequently used operation in embedded programmin
19546 g.
19547  SDCC tries to implement bit-shift operations in the most efficient way
19548  possible, e.g.:
19549 \layout Verse
19550
19551
19552 \family typewriter 
19553 unsigned char i;
19554 \newline 
19555 ...
19556  
19557 \newline 
19558 i >>= 4; 
19559 \newline 
19560 ...
19561 \layout Standard
19562
19563 generates the following code:
19564 \layout Verse
19565
19566
19567 \family typewriter 
19568 mov\SpecialChar ~
19569  a,_i 
19570 \newline 
19571 swap a 
19572 \newline 
19573 anl\SpecialChar ~
19574  a,#0x0f 
19575 \newline 
19576 mov\SpecialChar ~
19577  _i,a
19578 \layout Standard
19579
19580 In general SDCC will never setup a loop if the shift count is known.
19581  Another example:
19582 \layout Verse
19583
19584
19585 \family typewriter 
19586 unsigned int i; 
19587 \newline 
19588 ...
19589  
19590 \newline 
19591 i >>= 9; 
19592 \newline 
19593 ...
19594 \layout Standard
19595
19596 will generate:
19597 \layout Verse
19598
19599
19600 \family typewriter 
19601 mov\SpecialChar ~
19602 \SpecialChar ~
19603 a,(_i + 1) 
19604 \newline 
19605 mov\SpecialChar ~
19606 \SpecialChar ~
19607 (_i + 1),#0x00 
19608 \newline 
19609 clr\SpecialChar ~
19610 \SpecialChar ~
19611
19612 \newline 
19613 rrc\SpecialChar ~
19614 \SpecialChar ~
19615
19616 \newline 
19617 mov\SpecialChar ~
19618 \SpecialChar ~
19619 _i,a
19620 \layout Subsection
19621
19622 Bit-rotation
19623 \begin_inset LatexCommand \index{Bit rotation}
19624
19625 \end_inset 
19626
19627
19628 \layout Standard
19629
19630 A special case of the bit-shift operation is bit rotation
19631 \begin_inset LatexCommand \index{rotating bits}
19632
19633 \end_inset 
19634
19635 , SDCC recognizes the following expression to be a left bit-rotation:
19636 \layout Verse
19637
19638
19639 \family typewriter 
19640 \series bold 
19641 unsigned
19642 \series default 
19643 \SpecialChar ~
19644 \SpecialChar ~
19645 char i;\SpecialChar ~
19646 \SpecialChar ~
19647 \SpecialChar ~
19648 \SpecialChar ~
19649 \SpecialChar ~
19650 \SpecialChar ~
19651 \SpecialChar ~
19652 \SpecialChar ~
19653 \SpecialChar ~
19654 \SpecialChar ~
19655 \SpecialChar ~
19656 /* unsigned is needed for rotation */ 
19657 \newline 
19658 ...
19659  
19660 \newline 
19661 i = ((i << 1) | (i >> 7)); 
19662 \family default 
19663
19664 \newline 
19665
19666 \family typewriter 
19667 ...
19668 \layout Standard
19669
19670 will generate the following code:
19671 \layout Verse
19672
19673
19674 \family typewriter 
19675 mov\SpecialChar ~
19676 \SpecialChar ~
19677 a,_i 
19678 \newline 
19679 rl\SpecialChar ~
19680 \SpecialChar ~
19681 \SpecialChar ~
19682
19683 \newline 
19684 mov\SpecialChar ~
19685 \SpecialChar ~
19686 _i,a
19687 \layout Standard
19688
19689 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
19690 ns of this case will also be recognized as bit-rotation, i.e.: 
19691 \layout Verse
19692
19693
19694 \family typewriter 
19695 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
19696 \layout Subsection
19697
19698 Nibble and Byte Swapping
19699 \layout Standard
19700
19701 Other special cases of the bit-shift operations are nibble or byte swapping
19702 \begin_inset LatexCommand \index{swapping nibbles/bytes}
19703
19704 \end_inset 
19705
19706 , SDCC recognizes the following expressions:
19707 \layout Verse
19708
19709
19710 \family typewriter 
19711 \series bold 
19712 unsigned
19713 \series default 
19714 \SpecialChar ~
19715 \SpecialChar ~
19716 char i; 
19717 \newline 
19718
19719 \series bold 
19720 unsigned
19721 \series default 
19722 \SpecialChar ~
19723 \SpecialChar ~
19724 int j; 
19725 \newline 
19726 ...
19727  
19728 \newline 
19729 i = ((i << 4) | (i >> 4)); 
19730 \family default 
19731
19732 \newline 
19733
19734 \family typewriter 
19735 j = ((j << 8) | (j >> 8)); 
19736 \layout Standard
19737
19738 and generates a swap instruction for the nibble swapping
19739 \begin_inset LatexCommand \index{Nibble swapping}
19740
19741 \end_inset 
19742
19743  or move instructions for the byte swapping
19744 \begin_inset LatexCommand \index{Byte swapping}
19745
19746 \end_inset 
19747
19748 .
19749  The 
19750 \begin_inset Quotes sld
19751 \end_inset 
19752
19753 j
19754 \begin_inset Quotes srd
19755 \end_inset 
19756
19757  example can be used to convert from little to big-endian or vice versa.
19758  If you want to change the endianness of a 
19759 \emph on 
19760 signed
19761 \emph default 
19762  integer you have to cast to 
19763 \family typewriter 
19764 (unsigned int)
19765 \family default 
19766  first.
19767 \layout Standard
19768
19769 Note that SDCC stores numbers in little-endian
19770 \begin_inset Foot
19771 collapsed false
19772
19773 \layout Standard
19774
19775 Usually 8-bit processors don't care much about endianness.
19776  This is not the case for the standard 8051 which only has an instruction
19777  to increment its 
19778 \emph on 
19779 dptr
19780 \emph default 
19781
19782 \begin_inset LatexCommand \index{DPTR}
19783
19784 \end_inset 
19785
19786 -datapointer
19787 \emph on 
19788  
19789 \emph default 
19790 so little-endian is the more efficient byte order.
19791 \end_inset 
19792
19793
19794 \begin_inset LatexCommand \index{little-endian}
19795
19796 \end_inset 
19797
19798
19799 \begin_inset LatexCommand \index{Endianness}
19800
19801 \end_inset 
19802
19803  format (i.e.
19804  lowest order first).
19805 \layout Subsection
19806
19807 Highest Order Bit
19808 \begin_inset LatexCommand \index{Highest Order Bit}
19809
19810 \end_inset 
19811
19812
19813 \layout Standard
19814
19815 It is frequently required to obtain the highest order bit of an integral
19816  type (long, int, short or char types).
19817  SDCC recognizes the following expression to yield the highest order bit
19818  and generates optimized code for it, e.g.:
19819 \layout Verse
19820
19821
19822 \family typewriter 
19823 unsigned int gint; 
19824 \newline 
19825
19826 \newline 
19827 foo () { 
19828 \newline 
19829 \SpecialChar ~
19830 \SpecialChar ~
19831 unsigned char hob; 
19832 \newline 
19833 \SpecialChar ~
19834 \SpecialChar ~
19835 ...
19836  
19837 \newline 
19838 \SpecialChar ~
19839 \SpecialChar ~
19840 hob = (gint >> 15) & 1; 
19841 \newline 
19842 \SpecialChar ~
19843 \SpecialChar ~
19844 ..
19845  
19846 \newline 
19847 }
19848 \layout Standard
19849
19850 will generate the following code:
19851 \layout Verse
19852
19853
19854 \family typewriter 
19855 \SpecialChar ~
19856 \SpecialChar ~
19857 \SpecialChar ~
19858 \SpecialChar ~
19859 \SpecialChar ~
19860 \SpecialChar ~
19861 \SpecialChar ~
19862 \SpecialChar ~
19863 \SpecialChar ~
19864 \SpecialChar ~
19865 \SpecialChar ~
19866 \SpecialChar ~
19867 \SpecialChar ~
19868 \SpecialChar ~
19869 \SpecialChar ~
19870 \SpecialChar ~
19871 \SpecialChar ~
19872 \SpecialChar ~
19873 \SpecialChar ~
19874 \SpecialChar ~
19875 \SpecialChar ~
19876 \SpecialChar ~
19877 \SpecialChar ~
19878 \SpecialChar ~
19879 \SpecialChar ~
19880  61 ;\SpecialChar ~
19881  hob.c 7 
19882 \newline 
19883 000A E5*01\SpecialChar ~
19884 \SpecialChar ~
19885 \SpecialChar ~
19886 \SpecialChar ~
19887 \SpecialChar ~
19888 \SpecialChar ~
19889 \SpecialChar ~
19890 \SpecialChar ~
19891 \SpecialChar ~
19892 \SpecialChar ~
19893 \SpecialChar ~
19894 \SpecialChar ~
19895 \SpecialChar ~
19896 \SpecialChar ~
19897 \SpecialChar ~
19898  62\SpecialChar ~
19899 \SpecialChar ~
19900 \SpecialChar ~
19901 \SpecialChar ~
19902 \SpecialChar ~
19903 \SpecialChar ~
19904 \SpecialChar ~
19905 \SpecialChar ~
19906  mov\SpecialChar ~
19907 \SpecialChar ~
19908  a,(_gint + 1) 
19909 \newline 
19910 000C 23\SpecialChar ~
19911 \SpecialChar ~
19912 \SpecialChar ~
19913 \SpecialChar ~
19914 \SpecialChar ~
19915 \SpecialChar ~
19916 \SpecialChar ~
19917 \SpecialChar ~
19918 \SpecialChar ~
19919 \SpecialChar ~
19920 \SpecialChar ~
19921 \SpecialChar ~
19922 \SpecialChar ~
19923 \SpecialChar ~
19924 \SpecialChar ~
19925 \SpecialChar ~
19926 \SpecialChar ~
19927 \SpecialChar ~
19928  63\SpecialChar ~
19929 \SpecialChar ~
19930 \SpecialChar ~
19931 \SpecialChar ~
19932 \SpecialChar ~
19933 \SpecialChar ~
19934 \SpecialChar ~
19935 \SpecialChar ~
19936  rl\SpecialChar ~
19937 \SpecialChar ~
19938 \SpecialChar ~
19939  a 
19940 \newline 
19941 000D 54 01\SpecialChar ~
19942 \SpecialChar ~
19943 \SpecialChar ~
19944 \SpecialChar ~
19945 \SpecialChar ~
19946 \SpecialChar ~
19947 \SpecialChar ~
19948 \SpecialChar ~
19949 \SpecialChar ~
19950 \SpecialChar ~
19951 \SpecialChar ~
19952 \SpecialChar ~
19953 \SpecialChar ~
19954 \SpecialChar ~
19955 \SpecialChar ~
19956  64\SpecialChar ~
19957 \SpecialChar ~
19958 \SpecialChar ~
19959 \SpecialChar ~
19960 \SpecialChar ~
19961 \SpecialChar ~
19962 \SpecialChar ~
19963 \SpecialChar ~
19964  anl\SpecialChar ~
19965 \SpecialChar ~
19966  a,#0x01 
19967 \newline 
19968 000F F5*02\SpecialChar ~
19969 \SpecialChar ~
19970 \SpecialChar ~
19971 \SpecialChar ~
19972 \SpecialChar ~
19973 \SpecialChar ~
19974 \SpecialChar ~
19975 \SpecialChar ~
19976 \SpecialChar ~
19977 \SpecialChar ~
19978 \SpecialChar ~
19979 \SpecialChar ~
19980 \SpecialChar ~
19981 \SpecialChar ~
19982 \SpecialChar ~
19983  65\SpecialChar ~
19984 \SpecialChar ~
19985 \SpecialChar ~
19986 \SpecialChar ~
19987 \SpecialChar ~
19988 \SpecialChar ~
19989 \SpecialChar ~
19990 \SpecialChar ~
19991  mov\SpecialChar ~
19992 \SpecialChar ~
19993  _foo_hob_1_1,a
19994 \layout Standard
19995
19996 Variations of this case however will 
19997 \emph on 
19998 not
19999 \emph default 
20000  be recognized.
20001  It is a standard C expression, so I heartily recommend this be the only
20002  way to get the highest order bit, (it is portable).
20003  Of course it will be recognized even if it is embedded in other expressions,
20004  e.g.:
20005 \layout Verse
20006
20007
20008 \family typewriter 
20009 xyz = gint + ((gint >> 15) & 1);
20010 \layout Standard
20011
20012 will still be recognized.
20013 \layout Subsection
20014
20015 Peephole Optimizer
20016 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
20017
20018 \end_inset 
20019
20020
20021 \begin_inset LatexCommand \index{Peephole optimizer}
20022
20023 \end_inset 
20024
20025
20026 \layout Standard
20027
20028 The compiler uses a rule based, pattern matching and re-writing mechanism
20029  for peep-hole optimization.
20030  It is inspired by 
20031 \emph on 
20032 copt
20033 \emph default 
20034  a peep-hole optimizer by Christopher W.
20035  Fraser (cwfraser@microsoft.com).
20036  A default set of rules are compiled into the compiler, additional rules
20037  may be added with the 
20038 \emph on 
20039 -
20040 \begin_inset ERT
20041 status Collapsed
20042
20043 \layout Standard
20044
20045 \backslash 
20046 /
20047 \end_inset 
20048
20049 -peep-file
20050 \begin_inset LatexCommand \index{-\/-peep-file}
20051
20052 \end_inset 
20053
20054  <filename>
20055 \emph default 
20056  option.
20057  The rule language is best illustrated with examples.
20058 \layout Verse
20059
20060
20061 \family typewriter 
20062 replace { 
20063 \newline 
20064 \SpecialChar ~
20065 \SpecialChar ~
20066 mov %1,a 
20067 \newline 
20068 \SpecialChar ~
20069 \SpecialChar ~
20070 mov a,%1
20071 \newline 
20072 } by {
20073 \newline 
20074 \SpecialChar ~
20075 \SpecialChar ~
20076 mov %1,a
20077 \newline 
20078 }
20079 \layout Standard
20080
20081 The above rule will change the following assembly
20082 \begin_inset LatexCommand \index{Assembler routines}
20083
20084 \end_inset 
20085
20086  sequence:
20087 \layout Verse
20088
20089
20090 \family typewriter 
20091 mov r1,a 
20092 \newline 
20093 mov a,r1
20094 \layout Standard
20095
20096 to
20097 \layout Verse
20098
20099
20100 \family typewriter 
20101 mov r1,a
20102 \layout Standard
20103
20104 Note: All occurrences of a 
20105 \emph on 
20106 %n
20107 \emph default 
20108  (pattern variable) must denote the same string.
20109  With the above rule, the assembly sequence:
20110 \layout Verse
20111
20112
20113 \family typewriter 
20114 mov r1,a 
20115 \newline 
20116 mov a,r2
20117 \layout Standard
20118
20119 will remain unmodified.
20120 \newline 
20121
20122 \newline 
20123 Other special case optimizations may be added by the user (via 
20124 \emph on 
20125 -
20126 \begin_inset ERT
20127 status Collapsed
20128
20129 \layout Standard
20130
20131 \backslash 
20132 /
20133 \end_inset 
20134
20135 -peep-file option
20136 \emph default 
20137 ).
20138  E.g.
20139  some variants of the 8051 MCU allow only 
20140 \family typewriter 
20141 ajmp
20142 \family default 
20143  and 
20144 \family typewriter 
20145 acall
20146 \family default 
20147 .
20148  The following two rules will change all 
20149 \family typewriter 
20150 ljmp
20151 \family default 
20152  and 
20153 \family typewriter 
20154 lcall
20155 \family default 
20156  to 
20157 \family typewriter 
20158 ajmp
20159 \family default 
20160  and 
20161 \family typewriter 
20162 acall
20163 \layout Verse
20164
20165
20166 \family typewriter 
20167 replace { lcall %1 } by { acall %1 } 
20168 \newline 
20169 replace { ljmp %1 } by { ajmp %1 }
20170 \layout Standard
20171
20172 The 
20173 \emph on 
20174 inline-assembler code
20175 \emph default 
20176  is also passed through the peep hole optimizer, thus the peephole optimizer
20177  can also be used as an assembly level macro expander.
20178  The rules themselves are MCU dependent whereas the rule language infra-structur
20179 e is MCU independent.
20180  Peephole optimization rules for other MCU can be easily programmed using
20181  the rule language.
20182 \newline 
20183
20184 \newline 
20185 The syntax for a rule is as follows:
20186 \layout Verse
20187
20188
20189 \family typewriter 
20190 rule := replace [ restart ] '{' <assembly sequence> '
20191 \backslash 
20192 n' 
20193 \newline 
20194 \SpecialChar ~
20195  \SpecialChar ~
20196  \SpecialChar ~
20197  \SpecialChar ~
20198  \SpecialChar ~
20199  \SpecialChar ~
20200  \SpecialChar ~
20201  \SpecialChar ~
20202  \SpecialChar ~
20203  \SpecialChar ~
20204  \SpecialChar ~
20205  \SpecialChar ~
20206  \SpecialChar ~
20207  \SpecialChar ~
20208  '}' by '{' '
20209 \backslash 
20210 n' 
20211 \newline 
20212 \SpecialChar ~
20213  \SpecialChar ~
20214  \SpecialChar ~
20215  \SpecialChar ~
20216  \SpecialChar ~
20217  \SpecialChar ~
20218  \SpecialChar ~
20219  \SpecialChar ~
20220  \SpecialChar ~
20221  \SpecialChar ~
20222  \SpecialChar ~
20223  \SpecialChar ~
20224  \SpecialChar ~
20225  \SpecialChar ~
20226  \SpecialChar ~
20227  \SpecialChar ~
20228  <assembly sequence> '
20229 \backslash 
20230 n' 
20231 \newline 
20232 \SpecialChar ~
20233  \SpecialChar ~
20234  \SpecialChar ~
20235  \SpecialChar ~
20236  \SpecialChar ~
20237  \SpecialChar ~
20238  \SpecialChar ~
20239  \SpecialChar ~
20240  \SpecialChar ~
20241  \SpecialChar ~
20242  \SpecialChar ~
20243  \SpecialChar ~
20244  \SpecialChar ~
20245  \SpecialChar ~
20246  '}' [if <functionName> ] '
20247 \backslash 
20248 n' 
20249 \layout Standard
20250
20251 <assembly sequence> := assembly instruction (each instruction including
20252  labels must be on a separate line).
20253 \newline 
20254
20255 \newline 
20256 The optimizer will apply to the rules one by one from the top in the sequence
20257  of their appearance, it will terminate when all rules are exhausted.
20258  If the 'restart' option is specified, then the optimizer will start matching
20259  the rules again from the top, this option for a rule is expensive (performance)
20260 , it is intended to be used in situations where a transformation will trigger
20261  the same rule again.
20262  An example of this (not a good one, it has side effects) is the following
20263  rule:
20264 \layout Verse
20265
20266
20267 \family typewriter 
20268 replace restart { 
20269 \newline 
20270 \SpecialChar ~
20271 \SpecialChar ~
20272 pop %1 
20273 \newline 
20274 \SpecialChar ~
20275 \SpecialChar ~
20276 push %1 } by { 
20277 \newline 
20278 \SpecialChar ~
20279 \SpecialChar ~
20280 ; nop 
20281 \newline 
20282 }
20283 \layout Standard
20284
20285 Note that the replace pattern cannot be a blank, but can be a comment line.
20286  Without the 'restart' option only the innermost 'pop' 'push' pair would
20287  be eliminated, i.e.:
20288 \layout Verse
20289
20290
20291 \family typewriter 
20292 pop ar1 
20293 \newline 
20294 pop ar2 
20295 \newline 
20296 push ar2 
20297 \newline 
20298 push ar1
20299 \layout Standard
20300
20301 would result in:
20302 \layout Verse
20303
20304
20305 \family typewriter 
20306 pop ar1 
20307 \newline 
20308 ; nop 
20309 \newline 
20310 push ar1
20311 \layout Standard
20312
20313
20314 \emph on 
20315 with
20316 \emph default 
20317  the restart option the rule will be applied again to the resulting code
20318  and then all the pop-push pairs will be eliminated to yield:
20319 \layout Verse
20320
20321
20322 \family typewriter 
20323 ; nop 
20324 \newline 
20325 ; nop
20326 \layout Standard
20327
20328 A conditional function can be attached to a rule.
20329  Attaching rules are somewhat more involved, let me illustrate this with
20330  an example.
20331 \layout Verse
20332
20333
20334 \family typewriter 
20335 replace { 
20336 \newline 
20337 \SpecialChar ~
20338  \SpecialChar ~
20339  \SpecialChar ~
20340 ljmp %5 
20341 \newline 
20342 %2:
20343 \newline 
20344 } by { 
20345 \newline 
20346 \SpecialChar ~
20347  \SpecialChar ~
20348  \SpecialChar ~
20349 sjmp %5 
20350 \newline 
20351 %2:
20352 \newline 
20353 } if labelInRange
20354 \layout Standard
20355
20356 The optimizer does a look-up of a function name table defined in function
20357  
20358 \emph on 
20359 callFuncByName
20360 \emph default 
20361  in the source file SDCCpeeph.c, with the name 
20362 \emph on 
20363 labelInRange
20364 \emph default 
20365 .
20366  If it finds a corresponding entry the function is called.
20367  Note there can be no parameters specified for these functions, in this
20368  case the use of 
20369 \emph on 
20370 %5
20371 \emph default 
20372  is crucial, since the function 
20373 \emph on 
20374 labelInRange
20375 \emph default 
20376  expects to find the label in that particular variable (the hash table containin
20377 g the variable bindings is passed as a parameter).
20378  If you want to code more such functions, take a close look at the function
20379  labelInRange and the calling mechanism in source file SDCCpeeph.c.
20380  Currently implemented are 
20381 \emph on 
20382 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
20383  24bitMode, portIsDS390, 24bitModeAndPortDS390 
20384 \emph default 
20385 and
20386 \emph on 
20387  notVolatile
20388 \emph default 
20389 .
20390 \layout Standard
20391
20392 I know this whole thing is a little kludgey, but maybe some day we will
20393  have some better means.
20394  If you are looking at this file, you will see the default rules that are
20395  compiled into the compiler, you can add your own rules in the default set
20396  there if you get tired of specifying the -
20397 \begin_inset ERT
20398 status Collapsed
20399
20400 \layout Standard
20401
20402 \backslash 
20403 /
20404 \end_inset 
20405
20406 -peep-file option.
20407 \layout Section
20408
20409 ANSI-Compliance
20410 \begin_inset LatexCommand \index{ANSI-compliance}
20411
20412 \end_inset 
20413
20414
20415 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
20416
20417 \end_inset 
20418
20419
20420 \layout Standard
20421
20422 Deviations from the compliance:
20423 \layout Itemize
20424
20425 functions are not always reentrant
20426 \begin_inset LatexCommand \index{reentrant}
20427
20428 \end_inset 
20429
20430 .
20431 \layout Itemize
20432
20433 structures cannot be assigned values directly, cannot be passed as function
20434  parameters or assigned to each other and cannot be a return value from
20435  a function, e.g.:
20436 \begin_deeper 
20437 \layout Verse
20438
20439
20440 \family typewriter 
20441 struct s { ...
20442  }; 
20443 \newline 
20444 struct s s1, s2; 
20445 \newline 
20446 foo() 
20447 \newline 
20448
20449 \newline 
20450 \SpecialChar ~
20451 \SpecialChar ~
20452 \SpecialChar ~
20453 \SpecialChar ~
20454 ...
20455  
20456 \newline 
20457 \SpecialChar ~
20458 \SpecialChar ~
20459 \SpecialChar ~
20460 \SpecialChar ~
20461 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
20462 \newline 
20463 \SpecialChar ~
20464 \SpecialChar ~
20465 \SpecialChar ~
20466 \SpecialChar ~
20467 ...
20468  
20469 \newline 
20470 }
20471 \newline 
20472 struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
20473  */
20474 \newline 
20475
20476 \newline 
20477 \SpecialChar ~
20478 \SpecialChar ~
20479 \SpecialChar ~
20480 \SpecialChar ~
20481 struct s rets; 
20482 \newline 
20483 \SpecialChar ~
20484 \SpecialChar ~
20485 \SpecialChar ~
20486 \SpecialChar ~
20487 ...
20488  
20489 \newline 
20490 \SpecialChar ~
20491 \SpecialChar ~
20492 \SpecialChar ~
20493 \SpecialChar ~
20494 return rets;/* is invalid in SDCC although allowed in ANSI */ 
20495 \newline 
20496 }
20497 \end_deeper 
20498 \layout Itemize
20499
20500 'long long
20501 \begin_inset LatexCommand \index{long long (not supported)}
20502
20503 \end_inset 
20504
20505 ' (64 bit integers
20506 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
20507
20508 \end_inset 
20509
20510 ) not supported.
20511 \layout Itemize
20512
20513 'double
20514 \begin_inset LatexCommand \index{double (not supported)}
20515
20516 \end_inset 
20517
20518 ' precision floating point 
20519 \begin_inset LatexCommand \index{Floating point support}
20520
20521 \end_inset 
20522
20523 not supported.
20524 \layout Itemize
20525
20526 No support for setjmp
20527 \begin_inset LatexCommand \index{setjmp (not supported)}
20528
20529 \end_inset 
20530
20531  and longjmp
20532 \begin_inset LatexCommand \index{longjmp (not supported)}
20533
20534 \end_inset 
20535
20536  (for now).
20537 \layout Itemize
20538
20539 Old K&R style
20540 \begin_inset LatexCommand \index{K\&R style}
20541
20542 \end_inset 
20543
20544  function declarations are NOT allowed.
20545 \begin_deeper 
20546 \layout Verse
20547
20548
20549 \family typewriter 
20550 foo(i,j) /* this old style of function declarations */ 
20551 \newline 
20552 int i,j; /* are valid in ANSI but not valid in SDCC */ 
20553 \newline 
20554
20555 \newline 
20556 \SpecialChar ~
20557 \SpecialChar ~
20558 \SpecialChar ~
20559 \SpecialChar ~
20560 ...
20561  
20562 \newline 
20563 }
20564 \end_deeper 
20565 \layout Itemize
20566
20567 functions declared as pointers
20568 \begin_inset LatexCommand \index{Pointer (to function)}
20569
20570 \end_inset 
20571
20572
20573 \begin_inset LatexCommand \index{function pointers}
20574
20575 \end_inset 
20576
20577  must be dereferenced during the call.
20578 \begin_deeper 
20579 \layout Verse
20580
20581
20582 \family typewriter 
20583 int (*foo)();
20584 \newline 
20585 ...
20586  
20587 \newline 
20588 /* has to be called like this */ 
20589 \newline 
20590 (*foo)(); /* ANSI standard allows calls to be made like 'foo()' */
20591 \end_deeper 
20592 \layout Section
20593
20594 Cyclomatic Complexity
20595 \begin_inset LatexCommand \index{Cyclomatic complexity}
20596
20597 \end_inset 
20598
20599
20600 \layout Standard
20601
20602 Cyclomatic complexity of a function is defined as the number of independent
20603  paths the program can take during execution of the function.
20604  This is an important number since it defines the number test cases you
20605  have to generate to validate the function.
20606  The accepted industry standard for complexity number is 10, if the cyclomatic
20607  complexity reported by SDCC exceeds 10 you should think about simplification
20608  of the function logic.
20609  Note that the complexity level is not related to the number of lines of
20610  code in a function.
20611  Large functions can have low complexity, and small functions can have large
20612  complexity levels.
20613  
20614 \newline 
20615
20616 \newline 
20617 SDCC uses the following formula to compute the complexity:
20618 \newline 
20619
20620 \layout Standard
20621
20622 complexity = (number of edges in control flow graph) - (number of nodes
20623  in control flow graph) + 2;
20624 \newline 
20625
20626 \newline 
20627 Having said that the industry standard is 10, you should be aware that in
20628  some cases it be may unavoidable to have a complexity level of less than
20629  10.
20630  For example if you have switch statement with more than 10 case labels,
20631  each case label adds one to the complexity level.
20632  The complexity level is by no means an absolute measure of the algorithmic
20633  complexity of the function, it does however provide a good starting point
20634  for which functions you might look at for further optimization.
20635 \layout Section
20636
20637 Retargetting for other Processors
20638 \layout Standard
20639
20640 The issues for retargetting the compiler are far too numerous to be covered
20641  by this document.
20642  What follows is a brief description of each of the seven phases of the
20643  compiler and its MCU dependency.
20644 \layout Itemize
20645
20646 Parsing the source and building the annotated parse tree.
20647  This phase is largely MCU independent (except for the language extensions).
20648  Syntax & semantic checks are also done in this phase, along with some initial
20649  optimizations like back patching labels and the pattern matching optimizations
20650  like bit-rotation etc.
20651 \layout Itemize
20652
20653 The second phase involves generating an intermediate code which can be easy
20654  manipulated during the later phases.
20655  This phase is entirely MCU independent.
20656  The intermediate code generation assumes the target machine has unlimited
20657  number of registers, and designates them with the name iTemp.
20658  The compiler can be made to dump a human readable form of the code generated
20659  by using the -
20660 \begin_inset ERT
20661 status Collapsed
20662
20663 \layout Standard
20664
20665 \backslash 
20666 /
20667 \end_inset 
20668
20669 -dumpraw option.
20670 \layout Itemize
20671
20672 This phase does the bulk of the standard optimizations and is also MCU independe
20673 nt.
20674  This phase can be broken down into several sub-phases:
20675 \newline 
20676
20677 \newline 
20678 Break down intermediate code (iCode) into basic blocks.
20679 \newline 
20680 Do control flow & data flow analysis on the basic blocks.
20681 \newline 
20682 Do local common subexpression elimination, then global subexpression elimination
20683 \newline 
20684 Dead code elimination
20685 \newline 
20686 Loop optimizations
20687 \newline 
20688 If loop optimizations caused any changes then do 'global subexpression eliminati
20689 on' and 'dead code elimination' again.
20690 \layout Itemize
20691
20692 This phase determines the live-ranges; by live range I mean those iTemp
20693  variables defined by the compiler that still survive after all the optimization
20694 s.
20695  Live range analysis
20696 \begin_inset LatexCommand \index{Live range analysis}
20697
20698 \end_inset 
20699
20700  is essential for register allocation, since these computation determines
20701  which of these iTemps will be assigned to registers, and for how long.
20702 \layout Itemize
20703
20704 Phase five is register allocation.
20705  There are two parts to this process.
20706 \newline 
20707
20708 \newline 
20709 The first part I call 'register packing' (for lack of a better term).
20710  In this case several MCU specific expression folding is done to reduce
20711  register pressure.
20712 \newline 
20713
20714 \newline 
20715 The second part is more MCU independent and deals with allocating registers
20716  to the remaining live ranges.
20717  A lot of MCU specific code does creep into this phase because of the limited
20718  number of index registers available in the 8051.
20719 \layout Itemize
20720
20721 The Code generation phase is (unhappily), entirely MCU dependent and very
20722  little (if any at all) of this code can be reused for other MCU.
20723  However the scheme for allocating a homogenized assembler operand for each
20724  iCode operand may be reused.
20725 \layout Itemize
20726
20727 As mentioned in the optimization section the peep-hole optimizer is rule
20728  based system, which can reprogrammed for other MCUs.
20729 \layout Chapter
20730
20731 Compiler internals
20732 \begin_inset LatexCommand \index{Compiler internals}
20733
20734 \end_inset 
20735
20736
20737 \layout Section
20738
20739 The anatomy of the compiler
20740 \begin_inset LatexCommand \label{sub:The-anatomy-of}
20741
20742 \end_inset 
20743
20744
20745 \layout Standard
20746
20747
20748 \shape italic 
20749 This is an excerpt from an article published in Circuit Cellar Magazine
20750  in august 2000.
20751  It's a little outdated (the compiler is much more efficient now and user/develo
20752 per friendly), but pretty well exposes the guts of it all.
20753 \shape default 
20754
20755 \newline 
20756
20757 \newline 
20758 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
20759  It is fairly easy to retarget for other 8-bit MCU.
20760  Here we take a look at some of the internals of the compiler.
20761  
20762 \layout Paragraph*
20763
20764 Parsing
20765 \begin_inset LatexCommand \index{Parsing}
20766
20767 \end_inset 
20768
20769  
20770 \layout Standard
20771
20772 Parsing the input source file and creating an AST (Annotated Syntax Tree
20773 \begin_inset LatexCommand \index{Annotated syntax tree}
20774
20775 \end_inset 
20776
20777 ).
20778  This phase also involves propagating types (annotating each node of the
20779  parse tree with type information) and semantic analysis.
20780  There are some MCU specific parsing rules.
20781  For example the storage classes, the extended storage classes are MCU specific
20782  while there may be a xdata storage class for 8051 there is no such storage
20783  class for z80 or Atmel AVR.
20784  SDCC allows MCU specific storage class extensions, i.e.
20785  xdata will be treated as a storage class specifier when parsing 8051 C
20786  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
20787  C code.
20788 \layout Paragraph*
20789
20790 Generating iCode
20791 \begin_inset LatexCommand \index{iCode}
20792
20793 \end_inset 
20794
20795
20796 \layout Standard
20797
20798 Intermediate code generation.
20799  In this phase the AST is broken down into three-operand form (iCode).
20800  These three operand forms are represented as doubly linked lists.
20801  ICode is the term given to the intermediate form generated by the compiler.
20802  ICode example section shows some examples of iCode generated for some simple
20803  C source functions.
20804 \layout Paragraph*
20805
20806 Optimizations
20807 \begin_inset LatexCommand \index{Optimizations}
20808
20809 \end_inset 
20810
20811 .
20812 \layout Standard
20813
20814 Bulk of the target independent optimizations is performed in this phase.
20815  The optimizations include constant propagation, common sub-expression eliminati
20816 on, loop invariant code movement, strength reduction of loop induction variables
20817  and dead-code elimination.
20818 \layout Paragraph*
20819
20820 Live range analysis
20821 \begin_inset LatexCommand \index{Live range analysis}
20822
20823 \end_inset 
20824
20825
20826 \layout Standard
20827
20828 During intermediate code generation phase, the compiler assumes the target
20829  machine has infinite number of registers and generates a lot of temporary
20830  variables.
20831  The live range computation determines the lifetime of each of these compiler-ge
20832 nerated temporaries.
20833  A picture speaks a thousand words.
20834  ICode example sections show the live range annotations for each of the
20835  operand.
20836  It is important to note here, each iCode is assigned a number in the order
20837  of its execution in the function.
20838  The live ranges are computed in terms of these numbers.
20839  The from number is the number of the iCode which first defines the operand
20840  and the to number signifies the iCode which uses this operand last.
20841 \layout Paragraph*
20842
20843 Register Allocation
20844 \begin_inset LatexCommand \index{Register allocation}
20845
20846 \end_inset 
20847
20848
20849 \layout Standard
20850
20851 The register allocation determines the type and number of registers needed
20852  by each operand.
20853  In most MCUs only a few registers can be used for indirect addressing.
20854  In case of 8051 for example the registers R0 & R1 can be used to indirectly
20855  address the internal ram and DPTR to indirectly address the external ram.
20856  The compiler will try to allocate the appropriate register to pointer variables
20857  if it can.
20858  ICode example section shows the operands annotated with the registers assigned
20859  to them.
20860  The compiler will try to keep operands in registers as much as possible;
20861  there are several schemes the compiler uses to do achieve this.
20862  When the compiler runs out of registers the compiler will check to see
20863  if there are any live operands which is not used or defined in the current
20864  basic block being processed, if there are any found then it will push that
20865  operand and use the registers in this block, the operand will then be popped
20866  at the end of the basic block.
20867  
20868 \layout Standard
20869
20870 There are other MCU specific considerations in this phase.
20871  Some MCUs have an accumulator; very short-lived operands could be assigned
20872  to the accumulator instead of a general-purpose register.
20873 \layout Paragraph*
20874
20875 Code generation
20876 \layout Standard
20877
20878 Figure II gives a table of iCode operations supported by the compiler.
20879  The code generation involves translating these operations into corresponding
20880  assembly code for the processor.
20881  This sounds overly simple but that is the essence of code generation.
20882  Some of the iCode operations are generated on a MCU specific manner for
20883  example, the z80 port does not use registers to pass parameters so the
20884  SEND and RECV iCode operations will not be generated, and it also does
20885  not support JUMPTABLES.
20886  
20887 \newline 
20888
20889 \series bold 
20890 \shape italic 
20891 \color red
20892 <Where is Figure II ?>
20893 \layout Paragraph*
20894
20895 ICode Example
20896 \begin_inset LatexCommand \index{iCode}
20897
20898 \end_inset 
20899
20900
20901 \layout Standard
20902
20903 This section shows some details of iCode.
20904  The example C code does not do anything useful; it is used as an example
20905  to illustrate the intermediate code generated by the compiler.
20906 \layout Verse
20907
20908
20909 \family typewriter 
20910 1.\SpecialChar ~
20911 xdata int * p;
20912 \newline 
20913 2.\SpecialChar ~
20914 int gint;
20915 \newline 
20916 3.\SpecialChar ~
20917 /* This function does nothing useful.
20918  It is used
20919 \newline 
20920 4.\SpecialChar ~
20921 \SpecialChar ~
20922 \SpecialChar ~
20923 \SpecialChar ~
20924 for the purpose of explaining iCode */
20925 \newline 
20926 5.\SpecialChar ~
20927 short function (data int *x)
20928 \newline 
20929 6.\SpecialChar ~
20930 {
20931 \newline 
20932 7.\SpecialChar ~
20933 \SpecialChar ~
20934 \SpecialChar ~
20935 short i=10; \SpecialChar ~
20936 \SpecialChar ~
20937 /* dead initialization eliminated */
20938 \newline 
20939 8.\SpecialChar ~
20940 \SpecialChar ~
20941 \SpecialChar ~
20942 short sum=10; /* dead initialization eliminated */
20943 \newline 
20944 9.\SpecialChar ~
20945 \SpecialChar ~
20946 \SpecialChar ~
20947 short mul;
20948 \newline 
20949 10.\SpecialChar ~
20950 \SpecialChar ~
20951 int j ;
20952 \newline 
20953 11.\SpecialChar ~
20954 \SpecialChar ~
20955 while (*x) *x++ = *p++; 
20956 \newline 
20957 12.\SpecialChar ~
20958 \SpecialChar ~
20959 \SpecialChar ~
20960 \SpecialChar ~
20961 sum = 0 ; 
20962 \newline 
20963 13.\SpecialChar ~
20964 \SpecialChar ~
20965 mul = 0;
20966 \newline 
20967 14.\SpecialChar ~
20968 \SpecialChar ~
20969 /* compiler detects i,j to be induction variables */
20970 \newline 
20971 15.\SpecialChar ~
20972 \SpecialChar ~
20973 for (i = 0, j = 10 ; i < 10 ; i++, j
20974 \family default 
20975 -
20976 \begin_inset ERT
20977 status Collapsed
20978
20979 \layout Standard
20980
20981 \backslash 
20982 /
20983 \end_inset 
20984
20985 -
20986 \family typewriter 
20987 ) {
20988 \newline 
20989 16.\SpecialChar ~
20990 \SpecialChar ~
20991 \SpecialChar ~
20992 \SpecialChar ~
20993 sum += i;
20994 \newline 
20995 17.\SpecialChar ~
20996 \SpecialChar ~
20997 \SpecialChar ~
20998 \SpecialChar ~
20999 mul += i * 3; \SpecialChar ~
21000 \SpecialChar ~
21001 /* this multiplication remains */
21002 \newline 
21003 18.\SpecialChar ~
21004 \SpecialChar ~
21005 \SpecialChar ~
21006 \SpecialChar ~
21007 gint += j * 3;\SpecialChar ~
21008 \SpecialChar ~
21009 /* this multiplication changed to addition */
21010 \newline 
21011 19.\SpecialChar ~
21012 \SpecialChar ~
21013 }
21014 \newline 
21015 20.\SpecialChar ~
21016 \SpecialChar ~
21017 return sum+mul;
21018 \newline 
21019 21.\SpecialChar ~
21020 }
21021 \layout Standard
21022
21023 In addition to the operands each iCode contains information about the filename
21024  and line it corresponds to in the source file.
21025  The first field in the listing should be interpreted as follows:
21026 \newline 
21027
21028 \shape italic 
21029 \size footnotesize 
21030 Filename(linenumber: iCode Execution sequence number : ICode hash table
21031  key : loop depth of the iCode).
21032 \shape default 
21033 \size default 
21034
21035 \newline 
21036 Then follows the human readable form of the ICode operation.
21037  Each operand of this triplet form can be of three basic types a) compiler
21038  generated temporary b) user defined variable c) a constant value.
21039  Note that local variables and parameters are replaced by compiler generated
21040  temporaries.
21041  Live ranges
21042 \begin_inset LatexCommand \index{Live range analysis}
21043
21044 \end_inset 
21045
21046  are computed only for temporaries (i.e.
21047  live ranges are not computed for global variables).
21048  Registers
21049 \begin_inset LatexCommand \index{Register allocation}
21050
21051 \end_inset 
21052
21053  are allocated for temporaries only.
21054  Operands are formatted in the following manner:
21055 \newline 
21056
21057 \shape italic 
21058 \size footnotesize 
21059 Operand Name [lr live-from : live-to ] { type information } [ registers
21060  allocated ].
21061 \shape default 
21062 \size default 
21063
21064 \newline 
21065 As mentioned earlier the live ranges are computed in terms of the execution
21066  sequence number of the iCodes, for example 
21067 \newline 
21068 the iTemp0 is live from (i.e.
21069  first defined in iCode with execution sequence number 3, and is last used
21070  in the iCode with sequence number 5).
21071  For induction variables such as iTemp21 the live range computation extends
21072  the lifetime from the start to the end of the loop.
21073 \newline 
21074 The register allocator used the live range information to allocate registers,
21075  the same registers may be used for different temporaries if their live
21076  ranges do not overlap, for example r0 is allocated to both iTemp6 and to
21077  iTemp17 since their live ranges do not overlap.
21078  In addition the allocator also takes into consideration the type and usage
21079  of a temporary, for example itemp6 is a pointer to near space and is used
21080  as to fetch data from (i.e.
21081  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
21082  Some short lived temporaries are allocated to special registers which have
21083  meaning to the code generator e.g.
21084  iTemp13 is allocated to a pseudo register CC which tells the back end that
21085  the temporary is used only for a conditional jump the code generation makes
21086  use of this information to optimize a compare and jump ICode.
21087 \newline 
21088 There are several loop optimizations
21089 \begin_inset LatexCommand \index{Loop optimization}
21090
21091 \end_inset 
21092
21093  performed by the compiler.
21094  It can detect induction variables iTemp21(i) and iTemp23(j).
21095  Also note the compiler does selective strength reduction
21096 \begin_inset LatexCommand \index{Strength reduction}
21097
21098 \end_inset 
21099
21100 , i.e.
21101  the multiplication of an induction variable in line 18 (gint = j * 3) is
21102  changed to addition, a new temporary iTemp17 is allocated and assigned
21103  a initial value, a constant 3 is then added for each iteration of the loop.
21104  The compiler does not change the multiplication
21105 \begin_inset LatexCommand \index{Multiplication}
21106
21107 \end_inset 
21108
21109  in line 17 however since the processor does support an 8 * 8 bit multiplication.
21110 \newline 
21111 Note the dead code elimination
21112 \begin_inset LatexCommand \index{Dead-code elimination}
21113
21114 \end_inset 
21115
21116  optimization eliminated the dead assignments in line 7 & 8 to I and sum
21117  respectively.
21118 \newline 
21119
21120 \layout Standard
21121
21122
21123 \size footnotesize 
21124 Sample.c (5:1:0:0) _entry($9) :
21125 \layout Standard
21126
21127
21128 \size footnotesize 
21129 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
21130 \layout Standard
21131
21132
21133 \size footnotesize 
21134 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
21135 \layout Standard
21136
21137
21138 \size footnotesize 
21139 Sample.c(11:4:53:0) preHeaderLbl0($11) :
21140 \layout Standard
21141
21142
21143 \size footnotesize 
21144 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
21145  * int}[r2]
21146 \layout Standard
21147
21148
21149 \size footnotesize 
21150 Sample.c(11:6:5:1) _whilecontinue_0($1) :
21151 \layout Standard
21152
21153
21154 \size footnotesize 
21155 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
21156  int}[r0]]
21157 \layout Standard
21158
21159
21160 \size footnotesize 
21161 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
21162 \layout Standard
21163
21164
21165 \size footnotesize 
21166 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
21167  * int}
21168 \layout Standard
21169
21170
21171 \size footnotesize 
21172 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
21173  {short}
21174 \layout Standard
21175
21176
21177 \size footnotesize 
21178 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
21179  * int}[DPTR]]
21180 \layout Standard
21181
21182
21183 \size footnotesize 
21184 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
21185 }[r2 r3]
21186 \layout Standard
21187
21188
21189 \size footnotesize 
21190 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
21191  * int}[r0] + 0x2 {short}
21192 \layout Standard
21193
21194
21195 \size footnotesize 
21196 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
21197 \layout Standard
21198
21199
21200 \size footnotesize 
21201 Sample.c(11:17:21:0)_whilebreak_0($3) :
21202 \layout Standard
21203
21204
21205 \size footnotesize 
21206 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
21207 \layout Standard
21208
21209
21210 \size footnotesize 
21211 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
21212 \layout Standard
21213
21214
21215 \size footnotesize 
21216 Sample.c(15:20:54:0)preHeaderLbl1($13) :
21217 \layout Standard
21218
21219
21220 \size footnotesize 
21221 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
21222 \layout Standard
21223
21224
21225 \size footnotesize 
21226 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
21227 \layout Standard
21228
21229
21230 \size footnotesize 
21231 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
21232 \layout Standard
21233
21234
21235 \size footnotesize 
21236 Sample.c(15:24:26:1)_forcond_0($4) :
21237 \layout Standard
21238
21239
21240 \size footnotesize 
21241 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
21242  < 0xa {short}
21243 \layout Standard
21244
21245
21246 \size footnotesize 
21247 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
21248 \layout Standard
21249
21250
21251 \size footnotesize 
21252 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
21253  + ITemp21 [lr21:38]{short}[r4]
21254 \layout Standard
21255
21256
21257 \size footnotesize 
21258 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
21259  * 0x3 {short}
21260 \layout Standard
21261
21262
21263 \size footnotesize 
21264 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
21265  + iTemp15 [lr29:30]{short}[r1]
21266 \layout Standard
21267
21268
21269 \size footnotesize 
21270 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
21271  r0]- 0x3 {short}
21272 \layout Standard
21273
21274
21275 \size footnotesize 
21276 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
21277 int}[r7 r0]
21278 \layout Standard
21279
21280
21281 \size footnotesize 
21282 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
21283  + 0x1 {short}
21284 \layout Standard
21285
21286
21287 \size footnotesize 
21288 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
21289  r6]- 0x1 {short}
21290 \layout Standard
21291
21292
21293 \size footnotesize 
21294 Sample.c(19:38:47:1) goto _forcond_0($4)
21295 \layout Standard
21296
21297
21298 \size footnotesize 
21299 Sample.c(19:39:48:0)_forbreak_0($7) :
21300 \layout Standard
21301
21302
21303 \size footnotesize 
21304 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
21305  + ITemp11 [lr19:40]{short}[r3]
21306 \layout Standard
21307
21308
21309 \size footnotesize 
21310 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
21311 \layout Standard
21312
21313
21314 \size footnotesize 
21315 Sample.c(20:42:51:0)_return($8) :
21316 \layout Standard
21317
21318
21319 \size footnotesize 
21320 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
21321 \size default 
21322
21323 \newline 
21324
21325 \newline 
21326 Finally the code generated for this function:
21327 \newline 
21328
21329 \layout Standard
21330
21331
21332 \size footnotesize 
21333 .area DSEG (DATA)
21334 \layout Standard
21335
21336
21337 \size footnotesize 
21338 _p::
21339 \layout Standard
21340
21341
21342 \size footnotesize 
21343 \SpecialChar ~
21344 \SpecialChar ~
21345 .ds 2
21346 \layout Standard
21347
21348
21349 \size footnotesize 
21350 _gint::
21351 \layout Standard
21352
21353
21354 \size footnotesize 
21355 \SpecialChar ~
21356 \SpecialChar ~
21357 .ds 2
21358 \layout Standard
21359
21360
21361 \size footnotesize 
21362 ; sample.c 5
21363 \layout Standard
21364
21365
21366 \size footnotesize 
21367 ; ----------------------------------------------
21368 \layout Standard
21369
21370
21371 \size footnotesize 
21372 ; function function
21373 \layout Standard
21374
21375
21376 \size footnotesize 
21377 ; ----------------------------------------------
21378 \layout Standard
21379
21380
21381 \size footnotesize 
21382 _function:
21383 \layout Standard
21384
21385
21386 \size footnotesize 
21387 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
21388 \layout Standard
21389
21390
21391 \size footnotesize 
21392 \SpecialChar ~
21393 \SpecialChar ~
21394 mov r2,dpl
21395 \layout Standard
21396
21397
21398 \size footnotesize 
21399 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
21400 \layout Standard
21401
21402
21403 \size footnotesize 
21404 \SpecialChar ~
21405 \SpecialChar ~
21406 mov ar0,r2
21407 \layout Standard
21408
21409
21410 \size footnotesize 
21411 ;_whilecontinue_0($1) :
21412 \layout Standard
21413
21414
21415 \size footnotesize 
21416 00101$:
21417 \layout Standard
21418
21419
21420 \size footnotesize 
21421 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
21422 \layout Standard
21423
21424
21425 \size footnotesize 
21426 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
21427 \layout Standard
21428
21429
21430 \size footnotesize 
21431 \SpecialChar ~
21432 \SpecialChar ~
21433 mov ar2,@r0
21434 \layout Standard
21435
21436
21437 \size footnotesize 
21438 \SpecialChar ~
21439 \SpecialChar ~
21440 inc r0
21441 \layout Standard
21442
21443
21444 \size footnotesize 
21445 \SpecialChar ~
21446 \SpecialChar ~
21447 mov ar3,@r0
21448 \layout Standard
21449
21450
21451 \size footnotesize 
21452 \SpecialChar ~
21453 \SpecialChar ~
21454 dec r0
21455 \layout Standard
21456
21457
21458 \size footnotesize 
21459 \SpecialChar ~
21460 \SpecialChar ~
21461 mov a,r2
21462 \layout Standard
21463
21464
21465 \size footnotesize 
21466 \SpecialChar ~
21467 \SpecialChar ~
21468 orl a,r3
21469 \layout Standard
21470
21471
21472 \size footnotesize 
21473 \SpecialChar ~
21474 \SpecialChar ~
21475 jz 00103$
21476 \layout Standard
21477
21478
21479 \size footnotesize 
21480 00114$:
21481 \layout Standard
21482
21483
21484 \size footnotesize 
21485 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
21486 \layout Standard
21487
21488
21489 \size footnotesize 
21490 \SpecialChar ~
21491 \SpecialChar ~
21492 mov dpl,_p
21493 \layout Standard
21494
21495
21496 \size footnotesize 
21497 \SpecialChar ~
21498 \SpecialChar ~
21499 mov dph,(_p + 1)
21500 \layout Standard
21501
21502
21503 \size footnotesize 
21504 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
21505 \layout Standard
21506
21507
21508 \size footnotesize 
21509 \SpecialChar ~
21510 \SpecialChar ~
21511 mov a,#0x02
21512 \layout Standard
21513
21514
21515 \size footnotesize 
21516 \SpecialChar ~
21517 \SpecialChar ~
21518 add a,_p
21519 \layout Standard
21520
21521
21522 \size footnotesize 
21523 \SpecialChar ~
21524 \SpecialChar ~
21525 mov _p,a
21526 \layout Standard
21527
21528
21529 \size footnotesize 
21530 \SpecialChar ~
21531 \SpecialChar ~
21532 clr a
21533 \layout Standard
21534
21535
21536 \size footnotesize 
21537 \SpecialChar ~
21538 \SpecialChar ~
21539 addc a,(_p + 1)
21540 \layout Standard
21541
21542
21543 \size footnotesize 
21544 \SpecialChar ~
21545 \SpecialChar ~
21546 mov (_p + 1),a
21547 \layout Standard
21548
21549
21550 \size footnotesize 
21551 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
21552 \layout Standard
21553
21554
21555 \size footnotesize 
21556 \SpecialChar ~
21557 \SpecialChar ~
21558 movx a,@dptr
21559 \layout Standard
21560
21561
21562 \size footnotesize 
21563 \SpecialChar ~
21564 \SpecialChar ~
21565 mov r2,a
21566 \layout Standard
21567
21568
21569 \size footnotesize 
21570 \SpecialChar ~
21571 \SpecialChar ~
21572 inc dptr
21573 \layout Standard
21574
21575
21576 \size footnotesize 
21577 \SpecialChar ~
21578 \SpecialChar ~
21579 movx a,@dptr
21580 \layout Standard
21581
21582
21583 \size footnotesize 
21584 \SpecialChar ~
21585 \SpecialChar ~
21586 mov r3,a
21587 \layout Standard
21588
21589
21590 \size footnotesize 
21591 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
21592 \layout Standard
21593
21594
21595 \size footnotesize 
21596 \SpecialChar ~
21597 \SpecialChar ~
21598 mov @r0,ar2
21599 \layout Standard
21600
21601
21602 \size footnotesize 
21603 \SpecialChar ~
21604 \SpecialChar ~
21605 inc r0
21606 \layout Standard
21607
21608
21609 \size footnotesize 
21610 \SpecialChar ~
21611 \SpecialChar ~
21612 mov @r0,ar3
21613 \layout Standard
21614
21615
21616 \size footnotesize 
21617 ; iTemp6 [lr5:16]{_near * int}[r0] = 
21618 \layout Standard
21619
21620
21621 \size footnotesize 
21622 ; iTemp6 [lr5:16]{_near * int}[r0] + 
21623 \layout Standard
21624
21625
21626 \size footnotesize 
21627 ; 0x2 {short}
21628 \layout Standard
21629
21630
21631 \size footnotesize 
21632 \SpecialChar ~
21633 \SpecialChar ~
21634 inc r0
21635 \layout Standard
21636
21637
21638 \size footnotesize 
21639 ; goto _whilecontinue_0($1)
21640 \layout Standard
21641
21642
21643 \size footnotesize 
21644 \SpecialChar ~
21645 \SpecialChar ~
21646 sjmp 00101$
21647 \layout Standard
21648
21649
21650 \size footnotesize 
21651 ; _whilebreak_0($3) :
21652 \layout Standard
21653
21654
21655 \size footnotesize 
21656 00103$:
21657 \layout Standard
21658
21659
21660 \size footnotesize 
21661 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
21662 \layout Standard
21663
21664
21665 \size footnotesize 
21666 \SpecialChar ~
21667 \SpecialChar ~
21668 mov r2,#0x00
21669 \layout Standard
21670
21671
21672 \size footnotesize 
21673 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
21674 \layout Standard
21675
21676
21677 \size footnotesize 
21678 \SpecialChar ~
21679 \SpecialChar ~
21680 mov r3,#0x00
21681 \layout Standard
21682
21683
21684 \size footnotesize 
21685 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
21686 \layout Standard
21687
21688
21689 \size footnotesize 
21690 \SpecialChar ~
21691 \SpecialChar ~
21692 mov r4,#0x00
21693 \layout Standard
21694
21695
21696 \size footnotesize 
21697 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
21698 \layout Standard
21699
21700
21701 \size footnotesize 
21702 \SpecialChar ~
21703 \SpecialChar ~
21704 mov r5,#0x0A
21705 \layout Standard
21706
21707
21708 \size footnotesize 
21709 \SpecialChar ~
21710 \SpecialChar ~
21711 mov r6,#0x00
21712 \layout Standard
21713
21714
21715 \size footnotesize 
21716 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
21717 \layout Standard
21718
21719
21720 \size footnotesize 
21721 \SpecialChar ~
21722 \SpecialChar ~
21723 mov r7,#0x1E
21724 \layout Standard
21725
21726
21727 \size footnotesize 
21728 \SpecialChar ~
21729 \SpecialChar ~
21730 mov r0,#0x00
21731 \layout Standard
21732
21733
21734 \size footnotesize 
21735 ; _forcond_0($4) :
21736 \layout Standard
21737
21738
21739 \size footnotesize 
21740 00104$:
21741 \layout Standard
21742
21743
21744 \size footnotesize 
21745 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
21746 \layout Standard
21747
21748
21749 \size footnotesize 
21750 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
21751 \layout Standard
21752
21753
21754 \size footnotesize 
21755 \SpecialChar ~
21756 \SpecialChar ~
21757 clr c
21758 \layout Standard
21759
21760
21761 \size footnotesize 
21762 \SpecialChar ~
21763 \SpecialChar ~
21764 mov a,r4
21765 \layout Standard
21766
21767
21768 \size footnotesize 
21769 \SpecialChar ~
21770 \SpecialChar ~
21771 xrl a,#0x80
21772 \layout Standard
21773
21774
21775 \size footnotesize 
21776 \SpecialChar ~
21777 \SpecialChar ~
21778 subb a,#0x8a
21779 \layout Standard
21780
21781
21782 \size footnotesize 
21783 \SpecialChar ~
21784 \SpecialChar ~
21785 jnc 00107$
21786 \layout Standard
21787
21788
21789 \size footnotesize 
21790 00115$:
21791 \layout Standard
21792
21793
21794 \size footnotesize 
21795 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
21796 \layout Standard
21797
21798
21799 \size footnotesize 
21800 ; iTemp21 [lr21:38]{short}[r4]
21801 \layout Standard
21802
21803
21804 \size footnotesize 
21805 \SpecialChar ~
21806 \SpecialChar ~
21807 mov a,r4
21808 \layout Standard
21809
21810
21811 \size footnotesize 
21812 \SpecialChar ~
21813 \SpecialChar ~
21814 add a,r2
21815 \layout Standard
21816
21817
21818 \size footnotesize 
21819 \SpecialChar ~
21820 \SpecialChar ~
21821 mov r2,a
21822 \layout Standard
21823
21824
21825 \size footnotesize 
21826 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
21827 \layout Standard
21828
21829
21830 \size footnotesize 
21831 \SpecialChar ~
21832 \SpecialChar ~
21833 mov b,#0x03
21834 \layout Standard
21835
21836
21837 \size footnotesize 
21838 \SpecialChar ~
21839 \SpecialChar ~
21840 mov a,r4
21841 \layout Standard
21842
21843
21844 \size footnotesize 
21845 \SpecialChar ~
21846 \SpecialChar ~
21847 mul ab
21848 \layout Standard
21849
21850
21851 \size footnotesize 
21852 \SpecialChar ~
21853 \SpecialChar ~
21854 mov r1,a
21855 \layout Standard
21856
21857
21858 \size footnotesize 
21859 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
21860 \layout Standard
21861
21862
21863 \size footnotesize 
21864 ; iTemp15 [lr29:30]{short}[r1]
21865 \layout Standard
21866
21867
21868 \size footnotesize 
21869 \SpecialChar ~
21870 \SpecialChar ~
21871 add a,r3
21872 \layout Standard
21873
21874
21875 \size footnotesize 
21876 \SpecialChar ~
21877 \SpecialChar ~
21878 mov r3,a
21879 \layout Standard
21880
21881
21882 \size footnotesize 
21883 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
21884 \layout Standard
21885
21886
21887 \size footnotesize 
21888 \SpecialChar ~
21889 \SpecialChar ~
21890 mov a,r7
21891 \layout Standard
21892
21893
21894 \size footnotesize 
21895 \SpecialChar ~
21896 \SpecialChar ~
21897 add a,#0xfd
21898 \layout Standard
21899
21900
21901 \size footnotesize 
21902 \SpecialChar ~
21903 \SpecialChar ~
21904 mov r7,a
21905 \layout Standard
21906
21907
21908 \size footnotesize 
21909 \SpecialChar ~
21910 \SpecialChar ~
21911 mov a,r0
21912 \layout Standard
21913
21914
21915 \size footnotesize 
21916 \SpecialChar ~
21917 \SpecialChar ~
21918 addc a,#0xff
21919 \layout Standard
21920
21921
21922 \size footnotesize 
21923 \SpecialChar ~
21924 \SpecialChar ~
21925 mov r0,a
21926 \layout Standard
21927
21928
21929 \size footnotesize 
21930 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
21931 \layout Standard
21932
21933
21934 \size footnotesize 
21935 \SpecialChar ~
21936 \SpecialChar ~
21937 mov a,r7
21938 \layout Standard
21939
21940
21941 \size footnotesize 
21942 \SpecialChar ~
21943 \SpecialChar ~
21944 add a,_gint
21945 \layout Standard
21946
21947
21948 \size footnotesize 
21949 \SpecialChar ~
21950 \SpecialChar ~
21951 mov _gint,a
21952 \layout Standard
21953
21954
21955 \size footnotesize 
21956 \SpecialChar ~
21957 \SpecialChar ~
21958 mov a,r0
21959 \layout Standard
21960
21961
21962 \size footnotesize 
21963 \SpecialChar ~
21964 \SpecialChar ~
21965 addc a,(_gint + 1)
21966 \layout Standard
21967
21968
21969 \size footnotesize 
21970 \SpecialChar ~
21971 \SpecialChar ~
21972 mov (_gint + 1),a
21973 \layout Standard
21974
21975
21976 \size footnotesize 
21977 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
21978 \layout Standard
21979
21980
21981 \size footnotesize 
21982 \SpecialChar ~
21983 \SpecialChar ~
21984 inc r4
21985 \layout Standard
21986
21987
21988 \size footnotesize 
21989 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
21990 \layout Standard
21991
21992
21993 \size footnotesize 
21994 \SpecialChar ~
21995 \SpecialChar ~
21996 dec r5
21997 \layout Standard
21998
21999
22000 \size footnotesize 
22001 \SpecialChar ~
22002 \SpecialChar ~
22003 cjne r5,#0xff,00104$
22004 \layout Standard
22005
22006
22007 \size footnotesize 
22008 \SpecialChar ~
22009 \SpecialChar ~
22010 dec r6
22011 \layout Standard
22012
22013
22014 \size footnotesize 
22015 ; goto _forcond_0($4)
22016 \layout Standard
22017
22018
22019 \size footnotesize 
22020 \SpecialChar ~
22021 \SpecialChar ~
22022 sjmp 00104$
22023 \layout Standard
22024
22025
22026 \size footnotesize 
22027 ; _forbreak_0($7) :
22028 \layout Standard
22029
22030
22031 \size footnotesize 
22032 00107$:
22033 \layout Standard
22034
22035
22036 \size footnotesize 
22037 ; ret iTemp24 [lr40:41]{short}
22038 \layout Standard
22039
22040
22041 \size footnotesize 
22042 \SpecialChar ~
22043 \SpecialChar ~
22044 mov a,r3
22045 \layout Standard
22046
22047
22048 \size footnotesize 
22049 \SpecialChar ~
22050 \SpecialChar ~
22051 add a,r2
22052 \layout Standard
22053
22054
22055 \size footnotesize 
22056 \SpecialChar ~
22057 \SpecialChar ~
22058 mov dpl,a
22059 \layout Standard
22060
22061
22062 \size footnotesize 
22063 ; _return($8) :
22064 \layout Standard
22065
22066
22067 \size footnotesize 
22068 00108$:
22069 \layout Standard
22070
22071
22072 \size footnotesize 
22073 \SpecialChar ~
22074 \SpecialChar ~
22075 ret
22076 \newline 
22077
22078 \layout Section
22079
22080 A few words about basic block successors, predecessors and dominators
22081 \layout Standard
22082
22083 Successors are basic blocks
22084 \begin_inset LatexCommand \index{Basic blocks}
22085
22086 \end_inset 
22087
22088  that might execute after this basic block.
22089 \newline 
22090 Predecessors are basic blocks that might execute before reaching this basic
22091  block.
22092 \newline 
22093 Dominators are basic blocks that WILL execute before reaching this basic
22094  block.
22095 \newline 
22096
22097 \layout Standard
22098
22099 [basic block 1]
22100 \layout Standard
22101
22102 if (something)
22103 \layout Standard
22104
22105 \SpecialChar ~
22106 \SpecialChar ~
22107 \SpecialChar ~
22108 \SpecialChar ~
22109 [basic block 2]
22110 \layout Standard
22111
22112 else
22113 \layout Standard
22114
22115 \SpecialChar ~
22116 \SpecialChar ~
22117 \SpecialChar ~
22118 \SpecialChar ~
22119 [basic block 3]
22120 \layout Standard
22121
22122 [basic block 4]
22123 \newline 
22124
22125 \layout Standard
22126
22127 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
22128 \layout Standard
22129
22130 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
22131 \layout Standard
22132
22133 c) domVect of [BB4] = BB1 ...
22134  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
22135  was executed.
22136 \layout Chapter
22137
22138 Acknowledgments
22139 \layout Standard
22140
22141
22142 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
22143
22144 \end_inset 
22145
22146
22147 \newline 
22148
22149 \newline 
22150
22151 \emph on 
22152 Thanks to all the other volunteer developers who have helped with coding,
22153  testing, web-page creation, distribution sets, etc.
22154  You know who you are :-)
22155 \emph default 
22156
22157 \newline 
22158
22159 \layout Standard
22160
22161 This document was initially written by Sandeep Dutta
22162 \layout Standard
22163
22164 All product names mentioned herein may be trademarks
22165 \begin_inset LatexCommand \index{Trademarks}
22166
22167 \end_inset 
22168
22169  of their respective companies.
22170  
22171 \layout Section*
22172
22173 Alphabetical index
22174 \layout Standard
22175
22176 To avoid confusion, the installation and building options for SDCC itself
22177  (chapter 2) are not part of the index.
22178 \layout Standard
22179
22180
22181 \begin_inset LatexCommand \printindex{}
22182
22183 \end_inset 
22184
22185
22186 \the_end