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