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