* doc/sdccman.lyx,
[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  So that the startup code can correctly initialize xdata variables, you
14278  should define an sfr with the name _XPAGE at the appropriate location if
14279  the default, port P2, is not used for this.
14280  Some examples are:
14281 \layout Verse
14282
14283
14284 \family typewriter 
14285 sfr at 0x92 _XPAGE; /* Cypress EZ-USB family */
14286 \layout Verse
14287
14288
14289 \family typewriter 
14290 sfr at 0xaf _XPAGE; /* some Silicon Labs (Cygnal) chips */
14291 \layout Verse
14292
14293
14294 \family typewriter 
14295 sfr at 0xaa _XPAGE; /* some Silicon Labs (Cygnal) chips */
14296 \layout Standard
14297
14298 For more exotic implementations further customizations may be needed.
14299  See section 
14300 \begin_inset LatexCommand \ref{sub:Startup-Code}
14301
14302 \end_inset 
14303
14304  for other possibilities.
14305 \layout Subsection
14306
14307 Other Features available by SFR
14308 \layout Standard
14309
14310 Some MCS51 variants offer features like Double DPTR
14311 \begin_inset LatexCommand \index{DPTR}
14312
14313 \end_inset 
14314
14315 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
14316  These are currently not used for the MCS51 port.
14317  If you absolutely need them you can fall back to inline assembly or submit
14318  a patch to SDCC.
14319 \layout Section
14320
14321 The Z80 and gbz80 port
14322 \layout Standard
14323
14324 SDCC can target both the Zilog 
14325 \begin_inset LatexCommand \index{Z80}
14326
14327 \end_inset 
14328
14329  and the Nintendo Gameboy's Z80-like gbz80
14330 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
14331
14332 \end_inset 
14333
14334 .
14335  The Z80 port is passed through the same 
14336 \emph on 
14337 regressions tests
14338 \begin_inset LatexCommand \index{Regression test}
14339
14340 \end_inset 
14341
14342
14343 \emph default 
14344  as the MCS51 and DS390 ports, so floating point support, support for long
14345  variables and bitfield support is fine.
14346  See mailing lists and forums about interrupt routines.
14347 \layout Standard
14348
14349 As always, the code is the authoritative reference - see z80/ralloc.c and
14350  z80/gen.c.
14351  The stack
14352 \begin_inset LatexCommand \index{stack}
14353
14354 \end_inset 
14355
14356  frame is similar to that generated by the IAR Z80 compiler.
14357  IX is used as the base pointer, HL and IY are used as a temporary registers,
14358  and BC and DE are available for holding variables.
14359  Return values
14360 \begin_inset LatexCommand \index{return value}
14361
14362 \end_inset 
14363
14364  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
14365  bytes).
14366  The gbz80 port use the same set of registers for the return values, but
14367  in a different order of significance: E (one byte), DE (two bytes), or
14368  HLDE (four bytes).
14369 \layout Section
14370
14371 The HC08 port
14372 \layout Standard
14373
14374 The port to the Motorola HC08
14375 \begin_inset LatexCommand \index{HC08}
14376
14377 \end_inset 
14378
14379  family has been added in October 2003, and is still undergoing some basic
14380  development.
14381  The code generator is complete, but the register allocation is still quite
14382  unoptimized.
14383  Some of the SDCC's standard C library functions have embedded non-HC08
14384  inline assembly and so are not yet usable.
14385 \newline 
14386
14387 \newline 
14388
14389 \layout Section
14390
14391 The PIC14 port
14392 \layout Standard
14393
14394 The 14bit PIC
14395 \begin_inset LatexCommand \index{PIC14}
14396
14397 \end_inset 
14398
14399  port still requires a major effort from the development community.
14400  However it can work for very simple code.
14401 \layout Subsection
14402
14403 C code and 14bit PIC code page
14404 \begin_inset LatexCommand \index{code page (pic14)}
14405
14406 \end_inset 
14407
14408  and RAM banks
14409 \begin_inset LatexCommand \index{RAM bank (pic14)}
14410
14411 \end_inset 
14412
14413
14414 \layout Standard
14415
14416 The linker organizes allocation for the code page and RAM banks.
14417  It does not have intimate knowledge of the code flow.
14418  It will put all the code section of a single asm file into a single code
14419  page.
14420  In order to make use of multiple code pages, separate asm files must be
14421  used.
14422  The compiler treats all functions of a single C file as being in the same
14423  code page unless it is non static.
14424  The compiler treats all local variables of a single C file as being in
14425  the same RAM bank unless it is an extern.
14426 \newline 
14427
14428 \newline 
14429 To get the best follow these guide lines:
14430 \layout Enumerate
14431
14432 make local functions static, as non static functions require code page selection
14433  overhead.
14434 \layout Enumerate
14435
14436 Make local variables static as extern variables require RAM bank selection
14437  overhead.
14438 \layout Enumerate
14439
14440 For devices that have multiple code pages it is more efficient to use the
14441  same number of files as pages, i.e.
14442  for the 16F877 use 4 separate files and i.e.
14443  for the 16F874 use 2 separate files.
14444  This way the linker can put the code for each file into different code
14445  pages and the compiler can allocate reusable variables more efficiently
14446  and there's less page selection overhead.
14447  And as for any 8 bit micro (especially for PIC 14 as they have a very simple
14448  instruction set) use 'unsigned char' whereever possible instead of 'int'.
14449 \layout Subsection
14450
14451 Creating a device include file 
14452 \layout Standard
14453
14454 For generating a device include file use the support perl script inc2h.pl
14455  kept in directory support/script.
14456 \layout Subsection
14457
14458 Interrupt code
14459 \layout Standard
14460
14461 For the interrupt function, use the keyword 'interrupt'
14462 \begin_inset LatexCommand \index{interrupt}
14463
14464 \end_inset 
14465
14466  with level number of 0 (PIC14 only has 1 interrupt so this number is only
14467  there to avoid a syntax error - it ought to be fixed).
14468  E.g.:
14469 \layout Verse
14470
14471
14472 \family typewriter 
14473 void Intr(void) interrupt 0
14474 \newline 
14475 {
14476 \newline 
14477 \SpecialChar ~
14478 \SpecialChar ~
14479 T0IF = 0; /* Clear timer interrupt */
14480 \newline 
14481 }
14482 \layout Standard
14483
14484 Linking and assembling
14485 \newline 
14486 For assembling you can use either GPUTILS'
14487 \begin_inset LatexCommand \index{gputils (pic tools)}
14488
14489 \end_inset 
14490
14491  gpasm.exe or MPLAB's mpasmwin.exe.
14492  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
14493  If you use MPLAB and an interrupt function then the linker script file
14494  vectors section will need to be enlarged to link with mplink.
14495 \newline 
14496
14497 \newline 
14498 Here is a 
14499 \family typewriter 
14500 Makefile
14501 \family default 
14502  using GPUTILS:
14503 \layout Verse
14504
14505
14506 \family typewriter 
14507 .c.o:
14508 \newline 
14509 \SpecialChar ~
14510 \SpecialChar ~
14511 \SpecialChar ~
14512 \SpecialChar ~
14513 \SpecialChar ~
14514 \SpecialChar ~
14515 \SpecialChar ~
14516 \SpecialChar ~
14517 sdcc -S -V -mpic14 -p16F877 $< 
14518 \newline 
14519 \SpecialChar ~
14520 \SpecialChar ~
14521 \SpecialChar ~
14522 \SpecialChar ~
14523 \SpecialChar ~
14524 \SpecialChar ~
14525 \SpecialChar ~
14526 \SpecialChar ~
14527 gpasm -c $*.asm
14528 \newline 
14529
14530 \newline 
14531 $(PRJ).hex: $(OBJS) 
14532 \newline 
14533 \SpecialChar ~
14534 \SpecialChar ~
14535 \SpecialChar ~
14536 \SpecialChar ~
14537 \SpecialChar ~
14538 \SpecialChar ~
14539 \SpecialChar ~
14540 \SpecialChar ~
14541 gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS)
14542 \layout Standard
14543
14544 Here is a 
14545 \family typewriter 
14546 Makefile
14547 \family default 
14548  using MPLAB:
14549 \layout Verse
14550
14551
14552 \family typewriter 
14553 .c.o: 
14554 \newline 
14555 \SpecialChar ~
14556 \SpecialChar ~
14557 \SpecialChar ~
14558 \SpecialChar ~
14559 \SpecialChar ~
14560 \SpecialChar ~
14561 \SpecialChar ~
14562 \SpecialChar ~
14563 sdcc -S -V -mpic14 -p16F877 $< 
14564 \newline 
14565 \SpecialChar ~
14566 \SpecialChar ~
14567 \SpecialChar ~
14568 \SpecialChar ~
14569 \SpecialChar ~
14570 \SpecialChar ~
14571 \SpecialChar ~
14572 \SpecialChar ~
14573 mpasmwin /q /o $*.asm
14574 \newline 
14575
14576 \newline 
14577 $(PRJ).hex: $(OBJS) 
14578 \newline 
14579 \SpecialChar ~
14580 \SpecialChar ~
14581 \SpecialChar ~
14582 \SpecialChar ~
14583 \SpecialChar ~
14584 \SpecialChar ~
14585 \SpecialChar ~
14586 \SpecialChar ~
14587 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS)
14588 \layout Section
14589
14590 The PIC16
14591 \begin_inset LatexCommand \index{PIC16}
14592
14593 \end_inset 
14594
14595  port
14596 \layout Standard
14597
14598 The PIC16
14599 \begin_inset LatexCommand \index{PIC16}
14600
14601 \end_inset 
14602
14603  port is the portion of SDCC that is responsible to produce code for the
14604  Microchip
14605 \begin_inset LatexCommand \index{Microchip}
14606
14607 \end_inset 
14608
14609 (TM) microcontrollers with 16 bit core.
14610  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
14611 \layout Subsection
14612
14613 Global Options
14614 \layout Standard
14615
14616 PIC16 port supports the standard command line arguments as supposed, with
14617  the exception of certain cases that will be mentioned in the following
14618  list:
14619 \layout List
14620 \labelwidthstring 00.00.0000
14621
14622 -
14623 \begin_inset ERT
14624 status Collapsed
14625
14626 \layout Standard
14627
14628 \backslash 
14629 /
14630 \end_inset 
14631
14632 -stack-auto Auto variables that are function parameters, will be saved on
14633  stack by default.
14634  
14635 \emph on 
14636 There is no need to specify this in the command line.
14637 \layout List
14638 \labelwidthstring 00.00.0000
14639
14640 -
14641 \begin_inset ERT
14642 status Collapsed
14643
14644 \layout Standard
14645
14646 \backslash 
14647 /
14648 \end_inset 
14649
14650 -float-reent All floating point functions are reentrant by default.
14651  
14652 \emph on 
14653 There is no need to specifiy this in the command line.
14654 \layout List
14655 \labelwidthstring 00.00.0000
14656
14657 -
14658 \begin_inset ERT
14659 status Collapsed
14660
14661 \layout Standard
14662
14663 \backslash 
14664 /
14665 \end_inset 
14666
14667 -callee-saves See -
14668 \begin_inset ERT
14669 status Collapsed
14670
14671 \layout Standard
14672
14673 \backslash 
14674 /
14675 \end_inset 
14676
14677 -all-callee-saves
14678 \layout List
14679 \labelwidthstring 00.00.0000
14680
14681 -
14682 \begin_inset ERT
14683 status Collapsed
14684
14685 \layout Standard
14686
14687 \backslash 
14688 /
14689 \end_inset 
14690
14691 -all-callee-saves All function arguments are passed on stack by default.
14692  
14693 \emph on 
14694 There is no need to specify this in the command line.
14695 \layout List
14696 \labelwidthstring 00.00.0000
14697
14698 -
14699 \begin_inset ERT
14700 status Collapsed
14701
14702 \layout Standard
14703
14704 \backslash 
14705 /
14706 \end_inset 
14707
14708 -fommit-frame-pointer Frame pointer will be omitted when the function uses
14709  no local variables.
14710 \layout Subsection
14711
14712 Port Specific Options
14713 \layout Standard
14714
14715 The port specific options appear after the global options in the sdcc --help
14716  output.
14717 \layout Subsubsection
14718
14719 General Options
14720 \layout Standard
14721
14722 General options enable certain port features and optimizations.
14723 \layout List
14724 \labelwidthstring 00.00.0000
14725
14726 -
14727 \begin_inset ERT
14728 status Collapsed
14729
14730 \layout Standard
14731
14732 \backslash 
14733 /
14734 \end_inset 
14735
14736 -pgen-bank Instructs the port to insert BANKSEL directives before instructions
14737  that use the Bank Select Register (BSR).
14738 \layout List
14739 \labelwidthstring 00.00.0000
14740
14741 -
14742 \begin_inset ERT
14743 status Collapsed
14744
14745 \layout Standard
14746
14747 \backslash 
14748 /
14749 \end_inset 
14750
14751 -pomit-config-words Instructs the port to omit the generation of the configurati
14752 on words.
14753 \layout List
14754 \labelwidthstring 00.00.0000
14755
14756 -
14757 \begin_inset ERT
14758 status Collapsed
14759
14760 \layout Standard
14761
14762 \backslash 
14763 /
14764 \end_inset 
14765
14766 -pomit-ivt Instructs the port to omit the generation of the interrupt vectors
14767 \layout List
14768 \labelwidthstring 00.00.0000
14769
14770 -
14771 \begin_inset ERT
14772 status Collapsed
14773
14774 \layout Standard
14775
14776 \backslash 
14777 /
14778 \end_inset 
14779
14780 -pleave-reset-vector Used in conjuction with the previous command, instructs
14781  the port NOT to omit the reset vector.
14782 \layout List
14783 \labelwidthstring 00.00.0000
14784
14785 -
14786 \begin_inset ERT
14787 status Collapsed
14788
14789 \layout Standard
14790
14791 \backslash 
14792 /
14793 \end_inset 
14794
14795 -stack-model=[model] Used in conjuction with the command above.
14796  Defines the stack model to be used, valid stack models are : 
14797 \begin_deeper 
14798 \layout List
14799 \labelwidthstring 00.00.0000
14800
14801
14802 \emph on 
14803 small
14804 \emph default 
14805  Selects small stack model.
14806  8 bit stack and frame pointers.
14807  Supports 256 bytes stack size.
14808 \layout List
14809 \labelwidthstring 00.00.0000
14810
14811
14812 \emph on 
14813 large
14814 \emph default 
14815  Selects large stack model.
14816  16 bit stack and frame pointers.
14817  Supports 65536 bytes stack size.
14818 \end_deeper 
14819 \layout List
14820 \labelwidthstring 00.00.0000
14821
14822 -
14823 \begin_inset ERT
14824 status Collapsed
14825
14826 \layout Standard
14827
14828 \backslash 
14829 /
14830 \end_inset 
14831
14832 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
14833  unitialized data variables with [kword].
14834  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
14835 \layout Subsubsection
14836
14837 Debugging Options
14838 \layout Standard
14839
14840 Debugging options enable extra debugging information in the output files.
14841 \layout List
14842 \labelwidthstring 00.00.0000
14843
14844 -
14845 \begin_inset ERT
14846 status Collapsed
14847
14848 \layout Standard
14849
14850 \backslash 
14851 /
14852 \end_inset 
14853
14854 -debug-xtra Similar to --debug, but dumps more information.
14855 \layout List
14856 \labelwidthstring 00.00.0000
14857
14858 -
14859 \begin_inset ERT
14860 status Collapsed
14861
14862 \layout Standard
14863
14864 \backslash 
14865 /
14866 \end_inset 
14867
14868 -debug-ralloc Force register allocator to dump <source>.d file with debugging
14869  information.
14870  <source> is the name of the file compiled.
14871 \layout List
14872 \labelwidthstring 00.00.0000
14873
14874 -
14875 \begin_inset ERT
14876 status Collapsed
14877
14878 \layout Standard
14879
14880 \backslash 
14881 /
14882 \end_inset 
14883
14884 -pcode-verbose Enable pcode debugging information in translation.
14885 \layout Subsection
14886
14887 Preprocessor Macros
14888 \layout Standard
14889
14890 PIC16 port defines the following preprocessor macros while translating a
14891  source.
14892 \layout Standard
14893 \align center 
14894
14895 \begin_inset  Tabular
14896 <lyxtabular version="3" rows="2" columns="2">
14897 <features>
14898 <column alignment="center" valignment="top" leftline="true" width="0">
14899 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
14900 <row topline="true" bottomline="true">
14901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14902 \begin_inset Text
14903
14904 \layout Standard
14905
14906 Macro
14907 \end_inset 
14908 </cell>
14909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14910 \begin_inset Text
14911
14912 \layout Standard
14913
14914 Description
14915 \end_inset 
14916 </cell>
14917 </row>
14918 <row topline="true" bottomline="true">
14919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14920 \begin_inset Text
14921
14922 \layout Standard
14923
14924 pic18fxxxx
14925 \end_inset 
14926 </cell>
14927 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14928 \begin_inset Text
14929
14930 \layout Standard
14931
14932 MCU Identification.
14933  
14934 \emph on 
14935 xxxx
14936 \emph default 
14937  is the microcontrol identification number, i.e.
14938  452, 6620, etc
14939 \end_inset 
14940 </cell>
14941 </row>
14942 </lyxtabular>
14943
14944 \end_inset 
14945
14946
14947 \layout Subsection
14948
14949 Directories
14950 \layout Standard
14951
14952 PIC16 port uses the following directories for searching header files and
14953  libraries.
14954 \layout Standard
14955 \align center 
14956
14957 \begin_inset  Tabular
14958 <lyxtabular version="3" rows="3" columns="4">
14959 <features>
14960 <column alignment="center" valignment="top" leftline="true" width="0">
14961 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
14962 <column alignment="center" valignment="top" width="0">
14963 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
14964 <row topline="true" bottomline="true">
14965 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14966 \begin_inset Text
14967
14968 \layout Standard
14969
14970 Directory
14971 \end_inset 
14972 </cell>
14973 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14974 \begin_inset Text
14975
14976 \layout Standard
14977
14978 Description
14979 \end_inset 
14980 </cell>
14981 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14982 \begin_inset Text
14983
14984 \layout Standard
14985
14986 Target
14987 \end_inset 
14988 </cell>
14989 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14990 \begin_inset Text
14991
14992 \layout Standard
14993
14994 Command prefix
14995 \end_inset 
14996 </cell>
14997 </row>
14998 <row topline="true">
14999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15000 \begin_inset Text
15001
15002 \layout Standard
15003
15004 PREFIX/sdcc/include/pic16
15005 \end_inset 
15006 </cell>
15007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15008 \begin_inset Text
15009
15010 \layout Standard
15011
15012 PIC16 specific headers
15013 \end_inset 
15014 </cell>
15015 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15016 \begin_inset Text
15017
15018 \layout Standard
15019
15020 Compiler
15021 \end_inset 
15022 </cell>
15023 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15024 \begin_inset Text
15025
15026 \layout Standard
15027
15028 -I
15029 \end_inset 
15030 </cell>
15031 </row>
15032 <row topline="true" bottomline="true">
15033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15034 \begin_inset Text
15035
15036 \layout Standard
15037
15038 PREFIX/sdcc/lib/pic16
15039 \end_inset 
15040 </cell>
15041 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15042 \begin_inset Text
15043
15044 \layout Standard
15045
15046 PIC16 specific libraries
15047 \end_inset 
15048 </cell>
15049 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15050 \begin_inset Text
15051
15052 \layout Standard
15053
15054 Linker
15055 \end_inset 
15056 </cell>
15057 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15058 \begin_inset Text
15059
15060 \layout Standard
15061
15062 -L
15063 \end_inset 
15064 </cell>
15065 </row>
15066 </lyxtabular>
15067
15068 \end_inset 
15069
15070
15071 \layout Subsection
15072
15073 Pragmas
15074 \layout Standard
15075
15076 PIC16 port currently supports the following pragmas:
15077 \layout List
15078 \labelwidthstring 00.00.0000
15079
15080 stack pragma stack forces the code generator to initialize the stack & frame
15081  pointers at a specific address.
15082  This is an adhoc solution since gplink does not support yet stack.
15083  When the gplink issue is resolved the pragma will be deprecated
15084 \begin_inset Foot
15085 collapsed true
15086
15087 \layout Standard
15088
15089
15090 \emph on 
15091 It is important to initialize the stack, otherwise strange things can happen.
15092  Stack is not initialized by default because there are some sources that
15093  do not require it.
15094  (like library sources)
15095 \end_inset 
15096
15097 .
15098 \newline 
15099 The stack pragma should be used only once in a project.
15100  Multiple pragmas may result in indeterminate behaviour of the program.
15101 \newline 
15102 If you omit setting the pragma the port emits a warning message before linking.
15103  If not initializing the stack is desired ignore the message.
15104 \layout LyX-Code
15105
15106 Example:
15107 \layout LyX-Code
15108
15109 \layout LyX-Code
15110
15111 /* initializes stack at RAM address 0x5ff*/
15112 \layout LyX-Code
15113
15114 #pragma stack 0x5ff
15115 \layout LyX-Code
15116
15117 \layout Subsection
15118
15119 Header Files
15120 \layout Standard
15121
15122 There is one main header file that can be included to the source files using
15123  the pic16 port.
15124  That file is the 
15125 \series bold 
15126 pic18fregs.h
15127 \series default 
15128 .
15129  This header file contains the definitions for the processor special registers,
15130  so it is necessery if the soruce accesses them.
15131  It can be included by adding the following line in the beginning of the
15132  file:
15133 \layout LyX-Code
15134
15135 #include <pic18fregs.h>
15136 \layout Standard
15137
15138 The specific microcontroller is selected within the pic18fregs.h automatically,
15139  so the same source can be used with a variety of devices.
15140 \layout Subsection
15141
15142 Libraries
15143 \layout Standard
15144
15145 The libraries that pic16 port depends on are the microcontroller device
15146  libraries which contain the symbol definitions for the microcontroller
15147  special function registers.
15148  These libraries have the format pic18fxxxx.lib, where 
15149 \emph on 
15150 xxxx
15151 \emph default 
15152  is the microcontroller identification number.
15153  The specific library is selected automatically by the compiler at link
15154  stage according to the selected device.
15155 \layout Standard
15156
15157 Libraries are created with gplib which is part of the gputils package 
15158 \begin_inset LatexCommand \url{http://gputils.sourceforge.net}
15159
15160 \end_inset 
15161
15162 .
15163 \layout Subsection
15164
15165 Memory Models
15166 \layout Standard
15167
15168 The following memory models are supported by PIC16 port:
15169 \layout Itemize
15170
15171 small model
15172 \layout Itemize
15173
15174 large model
15175 \layout Standard
15176
15177 Memory model affects the default size of pointers within the source.
15178  The sizes are shown in the next table:
15179 \layout Standard
15180 \align center 
15181
15182 \begin_inset  Tabular
15183 <lyxtabular version="3" rows="3" columns="3">
15184 <features>
15185 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15186 <column alignment="center" valignment="top" leftline="true" width="0">
15187 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15188 <row topline="true" bottomline="true">
15189 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15190 \begin_inset Text
15191
15192 \layout Standard
15193
15194 Pointer sizes according to memory model
15195 \end_inset 
15196 </cell>
15197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15198 \begin_inset Text
15199
15200 \layout Standard
15201
15202 small model
15203 \end_inset 
15204 </cell>
15205 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15206 \begin_inset Text
15207
15208 \layout Standard
15209
15210 large model
15211 \end_inset 
15212 </cell>
15213 </row>
15214 <row topline="true" bottomline="true">
15215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15216 \begin_inset Text
15217
15218 \layout Standard
15219
15220 code pointers
15221 \end_inset 
15222 </cell>
15223 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15224 \begin_inset Text
15225
15226 \layout Standard
15227
15228 16-bits
15229 \end_inset 
15230 </cell>
15231 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15232 \begin_inset Text
15233
15234 \layout Standard
15235
15236 24-bits
15237 \end_inset 
15238 </cell>
15239 </row>
15240 <row topline="true" bottomline="true">
15241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15242 \begin_inset Text
15243
15244 \layout Standard
15245
15246 data pointers
15247 \end_inset 
15248 </cell>
15249 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
15250 \begin_inset Text
15251
15252 \layout Standard
15253
15254 16-bits
15255 \end_inset 
15256 </cell>
15257 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15258 \begin_inset Text
15259
15260 \layout Standard
15261
15262 16-bits
15263 \end_inset 
15264 </cell>
15265 </row>
15266 </lyxtabular>
15267
15268 \end_inset 
15269
15270
15271 \layout Standard
15272
15273 It is advisable that all sources within a project are compiled with the
15274  same memory model.
15275  If one wants to override the default memory model, this can be done by
15276  declaring a pointer as 
15277 \series bold 
15278 far
15279 \series default 
15280  or 
15281 \series bold 
15282 near
15283 \series default 
15284 .
15285  Far selects large memory model's pointers, while near selects small memory
15286  model's pointers.
15287 \layout Standard
15288
15289 The standard device libraries (see 4.5.6) contain no reference to pointers,
15290  so they can be used with both memory models.
15291 \layout Subsection
15292
15293 Stack
15294 \layout Standard
15295
15296 The stack implementation for the PIC16 port uses two indirect registers,
15297  FSR1 and FSR2.
15298 \layout List
15299 \labelwidthstring 00.00.0000
15300
15301 FSR1 is assigned as stack pointer
15302 \layout List
15303 \labelwidthstring 00.00.0000
15304
15305 FSR2 is assigned as frame pointer
15306 \layout Standard
15307
15308 The following stack models are supported by PIC16 port
15309 \layout Itemize
15310
15311 small model
15312 \layout Itemize
15313
15314 large model
15315 \layout Standard
15316
15317
15318 \noun on 
15319 Small
15320 \noun default 
15321  model means that only the FSRxL byte is used to access stack and frame,
15322  while 
15323 \emph on 
15324 \noun on 
15325 large
15326 \emph default 
15327 \noun default 
15328  uses both FSRxL and FSRxH registers.
15329  The following table shows the stack/frame pointers sizes according to stack
15330  model and the maximum space they can address:
15331 \layout Standard
15332 \align center 
15333
15334 \begin_inset  Tabular
15335 <lyxtabular version="3" rows="3" columns="3">
15336 <features>
15337 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15338 <column alignment="center" valignment="top" leftline="true" width="0">
15339 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15340 <row topline="true" bottomline="true">
15341 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15342 \begin_inset Text
15343
15344 \layout Standard
15345
15346 Stack & Frame pointer sizes according to stack model
15347 \end_inset 
15348 </cell>
15349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15350 \begin_inset Text
15351
15352 \layout Standard
15353
15354 small
15355 \end_inset 
15356 </cell>
15357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15358 \begin_inset Text
15359
15360 \layout Standard
15361
15362 large
15363 \end_inset 
15364 </cell>
15365 </row>
15366 <row topline="true">
15367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15368 \begin_inset Text
15369
15370 \layout Standard
15371
15372 Stack pointer FSR1
15373 \end_inset 
15374 </cell>
15375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15376 \begin_inset Text
15377
15378 \layout Standard
15379
15380 8-bits
15381 \end_inset 
15382 </cell>
15383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15384 \begin_inset Text
15385
15386 \layout Standard
15387
15388 16-bits
15389 \end_inset 
15390 </cell>
15391 </row>
15392 <row topline="true" bottomline="true">
15393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15394 \begin_inset Text
15395
15396 \layout Standard
15397
15398 Frame pointer FSR2
15399 \end_inset 
15400 </cell>
15401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15402 \begin_inset Text
15403
15404 \layout Standard
15405
15406 8-bits
15407 \end_inset 
15408 </cell>
15409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15410 \begin_inset Text
15411
15412 \layout Standard
15413
15414 16-bits
15415 \end_inset 
15416 </cell>
15417 </row>
15418 </lyxtabular>
15419
15420 \end_inset 
15421
15422
15423 \layout Standard
15424
15425
15426 \series bold 
15427 Currently stack and frame pointers should be initialized explicit by the
15428  user at the desired Data RAM position (see 4.5.5 Pragma Stack).
15429  Uninitialized stack and frame pointers can result in unexpected behavior
15430  of the resulting binary.
15431 \layout Subsection
15432
15433 Function return values
15434 \layout Standard
15435
15436 Return values from functions are placed to the appropriate registers following
15437  a modified Microchip policy optimized for SDCC.
15438  The following table shows these registers:
15439 \layout Standard
15440 \align center 
15441
15442 \begin_inset  Tabular
15443 <lyxtabular version="3" rows="6" columns="2">
15444 <features>
15445 <column alignment="center" valignment="top" leftline="true" width="0">
15446 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15447 <row topline="true" bottomline="true">
15448 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15449 \begin_inset Text
15450
15451 \layout Standard
15452
15453 size
15454 \end_inset 
15455 </cell>
15456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15457 \begin_inset Text
15458
15459 \layout Standard
15460
15461 destination register
15462 \end_inset 
15463 </cell>
15464 </row>
15465 <row topline="true">
15466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15467 \begin_inset Text
15468
15469 \layout Standard
15470
15471 8 bits
15472 \end_inset 
15473 </cell>
15474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15475 \begin_inset Text
15476
15477 \layout Standard
15478
15479 WREG
15480 \end_inset 
15481 </cell>
15482 </row>
15483 <row topline="true">
15484 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15485 \begin_inset Text
15486
15487 \layout Standard
15488
15489 16 bits
15490 \end_inset 
15491 </cell>
15492 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15493 \begin_inset Text
15494
15495 \layout Standard
15496
15497 PRODL:WREG
15498 \end_inset 
15499 </cell>
15500 </row>
15501 <row topline="true">
15502 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15503 \begin_inset Text
15504
15505 \layout Standard
15506
15507 24 bits
15508 \end_inset 
15509 </cell>
15510 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15511 \begin_inset Text
15512
15513 \layout Standard
15514
15515 PRODH:PRODL:WREG
15516 \end_inset 
15517 </cell>
15518 </row>
15519 <row topline="true">
15520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15521 \begin_inset Text
15522
15523 \layout Standard
15524
15525 32 bits
15526 \end_inset 
15527 </cell>
15528 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15529 \begin_inset Text
15530
15531 \layout Standard
15532
15533 FSR0L:PRODH:PRODL:WREG
15534 \end_inset 
15535 </cell>
15536 </row>
15537 <row topline="true" bottomline="true">
15538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15539 \begin_inset Text
15540
15541 \layout Standard
15542
15543 >32 bits
15544 \end_inset 
15545 </cell>
15546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15547 \begin_inset Text
15548
15549 \layout Standard
15550
15551 on stack, FSR0 points to the beginning
15552 \end_inset 
15553 </cell>
15554 </row>
15555 </lyxtabular>
15556
15557 \end_inset 
15558
15559
15560 \layout Subsection
15561
15562 Interrupts
15563 \layout Standard
15564
15565 When entering an interrupt, currently the PIC16 port automatically saves
15566  the following registers:
15567 \layout Itemize
15568
15569 WREG
15570 \layout Itemize
15571
15572 STATUS
15573 \layout Itemize
15574
15575 BSR
15576 \layout Itemize
15577
15578 PROD (PRODL and PRODH)
15579 \layout Itemize
15580
15581 FSR0 (FSR0L and FSR0H)
15582 \layout Standard
15583
15584 These registers are restored upon return from the interrupt routine
15585 \begin_inset Foot
15586 collapsed false
15587
15588 \layout Standard
15589
15590 NOTE that when the _naked attribute is specified for an interrupt routine,
15591  then NO registers are stored or restored.
15592 \end_inset 
15593
15594 .
15595 \layout Chapter
15596
15597 Debugging with SDCDB
15598 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
15599
15600 \end_inset 
15601
15602
15603 \begin_inset LatexCommand \index{sdcdb (debugger)}
15604
15605 \end_inset 
15606
15607  
15608 \layout Standard
15609
15610 SDCC is distributed with a source level debugger
15611 \begin_inset LatexCommand \index{Debugger}
15612
15613 \end_inset 
15614
15615 .
15616  The debugger uses a command line interface, the command repertoire of the
15617  debugger has been kept as close to gdb
15618 \begin_inset LatexCommand \index{gdb}
15619
15620 \end_inset 
15621
15622  (the GNU debugger) as possible.
15623  The configuration and build process is part of the standard compiler installati
15624 on, which also builds and installs the debugger in the target directory
15625  specified during configuration.
15626  The debugger allows you debug BOTH at the C source and at the ASM source
15627  level.
15628  Sdcdb is available on Unix platforms only.
15629 \layout Section
15630
15631 Compiling for Debugging
15632 \layout Standard
15633
15634 The \SpecialChar \-
15635 \SpecialChar \-
15636 debug option must be specified for all files for which debug information
15637  is to be generated.
15638  The complier generates a .adb file for each of these files.
15639  The linker creates the .cdb
15640 \begin_inset LatexCommand \index{<file>.cdb}
15641
15642 \end_inset 
15643
15644  file from the .adb
15645 \begin_inset LatexCommand \index{<file>.adb}
15646
15647 \end_inset 
15648
15649  files and the address information.
15650  This .cdb is used by the debugger.
15651 \layout Section
15652
15653 How the Debugger Works
15654 \layout Standard
15655
15656 When the -
15657 \begin_inset ERT
15658 status Collapsed
15659
15660 \layout Standard
15661
15662 \backslash 
15663 /
15664 \end_inset 
15665
15666 -debug option is specified the compiler generates extra symbol information
15667  some of which are put into the assembler source and some are put into the
15668  .adb file.
15669   Then the linker creates the .cdb file from the individual .adb files with
15670  the address information for the symbols.
15671  The debugger reads the symbolic information generated by the compiler &
15672  the address information generated by the linker.
15673  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
15674  execution is controlled by the debugger.
15675  When a command is issued for the debugger, it translates it into appropriate
15676  commands for the simulator.
15677 \layout Section
15678
15679 Starting the Debugger
15680 \layout Standard
15681
15682 The debugger can be started using the following command line.
15683  (Assume the file you are debugging has the file name foo).
15684 \newline 
15685
15686 \newline 
15687
15688 \family sans 
15689 \series bold 
15690 sdcdb foo
15691 \newline 
15692
15693 \family default 
15694 \series default 
15695
15696 \newline 
15697 The debugger will look for the following files.
15698 \layout Itemize
15699
15700 foo.c - the source file.
15701 \layout Itemize
15702
15703 foo.cdb - the debugger symbol information file.
15704 \layout Itemize
15705
15706 foo.ihx - the Intel hex format
15707 \begin_inset LatexCommand \index{Intel hex format}
15708
15709 \end_inset 
15710
15711  object file.
15712 \layout Section
15713
15714 Command Line Options.
15715 \layout Itemize
15716
15717 -
15718 \begin_inset ERT
15719 status Collapsed
15720
15721 \layout Standard
15722
15723 \backslash 
15724 /
15725 \end_inset 
15726
15727 -directory=<source file directory> this option can used to specify the directory
15728  search list.
15729  The debugger will look into the directory list specified for source, cdb
15730  & ihx files.
15731  The items in the directory list must be separated by ':', e.g.
15732  if the source files can be in the directories /home/src1 and /home/src2,
15733  the -
15734 \begin_inset ERT
15735 status Collapsed
15736
15737 \layout Standard
15738
15739 \backslash 
15740 /
15741 \end_inset 
15742
15743 -directory option should be -
15744 \begin_inset ERT
15745 status Collapsed
15746
15747 \layout Standard
15748
15749 \backslash 
15750 /
15751 \end_inset 
15752
15753 -directory=/home/src1:/home/src2.
15754  Note there can be no spaces in the option.
15755  
15756 \layout Itemize
15757
15758 -cd <directory> - change to the <directory>.
15759 \layout Itemize
15760
15761 -fullname - used by GUI front ends.
15762 \layout Itemize
15763
15764 -cpu <cpu-type> - this argument is passed to the simulator please see the
15765  simulator docs for details.
15766 \layout Itemize
15767
15768 -X <Clock frequency > this options is passed to the simulator please see
15769  the simulator docs for details.
15770 \layout Itemize
15771
15772 -s <serial port file> passed to simulator see the simulator docs for details.
15773 \layout Itemize
15774
15775 -S <serial in,out> passed to simulator see the simulator docs for details.
15776 \layout Itemize
15777
15778 -k <port number> passed to simulator see the simulator docs for details.
15779 \layout Section
15780
15781 Debugger Commands.
15782 \layout Standard
15783
15784 As mentioned earlier the command interface for the debugger has been deliberatel
15785 y kept as close the GNU debugger gdb, as possible.
15786  This will help the integration with existing graphical user interfaces
15787  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
15788  If you use a graphical user interface for the debugger you can skip the
15789  next sections.
15790 \layout Subsubsection*
15791
15792 break [line | file:line | function | file:function]
15793 \layout Standard
15794
15795 Set breakpoint at specified line or function:
15796 \newline 
15797
15798 \newline 
15799
15800 \family sans 
15801 \series bold 
15802 sdcdb>break 100 
15803 \newline 
15804 sdcdb>break foo.c:100
15805 \newline 
15806 sdcdb>break funcfoo
15807 \newline 
15808 sdcdb>break foo.c:funcfoo
15809 \layout Subsubsection*
15810
15811 clear [line | file:line | function | file:function ]
15812 \layout Standard
15813
15814 Clear breakpoint at specified line or function:
15815 \newline 
15816
15817 \newline 
15818
15819 \family sans 
15820 \series bold 
15821 sdcdb>clear 100
15822 \newline 
15823 sdcdb>clear foo.c:100
15824 \newline 
15825 sdcdb>clear funcfoo
15826 \newline 
15827 sdcdb>clear foo.c:funcfoo
15828 \layout Subsubsection*
15829
15830 continue
15831 \layout Standard
15832
15833 Continue program being debugged, after breakpoint.
15834 \layout Subsubsection*
15835
15836 finish
15837 \layout Standard
15838
15839 Execute till the end of the current function.
15840 \layout Subsubsection*
15841
15842 delete [n]
15843 \layout Standard
15844
15845 Delete breakpoint number 'n'.
15846  If used without any option clear ALL user defined break points.
15847 \layout Subsubsection*
15848
15849 info [break | stack | frame | registers ]
15850 \layout Itemize
15851
15852 info break - list all breakpoints
15853 \layout Itemize
15854
15855 info stack - show the function call stack.
15856 \layout Itemize
15857
15858 info frame - show information about the current execution frame.
15859 \layout Itemize
15860
15861 info registers - show content of all registers.
15862 \layout Subsubsection*
15863
15864 step
15865 \layout Standard
15866
15867 Step program until it reaches a different source line.
15868  Note: pressing <return> repeats the last command.
15869 \layout Subsubsection*
15870
15871 next
15872 \layout Standard
15873
15874 Step program, proceeding through subroutine calls.
15875 \layout Subsubsection*
15876
15877 run
15878 \layout Standard
15879
15880 Start debugged program.
15881 \layout Subsubsection*
15882
15883 ptype variable 
15884 \layout Standard
15885
15886 Print type information of the variable.
15887 \layout Subsubsection*
15888
15889 print variable
15890 \layout Standard
15891
15892 print value of variable.
15893 \layout Subsubsection*
15894
15895 file filename
15896 \layout Standard
15897
15898 load the given file name.
15899  Note this is an alternate method of loading file for debugging.
15900 \layout Subsubsection*
15901
15902 frame
15903 \layout Standard
15904
15905 print information about current frame.
15906 \layout Subsubsection*
15907
15908 set srcmode
15909 \layout Standard
15910
15911 Toggle between C source & assembly source.
15912 \layout Subsubsection*
15913
15914 ! simulator command
15915 \layout Standard
15916
15917 Send the string following '!' to the simulator, the simulator response is
15918  displayed.
15919  Note the debugger does not interpret the command being sent to the simulator,
15920  so if a command like 'go' is sent the debugger can loose its execution
15921  context and may display incorrect values.
15922 \layout Subsubsection*
15923
15924 quit
15925 \layout Standard
15926
15927 "Watch me now.
15928  Iam going Down.
15929  My name is Bobby Brown"
15930 \layout Section
15931
15932 Interfacing with XEmacs
15933 \begin_inset LatexCommand \index{XEmacs}
15934
15935 \end_inset 
15936
15937
15938 \begin_inset LatexCommand \index{Emacs}
15939
15940 \end_inset 
15941
15942 .
15943 \layout Standard
15944
15945 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
15946  sdcdb.el and sdcdbsrc.el.
15947  These two files can be found in the $(prefix)/bin directory after the installat
15948 ion is complete.
15949  These files need to be loaded into XEmacs for the interface to work.
15950  This can be done at XEmacs startup time by inserting the following into
15951  your '.xemacs' file (which can be found in your HOME directory): 
15952 \newline 
15953
15954 \newline 
15955
15956 \family typewriter 
15957 (load-file sdcdbsrc.el) 
15958 \family default 
15959
15960 \newline 
15961
15962 \newline 
15963 .xemacs is a lisp file so the () around the command is REQUIRED.
15964  The files can also be loaded dynamically while XEmacs is running, set the
15965  environment variable 'EMACSLOADPATH' to the installation bin directory
15966  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
15967  To start the interface enter the following command: 
15968 \newline 
15969
15970 \newline 
15971
15972 \family sans 
15973 \series bold 
15974 ESC-x sdcdbsrc
15975 \family default 
15976 \series default 
15977
15978 \newline 
15979
15980 \newline 
15981 You will prompted to enter the file name to be debugged.
15982  
15983 \newline 
15984
15985 \newline 
15986 The command line options that are passed to the simulator directly are bound
15987  to default values in the file sdcdbsrc.el.
15988  The variables are listed below, these values maybe changed as required.
15989 \layout Itemize
15990
15991 sdcdbsrc-cpu-type '51
15992 \layout Itemize
15993
15994 sdcdbsrc-frequency '11059200
15995 \layout Itemize
15996
15997 sdcdbsrc-serial nil
15998 \layout Standard
15999
16000 The following is a list of key mapping for the debugger interface.
16001 \layout Standard
16002
16003 \SpecialChar ~
16004
16005 \family typewriter 
16006
16007 \newline 
16008 ;; Current Listing :: 
16009 \newline 
16010 ;;key\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 binding\SpecialChar ~
16026 \SpecialChar ~
16027 \SpecialChar ~
16028 \SpecialChar ~
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 Comment 
16048 \newline 
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 \SpecialChar ~
16067 \SpecialChar ~
16068 \SpecialChar ~
16069 \SpecialChar ~
16070 \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 \SpecialChar ~
16085 \SpecialChar ~
16086 --------
16087 \newline 
16088 ;; 
16089 \newline 
16090 ;; n\SpecialChar ~
16091 \SpecialChar ~
16092 \SpecialChar ~
16093 \SpecialChar ~
16094 \SpecialChar ~
16095 \SpecialChar ~
16096 \SpecialChar ~
16097 \SpecialChar ~
16098 \SpecialChar ~
16099 \SpecialChar ~
16100 \SpecialChar ~
16101 \SpecialChar ~
16102 \SpecialChar ~
16103 \SpecialChar ~
16104  sdcdb-next-from-src\SpecialChar ~
16105 \SpecialChar ~
16106 \SpecialChar ~
16107 \SpecialChar ~
16108 \SpecialChar ~
16109 \SpecialChar ~
16110 \SpecialChar ~
16111 \SpecialChar ~
16112 \SpecialChar ~
16113 \SpecialChar ~
16114 SDCDB next command 
16115 \newline 
16116 ;; b\SpecialChar ~
16117 \SpecialChar ~
16118 \SpecialChar ~
16119 \SpecialChar ~
16120 \SpecialChar ~
16121 \SpecialChar ~
16122 \SpecialChar ~
16123 \SpecialChar ~
16124 \SpecialChar ~
16125 \SpecialChar ~
16126 \SpecialChar ~
16127 \SpecialChar ~
16128 \SpecialChar ~
16129 \SpecialChar ~
16130  sdcdb-back-from-src\SpecialChar ~
16131 \SpecialChar ~
16132 \SpecialChar ~
16133 \SpecialChar ~
16134 \SpecialChar ~
16135 \SpecialChar ~
16136 \SpecialChar ~
16137 \SpecialChar ~
16138 \SpecialChar ~
16139 \SpecialChar ~
16140 SDCDB back command 
16141 \newline 
16142 ;; c\SpecialChar ~
16143 \SpecialChar ~
16144 \SpecialChar ~
16145 \SpecialChar ~
16146 \SpecialChar ~
16147 \SpecialChar ~
16148 \SpecialChar ~
16149 \SpecialChar ~
16150 \SpecialChar ~
16151 \SpecialChar ~
16152 \SpecialChar ~
16153 \SpecialChar ~
16154 \SpecialChar ~
16155 \SpecialChar ~
16156  sdcdb-cont-from-src\SpecialChar ~
16157 \SpecialChar ~
16158 \SpecialChar ~
16159 \SpecialChar ~
16160 \SpecialChar ~
16161 \SpecialChar ~
16162 \SpecialChar ~
16163 \SpecialChar ~
16164 \SpecialChar ~
16165 \SpecialChar ~
16166 SDCDB continue command
16167 \newline 
16168 ;; s\SpecialChar ~
16169 \SpecialChar ~
16170 \SpecialChar ~
16171 \SpecialChar ~
16172 \SpecialChar ~
16173 \SpecialChar ~
16174 \SpecialChar ~
16175 \SpecialChar ~
16176 \SpecialChar ~
16177 \SpecialChar ~
16178 \SpecialChar ~
16179 \SpecialChar ~
16180 \SpecialChar ~
16181 \SpecialChar ~
16182  sdcdb-step-from-src\SpecialChar ~
16183 \SpecialChar ~
16184 \SpecialChar ~
16185 \SpecialChar ~
16186 \SpecialChar ~
16187 \SpecialChar ~
16188 \SpecialChar ~
16189 \SpecialChar ~
16190 \SpecialChar ~
16191 \SpecialChar ~
16192 SDCDB step command 
16193 \newline 
16194 ;; ?\SpecialChar ~
16195 \SpecialChar ~
16196 \SpecialChar ~
16197 \SpecialChar ~
16198 \SpecialChar ~
16199 \SpecialChar ~
16200 \SpecialChar ~
16201 \SpecialChar ~
16202 \SpecialChar ~
16203 \SpecialChar ~
16204 \SpecialChar ~
16205 \SpecialChar ~
16206 \SpecialChar ~
16207 \SpecialChar ~
16208  sdcdb-whatis-c-sexp\SpecialChar ~
16209 \SpecialChar ~
16210 \SpecialChar ~
16211 \SpecialChar ~
16212 \SpecialChar ~
16213 \SpecialChar ~
16214 \SpecialChar ~
16215 \SpecialChar ~
16216 \SpecialChar ~
16217 \SpecialChar ~
16218 SDCDB ptypecommand for data at 
16219 \newline 
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 \SpecialChar ~
16247 \SpecialChar ~
16248 \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 \SpecialChar ~
16263 \SpecialChar ~
16264 \SpecialChar ~
16265 \SpecialChar ~
16266  buffer point 
16267 \newline 
16268 ;; x\SpecialChar ~
16269 \SpecialChar ~
16270 \SpecialChar ~
16271 \SpecialChar ~
16272 \SpecialChar ~
16273 \SpecialChar ~
16274 \SpecialChar ~
16275 \SpecialChar ~
16276 \SpecialChar ~
16277 \SpecialChar ~
16278 \SpecialChar ~
16279 \SpecialChar ~
16280 \SpecialChar ~
16281 \SpecialChar ~
16282  sdcdbsrc-delete\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 SDCDB Delete all breakpoints if no arg 
16297 \newline 
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 \SpecialChar ~
16325 \SpecialChar ~
16326 \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 \SpecialChar ~
16341 \SpecialChar ~
16342 \SpecialChar ~
16343 \SpecialChar ~
16344 given or delete arg (C-u arg x) 
16345 \newline 
16346 ;; m\SpecialChar ~
16347 \SpecialChar ~
16348 \SpecialChar ~
16349 \SpecialChar ~
16350 \SpecialChar ~
16351 \SpecialChar ~
16352 \SpecialChar ~
16353 \SpecialChar ~
16354 \SpecialChar ~
16355 \SpecialChar ~
16356 \SpecialChar ~
16357 \SpecialChar ~
16358 \SpecialChar ~
16359 \SpecialChar ~
16360  sdcdbsrc-frame\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 SDCDB Display current frame if no arg, 
16376 \newline 
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 \SpecialChar ~
16405 \SpecialChar ~
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 given or display frame arg 
16425 \newline 
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 \SpecialChar ~
16454 \SpecialChar ~
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 \SpecialChar ~
16470 \SpecialChar ~
16471 \SpecialChar ~
16472 \SpecialChar ~
16473 buffer point 
16474 \newline 
16475 ;; !\SpecialChar ~
16476 \SpecialChar ~
16477 \SpecialChar ~
16478 \SpecialChar ~
16479 \SpecialChar ~
16480 \SpecialChar ~
16481 \SpecialChar ~
16482 \SpecialChar ~
16483 \SpecialChar ~
16484 \SpecialChar ~
16485 \SpecialChar ~
16486 \SpecialChar ~
16487 \SpecialChar ~
16488 \SpecialChar ~
16489  sdcdbsrc-goto-sdcdb\SpecialChar ~
16490 \SpecialChar ~
16491 \SpecialChar ~
16492 \SpecialChar ~
16493 \SpecialChar ~
16494 \SpecialChar ~
16495 \SpecialChar ~
16496 \SpecialChar ~
16497 \SpecialChar ~
16498 \SpecialChar ~
16499 Goto the SDCDB output buffer 
16500 \newline 
16501 ;; p\SpecialChar ~
16502 \SpecialChar ~
16503 \SpecialChar ~
16504 \SpecialChar ~
16505 \SpecialChar ~
16506 \SpecialChar ~
16507 \SpecialChar ~
16508 \SpecialChar ~
16509 \SpecialChar ~
16510 \SpecialChar ~
16511 \SpecialChar ~
16512 \SpecialChar ~
16513 \SpecialChar ~
16514 \SpecialChar ~
16515  sdcdb-print-c-sexp\SpecialChar ~
16516 \SpecialChar ~
16517 \SpecialChar ~
16518 \SpecialChar ~
16519 \SpecialChar ~
16520 \SpecialChar ~
16521 \SpecialChar ~
16522 \SpecialChar ~
16523 \SpecialChar ~
16524 \SpecialChar ~
16525 \SpecialChar ~
16526 SDCDB print command for data at 
16527 \newline 
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 \SpecialChar ~
16555 \SpecialChar ~
16556 \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 \SpecialChar ~
16571 \SpecialChar ~
16572 \SpecialChar ~
16573 \SpecialChar ~
16574  buffer point 
16575 \newline 
16576 ;; g\SpecialChar ~
16577 \SpecialChar ~
16578 \SpecialChar ~
16579 \SpecialChar ~
16580 \SpecialChar ~
16581 \SpecialChar ~
16582 \SpecialChar ~
16583 \SpecialChar ~
16584 \SpecialChar ~
16585 \SpecialChar ~
16586 \SpecialChar ~
16587 \SpecialChar ~
16588 \SpecialChar ~
16589 \SpecialChar ~
16590  sdcdbsrc-goto-sdcdb\SpecialChar ~
16591 \SpecialChar ~
16592 \SpecialChar ~
16593 \SpecialChar ~
16594 \SpecialChar ~
16595 \SpecialChar ~
16596 \SpecialChar ~
16597 \SpecialChar ~
16598 \SpecialChar ~
16599 \SpecialChar ~
16600 Goto the SDCDB output buffer 
16601 \newline 
16602 ;; t\SpecialChar ~
16603 \SpecialChar ~
16604 \SpecialChar ~
16605 \SpecialChar ~
16606 \SpecialChar ~
16607 \SpecialChar ~
16608 \SpecialChar ~
16609 \SpecialChar ~
16610 \SpecialChar ~
16611 \SpecialChar ~
16612 \SpecialChar ~
16613 \SpecialChar ~
16614 \SpecialChar ~
16615 \SpecialChar ~
16616  sdcdbsrc-mode\SpecialChar ~
16617 \SpecialChar ~
16618 \SpecialChar ~
16619 \SpecialChar ~
16620 \SpecialChar ~
16621 \SpecialChar ~
16622 \SpecialChar ~
16623 \SpecialChar ~
16624 \SpecialChar ~
16625 \SpecialChar ~
16626 \SpecialChar ~
16627 \SpecialChar ~
16628 \SpecialChar ~
16629 \SpecialChar ~
16630 \SpecialChar ~
16631 \SpecialChar ~
16632 Toggles Sdcdbsrc mode (turns it off) 
16633 \newline 
16634 ;; 
16635 \newline 
16636 ;; C-c C-f\SpecialChar ~
16637 \SpecialChar ~
16638 \SpecialChar ~
16639 \SpecialChar ~
16640 \SpecialChar ~
16641 \SpecialChar ~
16642 \SpecialChar ~
16643 \SpecialChar ~
16644  sdcdb-finish-from-src\SpecialChar ~
16645 \SpecialChar ~
16646 \SpecialChar ~
16647 \SpecialChar ~
16648 \SpecialChar ~
16649 \SpecialChar ~
16650 \SpecialChar ~
16651 \SpecialChar ~
16652 SDCDB finish command 
16653 \newline 
16654 ;; 
16655 \newline 
16656 ;; C-x SPC\SpecialChar ~
16657 \SpecialChar ~
16658 \SpecialChar ~
16659 \SpecialChar ~
16660 \SpecialChar ~
16661 \SpecialChar ~
16662 \SpecialChar ~
16663 \SpecialChar ~
16664  sdcdb-break\SpecialChar ~
16665 \SpecialChar ~
16666 \SpecialChar ~
16667 \SpecialChar ~
16668 \SpecialChar ~
16669 \SpecialChar ~
16670 \SpecialChar ~
16671 \SpecialChar ~
16672 \SpecialChar ~
16673 \SpecialChar ~
16674 \SpecialChar ~
16675 \SpecialChar ~
16676 \SpecialChar ~
16677 \SpecialChar ~
16678 \SpecialChar ~
16679 \SpecialChar ~
16680 \SpecialChar ~
16681 \SpecialChar ~
16682 Set break for line with point 
16683 \newline 
16684 ;; ESC t\SpecialChar ~
16685 \SpecialChar ~
16686 \SpecialChar ~
16687 \SpecialChar ~
16688 \SpecialChar ~
16689 \SpecialChar ~
16690 \SpecialChar ~
16691 \SpecialChar ~
16692 \SpecialChar ~
16693 \SpecialChar ~
16694  sdcdbsrc-mode\SpecialChar ~
16695 \SpecialChar ~
16696 \SpecialChar ~
16697 \SpecialChar ~
16698 \SpecialChar ~
16699 \SpecialChar ~
16700 \SpecialChar ~
16701 \SpecialChar ~
16702 \SpecialChar ~
16703 \SpecialChar ~
16704 \SpecialChar ~
16705 \SpecialChar ~
16706 \SpecialChar ~
16707 \SpecialChar ~
16708 \SpecialChar ~
16709 \SpecialChar ~
16710 Toggle Sdcdbsrc mode 
16711 \newline 
16712 ;; ESC m\SpecialChar ~
16713 \SpecialChar ~
16714 \SpecialChar ~
16715 \SpecialChar ~
16716 \SpecialChar ~
16717 \SpecialChar ~
16718 \SpecialChar ~
16719 \SpecialChar ~
16720 \SpecialChar ~
16721 \SpecialChar ~
16722  sdcdbsrc-srcmode\SpecialChar ~
16723 \SpecialChar ~
16724 \SpecialChar ~
16725 \SpecialChar ~
16726 \SpecialChar ~
16727 \SpecialChar ~
16728 \SpecialChar ~
16729 \SpecialChar ~
16730 \SpecialChar ~
16731 \SpecialChar ~
16732 \SpecialChar ~
16733 \SpecialChar ~
16734  Toggle list mode 
16735 \newline 
16736 ;; 
16737 \newline 
16738
16739 \layout Chapter
16740 \pagebreak_top 
16741 TIPS
16742 \layout Standard
16743
16744 Here are a few guidelines that will help the compiler generate more efficient
16745  code, some of the tips are specific to this compiler others are generally
16746  good programming practice.
16747 \layout Itemize
16748
16749 Use the smallest data type to represent your data-value.
16750  If it is known in advance that the value is going to be less than 256 then
16751  use an 'unsigned char' instead of a 'short' or 'int'.
16752  Please note, that ANSI C requires both signed and unsigned chars to be
16753  promoted to 'signed int' before doing any operation.
16754  This promotion can be omitted, if the result is the same.
16755  The effect of the promotion rules together with the sign-extension is often
16756  supprising:
16757 \begin_deeper 
16758 \layout Verse
16759
16760
16761 \family typewriter 
16762 unsigned char uc = 0xfe;
16763 \newline 
16764 if (uc * uc < 0) /* this is true! */
16765 \newline 
16766 {
16767 \newline 
16768 \SpecialChar ~
16769 \SpecialChar ~
16770 \SpecialChar ~
16771 \SpecialChar ~
16772 ....
16773 \newline 
16774 }
16775 \layout Standard
16776
16777
16778 \family typewriter 
16779 uc * uc
16780 \family default 
16781  is evaluated as 
16782 \family typewriter 
16783 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
16784 \family default 
16785 .
16786  
16787 \newline 
16788 Another one:
16789 \layout Verse
16790
16791
16792 \family typewriter 
16793 (unsigned char) -12 / (signed char) -3 = ...
16794 \layout Standard
16795
16796 No, the result is not 4:
16797 \layout Verse
16798
16799
16800 \family typewriter 
16801 (int) (unsigned char) -12 / (int) (signed char) -3 =
16802 \newline 
16803 (int) (unsigned char) 0xf4 / (int) (signed char) 0xfd =
16804 \newline 
16805 (int) 0x00f4 / (int) 0xfffd =
16806 \newline 
16807 (int) 0x00f4 / (int) 0xfffd =
16808 \newline 
16809 (int) 244 / (int) -3 =
16810 \newline 
16811 (int) -81 = (int) 0xffaf;
16812 \layout Standard
16813
16814 Don't complain, that gcc gives you a different result.
16815  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
16816  Therefore the results are different.
16817 \newline 
16818 From 
16819 \begin_inset Quotes sld
16820 \end_inset 
16821
16822 comp.lang.c FAQ
16823 \begin_inset Quotes srd
16824 \end_inset 
16825
16826 :
16827 \layout Quote
16828
16829 If well-defined overflow characteristics are important and negative values
16830  are not, or if you want to steer clear of sign-extension problems when
16831  manipulating bits or bytes, use one of the corresponding unsigned types.
16832  (Beware when mixing signed and unsigned values in expressions, though.)
16833 \newline 
16834 Although character types (especially unsigned char) can be used as "tiny"
16835  integers, doing so is sometimes more trouble than it's worth, due to unpredicta
16836 ble sign extension and increased code size.
16837 \end_deeper 
16838 \layout Itemize
16839
16840 Use unsigned when it is known in advance that the value is not going to
16841  be negative.
16842  This helps especially if you are doing division or multiplication, bit-shifting
16843  or are using an array index.
16844 \layout Itemize
16845
16846 NEVER jump into a LOOP.
16847 \layout Itemize
16848
16849 Declare the variables to be local
16850 \begin_inset LatexCommand \index{local variables}
16851
16852 \end_inset 
16853
16854  whenever possible, especially loop control variables (induction).
16855 \layout Itemize
16856
16857 Since the compiler does not always do implicit integral promotion, the programme
16858 r should do an explicit cast when integral promotion is required.
16859 \layout Itemize
16860
16861 Reducing the size of division, multiplication & modulus operations can reduce
16862  code size substantially.
16863  Take the following code for example.
16864 \begin_deeper 
16865 \layout Verse
16866
16867
16868 \family typewriter 
16869 foobar(unsigned int p1, unsigned char ch)
16870 \newline 
16871 {
16872 \newline 
16873 \SpecialChar ~
16874 \SpecialChar ~
16875 \SpecialChar ~
16876 \SpecialChar ~
16877 unsigned char ch1 = p1 % ch ;
16878 \newline 
16879 \SpecialChar ~
16880 \SpecialChar ~
16881 \SpecialChar ~
16882 \SpecialChar ~
16883 ....
16884 \newline 
16885 }
16886 \layout Standard
16887
16888 For the modulus operation the variable ch will be promoted to unsigned int
16889  first then the modulus operation will be performed (this will lead to a
16890  call to support routine _moduint()), and the result will be casted to a
16891  char.
16892  If the code is changed to 
16893 \layout Verse
16894
16895
16896 \family typewriter 
16897 foobar(unsigned int p1, unsigned char ch)
16898 \newline 
16899 {
16900 \newline 
16901 \SpecialChar ~
16902 \SpecialChar ~
16903 \SpecialChar ~
16904 \SpecialChar ~
16905 unsigned char ch1 = (unsigned char)p1 % ch ;
16906 \newline 
16907 \SpecialChar ~
16908 \SpecialChar ~
16909 \SpecialChar ~
16910 \SpecialChar ~
16911 ....
16912 \newline 
16913 }
16914 \layout Standard
16915
16916 It would substantially reduce the code generated (future versions of the
16917  compiler will be smart enough to detect such optimization opportunities).
16918 \end_deeper 
16919 \layout Itemize
16920
16921 Have a look at the assembly listing to get a 
16922 \begin_inset Quotes sld
16923 \end_inset 
16924
16925 feeling
16926 \begin_inset Quotes srd
16927 \end_inset 
16928
16929  for the code generation.
16930 \layout Section
16931
16932 Tools
16933 \begin_inset LatexCommand \index{Tools}
16934
16935 \end_inset 
16936
16937  included in the distribution
16938 \layout Standard
16939 \align center 
16940
16941 \begin_inset  Tabular
16942 <lyxtabular version="3" rows="12" columns="3">
16943 <features>
16944 <column alignment="center" valignment="top" leftline="true" width="0pt">
16945 <column alignment="center" valignment="top" leftline="true" width="0pt">
16946 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
16947 <row topline="true" bottomline="true">
16948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16949 \begin_inset Text
16950
16951 \layout Standard
16952
16953 Name
16954 \end_inset 
16955 </cell>
16956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16957 \begin_inset Text
16958
16959 \layout Standard
16960
16961 Purpose
16962 \end_inset 
16963 </cell>
16964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16965 \begin_inset Text
16966
16967 \layout Standard
16968
16969 Directory
16970 \end_inset 
16971 </cell>
16972 </row>
16973 <row topline="true">
16974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16975 \begin_inset Text
16976
16977 \layout Standard
16978
16979 uCsim
16980 \end_inset 
16981 </cell>
16982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16983 \begin_inset Text
16984
16985 \layout Standard
16986
16987 Simulator for various architectures
16988 \end_inset 
16989 </cell>
16990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16991 \begin_inset Text
16992
16993 \layout Standard
16994
16995 sdcc/sim/ucsim
16996 \end_inset 
16997 </cell>
16998 </row>
16999 <row topline="true">
17000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17001 \begin_inset Text
17002
17003 \layout Standard
17004
17005 keil2sdcc.pl
17006 \end_inset 
17007 </cell>
17008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17009 \begin_inset Text
17010
17011 \layout Standard
17012
17013 header file conversion
17014 \end_inset 
17015 </cell>
17016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17017 \begin_inset Text
17018
17019 \layout Standard
17020
17021 sdcc/support/scripts
17022 \end_inset 
17023 </cell>
17024 </row>
17025 <row topline="true">
17026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17027 \begin_inset Text
17028
17029 \layout Standard
17030
17031 mh2h.c
17032 \end_inset 
17033 </cell>
17034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17035 \begin_inset Text
17036
17037 \layout Standard
17038
17039 header file conversion
17040 \end_inset 
17041 </cell>
17042 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17043 \begin_inset Text
17044
17045 \layout Standard
17046
17047 sdcc/support/scripts
17048 \end_inset 
17049 </cell>
17050 </row>
17051 <row topline="true">
17052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17053 \begin_inset Text
17054
17055 \layout Standard
17056
17057 as-gbz80
17058 \end_inset 
17059 </cell>
17060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17061 \begin_inset Text
17062
17063 \layout Standard
17064
17065 Assembler
17066 \end_inset 
17067 </cell>
17068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17069 \begin_inset Text
17070
17071 \layout Standard
17072
17073
17074 \family roman 
17075 \series medium 
17076 \shape up 
17077 \size normal 
17078 \emph off 
17079 \bar no 
17080 \noun off 
17081 \color none
17082 sdcc/bin
17083 \end_inset 
17084 </cell>
17085 </row>
17086 <row topline="true">
17087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17088 \begin_inset Text
17089
17090 \layout Standard
17091
17092 as-z80
17093 \end_inset 
17094 </cell>
17095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17096 \begin_inset Text
17097
17098 \layout Standard
17099
17100 Assembler
17101 \end_inset 
17102 </cell>
17103 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17104 \begin_inset Text
17105
17106 \layout Standard
17107
17108
17109 \family roman 
17110 \series medium 
17111 \shape up 
17112 \size normal 
17113 \emph off 
17114 \bar no 
17115 \noun off 
17116 \color none
17117 sdcc/bin
17118 \end_inset 
17119 </cell>
17120 </row>
17121 <row topline="true">
17122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17123 \begin_inset Text
17124
17125 \layout Standard
17126
17127 asx8051
17128 \end_inset 
17129 </cell>
17130 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17131 \begin_inset Text
17132
17133 \layout Standard
17134
17135 Assembler
17136 \end_inset 
17137 </cell>
17138 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17139 \begin_inset Text
17140
17141 \layout Standard
17142
17143
17144 \family roman 
17145 \series medium 
17146 \shape up 
17147 \size normal 
17148 \emph off 
17149 \bar no 
17150 \noun off 
17151 \color none
17152 sdcc/bin
17153 \end_inset 
17154 </cell>
17155 </row>
17156 <row topline="true">
17157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17158 \begin_inset Text
17159
17160 \layout Standard
17161
17162 sdcdb
17163 \end_inset 
17164 </cell>
17165 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17166 \begin_inset Text
17167
17168 \layout Standard
17169
17170 Simulator
17171 \end_inset 
17172 </cell>
17173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17174 \begin_inset Text
17175
17176 \layout Standard
17177
17178
17179 \family roman 
17180 \series medium 
17181 \shape up 
17182 \size normal 
17183 \emph off 
17184 \bar no 
17185 \noun off 
17186 \color none
17187 sdcc/bin
17188 \end_inset 
17189 </cell>
17190 </row>
17191 <row topline="true">
17192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17193 \begin_inset Text
17194
17195 \layout Standard
17196
17197 aslink
17198 \end_inset 
17199 </cell>
17200 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17201 \begin_inset Text
17202
17203 \layout Standard
17204
17205 Linker
17206 \end_inset 
17207 </cell>
17208 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17209 \begin_inset Text
17210
17211 \layout Standard
17212
17213
17214 \family roman 
17215 \series medium 
17216 \shape up 
17217 \size normal 
17218 \emph off 
17219 \bar no 
17220 \noun off 
17221 \color none
17222 sdcc/bin
17223 \end_inset 
17224 </cell>
17225 </row>
17226 <row topline="true">
17227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17228 \begin_inset Text
17229
17230 \layout Standard
17231
17232 link-z80
17233 \end_inset 
17234 </cell>
17235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17236 \begin_inset Text
17237
17238 \layout Standard
17239
17240 Linker
17241 \end_inset 
17242 </cell>
17243 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17244 \begin_inset Text
17245
17246 \layout Standard
17247
17248
17249 \family roman 
17250 \series medium 
17251 \shape up 
17252 \size normal 
17253 \emph off 
17254 \bar no 
17255 \noun off 
17256 \color none
17257 sdcc/bin
17258 \end_inset 
17259 </cell>
17260 </row>
17261 <row topline="true">
17262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17263 \begin_inset Text
17264
17265 \layout Standard
17266
17267 link-gbz80
17268 \end_inset 
17269 </cell>
17270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17271 \begin_inset Text
17272
17273 \layout Standard
17274
17275 Linker
17276 \end_inset 
17277 </cell>
17278 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17279 \begin_inset Text
17280
17281 \layout Standard
17282
17283
17284 \family roman 
17285 \series medium 
17286 \shape up 
17287 \size normal 
17288 \emph off 
17289 \bar no 
17290 \noun off 
17291 \color none
17292 sdcc/bin
17293 \end_inset 
17294 </cell>
17295 </row>
17296 <row topline="true" bottomline="true">
17297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17298 \begin_inset Text
17299
17300 \layout Standard
17301
17302 packihx
17303 \end_inset 
17304 </cell>
17305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17306 \begin_inset Text
17307
17308 \layout Standard
17309
17310 ihx packer
17311 \end_inset 
17312 </cell>
17313 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17314 \begin_inset Text
17315
17316 \layout Standard
17317
17318
17319 \family roman 
17320 \series medium 
17321 \shape up 
17322 \size normal 
17323 \emph off 
17324 \bar no 
17325 \noun off 
17326 \color none
17327 sdcc/bin
17328 \end_inset 
17329 </cell>
17330 </row>
17331 </lyxtabular>
17332
17333 \end_inset 
17334
17335
17336 \newline 
17337
17338 \layout Section
17339
17340 Documentation
17341 \begin_inset LatexCommand \index{Documentation}
17342
17343 \end_inset 
17344
17345  included in the distribution
17346 \layout Standard
17347 \align center 
17348
17349 \begin_inset  Tabular
17350 <lyxtabular version="3" rows="10" columns="2">
17351 <features>
17352 <column alignment="left" valignment="top" leftline="true" width="0">
17353 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
17354 <row topline="true" bottomline="true">
17355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17356 \begin_inset Text
17357
17358 \layout Standard
17359
17360 Subject / Title
17361 \end_inset 
17362 </cell>
17363 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17364 \begin_inset Text
17365
17366 \layout Standard
17367
17368 Where to get / filename
17369 \end_inset 
17370 </cell>
17371 </row>
17372 <row topline="true">
17373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17374 \begin_inset Text
17375
17376 \layout Standard
17377
17378 SDCC Compiler User Guide
17379 \end_inset 
17380 </cell>
17381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17382 \begin_inset Text
17383
17384 \layout Standard
17385
17386 You're reading it right now
17387 \end_inset 
17388 </cell>
17389 </row>
17390 <row topline="true">
17391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17392 \begin_inset Text
17393
17394 \layout Standard
17395
17396 Changelog of SDCC
17397 \end_inset 
17398 </cell>
17399 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17400 \begin_inset Text
17401
17402 \layout Standard
17403
17404 sdcc/Changelog
17405 \end_inset 
17406 </cell>
17407 </row>
17408 <row topline="true">
17409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17410 \begin_inset Text
17411
17412 \layout Standard
17413
17414 ASXXXX Assemblers and ASLINK Relocating Linker
17415 \end_inset 
17416 </cell>
17417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17418 \begin_inset Text
17419
17420 \layout Standard
17421
17422 sdcc/as/doc/asxhtm.html
17423 \end_inset 
17424 </cell>
17425 </row>
17426 <row topline="true">
17427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17428 \begin_inset Text
17429
17430 \layout Standard
17431
17432 SDCC regression test
17433 \begin_inset LatexCommand \index{Regression test}
17434
17435 \end_inset 
17436
17437
17438 \end_inset 
17439 </cell>
17440 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17441 \begin_inset Text
17442
17443 \layout Standard
17444
17445 sdcc/doc/test_suite_spec.pdf
17446 \end_inset 
17447 </cell>
17448 </row>
17449 <row topline="true">
17450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17451 \begin_inset Text
17452
17453 \layout Standard
17454
17455 Various notes
17456 \end_inset 
17457 </cell>
17458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17459 \begin_inset Text
17460
17461 \layout Standard
17462
17463 sdcc/doc/*
17464 \end_inset 
17465 </cell>
17466 </row>
17467 <row topline="true">
17468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17469 \begin_inset Text
17470
17471 \layout Standard
17472
17473 Notes on debugging with sdcdb
17474 \begin_inset LatexCommand \index{sdcdb (debugger)}
17475
17476 \end_inset 
17477
17478
17479 \end_inset 
17480 </cell>
17481 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17482 \begin_inset Text
17483
17484 \layout Standard
17485
17486 sdcc/debugger/README
17487 \end_inset 
17488 </cell>
17489 </row>
17490 <row topline="true">
17491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17492 \begin_inset Text
17493
17494 \layout Standard
17495
17496 Software simulator for microcontrollers
17497 \end_inset 
17498 </cell>
17499 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17500 \begin_inset Text
17501
17502 \layout Standard
17503
17504
17505 \family roman 
17506 \series medium 
17507 \shape up 
17508 \size normal 
17509 \emph off 
17510 \bar no 
17511 \noun off 
17512 \color none
17513 sdcc/sim/ucsim/doc
17514 \family default 
17515 \series default 
17516 \shape default 
17517 \size default 
17518 \emph default 
17519 \bar default 
17520 \noun default 
17521 \color default
17522 /index.html
17523 \end_inset 
17524 </cell>
17525 </row>
17526 <row topline="true">
17527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17528 \begin_inset Text
17529
17530 \layout Standard
17531
17532 Temporary notes on the pic16
17533 \begin_inset LatexCommand \index{PIC16}
17534
17535 \end_inset 
17536
17537  port
17538 \end_inset 
17539 </cell>
17540 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17541 \begin_inset Text
17542
17543 \layout Standard
17544
17545 sdcc/src/pic16/NOTES
17546 \end_inset 
17547 </cell>
17548 </row>
17549 <row topline="true" bottomline="true">
17550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17551 \begin_inset Text
17552
17553 \layout Standard
17554
17555 SDCC internal documentation (debugging file format)
17556 \end_inset 
17557 </cell>
17558 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17559 \begin_inset Text
17560
17561 \layout Standard
17562
17563 sdcc/doc/
17564 \family roman 
17565 \series medium 
17566 \shape up 
17567 \size normal 
17568 \emph off 
17569 \bar no 
17570 \noun off 
17571 \color none
17572 cdbfileformat.pd
17573 \family default 
17574 \series default 
17575 \shape default 
17576 \size default 
17577 \emph default 
17578 \bar default 
17579 \noun default 
17580 \color default
17581 f
17582 \end_inset 
17583 </cell>
17584 </row>
17585 </lyxtabular>
17586
17587 \end_inset 
17588
17589
17590 \newline 
17591
17592 \layout Section
17593
17594 Related open source tools
17595 \begin_inset LatexCommand \index{Related tools}
17596
17597 \end_inset 
17598
17599
17600 \layout Standard
17601 \align center 
17602
17603 \begin_inset  Tabular
17604 <lyxtabular version="3" rows="11" columns="3">
17605 <features>
17606 <column alignment="center" valignment="top" leftline="true" width="0pt">
17607 <column alignment="block" valignment="top" leftline="true" width="30line%">
17608 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
17609 <row topline="true" bottomline="true">
17610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17611 \begin_inset Text
17612
17613 \layout Standard
17614
17615 Name
17616 \end_inset 
17617 </cell>
17618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17619 \begin_inset Text
17620
17621 \layout Standard
17622
17623 Purpose
17624 \end_inset 
17625 </cell>
17626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17627 \begin_inset Text
17628
17629 \layout Standard
17630
17631 Where to get
17632 \end_inset 
17633 </cell>
17634 </row>
17635 <row topline="true">
17636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17637 \begin_inset Text
17638
17639 \layout Standard
17640
17641 gpsim
17642 \begin_inset LatexCommand \index{gpsim (pic simulator)}
17643
17644 \end_inset 
17645
17646
17647 \end_inset 
17648 </cell>
17649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17650 \begin_inset Text
17651
17652 \layout Standard
17653
17654 PIC simulator
17655 \end_inset 
17656 </cell>
17657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17658 \begin_inset Text
17659
17660 \layout Standard
17661
17662
17663 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
17664
17665 \end_inset 
17666
17667
17668 \end_inset 
17669 </cell>
17670 </row>
17671 <row topline="true">
17672 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17673 \begin_inset Text
17674
17675 \layout Standard
17676
17677 gputils
17678 \begin_inset LatexCommand \index{gputils (pic tools)}
17679
17680 \end_inset 
17681
17682
17683 \end_inset 
17684 </cell>
17685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17686 \begin_inset Text
17687
17688 \layout Standard
17689
17690 GNU PIC utilities
17691 \end_inset 
17692 </cell>
17693 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17694 \begin_inset Text
17695
17696 \layout Standard
17697
17698
17699 \begin_inset LatexCommand \url{http://gputils.sourceforge.net/}
17700
17701 \end_inset 
17702
17703
17704 \end_inset 
17705 </cell>
17706 </row>
17707 <row topline="true">
17708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17709 \begin_inset Text
17710
17711 \layout Standard
17712
17713 flP5
17714 \end_inset 
17715 </cell>
17716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17717 \begin_inset Text
17718
17719 \layout Standard
17720
17721 PIC programmer
17722 \end_inset 
17723 </cell>
17724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17725 \begin_inset Text
17726
17727 \layout Standard
17728
17729
17730 \begin_inset LatexCommand \url{http://digilander.libero.it/fbradasc/FLP5.html}
17731
17732 \end_inset 
17733
17734
17735 \end_inset 
17736 </cell>
17737 </row>
17738 <row topline="true">
17739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17740 \begin_inset Text
17741
17742 \layout Standard
17743
17744 indent
17745 \begin_inset LatexCommand \index{indent (source formatting tool)}
17746
17747 \end_inset 
17748
17749
17750 \end_inset 
17751 </cell>
17752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17753 \begin_inset Text
17754
17755 \layout Standard
17756
17757 Formats C source - Master of the white spaces
17758 \end_inset 
17759 </cell>
17760 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17761 \begin_inset Text
17762
17763 \layout Standard
17764
17765
17766 \begin_inset LatexCommand \url{http://home.hccnet.nl/d.ingamells/beautify.html}
17767
17768 \end_inset 
17769
17770
17771 \end_inset 
17772 </cell>
17773 </row>
17774 <row topline="true">
17775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17776 \begin_inset Text
17777
17778 \layout Standard
17779
17780 srecord
17781 \begin_inset LatexCommand \index{srecord (tool)}
17782
17783 \end_inset 
17784
17785
17786 \end_inset 
17787 </cell>
17788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17789 \begin_inset Text
17790
17791 \layout Standard
17792
17793 Object file conversion, checksumming, ...
17794 \end_inset 
17795 </cell>
17796 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17797 \begin_inset Text
17798
17799 \layout Standard
17800
17801
17802 \begin_inset LatexCommand \url{http://srecord.sourceforge.net/}
17803
17804 \end_inset 
17805
17806
17807 \end_inset 
17808 </cell>
17809 </row>
17810 <row topline="true">
17811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17812 \begin_inset Text
17813
17814 \layout Standard
17815
17816 objdump
17817 \begin_inset LatexCommand \index{objdump (tool)}
17818
17819 \end_inset 
17820
17821
17822 \end_inset 
17823 </cell>
17824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17825 \begin_inset Text
17826
17827 \layout Standard
17828
17829 Object file conversion, ...
17830 \end_inset 
17831 </cell>
17832 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17833 \begin_inset Text
17834
17835 \layout Standard
17836
17837 Part of binutils (should be there anyway)
17838 \end_inset 
17839 </cell>
17840 </row>
17841 <row topline="true">
17842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17843 \begin_inset Text
17844
17845 \layout Standard
17846
17847 doxygen
17848 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
17849
17850 \end_inset 
17851
17852
17853 \end_inset 
17854 </cell>
17855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17856 \begin_inset Text
17857
17858 \layout Standard
17859
17860 Source code documentation system
17861 \end_inset 
17862 </cell>
17863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17864 \begin_inset Text
17865
17866 \layout Standard
17867
17868
17869 \begin_inset LatexCommand \url{http://www.doxygen.org}
17870
17871 \end_inset 
17872
17873
17874 \end_inset 
17875 </cell>
17876 </row>
17877 <row topline="true">
17878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17879 \begin_inset Text
17880
17881 \layout Standard
17882
17883 kdevelop
17884 \end_inset 
17885 </cell>
17886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17887 \begin_inset Text
17888
17889 \layout Standard
17890
17891 IDE (has anyone tried integrating SDCC & sdcdb? Unix only)
17892 \end_inset 
17893 </cell>
17894 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17895 \begin_inset Text
17896
17897 \layout Standard
17898
17899
17900 \begin_inset LatexCommand \url{http://www.kdevelop.org}
17901
17902 \end_inset 
17903
17904
17905 \end_inset 
17906 </cell>
17907 </row>
17908 <row topline="true">
17909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17910 \begin_inset Text
17911
17912 \layout Standard
17913
17914 splint
17915 \begin_inset LatexCommand \index{splint (syntax checking tool)}
17916
17917 \end_inset 
17918
17919
17920 \end_inset 
17921 </cell>
17922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17923 \begin_inset Text
17924
17925 \layout Standard
17926
17927 Statically checks c sources
17928 \end_inset 
17929 </cell>
17930 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17931 \begin_inset Text
17932
17933 \layout Standard
17934
17935
17936 \begin_inset LatexCommand \url{http://www.splint.org}
17937
17938 \end_inset 
17939
17940
17941 \end_inset 
17942 </cell>
17943 </row>
17944 <row topline="true" bottomline="true">
17945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17946 \begin_inset Text
17947
17948 \layout Standard
17949
17950 ddd
17951 \begin_inset LatexCommand \index{ddd (debugger)}
17952
17953 \end_inset 
17954
17955
17956 \end_inset 
17957 </cell>
17958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17959 \begin_inset Text
17960
17961 \layout Standard
17962
17963 Debugger, serves nicely as GUI to sdcdb
17964 \begin_inset LatexCommand \index{sdcdb (debugger)}
17965
17966 \end_inset 
17967
17968  (Unix only)
17969 \end_inset 
17970 </cell>
17971 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17972 \begin_inset Text
17973
17974 \layout Standard
17975
17976
17977 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
17978
17979 \end_inset 
17980
17981
17982 \end_inset 
17983 </cell>
17984 </row>
17985 </lyxtabular>
17986
17987 \end_inset 
17988
17989
17990 \newline 
17991
17992 \layout Section
17993
17994 Related documentation / recommended reading
17995 \layout Standard
17996 \align center 
17997
17998 \begin_inset  Tabular
17999 <lyxtabular version="3" rows="6" columns="3">
18000 <features>
18001 <column alignment="center" valignment="top" leftline="true" width="0pt">
18002 <column alignment="block" valignment="top" leftline="true" width="30line%">
18003 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
18004 <row topline="true" bottomline="true">
18005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18006 \begin_inset Text
18007
18008 \layout Standard
18009
18010 Name
18011 \end_inset 
18012 </cell>
18013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18014 \begin_inset Text
18015
18016 \layout Standard
18017
18018 Subject / Title
18019 \end_inset 
18020 </cell>
18021 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18022 \begin_inset Text
18023
18024 \layout Standard
18025
18026 Where to get
18027 \end_inset 
18028 </cell>
18029 </row>
18030 <row topline="true">
18031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18032 \begin_inset Text
18033
18034 \layout Standard
18035
18036
18037 \family roman 
18038 \series medium 
18039 \shape up 
18040 \size normal 
18041 \emph off 
18042 \bar no 
18043 \noun off 
18044 \color none
18045 c-refcard.pdf
18046 \end_inset 
18047 </cell>
18048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18049 \begin_inset Text
18050
18051 \layout Standard
18052
18053 C Reference Card
18054 \begin_inset LatexCommand \index{C Reference card}
18055
18056 \end_inset 
18057
18058 , 2 pages
18059 \end_inset 
18060 </cell>
18061 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18062 \begin_inset Text
18063
18064 \layout Standard
18065
18066
18067 \begin_inset LatexCommand \url{http://www.refcards.com/about/c.html}
18068
18069 \end_inset 
18070
18071
18072 \end_inset 
18073 </cell>
18074 </row>
18075 <row topline="true">
18076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18077 \begin_inset Text
18078
18079 \layout Standard
18080
18081 c-faq
18082 \end_inset 
18083 </cell>
18084 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18085 \begin_inset Text
18086
18087 \layout Standard
18088
18089 C-FAQ-list
18090 \end_inset 
18091 </cell>
18092 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18093 \begin_inset Text
18094
18095 \layout Standard
18096
18097
18098 \begin_inset LatexCommand \url{http://www.eskimo.com/~scs/C-faq/top.html}
18099
18100 \end_inset 
18101
18102
18103 \end_inset 
18104 </cell>
18105 </row>
18106 <row topline="true">
18107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18108 \begin_inset Text
18109
18110 \layout Standard
18111
18112 \end_inset 
18113 </cell>
18114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18115 \begin_inset Text
18116
18117 \layout Standard
18118
18119 Latest datasheet of the target CPU
18120 \end_inset 
18121 </cell>
18122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18123 \begin_inset Text
18124
18125 \layout Standard
18126
18127 vendor
18128 \end_inset 
18129 </cell>
18130 </row>
18131 <row topline="true">
18132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18133 \begin_inset Text
18134
18135 \layout Standard
18136
18137 \end_inset 
18138 </cell>
18139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18140 \begin_inset Text
18141
18142 \layout Standard
18143
18144 Revision history of datasheet
18145 \end_inset 
18146 </cell>
18147 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18148 \begin_inset Text
18149
18150 \layout Standard
18151
18152 vendor
18153 \end_inset 
18154 </cell>
18155 </row>
18156 <row topline="true" bottomline="true">
18157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18158 \begin_inset Text
18159
18160 \layout Standard
18161
18162 S.
18163  S.
18164  Muchnick
18165 \end_inset 
18166 </cell>
18167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18168 \begin_inset Text
18169
18170 \layout Standard
18171
18172 Advanced Compiler Design and Implementation
18173 \end_inset 
18174 </cell>
18175 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18176 \begin_inset Text
18177
18178 \layout Standard
18179
18180 bookstore (very dedicated, probably read other books first)
18181 \end_inset 
18182 </cell>
18183 </row>
18184 </lyxtabular>
18185
18186 \end_inset 
18187
18188
18189 \newline 
18190
18191 \layout Section
18192
18193 Some Questions
18194 \layout Standard
18195
18196 Some questions answered, some pointers given - it might be time to in turn
18197  ask 
18198 \emph on 
18199 you
18200 \emph default 
18201  some questions: 
18202 \layout Itemize
18203
18204 can you solve your project with the selected microcontroller? Would you
18205  find out early or rather late that your target is too small/slow/whatever?
18206  Can you switch to a slightly better device if it doesn't fit?
18207 \layout Itemize
18208
18209 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
18210  and/or another programming language be more adequate? Would an operating
18211  system on the target device help?
18212 \layout Itemize
18213
18214 if you solved the problem, will the marketing department be happy?
18215 \layout Itemize
18216
18217 if the marketing department is happy, will customers be happy?
18218 \layout Itemize
18219
18220 if you're the project manager, marketing department and maybe even the customer
18221  in one person, have you tried to see the project from the outside?
18222 \layout Itemize
18223
18224 is the project done if you think it is done? Or is just that other interface/pro
18225 tocol/feature/configuration/option missing? How about website, manual(s),
18226  internationali(z|s)ation, packaging, labels, 2nd source for components,
18227  electromagnetic compatability/interference, documentation for production,
18228  production test software, update mechanism, patent issues?
18229 \layout Itemize
18230
18231 is your project adequately positioned in that magic triangle: fame, fortune,
18232  fun?
18233 \layout Standard
18234
18235 Maybe not all answers to these questions are known and some answers may
18236  even be 
18237 \emph on 
18238 no
18239 \emph default 
18240 , nevertheless knowing these questions may help you to avoid burnout
18241 \begin_inset Foot
18242 collapsed false
18243
18244 \layout Standard
18245
18246 burnout is bad for electronic devices, programmers and motorcycle tyres
18247 \end_inset 
18248
18249 .
18250  Chances are you didn't want to hear some of them...
18251 \layout Chapter
18252
18253 Support
18254 \begin_inset LatexCommand \index{Support}
18255
18256 \end_inset 
18257
18258
18259 \layout Standard
18260
18261 SDCC has grown to be a large project.
18262  The compiler alone (without the preprocessor, assembler and linker) is
18263  well over 100,000 lines of code (blank stripped).
18264  The open source nature of this project is a key to its continued growth
18265  and support.
18266  You gain the benefit and support of many active software developers and
18267  end users.
18268  Is SDCC perfect? No, that's why we need your help.
18269  The developers take pride in fixing reported bugs.
18270  You can help by reporting the bugs and helping other SDCC users.
18271  There are lots of ways to contribute, and we encourage you to take part
18272  in making SDCC a great software package.
18273  
18274 \layout Standard
18275
18276 The SDCC project is hosted on the SDCC sourceforge site at 
18277 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
18278
18279 \end_inset 
18280
18281 .
18282  You'll find the complete set of mailing lists
18283 \begin_inset LatexCommand \index{Mailing list}
18284
18285 \end_inset 
18286
18287 , forums, bug reporting system, patch submission
18288 \begin_inset LatexCommand \index{Patch submission}
18289
18290 \end_inset 
18291
18292  system, download
18293 \begin_inset LatexCommand \index{download}
18294
18295 \end_inset 
18296
18297  area and cvs code repository
18298 \begin_inset LatexCommand \index{cvs code repository}
18299
18300 \end_inset 
18301
18302  there.
18303 \layout Section
18304
18305 Reporting Bugs
18306 \begin_inset LatexCommand \index{Bug reporting}
18307
18308 \end_inset 
18309
18310
18311 \begin_inset LatexCommand \index{Reporting bugs}
18312
18313 \end_inset 
18314
18315
18316 \layout Standard
18317
18318 The recommended way of reporting bugs is using the infrastructure of the
18319  sourceforge site.
18320  You can follow the status of bug reports there and have an overview about
18321  the known bugs.
18322 \layout Standard
18323
18324 Bug reports are automatically forwarded to the developer mailing list and
18325  will be fixed ASAP.
18326  When reporting a bug, it is very useful to include a small test program
18327  (the smaller the better) which reproduces the problem.
18328  If you can isolate the problem by looking at the generated assembly code,
18329  this can be very helpful.
18330  Compiling your program with the -
18331 \begin_inset ERT
18332 status Collapsed
18333
18334 \layout Standard
18335
18336 \backslash 
18337 /
18338 \end_inset 
18339
18340 -dumpall
18341 \begin_inset LatexCommand \index{-\/-dumpall}
18342
18343 \end_inset 
18344
18345  option can sometimes be useful in locating optimization problems.
18346  When reporting a bug please maker sure you:
18347 \layout Enumerate
18348
18349 Attach the code you are compiling with SDCC.
18350  
18351 \layout Enumerate
18352
18353 Specify the exact command you use to run SDCC, or attach your Makefile.
18354  
18355 \layout Enumerate
18356
18357 Specify the SDCC version (type "
18358 \family sans 
18359 \series bold 
18360 sdcc -v
18361 \family default 
18362 \series default 
18363 "), your platform, and operating system.
18364  
18365 \layout Enumerate
18366
18367 Provide an exact copy of any error message or incorrect output.
18368  
18369 \layout Enumerate
18370
18371 Put something meaningful in the subject of your message.
18372 \layout Standard
18373
18374 Please attempt to include these 5 important parts, as applicable, in all
18375  requests for support or when reporting any problems or bugs with SDCC.
18376  Though this will make your message lengthy, it will greatly improve your
18377  chance that SDCC users and developers will be able to help you.
18378  Some SDCC developers are frustrated by bug reports without code provided
18379  that they can use to reproduce and ultimately fix the problem, so please
18380  be sure to provide sample code if you are reporting a bug! 
18381 \layout Standard
18382
18383 Please have a short check that you are using a recent version of SDCC and
18384  the bug is not yet known.
18385  This is the link for reporting bugs: 
18386 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
18387
18388 \end_inset 
18389
18390 .
18391 \layout Section
18392
18393 Requesting Features
18394 \begin_inset LatexCommand \label{sub:Requesting-Features}
18395
18396 \end_inset 
18397
18398
18399 \begin_inset LatexCommand \index{Feature request}
18400
18401 \end_inset 
18402
18403
18404 \begin_inset LatexCommand \index{Requesting features}
18405
18406 \end_inset 
18407
18408
18409 \layout Standard
18410
18411 Like bug reports feature requests are forwarded to the developer mailing
18412  list.
18413  This is the link for requesting features: 
18414 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
18415
18416 \end_inset 
18417
18418 .
18419 \layout Section
18420
18421 Submitting patches
18422 \layout Standard
18423
18424 Like bug reports contributed patches are forwarded to the developer mailing
18425  list.
18426  This is the link for submitting patches
18427 \begin_inset LatexCommand \index{Patch submission}
18428
18429 \end_inset 
18430
18431
18432 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
18433
18434 \end_inset 
18435
18436 .
18437 \layout Standard
18438
18439 You need to specify some parameters to the 
18440 \family typewriter 
18441 diff
18442 \family default 
18443  command for the patches to be useful.
18444  If you modified more than one file a patch created f.e.
18445  with 
18446 \family sans 
18447 \series bold 
18448
18449 \begin_inset Quotes sld
18450 \end_inset 
18451
18452 diff -Naur unmodified_directory modified_directory >my_changes.patch
18453 \begin_inset Quotes srd
18454 \end_inset 
18455
18456
18457 \family default 
18458 \series default 
18459  will be fine, otherwise 
18460 \family sans 
18461 \series bold 
18462
18463 \begin_inset Quotes sld
18464 \end_inset 
18465
18466 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
18467 \begin_inset Quotes srd
18468 \end_inset 
18469
18470
18471 \series default 
18472  
18473 \family default 
18474 will do.
18475 \layout Section
18476
18477 Getting Help
18478 \layout Standard
18479
18480 These links should take you directly to the 
18481 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
18482
18483 \end_inset 
18484
18485
18486 \begin_inset Foot
18487 collapsed false
18488
18489 \layout Standard
18490
18491 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
18492  automated messages (mid 2003)
18493 \end_inset 
18494
18495  and the 
18496 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
18497
18498 \end_inset 
18499
18500 , lists and forums are archived and searchable so if you are lucky someone
18501  already had a similar problem.
18502 \layout Section
18503
18504 ChangeLog
18505 \layout Standard
18506
18507 You can follow the status of the cvs version
18508 \begin_inset LatexCommand \index{version}
18509
18510 \end_inset 
18511
18512  of SDCC by watching the Changelog
18513 \begin_inset LatexCommand \index{Changelog}
18514
18515 \end_inset 
18516
18517  in the cvs-repository
18518 \newline 
18519
18520 \size footnotesize 
18521
18522 \begin_inset LatexCommand \htmlurl{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/sdcc/sdcc/ChangeLog?rev=HEAD&content-type=text/plain}
18523
18524 \end_inset 
18525
18526 .
18527 \layout Section
18528
18529 Release policy
18530 \begin_inset LatexCommand \index{Release policy}
18531
18532 \end_inset 
18533
18534
18535 \layout Standard
18536
18537 Historically there often were long delays between official releases and
18538  the sourceforge download area tends to get not updated at all.
18539  Excuses in the past might have referred to problems with live range analysis,
18540  but as this was fixed a while ago, the current problem is that another
18541  excuse has to be found.
18542  Kidding aside, we have to get better there! On the other hand there are
18543  daily snapshots available at 
18544 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
18545
18546 \end_inset 
18547
18548 , and you can always build the very last version (hopefully with many bugs
18549  fixed, and features added) from the source code available at 
18550 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
18551
18552 \end_inset 
18553
18554 .
18555 \layout Section
18556
18557 Examples
18558 \begin_inset LatexCommand \index{Examples}
18559
18560 \end_inset 
18561
18562
18563 \layout Standard
18564
18565 You'll find some small examples in the directory 
18566 \emph on 
18567 sdcc/device/examples/.
18568  
18569 \emph default 
18570 More examples and libraries are available at
18571 \emph on 
18572  The SDCC Open Knowledge Resource 
18573 \begin_inset LatexCommand \url{http://www.qsl.net/dl9sec/SDCC_OKR.html}
18574
18575 \end_inset 
18576
18577  
18578 \emph default 
18579 web site or at 
18580 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
18581
18582 \end_inset 
18583
18584 .
18585 \layout Comment
18586
18587 I did insert a reference to Paul's web site here although it seems rather
18588  dedicated to a specific 8032 board (I think it's okay because it f.e.
18589  shows LCD/Harddisc interface and has a free 8051 monitor.
18590  Independent 8032 board vendors face hard competition of heavily subsidized
18591  development boards anyway).
18592 \layout Comment
18593
18594 Maybe we should include some links to real world applications.
18595  Preferably pointer to pointers (one for each architecture) so this stays
18596  manageable here?
18597 \layout Section
18598
18599 Quality control
18600 \begin_inset LatexCommand \index{Quality control}
18601
18602 \end_inset 
18603
18604
18605 \layout Standard
18606
18607 The compiler is passed through nightly compile and build checks.
18608  The so called 
18609 \shape italic 
18610 regression tests
18611 \shape default 
18612
18613 \begin_inset LatexCommand \index{Regression test}
18614
18615 \end_inset 
18616
18617  check that SDCC itself compiles flawlessly on several platforms and checks
18618  the quality of the code generated by SDCC by running the code through simulator
18619 s.
18620  There is a separate document 
18621 \shape italic 
18622 test_suite.pdf
18623 \begin_inset LatexCommand \index{Test suite}
18624
18625 \end_inset 
18626
18627
18628 \shape default 
18629  about this.
18630 \layout Standard
18631
18632 You'll find the test code in the directory 
18633 \shape italic 
18634 sdcc/support/regression
18635 \shape default 
18636 .
18637  You can run these tests manually by running 
18638 \family sans 
18639 make
18640 \family default 
18641  in this directory (or f.e.
18642  
18643 \family sans 
18644 \series bold 
18645
18646 \begin_inset Quotes sld
18647 \end_inset 
18648
18649 make test-mcs51
18650 \begin_inset Quotes srd
18651 \end_inset 
18652
18653
18654 \family default 
18655 \series default 
18656  if you don't want to run the complete tests).
18657  The test code might also be interesting if you want to look for examples
18658 \begin_inset LatexCommand \index{Examples}
18659
18660 \end_inset 
18661
18662  checking corner cases of SDCC or if you plan to submit patches
18663 \begin_inset LatexCommand \index{Patch submission}
18664
18665 \end_inset 
18666
18667 .
18668 \layout Standard
18669
18670 The pic port uses a different set of regression tests, you'll find them
18671  in the directory 
18672 \shape italic 
18673 sdcc/src/regression
18674 \shape default 
18675 .
18676 \layout Chapter
18677 \pagebreak_top 
18678 SDCC Technical Data
18679 \layout Section
18680
18681 Optimizations
18682 \begin_inset LatexCommand \index{Optimizations}
18683
18684 \end_inset 
18685
18686
18687 \layout Standard
18688
18689 SDCC performs a host of standard optimizations in addition to some MCU specific
18690  optimizations.
18691  
18692 \layout Subsection
18693
18694 Sub-expression Elimination
18695 \begin_inset LatexCommand \index{Subexpression elimination}
18696
18697 \end_inset 
18698
18699
18700 \layout Standard
18701
18702 The compiler does local and 
18703 \emph on 
18704 g
18705 \emph default 
18706 lobal 
18707 \emph on 
18708 c
18709 \emph default 
18710 ommon 
18711 \emph on 
18712 s
18713 \emph default 
18714 ubexpression 
18715 \emph on 
18716 e
18717 \emph default 
18718 limination, e.g.: 
18719 \layout Verse
18720
18721
18722 \family typewriter 
18723 i = x + y + 1; 
18724 \newline 
18725 j = x + y;
18726 \layout Standard
18727
18728 will be translated to
18729 \layout Verse
18730
18731
18732 \family typewriter 
18733 iTemp = x + y; 
18734 \newline 
18735 i = iTemp + 1; 
18736 \newline 
18737 j = iTemp;
18738 \layout Standard
18739
18740 Some subexpressions are not as obvious as the above example, e.g.:
18741 \layout Verse
18742
18743
18744 \family typewriter 
18745 a->b[i].c = 10; 
18746 \newline 
18747 a->b[i].d = 11;
18748 \layout Standard
18749
18750 In this case the address arithmetic a->b[i] will be computed only once;
18751  the equivalent code in C would be.
18752 \layout Verse
18753
18754
18755 \family typewriter 
18756 iTemp = a->b[i]; 
18757 \newline 
18758 iTemp.c = 10; 
18759 \newline 
18760 iTemp.d = 11;
18761 \layout Standard
18762
18763 The compiler will try to keep these temporary variables in registers.
18764 \layout Subsection
18765
18766 Dead-Code Elimination
18767 \begin_inset LatexCommand \index{Dead-code elimination}
18768
18769 \end_inset 
18770
18771
18772 \layout Verse
18773
18774
18775 \family typewriter 
18776 int global;
18777 \newline 
18778
18779 \newline 
18780 void f () { 
18781 \newline 
18782 \SpecialChar ~
18783 \SpecialChar ~
18784 int i; 
18785 \newline 
18786 \SpecialChar ~
18787 \SpecialChar ~
18788 i = 1; \SpecialChar ~
18789 \SpecialChar ~
18790 \SpecialChar ~
18791 \SpecialChar ~
18792 \SpecialChar ~
18793 /* dead store */ 
18794 \newline 
18795 \SpecialChar ~
18796 \SpecialChar ~
18797 global = 1;\SpecialChar ~
18798 /* dead store */ 
18799 \newline 
18800 \SpecialChar ~
18801 \SpecialChar ~
18802 global = 2; 
18803 \newline 
18804 \SpecialChar ~
18805 \SpecialChar ~
18806 return; 
18807 \newline 
18808 \SpecialChar ~
18809 \SpecialChar ~
18810 global = 3;\SpecialChar ~
18811 /* unreachable */ 
18812 \newline 
18813 }
18814 \layout Standard
18815
18816 will be changed to
18817 \layout Verse
18818
18819
18820 \family typewriter 
18821 int global;
18822 \newline 
18823
18824 \newline 
18825 void f () {
18826 \newline 
18827 \SpecialChar ~
18828 \SpecialChar ~
18829 global = 2; 
18830 \newline 
18831 \SpecialChar ~
18832 \SpecialChar ~
18833 return; 
18834 \newline 
18835 }
18836 \layout Subsection
18837
18838 Copy-Propagation
18839 \begin_inset LatexCommand \index{Copy propagation}
18840
18841 \end_inset 
18842
18843
18844 \layout Verse
18845
18846
18847 \family typewriter 
18848 int f() { 
18849 \newline 
18850 \SpecialChar ~
18851 \SpecialChar ~
18852 int i, j; 
18853 \newline 
18854 \SpecialChar ~
18855 \SpecialChar ~
18856 i = 10; 
18857 \newline 
18858 \SpecialChar ~
18859 \SpecialChar ~
18860 j = i; 
18861 \newline 
18862 \SpecialChar ~
18863 \SpecialChar ~
18864 return j; 
18865 \newline 
18866 }
18867 \layout Standard
18868
18869 will be changed to 
18870 \layout Verse
18871
18872
18873 \family typewriter 
18874 int f() { 
18875 \newline 
18876 \SpecialChar ~
18877 \SpecialChar ~
18878 int i, j; 
18879 \newline 
18880 \SpecialChar ~
18881 \SpecialChar ~
18882 i = 10; 
18883 \newline 
18884 \SpecialChar ~
18885 \SpecialChar ~
18886 j = 10; 
18887 \newline 
18888 \SpecialChar ~
18889 \SpecialChar ~
18890 return 10; 
18891 \newline 
18892 }
18893 \layout Standard
18894
18895 Note: the dead stores created by this copy propagation will be eliminated
18896  by dead-code elimination.
18897 \layout Subsection
18898
18899 Loop Optimizations
18900 \begin_inset LatexCommand \index{Loop optimization}
18901
18902 \end_inset 
18903
18904
18905 \layout Standard
18906
18907 Two types of loop optimizations are done by SDCC loop invariant lifting
18908  and strength reduction of loop induction variables.
18909  In addition to the strength reduction the optimizer marks the induction
18910  variables and the register allocator tries to keep the induction variables
18911  in registers for the duration of the loop.
18912  Because of this preference of the register allocator
18913 \begin_inset LatexCommand \index{Register allocation}
18914
18915 \end_inset 
18916
18917 , loop induction optimization causes an increase in register pressure, which
18918  may cause unwanted spilling of other temporary variables into the stack
18919 \begin_inset LatexCommand \index{stack}
18920
18921 \end_inset 
18922
18923  / data space.
18924  The compiler will generate a warning message when it is forced to allocate
18925  extra space either on the stack or data space.
18926  If this extra space allocation is undesirable then induction optimization
18927  can be eliminated either for the entire source file (with -
18928 \begin_inset ERT
18929 status Collapsed
18930
18931 \layout Standard
18932
18933 \backslash 
18934 /
18935 \end_inset 
18936
18937 -noinduction option) or for a given function only using #pragma\SpecialChar ~
18938 noinduction
18939 \begin_inset LatexCommand \index{\#pragma noinduction}
18940
18941 \end_inset 
18942
18943 .
18944 \newline 
18945
18946 \newline 
18947 Loop Invariant:
18948 \layout Verse
18949
18950
18951 \family typewriter 
18952 for (i = 0 ; i < 100 ; i ++) 
18953 \newline 
18954 \SpecialChar ~
18955 \SpecialChar ~
18956 \SpecialChar ~
18957 \SpecialChar ~
18958 f += k + l;
18959 \layout Standard
18960
18961 changed to
18962 \layout Verse
18963
18964
18965 \family typewriter 
18966 itemp = k + l; 
18967 \newline 
18968 for (i = 0; i < 100; i++) 
18969 \newline 
18970 \SpecialChar ~
18971 \SpecialChar ~
18972 \SpecialChar ~
18973 \SpecialChar ~
18974 f += itemp;
18975 \layout Standard
18976
18977 As mentioned previously some loop invariants are not as apparent, all static
18978  address computations are also moved out of the loop.
18979 \newline 
18980
18981 \newline 
18982 Strength Reduction
18983 \begin_inset LatexCommand \index{Strength reduction}
18984
18985 \end_inset 
18986
18987 , this optimization substitutes an expression by a cheaper expression:
18988 \layout Verse
18989
18990
18991 \family typewriter 
18992 for (i=0;i < 100; i++)
18993 \newline 
18994 \SpecialChar ~
18995 \SpecialChar ~
18996 \SpecialChar ~
18997 \SpecialChar ~
18998 ar[i*5] = i*3;
18999 \layout Standard
19000
19001 changed to
19002 \layout Verse
19003
19004
19005 \family typewriter 
19006 itemp1 = 0; 
19007 \newline 
19008 itemp2 = 0; 
19009 \newline 
19010 for (i=0;i< 100;i++) { 
19011 \newline 
19012 \SpecialChar ~
19013 \SpecialChar ~
19014 \SpecialChar ~
19015 \SpecialChar ~
19016 ar[itemp1] = itemp2; 
19017 \newline 
19018 \SpecialChar ~
19019 \SpecialChar ~
19020 \SpecialChar ~
19021 \SpecialChar ~
19022 itemp1 += 5; 
19023 \newline 
19024 \SpecialChar ~
19025 \SpecialChar ~
19026 \SpecialChar ~
19027 \SpecialChar ~
19028 itemp2 += 3; 
19029 \newline 
19030 }
19031 \layout Standard
19032
19033 The more expensive multiplication
19034 \begin_inset LatexCommand \index{Multiplication}
19035
19036 \end_inset 
19037
19038  is changed to a less expensive addition.
19039 \layout Subsection
19040
19041 Loop Reversing
19042 \begin_inset LatexCommand \index{Loop reversing}
19043
19044 \end_inset 
19045
19046
19047 \layout Standard
19048
19049 This optimization is done to reduce the overhead of checking loop boundaries
19050  for every iteration.
19051  Some simple loops can be reversed and implemented using a 
19052 \begin_inset Quotes eld
19053 \end_inset 
19054
19055 decrement and jump if not zero
19056 \begin_inset Quotes erd
19057 \end_inset 
19058
19059  instruction.
19060  SDCC checks for the following criterion to determine if a loop is reversible
19061  (note: more sophisticated compilers use data-dependency analysis to make
19062  this determination, SDCC uses a more simple minded analysis).
19063 \layout Itemize
19064
19065 The 'for' loop is of the form 
19066 \newline 
19067
19068 \newline 
19069
19070 \family typewriter 
19071 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
19072  += 1])
19073 \newline 
19074 \SpecialChar ~
19075 \SpecialChar ~
19076 \SpecialChar ~
19077 \SpecialChar ~
19078 <for body>
19079 \layout Itemize
19080
19081 The <for body> does not contain 
19082 \begin_inset Quotes eld
19083 \end_inset 
19084
19085 continue
19086 \begin_inset Quotes erd
19087 \end_inset 
19088
19089  or 'break
19090 \begin_inset Quotes erd
19091 \end_inset 
19092
19093 .
19094 \layout Itemize
19095
19096 All goto's are contained within the loop.
19097 \layout Itemize
19098
19099 No function calls within the loop.
19100 \layout Itemize
19101
19102 The loop control variable <sym> is not assigned any value within the loop
19103 \layout Itemize
19104
19105 The loop control variable does NOT participate in any arithmetic operation
19106  within the loop.
19107 \layout Itemize
19108
19109 There are NO switch statements in the loop.
19110 \layout Subsection
19111
19112 Algebraic Simplifications
19113 \layout Standard
19114
19115 SDCC does numerous algebraic simplifications, the following is a small sub-set
19116  of these optimizations.
19117 \layout Verse
19118
19119
19120 \family typewriter 
19121 i = j + 0;\SpecialChar ~
19122 \SpecialChar ~
19123 \SpecialChar ~
19124 \SpecialChar ~
19125  /* changed to: */\SpecialChar ~
19126 \SpecialChar ~
19127 \SpecialChar ~
19128 \SpecialChar ~
19129  i = j; 
19130 \newline 
19131 i /= 2;\SpecialChar ~
19132 \SpecialChar ~
19133 \SpecialChar ~
19134 \SpecialChar ~
19135 \SpecialChar ~
19136 \SpecialChar ~
19137 \SpecialChar ~
19138  /* changed to: */\SpecialChar ~
19139 \SpecialChar ~
19140 \SpecialChar ~
19141 \SpecialChar ~
19142  i >>= 1; 
19143 \newline 
19144 i = j - j;\SpecialChar ~
19145 \SpecialChar ~
19146 \SpecialChar ~
19147 \SpecialChar ~
19148  /* changed to: */\SpecialChar ~
19149 \SpecialChar ~
19150 \SpecialChar ~
19151 \SpecialChar ~
19152  i = 0; 
19153 \newline 
19154 i = j / 1;\SpecialChar ~
19155 \SpecialChar ~
19156 \SpecialChar ~
19157 \SpecialChar ~
19158  /* changed to: */\SpecialChar ~
19159 \SpecialChar ~
19160 \SpecialChar ~
19161 \SpecialChar ~
19162  i = j;
19163 \layout Standard
19164
19165 Note the subexpressions
19166 \begin_inset LatexCommand \index{Subexpression}
19167
19168 \end_inset 
19169
19170  given above are generally introduced by macro expansions or as a result
19171  of copy/constant propagation.
19172 \layout Subsection
19173
19174 'switch' Statements
19175 \begin_inset LatexCommand \label{sub:'switch'-Statements}
19176
19177 \end_inset 
19178
19179
19180 \begin_inset LatexCommand \index{switch statement}
19181
19182 \end_inset 
19183
19184
19185 \layout Standard
19186
19187 SDCC changes switch statements to jump tables
19188 \begin_inset LatexCommand \index{jump tables}
19189
19190 \end_inset 
19191
19192  when the following conditions are true.
19193  
19194 \layout Itemize
19195
19196 The case labels are in numerical sequence, the labels need not be in order,
19197  and the starting number need not be one or zero.
19198 \begin_deeper 
19199 \layout Verse
19200
19201
19202 \family typewriter 
19203 switch(i) {\SpecialChar ~
19204 \SpecialChar ~
19205 \SpecialChar ~
19206 \SpecialChar ~
19207 \SpecialChar ~
19208 \SpecialChar ~
19209 \SpecialChar ~
19210 \SpecialChar ~
19211 \SpecialChar ~
19212 \SpecialChar ~
19213 \SpecialChar ~
19214 \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 switch (i) { 
19230 \newline 
19231 \SpecialChar ~
19232 \SpecialChar ~
19233 \SpecialChar ~
19234 case 4: ...\SpecialChar ~
19235 \SpecialChar ~
19236 \SpecialChar ~
19237 \SpecialChar ~
19238 \SpecialChar ~
19239 \SpecialChar ~
19240 \SpecialChar ~
19241 \SpecialChar ~
19242 \SpecialChar ~
19243 \SpecialChar ~
19244 \SpecialChar ~
19245 \SpecialChar ~
19246 \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 case 0: ...
19261  
19262 \newline 
19263 \SpecialChar ~
19264 \SpecialChar ~
19265 \SpecialChar ~
19266 case 5: ...\SpecialChar ~
19267 \SpecialChar ~
19268 \SpecialChar ~
19269 \SpecialChar ~
19270 \SpecialChar ~
19271 \SpecialChar ~
19272 \SpecialChar ~
19273 \SpecialChar ~
19274 \SpecialChar ~
19275 \SpecialChar ~
19276 \SpecialChar ~
19277 \SpecialChar ~
19278 \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 case 1: ...
19293  
19294 \newline 
19295 \SpecialChar ~
19296 \SpecialChar ~
19297 \SpecialChar ~
19298 case 3: ...\SpecialChar ~
19299 \SpecialChar ~
19300 \SpecialChar ~
19301 \SpecialChar ~
19302 \SpecialChar ~
19303 \SpecialChar ~
19304 \SpecialChar ~
19305 \SpecialChar ~
19306 \SpecialChar ~
19307 \SpecialChar ~
19308 \SpecialChar ~
19309 \SpecialChar ~
19310 \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 case 2: ...
19325  
19326 \newline 
19327 \SpecialChar ~
19328 \SpecialChar ~
19329 \SpecialChar ~
19330 case 6: ...\SpecialChar ~
19331 \SpecialChar ~
19332 \SpecialChar ~
19333 \SpecialChar ~
19334 \SpecialChar ~
19335 \SpecialChar ~
19336 \SpecialChar ~
19337 \SpecialChar ~
19338 \SpecialChar ~
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 case 3: ...
19357  
19358 \newline 
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 \SpecialChar ~
19376 \SpecialChar ~
19377 \SpecialChar ~
19378 \SpecialChar ~
19379 \SpecialChar ~
19380 \SpecialChar ~
19381 \SpecialChar ~
19382 \SpecialChar ~
19383 \SpecialChar ~
19384 \SpecialChar ~
19385 \SpecialChar ~
19386 \SpecialChar ~
19387 \SpecialChar ~
19388 \SpecialChar ~
19389 \SpecialChar ~
19390 \SpecialChar ~
19391 \SpecialChar ~
19392 \SpecialChar ~
19393 \SpecialChar ~
19394 \SpecialChar ~
19395 }
19396 \layout Standard
19397
19398 Both the above switch statements will be implemented using a jump-table.
19399  The example to the right side is slightly more efficient as the check for
19400  the lower boundary of the jump-table is not needed.
19401 \end_deeper 
19402 \layout Itemize
19403
19404 The number of case labels is at least three, since it takes two conditional
19405  statements to handle the boundary conditions.
19406 \layout Itemize
19407
19408 The number of case labels is less than 84, since each label takes 3 bytes
19409  and a jump-table can be utmost 256 bytes long.
19410 \layout Standard
19411
19412 Switch statements which have gaps in the numeric sequence or those that
19413  have more that 84 case labels can be split into more than one switch statement
19414  for efficient code generation, e.g.:
19415 \layout Verse
19416
19417
19418 \family typewriter 
19419 switch (i) { 
19420 \newline 
19421 \SpecialChar ~
19422 \SpecialChar ~
19423 case 1: ...
19424  
19425 \newline 
19426 \SpecialChar ~
19427 \SpecialChar ~
19428 case 2: ...
19429  
19430 \newline 
19431 \SpecialChar ~
19432 \SpecialChar ~
19433 case 3: ...
19434  
19435 \newline 
19436 \SpecialChar ~
19437 \SpecialChar ~
19438 case 4: ...
19439  
19440 \newline 
19441 \SpecialChar ~
19442 \SpecialChar ~
19443 case 9: ...
19444  
19445 \newline 
19446 \SpecialChar ~
19447 \SpecialChar ~
19448 case 10: ...
19449  
19450 \newline 
19451 \SpecialChar ~
19452 \SpecialChar ~
19453 case 11: ...
19454  
19455 \newline 
19456 \SpecialChar ~
19457 \SpecialChar ~
19458 case 12: ...
19459  
19460 \newline 
19461 }
19462 \layout Standard
19463
19464 If the above switch statement is broken down into two switch statements
19465 \layout Verse
19466
19467
19468 \family typewriter 
19469 switch (i) { 
19470 \newline 
19471 \SpecialChar ~
19472 \SpecialChar ~
19473 case 1: ...
19474  
19475 \newline 
19476 \SpecialChar ~
19477 \SpecialChar ~
19478 case 2: ...
19479  
19480 \newline 
19481 \SpecialChar ~
19482 \SpecialChar ~
19483 case 3: ...
19484  
19485 \newline 
19486 \SpecialChar ~
19487 \SpecialChar ~
19488 case 4: ...
19489  
19490 \newline 
19491 }
19492 \layout Standard
19493
19494 and
19495 \layout Verse
19496
19497
19498 \family typewriter 
19499 switch (i) { 
19500 \newline 
19501 \SpecialChar ~
19502 \SpecialChar ~
19503 case 9:\SpecialChar ~
19504 \SpecialChar ~
19505 ...
19506  
19507 \newline 
19508 \SpecialChar ~
19509 \SpecialChar ~
19510 case 10:\SpecialChar ~
19511 ...
19512  
19513 \newline 
19514 \SpecialChar ~
19515 \SpecialChar ~
19516 case 11:\SpecialChar ~
19517 ...
19518  
19519 \newline 
19520 \SpecialChar ~
19521 \SpecialChar ~
19522 case 12:\SpecialChar ~
19523 ...
19524  
19525 \newline 
19526 }
19527 \layout Standard
19528
19529 then both the switch statements will be implemented using jump-tables whereas
19530  the unmodified switch statement will not be.
19531  You might also consider inserting dummy cases 0 and 5 to 8 in this example.
19532  
19533 \newline 
19534 The pragma nojtbound
19535 \begin_inset LatexCommand \index{\#pragma nojtbound}
19536
19537 \end_inset 
19538
19539  can be used to turn off checking the 
19540 \emph on 
19541 j
19542 \emph default 
19543 ump 
19544 \emph on 
19545 t
19546 \emph default 
19547 able 
19548 \emph on 
19549 bound
19550 \emph default 
19551 aries.
19552  It has no effect if a default label is supplied.
19553  Use of this pragma is dangerous: if the switch argument is not matched
19554  by a case statement the processor will happily jump into Nirvana.
19555 \layout Subsection
19556
19557 Bit-shifting Operations
19558 \begin_inset LatexCommand \index{Bit shifting}
19559
19560 \end_inset 
19561
19562 .
19563 \layout Standard
19564
19565 Bit shifting is one of the most frequently used operation in embedded programmin
19566 g.
19567  SDCC tries to implement bit-shift operations in the most efficient way
19568  possible, e.g.:
19569 \layout Verse
19570
19571
19572 \family typewriter 
19573 unsigned char i;
19574 \newline 
19575 ...
19576  
19577 \newline 
19578 i >>= 4; 
19579 \newline 
19580 ...
19581 \layout Standard
19582
19583 generates the following code:
19584 \layout Verse
19585
19586
19587 \family typewriter 
19588 mov\SpecialChar ~
19589  a,_i 
19590 \newline 
19591 swap a 
19592 \newline 
19593 anl\SpecialChar ~
19594  a,#0x0f 
19595 \newline 
19596 mov\SpecialChar ~
19597  _i,a
19598 \layout Standard
19599
19600 In general SDCC will never setup a loop if the shift count is known.
19601  Another example:
19602 \layout Verse
19603
19604
19605 \family typewriter 
19606 unsigned int i; 
19607 \newline 
19608 ...
19609  
19610 \newline 
19611 i >>= 9; 
19612 \newline 
19613 ...
19614 \layout Standard
19615
19616 will generate:
19617 \layout Verse
19618
19619
19620 \family typewriter 
19621 mov\SpecialChar ~
19622 \SpecialChar ~
19623 a,(_i + 1) 
19624 \newline 
19625 mov\SpecialChar ~
19626 \SpecialChar ~
19627 (_i + 1),#0x00 
19628 \newline 
19629 clr\SpecialChar ~
19630 \SpecialChar ~
19631
19632 \newline 
19633 rrc\SpecialChar ~
19634 \SpecialChar ~
19635
19636 \newline 
19637 mov\SpecialChar ~
19638 \SpecialChar ~
19639 _i,a
19640 \layout Subsection
19641
19642 Bit-rotation
19643 \begin_inset LatexCommand \index{Bit rotation}
19644
19645 \end_inset 
19646
19647
19648 \layout Standard
19649
19650 A special case of the bit-shift operation is bit rotation
19651 \begin_inset LatexCommand \index{rotating bits}
19652
19653 \end_inset 
19654
19655 , SDCC recognizes the following expression to be a left bit-rotation:
19656 \layout Verse
19657
19658
19659 \family typewriter 
19660 \series bold 
19661 unsigned
19662 \series default 
19663 \SpecialChar ~
19664 \SpecialChar ~
19665 char i;\SpecialChar ~
19666 \SpecialChar ~
19667 \SpecialChar ~
19668 \SpecialChar ~
19669 \SpecialChar ~
19670 \SpecialChar ~
19671 \SpecialChar ~
19672 \SpecialChar ~
19673 \SpecialChar ~
19674 \SpecialChar ~
19675 \SpecialChar ~
19676 /* unsigned is needed for rotation */ 
19677 \newline 
19678 ...
19679  
19680 \newline 
19681 i = ((i << 1) | (i >> 7)); 
19682 \family default 
19683
19684 \newline 
19685
19686 \family typewriter 
19687 ...
19688 \layout Standard
19689
19690 will generate the following code:
19691 \layout Verse
19692
19693
19694 \family typewriter 
19695 mov\SpecialChar ~
19696 \SpecialChar ~
19697 a,_i 
19698 \newline 
19699 rl\SpecialChar ~
19700 \SpecialChar ~
19701 \SpecialChar ~
19702
19703 \newline 
19704 mov\SpecialChar ~
19705 \SpecialChar ~
19706 _i,a
19707 \layout Standard
19708
19709 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
19710 ns of this case will also be recognized as bit-rotation, i.e.: 
19711 \layout Verse
19712
19713
19714 \family typewriter 
19715 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
19716 \layout Subsection
19717
19718 Nibble and Byte Swapping
19719 \layout Standard
19720
19721 Other special cases of the bit-shift operations are nibble or byte swapping
19722 \begin_inset LatexCommand \index{swapping nibbles/bytes}
19723
19724 \end_inset 
19725
19726 , SDCC recognizes the following expressions:
19727 \layout Verse
19728
19729
19730 \family typewriter 
19731 \series bold 
19732 unsigned
19733 \series default 
19734 \SpecialChar ~
19735 \SpecialChar ~
19736 char i; 
19737 \newline 
19738
19739 \series bold 
19740 unsigned
19741 \series default 
19742 \SpecialChar ~
19743 \SpecialChar ~
19744 int j; 
19745 \newline 
19746 ...
19747  
19748 \newline 
19749 i = ((i << 4) | (i >> 4)); 
19750 \family default 
19751
19752 \newline 
19753
19754 \family typewriter 
19755 j = ((j << 8) | (j >> 8)); 
19756 \layout Standard
19757
19758 and generates a swap instruction for the nibble swapping
19759 \begin_inset LatexCommand \index{Nibble swapping}
19760
19761 \end_inset 
19762
19763  or move instructions for the byte swapping
19764 \begin_inset LatexCommand \index{Byte swapping}
19765
19766 \end_inset 
19767
19768 .
19769  The 
19770 \begin_inset Quotes sld
19771 \end_inset 
19772
19773 j
19774 \begin_inset Quotes srd
19775 \end_inset 
19776
19777  example can be used to convert from little to big-endian or vice versa.
19778  If you want to change the endianness of a 
19779 \emph on 
19780 signed
19781 \emph default 
19782  integer you have to cast to 
19783 \family typewriter 
19784 (unsigned int)
19785 \family default 
19786  first.
19787 \layout Standard
19788
19789 Note that SDCC stores numbers in little-endian
19790 \begin_inset Foot
19791 collapsed false
19792
19793 \layout Standard
19794
19795 Usually 8-bit processors don't care much about endianness.
19796  This is not the case for the standard 8051 which only has an instruction
19797  to increment its 
19798 \emph on 
19799 dptr
19800 \emph default 
19801
19802 \begin_inset LatexCommand \index{DPTR}
19803
19804 \end_inset 
19805
19806 -datapointer
19807 \emph on 
19808  
19809 \emph default 
19810 so little-endian is the more efficient byte order.
19811 \end_inset 
19812
19813
19814 \begin_inset LatexCommand \index{little-endian}
19815
19816 \end_inset 
19817
19818
19819 \begin_inset LatexCommand \index{Endianness}
19820
19821 \end_inset 
19822
19823  format (i.e.
19824  lowest order first).
19825 \layout Subsection
19826
19827 Highest Order Bit
19828 \begin_inset LatexCommand \index{Highest Order Bit}
19829
19830 \end_inset 
19831
19832
19833 \layout Standard
19834
19835 It is frequently required to obtain the highest order bit of an integral
19836  type (long, int, short or char types).
19837  SDCC recognizes the following expression to yield the highest order bit
19838  and generates optimized code for it, e.g.:
19839 \layout Verse
19840
19841
19842 \family typewriter 
19843 unsigned int gint; 
19844 \newline 
19845
19846 \newline 
19847 foo () { 
19848 \newline 
19849 \SpecialChar ~
19850 \SpecialChar ~
19851 unsigned char hob; 
19852 \newline 
19853 \SpecialChar ~
19854 \SpecialChar ~
19855 ...
19856  
19857 \newline 
19858 \SpecialChar ~
19859 \SpecialChar ~
19860 hob = (gint >> 15) & 1; 
19861 \newline 
19862 \SpecialChar ~
19863 \SpecialChar ~
19864 ..
19865  
19866 \newline 
19867 }
19868 \layout Standard
19869
19870 will generate the following code:
19871 \layout Verse
19872
19873
19874 \family typewriter 
19875 \SpecialChar ~
19876 \SpecialChar ~
19877 \SpecialChar ~
19878 \SpecialChar ~
19879 \SpecialChar ~
19880 \SpecialChar ~
19881 \SpecialChar ~
19882 \SpecialChar ~
19883 \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 \SpecialChar ~
19899 \SpecialChar ~
19900  61 ;\SpecialChar ~
19901  hob.c 7 
19902 \newline 
19903 000A E5*01\SpecialChar ~
19904 \SpecialChar ~
19905 \SpecialChar ~
19906 \SpecialChar ~
19907 \SpecialChar ~
19908 \SpecialChar ~
19909 \SpecialChar ~
19910 \SpecialChar ~
19911 \SpecialChar ~
19912 \SpecialChar ~
19913 \SpecialChar ~
19914 \SpecialChar ~
19915 \SpecialChar ~
19916 \SpecialChar ~
19917 \SpecialChar ~
19918  62\SpecialChar ~
19919 \SpecialChar ~
19920 \SpecialChar ~
19921 \SpecialChar ~
19922 \SpecialChar ~
19923 \SpecialChar ~
19924 \SpecialChar ~
19925 \SpecialChar ~
19926  mov\SpecialChar ~
19927 \SpecialChar ~
19928  a,(_gint + 1) 
19929 \newline 
19930 000C 23\SpecialChar ~
19931 \SpecialChar ~
19932 \SpecialChar ~
19933 \SpecialChar ~
19934 \SpecialChar ~
19935 \SpecialChar ~
19936 \SpecialChar ~
19937 \SpecialChar ~
19938 \SpecialChar ~
19939 \SpecialChar ~
19940 \SpecialChar ~
19941 \SpecialChar ~
19942 \SpecialChar ~
19943 \SpecialChar ~
19944 \SpecialChar ~
19945 \SpecialChar ~
19946 \SpecialChar ~
19947 \SpecialChar ~
19948  63\SpecialChar ~
19949 \SpecialChar ~
19950 \SpecialChar ~
19951 \SpecialChar ~
19952 \SpecialChar ~
19953 \SpecialChar ~
19954 \SpecialChar ~
19955 \SpecialChar ~
19956  rl\SpecialChar ~
19957 \SpecialChar ~
19958 \SpecialChar ~
19959  a 
19960 \newline 
19961 000D 54 01\SpecialChar ~
19962 \SpecialChar ~
19963 \SpecialChar ~
19964 \SpecialChar ~
19965 \SpecialChar ~
19966 \SpecialChar ~
19967 \SpecialChar ~
19968 \SpecialChar ~
19969 \SpecialChar ~
19970 \SpecialChar ~
19971 \SpecialChar ~
19972 \SpecialChar ~
19973 \SpecialChar ~
19974 \SpecialChar ~
19975 \SpecialChar ~
19976  64\SpecialChar ~
19977 \SpecialChar ~
19978 \SpecialChar ~
19979 \SpecialChar ~
19980 \SpecialChar ~
19981 \SpecialChar ~
19982 \SpecialChar ~
19983 \SpecialChar ~
19984  anl\SpecialChar ~
19985 \SpecialChar ~
19986  a,#0x01 
19987 \newline 
19988 000F F5*02\SpecialChar ~
19989 \SpecialChar ~
19990 \SpecialChar ~
19991 \SpecialChar ~
19992 \SpecialChar ~
19993 \SpecialChar ~
19994 \SpecialChar ~
19995 \SpecialChar ~
19996 \SpecialChar ~
19997 \SpecialChar ~
19998 \SpecialChar ~
19999 \SpecialChar ~
20000 \SpecialChar ~
20001 \SpecialChar ~
20002 \SpecialChar ~
20003  65\SpecialChar ~
20004 \SpecialChar ~
20005 \SpecialChar ~
20006 \SpecialChar ~
20007 \SpecialChar ~
20008 \SpecialChar ~
20009 \SpecialChar ~
20010 \SpecialChar ~
20011  mov\SpecialChar ~
20012 \SpecialChar ~
20013  _foo_hob_1_1,a
20014 \layout Standard
20015
20016 Variations of this case however will 
20017 \emph on 
20018 not
20019 \emph default 
20020  be recognized.
20021  It is a standard C expression, so I heartily recommend this be the only
20022  way to get the highest order bit, (it is portable).
20023  Of course it will be recognized even if it is embedded in other expressions,
20024  e.g.:
20025 \layout Verse
20026
20027
20028 \family typewriter 
20029 xyz = gint + ((gint >> 15) & 1);
20030 \layout Standard
20031
20032 will still be recognized.
20033 \layout Subsection
20034
20035 Peephole Optimizer
20036 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
20037
20038 \end_inset 
20039
20040
20041 \begin_inset LatexCommand \index{Peephole optimizer}
20042
20043 \end_inset 
20044
20045
20046 \layout Standard
20047
20048 The compiler uses a rule based, pattern matching and re-writing mechanism
20049  for peep-hole optimization.
20050  It is inspired by 
20051 \emph on 
20052 copt
20053 \emph default 
20054  a peep-hole optimizer by Christopher W.
20055  Fraser (cwfraser@microsoft.com).
20056  A default set of rules are compiled into the compiler, additional rules
20057  may be added with the 
20058 \emph on 
20059 -
20060 \begin_inset ERT
20061 status Collapsed
20062
20063 \layout Standard
20064
20065 \backslash 
20066 /
20067 \end_inset 
20068
20069 -peep-file
20070 \begin_inset LatexCommand \index{-\/-peep-file}
20071
20072 \end_inset 
20073
20074  <filename>
20075 \emph default 
20076  option.
20077  The rule language is best illustrated with examples.
20078 \layout Verse
20079
20080
20081 \family typewriter 
20082 replace { 
20083 \newline 
20084 \SpecialChar ~
20085 \SpecialChar ~
20086 mov %1,a 
20087 \newline 
20088 \SpecialChar ~
20089 \SpecialChar ~
20090 mov a,%1
20091 \newline 
20092 } by {
20093 \newline 
20094 \SpecialChar ~
20095 \SpecialChar ~
20096 mov %1,a
20097 \newline 
20098 }
20099 \layout Standard
20100
20101 The above rule will change the following assembly
20102 \begin_inset LatexCommand \index{Assembler routines}
20103
20104 \end_inset 
20105
20106  sequence:
20107 \layout Verse
20108
20109
20110 \family typewriter 
20111 mov r1,a 
20112 \newline 
20113 mov a,r1
20114 \layout Standard
20115
20116 to
20117 \layout Verse
20118
20119
20120 \family typewriter 
20121 mov r1,a
20122 \layout Standard
20123
20124 Note: All occurrences of a 
20125 \emph on 
20126 %n
20127 \emph default 
20128  (pattern variable) must denote the same string.
20129  With the above rule, the assembly sequence:
20130 \layout Verse
20131
20132
20133 \family typewriter 
20134 mov r1,a 
20135 \newline 
20136 mov a,r2
20137 \layout Standard
20138
20139 will remain unmodified.
20140 \newline 
20141
20142 \newline 
20143 Other special case optimizations may be added by the user (via 
20144 \emph on 
20145 -
20146 \begin_inset ERT
20147 status Collapsed
20148
20149 \layout Standard
20150
20151 \backslash 
20152 /
20153 \end_inset 
20154
20155 -peep-file option
20156 \emph default 
20157 ).
20158  E.g.
20159  some variants of the 8051 MCU allow only 
20160 \family typewriter 
20161 ajmp
20162 \family default 
20163  and 
20164 \family typewriter 
20165 acall
20166 \family default 
20167 .
20168  The following two rules will change all 
20169 \family typewriter 
20170 ljmp
20171 \family default 
20172  and 
20173 \family typewriter 
20174 lcall
20175 \family default 
20176  to 
20177 \family typewriter 
20178 ajmp
20179 \family default 
20180  and 
20181 \family typewriter 
20182 acall
20183 \layout Verse
20184
20185
20186 \family typewriter 
20187 replace { lcall %1 } by { acall %1 } 
20188 \newline 
20189 replace { ljmp %1 } by { ajmp %1 }
20190 \layout Standard
20191
20192 The 
20193 \emph on 
20194 inline-assembler code
20195 \emph default 
20196  is also passed through the peep hole optimizer, thus the peephole optimizer
20197  can also be used as an assembly level macro expander.
20198  The rules themselves are MCU dependent whereas the rule language infra-structur
20199 e is MCU independent.
20200  Peephole optimization rules for other MCU can be easily programmed using
20201  the rule language.
20202 \newline 
20203
20204 \newline 
20205 The syntax for a rule is as follows:
20206 \layout Verse
20207
20208
20209 \family typewriter 
20210 rule := replace [ restart ] '{' <assembly sequence> '
20211 \backslash 
20212 n' 
20213 \newline 
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  '}' by '{' '
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  \SpecialChar ~
20247  \SpecialChar ~
20248  <assembly sequence> '
20249 \backslash 
20250 n' 
20251 \newline 
20252 \SpecialChar ~
20253  \SpecialChar ~
20254  \SpecialChar ~
20255  \SpecialChar ~
20256  \SpecialChar ~
20257  \SpecialChar ~
20258  \SpecialChar ~
20259  \SpecialChar ~
20260  \SpecialChar ~
20261  \SpecialChar ~
20262  \SpecialChar ~
20263  \SpecialChar ~
20264  \SpecialChar ~
20265  \SpecialChar ~
20266  '}' [if <functionName> ] '
20267 \backslash 
20268 n' 
20269 \layout Standard
20270
20271 <assembly sequence> := assembly instruction (each instruction including
20272  labels must be on a separate line).
20273 \newline 
20274
20275 \newline 
20276 The optimizer will apply to the rules one by one from the top in the sequence
20277  of their appearance, it will terminate when all rules are exhausted.
20278  If the 'restart' option is specified, then the optimizer will start matching
20279  the rules again from the top, this option for a rule is expensive (performance)
20280 , it is intended to be used in situations where a transformation will trigger
20281  the same rule again.
20282  An example of this (not a good one, it has side effects) is the following
20283  rule:
20284 \layout Verse
20285
20286
20287 \family typewriter 
20288 replace restart { 
20289 \newline 
20290 \SpecialChar ~
20291 \SpecialChar ~
20292 pop %1 
20293 \newline 
20294 \SpecialChar ~
20295 \SpecialChar ~
20296 push %1 } by { 
20297 \newline 
20298 \SpecialChar ~
20299 \SpecialChar ~
20300 ; nop 
20301 \newline 
20302 }
20303 \layout Standard
20304
20305 Note that the replace pattern cannot be a blank, but can be a comment line.
20306  Without the 'restart' option only the innermost 'pop' 'push' pair would
20307  be eliminated, i.e.:
20308 \layout Verse
20309
20310
20311 \family typewriter 
20312 pop ar1 
20313 \newline 
20314 pop ar2 
20315 \newline 
20316 push ar2 
20317 \newline 
20318 push ar1
20319 \layout Standard
20320
20321 would result in:
20322 \layout Verse
20323
20324
20325 \family typewriter 
20326 pop ar1 
20327 \newline 
20328 ; nop 
20329 \newline 
20330 push ar1
20331 \layout Standard
20332
20333
20334 \emph on 
20335 with
20336 \emph default 
20337  the restart option the rule will be applied again to the resulting code
20338  and then all the pop-push pairs will be eliminated to yield:
20339 \layout Verse
20340
20341
20342 \family typewriter 
20343 ; nop 
20344 \newline 
20345 ; nop
20346 \layout Standard
20347
20348 A conditional function can be attached to a rule.
20349  Attaching rules are somewhat more involved, let me illustrate this with
20350  an example.
20351 \layout Verse
20352
20353
20354 \family typewriter 
20355 replace { 
20356 \newline 
20357 \SpecialChar ~
20358  \SpecialChar ~
20359  \SpecialChar ~
20360 ljmp %5 
20361 \newline 
20362 %2:
20363 \newline 
20364 } by { 
20365 \newline 
20366 \SpecialChar ~
20367  \SpecialChar ~
20368  \SpecialChar ~
20369 sjmp %5 
20370 \newline 
20371 %2:
20372 \newline 
20373 } if labelInRange
20374 \layout Standard
20375
20376 The optimizer does a look-up of a function name table defined in function
20377  
20378 \emph on 
20379 callFuncByName
20380 \emph default 
20381  in the source file SDCCpeeph.c, with the name 
20382 \emph on 
20383 labelInRange
20384 \emph default 
20385 .
20386  If it finds a corresponding entry the function is called.
20387  Note there can be no parameters specified for these functions, in this
20388  case the use of 
20389 \emph on 
20390 %5
20391 \emph default 
20392  is crucial, since the function 
20393 \emph on 
20394 labelInRange
20395 \emph default 
20396  expects to find the label in that particular variable (the hash table containin
20397 g the variable bindings is passed as a parameter).
20398  If you want to code more such functions, take a close look at the function
20399  labelInRange and the calling mechanism in source file SDCCpeeph.c.
20400  Currently implemented are 
20401 \emph on 
20402 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
20403  24bitMode, portIsDS390, 24bitModeAndPortDS390 
20404 \emph default 
20405 and
20406 \emph on 
20407  notVolatile
20408 \emph default 
20409 .
20410 \layout Standard
20411
20412 I know this whole thing is a little kludgey, but maybe some day we will
20413  have some better means.
20414  If you are looking at this file, you will see the default rules that are
20415  compiled into the compiler, you can add your own rules in the default set
20416  there if you get tired of specifying the -
20417 \begin_inset ERT
20418 status Collapsed
20419
20420 \layout Standard
20421
20422 \backslash 
20423 /
20424 \end_inset 
20425
20426 -peep-file option.
20427 \layout Section
20428
20429 ANSI-Compliance
20430 \begin_inset LatexCommand \index{ANSI-compliance}
20431
20432 \end_inset 
20433
20434
20435 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
20436
20437 \end_inset 
20438
20439
20440 \layout Standard
20441
20442 Deviations from the compliance:
20443 \layout Itemize
20444
20445 functions are not always reentrant
20446 \begin_inset LatexCommand \index{reentrant}
20447
20448 \end_inset 
20449
20450 .
20451 \layout Itemize
20452
20453 structures cannot be assigned values directly, cannot be passed as function
20454  parameters or assigned to each other and cannot be a return value from
20455  a function, e.g.:
20456 \begin_deeper 
20457 \layout Verse
20458
20459
20460 \family typewriter 
20461 struct s { ...
20462  }; 
20463 \newline 
20464 struct s s1, s2; 
20465 \newline 
20466 foo() 
20467 \newline 
20468
20469 \newline 
20470 \SpecialChar ~
20471 \SpecialChar ~
20472 \SpecialChar ~
20473 \SpecialChar ~
20474 ...
20475  
20476 \newline 
20477 \SpecialChar ~
20478 \SpecialChar ~
20479 \SpecialChar ~
20480 \SpecialChar ~
20481 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
20482 \newline 
20483 \SpecialChar ~
20484 \SpecialChar ~
20485 \SpecialChar ~
20486 \SpecialChar ~
20487 ...
20488  
20489 \newline 
20490 }
20491 \newline 
20492 struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
20493  */
20494 \newline 
20495
20496 \newline 
20497 \SpecialChar ~
20498 \SpecialChar ~
20499 \SpecialChar ~
20500 \SpecialChar ~
20501 struct s rets; 
20502 \newline 
20503 \SpecialChar ~
20504 \SpecialChar ~
20505 \SpecialChar ~
20506 \SpecialChar ~
20507 ...
20508  
20509 \newline 
20510 \SpecialChar ~
20511 \SpecialChar ~
20512 \SpecialChar ~
20513 \SpecialChar ~
20514 return rets;/* is invalid in SDCC although allowed in ANSI */ 
20515 \newline 
20516 }
20517 \end_deeper 
20518 \layout Itemize
20519
20520 'long long
20521 \begin_inset LatexCommand \index{long long (not supported)}
20522
20523 \end_inset 
20524
20525 ' (64 bit integers
20526 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
20527
20528 \end_inset 
20529
20530 ) not supported.
20531 \layout Itemize
20532
20533 'double
20534 \begin_inset LatexCommand \index{double (not supported)}
20535
20536 \end_inset 
20537
20538 ' precision floating point 
20539 \begin_inset LatexCommand \index{Floating point support}
20540
20541 \end_inset 
20542
20543 not supported.
20544 \layout Itemize
20545
20546 No support for setjmp
20547 \begin_inset LatexCommand \index{setjmp (not supported)}
20548
20549 \end_inset 
20550
20551  and longjmp
20552 \begin_inset LatexCommand \index{longjmp (not supported)}
20553
20554 \end_inset 
20555
20556  (for now).
20557 \layout Itemize
20558
20559 Old K&R style
20560 \begin_inset LatexCommand \index{K\&R style}
20561
20562 \end_inset 
20563
20564  function declarations are NOT allowed.
20565 \begin_deeper 
20566 \layout Verse
20567
20568
20569 \family typewriter 
20570 foo(i,j) /* this old style of function declarations */ 
20571 \newline 
20572 int i,j; /* are valid in ANSI but not valid in SDCC */ 
20573 \newline 
20574
20575 \newline 
20576 \SpecialChar ~
20577 \SpecialChar ~
20578 \SpecialChar ~
20579 \SpecialChar ~
20580 ...
20581  
20582 \newline 
20583 }
20584 \end_deeper 
20585 \layout Itemize
20586
20587 functions declared as pointers
20588 \begin_inset LatexCommand \index{Pointer (to function)}
20589
20590 \end_inset 
20591
20592
20593 \begin_inset LatexCommand \index{function pointers}
20594
20595 \end_inset 
20596
20597  must be dereferenced during the call.
20598 \begin_deeper 
20599 \layout Verse
20600
20601
20602 \family typewriter 
20603 int (*foo)();
20604 \newline 
20605 ...
20606  
20607 \newline 
20608 /* has to be called like this */ 
20609 \newline 
20610 (*foo)(); /* ANSI standard allows calls to be made like 'foo()' */
20611 \end_deeper 
20612 \layout Section
20613
20614 Cyclomatic Complexity
20615 \begin_inset LatexCommand \index{Cyclomatic complexity}
20616
20617 \end_inset 
20618
20619
20620 \layout Standard
20621
20622 Cyclomatic complexity of a function is defined as the number of independent
20623  paths the program can take during execution of the function.
20624  This is an important number since it defines the number test cases you
20625  have to generate to validate the function.
20626  The accepted industry standard for complexity number is 10, if the cyclomatic
20627  complexity reported by SDCC exceeds 10 you should think about simplification
20628  of the function logic.
20629  Note that the complexity level is not related to the number of lines of
20630  code in a function.
20631  Large functions can have low complexity, and small functions can have large
20632  complexity levels.
20633  
20634 \newline 
20635
20636 \newline 
20637 SDCC uses the following formula to compute the complexity:
20638 \newline 
20639
20640 \layout Standard
20641
20642 complexity = (number of edges in control flow graph) - (number of nodes
20643  in control flow graph) + 2;
20644 \newline 
20645
20646 \newline 
20647 Having said that the industry standard is 10, you should be aware that in
20648  some cases it be may unavoidable to have a complexity level of less than
20649  10.
20650  For example if you have switch statement with more than 10 case labels,
20651  each case label adds one to the complexity level.
20652  The complexity level is by no means an absolute measure of the algorithmic
20653  complexity of the function, it does however provide a good starting point
20654  for which functions you might look at for further optimization.
20655 \layout Section
20656
20657 Retargetting for other Processors
20658 \layout Standard
20659
20660 The issues for retargetting the compiler are far too numerous to be covered
20661  by this document.
20662  What follows is a brief description of each of the seven phases of the
20663  compiler and its MCU dependency.
20664 \layout Itemize
20665
20666 Parsing the source and building the annotated parse tree.
20667  This phase is largely MCU independent (except for the language extensions).
20668  Syntax & semantic checks are also done in this phase, along with some initial
20669  optimizations like back patching labels and the pattern matching optimizations
20670  like bit-rotation etc.
20671 \layout Itemize
20672
20673 The second phase involves generating an intermediate code which can be easy
20674  manipulated during the later phases.
20675  This phase is entirely MCU independent.
20676  The intermediate code generation assumes the target machine has unlimited
20677  number of registers, and designates them with the name iTemp.
20678  The compiler can be made to dump a human readable form of the code generated
20679  by using the -
20680 \begin_inset ERT
20681 status Collapsed
20682
20683 \layout Standard
20684
20685 \backslash 
20686 /
20687 \end_inset 
20688
20689 -dumpraw option.
20690 \layout Itemize
20691
20692 This phase does the bulk of the standard optimizations and is also MCU independe
20693 nt.
20694  This phase can be broken down into several sub-phases:
20695 \newline 
20696
20697 \newline 
20698 Break down intermediate code (iCode) into basic blocks.
20699 \newline 
20700 Do control flow & data flow analysis on the basic blocks.
20701 \newline 
20702 Do local common subexpression elimination, then global subexpression elimination
20703 \newline 
20704 Dead code elimination
20705 \newline 
20706 Loop optimizations
20707 \newline 
20708 If loop optimizations caused any changes then do 'global subexpression eliminati
20709 on' and 'dead code elimination' again.
20710 \layout Itemize
20711
20712 This phase determines the live-ranges; by live range I mean those iTemp
20713  variables defined by the compiler that still survive after all the optimization
20714 s.
20715  Live range analysis
20716 \begin_inset LatexCommand \index{Live range analysis}
20717
20718 \end_inset 
20719
20720  is essential for register allocation, since these computation determines
20721  which of these iTemps will be assigned to registers, and for how long.
20722 \layout Itemize
20723
20724 Phase five is register allocation.
20725  There are two parts to this process.
20726 \newline 
20727
20728 \newline 
20729 The first part I call 'register packing' (for lack of a better term).
20730  In this case several MCU specific expression folding is done to reduce
20731  register pressure.
20732 \newline 
20733
20734 \newline 
20735 The second part is more MCU independent and deals with allocating registers
20736  to the remaining live ranges.
20737  A lot of MCU specific code does creep into this phase because of the limited
20738  number of index registers available in the 8051.
20739 \layout Itemize
20740
20741 The Code generation phase is (unhappily), entirely MCU dependent and very
20742  little (if any at all) of this code can be reused for other MCU.
20743  However the scheme for allocating a homogenized assembler operand for each
20744  iCode operand may be reused.
20745 \layout Itemize
20746
20747 As mentioned in the optimization section the peep-hole optimizer is rule
20748  based system, which can reprogrammed for other MCUs.
20749 \layout Chapter
20750
20751 Compiler internals
20752 \begin_inset LatexCommand \index{Compiler internals}
20753
20754 \end_inset 
20755
20756
20757 \layout Section
20758
20759 The anatomy of the compiler
20760 \begin_inset LatexCommand \label{sub:The-anatomy-of}
20761
20762 \end_inset 
20763
20764
20765 \layout Standard
20766
20767
20768 \shape italic 
20769 This is an excerpt from an article published in Circuit Cellar Magazine
20770  in august 2000.
20771  It's a little outdated (the compiler is much more efficient now and user/develo
20772 per friendly), but pretty well exposes the guts of it all.
20773 \shape default 
20774
20775 \newline 
20776
20777 \newline 
20778 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
20779  It is fairly easy to retarget for other 8-bit MCU.
20780  Here we take a look at some of the internals of the compiler.
20781  
20782 \layout Paragraph*
20783
20784 Parsing
20785 \begin_inset LatexCommand \index{Parsing}
20786
20787 \end_inset 
20788
20789  
20790 \layout Standard
20791
20792 Parsing the input source file and creating an AST (Annotated Syntax Tree
20793 \begin_inset LatexCommand \index{Annotated syntax tree}
20794
20795 \end_inset 
20796
20797 ).
20798  This phase also involves propagating types (annotating each node of the
20799  parse tree with type information) and semantic analysis.
20800  There are some MCU specific parsing rules.
20801  For example the storage classes, the extended storage classes are MCU specific
20802  while there may be a xdata storage class for 8051 there is no such storage
20803  class for z80 or Atmel AVR.
20804  SDCC allows MCU specific storage class extensions, i.e.
20805  xdata will be treated as a storage class specifier when parsing 8051 C
20806  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
20807  C code.
20808 \layout Paragraph*
20809
20810 Generating iCode
20811 \begin_inset LatexCommand \index{iCode}
20812
20813 \end_inset 
20814
20815
20816 \layout Standard
20817
20818 Intermediate code generation.
20819  In this phase the AST is broken down into three-operand form (iCode).
20820  These three operand forms are represented as doubly linked lists.
20821  ICode is the term given to the intermediate form generated by the compiler.
20822  ICode example section shows some examples of iCode generated for some simple
20823  C source functions.
20824 \layout Paragraph*
20825
20826 Optimizations
20827 \begin_inset LatexCommand \index{Optimizations}
20828
20829 \end_inset 
20830
20831 .
20832 \layout Standard
20833
20834 Bulk of the target independent optimizations is performed in this phase.
20835  The optimizations include constant propagation, common sub-expression eliminati
20836 on, loop invariant code movement, strength reduction of loop induction variables
20837  and dead-code elimination.
20838 \layout Paragraph*
20839
20840 Live range analysis
20841 \begin_inset LatexCommand \index{Live range analysis}
20842
20843 \end_inset 
20844
20845
20846 \layout Standard
20847
20848 During intermediate code generation phase, the compiler assumes the target
20849  machine has infinite number of registers and generates a lot of temporary
20850  variables.
20851  The live range computation determines the lifetime of each of these compiler-ge
20852 nerated temporaries.
20853  A picture speaks a thousand words.
20854  ICode example sections show the live range annotations for each of the
20855  operand.
20856  It is important to note here, each iCode is assigned a number in the order
20857  of its execution in the function.
20858  The live ranges are computed in terms of these numbers.
20859  The from number is the number of the iCode which first defines the operand
20860  and the to number signifies the iCode which uses this operand last.
20861 \layout Paragraph*
20862
20863 Register Allocation
20864 \begin_inset LatexCommand \index{Register allocation}
20865
20866 \end_inset 
20867
20868
20869 \layout Standard
20870
20871 The register allocation determines the type and number of registers needed
20872  by each operand.
20873  In most MCUs only a few registers can be used for indirect addressing.
20874  In case of 8051 for example the registers R0 & R1 can be used to indirectly
20875  address the internal ram and DPTR to indirectly address the external ram.
20876  The compiler will try to allocate the appropriate register to pointer variables
20877  if it can.
20878  ICode example section shows the operands annotated with the registers assigned
20879  to them.
20880  The compiler will try to keep operands in registers as much as possible;
20881  there are several schemes the compiler uses to do achieve this.
20882  When the compiler runs out of registers the compiler will check to see
20883  if there are any live operands which is not used or defined in the current
20884  basic block being processed, if there are any found then it will push that
20885  operand and use the registers in this block, the operand will then be popped
20886  at the end of the basic block.
20887  
20888 \layout Standard
20889
20890 There are other MCU specific considerations in this phase.
20891  Some MCUs have an accumulator; very short-lived operands could be assigned
20892  to the accumulator instead of a general-purpose register.
20893 \layout Paragraph*
20894
20895 Code generation
20896 \layout Standard
20897
20898 Figure II gives a table of iCode operations supported by the compiler.
20899  The code generation involves translating these operations into corresponding
20900  assembly code for the processor.
20901  This sounds overly simple but that is the essence of code generation.
20902  Some of the iCode operations are generated on a MCU specific manner for
20903  example, the z80 port does not use registers to pass parameters so the
20904  SEND and RECV iCode operations will not be generated, and it also does
20905  not support JUMPTABLES.
20906  
20907 \newline 
20908
20909 \series bold 
20910 \shape italic 
20911 \color red
20912 <Where is Figure II ?>
20913 \layout Paragraph*
20914
20915 ICode Example
20916 \begin_inset LatexCommand \index{iCode}
20917
20918 \end_inset 
20919
20920
20921 \layout Standard
20922
20923 This section shows some details of iCode.
20924  The example C code does not do anything useful; it is used as an example
20925  to illustrate the intermediate code generated by the compiler.
20926 \layout Verse
20927
20928
20929 \family typewriter 
20930 1.\SpecialChar ~
20931 xdata int * p;
20932 \newline 
20933 2.\SpecialChar ~
20934 int gint;
20935 \newline 
20936 3.\SpecialChar ~
20937 /* This function does nothing useful.
20938  It is used
20939 \newline 
20940 4.\SpecialChar ~
20941 \SpecialChar ~
20942 \SpecialChar ~
20943 \SpecialChar ~
20944 for the purpose of explaining iCode */
20945 \newline 
20946 5.\SpecialChar ~
20947 short function (data int *x)
20948 \newline 
20949 6.\SpecialChar ~
20950 {
20951 \newline 
20952 7.\SpecialChar ~
20953 \SpecialChar ~
20954 \SpecialChar ~
20955 short i=10; \SpecialChar ~
20956 \SpecialChar ~
20957 /* dead initialization eliminated */
20958 \newline 
20959 8.\SpecialChar ~
20960 \SpecialChar ~
20961 \SpecialChar ~
20962 short sum=10; /* dead initialization eliminated */
20963 \newline 
20964 9.\SpecialChar ~
20965 \SpecialChar ~
20966 \SpecialChar ~
20967 short mul;
20968 \newline 
20969 10.\SpecialChar ~
20970 \SpecialChar ~
20971 int j ;
20972 \newline 
20973 11.\SpecialChar ~
20974 \SpecialChar ~
20975 while (*x) *x++ = *p++; 
20976 \newline 
20977 12.\SpecialChar ~
20978 \SpecialChar ~
20979 \SpecialChar ~
20980 \SpecialChar ~
20981 sum = 0 ; 
20982 \newline 
20983 13.\SpecialChar ~
20984 \SpecialChar ~
20985 mul = 0;
20986 \newline 
20987 14.\SpecialChar ~
20988 \SpecialChar ~
20989 /* compiler detects i,j to be induction variables */
20990 \newline 
20991 15.\SpecialChar ~
20992 \SpecialChar ~
20993 for (i = 0, j = 10 ; i < 10 ; i++, j
20994 \family default 
20995 -
20996 \begin_inset ERT
20997 status Collapsed
20998
20999 \layout Standard
21000
21001 \backslash 
21002 /
21003 \end_inset 
21004
21005 -
21006 \family typewriter 
21007 ) {
21008 \newline 
21009 16.\SpecialChar ~
21010 \SpecialChar ~
21011 \SpecialChar ~
21012 \SpecialChar ~
21013 sum += i;
21014 \newline 
21015 17.\SpecialChar ~
21016 \SpecialChar ~
21017 \SpecialChar ~
21018 \SpecialChar ~
21019 mul += i * 3; \SpecialChar ~
21020 \SpecialChar ~
21021 /* this multiplication remains */
21022 \newline 
21023 18.\SpecialChar ~
21024 \SpecialChar ~
21025 \SpecialChar ~
21026 \SpecialChar ~
21027 gint += j * 3;\SpecialChar ~
21028 \SpecialChar ~
21029 /* this multiplication changed to addition */
21030 \newline 
21031 19.\SpecialChar ~
21032 \SpecialChar ~
21033 }
21034 \newline 
21035 20.\SpecialChar ~
21036 \SpecialChar ~
21037 return sum+mul;
21038 \newline 
21039 21.\SpecialChar ~
21040 }
21041 \layout Standard
21042
21043 In addition to the operands each iCode contains information about the filename
21044  and line it corresponds to in the source file.
21045  The first field in the listing should be interpreted as follows:
21046 \newline 
21047
21048 \shape italic 
21049 \size footnotesize 
21050 Filename(linenumber: iCode Execution sequence number : ICode hash table
21051  key : loop depth of the iCode).
21052 \shape default 
21053 \size default 
21054
21055 \newline 
21056 Then follows the human readable form of the ICode operation.
21057  Each operand of this triplet form can be of three basic types a) compiler
21058  generated temporary b) user defined variable c) a constant value.
21059  Note that local variables and parameters are replaced by compiler generated
21060  temporaries.
21061  Live ranges
21062 \begin_inset LatexCommand \index{Live range analysis}
21063
21064 \end_inset 
21065
21066  are computed only for temporaries (i.e.
21067  live ranges are not computed for global variables).
21068  Registers
21069 \begin_inset LatexCommand \index{Register allocation}
21070
21071 \end_inset 
21072
21073  are allocated for temporaries only.
21074  Operands are formatted in the following manner:
21075 \newline 
21076
21077 \shape italic 
21078 \size footnotesize 
21079 Operand Name [lr live-from : live-to ] { type information } [ registers
21080  allocated ].
21081 \shape default 
21082 \size default 
21083
21084 \newline 
21085 As mentioned earlier the live ranges are computed in terms of the execution
21086  sequence number of the iCodes, for example 
21087 \newline 
21088 the iTemp0 is live from (i.e.
21089  first defined in iCode with execution sequence number 3, and is last used
21090  in the iCode with sequence number 5).
21091  For induction variables such as iTemp21 the live range computation extends
21092  the lifetime from the start to the end of the loop.
21093 \newline 
21094 The register allocator used the live range information to allocate registers,
21095  the same registers may be used for different temporaries if their live
21096  ranges do not overlap, for example r0 is allocated to both iTemp6 and to
21097  iTemp17 since their live ranges do not overlap.
21098  In addition the allocator also takes into consideration the type and usage
21099  of a temporary, for example itemp6 is a pointer to near space and is used
21100  as to fetch data from (i.e.
21101  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
21102  Some short lived temporaries are allocated to special registers which have
21103  meaning to the code generator e.g.
21104  iTemp13 is allocated to a pseudo register CC which tells the back end that
21105  the temporary is used only for a conditional jump the code generation makes
21106  use of this information to optimize a compare and jump ICode.
21107 \newline 
21108 There are several loop optimizations
21109 \begin_inset LatexCommand \index{Loop optimization}
21110
21111 \end_inset 
21112
21113  performed by the compiler.
21114  It can detect induction variables iTemp21(i) and iTemp23(j).
21115  Also note the compiler does selective strength reduction
21116 \begin_inset LatexCommand \index{Strength reduction}
21117
21118 \end_inset 
21119
21120 , i.e.
21121  the multiplication of an induction variable in line 18 (gint = j * 3) is
21122  changed to addition, a new temporary iTemp17 is allocated and assigned
21123  a initial value, a constant 3 is then added for each iteration of the loop.
21124  The compiler does not change the multiplication
21125 \begin_inset LatexCommand \index{Multiplication}
21126
21127 \end_inset 
21128
21129  in line 17 however since the processor does support an 8 * 8 bit multiplication.
21130 \newline 
21131 Note the dead code elimination
21132 \begin_inset LatexCommand \index{Dead-code elimination}
21133
21134 \end_inset 
21135
21136  optimization eliminated the dead assignments in line 7 & 8 to I and sum
21137  respectively.
21138 \newline 
21139
21140 \layout Standard
21141
21142
21143 \size footnotesize 
21144 Sample.c (5:1:0:0) _entry($9) :
21145 \layout Standard
21146
21147
21148 \size footnotesize 
21149 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
21150 \layout Standard
21151
21152
21153 \size footnotesize 
21154 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
21155 \layout Standard
21156
21157
21158 \size footnotesize 
21159 Sample.c(11:4:53:0) preHeaderLbl0($11) :
21160 \layout Standard
21161
21162
21163 \size footnotesize 
21164 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
21165  * int}[r2]
21166 \layout Standard
21167
21168
21169 \size footnotesize 
21170 Sample.c(11:6:5:1) _whilecontinue_0($1) :
21171 \layout Standard
21172
21173
21174 \size footnotesize 
21175 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
21176  int}[r0]]
21177 \layout Standard
21178
21179
21180 \size footnotesize 
21181 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
21182 \layout Standard
21183
21184
21185 \size footnotesize 
21186 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
21187  * int}
21188 \layout Standard
21189
21190
21191 \size footnotesize 
21192 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
21193  {short}
21194 \layout Standard
21195
21196
21197 \size footnotesize 
21198 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
21199  * int}[DPTR]]
21200 \layout Standard
21201
21202
21203 \size footnotesize 
21204 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
21205 }[r2 r3]
21206 \layout Standard
21207
21208
21209 \size footnotesize 
21210 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
21211  * int}[r0] + 0x2 {short}
21212 \layout Standard
21213
21214
21215 \size footnotesize 
21216 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
21217 \layout Standard
21218
21219
21220 \size footnotesize 
21221 Sample.c(11:17:21:0)_whilebreak_0($3) :
21222 \layout Standard
21223
21224
21225 \size footnotesize 
21226 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
21227 \layout Standard
21228
21229
21230 \size footnotesize 
21231 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
21232 \layout Standard
21233
21234
21235 \size footnotesize 
21236 Sample.c(15:20:54:0)preHeaderLbl1($13) :
21237 \layout Standard
21238
21239
21240 \size footnotesize 
21241 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
21242 \layout Standard
21243
21244
21245 \size footnotesize 
21246 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
21247 \layout Standard
21248
21249
21250 \size footnotesize 
21251 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
21252 \layout Standard
21253
21254
21255 \size footnotesize 
21256 Sample.c(15:24:26:1)_forcond_0($4) :
21257 \layout Standard
21258
21259
21260 \size footnotesize 
21261 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
21262  < 0xa {short}
21263 \layout Standard
21264
21265
21266 \size footnotesize 
21267 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
21268 \layout Standard
21269
21270
21271 \size footnotesize 
21272 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
21273  + ITemp21 [lr21:38]{short}[r4]
21274 \layout Standard
21275
21276
21277 \size footnotesize 
21278 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
21279  * 0x3 {short}
21280 \layout Standard
21281
21282
21283 \size footnotesize 
21284 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
21285  + iTemp15 [lr29:30]{short}[r1]
21286 \layout Standard
21287
21288
21289 \size footnotesize 
21290 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
21291  r0]- 0x3 {short}
21292 \layout Standard
21293
21294
21295 \size footnotesize 
21296 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
21297 int}[r7 r0]
21298 \layout Standard
21299
21300
21301 \size footnotesize 
21302 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
21303  + 0x1 {short}
21304 \layout Standard
21305
21306
21307 \size footnotesize 
21308 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
21309  r6]- 0x1 {short}
21310 \layout Standard
21311
21312
21313 \size footnotesize 
21314 Sample.c(19:38:47:1) goto _forcond_0($4)
21315 \layout Standard
21316
21317
21318 \size footnotesize 
21319 Sample.c(19:39:48:0)_forbreak_0($7) :
21320 \layout Standard
21321
21322
21323 \size footnotesize 
21324 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
21325  + ITemp11 [lr19:40]{short}[r3]
21326 \layout Standard
21327
21328
21329 \size footnotesize 
21330 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
21331 \layout Standard
21332
21333
21334 \size footnotesize 
21335 Sample.c(20:42:51:0)_return($8) :
21336 \layout Standard
21337
21338
21339 \size footnotesize 
21340 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
21341 \size default 
21342
21343 \newline 
21344
21345 \newline 
21346 Finally the code generated for this function:
21347 \newline 
21348
21349 \layout Standard
21350
21351
21352 \size footnotesize 
21353 .area DSEG (DATA)
21354 \layout Standard
21355
21356
21357 \size footnotesize 
21358 _p::
21359 \layout Standard
21360
21361
21362 \size footnotesize 
21363 \SpecialChar ~
21364 \SpecialChar ~
21365 .ds 2
21366 \layout Standard
21367
21368
21369 \size footnotesize 
21370 _gint::
21371 \layout Standard
21372
21373
21374 \size footnotesize 
21375 \SpecialChar ~
21376 \SpecialChar ~
21377 .ds 2
21378 \layout Standard
21379
21380
21381 \size footnotesize 
21382 ; sample.c 5
21383 \layout Standard
21384
21385
21386 \size footnotesize 
21387 ; ----------------------------------------------
21388 \layout Standard
21389
21390
21391 \size footnotesize 
21392 ; function function
21393 \layout Standard
21394
21395
21396 \size footnotesize 
21397 ; ----------------------------------------------
21398 \layout Standard
21399
21400
21401 \size footnotesize 
21402 _function:
21403 \layout Standard
21404
21405
21406 \size footnotesize 
21407 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
21408 \layout Standard
21409
21410
21411 \size footnotesize 
21412 \SpecialChar ~
21413 \SpecialChar ~
21414 mov r2,dpl
21415 \layout Standard
21416
21417
21418 \size footnotesize 
21419 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
21420 \layout Standard
21421
21422
21423 \size footnotesize 
21424 \SpecialChar ~
21425 \SpecialChar ~
21426 mov ar0,r2
21427 \layout Standard
21428
21429
21430 \size footnotesize 
21431 ;_whilecontinue_0($1) :
21432 \layout Standard
21433
21434
21435 \size footnotesize 
21436 00101$:
21437 \layout Standard
21438
21439
21440 \size footnotesize 
21441 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
21442 \layout Standard
21443
21444
21445 \size footnotesize 
21446 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
21447 \layout Standard
21448
21449
21450 \size footnotesize 
21451 \SpecialChar ~
21452 \SpecialChar ~
21453 mov ar2,@r0
21454 \layout Standard
21455
21456
21457 \size footnotesize 
21458 \SpecialChar ~
21459 \SpecialChar ~
21460 inc r0
21461 \layout Standard
21462
21463
21464 \size footnotesize 
21465 \SpecialChar ~
21466 \SpecialChar ~
21467 mov ar3,@r0
21468 \layout Standard
21469
21470
21471 \size footnotesize 
21472 \SpecialChar ~
21473 \SpecialChar ~
21474 dec r0
21475 \layout Standard
21476
21477
21478 \size footnotesize 
21479 \SpecialChar ~
21480 \SpecialChar ~
21481 mov a,r2
21482 \layout Standard
21483
21484
21485 \size footnotesize 
21486 \SpecialChar ~
21487 \SpecialChar ~
21488 orl a,r3
21489 \layout Standard
21490
21491
21492 \size footnotesize 
21493 \SpecialChar ~
21494 \SpecialChar ~
21495 jz 00103$
21496 \layout Standard
21497
21498
21499 \size footnotesize 
21500 00114$:
21501 \layout Standard
21502
21503
21504 \size footnotesize 
21505 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
21506 \layout Standard
21507
21508
21509 \size footnotesize 
21510 \SpecialChar ~
21511 \SpecialChar ~
21512 mov dpl,_p
21513 \layout Standard
21514
21515
21516 \size footnotesize 
21517 \SpecialChar ~
21518 \SpecialChar ~
21519 mov dph,(_p + 1)
21520 \layout Standard
21521
21522
21523 \size footnotesize 
21524 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
21525 \layout Standard
21526
21527
21528 \size footnotesize 
21529 \SpecialChar ~
21530 \SpecialChar ~
21531 mov a,#0x02
21532 \layout Standard
21533
21534
21535 \size footnotesize 
21536 \SpecialChar ~
21537 \SpecialChar ~
21538 add a,_p
21539 \layout Standard
21540
21541
21542 \size footnotesize 
21543 \SpecialChar ~
21544 \SpecialChar ~
21545 mov _p,a
21546 \layout Standard
21547
21548
21549 \size footnotesize 
21550 \SpecialChar ~
21551 \SpecialChar ~
21552 clr a
21553 \layout Standard
21554
21555
21556 \size footnotesize 
21557 \SpecialChar ~
21558 \SpecialChar ~
21559 addc a,(_p + 1)
21560 \layout Standard
21561
21562
21563 \size footnotesize 
21564 \SpecialChar ~
21565 \SpecialChar ~
21566 mov (_p + 1),a
21567 \layout Standard
21568
21569
21570 \size footnotesize 
21571 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
21572 \layout Standard
21573
21574
21575 \size footnotesize 
21576 \SpecialChar ~
21577 \SpecialChar ~
21578 movx a,@dptr
21579 \layout Standard
21580
21581
21582 \size footnotesize 
21583 \SpecialChar ~
21584 \SpecialChar ~
21585 mov r2,a
21586 \layout Standard
21587
21588
21589 \size footnotesize 
21590 \SpecialChar ~
21591 \SpecialChar ~
21592 inc dptr
21593 \layout Standard
21594
21595
21596 \size footnotesize 
21597 \SpecialChar ~
21598 \SpecialChar ~
21599 movx a,@dptr
21600 \layout Standard
21601
21602
21603 \size footnotesize 
21604 \SpecialChar ~
21605 \SpecialChar ~
21606 mov r3,a
21607 \layout Standard
21608
21609
21610 \size footnotesize 
21611 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
21612 \layout Standard
21613
21614
21615 \size footnotesize 
21616 \SpecialChar ~
21617 \SpecialChar ~
21618 mov @r0,ar2
21619 \layout Standard
21620
21621
21622 \size footnotesize 
21623 \SpecialChar ~
21624 \SpecialChar ~
21625 inc r0
21626 \layout Standard
21627
21628
21629 \size footnotesize 
21630 \SpecialChar ~
21631 \SpecialChar ~
21632 mov @r0,ar3
21633 \layout Standard
21634
21635
21636 \size footnotesize 
21637 ; iTemp6 [lr5:16]{_near * int}[r0] = 
21638 \layout Standard
21639
21640
21641 \size footnotesize 
21642 ; iTemp6 [lr5:16]{_near * int}[r0] + 
21643 \layout Standard
21644
21645
21646 \size footnotesize 
21647 ; 0x2 {short}
21648 \layout Standard
21649
21650
21651 \size footnotesize 
21652 \SpecialChar ~
21653 \SpecialChar ~
21654 inc r0
21655 \layout Standard
21656
21657
21658 \size footnotesize 
21659 ; goto _whilecontinue_0($1)
21660 \layout Standard
21661
21662
21663 \size footnotesize 
21664 \SpecialChar ~
21665 \SpecialChar ~
21666 sjmp 00101$
21667 \layout Standard
21668
21669
21670 \size footnotesize 
21671 ; _whilebreak_0($3) :
21672 \layout Standard
21673
21674
21675 \size footnotesize 
21676 00103$:
21677 \layout Standard
21678
21679
21680 \size footnotesize 
21681 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
21682 \layout Standard
21683
21684
21685 \size footnotesize 
21686 \SpecialChar ~
21687 \SpecialChar ~
21688 mov r2,#0x00
21689 \layout Standard
21690
21691
21692 \size footnotesize 
21693 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
21694 \layout Standard
21695
21696
21697 \size footnotesize 
21698 \SpecialChar ~
21699 \SpecialChar ~
21700 mov r3,#0x00
21701 \layout Standard
21702
21703
21704 \size footnotesize 
21705 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
21706 \layout Standard
21707
21708
21709 \size footnotesize 
21710 \SpecialChar ~
21711 \SpecialChar ~
21712 mov r4,#0x00
21713 \layout Standard
21714
21715
21716 \size footnotesize 
21717 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
21718 \layout Standard
21719
21720
21721 \size footnotesize 
21722 \SpecialChar ~
21723 \SpecialChar ~
21724 mov r5,#0x0A
21725 \layout Standard
21726
21727
21728 \size footnotesize 
21729 \SpecialChar ~
21730 \SpecialChar ~
21731 mov r6,#0x00
21732 \layout Standard
21733
21734
21735 \size footnotesize 
21736 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
21737 \layout Standard
21738
21739
21740 \size footnotesize 
21741 \SpecialChar ~
21742 \SpecialChar ~
21743 mov r7,#0x1E
21744 \layout Standard
21745
21746
21747 \size footnotesize 
21748 \SpecialChar ~
21749 \SpecialChar ~
21750 mov r0,#0x00
21751 \layout Standard
21752
21753
21754 \size footnotesize 
21755 ; _forcond_0($4) :
21756 \layout Standard
21757
21758
21759 \size footnotesize 
21760 00104$:
21761 \layout Standard
21762
21763
21764 \size footnotesize 
21765 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
21766 \layout Standard
21767
21768
21769 \size footnotesize 
21770 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
21771 \layout Standard
21772
21773
21774 \size footnotesize 
21775 \SpecialChar ~
21776 \SpecialChar ~
21777 clr c
21778 \layout Standard
21779
21780
21781 \size footnotesize 
21782 \SpecialChar ~
21783 \SpecialChar ~
21784 mov a,r4
21785 \layout Standard
21786
21787
21788 \size footnotesize 
21789 \SpecialChar ~
21790 \SpecialChar ~
21791 xrl a,#0x80
21792 \layout Standard
21793
21794
21795 \size footnotesize 
21796 \SpecialChar ~
21797 \SpecialChar ~
21798 subb a,#0x8a
21799 \layout Standard
21800
21801
21802 \size footnotesize 
21803 \SpecialChar ~
21804 \SpecialChar ~
21805 jnc 00107$
21806 \layout Standard
21807
21808
21809 \size footnotesize 
21810 00115$:
21811 \layout Standard
21812
21813
21814 \size footnotesize 
21815 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
21816 \layout Standard
21817
21818
21819 \size footnotesize 
21820 ; iTemp21 [lr21:38]{short}[r4]
21821 \layout Standard
21822
21823
21824 \size footnotesize 
21825 \SpecialChar ~
21826 \SpecialChar ~
21827 mov a,r4
21828 \layout Standard
21829
21830
21831 \size footnotesize 
21832 \SpecialChar ~
21833 \SpecialChar ~
21834 add a,r2
21835 \layout Standard
21836
21837
21838 \size footnotesize 
21839 \SpecialChar ~
21840 \SpecialChar ~
21841 mov r2,a
21842 \layout Standard
21843
21844
21845 \size footnotesize 
21846 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
21847 \layout Standard
21848
21849
21850 \size footnotesize 
21851 \SpecialChar ~
21852 \SpecialChar ~
21853 mov b,#0x03
21854 \layout Standard
21855
21856
21857 \size footnotesize 
21858 \SpecialChar ~
21859 \SpecialChar ~
21860 mov a,r4
21861 \layout Standard
21862
21863
21864 \size footnotesize 
21865 \SpecialChar ~
21866 \SpecialChar ~
21867 mul ab
21868 \layout Standard
21869
21870
21871 \size footnotesize 
21872 \SpecialChar ~
21873 \SpecialChar ~
21874 mov r1,a
21875 \layout Standard
21876
21877
21878 \size footnotesize 
21879 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
21880 \layout Standard
21881
21882
21883 \size footnotesize 
21884 ; iTemp15 [lr29:30]{short}[r1]
21885 \layout Standard
21886
21887
21888 \size footnotesize 
21889 \SpecialChar ~
21890 \SpecialChar ~
21891 add a,r3
21892 \layout Standard
21893
21894
21895 \size footnotesize 
21896 \SpecialChar ~
21897 \SpecialChar ~
21898 mov r3,a
21899 \layout Standard
21900
21901
21902 \size footnotesize 
21903 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
21904 \layout Standard
21905
21906
21907 \size footnotesize 
21908 \SpecialChar ~
21909 \SpecialChar ~
21910 mov a,r7
21911 \layout Standard
21912
21913
21914 \size footnotesize 
21915 \SpecialChar ~
21916 \SpecialChar ~
21917 add a,#0xfd
21918 \layout Standard
21919
21920
21921 \size footnotesize 
21922 \SpecialChar ~
21923 \SpecialChar ~
21924 mov r7,a
21925 \layout Standard
21926
21927
21928 \size footnotesize 
21929 \SpecialChar ~
21930 \SpecialChar ~
21931 mov a,r0
21932 \layout Standard
21933
21934
21935 \size footnotesize 
21936 \SpecialChar ~
21937 \SpecialChar ~
21938 addc a,#0xff
21939 \layout Standard
21940
21941
21942 \size footnotesize 
21943 \SpecialChar ~
21944 \SpecialChar ~
21945 mov r0,a
21946 \layout Standard
21947
21948
21949 \size footnotesize 
21950 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
21951 \layout Standard
21952
21953
21954 \size footnotesize 
21955 \SpecialChar ~
21956 \SpecialChar ~
21957 mov a,r7
21958 \layout Standard
21959
21960
21961 \size footnotesize 
21962 \SpecialChar ~
21963 \SpecialChar ~
21964 add a,_gint
21965 \layout Standard
21966
21967
21968 \size footnotesize 
21969 \SpecialChar ~
21970 \SpecialChar ~
21971 mov _gint,a
21972 \layout Standard
21973
21974
21975 \size footnotesize 
21976 \SpecialChar ~
21977 \SpecialChar ~
21978 mov a,r0
21979 \layout Standard
21980
21981
21982 \size footnotesize 
21983 \SpecialChar ~
21984 \SpecialChar ~
21985 addc a,(_gint + 1)
21986 \layout Standard
21987
21988
21989 \size footnotesize 
21990 \SpecialChar ~
21991 \SpecialChar ~
21992 mov (_gint + 1),a
21993 \layout Standard
21994
21995
21996 \size footnotesize 
21997 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
21998 \layout Standard
21999
22000
22001 \size footnotesize 
22002 \SpecialChar ~
22003 \SpecialChar ~
22004 inc r4
22005 \layout Standard
22006
22007
22008 \size footnotesize 
22009 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
22010 \layout Standard
22011
22012
22013 \size footnotesize 
22014 \SpecialChar ~
22015 \SpecialChar ~
22016 dec r5
22017 \layout Standard
22018
22019
22020 \size footnotesize 
22021 \SpecialChar ~
22022 \SpecialChar ~
22023 cjne r5,#0xff,00104$
22024 \layout Standard
22025
22026
22027 \size footnotesize 
22028 \SpecialChar ~
22029 \SpecialChar ~
22030 dec r6
22031 \layout Standard
22032
22033
22034 \size footnotesize 
22035 ; goto _forcond_0($4)
22036 \layout Standard
22037
22038
22039 \size footnotesize 
22040 \SpecialChar ~
22041 \SpecialChar ~
22042 sjmp 00104$
22043 \layout Standard
22044
22045
22046 \size footnotesize 
22047 ; _forbreak_0($7) :
22048 \layout Standard
22049
22050
22051 \size footnotesize 
22052 00107$:
22053 \layout Standard
22054
22055
22056 \size footnotesize 
22057 ; ret iTemp24 [lr40:41]{short}
22058 \layout Standard
22059
22060
22061 \size footnotesize 
22062 \SpecialChar ~
22063 \SpecialChar ~
22064 mov a,r3
22065 \layout Standard
22066
22067
22068 \size footnotesize 
22069 \SpecialChar ~
22070 \SpecialChar ~
22071 add a,r2
22072 \layout Standard
22073
22074
22075 \size footnotesize 
22076 \SpecialChar ~
22077 \SpecialChar ~
22078 mov dpl,a
22079 \layout Standard
22080
22081
22082 \size footnotesize 
22083 ; _return($8) :
22084 \layout Standard
22085
22086
22087 \size footnotesize 
22088 00108$:
22089 \layout Standard
22090
22091
22092 \size footnotesize 
22093 \SpecialChar ~
22094 \SpecialChar ~
22095 ret
22096 \newline 
22097
22098 \layout Section
22099
22100 A few words about basic block successors, predecessors and dominators
22101 \layout Standard
22102
22103 Successors are basic blocks
22104 \begin_inset LatexCommand \index{Basic blocks}
22105
22106 \end_inset 
22107
22108  that might execute after this basic block.
22109 \newline 
22110 Predecessors are basic blocks that might execute before reaching this basic
22111  block.
22112 \newline 
22113 Dominators are basic blocks that WILL execute before reaching this basic
22114  block.
22115 \newline 
22116
22117 \layout Standard
22118
22119 [basic block 1]
22120 \layout Standard
22121
22122 if (something)
22123 \layout Standard
22124
22125 \SpecialChar ~
22126 \SpecialChar ~
22127 \SpecialChar ~
22128 \SpecialChar ~
22129 [basic block 2]
22130 \layout Standard
22131
22132 else
22133 \layout Standard
22134
22135 \SpecialChar ~
22136 \SpecialChar ~
22137 \SpecialChar ~
22138 \SpecialChar ~
22139 [basic block 3]
22140 \layout Standard
22141
22142 [basic block 4]
22143 \newline 
22144
22145 \layout Standard
22146
22147 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
22148 \layout Standard
22149
22150 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
22151 \layout Standard
22152
22153 c) domVect of [BB4] = BB1 ...
22154  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
22155  was executed.
22156 \layout Chapter
22157
22158 Acknowledgments
22159 \layout Standard
22160
22161
22162 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
22163
22164 \end_inset 
22165
22166
22167 \newline 
22168
22169 \newline 
22170
22171 \emph on 
22172 Thanks to all the other volunteer developers who have helped with coding,
22173  testing, web-page creation, distribution sets, etc.
22174  You know who you are :-)
22175 \emph default 
22176
22177 \newline 
22178
22179 \layout Standard
22180
22181 This document was initially written by Sandeep Dutta
22182 \layout Standard
22183
22184 All product names mentioned herein may be trademarks
22185 \begin_inset LatexCommand \index{Trademarks}
22186
22187 \end_inset 
22188
22189  of their respective companies.
22190  
22191 \layout Section*
22192
22193 Alphabetical index
22194 \layout Standard
22195
22196 To avoid confusion, the installation and building options for SDCC itself
22197  (chapter 2) are not part of the index.
22198 \layout Standard
22199
22200
22201 \begin_inset LatexCommand \printindex{}
22202
22203 \end_inset 
22204
22205
22206 \the_end