be855b59c46443a6f53664772cfc3e711a21c40a
[fw/sdcc] / doc / sdccman.lyx
1 #LyX 1.3 created this file. For more info see http://www.lyx.org/
2 \lyxformat 221
3 \textclass book
4 \begin_preamble
5 \usepackage[
6   pdftitle={SDCC Compiler User Guide},
7   pdfauthor={SDCC development team},
8   pdfsubject={installation, user manual},
9   pdfkeywords={8032, 8051, ansi, c, compiler, CPU, DS390, 
10                embedded, GPL, HC08, manual, mcs51, PIC, Z80},
11   colorlinks=true,
12   linkcolor=blue] {hyperref}
13 %
14 \sloppy
15 \tolerance=500          
16 \emergencystretch=30pt 
17 %
18 \date{}
19 \end_preamble
20 \language english
21 \inputencoding default
22 \fontscheme pslatex
23 \graphics default
24 \paperfontsize default
25 \spacing single 
26 \papersize letterpaper
27 \paperpackage a4
28 \use_geometry 1
29 \use_amsmath 0
30 \use_natbib 0
31 \use_numerical_citations 0
32 \paperorientation portrait
33 \leftmargin 30mm
34 \topmargin 20mm
35 \rightmargin 25mm
36 \bottommargin 20mm
37 \secnumdepth 3
38 \tocdepth 3
39 \paragraph_separation indent
40 \defskip medskip
41 \quotes_language swedish
42 \quotes_times 2
43 \papercolumns 1
44 \papersides 1
45 \paperpagestyle fancy
46
47 \layout Comment
48
49 Please note: double dashed longoptions (e.g.
50  --version) are written this way: -
51 \begin_inset ERT
52 status Collapsed
53
54 \layout Standard
55
56 \backslash 
57 /
58 \end_inset 
59
60 -
61 \layout Comment
62
63 Two resp.
64  three consecutive dashes simply result in a long resp.
65  extra long dash.
66 \layout Comment
67
68 Architecture specific stuff (like memory models, code examples) should maybe
69  later go
70 \layout Comment
71
72 into seperate sections/chapters/appendices (it is hard to document PIC or
73  Z80 in 
74 \layout Comment
75
76 a 8051 centered document) - for now simply add.
77 \layout Title
78
79 SDCC Compiler User Guide
80 \layout Date
81
82
83 \size normal 
84 SDCC 2.4.0
85 \size footnotesize 
86
87 \newline 
88 $Date$ 
89 \newline 
90 $Revision$
91 \layout Comment
92
93 The above strings enclosed in $ are automatically updated by cvs
94 \layout Standard
95
96
97 \begin_inset LatexCommand \tableofcontents{}
98
99 \end_inset 
100
101
102 \layout Chapter
103
104 Introduction
105 \layout Section
106
107 About SDCC
108 \layout Standard
109
110
111 \series bold 
112 SDCC
113 \series default 
114  (
115 \emph on 
116 S
117 \emph default 
118 mall 
119 \emph on 
120 D
121 \emph default 
122 evice 
123 \emph on 
124 C
125 \emph default 
126  
127 \emph on 
128 C
129 \emph default 
130 ompiler) is a Freeware, retargettable, optimizing ANSI-C compiler by 
131 \series bold 
132 Sandeep Dutta
133 \series default 
134  designed for 8 bit Microprocessors.
135  The current version targets Intel MCS51 based Microprocessors (8031, 8032,
136  8051, 8052
137 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
138
139 \end_inset 
140
141 , etc.), Dallas DS80C390 variants, Motorola HC08 and Zilog Z80 based MCUs.
142  It can be retargetted for other microprocessors, support for Microchip
143  PIC, Atmel AVR is under development.
144  The entire source code for the compiler is distributed under GPL.
145  SDCC uses ASXXXX & ASLINK, a Freeware, retargettable assembler & linker.
146  SDCC has extensive language extensions suitable for utilizing various microcont
147 rollers and underlying hardware effectively.
148  
149 \newline 
150
151 \newline 
152 In addition to the MCU specific optimizations SDCC also does a host of standard
153  optimizations like:
154 \layout Itemize
155
156 global sub expression elimination, 
157 \layout Itemize
158
159 loop optimizations (loop invariant, strength reduction of induction variables
160  and loop reversing), 
161 \layout Itemize
162
163 constant folding & propagation, 
164 \layout Itemize
165
166 copy propagation, 
167 \layout Itemize
168
169 dead code elimination 
170 \layout Itemize
171
172 jump tables for 
173 \emph on 
174 switch
175 \emph default 
176  statements.
177 \layout Standard
178
179 For the back-end SDCC uses a global register allocation scheme which should
180  be well suited for other 8 bit MCUs.
181  
182 \newline 
183
184 \newline 
185 The peep hole optimizer uses a rule based substitution mechanism which is
186  MCU independent.
187  
188 \newline 
189
190 \newline 
191 Supported data-types are:
192 \layout Itemize
193
194 char (8 bits, 1 byte), 
195 \layout Itemize
196
197 short and int (16 bits, 2 bytes), 
198 \layout Itemize
199
200 long (32 bit, 4 bytes)
201 \layout Itemize
202
203 float (4 byte IEEE).
204  
205 \layout Standard
206
207 The compiler also allows 
208 \emph on 
209 inline assembler code
210 \emph default 
211  to be embedded anywhere in a function.
212  In addition, routines developed in assembly can also be called.
213 \newline 
214
215 \newline 
216 SDCC also provides an option (-
217 \begin_inset ERT
218 status Collapsed
219
220 \layout Standard
221
222 \backslash 
223 /
224 \end_inset 
225
226 -cyclomatic) to report the relative complexity of a function.
227  These functions can then be further optimized, or hand coded in assembly
228  if needed.
229  
230 \newline 
231
232 \newline 
233 SDCC also comes with a companion source level debugger SDCDB, the debugger
234  currently uses ucSim a freeware simulator for 8051 and other micro-controllers.
235  
236 \newline 
237
238 \newline 
239 The latest version can be downloaded from 
240 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
241
242 \end_inset 
243
244 .
245
246 \series bold 
247  
248 \series default 
249 \emph on 
250 Please note: the compiler will probably always be some steps ahead of this
251  documentation
252 \series bold 
253 \emph default 
254
255 \begin_inset LatexCommand \index{Status of documentation}
256
257 \end_inset 
258
259
260 \begin_inset Foot
261 collapsed false
262
263 \layout Standard
264
265 Obviously this has pros and cons
266 \end_inset 
267
268 .
269 \layout Section
270
271 Open Source
272 \layout Standard
273
274 All packages used in this compiler system are 
275 \emph on 
276 opensource
277 \emph default 
278  and 
279 \emph on 
280 freeware
281 \emph default 
282 ; source code for all the sub-packages (pre-processor, assemblers, linkers
283  etc) is distributed with the package.
284  This documentation is maintained using a freeware word processor (LyX).
285 \newline 
286 This program is free software; you can redistribute it and/or modify it
287  under the terms of the GNU General Public License
288 \begin_inset LatexCommand \index{GNU General Public License, GPL}
289
290 \end_inset 
291
292  as published by the Free Software Foundation; either version 2, or (at
293  your option) any later version.
294  This program is distributed in the hope that it will be useful, but WITHOUT
295  ANY WARRANTY; without even the implied warranty
296 \begin_inset LatexCommand \index{warranty}
297
298 \end_inset 
299
300  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
301  See the GNU General Public License for more details.
302  You should have received a copy of the GNU General Public License along
303  with this program; if not, write to the Free Software Foundation, 59 Temple
304  Place - Suite 330, Boston, MA 02111-1307, USA.
305  In other words, you are welcome to use, share and improve this program.
306  You are forbidden to forbid anyone else to use, share and improve what
307  you give them.
308  Help stamp out software-hoarding! 
309 \layout Section
310
311 Typographic conventions
312 \begin_inset LatexCommand \index{Typographic conventions}
313
314 \end_inset 
315
316
317 \layout Standard
318
319 Throughout this manual, we will use the following convention.
320  Commands you have to type in are printed in 
321 \family sans 
322 \series bold 
323 "sans serif"
324 \series default 
325 .
326
327 \family default 
328  Code samples are printed in 
329 \family typewriter 
330 typewriter font.
331
332 \family default 
333  Interesting items and new terms are printed in 
334 \emph on 
335 italic.
336 \layout Section
337
338 Compatibility with previous versions
339 \layout Standard
340
341 This version has numerous bug fixes compared with the previous version.
342  But we also introduced some incompatibilities with older versions.
343  Not just for the fun of it, but to make the compiler more stable, efficient
344  and ANSI compliant
345 \begin_inset LatexCommand \index{ANSI-compliance}
346
347 \end_inset 
348
349  (see section 
350 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
351
352 \end_inset 
353
354  for ANSI-Compliance).
355  
356 \newline 
357
358 \layout Itemize
359
360 short is now equivalent to int (16 bits), it used to be equivalent to char
361  (8 bits) which is not ANSI compliant
362 \layout Itemize
363
364 the default directory for gcc-builds where include, library and documentation
365  files are stored is now in /usr/local/share
366 \layout Itemize
367
368 char type parameters to vararg functions are casted to int unless explicitly
369  casted, e.g.: 
370 \newline 
371
372 \family typewriter 
373 \SpecialChar ~
374 \SpecialChar ~
375 char a=3;
376 \newline 
377 \SpecialChar ~
378 \SpecialChar ~
379 printf ("%d %c
380 \backslash 
381 n", a, (char)a);
382 \family default 
383
384 \newline 
385  will push a as an int and as a char resp.
386 \layout Itemize
387
388 option -
389 \begin_inset ERT
390 status Collapsed
391
392 \layout Standard
393
394 \backslash 
395 /
396 \end_inset 
397
398 -regextend has been removed
399 \layout Itemize
400
401 option -
402 \begin_inset ERT
403 status Collapsed
404
405 \layout Standard
406
407 \backslash 
408 /
409 \end_inset 
410
411 -noregparms has been removed
412 \layout Itemize
413
414 option -
415 \begin_inset ERT
416 status Collapsed
417
418 \layout Standard
419
420 \backslash 
421 /
422 \end_inset 
423
424 -stack-after-data has been removed
425 \layout Standard
426
427
428 \emph on 
429 <pending: more incompatibilities?>
430 \layout Section
431
432 System Requirements
433 \layout Standard
434
435 What do you need before you start installation of SDCC? A computer, and
436  a desire to compute.
437  The preferred method of installation is to compile SDCC from source using
438  GNU gcc and make.
439  For Windows some pre-compiled binary distributions are available for your
440  convenience.
441  You should have some experience with command line tools and compiler use.
442 \layout Section
443
444 Other Resources
445 \layout Standard
446
447 The SDCC home page at 
448 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
449
450 \end_inset 
451
452  is a great place to find distribution sets.
453  You can also find links to the user mailing lists that offer help or discuss
454  SDCC with other SDCC users.
455  Web links to other SDCC related sites can also be found here.
456  This document can be found in the DOC directory of the source package as
457  a text or HTML file.
458  Some of the other tools (simulator and assembler) included with SDCC contain
459  their own documentation and can be found in the source distribution.
460  If you want the latest unreleased software, the complete source package
461  is available directly by anonymous CVS on cvs.sdcc.sourceforge.net.
462 \layout Section
463
464 Wishes for the future
465 \layout Standard
466
467 There are (and always will be) some things that could be done.
468  Here are some I can think of:
469 \newline 
470
471 \layout Standard
472
473
474 \family typewriter 
475 char KernelFunction3(char p) at 0x340;
476 \newline 
477
478 \layout Standard
479
480
481 \family typewriter 
482 code banking
483 \begin_inset LatexCommand \index{code banking (not supported)}
484
485 \end_inset 
486
487  support for mcs51
488 \newline 
489
490 \newline 
491
492 \family default 
493 If you can think of some more, please see the section 
494 \begin_inset LatexCommand \ref{sub:Requesting-Features}
495
496 \end_inset 
497
498  about filing feature requests
499 \begin_inset LatexCommand \index{Requesting features}
500
501 \end_inset 
502
503
504 \begin_inset LatexCommand \index{Feature request}
505
506 \end_inset 
507
508 .
509 \newline 
510
511 \layout Chapter
512
513 Installing SDCC
514 \begin_inset LatexCommand \index{Installation}
515
516 \end_inset 
517
518
519 \layout Standard
520
521 For most users it is sufficient to skip to either section 
522 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
523
524 \end_inset 
525
526  or section 
527 \begin_inset LatexCommand \ref{sub:Windows-Install}
528
529 \end_inset 
530
531 .
532  More detailled instructions follow below.
533 \layout Section
534
535 Configure Options
536 \begin_inset LatexCommand \index{Options SDCC configuration}
537
538 \end_inset 
539
540
541 \layout Standard
542
543 The install paths, search paths and other options are defined when running
544  'configure'.
545  The defaults can be overridden by:
546 \layout List
547 \labelwidthstring 00.00.0000
548
549 -
550 \begin_inset ERT
551 status Collapsed
552
553 \layout Standard
554
555 \backslash 
556 /
557 \end_inset 
558
559 -prefix see table below
560 \layout List
561 \labelwidthstring 00.00.0000
562
563 -
564 \begin_inset ERT
565 status Collapsed
566
567 \layout Standard
568
569 \backslash 
570 /
571 \end_inset 
572
573 -exec_prefix see table below
574 \layout List
575 \labelwidthstring 00.00.0000
576
577 -
578 \begin_inset ERT
579 status Collapsed
580
581 \layout Standard
582
583 \backslash 
584 /
585 \end_inset 
586
587 -bindir see table below
588 \layout List
589 \labelwidthstring 00.00.0000
590
591 -
592 \begin_inset ERT
593 status Collapsed
594
595 \layout Standard
596
597 \backslash 
598 /
599 \end_inset 
600
601 -datadir see table below
602 \layout List
603 \labelwidthstring 00.00.0000
604
605 docdir environment variable, see table below
606 \layout List
607 \labelwidthstring 00.00.0000
608
609 include_dir_suffix environment variable, see table below
610 \layout List
611 \labelwidthstring 00.00.0000
612
613 lib_dir_suffix environment variable, see table below
614 \layout List
615 \labelwidthstring 00.00.0000
616
617 sdccconf_h_dir_separator environment variable, either / or 
618 \backslash 
619
620 \backslash 
621  makes sense here.
622  This character will only be used in sdccconf.h; don't forget it's a C-header,
623  therefore a double-backslash is needed there.
624 \layout List
625 \labelwidthstring 00.00.0000
626
627 -
628 \begin_inset ERT
629 status Collapsed
630
631 \layout Standard
632
633 \backslash 
634 /
635 \end_inset 
636
637 -disable-mcs51-port Excludes the Intel mcs51 port
638 \layout List
639 \labelwidthstring 00.00.0000
640
641 -
642 \begin_inset ERT
643 status Collapsed
644
645 \layout Standard
646
647 \backslash 
648 /
649 \end_inset 
650
651 -disable-gbz80-port Excludes the Gameboy gbz80 port
652 \layout List
653 \labelwidthstring 00.00.0000
654
655 -
656 \begin_inset ERT
657 status Collapsed
658
659 \layout Standard
660
661 \backslash 
662 /
663 \end_inset 
664
665 -disable-z80-port Excludes the z80 port
666 \layout List
667 \labelwidthstring 00.00.0000
668
669 -
670 \begin_inset ERT
671 status Collapsed
672
673 \layout Standard
674
675 \backslash 
676 /
677 \end_inset 
678
679 -disable-avr-port Excludes the AVR port
680 \layout List
681 \labelwidthstring 00.00.0000
682
683 -
684 \begin_inset ERT
685 status Collapsed
686
687 \layout Standard
688
689 \backslash 
690 /
691 \end_inset 
692
693 -disable-ds390-port Excludes the DS390 port
694 \layout List
695 \labelwidthstring 00.00.0000
696
697 -
698 \begin_inset ERT
699 status Collapsed
700
701 \layout Standard
702
703 \backslash 
704 /
705 \end_inset 
706
707 -disable-hc08-port Excludes the HC08 port
708 \layout List
709 \labelwidthstring 00.00.0000
710
711 -
712 \begin_inset ERT
713 status Collapsed
714
715 \layout Standard
716
717 \backslash 
718 /
719 \end_inset 
720
721 -disable-pic-port Excludes the PIC port
722 \layout List
723 \labelwidthstring 00.00.0000
724
725 -
726 \begin_inset ERT
727 status Collapsed
728
729 \layout Standard
730
731 \backslash 
732 /
733 \end_inset 
734
735 -disable-xa51-port Excludes the XA51 port
736 \layout List
737 \labelwidthstring 00.00.0000
738
739 -
740 \begin_inset ERT
741 status Collapsed
742
743 \layout Standard
744
745 \backslash 
746 /
747 \end_inset 
748
749 -disable-ucsim Disables configuring and building of ucsim
750 \layout List
751 \labelwidthstring 00.00.0000
752
753 -
754 \begin_inset ERT
755 status Collapsed
756
757 \layout Standard
758
759 \backslash 
760 /
761 \end_inset 
762
763 -disable-device-lib-build Disables automatically building device libraries
764 \layout List
765 \labelwidthstring 00.00.0000
766
767 -
768 \begin_inset ERT
769 status Collapsed
770
771 \layout Standard
772
773 \backslash 
774 /
775 \end_inset 
776
777 -disable-packihx Disables building packihx
778 \layout List
779 \labelwidthstring 00.00.0000
780
781 -
782 \begin_inset ERT
783 status Collapsed
784
785 \layout Standard
786
787 \backslash 
788 /
789 \end_inset 
790
791 -enable-libgc Use the Bohem memory allocator.
792  Lower runtime footprint.
793 \layout Standard
794
795 Furthermore the environment variables CC, CFLAGS, ...
796  the tools and their arguments can be influenced.
797  Please see `configure -
798 \begin_inset ERT
799 status Collapsed
800
801 \layout Standard
802
803 \backslash 
804 /
805 \end_inset 
806
807 -help` and the man/info pages of `configure` for details.
808 \newline 
809
810 \newline 
811 The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB,
812  STD_FP_LIB, STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_
813 NAME, SDCC_INCLUDE_NAME, SDCC_LIB_NAME are defined by `configure` too.
814  At the moment it's not possible to change the default settings (it was
815  simply never required).
816 \newline 
817
818 \newline 
819 These configure options are compiled into the binaries, and can only be
820  changed by rerunning 'configure' and recompiling SDCC.
821  The configure options are written in 
822 \emph on 
823 italics
824 \emph default 
825  to distinguish them from run time environment variables (see section search
826  paths).
827 \newline 
828
829 \newline 
830 The settings for 
831 \begin_inset Quotes sld
832 \end_inset 
833
834 Win32 builds
835 \begin_inset Quotes srd
836 \end_inset 
837
838  are used by the SDCC team to build the official Win32 binaries.
839  The SDCC team uses Mingw32 to build the official Windows binaries, because
840  it's
841 \layout Enumerate
842
843 open source, 
844 \layout Enumerate
845
846 a gcc compiler and last but not least
847 \layout Enumerate
848
849 the binaries can be built by cross compiling on Sourceforge's compile farm.
850 \layout Standard
851
852 See the examples, how to pass the Win32 settings to 'configure'.
853  The other Win32 builds using Borland, VC or whatever don't use 'configure',
854  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
855  for Win32.
856 \newline 
857
858 \newline 
859 These defaults are:
860 \newline 
861
862 \layout Standard
863 \align center 
864
865 \begin_inset  Tabular
866 <lyxtabular version="3" rows="8" columns="3">
867 <features>
868 <column alignment="block" valignment="top" leftline="true" width="0in">
869 <column alignment="block" valignment="top" leftline="true" width="0in">
870 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
871 <row topline="true" bottomline="true">
872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
873 \begin_inset Text
874
875 \layout Standard
876
877 Variable
878 \end_inset 
879 </cell>
880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
881 \begin_inset Text
882
883 \layout Standard
884
885 default
886 \end_inset 
887 </cell>
888 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
889 \begin_inset Text
890
891 \layout Standard
892
893 Win32 builds
894 \end_inset 
895 </cell>
896 </row>
897 <row topline="true">
898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
899 \begin_inset Text
900
901 \layout Standard
902
903
904 \emph on 
905 PREFIX
906 \end_inset 
907 </cell>
908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
909 \begin_inset Text
910
911 \layout Standard
912
913 /usr/local
914 \end_inset 
915 </cell>
916 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
917 \begin_inset Text
918
919 \layout Standard
920
921
922 \backslash 
923 sdcc
924 \end_inset 
925 </cell>
926 </row>
927 <row topline="true">
928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
929 \begin_inset Text
930
931 \layout Standard
932
933
934 \emph on 
935 EXEC_PREFIX
936 \end_inset 
937 </cell>
938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
939 \begin_inset Text
940
941 \layout Standard
942
943
944 \emph on 
945 $PREFIX
946 \end_inset 
947 </cell>
948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
949 \begin_inset Text
950
951 \layout Standard
952
953
954 \emph on 
955 $PREFIX
956 \end_inset 
957 </cell>
958 </row>
959 <row topline="true">
960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
961 \begin_inset Text
962
963 \layout Standard
964
965
966 \emph on 
967 BINDIR
968 \end_inset 
969 </cell>
970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
971 \begin_inset Text
972
973 \layout Standard
974
975
976 \emph on 
977 $EXECPREFIX
978 \emph default 
979 /bin
980 \end_inset 
981 </cell>
982 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
983 \begin_inset Text
984
985 \layout Standard
986
987
988 \emph on 
989 $EXECPREFIX
990 \emph default 
991
992 \backslash 
993 bin
994 \end_inset 
995 </cell>
996 </row>
997 <row topline="true">
998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
999 \begin_inset Text
1000
1001 \layout Standard
1002
1003
1004 \emph on 
1005 DATADIR
1006 \end_inset 
1007 </cell>
1008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1009 \begin_inset Text
1010
1011 \layout Standard
1012
1013
1014 \emph on 
1015 $PREFIX
1016 \emph default 
1017 /share
1018 \end_inset 
1019 </cell>
1020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1021 \begin_inset Text
1022
1023 \layout Standard
1024
1025
1026 \emph on 
1027 $PREFIX
1028 \end_inset 
1029 </cell>
1030 </row>
1031 <row topline="true">
1032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1033 \begin_inset Text
1034
1035 \layout Standard
1036
1037
1038 \emph on 
1039 DOCDIR
1040 \end_inset 
1041 </cell>
1042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1043 \begin_inset Text
1044
1045 \layout Standard
1046
1047
1048 \emph on 
1049 $DATADIR
1050 \emph default 
1051 /sdcc/doc
1052 \end_inset 
1053 </cell>
1054 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1055 \begin_inset Text
1056
1057 \layout Standard
1058
1059
1060 \emph on 
1061 $DATADIR
1062 \emph default 
1063
1064 \backslash 
1065 doc
1066 \end_inset 
1067 </cell>
1068 </row>
1069 <row topline="true">
1070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1071 \begin_inset Text
1072
1073 \layout Standard
1074
1075
1076 \emph on 
1077 INCLUDE_DIR_SUFFIX
1078 \end_inset 
1079 </cell>
1080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1081 \begin_inset Text
1082
1083 \layout Standard
1084
1085 sdcc/include
1086 \end_inset 
1087 </cell>
1088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1089 \begin_inset Text
1090
1091 \layout Standard
1092
1093 include
1094 \end_inset 
1095 </cell>
1096 </row>
1097 <row topline="true" bottomline="true">
1098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1099 \begin_inset Text
1100
1101 \layout Standard
1102
1103
1104 \emph on 
1105 LIB_DIR_SUFFIX
1106 \end_inset 
1107 </cell>
1108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1109 \begin_inset Text
1110
1111 \layout Standard
1112
1113 sdcc/lib
1114 \end_inset 
1115 </cell>
1116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1117 \begin_inset Text
1118
1119 \layout Standard
1120
1121 lib
1122 \end_inset 
1123 </cell>
1124 </row>
1125 </lyxtabular>
1126
1127 \end_inset 
1128
1129
1130 \newline 
1131
1132 \layout Standard
1133 \noindent 
1134 'configure' also computes relative paths.
1135  This is needed for full relocatability of a binary package and to complete
1136  search paths (see section search paths below):
1137 \newline 
1138  
1139 \layout Standard
1140 \align center 
1141
1142 \begin_inset  Tabular
1143 <lyxtabular version="3" rows="4" columns="3">
1144 <features>
1145 <column alignment="block" valignment="top" leftline="true" width="0in">
1146 <column alignment="block" valignment="top" leftline="true" width="0in">
1147 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1148 <row topline="true" bottomline="true">
1149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1150 \begin_inset Text
1151
1152 \layout Standard
1153
1154 Variable (computed)
1155 \end_inset 
1156 </cell>
1157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1158 \begin_inset Text
1159
1160 \layout Standard
1161
1162 default
1163 \end_inset 
1164 </cell>
1165 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1166 \begin_inset Text
1167
1168 \layout Standard
1169
1170 Win32 builds
1171 \end_inset 
1172 </cell>
1173 </row>
1174 <row topline="true" bottomline="true">
1175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1176 \begin_inset Text
1177
1178 \layout Standard
1179
1180
1181 \emph on 
1182 BIN2DATA_DIR
1183 \end_inset 
1184 </cell>
1185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1186 \begin_inset Text
1187
1188 \layout Standard
1189
1190 ../share
1191 \end_inset 
1192 </cell>
1193 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1194 \begin_inset Text
1195
1196 \layout Standard
1197
1198 ..
1199 \end_inset 
1200 </cell>
1201 </row>
1202 <row bottomline="true">
1203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1204 \begin_inset Text
1205
1206 \layout Standard
1207
1208
1209 \emph on 
1210 PREFIX2BIN_DIR
1211 \end_inset 
1212 </cell>
1213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1214 \begin_inset Text
1215
1216 \layout Standard
1217
1218 bin
1219 \end_inset 
1220 </cell>
1221 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1222 \begin_inset Text
1223
1224 \layout Standard
1225
1226 bin
1227 \end_inset 
1228 </cell>
1229 </row>
1230 <row bottomline="true">
1231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1232 \begin_inset Text
1233
1234 \layout Standard
1235
1236
1237 \emph on 
1238 PREFIX2DATA_DIR
1239 \end_inset 
1240 </cell>
1241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1242 \begin_inset Text
1243
1244 \layout Standard
1245
1246 share/sdcc
1247 \end_inset 
1248 </cell>
1249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1250 \begin_inset Text
1251
1252 \layout Standard
1253
1254 \end_inset 
1255 </cell>
1256 </row>
1257 </lyxtabular>
1258
1259 \end_inset 
1260
1261
1262 \newline 
1263
1264 \layout Standard
1265 \noindent 
1266 Examples:
1267 \layout LyX-Code
1268
1269 ./configure
1270 \newline 
1271 ./configure -
1272 \begin_inset ERT
1273 status Collapsed
1274
1275 \layout Standard
1276
1277 \backslash 
1278 /
1279 \end_inset 
1280
1281 -prefix=
1282 \begin_inset Quotes srd
1283 \end_inset 
1284
1285 /usr/bin
1286 \begin_inset Quotes srd
1287 \end_inset 
1288
1289  -
1290 \begin_inset ERT
1291 status Collapsed
1292
1293 \layout Standard
1294
1295 \backslash 
1296 /
1297 \end_inset 
1298
1299 -datadir=
1300 \begin_inset Quotes srd
1301 \end_inset 
1302
1303 /usr/share
1304 \begin_inset Quotes srd
1305 \end_inset 
1306
1307
1308 \newline 
1309 ./configure -
1310 \begin_inset ERT
1311 status Collapsed
1312
1313 \layout Standard
1314
1315 \backslash 
1316 /
1317 \end_inset 
1318
1319 -disable-avr-port -
1320 \begin_inset ERT
1321 status Collapsed
1322
1323 \layout Standard
1324
1325 \backslash 
1326 /
1327 \end_inset 
1328
1329 -disable-xa51-port
1330 \layout Standard
1331
1332 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1333 32'):
1334 \layout LyX-Code
1335
1336 ./configure 
1337 \backslash 
1338
1339 \newline 
1340 CC=
1341 \begin_inset Quotes srd
1342 \end_inset 
1343
1344 i586-mingw32msvc-gcc
1345 \begin_inset Quotes srd
1346 \end_inset 
1347
1348  CXX=
1349 \begin_inset Quotes srd
1350 \end_inset 
1351
1352 i586-mingw32msvc-g++
1353 \begin_inset Quotes srd
1354 \end_inset 
1355
1356  
1357 \backslash 
1358  
1359 \newline 
1360 RANLIB=
1361 \begin_inset Quotes srd
1362 \end_inset 
1363
1364 i586-mingw32msvc-ranlib
1365 \begin_inset Quotes srd
1366 \end_inset 
1367
1368  
1369 \backslash 
1370
1371 \newline 
1372 STRIP=
1373 \begin_inset Quotes srd
1374 \end_inset 
1375
1376 i586-mingw32msvc-strip
1377 \begin_inset Quotes srd
1378 \end_inset 
1379
1380  
1381 \backslash 
1382
1383 \newline 
1384 -
1385 \begin_inset ERT
1386 status Collapsed
1387
1388 \layout Standard
1389
1390 \backslash 
1391 /
1392 \end_inset 
1393
1394 -prefix=
1395 \begin_inset Quotes srd
1396 \end_inset 
1397
1398 /sdcc
1399 \begin_inset Quotes srd
1400 \end_inset 
1401
1402  
1403 \backslash 
1404
1405 \newline 
1406 -
1407 \begin_inset ERT
1408 status Collapsed
1409
1410 \layout Standard
1411
1412 \backslash 
1413 /
1414 \end_inset 
1415
1416 -datadir=
1417 \begin_inset Quotes srd
1418 \end_inset 
1419
1420 /sdcc
1421 \begin_inset Quotes srd
1422 \end_inset 
1423
1424  
1425 \backslash 
1426
1427 \newline 
1428 docdir=
1429 \begin_inset Quotes srd
1430 \end_inset 
1431
1432 /sdcc/doc
1433 \begin_inset Quotes srd
1434 \end_inset 
1435
1436  
1437 \backslash 
1438
1439 \newline 
1440 include_dir_suffix=
1441 \begin_inset Quotes srd
1442 \end_inset 
1443
1444 include
1445 \begin_inset Quotes srd
1446 \end_inset 
1447
1448  
1449 \backslash 
1450
1451 \newline 
1452 lib_dir_suffix=
1453 \begin_inset Quotes srd
1454 \end_inset 
1455
1456 lib
1457 \begin_inset Quotes srd
1458 \end_inset 
1459
1460  
1461 \backslash 
1462
1463 \newline 
1464 sdccconf_h_dir_separator=
1465 \begin_inset Quotes srd
1466 \end_inset 
1467
1468
1469 \backslash 
1470
1471 \backslash 
1472
1473 \backslash 
1474
1475 \backslash 
1476
1477 \begin_inset Quotes srd
1478 \end_inset 
1479
1480  
1481 \backslash 
1482
1483 \newline 
1484 -
1485 \begin_inset ERT
1486 status Collapsed
1487
1488 \layout Standard
1489
1490 \backslash 
1491 /
1492 \end_inset 
1493
1494 -disable-device-lib-build
1495 \backslash 
1496
1497 \newline 
1498 -
1499 \begin_inset ERT
1500 status Collapsed
1501
1502 \layout Standard
1503
1504 \backslash 
1505 /
1506 \end_inset 
1507
1508 -disable-ucsim
1509 \backslash 
1510
1511 \newline 
1512 -
1513 \begin_inset ERT
1514 status Collapsed
1515
1516 \layout Standard
1517
1518 \backslash 
1519 /
1520 \end_inset 
1521
1522 -host=i586-mingw32msvc -
1523 \begin_inset ERT
1524 status Collapsed
1525
1526 \layout Standard
1527
1528 \backslash 
1529 /
1530 \end_inset 
1531
1532 -build=unknown-unknown-linux-gnu
1533 \layout Standard
1534
1535 To 
1536 \begin_inset Quotes sld
1537 \end_inset 
1538
1539 cross
1540 \begin_inset Quotes srd
1541 \end_inset 
1542
1543 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
1544 ):
1545 \layout LyX-Code
1546
1547 ./configure -C 
1548 \backslash 
1549
1550 \newline 
1551 CFLAGS=
1552 \begin_inset Quotes srd
1553 \end_inset 
1554
1555 -mno-cygwin -O2
1556 \begin_inset Quotes srd
1557 \end_inset 
1558
1559  
1560 \backslash 
1561
1562 \newline 
1563 LDFLAGS=
1564 \begin_inset Quotes srd
1565 \end_inset 
1566
1567 -mno-cygwin
1568 \begin_inset Quotes srd
1569 \end_inset 
1570
1571  
1572 \backslash 
1573
1574 \newline 
1575 -
1576 \begin_inset ERT
1577 status Collapsed
1578
1579 \layout Standard
1580
1581 \backslash 
1582 /
1583 \end_inset 
1584
1585 -prefix=
1586 \begin_inset Quotes srd
1587 \end_inset 
1588
1589 /sdcc
1590 \begin_inset Quotes srd
1591 \end_inset 
1592
1593  
1594 \backslash 
1595
1596 \newline 
1597 -
1598 \begin_inset ERT
1599 status Collapsed
1600
1601 \layout Standard
1602
1603 \backslash 
1604 /
1605 \end_inset 
1606
1607 -datadir=
1608 \begin_inset Quotes srd
1609 \end_inset 
1610
1611 /sdcc
1612 \begin_inset Quotes srd
1613 \end_inset 
1614
1615  
1616 \backslash 
1617
1618 \newline 
1619 docdir=
1620 \begin_inset Quotes srd
1621 \end_inset 
1622
1623 /sdcc/doc
1624 \begin_inset Quotes srd
1625 \end_inset 
1626
1627  
1628 \backslash 
1629  
1630 \newline 
1631 include_dir_suffix=
1632 \begin_inset Quotes srd
1633 \end_inset 
1634
1635 include
1636 \begin_inset Quotes srd
1637 \end_inset 
1638
1639  
1640 \backslash 
1641
1642 \newline 
1643 lib_dir_suffix=
1644 \begin_inset Quotes srd
1645 \end_inset 
1646
1647 lib
1648 \begin_inset Quotes srd
1649 \end_inset 
1650
1651  
1652 \backslash 
1653
1654 \newline 
1655 sdccconf_h_dir_separator=
1656 \begin_inset Quotes srd
1657 \end_inset 
1658
1659
1660 \backslash 
1661
1662 \backslash 
1663
1664 \backslash 
1665
1666 \backslash 
1667
1668 \begin_inset Quotes srd
1669 \end_inset 
1670
1671  
1672 \backslash 
1673
1674 \newline 
1675 -
1676 \begin_inset ERT
1677 status Collapsed
1678
1679 \layout Standard
1680
1681 \backslash 
1682 /
1683 \end_inset 
1684
1685 -disable-ucsim
1686 \layout Standard
1687
1688 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
1689  The option '-
1690 \begin_inset ERT
1691 status Collapsed
1692
1693 \layout Standard
1694
1695 \backslash 
1696 /
1697 \end_inset 
1698
1699 -C' turns on caching, which gives a little bit extra speed.
1700  However if options are changed, it can be necessary to delete the config.cache
1701  file.
1702 \layout Section
1703
1704 Install paths
1705 \begin_inset LatexCommand \label{sub:Install-paths}
1706
1707 \end_inset 
1708
1709
1710 \begin_inset LatexCommand \index{Install paths}
1711
1712 \end_inset 
1713
1714
1715 \layout Standard
1716 \added_space_top medskip \align center 
1717
1718 \begin_inset  Tabular
1719 <lyxtabular version="3" rows="5" columns="4">
1720 <features>
1721 <column alignment="center" valignment="top" leftline="true" width="0">
1722 <column alignment="center" valignment="top" leftline="true" width="0">
1723 <column alignment="center" valignment="top" leftline="true" width="0">
1724 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
1725 <row topline="true" bottomline="true">
1726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1727 \begin_inset Text
1728
1729 \layout Standard
1730
1731
1732 \series bold 
1733 Description
1734 \end_inset 
1735 </cell>
1736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1737 \begin_inset Text
1738
1739 \layout Standard
1740
1741
1742 \series bold 
1743 Path
1744 \end_inset 
1745 </cell>
1746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1747 \begin_inset Text
1748
1749 \layout Standard
1750
1751
1752 \series bold 
1753 Default
1754 \end_inset 
1755 </cell>
1756 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1757 \begin_inset Text
1758
1759 \layout Standard
1760
1761
1762 \series bold 
1763 Win32 builds
1764 \end_inset 
1765 </cell>
1766 </row>
1767 <row topline="true">
1768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1769 \begin_inset Text
1770
1771 \layout Standard
1772
1773 Binary files*
1774 \end_inset 
1775 </cell>
1776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1777 \begin_inset Text
1778
1779 \layout Standard
1780
1781
1782 \emph on 
1783 $EXEC_PREFIX
1784 \end_inset 
1785 </cell>
1786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1787 \begin_inset Text
1788
1789 \layout Standard
1790
1791 /usr/local/bin
1792 \end_inset 
1793 </cell>
1794 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1795 \begin_inset Text
1796
1797 \layout Standard
1798
1799
1800 \backslash 
1801 sdcc
1802 \backslash 
1803 bin
1804 \end_inset 
1805 </cell>
1806 </row>
1807 <row topline="true">
1808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1809 \begin_inset Text
1810
1811 \layout Standard
1812
1813 Include files
1814 \end_inset 
1815 </cell>
1816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1817 \begin_inset Text
1818
1819 \layout Standard
1820
1821
1822 \emph on 
1823 $DATADIR/ $INCLUDE_DIR_SUFFIX
1824 \end_inset 
1825 </cell>
1826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1827 \begin_inset Text
1828
1829 \layout Standard
1830
1831 /usr/local/share/sdcc/include
1832 \end_inset 
1833 </cell>
1834 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1835 \begin_inset Text
1836
1837 \layout Standard
1838
1839
1840 \backslash 
1841 sdcc
1842 \backslash 
1843 include
1844 \end_inset 
1845 </cell>
1846 </row>
1847 <row topline="true">
1848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1849 \begin_inset Text
1850
1851 \layout Standard
1852
1853 Library file**
1854 \end_inset 
1855 </cell>
1856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1857 \begin_inset Text
1858
1859 \layout Standard
1860
1861
1862 \emph on 
1863 $DATADIR/$LIB_DIR_SUFFIX
1864 \end_inset 
1865 </cell>
1866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1867 \begin_inset Text
1868
1869 \layout Standard
1870
1871 /usr/local/share/sdcc/lib
1872 \end_inset 
1873 </cell>
1874 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1875 \begin_inset Text
1876
1877 \layout Standard
1878
1879
1880 \backslash 
1881 sdcc
1882 \backslash 
1883 lib
1884 \end_inset 
1885 </cell>
1886 </row>
1887 <row topline="true" bottomline="true">
1888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1889 \begin_inset Text
1890
1891 \layout Standard
1892
1893 Documentation
1894 \end_inset 
1895 </cell>
1896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1897 \begin_inset Text
1898
1899 \layout Standard
1900
1901
1902 \emph on 
1903 $DOCDIR
1904 \end_inset 
1905 </cell>
1906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1907 \begin_inset Text
1908
1909 \layout Standard
1910
1911 /usr/local/share/sdcc/doc
1912 \end_inset 
1913 </cell>
1914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1915 \begin_inset Text
1916
1917 \layout Standard
1918
1919
1920 \backslash 
1921 sdcc
1922 \backslash 
1923 doc
1924 \end_inset 
1925 </cell>
1926 </row>
1927 </lyxtabular>
1928
1929 \end_inset 
1930
1931
1932 \layout Verse
1933
1934
1935 \size footnotesize 
1936 *compiler, preprocessor, assembler, and linker
1937 \newline 
1938 **the 
1939 \shape italic 
1940 model
1941 \shape default 
1942  is auto-appended by the compiler, e.g.
1943  small, large, z80, ds390 etc
1944 \layout Standard
1945 \noindent 
1946 The install paths can still be changed during `make install` with e.g.:
1947 \layout LyX-Code
1948
1949 make install prefix=$(HOME)/local/sdcc
1950 \layout Standard
1951
1952 Of course this doesn't change the search paths compiled into the binaries.
1953 \layout Section
1954
1955 Search Paths
1956 \begin_inset LatexCommand \label{sub:Search-Paths}
1957
1958 \end_inset 
1959
1960
1961 \begin_inset LatexCommand \index{Search path}
1962
1963 \end_inset 
1964
1965
1966 \layout Standard
1967
1968 Some search paths or parts of them are determined by configure variables
1969  (in 
1970 \emph on 
1971 italics
1972 \emph default 
1973 , see section above).
1974  Further search paths are determined by environment variables during runtime.
1975  
1976 \newline 
1977 The paths searched when running the compiler are as follows (the first catch
1978  wins):
1979 \newline 
1980
1981 \newline 
1982 1.
1983  Binary files (preprocessor, assembler and linker)
1984 \newline 
1985
1986 \layout Standard
1987 \align center 
1988
1989 \begin_inset  Tabular
1990 <lyxtabular version="3" rows="4" columns="3">
1991 <features>
1992 <column alignment="block" valignment="top" leftline="true" width="0in">
1993 <column alignment="block" valignment="top" leftline="true" width="0in">
1994 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1995 <row topline="true" bottomline="true">
1996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1997 \begin_inset Text
1998
1999 \layout Standard
2000
2001 Search path
2002 \end_inset 
2003 </cell>
2004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2005 \begin_inset Text
2006
2007 \layout Standard
2008
2009 default
2010 \end_inset 
2011 </cell>
2012 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2013 \begin_inset Text
2014
2015 \layout Standard
2016
2017 Win32 builds
2018 \end_inset 
2019 </cell>
2020 </row>
2021 <row topline="true">
2022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2023 \begin_inset Text
2024
2025 \layout Standard
2026
2027 $SDCC_HOME/
2028 \emph on 
2029 $PPREFIX2BIN_DIR
2030 \end_inset 
2031 </cell>
2032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2033 \begin_inset Text
2034
2035 \layout Standard
2036
2037 $SDCC_HOME/bin
2038 \end_inset 
2039 </cell>
2040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2041 \begin_inset Text
2042
2043 \layout Standard
2044
2045 $SDCC_HOME
2046 \backslash 
2047 bin
2048 \end_inset 
2049 </cell>
2050 </row>
2051 <row topline="true">
2052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2053 \begin_inset Text
2054
2055 \layout Standard
2056
2057 Path of argv[0] (if available)
2058 \end_inset 
2059 </cell>
2060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2061 \begin_inset Text
2062
2063 \layout Standard
2064
2065 Path of argv[0]
2066 \end_inset 
2067 </cell>
2068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2069 \begin_inset Text
2070
2071 \layout Standard
2072
2073 Path of argv[0]
2074 \end_inset 
2075 </cell>
2076 </row>
2077 <row topline="true" bottomline="true">
2078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2079 \begin_inset Text
2080
2081 \layout Standard
2082
2083 $PATH
2084 \end_inset 
2085 </cell>
2086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2087 \begin_inset Text
2088
2089 \layout Standard
2090
2091 $PATH
2092 \end_inset 
2093 </cell>
2094 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2095 \begin_inset Text
2096
2097 \layout Standard
2098
2099 $PATH
2100 \end_inset 
2101 </cell>
2102 </row>
2103 </lyxtabular>
2104
2105 \end_inset 
2106
2107  
2108 \newline 
2109
2110 \layout Standard
2111 \noindent 
2112 2.
2113  Include files
2114 \newline 
2115
2116 \layout Standard
2117 \align center 
2118
2119 \begin_inset  Tabular
2120 <lyxtabular version="3" rows="6" columns="3">
2121 <features>
2122 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2123 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2124 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2125 <row topline="true" bottomline="true">
2126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2127 \begin_inset Text
2128
2129 \layout Standard
2130
2131 Search path
2132 \end_inset 
2133 </cell>
2134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2135 \begin_inset Text
2136
2137 \layout Standard
2138
2139 default
2140 \end_inset 
2141 </cell>
2142 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2143 \begin_inset Text
2144
2145 \layout Standard
2146
2147 Win32 builds
2148 \end_inset 
2149 </cell>
2150 </row>
2151 <row topline="true">
2152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2153 \begin_inset Text
2154
2155 \layout Standard
2156
2157 -
2158 \begin_inset ERT
2159 status Collapsed
2160
2161 \layout Standard
2162
2163 \backslash 
2164 /
2165 \end_inset 
2166
2167 -I dir
2168 \end_inset 
2169 </cell>
2170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2171 \begin_inset Text
2172
2173 \layout Standard
2174
2175 -
2176 \begin_inset ERT
2177 status Collapsed
2178
2179 \layout Standard
2180
2181 \backslash 
2182 /
2183 \end_inset 
2184
2185 -I dir
2186 \end_inset 
2187 </cell>
2188 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2189 \begin_inset Text
2190
2191 \layout Standard
2192
2193 -
2194 \begin_inset ERT
2195 status Collapsed
2196
2197 \layout Standard
2198
2199 \backslash 
2200 /
2201 \end_inset 
2202
2203 -I dir
2204 \end_inset 
2205 </cell>
2206 </row>
2207 <row topline="true">
2208 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2209 \begin_inset Text
2210
2211 \layout Standard
2212
2213 $SDCC_INCLUDE
2214 \end_inset 
2215 </cell>
2216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2217 \begin_inset Text
2218
2219 \layout Standard
2220
2221 $SDCC_INCLUDE
2222 \end_inset 
2223 </cell>
2224 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2225 \begin_inset Text
2226
2227 \layout Standard
2228
2229 $SDCC_INCLUDE
2230 \end_inset 
2231 </cell>
2232 </row>
2233 <row topline="true">
2234 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2235 \begin_inset Text
2236
2237 \layout Standard
2238
2239 $SDCC_HOME/
2240 \newline 
2241
2242 \emph on 
2243 $PREFIX2DATA_DIR/
2244 \newline 
2245 $INCLUDE_DIR_SUFFIX
2246 \end_inset 
2247 </cell>
2248 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2249 \begin_inset Text
2250
2251 \layout Standard
2252
2253 $SDCC_ HOME/
2254 \newline 
2255 share/sdcc/
2256 \newline 
2257 include
2258 \end_inset 
2259 </cell>
2260 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2261 \begin_inset Text
2262
2263 \layout Standard
2264
2265 $SDCC_HOME
2266 \backslash 
2267 include
2268 \end_inset 
2269 </cell>
2270 </row>
2271 <row topline="true">
2272 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2273 \begin_inset Text
2274
2275 \layout Standard
2276
2277 path(argv[0])/
2278 \newline 
2279
2280 \emph on 
2281 $BIN2DATADIR/
2282 \emph default 
2283
2284 \newline 
2285
2286 \emph on 
2287 $INCLUDE_DIR_SUFFIX
2288 \end_inset 
2289 </cell>
2290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2291 \begin_inset Text
2292
2293 \layout Standard
2294
2295 path(argv[0])/
2296 \newline 
2297 ../sdcc/include
2298 \newline 
2299 \SpecialChar ~
2300 \SpecialChar ~
2301 \SpecialChar ~
2302 \SpecialChar ~
2303 \SpecialChar ~
2304 \SpecialChar ~
2305 \SpecialChar ~
2306 \SpecialChar ~
2307 \SpecialChar ~
2308 \SpecialChar ~
2309 \SpecialChar ~
2310 \SpecialChar ~
2311 \SpecialChar ~
2312 \SpecialChar ~
2313 \SpecialChar ~
2314 \SpecialChar ~
2315 \SpecialChar ~
2316 \SpecialChar ~
2317 \SpecialChar ~
2318 \SpecialChar ~
2319 \SpecialChar ~
2320 \SpecialChar ~
2321 \SpecialChar ~
2322 \SpecialChar ~
2323 \SpecialChar ~
2324 \SpecialChar ~
2325 \SpecialChar ~
2326 \SpecialChar ~
2327 \SpecialChar ~
2328 \SpecialChar ~
2329 \SpecialChar ~
2330 \SpecialChar ~
2331 \SpecialChar ~
2332 \SpecialChar ~
2333 \SpecialChar ~
2334 \SpecialChar ~
2335 \SpecialChar ~
2336 \SpecialChar ~
2337
2338 \end_inset 
2339 </cell>
2340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2341 \begin_inset Text
2342
2343 \layout Standard
2344
2345 path(argv[0])
2346 \backslash 
2347 ..
2348 \backslash 
2349 include
2350 \end_inset 
2351 </cell>
2352 </row>
2353 <row topline="true" bottomline="true">
2354 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2355 \begin_inset Text
2356
2357 \layout Standard
2358
2359
2360 \emph on 
2361 $DATADIR/
2362 \emph default 
2363
2364 \newline 
2365
2366 \emph on 
2367 $INCLUDE_DIR_SUFFIX
2368 \end_inset 
2369 </cell>
2370 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2371 \begin_inset Text
2372
2373 \layout Standard
2374
2375 /usr/local/share/sdcc/
2376 \newline 
2377 include
2378 \end_inset 
2379 </cell>
2380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2381 \begin_inset Text
2382
2383 \layout Standard
2384
2385 (not on Win32)
2386 \end_inset 
2387 </cell>
2388 </row>
2389 </lyxtabular>
2390
2391 \end_inset 
2392
2393  
2394 \newline 
2395
2396 \layout Standard
2397 \noindent 
2398 The option -
2399 \begin_inset ERT
2400 status Collapsed
2401
2402 \layout Standard
2403
2404 \backslash 
2405 /
2406 \end_inset 
2407
2408 -nostdinc disables the last two search paths.
2409 \newline 
2410
2411 \newline 
2412 3.
2413  Library files 
2414 \newline 
2415
2416 \layout Standard
2417
2418 With the exception of 
2419 \begin_inset Quotes sld
2420 \end_inset 
2421
2422 -
2423 \begin_inset ERT
2424 status Collapsed
2425
2426 \layout Standard
2427
2428 \backslash 
2429 /
2430 \end_inset 
2431
2432 -L dir
2433 \begin_inset Quotes srd
2434 \end_inset 
2435
2436  the 
2437 \shape italic 
2438 model
2439 \shape default 
2440  is auto-appended by the compiler (e.g.
2441  small, large, z80, ds390 etc.).
2442  
2443 \newline 
2444
2445 \layout Standard
2446 \align center 
2447
2448 \begin_inset  Tabular
2449 <lyxtabular version="3" rows="6" columns="3">
2450 <features>
2451 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2452 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2453 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2454 <row topline="true" bottomline="true">
2455 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2456 \begin_inset Text
2457
2458 \layout Standard
2459
2460 Search path
2461 \end_inset 
2462 </cell>
2463 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2464 \begin_inset Text
2465
2466 \layout Standard
2467
2468 default
2469 \end_inset 
2470 </cell>
2471 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2472 \begin_inset Text
2473
2474 \layout Standard
2475
2476 Win32 builds
2477 \end_inset 
2478 </cell>
2479 </row>
2480 <row topline="true">
2481 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2482 \begin_inset Text
2483
2484 \layout Standard
2485
2486 -
2487 \begin_inset ERT
2488 status Collapsed
2489
2490 \layout Standard
2491
2492 \backslash 
2493 /
2494 \end_inset 
2495
2496 -L dir
2497 \end_inset 
2498 </cell>
2499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2500 \begin_inset Text
2501
2502 \layout Standard
2503
2504 -
2505 \begin_inset ERT
2506 status Collapsed
2507
2508 \layout Standard
2509
2510 \backslash 
2511 /
2512 \end_inset 
2513
2514 -L dir
2515 \end_inset 
2516 </cell>
2517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2518 \begin_inset Text
2519
2520 \layout Standard
2521
2522 -
2523 \begin_inset ERT
2524 status Collapsed
2525
2526 \layout Standard
2527
2528 \backslash 
2529 /
2530 \end_inset 
2531
2532 -L dir
2533 \end_inset 
2534 </cell>
2535 </row>
2536 <row topline="true">
2537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2538 \begin_inset Text
2539
2540 \layout Standard
2541
2542 $SDCC_LIB/
2543 \newline 
2544
2545 \emph on 
2546 <model>
2547 \end_inset 
2548 </cell>
2549 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2550 \begin_inset Text
2551
2552 \layout Standard
2553
2554 $SDCC_LIB/
2555 \newline 
2556
2557 \emph on 
2558 <model>
2559 \end_inset 
2560 </cell>
2561 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2562 \begin_inset Text
2563
2564 \layout Standard
2565
2566 $SDCC_LIB
2567 \backslash 
2568
2569 \newline 
2570
2571 \emph on 
2572 <model>
2573 \end_inset 
2574 </cell>
2575 </row>
2576 <row topline="true">
2577 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2578 \begin_inset Text
2579
2580 \layout Standard
2581
2582 $SDCC_HOME/
2583 \newline 
2584
2585 \emph on 
2586 $PREFIX2DATA_DIR/
2587 \newline 
2588 $LIB_DIR_SUFFIX/<model>
2589 \end_inset 
2590 </cell>
2591 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2592 \begin_inset Text
2593
2594 \layout Standard
2595
2596 $SDCC_HOME/
2597 \newline 
2598 share/sdcc/
2599 \newline 
2600 lib/
2601 \emph on 
2602 <model>
2603 \end_inset 
2604 </cell>
2605 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2606 \begin_inset Text
2607
2608 \layout Standard
2609
2610 $SDCC_HOME
2611 \backslash 
2612 lib
2613 \backslash 
2614
2615 \emph on 
2616
2617 \newline 
2618 <model>
2619 \end_inset 
2620 </cell>
2621 </row>
2622 <row topline="true">
2623 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2624 \begin_inset Text
2625
2626 \layout Standard
2627
2628 path(argv[0])/
2629 \newline 
2630
2631 \emph on 
2632 $BIN2DATADIR/
2633 \emph default 
2634
2635 \newline 
2636
2637 \emph on 
2638 $LIB_DIR_SUFFIX/<model>
2639 \end_inset 
2640 </cell>
2641 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2642 \begin_inset Text
2643
2644 \layout Standard
2645
2646 path(argv[0])/
2647 \newline 
2648 ../sdcc/lib/
2649 \emph on 
2650 <model>
2651 \newline 
2652 \SpecialChar ~
2653 \SpecialChar ~
2654 \SpecialChar ~
2655 \SpecialChar ~
2656 \SpecialChar ~
2657 \SpecialChar ~
2658 \SpecialChar ~
2659 \SpecialChar ~
2660 \SpecialChar ~
2661 \SpecialChar ~
2662 \SpecialChar ~
2663 \SpecialChar ~
2664 \SpecialChar ~
2665 \SpecialChar ~
2666 \SpecialChar ~
2667 \SpecialChar ~
2668 \SpecialChar ~
2669 \SpecialChar ~
2670 \SpecialChar ~
2671 \SpecialChar ~
2672 \SpecialChar ~
2673 \SpecialChar ~
2674 \SpecialChar ~
2675 \SpecialChar ~
2676 \SpecialChar ~
2677 \SpecialChar ~
2678 \SpecialChar ~
2679 \SpecialChar ~
2680 \SpecialChar ~
2681 \SpecialChar ~
2682 \SpecialChar ~
2683 \SpecialChar ~
2684 \SpecialChar ~
2685 \SpecialChar ~
2686 \SpecialChar ~
2687 \SpecialChar ~
2688 \SpecialChar ~
2689 \SpecialChar ~
2690 \SpecialChar ~
2691
2692 \end_inset 
2693 </cell>
2694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2695 \begin_inset Text
2696
2697 \layout Standard
2698
2699 path(argv[0])
2700 \backslash 
2701
2702 \newline 
2703 ..
2704 \backslash 
2705 lib
2706 \backslash 
2707
2708 \emph on 
2709 <model>
2710 \newline 
2711 \SpecialChar ~
2712 \SpecialChar ~
2713 \SpecialChar ~
2714 \SpecialChar ~
2715 \SpecialChar ~
2716 \SpecialChar ~
2717 \SpecialChar ~
2718 \SpecialChar ~
2719 \SpecialChar ~
2720 \SpecialChar ~
2721 \SpecialChar ~
2722 \SpecialChar ~
2723 \SpecialChar ~
2724 \SpecialChar ~
2725 \SpecialChar ~
2726 \SpecialChar ~
2727 \SpecialChar ~
2728 \SpecialChar ~
2729 \SpecialChar ~
2730 \SpecialChar ~
2731 \SpecialChar ~
2732 \SpecialChar ~
2733 \SpecialChar ~
2734 \SpecialChar ~
2735 \SpecialChar ~
2736 \SpecialChar ~
2737 \SpecialChar ~
2738 \SpecialChar ~
2739 \SpecialChar ~
2740 \SpecialChar ~
2741 \SpecialChar ~
2742 \SpecialChar ~
2743 \SpecialChar ~
2744 \SpecialChar ~
2745 \SpecialChar ~
2746
2747 \end_inset 
2748 </cell>
2749 </row>
2750 <row topline="true" bottomline="true">
2751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2752 \begin_inset Text
2753
2754 \layout Standard
2755
2756
2757 \emph on 
2758 $DATADIR/
2759 \newline 
2760 $LIB_DIR_SUFFIX/<model>
2761 \end_inset 
2762 </cell>
2763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2764 \begin_inset Text
2765
2766 \layout Standard
2767
2768 /usr/local/share/sdcc/
2769 \newline 
2770 lib/
2771 \emph on 
2772 <model>
2773 \end_inset 
2774 </cell>
2775 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2776 \begin_inset Text
2777
2778 \layout Standard
2779
2780 (not on Win32)
2781 \end_inset 
2782 </cell>
2783 </row>
2784 </lyxtabular>
2785
2786 \end_inset 
2787
2788
2789 \newline 
2790
2791 \layout Comment
2792
2793 Don't delete any of the stray spaces in the table above without checking
2794  the HTML output (last line)!
2795 \layout Standard
2796
2797 \SpecialChar ~
2798
2799 \newline 
2800 The option -
2801 \begin_inset ERT
2802 status Collapsed
2803
2804 \layout Standard
2805
2806 \backslash 
2807 /
2808 \end_inset 
2809
2810 -nostdlib disables the last two search paths.
2811 \layout Section
2812
2813 Building SDCC
2814 \begin_inset LatexCommand \index{Building SDCC}
2815
2816 \end_inset 
2817
2818
2819 \layout Subsection
2820
2821 Building SDCC on Linux
2822 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
2823
2824 \end_inset 
2825
2826
2827 \layout Enumerate
2828
2829
2830 \series medium 
2831 Download the source package
2832 \series default 
2833  either from the SDCC CVS repository or from the nightly snapshots
2834 \series medium 
2835 , it will be named something like sdcc
2836 \series default 
2837 .src
2838 \series medium 
2839 .t
2840 \series default 
2841 ar.
2842 \series medium 
2843 gz
2844 \series default 
2845  
2846 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
2847
2848 \end_inset 
2849
2850 .
2851 \layout Enumerate
2852
2853
2854 \series medium 
2855 Bring up a command line terminal, such as xterm.
2856 \layout Enumerate
2857
2858
2859 \series medium 
2860 Unpack the file using a command like: 
2861 \family sans 
2862 \series bold 
2863 "tar -xvzf sdcc.src.tar.gz
2864 \family default 
2865 \series default 
2866 "
2867 \series medium 
2868 , this will create a sub-directory called sdcc with all of the sources.
2869 \layout Enumerate
2870
2871 Change directory into the main SDCC directory, for example type: 
2872 \family sans 
2873 \series bold 
2874 "cd sdcc
2875 \series default 
2876 ".
2877 \layout Enumerate
2878
2879
2880 \series medium 
2881 Type 
2882 \family sans 
2883 \series bold 
2884 "./configure
2885 \family default 
2886 \series default 
2887 ".
2888  This configures the package for compilation on your system.
2889 \layout Enumerate
2890
2891
2892 \series medium 
2893 Type 
2894 \family sans 
2895 \series bold 
2896 "make
2897 \family default 
2898 \series default 
2899 "
2900 \series medium 
2901 .
2902
2903 \series default 
2904  All of the source packages will compile, this can take a while.
2905 \layout Enumerate
2906
2907
2908 \series medium 
2909 Type 
2910 \family sans 
2911 \series bold 
2912 "make install"
2913 \family default 
2914 \series default 
2915  as root
2916 \series medium 
2917 .
2918
2919 \series default 
2920  This copies the binary executables, the include files, the libraries and
2921  the documentation to the install directories.
2922  Proceed with section 
2923 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
2924
2925 \end_inset 
2926
2927 .
2928 \layout Subsection
2929
2930 Building SDCC on OSX 2.x
2931 \layout Standard
2932
2933 Follow the instruction for Linux.
2934 \newline 
2935
2936 \newline 
2937 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
2938 )) fails to compile SDCC.
2939  Fortunately there's also gcc 2.9.x installed, which works fine.
2940  This compiler can be selected by running 'configure' with:
2941 \layout LyX-Code
2942
2943 ./configure CC=gcc2 CXX=g++2
2944 \layout Subsection
2945
2946 Cross compiling SDCC on Linux for Windows
2947 \layout Standard
2948
2949 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
2950  See section 'Configure Options'.
2951 \layout Subsection
2952
2953 Building SDCC on Windows 
2954 \layout Standard
2955
2956 With the exception of Cygwin the SDCC binaries uCsim and sdcdb can't be
2957  built on Windows.
2958  They use Unix-sockets, which are not available on Win32.
2959 \layout Subsection
2960
2961 Building SDCC using Cygwin and Mingw32
2962 \layout Standard
2963
2964 For building and installing a Cygwin executable follow the instructions
2965  for Linux.
2966 \newline 
2967
2968 \newline 
2969 On Cygwin a 
2970 \begin_inset Quotes sld
2971 \end_inset 
2972
2973 native
2974 \begin_inset Quotes srd
2975 \end_inset 
2976
2977  Win32-binary can be built, which will not need the Cygwin-DLL.
2978  For the necessary 'configure' options see section 'configure options' or
2979  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
2980 \newline 
2981
2982 \newline 
2983 In order to install Cygwin on Windows download setup.exe from 
2984 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
2985
2986 \end_inset 
2987
2988 .
2989  Run it, set the 
2990 \begin_inset Quotes sld
2991 \end_inset 
2992
2993 default text file type
2994 \begin_inset Quotes srd
2995 \end_inset 
2996
2997  to 
2998 \begin_inset Quotes sld
2999 \end_inset 
3000
3001 unix
3002 \begin_inset Quotes srd
3003 \end_inset 
3004
3005  and download/install at least the following packages.
3006  Some packages are selected by default, others will be automatically selected
3007  because of dependencies with the manually selected packages.
3008  Never deselect these packages!
3009 \layout Itemize
3010
3011 flex
3012 \layout Itemize
3013
3014 bison
3015 \layout Itemize
3016
3017 gcc ; version 3.x is fine, no need to use the old 2.9x
3018 \layout Itemize
3019
3020 binutils ; selected with gcc
3021 \layout Itemize
3022
3023 make
3024 \layout Itemize
3025
3026 rxvt ; a nice console, which makes life much easier under windoze (see below)
3027 \layout Itemize
3028
3029 man ; not really needed for building SDCC, but you'll miss it sooner or
3030  later
3031 \layout Itemize
3032
3033 less ; not really needed for building SDCC, but you'll miss it sooner or
3034  later
3035 \layout Itemize
3036
3037 cvs ; only if you use CVS access
3038 \layout Standard
3039
3040 If you want to develop something you'll need:
3041 \layout Itemize
3042
3043 python ; for the regression tests
3044 \layout Itemize
3045
3046 gdb ; the gnu debugger, together with the nice GUI 
3047 \begin_inset Quotes sld
3048 \end_inset 
3049
3050 insight
3051 \begin_inset Quotes srd
3052 \end_inset 
3053
3054
3055 \layout Itemize
3056
3057 openssh ; to access the CF or commit changes
3058 \layout Itemize
3059
3060 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3061  use autoconf-stable!
3062 \layout Standard
3063
3064 rxvt is a nice console with history.
3065  Replace in your cygwin.bat the line
3066 \layout LyX-Code
3067
3068 bash -
3069 \begin_inset ERT
3070 status Collapsed
3071
3072 \layout Standard
3073
3074 \backslash 
3075 /
3076 \end_inset 
3077
3078 -login -i 
3079 \layout Standard
3080
3081 with (one line):
3082 \layout LyX-Code
3083
3084 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3085 \layout LyX-Code
3086
3087      -bg black -fg white -geometry 100x65 -e bash -
3088 \begin_inset ERT
3089 status Collapsed
3090
3091 \layout Standard
3092
3093 \backslash 
3094 /
3095 \end_inset 
3096
3097 -login
3098 \layout Standard
3099
3100 Text selected with the mouse is automatically copied to the clipboard, pasting
3101  works with shift-insert.
3102 \newline 
3103
3104 \newline 
3105 The other good tip is to make sure you have no //c/-style paths anywhere,
3106  use /cygdrive/c/ instead.
3107  Using // invokes a network lookup which is very slow.
3108  If you think 
3109 \begin_inset Quotes sld
3110 \end_inset 
3111
3112 cygdrive
3113 \begin_inset Quotes srd
3114 \end_inset 
3115
3116  is too long, you can change it with e.g.
3117 \layout LyX-Code
3118
3119 mount -s -u -c /mnt
3120 \layout Standard
3121
3122 SDCC sources use the unix line ending LF.
3123  Life is much easier, if you store the source tree on a drive which is mounted
3124  in binary mode.
3125  And use an editor which can handle LF-only line endings.
3126  Make sure not to commit files with windows line endings.
3127  The tabulator spacing
3128 \begin_inset LatexCommand \index{tabulator spacing (8)}
3129
3130 \end_inset 
3131
3132  used in the project is 8.
3133 \layout Subsection
3134
3135 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3136 \layout Standard
3137
3138
3139 \series medium 
3140 Download the source package
3141 \series default 
3142  either from the SDCC CVS repository or from the 
3143 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3144
3145 \end_inset 
3146
3147
3148 \series medium 
3149 , it will be named something like sdcc
3150 \series default 
3151 .src
3152 \series medium 
3153 .tgz.
3154
3155 \series default 
3156  SDCC is distributed with all the projects, workspaces, and files you need
3157  to build it using Visual C++ 6.0/NET (except for sdcdb.exe which currently
3158  doesn't build under MSVC).
3159  The workspace name is 'sdcc.dsw'.
3160  Please note that as it is now, all the executables are created in a folder
3161  called sdcc
3162 \backslash 
3163 bin_vc.
3164  Once built you need to copy the executables from sdcc
3165 \backslash 
3166 bin_vc to sdcc
3167 \backslash 
3168 bin before running SDCC.
3169  
3170 \newline 
3171
3172 \newline 
3173 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3174  flex.exe, and gawk.exe.
3175  One good place to get them is 
3176 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3177
3178 \end_inset 
3179
3180
3181 \newline 
3182
3183 \newline 
3184 Download the file UnxUtils
3185 \begin_inset LatexCommand \index{UnxUtils}
3186
3187 \end_inset 
3188
3189 .zip.
3190  Now you have to install the utilities and setup MSVC so it can locate the
3191  required programs.
3192  Here there are two alternatives (choose one!):
3193 \layout Enumerate
3194
3195 The easy way:
3196 \newline 
3197
3198 \newline 
3199 a) Extract UnxUtils.zip to your C:
3200 \backslash 
3201  hard disk PRESERVING the original paths, otherwise bison won't work.
3202  (If you are using WinZip make certain that 'Use folder names' is selected)
3203 \newline 
3204
3205 \newline 
3206 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3207  in 'Show directories for:' select 'Executable files', and in the directories
3208  window add a new path: 'C:
3209 \backslash 
3210 user
3211 \backslash 
3212 local
3213 \backslash 
3214 wbin', click ok.
3215 \newline 
3216
3217 \newline 
3218 (As a side effect, you get a bunch of Unix utilities that could be useful,
3219  such as diff and patch.)
3220 \layout Enumerate
3221
3222 A more compact way:
3223 \newline 
3224
3225 \newline 
3226 This one avoids extracting a bunch of files you may not use, but requires
3227  some extra work:
3228 \newline 
3229
3230 \newline 
3231 a) Create a directory were to put the tools needed, or use a directory already
3232  present.
3233  Say for example 'C:
3234 \backslash 
3235 util'.
3236 \newline 
3237
3238 \newline 
3239 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3240  to such directory WITHOUT preserving the original paths.
3241  (If you are using WinZip make certain that 'Use folder names' is not selected)
3242 \newline 
3243
3244 \newline 
3245 c) Rename bison.exe to '_bison.exe'.
3246 \newline 
3247
3248 \newline 
3249 d) Create a batch file 'bison.bat' in 'C:
3250 \backslash 
3251 util
3252 \backslash 
3253 ' and add these lines: 
3254 \newline 
3255 \SpecialChar ~
3256 \SpecialChar ~
3257 set BISON_SIMPLE=C:
3258 \backslash 
3259 util
3260 \backslash 
3261 bison.simple 
3262 \newline 
3263 \SpecialChar ~
3264 \SpecialChar ~
3265 set BISON_HAIRY=C:
3266 \backslash 
3267 util
3268 \backslash 
3269 bison.hairy
3270 \newline 
3271 \SpecialChar ~
3272 \SpecialChar ~
3273 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3274 \newline 
3275
3276 \newline 
3277 Steps 'c' and 'd' are needed because bison requires by default that the
3278  files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3279  '/usr/local/share/' I think.
3280  So it is necessary to tell bison where those files are located if they
3281  are not in such directory.
3282  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3283 \newline 
3284
3285 \newline 
3286 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3287  in 'Show directories for:' select 'Executable files', and in the directories
3288  window add a new path: 'c:
3289 \backslash 
3290 util', click ok.
3291  Note that you can use any other path instead of 'c:
3292 \backslash 
3293 util', even the path where the Visual C++ tools are, probably: 'C:
3294 \backslash 
3295 Program Files
3296 \backslash 
3297 Microsoft Visual Studio
3298 \backslash 
3299 Common
3300 \backslash 
3301 Tools'.
3302  So you don't have to execute step 'e' :)
3303 \layout Standard
3304
3305 That is it.
3306  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3307  the executables from sdcc
3308 \backslash 
3309 bin_vc to sdcc
3310 \backslash 
3311 bin, and you can compile using SDCC.
3312 \layout Subsection
3313
3314 Building SDCC Using Borland
3315 \layout Enumerate
3316
3317 From the sdcc directory, run the command "make -f Makefile.bcc".
3318  This should regenerate all the .exe files in the bin directory except for
3319  sdcdb.exe (which currently doesn't build under Borland C++).
3320 \layout Enumerate
3321
3322 If you modify any source files and need to rebuild, be aware that the dependenci
3323 es may not be correctly calculated.
3324  The safest option is to delete all .obj files and run the build again.
3325  From a Cygwin BASH prompt, this can easily be done with the command (be
3326  sure you are in the sdcc directory):
3327 \newline 
3328
3329 \newline 
3330
3331 \family sans 
3332 \series bold 
3333 find .
3334  
3335 \backslash 
3336 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
3337 \backslash 
3338 ) -print -exec rm {} 
3339 \backslash 
3340 ;
3341 \family default 
3342 \series default 
3343
3344 \newline 
3345
3346 \newline 
3347 or on Windows NT/2000/XP from the command prompt with the command:
3348 \newline 
3349
3350 \family sans 
3351 \series bold 
3352
3353 \newline 
3354 del /s *.obj *.lib *.rul
3355 \family default 
3356 \series default 
3357  from the sdcc directory.
3358 \layout Subsection
3359
3360 Windows Install Using a Binary Package
3361 \begin_inset LatexCommand \label{sub:Windows-Install}
3362
3363 \end_inset 
3364
3365
3366 \layout Enumerate
3367
3368 Download the binary package from 
3369 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3370
3371 \end_inset 
3372
3373  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
3374  This should unpack to a group of sub-directories.
3375  An example directory structure after unpacking the mingw32 package is:
3376  c:
3377 \backslash 
3378 sdcc
3379 \backslash 
3380 bin for the executables, c:
3381 \backslash 
3382 sdcc
3383 \backslash 
3384 include and c:
3385 \backslash 
3386 sdcc
3387 \backslash 
3388 lib for the include and libraries.
3389 \layout Enumerate
3390
3391 Adjust your environment variable PATH to include the location of the bin
3392  directory or start sdcc using the full path.
3393 \layout Section
3394
3395 Building the Documentation
3396 \layout Standard
3397
3398 If the necessary tools (LyX, LaTeX, LaTeX2HTML) are installed it is as easy
3399  as changing into the doc directory and typing 
3400 \family sans 
3401 \series bold 
3402
3403 \begin_inset Quotes srd
3404 \end_inset 
3405
3406 make
3407 \begin_inset Quotes srd
3408 \end_inset 
3409
3410
3411 \family default 
3412 \series default 
3413  there.
3414  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
3415 x).
3416  Using LyX 
3417 \begin_inset LatexCommand \url{www.lyx.org}
3418
3419 \end_inset 
3420
3421  as editor this is straightforward.
3422  If you want to avoid installing the tools you will have some success with
3423  a bootable Knoppix CD 
3424 \begin_inset LatexCommand \url{http://www.knoppix.net}
3425
3426 \end_inset 
3427
3428 .
3429  Prebuilt documentation in html and pdf format is available from 
3430 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3431
3432 \end_inset 
3433
3434 .
3435 \layout Section
3436
3437 Reading the Documentation
3438 \layout Standard
3439
3440 Currently reading the document in pdf format is recommended, as for unknown
3441  reason the hyperlinks are working there whereas in the html version they
3442  are not
3443 \begin_inset Foot
3444 collapsed false
3445
3446 \layout Standard
3447
3448 If you should know why please drop us a note
3449 \end_inset 
3450
3451 .
3452  You'll find the pdf version at 
3453 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
3454
3455 \end_inset 
3456
3457 .
3458 \newline 
3459 This documentation is in some aspects different from a commercial documentation:
3460  
3461 \layout Itemize
3462
3463 It tries to document SDCC for several processor architectures in one document
3464  (commercially these probably would be separate documents/products).
3465  This document
3466 \begin_inset LatexCommand \index{Status of documentation}
3467
3468 \end_inset 
3469
3470  currently matches SDCC for mcs51 and DS390 best and does give too few informati
3471 on about f.e.
3472  Z80, PIC14, PIC16 and HC08.
3473 \layout Itemize
3474
3475 There are many references pointing away from this documentation.
3476  Don't let this distract you.
3477  If there f.e.
3478  was a reference like 
3479 \begin_inset LatexCommand \url{www.opencores.org}
3480
3481 \end_inset 
3482
3483  together with a statement 
3484 \begin_inset Quotes sld
3485 \end_inset 
3486
3487 some processors which are targetted by SDCC can be implemented in a 
3488 \emph on 
3489 f
3490 \emph default 
3491 ield 
3492 \emph on 
3493 p
3494 \emph default 
3495 rogrammable 
3496 \emph on 
3497 g
3498 \emph default 
3499 ate 
3500 \emph on 
3501 a
3502 \emph default 
3503 rray
3504 \begin_inset LatexCommand \index{fpga (field programmable gate array)}
3505
3506 \end_inset 
3507
3508
3509 \begin_inset Quotes srd
3510 \end_inset 
3511
3512  we expect you to have a quick look there and come back.
3513  If you read this you are on the right track.
3514 \layout Itemize
3515
3516 Some sections attribute more space to problems, restrictions and warnings
3517  than to the solution.
3518 \layout Itemize
3519
3520 The installation section and the section about the debugger is intimidating.
3521 \layout Itemize
3522
3523 There are still lots of typos and there are more different writing styles
3524  than pictures.
3525 \layout Section
3526
3527 Testing the SDCC Compiler
3528 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
3529
3530 \end_inset 
3531
3532
3533 \layout Standard
3534
3535 The first thing you should do after installing your SDCC compiler is to
3536  see if it runs.
3537  Type 
3538 \family sans 
3539 \series bold 
3540 "sdcc -
3541 \begin_inset ERT
3542 status Collapsed
3543
3544 \layout Standard
3545
3546 \backslash 
3547 /
3548 \end_inset 
3549
3550 -version"
3551 \begin_inset LatexCommand \index{version}
3552
3553 \end_inset 
3554
3555
3556 \family default 
3557 \series default 
3558  at the prompt, and the program should run and tell you the version.
3559  If it doesn't run, or gives a message about not finding sdcc program, then
3560  you need to check over your installation.
3561  Make sure that the sdcc bin directory is in your executable search path
3562  defined by the PATH environment setting (
3563 \series medium 
3564 see 
3565 \series default 
3566 section 
3567 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3568
3569 \end_inset 
3570
3571 \SpecialChar ~
3572
3573 \series medium 
3574 Install trouble-shooting for suggestions
3575 \series default 
3576 ).
3577  Make sure that the sdcc program is in the bin folder, if not perhaps something
3578  did not install correctly.
3579 \newline 
3580
3581 \newline 
3582
3583 \series medium 
3584 SDCC 
3585 \series default 
3586 is commonly installed as described in section 
3587 \begin_inset Quotes sld
3588 \end_inset 
3589
3590 Install and search paths
3591 \begin_inset Quotes srd
3592 \end_inset 
3593
3594 .
3595 \newline 
3596
3597 \newline 
3598
3599 \series medium 
3600 Make sure the compiler works on a very simple example.
3601  Type in the following test.c program using your favorite 
3602 \series default 
3603 ASCII 
3604 \series medium 
3605 editor:
3606 \layout Verse
3607
3608
3609 \family typewriter 
3610 char test;
3611 \newline 
3612
3613 \newline 
3614 void main(void) {
3615 \newline 
3616 \SpecialChar ~
3617 \SpecialChar ~
3618 \SpecialChar ~
3619 \SpecialChar ~
3620 test=0;
3621 \newline 
3622 }
3623 \layout Standard
3624
3625
3626 \series medium 
3627 Compile this using the following command: 
3628 \family sans 
3629 \series bold 
3630 "sdcc -c test.c".
3631
3632 \family default 
3633 \series default 
3634  
3635 \series medium 
3636 If all goes well, the compiler will generate a test.asm and test.rel file.
3637  Congratulations, you've just compiled your first program with SDCC.
3638  We used the -c option to tell SDCC not to link the generated code, just
3639  to keep things simple for this step.
3640 \series default 
3641
3642 \newline 
3643
3644 \newline 
3645
3646 \series medium 
3647 The next step is to try it with the linker.
3648  Type in 
3649 \family sans 
3650 \series bold 
3651 "sdcc test.c
3652 \family default 
3653 \series default 
3654 "
3655 \series medium 
3656 .
3657  If all goes well the compiler will link with the libraries and produce
3658  a test.ihx output file.
3659  If this step fails
3660 \series default 
3661  
3662 \series medium 
3663 (no test.ihx, and the linker generates warnings), then the problem is most
3664  likely that 
3665 \series default 
3666 SDCC
3667 \series medium 
3668  cannot find the 
3669 \series default 
3670 /
3671 \series medium 
3672 usr/local/share/sdcc/lib directory
3673 \series default 
3674  
3675 \series medium 
3676 (see 
3677 \series default 
3678 section 
3679 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3680
3681 \end_inset 
3682
3683 \SpecialChar ~
3684
3685 \series medium 
3686 Install trouble-shooting for suggestions).
3687 \series default 
3688
3689 \newline 
3690
3691 \newline 
3692
3693 \series medium 
3694 The final test is to ensure 
3695 \series default 
3696 SDCC
3697 \series medium 
3698  can use the 
3699 \series default 
3700 standard
3701 \series medium 
3702  header files and libraries.
3703  Edit test.c and change it to the following:
3704 \layout Verse
3705
3706
3707 \family typewriter 
3708 #include <string.h>
3709 \newline 
3710
3711 \newline 
3712 char str1[10];
3713 \newline 
3714
3715 \newline 
3716 void main(void) {
3717 \newline 
3718 \SpecialChar ~
3719 \SpecialChar ~
3720 strcpy(str1, "testing");
3721 \newline 
3722 }
3723 \layout Standard
3724
3725
3726 \series medium 
3727 Compile this by typing 
3728 \family sans 
3729 \series bold 
3730 "sdcc test.c"
3731 \family default 
3732 \series medium 
3733 .
3734  This should generate a test.ihx output file, and it should give no warnings
3735  such as not finding the string.h file.
3736  If it cannot find the string.h file, then the problem is that 
3737 \series default 
3738 SDCC
3739 \series medium 
3740  cannot find the /usr/local/share/sdcc/include directory
3741 \series default 
3742  
3743 \series medium 
3744 (see the 
3745 \series default 
3746 section 
3747 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3748
3749 \end_inset 
3750
3751 \SpecialChar ~
3752
3753 \series medium 
3754 Install trouble-shooting section for suggestions).
3755
3756 \series default 
3757  Use option 
3758 \series bold 
3759 -
3760 \begin_inset ERT
3761 status Collapsed
3762
3763 \layout Standard
3764
3765 \backslash 
3766 /
3767 \end_inset 
3768
3769 -print-search-dirs
3770 \series default 
3771
3772 \begin_inset LatexCommand \index{-\/-print-search-dirs}
3773
3774 \end_inset 
3775
3776  to find exactly where SDCC is looking for the include and lib files.
3777 \layout Section
3778
3779 Install Trouble-shooting
3780 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
3781
3782 \end_inset 
3783
3784
3785 \begin_inset LatexCommand \index{Install trouble-shooting}
3786
3787 \end_inset 
3788
3789
3790 \layout Subsection
3791
3792 If SDCC does not build correctly
3793 \layout Standard
3794
3795 A thing to try is starting from scratch by unpacking the .tgz source package
3796  again in an empty directory.
3797  Configure it like:
3798 \newline 
3799
3800 \newline 
3801
3802 \family sans 
3803 \series bold 
3804 ./configure 2>&1 | tee configure.log
3805 \family default 
3806 \series default 
3807
3808 \newline 
3809
3810 \newline 
3811 and build it like:
3812 \newline 
3813
3814 \newline 
3815
3816 \family sans 
3817 \series bold 
3818 make 2>&1 | tee make.log
3819 \family default 
3820 \series default 
3821
3822 \newline 
3823
3824 \newline 
3825 If anything goes wrong, you can review the log files to locate the problem.
3826  Or a relevant part of this can be attached to an email that could be helpful
3827  when requesting help from the mailing list.
3828 \layout Subsection
3829
3830 What the 
3831 \begin_inset Quotes sld
3832 \end_inset 
3833
3834 ./configure
3835 \begin_inset Quotes srd
3836 \end_inset 
3837
3838  does
3839 \layout Standard
3840
3841 The 
3842 \begin_inset Quotes sld
3843 \end_inset 
3844
3845 ./configure
3846 \begin_inset Quotes srd
3847 \end_inset 
3848
3849  command is a script that analyzes your system and performs some configuration
3850  to ensure the source package compiles on your system.
3851  It will take a few minutes to run, and will compile a few tests to determine
3852  what compiler features are installed.
3853 \layout Subsection
3854
3855 What the 
3856 \begin_inset Quotes sld
3857 \end_inset 
3858
3859 make
3860 \begin_inset Quotes srd
3861 \end_inset 
3862
3863  does
3864 \layout Standard
3865
3866 This runs the GNU make tool, which automatically compiles all the source
3867  packages into the final installed binary executables.
3868 \layout Subsection
3869
3870 What the 
3871 \begin_inset Quotes sld
3872 \end_inset 
3873
3874 make install
3875 \begin_inset Quotes erd
3876 \end_inset 
3877
3878  command does.
3879 \layout Standard
3880
3881 This will install the compiler, other executables libraries and include
3882  files into the appropriate directories.
3883  See sections 
3884 \begin_inset LatexCommand \ref{sub:Install-paths}
3885
3886 \end_inset 
3887
3888 ,\SpecialChar ~
3889
3890 \begin_inset LatexCommand \ref{sub:Search-Paths}
3891
3892 \end_inset 
3893
3894 \SpecialChar ~
3895 about install and search paths.
3896 \newline 
3897 On most systems you will need super-user privileges to do this.
3898 \layout Section
3899
3900 Components of SDCC
3901 \layout Standard
3902
3903 SDCC is not just a compiler, but a collection of tools by various developers.
3904  These include linkers, assemblers, simulators and other components.
3905  Here is a summary of some of the components.
3906  Note that the included simulator and assembler have separate documentation
3907  which you can find in the source package in their respective directories.
3908  As SDCC grows to include support for other processors, other packages from
3909  various developers are included and may have their own sets of documentation.
3910 \newline 
3911
3912 \newline 
3913 You might want to look at the files which are installed in <installdir>.
3914  At the time of this writing, we find the following programs for gcc-builds:
3915 \newline 
3916  
3917 \newline 
3918 In <installdir>/bin:
3919 \layout Itemize
3920
3921 sdcc - The compiler.
3922 \layout Itemize
3923
3924 sdcpp - The C preprocessor.
3925 \layout Itemize
3926
3927 asx8051 - The assembler for 8051 type processors.
3928 \layout Itemize
3929
3930 as-z80
3931 \series bold 
3932
3933 \series default 
3934 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
3935 \layout Itemize
3936
3937 aslink -The linker for 8051 type processors.
3938 \layout Itemize
3939
3940 link-z80
3941 \series bold 
3942
3943 \series default 
3944 link-gbz80 - The Z80 and GameBoy Z80 linkers.
3945 \layout Itemize
3946
3947 s51 - The ucSim 8051 simulator.
3948 \layout Itemize
3949
3950 sdcdb - The source debugger.
3951 \layout Itemize
3952
3953 packihx - A tool to pack (compress) Intel hex files.
3954 \layout Standard
3955
3956 In <installdir>/share/sdcc/include
3957 \layout Itemize
3958
3959 the include files
3960 \layout Standard
3961
3962 In <installdir>/share/sdcc/lib
3963 \layout Itemize
3964
3965 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
3966  relocatables.
3967 \layout Standard
3968
3969 In <installdir>/share/sdcc/doc
3970 \layout Itemize
3971
3972 the documentation
3973 \layout Standard
3974
3975 As development for other processors proceeds, this list will expand to include
3976  executables to support processors like AVR, PIC, etc.
3977 \layout Subsection
3978
3979 sdcc - The Compiler
3980 \layout Standard
3981
3982 This is the actual compiler, it in turn uses the c-preprocessor and invokes
3983  the assembler and linkage editor.
3984 \layout Subsection
3985
3986 sdcpp - The C-Preprocessor
3987 \layout Standard
3988
3989 The preprocessor
3990 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
3991
3992 \end_inset 
3993
3994  is a modified version of the GNU preprocessor.
3995  The C preprocessor is used to pull in #include sources, process #ifdef
3996  statements, #defines and so on.
3997 \layout Subsection
3998
3999 as
4000 \emph on 
4001 xxxx
4002 \emph default 
4003 , aslink, link-
4004 \emph on 
4005 xxx
4006 \emph default 
4007  - The Assemblers and Linkage Editors
4008 \layout Standard
4009
4010 This is retargettable assembler & linkage editor, it was developed by Alan
4011  Baldwin.
4012  John Hartman created the version for 8051, and I (Sandeep) have made some
4013  enhancements and bug fixes for it to work properly with SDCC.
4014 \layout Subsection
4015
4016 s51 - The Simulator
4017 \layout Standard
4018
4019 S51
4020 \begin_inset LatexCommand \index{s51}
4021
4022 \end_inset 
4023
4024  is a freeware, opensource simulator developed by Daniel Drotos (
4025 \begin_inset LatexCommand \url{mailto:drdani@mazsola.iit.uni-miskolc.hu}
4026
4027 \end_inset 
4028
4029 ).
4030  The simulator is built as part of the build process.
4031  For more information visit Daniel's web site at: 
4032 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
4033
4034 \end_inset 
4035
4036 .
4037  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
4038  XA51 family.
4039 \layout Subsection
4040
4041 sdcdb - Source Level Debugger
4042 \layout Standard
4043
4044 Sdcdb
4045 \begin_inset LatexCommand \index{sdcdb (debugger)}
4046
4047 \end_inset 
4048
4049  is the companion source level debugger.
4050  More about sdcdb in section 
4051 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
4052
4053 \end_inset 
4054
4055 .
4056  The current version of the debugger uses Daniel's Simulator S51
4057 \begin_inset LatexCommand \index{s51}
4058
4059 \end_inset 
4060
4061 , but can be easily changed to use other simulators.
4062  
4063 \layout Chapter
4064
4065 Using SDCC
4066 \layout Section
4067
4068 Compiling
4069 \layout Subsection
4070
4071 Single Source File Projects
4072 \layout Standard
4073
4074 For single source file 8051 projects the process is very simple.
4075  Compile your programs with the following command 
4076 \family sans 
4077 \series bold 
4078 "sdcc sourcefile.c".
4079
4080 \family default 
4081 \series default 
4082  This will compile, assemble and link your source file.
4083  Output files are as follows:
4084 \layout Itemize
4085
4086 sourcefile.asm
4087 \begin_inset LatexCommand \index{<file>.asm}
4088
4089 \end_inset 
4090
4091  - Assembler source
4092 \begin_inset LatexCommand \index{Assembler source}
4093
4094 \end_inset 
4095
4096  file created by the compiler
4097 \layout Itemize
4098
4099 sourcefile.lst
4100 \begin_inset LatexCommand \index{<file>.lst}
4101
4102 \end_inset 
4103
4104  - Assembler listing
4105 \begin_inset LatexCommand \index{Assembler listing}
4106
4107 \end_inset 
4108
4109  file created by the Assembler
4110 \layout Itemize
4111
4112 sourcefile.rst
4113 \begin_inset LatexCommand \index{<file>.rst}
4114
4115 \end_inset 
4116
4117  - Assembler listing
4118 \begin_inset LatexCommand \index{Assembler listing}
4119
4120 \end_inset 
4121
4122  file updated with linkedit information, created by linkage editor
4123 \layout Itemize
4124
4125 sourcefile.sym
4126 \begin_inset LatexCommand \index{<file>.sym}
4127
4128 \end_inset 
4129
4130  - symbol listing
4131 \begin_inset LatexCommand \index{Symbol listing}
4132
4133 \end_inset 
4134
4135  for the sourcefile, created by the assembler
4136 \layout Itemize
4137
4138 sourcefile.rel
4139 \begin_inset LatexCommand \index{<file>.rel}
4140
4141 \end_inset 
4142
4143  or sourcefile.o
4144 \begin_inset LatexCommand \index{<file>.o}
4145
4146 \end_inset 
4147
4148  - Object file
4149 \begin_inset LatexCommand \index{Object file}
4150
4151 \end_inset 
4152
4153  created by the assembler, input to Linkage editor
4154 \layout Itemize
4155
4156 sourcefile.map
4157 \begin_inset LatexCommand \index{<file>.map}
4158
4159 \end_inset 
4160
4161  - The memory map
4162 \begin_inset LatexCommand \index{Memory map}
4163
4164 \end_inset 
4165
4166  for the load module, created by the Linker
4167 \layout Itemize
4168
4169 sourcefile.mem
4170 \begin_inset LatexCommand \index{<file>.mem}
4171
4172 \end_inset 
4173
4174  - A file with a summary of the memory usage
4175 \layout Itemize
4176
4177 sourcefile.ihx
4178 \begin_inset LatexCommand \index{<file>.ihx}
4179
4180 \end_inset 
4181
4182  - The load module in Intel hex format
4183 \begin_inset LatexCommand \index{Intel hex format}
4184
4185 \end_inset 
4186
4187  (you can select the Motorola S19 format
4188 \begin_inset LatexCommand \index{Motorola S19 format}
4189
4190 \end_inset 
4191
4192  with -
4193 \begin_inset ERT
4194 status Collapsed
4195
4196 \layout Standard
4197
4198 \backslash 
4199 /
4200 \end_inset 
4201
4202 -out-fmt-s19
4203 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
4204
4205 \end_inset 
4206
4207 .
4208  If you need another format you might want to use 
4209 \family sans 
4210 \shape italic 
4211 objdump
4212 \family default 
4213 \shape default 
4214
4215 \begin_inset LatexCommand \index{objdump (tool)}
4216
4217 \end_inset 
4218
4219  or
4220 \family sans 
4221 \shape italic 
4222  srecord
4223 \family default 
4224 \shape default 
4225
4226 \begin_inset LatexCommand \index{srecord (tool)}
4227
4228 \end_inset 
4229
4230 ).
4231  Both formats are documented in the documentation of srecord
4232 \begin_inset LatexCommand \index{srecord (tool)}
4233
4234 \end_inset 
4235
4236
4237 \layout Itemize
4238
4239 sourcefile.adb
4240 \begin_inset LatexCommand \index{<file>.adb}
4241
4242 \end_inset 
4243
4244  - An intermediate file containing debug information needed to create the
4245  .cdb file (with -
4246 \begin_inset ERT
4247 status Collapsed
4248
4249 \layout Standard
4250
4251 \backslash 
4252 /
4253 \end_inset 
4254
4255 -debug
4256 \begin_inset LatexCommand \index{-\/-debug}
4257
4258 \end_inset 
4259
4260
4261 \layout Itemize
4262
4263 sourcefile.cdb
4264 \begin_inset LatexCommand \index{<file>.cdb}
4265
4266 \end_inset 
4267
4268  - An optional file (with -
4269 \begin_inset ERT
4270 status Collapsed
4271
4272 \layout Standard
4273
4274 \backslash 
4275 /
4276 \end_inset 
4277
4278 -debug) containing debug information.
4279  The format is documented in cdbfileformat.pdf.
4280 \layout Itemize
4281
4282 sourcefile.
4283  - (no extension)
4284 \begin_inset LatexCommand \index{<file> (no extension)}
4285
4286 \end_inset 
4287
4288  An optional AOMF or AOMF51
4289 \begin_inset LatexCommand \index{AOMF, AOMF51}
4290
4291 \end_inset 
4292
4293  file containing debug information (generated with option -
4294 \begin_inset ERT
4295 status Collapsed
4296
4297 \layout Standard
4298
4299 \backslash 
4300 /
4301 \end_inset 
4302
4303 -debug).
4304  The (Intel)
4305 \emph on 
4306  a
4307 \emph default 
4308 bsolute 
4309 \emph on 
4310 o
4311 \emph default 
4312 bject 
4313 \emph on 
4314 m
4315 \emph default 
4316 odule 
4317 \emph on 
4318 f
4319 \emph default 
4320 ormat is commonly used by third party tools (debuggers
4321 \begin_inset LatexCommand \index{Debugger}
4322
4323 \end_inset 
4324
4325 , simulators, emulators)
4326 \layout Itemize
4327
4328 sourcefile.dump*
4329 \begin_inset LatexCommand \index{<file>.dump*}
4330
4331 \end_inset 
4332
4333  - Dump file to debug the compiler it self (generated with option -
4334 \begin_inset ERT
4335 status Collapsed
4336
4337 \layout Standard
4338
4339 \backslash 
4340 /
4341 \end_inset 
4342
4343 -dumpall) (see section 
4344 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
4345
4346 \end_inset 
4347
4348 \SpecialChar ~
4349  and section 
4350 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
4351
4352 \end_inset 
4353
4354 \SpecialChar ~
4355
4356 \begin_inset Quotes sld
4357 \end_inset 
4358
4359 Anatomy of the compiler
4360 \begin_inset Quotes srd
4361 \end_inset 
4362
4363 ).
4364 \layout Subsection
4365
4366 Projects with Multiple Source Files
4367 \layout Standard
4368
4369 SDCC can compile only ONE file at a time.
4370  Let us for example assume that you have a project containing the following
4371  files:
4372 \newline 
4373
4374 \newline 
4375 foo1.c (contains some functions)
4376 \newline 
4377 foo2.c (contains some more functions)
4378 \newline 
4379 foomain.c (contains more functions and the function main)
4380 \newline 
4381
4382 \size footnotesize 
4383
4384 \newline 
4385
4386 \size default 
4387 The first two files will need to be compiled separately with the commands:
4388 \size footnotesize 
4389  
4390 \size default 
4391
4392 \newline 
4393
4394 \newline 
4395
4396 \family sans 
4397 \series bold 
4398 sdcc\SpecialChar ~
4399 -c\SpecialChar ~
4400 foo1.c
4401 \family default 
4402 \series default 
4403 \size footnotesize 
4404
4405 \newline 
4406
4407 \family sans 
4408 \series bold 
4409 \size default 
4410 sdcc\SpecialChar ~
4411 -c\SpecialChar ~
4412 foo2.c
4413 \family default 
4414 \series default 
4415
4416 \newline 
4417
4418 \newline 
4419 Then compile the source file containing the 
4420 \emph on 
4421 main()
4422 \emph default 
4423  function and link
4424 \begin_inset LatexCommand \index{Linker}
4425
4426 \end_inset 
4427
4428  the files together with the following command: 
4429 \newline 
4430
4431 \newline 
4432
4433 \family sans 
4434 \series bold 
4435 sdcc\SpecialChar ~
4436 foomain.c\SpecialChar ~
4437 foo1.rel\SpecialChar ~
4438 foo2.rel
4439 \family default 
4440 \series default 
4441
4442 \begin_inset LatexCommand \index{<file>.rel}
4443
4444 \end_inset 
4445
4446
4447 \newline 
4448
4449 \newline 
4450 Alternatively, 
4451 \emph on 
4452 foomain.c 
4453 \emph default 
4454 can be separately compiled as well: 
4455 \family sans 
4456 \series bold 
4457
4458 \newline 
4459
4460 \newline 
4461 sdcc\SpecialChar ~
4462 -c\SpecialChar ~
4463 foomain.c
4464 \newline 
4465 sdcc foomain.rel foo1.rel foo2.rel
4466 \newline 
4467
4468 \newline 
4469
4470 \family default 
4471 \series default 
4472 The file containing the 
4473 \emph on 
4474 main()
4475 \emph default 
4476  function
4477 \emph on 
4478  
4479 \emph default 
4480 \noun on 
4481 must
4482 \noun default 
4483  be the 
4484 \noun on 
4485 first
4486 \noun default 
4487  file specified in the command line, since the linkage editor processes
4488  file in the order they are presented to it.
4489  The linker is invoked from SDCC using a script file with extension .lnk
4490 \begin_inset LatexCommand \index{<file>.lnk}
4491
4492 \end_inset 
4493
4494 .
4495  You can view this file to troubleshoot linking problems such as those arising
4496  from missing libraries.
4497 \layout Subsection
4498
4499 Projects with Additional Libraries
4500 \begin_inset LatexCommand \index{Libraries}
4501
4502 \end_inset 
4503
4504
4505 \layout Standard
4506
4507 Some reusable routines may be compiled into a library, see the documentation
4508  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
4509  for how to create a 
4510 \emph on 
4511 .lib
4512 \begin_inset LatexCommand \index{<file>.lib}
4513
4514 \end_inset 
4515
4516
4517 \emph default 
4518  library file.
4519  Libraries created in this manner can be included in the command line.
4520  Make sure you include the -L <library-path> option to tell the linker where
4521  to look for these files if they are not in the current directory.
4522  Here is an example, assuming you have the source file 
4523 \emph on 
4524 foomain.c
4525 \emph default 
4526  and a library
4527 \emph on 
4528  foolib.lib
4529 \emph default 
4530  in the directory 
4531 \emph on 
4532 mylib
4533 \emph default 
4534  (if that is not the same as your current project):
4535 \newline 
4536
4537 \newline 
4538
4539 \family sans 
4540 \series bold 
4541 sdcc foomain.c foolib.lib -L mylib
4542 \newline 
4543
4544 \newline 
4545
4546 \family default 
4547 \series default 
4548 Note here that
4549 \emph on 
4550  mylib
4551 \emph default 
4552  must be an absolute path name.
4553 \newline 
4554
4555 \newline 
4556 The most efficient way to use libraries is to keep separate modules in separate
4557  source files.
4558  The lib file now should name all the modules.rel
4559 \begin_inset LatexCommand \index{<file>.rel}
4560
4561 \end_inset 
4562
4563  files.
4564  For an example see the standard library file 
4565 \emph on 
4566 libsdcc.lib
4567 \emph default 
4568  in the directory <installdir>/share/lib/small.
4569 \layout Subsection
4570
4571 Using sdcclib to Create and Manage Libraries
4572 \begin_inset LatexCommand \index{sdcclib}
4573
4574 \end_inset 
4575
4576
4577 \layout Standard
4578
4579 Alternatively, instead of having a .rel file for each entry on the library
4580  file as described in the preceding section, sdcclib can be used to embed
4581  all the modules belonging to such library in the library file itself.
4582  This results in a larger library file, but it greatly reduces the number
4583  of disk files accessed by the linker.
4584   Additionally, the packed library file contains an index of all include
4585  modules and symbols that significantly speeds up the linking process.
4586  To display a list of options supported by sdcclib type:
4587 \newline 
4588
4589 \layout Standard
4590
4591
4592 \family sans 
4593 \series bold 
4594 sdcclib -?
4595 \begin_inset LatexCommand \index{sdcclib}
4596
4597 \end_inset 
4598
4599
4600 \newline 
4601
4602 \newline 
4603
4604 \family default 
4605 \series default 
4606 To create a new library file, start by compiling all the required modules.
4607  For example:
4608 \newline 
4609
4610 \layout Standard
4611
4612
4613 \series bold 
4614 sdcc -c _divsint.c
4615 \layout Standard
4616
4617
4618 \series bold 
4619 sdcc -c _divuint.c
4620 \layout Standard
4621
4622
4623 \series bold 
4624 sdcc -c _modsint.c
4625 \layout Standard
4626
4627
4628 \series bold 
4629 sdcc -c _moduint.c
4630 \layout Standard
4631
4632
4633 \series bold 
4634 sdcc -c _mulint.c
4635 \newline 
4636
4637 \layout Standard
4638
4639 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
4640  and _mulint.rel.
4641  The next step is to add the .rel files to the library file:
4642 \newline 
4643
4644 \layout Standard
4645
4646
4647 \series bold 
4648 sdcclib libint.lib _divsint.rel
4649 \begin_inset LatexCommand \index{sdcclib}
4650
4651 \end_inset 
4652
4653
4654 \layout Standard
4655
4656
4657 \series bold 
4658 sdcclib libint.lib _divuint.rel
4659 \layout Standard
4660
4661
4662 \series bold 
4663 sdcclib libint.lib _modsint.rel
4664 \layout Standard
4665
4666
4667 \series bold 
4668 sdcclib libint.lib _moduint.rel
4669 \layout Standard
4670
4671
4672 \series bold 
4673 sdcclib libint.lib _mulint.rel
4674 \series default 
4675
4676 \newline 
4677
4678 \layout Standard
4679
4680 If the file already exists in the library, it will be replaced.
4681  To see what modules and symbols are included in the library, options -s
4682  and -m are available.
4683  For example:
4684 \newline 
4685
4686 \newline 
4687
4688 \series bold 
4689 sdcclib -s libint.lib
4690 \begin_inset LatexCommand \index{sdcclib}
4691
4692 \end_inset 
4693
4694
4695 \newline 
4696 _divsint.rel:
4697 \layout Standard
4698
4699
4700 \series bold 
4701 __divsint_a_1_1
4702 \layout Standard
4703
4704
4705 \series bold 
4706 __divsint_PARM_2
4707 \layout Standard
4708
4709
4710 \series bold 
4711 __divsint
4712 \newline 
4713 _divuint.rel:
4714 \layout Standard
4715
4716
4717 \series bold 
4718 __divuint_a_1_1
4719 \layout Standard
4720
4721
4722 \series bold 
4723 __divuint_PARM_2
4724 \layout Standard
4725
4726
4727 \series bold 
4728 __divuint_reste_1_1
4729 \layout Standard
4730
4731
4732 \series bold 
4733 __divuint_count_1_1
4734 \layout Standard
4735
4736
4737 \series bold 
4738 __divuint
4739 \newline 
4740 _modsint.rel:
4741 \layout Standard
4742
4743
4744 \series bold 
4745 __modsint_a_1_1
4746 \layout Standard
4747
4748
4749 \series bold 
4750 __modsint_PARM_2
4751 \layout Standard
4752
4753
4754 \series bold 
4755 __modsint
4756 \newline 
4757 _moduint.rel:
4758 \layout Standard
4759
4760
4761 \series bold 
4762 __moduint_a_1_1
4763 \layout Standard
4764
4765
4766 \series bold 
4767 __moduint_PARM_2
4768 \layout Standard
4769
4770
4771 \series bold 
4772 __moduint_count_1_1
4773 \layout Standard
4774
4775
4776 \series bold 
4777 __moduint
4778 \newline 
4779 _mulint.rel:
4780 \layout Standard
4781
4782
4783 \series bold 
4784 __mulint_PARM_2
4785 \layout Standard
4786
4787
4788 \series bold 
4789 __mulint
4790 \newline 
4791
4792 \layout Standard
4793
4794 If the source files are compiled using --debug, the corresponding debug
4795  information file .adb will be include in the library file as well.
4796  The library files created with sdcclib are plain text files, so they can
4797  be viewed with a text editor.
4798  It is not recomended to modify a library file created with sdcclib using
4799  a text editor, as there are file indexes numbers located accross the file
4800  used by the linker to quickly locate the required module to link.
4801  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
4802  it can be safely deleted, since all the information required for linking
4803  is embedded in the library file itself.
4804  Library files created using sdcclib are used as described in the preceding
4805  sections.
4806 \layout Section
4807
4808 Command Line Options
4809 \begin_inset LatexCommand \index{Command Line Options}
4810
4811 \end_inset 
4812
4813
4814 \layout Subsection
4815
4816 Processor Selection Options
4817 \begin_inset LatexCommand \index{Options processor selection}
4818
4819 \end_inset 
4820
4821
4822 \begin_inset LatexCommand \index{Processor selection options}
4823
4824 \end_inset 
4825
4826
4827 \layout List
4828 \labelwidthstring 00.00.0000
4829
4830
4831 \series bold 
4832 -mmcs51
4833 \begin_inset LatexCommand \index{-mmcs51}
4834
4835 \end_inset 
4836
4837
4838 \series default 
4839  Generate code for the Intel MCS51
4840 \begin_inset LatexCommand \index{MCS51}
4841
4842 \end_inset 
4843
4844  family of processors.
4845  This is the default processor target.
4846 \layout List
4847 \labelwidthstring 00.00.0000
4848
4849
4850 \series bold 
4851 -mds390
4852 \begin_inset LatexCommand \index{-mds390}
4853
4854 \end_inset 
4855
4856
4857 \series default 
4858  Generate code for the Dallas DS80C390
4859 \begin_inset LatexCommand \index{DS80C390}
4860
4861 \end_inset 
4862
4863  processor.
4864 \layout List
4865 \labelwidthstring 00.00.0000
4866
4867
4868 \series bold 
4869 -mds400
4870 \begin_inset LatexCommand \index{-mds400}
4871
4872 \end_inset 
4873
4874
4875 \series default 
4876  Generate code for the Dallas DS80C400
4877 \begin_inset LatexCommand \index{DS80C400}
4878
4879 \end_inset 
4880
4881  processor.
4882 \layout List
4883 \labelwidthstring 00.00.0000
4884
4885
4886 \series bold 
4887 -mhc08
4888 \begin_inset LatexCommand \index{-mhc08}
4889
4890 \end_inset 
4891
4892
4893 \series default 
4894  Generate code for the Motorola HC08
4895 \begin_inset LatexCommand \index{HC08}
4896
4897 \end_inset 
4898
4899  family of processors (added Oct 2003).
4900 \layout List
4901 \labelwidthstring 00.00.0000
4902
4903
4904 \series bold 
4905 -mz80
4906 \begin_inset LatexCommand \index{-mz80}
4907
4908 \end_inset 
4909
4910
4911 \series default 
4912  Generate code for the Zilog Z80
4913 \begin_inset LatexCommand \index{Z80}
4914
4915 \end_inset 
4916
4917  family of processors.
4918 \layout List
4919 \labelwidthstring 00.00.0000
4920
4921
4922 \series bold 
4923 -mgbz80
4924 \begin_inset LatexCommand \index{-mgbz80}
4925
4926 \end_inset 
4927
4928
4929 \series default 
4930  Generate code for the GameBoy Z80
4931 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
4932
4933 \end_inset 
4934
4935  processor (Not actively maintained).
4936 \layout List
4937 \labelwidthstring 00.00.0000
4938
4939
4940 \series bold 
4941 -mavr
4942 \begin_inset LatexCommand \index{-mavr}
4943
4944 \end_inset 
4945
4946
4947 \series default 
4948  Generate code for the Atmel AVR
4949 \begin_inset LatexCommand \index{AVR}
4950
4951 \end_inset 
4952
4953  processor (In development, not complete).
4954  AVR users should probably have a look at avr-gcc 
4955 \begin_inset LatexCommand \url{ http://savannah.nongnu.org/download/avr-libc/snapshots/}
4956
4957 \end_inset 
4958
4959 .
4960 \layout Comment
4961
4962 I think it is fair to direct users there for now.
4963  Open source is also about avoiding unnecessary work .
4964  But I didn't find the 'official' link.
4965 \layout List
4966 \labelwidthstring 00.00.0000
4967
4968
4969 \series bold 
4970 -mpic14
4971 \begin_inset LatexCommand \index{-mpic14}
4972
4973 \end_inset 
4974
4975
4976 \series default 
4977  Generate code for the Microchip PIC 14
4978 \begin_inset LatexCommand \index{PIC14}
4979
4980 \end_inset 
4981
4982 -bit processors (p16f84 and variants.
4983  In development, not complete).
4984 \layout Comment
4985
4986 p16f627 p16f628 p16f84 p16f873 p16f877?
4987 \layout List
4988 \labelwidthstring 00.00.0000
4989
4990
4991 \series bold 
4992 -mpic16
4993 \begin_inset LatexCommand \index{-mpic16}
4994
4995 \end_inset 
4996
4997
4998 \series default 
4999  Generate code for the Microchip PIC 16
5000 \begin_inset LatexCommand \index{PIC16}
5001
5002 \end_inset 
5003
5004 -bit processors (p18f452 and variants.
5005  In development, not complete).
5006 \layout List
5007 \labelwidthstring 00.00.0000
5008
5009
5010 \series bold 
5011 -mtlcs900h
5012 \series default 
5013  Generate code for the Toshiba TLCS-900H
5014 \begin_inset LatexCommand \index{TLCS-900H}
5015
5016 \end_inset 
5017
5018  processor (Not maintained, not complete).
5019 \layout List
5020 \labelwidthstring 00.00.0000
5021
5022
5023 \series bold 
5024 -mxa51
5025 \begin_inset LatexCommand \index{-mxa51}
5026
5027 \end_inset 
5028
5029
5030 \series default 
5031  Generate code for the Phillips XA51
5032 \begin_inset LatexCommand \index{XA51}
5033
5034 \end_inset 
5035
5036  processor (Not maintained, not complete).
5037 \layout Subsection
5038
5039 Preprocessor Options
5040 \begin_inset LatexCommand \index{Options preprocessor}
5041
5042 \end_inset 
5043
5044
5045 \begin_inset LatexCommand \index{Preprocessor options}
5046
5047 \end_inset 
5048
5049
5050 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5051
5052 \end_inset 
5053
5054
5055 \layout List
5056 \labelwidthstring 00.00.0000
5057
5058
5059 \series bold 
5060 -I<path>
5061 \begin_inset LatexCommand \index{-I<path>}
5062
5063 \end_inset 
5064
5065
5066 \series default 
5067  The additional location where the pre processor will look for <..h> or 
5068 \begin_inset Quotes eld
5069 \end_inset 
5070
5071 ..h
5072 \begin_inset Quotes erd
5073 \end_inset 
5074
5075  files.
5076 \layout List
5077 \labelwidthstring 00.00.0000
5078
5079
5080 \series bold 
5081 -D<macro[=value]>
5082 \begin_inset LatexCommand \index{-D<macro[=value]>}
5083
5084 \end_inset 
5085
5086
5087 \series default 
5088  Command line definition of macros.
5089  Passed to the preprocessor.
5090 \layout List
5091 \labelwidthstring 00.00.0000
5092
5093
5094 \series bold 
5095 -M
5096 \begin_inset LatexCommand \index{-M}
5097
5098 \end_inset 
5099
5100
5101 \series default 
5102  Tell the preprocessor to output a rule suitable for make describing the
5103  dependencies of each object file.
5104  For each source file, the preprocessor outputs one make-rule whose target
5105  is the object file name for that source file and whose dependencies are
5106  all the files `#include'd in it.
5107  This rule may be a single line or may be continued with `
5108 \backslash 
5109 '-newline if it is long.
5110  The list of rules is printed on standard output instead of the preprocessed
5111  C program.
5112  `-M' implies `-E
5113 \begin_inset LatexCommand \index{-E}
5114
5115 \end_inset 
5116
5117 '.
5118 \layout List
5119 \labelwidthstring 00.00.0000
5120
5121
5122 \series bold 
5123 -C
5124 \begin_inset LatexCommand \index{-C}
5125
5126 \end_inset 
5127
5128
5129 \series default 
5130  Tell the preprocessor not to discard comments.
5131  Used with the `-E' option.
5132 \layout List
5133 \labelwidthstring 00.00.0000
5134
5135
5136 \series bold 
5137 -MM
5138 \begin_inset LatexCommand \index{-MM}
5139
5140 \end_inset 
5141
5142
5143 \size large 
5144 \bar under 
5145  
5146 \series default 
5147 \size default 
5148 \bar default 
5149 Like `-M' but the output mentions only the user header files included with
5150  `#include 
5151 \begin_inset Quotes eld
5152 \end_inset 
5153
5154 file"'.
5155  System header files included with `#include <file>' are omitted.
5156 \layout List
5157 \labelwidthstring 00.00.0000
5158
5159
5160 \series bold 
5161 -Aquestion(answer)
5162 \begin_inset LatexCommand \index{-Aquestion(answer)}
5163
5164 \end_inset 
5165
5166
5167 \series default 
5168  Assert the answer answer for question, in case it is tested with a preprocessor
5169  conditional such as `#if #question(answer)'.
5170  `-A-' disables the standard assertions that normally describe the target
5171  machine.
5172 \layout List
5173 \labelwidthstring 00.00.0000
5174
5175
5176 \series bold 
5177 -Umacro
5178 \begin_inset LatexCommand \index{-Umacro}
5179
5180 \end_inset 
5181
5182
5183 \series default 
5184  Undefine macro macro.
5185  `-U' options are evaluated after all `-D' options, but before any `-include'
5186  and `-imacros' options.
5187 \layout List
5188 \labelwidthstring 00.00.0000
5189
5190
5191 \series bold 
5192 -dM
5193 \begin_inset LatexCommand \index{-dM}
5194
5195 \end_inset 
5196
5197
5198 \series default 
5199  Tell the preprocessor to output only a list of the macro definitions that
5200  are in effect at the end of preprocessing.
5201  Used with the `-E' option.
5202 \layout List
5203 \labelwidthstring 00.00.0000
5204
5205
5206 \series bold 
5207 -dD
5208 \begin_inset LatexCommand \index{-dD}
5209
5210 \end_inset 
5211
5212
5213 \series default 
5214  Tell the preprocessor to pass all macro definitions into the output, in
5215  their proper sequence in the rest of the output.
5216 \layout List
5217 \labelwidthstring 00.00.0000
5218
5219
5220 \series bold 
5221 -dN
5222 \begin_inset LatexCommand \index{-dN}
5223
5224 \end_inset 
5225
5226
5227 \size large 
5228 \bar under 
5229  
5230 \series default 
5231 \size default 
5232 \bar default 
5233 Like `-dD' except that the macro arguments and contents are omitted.
5234  Only `#define name' is included in the output.
5235 \layout List
5236 \labelwidthstring 00.00.0000
5237
5238
5239 \series bold 
5240 -Wp\SpecialChar ~
5241 preprocessorOption[,preprocessorOption]
5242 \series default 
5243
5244 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
5245
5246 \end_inset 
5247
5248 ...
5249  Pass the preprocessorOption to the preprocessor 
5250 \family typewriter 
5251 sdcpp
5252 \family default 
5253
5254 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5255
5256 \end_inset 
5257
5258 .
5259  SDCC uses an adapted version of the preprocessor cpp of the GNU Compiler
5260  Collection (gcc), if you need more dedicated options please refer to the
5261  documentation at 
5262 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
5263
5264 \end_inset 
5265
5266 .
5267 \layout Subsection
5268
5269 Linker Options
5270 \begin_inset LatexCommand \index{Options linker}
5271
5272 \end_inset 
5273
5274
5275 \begin_inset LatexCommand \index{Linker options}
5276
5277 \end_inset 
5278
5279
5280 \layout List
5281 \labelwidthstring 00.00.0000
5282
5283
5284 \series bold 
5285 -L\SpecialChar ~
5286 -
5287 \series default 
5288
5289 \begin_inset ERT
5290 status Collapsed
5291
5292 \layout Standard
5293
5294 \backslash 
5295 /
5296 \end_inset 
5297
5298
5299 \series bold 
5300 -lib-path
5301 \begin_inset LatexCommand \index{-\/-lib-path <path>}
5302
5303 \end_inset 
5304
5305
5306 \begin_inset LatexCommand \index{-L -\/-lib-path}
5307
5308 \end_inset 
5309
5310
5311 \series default 
5312 \SpecialChar ~
5313 <absolute path to additional libraries> This option is passed to the linkage
5314  editor's additional libraries
5315 \begin_inset LatexCommand \index{Libraries}
5316
5317 \end_inset 
5318
5319  search path.
5320  The path name must be absolute.
5321  Additional library files may be specified in the command line.
5322  See section Compiling programs for more details.
5323 \layout List
5324 \labelwidthstring 00.00.0000
5325
5326
5327 \series bold 
5328 -
5329 \begin_inset ERT
5330 status Collapsed
5331
5332 \layout Standard
5333
5334 \backslash 
5335 /
5336 \end_inset 
5337
5338 -xram-loc
5339 \series default 
5340
5341 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
5342
5343 \end_inset 
5344
5345 \SpecialChar ~
5346 <Value> The start location of the external ram
5347 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
5348
5349 \end_inset 
5350
5351 , default value is 0.
5352  The value entered can be in Hexadecimal or Decimal format, e.g.: -
5353 \begin_inset ERT
5354 status Collapsed
5355
5356 \layout Standard
5357
5358 \backslash 
5359 /
5360 \end_inset 
5361
5362 -xram-loc 0x8000 or -
5363 \begin_inset ERT
5364 status Collapsed
5365
5366 \layout Standard
5367
5368 \backslash 
5369 /
5370 \end_inset 
5371
5372 -xram-loc 32768.
5373 \layout List
5374 \labelwidthstring 00.00.0000
5375
5376
5377 \series bold 
5378 -
5379 \begin_inset ERT
5380 status Collapsed
5381
5382 \layout Standard
5383
5384 \backslash 
5385 /
5386 \end_inset 
5387
5388 -code-loc
5389 \series default 
5390
5391 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
5392
5393 \end_inset 
5394
5395 \SpecialChar ~
5396 <Value> The start location of the code
5397 \begin_inset LatexCommand \index{code}
5398
5399 \end_inset 
5400
5401  segment, default value 0.
5402  Note when this option is used the interrupt vector table is also relocated
5403  to the given address.
5404  The value entered can be in Hexadecimal or Decimal format, e.g.: -
5405 \begin_inset ERT
5406 status Collapsed
5407
5408 \layout Standard
5409
5410 \backslash 
5411 /
5412 \end_inset 
5413
5414 -code-loc 0x8000 or -
5415 \begin_inset ERT
5416 status Collapsed
5417
5418 \layout Standard
5419
5420 \backslash 
5421 /
5422 \end_inset 
5423
5424 -code-loc 32768.
5425 \layout List
5426 \labelwidthstring 00.00.0000
5427
5428
5429 \series bold 
5430 -
5431 \begin_inset ERT
5432 status Collapsed
5433
5434 \layout Standard
5435
5436 \backslash 
5437 /
5438 \end_inset 
5439
5440 -stack-loc
5441 \series default 
5442
5443 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
5444
5445 \end_inset 
5446
5447 \SpecialChar ~
5448 <Value> By default the stack
5449 \begin_inset LatexCommand \index{stack}
5450
5451 \end_inset 
5452
5453  is placed after the data segment.
5454  Using this option the stack can be placed anywhere in the internal memory
5455  space of the 8051.
5456  The value entered can be in Hexadecimal or Decimal format, e.g.
5457  -
5458 \begin_inset ERT
5459 status Collapsed
5460
5461 \layout Standard
5462
5463 \backslash 
5464 /
5465 \end_inset 
5466
5467 -stack-loc 0x20 or -
5468 \begin_inset ERT
5469 status Collapsed
5470
5471 \layout Standard
5472
5473 \backslash 
5474 /
5475 \end_inset 
5476
5477 -stack-loc 32.
5478  Since the sp register is incremented before a push or call, the initial
5479  sp will be set to one byte prior the provided value.
5480  The provided value should not overlap any other memory areas such as used
5481  register banks or the data segment and with enough space for the current
5482  application.
5483 \layout List
5484 \labelwidthstring 00.00.0000
5485
5486
5487 \series bold 
5488 -
5489 \begin_inset ERT
5490 status Collapsed
5491
5492 \layout Standard
5493
5494 \backslash 
5495 /
5496 \end_inset 
5497
5498 -data-loc
5499 \series default 
5500
5501 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
5502
5503 \end_inset 
5504
5505 \SpecialChar ~
5506 <Value> The start location of the internal ram data
5507 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
5508
5509 \end_inset 
5510
5511  segment.
5512  The value entered can be in Hexadecimal or Decimal format, eg.
5513  -
5514 \begin_inset ERT
5515 status Collapsed
5516
5517 \layout Standard
5518
5519 \backslash 
5520 /
5521 \end_inset 
5522
5523 -data-loc 0x20 or -
5524 \begin_inset ERT
5525 status Collapsed
5526
5527 \layout Standard
5528
5529 \backslash 
5530 /
5531 \end_inset 
5532
5533 -data-loc 32.
5534  (By default, the start location of the internal ram data segment  is set
5535  as low as possible in memory, taking into account the used register banks
5536  and the bit segment at address 0x20.
5537  For example if register banks 0 and 1 are used without bit variables, the
5538  data segment will be set, if -
5539 \begin_inset ERT
5540 status Collapsed
5541
5542 \layout Standard
5543
5544 \backslash 
5545 /
5546 \end_inset 
5547
5548 -data-loc is not used, to location 0x10.)
5549 \layout List
5550 \labelwidthstring 00.00.0000
5551
5552
5553 \series bold 
5554 -
5555 \begin_inset ERT
5556 status Collapsed
5557
5558 \layout Standard
5559
5560 \backslash 
5561 /
5562 \end_inset 
5563
5564 -idata-loc
5565 \series default 
5566
5567 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
5568
5569 \end_inset 
5570
5571 \SpecialChar ~
5572 <Value> The start location of the indirectly addressable internal ram
5573 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
5574
5575 \end_inset 
5576
5577  of the 8051, default value is 0x80.
5578  The value entered can be in Hexadecimal or Decimal format, eg.
5579  -
5580 \begin_inset ERT
5581 status Collapsed
5582
5583 \layout Standard
5584
5585 \backslash 
5586 /
5587 \end_inset 
5588
5589 -idata-loc 0x88 or -
5590 \begin_inset ERT
5591 status Collapsed
5592
5593 \layout Standard
5594
5595 \backslash 
5596 /
5597 \end_inset 
5598
5599 -idata-loc 136.
5600 \layout List
5601 \labelwidthstring 00.00.0000
5602
5603
5604 \series bold 
5605 -
5606 \begin_inset ERT
5607 status Collapsed
5608
5609 \layout Standard
5610
5611 \backslash 
5612 /
5613 \end_inset 
5614
5615 -bit-loc
5616 \series default 
5617 \SpecialChar ~
5618 <Value> The start location of the bit
5619 \begin_inset LatexCommand \index{bit}
5620
5621 \end_inset 
5622
5623  addressable internal ram of the 8051.
5624  This is 
5625 \emph on 
5626 not
5627 \emph default 
5628  implemented yet.
5629  Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
5630 -bBSEG=<Value>.
5631 \layout List
5632 \labelwidthstring 00.00.0000
5633
5634
5635 \series bold 
5636 -
5637 \begin_inset ERT
5638 status Collapsed
5639
5640 \layout Standard
5641
5642 \backslash 
5643 /
5644 \end_inset 
5645
5646 -out-fmt-ihx
5647 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
5648
5649 \end_inset 
5650
5651
5652 \bar under 
5653  
5654 \series default 
5655 \bar default 
5656 The linker output (final object code) is in Intel Hex format.
5657 \begin_inset LatexCommand \index{Intel hex format}
5658
5659 \end_inset 
5660
5661  This is the default option.
5662  The format itself is documented in the documentation of srecord
5663 \begin_inset LatexCommand \index{srecord (tool)}
5664
5665 \end_inset 
5666
5667 .
5668 \layout List
5669 \labelwidthstring 00.00.0000
5670
5671
5672 \series bold 
5673 -
5674 \begin_inset ERT
5675 status Collapsed
5676
5677 \layout Standard
5678
5679 \backslash 
5680 /
5681 \end_inset 
5682
5683 -out-fmt-s19
5684 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5685
5686 \end_inset 
5687
5688
5689 \bar under 
5690  
5691 \series default 
5692 \bar default 
5693 The linker output (final object code) is in Motorola S19 format
5694 \begin_inset LatexCommand \index{Motorola S19 format}
5695
5696 \end_inset 
5697
5698 .
5699  The format itself is documented in the documentation of srecord.
5700 \layout List
5701 \labelwidthstring 00.00.0000
5702
5703
5704 \series bold 
5705 -Wl\SpecialChar ~
5706 linkOption[,linkOption]
5707 \series default 
5708
5709 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
5710
5711 \end_inset 
5712
5713 ...
5714  Pass the linkOption to the linker.
5715  See file sdcc/as/doc/asxhtm.html for more on linker options.
5716 \layout Subsection
5717
5718 MCS51 Options
5719 \begin_inset LatexCommand \index{Options MCS51}
5720
5721 \end_inset 
5722
5723
5724 \begin_inset LatexCommand \index{MCS51 options}
5725
5726 \end_inset 
5727
5728
5729 \layout List
5730 \labelwidthstring 00.00.0000
5731
5732
5733 \series bold 
5734 -
5735 \begin_inset ERT
5736 status Collapsed
5737
5738 \layout Standard
5739
5740 \backslash 
5741 /
5742 \end_inset 
5743
5744 -model-small
5745 \begin_inset LatexCommand \index{-\/-model-small}
5746
5747 \end_inset 
5748
5749
5750 \series default 
5751 \size large 
5752 \emph on 
5753  
5754 \size default 
5755 \emph default 
5756 Generate code for Small Model programs, see section Memory Models for more
5757  details.
5758  This is the default model.
5759 \layout List
5760 \labelwidthstring 00.00.0000
5761
5762
5763 \series bold 
5764 -
5765 \begin_inset ERT
5766 status Collapsed
5767
5768 \layout Standard
5769
5770 \backslash 
5771 /
5772 \end_inset 
5773
5774 -model-large
5775 \begin_inset LatexCommand \index{-\/-model-large}
5776
5777 \end_inset 
5778
5779
5780 \series default 
5781  Generate code for Large model programs, see section Memory Models for more
5782  details.
5783  If this option is used all source files in the project have to be compiled
5784  with this option.
5785 \layout List
5786 \labelwidthstring 00.00.0000
5787
5788
5789 \series bold 
5790 -
5791 \begin_inset ERT
5792 status Collapsed
5793
5794 \layout Standard
5795
5796 \backslash 
5797 /
5798 \end_inset 
5799
5800 -xstack
5801 \begin_inset LatexCommand \index{-\/-xstack}
5802
5803 \end_inset 
5804
5805
5806 \series default 
5807  Uses a pseudo stack in the first 256 bytes in the external ram for allocating
5808  variables and passing parameters.
5809  See section 
5810 \begin_inset LatexCommand \ref{sub:External-Stack}
5811
5812 \end_inset 
5813
5814 \SpecialChar ~
5815  External Stack for more details.
5816 \layout List
5817 \labelwidthstring 00.00.0000
5818
5819
5820 \series bold 
5821 -
5822 \begin_inset ERT
5823 status Collapsed
5824
5825 \layout Standard
5826
5827 \backslash 
5828 /
5829 \end_inset 
5830
5831 -iram-size
5832 \series default 
5833 \SpecialChar ~
5834 <Value>
5835 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
5836
5837 \end_inset 
5838
5839  Causes the linker to check if the internal ram usage is within limits of
5840  the given value.
5841 \layout List
5842 \labelwidthstring 00.00.0000
5843
5844
5845 \series bold 
5846 -
5847 \begin_inset ERT
5848 status Collapsed
5849
5850 \layout Standard
5851
5852 \backslash 
5853 /
5854 \end_inset 
5855
5856 -xram-size
5857 \series default 
5858 \SpecialChar ~
5859 <Value>
5860 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
5861
5862 \end_inset 
5863
5864  Causes the linker to check if the external ram usage is within limits of
5865  the given value.
5866 \layout List
5867 \labelwidthstring 00.00.0000
5868
5869
5870 \series bold 
5871 -
5872 \begin_inset ERT
5873 status Collapsed
5874
5875 \layout Standard
5876
5877 \backslash 
5878 /
5879 \end_inset 
5880
5881 -code-size
5882 \series default 
5883 \SpecialChar ~
5884 <Value>
5885 \begin_inset LatexCommand \index{-\/-code-size <Value>}
5886
5887 \end_inset 
5888
5889  Causes the linker to check if the code memory usage is within limits of
5890  the given value.
5891 \layout List
5892 \labelwidthstring 00.00.0000
5893
5894
5895 \series bold 
5896 -
5897 \begin_inset ERT
5898 status Collapsed
5899
5900 \layout Standard
5901
5902 \backslash 
5903 /
5904 \end_inset 
5905
5906 -stack-size
5907 \series default 
5908 \SpecialChar ~
5909 <Value>
5910 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
5911
5912 \end_inset 
5913
5914  Causes the linker to check if there is at minimum <Value> bytes for stack.
5915 \layout List
5916 \labelwidthstring 00.00.0000
5917
5918
5919 \series bold 
5920 -
5921 \begin_inset ERT
5922 status Collapsed
5923
5924 \layout Standard
5925
5926 \backslash 
5927 /
5928 \end_inset 
5929
5930 -pack-iram
5931 \series default 
5932 \SpecialChar ~
5933
5934 \begin_inset LatexCommand \index{-\/-pack-iram}
5935
5936 \end_inset 
5937
5938  Causes the linker use unused register banks for data variables or stack.
5939 \layout Subsection
5940
5941 DS390 / DS400 Options
5942 \begin_inset LatexCommand \index{Options DS390}
5943
5944 \end_inset 
5945
5946
5947 \begin_inset LatexCommand \index{DS390 options}
5948
5949 \end_inset 
5950
5951
5952 \layout List
5953 \labelwidthstring 00.00.0000
5954
5955
5956 \series bold 
5957 -
5958 \begin_inset ERT
5959 status Collapsed
5960
5961 \layout Standard
5962
5963 \backslash 
5964 /
5965 \end_inset 
5966
5967 -model-flat24
5968 \series default 
5969
5970 \begin_inset LatexCommand \index{-\/-model-flat24}
5971
5972 \end_inset 
5973
5974
5975 \size large 
5976 \emph on 
5977  
5978 \size default 
5979 \emph default 
5980 Generate 24-bit flat mode code.
5981  This is the one and only that the ds390 code generator supports right now
5982  and is default when using 
5983 \emph on 
5984 -mds390
5985 \emph default 
5986 .
5987  See section Memory Models for more details.
5988 \layout List
5989 \labelwidthstring 00.00.0000
5990
5991
5992 \series bold 
5993 -
5994 \begin_inset ERT
5995 status Collapsed
5996
5997 \layout Standard
5998
5999 \backslash 
6000 /
6001 \end_inset 
6002
6003 -protect-sp-update
6004 \begin_inset LatexCommand \index{-\/-protect-sp-update}
6005
6006 \end_inset 
6007
6008
6009 \series default 
6010  disable interrupts during ESP:SP updates.
6011 \layout List
6012 \labelwidthstring 00.00.0000
6013
6014
6015 \series bold 
6016 -
6017 \begin_inset ERT
6018 status Collapsed
6019
6020 \layout Standard
6021
6022 \backslash 
6023 /
6024 \end_inset 
6025
6026 -stack-10bit
6027 \series default 
6028
6029 \begin_inset LatexCommand \index{-\/-stack-10bit}
6030
6031 \end_inset 
6032
6033  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
6034  This is the one and only that the ds390 code generator supports right now
6035  and is default when using 
6036 \emph on 
6037 -mds390
6038 \emph default 
6039 .
6040  In this mode, the stack is located in the lower 1K of the internal RAM,
6041  which is mapped to 0x400000.
6042  Note that the support is incomplete, since it still uses a single byte
6043  as the stack pointer.
6044  This means that only the lower 256 bytes of the potential 1K stack space
6045  will actually be used.
6046  However, this does allow you to reclaim the precious 256 bytes of low RAM
6047  for use for the DATA and IDATA segments.
6048  The compiler will not generate any code to put the processor into 10 bit
6049  stack mode.
6050  It is important to ensure that the processor is in this mode before calling
6051  any re-entrant functions compiled with this option.
6052  In principle, this should work with the 
6053 \emph on 
6054 -
6055 \begin_inset ERT
6056 status Collapsed
6057
6058 \layout Standard
6059
6060 \backslash 
6061 /
6062 \end_inset 
6063
6064 -stack-auto
6065 \begin_inset LatexCommand \index{-\/-stack-auto}
6066
6067 \end_inset 
6068
6069
6070 \emph default 
6071  option, but that has not been tested.
6072  It is incompatible with the 
6073 \emph on 
6074 -
6075 \begin_inset ERT
6076 status Collapsed
6077
6078 \layout Standard
6079
6080 \backslash 
6081 /
6082 \end_inset 
6083
6084 -xstack
6085 \begin_inset LatexCommand \index{-\/-xstack}
6086
6087 \end_inset 
6088
6089
6090 \emph default 
6091  option.
6092  It also only makes sense if the processor is in 24 bit contiguous addressing
6093  mode (see the 
6094 \emph on 
6095 -
6096 \begin_inset ERT
6097 status Collapsed
6098
6099 \layout Standard
6100
6101 \backslash 
6102 /
6103 \end_inset 
6104
6105 -model-flat24 option
6106 \emph default 
6107 ).
6108 \layout List
6109 \labelwidthstring 00.00.0000
6110
6111
6112 \series bold 
6113 -
6114 \begin_inset ERT
6115 status Collapsed
6116
6117 \layout Standard
6118
6119 \backslash 
6120 /
6121 \end_inset 
6122
6123 -stack-probe
6124 \begin_inset LatexCommand \index{-\/-stack-probe}
6125
6126 \end_inset 
6127
6128
6129 \series default 
6130  insert call to function __stack_probe at each function prologue.
6131 \layout List
6132 \labelwidthstring 00.00.0000
6133
6134
6135 \series bold 
6136 -
6137 \begin_inset ERT
6138 status Collapsed
6139
6140 \layout Standard
6141
6142 \backslash 
6143 /
6144 \end_inset 
6145
6146 -tini-libid
6147 \begin_inset LatexCommand \index{-\/-tini-libid}
6148
6149 \end_inset 
6150
6151
6152 \series default 
6153  <nnnn> LibraryID used in -mTININative.
6154  
6155 \layout List
6156 \labelwidthstring 00.00.0000
6157
6158
6159 \series bold 
6160 -
6161 \begin_inset ERT
6162 status Collapsed
6163
6164 \layout Standard
6165
6166 \backslash 
6167 /
6168 \end_inset 
6169
6170 -use-accelerator
6171 \begin_inset LatexCommand \index{-\/-use-accelerator}
6172
6173 \end_inset 
6174
6175
6176 \series default 
6177  generate code for DS390 Arithmetic Accelerator.
6178  
6179 \layout Subsection
6180
6181 Z80 Options
6182 \begin_inset LatexCommand \index{Options Z80}
6183
6184 \end_inset 
6185
6186
6187 \begin_inset LatexCommand \index{Z80 options}
6188
6189 \end_inset 
6190
6191
6192 \layout List
6193 \labelwidthstring 00.00.0000
6194
6195
6196 \series bold 
6197 -
6198 \begin_inset ERT
6199 status Collapsed
6200
6201 \layout Standard
6202
6203 \backslash 
6204 /
6205 \end_inset 
6206
6207 -callee-saves-bc
6208 \series default 
6209
6210 \begin_inset LatexCommand \index{-\/-callee-saves-bc}
6211
6212 \end_inset 
6213
6214
6215 \size large 
6216 \emph on 
6217  
6218 \size default 
6219 \emph default 
6220 Force a called function to always save BC.
6221 \layout List
6222 \labelwidthstring 00.00.0000
6223
6224
6225 \series bold 
6226 -
6227 \begin_inset ERT
6228 status Collapsed
6229
6230 \layout Standard
6231
6232 \backslash 
6233 /
6234 \end_inset 
6235
6236 -no-std-crt0
6237 \series default 
6238
6239 \begin_inset LatexCommand \index{-\/-no-std-crt0}
6240
6241 \end_inset 
6242
6243  When linking, skip the standard crt0.o object file.
6244  You must provide your own crt0.o for your system when linking.
6245  
6246 \layout Subsection
6247
6248 Optimization Options
6249 \begin_inset LatexCommand \index{Options optimization}
6250
6251 \end_inset 
6252
6253
6254 \begin_inset LatexCommand \index{Optimization options}
6255
6256 \end_inset 
6257
6258
6259 \layout List
6260 \labelwidthstring 00.00.0000
6261
6262
6263 \series bold 
6264 -
6265 \begin_inset ERT
6266 status Collapsed
6267
6268 \layout Standard
6269
6270 \backslash 
6271 /
6272 \end_inset 
6273
6274 -nogcse
6275 \begin_inset LatexCommand \index{-\/-nogcse}
6276
6277 \end_inset 
6278
6279
6280 \series default 
6281  Will not do global subexpression elimination, this option may be used when
6282  the compiler creates undesirably large stack/data spaces to store compiler
6283  temporaries.
6284  A warning message will be generated when this happens and the compiler
6285  will indicate the number of extra bytes it allocated.
6286  It is recommended that this option NOT be used, #pragma\SpecialChar ~
6287 nogcse
6288 \begin_inset LatexCommand \index{\#pragma nogcse}
6289
6290 \end_inset 
6291
6292  can be used to turn off global subexpression elimination
6293 \begin_inset LatexCommand \index{Subexpression elimination}
6294
6295 \end_inset 
6296
6297  for a given function only.
6298 \layout List
6299 \labelwidthstring 00.00.0000
6300
6301
6302 \series bold 
6303 -
6304 \begin_inset ERT
6305 status Collapsed
6306
6307 \layout Standard
6308
6309 \backslash 
6310 /
6311 \end_inset 
6312
6313 -noinvariant
6314 \begin_inset LatexCommand \index{-\/-noinvariant}
6315
6316 \end_inset 
6317
6318
6319 \series default 
6320  Will not do loop invariant optimizations, this may be turned off for reasons
6321  explained for the previous option.
6322  For more details of loop optimizations performed see section Loop Invariants.
6323  It is recommended that this option NOT be used, #pragma\SpecialChar ~
6324 noinvariant
6325 \begin_inset LatexCommand \index{\#pragma noinvariant}
6326
6327 \end_inset 
6328
6329  can be used to turn off invariant optimizations for a given function only.
6330 \layout List
6331 \labelwidthstring 00.00.0000
6332
6333
6334 \series bold 
6335 -
6336 \begin_inset ERT
6337 status Collapsed
6338
6339 \layout Standard
6340
6341 \backslash 
6342 /
6343 \end_inset 
6344
6345 -noinduction
6346 \begin_inset LatexCommand \index{-\/-noinduction}
6347
6348 \end_inset 
6349
6350
6351 \series default 
6352  Will not do loop induction optimizations, see section strength reduction
6353  for more details.
6354  It is recommended that this option is NOT used, #pragma\SpecialChar ~
6355 noinduction
6356 \begin_inset LatexCommand \index{\#pragma noinduction}
6357
6358 \end_inset 
6359
6360  can be used to turn off induction optimizations for a given function only.
6361 \layout List
6362 \labelwidthstring 00.00.0000
6363
6364
6365 \series bold 
6366 -
6367 \begin_inset ERT
6368 status Collapsed
6369
6370 \layout Standard
6371
6372 \backslash 
6373 /
6374 \end_inset 
6375
6376 -nojtbound
6377 \begin_inset LatexCommand \index{-\/-nojtbound}
6378
6379 \end_inset 
6380
6381
6382 \size large 
6383 \bar under 
6384  
6385 \series default 
6386 \size default 
6387 \bar default 
6388  Will not generate boundary condition check when switch statements
6389 \begin_inset LatexCommand \index{switch statement}
6390
6391 \end_inset 
6392
6393  are implemented using jump-tables.
6394  See section 
6395 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
6396
6397 \end_inset 
6398
6399 \SpecialChar ~
6400 Switch Statements for more details.
6401  It is recommended that this option is NOT used, #pragma\SpecialChar ~
6402 nojtbound
6403 \begin_inset LatexCommand \index{\#pragma nojtbound}
6404
6405 \end_inset 
6406
6407  can be used to turn off boundary checking for jump tables for a given function
6408  only.
6409 \layout List
6410 \labelwidthstring 00.00.0000
6411
6412
6413 \series bold 
6414 -
6415 \begin_inset ERT
6416 status Collapsed
6417
6418 \layout Standard
6419
6420 \backslash 
6421 /
6422 \end_inset 
6423
6424 -noloopreverse
6425 \begin_inset LatexCommand \index{-\/-noloopreverse}
6426
6427 \end_inset 
6428
6429
6430 \series default 
6431 \size large 
6432  
6433 \size default 
6434 Will not do loop reversal 
6435 \begin_inset LatexCommand \index{Loop reversing}
6436
6437 \end_inset 
6438
6439 optimization.
6440 \layout List
6441 \labelwidthstring 00.00.0000
6442
6443 -
6444 \begin_inset ERT
6445 status Collapsed
6446
6447 \layout Standard
6448
6449 \backslash 
6450 /
6451 \end_inset 
6452
6453 -
6454 \series bold 
6455 nolabelopt
6456 \series default 
6457  
6458 \begin_inset LatexCommand \index{-\/-nolabelopt }
6459
6460 \end_inset 
6461
6462 Will not optimize labels (makes the dumpfiles more readable).
6463 \layout List
6464 \labelwidthstring 00.00.0000
6465
6466
6467 \series bold 
6468 -
6469 \begin_inset ERT
6470 status Collapsed
6471
6472 \layout Standard
6473
6474 \backslash 
6475 /
6476 \end_inset 
6477
6478 -no-xinit-opt
6479 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
6480
6481 \end_inset 
6482
6483
6484 \series default 
6485  Will not memcpy initialized data from code space into xdata space.
6486  This saves a few bytes in code space if you don't have initialized data.
6487 \layout List
6488 \labelwidthstring 00.00.0000
6489
6490
6491 \series bold 
6492 -
6493 \begin_inset ERT
6494 status Collapsed
6495
6496 \layout Standard
6497
6498 \backslash 
6499 /
6500 \end_inset 
6501
6502 -nooverlay
6503 \begin_inset LatexCommand \index{-\/-nooverlay}
6504
6505 \end_inset 
6506
6507
6508 \series default 
6509   The compiler will not overlay parameters and local variables of any function,
6510  see section Parameters and local variables for more details.
6511 \layout List
6512 \labelwidthstring 00.00.0000
6513
6514
6515 \series bold 
6516 -
6517 \begin_inset ERT
6518 status Collapsed
6519
6520 \layout Standard
6521
6522 \backslash 
6523 /
6524 \end_inset 
6525
6526 -no-peep
6527 \begin_inset LatexCommand \index{-\/-no-peep}
6528
6529 \end_inset 
6530
6531
6532 \series default 
6533  Disable peep-hole optimization.
6534 \layout List
6535 \labelwidthstring 00.00.0000
6536
6537
6538 \series bold 
6539 -
6540 \begin_inset ERT
6541 status Collapsed
6542
6543 \layout Standard
6544
6545 \backslash 
6546 /
6547 \end_inset 
6548
6549 -peep-file
6550 \series default 
6551
6552 \begin_inset LatexCommand \index{-\/-peep-file}
6553
6554 \end_inset 
6555
6556 \SpecialChar ~
6557 <filename> This option can be used to use additional rules to be used by
6558  the peep hole optimizer.
6559  See section 
6560 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
6561
6562 \end_inset 
6563
6564 \SpecialChar ~
6565 Peep Hole optimizations for details on how to write these rules.
6566 \layout List
6567 \labelwidthstring 00.00.0000
6568
6569
6570 \series bold 
6571 -
6572 \begin_inset ERT
6573 status Collapsed
6574
6575 \layout Standard
6576
6577 \backslash 
6578 /
6579 \end_inset 
6580
6581 -peep-asm
6582 \begin_inset LatexCommand \index{-\/-peep-asm}
6583
6584 \end_inset 
6585
6586
6587 \series default 
6588   Pass the inline assembler code through the peep hole optimizer.
6589  This can cause unexpected changes to inline assembler code, please go through
6590  the peephole optimizer
6591 \begin_inset LatexCommand \index{Peephole optimizer}
6592
6593 \end_inset 
6594
6595  rules defined in the source file tree '<target>/peeph.def' before using
6596  this option.
6597 \layout Subsection
6598
6599 Other Options
6600 \begin_inset LatexCommand \index{Options other}
6601
6602 \end_inset 
6603
6604
6605 \layout List
6606 \labelwidthstring 00.00.0000
6607
6608
6609 \series bold 
6610 -c\SpecialChar ~
6611 -
6612 \begin_inset ERT
6613 status Collapsed
6614
6615 \layout Standard
6616
6617 \backslash 
6618 /
6619 \end_inset 
6620
6621 -compile-only
6622 \begin_inset LatexCommand \index{-\/-compile-only}
6623
6624 \end_inset 
6625
6626
6627 \begin_inset LatexCommand \index{-c -\/-compile-only}
6628
6629 \end_inset 
6630
6631
6632 \series default 
6633  will compile and assemble the source, but will not call the linkage editor.
6634 \layout List
6635 \labelwidthstring 00.00.0000
6636
6637
6638 \series bold 
6639 -
6640 \series default 
6641
6642 \begin_inset ERT
6643 status Collapsed
6644
6645 \layout Standard
6646
6647 \backslash 
6648 /
6649 \end_inset 
6650
6651
6652 \series bold 
6653 -c1mode
6654 \begin_inset LatexCommand \index{-\/-c1mode}
6655
6656 \end_inset 
6657
6658
6659 \series default 
6660  reads the preprocessed source from standard input and compiles it.
6661  The file name for the assembler output must be specified using the -o option.
6662 \layout List
6663 \labelwidthstring 00.00.0000
6664
6665
6666 \series bold 
6667 -E
6668 \begin_inset LatexCommand \index{-E}
6669
6670 \end_inset 
6671
6672
6673 \series default 
6674  Run only the C preprocessor.
6675  Preprocess all the C source files specified and output the results to standard
6676  output.
6677 \layout List
6678 \labelwidthstring 00.00.0000
6679
6680
6681 \series bold 
6682 -o\SpecialChar ~
6683 <path/file>
6684 \begin_inset LatexCommand \index{-o <path/file>}
6685
6686 \end_inset 
6687
6688  
6689 \series default 
6690 The output path resp.
6691  file where everything will be placed.
6692  If the parameter is a path, it must have a trailing slash (or backslash
6693  for the Windows binaries) to be recognized as a path.
6694  
6695 \layout List
6696 \labelwidthstring 00.00.0000
6697
6698
6699 \series bold 
6700 -
6701 \begin_inset ERT
6702 status Collapsed
6703
6704 \layout Standard
6705
6706 \backslash 
6707 /
6708 \end_inset 
6709
6710 -stack-auto
6711 \begin_inset LatexCommand \index{-\/-stack-auto}
6712
6713 \end_inset 
6714
6715
6716 \series default 
6717 \size large 
6718 \emph on 
6719  
6720 \size default 
6721 \emph default 
6722 All functions in the source file will be compiled as 
6723 \emph on 
6724 reentrant
6725 \emph default 
6726
6727 \begin_inset LatexCommand \index{reentrant}
6728
6729 \end_inset 
6730
6731 , i.e.
6732  the parameters and local variables will be allocated on the stack
6733 \begin_inset LatexCommand \index{stack}
6734
6735 \end_inset 
6736
6737 .
6738  see section Parameters and Local Variables for more details.
6739  If this option is used all source files in the project should be compiled
6740  with this option.
6741  
6742 \layout List
6743 \labelwidthstring 00.00.0000
6744
6745
6746 \series bold 
6747 -
6748 \begin_inset ERT
6749 status Collapsed
6750
6751 \layout Standard
6752
6753 \backslash 
6754 /
6755 \end_inset 
6756
6757 -callee-saves
6758 \begin_inset LatexCommand \index{-\/-callee-saves}
6759
6760 \end_inset 
6761
6762  function1[,function2][,function3]....
6763
6764 \series default 
6765  The compiler by default uses a caller saves convention for register saving
6766  across function calls, however this can cause unnecessary register pushing
6767  & popping when calling small functions from larger functions.
6768  This option can be used to switch the register saving convention for the
6769  function names specified.
6770  The compiler will not save registers when calling these functions, no extra
6771  code will be generated at the entry & exit (function prologue
6772 \series bold 
6773
6774 \begin_inset LatexCommand \index{function prologue}
6775
6776 \end_inset 
6777
6778
6779 \series default 
6780  & epilogue
6781 \series bold 
6782
6783 \begin_inset LatexCommand \index{function epilogue}
6784
6785 \end_inset 
6786
6787
6788 \series default 
6789 ) for these functions to save & restore the registers used by these functions,
6790  this can SUBSTANTIALLY reduce code & improve run time performance of the
6791  generated code.
6792  In the future the compiler (with inter procedural analysis) will be able
6793  to determine the appropriate scheme to use for each function call.
6794  DO NOT use this option for built-in functions such as _mulint..., if this
6795  option is used for a library function the appropriate library function
6796  needs to be recompiled with the same option.
6797  If the project consists of multiple source files then all the source file
6798  should be compiled with the same -
6799 \begin_inset ERT
6800 status Collapsed
6801
6802 \layout Standard
6803
6804 \backslash 
6805 /
6806 \end_inset 
6807
6808 -callee-saves option string.
6809  Also see #pragma\SpecialChar ~
6810 callee_saves
6811 \begin_inset LatexCommand \index{\#pragma callee\_saves}
6812
6813 \end_inset 
6814
6815 .
6816 \layout List
6817 \labelwidthstring 00.00.0000
6818
6819
6820 \series bold 
6821 -
6822 \begin_inset ERT
6823 status Collapsed
6824
6825 \layout Standard
6826
6827 \backslash 
6828 /
6829 \end_inset 
6830
6831 -debug
6832 \begin_inset LatexCommand \index{-\/-debug}
6833
6834 \end_inset 
6835
6836
6837 \bar under 
6838  
6839 \series default 
6840 \bar default 
6841 When this option is used the compiler will generate debug information.
6842  The debug information collected in a file with .cdb extension can be used
6843  with the SDCDB.
6844  For more information see documentation for SDCDB.
6845  Another file with no extension contains debug information in AOMF or AOMF51
6846 \begin_inset LatexCommand \index{AOMF, AOMF51}
6847
6848 \end_inset 
6849
6850  format which is commonly used by third party tools.
6851 \layout List
6852 \labelwidthstring 00.00.0000
6853
6854
6855 \series bold 
6856 -S
6857 \begin_inset LatexCommand \index{-S}
6858
6859 \end_inset 
6860
6861
6862 \size large 
6863 \bar under 
6864  
6865 \series default 
6866 \size default 
6867 \bar default 
6868 Stop after the stage of compilation proper; do not assemble.
6869  The output is an assembler code file for the input file specified.
6870 \layout List
6871 \labelwidthstring 00.00.0000
6872
6873
6874 \series bold 
6875 -
6876 \begin_inset ERT
6877 status Collapsed
6878
6879 \layout Standard
6880
6881 \backslash 
6882 /
6883 \end_inset 
6884
6885 -int-long-reent
6886 \begin_inset LatexCommand \index{-\/-int-long-reent}
6887
6888 \end_inset 
6889
6890
6891 \series default 
6892  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
6893  Note by default these libraries are compiled as non-reentrant.
6894  See section Installation for more details.
6895 \layout List
6896 \labelwidthstring 00.00.0000
6897
6898
6899 \series bold 
6900 -
6901 \begin_inset ERT
6902 status Collapsed
6903
6904 \layout Standard
6905
6906 \backslash 
6907 /
6908 \end_inset 
6909
6910 -cyclomatic
6911 \begin_inset LatexCommand \index{-\/-cyclomatic}
6912
6913 \end_inset 
6914
6915
6916 \bar under 
6917  
6918 \series default 
6919 \bar default 
6920 This option will cause the compiler to generate an information message for
6921  each function in the source file.
6922  The message contains some 
6923 \emph on 
6924 important
6925 \emph default 
6926  information about the function.
6927  The number of edges and nodes the compiler detected in the control flow
6928  graph of the function, and most importantly the 
6929 \emph on 
6930 cyclomatic complexity
6931 \begin_inset LatexCommand \index{Cyclomatic complexity}
6932
6933 \end_inset 
6934
6935
6936 \emph default 
6937  see section on Cyclomatic Complexity for more details.
6938 \layout List
6939 \labelwidthstring 00.00.0000
6940
6941
6942 \series bold 
6943 -
6944 \begin_inset ERT
6945 status Collapsed
6946
6947 \layout Standard
6948
6949 \backslash 
6950 /
6951 \end_inset 
6952
6953 -float-reent
6954 \begin_inset LatexCommand \index{-\/-float-reent}
6955
6956 \end_inset 
6957
6958
6959 \series default 
6960  Floating point library is compiled as reentrant
6961 \begin_inset LatexCommand \index{reentrant}
6962
6963 \end_inset 
6964
6965 .
6966  See section Installation for more details.
6967 \layout List
6968 \labelwidthstring 00.00.0000
6969
6970
6971 \series bold 
6972 -
6973 \begin_inset ERT
6974 status Collapsed
6975
6976 \layout Standard
6977
6978 \backslash 
6979 /
6980 \end_inset 
6981
6982 -main-return
6983 \begin_inset LatexCommand \index{-\/-main-return}
6984
6985 \end_inset 
6986
6987
6988 \series default 
6989  This option can be used when the code generated is called by a monitor
6990  program.
6991  The compiler will generate a 'ret' upon return from the 'main'
6992 \begin_inset LatexCommand \index{main return}
6993
6994 \end_inset 
6995
6996  function.
6997  The default setting is to lock up i.e.
6998  generate a '
6999 \family typewriter 
7000 sjmp .
7001 \family default 
7002 '.
7003 \layout List
7004 \labelwidthstring 00.00.0000
7005
7006
7007 \series bold 
7008 -
7009 \begin_inset ERT
7010 status Collapsed
7011
7012 \layout Standard
7013
7014 \backslash 
7015 /
7016 \end_inset 
7017
7018 -nostdincl
7019 \begin_inset LatexCommand \index{-\/-nostdincl}
7020
7021 \end_inset 
7022
7023
7024 \series default 
7025  This will prevent the compiler from passing on the default include path
7026  to the preprocessor.
7027 \layout List
7028 \labelwidthstring 00.00.0000
7029
7030
7031 \series bold 
7032 -
7033 \begin_inset ERT
7034 status Collapsed
7035
7036 \layout Standard
7037
7038 \backslash 
7039 /
7040 \end_inset 
7041
7042 -nostdlib
7043 \begin_inset LatexCommand \index{-\/-nostdlib}
7044
7045 \end_inset 
7046
7047
7048 \series default 
7049  This will prevent the compiler from passing on the default library
7050 \begin_inset LatexCommand \index{Libraries}
7051
7052 \end_inset 
7053
7054  path to the linker.
7055 \layout List
7056 \labelwidthstring 00.00.0000
7057
7058
7059 \series bold 
7060 -
7061 \begin_inset ERT
7062 status Collapsed
7063
7064 \layout Standard
7065
7066 \backslash 
7067 /
7068 \end_inset 
7069
7070 -verbose
7071 \begin_inset LatexCommand \index{-\/-verbose}
7072
7073 \end_inset 
7074
7075
7076 \series default 
7077  Shows the various actions the compiler is performing.
7078 \layout List
7079 \labelwidthstring 00.00.0000
7080
7081
7082 \series bold 
7083 -V
7084 \begin_inset LatexCommand \index{-V}
7085
7086 \end_inset 
7087
7088
7089 \series default 
7090  Shows the actual commands the compiler is executing.
7091 \layout List
7092 \labelwidthstring 00.00.0000
7093
7094
7095 \series bold 
7096 -
7097 \begin_inset ERT
7098 status Collapsed
7099
7100 \layout Standard
7101
7102 \backslash 
7103 /
7104 \end_inset 
7105
7106 -no-c-code-in-asm
7107 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
7108
7109 \end_inset 
7110
7111
7112 \series default 
7113  Hides your ugly and inefficient c-code from the asm file, so you can always
7114  blame the compiler :).
7115 \layout List
7116 \labelwidthstring 00.00.0000
7117
7118
7119 \series bold 
7120 -
7121 \begin_inset ERT
7122 status Collapsed
7123
7124 \layout Standard
7125
7126 \backslash 
7127 /
7128 \end_inset 
7129
7130 -i-code-in-asm
7131 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
7132
7133 \end_inset 
7134
7135
7136 \series default 
7137  Include i-codes in the asm file.
7138  Sounds like noise but is most helpful for debugging the compiler itself.
7139 \layout List
7140 \labelwidthstring 00.00.0000
7141
7142
7143 \series bold 
7144 -
7145 \begin_inset ERT
7146 status Collapsed
7147
7148 \layout Standard
7149
7150 \backslash 
7151 /
7152 \end_inset 
7153
7154 -less-pedantic
7155 \begin_inset LatexCommand \index{-\/-less-pedantic}
7156
7157 \end_inset 
7158
7159
7160 \series default 
7161  Disable some of the more pedantic warnings
7162 \begin_inset LatexCommand \index{Warnings}
7163
7164 \end_inset 
7165
7166  (jwk burps: please be more specific here, please!).
7167  If you want rather more than less warnings you should consider using a
7168  separate tool dedicated to syntax checking like splint 
7169 \begin_inset LatexCommand \url{www.splint.org}
7170
7171 \end_inset 
7172
7173 .
7174 \layout List
7175 \labelwidthstring 00.00.0000
7176
7177
7178 \series bold 
7179 -
7180 \begin_inset ERT
7181 status Collapsed
7182
7183 \layout Standard
7184
7185 \backslash 
7186 /
7187 \end_inset 
7188
7189 -print-search-dirs
7190 \begin_inset LatexCommand \index{-\/-print-search-dirs}
7191
7192 \end_inset 
7193
7194
7195 \series default 
7196  Display the directories in the compiler's search path
7197 \layout List
7198 \labelwidthstring 00.00.0000
7199
7200
7201 \series bold 
7202 -
7203 \begin_inset ERT
7204 status Collapsed
7205
7206 \layout Standard
7207
7208 \backslash 
7209 /
7210 \end_inset 
7211
7212 -vc
7213 \begin_inset LatexCommand \index{-\/-vc}
7214
7215 \end_inset 
7216
7217
7218 \series default 
7219  Display errors and warnings using MSVC style, so you can use SDCC with
7220  visual studio.
7221 \layout List
7222 \labelwidthstring 00.00.0000
7223
7224
7225 \series bold 
7226 -
7227 \begin_inset ERT
7228 status Collapsed
7229
7230 \layout Standard
7231
7232 \backslash 
7233 /
7234 \end_inset 
7235
7236 -use-stdout
7237 \begin_inset LatexCommand \index{-\/-use-stdout}
7238
7239 \end_inset 
7240
7241
7242 \series default 
7243  Send errors and warnings to stdout instead of stderr.
7244 \layout List
7245 \labelwidthstring 00.00.0000
7246
7247
7248 \series bold 
7249 -Wa\SpecialChar ~
7250 asmOption[,asmOption]
7251 \series default 
7252
7253 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
7254
7255 \end_inset 
7256
7257 ...
7258  Pass the asmOption to the assembler
7259 \begin_inset LatexCommand \index{Options assembler}
7260
7261 \end_inset 
7262
7263
7264 \begin_inset LatexCommand \index{Assembler options}
7265
7266 \end_inset 
7267
7268 .
7269  See file sdcc/as/doc/asxhtm.html for assembler options.
7270 \layout Subsection
7271
7272 Intermediate Dump Options
7273 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
7274
7275 \end_inset 
7276
7277
7278 \begin_inset LatexCommand \index{Options intermediate dump}
7279
7280 \end_inset 
7281
7282
7283 \begin_inset LatexCommand \index{Intermediate dump options}
7284
7285 \end_inset 
7286
7287
7288 \layout Standard
7289
7290 The following options are provided for the purpose of retargetting and debugging
7291  the compiler.
7292  These provided a means to dump the intermediate code (iCode
7293 \begin_inset LatexCommand \index{iCode}
7294
7295 \end_inset 
7296
7297 ) generated by the compiler in human readable form at various stages of
7298  the compilation process.
7299  More on iCodes see chapter 
7300 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
7301
7302 \end_inset 
7303
7304  
7305 \begin_inset Quotes srd
7306 \end_inset 
7307
7308 The anatomy of the compiler
7309 \begin_inset Quotes srd
7310 \end_inset 
7311
7312 .
7313 \layout List
7314 \labelwidthstring 00.00.0000
7315
7316
7317 \series bold 
7318 -
7319 \begin_inset ERT
7320 status Collapsed
7321
7322 \layout Standard
7323
7324 \backslash 
7325 /
7326 \end_inset 
7327
7328 -dumpraw
7329 \begin_inset LatexCommand \index{-\/-dumpraw}
7330
7331 \end_inset 
7332
7333
7334 \series default 
7335  This option will cause the compiler to dump the intermediate code into
7336  a file of named 
7337 \emph on 
7338 <source filename>.dumpraw
7339 \emph default 
7340  just after the intermediate code has been generated for a function, i.e.
7341  before any optimizations are done.
7342  The basic blocks
7343 \begin_inset LatexCommand \index{Basic blocks}
7344
7345 \end_inset 
7346
7347  at this stage ordered in the depth first number, so they may not be in
7348  sequence of execution.
7349 \layout List
7350 \labelwidthstring 00.00.0000
7351
7352
7353 \series bold 
7354 -
7355 \begin_inset ERT
7356 status Collapsed
7357
7358 \layout Standard
7359
7360 \backslash 
7361 /
7362 \end_inset 
7363
7364 -dumpgcse
7365 \begin_inset LatexCommand \index{-\/-dumpgcse}
7366
7367 \end_inset 
7368
7369
7370 \series default 
7371  Will create a dump of iCode's, after global subexpression elimination
7372 \begin_inset LatexCommand \index{Global subexpression elimination}
7373
7374 \end_inset 
7375
7376 , into a file named 
7377 \emph on 
7378 <source filename>.dumpgcse.
7379 \layout List
7380 \labelwidthstring 00.00.0000
7381
7382
7383 \series bold 
7384 -
7385 \begin_inset ERT
7386 status Collapsed
7387
7388 \layout Standard
7389
7390 \backslash 
7391 /
7392 \end_inset 
7393
7394 -dumpdeadcode
7395 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
7396
7397 \end_inset 
7398
7399
7400 \series default 
7401  Will create a dump of iCode's, after deadcode elimination
7402 \begin_inset LatexCommand \index{Dead-code elimination}
7403
7404 \end_inset 
7405
7406 , into a file named 
7407 \emph on 
7408 <source filename>.dumpdeadcode.
7409 \layout List
7410 \labelwidthstring 00.00.0000
7411
7412
7413 \series bold 
7414 -
7415 \begin_inset ERT
7416 status Collapsed
7417
7418 \layout Standard
7419
7420 \backslash 
7421 /
7422 \end_inset 
7423
7424 -dumploop
7425 \begin_inset LatexCommand \index{-\/-dumploop}
7426
7427 \end_inset 
7428
7429
7430 \series default 
7431 \size large 
7432  
7433 \size default 
7434 Will create a dump of iCode's, after loop optimizations
7435 \begin_inset LatexCommand \index{Loop optimization}
7436
7437 \end_inset 
7438
7439 , into a file named 
7440 \emph on 
7441 <source filename>.dumploop.
7442 \layout List
7443 \labelwidthstring 00.00.0000
7444
7445
7446 \series bold 
7447 -
7448 \begin_inset ERT
7449 status Collapsed
7450
7451 \layout Standard
7452
7453 \backslash 
7454 /
7455 \end_inset 
7456
7457 -dumprange
7458 \begin_inset LatexCommand \index{-\/-dumprange}
7459
7460 \end_inset 
7461
7462
7463 \series default 
7464 \size large 
7465  
7466 \size default 
7467 Will create a dump of iCode's, after live range analysis
7468 \begin_inset LatexCommand \index{Live range analysis}
7469
7470 \end_inset 
7471
7472 , into a file named 
7473 \emph on 
7474 <source filename>.dumprange.
7475 \layout List
7476 \labelwidthstring 00.00.0000
7477
7478
7479 \series bold 
7480 -
7481 \begin_inset ERT
7482 status Collapsed
7483
7484 \layout Standard
7485
7486 \backslash 
7487 /
7488 \end_inset 
7489
7490 -dumlrange
7491 \begin_inset LatexCommand \index{-\/-dumlrange}
7492
7493 \end_inset 
7494
7495
7496 \series default 
7497  Will dump the life ranges
7498 \begin_inset LatexCommand \index{Live range analysis}
7499
7500 \end_inset 
7501
7502  for all symbols.
7503 \layout List
7504 \labelwidthstring 00.00.0000
7505
7506
7507 \series bold 
7508 -
7509 \begin_inset ERT
7510 status Collapsed
7511
7512 \layout Standard
7513
7514 \backslash 
7515 /
7516 \end_inset 
7517
7518 -dumpregassign
7519 \begin_inset LatexCommand \index{-\/-dumpregassign}
7520
7521 \end_inset 
7522
7523
7524 \bar under 
7525  
7526 \series default 
7527 \bar default 
7528 Will create a dump of iCode's, after register assignment
7529 \begin_inset LatexCommand \index{Register assignment}
7530
7531 \end_inset 
7532
7533 , into a file named 
7534 \emph on 
7535 <source filename>.dumprassgn.
7536 \layout List
7537 \labelwidthstring 00.00.0000
7538
7539
7540 \series bold 
7541 -
7542 \begin_inset ERT
7543 status Collapsed
7544
7545 \layout Standard
7546
7547 \backslash 
7548 /
7549 \end_inset 
7550
7551 -dumplrange
7552 \begin_inset LatexCommand \index{-\/-dumplrange}
7553
7554 \end_inset 
7555
7556
7557 \series default 
7558  Will create a dump of the live ranges of iTemp's
7559 \layout List
7560 \labelwidthstring 00.00.0000
7561
7562
7563 \series bold 
7564 -
7565 \begin_inset ERT
7566 status Collapsed
7567
7568 \layout Standard
7569
7570 \backslash 
7571 /
7572 \end_inset 
7573
7574 -dumpall
7575 \begin_inset LatexCommand \index{-\/-dumpall}
7576
7577 \end_inset 
7578
7579
7580 \size large 
7581 \bar under 
7582  
7583 \series default 
7584 \size default 
7585 \bar default 
7586 Will cause all the above mentioned dumps to be created.
7587 \layout Subsection
7588
7589 Redirecting output on Windows Shells
7590 \layout Standard
7591
7592 By default SDCC writes it's error messages to 
7593 \begin_inset Quotes sld
7594 \end_inset 
7595
7596 standard error
7597 \begin_inset Quotes srd
7598 \end_inset 
7599
7600 .
7601  To force all messages to 
7602 \begin_inset Quotes sld
7603 \end_inset 
7604
7605 standard output
7606 \begin_inset Quotes srd
7607 \end_inset 
7608
7609  use 
7610 \series bold 
7611 -
7612 \series default 
7613 \emph on 
7614
7615 \begin_inset ERT
7616 status Collapsed
7617
7618 \layout Standard
7619
7620 \backslash 
7621 /
7622 \end_inset 
7623
7624
7625 \series bold 
7626 \emph default 
7627 -
7628 \series default 
7629 use-stdout
7630 \begin_inset LatexCommand \index{-\/-use-stdout}
7631
7632 \end_inset 
7633
7634 .
7635  Additionally, if you happen to have visual studio installed in your windows
7636  machine, you can use it to compile your sources using a custom build and
7637  the SDCC -
7638 \emph on 
7639
7640 \begin_inset ERT
7641 status Collapsed
7642
7643 \layout Standard
7644
7645 \backslash 
7646 /
7647 \end_inset 
7648
7649
7650 \emph default 
7651 -vc
7652 \begin_inset LatexCommand \index{-\/-vc}
7653
7654 \end_inset 
7655
7656  option.
7657  Something like this should work:
7658 \newline 
7659
7660 \newline 
7661
7662 \series bold 
7663 c:
7664 \backslash 
7665 sdcc
7666 \backslash 
7667 bin
7668 \backslash 
7669 sdcc.exe -
7670 \series default 
7671 \emph on 
7672
7673 \begin_inset ERT
7674 status Collapsed
7675
7676 \layout Standard
7677
7678 \backslash 
7679 /
7680 \end_inset 
7681
7682
7683 \series bold 
7684 \emph default 
7685 -vc -
7686 \series default 
7687 \emph on 
7688
7689 \begin_inset ERT
7690 status Collapsed
7691
7692 \layout Standard
7693
7694 \backslash 
7695 /
7696 \end_inset 
7697
7698
7699 \series bold 
7700 \emph default 
7701 -model-large -c $(InputPath)
7702 \layout Section
7703
7704 Environment variables
7705 \begin_inset LatexCommand \index{Environment variables}
7706
7707 \end_inset 
7708
7709
7710 \layout Standard
7711
7712 SDCC recognizes the following environment variables:
7713 \layout List
7714 \labelwidthstring 00.00.0000
7715
7716
7717 \series bold 
7718 SDCC_LEAVE_SIGNALS
7719 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
7720
7721 \end_inset 
7722
7723
7724 \series default 
7725  SDCC installs a signal handler
7726 \begin_inset LatexCommand \index{signal handler}
7727
7728 \end_inset 
7729
7730  to be able to delete temporary files after an user break (^C) or an exception.
7731  If this environment variable is set, SDCC won't install the signal handler
7732  in order to be able to debug SDCC.
7733 \layout List
7734 \labelwidthstring 00.00.0000
7735
7736
7737 \series bold 
7738 TMP,\SpecialChar ~
7739 TEMP,\SpecialChar ~
7740 TMPDIR
7741 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
7742
7743 \end_inset 
7744
7745
7746 \series default 
7747  Path, where temporary files will be created.
7748  The order of the variables is the search order.
7749  In a standard *nix environment these variables are not set, and there's
7750  no need to set them.
7751  On Windows it's recommended to set one of them.
7752 \layout List
7753 \labelwidthstring 00.00.0000
7754
7755
7756 \series bold 
7757 SDCC_HOME
7758 \begin_inset LatexCommand \index{SDCC\_HOME}
7759
7760 \end_inset 
7761
7762
7763 \series default 
7764  Path, see section 
7765 \begin_inset LatexCommand \ref{sub:Install-paths}
7766
7767 \end_inset 
7768
7769 \SpecialChar ~
7770
7771 \begin_inset Quotes sld
7772 \end_inset 
7773
7774  Install Paths
7775 \begin_inset Quotes srd
7776 \end_inset 
7777
7778 .
7779 \layout List
7780 \labelwidthstring 00.00.0000
7781
7782
7783 \series bold 
7784 SDCC_INCLUDE
7785 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
7786
7787 \end_inset 
7788
7789
7790 \series default 
7791  Path, see section 
7792 \begin_inset LatexCommand \ref{sub:Search-Paths}
7793
7794 \end_inset 
7795
7796 \SpecialChar ~
7797
7798 \begin_inset Quotes sld
7799 \end_inset 
7800
7801 Search Paths
7802 \begin_inset Quotes srd
7803 \end_inset 
7804
7805 .
7806 \layout List
7807 \labelwidthstring 00.00.0000
7808
7809
7810 \series bold 
7811 SDCC_LIB
7812 \begin_inset LatexCommand \index{SDCC\_LIB}
7813
7814 \end_inset 
7815
7816
7817 \series default 
7818  Path, see section 
7819 \begin_inset LatexCommand \ref{sub:Search-Paths}
7820
7821 \end_inset 
7822
7823 \SpecialChar ~
7824
7825 \begin_inset Quotes sld
7826 \end_inset 
7827
7828 Search Paths
7829 \begin_inset Quotes srd
7830 \end_inset 
7831
7832 ..
7833 \layout Standard
7834
7835 There are some more environment variables recognized by SDCC, but these
7836  are solely used for debugging purposes.
7837  They can change or disappear very quickly, and will never be documented.
7838 \layout Section
7839
7840 Storage Class Language Extensions
7841 \layout Subsection
7842
7843 MCS51/DS390 Storage Class
7844 \begin_inset LatexCommand \index{Storage class}
7845
7846 \end_inset 
7847
7848  Language Extensions
7849 \layout Standard
7850
7851 In addition to the ANSI storage classes SDCC allows the following MCS51
7852  specific storage classes:
7853 \layout Subsubsection
7854
7855 data
7856 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7857
7858 \end_inset 
7859
7860  / near
7861 \begin_inset LatexCommand \index{near (storage class)}
7862
7863 \end_inset 
7864
7865
7866 \layout Standard
7867
7868 This is the 
7869 \series bold 
7870 default
7871 \series default 
7872  storage class for the Small Memory model (
7873 \emph on 
7874 data
7875 \emph default 
7876  and 
7877 \emph on 
7878 near
7879 \emph default 
7880  can be used synonymously).
7881  Variables declared with this storage class will be allocated in the directly
7882  addressable portion of the internal RAM of a 8051, e.g.:
7883 \layout Verse
7884
7885
7886 \family typewriter 
7887 data unsigned char test_data;
7888 \layout Standard
7889
7890 Writing 0x01 to this variable generates the assembly code:
7891 \layout Verse
7892
7893
7894 \family typewriter 
7895 75*00 01\SpecialChar ~
7896 \SpecialChar ~
7897 \SpecialChar ~
7898 mov\SpecialChar ~
7899 \SpecialChar ~
7900 _test_data,#0x01 
7901 \layout Subsubsection
7902
7903 xdata
7904 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7905
7906 \end_inset 
7907
7908  / far
7909 \begin_inset LatexCommand \index{far (storage class)}
7910
7911 \end_inset 
7912
7913
7914 \layout Standard
7915
7916 Variables declared with this storage class will be placed in the external
7917  RAM.
7918  This is the 
7919 \series bold 
7920 default
7921 \series default 
7922  storage class for the Large Memory model, e.g.:
7923 \layout Verse
7924
7925
7926 \family typewriter 
7927 xdata unsigned char test_xdata;
7928 \layout Standard
7929
7930 Writing 0x01 to this variable generates the assembly code:
7931 \layout Verse
7932
7933
7934 \family typewriter 
7935 90s00r00\SpecialChar ~
7936 \SpecialChar ~
7937 \SpecialChar ~
7938 mov\SpecialChar ~
7939 \SpecialChar ~
7940 dptr,#_test_xdata 
7941 \newline 
7942 74\SpecialChar ~
7943 01\SpecialChar ~
7944 \SpecialChar ~
7945 \SpecialChar ~
7946 \SpecialChar ~
7947 \SpecialChar ~
7948 \SpecialChar ~
7949 mov\SpecialChar ~
7950 \SpecialChar ~
7951 a,#0x01 
7952 \newline 
7953 F0\SpecialChar ~
7954 \SpecialChar ~
7955 \SpecialChar ~
7956 \SpecialChar ~
7957 \SpecialChar ~
7958 \SpecialChar ~
7959 \SpecialChar ~
7960 \SpecialChar ~
7961 \SpecialChar ~
7962 movx\SpecialChar ~
7963 @dptr,a 
7964 \layout Subsubsection
7965
7966 idata
7967 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7968
7969 \end_inset 
7970
7971
7972 \layout Standard
7973
7974 Variables declared with this storage class will be allocated into the indirectly
7975  addressable portion of the internal ram of a 8051, e.g.:
7976 \layout Verse
7977
7978
7979 \family typewriter 
7980 idata unsigned char test_idata;
7981 \layout Standard
7982
7983 Writing 0x01 to this variable generates the assembly code:
7984 \layout Verse
7985
7986
7987 \family typewriter 
7988 78r00\SpecialChar ~
7989 \SpecialChar ~
7990 \SpecialChar ~
7991 \SpecialChar ~
7992 \SpecialChar ~
7993 \SpecialChar ~
7994 \SpecialChar ~
7995 mov\SpecialChar ~
7996 \SpecialChar ~
7997 r0,#_test_idata
7998 \newline 
7999 76\SpecialChar ~
8000 01\SpecialChar ~
8001 \SpecialChar ~
8002 \SpecialChar ~
8003 \SpecialChar ~
8004 \SpecialChar ~
8005 \SpecialChar ~
8006 \SpecialChar ~
8007 mov\SpecialChar ~
8008 \SpecialChar ~
8009 @r0,#0x01
8010 \layout Standard
8011
8012 Please note, the first 128 byte of idata physically access the same RAM
8013  as the data memory.
8014  The original 8051 had 128 byte idata memory, nowadays most devices have
8015  256 byte idata memory.
8016  The stack
8017 \begin_inset LatexCommand \index{stack}
8018
8019 \end_inset 
8020
8021  is located in idata memory.
8022 \layout Subsubsection
8023
8024 pdata
8025 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8026
8027 \end_inset 
8028
8029
8030 \layout Standard
8031
8032 Paged xdata access is currently not as straightforward as using the other
8033  addressing modes of a 8051.
8034  The following example writes 0x01 to the address pointed to.
8035  Please note, pdata access physically accesses xdata memory.
8036  The high byte of the address is determined by port P2 
8037 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
8038
8039 \end_inset 
8040
8041 (or in case of some 8051 variants by a separate Special Function Register,
8042  see section 
8043 \begin_inset LatexCommand \ref{sub:MCS51-variants}
8044
8045 \end_inset 
8046
8047 ).
8048 \layout Verse
8049
8050
8051 \family typewriter 
8052 pdata unsigned char *test_pdata_ptr;
8053 \newline 
8054
8055 \newline 
8056 void main() 
8057 \newline 
8058
8059 \newline 
8060 \SpecialChar ~
8061 \SpecialChar ~
8062 \SpecialChar ~
8063 \SpecialChar ~
8064 test_pdata_ptr = (pdata *)0xfe; 
8065 \newline 
8066 \SpecialChar ~
8067 \SpecialChar ~
8068 \SpecialChar ~
8069 \SpecialChar ~
8070 *test_pdata_ptr = 1; 
8071 \newline 
8072
8073 \layout Standard
8074
8075 Generates the assembly code:
8076 \layout Verse
8077
8078
8079 \family typewriter 
8080 75*01 FE\SpecialChar ~
8081 \SpecialChar ~
8082 \SpecialChar ~
8083 mov\SpecialChar ~
8084  _test_pdata_ptr,#0xFE
8085 \newline 
8086 78 FE\SpecialChar ~
8087 \SpecialChar ~
8088 \SpecialChar ~
8089 \SpecialChar ~
8090 \SpecialChar ~
8091 \SpecialChar ~
8092 mov\SpecialChar ~
8093  r0,#0xFE 
8094 \newline 
8095 74 01\SpecialChar ~
8096 \SpecialChar ~
8097 \SpecialChar ~
8098 \SpecialChar ~
8099 \SpecialChar ~
8100 \SpecialChar ~
8101 mov\SpecialChar ~
8102  a,#0x01
8103 \newline 
8104 F2\SpecialChar ~
8105 \SpecialChar ~
8106 \SpecialChar ~
8107 \SpecialChar ~
8108 \SpecialChar ~
8109 \SpecialChar ~
8110 \SpecialChar ~
8111 \SpecialChar ~
8112 \SpecialChar ~
8113 movx @r0,a 
8114 \layout Standard
8115
8116 Be extremely carefull if you use pdata together with the -
8117 \begin_inset ERT
8118 status Collapsed
8119
8120 \layout Standard
8121
8122 \backslash 
8123 /
8124 \end_inset 
8125
8126 -xstack
8127 \begin_inset LatexCommand \index{-\/-xstack}
8128
8129 \end_inset 
8130
8131  option.
8132 \layout Subsubsection
8133
8134 code
8135 \begin_inset LatexCommand \index{code}
8136
8137 \end_inset 
8138
8139
8140 \layout Standard
8141
8142 'Variables' declared with this storage class will be placed in the code
8143  memory:
8144 \layout Verse
8145
8146
8147 \family typewriter 
8148 code unsigned char test_code;
8149 \layout Standard
8150
8151 Read access to this variable generates the assembly code:
8152 \layout Verse
8153
8154
8155 \family typewriter 
8156 90s00r6F\SpecialChar ~
8157 \SpecialChar ~
8158 \SpecialChar ~
8159 mov dptr,#_test_code
8160 \newline 
8161 E4\SpecialChar ~
8162 \SpecialChar ~
8163 \SpecialChar ~
8164 \SpecialChar ~
8165 \SpecialChar ~
8166 \SpecialChar ~
8167 \SpecialChar ~
8168 \SpecialChar ~
8169 \SpecialChar ~
8170 clr a
8171 \newline 
8172 93\SpecialChar ~
8173 \SpecialChar ~
8174 \SpecialChar ~
8175 \SpecialChar ~
8176 \SpecialChar ~
8177 \SpecialChar ~
8178 \SpecialChar ~
8179 \SpecialChar ~
8180 \SpecialChar ~
8181 movc a,@a+dptr 
8182 \layout Standard
8183
8184
8185 \family typewriter 
8186 char
8187 \family default 
8188  indexed arrays of characters in code memory can be accessed efficiently:
8189 \layout Verse
8190
8191
8192 \family typewriter 
8193 code char test_array[] = {'c','h','e','a','p'}; 
8194 \layout Standard
8195
8196 Read access to this array using an 8-bit unsigned index generates the assembly
8197  code:
8198 \layout Verse
8199
8200
8201 \family typewriter 
8202 E5*00\SpecialChar ~
8203 \SpecialChar ~
8204 \SpecialChar ~
8205 \SpecialChar ~
8206 \SpecialChar ~
8207 \SpecialChar ~
8208 mov a,_index 
8209 \layout Verse
8210
8211
8212 \family typewriter 
8213 90s00r41\SpecialChar ~
8214 \SpecialChar ~
8215 \SpecialChar ~
8216 mov dptr,#_test_array
8217 \layout Verse
8218
8219
8220 \family typewriter 
8221 93\SpecialChar ~
8222 \SpecialChar ~
8223 \SpecialChar ~
8224 \SpecialChar ~
8225 \SpecialChar ~
8226 \SpecialChar ~
8227 \SpecialChar ~
8228 \SpecialChar ~
8229 \SpecialChar ~
8230 movc a,@a+dptr 
8231 \layout Subsubsection
8232
8233 bit
8234 \begin_inset LatexCommand \index{bit}
8235
8236 \end_inset 
8237
8238
8239 \layout Standard
8240
8241 This is a data-type and a storage class specifier.
8242  When a variable is declared as a bit, it is allocated into the bit addressable
8243  memory of 8051, e.g.:
8244 \layout Verse
8245
8246
8247 \family typewriter 
8248 bit test_bit;
8249 \layout Standard
8250
8251 Writing 1 to this variable generates the assembly code:
8252 \layout Verse
8253
8254
8255 \family typewriter 
8256 D2*00\SpecialChar ~
8257 \SpecialChar ~
8258 \SpecialChar ~
8259 \SpecialChar ~
8260 \SpecialChar ~
8261 \SpecialChar ~
8262 \SpecialChar ~
8263 setb\SpecialChar ~
8264 _test_bit
8265 \layout Standard
8266
8267 The bit addressable memory consists of 128 bits which are located from 0x20
8268  to 0x2f in data memory.
8269  
8270 \layout Standard
8271
8272 Apart from this 8051 specific storage class most architectures support ANSI-C
8273  bitfields
8274 \begin_inset LatexCommand \index{bitfields}
8275
8276 \end_inset 
8277
8278  
8279 \begin_inset Foot
8280 collapsed false
8281
8282 \layout Standard
8283
8284 Not really meant as examples, but nevertheless showing what bitfields are
8285  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
8286 \end_inset 
8287
8288 .
8289 \layout Subsubsection
8290
8291 sfr
8292 \begin_inset LatexCommand \index{sfr}
8293
8294 \end_inset 
8295
8296  / sbit
8297 \begin_inset LatexCommand \index{sbit}
8298
8299 \end_inset 
8300
8301
8302 \layout Standard
8303
8304 Like the bit keyword, 
8305 \emph on 
8306 sfr / sbit 
8307 \emph default 
8308 signifies both a data-type and storage class, they are used to describe
8309  the 
8310 \emph on 
8311 s
8312 \emph default 
8313 pecial 
8314 \emph on 
8315 f
8316 \emph default 
8317 unction 
8318 \emph on 
8319 r
8320 \emph default 
8321 egisters and 
8322 \emph on 
8323 s
8324 \emph default 
8325 pecial 
8326 \emph on 
8327 bit
8328 \emph default 
8329  variables of a 8051, eg:
8330 \layout Verse
8331
8332
8333 \family typewriter 
8334 sfr at
8335 \begin_inset LatexCommand \index{at}
8336
8337 \end_inset 
8338
8339  0x80 P0;\SpecialChar ~
8340  /* special function register P0 at location 0x80 */
8341 \newline 
8342 sbit at 0xd7 CY; /* CY (Carry Flag
8343 \begin_inset LatexCommand \index{Flags}
8344
8345 \end_inset 
8346
8347
8348 \begin_inset LatexCommand \index{Carry flag}
8349
8350 \end_inset 
8351
8352 ) */
8353 \layout Standard
8354
8355 Special function registers which are located on an address dividable by
8356  8 are bit-addressable, an
8357 \emph on 
8358  sbit
8359 \emph default 
8360  addresses a specific bit within these sfr.
8361 \layout Subsubsection
8362
8363 Pointers
8364 \begin_inset LatexCommand \index{Pointer}
8365
8366 \end_inset 
8367
8368  to MCS51/DS390 specific memory spaces
8369 \layout Standard
8370
8371 SDCC allows (via language extensions) pointers to explicitly point to any
8372  of the memory spaces
8373 \begin_inset LatexCommand \index{Memory model}
8374
8375 \end_inset 
8376
8377  of the 8051.
8378  In addition to the explicit pointers, the compiler uses (by default) generic
8379  pointers which can be used to point to any of the memory spaces.
8380 \newline 
8381
8382 \newline 
8383 Pointer declaration examples:
8384 \layout Verse
8385
8386
8387 \family typewriter 
8388 /* pointer physically in internal ram pointing to object in external ram
8389  */ 
8390 \newline 
8391 xdata unsigned char * data p;
8392 \newline 
8393
8394 \newline 
8395 /* pointer physically in external ram pointing to object in internal ram
8396  */ 
8397 \newline 
8398 data unsigned char * xdata p;
8399 \newline 
8400
8401 \newline 
8402 /* pointer physically in code rom pointing to data in xdata space */ 
8403 \newline 
8404 xdata unsigned char * code p;
8405 \newline 
8406
8407 \newline 
8408 /* pointer physically in code space pointing to data in code space */ 
8409 \newline 
8410 code unsigned char * code p;
8411 \newline 
8412
8413 \newline 
8414 /* the following is a generic pointer physically located in xdata space
8415  */
8416 \newline 
8417 char * xdata p;
8418 \layout Standard
8419
8420 Well you get the idea.
8421  
8422 \newline 
8423
8424 \newline 
8425 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
8426 \emph on 
8427 generic
8428 \emph default 
8429  pointers.
8430  
8431 \size small 
8432
8433 \newline 
8434
8435 \newline 
8436
8437 \size default 
8438 The highest order byte of the 
8439 \emph on 
8440 generic
8441 \emph default 
8442  pointers contains the data space information.
8443  Assembler support routines are called whenever data is stored or retrieved
8444  using 
8445 \emph on 
8446 generic
8447 \emph default 
8448  pointers.
8449  These are useful for developing reusable library
8450 \begin_inset LatexCommand \index{Libraries}
8451
8452 \end_inset 
8453
8454  routines.
8455  Explicitly specifying the pointer type will generate the most efficient
8456  code.
8457 \layout Subsubsection
8458
8459 Notes on MCS51 memory
8460 \begin_inset LatexCommand \index{MCS51 memory}
8461
8462 \end_inset 
8463
8464  layout
8465 \layout Standard
8466
8467 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
8468  RAM memory which is structured as follows:
8469 \newline 
8470
8471 \newline 
8472 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
8473  
8474 \newline 
8475 - Bytes 20-2F - 16 bytes to hold 128 bit
8476 \begin_inset LatexCommand \index{bit}
8477
8478 \end_inset 
8479
8480  variables and, 
8481 \newline 
8482 - Bytes 30-7F - 80 bytes for general purpose use.
8483 \newline 
8484
8485 \layout Standard
8486
8487 Additionally some members of the MCS51 family may have up to 128 bytes of
8488  additional, indirectly addressable, internal RAM memory (
8489 \emph on 
8490 idata
8491 \emph default 
8492
8493 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
8494
8495 \end_inset 
8496
8497 ).
8498  Furthermore, some chips may have some built in external memory (
8499 \emph on 
8500 xdata
8501 \emph default 
8502
8503 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
8504
8505 \end_inset 
8506
8507 ) which should not be confused with the internal, directly addressable RAM
8508  memory (
8509 \emph on 
8510 data
8511 \emph default 
8512
8513 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
8514
8515 \end_inset 
8516
8517 ).
8518  Sometimes this built in 
8519 \emph on 
8520 xdata
8521 \emph default 
8522  memory has to be activated before using it (you can probably find this
8523  information on the datasheet of the microcontroller your are using, see
8524  also section 
8525 \begin_inset LatexCommand \ref{sub:Startup-Code}
8526
8527 \end_inset 
8528
8529 \SpecialChar ~
8530 Startup-Code).
8531 \layout Standard
8532
8533 Normally SDCC will only use the first bank
8534 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
8535
8536 \end_inset 
8537
8538  of registers (register bank 0), but it is possible to specify that other
8539  banks of registers should be used in interrupt
8540 \begin_inset LatexCommand \index{interrupt}
8541
8542 \end_inset 
8543
8544  routines.
8545  By default, the compiler will place the stack after the last byte of allocated
8546  memory for variables.
8547  For example, if the first 2 banks of registers are used, and only four
8548  bytes are used for 
8549 \emph on 
8550 data
8551 \emph default 
8552  variables, it will position the base of the internal stack at address 20
8553  (0x14).
8554  This implies that as the stack
8555 \begin_inset LatexCommand \index{stack}
8556
8557 \end_inset 
8558
8559  grows, it will use up the remaining register banks, and the 16 bytes used
8560  by the 128 bit variables, and 80 bytes for general purpose use.
8561  If any bit variables are used, the data variables will be placed after
8562  the byte holding the last bit variable.
8563  For example, if register banks 0 and 1 are used, and there are 9 bit variables
8564  (two bytes used), 
8565 \emph on 
8566 data
8567 \emph default 
8568  variables will be placed starting at address 0x22.
8569  You can also use -
8570 \begin_inset ERT
8571 status Collapsed
8572
8573 \layout Standard
8574
8575 \backslash 
8576 /
8577 \end_inset 
8578
8579 -data-loc
8580 \begin_inset LatexCommand \index{-\/-data-loc<Value>}
8581
8582 \end_inset 
8583
8584  to specify the start address of the 
8585 \emph on 
8586 data
8587 \emph default 
8588  and -
8589 \begin_inset ERT
8590 status Collapsed
8591
8592 \layout Standard
8593
8594 \backslash 
8595 /
8596 \end_inset 
8597
8598 -iram-size to specify the size of the total internal RAM (
8599 \emph on 
8600 data
8601 \emph default 
8602 +
8603 \emph on 
8604 idata
8605 \emph default 
8606 ).
8607  
8608 \layout Standard
8609
8610 By default the 8051 linker will place the stack after the last byte of data
8611  variables.
8612  Option -
8613 \begin_inset ERT
8614 status Collapsed
8615
8616 \layout Standard
8617
8618 \backslash 
8619 /
8620 \end_inset 
8621
8622 -stack-loc
8623 \begin_inset LatexCommand \index{-\/-stack-loc<Value>}
8624
8625 \end_inset 
8626
8627  allows you to specify the start of the stack, i.e.
8628  you could start it after any data in the general purpose area.
8629  If your microcontroller has additional indirectly addressable internal
8630  RAM (
8631 \emph on 
8632 idata
8633 \emph default 
8634 ) you can place the stack on it.
8635  You may also need to use -
8636 \begin_inset ERT
8637 status Collapsed
8638
8639 \layout Standard
8640
8641 \backslash 
8642 /
8643 \end_inset 
8644
8645 -xdata-loc
8646 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
8647
8648 \end_inset 
8649
8650  to set the start address of the external RAM (
8651 \emph on 
8652 xdata
8653 \emph default 
8654 ) and -
8655 \begin_inset ERT
8656 status Collapsed
8657
8658 \layout Standard
8659
8660 \backslash 
8661 /
8662 \end_inset 
8663
8664 -xram-size
8665 \begin_inset LatexCommand \index{-\/-data-loc}
8666
8667 \end_inset 
8668
8669  to specify its size.
8670  Same goes for the code memory, using -
8671 \begin_inset ERT
8672 status Collapsed
8673
8674 \layout Standard
8675
8676 \backslash 
8677 /
8678 \end_inset 
8679
8680 -code-loc
8681 \begin_inset LatexCommand \index{-\/-data-loc}
8682
8683 \end_inset 
8684
8685  and -
8686 \begin_inset ERT
8687 status Collapsed
8688
8689 \layout Standard
8690
8691 \backslash 
8692 /
8693 \end_inset 
8694
8695 -code-size
8696 \begin_inset LatexCommand \index{-\/-data-loc}
8697
8698 \end_inset 
8699
8700 .
8701  If in doubt, don't specify any options and see if the resulting memory
8702  layout is appropriate, then you can adjust it.
8703 \layout Standard
8704
8705 The linker generates two files with memory allocation information.
8706  The first, with extension .map
8707 \begin_inset LatexCommand \index{<file>.map}
8708
8709 \end_inset 
8710
8711  shows all the variables and segments.
8712  The second with extension .mem
8713 \begin_inset LatexCommand \index{<file>.mem}
8714
8715 \end_inset 
8716
8717  shows the final memory layout.
8718  The linker will complain either if memory segments overlap, there is not
8719  enough memory, or there is not enough space for stack.
8720  If you get any linking warnings and/or errors related to stack or segments
8721  allocation, take a look at either the .map or .mem files to find out what
8722  the problem is.
8723  The .mem file may even suggest a solution to the problem.
8724 \layout Subsection
8725
8726 Z80/Z180 Storage Class
8727 \begin_inset LatexCommand \index{Storage class}
8728
8729 \end_inset 
8730
8731  Language Extensions
8732 \layout Subsubsection
8733
8734 sfr
8735 \begin_inset LatexCommand \index{sfr}
8736
8737 \end_inset 
8738
8739  (in/out to 8-bit addresses)
8740 \layout Standard
8741
8742 The Z80
8743 \begin_inset LatexCommand \index{Z80}
8744
8745 \end_inset 
8746
8747  family has separate address spaces for memory and 
8748 \emph on 
8749 i
8750 \emph default 
8751 nput/
8752 \emph on 
8753 o
8754 \emph default 
8755 utput memory.
8756  I/O memory
8757 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
8758
8759 \end_inset 
8760
8761  is accessed with special instructions, e.g.:
8762 \layout Verse
8763
8764
8765 \family typewriter 
8766 sfr at 0x78 IoPort;\SpecialChar ~
8767 \SpecialChar ~
8768 /* define a var in I/O space at 78h called IoPort */
8769  
8770 \layout Standard
8771
8772 Writing 0x01 to this variable generates the assembly code:
8773 \layout Verse
8774
8775
8776 \family typewriter 
8777 3E 01\SpecialChar ~
8778 \SpecialChar ~
8779 \SpecialChar ~
8780 \SpecialChar ~
8781 \SpecialChar ~
8782 \SpecialChar ~
8783 ld a,#0x01
8784 \newline 
8785 D3 78\SpecialChar ~
8786 \SpecialChar ~
8787 \SpecialChar ~
8788 \SpecialChar ~
8789 \SpecialChar ~
8790 \SpecialChar ~
8791 out (_IoPort),a 
8792 \layout Subsubsection
8793
8794 banked sfr
8795 \begin_inset LatexCommand \index{sfr}
8796
8797 \end_inset 
8798
8799  (in/out to 16-bit addresses)
8800 \layout Standard
8801
8802 The keyword 
8803 \emph on 
8804 banked
8805 \emph default 
8806  is used to support 16 bit addresses in I/O memory e.g.:
8807 \layout Verse
8808
8809
8810 \family typewriter 
8811 sfr banked at
8812 \begin_inset LatexCommand \index{at}
8813
8814 \end_inset 
8815
8816  0x123 IoPort; 
8817 \layout Standard
8818
8819 Writing 0x01 to this variable generates the assembly code:
8820 \layout Verse
8821
8822
8823 \family typewriter 
8824 01 23 01\SpecialChar ~
8825 \SpecialChar ~
8826 \SpecialChar ~
8827 ld bc,#_IoPort
8828 \newline 
8829 3E 01\SpecialChar ~
8830 \SpecialChar ~
8831 \SpecialChar ~
8832 \SpecialChar ~
8833 \SpecialChar ~
8834 \SpecialChar ~
8835 ld a,#0x01 
8836 \newline 
8837 ED 79\SpecialChar ~
8838 \SpecialChar ~
8839 \SpecialChar ~
8840 \SpecialChar ~
8841 \SpecialChar ~
8842 \SpecialChar ~
8843 out (c),a 
8844 \layout Subsubsection
8845
8846 sfr
8847 \begin_inset LatexCommand \index{sfr}
8848
8849 \end_inset 
8850
8851  (in0/out0 to 8 bit addresses on Z180
8852 \begin_inset LatexCommand \index{Z180}
8853
8854 \end_inset 
8855
8856 /HD64180
8857 \begin_inset LatexCommand \index{HD64180}
8858
8859 \end_inset 
8860
8861 )
8862 \layout Standard
8863
8864 The compiler option -
8865 \begin_inset ERT
8866 status Collapsed
8867
8868 \layout Standard
8869
8870 \backslash 
8871 /
8872 \end_inset 
8873
8874 -portmode=180 (80) and a compiler #pragma\SpecialChar ~
8875 portmode
8876 \begin_inset LatexCommand \index{\#pragma portmode}
8877
8878 \end_inset 
8879
8880 =z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
8881 ns 
8882 \family typewriter 
8883 in0/out0
8884 \family default 
8885  instead of 
8886 \family typewriter 
8887 in/out
8888 \family default 
8889 .
8890  If you include the file z180.h this will be set automatically.
8891 \layout Subsection
8892
8893 HC08 Storage Class
8894 \begin_inset LatexCommand \index{Storage class}
8895
8896 \end_inset 
8897
8898  Language Extensions
8899 \layout Subsubsection
8900
8901 data
8902 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
8903
8904 \end_inset 
8905
8906
8907 \layout Standard
8908
8909 The data storage class declares a variable that resides in the first 256
8910  bytes of memory (the direct page).
8911  The HC08 is most efficient at accessing variables (especially pointers)
8912  stored here.
8913 \layout Subsubsection
8914
8915 xdata
8916 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
8917
8918 \end_inset 
8919
8920
8921 \layout Standard
8922
8923 The xdata storage class declares a variable that can reside anywhere in
8924  memory.
8925  This is the default if no storage class is specified.
8926  
8927 \layout Section
8928
8929 Absolute Addressing
8930 \begin_inset LatexCommand \index{Absolute addressing}
8931
8932 \end_inset 
8933
8934
8935 \layout Standard
8936
8937 Data items can be assigned an absolute address with the 
8938 \emph on 
8939 at
8940 \begin_inset LatexCommand \index{at}
8941
8942 \end_inset 
8943
8944  <address>
8945 \emph default 
8946  keyword, in addition to a storage class, e.g.:
8947 \layout Verse
8948
8949
8950 \family typewriter 
8951 xdata
8952 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
8953
8954 \end_inset 
8955
8956  at
8957 \begin_inset LatexCommand \index{at}
8958
8959 \end_inset 
8960
8961  0x7ffe unsigned int chksum;
8962 \layout Standard
8963
8964 In the above example the variable chksum will located at 0x7ffe and 0x7fff
8965  of the external ram.
8966  The compiler does 
8967 \emph on 
8968 not
8969 \emph default 
8970  reserve any space for variables declared in this way (they are implemented
8971  with an equate in the assembler).
8972  Thus it is left to the programmer to make sure there are no overlaps with
8973  other variables that are declared without the absolute address.
8974  The assembler listing file (.lst
8975 \begin_inset LatexCommand \index{<file>.lst}
8976
8977 \end_inset 
8978
8979 ) and the linker output files (.rst
8980 \begin_inset LatexCommand \index{<file>.rst}
8981
8982 \end_inset 
8983
8984 ) and (.map
8985 \begin_inset LatexCommand \index{<file>.map}
8986
8987 \end_inset 
8988
8989 ) are good places to look for such overlaps.
8990  Variables with an absolute address are 
8991 \emph on 
8992 not
8993 \emph default 
8994  initialized
8995 \begin_inset LatexCommand \index{Variable initialization}
8996
8997 \end_inset 
8998
8999 .
9000 \layout Standard
9001
9002 In case of memory mapped I/O devices the keyword 
9003 \emph on 
9004 volatile
9005 \emph default 
9006  should be used to tell the compiler that accesses might not be optimized
9007  away:
9008 \layout Verse
9009
9010
9011 \family typewriter 
9012 volatile
9013 \begin_inset LatexCommand \index{volatile}
9014
9015 \end_inset 
9016
9017  xdata
9018 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9019
9020 \end_inset 
9021
9022  at
9023 \begin_inset LatexCommand \index{at}
9024
9025 \end_inset 
9026
9027  0x8000 unsigned char PORTA_8255;
9028 \layout Standard
9029
9030 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
9031 r) array
9032 \family typewriter 
9033 \size footnotesize 
9034
9035 \begin_inset LatexCommand \index{Aligned array}
9036
9037 \end_inset 
9038
9039
9040 \family default 
9041 \size default 
9042  starts at a block (256 byte) boundary
9043 \begin_inset LatexCommand \index{block boundary}
9044
9045 \end_inset 
9046
9047  (section 
9048 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
9049
9050 \end_inset 
9051
9052  has an example).
9053 \newline 
9054 Absolute addresses can be specified for variables in all storage classes,
9055  e.g.:
9056 \layout Verse
9057
9058
9059 \family typewriter 
9060 bit
9061 \begin_inset LatexCommand \index{bit}
9062
9063 \end_inset 
9064
9065  at
9066 \begin_inset LatexCommand \index{at}
9067
9068 \end_inset 
9069
9070  0x02 bvar;
9071 \layout Standard
9072
9073 The above example will allocate the variable at offset 0x02 in the bit-addressab
9074 le space.
9075  There is no real advantage to assigning absolute addresses to variables
9076  in this manner, unless you want strict control over all the variables allocated.
9077  One possible use would be to write hardware portable code.
9078  For example, if you have a routine that uses one or more of the microcontroller
9079  I/O pins, and such pins are different for two different hardwares, you
9080  can declare the I/O pins in your routine using:
9081 \layout Verse
9082
9083
9084 \family typewriter 
9085 extern volatile bit SDI;
9086 \newline 
9087 extern volatile bit SCLK;
9088 \newline 
9089 extern volatile bit CPOL;
9090 \newline 
9091
9092 \newline 
9093 void DS1306_put(unsigned char value)
9094 \newline 
9095 {
9096 \newline 
9097 \SpecialChar ~
9098 \SpecialChar ~
9099 \SpecialChar ~
9100 \SpecialChar ~
9101 unsigned char mask=0x80;
9102 \newline 
9103
9104 \newline 
9105 \SpecialChar ~
9106 \SpecialChar ~
9107 \SpecialChar ~
9108 \SpecialChar ~
9109 while(mask)
9110 \newline 
9111 \SpecialChar ~
9112 \SpecialChar ~
9113 \SpecialChar ~
9114 \SpecialChar ~
9115 {
9116 \newline 
9117 \SpecialChar ~
9118 \SpecialChar ~
9119 \SpecialChar ~
9120 \SpecialChar ~
9121 \SpecialChar ~
9122 \SpecialChar ~
9123 \SpecialChar ~
9124 \SpecialChar ~
9125 SDI=(value & mask)?1:0;
9126 \newline 
9127 \SpecialChar ~
9128 \SpecialChar ~
9129 \SpecialChar ~
9130 \SpecialChar ~
9131 \SpecialChar ~
9132 \SpecialChar ~
9133 \SpecialChar ~
9134 \SpecialChar ~
9135 SCLK=!CPOL;
9136 \newline 
9137 \SpecialChar ~
9138 \SpecialChar ~
9139 \SpecialChar ~
9140 \SpecialChar ~
9141 \SpecialChar ~
9142 \SpecialChar ~
9143 \SpecialChar ~
9144 \SpecialChar ~
9145 SCLK=CPOL;
9146 \newline 
9147 \SpecialChar ~
9148 \SpecialChar ~
9149 \SpecialChar ~
9150 \SpecialChar ~
9151 \SpecialChar ~
9152 \SpecialChar ~
9153 \SpecialChar ~
9154 \SpecialChar ~
9155 mask/=2;
9156 \newline 
9157 \SpecialChar ~
9158 \SpecialChar ~
9159 \SpecialChar ~
9160 \SpecialChar ~
9161 }
9162 \newline 
9163 }
9164 \layout Standard
9165
9166 Then, someplace in the code for the first hardware you would use
9167 \layout Verse
9168
9169
9170 \family typewriter 
9171 bit at 0x80 SDI;\SpecialChar ~
9172 \SpecialChar ~
9173 \SpecialChar ~
9174 \SpecialChar ~
9175 /* I/O port 0, bit 0 */
9176 \newline 
9177 bit at 0x81 SCLK;\SpecialChar ~
9178 \SpecialChar ~
9179 \SpecialChar ~
9180 /* I/O port 0, bit 1 */
9181 \newline 
9182 bit CPOL;\SpecialChar ~
9183 \SpecialChar ~
9184 \SpecialChar ~
9185 \SpecialChar ~
9186 \SpecialChar ~
9187 \SpecialChar ~
9188 \SpecialChar ~
9189 \SpecialChar ~
9190 \SpecialChar ~
9191 \SpecialChar ~
9192 \SpecialChar ~
9193 /* This is a variable, let the linker allocate this one */
9194 \layout Standard
9195
9196 Similarly, for the second hardware you would use
9197 \layout Verse
9198
9199
9200 \family typewriter 
9201 bit at 0x83 SDI;\SpecialChar ~
9202 \SpecialChar ~
9203 \SpecialChar ~
9204 \SpecialChar ~
9205 /* I/O port 0, bit 3 */
9206 \newline 
9207 bit at 0x91 SCLK;\SpecialChar ~
9208 \SpecialChar ~
9209 \SpecialChar ~
9210 /* I/O port 1, bit 1 */
9211 \newline 
9212 bit
9213 \begin_inset LatexCommand \index{bit}
9214
9215 \end_inset 
9216
9217  CPOL;\SpecialChar ~
9218 \SpecialChar ~
9219 \SpecialChar ~
9220 \SpecialChar ~
9221 \SpecialChar ~
9222 \SpecialChar ~
9223 \SpecialChar ~
9224 \SpecialChar ~
9225 \SpecialChar ~
9226 \SpecialChar ~
9227 \SpecialChar ~
9228 /* This is a variable, let the linker allocate this one */
9229 \layout Standard
9230
9231 and you can use the same hardware dependent routine without changes, as
9232  for example in a library.
9233  This is somehow similar to sbit, but only one absolute address has to be
9234  specified in the whole project.
9235 \layout Section
9236
9237 Parameters
9238 \begin_inset LatexCommand \index{Parameters}
9239
9240 \end_inset 
9241
9242
9243 \begin_inset LatexCommand \index{function parameter}
9244
9245 \end_inset 
9246
9247  & Local Variables
9248 \begin_inset LatexCommand \index{local variables}
9249
9250 \end_inset 
9251
9252
9253 \layout Standard
9254
9255 Automatic (local) variables and parameters to functions can either be placed
9256  on the stack or in data-space.
9257  The default action of the compiler is to place these variables in the internal
9258  RAM (for small model) or external RAM (for large model).
9259  This in fact makes them similar to 
9260 \emph on 
9261 static
9262 \begin_inset LatexCommand \index{static}
9263
9264 \end_inset 
9265
9266
9267 \emph default 
9268  so by default functions are non-reentrant
9269 \begin_inset LatexCommand \index{reentrant}
9270
9271 \end_inset 
9272
9273 .
9274  
9275 \newline 
9276
9277 \newline 
9278 They can be placed on the stack
9279 \begin_inset LatexCommand \index{stack}
9280
9281 \end_inset 
9282
9283  either by using the
9284 \emph on 
9285  -
9286 \begin_inset ERT
9287 status Collapsed
9288
9289 \layout Standard
9290
9291 \backslash 
9292 /
9293 \end_inset 
9294
9295 -stack-auto
9296 \begin_inset LatexCommand \index{-\/-stack-auto}
9297
9298 \end_inset 
9299
9300
9301 \emph default 
9302  option or by using the 
9303 \emph on 
9304 reentrant
9305 \begin_inset LatexCommand \index{reentrant}
9306
9307 \end_inset 
9308
9309
9310 \emph default 
9311  keyword in the function declaration, e.g.:
9312 \layout Verse
9313
9314
9315 \family typewriter 
9316 unsigned char foo(char i) reentrant 
9317 \newline 
9318
9319 \newline 
9320 \SpecialChar ~
9321 \SpecialChar ~
9322 \SpecialChar ~
9323 \SpecialChar ~
9324 ...
9325  
9326 \newline 
9327 }
9328 \layout Standard
9329
9330 Since stack space on 8051 is limited, the 
9331 \emph on 
9332 reentrant 
9333 \emph default 
9334 keyword or the
9335 \emph on 
9336  -
9337 \begin_inset ERT
9338 status Collapsed
9339
9340 \layout Standard
9341
9342 \backslash 
9343 /
9344 \end_inset 
9345
9346 -stack-auto
9347 \emph default 
9348  option should be used sparingly.
9349  Note that the reentrant keyword just means that the parameters & local
9350  variables will be allocated to the stack, it 
9351 \emph on 
9352 does not
9353 \emph default 
9354  mean that the function is register bank
9355 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
9356
9357 \end_inset 
9358
9359  independent.
9360 \newline 
9361
9362 \newline 
9363 Local variables
9364 \begin_inset LatexCommand \index{local variables}
9365
9366 \end_inset 
9367
9368  can be assigned storage classes and absolute
9369 \begin_inset LatexCommand \index{Absolute addressing}
9370
9371 \end_inset 
9372
9373  addresses, e.g.: 
9374 \layout Verse
9375
9376
9377 \family typewriter 
9378 unsigned char foo() 
9379 \newline 
9380 {
9381 \newline 
9382 \SpecialChar ~
9383 \SpecialChar ~
9384 \SpecialChar ~
9385 \SpecialChar ~
9386 xdata unsigned char i;
9387 \newline 
9388 \SpecialChar ~
9389 \SpecialChar ~
9390 \SpecialChar ~
9391 \SpecialChar ~
9392 bit bvar;
9393 \newline 
9394 \SpecialChar ~
9395 \SpecialChar ~
9396 \SpecialChar ~
9397 \SpecialChar ~
9398 data at
9399 \begin_inset LatexCommand \index{at}
9400
9401 \end_inset 
9402
9403  0x31 unsigned char j;
9404 \newline 
9405 \SpecialChar ~
9406 \SpecialChar ~
9407 \SpecialChar ~
9408 \SpecialChar ~
9409 ...
9410  
9411 \newline 
9412 }
9413 \layout Standard
9414
9415 In the above example the variable 
9416 \emph on 
9417 i
9418 \emph default 
9419  will be allocated in the external ram, 
9420 \emph on 
9421 bvar
9422 \emph default 
9423  in bit addressable space and
9424 \emph on 
9425  j
9426 \emph default 
9427  in internal ram.
9428  When compiled with 
9429 \emph on 
9430 -
9431 \begin_inset ERT
9432 status Collapsed
9433
9434 \layout Standard
9435
9436 \backslash 
9437 /
9438 \end_inset 
9439
9440 -stack-auto
9441 \emph default 
9442  or when a function is declared as 
9443 \emph on 
9444 reentrant
9445 \emph default 
9446  this should only be done for static variables.
9447 \layout Standard
9448
9449 Parameters
9450 \begin_inset LatexCommand \index{function parameter}
9451
9452 \end_inset 
9453
9454  however are not allowed any storage class
9455 \begin_inset LatexCommand \index{Storage class}
9456
9457 \end_inset 
9458
9459 , (storage classes for parameters will be ignored), their allocation is
9460  governed by the memory model in use, and the reentrancy options.
9461 \layout Section
9462
9463 Overlaying
9464 \begin_inset LatexCommand \label{sub:Overlaying}
9465
9466 \end_inset 
9467
9468
9469 \begin_inset LatexCommand \index{Overlaying}
9470
9471 \end_inset 
9472
9473
9474 \layout Standard
9475
9476 For non-reentrant
9477 \begin_inset LatexCommand \index{reentrant}
9478
9479 \end_inset 
9480
9481  functions SDCC will try to reduce internal ram space usage by overlaying
9482  parameters and local variables of a function (if possible).
9483  Parameters and local variables
9484 \begin_inset LatexCommand \index{local variables}
9485
9486 \end_inset 
9487
9488  of a function will be allocated to an overlayable segment if the function
9489  has 
9490 \emph on 
9491 no other function calls and the function is non-reentrant and the memory
9492  model
9493 \begin_inset LatexCommand \index{Memory model}
9494
9495 \end_inset 
9496
9497  is small.
9498
9499 \emph default 
9500  If an explicit storage class
9501 \begin_inset LatexCommand \index{Storage class}
9502
9503 \end_inset 
9504
9505  is specified for a local variable, it will NOT be overlayed.
9506 \layout Standard
9507
9508 Note that the compiler (not the linkage editor) makes the decision for overlayin
9509 g the data items.
9510  Functions that are called from an interrupt service routine should be preceded
9511  by a #pragma\SpecialChar ~
9512 nooverlay
9513 \begin_inset LatexCommand \index{\#pragma nooverlay}
9514
9515 \end_inset 
9516
9517  if they are not reentrant.
9518 \layout Standard
9519
9520 Also note that the compiler does not do any processing of inline assembler
9521  code, so the compiler might incorrectly assign local variables and parameters
9522  of a function into the overlay segment if the inline assembler code calls
9523  other c-functions that might use the overlay.
9524  In that case the #pragma\SpecialChar ~
9525 nooverlay should be used.
9526 \layout Standard
9527
9528 Parameters and local variables of functions that contain 16 or 32 bit multiplica
9529 tion
9530 \begin_inset LatexCommand \index{Multiplication}
9531
9532 \end_inset 
9533
9534  or division
9535 \begin_inset LatexCommand \index{Division}
9536
9537 \end_inset 
9538
9539  will NOT be overlayed since these are implemented using external functions,
9540  e.g.:
9541 \layout Verse
9542
9543
9544 \family typewriter 
9545 #pragma save 
9546 \newline 
9547 #pragma nooverlay
9548 \begin_inset LatexCommand \index{\#pragma nooverlay}
9549
9550 \end_inset 
9551
9552  
9553 \newline 
9554 void set_error(unsigned char errcd) 
9555 \newline 
9556 {
9557 \newline 
9558 \SpecialChar ~
9559 \SpecialChar ~
9560 \SpecialChar ~
9561 \SpecialChar ~
9562 P3 = errcd;
9563 \newline 
9564
9565 \newline 
9566 #pragma restore 
9567 \newline 
9568
9569 \newline 
9570 void some_isr () interrupt
9571 \begin_inset LatexCommand \index{interrupt}
9572
9573 \end_inset 
9574
9575  2
9576 \newline 
9577 {
9578 \newline 
9579 \SpecialChar ~
9580 \SpecialChar ~
9581 \SpecialChar ~
9582 \SpecialChar ~
9583 ...
9584 \newline 
9585 \SpecialChar ~
9586 \SpecialChar ~
9587 \SpecialChar ~
9588 \SpecialChar ~
9589 set_error(10);
9590 \newline 
9591 \SpecialChar ~
9592 \SpecialChar ~
9593 \SpecialChar ~
9594 \SpecialChar ~
9595 ...
9596  
9597 \newline 
9598 }
9599 \layout Standard
9600
9601 In the above example the parameter 
9602 \emph on 
9603 errcd
9604 \emph default 
9605  for the function 
9606 \emph on 
9607 set_error
9608 \emph default 
9609  would be assigned to the overlayable segment if the #pragma\SpecialChar ~
9610 nooverlay was
9611  not present, this could cause unpredictable runtime behavior when called
9612  from an interrupt service routine.
9613  The #pragma\SpecialChar ~
9614 nooverlay ensures that the parameters and local variables for
9615  the function are NOT overlayed.
9616 \layout Section
9617
9618 Interrupt Service Routines
9619 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
9620
9621 \end_inset 
9622
9623
9624 \layout Subsection
9625
9626 General Information
9627 \layout Standard
9628
9629 SDCC allows 
9630 \emph on 
9631 i
9632 \emph default 
9633 nterrupt 
9634 \emph on 
9635 s
9636 \emph default 
9637 ervice 
9638 \emph on 
9639 r
9640 \emph default 
9641 outines to be coded in C, with some extended keywords.
9642 \layout Verse
9643
9644
9645 \family typewriter 
9646 void timer_isr (void) interrupt 1 using 1 
9647 \newline 
9648
9649 \newline 
9650 \SpecialChar ~
9651 \SpecialChar ~
9652 \SpecialChar ~
9653 \SpecialChar ~
9654 ...
9655  
9656 \newline 
9657 }
9658 \layout Standard
9659
9660 The optional number following the 
9661 \emph on 
9662 interrupt
9663 \begin_inset LatexCommand \index{interrupt}
9664
9665 \end_inset 
9666
9667
9668 \emph default 
9669  keyword is the interrupt number this routine will service.
9670  When present, the compiler will insert a call to this routine in the interrupt
9671  vector table for the interrupt number specified.
9672  If you have multiple source files in your project, interrupt service routines
9673  can be present in any of them, but a prototype of the isr MUST be present
9674  or included in the file that contains the function 
9675 \emph on 
9676 main
9677 \emph default 
9678 .
9679  The 
9680 \emph on 
9681 using
9682 \emph default 
9683  keyword can be used to tell the compiler to use the specified register
9684  bank (8051 specific) when generating code for this function.
9685  
9686 \newline 
9687
9688 \layout Standard
9689
9690 Interrupt service routines open the door for some very interesting bugs:
9691  
9692 \layout Standard
9693
9694 If the interrupt service routines changes variables which are accessed by
9695  other functions these variables should be declared 
9696 \emph on 
9697 volatile
9698 \emph default 
9699
9700 \begin_inset LatexCommand \index{volatile}
9701
9702 \end_inset 
9703
9704 .
9705  
9706 \layout Standard
9707
9708 If the access to these variables is not 
9709 \emph on 
9710 atomic
9711 \begin_inset LatexCommand \index{atomic access}
9712
9713 \end_inset 
9714
9715
9716 \emph default 
9717  (i.e.
9718  the processor needs more than one instruction for the access and could
9719  be interrupted while accessing the variable) the interrupt must disabled
9720  during the access to avoid inconsistent data.
9721  Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
9722  and should be protected by disabling interrupts.
9723  You're not automatically on the safe side if you use 8 bit variables though.
9724  We need an example here: f.e.
9725  on the 8051 the harmless looking 
9726 \begin_inset Quotes srd
9727 \end_inset 
9728
9729
9730 \family typewriter 
9731 flags\SpecialChar ~
9732 |=\SpecialChar ~
9733 0x80;
9734 \family default 
9735
9736 \begin_inset Quotes sld
9737 \end_inset 
9738
9739  is not atomic if 
9740 \family typewriter 
9741 flags
9742 \family default 
9743  resides in xdata.
9744  Setting 
9745 \begin_inset Quotes srd
9746 \end_inset 
9747
9748
9749 \family typewriter 
9750 flags\SpecialChar ~
9751 |=\SpecialChar ~
9752 0x40;
9753 \family default 
9754
9755 \begin_inset Quotes sld
9756 \end_inset 
9757
9758  from within an interrupt routine might get lost if the interrupt occurs
9759  at the wrong time.
9760  
9761 \begin_inset Quotes sld
9762 \end_inset 
9763
9764
9765 \family typewriter 
9766 counter\SpecialChar ~
9767 +=\SpecialChar ~
9768 8;
9769 \family default 
9770
9771 \begin_inset Quotes srd
9772 \end_inset 
9773
9774  is not atomic on the 8051 even if 
9775 \family typewriter 
9776 counter
9777 \family default 
9778  is located in data memory.
9779  Bugs like these are hard to reproduce and can cause a lot of trouble.
9780  
9781 \layout Standard
9782
9783 A special note here, int (16 bit) and long (32 bit) integer division
9784 \begin_inset LatexCommand \index{Division}
9785
9786 \end_inset 
9787
9788 , multiplication
9789 \begin_inset LatexCommand \index{Multiplication}
9790
9791 \end_inset 
9792
9793  & modulus
9794 \begin_inset LatexCommand \index{Modulus}
9795
9796 \end_inset 
9797
9798  and floating-point
9799 \begin_inset LatexCommand \index{Floating point support}
9800
9801 \end_inset 
9802
9803  operations are implemented using external support routines developed in
9804  ANSI-C.
9805  If an interrupt service routine needs to do any of these operations then
9806  the support routines (as mentioned in a following section) will have to
9807  be recompiled using the
9808 \emph on 
9809  -
9810 \begin_inset ERT
9811 status Collapsed
9812
9813 \layout Standard
9814
9815 \backslash 
9816 /
9817 \end_inset 
9818
9819 -stack-auto
9820 \begin_inset LatexCommand \index{-\/-stack-auto}
9821
9822 \end_inset 
9823
9824
9825 \emph default 
9826  option and the source file will need to be compiled using the 
9827 \emph on 
9828 -
9829 \begin_inset ERT
9830 status Collapsed
9831
9832 \layout Standard
9833
9834 \backslash 
9835 /
9836 \end_inset 
9837
9838 -int-long-reent
9839 \emph default 
9840
9841 \begin_inset LatexCommand \index{-\/-int-long-reent}
9842
9843 \end_inset 
9844
9845  compiler option.
9846 \layout Standard
9847
9848 Calling other functions from an interrupt service routine is not recommended,
9849  avoid it if possible.
9850  Note that when some function is called from an interrupt service routine
9851  it should be preceded by a #pragma\SpecialChar ~
9852 nooverlay
9853 \begin_inset LatexCommand \index{\#pragma nooverlay}
9854
9855 \end_inset 
9856
9857  if it is not reentrant.
9858  Furthermore nonreentrant functions should not be called from the main program
9859  while the interrupt service routine might be active.
9860  
9861 \newline 
9862
9863 \newline 
9864 Also see section 
9865 \begin_inset LatexCommand \ref{sub:Overlaying}
9866
9867 \end_inset 
9868
9869 \SpecialChar ~
9870 about Overlaying and section 
9871 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
9872
9873 \end_inset 
9874
9875 \SpecialChar ~
9876 about Functions using private register banks.
9877 \layout Subsection
9878
9879 MCS51/DS390 Interrupt Service Routines
9880 \layout Standard
9881
9882 Interrupt numbers and the corresponding address & descriptions for the Standard
9883  8051/8052 are listed below.
9884  SDCC will automatically adjust the interrupt vector table to the maximum
9885  interrupt number specified.
9886 \newline 
9887
9888 \layout Standard
9889 \align center 
9890
9891 \begin_inset  Tabular
9892 <lyxtabular version="3" rows="7" columns="3">
9893 <features>
9894 <column alignment="center" valignment="top" leftline="true" width="0in">
9895 <column alignment="center" valignment="top" leftline="true" width="0in">
9896 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0in">
9897 <row topline="true" bottomline="true">
9898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9899 \begin_inset Text
9900
9901 \layout Standard
9902
9903 Interrupt #
9904 \end_inset 
9905 </cell>
9906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9907 \begin_inset Text
9908
9909 \layout Standard
9910
9911 Description
9912 \end_inset 
9913 </cell>
9914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9915 \begin_inset Text
9916
9917 \layout Standard
9918
9919 Vector Address
9920 \end_inset 
9921 </cell>
9922 </row>
9923 <row topline="true">
9924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9925 \begin_inset Text
9926
9927 \layout Standard
9928
9929 0
9930 \end_inset 
9931 </cell>
9932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9933 \begin_inset Text
9934
9935 \layout Standard
9936
9937 External 0
9938 \end_inset 
9939 </cell>
9940 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9941 \begin_inset Text
9942
9943 \layout Standard
9944
9945 0x0003
9946 \end_inset 
9947 </cell>
9948 </row>
9949 <row topline="true">
9950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9951 \begin_inset Text
9952
9953 \layout Standard
9954
9955 1
9956 \end_inset 
9957 </cell>
9958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9959 \begin_inset Text
9960
9961 \layout Standard
9962
9963 Timer 0
9964 \end_inset 
9965 </cell>
9966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9967 \begin_inset Text
9968
9969 \layout Standard
9970
9971 0x000B
9972 \end_inset 
9973 </cell>
9974 </row>
9975 <row topline="true">
9976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9977 \begin_inset Text
9978
9979 \layout Standard
9980
9981 2
9982 \end_inset 
9983 </cell>
9984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9985 \begin_inset Text
9986
9987 \layout Standard
9988
9989 External 1
9990 \end_inset 
9991 </cell>
9992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9993 \begin_inset Text
9994
9995 \layout Standard
9996
9997 0x0013
9998 \end_inset 
9999 </cell>
10000 </row>
10001 <row topline="true">
10002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10003 \begin_inset Text
10004
10005 \layout Standard
10006
10007 3
10008 \end_inset 
10009 </cell>
10010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10011 \begin_inset Text
10012
10013 \layout Standard
10014
10015 Timer 1
10016 \end_inset 
10017 </cell>
10018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10019 \begin_inset Text
10020
10021 \layout Standard
10022
10023 0x001B
10024 \end_inset 
10025 </cell>
10026 </row>
10027 <row topline="true">
10028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10029 \begin_inset Text
10030
10031 \layout Standard
10032
10033 4
10034 \end_inset 
10035 </cell>
10036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10037 \begin_inset Text
10038
10039 \layout Standard
10040
10041 Serial
10042 \end_inset 
10043 </cell>
10044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10045 \begin_inset Text
10046
10047 \layout Standard
10048
10049 0x0023
10050 \end_inset 
10051 </cell>
10052 </row>
10053 <row topline="true" bottomline="true">
10054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10055 \begin_inset Text
10056
10057 \layout Standard
10058
10059 5
10060 \end_inset 
10061 </cell>
10062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10063 \begin_inset Text
10064
10065 \layout Standard
10066
10067 Timer 2 (8052)
10068 \end_inset 
10069 </cell>
10070 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10071 \begin_inset Text
10072
10073 \layout Standard
10074
10075 0x002B
10076 \end_inset 
10077 </cell>
10078 </row>
10079 </lyxtabular>
10080
10081 \end_inset 
10082
10083
10084 \newline 
10085
10086 \layout Standard
10087
10088 If the interrupt service routine is defined without 
10089 \emph on 
10090 using
10091 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10092
10093 \end_inset 
10094
10095
10096 \emph default 
10097  a register bank or with register bank 0 (
10098 \emph on 
10099 using
10100 \emph default 
10101  0), the compiler will save the registers used by itself on the stack upon
10102  entry and restore them at exit, however if such an interrupt service routine
10103  calls another function then the entire register bank will be saved on the
10104  stack.
10105  This scheme may be advantageous for small interrupt service routines which
10106  have low register usage.
10107 \layout Standard
10108
10109 If the interrupt service routine is defined to be using a specific register
10110  bank then only 
10111 \emph on 
10112 a, b, dptr
10113 \emph default 
10114  & psw are saved and restored, if such an interrupt service routine calls
10115  another function (using another register bank) then the entire register
10116  bank of the called function will be saved on the stack.
10117  This scheme is recommended for larger interrupt service routines.
10118 \layout Subsection
10119
10120 HC08 Interrupt Service Routines
10121 \layout Standard
10122
10123 Since the number of interrupts available is chip specific and the interrupt
10124  vector table always ends at the last byte of memory, the interrupt numbers
10125  corresponds to the interrupt vectors in reverse order of address.
10126  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
10127  2 will use the interrupt vector at 0xfffa, and so on.
10128  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
10129  this way; instead see section 
10130 \begin_inset LatexCommand \ref{sub:Startup-Code}
10131
10132 \end_inset 
10133
10134  for details on customizing startup.
10135 \layout Section
10136
10137 Enabling and Disabling Interrupts
10138 \layout Subsection
10139
10140 Critical Functions and Critical Statements
10141 \layout Standard
10142
10143 A special keyword may be associated with a block or a function declaring
10144  it as 
10145 \emph on 
10146 critical
10147 \emph default 
10148 .
10149  SDCC will generate code to disable all interrupts
10150 \begin_inset LatexCommand \index{interrupt}
10151
10152 \end_inset 
10153
10154  upon entry to a critical function and restore the interrupt enable to the
10155  previous state before returning.
10156  Nesting critical functions will need one additional byte on the stack
10157 \begin_inset LatexCommand \index{stack}
10158
10159 \end_inset 
10160
10161  for each call.
10162 \layout Verse
10163
10164
10165 \family typewriter 
10166 int foo () critical
10167 \begin_inset LatexCommand \index{critical}
10168
10169 \end_inset 
10170
10171  
10172 \newline 
10173
10174 \newline 
10175 \SpecialChar ~
10176 \SpecialChar ~
10177 \SpecialChar ~
10178 \SpecialChar ~
10179 ...
10180  
10181 \newline 
10182 \SpecialChar ~
10183 \SpecialChar ~
10184 \SpecialChar ~
10185 \SpecialChar ~
10186 ...
10187  
10188 \newline 
10189 }
10190 \layout Standard
10191
10192 The critical attribute maybe used with other attributes like 
10193 \emph on 
10194 reentrant.
10195 \emph default 
10196
10197 \newline 
10198 The keyword 
10199 \emph on 
10200 critical
10201 \emph default 
10202  may also be used to disable interrupts more locally:
10203 \layout Verse
10204
10205
10206 \family typewriter 
10207 critical{ i++; }
10208 \layout Standard
10209
10210 More than one statement could have been included in the block.
10211 \layout Subsection
10212
10213 Enabling and Disabling Interrupts directly
10214 \layout Standard
10215
10216 Interrupts
10217 \begin_inset LatexCommand \index{interrupt}
10218
10219 \end_inset 
10220
10221  can also be disabled and enabled directly (8051):
10222 \layout Verse
10223
10224
10225 \family typewriter 
10226 EA = 0;\SpecialChar ~
10227 \SpecialChar ~
10228 \SpecialChar ~
10229 \SpecialChar ~
10230 \SpecialChar ~
10231 \SpecialChar ~
10232 \SpecialChar ~
10233 \SpecialChar ~
10234 \SpecialChar ~
10235 \SpecialChar ~
10236 \SpecialChar ~
10237 \SpecialChar ~
10238 or:\SpecialChar ~
10239 \SpecialChar ~
10240 \SpecialChar ~
10241 \SpecialChar ~
10242 \SpecialChar ~
10243 \SpecialChar ~
10244 \SpecialChar ~
10245 \SpecialChar ~
10246 \SpecialChar ~
10247 \SpecialChar ~
10248 \SpecialChar ~
10249 EA_SAVE = EA;
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 EA = 0;
10285 \layout Verse
10286
10287
10288 \family typewriter 
10289 EA = 1;\SpecialChar ~
10290 \SpecialChar ~
10291 \SpecialChar ~
10292 \SpecialChar ~
10293 \SpecialChar ~
10294 \SpecialChar ~
10295 \SpecialChar ~
10296 \SpecialChar ~
10297 \SpecialChar ~
10298 \SpecialChar ~
10299 \SpecialChar ~
10300 \SpecialChar ~
10301 \SpecialChar ~
10302 \SpecialChar ~
10303 \SpecialChar ~
10304 \SpecialChar ~
10305 \SpecialChar ~
10306 \SpecialChar ~
10307 \SpecialChar ~
10308 \SpecialChar ~
10309 \SpecialChar ~
10310 \SpecialChar ~
10311 \SpecialChar ~
10312 \SpecialChar ~
10313 \SpecialChar ~
10314 \SpecialChar ~
10315 ...
10316 \layout Verse
10317
10318
10319 \family typewriter 
10320 \SpecialChar ~
10321 \SpecialChar ~
10322 \SpecialChar ~
10323 \SpecialChar ~
10324 \SpecialChar ~
10325 \SpecialChar ~
10326 \SpecialChar ~
10327 \SpecialChar ~
10328 \SpecialChar ~
10329 \SpecialChar ~
10330 \SpecialChar ~
10331 \SpecialChar ~
10332 \SpecialChar ~
10333 \SpecialChar ~
10334 \SpecialChar ~
10335 \SpecialChar ~
10336 \SpecialChar ~
10337 \SpecialChar ~
10338 \SpecialChar ~
10339 \SpecialChar ~
10340 \SpecialChar ~
10341 \SpecialChar ~
10342 \SpecialChar ~
10343 \SpecialChar ~
10344 \SpecialChar ~
10345 \SpecialChar ~
10346 \SpecialChar ~
10347 \SpecialChar ~
10348 \SpecialChar ~
10349 \SpecialChar ~
10350 \SpecialChar ~
10351 \SpecialChar ~
10352 \SpecialChar ~
10353 EA = EA_SAVE;
10354 \layout Standard
10355
10356 On other architectures which have seperate opcodes for enabling and disabling
10357  interrupts you might want to make use of defines with inline assembly
10358 \begin_inset LatexCommand \index{Assembler routines}
10359
10360 \end_inset 
10361
10362  (HC08):
10363 \layout Verse
10364
10365
10366 \family typewriter 
10367 #define CLI _asm
10368 \begin_inset LatexCommand \index{\_asm}
10369
10370 \end_inset 
10371
10372 \SpecialChar ~
10373 \SpecialChar ~
10374 cli\SpecialChar ~
10375 \SpecialChar ~
10376 _endasm
10377 \begin_inset LatexCommand \index{\_endasm}
10378
10379 \end_inset 
10380
10381
10382 \layout Verse
10383
10384
10385 \family typewriter 
10386 #define SEI _asm\SpecialChar ~
10387 \SpecialChar ~
10388 sei\SpecialChar ~
10389 \SpecialChar ~
10390 _endasm; 
10391 \layout Verse
10392
10393
10394 \family typewriter 
10395 ...
10396 \layout Standard
10397
10398 Note: it is sometimes sufficient to disable only a specific interrupt source
10399  like f.e.
10400  a timer or serial interrupt by manipulating an 
10401 \emph on 
10402 interrupt mask
10403 \begin_inset LatexCommand \index{interrupt mask}
10404
10405 \end_inset 
10406
10407
10408 \emph default 
10409  register.
10410  
10411 \layout Standard
10412
10413 Usually the time during which interrupts are disabled should be kept as
10414  short as possible.
10415  This minimizes both 
10416 \emph on 
10417 interrupt latency
10418 \emph default 
10419
10420 \begin_inset LatexCommand \index{interrupt latency}
10421
10422 \end_inset 
10423
10424  (the time between the occurrence of the interrupt and the execution of
10425  the first code in the interrupt routine) and 
10426 \emph on 
10427 interrupt jitter
10428 \emph default 
10429
10430 \begin_inset LatexCommand \index{interrupt jitter}
10431
10432 \end_inset 
10433
10434  (the difference between the shortest and the longest interrupt latency).
10435  These really are something different, f.e.
10436  a serial interrupt has to be served before its buffer overruns so it cares
10437  for the maximum interrupt latency, whereas it does not care about jitter.
10438  On a loudspeaker driven via a digital to analog converter which is fed
10439  by an interrupt a latency of a few milliseconds might be tolerable, whereas
10440  a much smaller jitter will be very audible.
10441 \layout Standard
10442
10443 You can reenable interrupts within an interrupt routine and on some architecture
10444 s you can make use of two (or more) levels of 
10445 \emph on 
10446 interrupt priorities
10447 \emph default 
10448
10449 \begin_inset LatexCommand \index{interrupt priority}
10450
10451 \end_inset 
10452
10453 .
10454  On some architectures which don't support interrupt priorities these can
10455  be implemented by manipulating the interrupt mask and reenabling interrupts
10456  within the interrupt routine.
10457  Don't add complexity unless you have to.
10458  
10459 \layout Section
10460
10461 Functions using private register banks
10462 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
10463
10464 \end_inset 
10465
10466  (mcs51/ds390)
10467 \layout Standard
10468
10469 Some architectures have support for quickly changing register sets.
10470  SDCC supports this feature with the 
10471 \emph on 
10472 using
10473 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10474
10475 \end_inset 
10476
10477
10478 \emph default 
10479  attribute (which tells the compiler to use a register bank
10480 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10481
10482 \end_inset 
10483
10484  other than the default bank zero).
10485  It should only be applied to 
10486 \emph on 
10487 interrupt
10488 \begin_inset LatexCommand \index{interrupt}
10489
10490 \end_inset 
10491
10492
10493 \emph default 
10494  functions (see footnote below).
10495  This will in most circumstances make the generated ISR code more efficient
10496  since it will not have to save registers on the stack.
10497 \layout Standard
10498
10499 The 
10500 \emph on 
10501 using
10502 \emph default 
10503  attribute will have no effect on the generated code for a 
10504 \emph on 
10505 non-interrupt
10506 \emph default 
10507  function (but may occasionally be useful anyway
10508 \begin_inset Foot
10509 collapsed false
10510
10511 \layout Standard
10512
10513 possible exception: if a function is called ONLY from 'interrupt' functions
10514  using a particular bank, it can be declared with the same 'using' attribute
10515  as the calling 'interrupt' functions.
10516  For instance, if you have several ISRs using bank one, and all of them
10517  call memcpy(), it might make sense to create a specialized version of memcpy()
10518  'using 1', since this would prevent the ISR from having to save bank zero
10519  to the stack on entry and switch to bank zero before calling the function
10520 \end_inset 
10521
10522 ).
10523 \newline 
10524
10525 \emph on 
10526 (pending: I don't think this has been done yet)
10527 \layout Standard
10528
10529 An 
10530 \emph on 
10531 interrupt
10532 \emph default 
10533  function using a non-zero bank will assume that it can trash that register
10534  bank, and will not save it.
10535  Since high-priority interrupts
10536 \begin_inset LatexCommand \index{interrupt priority}
10537
10538 \end_inset 
10539
10540  can interrupt low-priority ones on the 8051 and friends, this means that
10541  if a high-priority ISR 
10542 \emph on 
10543 using
10544 \emph default 
10545  a particular bank occurs while processing a low-priority ISR 
10546 \emph on 
10547 using
10548 \emph default 
10549  the same bank, terrible and bad things can happen.
10550  To prevent this, no single register bank should be 
10551 \emph on 
10552 used
10553 \emph default 
10554  by both a high priority and a low priority ISR.
10555  This is probably most easily done by having all high priority ISRs use
10556  one bank and all low priority ISRs use another.
10557  If you have an ISR which can change priority at runtime, you're on your
10558  own: I suggest using the default bank zero and taking the small performance
10559  hit.
10560 \layout Standard
10561
10562 It is most efficient if your ISR calls no other functions.
10563  If your ISR must call other functions, it is most efficient if those functions
10564  use the same bank as the ISR (see note 1 below); the next best is if the
10565  called functions use bank zero.
10566  It is very inefficient to call a function using a different, non-zero bank
10567  from an ISR.
10568  
10569 \layout Section
10570
10571 Startup Code
10572 \begin_inset LatexCommand \label{sub:Startup-Code}
10573
10574 \end_inset 
10575
10576
10577 \begin_inset LatexCommand \index{Startup code}
10578
10579 \end_inset 
10580
10581
10582 \layout Subsection
10583
10584 MCS51/DS390 Startup Code
10585 \layout Standard
10586
10587 The compiler inserts a call to the C routine 
10588 \emph on 
10589 _sdcc_external_startup()
10590 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
10591
10592 \end_inset 
10593
10594
10595 \series bold 
10596 \emph default 
10597  
10598 \series default 
10599 at the start of the CODE area.
10600  This routine is in the runtime library
10601 \begin_inset LatexCommand \index{Runtime library}
10602
10603 \end_inset 
10604
10605 .
10606  By default this routine returns 0, if this routine returns a non-zero value,
10607  the static & global variable initialization will be skipped and the function
10608  main will be invoked.
10609  Otherwise static & global variables will be initialized before the function
10610  main is invoked.
10611  You could add a 
10612 \emph on 
10613 _sdcc_external_startup()
10614 \emph default 
10615  routine to your program to override the default if you need to setup hardware
10616  or perform some other critical operation prior to static & global variable
10617  initialization.
10618  On some mcs51 variants xdata has to be explicitly enabled before it can
10619  be accessed, this is the place to do it.
10620  See also the compiler option 
10621 \emph on 
10622 -
10623 \begin_inset ERT
10624 status Collapsed
10625
10626 \layout Standard
10627
10628 \backslash 
10629 /
10630 \end_inset 
10631
10632 -no-xinit
10633 \emph default 
10634 -
10635 \emph on 
10636 opt
10637 \emph default 
10638
10639 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
10640
10641 \end_inset 
10642
10643  and section 
10644 \begin_inset LatexCommand \ref{sub:MCS51-variants}
10645
10646 \end_inset 
10647
10648 \SpecialChar ~
10649 about MCS51-variants.
10650 \layout Subsection
10651
10652 HC08 Startup Code
10653 \layout Standard
10654
10655 The HC08 startup code follows the same scheme as the MCS51 startup code.
10656 \layout Subsection
10657
10658 Z80 Startup Code
10659 \layout Standard
10660
10661 On the Z80 the startup code is inserted by linking with crt0.o which is generated
10662  from sdcc/device/lib/z80/crt0.s.
10663  If you need a different startup code you can use the compiler option 
10664 \emph on 
10665 -
10666 \series bold 
10667 \emph default 
10668
10669 \begin_inset ERT
10670 status Collapsed
10671
10672 \layout Standard
10673
10674 \backslash 
10675 /
10676 \end_inset 
10677
10678
10679 \series default 
10680 \emph on 
10681 -no-std-crt0
10682 \emph default 
10683
10684 \begin_inset LatexCommand \index{-\/-no-std-crt0}
10685
10686 \end_inset 
10687
10688  and provide your own crt0.o.
10689  
10690 \layout Section
10691
10692 Inline Assembler Code
10693 \begin_inset LatexCommand \index{Assembler routines}
10694
10695 \end_inset 
10696
10697
10698 \layout Subsection
10699
10700 A Step by Step Introduction
10701 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
10702
10703 \end_inset 
10704
10705
10706 \layout Standard
10707
10708 Starting from a small snippet of c-code this example shows for the MCS51
10709  how to use inline assembly, access variables, a function parameter and
10710  an array in xdata memory.
10711  The example uses an MCS51 here but is easily adapted for other architectures.
10712  This is a buffer routine which should be optimized:
10713 \layout Verse
10714
10715
10716 \family typewriter 
10717 \size footnotesize 
10718 unsigned char far
10719 \begin_inset LatexCommand \index{far (storage class)}
10720
10721 \end_inset 
10722
10723  at
10724 \begin_inset LatexCommand \index{at}
10725
10726 \end_inset 
10727
10728  0x7f00 buf[0x100];
10729 \begin_inset LatexCommand \index{Aligned array}
10730
10731 \end_inset 
10732
10733
10734 \newline 
10735 unsigned char head,tail;
10736 \newline 
10737
10738 \newline 
10739 void to_buffer( unsigned char c ) 
10740 \newline 
10741 {
10742 \newline 
10743 \SpecialChar ~
10744 \SpecialChar ~
10745 \SpecialChar ~
10746 \SpecialChar ~
10747 if( head != tail-1 ) 
10748 \newline 
10749 \SpecialChar ~
10750 \SpecialChar ~
10751 \SpecialChar ~
10752 \SpecialChar ~
10753 \SpecialChar ~
10754 \SpecialChar ~
10755 \SpecialChar ~
10756 \SpecialChar ~
10757 buf[ head++ ] = c; 
10758 \newline 
10759
10760 \layout Standard
10761
10762 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
10763  then a corresponding buffer.asm file is generated.
10764  We define a new function 
10765 \family typewriter 
10766 to_buffer_asm()
10767 \family default 
10768  in file buffer.c in which we cut and paste the generated code, removing
10769  unwanted comments and some ':'.
10770  Then add 
10771 \begin_inset Quotes sld
10772 \end_inset 
10773
10774 _asm
10775 \begin_inset Quotes srd
10776 \end_inset 
10777
10778  and 
10779 \begin_inset Quotes sld
10780 \end_inset 
10781
10782 _endasm;
10783 \begin_inset Quotes srd
10784 \end_inset 
10785
10786  to the beginning and the end of the function body:
10787 \layout Verse
10788
10789
10790 \family typewriter 
10791 \size footnotesize 
10792 /* With a cut and paste from the .asm file, we have something to start with.
10793 \newline 
10794 \SpecialChar ~
10795 \SpecialChar ~
10796 \SpecialChar ~
10797 The function is not yet OK! (registers aren't saved) */ 
10798 \newline 
10799 void to_buffer_asm( unsigned char c ) 
10800 \newline 
10801
10802 \newline 
10803 \SpecialChar ~
10804 \SpecialChar ~
10805 \SpecialChar ~
10806 \SpecialChar ~
10807 _asm
10808 \begin_inset LatexCommand \index{\_asm}
10809
10810 \end_inset 
10811
10812
10813 \newline 
10814 \SpecialChar ~
10815 \SpecialChar ~
10816 \SpecialChar ~
10817 \SpecialChar ~
10818 mov\SpecialChar ~
10819 \SpecialChar ~
10820 r2,dpl 
10821 \newline 
10822 ;buffer.c if( head != tail-1 ) 
10823 \newline 
10824 \SpecialChar ~
10825 \SpecialChar ~
10826 \SpecialChar ~
10827 \SpecialChar ~
10828 mov\SpecialChar ~
10829 \SpecialChar ~
10830 a,_tail 
10831 \newline 
10832 \SpecialChar ~
10833 \SpecialChar ~
10834 \SpecialChar ~
10835 \SpecialChar ~
10836 dec\SpecialChar ~
10837 \SpecialChar ~
10838
10839 \newline 
10840 \SpecialChar ~
10841 \SpecialChar ~
10842 \SpecialChar ~
10843 \SpecialChar ~
10844 mov\SpecialChar ~
10845 \SpecialChar ~
10846 r3,a 
10847 \newline 
10848 \SpecialChar ~
10849 \SpecialChar ~
10850 \SpecialChar ~
10851 \SpecialChar ~
10852 mov\SpecialChar ~
10853 \SpecialChar ~
10854 a,_head 
10855 \newline 
10856 \SpecialChar ~
10857 \SpecialChar ~
10858 \SpecialChar ~
10859 \SpecialChar ~
10860 cjne a,ar3,00106$ 
10861 \newline 
10862 \SpecialChar ~
10863 \SpecialChar ~
10864 \SpecialChar ~
10865 \SpecialChar ~
10866 ret
10867 \newline 
10868 00106$: 
10869 \newline 
10870 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
10871 \begin_inset LatexCommand \index{Aligned array}
10872
10873 \end_inset 
10874
10875
10876 \newline 
10877 \SpecialChar ~
10878 \SpecialChar ~
10879 \SpecialChar ~
10880 \SpecialChar ~
10881 mov\SpecialChar ~
10882 \SpecialChar ~
10883 r3,_head 
10884 \newline 
10885 \SpecialChar ~
10886 \SpecialChar ~
10887 \SpecialChar ~
10888 \SpecialChar ~
10889 inc\SpecialChar ~
10890 \SpecialChar ~
10891 _head 
10892 \newline 
10893 \SpecialChar ~
10894 \SpecialChar ~
10895 \SpecialChar ~
10896 \SpecialChar ~
10897 mov\SpecialChar ~
10898 \SpecialChar ~
10899 dpl,r3 
10900 \newline 
10901 \SpecialChar ~
10902 \SpecialChar ~
10903 \SpecialChar ~
10904 \SpecialChar ~
10905 mov\SpecialChar ~
10906 \SpecialChar ~
10907 dph,#(_buf >> 8) 
10908 \newline 
10909 \SpecialChar ~
10910 \SpecialChar ~
10911 \SpecialChar ~
10912 \SpecialChar ~
10913 mov\SpecialChar ~
10914 \SpecialChar ~
10915 a,r2 
10916 \newline 
10917 \SpecialChar ~
10918 \SpecialChar ~
10919 \SpecialChar ~
10920 \SpecialChar ~
10921 movx @dptr,a 
10922 \newline 
10923 00103$: 
10924 \newline 
10925 \SpecialChar ~
10926 \SpecialChar ~
10927 \SpecialChar ~
10928 \SpecialChar ~
10929 ret
10930 \newline 
10931 \SpecialChar ~
10932 \SpecialChar ~
10933 \SpecialChar ~
10934 \SpecialChar ~
10935 _endasm;
10936 \newline 
10937
10938 \layout Standard
10939
10940 The new file buffer.c should compile with only one warning about the unreferenced
10941  function argument 'c'.
10942  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
10943  (1) and finally have:
10944 \layout Verse
10945
10946
10947 \family typewriter 
10948 \size footnotesize 
10949 unsigned char far at 0x7f00 buf[0x100];
10950 \newline 
10951 unsigned char head,tail;
10952 \newline 
10953 #define USE_ASSEMBLY (1)
10954 \newline 
10955
10956 \newline 
10957 #if !USE_ASSEMBLY
10958 \newline 
10959
10960 \newline 
10961 void to_buffer( unsigned char c )
10962 \newline 
10963 {
10964 \newline 
10965 \SpecialChar ~
10966 \SpecialChar ~
10967 \SpecialChar ~
10968 \SpecialChar ~
10969 if( head != tail-1 )
10970 \newline 
10971 \SpecialChar ~
10972 \SpecialChar ~
10973 \SpecialChar ~
10974 \SpecialChar ~
10975 \SpecialChar ~
10976 \SpecialChar ~
10977 \SpecialChar ~
10978 \SpecialChar ~
10979 buf[ head++ ] = c;
10980 \newline 
10981 }
10982 \newline 
10983
10984 \newline 
10985 #else
10986 \newline 
10987
10988 \newline 
10989 void to_buffer( unsigned char c )
10990 \newline 
10991 {
10992 \newline 
10993 \SpecialChar ~
10994 \SpecialChar ~
10995 \SpecialChar ~
10996 \SpecialChar ~
10997 c; // to avoid warning: unreferenced function argument
10998 \newline 
10999 \SpecialChar ~
11000 \SpecialChar ~
11001 \SpecialChar ~
11002 \SpecialChar ~
11003 _asm
11004 \begin_inset LatexCommand \index{\_asm}
11005
11006 \end_inset 
11007
11008
11009 \newline 
11010 \SpecialChar ~
11011 \SpecialChar ~
11012 \SpecialChar ~
11013 \SpecialChar ~
11014 \SpecialChar ~
11015 \SpecialChar ~
11016 \SpecialChar ~
11017 \SpecialChar ~
11018 ; save used registers here.
11019  
11020 \newline 
11021 \SpecialChar ~
11022 \SpecialChar ~
11023 \SpecialChar ~
11024 \SpecialChar ~
11025 \SpecialChar ~
11026 \SpecialChar ~
11027 \SpecialChar ~
11028 \SpecialChar ~
11029 ; If we were still using r2,r3 we would have to push them here.
11030  
11031 \newline 
11032 ; if( head != tail-1 )
11033 \newline 
11034 \SpecialChar ~
11035 \SpecialChar ~
11036 \SpecialChar ~
11037 \SpecialChar ~
11038 \SpecialChar ~
11039 \SpecialChar ~
11040 \SpecialChar ~
11041 \SpecialChar ~
11042 mov\SpecialChar ~
11043  a,_tail
11044 \newline 
11045 \SpecialChar ~
11046 \SpecialChar ~
11047 \SpecialChar ~
11048 \SpecialChar ~
11049 \SpecialChar ~
11050 \SpecialChar ~
11051 \SpecialChar ~
11052 \SpecialChar ~
11053 dec\SpecialChar ~
11054  a
11055 \newline 
11056 \SpecialChar ~
11057 \SpecialChar ~
11058 \SpecialChar ~
11059 \SpecialChar ~
11060 \SpecialChar ~
11061 \SpecialChar ~
11062 \SpecialChar ~
11063 \SpecialChar ~
11064 xrl\SpecialChar ~
11065  a,_head
11066 \newline 
11067 \SpecialChar ~
11068 \SpecialChar ~
11069 \SpecialChar ~
11070 \SpecialChar ~
11071 \SpecialChar ~
11072 \SpecialChar ~
11073 \SpecialChar ~
11074 \SpecialChar ~
11075 ; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
11076 \newline 
11077 \SpecialChar ~
11078 \SpecialChar ~
11079 \SpecialChar ~
11080 \SpecialChar ~
11081 \SpecialChar ~
11082 \SpecialChar ~
11083 \SpecialChar ~
11084 \SpecialChar ~
11085 jz\SpecialChar ~
11086 \SpecialChar ~
11087  t_b_end$
11088 \newline 
11089 \SpecialChar ~
11090 \SpecialChar ~
11091 \SpecialChar ~
11092 \SpecialChar ~
11093 \SpecialChar ~
11094 \SpecialChar ~
11095 \SpecialChar ~
11096 \SpecialChar ~
11097 ;
11098 \newline 
11099 ; buf[ head++ ] = c;
11100 \newline 
11101 \SpecialChar ~
11102 \SpecialChar ~
11103 \SpecialChar ~
11104 \SpecialChar ~
11105 \SpecialChar ~
11106 \SpecialChar ~
11107 \SpecialChar ~
11108 \SpecialChar ~
11109 mov\SpecialChar ~
11110  a,dpl \SpecialChar ~
11111 \SpecialChar ~
11112 \SpecialChar ~
11113 \SpecialChar ~
11114 \SpecialChar ~
11115 \SpecialChar ~
11116 \SpecialChar ~
11117 ; dpl holds lower byte of function argument
11118 \newline 
11119 \SpecialChar ~
11120 \SpecialChar ~
11121 \SpecialChar ~
11122 \SpecialChar ~
11123 \SpecialChar ~
11124 \SpecialChar ~
11125 \SpecialChar ~
11126 \SpecialChar ~
11127 mov\SpecialChar ~
11128  dpl,_head \SpecialChar ~
11129 \SpecialChar ~
11130 \SpecialChar ~
11131 ; buf is 0x100 byte aligned so head can be used directly
11132 \newline 
11133 \SpecialChar ~
11134 \SpecialChar ~
11135 \SpecialChar ~
11136 \SpecialChar ~
11137 \SpecialChar ~
11138 \SpecialChar ~
11139 \SpecialChar ~
11140 \SpecialChar ~
11141 mov\SpecialChar ~
11142  dph,#(_buf>>8)
11143 \newline 
11144 \SpecialChar ~
11145 \SpecialChar ~
11146 \SpecialChar ~
11147 \SpecialChar ~
11148 \SpecialChar ~
11149 \SpecialChar ~
11150 \SpecialChar ~
11151 \SpecialChar ~
11152 movx @dptr,a
11153 \newline 
11154 \SpecialChar ~
11155 \SpecialChar ~
11156 \SpecialChar ~
11157 \SpecialChar ~
11158 \SpecialChar ~
11159 \SpecialChar ~
11160 \SpecialChar ~
11161 \SpecialChar ~
11162 inc \SpecialChar ~
11163 _head
11164 \newline 
11165 \SpecialChar ~
11166 \SpecialChar ~
11167 \SpecialChar ~
11168 \SpecialChar ~
11169 \SpecialChar ~
11170 \SpecialChar ~
11171 \SpecialChar ~
11172 \SpecialChar ~
11173 ; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)
11174 \newline 
11175 t_b_end$:
11176 \newline 
11177 \SpecialChar ~
11178 \SpecialChar ~
11179 \SpecialChar ~
11180 \SpecialChar ~
11181 \SpecialChar ~
11182 \SpecialChar ~
11183 \SpecialChar ~
11184 \SpecialChar ~
11185 ; restore used registers here 
11186 \newline 
11187 \SpecialChar ~
11188 \SpecialChar ~
11189 \SpecialChar ~
11190 \SpecialChar ~
11191 _endasm;
11192 \newline 
11193 }
11194 \newline 
11195 #endif
11196 \layout Standard
11197
11198 The inline assembler code can contain any valid code understood by the assembler
11199 , this includes any assembler directives and comment lines
11200 \begin_inset Foot
11201 collapsed false
11202
11203 \layout Standard
11204
11205 The assembler does not like some characters like ':' or ''' in comments.
11206  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
11207 \end_inset 
11208
11209 .
11210  The compiler does not do any validation of the code within the 
11211 \family typewriter 
11212 _asm
11213 \begin_inset LatexCommand \index{\_asm}
11214
11215 \end_inset 
11216
11217  ...
11218  _endasm;
11219 \family default 
11220  keyword pair.
11221  Specifically it will not know which registers are used and thus register
11222  pushing/popping
11223 \begin_inset LatexCommand \index{push/pop}
11224
11225 \end_inset 
11226
11227  has to be done manually.
11228  
11229 \layout Standard
11230
11231 It is recommended that each assembly instruction (including labels) be placed
11232  in a separate line (as the example shows).
11233  When the -
11234 \begin_inset ERT
11235 status Collapsed
11236
11237 \layout Standard
11238
11239 \backslash 
11240 /
11241 \end_inset 
11242
11243 -
11244 \emph on 
11245 peep-asm
11246 \begin_inset LatexCommand \index{-\/-peep-asm}
11247
11248 \end_inset 
11249
11250
11251 \emph default 
11252  command line option is used, the inline assembler code will be passed through
11253  the peephole optimizer
11254 \begin_inset LatexCommand \index{Peephole optimizer}
11255
11256 \end_inset 
11257
11258 .
11259  There are only a few (if any) cases where this option makes sense, it might
11260  cause some unexpected changes in the inline assembler code.
11261  Please go through the peephole optimizer rules defined in file 
11262 \emph on 
11263 SDCCpeeph.def
11264 \emph default 
11265  before using this option.
11266 \layout Subsection
11267
11268 Naked Functions
11269 \begin_inset LatexCommand \label{sub:Naked-Functions}
11270
11271 \end_inset 
11272
11273
11274 \begin_inset LatexCommand \index{Naked functions}
11275
11276 \end_inset 
11277
11278
11279 \layout Standard
11280
11281 A special keyword may be associated with a function declaring it as 
11282 \emph on 
11283 _naked
11284 \begin_inset LatexCommand \index{\_naked}
11285
11286 \end_inset 
11287
11288 .
11289  
11290 \emph default 
11291 The 
11292 \emph on 
11293 _naked
11294 \emph default 
11295  function modifier attribute prevents the compiler from generating prologue
11296 \begin_inset LatexCommand \index{function prologue}
11297
11298 \end_inset 
11299
11300  and epilogue
11301 \begin_inset LatexCommand \index{function epilogue}
11302
11303 \end_inset 
11304
11305  code for that function.
11306  This means that the user is entirely responsible for such things as saving
11307  any registers that may need to be preserved, selecting the proper register
11308  bank, generating the 
11309 \emph on 
11310 return
11311 \emph default 
11312  instruction at the end, etc.
11313  Practically, this means that the contents of the function must be written
11314  in inline assembler.
11315  This is particularly useful for interrupt functions, which can have a large
11316  (and often unnecessary) prologue/epilogue.
11317  For example, compare the code generated by these two functions:
11318 \layout Verse
11319
11320
11321 \family typewriter 
11322 volatile
11323 \begin_inset LatexCommand \index{volatile}
11324
11325 \end_inset 
11326
11327  data unsigned char counter;
11328 \newline 
11329
11330 \newline 
11331 void simpleInterrupt(void) interrupt
11332 \begin_inset LatexCommand \index{interrupt}
11333
11334 \end_inset 
11335
11336  1
11337 \newline 
11338 {
11339 \newline 
11340 \SpecialChar ~
11341 \SpecialChar ~
11342 \SpecialChar ~
11343 \SpecialChar ~
11344 counter++;
11345 \newline 
11346 }
11347 \newline 
11348
11349 \newline 
11350 void nakedInterrupt(void) interrupt 2 _naked
11351 \newline 
11352 {
11353 \newline 
11354 \SpecialChar ~
11355 \SpecialChar ~
11356 \SpecialChar ~
11357 \SpecialChar ~
11358 _asm
11359 \begin_inset LatexCommand \index{\_asm}
11360
11361 \end_inset 
11362
11363
11364 \newline 
11365 \SpecialChar ~
11366 \SpecialChar ~
11367 \SpecialChar ~
11368 \SpecialChar ~
11369 \SpecialChar ~
11370 \SpecialChar ~
11371 inc\SpecialChar ~
11372 \SpecialChar ~
11373 \SpecialChar ~
11374 \SpecialChar ~
11375 \SpecialChar ~
11376 _counter ; does not change flags, no need to save psw
11377 \newline 
11378 \SpecialChar ~
11379 \SpecialChar ~
11380 \SpecialChar ~
11381 \SpecialChar ~
11382 \SpecialChar ~
11383 \SpecialChar ~
11384 reti\SpecialChar ~
11385 \SpecialChar ~
11386 \SpecialChar ~
11387 \SpecialChar ~
11388 ; MUST explicitly include ret or reti in _naked function.
11389 \newline 
11390 \SpecialChar ~
11391 \SpecialChar ~
11392 \SpecialChar ~
11393 \SpecialChar ~
11394 _endasm
11395 \begin_inset LatexCommand \index{\_endasm}
11396
11397 \end_inset 
11398
11399 ;
11400 \newline 
11401 }
11402 \layout Standard
11403
11404 For an 8051 target, the generated simpleInterrupt looks like:
11405 \layout Verse
11406
11407
11408 \family typewriter 
11409 _simpleInterrupt:
11410 \newline 
11411 \SpecialChar ~
11412 \SpecialChar ~
11413 \SpecialChar ~
11414 \SpecialChar ~
11415 push\SpecialChar ~
11416 \SpecialChar ~
11417 \SpecialChar ~
11418 \SpecialChar ~
11419 acc
11420 \newline 
11421 \SpecialChar ~
11422 \SpecialChar ~
11423 \SpecialChar ~
11424 \SpecialChar ~
11425 push\SpecialChar ~
11426 \SpecialChar ~
11427 \SpecialChar ~
11428 \SpecialChar ~
11429 b
11430 \newline 
11431 \SpecialChar ~
11432 \SpecialChar ~
11433 \SpecialChar ~
11434 \SpecialChar ~
11435 push\SpecialChar ~
11436 \SpecialChar ~
11437 \SpecialChar ~
11438 \SpecialChar ~
11439 dpl
11440 \newline 
11441 \SpecialChar ~
11442 \SpecialChar ~
11443 \SpecialChar ~
11444 \SpecialChar ~
11445 push\SpecialChar ~
11446 \SpecialChar ~
11447 \SpecialChar ~
11448 \SpecialChar ~
11449 dph
11450 \newline 
11451 \SpecialChar ~
11452 \SpecialChar ~
11453 \SpecialChar ~
11454 \SpecialChar ~
11455 push\SpecialChar ~
11456 \SpecialChar ~
11457 \SpecialChar ~
11458 \SpecialChar ~
11459 psw
11460 \newline 
11461 \SpecialChar ~
11462 \SpecialChar ~
11463 \SpecialChar ~
11464 \SpecialChar ~
11465 mov\SpecialChar ~
11466 \SpecialChar ~
11467 \SpecialChar ~
11468 \SpecialChar ~
11469 \SpecialChar ~
11470 psw,#0x00
11471 \newline 
11472 \SpecialChar ~
11473 \SpecialChar ~
11474 \SpecialChar ~
11475 \SpecialChar ~
11476 inc\SpecialChar ~
11477 \SpecialChar ~
11478 \SpecialChar ~
11479 \SpecialChar ~
11480 \SpecialChar ~
11481 _counter
11482 \newline 
11483 \SpecialChar ~
11484 \SpecialChar ~
11485 \SpecialChar ~
11486 \SpecialChar ~
11487 pop\SpecialChar ~
11488 \SpecialChar ~
11489 \SpecialChar ~
11490 \SpecialChar ~
11491 \SpecialChar ~
11492 psw
11493 \newline 
11494 \SpecialChar ~
11495 \SpecialChar ~
11496 \SpecialChar ~
11497 \SpecialChar ~
11498 pop\SpecialChar ~
11499 \SpecialChar ~
11500 \SpecialChar ~
11501 \SpecialChar ~
11502 \SpecialChar ~
11503 dph
11504 \newline 
11505 \SpecialChar ~
11506 \SpecialChar ~
11507 \SpecialChar ~
11508 \SpecialChar ~
11509 pop\SpecialChar ~
11510 \SpecialChar ~
11511 \SpecialChar ~
11512 \SpecialChar ~
11513 \SpecialChar ~
11514 dpl
11515 \newline 
11516 \SpecialChar ~
11517 \SpecialChar ~
11518 \SpecialChar ~
11519 \SpecialChar ~
11520 pop\SpecialChar ~
11521 \SpecialChar ~
11522 \SpecialChar ~
11523 \SpecialChar ~
11524 \SpecialChar ~
11525 b
11526 \newline 
11527 \SpecialChar ~
11528 \SpecialChar ~
11529 \SpecialChar ~
11530 \SpecialChar ~
11531 pop\SpecialChar ~
11532 \SpecialChar ~
11533 \SpecialChar ~
11534 \SpecialChar ~
11535 \SpecialChar ~
11536 acc
11537 \newline 
11538 \SpecialChar ~
11539 \SpecialChar ~
11540 \SpecialChar ~
11541 \SpecialChar ~
11542 reti
11543 \layout Standard
11544
11545 whereas nakedInterrupt looks like:
11546 \layout Verse
11547
11548
11549 \family typewriter 
11550 _nakedInterrupt:
11551 \newline 
11552 \SpecialChar ~
11553 \SpecialChar ~
11554 \SpecialChar ~
11555 \SpecialChar ~
11556 inc\SpecialChar ~
11557 \SpecialChar ~
11558 \SpecialChar ~
11559 \SpecialChar ~
11560 _counter ; does not change flags, no need to save psw
11561 \newline 
11562 \SpecialChar ~
11563 \SpecialChar ~
11564 \SpecialChar ~
11565 \SpecialChar ~
11566 reti\SpecialChar ~
11567 \SpecialChar ~
11568 \SpecialChar ~
11569 \SpecialChar ~
11570 \SpecialChar ~
11571 \SpecialChar ~
11572 \SpecialChar ~
11573 \SpecialChar ~
11574 \SpecialChar ~
11575 \SpecialChar ~
11576 \SpecialChar ~
11577 \SpecialChar ~
11578 ; MUST explicitly include ret or reti in _naked function
11579 \layout Standard
11580
11581 The related directive #pragma exclude
11582 \begin_inset LatexCommand \index{\#pragma exclude}
11583
11584 \end_inset 
11585
11586  allows a more fine grained control over pushing & popping
11587 \begin_inset LatexCommand \index{push/pop}
11588
11589 \end_inset 
11590
11591  the registers.
11592 \layout Standard
11593
11594 While there is nothing preventing you from writing C code inside a 
11595 \family typewriter 
11596 _naked
11597 \family default 
11598  function, there are many ways to shoot yourself in the foot doing this,
11599  and it is recommended that you stick to inline assembler.
11600 \layout Subsection
11601
11602 Use of Labels within Inline Assembler
11603 \layout Standard
11604
11605 SDCC allows the use of in-line assembler with a few restrictions regarding
11606  labels.
11607  In older versions of the compiler all labels defined within inline assembler
11608  code 
11609 \emph on 
11610 had to be
11611 \emph default 
11612  of the form 
11613 \emph on 
11614 nnnnn$
11615 \emph default 
11616  where nnnn is a number less than 100 (which implies a limit of utmost 100
11617  inline assembler labels 
11618 \emph on 
11619 per function
11620 \emph default 
11621 \noun on 
11622 )
11623 \noun default 
11624 .
11625  
11626 \layout Verse
11627
11628
11629 \family typewriter 
11630 _asm
11631 \begin_inset LatexCommand \index{\_asm}
11632
11633 \end_inset 
11634
11635  
11636 \newline 
11637 \SpecialChar ~
11638 \SpecialChar ~
11639 \SpecialChar ~
11640 \SpecialChar ~
11641 mov\SpecialChar ~
11642 \SpecialChar ~
11643 \SpecialChar ~
11644 \SpecialChar ~
11645 \SpecialChar ~
11646 b,#10 
11647 \newline 
11648 00001$: 
11649 \newline 
11650 \SpecialChar ~
11651 \SpecialChar ~
11652 \SpecialChar ~
11653 \SpecialChar ~
11654 djnz\SpecialChar ~
11655 \SpecialChar ~
11656 \SpecialChar ~
11657 \SpecialChar ~
11658 b,00001$ 
11659 \newline 
11660 _endasm
11661 \begin_inset LatexCommand \index{\_endasm}
11662
11663 \end_inset 
11664
11665  ;
11666 \layout Standard
11667
11668 Inline assembler code cannot reference any C-Labels, however it can reference
11669  labels
11670 \begin_inset LatexCommand \index{Labels}
11671
11672 \end_inset 
11673
11674  defined by the inline assembler, e.g.:
11675 \layout Verse
11676
11677
11678 \family typewriter 
11679 foo() { 
11680 \newline 
11681 \SpecialChar ~
11682 \SpecialChar ~
11683 \SpecialChar ~
11684 \SpecialChar ~
11685 /* some c code */ 
11686 \newline 
11687 \SpecialChar ~
11688 \SpecialChar ~
11689 \SpecialChar ~
11690 \SpecialChar ~
11691 _asm 
11692 \newline 
11693 \SpecialChar ~
11694 \SpecialChar ~
11695 \SpecialChar ~
11696 \SpecialChar ~
11697 \SpecialChar ~
11698 \SpecialChar ~
11699 ; some assembler code 
11700 \newline 
11701 \SpecialChar ~
11702 \SpecialChar ~
11703 \SpecialChar ~
11704 \SpecialChar ~
11705 \SpecialChar ~
11706 \SpecialChar ~
11707 ljmp $0003 
11708 \newline 
11709 \SpecialChar ~
11710 \SpecialChar ~
11711 \SpecialChar ~
11712 \SpecialChar ~
11713 _endasm; 
11714 \newline 
11715 \SpecialChar ~
11716 \SpecialChar ~
11717 \SpecialChar ~
11718 \SpecialChar ~
11719 /* some more c code */ 
11720 \newline 
11721 clabel:\SpecialChar ~
11722 \SpecialChar ~
11723 /* inline assembler cannot reference this label */ 
11724 \newline 
11725 \SpecialChar ~
11726 \SpecialChar ~
11727 \SpecialChar ~
11728 \SpecialChar ~
11729 _asm
11730 \newline 
11731 \SpecialChar ~
11732 \SpecialChar ~
11733 \SpecialChar ~
11734 \SpecialChar ~
11735 $0003: ;label (can be referenced by inline assembler only) 
11736 \newline 
11737 \SpecialChar ~
11738 \SpecialChar ~
11739 \SpecialChar ~
11740 \SpecialChar ~
11741 _endasm ; 
11742 \newline 
11743 \SpecialChar ~
11744 \SpecialChar ~
11745 \SpecialChar ~
11746 \SpecialChar ~
11747 /* some more c code */
11748 \newline 
11749 }
11750 \layout Standard
11751
11752 In other words inline assembly code can access labels defined in inline
11753  assembly within the scope of the function.
11754  The same goes the other way, i.e.
11755  labels defines in inline assembly can not be accessed by C statements.
11756 \layout Section
11757
11758 Interfacing with Assembler Code
11759 \begin_inset LatexCommand \index{Assembler routines}
11760
11761 \end_inset 
11762
11763
11764 \layout Subsection
11765
11766 Global Registers used for Parameter Passing
11767 \begin_inset LatexCommand \index{Parameter passing}
11768
11769 \end_inset 
11770
11771
11772 \layout Standard
11773
11774 The compiler always uses the global registers 
11775 \emph on 
11776 DPL, DPH
11777 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
11778
11779 \end_inset 
11780
11781
11782 \begin_inset LatexCommand \index{DPTR}
11783
11784 \end_inset 
11785
11786 , B
11787 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
11788
11789 \end_inset 
11790
11791  
11792 \emph default 
11793 and
11794 \emph on 
11795  ACC
11796 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
11797
11798 \end_inset 
11799
11800
11801 \emph default 
11802  to pass the first parameter to a routine.
11803  The second parameter onwards is either allocated on the stack (for reentrant
11804  routines or if -
11805 \begin_inset ERT
11806 status Collapsed
11807
11808 \layout Standard
11809
11810 \backslash 
11811 /
11812 \end_inset 
11813
11814 -stack-auto is used) or in data / xdata memory (depending on the memory
11815  model).
11816  
11817 \layout Subsection
11818
11819 Assembler Routine (non-reentrant)
11820 \layout Standard
11821
11822 In the following example
11823 \begin_inset LatexCommand \index{reentrant}
11824
11825 \end_inset 
11826
11827
11828 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
11829
11830 \end_inset 
11831
11832  the function c_func calls an assembler routine asm_func, which takes two
11833  parameters
11834 \begin_inset LatexCommand \index{function parameter}
11835
11836 \end_inset 
11837
11838 .
11839 \layout Verse
11840
11841
11842 \family typewriter 
11843 extern int asm_func(unsigned char, unsigned char);
11844 \newline 
11845
11846 \newline 
11847 int c_func (unsigned char i, unsigned char j)
11848 \newline 
11849 {
11850 \newline 
11851 \SpecialChar ~
11852 \SpecialChar ~
11853 \SpecialChar ~
11854 \SpecialChar ~
11855 return asm_func(i,j);
11856 \newline 
11857 }
11858 \newline 
11859
11860 \newline 
11861 int main()
11862 \newline 
11863 {
11864 \newline 
11865 \SpecialChar ~
11866 \SpecialChar ~
11867 \SpecialChar ~
11868 \SpecialChar ~
11869 return c_func(10,9);
11870 \newline 
11871 }
11872 \layout Standard
11873
11874 The corresponding assembler function is:
11875 \layout Verse
11876
11877
11878 \family typewriter 
11879 .globl _asm_func_PARM_2 
11880 \newline 
11881 \SpecialChar ~
11882 \SpecialChar ~
11883 \SpecialChar ~
11884 \SpecialChar ~
11885 \SpecialChar ~
11886 \SpecialChar ~
11887 \SpecialChar ~
11888 \SpecialChar ~
11889 .globl _asm_func 
11890 \newline 
11891 \SpecialChar ~
11892 \SpecialChar ~
11893 \SpecialChar ~
11894 \SpecialChar ~
11895 \SpecialChar ~
11896 \SpecialChar ~
11897 \SpecialChar ~
11898 \SpecialChar ~
11899 .area OSEG 
11900 \newline 
11901 _asm_func_PARM_2:
11902 \newline 
11903 \SpecialChar ~
11904 \SpecialChar ~
11905 \SpecialChar ~
11906 \SpecialChar ~
11907 \SpecialChar ~
11908 \SpecialChar ~
11909 \SpecialChar ~
11910 \SpecialChar ~
11911 .ds    1 
11912 \newline 
11913 \SpecialChar ~
11914 \SpecialChar ~
11915 \SpecialChar ~
11916 \SpecialChar ~
11917 \SpecialChar ~
11918 \SpecialChar ~
11919 \SpecialChar ~
11920 \SpecialChar ~
11921 .area CSEG 
11922 \newline 
11923 _asm_func: 
11924 \newline 
11925 \SpecialChar ~
11926 \SpecialChar ~
11927 \SpecialChar ~
11928 \SpecialChar ~
11929 \SpecialChar ~
11930 \SpecialChar ~
11931 \SpecialChar ~
11932 \SpecialChar ~
11933 mov\SpecialChar ~
11934 \SpecialChar ~
11935 \SpecialChar ~
11936 \SpecialChar ~
11937 a,dpl 
11938 \newline 
11939 \SpecialChar ~
11940 \SpecialChar ~
11941 \SpecialChar ~
11942 \SpecialChar ~
11943 \SpecialChar ~
11944 \SpecialChar ~
11945 \SpecialChar ~
11946 \SpecialChar ~
11947 add\SpecialChar ~
11948 \SpecialChar ~
11949 \SpecialChar ~
11950 \SpecialChar ~
11951 a,_asm_func_PARM_2 
11952 \newline 
11953 \SpecialChar ~
11954 \SpecialChar ~
11955 \SpecialChar ~
11956 \SpecialChar ~
11957 \SpecialChar ~
11958 \SpecialChar ~
11959 \SpecialChar ~
11960 \SpecialChar ~
11961 mov\SpecialChar ~
11962 \SpecialChar ~
11963 \SpecialChar ~
11964 \SpecialChar ~
11965 dpl,a 
11966 \newline 
11967 \SpecialChar ~
11968 \SpecialChar ~
11969 \SpecialChar ~
11970 \SpecialChar ~
11971 \SpecialChar ~
11972 \SpecialChar ~
11973 \SpecialChar ~
11974 \SpecialChar ~
11975 mov\SpecialChar ~
11976 \SpecialChar ~
11977 \SpecialChar ~
11978 \SpecialChar ~
11979 dph
11980 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
11981
11982 \end_inset 
11983
11984 ,#0x00 
11985 \newline 
11986 \SpecialChar ~
11987 \SpecialChar ~
11988 \SpecialChar ~
11989 \SpecialChar ~
11990 \SpecialChar ~
11991 \SpecialChar ~
11992 \SpecialChar ~
11993 \SpecialChar ~
11994 ret
11995 \layout Standard
11996
11997 Note here that the return values
11998 \begin_inset LatexCommand \index{return value}
11999
12000 \end_inset 
12001
12002  are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
12003  two byte values.
12004  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
12005 b' & 'acc' for four byte values.
12006 \layout Standard
12007
12008 The parameter naming convention is _<function_name>_PARM_<n>, where n is
12009  the parameter number starting from 1, and counting from the left.
12010  The first parameter is passed in 
12011 \begin_inset Quotes eld
12012 \end_inset 
12013
12014 dpl
12015 \begin_inset Quotes erd
12016 \end_inset 
12017
12018  for a one byte parameter, 
12019 \begin_inset Quotes eld
12020 \end_inset 
12021
12022 dptr
12023 \begin_inset Quotes erd
12024 \end_inset 
12025
12026  for two bytes, 
12027 \begin_inset Quotes eld
12028 \end_inset 
12029
12030 b,dptr
12031 \begin_inset Quotes erd
12032 \end_inset 
12033
12034  for three bytes and 
12035 \begin_inset Quotes eld
12036 \end_inset 
12037
12038 acc,b,dptr
12039 \begin_inset Quotes erd
12040 \end_inset 
12041
12042  for a four bytes parameter.
12043  The variable name for the second parameter will be _<function_name>_PARM_2.
12044 \newline 
12045
12046 \newline 
12047 Assemble the assembler routine with the following command:
12048 \newline 
12049
12050 \newline 
12051
12052 \family sans 
12053 \series bold 
12054 asx8051 -losg asmfunc.asm
12055 \newline 
12056
12057 \newline 
12058
12059 \family default 
12060 \series default 
12061 Then compile and link the assembler routine to the C source file with the
12062  following command:
12063 \newline 
12064
12065 \newline 
12066
12067 \family sans 
12068 \series bold 
12069 sdcc cfunc.c asmfunc.rel
12070 \layout Subsection
12071
12072 Assembler Routine (reentrant)
12073 \layout Standard
12074
12075 In this case
12076 \begin_inset LatexCommand \index{reentrant}
12077
12078 \end_inset 
12079
12080
12081 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
12082
12083 \end_inset 
12084
12085  the second parameter
12086 \begin_inset LatexCommand \index{function parameter}
12087
12088 \end_inset 
12089
12090  onwards will be passed on the stack, the parameters are pushed from right
12091  to left i.e.
12092  after the call the leftmost parameter will be on the top of the stack.
12093  Here is an example:
12094 \layout Verse
12095
12096
12097 \family typewriter 
12098 extern int asm_func(unsigned char, unsigned char);
12099 \newline 
12100
12101 \newline 
12102 int c_func (unsigned char i, unsigned char j) reentrant 
12103 \newline 
12104
12105 \newline 
12106 \SpecialChar ~
12107 \SpecialChar ~
12108 \SpecialChar ~
12109 \SpecialChar ~
12110 return asm_func(i,j); 
12111 \newline 
12112
12113 \newline 
12114
12115 \newline 
12116 int main() 
12117 \newline 
12118
12119 \newline 
12120 \SpecialChar ~
12121 \SpecialChar ~
12122 \SpecialChar ~
12123 \SpecialChar ~
12124 return c_func(10,9); 
12125 \newline 
12126 }
12127 \layout Standard
12128
12129 The corresponding assembler routine is:
12130 \layout Verse
12131
12132
12133 \family typewriter 
12134 .globl _asm_func 
12135 \newline 
12136 _asm_func: 
12137 \newline 
12138 \SpecialChar ~
12139 \SpecialChar ~
12140 \SpecialChar ~
12141 \SpecialChar ~
12142 push  _bp 
12143 \newline 
12144 \SpecialChar ~
12145 \SpecialChar ~
12146 \SpecialChar ~
12147 \SpecialChar ~
12148 mov _bp,sp 
12149 \newline 
12150 \SpecialChar ~
12151 \SpecialChar ~
12152 \SpecialChar ~
12153 \SpecialChar ~
12154 mov r2,dpl
12155 \newline 
12156 \SpecialChar ~
12157 \SpecialChar ~
12158 \SpecialChar ~
12159 \SpecialChar ~
12160 mov a,_bp 
12161 \newline 
12162 \SpecialChar ~
12163 \SpecialChar ~
12164 \SpecialChar ~
12165 \SpecialChar ~
12166 add a,#0xfd 
12167 \newline 
12168 \SpecialChar ~
12169 \SpecialChar ~
12170 \SpecialChar ~
12171 \SpecialChar ~
12172 mov r0,a 
12173 \newline 
12174 \SpecialChar ~
12175 \SpecialChar ~
12176 \SpecialChar ~
12177 \SpecialChar ~
12178 add  a,#0xfc ;?
12179 \newline 
12180 \SpecialChar ~
12181 \SpecialChar ~
12182 \SpecialChar ~
12183 \SpecialChar ~
12184 mov  r1,a 
12185 \newline 
12186 \SpecialChar ~
12187 \SpecialChar ~
12188 \SpecialChar ~
12189 \SpecialChar ~
12190 mov  a,@r0 
12191 \newline 
12192 \SpecialChar ~
12193 \SpecialChar ~
12194 \SpecialChar ~
12195 \SpecialChar ~
12196 add  a,r2 ;?
12197 \newline 
12198 \SpecialChar ~
12199 \SpecialChar ~
12200 \SpecialChar ~
12201 \SpecialChar ~
12202 mov  dpl,a 
12203 \newline 
12204 \SpecialChar ~
12205 \SpecialChar ~
12206 \SpecialChar ~
12207 \SpecialChar ~
12208 mov  dph,#0x00 
12209 \newline 
12210 \SpecialChar ~
12211 \SpecialChar ~
12212 \SpecialChar ~
12213 \SpecialChar ~
12214 mov  sp,_bp 
12215 \newline 
12216 \SpecialChar ~
12217 \SpecialChar ~
12218 \SpecialChar ~
12219 \SpecialChar ~
12220 pop  _bp 
12221 \newline 
12222 \SpecialChar ~
12223 \SpecialChar ~
12224 \SpecialChar ~
12225 \SpecialChar ~
12226 ret
12227 \layout Standard
12228
12229 The compiling and linking procedure remains the same, however note the extra
12230  entry & exit linkage required for the assembler code, _bp is the stack
12231  frame pointer and is used to compute the offset into the stack for parameters
12232  and local variables.
12233 \layout Section
12234
12235 int (16 bit)
12236 \begin_inset LatexCommand \index{int (16 bit)}
12237
12238 \end_inset 
12239
12240  and long (32 bit)
12241 \begin_inset LatexCommand \index{long (32 bit)}
12242
12243 \end_inset 
12244
12245  Support
12246 \layout Standard
12247
12248 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
12249  multiplication and modulus operations are implemented by support routines.
12250  These support routines are all developed in ANSI-C to facilitate porting
12251  to other MCUs, although some model specific assembler optimizations are
12252  used.
12253  The following files contain the described routines, all of them can be
12254  found in <installdir>/share/sdcc/lib.
12255 \newline 
12256
12257 \layout Standard
12258 \align center 
12259
12260 \begin_inset  Tabular
12261 <lyxtabular version="3" rows="11" columns="2">
12262 <features>
12263 <column alignment="center" valignment="top" leftline="true" width="0">
12264 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
12265 <row topline="true" bottomline="true">
12266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12267 \begin_inset Text
12268
12269 \layout Standard
12270
12271
12272 \series bold 
12273 Function
12274 \end_inset 
12275 </cell>
12276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12277 \begin_inset Text
12278
12279 \layout Standard
12280
12281
12282 \series bold 
12283 Description
12284 \end_inset 
12285 </cell>
12286 </row>
12287 <row topline="true">
12288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12289 \begin_inset Text
12290
12291 \layout Standard
12292
12293 _mulint.c 
12294 \end_inset 
12295 </cell>
12296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12297 \begin_inset Text
12298
12299 \layout Standard
12300
12301 16 bit multiplication
12302 \end_inset 
12303 </cell>
12304 </row>
12305 <row topline="true">
12306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12307 \begin_inset Text
12308
12309 \layout Standard
12310
12311 _divsint.c 
12312 \end_inset 
12313 </cell>
12314 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12315 \begin_inset Text
12316
12317 \layout Standard
12318
12319  signed 16 bit division (calls _divuint)
12320 \end_inset 
12321 </cell>
12322 </row>
12323 <row topline="true">
12324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12325 \begin_inset Text
12326
12327 \layout Standard
12328
12329 _divuint.c 
12330 \end_inset 
12331 </cell>
12332 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12333 \begin_inset Text
12334
12335 \layout Standard
12336
12337  unsigned 16 bit division
12338 \end_inset 
12339 </cell>
12340 </row>
12341 <row topline="true">
12342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12343 \begin_inset Text
12344
12345 \layout Standard
12346
12347 _modsint.c
12348 \end_inset 
12349 </cell>
12350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12351 \begin_inset Text
12352
12353 \layout Standard
12354
12355 signed 16 bit modulus (calls _moduint)
12356 \end_inset 
12357 </cell>
12358 </row>
12359 <row topline="true">
12360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12361 \begin_inset Text
12362
12363 \layout Standard
12364
12365 _moduint.c
12366 \end_inset 
12367 </cell>
12368 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12369 \begin_inset Text
12370
12371 \layout Standard
12372
12373 unsigned 16 bit modulus
12374 \end_inset 
12375 </cell>
12376 </row>
12377 <row topline="true">
12378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12379 \begin_inset Text
12380
12381 \layout Standard
12382
12383 _mullong.c
12384 \end_inset 
12385 </cell>
12386 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12387 \begin_inset Text
12388
12389 \layout Standard
12390
12391 32 bit multiplication
12392 \end_inset 
12393 </cell>
12394 </row>
12395 <row topline="true">
12396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12397 \begin_inset Text
12398
12399 \layout Standard
12400
12401 _divslong.c 
12402 \end_inset 
12403 </cell>
12404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12405 \begin_inset Text
12406
12407 \layout Standard
12408
12409  signed 32 division (calls _divulong)
12410 \end_inset 
12411 </cell>
12412 </row>
12413 <row topline="true">
12414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12415 \begin_inset Text
12416
12417 \layout Standard
12418
12419 _divulong.c 
12420 \end_inset 
12421 </cell>
12422 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12423 \begin_inset Text
12424
12425 \layout Standard
12426
12427 unsigned 32 division
12428 \end_inset 
12429 </cell>
12430 </row>
12431 <row topline="true">
12432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12433 \begin_inset Text
12434
12435 \layout Standard
12436
12437 _modslong.c
12438 \end_inset 
12439 </cell>
12440 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12441 \begin_inset Text
12442
12443 \layout Standard
12444
12445  signed 32 bit modulus (calls _modulong)
12446 \end_inset 
12447 </cell>
12448 </row>
12449 <row topline="true" bottomline="true">
12450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12451 \begin_inset Text
12452
12453 \layout Standard
12454
12455 _modulong.c
12456 \end_inset 
12457 </cell>
12458 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12459 \begin_inset Text
12460
12461 \layout Standard
12462
12463 unsigned 32 bit modulus
12464 \end_inset 
12465 </cell>
12466 </row>
12467 </lyxtabular>
12468
12469 \end_inset 
12470
12471
12472 \newline 
12473
12474 \layout Standard
12475
12476 Since they are compiled as 
12477 \emph on 
12478 non-reentrant
12479 \emph default 
12480
12481 \begin_inset LatexCommand \index{reentrant}
12482
12483 \end_inset 
12484
12485 , interrupt
12486 \begin_inset LatexCommand \index{interrupt}
12487
12488 \end_inset 
12489
12490  service routines should not do any of the above operations.
12491  If this is unavoidable then the above routines will need to be compiled
12492  with the 
12493 \emph on 
12494 -
12495 \begin_inset ERT
12496 status Collapsed
12497
12498 \layout Standard
12499
12500 \backslash 
12501 /
12502 \end_inset 
12503
12504 -stack-auto
12505 \begin_inset LatexCommand \index{-\/-stack-auto}
12506
12507 \end_inset 
12508
12509
12510 \emph default 
12511  option, after which the source program will have to be compiled with 
12512 \emph on 
12513 -
12514 \begin_inset ERT
12515 status Collapsed
12516
12517 \layout Standard
12518
12519 \backslash 
12520 /
12521 \end_inset 
12522
12523 -int-long-reent
12524 \begin_inset LatexCommand \index{-\/-int-long-reent}
12525
12526 \end_inset 
12527
12528
12529 \emph default 
12530  option.
12531  Notice that you don't have to call these routines directly.
12532  The compiler will use them automatically every time an integer operation
12533  is required.
12534 \layout Section
12535
12536 Floating Point Support
12537 \begin_inset LatexCommand \index{Floating point support}
12538
12539 \end_inset 
12540
12541
12542 \layout Standard
12543
12544 SDCC supports IEEE (single precision 4 bytes) floating point numbers.The
12545  floating point support routines are derived from gcc's floatlib.c and consist
12546  of the following routines:
12547 \newline 
12548
12549 \layout Standard
12550 \align center 
12551
12552 \size footnotesize 
12553
12554 \begin_inset  Tabular
12555 <lyxtabular version="3" rows="17" columns="2">
12556 <features>
12557 <column alignment="center" valignment="top" leftline="true" width="0">
12558 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
12559 <row topline="true" bottomline="true">
12560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12561 \begin_inset Text
12562
12563 \layout Standard
12564
12565
12566 \family roman 
12567 \series medium 
12568 \shape up 
12569 \size normal 
12570 \emph off 
12571 \bar no 
12572 \noun off 
12573 \color none
12574 Function 
12575 \end_inset 
12576 </cell>
12577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12578 \begin_inset Text
12579
12580 \layout Standard
12581
12582 Description
12583 \end_inset 
12584 </cell>
12585 </row>
12586 <row topline="true">
12587 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12588 \begin_inset Text
12589
12590 \layout Standard
12591
12592
12593 \family roman 
12594 \series medium 
12595 \shape up 
12596 \size normal 
12597 \emph off 
12598 \bar no 
12599 \noun off 
12600 \color none
12601 _fsadd.c
12602 \end_inset 
12603 </cell>
12604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12605 \begin_inset Text
12606
12607 \layout Standard
12608
12609
12610 \family roman 
12611 \series medium 
12612 \shape up 
12613 \size normal 
12614 \emph off 
12615 \bar no 
12616 \noun off 
12617 \color none
12618 add floating point numbers
12619 \end_inset 
12620 </cell>
12621 </row>
12622 <row topline="true">
12623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12624 \begin_inset Text
12625
12626 \layout Standard
12627
12628
12629 \family roman 
12630 \series medium 
12631 \shape up 
12632 \size normal 
12633 \emph off 
12634 \bar no 
12635 \noun off 
12636 \color none
12637 _fssub.c 
12638 \end_inset 
12639 </cell>
12640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12641 \begin_inset Text
12642
12643 \layout Standard
12644
12645
12646 \family roman 
12647 \series medium 
12648 \shape up 
12649 \size normal 
12650 \emph off 
12651 \bar no 
12652 \noun off 
12653 \color none
12654 subtract floating point numbers 
12655 \end_inset 
12656 </cell>
12657 </row>
12658 <row topline="true">
12659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12660 \begin_inset Text
12661
12662 \layout Standard
12663
12664
12665 \family roman 
12666 \series medium 
12667 \shape up 
12668 \size normal 
12669 \emph off 
12670 \bar no 
12671 \noun off 
12672 \color none
12673 _fsdiv.c 
12674 \end_inset 
12675 </cell>
12676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12677 \begin_inset Text
12678
12679 \layout Standard
12680
12681
12682 \family roman 
12683 \series medium 
12684 \shape up 
12685 \size normal 
12686 \emph off 
12687 \bar no 
12688 \noun off 
12689 \color none
12690 divide floating point numbers 
12691 \end_inset 
12692 </cell>
12693 </row>
12694 <row topline="true">
12695 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12696 \begin_inset Text
12697
12698 \layout Standard
12699
12700
12701 \family roman 
12702 \series medium 
12703 \shape up 
12704 \size normal 
12705 \emph off 
12706 \bar no 
12707 \noun off 
12708 \color none
12709 _fsmul.c 
12710 \end_inset 
12711 </cell>
12712 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12713 \begin_inset Text
12714
12715 \layout Standard
12716
12717
12718 \family roman 
12719 \series medium 
12720 \shape up 
12721 \size normal 
12722 \emph off 
12723 \bar no 
12724 \noun off 
12725 \color none
12726 multiply floating point numbers 
12727 \end_inset 
12728 </cell>
12729 </row>
12730 <row topline="true">
12731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12732 \begin_inset Text
12733
12734 \layout Standard
12735
12736
12737 \family roman 
12738 \series medium 
12739 \shape up 
12740 \size normal 
12741 \emph off 
12742 \bar no 
12743 \noun off 
12744 \color none
12745 _fs2uchar.c
12746 \end_inset 
12747 </cell>
12748 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12749 \begin_inset Text
12750
12751 \layout Standard
12752
12753
12754 \family roman 
12755 \series medium 
12756 \shape up 
12757 \size normal 
12758 \emph off 
12759 \bar no 
12760 \noun off 
12761 \color none
12762 convert floating point to unsigned char
12763 \end_inset 
12764 </cell>
12765 </row>
12766 <row topline="true">
12767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12768 \begin_inset Text
12769
12770 \layout Standard
12771
12772
12773 \family roman 
12774 \series medium 
12775 \shape up 
12776 \size normal 
12777 \emph off 
12778 \bar no 
12779 \noun off 
12780 \color none
12781 _fs2char.c
12782 \end_inset 
12783 </cell>
12784 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12785 \begin_inset Text
12786
12787 \layout Standard
12788
12789
12790 \family roman 
12791 \series medium 
12792 \shape up 
12793 \size normal 
12794 \emph off 
12795 \bar no 
12796 \noun off 
12797 \color none
12798 convert floating point to signed char
12799 \end_inset 
12800 </cell>
12801 </row>
12802 <row topline="true">
12803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12804 \begin_inset Text
12805
12806 \layout Standard
12807
12808
12809 \family roman 
12810 \series medium 
12811 \shape up 
12812 \size normal 
12813 \emph off 
12814 \bar no 
12815 \noun off 
12816 \color none
12817 _fs2uint.c
12818 \end_inset 
12819 </cell>
12820 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12821 \begin_inset Text
12822
12823 \layout Standard
12824
12825
12826 \family roman 
12827 \series medium 
12828 \shape up 
12829 \size normal 
12830 \emph off 
12831 \bar no 
12832 \noun off 
12833 \color none
12834 convert floating point to unsigned int
12835 \end_inset 
12836 </cell>
12837 </row>
12838 <row topline="true">
12839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12840 \begin_inset Text
12841
12842 \layout Standard
12843
12844
12845 \family roman 
12846 \series medium 
12847 \shape up 
12848 \size normal 
12849 \emph off 
12850 \bar no 
12851 \noun off 
12852 \color none
12853 _fs2int.c
12854 \end_inset 
12855 </cell>
12856 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12857 \begin_inset Text
12858
12859 \layout Standard
12860
12861
12862 \family roman 
12863 \series medium 
12864 \shape up 
12865 \size normal 
12866 \emph off 
12867 \bar no 
12868 \noun off 
12869 \color none
12870 convert floating point to signed int
12871 \end_inset 
12872 </cell>
12873 </row>
12874 <row topline="true">
12875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12876 \begin_inset Text
12877
12878 \layout Standard
12879
12880
12881 \family roman 
12882 \series medium 
12883 \shape up 
12884 \size normal 
12885 \emph off 
12886 \bar no 
12887 \noun off 
12888 \color none
12889 _fs2ulong.
12890 \family default 
12891 \series default 
12892 \shape default 
12893 \size default 
12894 \emph default 
12895 \bar default 
12896 \noun default 
12897 \color default
12898 c
12899 \end_inset 
12900 </cell>
12901 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12902 \begin_inset Text
12903
12904 \layout Standard
12905
12906
12907 \family roman 
12908 \series medium 
12909 \shape up 
12910 \size normal 
12911 \emph off 
12912 \bar no 
12913 \noun off 
12914 \color none
12915 convert floating point to unsigned long
12916 \end_inset 
12917 </cell>
12918 </row>
12919 <row topline="true">
12920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12921 \begin_inset Text
12922
12923 \layout Standard
12924
12925
12926 \family roman 
12927 \series medium 
12928 \shape up 
12929 \size normal 
12930 \emph off 
12931 \bar no 
12932 \noun off 
12933 \color none
12934 _fs2long.c
12935 \end_inset 
12936 </cell>
12937 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12938 \begin_inset Text
12939
12940 \layout Standard
12941
12942
12943 \family roman 
12944 \series medium 
12945 \shape up 
12946 \size normal 
12947 \emph off 
12948 \bar no 
12949 \noun off 
12950 \color none
12951 convert floating point to signed long
12952 \end_inset 
12953 </cell>
12954 </row>
12955 <row topline="true">
12956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12957 \begin_inset Text
12958
12959 \layout Standard
12960
12961
12962 \family roman 
12963 \series medium 
12964 \shape up 
12965 \size normal 
12966 \emph off 
12967 \bar no 
12968 \noun off 
12969 \color none
12970 _uchar2fs.c
12971 \end_inset 
12972 </cell>
12973 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12974 \begin_inset Text
12975
12976 \layout Standard
12977
12978
12979 \family roman 
12980 \series medium 
12981 \shape up 
12982 \size normal 
12983 \emph off 
12984 \bar no 
12985 \noun off 
12986 \color none
12987 convert unsigned char to floating point
12988 \end_inset 
12989 </cell>
12990 </row>
12991 <row topline="true">
12992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12993 \begin_inset Text
12994
12995 \layout Standard
12996
12997
12998 \family roman 
12999 \series medium 
13000 \shape up 
13001 \size normal 
13002 \emph off 
13003 \bar no 
13004 \noun off 
13005 \color none
13006 _char2fs.c
13007 \end_inset 
13008 </cell>
13009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13010 \begin_inset Text
13011
13012 \layout Standard
13013
13014
13015 \family roman 
13016 \series medium 
13017 \shape up 
13018 \size normal 
13019 \emph off 
13020 \bar no 
13021 \noun off 
13022 \color none
13023 convert char to floating point number
13024 \end_inset 
13025 </cell>
13026 </row>
13027 <row topline="true">
13028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13029 \begin_inset Text
13030
13031 \layout Standard
13032
13033
13034 \family roman 
13035 \series medium 
13036 \shape up 
13037 \size normal 
13038 \emph off 
13039 \bar no 
13040 \noun off 
13041 \color none
13042 _uint2fs.c
13043 \end_inset 
13044 </cell>
13045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13046 \begin_inset Text
13047
13048 \layout Standard
13049
13050
13051 \family roman 
13052 \series medium 
13053 \shape up 
13054 \size normal 
13055 \emph off 
13056 \bar no 
13057 \noun off 
13058 \color none
13059 convert unsigned int to floating point
13060 \end_inset 
13061 </cell>
13062 </row>
13063 <row topline="true">
13064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13065 \begin_inset Text
13066
13067 \layout Standard
13068
13069
13070 \family roman 
13071 \series medium 
13072 \shape up 
13073 \size normal 
13074 \emph off 
13075 \bar no 
13076 \noun off 
13077 \color none
13078 _int2fs.c
13079 \end_inset 
13080 </cell>
13081 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13082 \begin_inset Text
13083
13084 \layout Standard
13085
13086
13087 \family roman 
13088 \series medium 
13089 \shape up 
13090 \size normal 
13091 \emph off 
13092 \bar no 
13093 \noun off 
13094 \color none
13095 convert int to floating point numbers
13096 \end_inset 
13097 </cell>
13098 </row>
13099 <row topline="true">
13100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13101 \begin_inset Text
13102
13103 \layout Standard
13104
13105
13106 \family roman 
13107 \series medium 
13108 \shape up 
13109 \size normal 
13110 \emph off 
13111 \bar no 
13112 \noun off 
13113 \color none
13114 _ulong2fs.c
13115 \end_inset 
13116 </cell>
13117 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13118 \begin_inset Text
13119
13120 \layout Standard
13121
13122
13123 \family roman 
13124 \series medium 
13125 \shape up 
13126 \size normal 
13127 \emph off 
13128 \bar no 
13129 \noun off 
13130 \color none
13131 convert unsigned long to floating point number
13132 \end_inset 
13133 </cell>
13134 </row>
13135 <row topline="true" bottomline="true">
13136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13137 \begin_inset Text
13138
13139 \layout Standard
13140
13141
13142 \family roman 
13143 \series medium 
13144 \shape up 
13145 \size normal 
13146 \emph off 
13147 \bar no 
13148 \noun off 
13149 \color none
13150 _long2fs.c
13151 \end_inset 
13152 </cell>
13153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13154 \begin_inset Text
13155
13156 \layout Standard
13157
13158
13159 \family roman 
13160 \series medium 
13161 \shape up 
13162 \size normal 
13163 \emph off 
13164 \bar no 
13165 \noun off 
13166 \color none
13167 convert long to floating point number
13168 \end_inset 
13169 </cell>
13170 </row>
13171 </lyxtabular>
13172
13173 \end_inset 
13174
13175
13176 \newline 
13177
13178 \layout Standard
13179
13180 These support routines are developed in ANSI-C so there is room for space
13181  and speed improvement.
13182  Note if all these routines are used simultaneously the data space might
13183  overflow.
13184  For serious floating point usage it is recommended that the large model
13185  be used.
13186  Also notice that you don't have to call this routines directly.
13187  The compiler will use them automatically every time a floating point operation
13188  is required.
13189 \layout Section
13190
13191 Library Routines
13192 \begin_inset LatexCommand \index{Libraries}
13193
13194 \end_inset 
13195
13196
13197 \layout Standard
13198
13199
13200 \emph on 
13201 <pending: this is messy and incomplete - a little more information is in
13202  sdcc/doc/libdoc.txt
13203 \emph default 
13204  >
13205 \layout Subsection
13206
13207 Compiler support routines (_gptrget, _mulint etc.)
13208 \layout Subsection
13209
13210 Stdclib functions (puts, printf, strcat etc.)
13211 \layout Subsubsection
13212
13213 <stdio.h>
13214 \layout Standard
13215
13216
13217 \begin_inset LatexCommand \index{<stdio.h>}
13218
13219 \end_inset 
13220
13221 As usual on embedded systems you have to provide your own 
13222 \family typewriter 
13223 getchar()
13224 \begin_inset LatexCommand \index{getchar()}
13225
13226 \end_inset 
13227
13228  
13229 \family default 
13230 and 
13231 \family typewriter 
13232 putchar()
13233 \begin_inset LatexCommand \index{putchar()}
13234
13235 \end_inset 
13236
13237
13238 \family default 
13239  routines.
13240  SDCC does not know whether the system connects to a serial line with or
13241  without handshake, LCD, keyboard or other device.
13242  You'll find examples for serial routines f.e.
13243  in sdcc/device/lib.
13244 \layout Standard
13245
13246 If you're short on memory you might want to use 
13247 \family typewriter 
13248 printf_small()
13249 \family default 
13250  
13251 \emph on 
13252 instead
13253 \emph default 
13254  of
13255 \family typewriter 
13256  printf()
13257 \begin_inset LatexCommand \index{printf()}
13258
13259 \end_inset 
13260
13261 .
13262
13263 \family default 
13264  For the mcs51 there is an assembly version 
13265 \family typewriter 
13266 printf_fast()
13267 \family default 
13268  which should fit the requirements of many embedded systems (by unsetting
13269  #defines it can be customized to 
13270 \emph on 
13271 not
13272 \emph default 
13273  support long variables and field widths).
13274 \layout Subsection
13275
13276 Math functions (sin, pow, sqrt etc.)
13277 \layout Subsection
13278
13279 Other libraries
13280 \layout Standard
13281
13282 Libraries
13283 \begin_inset LatexCommand \index{Libraries}
13284
13285 \end_inset 
13286
13287  included in SDCC should have a license at least as liberal as the GNU Lesser
13288  General Public License
13289 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
13290
13291 \end_inset 
13292
13293  
13294 \emph on 
13295 LGPL
13296 \emph default 
13297 .
13298 \layout Comment
13299
13300 license statements for the libraries are missing.
13301  sdcc/device/lib/ser_ir.c
13302 \layout Comment
13303
13304 or _decdptr f.e.
13305  come with a GPL (as opposed to LGPL) License - this will not be liberal
13306  enough for many embedded programmers.
13307 \layout Standard
13308
13309 If you have ported some library or want to share experience about some code
13310  which f.e.
13311  falls into any of these categories Busses (I
13312 \begin_inset Formula $^{\textrm{2}}$
13313 \end_inset 
13314
13315 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
13316  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
13317  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
13318 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
13319
13320 \end_inset 
13321
13322 \SpecialChar ~
13323 would certainly like to hear about it.
13324  Programmers coding for embedded systems are not especially famous for being
13325  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
13326 e these references are very valuable.
13327  Let's help to create a climate where information is shared.
13328 \layout Section
13329
13330 Memory Models
13331 \layout Subsection
13332
13333 MCS51 Memory Models
13334 \begin_inset LatexCommand \index{Memory model}
13335
13336 \end_inset 
13337
13338
13339 \begin_inset LatexCommand \index{MCS51 memory model}
13340
13341 \end_inset 
13342
13343
13344 \layout Subsubsection
13345
13346 Small and Large
13347 \layout Standard
13348
13349 SDCC allows two memory models for MCS51 code, 
13350 \shape slanted 
13351 small
13352 \shape default 
13353  and 
13354 \shape slanted 
13355 large
13356 \shape default 
13357 .
13358  Modules compiled with different memory models should 
13359 \emph on 
13360 never
13361 \emph default 
13362  be combined together or the results would be unpredictable.
13363  The library routines supplied with the compiler are compiled as both small
13364  and large.
13365  The compiled library modules are contained in separate directories as small
13366  and large so that you can link to either set.
13367  
13368 \layout Standard
13369
13370 When the large model is used all variables declared without a storage class
13371  will be allocated into the external ram, this includes all parameters and
13372  local variables (for non-reentrant
13373 \begin_inset LatexCommand \index{reentrant}
13374
13375 \end_inset 
13376
13377  functions).
13378  When the small model is used variables without storage class are allocated
13379  in the internal ram.
13380 \layout Standard
13381
13382 Judicious usage of the processor specific storage classes
13383 \begin_inset LatexCommand \index{Storage class}
13384
13385 \end_inset 
13386
13387  and the 'reentrant' function type will yield much more efficient code,
13388  than using the large model.
13389  Several optimizations are disabled when the program is compiled using the
13390  large model, it is therefore recommended that the small model be used unless
13391  absolutely required.
13392 \layout Subsubsection
13393
13394 External Stack
13395 \begin_inset LatexCommand \label{sub:External-Stack}
13396
13397 \end_inset 
13398
13399
13400 \begin_inset LatexCommand \index{stack}
13401
13402 \end_inset 
13403
13404
13405 \begin_inset LatexCommand \index{External stack (mcs51)}
13406
13407 \end_inset 
13408
13409
13410 \layout Standard
13411
13412
13413 \series bold 
13414 Attention
13415 \series default 
13416 : this option wasn't maintained for a long time and is quite buggy.
13417  Small programs might work.
13418  You've been warned!
13419 \layout Standard
13420
13421 The external stack (-
13422 \begin_inset ERT
13423 status Collapsed
13424
13425 \layout Standard
13426
13427 \backslash 
13428 /
13429 \end_inset 
13430
13431 -xstack option
13432 \begin_inset LatexCommand \index{-\/-xstack}
13433
13434 \end_inset 
13435
13436 ) is located in pdata
13437 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
13438
13439 \end_inset 
13440
13441  memory (usually at the start of the external ram segment) and is 256 bytes
13442  in size.
13443  When -
13444 \begin_inset ERT
13445 status Collapsed
13446
13447 \layout Standard
13448
13449 \backslash 
13450 /
13451 \end_inset 
13452
13453 -xstack option is used to compile the program, the parameters and local
13454  variables
13455 \begin_inset LatexCommand \index{local variables}
13456
13457 \end_inset 
13458
13459  of all reentrant functions are allocated in this area.
13460  This option is provided for programs with large stack space requirements.
13461  When used with the -
13462 \begin_inset ERT
13463 status Collapsed
13464
13465 \layout Standard
13466
13467 \backslash 
13468 /
13469 \end_inset 
13470
13471 -stack-auto
13472 \begin_inset LatexCommand \index{-\/-stack-auto}
13473
13474 \end_inset 
13475
13476  option, all parameters and local variables are allocated on the external
13477  stack (note: support libraries will need to be recompiled with the same
13478  options).
13479 \layout Standard
13480
13481 The compiler outputs the higher order address byte of the external ram segment
13482  into port P2
13483 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
13484
13485 \end_inset 
13486
13487  (see also section 
13488 \begin_inset LatexCommand \ref{sub:MCS51-variants}
13489
13490 \end_inset 
13491
13492 ), therefore when using the External Stack option, this port 
13493 \emph on 
13494 may not
13495 \emph default 
13496  be used by the application program.
13497 \layout Subsection
13498
13499 DS390 Memory Model
13500 \begin_inset LatexCommand \index{Memory model}
13501
13502 \end_inset 
13503
13504
13505 \begin_inset LatexCommand \index{DS390 memory model}
13506
13507 \end_inset 
13508
13509
13510 \layout Standard
13511
13512 The only model supported is Flat 24
13513 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
13514
13515 \end_inset 
13516
13517 .
13518  This generates code for the 24 bit contiguous addressing mode of the Dallas
13519  DS80C390 part.
13520  In this mode, up to four meg of external RAM or code space can be directly
13521  addressed.
13522  See the data sheets at www.dalsemi.com for further information on this part.
13523 \newline 
13524
13525 \newline 
13526 Note that the compiler does not generate any code to place the processor
13527  into 24 bitmode (although 
13528 \emph on 
13529 tinibios
13530 \emph default 
13531  in the ds390 libraries will do that for you).
13532  If you don't use 
13533 \emph on 
13534 tinibios
13535 \emph default 
13536
13537 \begin_inset LatexCommand \index{Tinibios (DS390)}
13538
13539 \end_inset 
13540
13541 , the boot loader or similar code must ensure that the processor is in 24
13542  bit contiguous addressing mode before calling the SDCC startup code.
13543 \newline 
13544
13545 \newline 
13546 Like the 
13547 \emph on 
13548 -
13549 \begin_inset ERT
13550 status Collapsed
13551
13552 \layout Standard
13553
13554 \backslash 
13555 /
13556 \end_inset 
13557
13558 -model-large
13559 \emph default 
13560  option, variables will by default be placed into the XDATA segment.
13561  
13562 \newline 
13563
13564 \newline 
13565 Segments may be placed anywhere in the 4 meg address space using the usual
13566  -
13567 \begin_inset ERT
13568 status Collapsed
13569
13570 \layout Standard
13571
13572 \backslash 
13573 /
13574 \end_inset 
13575
13576 -*-loc options.
13577  Note that if any segments are located above 64K, the -r flag must be passed
13578  to the linker to generate the proper segment relocations, and the Intel
13579  HEX output format must be used.
13580  The -r flag can be passed to the linker by using the option 
13581 \emph on 
13582 -Wl-r
13583 \emph default 
13584  on the SDCC command line.
13585  However, currently the linker can not handle code segments > 64k.
13586 \layout Section
13587
13588 Pragmas
13589 \begin_inset LatexCommand \index{Pragmas}
13590
13591 \end_inset 
13592
13593
13594 \layout Standard
13595
13596 SDCC supports the following #pragma directives:
13597 \layout Itemize
13598
13599 save
13600 \begin_inset LatexCommand \index{\#pragma save}
13601
13602 \end_inset 
13603
13604  - this will save all current options to the save/restore stack.
13605  See restore.
13606 \layout Itemize
13607
13608 restore
13609 \begin_inset LatexCommand \index{\#pragma restore}
13610
13611 \end_inset 
13612
13613  - will restore saved options from the last save.
13614  saves & restores can be nested.
13615  SDCC uses a save/restore stack: save pushes current options to the stack,
13616  restore pulls current options from the stack.
13617  See save.
13618 \layout Itemize
13619
13620 nogcse
13621 \begin_inset LatexCommand \index{\#pragma nogcse}
13622
13623 \end_inset 
13624
13625  - will stop global common subexpression elimination.
13626 \layout Itemize
13627
13628 noinduction
13629 \begin_inset LatexCommand \index{\#pragma noinduction}
13630
13631 \end_inset 
13632
13633  - will stop loop induction optimizations.
13634 \layout Itemize
13635
13636 nojtbound
13637 \begin_inset LatexCommand \index{\#pragma nojtbound}
13638
13639 \end_inset 
13640
13641  - will not generate code for boundary value checking, when switch statements
13642  are turned into jump-tables (dangerous).
13643  For more details see section 
13644 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
13645
13646 \end_inset 
13647
13648 .
13649 \layout Itemize
13650
13651 nooverlay
13652 \begin_inset LatexCommand \index{\#pragma nooverlay}
13653
13654 \end_inset 
13655
13656  - the compiler will not overlay the parameters and local variables of a
13657  function.
13658 \layout Itemize
13659
13660 less_pedantic
13661 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
13662
13663 \end_inset 
13664
13665  - the compiler will not warn you anymore for obvious mistakes, you'r on
13666  your own now ;-(
13667 \layout Itemize
13668
13669 noloopreverse
13670 \begin_inset LatexCommand \index{\#pragma noloopreverse}
13671
13672 \end_inset 
13673
13674  - Will not do loop reversal optimization
13675 \layout Itemize
13676
13677 exclude
13678 \begin_inset LatexCommand \index{\#pragma exclude}
13679
13680 \end_inset 
13681
13682  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables generation of
13683  pair of push/pop
13684 \begin_inset LatexCommand \index{push/pop}
13685
13686 \end_inset 
13687
13688  instruction in ISR function (using interrupt
13689 \begin_inset LatexCommand \index{interrupt}
13690
13691 \end_inset 
13692
13693  keyword).
13694  The directive should be placed immediately before the ISR function definition
13695  and it affects ALL ISR functions following it.
13696  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
13697 exclude\SpecialChar ~
13698 none
13699 \begin_inset LatexCommand \index{\#pragma exclude}
13700
13701 \end_inset 
13702
13703 .
13704 \layout Itemize
13705
13706 noiv
13707 \begin_inset LatexCommand \index{\#pragma noiv}
13708
13709 \end_inset 
13710
13711  - Do not generate interrupt
13712 \begin_inset LatexCommand \index{interrupt}
13713
13714 \end_inset 
13715
13716  vector table entries for all ISR functions defined after the pragma.
13717  This is useful in cases where the interrupt vector table must be defined
13718  manually, or when there is a secondary, manually defined interrupt vector
13719  table (e.g.
13720  for the autovector feature of the Cypress EZ-USB FX2).
13721  More elegantly this can be achieved by obmitting the optional interrupt
13722  number after the interrupt keyword, see section 
13723 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
13724
13725 \end_inset 
13726
13727 \SpecialChar ~
13728 about interrupts.
13729 \layout Itemize
13730
13731 callee_saves
13732 \begin_inset LatexCommand \index{\#pragma callee\_saves}
13733
13734 \end_inset 
13735
13736
13737 \begin_inset LatexCommand \index{function prologue}
13738
13739 \end_inset 
13740
13741  function1[,function2[,function3...]] - The compiler by default uses a caller
13742  saves convention for register saving across function calls, however this
13743  can cause unnecessary register pushing & popping
13744 \begin_inset LatexCommand \index{push/pop}
13745
13746 \end_inset 
13747
13748  when calling small functions from larger functions.
13749  This option can be used to switch off the register saving convention for
13750  the function names specified.
13751  The compiler will not save registers when calling these functions, extra
13752  code need to be manually inserted at the entry & exit for these functions
13753  to save & restore the registers used by these functions, this can SUBSTANTIALLY
13754  reduce code & improve run time performance of the generated code.
13755  In the future the compiler (with inter procedural analysis) may be able
13756  to determine the appropriate scheme to use for each function call.
13757  If -
13758 \begin_inset ERT
13759 status Collapsed
13760
13761 \layout Standard
13762
13763 \backslash 
13764 /
13765 \end_inset 
13766
13767 -callee-saves command line option is used, the function names specified
13768  in #pragma\SpecialChar ~
13769 callee_saves
13770 \begin_inset LatexCommand \index{\#pragma callee\_saves}
13771
13772 \end_inset 
13773
13774  is appended to the list of functions specified in the command line.
13775 \layout Standard
13776
13777 SDCPP supports the following #pragma directives:
13778 \layout Itemize
13779
13780 preproc_asm
13781 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
13782
13783 \end_inset 
13784
13785  (+ | -) - switch _asm _endasm block preprocessing on / off.
13786  Default is on.
13787 \layout Standard
13788
13789 The pragma's are intended to be used to turn-on or off certain optimizations
13790  which might cause the compiler to generate extra stack / data space to
13791  store compiler generated temporary variables.
13792  This usually happens in large functions.
13793  Pragma directives should be used as shown in the following example, they
13794  are used to control options & optimizations for a given function; pragmas
13795  should be placed before and/or after a function, placing pragma's inside
13796  a function body could have unpredictable results.
13797 \layout Verse
13798
13799
13800 \family typewriter 
13801 #pragma save
13802 \begin_inset LatexCommand \index{\#pragma save}
13803
13804 \end_inset 
13805
13806  \SpecialChar ~
13807 \SpecialChar ~
13808 \SpecialChar ~
13809 \SpecialChar ~
13810 \SpecialChar ~
13811 \SpecialChar ~
13812 \SpecialChar ~
13813 /* save the current settings */ 
13814 \newline 
13815 #pragma nogcse
13816 \begin_inset LatexCommand \index{\#pragma nogcse}
13817
13818 \end_inset 
13819
13820  \SpecialChar ~
13821 \SpecialChar ~
13822 \SpecialChar ~
13823 \SpecialChar ~
13824 \SpecialChar ~
13825 /* turnoff global subexpression elimination */ 
13826 \newline 
13827 #pragma noinduction
13828 \begin_inset LatexCommand \index{\#pragma noinduction}
13829
13830 \end_inset 
13831
13832  /* turn off induction optimizations */ 
13833 \newline 
13834 int foo () 
13835 \newline 
13836
13837 \newline 
13838 \SpecialChar ~
13839  \SpecialChar ~
13840  ...
13841  
13842 \newline 
13843 \SpecialChar ~
13844  \SpecialChar ~
13845  /* large code */ 
13846 \newline 
13847 \SpecialChar ~
13848  \SpecialChar ~
13849  ...
13850  
13851 \newline 
13852
13853 \newline 
13854 #pragma restore
13855 \begin_inset LatexCommand \index{\#pragma restore}
13856
13857 \end_inset 
13858
13859  /* turn the optimizations back on */
13860 \layout Standard
13861
13862 The compiler will generate a warning message when extra space is allocated.
13863  It is strongly recommended that the save and restore pragma's be used when
13864  changing options for a function.
13865 \layout Section
13866
13867 Defines Created by the Compiler
13868 \layout Standard
13869
13870 The compiler creates the following #defines
13871 \begin_inset LatexCommand \index{\#defines}
13872
13873 \end_inset 
13874
13875
13876 \begin_inset LatexCommand \index{Defines created by the compiler}
13877
13878 \end_inset 
13879
13880 :
13881 \newline 
13882
13883 \layout Standard
13884
13885
13886 \begin_inset  Tabular
13887 <lyxtabular version="3" rows="10" columns="2">
13888 <features>
13889 <column alignment="center" valignment="top" leftline="true" width="0">
13890 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
13891 <row topline="true" bottomline="true">
13892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13893 \begin_inset Text
13894
13895 \layout Standard
13896
13897
13898 \series bold 
13899 #define
13900 \end_inset 
13901 </cell>
13902 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13903 \begin_inset Text
13904
13905 \layout Standard
13906
13907
13908 \series bold 
13909 Description
13910 \end_inset 
13911 </cell>
13912 </row>
13913 <row topline="true">
13914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13915 \begin_inset Text
13916
13917 \layout Standard
13918
13919 SDCC
13920 \begin_inset LatexCommand \index{SDCC}
13921
13922 \end_inset 
13923
13924  
13925 \end_inset 
13926 </cell>
13927 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13928 \begin_inset Text
13929
13930 \layout Standard
13931
13932 this Symbol is always defined
13933 \end_inset 
13934 </cell>
13935 </row>
13936 <row topline="true">
13937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13938 \begin_inset Text
13939
13940 \layout Standard
13941
13942 SDCC_mcs51
13943 \begin_inset LatexCommand \index{SDCC\_mcs51}
13944
13945 \end_inset 
13946
13947  or SDCC_ds390
13948 \begin_inset LatexCommand \index{SDCC\_ds390}
13949
13950 \end_inset 
13951
13952  or SDCC_z80
13953 \begin_inset LatexCommand \index{SDCC\_z80}
13954
13955 \end_inset 
13956
13957 , etc
13958 \end_inset 
13959 </cell>
13960 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13961 \begin_inset Text
13962
13963 \layout Standard
13964
13965 depending on the model used (e.g.: -mds390
13966 \end_inset 
13967 </cell>
13968 </row>
13969 <row topline="true">
13970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13971 \begin_inset Text
13972
13973 \layout Standard
13974
13975 __mcs51
13976 \begin_inset LatexCommand \index{\_\_mcs51}
13977
13978 \end_inset 
13979
13980 , __ds390
13981 \begin_inset LatexCommand \index{\_\_ds390}
13982
13983 \end_inset 
13984
13985 , __hc08
13986 \begin_inset LatexCommand \index{\_\_hc08}
13987
13988 \end_inset 
13989
13990 , __z80
13991 \begin_inset LatexCommand \index{\_\_z80}
13992
13993 \end_inset 
13994
13995 , etc
13996 \end_inset 
13997 </cell>
13998 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13999 \begin_inset Text
14000
14001 \layout Standard
14002
14003 depending on the model used (e.g.
14004  -mz80)
14005 \end_inset 
14006 </cell>
14007 </row>
14008 <row topline="true">
14009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14010 \begin_inset Text
14011
14012 \layout Standard
14013
14014 SDCC_STACK_AUTO
14015 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
14016
14017 \end_inset 
14018
14019
14020 \end_inset 
14021 </cell>
14022 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14023 \begin_inset Text
14024
14025 \layout Standard
14026
14027 when 
14028 \emph on 
14029 -
14030 \begin_inset ERT
14031 status Collapsed
14032
14033 \layout Standard
14034
14035 \backslash 
14036 /
14037 \end_inset 
14038
14039 -stack-auto
14040 \emph default 
14041  option is used
14042 \end_inset 
14043 </cell>
14044 </row>
14045 <row topline="true">
14046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14047 \begin_inset Text
14048
14049 \layout Standard
14050
14051 SDCC_MODEL_SMALL
14052 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
14053
14054 \end_inset 
14055
14056
14057 \end_inset 
14058 </cell>
14059 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14060 \begin_inset Text
14061
14062 \layout Standard
14063
14064 when 
14065 \emph on 
14066 -
14067 \begin_inset ERT
14068 status Collapsed
14069
14070 \layout Standard
14071
14072 \backslash 
14073 /
14074 \end_inset 
14075
14076 -model-small
14077 \emph default 
14078  is used
14079 \end_inset 
14080 </cell>
14081 </row>
14082 <row topline="true">
14083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14084 \begin_inset Text
14085
14086 \layout Standard
14087
14088 SDCC_MODEL_LARGE
14089 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
14090
14091 \end_inset 
14092
14093
14094 \end_inset 
14095 </cell>
14096 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14097 \begin_inset Text
14098
14099 \layout Standard
14100
14101 when 
14102 \emph on 
14103 -
14104 \begin_inset ERT
14105 status Collapsed
14106
14107 \layout Standard
14108
14109 \backslash 
14110 /
14111 \end_inset 
14112
14113 -model-large
14114 \emph default 
14115  is used
14116 \end_inset 
14117 </cell>
14118 </row>
14119 <row topline="true">
14120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14121 \begin_inset Text
14122
14123 \layout Standard
14124
14125 SDCC_USE_XSTACK
14126 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
14127
14128 \end_inset 
14129
14130
14131 \end_inset 
14132 </cell>
14133 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14134 \begin_inset Text
14135
14136 \layout Standard
14137
14138 when 
14139 \emph on 
14140 -
14141 \begin_inset ERT
14142 status Collapsed
14143
14144 \layout Standard
14145
14146 \backslash 
14147 /
14148 \end_inset 
14149
14150 -xstack
14151 \emph default 
14152  option is used
14153 \end_inset 
14154 </cell>
14155 </row>
14156 <row topline="true">
14157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14158 \begin_inset Text
14159
14160 \layout Standard
14161
14162 SDCC_STACK_TENBIT
14163 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
14164
14165 \end_inset 
14166
14167  
14168 \end_inset 
14169 </cell>
14170 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14171 \begin_inset Text
14172
14173 \layout Standard
14174
14175 when 
14176 \emph on 
14177 -mds390
14178 \emph default 
14179  is used
14180 \end_inset 
14181 </cell>
14182 </row>
14183 <row topline="true" bottomline="true">
14184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14185 \begin_inset Text
14186
14187 \layout Standard
14188
14189 SDCC_MODEL_FLAT24
14190 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
14191
14192 \end_inset 
14193
14194
14195 \end_inset 
14196 </cell>
14197 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14198 \begin_inset Text
14199
14200 \layout Standard
14201
14202 when 
14203 \emph on 
14204 -mds390
14205 \emph default 
14206  is used
14207 \end_inset 
14208 </cell>
14209 </row>
14210 </lyxtabular>
14211
14212 \end_inset 
14213
14214
14215 \layout Chapter
14216
14217 Notes on supported Processors
14218 \layout Section
14219
14220 MCS51 variants
14221 \begin_inset LatexCommand \label{sub:MCS51-variants}
14222
14223 \end_inset 
14224
14225
14226 \begin_inset LatexCommand \index{MCS51 variants}
14227
14228 \end_inset 
14229
14230
14231 \layout Standard
14232
14233 MCS51 processors are available from many vendors and come in many different
14234  flavours.
14235  While they might differ considerably in respect to Special Function Registers
14236  the core MCS51 is usually not modified or is kept compatible.
14237  
14238 \layout Subsection
14239
14240 pdata access by SFR 
14241 \layout Standard
14242
14243 With the upcome of devices with internal xdata and flash memory devices
14244  using port P2
14245 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
14246
14247 \end_inset 
14248
14249  as dedicated I/O port is becoming more popular.
14250  Switching the high byte for pdata
14251 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
14252
14253 \end_inset 
14254
14255  access which was formerly done by port P2 is then achieved by a Special
14256  Function Register
14257 \begin_inset LatexCommand \index{sfr}
14258
14259 \end_inset 
14260
14261 .
14262  In well-established MCS51 tradition the address of this 
14263 \emph on 
14264 sfr
14265 \emph default 
14266  is where the chip designers decided to put it.
14267  Needless to say that they didn't agree on a common name either.
14268  As pdata addressing is used in the startup code for the initialization
14269  of xdata variables a separate startup code should be used as described
14270  in section 
14271 \begin_inset LatexCommand \ref{sub:Startup-Code}
14272
14273 \end_inset 
14274
14275 .
14276 \layout Subsection
14277
14278 Other Features available by SFR
14279 \layout Standard
14280
14281 Some MCS51 variants offer features like Double DPTR
14282 \begin_inset LatexCommand \index{DPTR}
14283
14284 \end_inset 
14285
14286 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
14287  These are currently not used for the MCS51 port.
14288  If you absolutely need them you can fall back to inline assembly or submit
14289  a patch to SDCC.
14290 \layout Section
14291
14292 The Z80 and gbz80 port
14293 \layout Standard
14294
14295 SDCC can target both the Zilog 
14296 \begin_inset LatexCommand \index{Z80}
14297
14298 \end_inset 
14299
14300  and the Nintendo Gameboy's Z80-like gbz80
14301 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
14302
14303 \end_inset 
14304
14305 .
14306  The Z80 port is passed through the same 
14307 \emph on 
14308 regressions tests
14309 \begin_inset LatexCommand \index{Regression test}
14310
14311 \end_inset 
14312
14313
14314 \emph default 
14315  as the MCS51 and DS390 ports, so floating point support, support for long
14316  variables and bitfield support is fine.
14317  See mailing lists and forums about interrupt routines.
14318 \layout Standard
14319
14320 As always, the code is the authoritative reference - see z80/ralloc.c and
14321  z80/gen.c.
14322  The stack
14323 \begin_inset LatexCommand \index{stack}
14324
14325 \end_inset 
14326
14327  frame is similar to that generated by the IAR Z80 compiler.
14328  IX is used as the base pointer, HL and IY are used as a temporary registers,
14329  and BC and DE are available for holding variables.
14330  Return values
14331 \begin_inset LatexCommand \index{return value}
14332
14333 \end_inset 
14334
14335  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
14336  bytes).
14337  The gbz80 port use the same set of registers for the return values, but
14338  in a different order of significance: E (one byte), DE (two bytes), or
14339  HLDE (four bytes).
14340 \layout Section
14341
14342 The HC08 port
14343 \layout Standard
14344
14345 The port to the Motorola HC08
14346 \begin_inset LatexCommand \index{HC08}
14347
14348 \end_inset 
14349
14350  family has been added in October 2003, and is still undergoing some basic
14351  development.
14352  The code generator is complete, but the register allocation is still quite
14353  unoptimized.
14354  Some of the SDCC's standard C library functions have embedded non-HC08
14355  inline assembly and so are not yet usable.
14356 \newline 
14357
14358 \newline 
14359
14360 \layout Section
14361
14362 The PIC14 port
14363 \layout Standard
14364
14365 The 14bit PIC
14366 \begin_inset LatexCommand \index{PIC14}
14367
14368 \end_inset 
14369
14370  port still requires a major effort from the development community.
14371  However it can work for very simple code.
14372 \layout Subsection
14373
14374 C code and 14bit PIC code page
14375 \begin_inset LatexCommand \index{code page (pic14)}
14376
14377 \end_inset 
14378
14379  and RAM banks
14380 \begin_inset LatexCommand \index{RAM bank (pic14)}
14381
14382 \end_inset 
14383
14384
14385 \layout Standard
14386
14387 The linker organizes allocation for the code page and RAM banks.
14388  It does not have intimate knowledge of the code flow.
14389  It will put all the code section of a single asm file into a single code
14390  page.
14391  In order to make use of multiple code pages, separate asm files must be
14392  used.
14393  The compiler treats all functions of a single C file as being in the same
14394  code page unless it is non static.
14395  The compiler treats all local variables of a single C file as being in
14396  the same RAM bank unless it is an extern.
14397 \newline 
14398
14399 \newline 
14400 To get the best follow these guide lines:
14401 \layout Enumerate
14402
14403 make local functions static, as non static functions require code page selection
14404  overhead.
14405 \layout Enumerate
14406
14407 Make local variables static as extern variables require RAM bank selection
14408  overhead.
14409 \layout Enumerate
14410
14411 For devices that have multiple code pages it is more efficient to use the
14412  same number of files as pages, i.e.
14413  for the 16F877 use 4 separate files and i.e.
14414  for the 16F874 use 2 separate files.
14415  This way the linker can put the code for each file into different code
14416  pages and the compiler can allocate reusable variables more efficiently
14417  and there's less page selection overhead.
14418  And as for any 8 bit micro (especially for PIC 14 as they have a very simple
14419  instruction set) use 'unsigned char' whereever possible instead of 'int'.
14420 \layout Subsection
14421
14422 Creating a device include file 
14423 \layout Standard
14424
14425 For generating a device include file use the support perl script inc2h.pl
14426  kept in directory support/script.
14427 \layout Subsection
14428
14429 Interrupt code
14430 \layout Standard
14431
14432 For the interrupt function, use the keyword 'interrupt'
14433 \begin_inset LatexCommand \index{interrupt}
14434
14435 \end_inset 
14436
14437  with level number of 0 (PIC14 only has 1 interrupt so this number is only
14438  there to avoid a syntax error - it ought to be fixed).
14439  E.g.:
14440 \layout Verse
14441
14442
14443 \family typewriter 
14444 void Intr(void) interrupt 0
14445 \newline 
14446 {
14447 \newline 
14448 \SpecialChar ~
14449 \SpecialChar ~
14450 T0IF = 0; /* Clear timer interrupt */
14451 \newline 
14452 }
14453 \layout Standard
14454
14455 Linking and assembling
14456 \newline 
14457 For assembling you can use either GPUTILS'
14458 \begin_inset LatexCommand \index{gputils (pic tools)}
14459
14460 \end_inset 
14461
14462  gpasm.exe or MPLAB's mpasmwin.exe.
14463  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
14464  If you use MPLAB and an interrupt function then the linker script file
14465  vectors section will need to be enlarged to link with mplink.
14466 \newline 
14467
14468 \newline 
14469 Here is a 
14470 \family typewriter 
14471 Makefile
14472 \family default 
14473  using GPUTILS:
14474 \layout Verse
14475
14476
14477 \family typewriter 
14478 .c.o:
14479 \newline 
14480 \SpecialChar ~
14481 \SpecialChar ~
14482 \SpecialChar ~
14483 \SpecialChar ~
14484 \SpecialChar ~
14485 \SpecialChar ~
14486 \SpecialChar ~
14487 \SpecialChar ~
14488 sdcc -S -V -mpic14 -p16F877 $< 
14489 \newline 
14490 \SpecialChar ~
14491 \SpecialChar ~
14492 \SpecialChar ~
14493 \SpecialChar ~
14494 \SpecialChar ~
14495 \SpecialChar ~
14496 \SpecialChar ~
14497 \SpecialChar ~
14498 gpasm -c $*.asm
14499 \newline 
14500
14501 \newline 
14502 $(PRJ).hex: $(OBJS) 
14503 \newline 
14504 \SpecialChar ~
14505 \SpecialChar ~
14506 \SpecialChar ~
14507 \SpecialChar ~
14508 \SpecialChar ~
14509 \SpecialChar ~
14510 \SpecialChar ~
14511 \SpecialChar ~
14512 gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS)
14513 \layout Standard
14514
14515 Here is a 
14516 \family typewriter 
14517 Makefile
14518 \family default 
14519  using MPLAB:
14520 \layout Verse
14521
14522
14523 \family typewriter 
14524 .c.o: 
14525 \newline 
14526 \SpecialChar ~
14527 \SpecialChar ~
14528 \SpecialChar ~
14529 \SpecialChar ~
14530 \SpecialChar ~
14531 \SpecialChar ~
14532 \SpecialChar ~
14533 \SpecialChar ~
14534 sdcc -S -V -mpic14 -p16F877 $< 
14535 \newline 
14536 \SpecialChar ~
14537 \SpecialChar ~
14538 \SpecialChar ~
14539 \SpecialChar ~
14540 \SpecialChar ~
14541 \SpecialChar ~
14542 \SpecialChar ~
14543 \SpecialChar ~
14544 mpasmwin /q /o $*.asm
14545 \newline 
14546
14547 \newline 
14548 $(PRJ).hex: $(OBJS) 
14549 \newline 
14550 \SpecialChar ~
14551 \SpecialChar ~
14552 \SpecialChar ~
14553 \SpecialChar ~
14554 \SpecialChar ~
14555 \SpecialChar ~
14556 \SpecialChar ~
14557 \SpecialChar ~
14558 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS)
14559 \layout Section
14560
14561 The PIC16
14562 \begin_inset LatexCommand \index{PIC16}
14563
14564 \end_inset 
14565
14566  port
14567 \layout Standard
14568
14569 The PIC16
14570 \begin_inset LatexCommand \index{PIC16}
14571
14572 \end_inset 
14573
14574  port is the portion of SDCC that is responsible to produce code for the
14575  Microchip
14576 \begin_inset LatexCommand \index{Microchip}
14577
14578 \end_inset 
14579
14580 (TM) microcontrollers with 16 bit core.
14581  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
14582 \layout Subsection
14583
14584 Global Options
14585 \layout Standard
14586
14587 PIC16 port supports the standard command line arguments as supposed, with
14588  the exception of certain cases that will be mentioned in the following
14589  list:
14590 \layout List
14591 \labelwidthstring 00.00.0000
14592
14593 -
14594 \begin_inset ERT
14595 status Collapsed
14596
14597 \layout Standard
14598
14599 \backslash 
14600 /
14601 \end_inset 
14602
14603 -stack-auto Auto variables that are function parameters, will be saved on
14604  stack by default.
14605  
14606 \emph on 
14607 There is no need to specify this in the command line.
14608 \layout List
14609 \labelwidthstring 00.00.0000
14610
14611 -
14612 \begin_inset ERT
14613 status Collapsed
14614
14615 \layout Standard
14616
14617 \backslash 
14618 /
14619 \end_inset 
14620
14621 -float-reent All floating point functions are reentrant by default.
14622  
14623 \emph on 
14624 There is no need to specifiy this in the command line.
14625 \layout List
14626 \labelwidthstring 00.00.0000
14627
14628 -
14629 \begin_inset ERT
14630 status Collapsed
14631
14632 \layout Standard
14633
14634 \backslash 
14635 /
14636 \end_inset 
14637
14638 -callee-saves See -
14639 \begin_inset ERT
14640 status Collapsed
14641
14642 \layout Standard
14643
14644 \backslash 
14645 /
14646 \end_inset 
14647
14648 -all-callee-saves
14649 \layout List
14650 \labelwidthstring 00.00.0000
14651
14652 -
14653 \begin_inset ERT
14654 status Collapsed
14655
14656 \layout Standard
14657
14658 \backslash 
14659 /
14660 \end_inset 
14661
14662 -all-callee-saves All function arguments are passed on stack by default.
14663  
14664 \emph on 
14665 There is no need to specify this in the command line.
14666 \layout List
14667 \labelwidthstring 00.00.0000
14668
14669 -
14670 \begin_inset ERT
14671 status Collapsed
14672
14673 \layout Standard
14674
14675 \backslash 
14676 /
14677 \end_inset 
14678
14679 -fommit-frame-pointer Frame pointer will be omitted when the function uses
14680  no local variables.
14681 \layout Subsection
14682
14683 Port Specific Options
14684 \layout Standard
14685
14686 The port specific options appear after the global options in the sdcc --help
14687  output.
14688 \layout Subsubsection
14689
14690 General Options
14691 \layout Standard
14692
14693 General options enable certain port features and optimizations.
14694 \layout List
14695 \labelwidthstring 00.00.0000
14696
14697 -
14698 \begin_inset ERT
14699 status Collapsed
14700
14701 \layout Standard
14702
14703 \backslash 
14704 /
14705 \end_inset 
14706
14707 -pgen-bank Instructs the port to insert BANKSEL directives before instructions
14708  that use the Bank Select Register (BSR).
14709 \layout List
14710 \labelwidthstring 00.00.0000
14711
14712 -
14713 \begin_inset ERT
14714 status Collapsed
14715
14716 \layout Standard
14717
14718 \backslash 
14719 /
14720 \end_inset 
14721
14722 -pomit-config-words Instructs the port to omit the generation of the configurati
14723 on words.
14724 \layout List
14725 \labelwidthstring 00.00.0000
14726
14727 -
14728 \begin_inset ERT
14729 status Collapsed
14730
14731 \layout Standard
14732
14733 \backslash 
14734 /
14735 \end_inset 
14736
14737 -pomit-ivt Instructs the port to omit the generation of the interrupt vectors
14738 \layout List
14739 \labelwidthstring 00.00.0000
14740
14741 -
14742 \begin_inset ERT
14743 status Collapsed
14744
14745 \layout Standard
14746
14747 \backslash 
14748 /
14749 \end_inset 
14750
14751 -pleave-reset-vector Used in conjuction with the previous command, instructs
14752  the port NOT to omit the reset vector.
14753 \layout List
14754 \labelwidthstring 00.00.0000
14755
14756 -
14757 \begin_inset ERT
14758 status Collapsed
14759
14760 \layout Standard
14761
14762 \backslash 
14763 /
14764 \end_inset 
14765
14766 -stack-model=[model] Used in conjuction with the command above.
14767  Defines the stack model to be used, valid stack models are : 
14768 \begin_deeper 
14769 \layout List
14770 \labelwidthstring 00.00.0000
14771
14772
14773 \emph on 
14774 small
14775 \emph default 
14776  Selects small stack model.
14777  8 bit stack and frame pointers.
14778  Supports 256 bytes stack size.
14779 \layout List
14780 \labelwidthstring 00.00.0000
14781
14782
14783 \emph on 
14784 large
14785 \emph default 
14786  Selects large stack model.
14787  16 bit stack and frame pointers.
14788  Supports 65536 bytes stack size.
14789 \end_deeper 
14790 \layout List
14791 \labelwidthstring 00.00.0000
14792
14793 -
14794 \begin_inset ERT
14795 status Collapsed
14796
14797 \layout Standard
14798
14799 \backslash 
14800 /
14801 \end_inset 
14802
14803 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
14804  unitialized data variables with [kword].
14805  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
14806 \layout Subsubsection
14807
14808 Debugging Options
14809 \layout Standard
14810
14811 Debugging options enable extra debugging information in the output files.
14812 \layout List
14813 \labelwidthstring 00.00.0000
14814
14815 -
14816 \begin_inset ERT
14817 status Collapsed
14818
14819 \layout Standard
14820
14821 \backslash 
14822 /
14823 \end_inset 
14824
14825 -debug-xtra Similar to --debug, but dumps more information.
14826 \layout List
14827 \labelwidthstring 00.00.0000
14828
14829 -
14830 \begin_inset ERT
14831 status Collapsed
14832
14833 \layout Standard
14834
14835 \backslash 
14836 /
14837 \end_inset 
14838
14839 -debug-ralloc Force register allocator to dump <source>.d file with debugging
14840  information.
14841  <source> is the name of the file compiled.
14842 \layout List
14843 \labelwidthstring 00.00.0000
14844
14845 -
14846 \begin_inset ERT
14847 status Collapsed
14848
14849 \layout Standard
14850
14851 \backslash 
14852 /
14853 \end_inset 
14854
14855 -pcode-verbose Enable pcode debugging information in translation.
14856 \layout Subsection
14857
14858 Preprocessor Macros
14859 \layout Standard
14860
14861 PIC16 port defines the following preprocessor macros while translating a
14862  source.
14863 \layout Standard
14864 \align center 
14865
14866 \begin_inset  Tabular
14867 <lyxtabular version="3" rows="2" columns="2">
14868 <features>
14869 <column alignment="center" valignment="top" leftline="true" width="0">
14870 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
14871 <row topline="true" bottomline="true">
14872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14873 \begin_inset Text
14874
14875 \layout Standard
14876
14877 Macro
14878 \end_inset 
14879 </cell>
14880 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14881 \begin_inset Text
14882
14883 \layout Standard
14884
14885 Description
14886 \end_inset 
14887 </cell>
14888 </row>
14889 <row topline="true" bottomline="true">
14890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14891 \begin_inset Text
14892
14893 \layout Standard
14894
14895 pic18fxxxx
14896 \end_inset 
14897 </cell>
14898 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14899 \begin_inset Text
14900
14901 \layout Standard
14902
14903 MCU Identification.
14904  
14905 \emph on 
14906 xxxx
14907 \emph default 
14908  is the microcontrol identification number, i.e.
14909  452, 6620, etc
14910 \end_inset 
14911 </cell>
14912 </row>
14913 </lyxtabular>
14914
14915 \end_inset 
14916
14917
14918 \layout Subsection
14919
14920 Directories
14921 \layout Standard
14922
14923 PIC16 port uses the following directories for searching header files and
14924  libraries.
14925 \layout Standard
14926 \align center 
14927
14928 \begin_inset  Tabular
14929 <lyxtabular version="3" rows="3" columns="4">
14930 <features>
14931 <column alignment="center" valignment="top" leftline="true" width="0">
14932 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
14933 <column alignment="center" valignment="top" width="0">
14934 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
14935 <row topline="true" bottomline="true">
14936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14937 \begin_inset Text
14938
14939 \layout Standard
14940
14941 Directory
14942 \end_inset 
14943 </cell>
14944 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14945 \begin_inset Text
14946
14947 \layout Standard
14948
14949 Description
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 Target
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 Command prefix
14966 \end_inset 
14967 </cell>
14968 </row>
14969 <row topline="true">
14970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14971 \begin_inset Text
14972
14973 \layout Standard
14974
14975 PREFIX/sdcc/include/pic16
14976 \end_inset 
14977 </cell>
14978 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14979 \begin_inset Text
14980
14981 \layout Standard
14982
14983 PIC16 specific headers
14984 \end_inset 
14985 </cell>
14986 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14987 \begin_inset Text
14988
14989 \layout Standard
14990
14991 Compiler
14992 \end_inset 
14993 </cell>
14994 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14995 \begin_inset Text
14996
14997 \layout Standard
14998
14999 -I
15000 \end_inset 
15001 </cell>
15002 </row>
15003 <row topline="true" bottomline="true">
15004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15005 \begin_inset Text
15006
15007 \layout Standard
15008
15009 PREFIX/sdcc/lib/pic16
15010 \end_inset 
15011 </cell>
15012 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15013 \begin_inset Text
15014
15015 \layout Standard
15016
15017 PIC16 specific libraries
15018 \end_inset 
15019 </cell>
15020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15021 \begin_inset Text
15022
15023 \layout Standard
15024
15025 Linker
15026 \end_inset 
15027 </cell>
15028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15029 \begin_inset Text
15030
15031 \layout Standard
15032
15033 -L
15034 \end_inset 
15035 </cell>
15036 </row>
15037 </lyxtabular>
15038
15039 \end_inset 
15040
15041
15042 \layout Subsection
15043
15044 Pragmas
15045 \layout Standard
15046
15047 PIC16 port currently supports the following pragmas:
15048 \layout List
15049 \labelwidthstring 00.00.0000
15050
15051 stack pragma stack forces the code generator to initialize the stack & frame
15052  pointers at a specific address.
15053  This is an adhoc solution since gplink does not support yet stack.
15054  When the gplink issue is resolved the pragma will be deprecated
15055 \begin_inset Foot
15056 collapsed true
15057
15058 \layout Standard
15059
15060
15061 \emph on 
15062 It is important to initialize the stack, otherwise strange things can happen.
15063  Stack is not initialized by default because there are some sources that
15064  do not require it.
15065  (like library sources)
15066 \end_inset 
15067
15068 .
15069 \newline 
15070 The stack pragma should be used only once in a project.
15071  Multiple pragmas may result in indeterminate behaviour of the program.
15072 \newline 
15073 If you omit setting the pragma the port emits a warning message before linking.
15074  If not initializing the stack is desired ignore the message.
15075 \layout LyX-Code
15076
15077 Example:
15078 \layout LyX-Code
15079
15080 \layout LyX-Code
15081
15082 /* initializes stack at RAM address 0x5ff*/
15083 \layout LyX-Code
15084
15085 #pragma stack 0x5ff
15086 \layout LyX-Code
15087
15088 \layout Subsection
15089
15090 Header Files
15091 \layout Standard
15092
15093 There is one main header file that can be included to the source files using
15094  the pic16 port.
15095  That file is the 
15096 \series bold 
15097 pic18fregs.h
15098 \series default 
15099 .
15100  This header file contains the definitions for the processor special registers,
15101  so it is necessery if the soruce accesses them.
15102  It can be included by adding the following line in the beginning of the
15103  file:
15104 \layout LyX-Code
15105
15106 #include <pic18fregs.h>
15107 \layout Standard
15108
15109 The specific microcontroller is selected within the pic18fregs.h automatically,
15110  so the same source can be used with a variety of devices.
15111 \layout Subsection
15112
15113 Libraries
15114 \layout Standard
15115
15116 The libraries that pic16 port depends on are the microcontroller device
15117  libraries which contain the symbol definitions for the microcontroller
15118  special function registers.
15119  These libraries have the format pic18fxxxx.lib, where 
15120 \emph on 
15121 xxxx
15122 \emph default 
15123  is the microcontroller identification number.
15124  The specific library is selected automatically by the compiler at link
15125  stage according to the selected device.
15126 \layout Standard
15127
15128 Libraries are created with gplib which is part of the gputils package 
15129 \begin_inset LatexCommand \url{http://gputils.sourceforge.net}
15130
15131 \end_inset 
15132
15133 .
15134 \layout Subsection
15135
15136 Memory Models
15137 \layout Standard
15138
15139 The following memory models are supported by PIC16 port:
15140 \layout Itemize
15141
15142 small model
15143 \layout Itemize
15144
15145 large model
15146 \layout Standard
15147
15148 Memory model affects the default size of pointers within the source.
15149  The sizes are shown in the next table:
15150 \layout Standard
15151 \align center 
15152
15153 \begin_inset  Tabular
15154 <lyxtabular version="3" rows="3" columns="3">
15155 <features>
15156 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15157 <column alignment="center" valignment="top" leftline="true" width="0">
15158 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15159 <row topline="true" bottomline="true">
15160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15161 \begin_inset Text
15162
15163 \layout Standard
15164
15165 Pointer sizes according to memory model
15166 \end_inset 
15167 </cell>
15168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15169 \begin_inset Text
15170
15171 \layout Standard
15172
15173 small model
15174 \end_inset 
15175 </cell>
15176 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15177 \begin_inset Text
15178
15179 \layout Standard
15180
15181 large model
15182 \end_inset 
15183 </cell>
15184 </row>
15185 <row topline="true" bottomline="true">
15186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15187 \begin_inset Text
15188
15189 \layout Standard
15190
15191 code pointers
15192 \end_inset 
15193 </cell>
15194 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15195 \begin_inset Text
15196
15197 \layout Standard
15198
15199 16-bits
15200 \end_inset 
15201 </cell>
15202 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15203 \begin_inset Text
15204
15205 \layout Standard
15206
15207 24-bits
15208 \end_inset 
15209 </cell>
15210 </row>
15211 <row topline="true" bottomline="true">
15212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15213 \begin_inset Text
15214
15215 \layout Standard
15216
15217 data pointers
15218 \end_inset 
15219 </cell>
15220 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
15221 \begin_inset Text
15222
15223 \layout Standard
15224
15225 16-bits
15226 \end_inset 
15227 </cell>
15228 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15229 \begin_inset Text
15230
15231 \layout Standard
15232
15233 16-bits
15234 \end_inset 
15235 </cell>
15236 </row>
15237 </lyxtabular>
15238
15239 \end_inset 
15240
15241
15242 \layout Standard
15243
15244 It is advisable that all sources within a project are compiled with the
15245  same memory model.
15246  If one wants to override the default memory model, this can be done by
15247  declaring a pointer as 
15248 \series bold 
15249 far
15250 \series default 
15251  or 
15252 \series bold 
15253 near
15254 \series default 
15255 .
15256  Far selects large memory model's pointers, while near selects small memory
15257  model's pointers.
15258 \layout Standard
15259
15260 The standard device libraries (see 4.5.6) contain no reference to pointers,
15261  so they can be used with both memory models.
15262 \layout Subsection
15263
15264 Stack
15265 \layout Standard
15266
15267 The stack implementation for the PIC16 port uses two indirect registers,
15268  FSR1 and FSR2.
15269 \layout List
15270 \labelwidthstring 00.00.0000
15271
15272 FSR1 is assigned as stack pointer
15273 \layout List
15274 \labelwidthstring 00.00.0000
15275
15276 FSR2 is assigned as frame pointer
15277 \layout Standard
15278
15279 The following stack models are supported by PIC16 port
15280 \layout Itemize
15281
15282 small model
15283 \layout Itemize
15284
15285 large model
15286 \layout Standard
15287
15288
15289 \noun on 
15290 Small
15291 \noun default 
15292  model means that only the FSRxL byte is used to access stack and frame,
15293  while 
15294 \emph on 
15295 \noun on 
15296 large
15297 \emph default 
15298 \noun default 
15299  uses both FSRxL and FSRxH registers.
15300  The following table shows the stack/frame pointers sizes according to stack
15301  model and the maximum space they can address:
15302 \layout Standard
15303 \align center 
15304
15305 \begin_inset  Tabular
15306 <lyxtabular version="3" rows="3" columns="3">
15307 <features>
15308 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15309 <column alignment="center" valignment="top" leftline="true" width="0">
15310 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15311 <row topline="true" bottomline="true">
15312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15313 \begin_inset Text
15314
15315 \layout Standard
15316
15317 Stack & Frame pointer sizes according to stack model
15318 \end_inset 
15319 </cell>
15320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15321 \begin_inset Text
15322
15323 \layout Standard
15324
15325 small
15326 \end_inset 
15327 </cell>
15328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15329 \begin_inset Text
15330
15331 \layout Standard
15332
15333 large
15334 \end_inset 
15335 </cell>
15336 </row>
15337 <row topline="true">
15338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15339 \begin_inset Text
15340
15341 \layout Standard
15342
15343 Stack pointer FSR1
15344 \end_inset 
15345 </cell>
15346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15347 \begin_inset Text
15348
15349 \layout Standard
15350
15351 8-bits
15352 \end_inset 
15353 </cell>
15354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15355 \begin_inset Text
15356
15357 \layout Standard
15358
15359 16-bits
15360 \end_inset 
15361 </cell>
15362 </row>
15363 <row topline="true" bottomline="true">
15364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15365 \begin_inset Text
15366
15367 \layout Standard
15368
15369 Frame pointer FSR2
15370 \end_inset 
15371 </cell>
15372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15373 \begin_inset Text
15374
15375 \layout Standard
15376
15377 8-bits
15378 \end_inset 
15379 </cell>
15380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15381 \begin_inset Text
15382
15383 \layout Standard
15384
15385 16-bits
15386 \end_inset 
15387 </cell>
15388 </row>
15389 </lyxtabular>
15390
15391 \end_inset 
15392
15393
15394 \layout Standard
15395
15396
15397 \series bold 
15398 Currently stack and frame pointers should be initialized explicit by the
15399  user at the desired Data RAM position (see 4.5.5 Pragma Stack).
15400  Uninitialized stack and frame pointers can result in unexpected behavior
15401  of the resulting binary.
15402 \layout Subsection
15403
15404 Function return values
15405 \layout Standard
15406
15407 Return values from functions are placed to the appropriate registers following
15408  a modified Microchip policy optimized for SDCC.
15409  The following table shows these registers:
15410 \layout Standard
15411 \align center 
15412
15413 \begin_inset  Tabular
15414 <lyxtabular version="3" rows="6" columns="2">
15415 <features>
15416 <column alignment="center" valignment="top" leftline="true" width="0">
15417 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15418 <row topline="true" bottomline="true">
15419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15420 \begin_inset Text
15421
15422 \layout Standard
15423
15424 size
15425 \end_inset 
15426 </cell>
15427 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15428 \begin_inset Text
15429
15430 \layout Standard
15431
15432 destination register
15433 \end_inset 
15434 </cell>
15435 </row>
15436 <row topline="true">
15437 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15438 \begin_inset Text
15439
15440 \layout Standard
15441
15442 8 bits
15443 \end_inset 
15444 </cell>
15445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15446 \begin_inset Text
15447
15448 \layout Standard
15449
15450 WREG
15451 \end_inset 
15452 </cell>
15453 </row>
15454 <row topline="true">
15455 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15456 \begin_inset Text
15457
15458 \layout Standard
15459
15460 16 bits
15461 \end_inset 
15462 </cell>
15463 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15464 \begin_inset Text
15465
15466 \layout Standard
15467
15468 PRODL:WREG
15469 \end_inset 
15470 </cell>
15471 </row>
15472 <row topline="true">
15473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15474 \begin_inset Text
15475
15476 \layout Standard
15477
15478 24 bits
15479 \end_inset 
15480 </cell>
15481 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15482 \begin_inset Text
15483
15484 \layout Standard
15485
15486 PRODH:PRODL:WREG
15487 \end_inset 
15488 </cell>
15489 </row>
15490 <row topline="true">
15491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15492 \begin_inset Text
15493
15494 \layout Standard
15495
15496 32 bits
15497 \end_inset 
15498 </cell>
15499 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15500 \begin_inset Text
15501
15502 \layout Standard
15503
15504 FSR0L:PRODH:PRODL:WREG
15505 \end_inset 
15506 </cell>
15507 </row>
15508 <row topline="true" bottomline="true">
15509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15510 \begin_inset Text
15511
15512 \layout Standard
15513
15514 >32 bits
15515 \end_inset 
15516 </cell>
15517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15518 \begin_inset Text
15519
15520 \layout Standard
15521
15522 on stack, FSR0 points to the beginning
15523 \end_inset 
15524 </cell>
15525 </row>
15526 </lyxtabular>
15527
15528 \end_inset 
15529
15530
15531 \layout Subsection
15532
15533 Interrupts
15534 \layout Standard
15535
15536 When entering an interrupt, currently the PIC16 port automatically saves
15537  the following registers:
15538 \layout Itemize
15539
15540 WREG
15541 \layout Itemize
15542
15543 STATUS
15544 \layout Itemize
15545
15546 BSR
15547 \layout Itemize
15548
15549 PROD (PRODL and PRODH)
15550 \layout Itemize
15551
15552 FSR0 (FSR0L and FSR0H)
15553 \layout Standard
15554
15555 These registers are restored upon return from the interrupt routine
15556 \begin_inset Foot
15557 collapsed false
15558
15559 \layout Standard
15560
15561 NOTE that when the _naked attribute is specified for an interrupt routine,
15562  then NO registers are stored or restored.
15563 \end_inset 
15564
15565 .
15566 \layout Chapter
15567
15568 Debugging with SDCDB
15569 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
15570
15571 \end_inset 
15572
15573
15574 \begin_inset LatexCommand \index{sdcdb (debugger)}
15575
15576 \end_inset 
15577
15578  
15579 \layout Standard
15580
15581 SDCC is distributed with a source level debugger
15582 \begin_inset LatexCommand \index{Debugger}
15583
15584 \end_inset 
15585
15586 .
15587  The debugger uses a command line interface, the command repertoire of the
15588  debugger has been kept as close to gdb
15589 \begin_inset LatexCommand \index{gdb}
15590
15591 \end_inset 
15592
15593  (the GNU debugger) as possible.
15594  The configuration and build process is part of the standard compiler installati
15595 on, which also builds and installs the debugger in the target directory
15596  specified during configuration.
15597  The debugger allows you debug BOTH at the C source and at the ASM source
15598  level.
15599  Sdcdb is available on Unix platforms only.
15600 \layout Section
15601
15602 Compiling for Debugging
15603 \layout Standard
15604
15605 The \SpecialChar \-
15606 \SpecialChar \-
15607 debug option must be specified for all files for which debug information
15608  is to be generated.
15609  The complier generates a .adb file for each of these files.
15610  The linker creates the .cdb
15611 \begin_inset LatexCommand \index{<file>.cdb}
15612
15613 \end_inset 
15614
15615  file from the .adb
15616 \begin_inset LatexCommand \index{<file>.adb}
15617
15618 \end_inset 
15619
15620  files and the address information.
15621  This .cdb is used by the debugger.
15622 \layout Section
15623
15624 How the Debugger Works
15625 \layout Standard
15626
15627 When the -
15628 \begin_inset ERT
15629 status Collapsed
15630
15631 \layout Standard
15632
15633 \backslash 
15634 /
15635 \end_inset 
15636
15637 -debug option is specified the compiler generates extra symbol information
15638  some of which are put into the assembler source and some are put into the
15639  .adb file.
15640   Then the linker creates the .cdb file from the individual .adb files with
15641  the address information for the symbols.
15642  The debugger reads the symbolic information generated by the compiler &
15643  the address information generated by the linker.
15644  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
15645  execution is controlled by the debugger.
15646  When a command is issued for the debugger, it translates it into appropriate
15647  commands for the simulator.
15648 \layout Section
15649
15650 Starting the Debugger
15651 \layout Standard
15652
15653 The debugger can be started using the following command line.
15654  (Assume the file you are debugging has the file name foo).
15655 \newline 
15656
15657 \newline 
15658
15659 \family sans 
15660 \series bold 
15661 sdcdb foo
15662 \newline 
15663
15664 \family default 
15665 \series default 
15666
15667 \newline 
15668 The debugger will look for the following files.
15669 \layout Itemize
15670
15671 foo.c - the source file.
15672 \layout Itemize
15673
15674 foo.cdb - the debugger symbol information file.
15675 \layout Itemize
15676
15677 foo.ihx - the Intel hex format
15678 \begin_inset LatexCommand \index{Intel hex format}
15679
15680 \end_inset 
15681
15682  object file.
15683 \layout Section
15684
15685 Command Line Options.
15686 \layout Itemize
15687
15688 -
15689 \begin_inset ERT
15690 status Collapsed
15691
15692 \layout Standard
15693
15694 \backslash 
15695 /
15696 \end_inset 
15697
15698 -directory=<source file directory> this option can used to specify the directory
15699  search list.
15700  The debugger will look into the directory list specified for source, cdb
15701  & ihx files.
15702  The items in the directory list must be separated by ':', e.g.
15703  if the source files can be in the directories /home/src1 and /home/src2,
15704  the -
15705 \begin_inset ERT
15706 status Collapsed
15707
15708 \layout Standard
15709
15710 \backslash 
15711 /
15712 \end_inset 
15713
15714 -directory option should be -
15715 \begin_inset ERT
15716 status Collapsed
15717
15718 \layout Standard
15719
15720 \backslash 
15721 /
15722 \end_inset 
15723
15724 -directory=/home/src1:/home/src2.
15725  Note there can be no spaces in the option.
15726  
15727 \layout Itemize
15728
15729 -cd <directory> - change to the <directory>.
15730 \layout Itemize
15731
15732 -fullname - used by GUI front ends.
15733 \layout Itemize
15734
15735 -cpu <cpu-type> - this argument is passed to the simulator please see the
15736  simulator docs for details.
15737 \layout Itemize
15738
15739 -X <Clock frequency > this options is passed to the simulator please see
15740  the simulator docs for details.
15741 \layout Itemize
15742
15743 -s <serial port file> passed to simulator see the simulator docs for details.
15744 \layout Itemize
15745
15746 -S <serial in,out> passed to simulator see the simulator docs for details.
15747 \layout Itemize
15748
15749 -k <port number> passed to simulator see the simulator docs for details.
15750 \layout Section
15751
15752 Debugger Commands.
15753 \layout Standard
15754
15755 As mentioned earlier the command interface for the debugger has been deliberatel
15756 y kept as close the GNU debugger gdb, as possible.
15757  This will help the integration with existing graphical user interfaces
15758  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
15759  If you use a graphical user interface for the debugger you can skip the
15760  next sections.
15761 \layout Subsubsection*
15762
15763 break [line | file:line | function | file:function]
15764 \layout Standard
15765
15766 Set breakpoint at specified line or function:
15767 \newline 
15768
15769 \newline 
15770
15771 \family sans 
15772 \series bold 
15773 sdcdb>break 100 
15774 \newline 
15775 sdcdb>break foo.c:100
15776 \newline 
15777 sdcdb>break funcfoo
15778 \newline 
15779 sdcdb>break foo.c:funcfoo
15780 \layout Subsubsection*
15781
15782 clear [line | file:line | function | file:function ]
15783 \layout Standard
15784
15785 Clear breakpoint at specified line or function:
15786 \newline 
15787
15788 \newline 
15789
15790 \family sans 
15791 \series bold 
15792 sdcdb>clear 100
15793 \newline 
15794 sdcdb>clear foo.c:100
15795 \newline 
15796 sdcdb>clear funcfoo
15797 \newline 
15798 sdcdb>clear foo.c:funcfoo
15799 \layout Subsubsection*
15800
15801 continue
15802 \layout Standard
15803
15804 Continue program being debugged, after breakpoint.
15805 \layout Subsubsection*
15806
15807 finish
15808 \layout Standard
15809
15810 Execute till the end of the current function.
15811 \layout Subsubsection*
15812
15813 delete [n]
15814 \layout Standard
15815
15816 Delete breakpoint number 'n'.
15817  If used without any option clear ALL user defined break points.
15818 \layout Subsubsection*
15819
15820 info [break | stack | frame | registers ]
15821 \layout Itemize
15822
15823 info break - list all breakpoints
15824 \layout Itemize
15825
15826 info stack - show the function call stack.
15827 \layout Itemize
15828
15829 info frame - show information about the current execution frame.
15830 \layout Itemize
15831
15832 info registers - show content of all registers.
15833 \layout Subsubsection*
15834
15835 step
15836 \layout Standard
15837
15838 Step program until it reaches a different source line.
15839  Note: pressing <return> repeats the last command.
15840 \layout Subsubsection*
15841
15842 next
15843 \layout Standard
15844
15845 Step program, proceeding through subroutine calls.
15846 \layout Subsubsection*
15847
15848 run
15849 \layout Standard
15850
15851 Start debugged program.
15852 \layout Subsubsection*
15853
15854 ptype variable 
15855 \layout Standard
15856
15857 Print type information of the variable.
15858 \layout Subsubsection*
15859
15860 print variable
15861 \layout Standard
15862
15863 print value of variable.
15864 \layout Subsubsection*
15865
15866 file filename
15867 \layout Standard
15868
15869 load the given file name.
15870  Note this is an alternate method of loading file for debugging.
15871 \layout Subsubsection*
15872
15873 frame
15874 \layout Standard
15875
15876 print information about current frame.
15877 \layout Subsubsection*
15878
15879 set srcmode
15880 \layout Standard
15881
15882 Toggle between C source & assembly source.
15883 \layout Subsubsection*
15884
15885 ! simulator command
15886 \layout Standard
15887
15888 Send the string following '!' to the simulator, the simulator response is
15889  displayed.
15890  Note the debugger does not interpret the command being sent to the simulator,
15891  so if a command like 'go' is sent the debugger can loose its execution
15892  context and may display incorrect values.
15893 \layout Subsubsection*
15894
15895 quit
15896 \layout Standard
15897
15898 "Watch me now.
15899  Iam going Down.
15900  My name is Bobby Brown"
15901 \layout Section
15902
15903 Interfacing with XEmacs
15904 \begin_inset LatexCommand \index{XEmacs}
15905
15906 \end_inset 
15907
15908
15909 \begin_inset LatexCommand \index{Emacs}
15910
15911 \end_inset 
15912
15913 .
15914 \layout Standard
15915
15916 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
15917  sdcdb.el and sdcdbsrc.el.
15918  These two files can be found in the $(prefix)/bin directory after the installat
15919 ion is complete.
15920  These files need to be loaded into XEmacs for the interface to work.
15921  This can be done at XEmacs startup time by inserting the following into
15922  your '.xemacs' file (which can be found in your HOME directory): 
15923 \newline 
15924
15925 \newline 
15926
15927 \family typewriter 
15928 (load-file sdcdbsrc.el) 
15929 \family default 
15930
15931 \newline 
15932
15933 \newline 
15934 .xemacs is a lisp file so the () around the command is REQUIRED.
15935  The files can also be loaded dynamically while XEmacs is running, set the
15936  environment variable 'EMACSLOADPATH' to the installation bin directory
15937  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
15938  To start the interface enter the following command: 
15939 \newline 
15940
15941 \newline 
15942
15943 \family sans 
15944 \series bold 
15945 ESC-x sdcdbsrc
15946 \family default 
15947 \series default 
15948
15949 \newline 
15950
15951 \newline 
15952 You will prompted to enter the file name to be debugged.
15953  
15954 \newline 
15955
15956 \newline 
15957 The command line options that are passed to the simulator directly are bound
15958  to default values in the file sdcdbsrc.el.
15959  The variables are listed below, these values maybe changed as required.
15960 \layout Itemize
15961
15962 sdcdbsrc-cpu-type '51
15963 \layout Itemize
15964
15965 sdcdbsrc-frequency '11059200
15966 \layout Itemize
15967
15968 sdcdbsrc-serial nil
15969 \layout Standard
15970
15971 The following is a list of key mapping for the debugger interface.
15972 \layout Standard
15973
15974 \SpecialChar ~
15975
15976 \family typewriter 
15977
15978 \newline 
15979 ;; Current Listing :: 
15980 \newline 
15981 ;;key\SpecialChar ~
15982 \SpecialChar ~
15983 \SpecialChar ~
15984 \SpecialChar ~
15985 \SpecialChar ~
15986 \SpecialChar ~
15987 \SpecialChar ~
15988 \SpecialChar ~
15989 \SpecialChar ~
15990 \SpecialChar ~
15991 \SpecialChar ~
15992 \SpecialChar ~
15993 \SpecialChar ~
15994 \SpecialChar ~
15995 \SpecialChar ~
15996 binding\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 \SpecialChar ~
16010 \SpecialChar ~
16011 \SpecialChar ~
16012 \SpecialChar ~
16013 \SpecialChar ~
16014 \SpecialChar ~
16015 \SpecialChar ~
16016 \SpecialChar ~
16017 \SpecialChar ~
16018 Comment 
16019 \newline 
16020 ;;---\SpecialChar ~
16021 \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 ------\SpecialChar ~
16036 \SpecialChar ~
16037 \SpecialChar ~
16038 \SpecialChar ~
16039 \SpecialChar ~
16040 \SpecialChar ~
16041 \SpecialChar ~
16042 \SpecialChar ~
16043 \SpecialChar ~
16044 \SpecialChar ~
16045 \SpecialChar ~
16046 \SpecialChar ~
16047 \SpecialChar ~
16048 \SpecialChar ~
16049 \SpecialChar ~
16050 \SpecialChar ~
16051 \SpecialChar ~
16052 \SpecialChar ~
16053 \SpecialChar ~
16054 \SpecialChar ~
16055 \SpecialChar ~
16056 \SpecialChar ~
16057 --------
16058 \newline 
16059 ;; 
16060 \newline 
16061 ;; n\SpecialChar ~
16062 \SpecialChar ~
16063 \SpecialChar ~
16064 \SpecialChar ~
16065 \SpecialChar ~
16066 \SpecialChar ~
16067 \SpecialChar ~
16068 \SpecialChar ~
16069 \SpecialChar ~
16070 \SpecialChar ~
16071 \SpecialChar ~
16072 \SpecialChar ~
16073 \SpecialChar ~
16074 \SpecialChar ~
16075  sdcdb-next-from-src\SpecialChar ~
16076 \SpecialChar ~
16077 \SpecialChar ~
16078 \SpecialChar ~
16079 \SpecialChar ~
16080 \SpecialChar ~
16081 \SpecialChar ~
16082 \SpecialChar ~
16083 \SpecialChar ~
16084 \SpecialChar ~
16085 SDCDB next command 
16086 \newline 
16087 ;; b\SpecialChar ~
16088 \SpecialChar ~
16089 \SpecialChar ~
16090 \SpecialChar ~
16091 \SpecialChar ~
16092 \SpecialChar ~
16093 \SpecialChar ~
16094 \SpecialChar ~
16095 \SpecialChar ~
16096 \SpecialChar ~
16097 \SpecialChar ~
16098 \SpecialChar ~
16099 \SpecialChar ~
16100 \SpecialChar ~
16101  sdcdb-back-from-src\SpecialChar ~
16102 \SpecialChar ~
16103 \SpecialChar ~
16104 \SpecialChar ~
16105 \SpecialChar ~
16106 \SpecialChar ~
16107 \SpecialChar ~
16108 \SpecialChar ~
16109 \SpecialChar ~
16110 \SpecialChar ~
16111 SDCDB back command 
16112 \newline 
16113 ;; c\SpecialChar ~
16114 \SpecialChar ~
16115 \SpecialChar ~
16116 \SpecialChar ~
16117 \SpecialChar ~
16118 \SpecialChar ~
16119 \SpecialChar ~
16120 \SpecialChar ~
16121 \SpecialChar ~
16122 \SpecialChar ~
16123 \SpecialChar ~
16124 \SpecialChar ~
16125 \SpecialChar ~
16126 \SpecialChar ~
16127  sdcdb-cont-from-src\SpecialChar ~
16128 \SpecialChar ~
16129 \SpecialChar ~
16130 \SpecialChar ~
16131 \SpecialChar ~
16132 \SpecialChar ~
16133 \SpecialChar ~
16134 \SpecialChar ~
16135 \SpecialChar ~
16136 \SpecialChar ~
16137 SDCDB continue command
16138 \newline 
16139 ;; s\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  sdcdb-step-from-src\SpecialChar ~
16154 \SpecialChar ~
16155 \SpecialChar ~
16156 \SpecialChar ~
16157 \SpecialChar ~
16158 \SpecialChar ~
16159 \SpecialChar ~
16160 \SpecialChar ~
16161 \SpecialChar ~
16162 \SpecialChar ~
16163 SDCDB step command 
16164 \newline 
16165 ;; ?\SpecialChar ~
16166 \SpecialChar ~
16167 \SpecialChar ~
16168 \SpecialChar ~
16169 \SpecialChar ~
16170 \SpecialChar ~
16171 \SpecialChar ~
16172 \SpecialChar ~
16173 \SpecialChar ~
16174 \SpecialChar ~
16175 \SpecialChar ~
16176 \SpecialChar ~
16177 \SpecialChar ~
16178 \SpecialChar ~
16179  sdcdb-whatis-c-sexp\SpecialChar ~
16180 \SpecialChar ~
16181 \SpecialChar ~
16182 \SpecialChar ~
16183 \SpecialChar ~
16184 \SpecialChar ~
16185 \SpecialChar ~
16186 \SpecialChar ~
16187 \SpecialChar ~
16188 \SpecialChar ~
16189 SDCDB ptypecommand for data at 
16190 \newline 
16191 ;;\SpecialChar ~
16192 \SpecialChar ~
16193 \SpecialChar ~
16194 \SpecialChar ~
16195 \SpecialChar ~
16196 \SpecialChar ~
16197 \SpecialChar ~
16198 \SpecialChar ~
16199 \SpecialChar ~
16200 \SpecialChar ~
16201 \SpecialChar ~
16202 \SpecialChar ~
16203 \SpecialChar ~
16204 \SpecialChar ~
16205 \SpecialChar ~
16206 \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  buffer point 
16238 \newline 
16239 ;; x\SpecialChar ~
16240 \SpecialChar ~
16241 \SpecialChar ~
16242 \SpecialChar ~
16243 \SpecialChar ~
16244 \SpecialChar ~
16245 \SpecialChar ~
16246 \SpecialChar ~
16247 \SpecialChar ~
16248 \SpecialChar ~
16249 \SpecialChar ~
16250 \SpecialChar ~
16251 \SpecialChar ~
16252 \SpecialChar ~
16253  sdcdbsrc-delete\SpecialChar ~
16254 \SpecialChar ~
16255 \SpecialChar ~
16256 \SpecialChar ~
16257 \SpecialChar ~
16258 \SpecialChar ~
16259 \SpecialChar ~
16260 \SpecialChar ~
16261 \SpecialChar ~
16262 \SpecialChar ~
16263 \SpecialChar ~
16264 \SpecialChar ~
16265 \SpecialChar ~
16266 \SpecialChar ~
16267 SDCDB Delete all breakpoints if no arg 
16268 \newline 
16269 ;;\SpecialChar ~
16270 \SpecialChar ~
16271 \SpecialChar ~
16272 \SpecialChar ~
16273 \SpecialChar ~
16274 \SpecialChar ~
16275 \SpecialChar ~
16276 \SpecialChar ~
16277 \SpecialChar ~
16278 \SpecialChar ~
16279 \SpecialChar ~
16280 \SpecialChar ~
16281 \SpecialChar ~
16282 \SpecialChar ~
16283 \SpecialChar ~
16284 \SpecialChar ~
16285 \SpecialChar ~
16286 \SpecialChar ~
16287 \SpecialChar ~
16288 \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 given or delete arg (C-u arg x) 
16316 \newline 
16317 ;; m\SpecialChar ~
16318 \SpecialChar ~
16319 \SpecialChar ~
16320 \SpecialChar ~
16321 \SpecialChar ~
16322 \SpecialChar ~
16323 \SpecialChar ~
16324 \SpecialChar ~
16325 \SpecialChar ~
16326 \SpecialChar ~
16327 \SpecialChar ~
16328 \SpecialChar ~
16329 \SpecialChar ~
16330 \SpecialChar ~
16331  sdcdbsrc-frame\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 SDCDB Display current frame if no arg, 
16347 \newline 
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 \SpecialChar ~
16379 \SpecialChar ~
16380 \SpecialChar ~
16381 \SpecialChar ~
16382 \SpecialChar ~
16383 \SpecialChar ~
16384 \SpecialChar ~
16385 \SpecialChar ~
16386 \SpecialChar ~
16387 \SpecialChar ~
16388 \SpecialChar ~
16389 \SpecialChar ~
16390 \SpecialChar ~
16391 \SpecialChar ~
16392 \SpecialChar ~
16393 \SpecialChar ~
16394 \SpecialChar ~
16395 given or display frame arg 
16396 \newline 
16397 ;;\SpecialChar ~
16398 \SpecialChar ~
16399 \SpecialChar ~
16400 \SpecialChar ~
16401 \SpecialChar ~
16402 \SpecialChar ~
16403 \SpecialChar ~
16404 \SpecialChar ~
16405 \SpecialChar ~
16406 \SpecialChar ~
16407 \SpecialChar ~
16408 \SpecialChar ~
16409 \SpecialChar ~
16410 \SpecialChar ~
16411 \SpecialChar ~
16412 \SpecialChar ~
16413 \SpecialChar ~
16414 \SpecialChar ~
16415 \SpecialChar ~
16416 \SpecialChar ~
16417 \SpecialChar ~
16418 \SpecialChar ~
16419 \SpecialChar ~
16420 \SpecialChar ~
16421 \SpecialChar ~
16422 \SpecialChar ~
16423 \SpecialChar ~
16424 \SpecialChar ~
16425 \SpecialChar ~
16426 \SpecialChar ~
16427 \SpecialChar ~
16428 \SpecialChar ~
16429 \SpecialChar ~
16430 \SpecialChar ~
16431 \SpecialChar ~
16432 \SpecialChar ~
16433 \SpecialChar ~
16434 \SpecialChar ~
16435 \SpecialChar ~
16436 \SpecialChar ~
16437 \SpecialChar ~
16438 \SpecialChar ~
16439 \SpecialChar ~
16440 \SpecialChar ~
16441 \SpecialChar ~
16442 \SpecialChar ~
16443 \SpecialChar ~
16444 buffer point 
16445 \newline 
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  sdcdbsrc-goto-sdcdb\SpecialChar ~
16461 \SpecialChar ~
16462 \SpecialChar ~
16463 \SpecialChar ~
16464 \SpecialChar ~
16465 \SpecialChar ~
16466 \SpecialChar ~
16467 \SpecialChar ~
16468 \SpecialChar ~
16469 \SpecialChar ~
16470 Goto the SDCDB output buffer 
16471 \newline 
16472 ;; p\SpecialChar ~
16473 \SpecialChar ~
16474 \SpecialChar ~
16475 \SpecialChar ~
16476 \SpecialChar ~
16477 \SpecialChar ~
16478 \SpecialChar ~
16479 \SpecialChar ~
16480 \SpecialChar ~
16481 \SpecialChar ~
16482 \SpecialChar ~
16483 \SpecialChar ~
16484 \SpecialChar ~
16485 \SpecialChar ~
16486  sdcdb-print-c-sexp\SpecialChar ~
16487 \SpecialChar ~
16488 \SpecialChar ~
16489 \SpecialChar ~
16490 \SpecialChar ~
16491 \SpecialChar ~
16492 \SpecialChar ~
16493 \SpecialChar ~
16494 \SpecialChar ~
16495 \SpecialChar ~
16496 \SpecialChar ~
16497 SDCDB print command for data at 
16498 \newline 
16499 ;;\SpecialChar ~
16500 \SpecialChar ~
16501 \SpecialChar ~
16502 \SpecialChar ~
16503 \SpecialChar ~
16504 \SpecialChar ~
16505 \SpecialChar ~
16506 \SpecialChar ~
16507 \SpecialChar ~
16508 \SpecialChar ~
16509 \SpecialChar ~
16510 \SpecialChar ~
16511 \SpecialChar ~
16512 \SpecialChar ~
16513 \SpecialChar ~
16514 \SpecialChar ~
16515 \SpecialChar ~
16516 \SpecialChar ~
16517 \SpecialChar ~
16518 \SpecialChar ~
16519 \SpecialChar ~
16520 \SpecialChar ~
16521 \SpecialChar ~
16522 \SpecialChar ~
16523 \SpecialChar ~
16524 \SpecialChar ~
16525 \SpecialChar ~
16526 \SpecialChar ~
16527 \SpecialChar ~
16528 \SpecialChar ~
16529 \SpecialChar ~
16530 \SpecialChar ~
16531 \SpecialChar ~
16532 \SpecialChar ~
16533 \SpecialChar ~
16534 \SpecialChar ~
16535 \SpecialChar ~
16536 \SpecialChar ~
16537 \SpecialChar ~
16538 \SpecialChar ~
16539 \SpecialChar ~
16540 \SpecialChar ~
16541 \SpecialChar ~
16542 \SpecialChar ~
16543 \SpecialChar ~
16544 \SpecialChar ~
16545  buffer point 
16546 \newline 
16547 ;; g\SpecialChar ~
16548 \SpecialChar ~
16549 \SpecialChar ~
16550 \SpecialChar ~
16551 \SpecialChar ~
16552 \SpecialChar ~
16553 \SpecialChar ~
16554 \SpecialChar ~
16555 \SpecialChar ~
16556 \SpecialChar ~
16557 \SpecialChar ~
16558 \SpecialChar ~
16559 \SpecialChar ~
16560 \SpecialChar ~
16561  sdcdbsrc-goto-sdcdb\SpecialChar ~
16562 \SpecialChar ~
16563 \SpecialChar ~
16564 \SpecialChar ~
16565 \SpecialChar ~
16566 \SpecialChar ~
16567 \SpecialChar ~
16568 \SpecialChar ~
16569 \SpecialChar ~
16570 \SpecialChar ~
16571 Goto the SDCDB output buffer 
16572 \newline 
16573 ;; t\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  sdcdbsrc-mode\SpecialChar ~
16588 \SpecialChar ~
16589 \SpecialChar ~
16590 \SpecialChar ~
16591 \SpecialChar ~
16592 \SpecialChar ~
16593 \SpecialChar ~
16594 \SpecialChar ~
16595 \SpecialChar ~
16596 \SpecialChar ~
16597 \SpecialChar ~
16598 \SpecialChar ~
16599 \SpecialChar ~
16600 \SpecialChar ~
16601 \SpecialChar ~
16602 \SpecialChar ~
16603 Toggles Sdcdbsrc mode (turns it off) 
16604 \newline 
16605 ;; 
16606 \newline 
16607 ;; C-c C-f\SpecialChar ~
16608 \SpecialChar ~
16609 \SpecialChar ~
16610 \SpecialChar ~
16611 \SpecialChar ~
16612 \SpecialChar ~
16613 \SpecialChar ~
16614 \SpecialChar ~
16615  sdcdb-finish-from-src\SpecialChar ~
16616 \SpecialChar ~
16617 \SpecialChar ~
16618 \SpecialChar ~
16619 \SpecialChar ~
16620 \SpecialChar ~
16621 \SpecialChar ~
16622 \SpecialChar ~
16623 SDCDB finish command 
16624 \newline 
16625 ;; 
16626 \newline 
16627 ;; C-x SPC\SpecialChar ~
16628 \SpecialChar ~
16629 \SpecialChar ~
16630 \SpecialChar ~
16631 \SpecialChar ~
16632 \SpecialChar ~
16633 \SpecialChar ~
16634 \SpecialChar ~
16635  sdcdb-break\SpecialChar ~
16636 \SpecialChar ~
16637 \SpecialChar ~
16638 \SpecialChar ~
16639 \SpecialChar ~
16640 \SpecialChar ~
16641 \SpecialChar ~
16642 \SpecialChar ~
16643 \SpecialChar ~
16644 \SpecialChar ~
16645 \SpecialChar ~
16646 \SpecialChar ~
16647 \SpecialChar ~
16648 \SpecialChar ~
16649 \SpecialChar ~
16650 \SpecialChar ~
16651 \SpecialChar ~
16652 \SpecialChar ~
16653 Set break for line with point 
16654 \newline 
16655 ;; ESC t\SpecialChar ~
16656 \SpecialChar ~
16657 \SpecialChar ~
16658 \SpecialChar ~
16659 \SpecialChar ~
16660 \SpecialChar ~
16661 \SpecialChar ~
16662 \SpecialChar ~
16663 \SpecialChar ~
16664 \SpecialChar ~
16665  sdcdbsrc-mode\SpecialChar ~
16666 \SpecialChar ~
16667 \SpecialChar ~
16668 \SpecialChar ~
16669 \SpecialChar ~
16670 \SpecialChar ~
16671 \SpecialChar ~
16672 \SpecialChar ~
16673 \SpecialChar ~
16674 \SpecialChar ~
16675 \SpecialChar ~
16676 \SpecialChar ~
16677 \SpecialChar ~
16678 \SpecialChar ~
16679 \SpecialChar ~
16680 \SpecialChar ~
16681 Toggle Sdcdbsrc mode 
16682 \newline 
16683 ;; ESC m\SpecialChar ~
16684 \SpecialChar ~
16685 \SpecialChar ~
16686 \SpecialChar ~
16687 \SpecialChar ~
16688 \SpecialChar ~
16689 \SpecialChar ~
16690 \SpecialChar ~
16691 \SpecialChar ~
16692 \SpecialChar ~
16693  sdcdbsrc-srcmode\SpecialChar ~
16694 \SpecialChar ~
16695 \SpecialChar ~
16696 \SpecialChar ~
16697 \SpecialChar ~
16698 \SpecialChar ~
16699 \SpecialChar ~
16700 \SpecialChar ~
16701 \SpecialChar ~
16702 \SpecialChar ~
16703 \SpecialChar ~
16704 \SpecialChar ~
16705  Toggle list mode 
16706 \newline 
16707 ;; 
16708 \newline 
16709
16710 \layout Chapter
16711 \pagebreak_top 
16712 TIPS
16713 \layout Standard
16714
16715 Here are a few guidelines that will help the compiler generate more efficient
16716  code, some of the tips are specific to this compiler others are generally
16717  good programming practice.
16718 \layout Itemize
16719
16720 Use the smallest data type to represent your data-value.
16721  If it is known in advance that the value is going to be less than 256 then
16722  use an 'unsigned char' instead of a 'short' or 'int'.
16723  Please note, that ANSI C requires both signed and unsigned chars to be
16724  promoted to 'signed int' before doing any operation.
16725  This promotion can be omitted, if the result is the same.
16726  The effect of the promotion rules together with the sign-extension is often
16727  supprising:
16728 \begin_deeper 
16729 \layout Verse
16730
16731
16732 \family typewriter 
16733 unsigned char uc = 0xfe;
16734 \newline 
16735 if (uc * uc < 0) /* this is true! */
16736 \newline 
16737 {
16738 \newline 
16739 \SpecialChar ~
16740 \SpecialChar ~
16741 \SpecialChar ~
16742 \SpecialChar ~
16743 ....
16744 \newline 
16745 }
16746 \layout Standard
16747
16748
16749 \family typewriter 
16750 uc * uc
16751 \family default 
16752  is evaluated as 
16753 \family typewriter 
16754 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
16755 \family default 
16756 .
16757  
16758 \newline 
16759 Another one:
16760 \layout Verse
16761
16762
16763 \family typewriter 
16764 (unsigned char) -12 / (signed char) -3 = ...
16765 \layout Standard
16766
16767 No, the result is not 4:
16768 \layout Verse
16769
16770
16771 \family typewriter 
16772 (int) (unsigned char) -12 / (int) (signed char) -3 =
16773 \newline 
16774 (int) (unsigned char) 0xf4 / (int) (signed char) 0xfd =
16775 \newline 
16776 (int) 0x00f4 / (int) 0xfffd =
16777 \newline 
16778 (int) 0x00f4 / (int) 0xfffd =
16779 \newline 
16780 (int) 244 / (int) -3 =
16781 \newline 
16782 (int) -81 = (int) 0xffaf;
16783 \layout Standard
16784
16785 Don't complain, that gcc gives you a different result.
16786  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
16787  Therefore the results are different.
16788 \newline 
16789 From 
16790 \begin_inset Quotes sld
16791 \end_inset 
16792
16793 comp.lang.c FAQ
16794 \begin_inset Quotes srd
16795 \end_inset 
16796
16797 :
16798 \layout Quote
16799
16800 If well-defined overflow characteristics are important and negative values
16801  are not, or if you want to steer clear of sign-extension problems when
16802  manipulating bits or bytes, use one of the corresponding unsigned types.
16803  (Beware when mixing signed and unsigned values in expressions, though.)
16804 \newline 
16805 Although character types (especially unsigned char) can be used as "tiny"
16806  integers, doing so is sometimes more trouble than it's worth, due to unpredicta
16807 ble sign extension and increased code size.
16808 \end_deeper 
16809 \layout Itemize
16810
16811 Use unsigned when it is known in advance that the value is not going to
16812  be negative.
16813  This helps especially if you are doing division or multiplication, bit-shifting
16814  or are using an array index.
16815 \layout Itemize
16816
16817 NEVER jump into a LOOP.
16818 \layout Itemize
16819
16820 Declare the variables to be local
16821 \begin_inset LatexCommand \index{local variables}
16822
16823 \end_inset 
16824
16825  whenever possible, especially loop control variables (induction).
16826 \layout Itemize
16827
16828 Since the compiler does not always do implicit integral promotion, the programme
16829 r should do an explicit cast when integral promotion is required.
16830 \layout Itemize
16831
16832 Reducing the size of division, multiplication & modulus operations can reduce
16833  code size substantially.
16834  Take the following code for example.
16835 \begin_deeper 
16836 \layout Verse
16837
16838
16839 \family typewriter 
16840 foobar(unsigned int p1, unsigned char ch)
16841 \newline 
16842 {
16843 \newline 
16844 \SpecialChar ~
16845 \SpecialChar ~
16846 \SpecialChar ~
16847 \SpecialChar ~
16848 unsigned char ch1 = p1 % ch ;
16849 \newline 
16850 \SpecialChar ~
16851 \SpecialChar ~
16852 \SpecialChar ~
16853 \SpecialChar ~
16854 ....
16855 \newline 
16856 }
16857 \layout Standard
16858
16859 For the modulus operation the variable ch will be promoted to unsigned int
16860  first then the modulus operation will be performed (this will lead to a
16861  call to support routine _moduint()), and the result will be casted to a
16862  char.
16863  If the code is changed to 
16864 \layout Verse
16865
16866
16867 \family typewriter 
16868 foobar(unsigned int p1, unsigned char ch)
16869 \newline 
16870 {
16871 \newline 
16872 \SpecialChar ~
16873 \SpecialChar ~
16874 \SpecialChar ~
16875 \SpecialChar ~
16876 unsigned char ch1 = (unsigned char)p1 % ch ;
16877 \newline 
16878 \SpecialChar ~
16879 \SpecialChar ~
16880 \SpecialChar ~
16881 \SpecialChar ~
16882 ....
16883 \newline 
16884 }
16885 \layout Standard
16886
16887 It would substantially reduce the code generated (future versions of the
16888  compiler will be smart enough to detect such optimization opportunities).
16889 \end_deeper 
16890 \layout Itemize
16891
16892 Have a look at the assembly listing to get a 
16893 \begin_inset Quotes sld
16894 \end_inset 
16895
16896 feeling
16897 \begin_inset Quotes srd
16898 \end_inset 
16899
16900  for the code generation.
16901 \layout Section
16902
16903 Tools
16904 \begin_inset LatexCommand \index{Tools}
16905
16906 \end_inset 
16907
16908  included in the distribution
16909 \layout Standard
16910 \align center 
16911
16912 \begin_inset  Tabular
16913 <lyxtabular version="3" rows="12" columns="3">
16914 <features>
16915 <column alignment="center" valignment="top" leftline="true" width="0pt">
16916 <column alignment="center" valignment="top" leftline="true" width="0pt">
16917 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
16918 <row topline="true" bottomline="true">
16919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16920 \begin_inset Text
16921
16922 \layout Standard
16923
16924 Name
16925 \end_inset 
16926 </cell>
16927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16928 \begin_inset Text
16929
16930 \layout Standard
16931
16932 Purpose
16933 \end_inset 
16934 </cell>
16935 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16936 \begin_inset Text
16937
16938 \layout Standard
16939
16940 Directory
16941 \end_inset 
16942 </cell>
16943 </row>
16944 <row topline="true">
16945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16946 \begin_inset Text
16947
16948 \layout Standard
16949
16950 uCsim
16951 \end_inset 
16952 </cell>
16953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16954 \begin_inset Text
16955
16956 \layout Standard
16957
16958 Simulator for various architectures
16959 \end_inset 
16960 </cell>
16961 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16962 \begin_inset Text
16963
16964 \layout Standard
16965
16966 sdcc/sim/ucsim
16967 \end_inset 
16968 </cell>
16969 </row>
16970 <row topline="true">
16971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16972 \begin_inset Text
16973
16974 \layout Standard
16975
16976 keil2sdcc.pl
16977 \end_inset 
16978 </cell>
16979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16980 \begin_inset Text
16981
16982 \layout Standard
16983
16984 header file conversion
16985 \end_inset 
16986 </cell>
16987 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16988 \begin_inset Text
16989
16990 \layout Standard
16991
16992 sdcc/support/scripts
16993 \end_inset 
16994 </cell>
16995 </row>
16996 <row topline="true">
16997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16998 \begin_inset Text
16999
17000 \layout Standard
17001
17002 mh2h.c
17003 \end_inset 
17004 </cell>
17005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17006 \begin_inset Text
17007
17008 \layout Standard
17009
17010 header file conversion
17011 \end_inset 
17012 </cell>
17013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17014 \begin_inset Text
17015
17016 \layout Standard
17017
17018 sdcc/support/scripts
17019 \end_inset 
17020 </cell>
17021 </row>
17022 <row topline="true">
17023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17024 \begin_inset Text
17025
17026 \layout Standard
17027
17028 as-gbz80
17029 \end_inset 
17030 </cell>
17031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17032 \begin_inset Text
17033
17034 \layout Standard
17035
17036 Assembler
17037 \end_inset 
17038 </cell>
17039 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17040 \begin_inset Text
17041
17042 \layout Standard
17043
17044
17045 \family roman 
17046 \series medium 
17047 \shape up 
17048 \size normal 
17049 \emph off 
17050 \bar no 
17051 \noun off 
17052 \color none
17053 sdcc/bin
17054 \end_inset 
17055 </cell>
17056 </row>
17057 <row topline="true">
17058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17059 \begin_inset Text
17060
17061 \layout Standard
17062
17063 as-z80
17064 \end_inset 
17065 </cell>
17066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17067 \begin_inset Text
17068
17069 \layout Standard
17070
17071 Assembler
17072 \end_inset 
17073 </cell>
17074 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17075 \begin_inset Text
17076
17077 \layout Standard
17078
17079
17080 \family roman 
17081 \series medium 
17082 \shape up 
17083 \size normal 
17084 \emph off 
17085 \bar no 
17086 \noun off 
17087 \color none
17088 sdcc/bin
17089 \end_inset 
17090 </cell>
17091 </row>
17092 <row topline="true">
17093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17094 \begin_inset Text
17095
17096 \layout Standard
17097
17098 asx8051
17099 \end_inset 
17100 </cell>
17101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17102 \begin_inset Text
17103
17104 \layout Standard
17105
17106 Assembler
17107 \end_inset 
17108 </cell>
17109 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17110 \begin_inset Text
17111
17112 \layout Standard
17113
17114
17115 \family roman 
17116 \series medium 
17117 \shape up 
17118 \size normal 
17119 \emph off 
17120 \bar no 
17121 \noun off 
17122 \color none
17123 sdcc/bin
17124 \end_inset 
17125 </cell>
17126 </row>
17127 <row topline="true">
17128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17129 \begin_inset Text
17130
17131 \layout Standard
17132
17133 sdcdb
17134 \end_inset 
17135 </cell>
17136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17137 \begin_inset Text
17138
17139 \layout Standard
17140
17141 Simulator
17142 \end_inset 
17143 </cell>
17144 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17145 \begin_inset Text
17146
17147 \layout Standard
17148
17149
17150 \family roman 
17151 \series medium 
17152 \shape up 
17153 \size normal 
17154 \emph off 
17155 \bar no 
17156 \noun off 
17157 \color none
17158 sdcc/bin
17159 \end_inset 
17160 </cell>
17161 </row>
17162 <row topline="true">
17163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17164 \begin_inset Text
17165
17166 \layout Standard
17167
17168 aslink
17169 \end_inset 
17170 </cell>
17171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17172 \begin_inset Text
17173
17174 \layout Standard
17175
17176 Linker
17177 \end_inset 
17178 </cell>
17179 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17180 \begin_inset Text
17181
17182 \layout Standard
17183
17184
17185 \family roman 
17186 \series medium 
17187 \shape up 
17188 \size normal 
17189 \emph off 
17190 \bar no 
17191 \noun off 
17192 \color none
17193 sdcc/bin
17194 \end_inset 
17195 </cell>
17196 </row>
17197 <row topline="true">
17198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17199 \begin_inset Text
17200
17201 \layout Standard
17202
17203 link-z80
17204 \end_inset 
17205 </cell>
17206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17207 \begin_inset Text
17208
17209 \layout Standard
17210
17211 Linker
17212 \end_inset 
17213 </cell>
17214 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17215 \begin_inset Text
17216
17217 \layout Standard
17218
17219
17220 \family roman 
17221 \series medium 
17222 \shape up 
17223 \size normal 
17224 \emph off 
17225 \bar no 
17226 \noun off 
17227 \color none
17228 sdcc/bin
17229 \end_inset 
17230 </cell>
17231 </row>
17232 <row topline="true">
17233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17234 \begin_inset Text
17235
17236 \layout Standard
17237
17238 link-gbz80
17239 \end_inset 
17240 </cell>
17241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17242 \begin_inset Text
17243
17244 \layout Standard
17245
17246 Linker
17247 \end_inset 
17248 </cell>
17249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17250 \begin_inset Text
17251
17252 \layout Standard
17253
17254
17255 \family roman 
17256 \series medium 
17257 \shape up 
17258 \size normal 
17259 \emph off 
17260 \bar no 
17261 \noun off 
17262 \color none
17263 sdcc/bin
17264 \end_inset 
17265 </cell>
17266 </row>
17267 <row topline="true" bottomline="true">
17268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17269 \begin_inset Text
17270
17271 \layout Standard
17272
17273 packihx
17274 \end_inset 
17275 </cell>
17276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17277 \begin_inset Text
17278
17279 \layout Standard
17280
17281 ihx packer
17282 \end_inset 
17283 </cell>
17284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17285 \begin_inset Text
17286
17287 \layout Standard
17288
17289
17290 \family roman 
17291 \series medium 
17292 \shape up 
17293 \size normal 
17294 \emph off 
17295 \bar no 
17296 \noun off 
17297 \color none
17298 sdcc/bin
17299 \end_inset 
17300 </cell>
17301 </row>
17302 </lyxtabular>
17303
17304 \end_inset 
17305
17306
17307 \newline 
17308
17309 \layout Section
17310
17311 Documentation
17312 \begin_inset LatexCommand \index{Documentation}
17313
17314 \end_inset 
17315
17316  included in the distribution
17317 \layout Standard
17318 \align center 
17319
17320 \begin_inset  Tabular
17321 <lyxtabular version="3" rows="10" columns="2">
17322 <features>
17323 <column alignment="left" valignment="top" leftline="true" width="0">
17324 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
17325 <row topline="true" bottomline="true">
17326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17327 \begin_inset Text
17328
17329 \layout Standard
17330
17331 Subject / Title
17332 \end_inset 
17333 </cell>
17334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17335 \begin_inset Text
17336
17337 \layout Standard
17338
17339 Where to get / filename
17340 \end_inset 
17341 </cell>
17342 </row>
17343 <row topline="true">
17344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17345 \begin_inset Text
17346
17347 \layout Standard
17348
17349 SDCC Compiler User Guide
17350 \end_inset 
17351 </cell>
17352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17353 \begin_inset Text
17354
17355 \layout Standard
17356
17357 You're reading it right now
17358 \end_inset 
17359 </cell>
17360 </row>
17361 <row topline="true">
17362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17363 \begin_inset Text
17364
17365 \layout Standard
17366
17367 Changelog of SDCC
17368 \end_inset 
17369 </cell>
17370 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17371 \begin_inset Text
17372
17373 \layout Standard
17374
17375 sdcc/Changelog
17376 \end_inset 
17377 </cell>
17378 </row>
17379 <row topline="true">
17380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17381 \begin_inset Text
17382
17383 \layout Standard
17384
17385 ASXXXX Assemblers and ASLINK Relocating Linker
17386 \end_inset 
17387 </cell>
17388 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17389 \begin_inset Text
17390
17391 \layout Standard
17392
17393 sdcc/as/doc/asxhtm.html
17394 \end_inset 
17395 </cell>
17396 </row>
17397 <row topline="true">
17398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17399 \begin_inset Text
17400
17401 \layout Standard
17402
17403 SDCC regression test
17404 \begin_inset LatexCommand \index{Regression test}
17405
17406 \end_inset 
17407
17408
17409 \end_inset 
17410 </cell>
17411 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17412 \begin_inset Text
17413
17414 \layout Standard
17415
17416 sdcc/doc/test_suite_spec.pdf
17417 \end_inset 
17418 </cell>
17419 </row>
17420 <row topline="true">
17421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17422 \begin_inset Text
17423
17424 \layout Standard
17425
17426 Various notes
17427 \end_inset 
17428 </cell>
17429 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17430 \begin_inset Text
17431
17432 \layout Standard
17433
17434 sdcc/doc/*
17435 \end_inset 
17436 </cell>
17437 </row>
17438 <row topline="true">
17439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17440 \begin_inset Text
17441
17442 \layout Standard
17443
17444 Notes on debugging with sdcdb
17445 \begin_inset LatexCommand \index{sdcdb (debugger)}
17446
17447 \end_inset 
17448
17449
17450 \end_inset 
17451 </cell>
17452 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17453 \begin_inset Text
17454
17455 \layout Standard
17456
17457 sdcc/debugger/README
17458 \end_inset 
17459 </cell>
17460 </row>
17461 <row topline="true">
17462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17463 \begin_inset Text
17464
17465 \layout Standard
17466
17467 Software simulator for microcontrollers
17468 \end_inset 
17469 </cell>
17470 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17471 \begin_inset Text
17472
17473 \layout Standard
17474
17475
17476 \family roman 
17477 \series medium 
17478 \shape up 
17479 \size normal 
17480 \emph off 
17481 \bar no 
17482 \noun off 
17483 \color none
17484 sdcc/sim/ucsim/doc
17485 \family default 
17486 \series default 
17487 \shape default 
17488 \size default 
17489 \emph default 
17490 \bar default 
17491 \noun default 
17492 \color default
17493 /index.html
17494 \end_inset 
17495 </cell>
17496 </row>
17497 <row topline="true">
17498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17499 \begin_inset Text
17500
17501 \layout Standard
17502
17503 Temporary notes on the pic16
17504 \begin_inset LatexCommand \index{PIC16}
17505
17506 \end_inset 
17507
17508  port
17509 \end_inset 
17510 </cell>
17511 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17512 \begin_inset Text
17513
17514 \layout Standard
17515
17516 sdcc/src/pic16/NOTES
17517 \end_inset 
17518 </cell>
17519 </row>
17520 <row topline="true" bottomline="true">
17521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17522 \begin_inset Text
17523
17524 \layout Standard
17525
17526 SDCC internal documentation (debugging file format)
17527 \end_inset 
17528 </cell>
17529 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17530 \begin_inset Text
17531
17532 \layout Standard
17533
17534 sdcc/doc/
17535 \family roman 
17536 \series medium 
17537 \shape up 
17538 \size normal 
17539 \emph off 
17540 \bar no 
17541 \noun off 
17542 \color none
17543 cdbfileformat.pd
17544 \family default 
17545 \series default 
17546 \shape default 
17547 \size default 
17548 \emph default 
17549 \bar default 
17550 \noun default 
17551 \color default
17552 f
17553 \end_inset 
17554 </cell>
17555 </row>
17556 </lyxtabular>
17557
17558 \end_inset 
17559
17560
17561 \newline 
17562
17563 \layout Section
17564
17565 Related open source tools
17566 \begin_inset LatexCommand \index{Related tools}
17567
17568 \end_inset 
17569
17570
17571 \layout Standard
17572 \align center 
17573
17574 \begin_inset  Tabular
17575 <lyxtabular version="3" rows="11" columns="3">
17576 <features>
17577 <column alignment="center" valignment="top" leftline="true" width="0pt">
17578 <column alignment="block" valignment="top" leftline="true" width="30line%">
17579 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
17580 <row topline="true" bottomline="true">
17581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17582 \begin_inset Text
17583
17584 \layout Standard
17585
17586 Name
17587 \end_inset 
17588 </cell>
17589 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17590 \begin_inset Text
17591
17592 \layout Standard
17593
17594 Purpose
17595 \end_inset 
17596 </cell>
17597 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17598 \begin_inset Text
17599
17600 \layout Standard
17601
17602 Where to get
17603 \end_inset 
17604 </cell>
17605 </row>
17606 <row topline="true">
17607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17608 \begin_inset Text
17609
17610 \layout Standard
17611
17612 gpsim
17613 \begin_inset LatexCommand \index{gpsim (pic simulator)}
17614
17615 \end_inset 
17616
17617
17618 \end_inset 
17619 </cell>
17620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17621 \begin_inset Text
17622
17623 \layout Standard
17624
17625 PIC simulator
17626 \end_inset 
17627 </cell>
17628 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17629 \begin_inset Text
17630
17631 \layout Standard
17632
17633
17634 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
17635
17636 \end_inset 
17637
17638
17639 \end_inset 
17640 </cell>
17641 </row>
17642 <row topline="true">
17643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17644 \begin_inset Text
17645
17646 \layout Standard
17647
17648 gputils
17649 \begin_inset LatexCommand \index{gputils (pic tools)}
17650
17651 \end_inset 
17652
17653
17654 \end_inset 
17655 </cell>
17656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17657 \begin_inset Text
17658
17659 \layout Standard
17660
17661 GNU PIC utilities
17662 \end_inset 
17663 </cell>
17664 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17665 \begin_inset Text
17666
17667 \layout Standard
17668
17669
17670 \begin_inset LatexCommand \url{http://gputils.sourceforge.net/}
17671
17672 \end_inset 
17673
17674
17675 \end_inset 
17676 </cell>
17677 </row>
17678 <row topline="true">
17679 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17680 \begin_inset Text
17681
17682 \layout Standard
17683
17684 flP5
17685 \end_inset 
17686 </cell>
17687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17688 \begin_inset Text
17689
17690 \layout Standard
17691
17692 PIC programmer
17693 \end_inset 
17694 </cell>
17695 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17696 \begin_inset Text
17697
17698 \layout Standard
17699
17700
17701 \begin_inset LatexCommand \url{http://digilander.libero.it/fbradasc/FLP5.html}
17702
17703 \end_inset 
17704
17705
17706 \end_inset 
17707 </cell>
17708 </row>
17709 <row topline="true">
17710 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17711 \begin_inset Text
17712
17713 \layout Standard
17714
17715 indent
17716 \begin_inset LatexCommand \index{indent (source formatting tool)}
17717
17718 \end_inset 
17719
17720
17721 \end_inset 
17722 </cell>
17723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17724 \begin_inset Text
17725
17726 \layout Standard
17727
17728 Formats C source - Master of the white spaces
17729 \end_inset 
17730 </cell>
17731 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17732 \begin_inset Text
17733
17734 \layout Standard
17735
17736
17737 \begin_inset LatexCommand \url{http://home.hccnet.nl/d.ingamells/beautify.html}
17738
17739 \end_inset 
17740
17741
17742 \end_inset 
17743 </cell>
17744 </row>
17745 <row topline="true">
17746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17747 \begin_inset Text
17748
17749 \layout Standard
17750
17751 srecord
17752 \begin_inset LatexCommand \index{srecord (tool)}
17753
17754 \end_inset 
17755
17756
17757 \end_inset 
17758 </cell>
17759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17760 \begin_inset Text
17761
17762 \layout Standard
17763
17764 Object file conversion, checksumming, ...
17765 \end_inset 
17766 </cell>
17767 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17768 \begin_inset Text
17769
17770 \layout Standard
17771
17772
17773 \begin_inset LatexCommand \url{http://srecord.sourceforge.net/}
17774
17775 \end_inset 
17776
17777
17778 \end_inset 
17779 </cell>
17780 </row>
17781 <row topline="true">
17782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17783 \begin_inset Text
17784
17785 \layout Standard
17786
17787 objdump
17788 \begin_inset LatexCommand \index{objdump (tool)}
17789
17790 \end_inset 
17791
17792
17793 \end_inset 
17794 </cell>
17795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17796 \begin_inset Text
17797
17798 \layout Standard
17799
17800 Object file conversion, ...
17801 \end_inset 
17802 </cell>
17803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17804 \begin_inset Text
17805
17806 \layout Standard
17807
17808 Part of binutils (should be there anyway)
17809 \end_inset 
17810 </cell>
17811 </row>
17812 <row topline="true">
17813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17814 \begin_inset Text
17815
17816 \layout Standard
17817
17818 doxygen
17819 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
17820
17821 \end_inset 
17822
17823
17824 \end_inset 
17825 </cell>
17826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17827 \begin_inset Text
17828
17829 \layout Standard
17830
17831 Source code documentation system
17832 \end_inset 
17833 </cell>
17834 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17835 \begin_inset Text
17836
17837 \layout Standard
17838
17839
17840 \begin_inset LatexCommand \url{http://www.doxygen.org}
17841
17842 \end_inset 
17843
17844
17845 \end_inset 
17846 </cell>
17847 </row>
17848 <row topline="true">
17849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17850 \begin_inset Text
17851
17852 \layout Standard
17853
17854 kdevelop
17855 \end_inset 
17856 </cell>
17857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17858 \begin_inset Text
17859
17860 \layout Standard
17861
17862 IDE (has anyone tried integrating SDCC & sdcdb? Unix only)
17863 \end_inset 
17864 </cell>
17865 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17866 \begin_inset Text
17867
17868 \layout Standard
17869
17870
17871 \begin_inset LatexCommand \url{http://www.kdevelop.org}
17872
17873 \end_inset 
17874
17875
17876 \end_inset 
17877 </cell>
17878 </row>
17879 <row topline="true">
17880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17881 \begin_inset Text
17882
17883 \layout Standard
17884
17885 splint
17886 \begin_inset LatexCommand \index{splint (syntax checking tool)}
17887
17888 \end_inset 
17889
17890
17891 \end_inset 
17892 </cell>
17893 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17894 \begin_inset Text
17895
17896 \layout Standard
17897
17898 Statically checks c sources
17899 \end_inset 
17900 </cell>
17901 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17902 \begin_inset Text
17903
17904 \layout Standard
17905
17906
17907 \begin_inset LatexCommand \url{http://www.splint.org}
17908
17909 \end_inset 
17910
17911
17912 \end_inset 
17913 </cell>
17914 </row>
17915 <row topline="true" bottomline="true">
17916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17917 \begin_inset Text
17918
17919 \layout Standard
17920
17921 ddd
17922 \begin_inset LatexCommand \index{ddd (debugger)}
17923
17924 \end_inset 
17925
17926
17927 \end_inset 
17928 </cell>
17929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17930 \begin_inset Text
17931
17932 \layout Standard
17933
17934 Debugger, serves nicely as GUI to sdcdb
17935 \begin_inset LatexCommand \index{sdcdb (debugger)}
17936
17937 \end_inset 
17938
17939  (Unix only)
17940 \end_inset 
17941 </cell>
17942 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17943 \begin_inset Text
17944
17945 \layout Standard
17946
17947
17948 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
17949
17950 \end_inset 
17951
17952
17953 \end_inset 
17954 </cell>
17955 </row>
17956 </lyxtabular>
17957
17958 \end_inset 
17959
17960
17961 \newline 
17962
17963 \layout Section
17964
17965 Related documentation / recommended reading
17966 \layout Standard
17967 \align center 
17968
17969 \begin_inset  Tabular
17970 <lyxtabular version="3" rows="6" columns="3">
17971 <features>
17972 <column alignment="center" valignment="top" leftline="true" width="0pt">
17973 <column alignment="block" valignment="top" leftline="true" width="30line%">
17974 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
17975 <row topline="true" bottomline="true">
17976 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17977 \begin_inset Text
17978
17979 \layout Standard
17980
17981 Name
17982 \end_inset 
17983 </cell>
17984 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17985 \begin_inset Text
17986
17987 \layout Standard
17988
17989 Subject / Title
17990 \end_inset 
17991 </cell>
17992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17993 \begin_inset Text
17994
17995 \layout Standard
17996
17997 Where to get
17998 \end_inset 
17999 </cell>
18000 </row>
18001 <row topline="true">
18002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18003 \begin_inset Text
18004
18005 \layout Standard
18006
18007
18008 \family roman 
18009 \series medium 
18010 \shape up 
18011 \size normal 
18012 \emph off 
18013 \bar no 
18014 \noun off 
18015 \color none
18016 c-refcard.pdf
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 C Reference Card
18025 \begin_inset LatexCommand \index{C Reference card}
18026
18027 \end_inset 
18028
18029 , 2 pages
18030 \end_inset 
18031 </cell>
18032 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18033 \begin_inset Text
18034
18035 \layout Standard
18036
18037
18038 \begin_inset LatexCommand \url{http://www.refcards.com/about/c.html}
18039
18040 \end_inset 
18041
18042
18043 \end_inset 
18044 </cell>
18045 </row>
18046 <row topline="true">
18047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18048 \begin_inset Text
18049
18050 \layout Standard
18051
18052 c-faq
18053 \end_inset 
18054 </cell>
18055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18056 \begin_inset Text
18057
18058 \layout Standard
18059
18060 C-FAQ-list
18061 \end_inset 
18062 </cell>
18063 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18064 \begin_inset Text
18065
18066 \layout Standard
18067
18068
18069 \begin_inset LatexCommand \url{http://www.eskimo.com/~scs/C-faq/top.html}
18070
18071 \end_inset 
18072
18073
18074 \end_inset 
18075 </cell>
18076 </row>
18077 <row topline="true">
18078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18079 \begin_inset Text
18080
18081 \layout Standard
18082
18083 \end_inset 
18084 </cell>
18085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18086 \begin_inset Text
18087
18088 \layout Standard
18089
18090 Latest datasheet of the target CPU
18091 \end_inset 
18092 </cell>
18093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18094 \begin_inset Text
18095
18096 \layout Standard
18097
18098 vendor
18099 \end_inset 
18100 </cell>
18101 </row>
18102 <row topline="true">
18103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18104 \begin_inset Text
18105
18106 \layout Standard
18107
18108 \end_inset 
18109 </cell>
18110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18111 \begin_inset Text
18112
18113 \layout Standard
18114
18115 Revision history of datasheet
18116 \end_inset 
18117 </cell>
18118 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18119 \begin_inset Text
18120
18121 \layout Standard
18122
18123 vendor
18124 \end_inset 
18125 </cell>
18126 </row>
18127 <row topline="true" bottomline="true">
18128 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18129 \begin_inset Text
18130
18131 \layout Standard
18132
18133 S.
18134  S.
18135  Muchnick
18136 \end_inset 
18137 </cell>
18138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18139 \begin_inset Text
18140
18141 \layout Standard
18142
18143 Advanced Compiler Design and Implementation
18144 \end_inset 
18145 </cell>
18146 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18147 \begin_inset Text
18148
18149 \layout Standard
18150
18151 bookstore (very dedicated, probably read other books first)
18152 \end_inset 
18153 </cell>
18154 </row>
18155 </lyxtabular>
18156
18157 \end_inset 
18158
18159
18160 \newline 
18161
18162 \layout Section
18163
18164 Some Questions
18165 \layout Standard
18166
18167 Some questions answered, some pointers given - it might be time to in turn
18168  ask 
18169 \emph on 
18170 you
18171 \emph default 
18172  some questions: 
18173 \layout Itemize
18174
18175 can you solve your project with the selected microcontroller? Would you
18176  find out early or rather late that your target is too small/slow/whatever?
18177  Can you switch to a slightly better device if it doesn't fit?
18178 \layout Itemize
18179
18180 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
18181  and/or another programming language be more adequate? Would an operating
18182  system on the target device help?
18183 \layout Itemize
18184
18185 if you solved the problem, will the marketing department be happy?
18186 \layout Itemize
18187
18188 if the marketing department is happy, will customers be happy?
18189 \layout Itemize
18190
18191 if you're the project manager, marketing department and maybe even the customer
18192  in one person, have you tried to see the project from the outside?
18193 \layout Itemize
18194
18195 is the project done if you think it is done? Or is just that other interface/pro
18196 tocol/feature/configuration/option missing? How about website, manual(s),
18197  internationali(z|s)ation, packaging, labels, 2nd source for components,
18198  electromagnetic compatability/interference, documentation for production,
18199  production test software, update mechanism, patent issues?
18200 \layout Itemize
18201
18202 is your project adequately positioned in that magic triangle: fame, fortune,
18203  fun?
18204 \layout Standard
18205
18206 Maybe not all answers to these questions are known and some answers may
18207  even be 
18208 \emph on 
18209 no
18210 \emph default 
18211 , nevertheless knowing these questions may help you to avoid burnout
18212 \begin_inset Foot
18213 collapsed false
18214
18215 \layout Standard
18216
18217 burnout is bad for electronic devices, programmers and motorcycle tyres
18218 \end_inset 
18219
18220 .
18221  Chances are you didn't want to hear some of them...
18222 \layout Chapter
18223
18224 Support
18225 \begin_inset LatexCommand \index{Support}
18226
18227 \end_inset 
18228
18229
18230 \layout Standard
18231
18232 SDCC has grown to be a large project.
18233  The compiler alone (without the preprocessor, assembler and linker) is
18234  well over 100,000 lines of code (blank stripped).
18235  The open source nature of this project is a key to its continued growth
18236  and support.
18237  You gain the benefit and support of many active software developers and
18238  end users.
18239  Is SDCC perfect? No, that's why we need your help.
18240  The developers take pride in fixing reported bugs.
18241  You can help by reporting the bugs and helping other SDCC users.
18242  There are lots of ways to contribute, and we encourage you to take part
18243  in making SDCC a great software package.
18244  
18245 \layout Standard
18246
18247 The SDCC project is hosted on the SDCC sourceforge site at 
18248 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
18249
18250 \end_inset 
18251
18252 .
18253  You'll find the complete set of mailing lists
18254 \begin_inset LatexCommand \index{Mailing list}
18255
18256 \end_inset 
18257
18258 , forums, bug reporting system, patch submission
18259 \begin_inset LatexCommand \index{Patch submission}
18260
18261 \end_inset 
18262
18263  system, download
18264 \begin_inset LatexCommand \index{download}
18265
18266 \end_inset 
18267
18268  area and cvs code repository
18269 \begin_inset LatexCommand \index{cvs code repository}
18270
18271 \end_inset 
18272
18273  there.
18274 \layout Section
18275
18276 Reporting Bugs
18277 \begin_inset LatexCommand \index{Bug reporting}
18278
18279 \end_inset 
18280
18281
18282 \begin_inset LatexCommand \index{Reporting bugs}
18283
18284 \end_inset 
18285
18286
18287 \layout Standard
18288
18289 The recommended way of reporting bugs is using the infrastructure of the
18290  sourceforge site.
18291  You can follow the status of bug reports there and have an overview about
18292  the known bugs.
18293 \layout Standard
18294
18295 Bug reports are automatically forwarded to the developer mailing list and
18296  will be fixed ASAP.
18297  When reporting a bug, it is very useful to include a small test program
18298  (the smaller the better) which reproduces the problem.
18299  If you can isolate the problem by looking at the generated assembly code,
18300  this can be very helpful.
18301  Compiling your program with the -
18302 \begin_inset ERT
18303 status Collapsed
18304
18305 \layout Standard
18306
18307 \backslash 
18308 /
18309 \end_inset 
18310
18311 -dumpall
18312 \begin_inset LatexCommand \index{-\/-dumpall}
18313
18314 \end_inset 
18315
18316  option can sometimes be useful in locating optimization problems.
18317  When reporting a bug please maker sure you:
18318 \layout Enumerate
18319
18320 Attach the code you are compiling with SDCC.
18321  
18322 \layout Enumerate
18323
18324 Specify the exact command you use to run SDCC, or attach your Makefile.
18325  
18326 \layout Enumerate
18327
18328 Specify the SDCC version (type "
18329 \family sans 
18330 \series bold 
18331 sdcc -v
18332 \family default 
18333 \series default 
18334 "), your platform, and operating system.
18335  
18336 \layout Enumerate
18337
18338 Provide an exact copy of any error message or incorrect output.
18339  
18340 \layout Enumerate
18341
18342 Put something meaningful in the subject of your message.
18343 \layout Standard
18344
18345 Please attempt to include these 5 important parts, as applicable, in all
18346  requests for support or when reporting any problems or bugs with SDCC.
18347  Though this will make your message lengthy, it will greatly improve your
18348  chance that SDCC users and developers will be able to help you.
18349  Some SDCC developers are frustrated by bug reports without code provided
18350  that they can use to reproduce and ultimately fix the problem, so please
18351  be sure to provide sample code if you are reporting a bug! 
18352 \layout Standard
18353
18354 Please have a short check that you are using a recent version of SDCC and
18355  the bug is not yet known.
18356  This is the link for reporting bugs: 
18357 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
18358
18359 \end_inset 
18360
18361 .
18362 \layout Section
18363
18364 Requesting Features
18365 \begin_inset LatexCommand \label{sub:Requesting-Features}
18366
18367 \end_inset 
18368
18369
18370 \begin_inset LatexCommand \index{Feature request}
18371
18372 \end_inset 
18373
18374
18375 \begin_inset LatexCommand \index{Requesting features}
18376
18377 \end_inset 
18378
18379
18380 \layout Standard
18381
18382 Like bug reports feature requests are forwarded to the developer mailing
18383  list.
18384  This is the link for requesting features: 
18385 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
18386
18387 \end_inset 
18388
18389 .
18390 \layout Section
18391
18392 Submitting patches
18393 \layout Standard
18394
18395 Like bug reports contributed patches are forwarded to the developer mailing
18396  list.
18397  This is the link for submitting patches
18398 \begin_inset LatexCommand \index{Patch submission}
18399
18400 \end_inset 
18401
18402
18403 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
18404
18405 \end_inset 
18406
18407 .
18408 \layout Standard
18409
18410 You need to specify some parameters to the 
18411 \family typewriter 
18412 diff
18413 \family default 
18414  command for the patches to be useful.
18415  If you modified more than one file a patch created f.e.
18416  with 
18417 \family sans 
18418 \series bold 
18419
18420 \begin_inset Quotes sld
18421 \end_inset 
18422
18423 diff -Naur unmodified_directory modified_directory >my_changes.patch
18424 \begin_inset Quotes srd
18425 \end_inset 
18426
18427
18428 \family default 
18429 \series default 
18430  will be fine, otherwise 
18431 \family sans 
18432 \series bold 
18433
18434 \begin_inset Quotes sld
18435 \end_inset 
18436
18437 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
18438 \begin_inset Quotes srd
18439 \end_inset 
18440
18441
18442 \series default 
18443  
18444 \family default 
18445 will do.
18446 \layout Section
18447
18448 Getting Help
18449 \layout Standard
18450
18451 These links should take you directly to the 
18452 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
18453
18454 \end_inset 
18455
18456
18457 \begin_inset Foot
18458 collapsed false
18459
18460 \layout Standard
18461
18462 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
18463  automated messages (mid 2003)
18464 \end_inset 
18465
18466  and the 
18467 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
18468
18469 \end_inset 
18470
18471 , lists and forums are archived and searchable so if you are lucky someone
18472  already had a similar problem.
18473 \layout Section
18474
18475 ChangeLog
18476 \layout Standard
18477
18478 You can follow the status of the cvs version
18479 \begin_inset LatexCommand \index{version}
18480
18481 \end_inset 
18482
18483  of SDCC by watching the Changelog
18484 \begin_inset LatexCommand \index{Changelog}
18485
18486 \end_inset 
18487
18488  in the cvs-repository
18489 \newline 
18490
18491 \size footnotesize 
18492
18493 \begin_inset LatexCommand \htmlurl{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/sdcc/sdcc/ChangeLog?rev=HEAD&content-type=text/plain}
18494
18495 \end_inset 
18496
18497 .
18498 \layout Section
18499
18500 Release policy
18501 \begin_inset LatexCommand \index{Release policy}
18502
18503 \end_inset 
18504
18505
18506 \layout Standard
18507
18508 Historically there often were long delays between official releases and
18509  the sourceforge download area tends to get not updated at all.
18510  Excuses in the past might have referred to problems with live range analysis,
18511  but as this was fixed a while ago, the current problem is that another
18512  excuse has to be found.
18513  Kidding aside, we have to get better there! On the other hand there are
18514  daily snapshots available at 
18515 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
18516
18517 \end_inset 
18518
18519 , and you can always build the very last version (hopefully with many bugs
18520  fixed, and features added) from the source code available at 
18521 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
18522
18523 \end_inset 
18524
18525 .
18526 \layout Section
18527
18528 Examples
18529 \begin_inset LatexCommand \index{Examples}
18530
18531 \end_inset 
18532
18533
18534 \layout Standard
18535
18536 You'll find some small examples in the directory 
18537 \emph on 
18538 sdcc/device/examples/.
18539  
18540 \emph default 
18541 More examples and libraries are available at
18542 \emph on 
18543  The SDCC Open Knowledge Resource 
18544 \begin_inset LatexCommand \url{http://www.qsl.net/dl9sec/SDCC_OKR.html}
18545
18546 \end_inset 
18547
18548  
18549 \emph default 
18550 web site or at 
18551 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
18552
18553 \end_inset 
18554
18555 .
18556 \layout Comment
18557
18558 I did insert a reference to Paul's web site here although it seems rather
18559  dedicated to a specific 8032 board (I think it's okay because it f.e.
18560  shows LCD/Harddisc interface and has a free 8051 monitor.
18561  Independent 8032 board vendors face hard competition of heavily subsidized
18562  development boards anyway).
18563 \layout Comment
18564
18565 Maybe we should include some links to real world applications.
18566  Preferably pointer to pointers (one for each architecture) so this stays
18567  manageable here?
18568 \layout Section
18569
18570 Quality control
18571 \begin_inset LatexCommand \index{Quality control}
18572
18573 \end_inset 
18574
18575
18576 \layout Standard
18577
18578 The compiler is passed through nightly compile and build checks.
18579  The so called 
18580 \shape italic 
18581 regression tests
18582 \shape default 
18583
18584 \begin_inset LatexCommand \index{Regression test}
18585
18586 \end_inset 
18587
18588  check that SDCC itself compiles flawlessly on several platforms and checks
18589  the quality of the code generated by SDCC by running the code through simulator
18590 s.
18591  There is a separate document 
18592 \shape italic 
18593 test_suite.pdf
18594 \begin_inset LatexCommand \index{Test suite}
18595
18596 \end_inset 
18597
18598
18599 \shape default 
18600  about this.
18601 \layout Standard
18602
18603 You'll find the test code in the directory 
18604 \shape italic 
18605 sdcc/support/regression
18606 \shape default 
18607 .
18608  You can run these tests manually by running 
18609 \family sans 
18610 make
18611 \family default 
18612  in this directory (or f.e.
18613  
18614 \family sans 
18615 \series bold 
18616
18617 \begin_inset Quotes sld
18618 \end_inset 
18619
18620 make test-mcs51
18621 \begin_inset Quotes srd
18622 \end_inset 
18623
18624
18625 \family default 
18626 \series default 
18627  if you don't want to run the complete tests).
18628  The test code might also be interesting if you want to look for examples
18629 \begin_inset LatexCommand \index{Examples}
18630
18631 \end_inset 
18632
18633  checking corner cases of SDCC or if you plan to submit patches
18634 \begin_inset LatexCommand \index{Patch submission}
18635
18636 \end_inset 
18637
18638 .
18639 \layout Standard
18640
18641 The pic port uses a different set of regression tests, you'll find them
18642  in the directory 
18643 \shape italic 
18644 sdcc/src/regression
18645 \shape default 
18646 .
18647 \layout Chapter
18648 \pagebreak_top 
18649 SDCC Technical Data
18650 \layout Section
18651
18652 Optimizations
18653 \begin_inset LatexCommand \index{Optimizations}
18654
18655 \end_inset 
18656
18657
18658 \layout Standard
18659
18660 SDCC performs a host of standard optimizations in addition to some MCU specific
18661  optimizations.
18662  
18663 \layout Subsection
18664
18665 Sub-expression Elimination
18666 \begin_inset LatexCommand \index{Subexpression elimination}
18667
18668 \end_inset 
18669
18670
18671 \layout Standard
18672
18673 The compiler does local and 
18674 \emph on 
18675 g
18676 \emph default 
18677 lobal 
18678 \emph on 
18679 c
18680 \emph default 
18681 ommon 
18682 \emph on 
18683 s
18684 \emph default 
18685 ubexpression 
18686 \emph on 
18687 e
18688 \emph default 
18689 limination, e.g.: 
18690 \layout Verse
18691
18692
18693 \family typewriter 
18694 i = x + y + 1; 
18695 \newline 
18696 j = x + y;
18697 \layout Standard
18698
18699 will be translated to
18700 \layout Verse
18701
18702
18703 \family typewriter 
18704 iTemp = x + y; 
18705 \newline 
18706 i = iTemp + 1; 
18707 \newline 
18708 j = iTemp;
18709 \layout Standard
18710
18711 Some subexpressions are not as obvious as the above example, e.g.:
18712 \layout Verse
18713
18714
18715 \family typewriter 
18716 a->b[i].c = 10; 
18717 \newline 
18718 a->b[i].d = 11;
18719 \layout Standard
18720
18721 In this case the address arithmetic a->b[i] will be computed only once;
18722  the equivalent code in C would be.
18723 \layout Verse
18724
18725
18726 \family typewriter 
18727 iTemp = a->b[i]; 
18728 \newline 
18729 iTemp.c = 10; 
18730 \newline 
18731 iTemp.d = 11;
18732 \layout Standard
18733
18734 The compiler will try to keep these temporary variables in registers.
18735 \layout Subsection
18736
18737 Dead-Code Elimination
18738 \begin_inset LatexCommand \index{Dead-code elimination}
18739
18740 \end_inset 
18741
18742
18743 \layout Verse
18744
18745
18746 \family typewriter 
18747 int global;
18748 \newline 
18749
18750 \newline 
18751 void f () { 
18752 \newline 
18753 \SpecialChar ~
18754 \SpecialChar ~
18755 int i; 
18756 \newline 
18757 \SpecialChar ~
18758 \SpecialChar ~
18759 i = 1; \SpecialChar ~
18760 \SpecialChar ~
18761 \SpecialChar ~
18762 \SpecialChar ~
18763 \SpecialChar ~
18764 /* dead store */ 
18765 \newline 
18766 \SpecialChar ~
18767 \SpecialChar ~
18768 global = 1;\SpecialChar ~
18769 /* dead store */ 
18770 \newline 
18771 \SpecialChar ~
18772 \SpecialChar ~
18773 global = 2; 
18774 \newline 
18775 \SpecialChar ~
18776 \SpecialChar ~
18777 return; 
18778 \newline 
18779 \SpecialChar ~
18780 \SpecialChar ~
18781 global = 3;\SpecialChar ~
18782 /* unreachable */ 
18783 \newline 
18784 }
18785 \layout Standard
18786
18787 will be changed to
18788 \layout Verse
18789
18790
18791 \family typewriter 
18792 int global;
18793 \newline 
18794
18795 \newline 
18796 void f () {
18797 \newline 
18798 \SpecialChar ~
18799 \SpecialChar ~
18800 global = 2; 
18801 \newline 
18802 \SpecialChar ~
18803 \SpecialChar ~
18804 return; 
18805 \newline 
18806 }
18807 \layout Subsection
18808
18809 Copy-Propagation
18810 \begin_inset LatexCommand \index{Copy propagation}
18811
18812 \end_inset 
18813
18814
18815 \layout Verse
18816
18817
18818 \family typewriter 
18819 int f() { 
18820 \newline 
18821 \SpecialChar ~
18822 \SpecialChar ~
18823 int i, j; 
18824 \newline 
18825 \SpecialChar ~
18826 \SpecialChar ~
18827 i = 10; 
18828 \newline 
18829 \SpecialChar ~
18830 \SpecialChar ~
18831 j = i; 
18832 \newline 
18833 \SpecialChar ~
18834 \SpecialChar ~
18835 return j; 
18836 \newline 
18837 }
18838 \layout Standard
18839
18840 will be changed to 
18841 \layout Verse
18842
18843
18844 \family typewriter 
18845 int f() { 
18846 \newline 
18847 \SpecialChar ~
18848 \SpecialChar ~
18849 int i, j; 
18850 \newline 
18851 \SpecialChar ~
18852 \SpecialChar ~
18853 i = 10; 
18854 \newline 
18855 \SpecialChar ~
18856 \SpecialChar ~
18857 j = 10; 
18858 \newline 
18859 \SpecialChar ~
18860 \SpecialChar ~
18861 return 10; 
18862 \newline 
18863 }
18864 \layout Standard
18865
18866 Note: the dead stores created by this copy propagation will be eliminated
18867  by dead-code elimination.
18868 \layout Subsection
18869
18870 Loop Optimizations
18871 \begin_inset LatexCommand \index{Loop optimization}
18872
18873 \end_inset 
18874
18875
18876 \layout Standard
18877
18878 Two types of loop optimizations are done by SDCC loop invariant lifting
18879  and strength reduction of loop induction variables.
18880  In addition to the strength reduction the optimizer marks the induction
18881  variables and the register allocator tries to keep the induction variables
18882  in registers for the duration of the loop.
18883  Because of this preference of the register allocator
18884 \begin_inset LatexCommand \index{Register allocation}
18885
18886 \end_inset 
18887
18888 , loop induction optimization causes an increase in register pressure, which
18889  may cause unwanted spilling of other temporary variables into the stack
18890 \begin_inset LatexCommand \index{stack}
18891
18892 \end_inset 
18893
18894  / data space.
18895  The compiler will generate a warning message when it is forced to allocate
18896  extra space either on the stack or data space.
18897  If this extra space allocation is undesirable then induction optimization
18898  can be eliminated either for the entire source file (with -
18899 \begin_inset ERT
18900 status Collapsed
18901
18902 \layout Standard
18903
18904 \backslash 
18905 /
18906 \end_inset 
18907
18908 -noinduction option) or for a given function only using #pragma\SpecialChar ~
18909 noinduction
18910 \begin_inset LatexCommand \index{\#pragma noinduction}
18911
18912 \end_inset 
18913
18914 .
18915 \newline 
18916
18917 \newline 
18918 Loop Invariant:
18919 \layout Verse
18920
18921
18922 \family typewriter 
18923 for (i = 0 ; i < 100 ; i ++) 
18924 \newline 
18925 \SpecialChar ~
18926 \SpecialChar ~
18927 \SpecialChar ~
18928 \SpecialChar ~
18929 f += k + l;
18930 \layout Standard
18931
18932 changed to
18933 \layout Verse
18934
18935
18936 \family typewriter 
18937 itemp = k + l; 
18938 \newline 
18939 for (i = 0; i < 100; i++) 
18940 \newline 
18941 \SpecialChar ~
18942 \SpecialChar ~
18943 \SpecialChar ~
18944 \SpecialChar ~
18945 f += itemp;
18946 \layout Standard
18947
18948 As mentioned previously some loop invariants are not as apparent, all static
18949  address computations are also moved out of the loop.
18950 \newline 
18951
18952 \newline 
18953 Strength Reduction
18954 \begin_inset LatexCommand \index{Strength reduction}
18955
18956 \end_inset 
18957
18958 , this optimization substitutes an expression by a cheaper expression:
18959 \layout Verse
18960
18961
18962 \family typewriter 
18963 for (i=0;i < 100; i++)
18964 \newline 
18965 \SpecialChar ~
18966 \SpecialChar ~
18967 \SpecialChar ~
18968 \SpecialChar ~
18969 ar[i*5] = i*3;
18970 \layout Standard
18971
18972 changed to
18973 \layout Verse
18974
18975
18976 \family typewriter 
18977 itemp1 = 0; 
18978 \newline 
18979 itemp2 = 0; 
18980 \newline 
18981 for (i=0;i< 100;i++) { 
18982 \newline 
18983 \SpecialChar ~
18984 \SpecialChar ~
18985 \SpecialChar ~
18986 \SpecialChar ~
18987 ar[itemp1] = itemp2; 
18988 \newline 
18989 \SpecialChar ~
18990 \SpecialChar ~
18991 \SpecialChar ~
18992 \SpecialChar ~
18993 itemp1 += 5; 
18994 \newline 
18995 \SpecialChar ~
18996 \SpecialChar ~
18997 \SpecialChar ~
18998 \SpecialChar ~
18999 itemp2 += 3; 
19000 \newline 
19001 }
19002 \layout Standard
19003
19004 The more expensive multiplication
19005 \begin_inset LatexCommand \index{Multiplication}
19006
19007 \end_inset 
19008
19009  is changed to a less expensive addition.
19010 \layout Subsection
19011
19012 Loop Reversing
19013 \begin_inset LatexCommand \index{Loop reversing}
19014
19015 \end_inset 
19016
19017
19018 \layout Standard
19019
19020 This optimization is done to reduce the overhead of checking loop boundaries
19021  for every iteration.
19022  Some simple loops can be reversed and implemented using a 
19023 \begin_inset Quotes eld
19024 \end_inset 
19025
19026 decrement and jump if not zero
19027 \begin_inset Quotes erd
19028 \end_inset 
19029
19030  instruction.
19031  SDCC checks for the following criterion to determine if a loop is reversible
19032  (note: more sophisticated compilers use data-dependency analysis to make
19033  this determination, SDCC uses a more simple minded analysis).
19034 \layout Itemize
19035
19036 The 'for' loop is of the form 
19037 \newline 
19038
19039 \newline 
19040
19041 \family typewriter 
19042 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
19043  += 1])
19044 \newline 
19045 \SpecialChar ~
19046 \SpecialChar ~
19047 \SpecialChar ~
19048 \SpecialChar ~
19049 <for body>
19050 \layout Itemize
19051
19052 The <for body> does not contain 
19053 \begin_inset Quotes eld
19054 \end_inset 
19055
19056 continue
19057 \begin_inset Quotes erd
19058 \end_inset 
19059
19060  or 'break
19061 \begin_inset Quotes erd
19062 \end_inset 
19063
19064 .
19065 \layout Itemize
19066
19067 All goto's are contained within the loop.
19068 \layout Itemize
19069
19070 No function calls within the loop.
19071 \layout Itemize
19072
19073 The loop control variable <sym> is not assigned any value within the loop
19074 \layout Itemize
19075
19076 The loop control variable does NOT participate in any arithmetic operation
19077  within the loop.
19078 \layout Itemize
19079
19080 There are NO switch statements in the loop.
19081 \layout Subsection
19082
19083 Algebraic Simplifications
19084 \layout Standard
19085
19086 SDCC does numerous algebraic simplifications, the following is a small sub-set
19087  of these optimizations.
19088 \layout Verse
19089
19090
19091 \family typewriter 
19092 i = j + 0;\SpecialChar ~
19093 \SpecialChar ~
19094 \SpecialChar ~
19095 \SpecialChar ~
19096  /* changed to: */\SpecialChar ~
19097 \SpecialChar ~
19098 \SpecialChar ~
19099 \SpecialChar ~
19100  i = j; 
19101 \newline 
19102 i /= 2;\SpecialChar ~
19103 \SpecialChar ~
19104 \SpecialChar ~
19105 \SpecialChar ~
19106 \SpecialChar ~
19107 \SpecialChar ~
19108 \SpecialChar ~
19109  /* changed to: */\SpecialChar ~
19110 \SpecialChar ~
19111 \SpecialChar ~
19112 \SpecialChar ~
19113  i >>= 1; 
19114 \newline 
19115 i = j - j;\SpecialChar ~
19116 \SpecialChar ~
19117 \SpecialChar ~
19118 \SpecialChar ~
19119  /* changed to: */\SpecialChar ~
19120 \SpecialChar ~
19121 \SpecialChar ~
19122 \SpecialChar ~
19123  i = 0; 
19124 \newline 
19125 i = j / 1;\SpecialChar ~
19126 \SpecialChar ~
19127 \SpecialChar ~
19128 \SpecialChar ~
19129  /* changed to: */\SpecialChar ~
19130 \SpecialChar ~
19131 \SpecialChar ~
19132 \SpecialChar ~
19133  i = j;
19134 \layout Standard
19135
19136 Note the subexpressions
19137 \begin_inset LatexCommand \index{Subexpression}
19138
19139 \end_inset 
19140
19141  given above are generally introduced by macro expansions or as a result
19142  of copy/constant propagation.
19143 \layout Subsection
19144
19145 'switch' Statements
19146 \begin_inset LatexCommand \label{sub:'switch'-Statements}
19147
19148 \end_inset 
19149
19150
19151 \begin_inset LatexCommand \index{switch statement}
19152
19153 \end_inset 
19154
19155
19156 \layout Standard
19157
19158 SDCC changes switch statements to jump tables
19159 \begin_inset LatexCommand \index{jump tables}
19160
19161 \end_inset 
19162
19163  when the following conditions are true.
19164  
19165 \layout Itemize
19166
19167 The case labels are in numerical sequence, the labels need not be in order,
19168  and the starting number need not be one or zero.
19169 \begin_deeper 
19170 \layout Verse
19171
19172
19173 \family typewriter 
19174 switch(i) {\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 \SpecialChar ~
19198 \SpecialChar ~
19199 \SpecialChar ~
19200 switch (i) { 
19201 \newline 
19202 \SpecialChar ~
19203 \SpecialChar ~
19204 \SpecialChar ~
19205 case 4: ...\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 \SpecialChar ~
19230 \SpecialChar ~
19231 case 0: ...
19232  
19233 \newline 
19234 \SpecialChar ~
19235 \SpecialChar ~
19236 \SpecialChar ~
19237 case 5: ...\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 \SpecialChar ~
19262 \SpecialChar ~
19263 case 1: ...
19264  
19265 \newline 
19266 \SpecialChar ~
19267 \SpecialChar ~
19268 \SpecialChar ~
19269 case 3: ...\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 case 2: ...
19296  
19297 \newline 
19298 \SpecialChar ~
19299 \SpecialChar ~
19300 \SpecialChar ~
19301 case 6: ...\SpecialChar ~
19302 \SpecialChar ~
19303 \SpecialChar ~
19304 \SpecialChar ~
19305 \SpecialChar ~
19306 \SpecialChar ~
19307 \SpecialChar ~
19308 \SpecialChar ~
19309 \SpecialChar ~
19310 \SpecialChar ~
19311 \SpecialChar ~
19312 \SpecialChar ~
19313 \SpecialChar ~
19314 \SpecialChar ~
19315 \SpecialChar ~
19316 \SpecialChar ~
19317 \SpecialChar ~
19318 \SpecialChar ~
19319 \SpecialChar ~
19320 \SpecialChar ~
19321 \SpecialChar ~
19322 \SpecialChar ~
19323 \SpecialChar ~
19324 \SpecialChar ~
19325 \SpecialChar ~
19326 \SpecialChar ~
19327 case 3: ...
19328  
19329 \newline 
19330 }\SpecialChar ~
19331 \SpecialChar ~
19332 \SpecialChar ~
19333 \SpecialChar ~
19334 \SpecialChar ~
19335 \SpecialChar ~
19336 \SpecialChar ~
19337 \SpecialChar ~
19338 \SpecialChar ~
19339 \SpecialChar ~
19340 \SpecialChar ~
19341 \SpecialChar ~
19342 \SpecialChar ~
19343 \SpecialChar ~
19344 \SpecialChar ~
19345 \SpecialChar ~
19346 \SpecialChar ~
19347 \SpecialChar ~
19348 \SpecialChar ~
19349 \SpecialChar ~
19350 \SpecialChar ~
19351 \SpecialChar ~
19352 \SpecialChar ~
19353 \SpecialChar ~
19354 \SpecialChar ~
19355 \SpecialChar ~
19356 \SpecialChar ~
19357 \SpecialChar ~
19358 \SpecialChar ~
19359 \SpecialChar ~
19360 \SpecialChar ~
19361 \SpecialChar ~
19362 \SpecialChar ~
19363 \SpecialChar ~
19364 \SpecialChar ~
19365 \SpecialChar ~
19366 }
19367 \layout Standard
19368
19369 Both the above switch statements will be implemented using a jump-table.
19370  The example to the right side is slightly more efficient as the check for
19371  the lower boundary of the jump-table is not needed.
19372 \end_deeper 
19373 \layout Itemize
19374
19375 The number of case labels is at least three, since it takes two conditional
19376  statements to handle the boundary conditions.
19377 \layout Itemize
19378
19379 The number of case labels is less than 84, since each label takes 3 bytes
19380  and a jump-table can be utmost 256 bytes long.
19381 \layout Standard
19382
19383 Switch statements which have gaps in the numeric sequence or those that
19384  have more that 84 case labels can be split into more than one switch statement
19385  for efficient code generation, e.g.:
19386 \layout Verse
19387
19388
19389 \family typewriter 
19390 switch (i) { 
19391 \newline 
19392 \SpecialChar ~
19393 \SpecialChar ~
19394 case 1: ...
19395  
19396 \newline 
19397 \SpecialChar ~
19398 \SpecialChar ~
19399 case 2: ...
19400  
19401 \newline 
19402 \SpecialChar ~
19403 \SpecialChar ~
19404 case 3: ...
19405  
19406 \newline 
19407 \SpecialChar ~
19408 \SpecialChar ~
19409 case 4: ...
19410  
19411 \newline 
19412 \SpecialChar ~
19413 \SpecialChar ~
19414 case 9: ...
19415  
19416 \newline 
19417 \SpecialChar ~
19418 \SpecialChar ~
19419 case 10: ...
19420  
19421 \newline 
19422 \SpecialChar ~
19423 \SpecialChar ~
19424 case 11: ...
19425  
19426 \newline 
19427 \SpecialChar ~
19428 \SpecialChar ~
19429 case 12: ...
19430  
19431 \newline 
19432 }
19433 \layout Standard
19434
19435 If the above switch statement is broken down into two switch statements
19436 \layout Verse
19437
19438
19439 \family typewriter 
19440 switch (i) { 
19441 \newline 
19442 \SpecialChar ~
19443 \SpecialChar ~
19444 case 1: ...
19445  
19446 \newline 
19447 \SpecialChar ~
19448 \SpecialChar ~
19449 case 2: ...
19450  
19451 \newline 
19452 \SpecialChar ~
19453 \SpecialChar ~
19454 case 3: ...
19455  
19456 \newline 
19457 \SpecialChar ~
19458 \SpecialChar ~
19459 case 4: ...
19460  
19461 \newline 
19462 }
19463 \layout Standard
19464
19465 and
19466 \layout Verse
19467
19468
19469 \family typewriter 
19470 switch (i) { 
19471 \newline 
19472 \SpecialChar ~
19473 \SpecialChar ~
19474 case 9:\SpecialChar ~
19475 \SpecialChar ~
19476 ...
19477  
19478 \newline 
19479 \SpecialChar ~
19480 \SpecialChar ~
19481 case 10:\SpecialChar ~
19482 ...
19483  
19484 \newline 
19485 \SpecialChar ~
19486 \SpecialChar ~
19487 case 11:\SpecialChar ~
19488 ...
19489  
19490 \newline 
19491 \SpecialChar ~
19492 \SpecialChar ~
19493 case 12:\SpecialChar ~
19494 ...
19495  
19496 \newline 
19497 }
19498 \layout Standard
19499
19500 then both the switch statements will be implemented using jump-tables whereas
19501  the unmodified switch statement will not be.
19502  You might also consider inserting dummy cases 0 and 5 to 8 in this example.
19503  
19504 \newline 
19505 The pragma nojtbound
19506 \begin_inset LatexCommand \index{\#pragma nojtbound}
19507
19508 \end_inset 
19509
19510  can be used to turn off checking the 
19511 \emph on 
19512 j
19513 \emph default 
19514 ump 
19515 \emph on 
19516 t
19517 \emph default 
19518 able 
19519 \emph on 
19520 bound
19521 \emph default 
19522 aries.
19523  It has no effect if a default label is supplied.
19524  Use of this pragma is dangerous: if the switch argument is not matched
19525  by a case statement the processor will happily jump into Nirvana.
19526 \layout Subsection
19527
19528 Bit-shifting Operations
19529 \begin_inset LatexCommand \index{Bit shifting}
19530
19531 \end_inset 
19532
19533 .
19534 \layout Standard
19535
19536 Bit shifting is one of the most frequently used operation in embedded programmin
19537 g.
19538  SDCC tries to implement bit-shift operations in the most efficient way
19539  possible, e.g.:
19540 \layout Verse
19541
19542
19543 \family typewriter 
19544 unsigned char i;
19545 \newline 
19546 ...
19547  
19548 \newline 
19549 i >>= 4; 
19550 \newline 
19551 ...
19552 \layout Standard
19553
19554 generates the following code:
19555 \layout Verse
19556
19557
19558 \family typewriter 
19559 mov\SpecialChar ~
19560  a,_i 
19561 \newline 
19562 swap a 
19563 \newline 
19564 anl\SpecialChar ~
19565  a,#0x0f 
19566 \newline 
19567 mov\SpecialChar ~
19568  _i,a
19569 \layout Standard
19570
19571 In general SDCC will never setup a loop if the shift count is known.
19572  Another example:
19573 \layout Verse
19574
19575
19576 \family typewriter 
19577 unsigned int i; 
19578 \newline 
19579 ...
19580  
19581 \newline 
19582 i >>= 9; 
19583 \newline 
19584 ...
19585 \layout Standard
19586
19587 will generate:
19588 \layout Verse
19589
19590
19591 \family typewriter 
19592 mov\SpecialChar ~
19593 \SpecialChar ~
19594 a,(_i + 1) 
19595 \newline 
19596 mov\SpecialChar ~
19597 \SpecialChar ~
19598 (_i + 1),#0x00 
19599 \newline 
19600 clr\SpecialChar ~
19601 \SpecialChar ~
19602
19603 \newline 
19604 rrc\SpecialChar ~
19605 \SpecialChar ~
19606
19607 \newline 
19608 mov\SpecialChar ~
19609 \SpecialChar ~
19610 _i,a
19611 \layout Subsection
19612
19613 Bit-rotation
19614 \begin_inset LatexCommand \index{Bit rotation}
19615
19616 \end_inset 
19617
19618
19619 \layout Standard
19620
19621 A special case of the bit-shift operation is bit rotation
19622 \begin_inset LatexCommand \index{rotating bits}
19623
19624 \end_inset 
19625
19626 , SDCC recognizes the following expression to be a left bit-rotation:
19627 \layout Verse
19628
19629
19630 \family typewriter 
19631 \series bold 
19632 unsigned
19633 \series default 
19634 \SpecialChar ~
19635 \SpecialChar ~
19636 char i;\SpecialChar ~
19637 \SpecialChar ~
19638 \SpecialChar ~
19639 \SpecialChar ~
19640 \SpecialChar ~
19641 \SpecialChar ~
19642 \SpecialChar ~
19643 \SpecialChar ~
19644 \SpecialChar ~
19645 \SpecialChar ~
19646 \SpecialChar ~
19647 /* unsigned is needed for rotation */ 
19648 \newline 
19649 ...
19650  
19651 \newline 
19652 i = ((i << 1) | (i >> 7)); 
19653 \family default 
19654
19655 \newline 
19656
19657 \family typewriter 
19658 ...
19659 \layout Standard
19660
19661 will generate the following code:
19662 \layout Verse
19663
19664
19665 \family typewriter 
19666 mov\SpecialChar ~
19667 \SpecialChar ~
19668 a,_i 
19669 \newline 
19670 rl\SpecialChar ~
19671 \SpecialChar ~
19672 \SpecialChar ~
19673
19674 \newline 
19675 mov\SpecialChar ~
19676 \SpecialChar ~
19677 _i,a
19678 \layout Standard
19679
19680 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
19681 ns of this case will also be recognized as bit-rotation, i.e.: 
19682 \layout Verse
19683
19684
19685 \family typewriter 
19686 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
19687 \layout Subsection
19688
19689 Nibble and Byte Swapping
19690 \layout Standard
19691
19692 Other special cases of the bit-shift operations are nibble or byte swapping
19693 \begin_inset LatexCommand \index{swapping nibbles/bytes}
19694
19695 \end_inset 
19696
19697 , SDCC recognizes the following expressions:
19698 \layout Verse
19699
19700
19701 \family typewriter 
19702 \series bold 
19703 unsigned
19704 \series default 
19705 \SpecialChar ~
19706 \SpecialChar ~
19707 char i; 
19708 \newline 
19709
19710 \series bold 
19711 unsigned
19712 \series default 
19713 \SpecialChar ~
19714 \SpecialChar ~
19715 int j; 
19716 \newline 
19717 ...
19718  
19719 \newline 
19720 i = ((i << 4) | (i >> 4)); 
19721 \family default 
19722
19723 \newline 
19724
19725 \family typewriter 
19726 j = ((j << 8) | (j >> 8)); 
19727 \layout Standard
19728
19729 and generates a swap instruction for the nibble swapping
19730 \begin_inset LatexCommand \index{Nibble swapping}
19731
19732 \end_inset 
19733
19734  or move instructions for the byte swapping
19735 \begin_inset LatexCommand \index{Byte swapping}
19736
19737 \end_inset 
19738
19739 .
19740  The 
19741 \begin_inset Quotes sld
19742 \end_inset 
19743
19744 j
19745 \begin_inset Quotes srd
19746 \end_inset 
19747
19748  example can be used to convert from little to big-endian or vice versa.
19749  If you want to change the endianness of a 
19750 \emph on 
19751 signed
19752 \emph default 
19753  integer you have to cast to 
19754 \family typewriter 
19755 (unsigned int)
19756 \family default 
19757  first.
19758 \layout Standard
19759
19760 Note that SDCC stores numbers in little-endian
19761 \begin_inset Foot
19762 collapsed false
19763
19764 \layout Standard
19765
19766 Usually 8-bit processors don't care much about endianness.
19767  This is not the case for the standard 8051 which only has an instruction
19768  to increment its 
19769 \emph on 
19770 dptr
19771 \emph default 
19772
19773 \begin_inset LatexCommand \index{DPTR}
19774
19775 \end_inset 
19776
19777 -datapointer
19778 \emph on 
19779  
19780 \emph default 
19781 so little-endian is the more efficient byte order.
19782 \end_inset 
19783
19784
19785 \begin_inset LatexCommand \index{little-endian}
19786
19787 \end_inset 
19788
19789
19790 \begin_inset LatexCommand \index{Endianness}
19791
19792 \end_inset 
19793
19794  format (i.e.
19795  lowest order first).
19796 \layout Subsection
19797
19798 Highest Order Bit
19799 \begin_inset LatexCommand \index{Highest Order Bit}
19800
19801 \end_inset 
19802
19803
19804 \layout Standard
19805
19806 It is frequently required to obtain the highest order bit of an integral
19807  type (long, int, short or char types).
19808  SDCC recognizes the following expression to yield the highest order bit
19809  and generates optimized code for it, e.g.:
19810 \layout Verse
19811
19812
19813 \family typewriter 
19814 unsigned int gint; 
19815 \newline 
19816
19817 \newline 
19818 foo () { 
19819 \newline 
19820 \SpecialChar ~
19821 \SpecialChar ~
19822 unsigned char hob; 
19823 \newline 
19824 \SpecialChar ~
19825 \SpecialChar ~
19826 ...
19827  
19828 \newline 
19829 \SpecialChar ~
19830 \SpecialChar ~
19831 hob = (gint >> 15) & 1; 
19832 \newline 
19833 \SpecialChar ~
19834 \SpecialChar ~
19835 ..
19836  
19837 \newline 
19838 }
19839 \layout Standard
19840
19841 will generate the following code:
19842 \layout Verse
19843
19844
19845 \family typewriter 
19846 \SpecialChar ~
19847 \SpecialChar ~
19848 \SpecialChar ~
19849 \SpecialChar ~
19850 \SpecialChar ~
19851 \SpecialChar ~
19852 \SpecialChar ~
19853 \SpecialChar ~
19854 \SpecialChar ~
19855 \SpecialChar ~
19856 \SpecialChar ~
19857 \SpecialChar ~
19858 \SpecialChar ~
19859 \SpecialChar ~
19860 \SpecialChar ~
19861 \SpecialChar ~
19862 \SpecialChar ~
19863 \SpecialChar ~
19864 \SpecialChar ~
19865 \SpecialChar ~
19866 \SpecialChar ~
19867 \SpecialChar ~
19868 \SpecialChar ~
19869 \SpecialChar ~
19870 \SpecialChar ~
19871  61 ;\SpecialChar ~
19872  hob.c 7 
19873 \newline 
19874 000A E5*01\SpecialChar ~
19875 \SpecialChar ~
19876 \SpecialChar ~
19877 \SpecialChar ~
19878 \SpecialChar ~
19879 \SpecialChar ~
19880 \SpecialChar ~
19881 \SpecialChar ~
19882 \SpecialChar ~
19883 \SpecialChar ~
19884 \SpecialChar ~
19885 \SpecialChar ~
19886 \SpecialChar ~
19887 \SpecialChar ~
19888 \SpecialChar ~
19889  62\SpecialChar ~
19890 \SpecialChar ~
19891 \SpecialChar ~
19892 \SpecialChar ~
19893 \SpecialChar ~
19894 \SpecialChar ~
19895 \SpecialChar ~
19896 \SpecialChar ~
19897  mov\SpecialChar ~
19898 \SpecialChar ~
19899  a,(_gint + 1) 
19900 \newline 
19901 000C 23\SpecialChar ~
19902 \SpecialChar ~
19903 \SpecialChar ~
19904 \SpecialChar ~
19905 \SpecialChar ~
19906 \SpecialChar ~
19907 \SpecialChar ~
19908 \SpecialChar ~
19909 \SpecialChar ~
19910 \SpecialChar ~
19911 \SpecialChar ~
19912 \SpecialChar ~
19913 \SpecialChar ~
19914 \SpecialChar ~
19915 \SpecialChar ~
19916 \SpecialChar ~
19917 \SpecialChar ~
19918 \SpecialChar ~
19919  63\SpecialChar ~
19920 \SpecialChar ~
19921 \SpecialChar ~
19922 \SpecialChar ~
19923 \SpecialChar ~
19924 \SpecialChar ~
19925 \SpecialChar ~
19926 \SpecialChar ~
19927  rl\SpecialChar ~
19928 \SpecialChar ~
19929 \SpecialChar ~
19930  a 
19931 \newline 
19932 000D 54 01\SpecialChar ~
19933 \SpecialChar ~
19934 \SpecialChar ~
19935 \SpecialChar ~
19936 \SpecialChar ~
19937 \SpecialChar ~
19938 \SpecialChar ~
19939 \SpecialChar ~
19940 \SpecialChar ~
19941 \SpecialChar ~
19942 \SpecialChar ~
19943 \SpecialChar ~
19944 \SpecialChar ~
19945 \SpecialChar ~
19946 \SpecialChar ~
19947  64\SpecialChar ~
19948 \SpecialChar ~
19949 \SpecialChar ~
19950 \SpecialChar ~
19951 \SpecialChar ~
19952 \SpecialChar ~
19953 \SpecialChar ~
19954 \SpecialChar ~
19955  anl\SpecialChar ~
19956 \SpecialChar ~
19957  a,#0x01 
19958 \newline 
19959 000F F5*02\SpecialChar ~
19960 \SpecialChar ~
19961 \SpecialChar ~
19962 \SpecialChar ~
19963 \SpecialChar ~
19964 \SpecialChar ~
19965 \SpecialChar ~
19966 \SpecialChar ~
19967 \SpecialChar ~
19968 \SpecialChar ~
19969 \SpecialChar ~
19970 \SpecialChar ~
19971 \SpecialChar ~
19972 \SpecialChar ~
19973 \SpecialChar ~
19974  65\SpecialChar ~
19975 \SpecialChar ~
19976 \SpecialChar ~
19977 \SpecialChar ~
19978 \SpecialChar ~
19979 \SpecialChar ~
19980 \SpecialChar ~
19981 \SpecialChar ~
19982  mov\SpecialChar ~
19983 \SpecialChar ~
19984  _foo_hob_1_1,a
19985 \layout Standard
19986
19987 Variations of this case however will 
19988 \emph on 
19989 not
19990 \emph default 
19991  be recognized.
19992  It is a standard C expression, so I heartily recommend this be the only
19993  way to get the highest order bit, (it is portable).
19994  Of course it will be recognized even if it is embedded in other expressions,
19995  e.g.:
19996 \layout Verse
19997
19998
19999 \family typewriter 
20000 xyz = gint + ((gint >> 15) & 1);
20001 \layout Standard
20002
20003 will still be recognized.
20004 \layout Subsection
20005
20006 Peephole Optimizer
20007 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
20008
20009 \end_inset 
20010
20011
20012 \begin_inset LatexCommand \index{Peephole optimizer}
20013
20014 \end_inset 
20015
20016
20017 \layout Standard
20018
20019 The compiler uses a rule based, pattern matching and re-writing mechanism
20020  for peep-hole optimization.
20021  It is inspired by 
20022 \emph on 
20023 copt
20024 \emph default 
20025  a peep-hole optimizer by Christopher W.
20026  Fraser (cwfraser@microsoft.com).
20027  A default set of rules are compiled into the compiler, additional rules
20028  may be added with the 
20029 \emph on 
20030 -
20031 \begin_inset ERT
20032 status Collapsed
20033
20034 \layout Standard
20035
20036 \backslash 
20037 /
20038 \end_inset 
20039
20040 -peep-file
20041 \begin_inset LatexCommand \index{-\/-peep-file}
20042
20043 \end_inset 
20044
20045  <filename>
20046 \emph default 
20047  option.
20048  The rule language is best illustrated with examples.
20049 \layout Verse
20050
20051
20052 \family typewriter 
20053 replace { 
20054 \newline 
20055 \SpecialChar ~
20056 \SpecialChar ~
20057 mov %1,a 
20058 \newline 
20059 \SpecialChar ~
20060 \SpecialChar ~
20061 mov a,%1
20062 \newline 
20063 } by {
20064 \newline 
20065 \SpecialChar ~
20066 \SpecialChar ~
20067 mov %1,a
20068 \newline 
20069 }
20070 \layout Standard
20071
20072 The above rule will change the following assembly
20073 \begin_inset LatexCommand \index{Assembler routines}
20074
20075 \end_inset 
20076
20077  sequence:
20078 \layout Verse
20079
20080
20081 \family typewriter 
20082 mov r1,a 
20083 \newline 
20084 mov a,r1
20085 \layout Standard
20086
20087 to
20088 \layout Verse
20089
20090
20091 \family typewriter 
20092 mov r1,a
20093 \layout Standard
20094
20095 Note: All occurrences of a 
20096 \emph on 
20097 %n
20098 \emph default 
20099  (pattern variable) must denote the same string.
20100  With the above rule, the assembly sequence:
20101 \layout Verse
20102
20103
20104 \family typewriter 
20105 mov r1,a 
20106 \newline 
20107 mov a,r2
20108 \layout Standard
20109
20110 will remain unmodified.
20111 \newline 
20112
20113 \newline 
20114 Other special case optimizations may be added by the user (via 
20115 \emph on 
20116 -
20117 \begin_inset ERT
20118 status Collapsed
20119
20120 \layout Standard
20121
20122 \backslash 
20123 /
20124 \end_inset 
20125
20126 -peep-file option
20127 \emph default 
20128 ).
20129  E.g.
20130  some variants of the 8051 MCU allow only 
20131 \family typewriter 
20132 ajmp
20133 \family default 
20134  and 
20135 \family typewriter 
20136 acall
20137 \family default 
20138 .
20139  The following two rules will change all 
20140 \family typewriter 
20141 ljmp
20142 \family default 
20143  and 
20144 \family typewriter 
20145 lcall
20146 \family default 
20147  to 
20148 \family typewriter 
20149 ajmp
20150 \family default 
20151  and 
20152 \family typewriter 
20153 acall
20154 \layout Verse
20155
20156
20157 \family typewriter 
20158 replace { lcall %1 } by { acall %1 } 
20159 \newline 
20160 replace { ljmp %1 } by { ajmp %1 }
20161 \layout Standard
20162
20163 The 
20164 \emph on 
20165 inline-assembler code
20166 \emph default 
20167  is also passed through the peep hole optimizer, thus the peephole optimizer
20168  can also be used as an assembly level macro expander.
20169  The rules themselves are MCU dependent whereas the rule language infra-structur
20170 e is MCU independent.
20171  Peephole optimization rules for other MCU can be easily programmed using
20172  the rule language.
20173 \newline 
20174
20175 \newline 
20176 The syntax for a rule is as follows:
20177 \layout Verse
20178
20179
20180 \family typewriter 
20181 rule := replace [ restart ] '{' <assembly sequence> '
20182 \backslash 
20183 n' 
20184 \newline 
20185 \SpecialChar ~
20186  \SpecialChar ~
20187  \SpecialChar ~
20188  \SpecialChar ~
20189  \SpecialChar ~
20190  \SpecialChar ~
20191  \SpecialChar ~
20192  \SpecialChar ~
20193  \SpecialChar ~
20194  \SpecialChar ~
20195  \SpecialChar ~
20196  \SpecialChar ~
20197  \SpecialChar ~
20198  \SpecialChar ~
20199  '}' by '{' '
20200 \backslash 
20201 n' 
20202 \newline 
20203 \SpecialChar ~
20204  \SpecialChar ~
20205  \SpecialChar ~
20206  \SpecialChar ~
20207  \SpecialChar ~
20208  \SpecialChar ~
20209  \SpecialChar ~
20210  \SpecialChar ~
20211  \SpecialChar ~
20212  \SpecialChar ~
20213  \SpecialChar ~
20214  \SpecialChar ~
20215  \SpecialChar ~
20216  \SpecialChar ~
20217  \SpecialChar ~
20218  \SpecialChar ~
20219  <assembly sequence> '
20220 \backslash 
20221 n' 
20222 \newline 
20223 \SpecialChar ~
20224  \SpecialChar ~
20225  \SpecialChar ~
20226  \SpecialChar ~
20227  \SpecialChar ~
20228  \SpecialChar ~
20229  \SpecialChar ~
20230  \SpecialChar ~
20231  \SpecialChar ~
20232  \SpecialChar ~
20233  \SpecialChar ~
20234  \SpecialChar ~
20235  \SpecialChar ~
20236  \SpecialChar ~
20237  '}' [if <functionName> ] '
20238 \backslash 
20239 n' 
20240 \layout Standard
20241
20242 <assembly sequence> := assembly instruction (each instruction including
20243  labels must be on a separate line).
20244 \newline 
20245
20246 \newline 
20247 The optimizer will apply to the rules one by one from the top in the sequence
20248  of their appearance, it will terminate when all rules are exhausted.
20249  If the 'restart' option is specified, then the optimizer will start matching
20250  the rules again from the top, this option for a rule is expensive (performance)
20251 , it is intended to be used in situations where a transformation will trigger
20252  the same rule again.
20253  An example of this (not a good one, it has side effects) is the following
20254  rule:
20255 \layout Verse
20256
20257
20258 \family typewriter 
20259 replace restart { 
20260 \newline 
20261 \SpecialChar ~
20262 \SpecialChar ~
20263 pop %1 
20264 \newline 
20265 \SpecialChar ~
20266 \SpecialChar ~
20267 push %1 } by { 
20268 \newline 
20269 \SpecialChar ~
20270 \SpecialChar ~
20271 ; nop 
20272 \newline 
20273 }
20274 \layout Standard
20275
20276 Note that the replace pattern cannot be a blank, but can be a comment line.
20277  Without the 'restart' option only the innermost 'pop' 'push' pair would
20278  be eliminated, i.e.:
20279 \layout Verse
20280
20281
20282 \family typewriter 
20283 pop ar1 
20284 \newline 
20285 pop ar2 
20286 \newline 
20287 push ar2 
20288 \newline 
20289 push ar1
20290 \layout Standard
20291
20292 would result in:
20293 \layout Verse
20294
20295
20296 \family typewriter 
20297 pop ar1 
20298 \newline 
20299 ; nop 
20300 \newline 
20301 push ar1
20302 \layout Standard
20303
20304
20305 \emph on 
20306 with
20307 \emph default 
20308  the restart option the rule will be applied again to the resulting code
20309  and then all the pop-push pairs will be eliminated to yield:
20310 \layout Verse
20311
20312
20313 \family typewriter 
20314 ; nop 
20315 \newline 
20316 ; nop
20317 \layout Standard
20318
20319 A conditional function can be attached to a rule.
20320  Attaching rules are somewhat more involved, let me illustrate this with
20321  an example.
20322 \layout Verse
20323
20324
20325 \family typewriter 
20326 replace { 
20327 \newline 
20328 \SpecialChar ~
20329  \SpecialChar ~
20330  \SpecialChar ~
20331 ljmp %5 
20332 \newline 
20333 %2:
20334 \newline 
20335 } by { 
20336 \newline 
20337 \SpecialChar ~
20338  \SpecialChar ~
20339  \SpecialChar ~
20340 sjmp %5 
20341 \newline 
20342 %2:
20343 \newline 
20344 } if labelInRange
20345 \layout Standard
20346
20347 The optimizer does a look-up of a function name table defined in function
20348  
20349 \emph on 
20350 callFuncByName
20351 \emph default 
20352  in the source file SDCCpeeph.c, with the name 
20353 \emph on 
20354 labelInRange
20355 \emph default 
20356 .
20357  If it finds a corresponding entry the function is called.
20358  Note there can be no parameters specified for these functions, in this
20359  case the use of 
20360 \emph on 
20361 %5
20362 \emph default 
20363  is crucial, since the function 
20364 \emph on 
20365 labelInRange
20366 \emph default 
20367  expects to find the label in that particular variable (the hash table containin
20368 g the variable bindings is passed as a parameter).
20369  If you want to code more such functions, take a close look at the function
20370  labelInRange and the calling mechanism in source file SDCCpeeph.c.
20371  Currently implemented are 
20372 \emph on 
20373 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
20374  24bitMode, portIsDS390, 24bitModeAndPortDS390 
20375 \emph default 
20376 and
20377 \emph on 
20378  notVolatile
20379 \emph default 
20380 .
20381 \layout Standard
20382
20383 I know this whole thing is a little kludgey, but maybe some day we will
20384  have some better means.
20385  If you are looking at this file, you will see the default rules that are
20386  compiled into the compiler, you can add your own rules in the default set
20387  there if you get tired of specifying the -
20388 \begin_inset ERT
20389 status Collapsed
20390
20391 \layout Standard
20392
20393 \backslash 
20394 /
20395 \end_inset 
20396
20397 -peep-file option.
20398 \layout Section
20399
20400 ANSI-Compliance
20401 \begin_inset LatexCommand \index{ANSI-compliance}
20402
20403 \end_inset 
20404
20405
20406 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
20407
20408 \end_inset 
20409
20410
20411 \layout Standard
20412
20413 Deviations from the compliance:
20414 \layout Itemize
20415
20416 functions are not always reentrant
20417 \begin_inset LatexCommand \index{reentrant}
20418
20419 \end_inset 
20420
20421 .
20422 \layout Itemize
20423
20424 structures cannot be assigned values directly, cannot be passed as function
20425  parameters or assigned to each other and cannot be a return value from
20426  a function, e.g.:
20427 \begin_deeper 
20428 \layout Verse
20429
20430
20431 \family typewriter 
20432 struct s { ...
20433  }; 
20434 \newline 
20435 struct s s1, s2; 
20436 \newline 
20437 foo() 
20438 \newline 
20439
20440 \newline 
20441 \SpecialChar ~
20442 \SpecialChar ~
20443 \SpecialChar ~
20444 \SpecialChar ~
20445 ...
20446  
20447 \newline 
20448 \SpecialChar ~
20449 \SpecialChar ~
20450 \SpecialChar ~
20451 \SpecialChar ~
20452 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
20453 \newline 
20454 \SpecialChar ~
20455 \SpecialChar ~
20456 \SpecialChar ~
20457 \SpecialChar ~
20458 ...
20459  
20460 \newline 
20461 }
20462 \newline 
20463 struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
20464  */
20465 \newline 
20466
20467 \newline 
20468 \SpecialChar ~
20469 \SpecialChar ~
20470 \SpecialChar ~
20471 \SpecialChar ~
20472 struct s rets; 
20473 \newline 
20474 \SpecialChar ~
20475 \SpecialChar ~
20476 \SpecialChar ~
20477 \SpecialChar ~
20478 ...
20479  
20480 \newline 
20481 \SpecialChar ~
20482 \SpecialChar ~
20483 \SpecialChar ~
20484 \SpecialChar ~
20485 return rets;/* is invalid in SDCC although allowed in ANSI */ 
20486 \newline 
20487 }
20488 \end_deeper 
20489 \layout Itemize
20490
20491 'long long
20492 \begin_inset LatexCommand \index{long long (not supported)}
20493
20494 \end_inset 
20495
20496 ' (64 bit integers
20497 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
20498
20499 \end_inset 
20500
20501 ) not supported.
20502 \layout Itemize
20503
20504 'double
20505 \begin_inset LatexCommand \index{double (not supported)}
20506
20507 \end_inset 
20508
20509 ' precision floating point 
20510 \begin_inset LatexCommand \index{Floating point support}
20511
20512 \end_inset 
20513
20514 not supported.
20515 \layout Itemize
20516
20517 No support for setjmp
20518 \begin_inset LatexCommand \index{setjmp (not supported)}
20519
20520 \end_inset 
20521
20522  and longjmp
20523 \begin_inset LatexCommand \index{longjmp (not supported)}
20524
20525 \end_inset 
20526
20527  (for now).
20528 \layout Itemize
20529
20530 Old K&R style
20531 \begin_inset LatexCommand \index{K\&R style}
20532
20533 \end_inset 
20534
20535  function declarations are NOT allowed.
20536 \begin_deeper 
20537 \layout Verse
20538
20539
20540 \family typewriter 
20541 foo(i,j) /* this old style of function declarations */ 
20542 \newline 
20543 int i,j; /* are valid in ANSI but not valid in SDCC */ 
20544 \newline 
20545
20546 \newline 
20547 \SpecialChar ~
20548 \SpecialChar ~
20549 \SpecialChar ~
20550 \SpecialChar ~
20551 ...
20552  
20553 \newline 
20554 }
20555 \end_deeper 
20556 \layout Itemize
20557
20558 functions declared as pointers
20559 \begin_inset LatexCommand \index{Pointer (to function)}
20560
20561 \end_inset 
20562
20563
20564 \begin_inset LatexCommand \index{function pointers}
20565
20566 \end_inset 
20567
20568  must be dereferenced during the call.
20569 \begin_deeper 
20570 \layout Verse
20571
20572
20573 \family typewriter 
20574 int (*foo)();
20575 \newline 
20576 ...
20577  
20578 \newline 
20579 /* has to be called like this */ 
20580 \newline 
20581 (*foo)(); /* ANSI standard allows calls to be made like 'foo()' */
20582 \end_deeper 
20583 \layout Section
20584
20585 Cyclomatic Complexity
20586 \begin_inset LatexCommand \index{Cyclomatic complexity}
20587
20588 \end_inset 
20589
20590
20591 \layout Standard
20592
20593 Cyclomatic complexity of a function is defined as the number of independent
20594  paths the program can take during execution of the function.
20595  This is an important number since it defines the number test cases you
20596  have to generate to validate the function.
20597  The accepted industry standard for complexity number is 10, if the cyclomatic
20598  complexity reported by SDCC exceeds 10 you should think about simplification
20599  of the function logic.
20600  Note that the complexity level is not related to the number of lines of
20601  code in a function.
20602  Large functions can have low complexity, and small functions can have large
20603  complexity levels.
20604  
20605 \newline 
20606
20607 \newline 
20608 SDCC uses the following formula to compute the complexity:
20609 \newline 
20610
20611 \layout Standard
20612
20613 complexity = (number of edges in control flow graph) - (number of nodes
20614  in control flow graph) + 2;
20615 \newline 
20616
20617 \newline 
20618 Having said that the industry standard is 10, you should be aware that in
20619  some cases it be may unavoidable to have a complexity level of less than
20620  10.
20621  For example if you have switch statement with more than 10 case labels,
20622  each case label adds one to the complexity level.
20623  The complexity level is by no means an absolute measure of the algorithmic
20624  complexity of the function, it does however provide a good starting point
20625  for which functions you might look at for further optimization.
20626 \layout Section
20627
20628 Retargetting for other Processors
20629 \layout Standard
20630
20631 The issues for retargetting the compiler are far too numerous to be covered
20632  by this document.
20633  What follows is a brief description of each of the seven phases of the
20634  compiler and its MCU dependency.
20635 \layout Itemize
20636
20637 Parsing the source and building the annotated parse tree.
20638  This phase is largely MCU independent (except for the language extensions).
20639  Syntax & semantic checks are also done in this phase, along with some initial
20640  optimizations like back patching labels and the pattern matching optimizations
20641  like bit-rotation etc.
20642 \layout Itemize
20643
20644 The second phase involves generating an intermediate code which can be easy
20645  manipulated during the later phases.
20646  This phase is entirely MCU independent.
20647  The intermediate code generation assumes the target machine has unlimited
20648  number of registers, and designates them with the name iTemp.
20649  The compiler can be made to dump a human readable form of the code generated
20650  by using the -
20651 \begin_inset ERT
20652 status Collapsed
20653
20654 \layout Standard
20655
20656 \backslash 
20657 /
20658 \end_inset 
20659
20660 -dumpraw option.
20661 \layout Itemize
20662
20663 This phase does the bulk of the standard optimizations and is also MCU independe
20664 nt.
20665  This phase can be broken down into several sub-phases:
20666 \newline 
20667
20668 \newline 
20669 Break down intermediate code (iCode) into basic blocks.
20670 \newline 
20671 Do control flow & data flow analysis on the basic blocks.
20672 \newline 
20673 Do local common subexpression elimination, then global subexpression elimination
20674 \newline 
20675 Dead code elimination
20676 \newline 
20677 Loop optimizations
20678 \newline 
20679 If loop optimizations caused any changes then do 'global subexpression eliminati
20680 on' and 'dead code elimination' again.
20681 \layout Itemize
20682
20683 This phase determines the live-ranges; by live range I mean those iTemp
20684  variables defined by the compiler that still survive after all the optimization
20685 s.
20686  Live range analysis
20687 \begin_inset LatexCommand \index{Live range analysis}
20688
20689 \end_inset 
20690
20691  is essential for register allocation, since these computation determines
20692  which of these iTemps will be assigned to registers, and for how long.
20693 \layout Itemize
20694
20695 Phase five is register allocation.
20696  There are two parts to this process.
20697 \newline 
20698
20699 \newline 
20700 The first part I call 'register packing' (for lack of a better term).
20701  In this case several MCU specific expression folding is done to reduce
20702  register pressure.
20703 \newline 
20704
20705 \newline 
20706 The second part is more MCU independent and deals with allocating registers
20707  to the remaining live ranges.
20708  A lot of MCU specific code does creep into this phase because of the limited
20709  number of index registers available in the 8051.
20710 \layout Itemize
20711
20712 The Code generation phase is (unhappily), entirely MCU dependent and very
20713  little (if any at all) of this code can be reused for other MCU.
20714  However the scheme for allocating a homogenized assembler operand for each
20715  iCode operand may be reused.
20716 \layout Itemize
20717
20718 As mentioned in the optimization section the peep-hole optimizer is rule
20719  based system, which can reprogrammed for other MCUs.
20720 \layout Chapter
20721
20722 Compiler internals
20723 \begin_inset LatexCommand \index{Compiler internals}
20724
20725 \end_inset 
20726
20727
20728 \layout Section
20729
20730 The anatomy of the compiler
20731 \begin_inset LatexCommand \label{sub:The-anatomy-of}
20732
20733 \end_inset 
20734
20735
20736 \layout Standard
20737
20738
20739 \shape italic 
20740 This is an excerpt from an article published in Circuit Cellar Magazine
20741  in august 2000.
20742  It's a little outdated (the compiler is much more efficient now and user/develo
20743 per friendly), but pretty well exposes the guts of it all.
20744 \shape default 
20745
20746 \newline 
20747
20748 \newline 
20749 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
20750  It is fairly easy to retarget for other 8-bit MCU.
20751  Here we take a look at some of the internals of the compiler.
20752  
20753 \layout Paragraph*
20754
20755 Parsing
20756 \begin_inset LatexCommand \index{Parsing}
20757
20758 \end_inset 
20759
20760  
20761 \layout Standard
20762
20763 Parsing the input source file and creating an AST (Annotated Syntax Tree
20764 \begin_inset LatexCommand \index{Annotated syntax tree}
20765
20766 \end_inset 
20767
20768 ).
20769  This phase also involves propagating types (annotating each node of the
20770  parse tree with type information) and semantic analysis.
20771  There are some MCU specific parsing rules.
20772  For example the storage classes, the extended storage classes are MCU specific
20773  while there may be a xdata storage class for 8051 there is no such storage
20774  class for z80 or Atmel AVR.
20775  SDCC allows MCU specific storage class extensions, i.e.
20776  xdata will be treated as a storage class specifier when parsing 8051 C
20777  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
20778  C code.
20779 \layout Paragraph*
20780
20781 Generating iCode
20782 \begin_inset LatexCommand \index{iCode}
20783
20784 \end_inset 
20785
20786
20787 \layout Standard
20788
20789 Intermediate code generation.
20790  In this phase the AST is broken down into three-operand form (iCode).
20791  These three operand forms are represented as doubly linked lists.
20792  ICode is the term given to the intermediate form generated by the compiler.
20793  ICode example section shows some examples of iCode generated for some simple
20794  C source functions.
20795 \layout Paragraph*
20796
20797 Optimizations
20798 \begin_inset LatexCommand \index{Optimizations}
20799
20800 \end_inset 
20801
20802 .
20803 \layout Standard
20804
20805 Bulk of the target independent optimizations is performed in this phase.
20806  The optimizations include constant propagation, common sub-expression eliminati
20807 on, loop invariant code movement, strength reduction of loop induction variables
20808  and dead-code elimination.
20809 \layout Paragraph*
20810
20811 Live range analysis
20812 \begin_inset LatexCommand \index{Live range analysis}
20813
20814 \end_inset 
20815
20816
20817 \layout Standard
20818
20819 During intermediate code generation phase, the compiler assumes the target
20820  machine has infinite number of registers and generates a lot of temporary
20821  variables.
20822  The live range computation determines the lifetime of each of these compiler-ge
20823 nerated temporaries.
20824  A picture speaks a thousand words.
20825  ICode example sections show the live range annotations for each of the
20826  operand.
20827  It is important to note here, each iCode is assigned a number in the order
20828  of its execution in the function.
20829  The live ranges are computed in terms of these numbers.
20830  The from number is the number of the iCode which first defines the operand
20831  and the to number signifies the iCode which uses this operand last.
20832 \layout Paragraph*
20833
20834 Register Allocation
20835 \begin_inset LatexCommand \index{Register allocation}
20836
20837 \end_inset 
20838
20839
20840 \layout Standard
20841
20842 The register allocation determines the type and number of registers needed
20843  by each operand.
20844  In most MCUs only a few registers can be used for indirect addressing.
20845  In case of 8051 for example the registers R0 & R1 can be used to indirectly
20846  address the internal ram and DPTR to indirectly address the external ram.
20847  The compiler will try to allocate the appropriate register to pointer variables
20848  if it can.
20849  ICode example section shows the operands annotated with the registers assigned
20850  to them.
20851  The compiler will try to keep operands in registers as much as possible;
20852  there are several schemes the compiler uses to do achieve this.
20853  When the compiler runs out of registers the compiler will check to see
20854  if there are any live operands which is not used or defined in the current
20855  basic block being processed, if there are any found then it will push that
20856  operand and use the registers in this block, the operand will then be popped
20857  at the end of the basic block.
20858  
20859 \layout Standard
20860
20861 There are other MCU specific considerations in this phase.
20862  Some MCUs have an accumulator; very short-lived operands could be assigned
20863  to the accumulator instead of a general-purpose register.
20864 \layout Paragraph*
20865
20866 Code generation
20867 \layout Standard
20868
20869 Figure II gives a table of iCode operations supported by the compiler.
20870  The code generation involves translating these operations into corresponding
20871  assembly code for the processor.
20872  This sounds overly simple but that is the essence of code generation.
20873  Some of the iCode operations are generated on a MCU specific manner for
20874  example, the z80 port does not use registers to pass parameters so the
20875  SEND and RECV iCode operations will not be generated, and it also does
20876  not support JUMPTABLES.
20877  
20878 \newline 
20879
20880 \series bold 
20881 \shape italic 
20882 \color red
20883 <Where is Figure II ?>
20884 \layout Paragraph*
20885
20886 ICode Example
20887 \begin_inset LatexCommand \index{iCode}
20888
20889 \end_inset 
20890
20891
20892 \layout Standard
20893
20894 This section shows some details of iCode.
20895  The example C code does not do anything useful; it is used as an example
20896  to illustrate the intermediate code generated by the compiler.
20897 \layout Verse
20898
20899
20900 \family typewriter 
20901 1.\SpecialChar ~
20902 xdata int * p;
20903 \newline 
20904 2.\SpecialChar ~
20905 int gint;
20906 \newline 
20907 3.\SpecialChar ~
20908 /* This function does nothing useful.
20909  It is used
20910 \newline 
20911 4.\SpecialChar ~
20912 \SpecialChar ~
20913 \SpecialChar ~
20914 \SpecialChar ~
20915 for the purpose of explaining iCode */
20916 \newline 
20917 5.\SpecialChar ~
20918 short function (data int *x)
20919 \newline 
20920 6.\SpecialChar ~
20921 {
20922 \newline 
20923 7.\SpecialChar ~
20924 \SpecialChar ~
20925 \SpecialChar ~
20926 short i=10; \SpecialChar ~
20927 \SpecialChar ~
20928 /* dead initialization eliminated */
20929 \newline 
20930 8.\SpecialChar ~
20931 \SpecialChar ~
20932 \SpecialChar ~
20933 short sum=10; /* dead initialization eliminated */
20934 \newline 
20935 9.\SpecialChar ~
20936 \SpecialChar ~
20937 \SpecialChar ~
20938 short mul;
20939 \newline 
20940 10.\SpecialChar ~
20941 \SpecialChar ~
20942 int j ;
20943 \newline 
20944 11.\SpecialChar ~
20945 \SpecialChar ~
20946 while (*x) *x++ = *p++; 
20947 \newline 
20948 12.\SpecialChar ~
20949 \SpecialChar ~
20950 \SpecialChar ~
20951 \SpecialChar ~
20952 sum = 0 ; 
20953 \newline 
20954 13.\SpecialChar ~
20955 \SpecialChar ~
20956 mul = 0;
20957 \newline 
20958 14.\SpecialChar ~
20959 \SpecialChar ~
20960 /* compiler detects i,j to be induction variables */
20961 \newline 
20962 15.\SpecialChar ~
20963 \SpecialChar ~
20964 for (i = 0, j = 10 ; i < 10 ; i++, j
20965 \family default 
20966 -
20967 \begin_inset ERT
20968 status Collapsed
20969
20970 \layout Standard
20971
20972 \backslash 
20973 /
20974 \end_inset 
20975
20976 -
20977 \family typewriter 
20978 ) {
20979 \newline 
20980 16.\SpecialChar ~
20981 \SpecialChar ~
20982 \SpecialChar ~
20983 \SpecialChar ~
20984 sum += i;
20985 \newline 
20986 17.\SpecialChar ~
20987 \SpecialChar ~
20988 \SpecialChar ~
20989 \SpecialChar ~
20990 mul += i * 3; \SpecialChar ~
20991 \SpecialChar ~
20992 /* this multiplication remains */
20993 \newline 
20994 18.\SpecialChar ~
20995 \SpecialChar ~
20996 \SpecialChar ~
20997 \SpecialChar ~
20998 gint += j * 3;\SpecialChar ~
20999 \SpecialChar ~
21000 /* this multiplication changed to addition */
21001 \newline 
21002 19.\SpecialChar ~
21003 \SpecialChar ~
21004 }
21005 \newline 
21006 20.\SpecialChar ~
21007 \SpecialChar ~
21008 return sum+mul;
21009 \newline 
21010 21.\SpecialChar ~
21011 }
21012 \layout Standard
21013
21014 In addition to the operands each iCode contains information about the filename
21015  and line it corresponds to in the source file.
21016  The first field in the listing should be interpreted as follows:
21017 \newline 
21018
21019 \shape italic 
21020 \size footnotesize 
21021 Filename(linenumber: iCode Execution sequence number : ICode hash table
21022  key : loop depth of the iCode).
21023 \shape default 
21024 \size default 
21025
21026 \newline 
21027 Then follows the human readable form of the ICode operation.
21028  Each operand of this triplet form can be of three basic types a) compiler
21029  generated temporary b) user defined variable c) a constant value.
21030  Note that local variables and parameters are replaced by compiler generated
21031  temporaries.
21032  Live ranges
21033 \begin_inset LatexCommand \index{Live range analysis}
21034
21035 \end_inset 
21036
21037  are computed only for temporaries (i.e.
21038  live ranges are not computed for global variables).
21039  Registers
21040 \begin_inset LatexCommand \index{Register allocation}
21041
21042 \end_inset 
21043
21044  are allocated for temporaries only.
21045  Operands are formatted in the following manner:
21046 \newline 
21047
21048 \shape italic 
21049 \size footnotesize 
21050 Operand Name [lr live-from : live-to ] { type information } [ registers
21051  allocated ].
21052 \shape default 
21053 \size default 
21054
21055 \newline 
21056 As mentioned earlier the live ranges are computed in terms of the execution
21057  sequence number of the iCodes, for example 
21058 \newline 
21059 the iTemp0 is live from (i.e.
21060  first defined in iCode with execution sequence number 3, and is last used
21061  in the iCode with sequence number 5).
21062  For induction variables such as iTemp21 the live range computation extends
21063  the lifetime from the start to the end of the loop.
21064 \newline 
21065 The register allocator used the live range information to allocate registers,
21066  the same registers may be used for different temporaries if their live
21067  ranges do not overlap, for example r0 is allocated to both iTemp6 and to
21068  iTemp17 since their live ranges do not overlap.
21069  In addition the allocator also takes into consideration the type and usage
21070  of a temporary, for example itemp6 is a pointer to near space and is used
21071  as to fetch data from (i.e.
21072  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
21073  Some short lived temporaries are allocated to special registers which have
21074  meaning to the code generator e.g.
21075  iTemp13 is allocated to a pseudo register CC which tells the back end that
21076  the temporary is used only for a conditional jump the code generation makes
21077  use of this information to optimize a compare and jump ICode.
21078 \newline 
21079 There are several loop optimizations
21080 \begin_inset LatexCommand \index{Loop optimization}
21081
21082 \end_inset 
21083
21084  performed by the compiler.
21085  It can detect induction variables iTemp21(i) and iTemp23(j).
21086  Also note the compiler does selective strength reduction
21087 \begin_inset LatexCommand \index{Strength reduction}
21088
21089 \end_inset 
21090
21091 , i.e.
21092  the multiplication of an induction variable in line 18 (gint = j * 3) is
21093  changed to addition, a new temporary iTemp17 is allocated and assigned
21094  a initial value, a constant 3 is then added for each iteration of the loop.
21095  The compiler does not change the multiplication
21096 \begin_inset LatexCommand \index{Multiplication}
21097
21098 \end_inset 
21099
21100  in line 17 however since the processor does support an 8 * 8 bit multiplication.
21101 \newline 
21102 Note the dead code elimination
21103 \begin_inset LatexCommand \index{Dead-code elimination}
21104
21105 \end_inset 
21106
21107  optimization eliminated the dead assignments in line 7 & 8 to I and sum
21108  respectively.
21109 \newline 
21110
21111 \layout Standard
21112
21113
21114 \size footnotesize 
21115 Sample.c (5:1:0:0) _entry($9) :
21116 \layout Standard
21117
21118
21119 \size footnotesize 
21120 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
21121 \layout Standard
21122
21123
21124 \size footnotesize 
21125 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
21126 \layout Standard
21127
21128
21129 \size footnotesize 
21130 Sample.c(11:4:53:0) preHeaderLbl0($11) :
21131 \layout Standard
21132
21133
21134 \size footnotesize 
21135 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
21136  * int}[r2]
21137 \layout Standard
21138
21139
21140 \size footnotesize 
21141 Sample.c(11:6:5:1) _whilecontinue_0($1) :
21142 \layout Standard
21143
21144
21145 \size footnotesize 
21146 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
21147  int}[r0]]
21148 \layout Standard
21149
21150
21151 \size footnotesize 
21152 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
21153 \layout Standard
21154
21155
21156 \size footnotesize 
21157 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
21158  * int}
21159 \layout Standard
21160
21161
21162 \size footnotesize 
21163 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
21164  {short}
21165 \layout Standard
21166
21167
21168 \size footnotesize 
21169 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
21170  * int}[DPTR]]
21171 \layout Standard
21172
21173
21174 \size footnotesize 
21175 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
21176 }[r2 r3]
21177 \layout Standard
21178
21179
21180 \size footnotesize 
21181 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
21182  * int}[r0] + 0x2 {short}
21183 \layout Standard
21184
21185
21186 \size footnotesize 
21187 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
21188 \layout Standard
21189
21190
21191 \size footnotesize 
21192 Sample.c(11:17:21:0)_whilebreak_0($3) :
21193 \layout Standard
21194
21195
21196 \size footnotesize 
21197 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
21198 \layout Standard
21199
21200
21201 \size footnotesize 
21202 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
21203 \layout Standard
21204
21205
21206 \size footnotesize 
21207 Sample.c(15:20:54:0)preHeaderLbl1($13) :
21208 \layout Standard
21209
21210
21211 \size footnotesize 
21212 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
21213 \layout Standard
21214
21215
21216 \size footnotesize 
21217 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
21218 \layout Standard
21219
21220
21221 \size footnotesize 
21222 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
21223 \layout Standard
21224
21225
21226 \size footnotesize 
21227 Sample.c(15:24:26:1)_forcond_0($4) :
21228 \layout Standard
21229
21230
21231 \size footnotesize 
21232 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
21233  < 0xa {short}
21234 \layout Standard
21235
21236
21237 \size footnotesize 
21238 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
21239 \layout Standard
21240
21241
21242 \size footnotesize 
21243 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
21244  + ITemp21 [lr21:38]{short}[r4]
21245 \layout Standard
21246
21247
21248 \size footnotesize 
21249 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
21250  * 0x3 {short}
21251 \layout Standard
21252
21253
21254 \size footnotesize 
21255 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
21256  + iTemp15 [lr29:30]{short}[r1]
21257 \layout Standard
21258
21259
21260 \size footnotesize 
21261 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
21262  r0]- 0x3 {short}
21263 \layout Standard
21264
21265
21266 \size footnotesize 
21267 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
21268 int}[r7 r0]
21269 \layout Standard
21270
21271
21272 \size footnotesize 
21273 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
21274  + 0x1 {short}
21275 \layout Standard
21276
21277
21278 \size footnotesize 
21279 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
21280  r6]- 0x1 {short}
21281 \layout Standard
21282
21283
21284 \size footnotesize 
21285 Sample.c(19:38:47:1) goto _forcond_0($4)
21286 \layout Standard
21287
21288
21289 \size footnotesize 
21290 Sample.c(19:39:48:0)_forbreak_0($7) :
21291 \layout Standard
21292
21293
21294 \size footnotesize 
21295 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
21296  + ITemp11 [lr19:40]{short}[r3]
21297 \layout Standard
21298
21299
21300 \size footnotesize 
21301 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
21302 \layout Standard
21303
21304
21305 \size footnotesize 
21306 Sample.c(20:42:51:0)_return($8) :
21307 \layout Standard
21308
21309
21310 \size footnotesize 
21311 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
21312 \size default 
21313
21314 \newline 
21315
21316 \newline 
21317 Finally the code generated for this function:
21318 \newline 
21319
21320 \layout Standard
21321
21322
21323 \size footnotesize 
21324 .area DSEG (DATA)
21325 \layout Standard
21326
21327
21328 \size footnotesize 
21329 _p::
21330 \layout Standard
21331
21332
21333 \size footnotesize 
21334 \SpecialChar ~
21335 \SpecialChar ~
21336 .ds 2
21337 \layout Standard
21338
21339
21340 \size footnotesize 
21341 _gint::
21342 \layout Standard
21343
21344
21345 \size footnotesize 
21346 \SpecialChar ~
21347 \SpecialChar ~
21348 .ds 2
21349 \layout Standard
21350
21351
21352 \size footnotesize 
21353 ; sample.c 5
21354 \layout Standard
21355
21356
21357 \size footnotesize 
21358 ; ----------------------------------------------
21359 \layout Standard
21360
21361
21362 \size footnotesize 
21363 ; function function
21364 \layout Standard
21365
21366
21367 \size footnotesize 
21368 ; ----------------------------------------------
21369 \layout Standard
21370
21371
21372 \size footnotesize 
21373 _function:
21374 \layout Standard
21375
21376
21377 \size footnotesize 
21378 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
21379 \layout Standard
21380
21381
21382 \size footnotesize 
21383 \SpecialChar ~
21384 \SpecialChar ~
21385 mov r2,dpl
21386 \layout Standard
21387
21388
21389 \size footnotesize 
21390 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
21391 \layout Standard
21392
21393
21394 \size footnotesize 
21395 \SpecialChar ~
21396 \SpecialChar ~
21397 mov ar0,r2
21398 \layout Standard
21399
21400
21401 \size footnotesize 
21402 ;_whilecontinue_0($1) :
21403 \layout Standard
21404
21405
21406 \size footnotesize 
21407 00101$:
21408 \layout Standard
21409
21410
21411 \size footnotesize 
21412 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
21413 \layout Standard
21414
21415
21416 \size footnotesize 
21417 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
21418 \layout Standard
21419
21420
21421 \size footnotesize 
21422 \SpecialChar ~
21423 \SpecialChar ~
21424 mov ar2,@r0
21425 \layout Standard
21426
21427
21428 \size footnotesize 
21429 \SpecialChar ~
21430 \SpecialChar ~
21431 inc r0
21432 \layout Standard
21433
21434
21435 \size footnotesize 
21436 \SpecialChar ~
21437 \SpecialChar ~
21438 mov ar3,@r0
21439 \layout Standard
21440
21441
21442 \size footnotesize 
21443 \SpecialChar ~
21444 \SpecialChar ~
21445 dec r0
21446 \layout Standard
21447
21448
21449 \size footnotesize 
21450 \SpecialChar ~
21451 \SpecialChar ~
21452 mov a,r2
21453 \layout Standard
21454
21455
21456 \size footnotesize 
21457 \SpecialChar ~
21458 \SpecialChar ~
21459 orl a,r3
21460 \layout Standard
21461
21462
21463 \size footnotesize 
21464 \SpecialChar ~
21465 \SpecialChar ~
21466 jz 00103$
21467 \layout Standard
21468
21469
21470 \size footnotesize 
21471 00114$:
21472 \layout Standard
21473
21474
21475 \size footnotesize 
21476 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
21477 \layout Standard
21478
21479
21480 \size footnotesize 
21481 \SpecialChar ~
21482 \SpecialChar ~
21483 mov dpl,_p
21484 \layout Standard
21485
21486
21487 \size footnotesize 
21488 \SpecialChar ~
21489 \SpecialChar ~
21490 mov dph,(_p + 1)
21491 \layout Standard
21492
21493
21494 \size footnotesize 
21495 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
21496 \layout Standard
21497
21498
21499 \size footnotesize 
21500 \SpecialChar ~
21501 \SpecialChar ~
21502 mov a,#0x02
21503 \layout Standard
21504
21505
21506 \size footnotesize 
21507 \SpecialChar ~
21508 \SpecialChar ~
21509 add a,_p
21510 \layout Standard
21511
21512
21513 \size footnotesize 
21514 \SpecialChar ~
21515 \SpecialChar ~
21516 mov _p,a
21517 \layout Standard
21518
21519
21520 \size footnotesize 
21521 \SpecialChar ~
21522 \SpecialChar ~
21523 clr a
21524 \layout Standard
21525
21526
21527 \size footnotesize 
21528 \SpecialChar ~
21529 \SpecialChar ~
21530 addc a,(_p + 1)
21531 \layout Standard
21532
21533
21534 \size footnotesize 
21535 \SpecialChar ~
21536 \SpecialChar ~
21537 mov (_p + 1),a
21538 \layout Standard
21539
21540
21541 \size footnotesize 
21542 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
21543 \layout Standard
21544
21545
21546 \size footnotesize 
21547 \SpecialChar ~
21548 \SpecialChar ~
21549 movx a,@dptr
21550 \layout Standard
21551
21552
21553 \size footnotesize 
21554 \SpecialChar ~
21555 \SpecialChar ~
21556 mov r2,a
21557 \layout Standard
21558
21559
21560 \size footnotesize 
21561 \SpecialChar ~
21562 \SpecialChar ~
21563 inc dptr
21564 \layout Standard
21565
21566
21567 \size footnotesize 
21568 \SpecialChar ~
21569 \SpecialChar ~
21570 movx a,@dptr
21571 \layout Standard
21572
21573
21574 \size footnotesize 
21575 \SpecialChar ~
21576 \SpecialChar ~
21577 mov r3,a
21578 \layout Standard
21579
21580
21581 \size footnotesize 
21582 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
21583 \layout Standard
21584
21585
21586 \size footnotesize 
21587 \SpecialChar ~
21588 \SpecialChar ~
21589 mov @r0,ar2
21590 \layout Standard
21591
21592
21593 \size footnotesize 
21594 \SpecialChar ~
21595 \SpecialChar ~
21596 inc r0
21597 \layout Standard
21598
21599
21600 \size footnotesize 
21601 \SpecialChar ~
21602 \SpecialChar ~
21603 mov @r0,ar3
21604 \layout Standard
21605
21606
21607 \size footnotesize 
21608 ; iTemp6 [lr5:16]{_near * int}[r0] = 
21609 \layout Standard
21610
21611
21612 \size footnotesize 
21613 ; iTemp6 [lr5:16]{_near * int}[r0] + 
21614 \layout Standard
21615
21616
21617 \size footnotesize 
21618 ; 0x2 {short}
21619 \layout Standard
21620
21621
21622 \size footnotesize 
21623 \SpecialChar ~
21624 \SpecialChar ~
21625 inc r0
21626 \layout Standard
21627
21628
21629 \size footnotesize 
21630 ; goto _whilecontinue_0($1)
21631 \layout Standard
21632
21633
21634 \size footnotesize 
21635 \SpecialChar ~
21636 \SpecialChar ~
21637 sjmp 00101$
21638 \layout Standard
21639
21640
21641 \size footnotesize 
21642 ; _whilebreak_0($3) :
21643 \layout Standard
21644
21645
21646 \size footnotesize 
21647 00103$:
21648 \layout Standard
21649
21650
21651 \size footnotesize 
21652 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
21653 \layout Standard
21654
21655
21656 \size footnotesize 
21657 \SpecialChar ~
21658 \SpecialChar ~
21659 mov r2,#0x00
21660 \layout Standard
21661
21662
21663 \size footnotesize 
21664 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
21665 \layout Standard
21666
21667
21668 \size footnotesize 
21669 \SpecialChar ~
21670 \SpecialChar ~
21671 mov r3,#0x00
21672 \layout Standard
21673
21674
21675 \size footnotesize 
21676 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
21677 \layout Standard
21678
21679
21680 \size footnotesize 
21681 \SpecialChar ~
21682 \SpecialChar ~
21683 mov r4,#0x00
21684 \layout Standard
21685
21686
21687 \size footnotesize 
21688 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
21689 \layout Standard
21690
21691
21692 \size footnotesize 
21693 \SpecialChar ~
21694 \SpecialChar ~
21695 mov r5,#0x0A
21696 \layout Standard
21697
21698
21699 \size footnotesize 
21700 \SpecialChar ~
21701 \SpecialChar ~
21702 mov r6,#0x00
21703 \layout Standard
21704
21705
21706 \size footnotesize 
21707 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
21708 \layout Standard
21709
21710
21711 \size footnotesize 
21712 \SpecialChar ~
21713 \SpecialChar ~
21714 mov r7,#0x1E
21715 \layout Standard
21716
21717
21718 \size footnotesize 
21719 \SpecialChar ~
21720 \SpecialChar ~
21721 mov r0,#0x00
21722 \layout Standard
21723
21724
21725 \size footnotesize 
21726 ; _forcond_0($4) :
21727 \layout Standard
21728
21729
21730 \size footnotesize 
21731 00104$:
21732 \layout Standard
21733
21734
21735 \size footnotesize 
21736 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
21737 \layout Standard
21738
21739
21740 \size footnotesize 
21741 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
21742 \layout Standard
21743
21744
21745 \size footnotesize 
21746 \SpecialChar ~
21747 \SpecialChar ~
21748 clr c
21749 \layout Standard
21750
21751
21752 \size footnotesize 
21753 \SpecialChar ~
21754 \SpecialChar ~
21755 mov a,r4
21756 \layout Standard
21757
21758
21759 \size footnotesize 
21760 \SpecialChar ~
21761 \SpecialChar ~
21762 xrl a,#0x80
21763 \layout Standard
21764
21765
21766 \size footnotesize 
21767 \SpecialChar ~
21768 \SpecialChar ~
21769 subb a,#0x8a
21770 \layout Standard
21771
21772
21773 \size footnotesize 
21774 \SpecialChar ~
21775 \SpecialChar ~
21776 jnc 00107$
21777 \layout Standard
21778
21779
21780 \size footnotesize 
21781 00115$:
21782 \layout Standard
21783
21784
21785 \size footnotesize 
21786 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
21787 \layout Standard
21788
21789
21790 \size footnotesize 
21791 ; iTemp21 [lr21:38]{short}[r4]
21792 \layout Standard
21793
21794
21795 \size footnotesize 
21796 \SpecialChar ~
21797 \SpecialChar ~
21798 mov a,r4
21799 \layout Standard
21800
21801
21802 \size footnotesize 
21803 \SpecialChar ~
21804 \SpecialChar ~
21805 add a,r2
21806 \layout Standard
21807
21808
21809 \size footnotesize 
21810 \SpecialChar ~
21811 \SpecialChar ~
21812 mov r2,a
21813 \layout Standard
21814
21815
21816 \size footnotesize 
21817 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
21818 \layout Standard
21819
21820
21821 \size footnotesize 
21822 \SpecialChar ~
21823 \SpecialChar ~
21824 mov b,#0x03
21825 \layout Standard
21826
21827
21828 \size footnotesize 
21829 \SpecialChar ~
21830 \SpecialChar ~
21831 mov a,r4
21832 \layout Standard
21833
21834
21835 \size footnotesize 
21836 \SpecialChar ~
21837 \SpecialChar ~
21838 mul ab
21839 \layout Standard
21840
21841
21842 \size footnotesize 
21843 \SpecialChar ~
21844 \SpecialChar ~
21845 mov r1,a
21846 \layout Standard
21847
21848
21849 \size footnotesize 
21850 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
21851 \layout Standard
21852
21853
21854 \size footnotesize 
21855 ; iTemp15 [lr29:30]{short}[r1]
21856 \layout Standard
21857
21858
21859 \size footnotesize 
21860 \SpecialChar ~
21861 \SpecialChar ~
21862 add a,r3
21863 \layout Standard
21864
21865
21866 \size footnotesize 
21867 \SpecialChar ~
21868 \SpecialChar ~
21869 mov r3,a
21870 \layout Standard
21871
21872
21873 \size footnotesize 
21874 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
21875 \layout Standard
21876
21877
21878 \size footnotesize 
21879 \SpecialChar ~
21880 \SpecialChar ~
21881 mov a,r7
21882 \layout Standard
21883
21884
21885 \size footnotesize 
21886 \SpecialChar ~
21887 \SpecialChar ~
21888 add a,#0xfd
21889 \layout Standard
21890
21891
21892 \size footnotesize 
21893 \SpecialChar ~
21894 \SpecialChar ~
21895 mov r7,a
21896 \layout Standard
21897
21898
21899 \size footnotesize 
21900 \SpecialChar ~
21901 \SpecialChar ~
21902 mov a,r0
21903 \layout Standard
21904
21905
21906 \size footnotesize 
21907 \SpecialChar ~
21908 \SpecialChar ~
21909 addc a,#0xff
21910 \layout Standard
21911
21912
21913 \size footnotesize 
21914 \SpecialChar ~
21915 \SpecialChar ~
21916 mov r0,a
21917 \layout Standard
21918
21919
21920 \size footnotesize 
21921 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
21922 \layout Standard
21923
21924
21925 \size footnotesize 
21926 \SpecialChar ~
21927 \SpecialChar ~
21928 mov a,r7
21929 \layout Standard
21930
21931
21932 \size footnotesize 
21933 \SpecialChar ~
21934 \SpecialChar ~
21935 add a,_gint
21936 \layout Standard
21937
21938
21939 \size footnotesize 
21940 \SpecialChar ~
21941 \SpecialChar ~
21942 mov _gint,a
21943 \layout Standard
21944
21945
21946 \size footnotesize 
21947 \SpecialChar ~
21948 \SpecialChar ~
21949 mov a,r0
21950 \layout Standard
21951
21952
21953 \size footnotesize 
21954 \SpecialChar ~
21955 \SpecialChar ~
21956 addc a,(_gint + 1)
21957 \layout Standard
21958
21959
21960 \size footnotesize 
21961 \SpecialChar ~
21962 \SpecialChar ~
21963 mov (_gint + 1),a
21964 \layout Standard
21965
21966
21967 \size footnotesize 
21968 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
21969 \layout Standard
21970
21971
21972 \size footnotesize 
21973 \SpecialChar ~
21974 \SpecialChar ~
21975 inc r4
21976 \layout Standard
21977
21978
21979 \size footnotesize 
21980 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
21981 \layout Standard
21982
21983
21984 \size footnotesize 
21985 \SpecialChar ~
21986 \SpecialChar ~
21987 dec r5
21988 \layout Standard
21989
21990
21991 \size footnotesize 
21992 \SpecialChar ~
21993 \SpecialChar ~
21994 cjne r5,#0xff,00104$
21995 \layout Standard
21996
21997
21998 \size footnotesize 
21999 \SpecialChar ~
22000 \SpecialChar ~
22001 dec r6
22002 \layout Standard
22003
22004
22005 \size footnotesize 
22006 ; goto _forcond_0($4)
22007 \layout Standard
22008
22009
22010 \size footnotesize 
22011 \SpecialChar ~
22012 \SpecialChar ~
22013 sjmp 00104$
22014 \layout Standard
22015
22016
22017 \size footnotesize 
22018 ; _forbreak_0($7) :
22019 \layout Standard
22020
22021
22022 \size footnotesize 
22023 00107$:
22024 \layout Standard
22025
22026
22027 \size footnotesize 
22028 ; ret iTemp24 [lr40:41]{short}
22029 \layout Standard
22030
22031
22032 \size footnotesize 
22033 \SpecialChar ~
22034 \SpecialChar ~
22035 mov a,r3
22036 \layout Standard
22037
22038
22039 \size footnotesize 
22040 \SpecialChar ~
22041 \SpecialChar ~
22042 add a,r2
22043 \layout Standard
22044
22045
22046 \size footnotesize 
22047 \SpecialChar ~
22048 \SpecialChar ~
22049 mov dpl,a
22050 \layout Standard
22051
22052
22053 \size footnotesize 
22054 ; _return($8) :
22055 \layout Standard
22056
22057
22058 \size footnotesize 
22059 00108$:
22060 \layout Standard
22061
22062
22063 \size footnotesize 
22064 \SpecialChar ~
22065 \SpecialChar ~
22066 ret
22067 \newline 
22068
22069 \layout Section
22070
22071 A few words about basic block successors, predecessors and dominators
22072 \layout Standard
22073
22074 Successors are basic blocks
22075 \begin_inset LatexCommand \index{Basic blocks}
22076
22077 \end_inset 
22078
22079  that might execute after this basic block.
22080 \newline 
22081 Predecessors are basic blocks that might execute before reaching this basic
22082  block.
22083 \newline 
22084 Dominators are basic blocks that WILL execute before reaching this basic
22085  block.
22086 \newline 
22087
22088 \layout Standard
22089
22090 [basic block 1]
22091 \layout Standard
22092
22093 if (something)
22094 \layout Standard
22095
22096 \SpecialChar ~
22097 \SpecialChar ~
22098 \SpecialChar ~
22099 \SpecialChar ~
22100 [basic block 2]
22101 \layout Standard
22102
22103 else
22104 \layout Standard
22105
22106 \SpecialChar ~
22107 \SpecialChar ~
22108 \SpecialChar ~
22109 \SpecialChar ~
22110 [basic block 3]
22111 \layout Standard
22112
22113 [basic block 4]
22114 \newline 
22115
22116 \layout Standard
22117
22118 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
22119 \layout Standard
22120
22121 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
22122 \layout Standard
22123
22124 c) domVect of [BB4] = BB1 ...
22125  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
22126  was executed.
22127 \layout Chapter
22128
22129 Acknowledgments
22130 \layout Standard
22131
22132
22133 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
22134
22135 \end_inset 
22136
22137
22138 \newline 
22139
22140 \newline 
22141
22142 \emph on 
22143 Thanks to all the other volunteer developers who have helped with coding,
22144  testing, web-page creation, distribution sets, etc.
22145  You know who you are :-)
22146 \emph default 
22147
22148 \newline 
22149
22150 \layout Standard
22151
22152 This document was initially written by Sandeep Dutta
22153 \layout Standard
22154
22155 All product names mentioned herein may be trademarks
22156 \begin_inset LatexCommand \index{Trademarks}
22157
22158 \end_inset 
22159
22160  of their respective companies.
22161  
22162 \layout Section*
22163
22164 Alphabetical index
22165 \layout Standard
22166
22167 To avoid confusion, the installation and building options for SDCC itself
22168  (chapter 2) are not part of the index.
22169 \layout Standard
22170
22171
22172 \begin_inset LatexCommand \printindex{}
22173
22174 \end_inset 
22175
22176
22177 \the_end