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