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