doc/sdccman.lyx: added Vangelis' contribution
[fw/sdcc] / doc / sdccman.lyx
1 #LyX 1.3 created this file. For more info see http://www.lyx.org/
2 \lyxformat 221
3 \textclass book
4 \begin_preamble
5 \usepackage[
6   pdftitle={SDCC Compiler User Guide},
7   pdfauthor={SDCC development team},
8   pdfsubject={installation, user manual},
9   pdfkeywords={8032, 8051, ansi, c, compiler, CPU, DS390, 
10                embedded, GPL, HC08, manual, mcs51, PIC, Z80},
11   colorlinks=true,
12   linkcolor=blue] {hyperref}
13 %
14 \sloppy
15 \tolerance=500          
16 \emergencystretch=30pt 
17 %
18 \date{}
19 \end_preamble
20 \language english
21 \inputencoding default
22 \fontscheme pslatex
23 \graphics default
24 \paperfontsize default
25 \spacing single 
26 \papersize letterpaper
27 \paperpackage a4
28 \use_geometry 1
29 \use_amsmath 0
30 \use_natbib 0
31 \use_numerical_citations 0
32 \paperorientation portrait
33 \leftmargin 30mm
34 \topmargin 20mm
35 \rightmargin 25mm
36 \bottommargin 20mm
37 \secnumdepth 3
38 \tocdepth 3
39 \paragraph_separation indent
40 \defskip medskip
41 \quotes_language swedish
42 \quotes_times 2
43 \papercolumns 1
44 \papersides 1
45 \paperpagestyle fancy
46
47 \layout Comment
48
49 Please note: double dashed longoptions (e.g.
50  --version) are written this way: -
51 \begin_inset ERT
52 status Collapsed
53
54 \layout Standard
55
56 \backslash 
57 /
58 \end_inset 
59
60 -
61 \layout Comment
62
63 Two resp.
64  three consecutive dashes simply result in a long resp.
65  extra long dash.
66 \layout Comment
67
68 Architecture specific stuff (like memory models, code examples) should maybe
69  later go
70 \layout Comment
71
72 into seperate sections/chapters/appendices (it is hard to document PIC or
73  Z80 in 
74 \layout Comment
75
76 a 8051 centered document) - for now simply add.
77 \layout Title
78
79 SDCC Compiler User Guide
80 \layout Date
81
82
83 \size normal 
84 SDCC 2.4.0
85 \size footnotesize 
86
87 \newline 
88 $Date$ 
89 \newline 
90 $Revision$
91 \layout Comment
92
93 The above strings enclosed in $ are automatically updated by cvs
94 \layout Standard
95
96
97 \begin_inset LatexCommand \tableofcontents{}
98
99 \end_inset 
100
101
102 \layout Chapter
103
104 Introduction
105 \layout Section
106
107 About SDCC
108 \layout Standard
109
110
111 \series bold 
112 SDCC
113 \series default 
114  (
115 \emph on 
116 S
117 \emph default 
118 mall 
119 \emph on 
120 D
121 \emph default 
122 evice 
123 \emph on 
124 C
125 \emph default 
126  
127 \emph on 
128 C
129 \emph default 
130 ompiler) is a Freeware, retargettable, optimizing ANSI-C compiler by 
131 \series bold 
132 Sandeep Dutta
133 \series default 
134  designed for 8 bit Microprocessors.
135  The current version targets Intel MCS51 based Microprocessors (8031, 8032,
136  8051, 8052
137 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
138
139 \end_inset 
140
141 , etc.), Dallas DS80C390 variants, Motorola HC08 and Zilog Z80 based MCUs.
142  It can be retargetted for other microprocessors, support for Microchip
143  PIC, Atmel AVR is under development.
144  The entire source code for the compiler is distributed under GPL.
145  SDCC uses ASXXXX & ASLINK, a Freeware, retargettable assembler & linker.
146  SDCC has extensive language extensions suitable for utilizing various microcont
147 rollers and underlying hardware effectively.
148  
149 \newline 
150
151 \newline 
152 In addition to the MCU specific optimizations SDCC also does a host of standard
153  optimizations like:
154 \layout Itemize
155
156 global sub expression elimination, 
157 \layout Itemize
158
159 loop optimizations (loop invariant, strength reduction of induction variables
160  and loop reversing), 
161 \layout Itemize
162
163 constant folding & propagation, 
164 \layout Itemize
165
166 copy propagation, 
167 \layout Itemize
168
169 dead code elimination 
170 \layout Itemize
171
172 jump tables for 
173 \emph on 
174 switch
175 \emph default 
176  statements.
177 \layout Standard
178
179 For the back-end SDCC uses a global register allocation scheme which should
180  be well suited for other 8 bit MCUs.
181  
182 \newline 
183
184 \newline 
185 The peep hole optimizer uses a rule based substitution mechanism which is
186  MCU independent.
187  
188 \newline 
189
190 \newline 
191 Supported data-types are:
192 \layout Itemize
193
194 char (8 bits, 1 byte), 
195 \layout Itemize
196
197 short and int (16 bits, 2 bytes), 
198 \layout Itemize
199
200 long (32 bit, 4 bytes)
201 \layout Itemize
202
203 float (4 byte IEEE).
204  
205 \layout Standard
206
207 The compiler also allows 
208 \emph on 
209 inline assembler code
210 \emph default 
211  to be embedded anywhere in a function.
212  In addition, routines developed in assembly can also be called.
213 \newline 
214
215 \newline 
216 SDCC also provides an option (-
217 \begin_inset ERT
218 status Collapsed
219
220 \layout Standard
221
222 \backslash 
223 /
224 \end_inset 
225
226 -cyclomatic) to report the relative complexity of a function.
227  These functions can then be further optimized, or hand coded in assembly
228  if needed.
229  
230 \newline 
231
232 \newline 
233 SDCC also comes with a companion source level debugger SDCDB, the debugger
234  currently uses ucSim a freeware simulator for 8051 and other micro-controllers.
235  
236 \newline 
237
238 \newline 
239 The latest version can be downloaded from 
240 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
241
242 \end_inset 
243
244 .
245
246 \series bold 
247  
248 \series default 
249 \emph on 
250 Please note: the compiler will probably always be some steps ahead of this
251  documentation
252 \series bold 
253 \emph default 
254
255 \begin_inset LatexCommand \index{Status of documentation}
256
257 \end_inset 
258
259
260 \begin_inset Foot
261 collapsed false
262
263 \layout Standard
264
265 Obviously this has pros and cons
266 \end_inset 
267
268 .
269 \layout Section
270
271 Open Source
272 \layout Standard
273
274 All packages used in this compiler system are 
275 \emph on 
276 opensource
277 \emph default 
278  and 
279 \emph on 
280 freeware
281 \emph default 
282 ; source code for all the sub-packages (pre-processor, assemblers, linkers
283  etc) is distributed with the package.
284  This documentation is maintained using a freeware word processor (LyX).
285 \newline 
286 This program is free software; you can redistribute it and/or modify it
287  under the terms of the GNU General Public License
288 \begin_inset LatexCommand \index{GNU General Public License, GPL}
289
290 \end_inset 
291
292  as published by the Free Software Foundation; either version 2, or (at
293  your option) any later version.
294  This program is distributed in the hope that it will be useful, but WITHOUT
295  ANY WARRANTY; without even the implied warranty
296 \begin_inset LatexCommand \index{warranty}
297
298 \end_inset 
299
300  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
301  See the GNU General Public License for more details.
302  You should have received a copy of the GNU General Public License along
303  with this program; if not, write to the Free Software Foundation, 59 Temple
304  Place - Suite 330, Boston, MA 02111-1307, USA.
305  In other words, you are welcome to use, share and improve this program.
306  You are forbidden to forbid anyone else to use, share and improve what
307  you give them.
308  Help stamp out software-hoarding! 
309 \layout Section
310
311 Typographic conventions
312 \begin_inset LatexCommand \index{Typographic conventions}
313
314 \end_inset 
315
316
317 \layout Standard
318
319 Throughout this manual, we will use the following convention.
320  Commands you have to type in are printed in 
321 \family sans 
322 \series bold 
323 "sans serif"
324 \series default 
325 .
326
327 \family default 
328  Code samples are printed in 
329 \family typewriter 
330 typewriter font.
331
332 \family default 
333  Interesting items and new terms are printed in 
334 \emph on 
335 italic.
336 \layout Section
337
338 Compatibility with previous versions
339 \layout Standard
340
341 This version has numerous bug fixes compared with the previous version.
342  But we also introduced some incompatibilities with older versions.
343  Not just for the fun of it, but to make the compiler more stable, efficient
344  and ANSI compliant
345 \begin_inset LatexCommand \index{ANSI-compliance}
346
347 \end_inset 
348
349  (see section 
350 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
351
352 \end_inset 
353
354  for ANSI-Compliance).
355  
356 \newline 
357
358 \layout Itemize
359
360 short is now equivalent to int (16 bits), it used to be equivalent to char
361  (8 bits) which is not ANSI compliant
362 \layout Itemize
363
364 the default directory for gcc-builds where include, library and documentation
365  files are stored is now in /usr/local/share
366 \layout Itemize
367
368 char type parameters to vararg functions are casted to int unless explicitly
369  casted, e.g.: 
370 \newline 
371
372 \family typewriter 
373 \SpecialChar ~
374 \SpecialChar ~
375 char a=3;
376 \newline 
377 \SpecialChar ~
378 \SpecialChar ~
379 printf ("%d %c
380 \backslash 
381 n", a, (char)a);
382 \family default 
383
384 \newline 
385  will push a as an int and as a char resp.
386 \layout Itemize
387
388 option -
389 \begin_inset ERT
390 status Collapsed
391
392 \layout Standard
393
394 \backslash 
395 /
396 \end_inset 
397
398 -regextend has been removed
399 \layout Itemize
400
401 option -
402 \begin_inset ERT
403 status Collapsed
404
405 \layout Standard
406
407 \backslash 
408 /
409 \end_inset 
410
411 -noregparms has been removed
412 \layout Itemize
413
414 option -
415 \begin_inset ERT
416 status Collapsed
417
418 \layout Standard
419
420 \backslash 
421 /
422 \end_inset 
423
424 -stack-after-data has been removed
425 \layout Standard
426
427
428 \emph on 
429 <pending: more incompatibilities?>
430 \layout Section
431
432 System Requirements
433 \layout Standard
434
435 What do you need before you start installation of SDCC? A computer, and
436  a desire to compute.
437  The preferred method of installation is to compile SDCC from source using
438  GNU gcc and make.
439  For Windows some pre-compiled binary distributions are available for your
440  convenience.
441  You should have some experience with command line tools and compiler use.
442 \layout Section
443
444 Other Resources
445 \layout Standard
446
447 The SDCC home page at 
448 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
449
450 \end_inset 
451
452  is a great place to find distribution sets.
453  You can also find links to the user mailing lists that offer help or discuss
454  SDCC with other SDCC users.
455  Web links to other SDCC related sites can also be found here.
456  This document can be found in the DOC directory of the source package as
457  a text or HTML file.
458  Some of the other tools (simulator and assembler) included with SDCC contain
459  their own documentation and can be found in the source distribution.
460  If you want the latest unreleased software, the complete source package
461  is available directly by anonymous CVS on cvs.sdcc.sourceforge.net.
462 \layout Section
463
464 Wishes for the future
465 \layout Standard
466
467 There are (and always will be) some things that could be done.
468  Here are some I can think of:
469 \newline 
470
471 \layout Standard
472
473
474 \family typewriter 
475 char KernelFunction3(char p) at 0x340;
476 \newline 
477
478 \layout Standard
479
480
481 \family typewriter 
482 code banking
483 \begin_inset LatexCommand \index{code banking (not supported)}
484
485 \end_inset 
486
487  support for mcs51
488 \newline 
489
490 \newline 
491
492 \family default 
493 If you can think of some more, please see the section 
494 \begin_inset LatexCommand \ref{sub:Requesting-Features}
495
496 \end_inset 
497
498  about filing feature requests
499 \begin_inset LatexCommand \index{Requesting features}
500
501 \end_inset 
502
503
504 \begin_inset LatexCommand \index{Feature request}
505
506 \end_inset 
507
508 .
509 \newline 
510
511 \layout Chapter
512
513 Installing SDCC
514 \begin_inset LatexCommand \index{Installation}
515
516 \end_inset 
517
518
519 \layout Standard
520
521 For most users it is sufficient to skip to either section 
522 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
523
524 \end_inset 
525
526  or section 
527 \begin_inset LatexCommand \ref{sub:Windows-Install}
528
529 \end_inset 
530
531 .
532  More detailled instructions follow below.
533 \layout Section
534
535 Configure Options
536 \begin_inset LatexCommand \index{Options SDCC configuration}
537
538 \end_inset 
539
540
541 \layout Standard
542
543 The install paths, search paths and other options are defined when running
544  'configure'.
545  The defaults can be overridden by:
546 \layout List
547 \labelwidthstring 00.00.0000
548
549 -
550 \begin_inset ERT
551 status Collapsed
552
553 \layout Standard
554
555 \backslash 
556 /
557 \end_inset 
558
559 -prefix see table below
560 \layout List
561 \labelwidthstring 00.00.0000
562
563 -
564 \begin_inset ERT
565 status Collapsed
566
567 \layout Standard
568
569 \backslash 
570 /
571 \end_inset 
572
573 -exec_prefix see table below
574 \layout List
575 \labelwidthstring 00.00.0000
576
577 -
578 \begin_inset ERT
579 status Collapsed
580
581 \layout Standard
582
583 \backslash 
584 /
585 \end_inset 
586
587 -bindir see table below
588 \layout List
589 \labelwidthstring 00.00.0000
590
591 -
592 \begin_inset ERT
593 status Collapsed
594
595 \layout Standard
596
597 \backslash 
598 /
599 \end_inset 
600
601 -datadir see table below
602 \layout List
603 \labelwidthstring 00.00.0000
604
605 docdir environment variable, see table below
606 \layout List
607 \labelwidthstring 00.00.0000
608
609 include_dir_suffix environment variable, see table below
610 \layout List
611 \labelwidthstring 00.00.0000
612
613 lib_dir_suffix environment variable, see table below
614 \layout List
615 \labelwidthstring 00.00.0000
616
617 sdccconf_h_dir_separator environment variable, either / or 
618 \backslash 
619
620 \backslash 
621  makes sense here.
622  This character will only be used in sdccconf.h; don't forget it's a C-header,
623  therefore a double-backslash is needed there.
624 \layout List
625 \labelwidthstring 00.00.0000
626
627 -
628 \begin_inset ERT
629 status Collapsed
630
631 \layout Standard
632
633 \backslash 
634 /
635 \end_inset 
636
637 -disable-mcs51-port Excludes the Intel mcs51 port
638 \layout List
639 \labelwidthstring 00.00.0000
640
641 -
642 \begin_inset ERT
643 status Collapsed
644
645 \layout Standard
646
647 \backslash 
648 /
649 \end_inset 
650
651 -disable-gbz80-port Excludes the Gameboy gbz80 port
652 \layout List
653 \labelwidthstring 00.00.0000
654
655 -
656 \begin_inset ERT
657 status Collapsed
658
659 \layout Standard
660
661 \backslash 
662 /
663 \end_inset 
664
665 -disable-z80-port Excludes the z80 port
666 \layout List
667 \labelwidthstring 00.00.0000
668
669 -
670 \begin_inset ERT
671 status Collapsed
672
673 \layout Standard
674
675 \backslash 
676 /
677 \end_inset 
678
679 -disable-avr-port Excludes the AVR port
680 \layout List
681 \labelwidthstring 00.00.0000
682
683 -
684 \begin_inset ERT
685 status Collapsed
686
687 \layout Standard
688
689 \backslash 
690 /
691 \end_inset 
692
693 -disable-ds390-port Excludes the DS390 port
694 \layout List
695 \labelwidthstring 00.00.0000
696
697 -
698 \begin_inset ERT
699 status Collapsed
700
701 \layout Standard
702
703 \backslash 
704 /
705 \end_inset 
706
707 -disable-hc08-port Excludes the HC08 port
708 \layout List
709 \labelwidthstring 00.00.0000
710
711 -
712 \begin_inset ERT
713 status Collapsed
714
715 \layout Standard
716
717 \backslash 
718 /
719 \end_inset 
720
721 -disable-pic-port Excludes the PIC port
722 \layout List
723 \labelwidthstring 00.00.0000
724
725 -
726 \begin_inset ERT
727 status Collapsed
728
729 \layout Standard
730
731 \backslash 
732 /
733 \end_inset 
734
735 -disable-xa51-port Excludes the XA51 port
736 \layout List
737 \labelwidthstring 00.00.0000
738
739 -
740 \begin_inset ERT
741 status Collapsed
742
743 \layout Standard
744
745 \backslash 
746 /
747 \end_inset 
748
749 -disable-ucsim Disables configuring and building of ucsim
750 \layout List
751 \labelwidthstring 00.00.0000
752
753 -
754 \begin_inset ERT
755 status Collapsed
756
757 \layout Standard
758
759 \backslash 
760 /
761 \end_inset 
762
763 -disable-device-lib-build Disables automatically building device libraries
764 \layout List
765 \labelwidthstring 00.00.0000
766
767 -
768 \begin_inset ERT
769 status Collapsed
770
771 \layout Standard
772
773 \backslash 
774 /
775 \end_inset 
776
777 -disable-packihx Disables building packihx
778 \layout List
779 \labelwidthstring 00.00.0000
780
781 -
782 \begin_inset ERT
783 status Collapsed
784
785 \layout Standard
786
787 \backslash 
788 /
789 \end_inset 
790
791 -enable-libgc Use the Bohem memory allocator.
792  Lower runtime footprint.
793 \layout Standard
794
795 Furthermore the environment variables CC, CFLAGS, ...
796  the tools and their arguments can be influenced.
797  Please see `configure -
798 \begin_inset ERT
799 status Collapsed
800
801 \layout Standard
802
803 \backslash 
804 /
805 \end_inset 
806
807 -help` and the man/info pages of `configure` for details.
808 \newline 
809
810 \newline 
811 The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB,
812  STD_FP_LIB, STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_
813 NAME, SDCC_INCLUDE_NAME, SDCC_LIB_NAME are defined by `configure` too.
814  At the moment it's not possible to change the default settings (it was
815  simply never required).
816 \newline 
817
818 \newline 
819 These configure options are compiled into the binaries, and can only be
820  changed by rerunning 'configure' and recompiling SDCC.
821  The configure options are written in 
822 \emph on 
823 italics
824 \emph default 
825  to distinguish them from run time environment variables (see section search
826  paths).
827 \newline 
828
829 \newline 
830 The settings for 
831 \begin_inset Quotes sld
832 \end_inset 
833
834 Win32 builds
835 \begin_inset Quotes srd
836 \end_inset 
837
838  are used by the SDCC team to build the official Win32 binaries.
839  The SDCC team uses Mingw32 to build the official Windows binaries, because
840  it's
841 \layout Enumerate
842
843 open source, 
844 \layout Enumerate
845
846 a gcc compiler and last but not least
847 \layout Enumerate
848
849 the binaries can be built by cross compiling on Sourceforge's compile farm.
850 \layout Standard
851
852 See the examples, how to pass the Win32 settings to 'configure'.
853  The other Win32 builds using Borland, VC or whatever don't use 'configure',
854  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
855  for Win32.
856 \newline 
857
858 \newline 
859 These defaults are:
860 \newline 
861
862 \layout Standard
863 \align center 
864
865 \begin_inset  Tabular
866 <lyxtabular version="3" rows="8" columns="3">
867 <features>
868 <column alignment="block" valignment="top" leftline="true" width="0in">
869 <column alignment="block" valignment="top" leftline="true" width="0in">
870 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
871 <row topline="true" bottomline="true">
872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
873 \begin_inset Text
874
875 \layout Standard
876
877 Variable
878 \end_inset 
879 </cell>
880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
881 \begin_inset Text
882
883 \layout Standard
884
885 default
886 \end_inset 
887 </cell>
888 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
889 \begin_inset Text
890
891 \layout Standard
892
893 Win32 builds
894 \end_inset 
895 </cell>
896 </row>
897 <row topline="true">
898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
899 \begin_inset Text
900
901 \layout Standard
902
903
904 \emph on 
905 PREFIX
906 \end_inset 
907 </cell>
908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
909 \begin_inset Text
910
911 \layout Standard
912
913 /usr/local
914 \end_inset 
915 </cell>
916 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
917 \begin_inset Text
918
919 \layout Standard
920
921
922 \backslash 
923 sdcc
924 \end_inset 
925 </cell>
926 </row>
927 <row topline="true">
928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
929 \begin_inset Text
930
931 \layout Standard
932
933
934 \emph on 
935 EXEC_PREFIX
936 \end_inset 
937 </cell>
938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
939 \begin_inset Text
940
941 \layout Standard
942
943
944 \emph on 
945 $PREFIX
946 \end_inset 
947 </cell>
948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
949 \begin_inset Text
950
951 \layout Standard
952
953
954 \emph on 
955 $PREFIX
956 \end_inset 
957 </cell>
958 </row>
959 <row topline="true">
960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
961 \begin_inset Text
962
963 \layout Standard
964
965
966 \emph on 
967 BINDIR
968 \end_inset 
969 </cell>
970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
971 \begin_inset Text
972
973 \layout Standard
974
975
976 \emph on 
977 $EXECPREFIX
978 \emph default 
979 /bin
980 \end_inset 
981 </cell>
982 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
983 \begin_inset Text
984
985 \layout Standard
986
987
988 \emph on 
989 $EXECPREFIX
990 \emph default 
991
992 \backslash 
993 bin
994 \end_inset 
995 </cell>
996 </row>
997 <row topline="true">
998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
999 \begin_inset Text
1000
1001 \layout Standard
1002
1003
1004 \emph on 
1005 DATADIR
1006 \end_inset 
1007 </cell>
1008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1009 \begin_inset Text
1010
1011 \layout Standard
1012
1013
1014 \emph on 
1015 $PREFIX
1016 \emph default 
1017 /share
1018 \end_inset 
1019 </cell>
1020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1021 \begin_inset Text
1022
1023 \layout Standard
1024
1025
1026 \emph on 
1027 $PREFIX
1028 \end_inset 
1029 </cell>
1030 </row>
1031 <row topline="true">
1032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1033 \begin_inset Text
1034
1035 \layout Standard
1036
1037
1038 \emph on 
1039 DOCDIR
1040 \end_inset 
1041 </cell>
1042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1043 \begin_inset Text
1044
1045 \layout Standard
1046
1047
1048 \emph on 
1049 $DATADIR
1050 \emph default 
1051 /sdcc/doc
1052 \end_inset 
1053 </cell>
1054 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1055 \begin_inset Text
1056
1057 \layout Standard
1058
1059
1060 \emph on 
1061 $DATADIR
1062 \emph default 
1063
1064 \backslash 
1065 doc
1066 \end_inset 
1067 </cell>
1068 </row>
1069 <row topline="true">
1070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1071 \begin_inset Text
1072
1073 \layout Standard
1074
1075
1076 \emph on 
1077 INCLUDE_DIR_SUFFIX
1078 \end_inset 
1079 </cell>
1080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1081 \begin_inset Text
1082
1083 \layout Standard
1084
1085 sdcc/include
1086 \end_inset 
1087 </cell>
1088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1089 \begin_inset Text
1090
1091 \layout Standard
1092
1093 include
1094 \end_inset 
1095 </cell>
1096 </row>
1097 <row topline="true" bottomline="true">
1098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1099 \begin_inset Text
1100
1101 \layout Standard
1102
1103
1104 \emph on 
1105 LIB_DIR_SUFFIX
1106 \end_inset 
1107 </cell>
1108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1109 \begin_inset Text
1110
1111 \layout Standard
1112
1113 sdcc/lib
1114 \end_inset 
1115 </cell>
1116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1117 \begin_inset Text
1118
1119 \layout Standard
1120
1121 lib
1122 \end_inset 
1123 </cell>
1124 </row>
1125 </lyxtabular>
1126
1127 \end_inset 
1128
1129
1130 \newline 
1131
1132 \layout Standard
1133 \noindent 
1134 'configure' also computes relative paths.
1135  This is needed for full relocatability of a binary package and to complete
1136  search paths (see section search paths below):
1137 \newline 
1138  
1139 \layout Standard
1140 \align center 
1141
1142 \begin_inset  Tabular
1143 <lyxtabular version="3" rows="4" columns="3">
1144 <features>
1145 <column alignment="block" valignment="top" leftline="true" width="0in">
1146 <column alignment="block" valignment="top" leftline="true" width="0in">
1147 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1148 <row topline="true" bottomline="true">
1149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1150 \begin_inset Text
1151
1152 \layout Standard
1153
1154 Variable (computed)
1155 \end_inset 
1156 </cell>
1157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1158 \begin_inset Text
1159
1160 \layout Standard
1161
1162 default
1163 \end_inset 
1164 </cell>
1165 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1166 \begin_inset Text
1167
1168 \layout Standard
1169
1170 Win32 builds
1171 \end_inset 
1172 </cell>
1173 </row>
1174 <row topline="true" bottomline="true">
1175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1176 \begin_inset Text
1177
1178 \layout Standard
1179
1180
1181 \emph on 
1182 BIN2DATA_DIR
1183 \end_inset 
1184 </cell>
1185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1186 \begin_inset Text
1187
1188 \layout Standard
1189
1190 ../share
1191 \end_inset 
1192 </cell>
1193 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1194 \begin_inset Text
1195
1196 \layout Standard
1197
1198 ..
1199 \end_inset 
1200 </cell>
1201 </row>
1202 <row bottomline="true">
1203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1204 \begin_inset Text
1205
1206 \layout Standard
1207
1208
1209 \emph on 
1210 PREFIX2BIN_DIR
1211 \end_inset 
1212 </cell>
1213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1214 \begin_inset Text
1215
1216 \layout Standard
1217
1218 bin
1219 \end_inset 
1220 </cell>
1221 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1222 \begin_inset Text
1223
1224 \layout Standard
1225
1226 bin
1227 \end_inset 
1228 </cell>
1229 </row>
1230 <row bottomline="true">
1231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1232 \begin_inset Text
1233
1234 \layout Standard
1235
1236
1237 \emph on 
1238 PREFIX2DATA_DIR
1239 \end_inset 
1240 </cell>
1241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1242 \begin_inset Text
1243
1244 \layout Standard
1245
1246 share/sdcc
1247 \end_inset 
1248 </cell>
1249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1250 \begin_inset Text
1251
1252 \layout Standard
1253
1254 \end_inset 
1255 </cell>
1256 </row>
1257 </lyxtabular>
1258
1259 \end_inset 
1260
1261
1262 \newline 
1263
1264 \layout Standard
1265 \noindent 
1266 Examples:
1267 \layout LyX-Code
1268
1269 ./configure
1270 \newline 
1271 ./configure -
1272 \begin_inset ERT
1273 status Collapsed
1274
1275 \layout Standard
1276
1277 \backslash 
1278 /
1279 \end_inset 
1280
1281 -prefix=
1282 \begin_inset Quotes srd
1283 \end_inset 
1284
1285 /usr/bin
1286 \begin_inset Quotes srd
1287 \end_inset 
1288
1289  -
1290 \begin_inset ERT
1291 status Collapsed
1292
1293 \layout Standard
1294
1295 \backslash 
1296 /
1297 \end_inset 
1298
1299 -datadir=
1300 \begin_inset Quotes srd
1301 \end_inset 
1302
1303 /usr/share
1304 \begin_inset Quotes srd
1305 \end_inset 
1306
1307
1308 \newline 
1309 ./configure -
1310 \begin_inset ERT
1311 status Collapsed
1312
1313 \layout Standard
1314
1315 \backslash 
1316 /
1317 \end_inset 
1318
1319 -disable-avr-port -
1320 \begin_inset ERT
1321 status Collapsed
1322
1323 \layout Standard
1324
1325 \backslash 
1326 /
1327 \end_inset 
1328
1329 -disable-xa51-port
1330 \layout Standard
1331
1332 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1333 32'):
1334 \layout LyX-Code
1335
1336 ./configure 
1337 \backslash 
1338
1339 \newline 
1340 CC=
1341 \begin_inset Quotes srd
1342 \end_inset 
1343
1344 i586-mingw32msvc-gcc
1345 \begin_inset Quotes srd
1346 \end_inset 
1347
1348  CXX=
1349 \begin_inset Quotes srd
1350 \end_inset 
1351
1352 i586-mingw32msvc-g++
1353 \begin_inset Quotes srd
1354 \end_inset 
1355
1356  
1357 \backslash 
1358  
1359 \newline 
1360 RANLIB=
1361 \begin_inset Quotes srd
1362 \end_inset 
1363
1364 i586-mingw32msvc-ranlib
1365 \begin_inset Quotes srd
1366 \end_inset 
1367
1368  
1369 \backslash 
1370
1371 \newline 
1372 STRIP=
1373 \begin_inset Quotes srd
1374 \end_inset 
1375
1376 i586-mingw32msvc-strip
1377 \begin_inset Quotes srd
1378 \end_inset 
1379
1380  
1381 \backslash 
1382
1383 \newline 
1384 -
1385 \begin_inset ERT
1386 status Collapsed
1387
1388 \layout Standard
1389
1390 \backslash 
1391 /
1392 \end_inset 
1393
1394 -prefix=
1395 \begin_inset Quotes srd
1396 \end_inset 
1397
1398 /sdcc
1399 \begin_inset Quotes srd
1400 \end_inset 
1401
1402  
1403 \backslash 
1404
1405 \newline 
1406 -
1407 \begin_inset ERT
1408 status Collapsed
1409
1410 \layout Standard
1411
1412 \backslash 
1413 /
1414 \end_inset 
1415
1416 -datadir=
1417 \begin_inset Quotes srd
1418 \end_inset 
1419
1420 /sdcc
1421 \begin_inset Quotes srd
1422 \end_inset 
1423
1424  
1425 \backslash 
1426
1427 \newline 
1428 docdir=
1429 \begin_inset Quotes srd
1430 \end_inset 
1431
1432 /sdcc/doc
1433 \begin_inset Quotes srd
1434 \end_inset 
1435
1436  
1437 \backslash 
1438
1439 \newline 
1440 include_dir_suffix=
1441 \begin_inset Quotes srd
1442 \end_inset 
1443
1444 include
1445 \begin_inset Quotes srd
1446 \end_inset 
1447
1448  
1449 \backslash 
1450
1451 \newline 
1452 lib_dir_suffix=
1453 \begin_inset Quotes srd
1454 \end_inset 
1455
1456 lib
1457 \begin_inset Quotes srd
1458 \end_inset 
1459
1460  
1461 \backslash 
1462
1463 \newline 
1464 sdccconf_h_dir_separator=
1465 \begin_inset Quotes srd
1466 \end_inset 
1467
1468
1469 \backslash 
1470
1471 \backslash 
1472
1473 \backslash 
1474
1475 \backslash 
1476
1477 \begin_inset Quotes srd
1478 \end_inset 
1479
1480  
1481 \backslash 
1482
1483 \newline 
1484 -
1485 \begin_inset ERT
1486 status Collapsed
1487
1488 \layout Standard
1489
1490 \backslash 
1491 /
1492 \end_inset 
1493
1494 -disable-device-lib-build
1495 \backslash 
1496
1497 \newline 
1498 -
1499 \begin_inset ERT
1500 status Collapsed
1501
1502 \layout Standard
1503
1504 \backslash 
1505 /
1506 \end_inset 
1507
1508 -disable-ucsim
1509 \backslash 
1510
1511 \newline 
1512 -
1513 \begin_inset ERT
1514 status Collapsed
1515
1516 \layout Standard
1517
1518 \backslash 
1519 /
1520 \end_inset 
1521
1522 -host=i586-mingw32msvc -
1523 \begin_inset ERT
1524 status Collapsed
1525
1526 \layout Standard
1527
1528 \backslash 
1529 /
1530 \end_inset 
1531
1532 -build=unknown-unknown-linux-gnu
1533 \layout Standard
1534
1535 To 
1536 \begin_inset Quotes sld
1537 \end_inset 
1538
1539 cross
1540 \begin_inset Quotes srd
1541 \end_inset 
1542
1543 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
1544 ):
1545 \layout LyX-Code
1546
1547 ./configure -C 
1548 \backslash 
1549
1550 \newline 
1551 CFLAGS=
1552 \begin_inset Quotes srd
1553 \end_inset 
1554
1555 -mno-cygwin -O2
1556 \begin_inset Quotes srd
1557 \end_inset 
1558
1559  
1560 \backslash 
1561
1562 \newline 
1563 LDFLAGS=
1564 \begin_inset Quotes srd
1565 \end_inset 
1566
1567 -mno-cygwin
1568 \begin_inset Quotes srd
1569 \end_inset 
1570
1571  
1572 \backslash 
1573
1574 \newline 
1575 -
1576 \begin_inset ERT
1577 status Collapsed
1578
1579 \layout Standard
1580
1581 \backslash 
1582 /
1583 \end_inset 
1584
1585 -prefix=
1586 \begin_inset Quotes srd
1587 \end_inset 
1588
1589 /sdcc
1590 \begin_inset Quotes srd
1591 \end_inset 
1592
1593  
1594 \backslash 
1595
1596 \newline 
1597 -
1598 \begin_inset ERT
1599 status Collapsed
1600
1601 \layout Standard
1602
1603 \backslash 
1604 /
1605 \end_inset 
1606
1607 -datadir=
1608 \begin_inset Quotes srd
1609 \end_inset 
1610
1611 /sdcc
1612 \begin_inset Quotes srd
1613 \end_inset 
1614
1615  
1616 \backslash 
1617
1618 \newline 
1619 docdir=
1620 \begin_inset Quotes srd
1621 \end_inset 
1622
1623 /sdcc/doc
1624 \begin_inset Quotes srd
1625 \end_inset 
1626
1627  
1628 \backslash 
1629  
1630 \newline 
1631 include_dir_suffix=
1632 \begin_inset Quotes srd
1633 \end_inset 
1634
1635 include
1636 \begin_inset Quotes srd
1637 \end_inset 
1638
1639  
1640 \backslash 
1641
1642 \newline 
1643 lib_dir_suffix=
1644 \begin_inset Quotes srd
1645 \end_inset 
1646
1647 lib
1648 \begin_inset Quotes srd
1649 \end_inset 
1650
1651  
1652 \backslash 
1653
1654 \newline 
1655 sdccconf_h_dir_separator=
1656 \begin_inset Quotes srd
1657 \end_inset 
1658
1659
1660 \backslash 
1661
1662 \backslash 
1663
1664 \backslash 
1665
1666 \backslash 
1667
1668 \begin_inset Quotes srd
1669 \end_inset 
1670
1671  
1672 \backslash 
1673
1674 \newline 
1675 -
1676 \begin_inset ERT
1677 status Collapsed
1678
1679 \layout Standard
1680
1681 \backslash 
1682 /
1683 \end_inset 
1684
1685 -disable-ucsim
1686 \layout Standard
1687
1688 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
1689  The option '-
1690 \begin_inset ERT
1691 status Collapsed
1692
1693 \layout Standard
1694
1695 \backslash 
1696 /
1697 \end_inset 
1698
1699 -C' turns on caching, which gives a little bit extra speed.
1700  However if options are changed, it can be necessary to delete the config.cache
1701  file.
1702 \layout Section
1703
1704 Install paths
1705 \begin_inset LatexCommand \label{sub:Install-paths}
1706
1707 \end_inset 
1708
1709
1710 \begin_inset LatexCommand \index{Install paths}
1711
1712 \end_inset 
1713
1714
1715 \layout Standard
1716 \added_space_top medskip \align center 
1717
1718 \begin_inset  Tabular
1719 <lyxtabular version="3" rows="5" columns="4">
1720 <features>
1721 <column alignment="center" valignment="top" leftline="true" width="0">
1722 <column alignment="center" valignment="top" leftline="true" width="0">
1723 <column alignment="center" valignment="top" leftline="true" width="0">
1724 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
1725 <row topline="true" bottomline="true">
1726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1727 \begin_inset Text
1728
1729 \layout Standard
1730
1731
1732 \series bold 
1733 Description
1734 \end_inset 
1735 </cell>
1736 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1737 \begin_inset Text
1738
1739 \layout Standard
1740
1741
1742 \series bold 
1743 Path
1744 \end_inset 
1745 </cell>
1746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1747 \begin_inset Text
1748
1749 \layout Standard
1750
1751
1752 \series bold 
1753 Default
1754 \end_inset 
1755 </cell>
1756 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1757 \begin_inset Text
1758
1759 \layout Standard
1760
1761
1762 \series bold 
1763 Win32 builds
1764 \end_inset 
1765 </cell>
1766 </row>
1767 <row topline="true">
1768 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1769 \begin_inset Text
1770
1771 \layout Standard
1772
1773 Binary files*
1774 \end_inset 
1775 </cell>
1776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1777 \begin_inset Text
1778
1779 \layout Standard
1780
1781
1782 \emph on 
1783 $EXEC_PREFIX
1784 \end_inset 
1785 </cell>
1786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1787 \begin_inset Text
1788
1789 \layout Standard
1790
1791 /usr/local/bin
1792 \end_inset 
1793 </cell>
1794 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1795 \begin_inset Text
1796
1797 \layout Standard
1798
1799
1800 \backslash 
1801 sdcc
1802 \backslash 
1803 bin
1804 \end_inset 
1805 </cell>
1806 </row>
1807 <row topline="true">
1808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1809 \begin_inset Text
1810
1811 \layout Standard
1812
1813 Include files
1814 \end_inset 
1815 </cell>
1816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1817 \begin_inset Text
1818
1819 \layout Standard
1820
1821
1822 \emph on 
1823 $DATADIR/ $INCLUDE_DIR_SUFFIX
1824 \end_inset 
1825 </cell>
1826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1827 \begin_inset Text
1828
1829 \layout Standard
1830
1831 /usr/local/share/sdcc/include
1832 \end_inset 
1833 </cell>
1834 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1835 \begin_inset Text
1836
1837 \layout Standard
1838
1839
1840 \backslash 
1841 sdcc
1842 \backslash 
1843 include
1844 \end_inset 
1845 </cell>
1846 </row>
1847 <row topline="true">
1848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1849 \begin_inset Text
1850
1851 \layout Standard
1852
1853 Library file**
1854 \end_inset 
1855 </cell>
1856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1857 \begin_inset Text
1858
1859 \layout Standard
1860
1861
1862 \emph on 
1863 $DATADIR/$LIB_DIR_SUFFIX
1864 \end_inset 
1865 </cell>
1866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1867 \begin_inset Text
1868
1869 \layout Standard
1870
1871 /usr/local/share/sdcc/lib
1872 \end_inset 
1873 </cell>
1874 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1875 \begin_inset Text
1876
1877 \layout Standard
1878
1879
1880 \backslash 
1881 sdcc
1882 \backslash 
1883 lib
1884 \end_inset 
1885 </cell>
1886 </row>
1887 <row topline="true" bottomline="true">
1888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1889 \begin_inset Text
1890
1891 \layout Standard
1892
1893 Documentation
1894 \end_inset 
1895 </cell>
1896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1897 \begin_inset Text
1898
1899 \layout Standard
1900
1901
1902 \emph on 
1903 $DOCDIR
1904 \end_inset 
1905 </cell>
1906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1907 \begin_inset Text
1908
1909 \layout Standard
1910
1911 /usr/local/share/sdcc/doc
1912 \end_inset 
1913 </cell>
1914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1915 \begin_inset Text
1916
1917 \layout Standard
1918
1919
1920 \backslash 
1921 sdcc
1922 \backslash 
1923 doc
1924 \end_inset 
1925 </cell>
1926 </row>
1927 </lyxtabular>
1928
1929 \end_inset 
1930
1931
1932 \layout Verse
1933
1934
1935 \size footnotesize 
1936 *compiler, preprocessor, assembler, and linker
1937 \newline 
1938 **the 
1939 \shape italic 
1940 model
1941 \shape default 
1942  is auto-appended by the compiler, e.g.
1943  small, large, z80, ds390 etc
1944 \layout Standard
1945 \noindent 
1946 The install paths can still be changed during `make install` with e.g.:
1947 \layout LyX-Code
1948
1949 make install prefix=$(HOME)/local/sdcc
1950 \layout Standard
1951
1952 Of course this doesn't change the search paths compiled into the binaries.
1953 \layout Section
1954
1955 Search Paths
1956 \begin_inset LatexCommand \label{sub:Search-Paths}
1957
1958 \end_inset 
1959
1960
1961 \begin_inset LatexCommand \index{Search path}
1962
1963 \end_inset 
1964
1965
1966 \layout Standard
1967
1968 Some search paths or parts of them are determined by configure variables
1969  (in 
1970 \emph on 
1971 italics
1972 \emph default 
1973 , see section above).
1974  Further search paths are determined by environment variables during runtime.
1975  
1976 \newline 
1977 The paths searched when running the compiler are as follows (the first catch
1978  wins):
1979 \newline 
1980
1981 \newline 
1982 1.
1983  Binary files (preprocessor, assembler and linker)
1984 \newline 
1985
1986 \layout Standard
1987 \align center 
1988
1989 \begin_inset  Tabular
1990 <lyxtabular version="3" rows="4" columns="3">
1991 <features>
1992 <column alignment="block" valignment="top" leftline="true" width="0in">
1993 <column alignment="block" valignment="top" leftline="true" width="0in">
1994 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1995 <row topline="true" bottomline="true">
1996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1997 \begin_inset Text
1998
1999 \layout Standard
2000
2001 Search path
2002 \end_inset 
2003 </cell>
2004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2005 \begin_inset Text
2006
2007 \layout Standard
2008
2009 default
2010 \end_inset 
2011 </cell>
2012 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2013 \begin_inset Text
2014
2015 \layout Standard
2016
2017 Win32 builds
2018 \end_inset 
2019 </cell>
2020 </row>
2021 <row topline="true">
2022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2023 \begin_inset Text
2024
2025 \layout Standard
2026
2027 $SDCC_HOME/
2028 \emph on 
2029 $PPREFIX2BIN_DIR
2030 \end_inset 
2031 </cell>
2032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2033 \begin_inset Text
2034
2035 \layout Standard
2036
2037 $SDCC_HOME/bin
2038 \end_inset 
2039 </cell>
2040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2041 \begin_inset Text
2042
2043 \layout Standard
2044
2045 $SDCC_HOME
2046 \backslash 
2047 bin
2048 \end_inset 
2049 </cell>
2050 </row>
2051 <row topline="true">
2052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2053 \begin_inset Text
2054
2055 \layout Standard
2056
2057 Path of argv[0] (if available)
2058 \end_inset 
2059 </cell>
2060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2061 \begin_inset Text
2062
2063 \layout Standard
2064
2065 Path of argv[0]
2066 \end_inset 
2067 </cell>
2068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2069 \begin_inset Text
2070
2071 \layout Standard
2072
2073 Path of argv[0]
2074 \end_inset 
2075 </cell>
2076 </row>
2077 <row topline="true" bottomline="true">
2078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2079 \begin_inset Text
2080
2081 \layout Standard
2082
2083 $PATH
2084 \end_inset 
2085 </cell>
2086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2087 \begin_inset Text
2088
2089 \layout Standard
2090
2091 $PATH
2092 \end_inset 
2093 </cell>
2094 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2095 \begin_inset Text
2096
2097 \layout Standard
2098
2099 $PATH
2100 \end_inset 
2101 </cell>
2102 </row>
2103 </lyxtabular>
2104
2105 \end_inset 
2106
2107  
2108 \newline 
2109
2110 \layout Standard
2111 \noindent 
2112 2.
2113  Include files
2114 \newline 
2115
2116 \layout Standard
2117 \align center 
2118
2119 \begin_inset  Tabular
2120 <lyxtabular version="3" rows="6" columns="3">
2121 <features>
2122 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2123 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2124 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2125 <row topline="true" bottomline="true">
2126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2127 \begin_inset Text
2128
2129 \layout Standard
2130
2131 Search path
2132 \end_inset 
2133 </cell>
2134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2135 \begin_inset Text
2136
2137 \layout Standard
2138
2139 default
2140 \end_inset 
2141 </cell>
2142 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2143 \begin_inset Text
2144
2145 \layout Standard
2146
2147 Win32 builds
2148 \end_inset 
2149 </cell>
2150 </row>
2151 <row topline="true">
2152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2153 \begin_inset Text
2154
2155 \layout Standard
2156
2157 -
2158 \begin_inset ERT
2159 status Collapsed
2160
2161 \layout Standard
2162
2163 \backslash 
2164 /
2165 \end_inset 
2166
2167 -I dir
2168 \end_inset 
2169 </cell>
2170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2171 \begin_inset Text
2172
2173 \layout Standard
2174
2175 -
2176 \begin_inset ERT
2177 status Collapsed
2178
2179 \layout Standard
2180
2181 \backslash 
2182 /
2183 \end_inset 
2184
2185 -I dir
2186 \end_inset 
2187 </cell>
2188 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2189 \begin_inset Text
2190
2191 \layout Standard
2192
2193 -
2194 \begin_inset ERT
2195 status Collapsed
2196
2197 \layout Standard
2198
2199 \backslash 
2200 /
2201 \end_inset 
2202
2203 -I dir
2204 \end_inset 
2205 </cell>
2206 </row>
2207 <row topline="true">
2208 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2209 \begin_inset Text
2210
2211 \layout Standard
2212
2213 $SDCC_INCLUDE
2214 \end_inset 
2215 </cell>
2216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2217 \begin_inset Text
2218
2219 \layout Standard
2220
2221 $SDCC_INCLUDE
2222 \end_inset 
2223 </cell>
2224 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2225 \begin_inset Text
2226
2227 \layout Standard
2228
2229 $SDCC_INCLUDE
2230 \end_inset 
2231 </cell>
2232 </row>
2233 <row topline="true">
2234 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2235 \begin_inset Text
2236
2237 \layout Standard
2238
2239 $SDCC_HOME/
2240 \newline 
2241
2242 \emph on 
2243 $PREFIX2DATA_DIR/
2244 \newline 
2245 $INCLUDE_DIR_SUFFIX
2246 \end_inset 
2247 </cell>
2248 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2249 \begin_inset Text
2250
2251 \layout Standard
2252
2253 $SDCC_ HOME/
2254 \newline 
2255 share/sdcc/
2256 \newline 
2257 include
2258 \end_inset 
2259 </cell>
2260 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2261 \begin_inset Text
2262
2263 \layout Standard
2264
2265 $SDCC_HOME
2266 \backslash 
2267 include
2268 \end_inset 
2269 </cell>
2270 </row>
2271 <row topline="true">
2272 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2273 \begin_inset Text
2274
2275 \layout Standard
2276
2277 path(argv[0])/
2278 \newline 
2279
2280 \emph on 
2281 $BIN2DATADIR/
2282 \emph default 
2283
2284 \newline 
2285
2286 \emph on 
2287 $INCLUDE_DIR_SUFFIX
2288 \end_inset 
2289 </cell>
2290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2291 \begin_inset Text
2292
2293 \layout Standard
2294
2295 path(argv[0])/
2296 \newline 
2297 ../sdcc/include
2298 \newline 
2299 \SpecialChar ~
2300 \SpecialChar ~
2301 \SpecialChar ~
2302 \SpecialChar ~
2303 \SpecialChar ~
2304 \SpecialChar ~
2305 \SpecialChar ~
2306 \SpecialChar ~
2307 \SpecialChar ~
2308 \SpecialChar ~
2309 \SpecialChar ~
2310 \SpecialChar ~
2311 \SpecialChar ~
2312 \SpecialChar ~
2313 \SpecialChar ~
2314 \SpecialChar ~
2315 \SpecialChar ~
2316 \SpecialChar ~
2317 \SpecialChar ~
2318 \SpecialChar ~
2319 \SpecialChar ~
2320 \SpecialChar ~
2321 \SpecialChar ~
2322 \SpecialChar ~
2323 \SpecialChar ~
2324 \SpecialChar ~
2325 \SpecialChar ~
2326 \SpecialChar ~
2327 \SpecialChar ~
2328 \SpecialChar ~
2329 \SpecialChar ~
2330 \SpecialChar ~
2331 \SpecialChar ~
2332 \SpecialChar ~
2333 \SpecialChar ~
2334 \SpecialChar ~
2335 \SpecialChar ~
2336 \SpecialChar ~
2337
2338 \end_inset 
2339 </cell>
2340 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2341 \begin_inset Text
2342
2343 \layout Standard
2344
2345 path(argv[0])
2346 \backslash 
2347 ..
2348 \backslash 
2349 include
2350 \end_inset 
2351 </cell>
2352 </row>
2353 <row topline="true" bottomline="true">
2354 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2355 \begin_inset Text
2356
2357 \layout Standard
2358
2359
2360 \emph on 
2361 $DATADIR/
2362 \emph default 
2363
2364 \newline 
2365
2366 \emph on 
2367 $INCLUDE_DIR_SUFFIX
2368 \end_inset 
2369 </cell>
2370 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2371 \begin_inset Text
2372
2373 \layout Standard
2374
2375 /usr/local/share/sdcc/
2376 \newline 
2377 include
2378 \end_inset 
2379 </cell>
2380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2381 \begin_inset Text
2382
2383 \layout Standard
2384
2385 (not on Win32)
2386 \end_inset 
2387 </cell>
2388 </row>
2389 </lyxtabular>
2390
2391 \end_inset 
2392
2393  
2394 \newline 
2395
2396 \layout Standard
2397 \noindent 
2398 The option -
2399 \begin_inset ERT
2400 status Collapsed
2401
2402 \layout Standard
2403
2404 \backslash 
2405 /
2406 \end_inset 
2407
2408 -nostdinc disables the last two search paths.
2409 \newline 
2410
2411 \newline 
2412 3.
2413  Library files 
2414 \newline 
2415
2416 \layout Standard
2417
2418 With the exception of 
2419 \begin_inset Quotes sld
2420 \end_inset 
2421
2422 -
2423 \begin_inset ERT
2424 status Collapsed
2425
2426 \layout Standard
2427
2428 \backslash 
2429 /
2430 \end_inset 
2431
2432 -L dir
2433 \begin_inset Quotes srd
2434 \end_inset 
2435
2436  the 
2437 \shape italic 
2438 model
2439 \shape default 
2440  is auto-appended by the compiler (e.g.
2441  small, large, z80, ds390 etc.).
2442  
2443 \newline 
2444
2445 \layout Standard
2446 \align center 
2447
2448 \begin_inset  Tabular
2449 <lyxtabular version="3" rows="6" columns="3">
2450 <features>
2451 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2452 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2453 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2454 <row topline="true" bottomline="true">
2455 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2456 \begin_inset Text
2457
2458 \layout Standard
2459
2460 Search path
2461 \end_inset 
2462 </cell>
2463 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2464 \begin_inset Text
2465
2466 \layout Standard
2467
2468 default
2469 \end_inset 
2470 </cell>
2471 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2472 \begin_inset Text
2473
2474 \layout Standard
2475
2476 Win32 builds
2477 \end_inset 
2478 </cell>
2479 </row>
2480 <row topline="true">
2481 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2482 \begin_inset Text
2483
2484 \layout Standard
2485
2486 -
2487 \begin_inset ERT
2488 status Collapsed
2489
2490 \layout Standard
2491
2492 \backslash 
2493 /
2494 \end_inset 
2495
2496 -L dir
2497 \end_inset 
2498 </cell>
2499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2500 \begin_inset Text
2501
2502 \layout Standard
2503
2504 -
2505 \begin_inset ERT
2506 status Collapsed
2507
2508 \layout Standard
2509
2510 \backslash 
2511 /
2512 \end_inset 
2513
2514 -L dir
2515 \end_inset 
2516 </cell>
2517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2518 \begin_inset Text
2519
2520 \layout Standard
2521
2522 -
2523 \begin_inset ERT
2524 status Collapsed
2525
2526 \layout Standard
2527
2528 \backslash 
2529 /
2530 \end_inset 
2531
2532 -L dir
2533 \end_inset 
2534 </cell>
2535 </row>
2536 <row topline="true">
2537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2538 \begin_inset Text
2539
2540 \layout Standard
2541
2542 $SDCC_LIB/
2543 \newline 
2544
2545 \emph on 
2546 <model>
2547 \end_inset 
2548 </cell>
2549 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2550 \begin_inset Text
2551
2552 \layout Standard
2553
2554 $SDCC_LIB/
2555 \newline 
2556
2557 \emph on 
2558 <model>
2559 \end_inset 
2560 </cell>
2561 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2562 \begin_inset Text
2563
2564 \layout Standard
2565
2566 $SDCC_LIB
2567 \backslash 
2568
2569 \newline 
2570
2571 \emph on 
2572 <model>
2573 \end_inset 
2574 </cell>
2575 </row>
2576 <row topline="true">
2577 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2578 \begin_inset Text
2579
2580 \layout Standard
2581
2582 $SDCC_HOME/
2583 \newline 
2584
2585 \emph on 
2586 $PREFIX2DATA_DIR/
2587 \newline 
2588 $LIB_DIR_SUFFIX/<model>
2589 \end_inset 
2590 </cell>
2591 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2592 \begin_inset Text
2593
2594 \layout Standard
2595
2596 $SDCC_HOME/
2597 \newline 
2598 share/sdcc/
2599 \newline 
2600 lib/
2601 \emph on 
2602 <model>
2603 \end_inset 
2604 </cell>
2605 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2606 \begin_inset Text
2607
2608 \layout Standard
2609
2610 $SDCC_HOME
2611 \backslash 
2612 lib
2613 \backslash 
2614
2615 \emph on 
2616
2617 \newline 
2618 <model>
2619 \end_inset 
2620 </cell>
2621 </row>
2622 <row topline="true">
2623 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2624 \begin_inset Text
2625
2626 \layout Standard
2627
2628 path(argv[0])/
2629 \newline 
2630
2631 \emph on 
2632 $BIN2DATADIR/
2633 \emph default 
2634
2635 \newline 
2636
2637 \emph on 
2638 $LIB_DIR_SUFFIX/<model>
2639 \end_inset 
2640 </cell>
2641 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2642 \begin_inset Text
2643
2644 \layout Standard
2645
2646 path(argv[0])/
2647 \newline 
2648 ../sdcc/lib/
2649 \emph on 
2650 <model>
2651 \newline 
2652 \SpecialChar ~
2653 \SpecialChar ~
2654 \SpecialChar ~
2655 \SpecialChar ~
2656 \SpecialChar ~
2657 \SpecialChar ~
2658 \SpecialChar ~
2659 \SpecialChar ~
2660 \SpecialChar ~
2661 \SpecialChar ~
2662 \SpecialChar ~
2663 \SpecialChar ~
2664 \SpecialChar ~
2665 \SpecialChar ~
2666 \SpecialChar ~
2667 \SpecialChar ~
2668 \SpecialChar ~
2669 \SpecialChar ~
2670 \SpecialChar ~
2671 \SpecialChar ~
2672 \SpecialChar ~
2673 \SpecialChar ~
2674 \SpecialChar ~
2675 \SpecialChar ~
2676 \SpecialChar ~
2677 \SpecialChar ~
2678 \SpecialChar ~
2679 \SpecialChar ~
2680 \SpecialChar ~
2681 \SpecialChar ~
2682 \SpecialChar ~
2683 \SpecialChar ~
2684 \SpecialChar ~
2685 \SpecialChar ~
2686 \SpecialChar ~
2687 \SpecialChar ~
2688 \SpecialChar ~
2689 \SpecialChar ~
2690 \SpecialChar ~
2691
2692 \end_inset 
2693 </cell>
2694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2695 \begin_inset Text
2696
2697 \layout Standard
2698
2699 path(argv[0])
2700 \backslash 
2701
2702 \newline 
2703 ..
2704 \backslash 
2705 lib
2706 \backslash 
2707
2708 \emph on 
2709 <model>
2710 \newline 
2711 \SpecialChar ~
2712 \SpecialChar ~
2713 \SpecialChar ~
2714 \SpecialChar ~
2715 \SpecialChar ~
2716 \SpecialChar ~
2717 \SpecialChar ~
2718 \SpecialChar ~
2719 \SpecialChar ~
2720 \SpecialChar ~
2721 \SpecialChar ~
2722 \SpecialChar ~
2723 \SpecialChar ~
2724 \SpecialChar ~
2725 \SpecialChar ~
2726 \SpecialChar ~
2727 \SpecialChar ~
2728 \SpecialChar ~
2729 \SpecialChar ~
2730 \SpecialChar ~
2731 \SpecialChar ~
2732 \SpecialChar ~
2733 \SpecialChar ~
2734 \SpecialChar ~
2735 \SpecialChar ~
2736 \SpecialChar ~
2737 \SpecialChar ~
2738 \SpecialChar ~
2739 \SpecialChar ~
2740 \SpecialChar ~
2741 \SpecialChar ~
2742 \SpecialChar ~
2743 \SpecialChar ~
2744 \SpecialChar ~
2745 \SpecialChar ~
2746
2747 \end_inset 
2748 </cell>
2749 </row>
2750 <row topline="true" bottomline="true">
2751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2752 \begin_inset Text
2753
2754 \layout Standard
2755
2756
2757 \emph on 
2758 $DATADIR/
2759 \newline 
2760 $LIB_DIR_SUFFIX/<model>
2761 \end_inset 
2762 </cell>
2763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2764 \begin_inset Text
2765
2766 \layout Standard
2767
2768 /usr/local/share/sdcc/
2769 \newline 
2770 lib/
2771 \emph on 
2772 <model>
2773 \end_inset 
2774 </cell>
2775 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2776 \begin_inset Text
2777
2778 \layout Standard
2779
2780 (not on Win32)
2781 \end_inset 
2782 </cell>
2783 </row>
2784 </lyxtabular>
2785
2786 \end_inset 
2787
2788
2789 \newline 
2790
2791 \layout Comment
2792
2793 Don't delete any of the stray spaces in the table above without checking
2794  the HTML output (last line)!
2795 \layout Standard
2796
2797 \SpecialChar ~
2798
2799 \newline 
2800 The option -
2801 \begin_inset ERT
2802 status Collapsed
2803
2804 \layout Standard
2805
2806 \backslash 
2807 /
2808 \end_inset 
2809
2810 -nostdlib disables the last two search paths.
2811 \layout Section
2812
2813 Building SDCC
2814 \begin_inset LatexCommand \index{Building SDCC}
2815
2816 \end_inset 
2817
2818
2819 \layout Subsection
2820
2821 Building SDCC on Linux
2822 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
2823
2824 \end_inset 
2825
2826
2827 \layout Enumerate
2828
2829
2830 \series medium 
2831 Download the source package
2832 \series default 
2833  either from the SDCC CVS repository or from the nightly snapshots
2834 \series medium 
2835 , it will be named something like sdcc
2836 \series default 
2837 .src
2838 \series medium 
2839 .t
2840 \series default 
2841 ar.
2842 \series medium 
2843 gz
2844 \series default 
2845  
2846 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
2847
2848 \end_inset 
2849
2850 .
2851 \layout Enumerate
2852
2853
2854 \series medium 
2855 Bring up a command line terminal, such as xterm.
2856 \layout Enumerate
2857
2858
2859 \series medium 
2860 Unpack the file using a command like: 
2861 \family sans 
2862 \series bold 
2863 "tar -xvzf sdcc.src.tar.gz
2864 \family default 
2865 \series default 
2866 "
2867 \series medium 
2868 , this will create a sub-directory called sdcc with all of the sources.
2869 \layout Enumerate
2870
2871 Change directory into the main SDCC directory, for example type: 
2872 \family sans 
2873 \series bold 
2874 "cd sdcc
2875 \series default 
2876 ".
2877 \layout Enumerate
2878
2879
2880 \series medium 
2881 Type 
2882 \family sans 
2883 \series bold 
2884 "./configure
2885 \family default 
2886 \series default 
2887 ".
2888  This configures the package for compilation on your system.
2889 \layout Enumerate
2890
2891
2892 \series medium 
2893 Type 
2894 \family sans 
2895 \series bold 
2896 "make
2897 \family default 
2898 \series default 
2899 "
2900 \series medium 
2901 .
2902
2903 \series default 
2904  All of the source packages will compile, this can take a while.
2905 \layout Enumerate
2906
2907
2908 \series medium 
2909 Type 
2910 \family sans 
2911 \series bold 
2912 "make install"
2913 \family default 
2914 \series default 
2915  as root
2916 \series medium 
2917 .
2918
2919 \series default 
2920  This copies the binary executables, the include files, the libraries and
2921  the documentation to the install directories.
2922  Proceed with section 
2923 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
2924
2925 \end_inset 
2926
2927 .
2928 \layout Subsection
2929
2930 Building SDCC on OSX 2.x
2931 \layout Standard
2932
2933 Follow the instruction for Linux.
2934 \newline 
2935
2936 \newline 
2937 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
2938 )) fails to compile SDCC.
2939  Fortunately there's also gcc 2.9.x installed, which works fine.
2940  This compiler can be selected by running 'configure' with:
2941 \layout LyX-Code
2942
2943 ./configure CC=gcc2 CXX=g++2
2944 \layout Subsection
2945
2946 Cross compiling SDCC on Linux for Windows
2947 \layout Standard
2948
2949 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
2950  See section 'Configure Options'.
2951 \layout Subsection
2952
2953 Building SDCC on Windows 
2954 \layout Standard
2955
2956 With the exception of Cygwin the SDCC binaries uCsim and sdcdb can't be
2957  built on Windows.
2958  They use Unix-sockets, which are not available on Win32.
2959 \layout Subsection
2960
2961 Building SDCC using Cygwin and Mingw32
2962 \layout Standard
2963
2964 For building and installing a Cygwin executable follow the instructions
2965  for Linux.
2966 \newline 
2967
2968 \newline 
2969 On Cygwin a 
2970 \begin_inset Quotes sld
2971 \end_inset 
2972
2973 native
2974 \begin_inset Quotes srd
2975 \end_inset 
2976
2977  Win32-binary can be built, which will not need the Cygwin-DLL.
2978  For the necessary 'configure' options see section 'configure options' or
2979  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
2980 \newline 
2981
2982 \newline 
2983 In order to install Cygwin on Windows download setup.exe from 
2984 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
2985
2986 \end_inset 
2987
2988 .
2989  Run it, set the 
2990 \begin_inset Quotes sld
2991 \end_inset 
2992
2993 default text file type
2994 \begin_inset Quotes srd
2995 \end_inset 
2996
2997  to 
2998 \begin_inset Quotes sld
2999 \end_inset 
3000
3001 unix
3002 \begin_inset Quotes srd
3003 \end_inset 
3004
3005  and download/install at least the following packages.
3006  Some packages are selected by default, others will be automatically selected
3007  because of dependencies with the manually selected packages.
3008  Never deselect these packages!
3009 \layout Itemize
3010
3011 flex
3012 \layout Itemize
3013
3014 bison
3015 \layout Itemize
3016
3017 gcc ; version 3.x is fine, no need to use the old 2.9x
3018 \layout Itemize
3019
3020 binutils ; selected with gcc
3021 \layout Itemize
3022
3023 make
3024 \layout Itemize
3025
3026 rxvt ; a nice console, which makes life much easier under windoze (see below)
3027 \layout Itemize
3028
3029 man ; not really needed for building SDCC, but you'll miss it sooner or
3030  later
3031 \layout Itemize
3032
3033 less ; not really needed for building SDCC, but you'll miss it sooner or
3034  later
3035 \layout Itemize
3036
3037 cvs ; only if you use CVS access
3038 \layout Standard
3039
3040 If you want to develop something you'll need:
3041 \layout Itemize
3042
3043 python ; for the regression tests
3044 \layout Itemize
3045
3046 gdb ; the gnu debugger, together with the nice GUI 
3047 \begin_inset Quotes sld
3048 \end_inset 
3049
3050 insight
3051 \begin_inset Quotes srd
3052 \end_inset 
3053
3054
3055 \layout Itemize
3056
3057 openssh ; to access the CF or commit changes
3058 \layout Itemize
3059
3060 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3061  use autoconf-stable!
3062 \layout Standard
3063
3064 rxvt is a nice console with history.
3065  Replace in your cygwin.bat the line
3066 \layout LyX-Code
3067
3068 bash -
3069 \begin_inset ERT
3070 status Collapsed
3071
3072 \layout Standard
3073
3074 \backslash 
3075 /
3076 \end_inset 
3077
3078 -login -i 
3079 \layout Standard
3080
3081 with (one line):
3082 \layout LyX-Code
3083
3084 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3085 \layout LyX-Code
3086
3087      -bg black -fg white -geometry 100x65 -e bash -
3088 \begin_inset ERT
3089 status Collapsed
3090
3091 \layout Standard
3092
3093 \backslash 
3094 /
3095 \end_inset 
3096
3097 -login
3098 \layout Standard
3099
3100 Text selected with the mouse is automatically copied to the clipboard, pasting
3101  works with shift-insert.
3102 \newline 
3103
3104 \newline 
3105 The other good tip is to make sure you have no //c/-style paths anywhere,
3106  use /cygdrive/c/ instead.
3107  Using // invokes a network lookup which is very slow.
3108  If you think 
3109 \begin_inset Quotes sld
3110 \end_inset 
3111
3112 cygdrive
3113 \begin_inset Quotes srd
3114 \end_inset 
3115
3116  is too long, you can change it with e.g.
3117 \layout LyX-Code
3118
3119 mount -s -u -c /mnt
3120 \layout Standard
3121
3122 SDCC sources use the unix line ending LF.
3123  Life is much easier, if you store the source tree on a drive which is mounted
3124  in binary mode.
3125  And use an editor which can handle LF-only line endings.
3126  Make sure not to commit files with windows line endings.
3127  The tabulator spacing
3128 \begin_inset LatexCommand \index{tabulator spacing (8)}
3129
3130 \end_inset 
3131
3132  used in the project is 8.
3133 \layout Subsection
3134
3135 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3136 \layout Standard
3137
3138
3139 \series medium 
3140 Download the source package
3141 \series default 
3142  either from the SDCC CVS repository or from the 
3143 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3144
3145 \end_inset 
3146
3147
3148 \series medium 
3149 , it will be named something like sdcc
3150 \series default 
3151 .src
3152 \series medium 
3153 .tgz.
3154
3155 \series default 
3156  SDCC is distributed with all the projects, workspaces, and files you need
3157  to build it using Visual C++ 6.0/NET (except for sdcdb.exe which currently
3158  doesn't build under MSVC).
3159  The workspace name is 'sdcc.dsw'.
3160  Please note that as it is now, all the executables are created in a folder
3161  called sdcc
3162 \backslash 
3163 bin_vc.
3164  Once built you need to copy the executables from sdcc
3165 \backslash 
3166 bin_vc to sdcc
3167 \backslash 
3168 bin before running SDCC.
3169  
3170 \newline 
3171
3172 \newline 
3173 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3174  flex.exe, and gawk.exe.
3175  One good place to get them is 
3176 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3177
3178 \end_inset 
3179
3180
3181 \newline 
3182
3183 \newline 
3184 Download the file UnxUtils
3185 \begin_inset LatexCommand \index{UnxUtils}
3186
3187 \end_inset 
3188
3189 .zip.
3190  Now you have to install the utilities and setup MSVC so it can locate the
3191  required programs.
3192  Here there are two alternatives (choose one!):
3193 \layout Enumerate
3194
3195 The easy way:
3196 \newline 
3197
3198 \newline 
3199 a) Extract UnxUtils.zip to your C:
3200 \backslash 
3201  hard disk PRESERVING the original paths, otherwise bison won't work.
3202  (If you are using WinZip make certain that 'Use folder names' is selected)
3203 \newline 
3204
3205 \newline 
3206 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3207  in 'Show directories for:' select 'Executable files', and in the directories
3208  window add a new path: 'C:
3209 \backslash 
3210 user
3211 \backslash 
3212 local
3213 \backslash 
3214 wbin', click ok.
3215 \newline 
3216
3217 \newline 
3218 (As a side effect, you get a bunch of Unix utilities that could be useful,
3219  such as diff and patch.)
3220 \layout Enumerate
3221
3222 A more compact way:
3223 \newline 
3224
3225 \newline 
3226 This one avoids extracting a bunch of files you may not use, but requires
3227  some extra work:
3228 \newline 
3229
3230 \newline 
3231 a) Create a directory were to put the tools needed, or use a directory already
3232  present.
3233  Say for example 'C:
3234 \backslash 
3235 util'.
3236 \newline 
3237
3238 \newline 
3239 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3240  to such directory WITHOUT preserving the original paths.
3241  (If you are using WinZip make certain that 'Use folder names' is not selected)
3242 \newline 
3243
3244 \newline 
3245 c) Rename bison.exe to '_bison.exe'.
3246 \newline 
3247
3248 \newline 
3249 d) Create a batch file 'bison.bat' in 'C:
3250 \backslash 
3251 util
3252 \backslash 
3253 ' and add these lines: 
3254 \newline 
3255 \SpecialChar ~
3256 \SpecialChar ~
3257 set BISON_SIMPLE=C:
3258 \backslash 
3259 util
3260 \backslash 
3261 bison.simple 
3262 \newline 
3263 \SpecialChar ~
3264 \SpecialChar ~
3265 set BISON_HAIRY=C:
3266 \backslash 
3267 util
3268 \backslash 
3269 bison.hairy
3270 \newline 
3271 \SpecialChar ~
3272 \SpecialChar ~
3273 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3274 \newline 
3275
3276 \newline 
3277 Steps 'c' and 'd' are needed because bison requires by default that the
3278  files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3279  '/usr/local/share/' I think.
3280  So it is necessary to tell bison where those files are located if they
3281  are not in such directory.
3282  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3283 \newline 
3284
3285 \newline 
3286 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3287  in 'Show directories for:' select 'Executable files', and in the directories
3288  window add a new path: 'c:
3289 \backslash 
3290 util', click ok.
3291  Note that you can use any other path instead of 'c:
3292 \backslash 
3293 util', even the path where the Visual C++ tools are, probably: 'C:
3294 \backslash 
3295 Program Files
3296 \backslash 
3297 Microsoft Visual Studio
3298 \backslash 
3299 Common
3300 \backslash 
3301 Tools'.
3302  So you don't have to execute step 'e' :)
3303 \layout Standard
3304
3305 That is it.
3306  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3307  the executables from sdcc
3308 \backslash 
3309 bin_vc to sdcc
3310 \backslash 
3311 bin, and you can compile using SDCC.
3312 \layout Subsection
3313
3314 Building SDCC Using Borland
3315 \layout Enumerate
3316
3317 From the sdcc directory, run the command "make -f Makefile.bcc".
3318  This should regenerate all the .exe files in the bin directory except for
3319  sdcdb.exe (which currently doesn't build under Borland C++).
3320 \layout Enumerate
3321
3322 If you modify any source files and need to rebuild, be aware that the dependenci
3323 es may not be correctly calculated.
3324  The safest option is to delete all .obj files and run the build again.
3325  From a Cygwin BASH prompt, this can easily be done with the command (be
3326  sure you are in the sdcc directory):
3327 \newline 
3328
3329 \newline 
3330
3331 \family sans 
3332 \series bold 
3333 find .
3334  
3335 \backslash 
3336 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
3337 \backslash 
3338 ) -print -exec rm {} 
3339 \backslash 
3340 ;
3341 \family default 
3342 \series default 
3343
3344 \newline 
3345
3346 \newline 
3347 or on Windows NT/2000/XP from the command prompt with the command:
3348 \newline 
3349
3350 \family sans 
3351 \series bold 
3352
3353 \newline 
3354 del /s *.obj *.lib *.rul
3355 \family default 
3356 \series default 
3357  from the sdcc directory.
3358 \layout Subsection
3359
3360 Windows Install Using a Binary Package
3361 \begin_inset LatexCommand \label{sub:Windows-Install}
3362
3363 \end_inset 
3364
3365
3366 \layout Enumerate
3367
3368 Download the binary package from 
3369 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3370
3371 \end_inset 
3372
3373  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
3374  This should unpack to a group of sub-directories.
3375  An example directory structure after unpacking the mingw32 package is:
3376  c:
3377 \backslash 
3378 sdcc
3379 \backslash 
3380 bin for the executables, c:
3381 \backslash 
3382 sdcc
3383 \backslash 
3384 include and c:
3385 \backslash 
3386 sdcc
3387 \backslash 
3388 lib for the include and libraries.
3389 \layout Enumerate
3390
3391 Adjust your environment variable PATH to include the location of the bin
3392  directory or start sdcc using the full path.
3393 \layout Section
3394
3395 Building the Documentation
3396 \layout Standard
3397
3398 If the necessary tools (LyX, LaTeX, LaTeX2HTML) are installed it is as easy
3399  as changing into the doc directory and typing 
3400 \family sans 
3401 \series bold 
3402
3403 \begin_inset Quotes srd
3404 \end_inset 
3405
3406 make
3407 \begin_inset Quotes srd
3408 \end_inset 
3409
3410
3411 \family default 
3412 \series default 
3413  there.
3414  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
3415 x).
3416  Using LyX 
3417 \begin_inset LatexCommand \url{www.lyx.org}
3418
3419 \end_inset 
3420
3421  as editor this is straightforward.
3422  If you want to avoid installing the tools you will have some success with
3423  a bootable Knoppix CD 
3424 \begin_inset LatexCommand \url{http://www.knoppix.net}
3425
3426 \end_inset 
3427
3428 .
3429  Prebuilt documentation in html and pdf format is available from 
3430 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3431
3432 \end_inset 
3433
3434 .
3435 \layout Section
3436
3437 Reading the Documentation
3438 \layout Standard
3439
3440 Currently reading the document in pdf format is recommended, as for unknown
3441  reason the hyperlinks are working there whereas in the html version they
3442  are not
3443 \begin_inset Foot
3444 collapsed false
3445
3446 \layout Standard
3447
3448 If you should know why please drop us a note
3449 \end_inset 
3450
3451 .
3452  You'll find the pdf version at 
3453 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
3454
3455 \end_inset 
3456
3457 .
3458 \newline 
3459 This documentation is in some aspects different from a commercial documentation:
3460  
3461 \layout Itemize
3462
3463 It tries to document SDCC for several processor architectures in one document
3464  (commercially these probably would be separate documents/products).
3465  This document
3466 \begin_inset LatexCommand \index{Status of documentation}
3467
3468 \end_inset 
3469
3470  currently matches SDCC for mcs51 and DS390 best and does give too few informati
3471 on about f.e.
3472  Z80, PIC and HC08.
3473 \layout Itemize
3474
3475 There are many references pointing away from this documentation.
3476  Don't let this distract you.
3477  If there f.e.
3478  was a reference like 
3479 \begin_inset LatexCommand \url{www.opencores.org}
3480
3481 \end_inset 
3482
3483  together with a statement 
3484 \begin_inset Quotes sld
3485 \end_inset 
3486
3487 some processors which are targetted by SDCC can be implemented in a 
3488 \emph on 
3489 f
3490 \emph default 
3491 ield 
3492 \emph on 
3493 p
3494 \emph default 
3495 rogrammable 
3496 \emph on 
3497 g
3498 \emph default 
3499 ate 
3500 \emph on 
3501 a
3502 \emph default 
3503 rray
3504 \begin_inset LatexCommand \index{fpga (field programmable gate array)}
3505
3506 \end_inset 
3507
3508
3509 \begin_inset Quotes srd
3510 \end_inset 
3511
3512  we expect you to have a quick look there and come back.
3513  If you read this you are on the right track.
3514 \layout Itemize
3515
3516 Some sections attribute more space to problems, restrictions and warnings
3517  than to the solution.
3518 \layout Itemize
3519
3520 The installation section and the section about the debugger is intimidating.
3521 \layout Itemize
3522
3523 There are still lots of typos and there are more different writing styles
3524  than pictures.
3525 \layout Section
3526
3527 Testing the SDCC Compiler
3528 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
3529
3530 \end_inset 
3531
3532
3533 \layout Standard
3534
3535 The first thing you should do after installing your SDCC compiler is to
3536  see if it runs.
3537  Type 
3538 \family sans 
3539 \series bold 
3540 "sdcc -
3541 \begin_inset ERT
3542 status Collapsed
3543
3544 \layout Standard
3545
3546 \backslash 
3547 /
3548 \end_inset 
3549
3550 -version"
3551 \begin_inset LatexCommand \index{version}
3552
3553 \end_inset 
3554
3555
3556 \family default 
3557 \series default 
3558  at the prompt, and the program should run and tell you the version.
3559  If it doesn't run, or gives a message about not finding sdcc program, then
3560  you need to check over your installation.
3561  Make sure that the sdcc bin directory is in your executable search path
3562  defined by the PATH environment setting (
3563 \series medium 
3564 see 
3565 \series default 
3566 section 
3567 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3568
3569 \end_inset 
3570
3571 \SpecialChar ~
3572
3573 \series medium 
3574 Install trouble-shooting for suggestions
3575 \series default 
3576 ).
3577  Make sure that the sdcc program is in the bin folder, if not perhaps something
3578  did not install correctly.
3579 \newline 
3580
3581 \newline 
3582
3583 \series medium 
3584 SDCC 
3585 \series default 
3586 is commonly installed as described in section 
3587 \begin_inset Quotes sld
3588 \end_inset 
3589
3590 Install and search paths
3591 \begin_inset Quotes srd
3592 \end_inset 
3593
3594 .
3595 \newline 
3596
3597 \newline 
3598
3599 \series medium 
3600 Make sure the compiler works on a very simple example.
3601  Type in the following test.c program using your favorite 
3602 \series default 
3603 ASCII 
3604 \series medium 
3605 editor:
3606 \layout Verse
3607
3608
3609 \family typewriter 
3610 char test;
3611 \newline 
3612
3613 \newline 
3614 void main(void) {
3615 \newline 
3616 \SpecialChar ~
3617 \SpecialChar ~
3618 \SpecialChar ~
3619 \SpecialChar ~
3620 test=0;
3621 \newline 
3622 }
3623 \layout Standard
3624
3625
3626 \series medium 
3627 Compile this using the following command: 
3628 \family sans 
3629 \series bold 
3630 "sdcc -c test.c".
3631
3632 \family default 
3633 \series default 
3634  
3635 \series medium 
3636 If all goes well, the compiler will generate a test.asm and test.rel file.
3637  Congratulations, you've just compiled your first program with SDCC.
3638  We used the -c option to tell SDCC not to link the generated code, just
3639  to keep things simple for this step.
3640 \series default 
3641
3642 \newline 
3643
3644 \newline 
3645
3646 \series medium 
3647 The next step is to try it with the linker.
3648  Type in 
3649 \family sans 
3650 \series bold 
3651 "sdcc test.c
3652 \family default 
3653 \series default 
3654 "
3655 \series medium 
3656 .
3657  If all goes well the compiler will link with the libraries and produce
3658  a test.ihx output file.
3659  If this step fails
3660 \series default 
3661  
3662 \series medium 
3663 (no test.ihx, and the linker generates warnings), then the problem is most
3664  likely that 
3665 \series default 
3666 SDCC
3667 \series medium 
3668  cannot find the 
3669 \series default 
3670 /
3671 \series medium 
3672 usr/local/share/sdcc/lib directory
3673 \series default 
3674  
3675 \series medium 
3676 (see 
3677 \series default 
3678 section 
3679 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3680
3681 \end_inset 
3682
3683 \SpecialChar ~
3684
3685 \series medium 
3686 Install trouble-shooting for suggestions).
3687 \series default 
3688
3689 \newline 
3690
3691 \newline 
3692
3693 \series medium 
3694 The final test is to ensure 
3695 \series default 
3696 SDCC
3697 \series medium 
3698  can use the 
3699 \series default 
3700 standard
3701 \series medium 
3702  header files and libraries.
3703  Edit test.c and change it to the following:
3704 \layout Verse
3705
3706
3707 \family typewriter 
3708 #include <string.h>
3709 \newline 
3710
3711 \newline 
3712 char str1[10];
3713 \newline 
3714
3715 \newline 
3716 void main(void) {
3717 \newline 
3718 \SpecialChar ~
3719 \SpecialChar ~
3720 strcpy(str1, "testing");
3721 \newline 
3722 }
3723 \layout Standard
3724
3725
3726 \series medium 
3727 Compile this by typing 
3728 \family sans 
3729 \series bold 
3730 "sdcc test.c"
3731 \family default 
3732 \series medium 
3733 .
3734  This should generate a test.ihx output file, and it should give no warnings
3735  such as not finding the string.h file.
3736  If it cannot find the string.h file, then the problem is that 
3737 \series default 
3738 SDCC
3739 \series medium 
3740  cannot find the /usr/local/share/sdcc/include directory
3741 \series default 
3742  
3743 \series medium 
3744 (see the 
3745 \series default 
3746 section 
3747 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3748
3749 \end_inset 
3750
3751 \SpecialChar ~
3752
3753 \series medium 
3754 Install trouble-shooting section for suggestions).
3755
3756 \series default 
3757  Use option 
3758 \series bold 
3759 -
3760 \begin_inset ERT
3761 status Collapsed
3762
3763 \layout Standard
3764
3765 \backslash 
3766 /
3767 \end_inset 
3768
3769 -print-search-dirs
3770 \series default 
3771
3772 \begin_inset LatexCommand \index{-\/-print-search-dirs}
3773
3774 \end_inset 
3775
3776  to find exactly where SDCC is looking for the include and lib files.
3777 \layout Section
3778
3779 Install Trouble-shooting
3780 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
3781
3782 \end_inset 
3783
3784
3785 \begin_inset LatexCommand \index{Install trouble-shooting}
3786
3787 \end_inset 
3788
3789
3790 \layout Subsection
3791
3792 If SDCC does not build correctly
3793 \layout Standard
3794
3795 A thing to try is starting from scratch by unpacking the .tgz source package
3796  again in an empty directory.
3797  Configure it like:
3798 \newline 
3799
3800 \newline 
3801
3802 \family sans 
3803 \series bold 
3804 ./configure 2>&1 | tee configure.log
3805 \family default 
3806 \series default 
3807
3808 \newline 
3809
3810 \newline 
3811 and build it like:
3812 \newline 
3813
3814 \newline 
3815
3816 \family sans 
3817 \series bold 
3818 make 2>&1 | tee make.log
3819 \family default 
3820 \series default 
3821
3822 \newline 
3823
3824 \newline 
3825 If anything goes wrong, you can review the log files to locate the problem.
3826  Or a relevant part of this can be attached to an email that could be helpful
3827  when requesting help from the mailing list.
3828 \layout Subsection
3829
3830 What the 
3831 \begin_inset Quotes sld
3832 \end_inset 
3833
3834 ./configure
3835 \begin_inset Quotes srd
3836 \end_inset 
3837
3838  does
3839 \layout Standard
3840
3841 The 
3842 \begin_inset Quotes sld
3843 \end_inset 
3844
3845 ./configure
3846 \begin_inset Quotes srd
3847 \end_inset 
3848
3849  command is a script that analyzes your system and performs some configuration
3850  to ensure the source package compiles on your system.
3851  It will take a few minutes to run, and will compile a few tests to determine
3852  what compiler features are installed.
3853 \layout Subsection
3854
3855 What the 
3856 \begin_inset Quotes sld
3857 \end_inset 
3858
3859 make
3860 \begin_inset Quotes srd
3861 \end_inset 
3862
3863  does
3864 \layout Standard
3865
3866 This runs the GNU make tool, which automatically compiles all the source
3867  packages into the final installed binary executables.
3868 \layout Subsection
3869
3870 What the 
3871 \begin_inset Quotes sld
3872 \end_inset 
3873
3874 make install
3875 \begin_inset Quotes erd
3876 \end_inset 
3877
3878  command does.
3879 \layout Standard
3880
3881 This will install the compiler, other executables libraries and include
3882  files into the appropriate directories.
3883  See sections 
3884 \begin_inset LatexCommand \ref{sub:Install-paths}
3885
3886 \end_inset 
3887
3888 ,\SpecialChar ~
3889
3890 \begin_inset LatexCommand \ref{sub:Search-Paths}
3891
3892 \end_inset 
3893
3894 \SpecialChar ~
3895 about install and search paths.
3896 \newline 
3897 On most systems you will need super-user privileges to do this.
3898 \layout Section
3899
3900 Components of SDCC
3901 \layout Standard
3902
3903 SDCC is not just a compiler, but a collection of tools by various developers.
3904  These include linkers, assemblers, simulators and other components.
3905  Here is a summary of some of the components.
3906  Note that the included simulator and assembler have separate documentation
3907  which you can find in the source package in their respective directories.
3908  As SDCC grows to include support for other processors, other packages from
3909  various developers are included and may have their own sets of documentation.
3910 \newline 
3911
3912 \newline 
3913 You might want to look at the files which are installed in <installdir>.
3914  At the time of this writing, we find the following programs for gcc-builds:
3915 \newline 
3916  
3917 \newline 
3918 In <installdir>/bin:
3919 \layout Itemize
3920
3921 sdcc - The compiler.
3922 \layout Itemize
3923
3924 sdcpp - The C preprocessor.
3925 \layout Itemize
3926
3927 asx8051 - The assembler for 8051 type processors.
3928 \layout Itemize
3929
3930 as-z80
3931 \series bold 
3932
3933 \series default 
3934 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
3935 \layout Itemize
3936
3937 aslink -The linker for 8051 type processors.
3938 \layout Itemize
3939
3940 link-z80
3941 \series bold 
3942
3943 \series default 
3944 link-gbz80 - The Z80 and GameBoy Z80 linkers.
3945 \layout Itemize
3946
3947 s51 - The ucSim 8051 simulator.
3948 \layout Itemize
3949
3950 sdcdb - The source debugger.
3951 \layout Itemize
3952
3953 packihx - A tool to pack (compress) Intel hex files.
3954 \layout Standard
3955
3956 In <installdir>/share/sdcc/include
3957 \layout Itemize
3958
3959 the include files
3960 \layout Standard
3961
3962 In <installdir>/share/sdcc/lib
3963 \layout Itemize
3964
3965 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
3966  relocatables.
3967 \layout Standard
3968
3969 In <installdir>/share/sdcc/doc
3970 \layout Itemize
3971
3972 the documentation
3973 \layout Standard
3974
3975 As development for other processors proceeds, this list will expand to include
3976  executables to support processors like AVR, PIC, etc.
3977 \layout Subsection
3978
3979 sdcc - The Compiler
3980 \layout Standard
3981
3982 This is the actual compiler, it in turn uses the c-preprocessor and invokes
3983  the assembler and linkage editor.
3984 \layout Subsection
3985
3986 sdcpp - The C-Preprocessor
3987 \layout Standard
3988
3989 The preprocessor
3990 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
3991
3992 \end_inset 
3993
3994  is a modified version of the GNU preprocessor.
3995  The C preprocessor is used to pull in #include sources, process #ifdef
3996  statements, #defines and so on.
3997 \layout Subsection
3998
3999 as
4000 \emph on 
4001 xxxx
4002 \emph default 
4003 , aslink, link-
4004 \emph on 
4005 xxx
4006 \emph default 
4007  - The Assemblers and Linkage Editors
4008 \layout Standard
4009
4010 This is retargettable assembler & linkage editor, it was developed by Alan
4011  Baldwin.
4012  John Hartman created the version for 8051, and I (Sandeep) have made some
4013  enhancements and bug fixes for it to work properly with SDCC.
4014 \layout Subsection
4015
4016 s51 - The Simulator
4017 \layout Standard
4018
4019 S51
4020 \begin_inset LatexCommand \index{s51}
4021
4022 \end_inset 
4023
4024  is a freeware, opensource simulator developed by Daniel Drotos (
4025 \begin_inset LatexCommand \url{mailto:drdani@mazsola.iit.uni-miskolc.hu}
4026
4027 \end_inset 
4028
4029 ).
4030  The simulator is built as part of the build process.
4031  For more information visit Daniel's web site at: 
4032 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
4033
4034 \end_inset 
4035
4036 .
4037  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
4038  XA51 family.
4039 \layout Subsection
4040
4041 sdcdb - Source Level Debugger
4042 \layout Standard
4043
4044 Sdcdb
4045 \begin_inset LatexCommand \index{sdcdb (debugger)}
4046
4047 \end_inset 
4048
4049  is the companion source level debugger.
4050  More about sdcdb in section 
4051 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
4052
4053 \end_inset 
4054
4055 .
4056  The current version of the debugger uses Daniel's Simulator S51
4057 \begin_inset LatexCommand \index{s51}
4058
4059 \end_inset 
4060
4061 , but can be easily changed to use other simulators.
4062  
4063 \layout Chapter
4064
4065 Using SDCC
4066 \layout Section
4067
4068 Compiling
4069 \layout Subsection
4070
4071 Single Source File Projects
4072 \layout Standard
4073
4074 For single source file 8051 projects the process is very simple.
4075  Compile your programs with the following command 
4076 \family sans 
4077 \series bold 
4078 "sdcc sourcefile.c".
4079
4080 \family default 
4081 \series default 
4082  This will compile, assemble and link your source file.
4083  Output files are as follows:
4084 \layout Itemize
4085
4086 sourcefile.asm
4087 \begin_inset LatexCommand \index{<file>.asm}
4088
4089 \end_inset 
4090
4091  - Assembler source
4092 \begin_inset LatexCommand \index{Assembler source}
4093
4094 \end_inset 
4095
4096  file created by the compiler
4097 \layout Itemize
4098
4099 sourcefile.lst
4100 \begin_inset LatexCommand \index{<file>.lst}
4101
4102 \end_inset 
4103
4104  - Assembler listing
4105 \begin_inset LatexCommand \index{Assembler listing}
4106
4107 \end_inset 
4108
4109  file created by the Assembler
4110 \layout Itemize
4111
4112 sourcefile.rst
4113 \begin_inset LatexCommand \index{<file>.rst}
4114
4115 \end_inset 
4116
4117  - Assembler listing
4118 \begin_inset LatexCommand \index{Assembler listing}
4119
4120 \end_inset 
4121
4122  file updated with linkedit information, created by linkage editor
4123 \layout Itemize
4124
4125 sourcefile.sym
4126 \begin_inset LatexCommand \index{<file>.sym}
4127
4128 \end_inset 
4129
4130  - symbol listing
4131 \begin_inset LatexCommand \index{Symbol listing}
4132
4133 \end_inset 
4134
4135  for the sourcefile, created by the assembler
4136 \layout Itemize
4137
4138 sourcefile.rel
4139 \begin_inset LatexCommand \index{<file>.rel}
4140
4141 \end_inset 
4142
4143  or sourcefile.o
4144 \begin_inset LatexCommand \index{<file>.o}
4145
4146 \end_inset 
4147
4148  - Object file
4149 \begin_inset LatexCommand \index{Object file}
4150
4151 \end_inset 
4152
4153  created by the assembler, input to Linkage editor
4154 \layout Itemize
4155
4156 sourcefile.map
4157 \begin_inset LatexCommand \index{<file>.map}
4158
4159 \end_inset 
4160
4161  - The memory map
4162 \begin_inset LatexCommand \index{Memory map}
4163
4164 \end_inset 
4165
4166  for the load module, created by the Linker
4167 \layout Itemize
4168
4169 sourcefile.mem
4170 \begin_inset LatexCommand \index{<file>.mem}
4171
4172 \end_inset 
4173
4174  - A file with a summary of the memory usage
4175 \layout Itemize
4176
4177 sourcefile.ihx
4178 \begin_inset LatexCommand \index{<file>.ihx}
4179
4180 \end_inset 
4181
4182  - The load module in Intel hex format
4183 \begin_inset LatexCommand \index{Intel hex format}
4184
4185 \end_inset 
4186
4187  (you can select the Motorola S19 format
4188 \begin_inset LatexCommand \index{Motorola S19 format}
4189
4190 \end_inset 
4191
4192  with -
4193 \begin_inset ERT
4194 status Collapsed
4195
4196 \layout Standard
4197
4198 \backslash 
4199 /
4200 \end_inset 
4201
4202 -out-fmt-s19
4203 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
4204
4205 \end_inset 
4206
4207 .
4208  If you need another format you might want to use 
4209 \family sans 
4210 \shape italic 
4211 objdump
4212 \family default 
4213 \shape default 
4214
4215 \begin_inset LatexCommand \index{objdump (tool)}
4216
4217 \end_inset 
4218
4219  or
4220 \family sans 
4221 \shape italic 
4222  srecord
4223 \family default 
4224 \shape default 
4225
4226 \begin_inset LatexCommand \index{srecord (tool)}
4227
4228 \end_inset 
4229
4230 ).
4231  Both formats are documented in the documentation of srecord
4232 \begin_inset LatexCommand \index{srecord (tool)}
4233
4234 \end_inset 
4235
4236
4237 \layout Itemize
4238
4239 sourcefile.adb
4240 \begin_inset LatexCommand \index{<file>.adb}
4241
4242 \end_inset 
4243
4244  - An intermediate file containing debug information needed to create the
4245  .cdb file (with -
4246 \begin_inset ERT
4247 status Collapsed
4248
4249 \layout Standard
4250
4251 \backslash 
4252 /
4253 \end_inset 
4254
4255 -debug
4256 \begin_inset LatexCommand \index{-\/-debug}
4257
4258 \end_inset 
4259
4260
4261 \layout Itemize
4262
4263 sourcefile.cdb
4264 \begin_inset LatexCommand \index{<file>.cdb}
4265
4266 \end_inset 
4267
4268  - An optional file (with -
4269 \begin_inset ERT
4270 status Collapsed
4271
4272 \layout Standard
4273
4274 \backslash 
4275 /
4276 \end_inset 
4277
4278 -debug) containing debug information.
4279  The format is documented in cdbfileformat.pdf.
4280 \layout Itemize
4281
4282 sourcefile.
4283  - (no extension)
4284 \begin_inset LatexCommand \index{<file> (no extension)}
4285
4286 \end_inset 
4287
4288  An optional AOMF or AOMF51
4289 \begin_inset LatexCommand \index{AOMF, AOMF51}
4290
4291 \end_inset 
4292
4293  file containing debug information (generated with option -
4294 \begin_inset ERT
4295 status Collapsed
4296
4297 \layout Standard
4298
4299 \backslash 
4300 /
4301 \end_inset 
4302
4303 -debug).
4304  The (Intel)
4305 \emph on 
4306  a
4307 \emph default 
4308 bsolute 
4309 \emph on 
4310 o
4311 \emph default 
4312 bject 
4313 \emph on 
4314 m
4315 \emph default 
4316 odule 
4317 \emph on 
4318 f
4319 \emph default 
4320 ormat is commonly used by third party tools (debuggers
4321 \begin_inset LatexCommand \index{Debugger}
4322
4323 \end_inset 
4324
4325 , simulators, emulators)
4326 \layout Itemize
4327
4328 sourcefile.dump*
4329 \begin_inset LatexCommand \index{<file>.dump*}
4330
4331 \end_inset 
4332
4333  - Dump file to debug the compiler it self (generated with option -
4334 \begin_inset ERT
4335 status Collapsed
4336
4337 \layout Standard
4338
4339 \backslash 
4340 /
4341 \end_inset 
4342
4343 -dumpall) (see section 
4344 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
4345
4346 \end_inset 
4347
4348 \SpecialChar ~
4349  and section 
4350 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
4351
4352 \end_inset 
4353
4354 \SpecialChar ~
4355
4356 \begin_inset Quotes sld
4357 \end_inset 
4358
4359 Anatomy of the compiler
4360 \begin_inset Quotes srd
4361 \end_inset 
4362
4363 ).
4364 \layout Subsection
4365
4366 Projects with Multiple Source Files
4367 \layout Standard
4368
4369 SDCC can compile only ONE file at a time.
4370  Let us for example assume that you have a project containing the following
4371  files:
4372 \newline 
4373
4374 \newline 
4375 foo1.c (contains some functions)
4376 \newline 
4377 foo2.c (contains some more functions)
4378 \newline 
4379 foomain.c (contains more functions and the function main)
4380 \newline 
4381
4382 \size footnotesize 
4383
4384 \newline 
4385
4386 \size default 
4387 The first two files will need to be compiled separately with the commands:
4388 \size footnotesize 
4389  
4390 \size default 
4391
4392 \newline 
4393
4394 \newline 
4395
4396 \family sans 
4397 \series bold 
4398 sdcc\SpecialChar ~
4399 -c\SpecialChar ~
4400 foo1.c
4401 \family default 
4402 \series default 
4403 \size footnotesize 
4404
4405 \newline 
4406
4407 \family sans 
4408 \series bold 
4409 \size default 
4410 sdcc\SpecialChar ~
4411 -c\SpecialChar ~
4412 foo2.c
4413 \family default 
4414 \series default 
4415
4416 \newline 
4417
4418 \newline 
4419 Then compile the source file containing the 
4420 \emph on 
4421 main()
4422 \emph default 
4423  function and link
4424 \begin_inset LatexCommand \index{Linker}
4425
4426 \end_inset 
4427
4428  the files together with the following command: 
4429 \newline 
4430
4431 \newline 
4432
4433 \family sans 
4434 \series bold 
4435 sdcc\SpecialChar ~
4436 foomain.c\SpecialChar ~
4437 foo1.rel\SpecialChar ~
4438 foo2.rel
4439 \family default 
4440 \series default 
4441
4442 \begin_inset LatexCommand \index{<file>.rel}
4443
4444 \end_inset 
4445
4446
4447 \newline 
4448
4449 \newline 
4450 Alternatively, 
4451 \emph on 
4452 foomain.c 
4453 \emph default 
4454 can be separately compiled as well: 
4455 \family sans 
4456 \series bold 
4457
4458 \newline 
4459
4460 \newline 
4461 sdcc\SpecialChar ~
4462 -c\SpecialChar ~
4463 foomain.c
4464 \newline 
4465 sdcc foomain.rel foo1.rel foo2.rel
4466 \newline 
4467
4468 \newline 
4469
4470 \family default 
4471 \series default 
4472 The file containing the 
4473 \emph on 
4474 main()
4475 \emph default 
4476  function
4477 \emph on 
4478  
4479 \emph default 
4480 \noun on 
4481 must
4482 \noun default 
4483  be the 
4484 \noun on 
4485 first
4486 \noun default 
4487  file specified in the command line, since the linkage editor processes
4488  file in the order they are presented to it.
4489  The linker is invoked from SDCC using a script file with extension .lnk
4490 \begin_inset LatexCommand \index{<file>.lnk}
4491
4492 \end_inset 
4493
4494 .
4495  You can view this file to troubleshoot linking problems such as those arising
4496  from missing libraries.
4497 \layout Subsection
4498
4499 Projects with Additional Libraries
4500 \begin_inset LatexCommand \index{Libraries}
4501
4502 \end_inset 
4503
4504
4505 \layout Standard
4506
4507 Some reusable routines may be compiled into a library, see the documentation
4508  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
4509  for how to create a 
4510 \emph on 
4511 .lib
4512 \begin_inset LatexCommand \index{<file>.lib}
4513
4514 \end_inset 
4515
4516
4517 \emph default 
4518  library file.
4519  Libraries created in this manner can be included in the command line.
4520  Make sure you include the -L <library-path> option to tell the linker where
4521  to look for these files if they are not in the current directory.
4522  Here is an example, assuming you have the source file 
4523 \emph on 
4524 foomain.c
4525 \emph default 
4526  and a library
4527 \emph on 
4528  foolib.lib
4529 \emph default 
4530  in the directory 
4531 \emph on 
4532 mylib
4533 \emph default 
4534  (if that is not the same as your current project):
4535 \newline 
4536
4537 \newline 
4538
4539 \family sans 
4540 \series bold 
4541 sdcc foomain.c foolib.lib -L mylib
4542 \newline 
4543
4544 \newline 
4545
4546 \family default 
4547 \series default 
4548 Note here that
4549 \emph on 
4550  mylib
4551 \emph default 
4552  must be an absolute path name.
4553 \newline 
4554
4555 \newline 
4556 The most efficient way to use libraries is to keep separate modules in separate
4557  source files.
4558  The lib file now should name all the modules.rel
4559 \begin_inset LatexCommand \index{<file>.rel}
4560
4561 \end_inset 
4562
4563  files.
4564  For an example see the standard library file 
4565 \emph on 
4566 libsdcc.lib
4567 \emph default 
4568  in the directory <installdir>/share/lib/small.
4569 \layout Subsection
4570
4571 Using sdcclib to Create and Manage Libraries
4572 \begin_inset LatexCommand \index{sdcclib}
4573
4574 \end_inset 
4575
4576
4577 \layout Standard
4578
4579 Alternatively, instead of having a .rel file for each entry on the library
4580  file as described in the preceding section, sdcclib can be used to embed
4581  all the modules belonging to such library in the library file itself.
4582  This results in a larger library file, but it greatly reduces the number
4583  of disk files accessed by the linker.
4584   Additionally, the packed library file contains an index of all include
4585  modules and symbols that significantly speeds up the linking process.
4586  To display a list of options supported by sdcclib type:
4587 \newline 
4588
4589 \layout Standard
4590
4591
4592 \family sans 
4593 \series bold 
4594 sdcclib -?
4595 \begin_inset LatexCommand \index{sdcclib}
4596
4597 \end_inset 
4598
4599
4600 \newline 
4601
4602 \newline 
4603
4604 \family default 
4605 \series default 
4606 To create a new library file, start by compiling all the required modules.
4607  For example:
4608 \newline 
4609
4610 \layout Standard
4611
4612
4613 \series bold 
4614 sdcc -c _divsint.c
4615 \layout Standard
4616
4617
4618 \series bold 
4619 sdcc -c _divuint.c
4620 \layout Standard
4621
4622
4623 \series bold 
4624 sdcc -c _modsint.c
4625 \layout Standard
4626
4627
4628 \series bold 
4629 sdcc -c _moduint.c
4630 \layout Standard
4631
4632
4633 \series bold 
4634 sdcc -c _mulint.c
4635 \newline 
4636
4637 \layout Standard
4638
4639 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
4640  and _mulint.rel.
4641  The next step is to add the .rel files to the library file:
4642 \newline 
4643
4644 \layout Standard
4645
4646
4647 \series bold 
4648 sdcclib libint.lib _divsint.rel
4649 \begin_inset LatexCommand \index{sdcclib}
4650
4651 \end_inset 
4652
4653
4654 \layout Standard
4655
4656
4657 \series bold 
4658 sdcclib libint.lib _divuint.rel
4659 \layout Standard
4660
4661
4662 \series bold 
4663 sdcclib libint.lib _modsint.rel
4664 \layout Standard
4665
4666
4667 \series bold 
4668 sdcclib libint.lib _moduint.rel
4669 \layout Standard
4670
4671
4672 \series bold 
4673 sdcclib libint.lib _mulint.rel
4674 \series default 
4675
4676 \newline 
4677
4678 \layout Standard
4679
4680 If the file already exists in the library, it will be replaced.
4681  To see what modules and symbols are included in the library, options -s
4682  and -m are available.
4683  For example:
4684 \newline 
4685
4686 \newline 
4687
4688 \series bold 
4689 sdcclib -s libint.lib
4690 \begin_inset LatexCommand \index{sdcclib}
4691
4692 \end_inset 
4693
4694
4695 \newline 
4696 _divsint.rel:
4697 \layout Standard
4698
4699
4700 \series bold 
4701 __divsint_a_1_1
4702 \layout Standard
4703
4704
4705 \series bold 
4706 __divsint_PARM_2
4707 \layout Standard
4708
4709
4710 \series bold 
4711 __divsint
4712 \newline 
4713 _divuint.rel:
4714 \layout Standard
4715
4716
4717 \series bold 
4718 __divuint_a_1_1
4719 \layout Standard
4720
4721
4722 \series bold 
4723 __divuint_PARM_2
4724 \layout Standard
4725
4726
4727 \series bold 
4728 __divuint_reste_1_1
4729 \layout Standard
4730
4731
4732 \series bold 
4733 __divuint_count_1_1
4734 \layout Standard
4735
4736
4737 \series bold 
4738 __divuint
4739 \newline 
4740 _modsint.rel:
4741 \layout Standard
4742
4743
4744 \series bold 
4745 __modsint_a_1_1
4746 \layout Standard
4747
4748
4749 \series bold 
4750 __modsint_PARM_2
4751 \layout Standard
4752
4753
4754 \series bold 
4755 __modsint
4756 \newline 
4757 _moduint.rel:
4758 \layout Standard
4759
4760
4761 \series bold 
4762 __moduint_a_1_1
4763 \layout Standard
4764
4765
4766 \series bold 
4767 __moduint_PARM_2
4768 \layout Standard
4769
4770
4771 \series bold 
4772 __moduint_count_1_1
4773 \layout Standard
4774
4775
4776 \series bold 
4777 __moduint
4778 \newline 
4779 _mulint.rel:
4780 \layout Standard
4781
4782
4783 \series bold 
4784 __mulint_PARM_2
4785 \layout Standard
4786
4787
4788 \series bold 
4789 __mulint
4790 \newline 
4791
4792 \layout Standard
4793
4794 If the source files are compiled using --debug, the corresponding debug
4795  information file .adb will be include in the library file as well.
4796  The library files created with sdcclib are plain text files, so they can
4797  be viewed with a text editor.
4798  It is not recomended to modify a library file created with sdcclib using
4799  a text editor, as there are file indexes numbers located accross the file
4800  used by the linker to quickly locate the required module to link.
4801  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
4802  it can be safely deleted, since all the information required for linking
4803  is embedded in the library file itself.
4804  Library files created using sdcclib are used as described in the preceding
4805  sections.
4806 \layout Section
4807
4808 Command Line Options
4809 \begin_inset LatexCommand \index{Command Line Options}
4810
4811 \end_inset 
4812
4813
4814 \layout Subsection
4815
4816 Processor Selection Options
4817 \begin_inset LatexCommand \index{Options processor selection}
4818
4819 \end_inset 
4820
4821
4822 \begin_inset LatexCommand \index{Processor selection options}
4823
4824 \end_inset 
4825
4826
4827 \layout List
4828 \labelwidthstring 00.00.0000
4829
4830
4831 \series bold 
4832 -mmcs51
4833 \begin_inset LatexCommand \index{-mmcs51}
4834
4835 \end_inset 
4836
4837
4838 \series default 
4839  Generate code for the Intel MCS51
4840 \begin_inset LatexCommand \index{MCS51}
4841
4842 \end_inset 
4843
4844  family of processors.
4845  This is the default processor target.
4846 \layout List
4847 \labelwidthstring 00.00.0000
4848
4849
4850 \series bold 
4851 -mds390
4852 \begin_inset LatexCommand \index{-mds390}
4853
4854 \end_inset 
4855
4856
4857 \series default 
4858  Generate code for the Dallas DS80C390
4859 \begin_inset LatexCommand \index{DS80C390}
4860
4861 \end_inset 
4862
4863  processor.
4864 \layout List
4865 \labelwidthstring 00.00.0000
4866
4867
4868 \series bold 
4869 -mds400
4870 \begin_inset LatexCommand \index{-mds400}
4871
4872 \end_inset 
4873
4874
4875 \series default 
4876  Generate code for the Dallas DS80C400
4877 \begin_inset LatexCommand \index{DS80C400}
4878
4879 \end_inset 
4880
4881  processor.
4882 \layout List
4883 \labelwidthstring 00.00.0000
4884
4885
4886 \series bold 
4887 -mhc08
4888 \begin_inset LatexCommand \index{-mhc08}
4889
4890 \end_inset 
4891
4892
4893 \series default 
4894  Generate code for the Motorola HC08
4895 \begin_inset LatexCommand \index{HC08}
4896
4897 \end_inset 
4898
4899  family of processors (added Oct 2003).
4900 \layout List
4901 \labelwidthstring 00.00.0000
4902
4903
4904 \series bold 
4905 -mz80
4906 \begin_inset LatexCommand \index{-mz80}
4907
4908 \end_inset 
4909
4910
4911 \series default 
4912  Generate code for the Zilog Z80
4913 \begin_inset LatexCommand \index{Z80}
4914
4915 \end_inset 
4916
4917  family of processors.
4918 \layout List
4919 \labelwidthstring 00.00.0000
4920
4921
4922 \series bold 
4923 -mgbz80
4924 \begin_inset LatexCommand \index{-mgbz80}
4925
4926 \end_inset 
4927
4928
4929 \series default 
4930  Generate code for the GameBoy Z80
4931 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
4932
4933 \end_inset 
4934
4935  processor (Not actively maintained).
4936 \layout List
4937 \labelwidthstring 00.00.0000
4938
4939
4940 \series bold 
4941 -mavr
4942 \begin_inset LatexCommand \index{-mavr}
4943
4944 \end_inset 
4945
4946
4947 \series default 
4948  Generate code for the Atmel AVR
4949 \begin_inset LatexCommand \index{AVR}
4950
4951 \end_inset 
4952
4953  processor (In development, not complete).
4954  AVR users should probably have a look at avr-gcc 
4955 \begin_inset LatexCommand \url{ http://savannah.nongnu.org/download/avr-libc/snapshots/}
4956
4957 \end_inset 
4958
4959 .
4960 \layout Comment
4961
4962 I think it is fair to direct users there for now.
4963  Open source is also about avoiding unnecessary work .
4964  But I didn't find the 'official' link.
4965 \layout List
4966 \labelwidthstring 00.00.0000
4967
4968
4969 \series bold 
4970 -mpic14
4971 \begin_inset LatexCommand \index{-mpic14}
4972
4973 \end_inset 
4974
4975
4976 \series default 
4977  Generate code for the Microchip PIC 14
4978 \begin_inset LatexCommand \index{PIC14}
4979
4980 \end_inset 
4981
4982 -bit processors (p16f84 and variants.
4983  In development, not complete).
4984 \layout Comment
4985
4986 p16f627 p16f628 p16f84 p16f873 p16f877?
4987 \layout List
4988 \labelwidthstring 00.00.0000
4989
4990
4991 \series bold 
4992 -mpic16
4993 \begin_inset LatexCommand \index{-mpic16}
4994
4995 \end_inset 
4996
4997
4998 \series default 
4999  Generate code for the Microchip PIC 16
5000 \begin_inset LatexCommand \index{PIC16}
5001
5002 \end_inset 
5003
5004 -bit processors (p18f452 and variants.
5005  In development, not complete).
5006 \layout List
5007 \labelwidthstring 00.00.0000
5008
5009
5010 \series bold 
5011 -mtlcs900h
5012 \series default 
5013  Generate code for the Toshiba TLCS-900H
5014 \begin_inset LatexCommand \index{TLCS-900H}
5015
5016 \end_inset 
5017
5018  processor (Not maintained, not complete).
5019 \layout List
5020 \labelwidthstring 00.00.0000
5021
5022
5023 \series bold 
5024 -mxa51
5025 \begin_inset LatexCommand \index{-mxa51}
5026
5027 \end_inset 
5028
5029
5030 \series default 
5031  Generate code for the Phillips XA51
5032 \begin_inset LatexCommand \index{XA51}
5033
5034 \end_inset 
5035
5036  processor (Not maintained, not complete).
5037 \layout Subsection
5038
5039 Preprocessor Options
5040 \begin_inset LatexCommand \index{Options preprocessor}
5041
5042 \end_inset 
5043
5044
5045 \begin_inset LatexCommand \index{Preprocessor options}
5046
5047 \end_inset 
5048
5049
5050 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5051
5052 \end_inset 
5053
5054
5055 \layout List
5056 \labelwidthstring 00.00.0000
5057
5058
5059 \series bold 
5060 -I<path>
5061 \begin_inset LatexCommand \index{-I<path>}
5062
5063 \end_inset 
5064
5065
5066 \series default 
5067  The additional location where the pre processor will look for <..h> or 
5068 \begin_inset Quotes eld
5069 \end_inset 
5070
5071 ..h
5072 \begin_inset Quotes erd
5073 \end_inset 
5074
5075  files.
5076 \layout List
5077 \labelwidthstring 00.00.0000
5078
5079
5080 \series bold 
5081 -D<macro[=value]>
5082 \begin_inset LatexCommand \index{-D<macro[=value]>}
5083
5084 \end_inset 
5085
5086
5087 \series default 
5088  Command line definition of macros.
5089  Passed to the preprocessor.
5090 \layout List
5091 \labelwidthstring 00.00.0000
5092
5093
5094 \series bold 
5095 -M
5096 \begin_inset LatexCommand \index{-M}
5097
5098 \end_inset 
5099
5100
5101 \series default 
5102  Tell the preprocessor to output a rule suitable for make describing the
5103  dependencies of each object file.
5104  For each source file, the preprocessor outputs one make-rule whose target
5105  is the object file name for that source file and whose dependencies are
5106  all the files `#include'd in it.
5107  This rule may be a single line or may be continued with `
5108 \backslash 
5109 '-newline if it is long.
5110  The list of rules is printed on standard output instead of the preprocessed
5111  C program.
5112  `-M' implies `-E
5113 \begin_inset LatexCommand \index{-E}
5114
5115 \end_inset 
5116
5117 '.
5118 \layout List
5119 \labelwidthstring 00.00.0000
5120
5121
5122 \series bold 
5123 -C
5124 \begin_inset LatexCommand \index{-C}
5125
5126 \end_inset 
5127
5128
5129 \series default 
5130  Tell the preprocessor not to discard comments.
5131  Used with the `-E' option.
5132 \layout List
5133 \labelwidthstring 00.00.0000
5134
5135
5136 \series bold 
5137 -MM
5138 \begin_inset LatexCommand \index{-MM}
5139
5140 \end_inset 
5141
5142
5143 \size large 
5144 \bar under 
5145  
5146 \series default 
5147 \size default 
5148 \bar default 
5149 Like `-M' but the output mentions only the user header files included with
5150  `#include 
5151 \begin_inset Quotes eld
5152 \end_inset 
5153
5154 file"'.
5155  System header files included with `#include <file>' are omitted.
5156 \layout List
5157 \labelwidthstring 00.00.0000
5158
5159
5160 \series bold 
5161 -Aquestion(answer)
5162 \begin_inset LatexCommand \index{-Aquestion(answer)}
5163
5164 \end_inset 
5165
5166
5167 \series default 
5168  Assert the answer answer for question, in case it is tested with a preprocessor
5169  conditional such as `#if #question(answer)'.
5170  `-A-' disables the standard assertions that normally describe the target
5171  machine.
5172 \layout List
5173 \labelwidthstring 00.00.0000
5174
5175
5176 \series bold 
5177 -Umacro
5178 \begin_inset LatexCommand \index{-Umacro}
5179
5180 \end_inset 
5181
5182
5183 \series default 
5184  Undefine macro macro.
5185  `-U' options are evaluated after all `-D' options, but before any `-include'
5186  and `-imacros' options.
5187 \layout List
5188 \labelwidthstring 00.00.0000
5189
5190
5191 \series bold 
5192 -dM
5193 \begin_inset LatexCommand \index{-dM}
5194
5195 \end_inset 
5196
5197
5198 \series default 
5199  Tell the preprocessor to output only a list of the macro definitions that
5200  are in effect at the end of preprocessing.
5201  Used with the `-E' option.
5202 \layout List
5203 \labelwidthstring 00.00.0000
5204
5205
5206 \series bold 
5207 -dD
5208 \begin_inset LatexCommand \index{-dD}
5209
5210 \end_inset 
5211
5212
5213 \series default 
5214  Tell the preprocessor to pass all macro definitions into the output, in
5215  their proper sequence in the rest of the output.
5216 \layout List
5217 \labelwidthstring 00.00.0000
5218
5219
5220 \series bold 
5221 -dN
5222 \begin_inset LatexCommand \index{-dN}
5223
5224 \end_inset 
5225
5226
5227 \size large 
5228 \bar under 
5229  
5230 \series default 
5231 \size default 
5232 \bar default 
5233 Like `-dD' except that the macro arguments and contents are omitted.
5234  Only `#define name' is included in the output.
5235 \layout List
5236 \labelwidthstring 00.00.0000
5237
5238
5239 \series bold 
5240 -Wp\SpecialChar ~
5241 preprocessorOption[,preprocessorOption]
5242 \series default 
5243
5244 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
5245
5246 \end_inset 
5247
5248 ...
5249  Pass the preprocessorOption to the preprocessor 
5250 \family typewriter 
5251 sdcpp
5252 \family default 
5253
5254 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5255
5256 \end_inset 
5257
5258 .
5259  SDCC uses an adapted version of the preprocessor cpp of the GNU Compiler
5260  Collection (gcc), if you need more dedicated options please refer to the
5261  documentation at 
5262 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
5263
5264 \end_inset 
5265
5266 .
5267 \layout Subsection
5268
5269 Linker Options
5270 \begin_inset LatexCommand \index{Options linker}
5271
5272 \end_inset 
5273
5274
5275 \begin_inset LatexCommand \index{Linker options}
5276
5277 \end_inset 
5278
5279
5280 \layout List
5281 \labelwidthstring 00.00.0000
5282
5283
5284 \series bold 
5285 -L\SpecialChar ~
5286 -
5287 \series default 
5288
5289 \begin_inset ERT
5290 status Collapsed
5291
5292 \layout Standard
5293
5294 \backslash 
5295 /
5296 \end_inset 
5297
5298
5299 \series bold 
5300 -lib-path
5301 \begin_inset LatexCommand \index{-\/-lib-path <path>}
5302
5303 \end_inset 
5304
5305
5306 \begin_inset LatexCommand \index{-L -\/-lib-path}
5307
5308 \end_inset 
5309
5310
5311 \series default 
5312 \SpecialChar ~
5313 <absolute path to additional libraries> This option is passed to the linkage
5314  editor's additional libraries
5315 \begin_inset LatexCommand \index{Libraries}
5316
5317 \end_inset 
5318
5319  search path.
5320  The path name must be absolute.
5321  Additional library files may be specified in the command line.
5322  See section Compiling programs for more details.
5323 \layout List
5324 \labelwidthstring 00.00.0000
5325
5326
5327 \series bold 
5328 -
5329 \begin_inset ERT
5330 status Collapsed
5331
5332 \layout Standard
5333
5334 \backslash 
5335 /
5336 \end_inset 
5337
5338 -xram-loc
5339 \series default 
5340
5341 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
5342
5343 \end_inset 
5344
5345 \SpecialChar ~
5346 <Value> The start location of the external ram
5347 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
5348
5349 \end_inset 
5350
5351 , default value is 0.
5352  The value entered can be in Hexadecimal or Decimal format, e.g.: -
5353 \begin_inset ERT
5354 status Collapsed
5355
5356 \layout Standard
5357
5358 \backslash 
5359 /
5360 \end_inset 
5361
5362 -xram-loc 0x8000 or -
5363 \begin_inset ERT
5364 status Collapsed
5365
5366 \layout Standard
5367
5368 \backslash 
5369 /
5370 \end_inset 
5371
5372 -xram-loc 32768.
5373 \layout List
5374 \labelwidthstring 00.00.0000
5375
5376
5377 \series bold 
5378 -
5379 \begin_inset ERT
5380 status Collapsed
5381
5382 \layout Standard
5383
5384 \backslash 
5385 /
5386 \end_inset 
5387
5388 -code-loc
5389 \series default 
5390
5391 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
5392
5393 \end_inset 
5394
5395 \SpecialChar ~
5396 <Value> The start location of the code
5397 \begin_inset LatexCommand \index{code}
5398
5399 \end_inset 
5400
5401  segment, default value 0.
5402  Note when this option is used the interrupt vector table is also relocated
5403  to the given address.
5404  The value entered can be in Hexadecimal or Decimal format, e.g.: -
5405 \begin_inset ERT
5406 status Collapsed
5407
5408 \layout Standard
5409
5410 \backslash 
5411 /
5412 \end_inset 
5413
5414 -code-loc 0x8000 or -
5415 \begin_inset ERT
5416 status Collapsed
5417
5418 \layout Standard
5419
5420 \backslash 
5421 /
5422 \end_inset 
5423
5424 -code-loc 32768.
5425 \layout List
5426 \labelwidthstring 00.00.0000
5427
5428
5429 \series bold 
5430 -
5431 \begin_inset ERT
5432 status Collapsed
5433
5434 \layout Standard
5435
5436 \backslash 
5437 /
5438 \end_inset 
5439
5440 -stack-loc
5441 \series default 
5442
5443 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
5444
5445 \end_inset 
5446
5447 \SpecialChar ~
5448 <Value> By default the stack
5449 \begin_inset LatexCommand \index{stack}
5450
5451 \end_inset 
5452
5453  is placed after the data segment.
5454  Using this option the stack can be placed anywhere in the internal memory
5455  space of the 8051.
5456  The value entered can be in Hexadecimal or Decimal format, e.g.
5457  -
5458 \begin_inset ERT
5459 status Collapsed
5460
5461 \layout Standard
5462
5463 \backslash 
5464 /
5465 \end_inset 
5466
5467 -stack-loc 0x20 or -
5468 \begin_inset ERT
5469 status Collapsed
5470
5471 \layout Standard
5472
5473 \backslash 
5474 /
5475 \end_inset 
5476
5477 -stack-loc 32.
5478  Since the sp register is incremented before a push or call, the initial
5479  sp will be set to one byte prior the provided value.
5480  The provided value should not overlap any other memory areas such as used
5481  register banks or the data segment and with enough space for the current
5482  application.
5483 \layout List
5484 \labelwidthstring 00.00.0000
5485
5486
5487 \series bold 
5488 -
5489 \begin_inset ERT
5490 status Collapsed
5491
5492 \layout Standard
5493
5494 \backslash 
5495 /
5496 \end_inset 
5497
5498 -data-loc
5499 \series default 
5500
5501 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
5502
5503 \end_inset 
5504
5505 \SpecialChar ~
5506 <Value> The start location of the internal ram data
5507 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
5508
5509 \end_inset 
5510
5511  segment.
5512  The value entered can be in Hexadecimal or Decimal format, eg.
5513  -
5514 \begin_inset ERT
5515 status Collapsed
5516
5517 \layout Standard
5518
5519 \backslash 
5520 /
5521 \end_inset 
5522
5523 -data-loc 0x20 or -
5524 \begin_inset ERT
5525 status Collapsed
5526
5527 \layout Standard
5528
5529 \backslash 
5530 /
5531 \end_inset 
5532
5533 -data-loc 32.
5534  (By default, the start location of the internal ram data segment  is set
5535  as low as possible in memory, taking into account the used register banks
5536  and the bit segment at address 0x20.
5537  For example if register banks 0 and 1 are used without bit variables, the
5538  data segment will be set, if -
5539 \begin_inset ERT
5540 status Collapsed
5541
5542 \layout Standard
5543
5544 \backslash 
5545 /
5546 \end_inset 
5547
5548 -data-loc is not used, to location 0x10.)
5549 \layout List
5550 \labelwidthstring 00.00.0000
5551
5552
5553 \series bold 
5554 -
5555 \begin_inset ERT
5556 status Collapsed
5557
5558 \layout Standard
5559
5560 \backslash 
5561 /
5562 \end_inset 
5563
5564 -idata-loc
5565 \series default 
5566
5567 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
5568
5569 \end_inset 
5570
5571 \SpecialChar ~
5572 <Value> The start location of the indirectly addressable internal ram
5573 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
5574
5575 \end_inset 
5576
5577  of the 8051, default value is 0x80.
5578  The value entered can be in Hexadecimal or Decimal format, eg.
5579  -
5580 \begin_inset ERT
5581 status Collapsed
5582
5583 \layout Standard
5584
5585 \backslash 
5586 /
5587 \end_inset 
5588
5589 -idata-loc 0x88 or -
5590 \begin_inset ERT
5591 status Collapsed
5592
5593 \layout Standard
5594
5595 \backslash 
5596 /
5597 \end_inset 
5598
5599 -idata-loc 136.
5600 \layout List
5601 \labelwidthstring 00.00.0000
5602
5603
5604 \series bold 
5605 -
5606 \begin_inset ERT
5607 status Collapsed
5608
5609 \layout Standard
5610
5611 \backslash 
5612 /
5613 \end_inset 
5614
5615 -bit-loc
5616 \series default 
5617 \SpecialChar ~
5618 <Value> The start location of the bit
5619 \begin_inset LatexCommand \index{bit}
5620
5621 \end_inset 
5622
5623  addressable internal ram of the 8051.
5624  This is 
5625 \emph on 
5626 not
5627 \emph default 
5628  implemented yet.
5629  Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
5630 -bBSEG=<Value>.
5631 \layout List
5632 \labelwidthstring 00.00.0000
5633
5634
5635 \series bold 
5636 -
5637 \begin_inset ERT
5638 status Collapsed
5639
5640 \layout Standard
5641
5642 \backslash 
5643 /
5644 \end_inset 
5645
5646 -out-fmt-ihx
5647 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
5648
5649 \end_inset 
5650
5651
5652 \bar under 
5653  
5654 \series default 
5655 \bar default 
5656 The linker output (final object code) is in Intel Hex format.
5657 \begin_inset LatexCommand \index{Intel hex format}
5658
5659 \end_inset 
5660
5661  This is the default option.
5662  The format itself is documented in the documentation of srecord
5663 \begin_inset LatexCommand \index{srecord (tool)}
5664
5665 \end_inset 
5666
5667 .
5668 \layout List
5669 \labelwidthstring 00.00.0000
5670
5671
5672 \series bold 
5673 -
5674 \begin_inset ERT
5675 status Collapsed
5676
5677 \layout Standard
5678
5679 \backslash 
5680 /
5681 \end_inset 
5682
5683 -out-fmt-s19
5684 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5685
5686 \end_inset 
5687
5688
5689 \bar under 
5690  
5691 \series default 
5692 \bar default 
5693 The linker output (final object code) is in Motorola S19 format
5694 \begin_inset LatexCommand \index{Motorola S19 format}
5695
5696 \end_inset 
5697
5698 .
5699  The format itself is documented in the documentation of srecord.
5700 \layout List
5701 \labelwidthstring 00.00.0000
5702
5703
5704 \series bold 
5705 -Wl\SpecialChar ~
5706 linkOption[,linkOption]
5707 \series default 
5708
5709 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
5710
5711 \end_inset 
5712
5713 ...
5714  Pass the linkOption to the linker.
5715  See file sdcc/as/doc/asxhtm.html for more on linker options.
5716 \layout Subsection
5717
5718 MCS51 Options
5719 \begin_inset LatexCommand \index{Options MCS51}
5720
5721 \end_inset 
5722
5723
5724 \begin_inset LatexCommand \index{MCS51 options}
5725
5726 \end_inset 
5727
5728
5729 \layout List
5730 \labelwidthstring 00.00.0000
5731
5732
5733 \series bold 
5734 -
5735 \begin_inset ERT
5736 status Collapsed
5737
5738 \layout Standard
5739
5740 \backslash 
5741 /
5742 \end_inset 
5743
5744 -model-small
5745 \begin_inset LatexCommand \index{-\/-model-small}
5746
5747 \end_inset 
5748
5749
5750 \series default 
5751 \size large 
5752 \emph on 
5753  
5754 \size default 
5755 \emph default 
5756 Generate code for Small Model programs, see section Memory Models for more
5757  details.
5758  This is the default model.
5759 \layout List
5760 \labelwidthstring 00.00.0000
5761
5762
5763 \series bold 
5764 -
5765 \begin_inset ERT
5766 status Collapsed
5767
5768 \layout Standard
5769
5770 \backslash 
5771 /
5772 \end_inset 
5773
5774 -model-large
5775 \begin_inset LatexCommand \index{-\/-model-large}
5776
5777 \end_inset 
5778
5779
5780 \series default 
5781  Generate code for Large model programs, see section Memory Models for more
5782  details.
5783  If this option is used all source files in the project have to be compiled
5784  with this option.
5785 \layout List
5786 \labelwidthstring 00.00.0000
5787
5788
5789 \series bold 
5790 -
5791 \begin_inset ERT
5792 status Collapsed
5793
5794 \layout Standard
5795
5796 \backslash 
5797 /
5798 \end_inset 
5799
5800 -xstack
5801 \begin_inset LatexCommand \index{-\/-xstack}
5802
5803 \end_inset 
5804
5805
5806 \series default 
5807  Uses a pseudo stack in the first 256 bytes in the external ram for allocating
5808  variables and passing parameters.
5809  See section 
5810 \begin_inset LatexCommand \ref{sub:External-Stack}
5811
5812 \end_inset 
5813
5814 \SpecialChar ~
5815  External Stack for more details.
5816 \layout List
5817 \labelwidthstring 00.00.0000
5818
5819
5820 \series bold 
5821 -
5822 \begin_inset ERT
5823 status Collapsed
5824
5825 \layout Standard
5826
5827 \backslash 
5828 /
5829 \end_inset 
5830
5831 -iram-size
5832 \series default 
5833 \SpecialChar ~
5834 <Value>
5835 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
5836
5837 \end_inset 
5838
5839  Causes the linker to check if the internal ram usage is within limits of
5840  the given value.
5841 \layout List
5842 \labelwidthstring 00.00.0000
5843
5844
5845 \series bold 
5846 -
5847 \begin_inset ERT
5848 status Collapsed
5849
5850 \layout Standard
5851
5852 \backslash 
5853 /
5854 \end_inset 
5855
5856 -xram-size
5857 \series default 
5858 \SpecialChar ~
5859 <Value>
5860 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
5861
5862 \end_inset 
5863
5864  Causes the linker to check if the external ram usage is within limits of
5865  the given value.
5866 \layout List
5867 \labelwidthstring 00.00.0000
5868
5869
5870 \series bold 
5871 -
5872 \begin_inset ERT
5873 status Collapsed
5874
5875 \layout Standard
5876
5877 \backslash 
5878 /
5879 \end_inset 
5880
5881 -code-size
5882 \series default 
5883 \SpecialChar ~
5884 <Value>
5885 \begin_inset LatexCommand \index{-\/-code-size <Value>}
5886
5887 \end_inset 
5888
5889  Causes the linker to check if the code memory usage is within limits of
5890  the given value.
5891 \layout Subsection
5892
5893 DS390 / DS400 Options
5894 \begin_inset LatexCommand \index{Options DS390}
5895
5896 \end_inset 
5897
5898
5899 \begin_inset LatexCommand \index{DS390 options}
5900
5901 \end_inset 
5902
5903
5904 \layout List
5905 \labelwidthstring 00.00.0000
5906
5907
5908 \series bold 
5909 -
5910 \begin_inset ERT
5911 status Collapsed
5912
5913 \layout Standard
5914
5915 \backslash 
5916 /
5917 \end_inset 
5918
5919 -model-flat24
5920 \series default 
5921
5922 \begin_inset LatexCommand \index{-\/-model-flat24}
5923
5924 \end_inset 
5925
5926
5927 \size large 
5928 \emph on 
5929  
5930 \size default 
5931 \emph default 
5932 Generate 24-bit flat mode code.
5933  This is the one and only that the ds390 code generator supports right now
5934  and is default when using 
5935 \emph on 
5936 -mds390
5937 \emph default 
5938 .
5939  See section Memory Models for more details.
5940 \layout List
5941 \labelwidthstring 00.00.0000
5942
5943
5944 \series bold 
5945 -
5946 \begin_inset ERT
5947 status Collapsed
5948
5949 \layout Standard
5950
5951 \backslash 
5952 /
5953 \end_inset 
5954
5955 -protect-sp-update
5956 \begin_inset LatexCommand \index{-\/-protect-sp-update}
5957
5958 \end_inset 
5959
5960
5961 \series default 
5962  disable interrupts during ESP:SP updates.
5963 \layout List
5964 \labelwidthstring 00.00.0000
5965
5966
5967 \series bold 
5968 -
5969 \begin_inset ERT
5970 status Collapsed
5971
5972 \layout Standard
5973
5974 \backslash 
5975 /
5976 \end_inset 
5977
5978 -stack-10bit
5979 \series default 
5980
5981 \begin_inset LatexCommand \index{-\/-stack-10bit}
5982
5983 \end_inset 
5984
5985  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
5986  This is the one and only that the ds390 code generator supports right now
5987  and is default when using 
5988 \emph on 
5989 -mds390
5990 \emph default 
5991 .
5992  In this mode, the stack is located in the lower 1K of the internal RAM,
5993  which is mapped to 0x400000.
5994  Note that the support is incomplete, since it still uses a single byte
5995  as the stack pointer.
5996  This means that only the lower 256 bytes of the potential 1K stack space
5997  will actually be used.
5998  However, this does allow you to reclaim the precious 256 bytes of low RAM
5999  for use for the DATA and IDATA segments.
6000  The compiler will not generate any code to put the processor into 10 bit
6001  stack mode.
6002  It is important to ensure that the processor is in this mode before calling
6003  any re-entrant functions compiled with this option.
6004  In principle, this should work with the 
6005 \emph on 
6006 -
6007 \begin_inset ERT
6008 status Collapsed
6009
6010 \layout Standard
6011
6012 \backslash 
6013 /
6014 \end_inset 
6015
6016 -stack-auto
6017 \begin_inset LatexCommand \index{-\/-stack-auto}
6018
6019 \end_inset 
6020
6021
6022 \emph default 
6023  option, but that has not been tested.
6024  It is incompatible with the 
6025 \emph on 
6026 -
6027 \begin_inset ERT
6028 status Collapsed
6029
6030 \layout Standard
6031
6032 \backslash 
6033 /
6034 \end_inset 
6035
6036 -xstack
6037 \begin_inset LatexCommand \index{-\/-xstack}
6038
6039 \end_inset 
6040
6041
6042 \emph default 
6043  option.
6044  It also only makes sense if the processor is in 24 bit contiguous addressing
6045  mode (see the 
6046 \emph on 
6047 -
6048 \begin_inset ERT
6049 status Collapsed
6050
6051 \layout Standard
6052
6053 \backslash 
6054 /
6055 \end_inset 
6056
6057 -model-flat24 option
6058 \emph default 
6059 ).
6060 \layout List
6061 \labelwidthstring 00.00.0000
6062
6063
6064 \series bold 
6065 -
6066 \begin_inset ERT
6067 status Collapsed
6068
6069 \layout Standard
6070
6071 \backslash 
6072 /
6073 \end_inset 
6074
6075 -stack-probe
6076 \begin_inset LatexCommand \index{-\/-stack-probe}
6077
6078 \end_inset 
6079
6080
6081 \series default 
6082  insert call to function __stack_probe at each function prologue.
6083 \layout List
6084 \labelwidthstring 00.00.0000
6085
6086
6087 \series bold 
6088 -
6089 \begin_inset ERT
6090 status Collapsed
6091
6092 \layout Standard
6093
6094 \backslash 
6095 /
6096 \end_inset 
6097
6098 -tini-libid
6099 \begin_inset LatexCommand \index{-\/-tini-libid}
6100
6101 \end_inset 
6102
6103
6104 \series default 
6105  <nnnn> LibraryID used in -mTININative.
6106  
6107 \layout List
6108 \labelwidthstring 00.00.0000
6109
6110
6111 \series bold 
6112 -
6113 \begin_inset ERT
6114 status Collapsed
6115
6116 \layout Standard
6117
6118 \backslash 
6119 /
6120 \end_inset 
6121
6122 -use-accelerator
6123 \begin_inset LatexCommand \index{-\/-use-accelerator}
6124
6125 \end_inset 
6126
6127
6128 \series default 
6129  generate code for DS390 Arithmetic Accelerator.
6130  
6131 \layout Subsection
6132
6133 PIC Options
6134 \begin_inset LatexCommand \index{Options PIC}
6135
6136 \end_inset 
6137
6138
6139 \begin_inset LatexCommand \index{PIC options}
6140
6141 \end_inset 
6142
6143
6144 \layout List
6145 \labelwidthstring 00.00.0000
6146
6147
6148 \series bold 
6149 -
6150 \begin_inset ERT
6151 status Collapsed
6152
6153 \layout Standard
6154
6155 \backslash 
6156 /
6157 \end_inset 
6158
6159 -gen-banksel
6160 \begin_inset LatexCommand \index{-\/-gen-banksel}
6161
6162 \end_inset 
6163
6164
6165 \series default 
6166  enable the generation of banksel assembler directives in the PIC16
6167 \begin_inset LatexCommand \index{PIC16}
6168
6169 \end_inset 
6170
6171  port.
6172 \layout Subsection
6173
6174 Z80 Options
6175 \begin_inset LatexCommand \index{Options Z80}
6176
6177 \end_inset 
6178
6179
6180 \begin_inset LatexCommand \index{Z80 options}
6181
6182 \end_inset 
6183
6184
6185 \layout List
6186 \labelwidthstring 00.00.0000
6187
6188
6189 \series bold 
6190 -
6191 \begin_inset ERT
6192 status Collapsed
6193
6194 \layout Standard
6195
6196 \backslash 
6197 /
6198 \end_inset 
6199
6200 -callee-saves-bc
6201 \series default 
6202
6203 \begin_inset LatexCommand \index{-\/-callee-saves-bc}
6204
6205 \end_inset 
6206
6207
6208 \size large 
6209 \emph on 
6210  
6211 \size default 
6212 \emph default 
6213 Force a called function to always save BC.
6214 \layout List
6215 \labelwidthstring 00.00.0000
6216
6217
6218 \series bold 
6219 -
6220 \begin_inset ERT
6221 status Collapsed
6222
6223 \layout Standard
6224
6225 \backslash 
6226 /
6227 \end_inset 
6228
6229 -no-std-crt0
6230 \series default 
6231
6232 \begin_inset LatexCommand \index{-\/-no-std-crt0}
6233
6234 \end_inset 
6235
6236  When linking, skip the standard crt0.o object file.
6237  You must provide your own crt0.o for your system when linking.
6238  
6239 \layout Subsection
6240
6241 Optimization Options
6242 \begin_inset LatexCommand \index{Options optimization}
6243
6244 \end_inset 
6245
6246
6247 \begin_inset LatexCommand \index{Optimization options}
6248
6249 \end_inset 
6250
6251
6252 \layout List
6253 \labelwidthstring 00.00.0000
6254
6255
6256 \series bold 
6257 -
6258 \begin_inset ERT
6259 status Collapsed
6260
6261 \layout Standard
6262
6263 \backslash 
6264 /
6265 \end_inset 
6266
6267 -nogcse
6268 \begin_inset LatexCommand \index{-\/-nogcse}
6269
6270 \end_inset 
6271
6272
6273 \series default 
6274  Will not do global subexpression elimination, this option may be used when
6275  the compiler creates undesirably large stack/data spaces to store compiler
6276  temporaries.
6277  A warning message will be generated when this happens and the compiler
6278  will indicate the number of extra bytes it allocated.
6279  It is recommended that this option NOT be used, #pragma\SpecialChar ~
6280 nogcse
6281 \begin_inset LatexCommand \index{\#pragma nogcse}
6282
6283 \end_inset 
6284
6285  can be used to turn off global subexpression elimination
6286 \begin_inset LatexCommand \index{Subexpression elimination}
6287
6288 \end_inset 
6289
6290  for a given function only.
6291 \layout List
6292 \labelwidthstring 00.00.0000
6293
6294
6295 \series bold 
6296 -
6297 \begin_inset ERT
6298 status Collapsed
6299
6300 \layout Standard
6301
6302 \backslash 
6303 /
6304 \end_inset 
6305
6306 -noinvariant
6307 \begin_inset LatexCommand \index{-\/-noinvariant}
6308
6309 \end_inset 
6310
6311
6312 \series default 
6313  Will not do loop invariant optimizations, this may be turned off for reasons
6314  explained for the previous option.
6315  For more details of loop optimizations performed see section Loop Invariants.
6316  It is recommended that this option NOT be used, #pragma\SpecialChar ~
6317 noinvariant
6318 \begin_inset LatexCommand \index{\#pragma noinvariant}
6319
6320 \end_inset 
6321
6322  can be used to turn off invariant optimizations for a given function only.
6323 \layout List
6324 \labelwidthstring 00.00.0000
6325
6326
6327 \series bold 
6328 -
6329 \begin_inset ERT
6330 status Collapsed
6331
6332 \layout Standard
6333
6334 \backslash 
6335 /
6336 \end_inset 
6337
6338 -noinduction
6339 \begin_inset LatexCommand \index{-\/-noinduction}
6340
6341 \end_inset 
6342
6343
6344 \series default 
6345  Will not do loop induction optimizations, see section strength reduction
6346  for more details.
6347  It is recommended that this option is NOT used, #pragma\SpecialChar ~
6348 noinduction
6349 \begin_inset LatexCommand \index{\#pragma noinduction}
6350
6351 \end_inset 
6352
6353  can be used to turn off induction optimizations for a given function only.
6354 \layout List
6355 \labelwidthstring 00.00.0000
6356
6357
6358 \series bold 
6359 -
6360 \begin_inset ERT
6361 status Collapsed
6362
6363 \layout Standard
6364
6365 \backslash 
6366 /
6367 \end_inset 
6368
6369 -nojtbound
6370 \begin_inset LatexCommand \index{-\/-nojtbound}
6371
6372 \end_inset 
6373
6374
6375 \size large 
6376 \bar under 
6377  
6378 \series default 
6379 \size default 
6380 \bar default 
6381  Will not generate boundary condition check when switch statements
6382 \begin_inset LatexCommand \index{switch statement}
6383
6384 \end_inset 
6385
6386  are implemented using jump-tables.
6387  See section 
6388 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
6389
6390 \end_inset 
6391
6392 \SpecialChar ~
6393 Switch Statements for more details.
6394  It is recommended that this option is NOT used, #pragma\SpecialChar ~
6395 nojtbound
6396 \begin_inset LatexCommand \index{\#pragma nojtbound}
6397
6398 \end_inset 
6399
6400  can be used to turn off boundary checking for jump tables for a given function
6401  only.
6402 \layout List
6403 \labelwidthstring 00.00.0000
6404
6405
6406 \series bold 
6407 -
6408 \begin_inset ERT
6409 status Collapsed
6410
6411 \layout Standard
6412
6413 \backslash 
6414 /
6415 \end_inset 
6416
6417 -noloopreverse
6418 \begin_inset LatexCommand \index{-\/-noloopreverse}
6419
6420 \end_inset 
6421
6422
6423 \series default 
6424 \size large 
6425  
6426 \size default 
6427 Will not do loop reversal 
6428 \begin_inset LatexCommand \index{Loop reversing}
6429
6430 \end_inset 
6431
6432 optimization.
6433 \layout List
6434 \labelwidthstring 00.00.0000
6435
6436 -
6437 \begin_inset ERT
6438 status Collapsed
6439
6440 \layout Standard
6441
6442 \backslash 
6443 /
6444 \end_inset 
6445
6446 -
6447 \series bold 
6448 nolabelopt
6449 \series default 
6450  
6451 \begin_inset LatexCommand \index{-\/-nolabelopt }
6452
6453 \end_inset 
6454
6455 Will not optimize labels (makes the dumpfiles more readable).
6456 \layout List
6457 \labelwidthstring 00.00.0000
6458
6459
6460 \series bold 
6461 -
6462 \begin_inset ERT
6463 status Collapsed
6464
6465 \layout Standard
6466
6467 \backslash 
6468 /
6469 \end_inset 
6470
6471 -no-xinit-opt
6472 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
6473
6474 \end_inset 
6475
6476
6477 \series default 
6478  Will not memcpy initialized data from code space into xdata space.
6479  This saves a few bytes in code space if you don't have initialized data.
6480 \layout List
6481 \labelwidthstring 00.00.0000
6482
6483
6484 \series bold 
6485 -
6486 \begin_inset ERT
6487 status Collapsed
6488
6489 \layout Standard
6490
6491 \backslash 
6492 /
6493 \end_inset 
6494
6495 -nooverlay
6496 \begin_inset LatexCommand \index{-\/-nooverlay}
6497
6498 \end_inset 
6499
6500
6501 \series default 
6502   The compiler will not overlay parameters and local variables of any function,
6503  see section Parameters and local variables for more details.
6504 \layout List
6505 \labelwidthstring 00.00.0000
6506
6507
6508 \series bold 
6509 -
6510 \begin_inset ERT
6511 status Collapsed
6512
6513 \layout Standard
6514
6515 \backslash 
6516 /
6517 \end_inset 
6518
6519 -no-peep
6520 \begin_inset LatexCommand \index{-\/-no-peep}
6521
6522 \end_inset 
6523
6524
6525 \series default 
6526  Disable peep-hole optimization.
6527 \layout List
6528 \labelwidthstring 00.00.0000
6529
6530
6531 \series bold 
6532 -
6533 \begin_inset ERT
6534 status Collapsed
6535
6536 \layout Standard
6537
6538 \backslash 
6539 /
6540 \end_inset 
6541
6542 -peep-file
6543 \series default 
6544
6545 \begin_inset LatexCommand \index{-\/-peep-file}
6546
6547 \end_inset 
6548
6549 \SpecialChar ~
6550 <filename> This option can be used to use additional rules to be used by
6551  the peep hole optimizer.
6552  See section 
6553 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
6554
6555 \end_inset 
6556
6557 \SpecialChar ~
6558 Peep Hole optimizations for details on how to write these rules.
6559 \layout List
6560 \labelwidthstring 00.00.0000
6561
6562
6563 \series bold 
6564 -
6565 \begin_inset ERT
6566 status Collapsed
6567
6568 \layout Standard
6569
6570 \backslash 
6571 /
6572 \end_inset 
6573
6574 -peep-asm
6575 \begin_inset LatexCommand \index{-\/-peep-asm}
6576
6577 \end_inset 
6578
6579
6580 \series default 
6581   Pass the inline assembler code through the peep hole optimizer.
6582  This can cause unexpected changes to inline assembler code, please go through
6583  the peephole optimizer
6584 \begin_inset LatexCommand \index{Peephole optimizer}
6585
6586 \end_inset 
6587
6588  rules defined in the source file tree '<target>/peeph.def' before using
6589  this option.
6590 \layout Subsection
6591
6592 Other Options
6593 \begin_inset LatexCommand \index{Options other}
6594
6595 \end_inset 
6596
6597
6598 \layout List
6599 \labelwidthstring 00.00.0000
6600
6601
6602 \series bold 
6603 -c\SpecialChar ~
6604 -
6605 \begin_inset ERT
6606 status Collapsed
6607
6608 \layout Standard
6609
6610 \backslash 
6611 /
6612 \end_inset 
6613
6614 -compile-only
6615 \begin_inset LatexCommand \index{-\/-compile-only}
6616
6617 \end_inset 
6618
6619
6620 \begin_inset LatexCommand \index{-c -\/-compile-only}
6621
6622 \end_inset 
6623
6624
6625 \series default 
6626  will compile and assemble the source, but will not call the linkage editor.
6627 \layout List
6628 \labelwidthstring 00.00.0000
6629
6630
6631 \series bold 
6632 -
6633 \series default 
6634
6635 \begin_inset ERT
6636 status Collapsed
6637
6638 \layout Standard
6639
6640 \backslash 
6641 /
6642 \end_inset 
6643
6644
6645 \series bold 
6646 -c1mode
6647 \begin_inset LatexCommand \index{-\/-c1mode}
6648
6649 \end_inset 
6650
6651
6652 \series default 
6653  reads the preprocessed source from standard input and compiles it.
6654  The file name for the assembler output must be specified using the -o option.
6655 \layout List
6656 \labelwidthstring 00.00.0000
6657
6658
6659 \series bold 
6660 -E
6661 \begin_inset LatexCommand \index{-E}
6662
6663 \end_inset 
6664
6665
6666 \series default 
6667  Run only the C preprocessor.
6668  Preprocess all the C source files specified and output the results to standard
6669  output.
6670 \layout List
6671 \labelwidthstring 00.00.0000
6672
6673
6674 \series bold 
6675 -o\SpecialChar ~
6676 <path/file>
6677 \begin_inset LatexCommand \index{-o <path/file>}
6678
6679 \end_inset 
6680
6681  
6682 \series default 
6683 The output path resp.
6684  file where everything will be placed.
6685  If the parameter is a path, it must have a trailing slash (or backslash
6686  for the Windows binaries) to be recognized as a path.
6687  
6688 \layout List
6689 \labelwidthstring 00.00.0000
6690
6691
6692 \series bold 
6693 -
6694 \begin_inset ERT
6695 status Collapsed
6696
6697 \layout Standard
6698
6699 \backslash 
6700 /
6701 \end_inset 
6702
6703 -stack-auto
6704 \begin_inset LatexCommand \index{-\/-stack-auto}
6705
6706 \end_inset 
6707
6708
6709 \series default 
6710 \size large 
6711 \emph on 
6712  
6713 \size default 
6714 \emph default 
6715 All functions in the source file will be compiled as 
6716 \emph on 
6717 reentrant
6718 \emph default 
6719
6720 \begin_inset LatexCommand \index{reentrant}
6721
6722 \end_inset 
6723
6724 , i.e.
6725  the parameters and local variables will be allocated on the stack
6726 \begin_inset LatexCommand \index{stack}
6727
6728 \end_inset 
6729
6730 .
6731  see section Parameters and Local Variables for more details.
6732  If this option is used all source files in the project should be compiled
6733  with this option.
6734  
6735 \layout List
6736 \labelwidthstring 00.00.0000
6737
6738
6739 \series bold 
6740 -
6741 \begin_inset ERT
6742 status Collapsed
6743
6744 \layout Standard
6745
6746 \backslash 
6747 /
6748 \end_inset 
6749
6750 -callee-saves
6751 \begin_inset LatexCommand \index{-\/-callee-saves}
6752
6753 \end_inset 
6754
6755  function1[,function2][,function3]....
6756
6757 \series default 
6758  The compiler by default uses a caller saves convention for register saving
6759  across function calls, however this can cause unnecessary register pushing
6760  & popping when calling small functions from larger functions.
6761  This option can be used to switch the register saving convention for the
6762  function names specified.
6763  The compiler will not save registers when calling these functions, no extra
6764  code will be generated at the entry & exit (function prologue
6765 \series bold 
6766
6767 \begin_inset LatexCommand \index{function prologue}
6768
6769 \end_inset 
6770
6771
6772 \series default 
6773  & epilogue
6774 \series bold 
6775
6776 \begin_inset LatexCommand \index{function epilogue}
6777
6778 \end_inset 
6779
6780
6781 \series default 
6782 ) for these functions to save & restore the registers used by these functions,
6783  this can SUBSTANTIALLY reduce code & improve run time performance of the
6784  generated code.
6785  In the future the compiler (with inter procedural analysis) will be able
6786  to determine the appropriate scheme to use for each function call.
6787  DO NOT use this option for built-in functions such as _mulint..., if this
6788  option is used for a library function the appropriate library function
6789  needs to be recompiled with the same option.
6790  If the project consists of multiple source files then all the source file
6791  should be compiled with the same -
6792 \begin_inset ERT
6793 status Collapsed
6794
6795 \layout Standard
6796
6797 \backslash 
6798 /
6799 \end_inset 
6800
6801 -callee-saves option string.
6802  Also see #pragma\SpecialChar ~
6803 callee_saves
6804 \begin_inset LatexCommand \index{\#pragma callee\_saves}
6805
6806 \end_inset 
6807
6808 .
6809 \layout List
6810 \labelwidthstring 00.00.0000
6811
6812
6813 \series bold 
6814 -
6815 \begin_inset ERT
6816 status Collapsed
6817
6818 \layout Standard
6819
6820 \backslash 
6821 /
6822 \end_inset 
6823
6824 -debug
6825 \begin_inset LatexCommand \index{-\/-debug}
6826
6827 \end_inset 
6828
6829
6830 \bar under 
6831  
6832 \series default 
6833 \bar default 
6834 When this option is used the compiler will generate debug information.
6835  The debug information collected in a file with .cdb extension can be used
6836  with the SDCDB.
6837  For more information see documentation for SDCDB.
6838  Another file with no extension contains debug information in AOMF or AOMF51
6839 \begin_inset LatexCommand \index{AOMF, AOMF51}
6840
6841 \end_inset 
6842
6843  format which is commonly used by third party tools.
6844 \layout List
6845 \labelwidthstring 00.00.0000
6846
6847
6848 \series bold 
6849 -S
6850 \begin_inset LatexCommand \index{-S}
6851
6852 \end_inset 
6853
6854
6855 \size large 
6856 \bar under 
6857  
6858 \series default 
6859 \size default 
6860 \bar default 
6861 Stop after the stage of compilation proper; do not assemble.
6862  The output is an assembler code file for the input file specified.
6863 \layout List
6864 \labelwidthstring 00.00.0000
6865
6866
6867 \series bold 
6868 -
6869 \begin_inset ERT
6870 status Collapsed
6871
6872 \layout Standard
6873
6874 \backslash 
6875 /
6876 \end_inset 
6877
6878 -int-long-reent
6879 \begin_inset LatexCommand \index{-\/-int-long-reent}
6880
6881 \end_inset 
6882
6883
6884 \series default 
6885  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
6886  Note by default these libraries are compiled as non-reentrant.
6887  See section Installation for more details.
6888 \layout List
6889 \labelwidthstring 00.00.0000
6890
6891
6892 \series bold 
6893 -
6894 \begin_inset ERT
6895 status Collapsed
6896
6897 \layout Standard
6898
6899 \backslash 
6900 /
6901 \end_inset 
6902
6903 -cyclomatic
6904 \begin_inset LatexCommand \index{-\/-cyclomatic}
6905
6906 \end_inset 
6907
6908
6909 \bar under 
6910  
6911 \series default 
6912 \bar default 
6913 This option will cause the compiler to generate an information message for
6914  each function in the source file.
6915  The message contains some 
6916 \emph on 
6917 important
6918 \emph default 
6919  information about the function.
6920  The number of edges and nodes the compiler detected in the control flow
6921  graph of the function, and most importantly the 
6922 \emph on 
6923 cyclomatic complexity
6924 \begin_inset LatexCommand \index{Cyclomatic complexity}
6925
6926 \end_inset 
6927
6928
6929 \emph default 
6930  see section on Cyclomatic Complexity for more details.
6931 \layout List
6932 \labelwidthstring 00.00.0000
6933
6934
6935 \series bold 
6936 -
6937 \begin_inset ERT
6938 status Collapsed
6939
6940 \layout Standard
6941
6942 \backslash 
6943 /
6944 \end_inset 
6945
6946 -float-reent
6947 \begin_inset LatexCommand \index{-\/-float-reent}
6948
6949 \end_inset 
6950
6951
6952 \series default 
6953  Floating point library is compiled as reentrant
6954 \begin_inset LatexCommand \index{reentrant}
6955
6956 \end_inset 
6957
6958 .
6959  See section Installation for more details.
6960 \layout List
6961 \labelwidthstring 00.00.0000
6962
6963
6964 \series bold 
6965 -
6966 \begin_inset ERT
6967 status Collapsed
6968
6969 \layout Standard
6970
6971 \backslash 
6972 /
6973 \end_inset 
6974
6975 -main-return
6976 \begin_inset LatexCommand \index{-\/-main-return}
6977
6978 \end_inset 
6979
6980
6981 \series default 
6982  This option can be used when the code generated is called by a monitor
6983  program.
6984  The compiler will generate a 'ret' upon return from the 'main'
6985 \begin_inset LatexCommand \index{main return}
6986
6987 \end_inset 
6988
6989  function.
6990  The default setting is to lock up i.e.
6991  generate a '
6992 \family typewriter 
6993 sjmp .
6994 \family default 
6995 '.
6996 \layout List
6997 \labelwidthstring 00.00.0000
6998
6999
7000 \series bold 
7001 -
7002 \begin_inset ERT
7003 status Collapsed
7004
7005 \layout Standard
7006
7007 \backslash 
7008 /
7009 \end_inset 
7010
7011 -nostdincl
7012 \begin_inset LatexCommand \index{-\/-nostdincl}
7013
7014 \end_inset 
7015
7016
7017 \series default 
7018  This will prevent the compiler from passing on the default include path
7019  to the preprocessor.
7020 \layout List
7021 \labelwidthstring 00.00.0000
7022
7023
7024 \series bold 
7025 -
7026 \begin_inset ERT
7027 status Collapsed
7028
7029 \layout Standard
7030
7031 \backslash 
7032 /
7033 \end_inset 
7034
7035 -nostdlib
7036 \begin_inset LatexCommand \index{-\/-nostdlib}
7037
7038 \end_inset 
7039
7040
7041 \series default 
7042  This will prevent the compiler from passing on the default library
7043 \begin_inset LatexCommand \index{Libraries}
7044
7045 \end_inset 
7046
7047  path to the linker.
7048 \layout List
7049 \labelwidthstring 00.00.0000
7050
7051
7052 \series bold 
7053 -
7054 \begin_inset ERT
7055 status Collapsed
7056
7057 \layout Standard
7058
7059 \backslash 
7060 /
7061 \end_inset 
7062
7063 -verbose
7064 \begin_inset LatexCommand \index{-\/-verbose}
7065
7066 \end_inset 
7067
7068
7069 \series default 
7070  Shows the various actions the compiler is performing.
7071 \layout List
7072 \labelwidthstring 00.00.0000
7073
7074
7075 \series bold 
7076 -V
7077 \begin_inset LatexCommand \index{-V}
7078
7079 \end_inset 
7080
7081
7082 \series default 
7083  Shows the actual commands the compiler is executing.
7084 \layout List
7085 \labelwidthstring 00.00.0000
7086
7087
7088 \series bold 
7089 -
7090 \begin_inset ERT
7091 status Collapsed
7092
7093 \layout Standard
7094
7095 \backslash 
7096 /
7097 \end_inset 
7098
7099 -no-c-code-in-asm
7100 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
7101
7102 \end_inset 
7103
7104
7105 \series default 
7106  Hides your ugly and inefficient c-code from the asm file, so you can always
7107  blame the compiler :).
7108 \layout List
7109 \labelwidthstring 00.00.0000
7110
7111
7112 \series bold 
7113 -
7114 \begin_inset ERT
7115 status Collapsed
7116
7117 \layout Standard
7118
7119 \backslash 
7120 /
7121 \end_inset 
7122
7123 -i-code-in-asm
7124 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
7125
7126 \end_inset 
7127
7128
7129 \series default 
7130  Include i-codes in the asm file.
7131  Sounds like noise but is most helpful for debugging the compiler itself.
7132 \layout List
7133 \labelwidthstring 00.00.0000
7134
7135
7136 \series bold 
7137 -
7138 \begin_inset ERT
7139 status Collapsed
7140
7141 \layout Standard
7142
7143 \backslash 
7144 /
7145 \end_inset 
7146
7147 -less-pedantic
7148 \begin_inset LatexCommand \index{-\/-less-pedantic}
7149
7150 \end_inset 
7151
7152
7153 \series default 
7154  Disable some of the more pedantic warnings
7155 \begin_inset LatexCommand \index{Warnings}
7156
7157 \end_inset 
7158
7159  (jwk burps: please be more specific here, please!).
7160  If you want rather more than less warnings you should consider using a
7161  separate tool dedicated to syntax checking like splint 
7162 \begin_inset LatexCommand \url{www.splint.org}
7163
7164 \end_inset 
7165
7166 .
7167 \layout List
7168 \labelwidthstring 00.00.0000
7169
7170
7171 \series bold 
7172 -
7173 \begin_inset ERT
7174 status Collapsed
7175
7176 \layout Standard
7177
7178 \backslash 
7179 /
7180 \end_inset 
7181
7182 -print-search-dirs
7183 \begin_inset LatexCommand \index{-\/-print-search-dirs}
7184
7185 \end_inset 
7186
7187
7188 \series default 
7189  Display the directories in the compiler's search path
7190 \layout List
7191 \labelwidthstring 00.00.0000
7192
7193
7194 \series bold 
7195 -
7196 \begin_inset ERT
7197 status Collapsed
7198
7199 \layout Standard
7200
7201 \backslash 
7202 /
7203 \end_inset 
7204
7205 -vc
7206 \begin_inset LatexCommand \index{-\/-vc}
7207
7208 \end_inset 
7209
7210
7211 \series default 
7212  Display errors and warnings using MSVC style, so you can use SDCC with
7213  visual studio.
7214 \layout List
7215 \labelwidthstring 00.00.0000
7216
7217
7218 \series bold 
7219 -
7220 \begin_inset ERT
7221 status Collapsed
7222
7223 \layout Standard
7224
7225 \backslash 
7226 /
7227 \end_inset 
7228
7229 -use-stdout
7230 \begin_inset LatexCommand \index{-\/-use-stdout}
7231
7232 \end_inset 
7233
7234
7235 \series default 
7236  Send errors and warnings to stdout instead of stderr.
7237 \layout List
7238 \labelwidthstring 00.00.0000
7239
7240
7241 \series bold 
7242 -Wa\SpecialChar ~
7243 asmOption[,asmOption]
7244 \series default 
7245
7246 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
7247
7248 \end_inset 
7249
7250 ...
7251  Pass the asmOption to the assembler
7252 \begin_inset LatexCommand \index{Options assembler}
7253
7254 \end_inset 
7255
7256
7257 \begin_inset LatexCommand \index{Assembler options}
7258
7259 \end_inset 
7260
7261 .
7262  See file sdcc/as/doc/asxhtm.html for assembler options.
7263 \layout Subsection
7264
7265 Intermediate Dump Options
7266 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
7267
7268 \end_inset 
7269
7270
7271 \begin_inset LatexCommand \index{Options intermediate dump}
7272
7273 \end_inset 
7274
7275
7276 \begin_inset LatexCommand \index{Intermediate dump options}
7277
7278 \end_inset 
7279
7280
7281 \layout Standard
7282
7283 The following options are provided for the purpose of retargetting and debugging
7284  the compiler.
7285  These provided a means to dump the intermediate code (iCode
7286 \begin_inset LatexCommand \index{iCode}
7287
7288 \end_inset 
7289
7290 ) generated by the compiler in human readable form at various stages of
7291  the compilation process.
7292  More on iCodes see chapter 
7293 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
7294
7295 \end_inset 
7296
7297  
7298 \begin_inset Quotes srd
7299 \end_inset 
7300
7301 The anatomy of the compiler
7302 \begin_inset Quotes srd
7303 \end_inset 
7304
7305 .
7306 \layout List
7307 \labelwidthstring 00.00.0000
7308
7309
7310 \series bold 
7311 -
7312 \begin_inset ERT
7313 status Collapsed
7314
7315 \layout Standard
7316
7317 \backslash 
7318 /
7319 \end_inset 
7320
7321 -dumpraw
7322 \begin_inset LatexCommand \index{-\/-dumpraw}
7323
7324 \end_inset 
7325
7326
7327 \series default 
7328  This option will cause the compiler to dump the intermediate code into
7329  a file of named 
7330 \emph on 
7331 <source filename>.dumpraw
7332 \emph default 
7333  just after the intermediate code has been generated for a function, i.e.
7334  before any optimizations are done.
7335  The basic blocks
7336 \begin_inset LatexCommand \index{Basic blocks}
7337
7338 \end_inset 
7339
7340  at this stage ordered in the depth first number, so they may not be in
7341  sequence of execution.
7342 \layout List
7343 \labelwidthstring 00.00.0000
7344
7345
7346 \series bold 
7347 -
7348 \begin_inset ERT
7349 status Collapsed
7350
7351 \layout Standard
7352
7353 \backslash 
7354 /
7355 \end_inset 
7356
7357 -dumpgcse
7358 \begin_inset LatexCommand \index{-\/-dumpgcse}
7359
7360 \end_inset 
7361
7362
7363 \series default 
7364  Will create a dump of iCode's, after global subexpression elimination
7365 \begin_inset LatexCommand \index{Global subexpression elimination}
7366
7367 \end_inset 
7368
7369 , into a file named 
7370 \emph on 
7371 <source filename>.dumpgcse.
7372 \layout List
7373 \labelwidthstring 00.00.0000
7374
7375
7376 \series bold 
7377 -
7378 \begin_inset ERT
7379 status Collapsed
7380
7381 \layout Standard
7382
7383 \backslash 
7384 /
7385 \end_inset 
7386
7387 -dumpdeadcode
7388 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
7389
7390 \end_inset 
7391
7392
7393 \series default 
7394  Will create a dump of iCode's, after deadcode elimination
7395 \begin_inset LatexCommand \index{Dead-code elimination}
7396
7397 \end_inset 
7398
7399 , into a file named 
7400 \emph on 
7401 <source filename>.dumpdeadcode.
7402 \layout List
7403 \labelwidthstring 00.00.0000
7404
7405
7406 \series bold 
7407 -
7408 \begin_inset ERT
7409 status Collapsed
7410
7411 \layout Standard
7412
7413 \backslash 
7414 /
7415 \end_inset 
7416
7417 -dumploop
7418 \begin_inset LatexCommand \index{-\/-dumploop}
7419
7420 \end_inset 
7421
7422
7423 \series default 
7424 \size large 
7425  
7426 \size default 
7427 Will create a dump of iCode's, after loop optimizations
7428 \begin_inset LatexCommand \index{Loop optimization}
7429
7430 \end_inset 
7431
7432 , into a file named 
7433 \emph on 
7434 <source filename>.dumploop.
7435 \layout List
7436 \labelwidthstring 00.00.0000
7437
7438
7439 \series bold 
7440 -
7441 \begin_inset ERT
7442 status Collapsed
7443
7444 \layout Standard
7445
7446 \backslash 
7447 /
7448 \end_inset 
7449
7450 -dumprange
7451 \begin_inset LatexCommand \index{-\/-dumprange}
7452
7453 \end_inset 
7454
7455
7456 \series default 
7457 \size large 
7458  
7459 \size default 
7460 Will create a dump of iCode's, after live range analysis
7461 \begin_inset LatexCommand \index{Live range analysis}
7462
7463 \end_inset 
7464
7465 , into a file named 
7466 \emph on 
7467 <source filename>.dumprange.
7468 \layout List
7469 \labelwidthstring 00.00.0000
7470
7471
7472 \series bold 
7473 -
7474 \begin_inset ERT
7475 status Collapsed
7476
7477 \layout Standard
7478
7479 \backslash 
7480 /
7481 \end_inset 
7482
7483 -dumlrange
7484 \begin_inset LatexCommand \index{-\/-dumlrange}
7485
7486 \end_inset 
7487
7488
7489 \series default 
7490  Will dump the life ranges
7491 \begin_inset LatexCommand \index{Live range analysis}
7492
7493 \end_inset 
7494
7495  for all symbols.
7496 \layout List
7497 \labelwidthstring 00.00.0000
7498
7499
7500 \series bold 
7501 -
7502 \begin_inset ERT
7503 status Collapsed
7504
7505 \layout Standard
7506
7507 \backslash 
7508 /
7509 \end_inset 
7510
7511 -dumpregassign
7512 \begin_inset LatexCommand \index{-\/-dumpregassign}
7513
7514 \end_inset 
7515
7516
7517 \bar under 
7518  
7519 \series default 
7520 \bar default 
7521 Will create a dump of iCode's, after register assignment
7522 \begin_inset LatexCommand \index{Register assignment}
7523
7524 \end_inset 
7525
7526 , into a file named 
7527 \emph on 
7528 <source filename>.dumprassgn.
7529 \layout List
7530 \labelwidthstring 00.00.0000
7531
7532
7533 \series bold 
7534 -
7535 \begin_inset ERT
7536 status Collapsed
7537
7538 \layout Standard
7539
7540 \backslash 
7541 /
7542 \end_inset 
7543
7544 -dumplrange
7545 \begin_inset LatexCommand \index{-\/-dumplrange}
7546
7547 \end_inset 
7548
7549
7550 \series default 
7551  Will create a dump of the live ranges of iTemp's
7552 \layout List
7553 \labelwidthstring 00.00.0000
7554
7555
7556 \series bold 
7557 -
7558 \begin_inset ERT
7559 status Collapsed
7560
7561 \layout Standard
7562
7563 \backslash 
7564 /
7565 \end_inset 
7566
7567 -dumpall
7568 \begin_inset LatexCommand \index{-\/-dumpall}
7569
7570 \end_inset 
7571
7572
7573 \size large 
7574 \bar under 
7575  
7576 \series default 
7577 \size default 
7578 \bar default 
7579 Will cause all the above mentioned dumps to be created.
7580 \layout Subsection
7581
7582 Redirecting output on Windows Shells
7583 \layout Standard
7584
7585 By default SDCC writes it's error messages to 
7586 \begin_inset Quotes sld
7587 \end_inset 
7588
7589 standard error
7590 \begin_inset Quotes srd
7591 \end_inset 
7592
7593 .
7594  To force all messages to 
7595 \begin_inset Quotes sld
7596 \end_inset 
7597
7598 standard output
7599 \begin_inset Quotes srd
7600 \end_inset 
7601
7602  use 
7603 \series bold 
7604 -
7605 \series default 
7606 \emph on 
7607
7608 \begin_inset ERT
7609 status Collapsed
7610
7611 \layout Standard
7612
7613 \backslash 
7614 /
7615 \end_inset 
7616
7617
7618 \series bold 
7619 \emph default 
7620 -
7621 \series default 
7622 use-stdout
7623 \begin_inset LatexCommand \index{-\/-use-stdout}
7624
7625 \end_inset 
7626
7627 .
7628  Additionally, if you happen to have visual studio installed in your windows
7629  machine, you can use it to compile your sources using a custom build and
7630  the SDCC -
7631 \emph on 
7632
7633 \begin_inset ERT
7634 status Collapsed
7635
7636 \layout Standard
7637
7638 \backslash 
7639 /
7640 \end_inset 
7641
7642
7643 \emph default 
7644 -vc
7645 \begin_inset LatexCommand \index{-\/-vc}
7646
7647 \end_inset 
7648
7649  option.
7650  Something like this should work:
7651 \newline 
7652
7653 \newline 
7654
7655 \series bold 
7656 c:
7657 \backslash 
7658 sdcc
7659 \backslash 
7660 bin
7661 \backslash 
7662 sdcc.exe -
7663 \series default 
7664 \emph on 
7665
7666 \begin_inset ERT
7667 status Collapsed
7668
7669 \layout Standard
7670
7671 \backslash 
7672 /
7673 \end_inset 
7674
7675
7676 \series bold 
7677 \emph default 
7678 -vc -
7679 \series default 
7680 \emph on 
7681
7682 \begin_inset ERT
7683 status Collapsed
7684
7685 \layout Standard
7686
7687 \backslash 
7688 /
7689 \end_inset 
7690
7691
7692 \series bold 
7693 \emph default 
7694 -model-large -c $(InputPath)
7695 \layout Section
7696
7697 Environment variables
7698 \begin_inset LatexCommand \index{Environment variables}
7699
7700 \end_inset 
7701
7702
7703 \layout Standard
7704
7705 SDCC recognizes the following environment variables:
7706 \layout List
7707 \labelwidthstring 00.00.0000
7708
7709
7710 \series bold 
7711 SDCC_LEAVE_SIGNALS
7712 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
7713
7714 \end_inset 
7715
7716
7717 \series default 
7718  SDCC installs a signal handler
7719 \begin_inset LatexCommand \index{signal handler}
7720
7721 \end_inset 
7722
7723  to be able to delete temporary files after an user break (^C) or an exception.
7724  If this environment variable is set, SDCC won't install the signal handler
7725  in order to be able to debug SDCC.
7726 \layout List
7727 \labelwidthstring 00.00.0000
7728
7729
7730 \series bold 
7731 TMP,\SpecialChar ~
7732 TEMP,\SpecialChar ~
7733 TMPDIR
7734 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
7735
7736 \end_inset 
7737
7738
7739 \series default 
7740  Path, where temporary files will be created.
7741  The order of the variables is the search order.
7742  In a standard *nix environment these variables are not set, and there's
7743  no need to set them.
7744  On Windows it's recommended to set one of them.
7745 \layout List
7746 \labelwidthstring 00.00.0000
7747
7748
7749 \series bold 
7750 SDCC_HOME
7751 \begin_inset LatexCommand \index{SDCC\_HOME}
7752
7753 \end_inset 
7754
7755
7756 \series default 
7757  Path, see section 
7758 \begin_inset LatexCommand \ref{sub:Install-paths}
7759
7760 \end_inset 
7761
7762 \SpecialChar ~
7763
7764 \begin_inset Quotes sld
7765 \end_inset 
7766
7767  Install Paths
7768 \begin_inset Quotes srd
7769 \end_inset 
7770
7771 .
7772 \layout List
7773 \labelwidthstring 00.00.0000
7774
7775
7776 \series bold 
7777 SDCC_INCLUDE
7778 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
7779
7780 \end_inset 
7781
7782
7783 \series default 
7784  Path, see section 
7785 \begin_inset LatexCommand \ref{sub:Search-Paths}
7786
7787 \end_inset 
7788
7789 \SpecialChar ~
7790
7791 \begin_inset Quotes sld
7792 \end_inset 
7793
7794 Search Paths
7795 \begin_inset Quotes srd
7796 \end_inset 
7797
7798 .
7799 \layout List
7800 \labelwidthstring 00.00.0000
7801
7802
7803 \series bold 
7804 SDCC_LIB
7805 \begin_inset LatexCommand \index{SDCC\_LIB}
7806
7807 \end_inset 
7808
7809
7810 \series default 
7811  Path, see section 
7812 \begin_inset LatexCommand \ref{sub:Search-Paths}
7813
7814 \end_inset 
7815
7816 \SpecialChar ~
7817
7818 \begin_inset Quotes sld
7819 \end_inset 
7820
7821 Search Paths
7822 \begin_inset Quotes srd
7823 \end_inset 
7824
7825 ..
7826 \layout Standard
7827
7828 There are some more environment variables recognized by SDCC, but these
7829  are solely used for debugging purposes.
7830  They can change or disappear very quickly, and will never be documented.
7831 \layout Section
7832
7833 Storage Class Language Extensions
7834 \layout Subsection
7835
7836 MCS51/DS390 Storage Class
7837 \begin_inset LatexCommand \index{Storage class}
7838
7839 \end_inset 
7840
7841  Language Extensions
7842 \layout Standard
7843
7844 In addition to the ANSI storage classes SDCC allows the following MCS51
7845  specific storage classes:
7846 \layout Subsubsection
7847
7848 data
7849 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7850
7851 \end_inset 
7852
7853  / near
7854 \begin_inset LatexCommand \index{near (storage class)}
7855
7856 \end_inset 
7857
7858
7859 \layout Standard
7860
7861 This is the 
7862 \series bold 
7863 default
7864 \series default 
7865  storage class for the Small Memory model (
7866 \emph on 
7867 data
7868 \emph default 
7869  and 
7870 \emph on 
7871 near
7872 \emph default 
7873  can be used synonymously).
7874  Variables declared with this storage class will be allocated in the directly
7875  addressable portion of the internal RAM of a 8051, e.g.:
7876 \layout Verse
7877
7878
7879 \family typewriter 
7880 data unsigned char test_data;
7881 \layout Standard
7882
7883 Writing 0x01 to this variable generates the assembly code:
7884 \layout Verse
7885
7886
7887 \family typewriter 
7888 75*00 01\SpecialChar ~
7889 \SpecialChar ~
7890 \SpecialChar ~
7891 mov\SpecialChar ~
7892 \SpecialChar ~
7893 _test_data,#0x01 
7894 \layout Subsubsection
7895
7896 xdata
7897 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
7898
7899 \end_inset 
7900
7901  / far
7902 \begin_inset LatexCommand \index{far (storage class)}
7903
7904 \end_inset 
7905
7906
7907 \layout Standard
7908
7909 Variables declared with this storage class will be placed in the external
7910  RAM.
7911  This is the 
7912 \series bold 
7913 default
7914 \series default 
7915  storage class for the Large Memory model, e.g.:
7916 \layout Verse
7917
7918
7919 \family typewriter 
7920 xdata unsigned char test_xdata;
7921 \layout Standard
7922
7923 Writing 0x01 to this variable generates the assembly code:
7924 \layout Verse
7925
7926
7927 \family typewriter 
7928 90s00r00\SpecialChar ~
7929 \SpecialChar ~
7930 \SpecialChar ~
7931 mov\SpecialChar ~
7932 \SpecialChar ~
7933 dptr,#_test_xdata 
7934 \newline 
7935 74\SpecialChar ~
7936 01\SpecialChar ~
7937 \SpecialChar ~
7938 \SpecialChar ~
7939 \SpecialChar ~
7940 \SpecialChar ~
7941 \SpecialChar ~
7942 mov\SpecialChar ~
7943 \SpecialChar ~
7944 a,#0x01 
7945 \newline 
7946 F0\SpecialChar ~
7947 \SpecialChar ~
7948 \SpecialChar ~
7949 \SpecialChar ~
7950 \SpecialChar ~
7951 \SpecialChar ~
7952 \SpecialChar ~
7953 \SpecialChar ~
7954 \SpecialChar ~
7955 movx\SpecialChar ~
7956 @dptr,a 
7957 \layout Subsubsection
7958
7959 idata
7960 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
7961
7962 \end_inset 
7963
7964
7965 \layout Standard
7966
7967 Variables declared with this storage class will be allocated into the indirectly
7968  addressable portion of the internal ram of a 8051, e.g.:
7969 \layout Verse
7970
7971
7972 \family typewriter 
7973 idata unsigned char test_idata;
7974 \layout Standard
7975
7976 Writing 0x01 to this variable generates the assembly code:
7977 \layout Verse
7978
7979
7980 \family typewriter 
7981 78r00\SpecialChar ~
7982 \SpecialChar ~
7983 \SpecialChar ~
7984 \SpecialChar ~
7985 \SpecialChar ~
7986 \SpecialChar ~
7987 \SpecialChar ~
7988 mov\SpecialChar ~
7989 \SpecialChar ~
7990 r0,#_test_idata
7991 \newline 
7992 76\SpecialChar ~
7993 01\SpecialChar ~
7994 \SpecialChar ~
7995 \SpecialChar ~
7996 \SpecialChar ~
7997 \SpecialChar ~
7998 \SpecialChar ~
7999 \SpecialChar ~
8000 mov\SpecialChar ~
8001 \SpecialChar ~
8002 @r0,#0x01
8003 \layout Standard
8004
8005 Please note, the first 128 byte of idata physically access the same RAM
8006  as the data memory.
8007  The original 8051 had 128 byte idata memory, nowadays most devices have
8008  256 byte idata memory.
8009  The stack
8010 \begin_inset LatexCommand \index{stack}
8011
8012 \end_inset 
8013
8014  is located in idata memory.
8015 \layout Subsubsection
8016
8017 pdata
8018 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8019
8020 \end_inset 
8021
8022
8023 \layout Standard
8024
8025 Paged xdata access is currently not as straightforward as using the other
8026  addressing modes of a 8051.
8027  The following example writes 0x01 to the address pointed to.
8028  Please note, pdata access physically accesses xdata memory.
8029  The high byte of the address is determined by port P2 
8030 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
8031
8032 \end_inset 
8033
8034 (or in case of some 8051 variants by a separate Special Function Register,
8035  see section 
8036 \begin_inset LatexCommand \ref{sub:MCS51-variants}
8037
8038 \end_inset 
8039
8040 ).
8041 \layout Verse
8042
8043
8044 \family typewriter 
8045 pdata unsigned char *test_pdata_ptr;
8046 \newline 
8047
8048 \newline 
8049 void main() 
8050 \newline 
8051
8052 \newline 
8053 \SpecialChar ~
8054 \SpecialChar ~
8055 \SpecialChar ~
8056 \SpecialChar ~
8057 test_pdata_ptr = (pdata *)0xfe; 
8058 \newline 
8059 \SpecialChar ~
8060 \SpecialChar ~
8061 \SpecialChar ~
8062 \SpecialChar ~
8063 *test_pdata_ptr = 1; 
8064 \newline 
8065
8066 \layout Standard
8067
8068 Generates the assembly code:
8069 \layout Verse
8070
8071
8072 \family typewriter 
8073 75*01 FE\SpecialChar ~
8074 \SpecialChar ~
8075 \SpecialChar ~
8076 mov\SpecialChar ~
8077  _test_pdata_ptr,#0xFE
8078 \newline 
8079 78 FE\SpecialChar ~
8080 \SpecialChar ~
8081 \SpecialChar ~
8082 \SpecialChar ~
8083 \SpecialChar ~
8084 \SpecialChar ~
8085 mov\SpecialChar ~
8086  r0,#0xFE 
8087 \newline 
8088 74 01\SpecialChar ~
8089 \SpecialChar ~
8090 \SpecialChar ~
8091 \SpecialChar ~
8092 \SpecialChar ~
8093 \SpecialChar ~
8094 mov\SpecialChar ~
8095  a,#0x01
8096 \newline 
8097 F2\SpecialChar ~
8098 \SpecialChar ~
8099 \SpecialChar ~
8100 \SpecialChar ~
8101 \SpecialChar ~
8102 \SpecialChar ~
8103 \SpecialChar ~
8104 \SpecialChar ~
8105 \SpecialChar ~
8106 movx @r0,a 
8107 \layout Standard
8108
8109 Be extremely carefull if you use pdata together with the -
8110 \begin_inset ERT
8111 status Collapsed
8112
8113 \layout Standard
8114
8115 \backslash 
8116 /
8117 \end_inset 
8118
8119 -xstack
8120 \begin_inset LatexCommand \index{-\/-xstack}
8121
8122 \end_inset 
8123
8124  option.
8125 \layout Subsubsection
8126
8127 code
8128 \begin_inset LatexCommand \index{code}
8129
8130 \end_inset 
8131
8132
8133 \layout Standard
8134
8135 'Variables' declared with this storage class will be placed in the code
8136  memory:
8137 \layout Verse
8138
8139
8140 \family typewriter 
8141 code unsigned char test_code;
8142 \layout Standard
8143
8144 Read access to this variable generates the assembly code:
8145 \layout Verse
8146
8147
8148 \family typewriter 
8149 90s00r6F\SpecialChar ~
8150 \SpecialChar ~
8151 \SpecialChar ~
8152 mov dptr,#_test_code
8153 \newline 
8154 E4\SpecialChar ~
8155 \SpecialChar ~
8156 \SpecialChar ~
8157 \SpecialChar ~
8158 \SpecialChar ~
8159 \SpecialChar ~
8160 \SpecialChar ~
8161 \SpecialChar ~
8162 \SpecialChar ~
8163 clr a
8164 \newline 
8165 93\SpecialChar ~
8166 \SpecialChar ~
8167 \SpecialChar ~
8168 \SpecialChar ~
8169 \SpecialChar ~
8170 \SpecialChar ~
8171 \SpecialChar ~
8172 \SpecialChar ~
8173 \SpecialChar ~
8174 movc a,@a+dptr 
8175 \layout Standard
8176
8177
8178 \family typewriter 
8179 char
8180 \family default 
8181  indexed arrays of characters in code memory can be accessed efficiently:
8182 \layout Verse
8183
8184
8185 \family typewriter 
8186 code char test_array[] = {'c','h','e','a','p'}; 
8187 \layout Standard
8188
8189 Read access to this array using an 8-bit unsigned index generates the assembly
8190  code:
8191 \layout Verse
8192
8193
8194 \family typewriter 
8195 E5*00\SpecialChar ~
8196 \SpecialChar ~
8197 \SpecialChar ~
8198 \SpecialChar ~
8199 \SpecialChar ~
8200 \SpecialChar ~
8201 mov a,_index 
8202 \layout Verse
8203
8204
8205 \family typewriter 
8206 90s00r41\SpecialChar ~
8207 \SpecialChar ~
8208 \SpecialChar ~
8209 mov dptr,#_test_array
8210 \layout Verse
8211
8212
8213 \family typewriter 
8214 93\SpecialChar ~
8215 \SpecialChar ~
8216 \SpecialChar ~
8217 \SpecialChar ~
8218 \SpecialChar ~
8219 \SpecialChar ~
8220 \SpecialChar ~
8221 \SpecialChar ~
8222 \SpecialChar ~
8223 movc a,@a+dptr 
8224 \layout Subsubsection
8225
8226 bit
8227 \begin_inset LatexCommand \index{bit}
8228
8229 \end_inset 
8230
8231
8232 \layout Standard
8233
8234 This is a data-type and a storage class specifier.
8235  When a variable is declared as a bit, it is allocated into the bit addressable
8236  memory of 8051, e.g.:
8237 \layout Verse
8238
8239
8240 \family typewriter 
8241 bit test_bit;
8242 \layout Standard
8243
8244 Writing 1 to this variable generates the assembly code:
8245 \layout Verse
8246
8247
8248 \family typewriter 
8249 D2*00\SpecialChar ~
8250 \SpecialChar ~
8251 \SpecialChar ~
8252 \SpecialChar ~
8253 \SpecialChar ~
8254 \SpecialChar ~
8255 \SpecialChar ~
8256 setb\SpecialChar ~
8257 _test_bit
8258 \layout Standard
8259
8260 The bit addressable memory consists of 128 bits which are located from 0x20
8261  to 0x2f in data memory.
8262  
8263 \layout Standard
8264
8265 Apart from this 8051 specific storage class most architectures support ANSI-C
8266  bitfields
8267 \begin_inset LatexCommand \index{bitfields}
8268
8269 \end_inset 
8270
8271  
8272 \begin_inset Foot
8273 collapsed false
8274
8275 \layout Standard
8276
8277 Not really meant as examples, but nevertheless showing what bitfields are
8278  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
8279 \end_inset 
8280
8281 .
8282 \layout Subsubsection
8283
8284 sfr
8285 \begin_inset LatexCommand \index{sfr}
8286
8287 \end_inset 
8288
8289  / sbit
8290 \begin_inset LatexCommand \index{sbit}
8291
8292 \end_inset 
8293
8294
8295 \layout Standard
8296
8297 Like the bit keyword, 
8298 \emph on 
8299 sfr / sbit 
8300 \emph default 
8301 signifies both a data-type and storage class, they are used to describe
8302  the 
8303 \emph on 
8304 s
8305 \emph default 
8306 pecial 
8307 \emph on 
8308 f
8309 \emph default 
8310 unction 
8311 \emph on 
8312 r
8313 \emph default 
8314 egisters and 
8315 \emph on 
8316 s
8317 \emph default 
8318 pecial 
8319 \emph on 
8320 bit
8321 \emph default 
8322  variables of a 8051, eg:
8323 \layout Verse
8324
8325
8326 \family typewriter 
8327 sfr at
8328 \begin_inset LatexCommand \index{at}
8329
8330 \end_inset 
8331
8332  0x80 P0;\SpecialChar ~
8333  /* special function register P0 at location 0x80 */
8334 \newline 
8335 sbit at 0xd7 CY; /* CY (Carry Flag
8336 \begin_inset LatexCommand \index{Flags}
8337
8338 \end_inset 
8339
8340
8341 \begin_inset LatexCommand \index{Carry flag}
8342
8343 \end_inset 
8344
8345 ) */
8346 \layout Standard
8347
8348 Special function registers which are located on an address dividable by
8349  8 are bit-addressable, an
8350 \emph on 
8351  sbit
8352 \emph default 
8353  addresses a specific bit within these sfr.
8354 \layout Subsubsection
8355
8356 Pointers
8357 \begin_inset LatexCommand \index{Pointer}
8358
8359 \end_inset 
8360
8361  to MCS51/DS390 specific memory spaces
8362 \layout Standard
8363
8364 SDCC allows (via language extensions) pointers to explicitly point to any
8365  of the memory spaces
8366 \begin_inset LatexCommand \index{Memory model}
8367
8368 \end_inset 
8369
8370  of the 8051.
8371  In addition to the explicit pointers, the compiler uses (by default) generic
8372  pointers which can be used to point to any of the memory spaces.
8373 \newline 
8374
8375 \newline 
8376 Pointer declaration examples:
8377 \layout Verse
8378
8379
8380 \family typewriter 
8381 /* pointer physically in internal ram pointing to object in external ram
8382  */ 
8383 \newline 
8384 xdata unsigned char * data p;
8385 \newline 
8386
8387 \newline 
8388 /* pointer physically in external ram pointing to object in internal ram
8389  */ 
8390 \newline 
8391 data unsigned char * xdata p;
8392 \newline 
8393
8394 \newline 
8395 /* pointer physically in code rom pointing to data in xdata space */ 
8396 \newline 
8397 xdata unsigned char * code p;
8398 \newline 
8399
8400 \newline 
8401 /* pointer physically in code space pointing to data in code space */ 
8402 \newline 
8403 code unsigned char * code p;
8404 \newline 
8405
8406 \newline 
8407 /* the following is a generic pointer physically located in xdata space
8408  */
8409 \newline 
8410 char * xdata p;
8411 \layout Standard
8412
8413 Well you get the idea.
8414  
8415 \newline 
8416
8417 \newline 
8418 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
8419 \emph on 
8420 generic
8421 \emph default 
8422  pointers.
8423  
8424 \size small 
8425
8426 \newline 
8427
8428 \newline 
8429
8430 \size default 
8431 The highest order byte of the 
8432 \emph on 
8433 generic
8434 \emph default 
8435  pointers contains the data space information.
8436  Assembler support routines are called whenever data is stored or retrieved
8437  using 
8438 \emph on 
8439 generic
8440 \emph default 
8441  pointers.
8442  These are useful for developing reusable library
8443 \begin_inset LatexCommand \index{Libraries}
8444
8445 \end_inset 
8446
8447  routines.
8448  Explicitly specifying the pointer type will generate the most efficient
8449  code.
8450 \layout Subsubsection
8451
8452 Notes on MCS51 memory
8453 \begin_inset LatexCommand \index{MCS51 memory}
8454
8455 \end_inset 
8456
8457  layout
8458 \layout Standard
8459
8460 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
8461  RAM memory which is structured as follows:
8462 \newline 
8463
8464 \newline 
8465 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
8466  
8467 \newline 
8468 - Bytes 20-2F - 16 bytes to hold 128 bit
8469 \begin_inset LatexCommand \index{bit}
8470
8471 \end_inset 
8472
8473  variables and, 
8474 \newline 
8475 - Bytes 30-7F - 80 bytes for general purpose use.
8476 \newline 
8477
8478 \layout Standard
8479
8480 Additionally some members of the MCS51 family may have up to 128 bytes of
8481  additional, indirectly addressable, internal RAM memory (
8482 \emph on 
8483 idata
8484 \emph default 
8485
8486 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
8487
8488 \end_inset 
8489
8490 ).
8491  Furthermore, some chips may have some built in external memory (
8492 \emph on 
8493 xdata
8494 \emph default 
8495
8496 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
8497
8498 \end_inset 
8499
8500 ) which should not be confused with the internal, directly addressable RAM
8501  memory (
8502 \emph on 
8503 data
8504 \emph default 
8505
8506 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
8507
8508 \end_inset 
8509
8510 ).
8511  Sometimes this built in 
8512 \emph on 
8513 xdata
8514 \emph default 
8515  memory has to be activated before using it (you can probably find this
8516  information on the datasheet of the microcontroller your are using, see
8517  also section 
8518 \begin_inset LatexCommand \ref{sub:Startup-Code}
8519
8520 \end_inset 
8521
8522 \SpecialChar ~
8523 Startup-Code).
8524 \layout Standard
8525
8526 Normally SDCC will only use the first bank
8527 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
8528
8529 \end_inset 
8530
8531  of registers (register bank 0), but it is possible to specify that other
8532  banks of registers should be used in interrupt
8533 \begin_inset LatexCommand \index{interrupt}
8534
8535 \end_inset 
8536
8537  routines.
8538  By default, the compiler will place the stack after the last byte of allocated
8539  memory for variables.
8540  For example, if the first 2 banks of registers are used, and only four
8541  bytes are used for 
8542 \emph on 
8543 data
8544 \emph default 
8545  variables, it will position the base of the internal stack at address 20
8546  (0x14).
8547  This implies that as the stack
8548 \begin_inset LatexCommand \index{stack}
8549
8550 \end_inset 
8551
8552  grows, it will use up the remaining register banks, and the 16 bytes used
8553  by the 128 bit variables, and 80 bytes for general purpose use.
8554  If any bit variables are used, the data variables will be placed after
8555  the byte holding the last bit variable.
8556  For example, if register banks 0 and 1 are used, and there are 9 bit variables
8557  (two bytes used), 
8558 \emph on 
8559 data
8560 \emph default 
8561  variables will be placed starting at address 0x22.
8562  You can also use -
8563 \begin_inset ERT
8564 status Collapsed
8565
8566 \layout Standard
8567
8568 \backslash 
8569 /
8570 \end_inset 
8571
8572 -data-loc
8573 \begin_inset LatexCommand \index{-\/-data-loc<Value>}
8574
8575 \end_inset 
8576
8577  to specify the start address of the 
8578 \emph on 
8579 data
8580 \emph default 
8581  and -
8582 \begin_inset ERT
8583 status Collapsed
8584
8585 \layout Standard
8586
8587 \backslash 
8588 /
8589 \end_inset 
8590
8591 -iram-size to specify the size of the total internal RAM (
8592 \emph on 
8593 data
8594 \emph default 
8595 +
8596 \emph on 
8597 idata
8598 \emph default 
8599 ).
8600  
8601 \layout Standard
8602
8603 By default the 8051 linker will place the stack after the last byte of data
8604  variables.
8605  Option -
8606 \begin_inset ERT
8607 status Collapsed
8608
8609 \layout Standard
8610
8611 \backslash 
8612 /
8613 \end_inset 
8614
8615 -stack-loc
8616 \begin_inset LatexCommand \index{-\/-stack-loc<Value>}
8617
8618 \end_inset 
8619
8620  allows you to specify the start of the stack, i.e.
8621  you could start it after any data in the general purpose area.
8622  If your microcontroller has additional indirectly addressable internal
8623  RAM (
8624 \emph on 
8625 idata
8626 \emph default 
8627 ) you can place the stack on it.
8628  You may also need to use -
8629 \begin_inset ERT
8630 status Collapsed
8631
8632 \layout Standard
8633
8634 \backslash 
8635 /
8636 \end_inset 
8637
8638 -xdata-loc
8639 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
8640
8641 \end_inset 
8642
8643  to set the start address of the external RAM (
8644 \emph on 
8645 xdata
8646 \emph default 
8647 ) and -
8648 \begin_inset ERT
8649 status Collapsed
8650
8651 \layout Standard
8652
8653 \backslash 
8654 /
8655 \end_inset 
8656
8657 -xram-size
8658 \begin_inset LatexCommand \index{-\/-data-loc}
8659
8660 \end_inset 
8661
8662  to specify its size.
8663  Same goes for the code memory, using -
8664 \begin_inset ERT
8665 status Collapsed
8666
8667 \layout Standard
8668
8669 \backslash 
8670 /
8671 \end_inset 
8672
8673 -code-loc
8674 \begin_inset LatexCommand \index{-\/-data-loc}
8675
8676 \end_inset 
8677
8678  and -
8679 \begin_inset ERT
8680 status Collapsed
8681
8682 \layout Standard
8683
8684 \backslash 
8685 /
8686 \end_inset 
8687
8688 -code-size
8689 \begin_inset LatexCommand \index{-\/-data-loc}
8690
8691 \end_inset 
8692
8693 .
8694  If in doubt, don't specify any options and see if the resulting memory
8695  layout is appropriate, then you can adjust it.
8696 \layout Standard
8697
8698 The linker generates two files with memory allocation information.
8699  The first, with extension .map
8700 \begin_inset LatexCommand \index{<file>.map}
8701
8702 \end_inset 
8703
8704  shows all the variables and segments.
8705  The second with extension .mem
8706 \begin_inset LatexCommand \index{<file>.mem}
8707
8708 \end_inset 
8709
8710  shows the final memory layout.
8711  The linker will complain either if memory segments overlap, there is not
8712  enough memory, or there is not enough space for stack.
8713  If you get any linking warnings and/or errors related to stack or segments
8714  allocation, take a look at either the .map or .mem files to find out what
8715  the problem is.
8716  The .mem file may even suggest a solution to the problem.
8717 \layout Subsection
8718
8719 Z80/Z180 Storage Class
8720 \begin_inset LatexCommand \index{Storage class}
8721
8722 \end_inset 
8723
8724  Language Extensions
8725 \layout Subsubsection
8726
8727 sfr
8728 \begin_inset LatexCommand \index{sfr}
8729
8730 \end_inset 
8731
8732  (in/out to 8-bit addresses)
8733 \layout Standard
8734
8735 The Z80
8736 \begin_inset LatexCommand \index{Z80}
8737
8738 \end_inset 
8739
8740  family has separate address spaces for memory and 
8741 \emph on 
8742 i
8743 \emph default 
8744 nput/
8745 \emph on 
8746 o
8747 \emph default 
8748 utput memory.
8749  I/O memory
8750 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
8751
8752 \end_inset 
8753
8754  is accessed with special instructions, e.g.:
8755 \layout Verse
8756
8757
8758 \family typewriter 
8759 sfr at 0x78 IoPort;\SpecialChar ~
8760 \SpecialChar ~
8761 /* define a var in I/O space at 78h called IoPort */
8762  
8763 \layout Standard
8764
8765 Writing 0x01 to this variable generates the assembly code:
8766 \layout Verse
8767
8768
8769 \family typewriter 
8770 3E 01\SpecialChar ~
8771 \SpecialChar ~
8772 \SpecialChar ~
8773 \SpecialChar ~
8774 \SpecialChar ~
8775 \SpecialChar ~
8776 ld a,#0x01
8777 \newline 
8778 D3 78\SpecialChar ~
8779 \SpecialChar ~
8780 \SpecialChar ~
8781 \SpecialChar ~
8782 \SpecialChar ~
8783 \SpecialChar ~
8784 out (_IoPort),a 
8785 \layout Subsubsection
8786
8787 banked sfr
8788 \begin_inset LatexCommand \index{sfr}
8789
8790 \end_inset 
8791
8792  (in/out to 16-bit addresses)
8793 \layout Standard
8794
8795 The keyword 
8796 \emph on 
8797 banked
8798 \emph default 
8799  is used to support 16 bit addresses in I/O memory e.g.:
8800 \layout Verse
8801
8802
8803 \family typewriter 
8804 sfr banked at
8805 \begin_inset LatexCommand \index{at}
8806
8807 \end_inset 
8808
8809  0x123 IoPort; 
8810 \layout Standard
8811
8812 Writing 0x01 to this variable generates the assembly code:
8813 \layout Verse
8814
8815
8816 \family typewriter 
8817 01 23 01\SpecialChar ~
8818 \SpecialChar ~
8819 \SpecialChar ~
8820 ld bc,#_IoPort
8821 \newline 
8822 3E 01\SpecialChar ~
8823 \SpecialChar ~
8824 \SpecialChar ~
8825 \SpecialChar ~
8826 \SpecialChar ~
8827 \SpecialChar ~
8828 ld a,#0x01 
8829 \newline 
8830 ED 79\SpecialChar ~
8831 \SpecialChar ~
8832 \SpecialChar ~
8833 \SpecialChar ~
8834 \SpecialChar ~
8835 \SpecialChar ~
8836 out (c),a 
8837 \layout Subsubsection
8838
8839 sfr
8840 \begin_inset LatexCommand \index{sfr}
8841
8842 \end_inset 
8843
8844  (in0/out0 to 8 bit addresses on Z180
8845 \begin_inset LatexCommand \index{Z180}
8846
8847 \end_inset 
8848
8849 /HD64180
8850 \begin_inset LatexCommand \index{HD64180}
8851
8852 \end_inset 
8853
8854 )
8855 \layout Standard
8856
8857 The compiler option -
8858 \begin_inset ERT
8859 status Collapsed
8860
8861 \layout Standard
8862
8863 \backslash 
8864 /
8865 \end_inset 
8866
8867 -portmode=180 (80) and a compiler #pragma\SpecialChar ~
8868 portmode
8869 \begin_inset LatexCommand \index{\#pragma portmode}
8870
8871 \end_inset 
8872
8873 =z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
8874 ns 
8875 \family typewriter 
8876 in0/out0
8877 \family default 
8878  instead of 
8879 \family typewriter 
8880 in/out
8881 \family default 
8882 .
8883  If you include the file z180.h this will be set automatically.
8884 \layout Section
8885
8886 Absolute Addressing
8887 \begin_inset LatexCommand \index{Absolute addressing}
8888
8889 \end_inset 
8890
8891
8892 \layout Standard
8893
8894 Data items can be assigned an absolute address with the 
8895 \emph on 
8896 at
8897 \begin_inset LatexCommand \index{at}
8898
8899 \end_inset 
8900
8901  <address>
8902 \emph default 
8903  keyword, in addition to a storage class, e.g.:
8904 \layout Verse
8905
8906
8907 \family typewriter 
8908 xdata
8909 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
8910
8911 \end_inset 
8912
8913  at
8914 \begin_inset LatexCommand \index{at}
8915
8916 \end_inset 
8917
8918  0x7ffe unsigned int chksum;
8919 \layout Standard
8920
8921 In the above example the variable chksum will located at 0x7ffe and 0x7fff
8922  of the external ram.
8923  The compiler does 
8924 \emph on 
8925 not
8926 \emph default 
8927  reserve any space for variables declared in this way (they are implemented
8928  with an equate in the assembler).
8929  Thus it is left to the programmer to make sure there are no overlaps with
8930  other variables that are declared without the absolute address.
8931  The assembler listing file (.lst
8932 \begin_inset LatexCommand \index{<file>.lst}
8933
8934 \end_inset 
8935
8936 ) and the linker output files (.rst
8937 \begin_inset LatexCommand \index{<file>.rst}
8938
8939 \end_inset 
8940
8941 ) and (.map
8942 \begin_inset LatexCommand \index{<file>.map}
8943
8944 \end_inset 
8945
8946 ) are good places to look for such overlaps.
8947  Variables with an absolute address are 
8948 \emph on 
8949 not
8950 \emph default 
8951  initialized
8952 \begin_inset LatexCommand \index{Variable initialization}
8953
8954 \end_inset 
8955
8956 .
8957 \layout Standard
8958
8959 In case of memory mapped I/O devices the keyword 
8960 \emph on 
8961 volatile
8962 \emph default 
8963  should be used to tell the compiler that accesses might not be optimized
8964  away:
8965 \layout Verse
8966
8967
8968 \family typewriter 
8969 volatile
8970 \begin_inset LatexCommand \index{volatile}
8971
8972 \end_inset 
8973
8974  xdata
8975 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
8976
8977 \end_inset 
8978
8979  at
8980 \begin_inset LatexCommand \index{at}
8981
8982 \end_inset 
8983
8984  0x8000 unsigned char PORTA_8255;
8985 \layout Standard
8986
8987 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
8988 r) array
8989 \family typewriter 
8990 \size footnotesize 
8991
8992 \begin_inset LatexCommand \index{Aligned array}
8993
8994 \end_inset 
8995
8996
8997 \family default 
8998 \size default 
8999  starts at a block (256 byte) boundary
9000 \begin_inset LatexCommand \index{block boundary}
9001
9002 \end_inset 
9003
9004  (section 
9005 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
9006
9007 \end_inset 
9008
9009  has an example).
9010 \newline 
9011 Absolute addresses can be specified for variables in all storage classes,
9012  e.g.:
9013 \layout Verse
9014
9015
9016 \family typewriter 
9017 bit
9018 \begin_inset LatexCommand \index{bit}
9019
9020 \end_inset 
9021
9022  at
9023 \begin_inset LatexCommand \index{at}
9024
9025 \end_inset 
9026
9027  0x02 bvar;
9028 \layout Standard
9029
9030 The above example will allocate the variable at offset 0x02 in the bit-addressab
9031 le space.
9032  There is no real advantage to assigning absolute addresses to variables
9033  in this manner, unless you want strict control over all the variables allocated.
9034  One possible use would be to write hardware portable code.
9035  For example, if you have a routine that uses one or more of the microcontroller
9036  I/O pins, and such pins are different for two different hardwares, you
9037  can declare the I/O pins in your routine using:
9038 \layout Verse
9039
9040
9041 \family typewriter 
9042 extern volatile bit SDI;
9043 \newline 
9044 extern volatile bit SCLK;
9045 \newline 
9046 extern volatile bit CPOL;
9047 \newline 
9048
9049 \newline 
9050 void DS1306_put(unsigned char value)
9051 \newline 
9052 {
9053 \newline 
9054 \SpecialChar ~
9055 \SpecialChar ~
9056 \SpecialChar ~
9057 \SpecialChar ~
9058 unsigned char mask=0x80;
9059 \newline 
9060
9061 \newline 
9062 \SpecialChar ~
9063 \SpecialChar ~
9064 \SpecialChar ~
9065 \SpecialChar ~
9066 while(mask)
9067 \newline 
9068 \SpecialChar ~
9069 \SpecialChar ~
9070 \SpecialChar ~
9071 \SpecialChar ~
9072 {
9073 \newline 
9074 \SpecialChar ~
9075 \SpecialChar ~
9076 \SpecialChar ~
9077 \SpecialChar ~
9078 \SpecialChar ~
9079 \SpecialChar ~
9080 \SpecialChar ~
9081 \SpecialChar ~
9082 SDI=(value & mask)?1:0;
9083 \newline 
9084 \SpecialChar ~
9085 \SpecialChar ~
9086 \SpecialChar ~
9087 \SpecialChar ~
9088 \SpecialChar ~
9089 \SpecialChar ~
9090 \SpecialChar ~
9091 \SpecialChar ~
9092 SCLK=!CPOL;
9093 \newline 
9094 \SpecialChar ~
9095 \SpecialChar ~
9096 \SpecialChar ~
9097 \SpecialChar ~
9098 \SpecialChar ~
9099 \SpecialChar ~
9100 \SpecialChar ~
9101 \SpecialChar ~
9102 SCLK=CPOL;
9103 \newline 
9104 \SpecialChar ~
9105 \SpecialChar ~
9106 \SpecialChar ~
9107 \SpecialChar ~
9108 \SpecialChar ~
9109 \SpecialChar ~
9110 \SpecialChar ~
9111 \SpecialChar ~
9112 mask/=2;
9113 \newline 
9114 \SpecialChar ~
9115 \SpecialChar ~
9116 \SpecialChar ~
9117 \SpecialChar ~
9118 }
9119 \newline 
9120 }
9121 \layout Standard
9122
9123 Then, someplace in the code for the first hardware you would use
9124 \layout Verse
9125
9126
9127 \family typewriter 
9128 bit at 0x80 SDI;\SpecialChar ~
9129 \SpecialChar ~
9130 \SpecialChar ~
9131 \SpecialChar ~
9132 /* I/O port 0, bit 0 */
9133 \newline 
9134 bit at 0x81 SCLK;\SpecialChar ~
9135 \SpecialChar ~
9136 \SpecialChar ~
9137 /* I/O port 0, bit 1 */
9138 \newline 
9139 bit CPOL;\SpecialChar ~
9140 \SpecialChar ~
9141 \SpecialChar ~
9142 \SpecialChar ~
9143 \SpecialChar ~
9144 \SpecialChar ~
9145 \SpecialChar ~
9146 \SpecialChar ~
9147 \SpecialChar ~
9148 \SpecialChar ~
9149 \SpecialChar ~
9150 /* This is a variable, let the linker allocate this one */
9151 \layout Standard
9152
9153 Similarly, for the second hardware you would use
9154 \layout Verse
9155
9156
9157 \family typewriter 
9158 bit at 0x83 SDI;\SpecialChar ~
9159 \SpecialChar ~
9160 \SpecialChar ~
9161 \SpecialChar ~
9162 /* I/O port 0, bit 3 */
9163 \newline 
9164 bit at 0x91 SCLK;\SpecialChar ~
9165 \SpecialChar ~
9166 \SpecialChar ~
9167 /* I/O port 1, bit 1 */
9168 \newline 
9169 bit
9170 \begin_inset LatexCommand \index{bit}
9171
9172 \end_inset 
9173
9174  CPOL;\SpecialChar ~
9175 \SpecialChar ~
9176 \SpecialChar ~
9177 \SpecialChar ~
9178 \SpecialChar ~
9179 \SpecialChar ~
9180 \SpecialChar ~
9181 \SpecialChar ~
9182 \SpecialChar ~
9183 \SpecialChar ~
9184 \SpecialChar ~
9185 /* This is a variable, let the linker allocate this one */
9186 \layout Standard
9187
9188 and you can use the same hardware dependent routine without changes, as
9189  for example in a library.
9190  This is somehow similar to sbit, but only one absolute address has to be
9191  specified in the whole project.
9192 \layout Section
9193
9194 Parameters
9195 \begin_inset LatexCommand \index{Parameters}
9196
9197 \end_inset 
9198
9199
9200 \begin_inset LatexCommand \index{function parameter}
9201
9202 \end_inset 
9203
9204  & Local Variables
9205 \begin_inset LatexCommand \index{local variables}
9206
9207 \end_inset 
9208
9209
9210 \layout Standard
9211
9212 Automatic (local) variables and parameters to functions can either be placed
9213  on the stack or in data-space.
9214  The default action of the compiler is to place these variables in the internal
9215  RAM (for small model) or external RAM (for large model).
9216  This in fact makes them similar to 
9217 \emph on 
9218 static
9219 \begin_inset LatexCommand \index{static}
9220
9221 \end_inset 
9222
9223
9224 \emph default 
9225  so by default functions are non-reentrant
9226 \begin_inset LatexCommand \index{reentrant}
9227
9228 \end_inset 
9229
9230 .
9231  
9232 \newline 
9233
9234 \newline 
9235 They can be placed on the stack
9236 \begin_inset LatexCommand \index{stack}
9237
9238 \end_inset 
9239
9240  either by using the
9241 \emph on 
9242  -
9243 \begin_inset ERT
9244 status Collapsed
9245
9246 \layout Standard
9247
9248 \backslash 
9249 /
9250 \end_inset 
9251
9252 -stack-auto
9253 \begin_inset LatexCommand \index{-\/-stack-auto}
9254
9255 \end_inset 
9256
9257
9258 \emph default 
9259  option or by using the 
9260 \emph on 
9261 reentrant
9262 \begin_inset LatexCommand \index{reentrant}
9263
9264 \end_inset 
9265
9266
9267 \emph default 
9268  keyword in the function declaration, e.g.:
9269 \layout Verse
9270
9271
9272 \family typewriter 
9273 unsigned char foo(char i) reentrant 
9274 \newline 
9275
9276 \newline 
9277 \SpecialChar ~
9278 \SpecialChar ~
9279 \SpecialChar ~
9280 \SpecialChar ~
9281 ...
9282  
9283 \newline 
9284 }
9285 \layout Standard
9286
9287 Since stack space on 8051 is limited, the 
9288 \emph on 
9289 reentrant 
9290 \emph default 
9291 keyword or the
9292 \emph on 
9293  -
9294 \begin_inset ERT
9295 status Collapsed
9296
9297 \layout Standard
9298
9299 \backslash 
9300 /
9301 \end_inset 
9302
9303 -stack-auto
9304 \emph default 
9305  option should be used sparingly.
9306  Note that the reentrant keyword just means that the parameters & local
9307  variables will be allocated to the stack, it 
9308 \emph on 
9309 does not
9310 \emph default 
9311  mean that the function is register bank
9312 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
9313
9314 \end_inset 
9315
9316  independent.
9317 \newline 
9318
9319 \newline 
9320 Local variables
9321 \begin_inset LatexCommand \index{local variables}
9322
9323 \end_inset 
9324
9325  can be assigned storage classes and absolute
9326 \begin_inset LatexCommand \index{Absolute addressing}
9327
9328 \end_inset 
9329
9330  addresses, e.g.: 
9331 \layout Verse
9332
9333
9334 \family typewriter 
9335 unsigned char foo() 
9336 \newline 
9337 {
9338 \newline 
9339 \SpecialChar ~
9340 \SpecialChar ~
9341 \SpecialChar ~
9342 \SpecialChar ~
9343 xdata unsigned char i;
9344 \newline 
9345 \SpecialChar ~
9346 \SpecialChar ~
9347 \SpecialChar ~
9348 \SpecialChar ~
9349 bit bvar;
9350 \newline 
9351 \SpecialChar ~
9352 \SpecialChar ~
9353 \SpecialChar ~
9354 \SpecialChar ~
9355 data at
9356 \begin_inset LatexCommand \index{at}
9357
9358 \end_inset 
9359
9360  0x31 unsigned char j;
9361 \newline 
9362 \SpecialChar ~
9363 \SpecialChar ~
9364 \SpecialChar ~
9365 \SpecialChar ~
9366 ...
9367  
9368 \newline 
9369 }
9370 \layout Standard
9371
9372 In the above example the variable 
9373 \emph on 
9374 i
9375 \emph default 
9376  will be allocated in the external ram, 
9377 \emph on 
9378 bvar
9379 \emph default 
9380  in bit addressable space and
9381 \emph on 
9382  j
9383 \emph default 
9384  in internal ram.
9385  When compiled with 
9386 \emph on 
9387 -
9388 \begin_inset ERT
9389 status Collapsed
9390
9391 \layout Standard
9392
9393 \backslash 
9394 /
9395 \end_inset 
9396
9397 -stack-auto
9398 \emph default 
9399  or when a function is declared as 
9400 \emph on 
9401 reentrant
9402 \emph default 
9403  this should only be done for static variables.
9404 \layout Standard
9405
9406 Parameters
9407 \begin_inset LatexCommand \index{function parameter}
9408
9409 \end_inset 
9410
9411  however are not allowed any storage class
9412 \begin_inset LatexCommand \index{Storage class}
9413
9414 \end_inset 
9415
9416 , (storage classes for parameters will be ignored), their allocation is
9417  governed by the memory model in use, and the reentrancy options.
9418 \layout Section
9419
9420 Overlaying
9421 \begin_inset LatexCommand \label{sub:Overlaying}
9422
9423 \end_inset 
9424
9425
9426 \begin_inset LatexCommand \index{Overlaying}
9427
9428 \end_inset 
9429
9430
9431 \layout Standard
9432
9433 For non-reentrant
9434 \begin_inset LatexCommand \index{reentrant}
9435
9436 \end_inset 
9437
9438  functions SDCC will try to reduce internal ram space usage by overlaying
9439  parameters and local variables of a function (if possible).
9440  Parameters and local variables
9441 \begin_inset LatexCommand \index{local variables}
9442
9443 \end_inset 
9444
9445  of a function will be allocated to an overlayable segment if the function
9446  has 
9447 \emph on 
9448 no other function calls and the function is non-reentrant and the memory
9449  model
9450 \begin_inset LatexCommand \index{Memory model}
9451
9452 \end_inset 
9453
9454  is small.
9455
9456 \emph default 
9457  If an explicit storage class
9458 \begin_inset LatexCommand \index{Storage class}
9459
9460 \end_inset 
9461
9462  is specified for a local variable, it will NOT be overlayed.
9463 \layout Standard
9464
9465 Note that the compiler (not the linkage editor) makes the decision for overlayin
9466 g the data items.
9467  Functions that are called from an interrupt service routine should be preceded
9468  by a #pragma\SpecialChar ~
9469 nooverlay
9470 \begin_inset LatexCommand \index{\#pragma nooverlay}
9471
9472 \end_inset 
9473
9474  if they are not reentrant.
9475 \layout Standard
9476
9477 Also note that the compiler does not do any processing of inline assembler
9478  code, so the compiler might incorrectly assign local variables and parameters
9479  of a function into the overlay segment if the inline assembler code calls
9480  other c-functions that might use the overlay.
9481  In that case the #pragma\SpecialChar ~
9482 nooverlay should be used.
9483 \layout Standard
9484
9485 Parameters and local variables of functions that contain 16 or 32 bit multiplica
9486 tion
9487 \begin_inset LatexCommand \index{Multiplication}
9488
9489 \end_inset 
9490
9491  or division
9492 \begin_inset LatexCommand \index{Division}
9493
9494 \end_inset 
9495
9496  will NOT be overlayed since these are implemented using external functions,
9497  e.g.:
9498 \layout Verse
9499
9500
9501 \family typewriter 
9502 #pragma save 
9503 \newline 
9504 #pragma nooverlay
9505 \begin_inset LatexCommand \index{\#pragma nooverlay}
9506
9507 \end_inset 
9508
9509  
9510 \newline 
9511 void set_error(unsigned char errcd) 
9512 \newline 
9513 {
9514 \newline 
9515 \SpecialChar ~
9516 \SpecialChar ~
9517 \SpecialChar ~
9518 \SpecialChar ~
9519 P3 = errcd;
9520 \newline 
9521
9522 \newline 
9523 #pragma restore 
9524 \newline 
9525
9526 \newline 
9527 void some_isr () interrupt
9528 \begin_inset LatexCommand \index{interrupt}
9529
9530 \end_inset 
9531
9532  2
9533 \newline 
9534 {
9535 \newline 
9536 \SpecialChar ~
9537 \SpecialChar ~
9538 \SpecialChar ~
9539 \SpecialChar ~
9540 ...
9541 \newline 
9542 \SpecialChar ~
9543 \SpecialChar ~
9544 \SpecialChar ~
9545 \SpecialChar ~
9546 set_error(10);
9547 \newline 
9548 \SpecialChar ~
9549 \SpecialChar ~
9550 \SpecialChar ~
9551 \SpecialChar ~
9552 ...
9553  
9554 \newline 
9555 }
9556 \layout Standard
9557
9558 In the above example the parameter 
9559 \emph on 
9560 errcd
9561 \emph default 
9562  for the function 
9563 \emph on 
9564 set_error
9565 \emph default 
9566  would be assigned to the overlayable segment if the #pragma\SpecialChar ~
9567 nooverlay was
9568  not present, this could cause unpredictable runtime behavior when called
9569  from an interrupt service routine.
9570  The #pragma\SpecialChar ~
9571 nooverlay ensures that the parameters and local variables for
9572  the function are NOT overlayed.
9573 \layout Section
9574
9575 Interrupt Service Routines
9576 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
9577
9578 \end_inset 
9579
9580
9581 \layout Standard
9582
9583 SDCC allows 
9584 \emph on 
9585 i
9586 \emph default 
9587 nterrupt 
9588 \emph on 
9589 s
9590 \emph default 
9591 ervice 
9592 \emph on 
9593 r
9594 \emph default 
9595 outines to be coded in C, with some extended keywords.
9596 \layout Verse
9597
9598
9599 \family typewriter 
9600 void timer_isr (void) interrupt 1 using 1 
9601 \newline 
9602
9603 \newline 
9604 \SpecialChar ~
9605 \SpecialChar ~
9606 \SpecialChar ~
9607 \SpecialChar ~
9608 ...
9609  
9610 \newline 
9611 }
9612 \layout Standard
9613
9614 The optional number following the 
9615 \emph on 
9616 interrupt
9617 \begin_inset LatexCommand \index{interrupt}
9618
9619 \end_inset 
9620
9621
9622 \emph default 
9623  keyword is the interrupt number this routine will service.
9624  When present, the compiler will insert a call to this routine in the interrupt
9625  vector table for the interrupt number specified.
9626  If you have multiple source files in your project, interrupt service routines
9627  can be present in any of them, but a prototype of the isr MUST be present
9628  or included in the file that contains the function 
9629 \emph on 
9630 main
9631 \emph default 
9632 .
9633  The 
9634 \emph on 
9635 using
9636 \emph default 
9637  keyword can be used to tell the compiler to use the specified register
9638  bank (8051 specific) when generating code for this function.
9639  
9640 \newline 
9641
9642 \layout Standard
9643
9644 Interrupt numbers and the corresponding address & descriptions for the Standard
9645  8051/8052 are listed below.
9646  SDCC will automatically adjust the interrupt vector table to the maximum
9647  interrupt number specified.
9648 \newline 
9649
9650 \layout Standard
9651 \align center 
9652
9653 \begin_inset  Tabular
9654 <lyxtabular version="3" rows="7" columns="3">
9655 <features>
9656 <column alignment="center" valignment="top" leftline="true" width="0in">
9657 <column alignment="center" valignment="top" leftline="true" width="0in">
9658 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0in">
9659 <row topline="true" bottomline="true">
9660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9661 \begin_inset Text
9662
9663 \layout Standard
9664
9665 Interrupt #
9666 \end_inset 
9667 </cell>
9668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9669 \begin_inset Text
9670
9671 \layout Standard
9672
9673 Description
9674 \end_inset 
9675 </cell>
9676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9677 \begin_inset Text
9678
9679 \layout Standard
9680
9681 Vector Address
9682 \end_inset 
9683 </cell>
9684 </row>
9685 <row topline="true">
9686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9687 \begin_inset Text
9688
9689 \layout Standard
9690
9691 0
9692 \end_inset 
9693 </cell>
9694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9695 \begin_inset Text
9696
9697 \layout Standard
9698
9699 External 0
9700 \end_inset 
9701 </cell>
9702 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9703 \begin_inset Text
9704
9705 \layout Standard
9706
9707 0x0003
9708 \end_inset 
9709 </cell>
9710 </row>
9711 <row topline="true">
9712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9713 \begin_inset Text
9714
9715 \layout Standard
9716
9717 1
9718 \end_inset 
9719 </cell>
9720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9721 \begin_inset Text
9722
9723 \layout Standard
9724
9725 Timer 0
9726 \end_inset 
9727 </cell>
9728 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9729 \begin_inset Text
9730
9731 \layout Standard
9732
9733 0x000B
9734 \end_inset 
9735 </cell>
9736 </row>
9737 <row topline="true">
9738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9739 \begin_inset Text
9740
9741 \layout Standard
9742
9743 2
9744 \end_inset 
9745 </cell>
9746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9747 \begin_inset Text
9748
9749 \layout Standard
9750
9751 External 1
9752 \end_inset 
9753 </cell>
9754 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9755 \begin_inset Text
9756
9757 \layout Standard
9758
9759 0x0013
9760 \end_inset 
9761 </cell>
9762 </row>
9763 <row topline="true">
9764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9765 \begin_inset Text
9766
9767 \layout Standard
9768
9769 3
9770 \end_inset 
9771 </cell>
9772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9773 \begin_inset Text
9774
9775 \layout Standard
9776
9777 Timer 1
9778 \end_inset 
9779 </cell>
9780 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9781 \begin_inset Text
9782
9783 \layout Standard
9784
9785 0x001B
9786 \end_inset 
9787 </cell>
9788 </row>
9789 <row topline="true">
9790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9791 \begin_inset Text
9792
9793 \layout Standard
9794
9795 4
9796 \end_inset 
9797 </cell>
9798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9799 \begin_inset Text
9800
9801 \layout Standard
9802
9803 Serial
9804 \end_inset 
9805 </cell>
9806 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9807 \begin_inset Text
9808
9809 \layout Standard
9810
9811 0x0023
9812 \end_inset 
9813 </cell>
9814 </row>
9815 <row topline="true" bottomline="true">
9816 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9817 \begin_inset Text
9818
9819 \layout Standard
9820
9821 5
9822 \end_inset 
9823 </cell>
9824 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9825 \begin_inset Text
9826
9827 \layout Standard
9828
9829 Timer 2 (8052)
9830 \end_inset 
9831 </cell>
9832 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9833 \begin_inset Text
9834
9835 \layout Standard
9836
9837 0x002B
9838 \end_inset 
9839 </cell>
9840 </row>
9841 </lyxtabular>
9842
9843 \end_inset 
9844
9845
9846 \newline 
9847
9848 \layout Standard
9849
9850 If the interrupt service routine is defined without 
9851 \emph on 
9852 using
9853 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
9854
9855 \end_inset 
9856
9857
9858 \emph default 
9859  a register bank or with register bank 0 (
9860 \emph on 
9861 using
9862 \emph default 
9863  0), the compiler will save the registers used by itself on the stack upon
9864  entry and restore them at exit, however if such an interrupt service routine
9865  calls another function then the entire register bank will be saved on the
9866  stack.
9867  This scheme may be advantageous for small interrupt service routines which
9868  have low register usage.
9869 \layout Standard
9870
9871 If the interrupt service routine is defined to be using a specific register
9872  bank then only 
9873 \emph on 
9874 a, b, dptr
9875 \emph default 
9876  & psw are saved and restored, if such an interrupt service routine calls
9877  another function (using another register bank) then the entire register
9878  bank of the called function will be saved on the stack.
9879  This scheme is recommended for larger interrupt service routines.
9880 \layout Standard
9881
9882 Interrupt service routines open the door for some very interesting bugs:
9883  
9884 \layout Standard
9885
9886 If the interrupt service routines changes variables which are accessed by
9887  other functions these variables should be declared 
9888 \emph on 
9889 volatile
9890 \emph default 
9891
9892 \begin_inset LatexCommand \index{volatile}
9893
9894 \end_inset 
9895
9896 .
9897  
9898 \layout Standard
9899
9900 If the access to these variables is not 
9901 \emph on 
9902 atomic
9903 \begin_inset LatexCommand \index{atomic access}
9904
9905 \end_inset 
9906
9907
9908 \emph default 
9909  (i.e.
9910  the processor needs more than one instruction for the access and could
9911  be interrupted while accessing the variable) the interrupt must disabled
9912  during the access to avoid inconsistent data.
9913  Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
9914  and should be protected by disabling interrupts.
9915  You're not automatically on the safe side if you use 8 bit variables though.
9916  We need an example here: f.e.
9917  on the 8051 the harmless looking 
9918 \begin_inset Quotes srd
9919 \end_inset 
9920
9921
9922 \family typewriter 
9923 flags\SpecialChar ~
9924 |=\SpecialChar ~
9925 0x80;
9926 \family default 
9927
9928 \begin_inset Quotes sld
9929 \end_inset 
9930
9931  is not atomic if 
9932 \family typewriter 
9933 flags
9934 \family default 
9935  resides in xdata.
9936  Setting 
9937 \begin_inset Quotes srd
9938 \end_inset 
9939
9940
9941 \family typewriter 
9942 flags\SpecialChar ~
9943 |=\SpecialChar ~
9944 0x40;
9945 \family default 
9946
9947 \begin_inset Quotes sld
9948 \end_inset 
9949
9950  from within an interrupt routine might get lost if the interrupt occurs
9951  at the wrong time.
9952  
9953 \begin_inset Quotes sld
9954 \end_inset 
9955
9956
9957 \family typewriter 
9958 counter\SpecialChar ~
9959 +=\SpecialChar ~
9960 8;
9961 \family default 
9962
9963 \begin_inset Quotes srd
9964 \end_inset 
9965
9966  is not atomic on the 8051 even if 
9967 \family typewriter 
9968 counter
9969 \family default 
9970  is located in data memory.
9971  Bugs like these are hard to reproduce and can cause a lot of trouble.
9972  
9973 \layout Standard
9974
9975 A special note here, int (16 bit) and long (32 bit) integer division
9976 \begin_inset LatexCommand \index{Division}
9977
9978 \end_inset 
9979
9980 , multiplication
9981 \begin_inset LatexCommand \index{Multiplication}
9982
9983 \end_inset 
9984
9985  & modulus
9986 \begin_inset LatexCommand \index{Modulus}
9987
9988 \end_inset 
9989
9990  and floating-point
9991 \begin_inset LatexCommand \index{Floating point support}
9992
9993 \end_inset 
9994
9995  operations are implemented using external support routines developed in
9996  ANSI-C.
9997  If an interrupt service routine needs to do any of these operations then
9998  the support routines (as mentioned in a following section) will have to
9999  be recompiled using the
10000 \emph on 
10001  -
10002 \begin_inset ERT
10003 status Collapsed
10004
10005 \layout Standard
10006
10007 \backslash 
10008 /
10009 \end_inset 
10010
10011 -stack-auto
10012 \begin_inset LatexCommand \index{-\/-stack-auto}
10013
10014 \end_inset 
10015
10016
10017 \emph default 
10018  option and the source file will need to be compiled using the 
10019 \emph on 
10020 -
10021 \begin_inset ERT
10022 status Collapsed
10023
10024 \layout Standard
10025
10026 \backslash 
10027 /
10028 \end_inset 
10029
10030 -int-long-reent
10031 \emph default 
10032
10033 \begin_inset LatexCommand \index{-\/-int-long-reent}
10034
10035 \end_inset 
10036
10037  compiler option.
10038 \layout Standard
10039
10040 Calling other functions from an interrupt service routine is not recommended,
10041  avoid it if possible.
10042  Note that when some function is called from an interrupt service routine
10043  it should be preceded by a #pragma\SpecialChar ~
10044 nooverlay
10045 \begin_inset LatexCommand \index{\#pragma nooverlay}
10046
10047 \end_inset 
10048
10049  if it is not reentrant.
10050  Furthermore nonreentrant functions should not be called from the main program
10051  while the interrupt service routine might be active.
10052  
10053 \newline 
10054
10055 \newline 
10056 Also see section 
10057 \begin_inset LatexCommand \ref{sub:Overlaying}
10058
10059 \end_inset 
10060
10061 \SpecialChar ~
10062 about Overlaying and section 
10063 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
10064
10065 \end_inset 
10066
10067 \SpecialChar ~
10068 about Functions using private register banks.
10069 \layout Section
10070
10071 Enabling and Disabling Interrupts
10072 \layout Subsection
10073
10074 Critical Functions and Critical Statements
10075 \layout Standard
10076
10077 A special keyword may be associated with a block or a function declaring
10078  it as 
10079 \emph on 
10080 critical
10081 \emph default 
10082 .
10083  SDCC will generate code to disable all interrupts
10084 \begin_inset LatexCommand \index{interrupt}
10085
10086 \end_inset 
10087
10088  upon entry to a critical function and restore the interrupt enable to the
10089  previous state before returning.
10090  Nesting critical functions will need one additional byte on the stack
10091 \begin_inset LatexCommand \index{stack}
10092
10093 \end_inset 
10094
10095  for each call.
10096 \layout Verse
10097
10098
10099 \family typewriter 
10100 int foo () critical
10101 \begin_inset LatexCommand \index{critical}
10102
10103 \end_inset 
10104
10105  
10106 \newline 
10107
10108 \newline 
10109 \SpecialChar ~
10110 \SpecialChar ~
10111 \SpecialChar ~
10112 \SpecialChar ~
10113 ...
10114  
10115 \newline 
10116 \SpecialChar ~
10117 \SpecialChar ~
10118 \SpecialChar ~
10119 \SpecialChar ~
10120 ...
10121  
10122 \newline 
10123 }
10124 \layout Standard
10125
10126 The critical attribute maybe used with other attributes like 
10127 \emph on 
10128 reentrant.
10129 \emph default 
10130
10131 \newline 
10132 The keyword 
10133 \emph on 
10134 critical
10135 \emph default 
10136  may also be used to disable interrupts more locally:
10137 \layout Verse
10138
10139
10140 \family typewriter 
10141 critical{ i++; }
10142 \layout Standard
10143
10144 More than one statement could have been included in the block.
10145 \layout Subsection
10146
10147 Enabling and Disabling Interrupts directly
10148 \layout Standard
10149
10150 Interrupts
10151 \begin_inset LatexCommand \index{interrupt}
10152
10153 \end_inset 
10154
10155  can also be disabled and enabled directly (8051):
10156 \layout Verse
10157
10158
10159 \family typewriter 
10160 EA = 0;\SpecialChar ~
10161 \SpecialChar ~
10162 \SpecialChar ~
10163 \SpecialChar ~
10164 \SpecialChar ~
10165 \SpecialChar ~
10166 \SpecialChar ~
10167 \SpecialChar ~
10168 \SpecialChar ~
10169 \SpecialChar ~
10170 \SpecialChar ~
10171 \SpecialChar ~
10172 or:\SpecialChar ~
10173 \SpecialChar ~
10174 \SpecialChar ~
10175 \SpecialChar ~
10176 \SpecialChar ~
10177 \SpecialChar ~
10178 \SpecialChar ~
10179 \SpecialChar ~
10180 \SpecialChar ~
10181 \SpecialChar ~
10182 \SpecialChar ~
10183 EA_SAVE = EA;
10184 \layout Verse
10185
10186
10187 \family typewriter 
10188 ...\SpecialChar ~
10189 \SpecialChar ~
10190 \SpecialChar ~
10191 \SpecialChar ~
10192 \SpecialChar ~
10193 \SpecialChar ~
10194 \SpecialChar ~
10195 \SpecialChar ~
10196 \SpecialChar ~
10197 \SpecialChar ~
10198 \SpecialChar ~
10199 \SpecialChar ~
10200 \SpecialChar ~
10201 \SpecialChar ~
10202 \SpecialChar ~
10203 \SpecialChar ~
10204 \SpecialChar ~
10205 \SpecialChar ~
10206 \SpecialChar ~
10207 \SpecialChar ~
10208 \SpecialChar ~
10209 \SpecialChar ~
10210 \SpecialChar ~
10211 \SpecialChar ~
10212 \SpecialChar ~
10213 \SpecialChar ~
10214 \SpecialChar ~
10215 \SpecialChar ~
10216 \SpecialChar ~
10217 \SpecialChar ~
10218 EA = 0;
10219 \layout Verse
10220
10221
10222 \family typewriter 
10223 EA = 1;\SpecialChar ~
10224 \SpecialChar ~
10225 \SpecialChar ~
10226 \SpecialChar ~
10227 \SpecialChar ~
10228 \SpecialChar ~
10229 \SpecialChar ~
10230 \SpecialChar ~
10231 \SpecialChar ~
10232 \SpecialChar ~
10233 \SpecialChar ~
10234 \SpecialChar ~
10235 \SpecialChar ~
10236 \SpecialChar ~
10237 \SpecialChar ~
10238 \SpecialChar ~
10239 \SpecialChar ~
10240 \SpecialChar ~
10241 \SpecialChar ~
10242 \SpecialChar ~
10243 \SpecialChar ~
10244 \SpecialChar ~
10245 \SpecialChar ~
10246 \SpecialChar ~
10247 \SpecialChar ~
10248 \SpecialChar ~
10249 ...
10250 \layout Verse
10251
10252
10253 \family typewriter 
10254 \SpecialChar ~
10255 \SpecialChar ~
10256 \SpecialChar ~
10257 \SpecialChar ~
10258 \SpecialChar ~
10259 \SpecialChar ~
10260 \SpecialChar ~
10261 \SpecialChar ~
10262 \SpecialChar ~
10263 \SpecialChar ~
10264 \SpecialChar ~
10265 \SpecialChar ~
10266 \SpecialChar ~
10267 \SpecialChar ~
10268 \SpecialChar ~
10269 \SpecialChar ~
10270 \SpecialChar ~
10271 \SpecialChar ~
10272 \SpecialChar ~
10273 \SpecialChar ~
10274 \SpecialChar ~
10275 \SpecialChar ~
10276 \SpecialChar ~
10277 \SpecialChar ~
10278 \SpecialChar ~
10279 \SpecialChar ~
10280 \SpecialChar ~
10281 \SpecialChar ~
10282 \SpecialChar ~
10283 \SpecialChar ~
10284 \SpecialChar ~
10285 \SpecialChar ~
10286 \SpecialChar ~
10287 EA = EA_SAVE;
10288 \layout Standard
10289
10290 On other architectures which have seperate opcodes for enabling and disabling
10291  interrupts you might want to make use of defines with inline assembly
10292 \begin_inset LatexCommand \index{Assembler routines}
10293
10294 \end_inset 
10295
10296  (HC08):
10297 \layout Verse
10298
10299
10300 \family typewriter 
10301 #define CLI _asm
10302 \begin_inset LatexCommand \index{\_asm}
10303
10304 \end_inset 
10305
10306 \SpecialChar ~
10307 \SpecialChar ~
10308 cli\SpecialChar ~
10309 \SpecialChar ~
10310 _endasm
10311 \begin_inset LatexCommand \index{\_endasm}
10312
10313 \end_inset 
10314
10315
10316 \layout Verse
10317
10318
10319 \family typewriter 
10320 #define SEI _asm\SpecialChar ~
10321 \SpecialChar ~
10322 sei\SpecialChar ~
10323 \SpecialChar ~
10324 _endasm; 
10325 \layout Verse
10326
10327
10328 \family typewriter 
10329 ...
10330 \layout Standard
10331
10332 Note: it is sometimes sufficient to disable only a specific interrupt source
10333  like f.e.
10334  a timer or serial interrupt by manipulating an 
10335 \emph on 
10336 interrupt mask
10337 \begin_inset LatexCommand \index{interrupt mask}
10338
10339 \end_inset 
10340
10341
10342 \emph default 
10343  register.
10344  
10345 \layout Standard
10346
10347 Usually the time during which interrupts are disabled should be kept as
10348  short as possible.
10349  This minimizes both 
10350 \emph on 
10351 interrupt latency
10352 \emph default 
10353
10354 \begin_inset LatexCommand \index{interrupt latency}
10355
10356 \end_inset 
10357
10358  (the time between the occurrence of the interrupt and the execution of
10359  the first code in the interrupt routine) and 
10360 \emph on 
10361 interrupt jitter
10362 \emph default 
10363
10364 \begin_inset LatexCommand \index{interrupt jitter}
10365
10366 \end_inset 
10367
10368  (the difference between the shortest and the longest interrupt latency).
10369  These really are something different, f.e.
10370  a serial interrupt has to be served before its buffer overruns so it cares
10371  for the maximum interrupt latency, whereas it does not care about jitter.
10372  On a loudspeaker driven via a digital to analog converter which is fed
10373  by an interrupt a latency of a few milliseconds might be tolerable, whereas
10374  a much smaller jitter will be very audible.
10375 \layout Standard
10376
10377 You can reenable interrupts within an interrupt routine and on some architecture
10378 s you can make use of two (or more) levels of 
10379 \emph on 
10380 interrupt priorities
10381 \emph default 
10382
10383 \begin_inset LatexCommand \index{interrupt priority}
10384
10385 \end_inset 
10386
10387 .
10388  On some architectures which don't support interrupt priorities these can
10389  be implemented by manipulating the interrupt mask and reenabling interrupts
10390  within the interrupt routine.
10391  Don't add complexity unless you have to.
10392  
10393 \layout Section
10394
10395 Functions using private register banks
10396 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
10397
10398 \end_inset 
10399
10400  (mcs51/ds390)
10401 \layout Standard
10402
10403 Some architectures have support for quickly changing register sets.
10404  SDCC supports this feature with the 
10405 \emph on 
10406 using
10407 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10408
10409 \end_inset 
10410
10411
10412 \emph default 
10413  attribute (which tells the compiler to use a register bank
10414 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10415
10416 \end_inset 
10417
10418  other than the default bank zero).
10419  It should only be applied to 
10420 \emph on 
10421 interrupt
10422 \begin_inset LatexCommand \index{interrupt}
10423
10424 \end_inset 
10425
10426
10427 \emph default 
10428  functions (see footnote below).
10429  This will in most circumstances make the generated ISR code more efficient
10430  since it will not have to save registers on the stack.
10431 \layout Standard
10432
10433 The 
10434 \emph on 
10435 using
10436 \emph default 
10437  attribute will have no effect on the generated code for a 
10438 \emph on 
10439 non-interrupt
10440 \emph default 
10441  function (but may occasionally be useful anyway
10442 \begin_inset Foot
10443 collapsed false
10444
10445 \layout Standard
10446
10447 possible exception: if a function is called ONLY from 'interrupt' functions
10448  using a particular bank, it can be declared with the same 'using' attribute
10449  as the calling 'interrupt' functions.
10450  For instance, if you have several ISRs using bank one, and all of them
10451  call memcpy(), it might make sense to create a specialized version of memcpy()
10452  'using 1', since this would prevent the ISR from having to save bank zero
10453  to the stack on entry and switch to bank zero before calling the function
10454 \end_inset 
10455
10456 ).
10457 \newline 
10458
10459 \emph on 
10460 (pending: I don't think this has been done yet)
10461 \layout Standard
10462
10463 An 
10464 \emph on 
10465 interrupt
10466 \emph default 
10467  function using a non-zero bank will assume that it can trash that register
10468  bank, and will not save it.
10469  Since high-priority interrupts
10470 \begin_inset LatexCommand \index{interrupt priority}
10471
10472 \end_inset 
10473
10474  can interrupt low-priority ones on the 8051 and friends, this means that
10475  if a high-priority ISR 
10476 \emph on 
10477 using
10478 \emph default 
10479  a particular bank occurs while processing a low-priority ISR 
10480 \emph on 
10481 using
10482 \emph default 
10483  the same bank, terrible and bad things can happen.
10484  To prevent this, no single register bank should be 
10485 \emph on 
10486 used
10487 \emph default 
10488  by both a high priority and a low priority ISR.
10489  This is probably most easily done by having all high priority ISRs use
10490  one bank and all low priority ISRs use another.
10491  If you have an ISR which can change priority at runtime, you're on your
10492  own: I suggest using the default bank zero and taking the small performance
10493  hit.
10494 \layout Standard
10495
10496 It is most efficient if your ISR calls no other functions.
10497  If your ISR must call other functions, it is most efficient if those functions
10498  use the same bank as the ISR (see note 1 below); the next best is if the
10499  called functions use bank zero.
10500  It is very inefficient to call a function using a different, non-zero bank
10501  from an ISR.
10502  
10503 \layout Section
10504
10505 Startup Code
10506 \begin_inset LatexCommand \label{sub:Startup-Code}
10507
10508 \end_inset 
10509
10510
10511 \begin_inset LatexCommand \index{Startup code}
10512
10513 \end_inset 
10514
10515
10516 \layout Subsection
10517
10518 MCS51/DS390 Startup Code
10519 \layout Standard
10520
10521 The compiler inserts a call to the C routine 
10522 \emph on 
10523 _sdcc_external_startup()
10524 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
10525
10526 \end_inset 
10527
10528
10529 \series bold 
10530 \emph default 
10531  
10532 \series default 
10533 at the start of the CODE area.
10534  This routine is in the runtime library
10535 \begin_inset LatexCommand \index{Runtime library}
10536
10537 \end_inset 
10538
10539 .
10540  By default this routine returns 0, if this routine returns a non-zero value,
10541  the static & global variable initialization will be skipped and the function
10542  main will be invoked.
10543  Otherwise static & global variables will be initialized before the function
10544  main is invoked.
10545  You could add a 
10546 \emph on 
10547 _sdcc_external_startup()
10548 \emph default 
10549  routine to your program to override the default if you need to setup hardware
10550  or perform some other critical operation prior to static & global variable
10551  initialization.
10552  On some mcs51 variants xdata has to be explicitly enabled before it can
10553  be accessed, this is the place to do it.
10554  See also the compiler option 
10555 \emph on 
10556 -
10557 \begin_inset ERT
10558 status Collapsed
10559
10560 \layout Standard
10561
10562 \backslash 
10563 /
10564 \end_inset 
10565
10566 -no-xinit
10567 \emph default 
10568 -
10569 \emph on 
10570 opt
10571 \emph default 
10572
10573 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
10574
10575 \end_inset 
10576
10577  and section 
10578 \begin_inset LatexCommand \ref{sub:MCS51-variants}
10579
10580 \end_inset 
10581
10582 \SpecialChar ~
10583 about MCS51-variants.
10584 \layout Subsection
10585
10586 HC08 Startup Code
10587 \layout Standard
10588
10589 The HC08 startup code follows the same scheme as the MCS51 startup code.
10590 \layout Subsection
10591
10592 Z80 Startup Code
10593 \layout Standard
10594
10595 On the Z80 the startup code is inserted by linking with crt0.o which is generated
10596  from sdcc/device/lib/z80/crt0.s.
10597  If you need a different startup code you can use the compiler option 
10598 \emph on 
10599 -
10600 \series bold 
10601 \emph default 
10602
10603 \begin_inset ERT
10604 status Collapsed
10605
10606 \layout Standard
10607
10608 \backslash 
10609 /
10610 \end_inset 
10611
10612
10613 \series default 
10614 \emph on 
10615 -no-std-crt0
10616 \emph default 
10617
10618 \begin_inset LatexCommand \index{-\/-no-std-crt0}
10619
10620 \end_inset 
10621
10622  and provide your own crt0.o.
10623  
10624 \layout Section
10625
10626 Inline Assembler Code
10627 \begin_inset LatexCommand \index{Assembler routines}
10628
10629 \end_inset 
10630
10631
10632 \layout Subsection
10633
10634 A Step by Step Introduction
10635 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
10636
10637 \end_inset 
10638
10639
10640 \layout Standard
10641
10642 Starting from a small snippet of c-code this example shows for the MCS51
10643  how to use inline assembly, access variables, a function parameter and
10644  an array in xdata memory.
10645  The example uses an MCS51 here but is easily adapted for other architectures.
10646  This is a buffer routine which should be optimized:
10647 \layout Verse
10648
10649
10650 \family typewriter 
10651 \size footnotesize 
10652 unsigned char far
10653 \begin_inset LatexCommand \index{far (storage class)}
10654
10655 \end_inset 
10656
10657  at
10658 \begin_inset LatexCommand \index{at}
10659
10660 \end_inset 
10661
10662  0x7f00 buf[0x100];
10663 \begin_inset LatexCommand \index{Aligned array}
10664
10665 \end_inset 
10666
10667
10668 \newline 
10669 unsigned char head,tail;
10670 \newline 
10671
10672 \newline 
10673 void to_buffer( unsigned char c ) 
10674 \newline 
10675 {
10676 \newline 
10677 \SpecialChar ~
10678 \SpecialChar ~
10679 \SpecialChar ~
10680 \SpecialChar ~
10681 if( head != tail-1 ) 
10682 \newline 
10683 \SpecialChar ~
10684 \SpecialChar ~
10685 \SpecialChar ~
10686 \SpecialChar ~
10687 \SpecialChar ~
10688 \SpecialChar ~
10689 \SpecialChar ~
10690 \SpecialChar ~
10691 buf[ head++ ] = c; 
10692 \newline 
10693
10694 \layout Standard
10695
10696 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
10697  then a corresponding buffer.asm file is generated.
10698  We define a new function 
10699 \family typewriter 
10700 to_buffer_asm()
10701 \family default 
10702  in file buffer.c in which we cut and paste the generated code, removing
10703  unwanted comments and some ':'.
10704  Then add 
10705 \begin_inset Quotes sld
10706 \end_inset 
10707
10708 _asm
10709 \begin_inset Quotes srd
10710 \end_inset 
10711
10712  and 
10713 \begin_inset Quotes sld
10714 \end_inset 
10715
10716 _endasm;
10717 \begin_inset Quotes srd
10718 \end_inset 
10719
10720  to the beginning and the end of the function body:
10721 \layout Verse
10722
10723
10724 \family typewriter 
10725 \size footnotesize 
10726 /* With a cut and paste from the .asm file, we have something to start with.
10727 \newline 
10728 \SpecialChar ~
10729 \SpecialChar ~
10730 \SpecialChar ~
10731 The function is not yet OK! (registers aren't saved) */ 
10732 \newline 
10733 void to_buffer_asm( unsigned char c ) 
10734 \newline 
10735
10736 \newline 
10737 \SpecialChar ~
10738 \SpecialChar ~
10739 \SpecialChar ~
10740 \SpecialChar ~
10741 _asm
10742 \begin_inset LatexCommand \index{\_asm}
10743
10744 \end_inset 
10745
10746
10747 \newline 
10748 \SpecialChar ~
10749 \SpecialChar ~
10750 \SpecialChar ~
10751 \SpecialChar ~
10752 mov\SpecialChar ~
10753 \SpecialChar ~
10754 r2,dpl 
10755 \newline 
10756 ;buffer.c if( head != tail-1 ) 
10757 \newline 
10758 \SpecialChar ~
10759 \SpecialChar ~
10760 \SpecialChar ~
10761 \SpecialChar ~
10762 mov\SpecialChar ~
10763 \SpecialChar ~
10764 a,_tail 
10765 \newline 
10766 \SpecialChar ~
10767 \SpecialChar ~
10768 \SpecialChar ~
10769 \SpecialChar ~
10770 dec\SpecialChar ~
10771 \SpecialChar ~
10772
10773 \newline 
10774 \SpecialChar ~
10775 \SpecialChar ~
10776 \SpecialChar ~
10777 \SpecialChar ~
10778 mov\SpecialChar ~
10779 \SpecialChar ~
10780 r3,a 
10781 \newline 
10782 \SpecialChar ~
10783 \SpecialChar ~
10784 \SpecialChar ~
10785 \SpecialChar ~
10786 mov\SpecialChar ~
10787 \SpecialChar ~
10788 a,_head 
10789 \newline 
10790 \SpecialChar ~
10791 \SpecialChar ~
10792 \SpecialChar ~
10793 \SpecialChar ~
10794 cjne a,ar3,00106$ 
10795 \newline 
10796 \SpecialChar ~
10797 \SpecialChar ~
10798 \SpecialChar ~
10799 \SpecialChar ~
10800 ret
10801 \newline 
10802 00106$: 
10803 \newline 
10804 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
10805 \begin_inset LatexCommand \index{Aligned array}
10806
10807 \end_inset 
10808
10809
10810 \newline 
10811 \SpecialChar ~
10812 \SpecialChar ~
10813 \SpecialChar ~
10814 \SpecialChar ~
10815 mov\SpecialChar ~
10816 \SpecialChar ~
10817 r3,_head 
10818 \newline 
10819 \SpecialChar ~
10820 \SpecialChar ~
10821 \SpecialChar ~
10822 \SpecialChar ~
10823 inc\SpecialChar ~
10824 \SpecialChar ~
10825 _head 
10826 \newline 
10827 \SpecialChar ~
10828 \SpecialChar ~
10829 \SpecialChar ~
10830 \SpecialChar ~
10831 mov\SpecialChar ~
10832 \SpecialChar ~
10833 dpl,r3 
10834 \newline 
10835 \SpecialChar ~
10836 \SpecialChar ~
10837 \SpecialChar ~
10838 \SpecialChar ~
10839 mov\SpecialChar ~
10840 \SpecialChar ~
10841 dph,#(_buf >> 8) 
10842 \newline 
10843 \SpecialChar ~
10844 \SpecialChar ~
10845 \SpecialChar ~
10846 \SpecialChar ~
10847 mov\SpecialChar ~
10848 \SpecialChar ~
10849 a,r2 
10850 \newline 
10851 \SpecialChar ~
10852 \SpecialChar ~
10853 \SpecialChar ~
10854 \SpecialChar ~
10855 movx @dptr,a 
10856 \newline 
10857 00103$: 
10858 \newline 
10859 \SpecialChar ~
10860 \SpecialChar ~
10861 \SpecialChar ~
10862 \SpecialChar ~
10863 ret
10864 \newline 
10865 \SpecialChar ~
10866 \SpecialChar ~
10867 \SpecialChar ~
10868 \SpecialChar ~
10869 _endasm;
10870 \newline 
10871
10872 \layout Standard
10873
10874 The new file buffer.c should compile with only one warning about the unreferenced
10875  function argument 'c'.
10876  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
10877  (1) and finally have:
10878 \layout Verse
10879
10880
10881 \family typewriter 
10882 \size footnotesize 
10883 unsigned char far at 0x7f00 buf[0x100];
10884 \newline 
10885 unsigned char head,tail;
10886 \newline 
10887 #define USE_ASSEMBLY (1)
10888 \newline 
10889
10890 \newline 
10891 #if !USE_ASSEMBLY
10892 \newline 
10893
10894 \newline 
10895 void to_buffer( unsigned char c )
10896 \newline 
10897 {
10898 \newline 
10899 \SpecialChar ~
10900 \SpecialChar ~
10901 \SpecialChar ~
10902 \SpecialChar ~
10903 if( head != tail-1 )
10904 \newline 
10905 \SpecialChar ~
10906 \SpecialChar ~
10907 \SpecialChar ~
10908 \SpecialChar ~
10909 \SpecialChar ~
10910 \SpecialChar ~
10911 \SpecialChar ~
10912 \SpecialChar ~
10913 buf[ head++ ] = c;
10914 \newline 
10915 }
10916 \newline 
10917
10918 \newline 
10919 #else
10920 \newline 
10921
10922 \newline 
10923 void to_buffer( unsigned char c )
10924 \newline 
10925 {
10926 \newline 
10927 \SpecialChar ~
10928 \SpecialChar ~
10929 \SpecialChar ~
10930 \SpecialChar ~
10931 c; // to avoid warning: unreferenced function argument
10932 \newline 
10933 \SpecialChar ~
10934 \SpecialChar ~
10935 \SpecialChar ~
10936 \SpecialChar ~
10937 _asm
10938 \begin_inset LatexCommand \index{\_asm}
10939
10940 \end_inset 
10941
10942
10943 \newline 
10944 \SpecialChar ~
10945 \SpecialChar ~
10946 \SpecialChar ~
10947 \SpecialChar ~
10948 \SpecialChar ~
10949 \SpecialChar ~
10950 \SpecialChar ~
10951 \SpecialChar ~
10952 ; save used registers here.
10953  
10954 \newline 
10955 \SpecialChar ~
10956 \SpecialChar ~
10957 \SpecialChar ~
10958 \SpecialChar ~
10959 \SpecialChar ~
10960 \SpecialChar ~
10961 \SpecialChar ~
10962 \SpecialChar ~
10963 ; If we were still using r2,r3 we would have to push them here.
10964  
10965 \newline 
10966 ; if( head != tail-1 )
10967 \newline 
10968 \SpecialChar ~
10969 \SpecialChar ~
10970 \SpecialChar ~
10971 \SpecialChar ~
10972 \SpecialChar ~
10973 \SpecialChar ~
10974 \SpecialChar ~
10975 \SpecialChar ~
10976 mov\SpecialChar ~
10977  a,_tail
10978 \newline 
10979 \SpecialChar ~
10980 \SpecialChar ~
10981 \SpecialChar ~
10982 \SpecialChar ~
10983 \SpecialChar ~
10984 \SpecialChar ~
10985 \SpecialChar ~
10986 \SpecialChar ~
10987 dec\SpecialChar ~
10988  a
10989 \newline 
10990 \SpecialChar ~
10991 \SpecialChar ~
10992 \SpecialChar ~
10993 \SpecialChar ~
10994 \SpecialChar ~
10995 \SpecialChar ~
10996 \SpecialChar ~
10997 \SpecialChar ~
10998 xrl\SpecialChar ~
10999  a,_head
11000 \newline 
11001 \SpecialChar ~
11002 \SpecialChar ~
11003 \SpecialChar ~
11004 \SpecialChar ~
11005 \SpecialChar ~
11006 \SpecialChar ~
11007 \SpecialChar ~
11008 \SpecialChar ~
11009 ; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
11010 \newline 
11011 \SpecialChar ~
11012 \SpecialChar ~
11013 \SpecialChar ~
11014 \SpecialChar ~
11015 \SpecialChar ~
11016 \SpecialChar ~
11017 \SpecialChar ~
11018 \SpecialChar ~
11019 jz\SpecialChar ~
11020 \SpecialChar ~
11021  t_b_end$
11022 \newline 
11023 \SpecialChar ~
11024 \SpecialChar ~
11025 \SpecialChar ~
11026 \SpecialChar ~
11027 \SpecialChar ~
11028 \SpecialChar ~
11029 \SpecialChar ~
11030 \SpecialChar ~
11031 ;
11032 \newline 
11033 ; buf[ head++ ] = c;
11034 \newline 
11035 \SpecialChar ~
11036 \SpecialChar ~
11037 \SpecialChar ~
11038 \SpecialChar ~
11039 \SpecialChar ~
11040 \SpecialChar ~
11041 \SpecialChar ~
11042 \SpecialChar ~
11043 mov\SpecialChar ~
11044  a,dpl \SpecialChar ~
11045 \SpecialChar ~
11046 \SpecialChar ~
11047 \SpecialChar ~
11048 \SpecialChar ~
11049 \SpecialChar ~
11050 \SpecialChar ~
11051 ; dpl holds lower byte of function argument
11052 \newline 
11053 \SpecialChar ~
11054 \SpecialChar ~
11055 \SpecialChar ~
11056 \SpecialChar ~
11057 \SpecialChar ~
11058 \SpecialChar ~
11059 \SpecialChar ~
11060 \SpecialChar ~
11061 mov\SpecialChar ~
11062  dpl,_head \SpecialChar ~
11063 \SpecialChar ~
11064 \SpecialChar ~
11065 ; buf is 0x100 byte aligned so head can be used directly
11066 \newline 
11067 \SpecialChar ~
11068 \SpecialChar ~
11069 \SpecialChar ~
11070 \SpecialChar ~
11071 \SpecialChar ~
11072 \SpecialChar ~
11073 \SpecialChar ~
11074 \SpecialChar ~
11075 mov\SpecialChar ~
11076  dph,#(_buf>>8)
11077 \newline 
11078 \SpecialChar ~
11079 \SpecialChar ~
11080 \SpecialChar ~
11081 \SpecialChar ~
11082 \SpecialChar ~
11083 \SpecialChar ~
11084 \SpecialChar ~
11085 \SpecialChar ~
11086 movx @dptr,a
11087 \newline 
11088 \SpecialChar ~
11089 \SpecialChar ~
11090 \SpecialChar ~
11091 \SpecialChar ~
11092 \SpecialChar ~
11093 \SpecialChar ~
11094 \SpecialChar ~
11095 \SpecialChar ~
11096 inc \SpecialChar ~
11097 _head
11098 \newline 
11099 \SpecialChar ~
11100 \SpecialChar ~
11101 \SpecialChar ~
11102 \SpecialChar ~
11103 \SpecialChar ~
11104 \SpecialChar ~
11105 \SpecialChar ~
11106 \SpecialChar ~
11107 ; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)
11108 \newline 
11109 t_b_end$:
11110 \newline 
11111 \SpecialChar ~
11112 \SpecialChar ~
11113 \SpecialChar ~
11114 \SpecialChar ~
11115 \SpecialChar ~
11116 \SpecialChar ~
11117 \SpecialChar ~
11118 \SpecialChar ~
11119 ; restore used registers here 
11120 \newline 
11121 \SpecialChar ~
11122 \SpecialChar ~
11123 \SpecialChar ~
11124 \SpecialChar ~
11125 _endasm;
11126 \newline 
11127 }
11128 \newline 
11129 #endif
11130 \layout Standard
11131
11132 The inline assembler code can contain any valid code understood by the assembler
11133 , this includes any assembler directives and comment lines
11134 \begin_inset Foot
11135 collapsed false
11136
11137 \layout Standard
11138
11139 The assembler does not like some characters like ':' or ''' in comments.
11140  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
11141 \end_inset 
11142
11143 .
11144  The compiler does not do any validation of the code within the 
11145 \family typewriter 
11146 _asm
11147 \begin_inset LatexCommand \index{\_asm}
11148
11149 \end_inset 
11150
11151  ...
11152  _endasm;
11153 \family default 
11154  keyword pair.
11155  Specifically it will not know which registers are used and thus register
11156  pushing/popping
11157 \begin_inset LatexCommand \index{push/pop}
11158
11159 \end_inset 
11160
11161  has to be done manually.
11162  
11163 \layout Standard
11164
11165 It is recommended that each assembly instruction (including labels) be placed
11166  in a separate line (as the example shows).
11167  When the -
11168 \begin_inset ERT
11169 status Collapsed
11170
11171 \layout Standard
11172
11173 \backslash 
11174 /
11175 \end_inset 
11176
11177 -
11178 \emph on 
11179 peep-asm
11180 \begin_inset LatexCommand \index{-\/-peep-asm}
11181
11182 \end_inset 
11183
11184
11185 \emph default 
11186  command line option is used, the inline assembler code will be passed through
11187  the peephole optimizer
11188 \begin_inset LatexCommand \index{Peephole optimizer}
11189
11190 \end_inset 
11191
11192 .
11193  There are only a few (if any) cases where this option makes sense, it might
11194  cause some unexpected changes in the inline assembler code.
11195  Please go through the peephole optimizer rules defined in file 
11196 \emph on 
11197 SDCCpeeph.def
11198 \emph default 
11199  before using this option.
11200 \layout Subsection
11201
11202 Naked Functions
11203 \begin_inset LatexCommand \label{sub:Naked-Functions}
11204
11205 \end_inset 
11206
11207
11208 \begin_inset LatexCommand \index{Naked functions}
11209
11210 \end_inset 
11211
11212
11213 \layout Standard
11214
11215 A special keyword may be associated with a function declaring it as 
11216 \emph on 
11217 _naked
11218 \begin_inset LatexCommand \index{\_naked}
11219
11220 \end_inset 
11221
11222 .
11223  
11224 \emph default 
11225 The 
11226 \emph on 
11227 _naked
11228 \emph default 
11229  function modifier attribute prevents the compiler from generating prologue
11230 \begin_inset LatexCommand \index{function prologue}
11231
11232 \end_inset 
11233
11234  and epilogue
11235 \begin_inset LatexCommand \index{function epilogue}
11236
11237 \end_inset 
11238
11239  code for that function.
11240  This means that the user is entirely responsible for such things as saving
11241  any registers that may need to be preserved, selecting the proper register
11242  bank, generating the 
11243 \emph on 
11244 return
11245 \emph default 
11246  instruction at the end, etc.
11247  Practically, this means that the contents of the function must be written
11248  in inline assembler.
11249  This is particularly useful for interrupt functions, which can have a large
11250  (and often unnecessary) prologue/epilogue.
11251  For example, compare the code generated by these two functions:
11252 \layout Verse
11253
11254
11255 \family typewriter 
11256 volatile
11257 \begin_inset LatexCommand \index{volatile}
11258
11259 \end_inset 
11260
11261  data unsigned char counter;
11262 \newline 
11263
11264 \newline 
11265 void simpleInterrupt(void) interrupt
11266 \begin_inset LatexCommand \index{interrupt}
11267
11268 \end_inset 
11269
11270  1
11271 \newline 
11272 {
11273 \newline 
11274 \SpecialChar ~
11275 \SpecialChar ~
11276 \SpecialChar ~
11277 \SpecialChar ~
11278 counter++;
11279 \newline 
11280 }
11281 \newline 
11282
11283 \newline 
11284 void nakedInterrupt(void) interrupt 2 _naked
11285 \newline 
11286 {
11287 \newline 
11288 \SpecialChar ~
11289 \SpecialChar ~
11290 \SpecialChar ~
11291 \SpecialChar ~
11292 _asm
11293 \begin_inset LatexCommand \index{\_asm}
11294
11295 \end_inset 
11296
11297
11298 \newline 
11299 \SpecialChar ~
11300 \SpecialChar ~
11301 \SpecialChar ~
11302 \SpecialChar ~
11303 \SpecialChar ~
11304 \SpecialChar ~
11305 inc\SpecialChar ~
11306 \SpecialChar ~
11307 \SpecialChar ~
11308 \SpecialChar ~
11309 \SpecialChar ~
11310 _counter ; does not change flags, no need to save psw
11311 \newline 
11312 \SpecialChar ~
11313 \SpecialChar ~
11314 \SpecialChar ~
11315 \SpecialChar ~
11316 \SpecialChar ~
11317 \SpecialChar ~
11318 reti\SpecialChar ~
11319 \SpecialChar ~
11320 \SpecialChar ~
11321 \SpecialChar ~
11322 ; MUST explicitly include ret or reti in _naked function.
11323 \newline 
11324 \SpecialChar ~
11325 \SpecialChar ~
11326 \SpecialChar ~
11327 \SpecialChar ~
11328 _endasm
11329 \begin_inset LatexCommand \index{\_endasm}
11330
11331 \end_inset 
11332
11333 ;
11334 \newline 
11335 }
11336 \layout Standard
11337
11338 For an 8051 target, the generated simpleInterrupt looks like:
11339 \layout Verse
11340
11341
11342 \family typewriter 
11343 _simpleInterrupt:
11344 \newline 
11345 \SpecialChar ~
11346 \SpecialChar ~
11347 \SpecialChar ~
11348 \SpecialChar ~
11349 push\SpecialChar ~
11350 \SpecialChar ~
11351 \SpecialChar ~
11352 \SpecialChar ~
11353 acc
11354 \newline 
11355 \SpecialChar ~
11356 \SpecialChar ~
11357 \SpecialChar ~
11358 \SpecialChar ~
11359 push\SpecialChar ~
11360 \SpecialChar ~
11361 \SpecialChar ~
11362 \SpecialChar ~
11363 b
11364 \newline 
11365 \SpecialChar ~
11366 \SpecialChar ~
11367 \SpecialChar ~
11368 \SpecialChar ~
11369 push\SpecialChar ~
11370 \SpecialChar ~
11371 \SpecialChar ~
11372 \SpecialChar ~
11373 dpl
11374 \newline 
11375 \SpecialChar ~
11376 \SpecialChar ~
11377 \SpecialChar ~
11378 \SpecialChar ~
11379 push\SpecialChar ~
11380 \SpecialChar ~
11381 \SpecialChar ~
11382 \SpecialChar ~
11383 dph
11384 \newline 
11385 \SpecialChar ~
11386 \SpecialChar ~
11387 \SpecialChar ~
11388 \SpecialChar ~
11389 push\SpecialChar ~
11390 \SpecialChar ~
11391 \SpecialChar ~
11392 \SpecialChar ~
11393 psw
11394 \newline 
11395 \SpecialChar ~
11396 \SpecialChar ~
11397 \SpecialChar ~
11398 \SpecialChar ~
11399 mov\SpecialChar ~
11400 \SpecialChar ~
11401 \SpecialChar ~
11402 \SpecialChar ~
11403 \SpecialChar ~
11404 psw,#0x00
11405 \newline 
11406 \SpecialChar ~
11407 \SpecialChar ~
11408 \SpecialChar ~
11409 \SpecialChar ~
11410 inc\SpecialChar ~
11411 \SpecialChar ~
11412 \SpecialChar ~
11413 \SpecialChar ~
11414 \SpecialChar ~
11415 _counter
11416 \newline 
11417 \SpecialChar ~
11418 \SpecialChar ~
11419 \SpecialChar ~
11420 \SpecialChar ~
11421 pop\SpecialChar ~
11422 \SpecialChar ~
11423 \SpecialChar ~
11424 \SpecialChar ~
11425 \SpecialChar ~
11426 psw
11427 \newline 
11428 \SpecialChar ~
11429 \SpecialChar ~
11430 \SpecialChar ~
11431 \SpecialChar ~
11432 pop\SpecialChar ~
11433 \SpecialChar ~
11434 \SpecialChar ~
11435 \SpecialChar ~
11436 \SpecialChar ~
11437 dph
11438 \newline 
11439 \SpecialChar ~
11440 \SpecialChar ~
11441 \SpecialChar ~
11442 \SpecialChar ~
11443 pop\SpecialChar ~
11444 \SpecialChar ~
11445 \SpecialChar ~
11446 \SpecialChar ~
11447 \SpecialChar ~
11448 dpl
11449 \newline 
11450 \SpecialChar ~
11451 \SpecialChar ~
11452 \SpecialChar ~
11453 \SpecialChar ~
11454 pop\SpecialChar ~
11455 \SpecialChar ~
11456 \SpecialChar ~
11457 \SpecialChar ~
11458 \SpecialChar ~
11459 b
11460 \newline 
11461 \SpecialChar ~
11462 \SpecialChar ~
11463 \SpecialChar ~
11464 \SpecialChar ~
11465 pop\SpecialChar ~
11466 \SpecialChar ~
11467 \SpecialChar ~
11468 \SpecialChar ~
11469 \SpecialChar ~
11470 acc
11471 \newline 
11472 \SpecialChar ~
11473 \SpecialChar ~
11474 \SpecialChar ~
11475 \SpecialChar ~
11476 reti
11477 \layout Standard
11478
11479 whereas nakedInterrupt looks like:
11480 \layout Verse
11481
11482
11483 \family typewriter 
11484 _nakedInterrupt:
11485 \newline 
11486 \SpecialChar ~
11487 \SpecialChar ~
11488 \SpecialChar ~
11489 \SpecialChar ~
11490 inc\SpecialChar ~
11491 \SpecialChar ~
11492 \SpecialChar ~
11493 \SpecialChar ~
11494 _counter ; does not change flags, no need to save psw
11495 \newline 
11496 \SpecialChar ~
11497 \SpecialChar ~
11498 \SpecialChar ~
11499 \SpecialChar ~
11500 reti\SpecialChar ~
11501 \SpecialChar ~
11502 \SpecialChar ~
11503 \SpecialChar ~
11504 \SpecialChar ~
11505 \SpecialChar ~
11506 \SpecialChar ~
11507 \SpecialChar ~
11508 \SpecialChar ~
11509 \SpecialChar ~
11510 \SpecialChar ~
11511 \SpecialChar ~
11512 ; MUST explicitly include ret or reti in _naked function
11513 \layout Standard
11514
11515 The related directive #pragma exclude
11516 \begin_inset LatexCommand \index{\#pragma exclude}
11517
11518 \end_inset 
11519
11520  allows a more fine grained control over pushing & popping
11521 \begin_inset LatexCommand \index{push/pop}
11522
11523 \end_inset 
11524
11525  the registers.
11526 \layout Standard
11527
11528 While there is nothing preventing you from writing C code inside a 
11529 \family typewriter 
11530 _naked
11531 \family default 
11532  function, there are many ways to shoot yourself in the foot doing this,
11533  and it is recommended that you stick to inline assembler.
11534 \layout Subsection
11535
11536 Use of Labels within Inline Assembler
11537 \layout Standard
11538
11539 SDCC allows the use of in-line assembler with a few restrictions regarding
11540  labels.
11541  In older versions of the compiler all labels defined within inline assembler
11542  code 
11543 \emph on 
11544 had to be
11545 \emph default 
11546  of the form 
11547 \emph on 
11548 nnnnn$
11549 \emph default 
11550  where nnnn is a number less than 100 (which implies a limit of utmost 100
11551  inline assembler labels 
11552 \emph on 
11553 per function
11554 \emph default 
11555 \noun on 
11556 )
11557 \noun default 
11558 .
11559  
11560 \layout Verse
11561
11562
11563 \family typewriter 
11564 _asm
11565 \begin_inset LatexCommand \index{\_asm}
11566
11567 \end_inset 
11568
11569  
11570 \newline 
11571 \SpecialChar ~
11572 \SpecialChar ~
11573 \SpecialChar ~
11574 \SpecialChar ~
11575 mov\SpecialChar ~
11576 \SpecialChar ~
11577 \SpecialChar ~
11578 \SpecialChar ~
11579 \SpecialChar ~
11580 b,#10 
11581 \newline 
11582 00001$: 
11583 \newline 
11584 \SpecialChar ~
11585 \SpecialChar ~
11586 \SpecialChar ~
11587 \SpecialChar ~
11588 djnz\SpecialChar ~
11589 \SpecialChar ~
11590 \SpecialChar ~
11591 \SpecialChar ~
11592 b,00001$ 
11593 \newline 
11594 _endasm
11595 \begin_inset LatexCommand \index{\_endasm}
11596
11597 \end_inset 
11598
11599  ;
11600 \layout Standard
11601
11602 Inline assembler code cannot reference any C-Labels, however it can reference
11603  labels
11604 \begin_inset LatexCommand \index{Labels}
11605
11606 \end_inset 
11607
11608  defined by the inline assembler, e.g.:
11609 \layout Verse
11610
11611
11612 \family typewriter 
11613 foo() { 
11614 \newline 
11615 \SpecialChar ~
11616 \SpecialChar ~
11617 \SpecialChar ~
11618 \SpecialChar ~
11619 /* some c code */ 
11620 \newline 
11621 \SpecialChar ~
11622 \SpecialChar ~
11623 \SpecialChar ~
11624 \SpecialChar ~
11625 _asm 
11626 \newline 
11627 \SpecialChar ~
11628 \SpecialChar ~
11629 \SpecialChar ~
11630 \SpecialChar ~
11631 \SpecialChar ~
11632 \SpecialChar ~
11633 ; some assembler code 
11634 \newline 
11635 \SpecialChar ~
11636 \SpecialChar ~
11637 \SpecialChar ~
11638 \SpecialChar ~
11639 \SpecialChar ~
11640 \SpecialChar ~
11641 ljmp $0003 
11642 \newline 
11643 \SpecialChar ~
11644 \SpecialChar ~
11645 \SpecialChar ~
11646 \SpecialChar ~
11647 _endasm; 
11648 \newline 
11649 \SpecialChar ~
11650 \SpecialChar ~
11651 \SpecialChar ~
11652 \SpecialChar ~
11653 /* some more c code */ 
11654 \newline 
11655 clabel:\SpecialChar ~
11656 \SpecialChar ~
11657 /* inline assembler cannot reference this label */ 
11658 \newline 
11659 \SpecialChar ~
11660 \SpecialChar ~
11661 \SpecialChar ~
11662 \SpecialChar ~
11663 _asm
11664 \newline 
11665 \SpecialChar ~
11666 \SpecialChar ~
11667 \SpecialChar ~
11668 \SpecialChar ~
11669 $0003: ;label (can be referenced by inline assembler only) 
11670 \newline 
11671 \SpecialChar ~
11672 \SpecialChar ~
11673 \SpecialChar ~
11674 \SpecialChar ~
11675 _endasm ; 
11676 \newline 
11677 \SpecialChar ~
11678 \SpecialChar ~
11679 \SpecialChar ~
11680 \SpecialChar ~
11681 /* some more c code */
11682 \newline 
11683 }
11684 \layout Standard
11685
11686 In other words inline assembly code can access labels defined in inline
11687  assembly within the scope of the function.
11688  The same goes the other way, i.e.
11689  labels defines in inline assembly can not be accessed by C statements.
11690 \layout Section
11691
11692 Interfacing with Assembler Code
11693 \begin_inset LatexCommand \index{Assembler routines}
11694
11695 \end_inset 
11696
11697
11698 \layout Subsection
11699
11700 Global Registers used for Parameter Passing
11701 \begin_inset LatexCommand \index{Parameter passing}
11702
11703 \end_inset 
11704
11705
11706 \layout Standard
11707
11708 The compiler always uses the global registers 
11709 \emph on 
11710 DPL, DPH
11711 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
11712
11713 \end_inset 
11714
11715
11716 \begin_inset LatexCommand \index{DPTR}
11717
11718 \end_inset 
11719
11720 , B
11721 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
11722
11723 \end_inset 
11724
11725  
11726 \emph default 
11727 and
11728 \emph on 
11729  ACC
11730 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
11731
11732 \end_inset 
11733
11734
11735 \emph default 
11736  to pass the first parameter to a routine.
11737  The second parameter onwards is either allocated on the stack (for reentrant
11738  routines or if -
11739 \begin_inset ERT
11740 status Collapsed
11741
11742 \layout Standard
11743
11744 \backslash 
11745 /
11746 \end_inset 
11747
11748 -stack-auto is used) or in data / xdata memory (depending on the memory
11749  model).
11750  
11751 \layout Subsection
11752
11753 Assembler Routine (non-reentrant)
11754 \layout Standard
11755
11756 In the following example
11757 \begin_inset LatexCommand \index{reentrant}
11758
11759 \end_inset 
11760
11761
11762 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
11763
11764 \end_inset 
11765
11766  the function c_func calls an assembler routine asm_func, which takes two
11767  parameters
11768 \begin_inset LatexCommand \index{function parameter}
11769
11770 \end_inset 
11771
11772 .
11773 \layout Verse
11774
11775
11776 \family typewriter 
11777 extern int asm_func(unsigned char, unsigned char);
11778 \newline 
11779
11780 \newline 
11781 int c_func (unsigned char i, unsigned char j)
11782 \newline 
11783 {
11784 \newline 
11785 \SpecialChar ~
11786 \SpecialChar ~
11787 \SpecialChar ~
11788 \SpecialChar ~
11789 return asm_func(i,j);
11790 \newline 
11791 }
11792 \newline 
11793
11794 \newline 
11795 int main()
11796 \newline 
11797 {
11798 \newline 
11799 \SpecialChar ~
11800 \SpecialChar ~
11801 \SpecialChar ~
11802 \SpecialChar ~
11803 return c_func(10,9);
11804 \newline 
11805 }
11806 \layout Standard
11807
11808 The corresponding assembler function is:
11809 \layout Verse
11810
11811
11812 \family typewriter 
11813 .globl _asm_func_PARM_2 
11814 \newline 
11815 \SpecialChar ~
11816 \SpecialChar ~
11817 \SpecialChar ~
11818 \SpecialChar ~
11819 \SpecialChar ~
11820 \SpecialChar ~
11821 \SpecialChar ~
11822 \SpecialChar ~
11823 .globl _asm_func 
11824 \newline 
11825 \SpecialChar ~
11826 \SpecialChar ~
11827 \SpecialChar ~
11828 \SpecialChar ~
11829 \SpecialChar ~
11830 \SpecialChar ~
11831 \SpecialChar ~
11832 \SpecialChar ~
11833 .area OSEG 
11834 \newline 
11835 _asm_func_PARM_2:
11836 \newline 
11837 \SpecialChar ~
11838 \SpecialChar ~
11839 \SpecialChar ~
11840 \SpecialChar ~
11841 \SpecialChar ~
11842 \SpecialChar ~
11843 \SpecialChar ~
11844 \SpecialChar ~
11845 .ds    1 
11846 \newline 
11847 \SpecialChar ~
11848 \SpecialChar ~
11849 \SpecialChar ~
11850 \SpecialChar ~
11851 \SpecialChar ~
11852 \SpecialChar ~
11853 \SpecialChar ~
11854 \SpecialChar ~
11855 .area CSEG 
11856 \newline 
11857 _asm_func: 
11858 \newline 
11859 \SpecialChar ~
11860 \SpecialChar ~
11861 \SpecialChar ~
11862 \SpecialChar ~
11863 \SpecialChar ~
11864 \SpecialChar ~
11865 \SpecialChar ~
11866 \SpecialChar ~
11867 mov\SpecialChar ~
11868 \SpecialChar ~
11869 \SpecialChar ~
11870 \SpecialChar ~
11871 a,dpl 
11872 \newline 
11873 \SpecialChar ~
11874 \SpecialChar ~
11875 \SpecialChar ~
11876 \SpecialChar ~
11877 \SpecialChar ~
11878 \SpecialChar ~
11879 \SpecialChar ~
11880 \SpecialChar ~
11881 add\SpecialChar ~
11882 \SpecialChar ~
11883 \SpecialChar ~
11884 \SpecialChar ~
11885 a,_asm_func_PARM_2 
11886 \newline 
11887 \SpecialChar ~
11888 \SpecialChar ~
11889 \SpecialChar ~
11890 \SpecialChar ~
11891 \SpecialChar ~
11892 \SpecialChar ~
11893 \SpecialChar ~
11894 \SpecialChar ~
11895 mov\SpecialChar ~
11896 \SpecialChar ~
11897 \SpecialChar ~
11898 \SpecialChar ~
11899 dpl,a 
11900 \newline 
11901 \SpecialChar ~
11902 \SpecialChar ~
11903 \SpecialChar ~
11904 \SpecialChar ~
11905 \SpecialChar ~
11906 \SpecialChar ~
11907 \SpecialChar ~
11908 \SpecialChar ~
11909 mov\SpecialChar ~
11910 \SpecialChar ~
11911 \SpecialChar ~
11912 \SpecialChar ~
11913 dph
11914 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
11915
11916 \end_inset 
11917
11918 ,#0x00 
11919 \newline 
11920 \SpecialChar ~
11921 \SpecialChar ~
11922 \SpecialChar ~
11923 \SpecialChar ~
11924 \SpecialChar ~
11925 \SpecialChar ~
11926 \SpecialChar ~
11927 \SpecialChar ~
11928 ret
11929 \layout Standard
11930
11931 Note here that the return values
11932 \begin_inset LatexCommand \index{return value}
11933
11934 \end_inset 
11935
11936  are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
11937  two byte values.
11938  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
11939 b' & 'acc' for four byte values.
11940 \layout Standard
11941
11942 The parameter naming convention is _<function_name>_PARM_<n>, where n is
11943  the parameter number starting from 1, and counting from the left.
11944  The first parameter is passed in 
11945 \begin_inset Quotes eld
11946 \end_inset 
11947
11948 dpl
11949 \begin_inset Quotes erd
11950 \end_inset 
11951
11952  for a one byte parameter, 
11953 \begin_inset Quotes eld
11954 \end_inset 
11955
11956 dptr
11957 \begin_inset Quotes erd
11958 \end_inset 
11959
11960  for two bytes, 
11961 \begin_inset Quotes eld
11962 \end_inset 
11963
11964 b,dptr
11965 \begin_inset Quotes erd
11966 \end_inset 
11967
11968  for three bytes and 
11969 \begin_inset Quotes eld
11970 \end_inset 
11971
11972 acc,b,dptr
11973 \begin_inset Quotes erd
11974 \end_inset 
11975
11976  for a four bytes parameter.
11977  The variable name for the second parameter will be _<function_name>_PARM_2.
11978 \newline 
11979
11980 \newline 
11981 Assemble the assembler routine with the following command:
11982 \newline 
11983
11984 \newline 
11985
11986 \family sans 
11987 \series bold 
11988 asx8051 -losg asmfunc.asm
11989 \newline 
11990
11991 \newline 
11992
11993 \family default 
11994 \series default 
11995 Then compile and link the assembler routine to the C source file with the
11996  following command:
11997 \newline 
11998
11999 \newline 
12000
12001 \family sans 
12002 \series bold 
12003 sdcc cfunc.c asmfunc.rel
12004 \layout Subsection
12005
12006 Assembler Routine (reentrant)
12007 \layout Standard
12008
12009 In this case
12010 \begin_inset LatexCommand \index{reentrant}
12011
12012 \end_inset 
12013
12014
12015 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
12016
12017 \end_inset 
12018
12019  the second parameter
12020 \begin_inset LatexCommand \index{function parameter}
12021
12022 \end_inset 
12023
12024  onwards will be passed on the stack, the parameters are pushed from right
12025  to left i.e.
12026  after the call the leftmost parameter will be on the top of the stack.
12027  Here is an example:
12028 \layout Verse
12029
12030
12031 \family typewriter 
12032 extern int asm_func(unsigned char, unsigned char);
12033 \newline 
12034
12035 \newline 
12036 int c_func (unsigned char i, unsigned char j) reentrant 
12037 \newline 
12038
12039 \newline 
12040 \SpecialChar ~
12041 \SpecialChar ~
12042 \SpecialChar ~
12043 \SpecialChar ~
12044 return asm_func(i,j); 
12045 \newline 
12046
12047 \newline 
12048
12049 \newline 
12050 int main() 
12051 \newline 
12052
12053 \newline 
12054 \SpecialChar ~
12055 \SpecialChar ~
12056 \SpecialChar ~
12057 \SpecialChar ~
12058 return c_func(10,9); 
12059 \newline 
12060 }
12061 \layout Standard
12062
12063 The corresponding assembler routine is:
12064 \layout Verse
12065
12066
12067 \family typewriter 
12068 .globl _asm_func 
12069 \newline 
12070 _asm_func: 
12071 \newline 
12072 \SpecialChar ~
12073 \SpecialChar ~
12074 \SpecialChar ~
12075 \SpecialChar ~
12076 push  _bp 
12077 \newline 
12078 \SpecialChar ~
12079 \SpecialChar ~
12080 \SpecialChar ~
12081 \SpecialChar ~
12082 mov _bp,sp 
12083 \newline 
12084 \SpecialChar ~
12085 \SpecialChar ~
12086 \SpecialChar ~
12087 \SpecialChar ~
12088 mov r2,dpl
12089 \newline 
12090 \SpecialChar ~
12091 \SpecialChar ~
12092 \SpecialChar ~
12093 \SpecialChar ~
12094 mov a,_bp 
12095 \newline 
12096 \SpecialChar ~
12097 \SpecialChar ~
12098 \SpecialChar ~
12099 \SpecialChar ~
12100 add a,#0xfd 
12101 \newline 
12102 \SpecialChar ~
12103 \SpecialChar ~
12104 \SpecialChar ~
12105 \SpecialChar ~
12106 mov r0,a 
12107 \newline 
12108 \SpecialChar ~
12109 \SpecialChar ~
12110 \SpecialChar ~
12111 \SpecialChar ~
12112 add  a,#0xfc ;?
12113 \newline 
12114 \SpecialChar ~
12115 \SpecialChar ~
12116 \SpecialChar ~
12117 \SpecialChar ~
12118 mov  r1,a 
12119 \newline 
12120 \SpecialChar ~
12121 \SpecialChar ~
12122 \SpecialChar ~
12123 \SpecialChar ~
12124 mov  a,@r0 
12125 \newline 
12126 \SpecialChar ~
12127 \SpecialChar ~
12128 \SpecialChar ~
12129 \SpecialChar ~
12130 add  a,r2 ;?
12131 \newline 
12132 \SpecialChar ~
12133 \SpecialChar ~
12134 \SpecialChar ~
12135 \SpecialChar ~
12136 mov  dpl,a 
12137 \newline 
12138 \SpecialChar ~
12139 \SpecialChar ~
12140 \SpecialChar ~
12141 \SpecialChar ~
12142 mov  dph,#0x00 
12143 \newline 
12144 \SpecialChar ~
12145 \SpecialChar ~
12146 \SpecialChar ~
12147 \SpecialChar ~
12148 mov  sp,_bp 
12149 \newline 
12150 \SpecialChar ~
12151 \SpecialChar ~
12152 \SpecialChar ~
12153 \SpecialChar ~
12154 pop  _bp 
12155 \newline 
12156 \SpecialChar ~
12157 \SpecialChar ~
12158 \SpecialChar ~
12159 \SpecialChar ~
12160 ret
12161 \layout Standard
12162
12163 The compiling and linking procedure remains the same, however note the extra
12164  entry & exit linkage required for the assembler code, _bp is the stack
12165  frame pointer and is used to compute the offset into the stack for parameters
12166  and local variables.
12167 \layout Section
12168
12169 int (16 bit)
12170 \begin_inset LatexCommand \index{int (16 bit)}
12171
12172 \end_inset 
12173
12174  and long (32 bit)
12175 \begin_inset LatexCommand \index{long (32 bit)}
12176
12177 \end_inset 
12178
12179  Support
12180 \layout Standard
12181
12182 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
12183  multiplication and modulus operations are implemented by support routines.
12184  These support routines are all developed in ANSI-C to facilitate porting
12185  to other MCUs, although some model specific assembler optimizations are
12186  used.
12187  The following files contain the described routines, all of them can be
12188  found in <installdir>/share/sdcc/lib.
12189 \newline 
12190
12191 \layout Standard
12192 \align center 
12193
12194 \begin_inset  Tabular
12195 <lyxtabular version="3" rows="11" columns="2">
12196 <features>
12197 <column alignment="center" valignment="top" leftline="true" width="0">
12198 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
12199 <row topline="true" bottomline="true">
12200 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12201 \begin_inset Text
12202
12203 \layout Standard
12204
12205
12206 \series bold 
12207 Function
12208 \end_inset 
12209 </cell>
12210 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12211 \begin_inset Text
12212
12213 \layout Standard
12214
12215
12216 \series bold 
12217 Description
12218 \end_inset 
12219 </cell>
12220 </row>
12221 <row topline="true">
12222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12223 \begin_inset Text
12224
12225 \layout Standard
12226
12227 _mulint.c 
12228 \end_inset 
12229 </cell>
12230 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12231 \begin_inset Text
12232
12233 \layout Standard
12234
12235 16 bit multiplication
12236 \end_inset 
12237 </cell>
12238 </row>
12239 <row topline="true">
12240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12241 \begin_inset Text
12242
12243 \layout Standard
12244
12245 _divsint.c 
12246 \end_inset 
12247 </cell>
12248 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12249 \begin_inset Text
12250
12251 \layout Standard
12252
12253  signed 16 bit division (calls _divuint)
12254 \end_inset 
12255 </cell>
12256 </row>
12257 <row topline="true">
12258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12259 \begin_inset Text
12260
12261 \layout Standard
12262
12263 _divuint.c 
12264 \end_inset 
12265 </cell>
12266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12267 \begin_inset Text
12268
12269 \layout Standard
12270
12271  unsigned 16 bit division
12272 \end_inset 
12273 </cell>
12274 </row>
12275 <row topline="true">
12276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12277 \begin_inset Text
12278
12279 \layout Standard
12280
12281 _modsint.c
12282 \end_inset 
12283 </cell>
12284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12285 \begin_inset Text
12286
12287 \layout Standard
12288
12289 signed 16 bit modulus (calls _moduint)
12290 \end_inset 
12291 </cell>
12292 </row>
12293 <row topline="true">
12294 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12295 \begin_inset Text
12296
12297 \layout Standard
12298
12299 _moduint.c
12300 \end_inset 
12301 </cell>
12302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12303 \begin_inset Text
12304
12305 \layout Standard
12306
12307 unsigned 16 bit modulus
12308 \end_inset 
12309 </cell>
12310 </row>
12311 <row topline="true">
12312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12313 \begin_inset Text
12314
12315 \layout Standard
12316
12317 _mullong.c
12318 \end_inset 
12319 </cell>
12320 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12321 \begin_inset Text
12322
12323 \layout Standard
12324
12325 32 bit multiplication
12326 \end_inset 
12327 </cell>
12328 </row>
12329 <row topline="true">
12330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12331 \begin_inset Text
12332
12333 \layout Standard
12334
12335 _divslong.c 
12336 \end_inset 
12337 </cell>
12338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12339 \begin_inset Text
12340
12341 \layout Standard
12342
12343  signed 32 division (calls _divulong)
12344 \end_inset 
12345 </cell>
12346 </row>
12347 <row topline="true">
12348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12349 \begin_inset Text
12350
12351 \layout Standard
12352
12353 _divulong.c 
12354 \end_inset 
12355 </cell>
12356 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12357 \begin_inset Text
12358
12359 \layout Standard
12360
12361 unsigned 32 division
12362 \end_inset 
12363 </cell>
12364 </row>
12365 <row topline="true">
12366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12367 \begin_inset Text
12368
12369 \layout Standard
12370
12371 _modslong.c
12372 \end_inset 
12373 </cell>
12374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12375 \begin_inset Text
12376
12377 \layout Standard
12378
12379  signed 32 bit modulus (calls _modulong)
12380 \end_inset 
12381 </cell>
12382 </row>
12383 <row topline="true" bottomline="true">
12384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12385 \begin_inset Text
12386
12387 \layout Standard
12388
12389 _modulong.c
12390 \end_inset 
12391 </cell>
12392 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12393 \begin_inset Text
12394
12395 \layout Standard
12396
12397 unsigned 32 bit modulus
12398 \end_inset 
12399 </cell>
12400 </row>
12401 </lyxtabular>
12402
12403 \end_inset 
12404
12405
12406 \newline 
12407
12408 \layout Standard
12409
12410 Since they are compiled as 
12411 \emph on 
12412 non-reentrant
12413 \emph default 
12414
12415 \begin_inset LatexCommand \index{reentrant}
12416
12417 \end_inset 
12418
12419 , interrupt
12420 \begin_inset LatexCommand \index{interrupt}
12421
12422 \end_inset 
12423
12424  service routines should not do any of the above operations.
12425  If this is unavoidable then the above routines will need to be compiled
12426  with the 
12427 \emph on 
12428 -
12429 \begin_inset ERT
12430 status Collapsed
12431
12432 \layout Standard
12433
12434 \backslash 
12435 /
12436 \end_inset 
12437
12438 -stack-auto
12439 \begin_inset LatexCommand \index{-\/-stack-auto}
12440
12441 \end_inset 
12442
12443
12444 \emph default 
12445  option, after which the source program will have to be compiled with 
12446 \emph on 
12447 -
12448 \begin_inset ERT
12449 status Collapsed
12450
12451 \layout Standard
12452
12453 \backslash 
12454 /
12455 \end_inset 
12456
12457 -int-long-reent
12458 \begin_inset LatexCommand \index{-\/-int-long-reent}
12459
12460 \end_inset 
12461
12462
12463 \emph default 
12464  option.
12465  Notice that you don't have to call these routines directly.
12466  The compiler will use them automatically every time an integer operation
12467  is required.
12468 \layout Section
12469
12470 Floating Point Support
12471 \begin_inset LatexCommand \index{Floating point support}
12472
12473 \end_inset 
12474
12475
12476 \layout Standard
12477
12478 SDCC supports IEEE (single precision 4 bytes) floating point numbers.The
12479  floating point support routines are derived from gcc's floatlib.c and consist
12480  of the following routines:
12481 \newline 
12482
12483 \layout Standard
12484 \align center 
12485
12486 \size footnotesize 
12487
12488 \begin_inset  Tabular
12489 <lyxtabular version="3" rows="17" columns="2">
12490 <features>
12491 <column alignment="center" valignment="top" leftline="true" width="0">
12492 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
12493 <row topline="true" bottomline="true">
12494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12495 \begin_inset Text
12496
12497 \layout Standard
12498
12499
12500 \family roman 
12501 \series medium 
12502 \shape up 
12503 \size normal 
12504 \emph off 
12505 \bar no 
12506 \noun off 
12507 \color none
12508 Function 
12509 \end_inset 
12510 </cell>
12511 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12512 \begin_inset Text
12513
12514 \layout Standard
12515
12516 Description
12517 \end_inset 
12518 </cell>
12519 </row>
12520 <row topline="true">
12521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12522 \begin_inset Text
12523
12524 \layout Standard
12525
12526
12527 \family roman 
12528 \series medium 
12529 \shape up 
12530 \size normal 
12531 \emph off 
12532 \bar no 
12533 \noun off 
12534 \color none
12535 _fsadd.c
12536 \end_inset 
12537 </cell>
12538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12539 \begin_inset Text
12540
12541 \layout Standard
12542
12543
12544 \family roman 
12545 \series medium 
12546 \shape up 
12547 \size normal 
12548 \emph off 
12549 \bar no 
12550 \noun off 
12551 \color none
12552 add floating point numbers
12553 \end_inset 
12554 </cell>
12555 </row>
12556 <row topline="true">
12557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12558 \begin_inset Text
12559
12560 \layout Standard
12561
12562
12563 \family roman 
12564 \series medium 
12565 \shape up 
12566 \size normal 
12567 \emph off 
12568 \bar no 
12569 \noun off 
12570 \color none
12571 _fssub.c 
12572 \end_inset 
12573 </cell>
12574 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12575 \begin_inset Text
12576
12577 \layout Standard
12578
12579
12580 \family roman 
12581 \series medium 
12582 \shape up 
12583 \size normal 
12584 \emph off 
12585 \bar no 
12586 \noun off 
12587 \color none
12588 subtract floating point numbers 
12589 \end_inset 
12590 </cell>
12591 </row>
12592 <row topline="true">
12593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12594 \begin_inset Text
12595
12596 \layout Standard
12597
12598
12599 \family roman 
12600 \series medium 
12601 \shape up 
12602 \size normal 
12603 \emph off 
12604 \bar no 
12605 \noun off 
12606 \color none
12607 _fsdiv.c 
12608 \end_inset 
12609 </cell>
12610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12611 \begin_inset Text
12612
12613 \layout Standard
12614
12615
12616 \family roman 
12617 \series medium 
12618 \shape up 
12619 \size normal 
12620 \emph off 
12621 \bar no 
12622 \noun off 
12623 \color none
12624 divide floating point numbers 
12625 \end_inset 
12626 </cell>
12627 </row>
12628 <row topline="true">
12629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12630 \begin_inset Text
12631
12632 \layout Standard
12633
12634
12635 \family roman 
12636 \series medium 
12637 \shape up 
12638 \size normal 
12639 \emph off 
12640 \bar no 
12641 \noun off 
12642 \color none
12643 _fsmul.c 
12644 \end_inset 
12645 </cell>
12646 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12647 \begin_inset Text
12648
12649 \layout Standard
12650
12651
12652 \family roman 
12653 \series medium 
12654 \shape up 
12655 \size normal 
12656 \emph off 
12657 \bar no 
12658 \noun off 
12659 \color none
12660 multiply floating point numbers 
12661 \end_inset 
12662 </cell>
12663 </row>
12664 <row topline="true">
12665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12666 \begin_inset Text
12667
12668 \layout Standard
12669
12670
12671 \family roman 
12672 \series medium 
12673 \shape up 
12674 \size normal 
12675 \emph off 
12676 \bar no 
12677 \noun off 
12678 \color none
12679 _fs2uchar.c
12680 \end_inset 
12681 </cell>
12682 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12683 \begin_inset Text
12684
12685 \layout Standard
12686
12687
12688 \family roman 
12689 \series medium 
12690 \shape up 
12691 \size normal 
12692 \emph off 
12693 \bar no 
12694 \noun off 
12695 \color none
12696 convert floating point to unsigned char
12697 \end_inset 
12698 </cell>
12699 </row>
12700 <row topline="true">
12701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12702 \begin_inset Text
12703
12704 \layout Standard
12705
12706
12707 \family roman 
12708 \series medium 
12709 \shape up 
12710 \size normal 
12711 \emph off 
12712 \bar no 
12713 \noun off 
12714 \color none
12715 _fs2char.c
12716 \end_inset 
12717 </cell>
12718 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12719 \begin_inset Text
12720
12721 \layout Standard
12722
12723
12724 \family roman 
12725 \series medium 
12726 \shape up 
12727 \size normal 
12728 \emph off 
12729 \bar no 
12730 \noun off 
12731 \color none
12732 convert floating point to signed char
12733 \end_inset 
12734 </cell>
12735 </row>
12736 <row topline="true">
12737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12738 \begin_inset Text
12739
12740 \layout Standard
12741
12742
12743 \family roman 
12744 \series medium 
12745 \shape up 
12746 \size normal 
12747 \emph off 
12748 \bar no 
12749 \noun off 
12750 \color none
12751 _fs2uint.c
12752 \end_inset 
12753 </cell>
12754 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12755 \begin_inset Text
12756
12757 \layout Standard
12758
12759
12760 \family roman 
12761 \series medium 
12762 \shape up 
12763 \size normal 
12764 \emph off 
12765 \bar no 
12766 \noun off 
12767 \color none
12768 convert floating point to unsigned int
12769 \end_inset 
12770 </cell>
12771 </row>
12772 <row topline="true">
12773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12774 \begin_inset Text
12775
12776 \layout Standard
12777
12778
12779 \family roman 
12780 \series medium 
12781 \shape up 
12782 \size normal 
12783 \emph off 
12784 \bar no 
12785 \noun off 
12786 \color none
12787 _fs2int.c
12788 \end_inset 
12789 </cell>
12790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12791 \begin_inset Text
12792
12793 \layout Standard
12794
12795
12796 \family roman 
12797 \series medium 
12798 \shape up 
12799 \size normal 
12800 \emph off 
12801 \bar no 
12802 \noun off 
12803 \color none
12804 convert floating point to signed int
12805 \end_inset 
12806 </cell>
12807 </row>
12808 <row topline="true">
12809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12810 \begin_inset Text
12811
12812 \layout Standard
12813
12814
12815 \family roman 
12816 \series medium 
12817 \shape up 
12818 \size normal 
12819 \emph off 
12820 \bar no 
12821 \noun off 
12822 \color none
12823 _fs2ulong.
12824 \family default 
12825 \series default 
12826 \shape default 
12827 \size default 
12828 \emph default 
12829 \bar default 
12830 \noun default 
12831 \color default
12832 c
12833 \end_inset 
12834 </cell>
12835 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12836 \begin_inset Text
12837
12838 \layout Standard
12839
12840
12841 \family roman 
12842 \series medium 
12843 \shape up 
12844 \size normal 
12845 \emph off 
12846 \bar no 
12847 \noun off 
12848 \color none
12849 convert floating point to unsigned long
12850 \end_inset 
12851 </cell>
12852 </row>
12853 <row topline="true">
12854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12855 \begin_inset Text
12856
12857 \layout Standard
12858
12859
12860 \family roman 
12861 \series medium 
12862 \shape up 
12863 \size normal 
12864 \emph off 
12865 \bar no 
12866 \noun off 
12867 \color none
12868 _fs2long.c
12869 \end_inset 
12870 </cell>
12871 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12872 \begin_inset Text
12873
12874 \layout Standard
12875
12876
12877 \family roman 
12878 \series medium 
12879 \shape up 
12880 \size normal 
12881 \emph off 
12882 \bar no 
12883 \noun off 
12884 \color none
12885 convert floating point to signed long
12886 \end_inset 
12887 </cell>
12888 </row>
12889 <row topline="true">
12890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12891 \begin_inset Text
12892
12893 \layout Standard
12894
12895
12896 \family roman 
12897 \series medium 
12898 \shape up 
12899 \size normal 
12900 \emph off 
12901 \bar no 
12902 \noun off 
12903 \color none
12904 _uchar2fs.c
12905 \end_inset 
12906 </cell>
12907 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12908 \begin_inset Text
12909
12910 \layout Standard
12911
12912
12913 \family roman 
12914 \series medium 
12915 \shape up 
12916 \size normal 
12917 \emph off 
12918 \bar no 
12919 \noun off 
12920 \color none
12921 convert unsigned char to floating point
12922 \end_inset 
12923 </cell>
12924 </row>
12925 <row topline="true">
12926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12927 \begin_inset Text
12928
12929 \layout Standard
12930
12931
12932 \family roman 
12933 \series medium 
12934 \shape up 
12935 \size normal 
12936 \emph off 
12937 \bar no 
12938 \noun off 
12939 \color none
12940 _char2fs.c
12941 \end_inset 
12942 </cell>
12943 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12944 \begin_inset Text
12945
12946 \layout Standard
12947
12948
12949 \family roman 
12950 \series medium 
12951 \shape up 
12952 \size normal 
12953 \emph off 
12954 \bar no 
12955 \noun off 
12956 \color none
12957 convert char to floating point number
12958 \end_inset 
12959 </cell>
12960 </row>
12961 <row topline="true">
12962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12963 \begin_inset Text
12964
12965 \layout Standard
12966
12967
12968 \family roman 
12969 \series medium 
12970 \shape up 
12971 \size normal 
12972 \emph off 
12973 \bar no 
12974 \noun off 
12975 \color none
12976 _uint2fs.c
12977 \end_inset 
12978 </cell>
12979 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12980 \begin_inset Text
12981
12982 \layout Standard
12983
12984
12985 \family roman 
12986 \series medium 
12987 \shape up 
12988 \size normal 
12989 \emph off 
12990 \bar no 
12991 \noun off 
12992 \color none
12993 convert unsigned int to floating point
12994 \end_inset 
12995 </cell>
12996 </row>
12997 <row topline="true">
12998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12999 \begin_inset Text
13000
13001 \layout Standard
13002
13003
13004 \family roman 
13005 \series medium 
13006 \shape up 
13007 \size normal 
13008 \emph off 
13009 \bar no 
13010 \noun off 
13011 \color none
13012 _int2fs.c
13013 \end_inset 
13014 </cell>
13015 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13016 \begin_inset Text
13017
13018 \layout Standard
13019
13020
13021 \family roman 
13022 \series medium 
13023 \shape up 
13024 \size normal 
13025 \emph off 
13026 \bar no 
13027 \noun off 
13028 \color none
13029 convert int to floating point numbers
13030 \end_inset 
13031 </cell>
13032 </row>
13033 <row topline="true">
13034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13035 \begin_inset Text
13036
13037 \layout Standard
13038
13039
13040 \family roman 
13041 \series medium 
13042 \shape up 
13043 \size normal 
13044 \emph off 
13045 \bar no 
13046 \noun off 
13047 \color none
13048 _ulong2fs.c
13049 \end_inset 
13050 </cell>
13051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13052 \begin_inset Text
13053
13054 \layout Standard
13055
13056
13057 \family roman 
13058 \series medium 
13059 \shape up 
13060 \size normal 
13061 \emph off 
13062 \bar no 
13063 \noun off 
13064 \color none
13065 convert unsigned long to floating point number
13066 \end_inset 
13067 </cell>
13068 </row>
13069 <row topline="true" bottomline="true">
13070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13071 \begin_inset Text
13072
13073 \layout Standard
13074
13075
13076 \family roman 
13077 \series medium 
13078 \shape up 
13079 \size normal 
13080 \emph off 
13081 \bar no 
13082 \noun off 
13083 \color none
13084 _long2fs.c
13085 \end_inset 
13086 </cell>
13087 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13088 \begin_inset Text
13089
13090 \layout Standard
13091
13092
13093 \family roman 
13094 \series medium 
13095 \shape up 
13096 \size normal 
13097 \emph off 
13098 \bar no 
13099 \noun off 
13100 \color none
13101 convert long to floating point number
13102 \end_inset 
13103 </cell>
13104 </row>
13105 </lyxtabular>
13106
13107 \end_inset 
13108
13109
13110 \newline 
13111
13112 \layout Standard
13113
13114 These support routines are developed in ANSI-C so there is room for space
13115  and speed improvement.
13116  Note if all these routines are used simultaneously the data space might
13117  overflow.
13118  For serious floating point usage it is recommended that the large model
13119  be used.
13120  Also notice that you don't have to call this routines directly.
13121  The compiler will use them automatically every time a floating point operation
13122  is required.
13123 \layout Section
13124
13125 Library Routines
13126 \begin_inset LatexCommand \index{Libraries}
13127
13128 \end_inset 
13129
13130
13131 \layout Standard
13132
13133
13134 \emph on 
13135 <pending: this is messy and incomplete - a little more information is in
13136  sdcc/doc/libdoc.txt
13137 \emph default 
13138  >
13139 \layout Subsection
13140
13141 Compiler support routines (_gptrget, _mulint etc.)
13142 \layout Subsection
13143
13144 Stdclib functions (puts, printf, strcat etc.)
13145 \layout Subsubsection
13146
13147 <stdio.h>
13148 \layout Standard
13149
13150
13151 \begin_inset LatexCommand \index{<stdio.h>}
13152
13153 \end_inset 
13154
13155 As usual on embedded systems you have to provide your own 
13156 \family typewriter 
13157 getchar()
13158 \begin_inset LatexCommand \index{getchar()}
13159
13160 \end_inset 
13161
13162  
13163 \family default 
13164 and 
13165 \family typewriter 
13166 putchar()
13167 \begin_inset LatexCommand \index{putchar()}
13168
13169 \end_inset 
13170
13171
13172 \family default 
13173  routines.
13174  SDCC does not know whether the system connects to a serial line with or
13175  without handshake, LCD, keyboard or other device.
13176  You'll find examples for serial routines f.e.
13177  in sdcc/device/lib.
13178 \layout Standard
13179
13180 If you're short on memory you might want to use 
13181 \family typewriter 
13182 printf_small()
13183 \family default 
13184  
13185 \emph on 
13186 instead
13187 \emph default 
13188  of
13189 \family typewriter 
13190  printf()
13191 \begin_inset LatexCommand \index{printf()}
13192
13193 \end_inset 
13194
13195 .
13196
13197 \family default 
13198  For the mcs51 there is an assembly version 
13199 \family typewriter 
13200 printf_fast()
13201 \family default 
13202  which should fit the requirements of many embedded systems (by unsetting
13203  #defines it can be customized to 
13204 \emph on 
13205 not
13206 \emph default 
13207  support long variables and field widths).
13208 \layout Subsection
13209
13210 Math functions (sin, pow, sqrt etc.)
13211 \layout Subsection
13212
13213 Other libraries
13214 \layout Standard
13215
13216 Libraries
13217 \begin_inset LatexCommand \index{Libraries}
13218
13219 \end_inset 
13220
13221  included in SDCC should have a license at least as liberal as the GNU Lesser
13222  General Public License
13223 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
13224
13225 \end_inset 
13226
13227  
13228 \emph on 
13229 LGPL
13230 \emph default 
13231 .
13232 \layout Comment
13233
13234 license statements for the libraries are missing.
13235  sdcc/device/lib/ser_ir.c
13236 \layout Comment
13237
13238 or _decdptr f.e.
13239  come with a GPL (as opposed to LGPL) License - this will not be liberal
13240  enough for many embedded programmers.
13241 \layout Standard
13242
13243 If you have ported some library or want to share experience about some code
13244  which f.e.
13245  falls into any of these categories Busses (I
13246 \begin_inset Formula $^{\textrm{2}}$
13247 \end_inset 
13248
13249 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
13250  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
13251  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
13252 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
13253
13254 \end_inset 
13255
13256 \SpecialChar ~
13257 would certainly like to hear about it.
13258  Programmers coding for embedded systems are not especially famous for being
13259  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
13260 e these references are very valuable.
13261  Let's help to create a climate where information is shared.
13262 \layout Section
13263
13264 Memory Models
13265 \layout Subsection
13266
13267 MCS51 Memory Models
13268 \begin_inset LatexCommand \index{Memory model}
13269
13270 \end_inset 
13271
13272
13273 \begin_inset LatexCommand \index{MCS51 memory model}
13274
13275 \end_inset 
13276
13277
13278 \layout Subsubsection
13279
13280 Small and Large
13281 \layout Standard
13282
13283 SDCC allows two memory models for MCS51 code, 
13284 \shape slanted 
13285 small
13286 \shape default 
13287  and 
13288 \shape slanted 
13289 large
13290 \shape default 
13291 .
13292  Modules compiled with different memory models should 
13293 \emph on 
13294 never
13295 \emph default 
13296  be combined together or the results would be unpredictable.
13297  The library routines supplied with the compiler are compiled as both small
13298  and large.
13299  The compiled library modules are contained in separate directories as small
13300  and large so that you can link to either set.
13301  
13302 \layout Standard
13303
13304 When the large model is used all variables declared without a storage class
13305  will be allocated into the external ram, this includes all parameters and
13306  local variables (for non-reentrant
13307 \begin_inset LatexCommand \index{reentrant}
13308
13309 \end_inset 
13310
13311  functions).
13312  When the small model is used variables without storage class are allocated
13313  in the internal ram.
13314 \layout Standard
13315
13316 Judicious usage of the processor specific storage classes
13317 \begin_inset LatexCommand \index{Storage class}
13318
13319 \end_inset 
13320
13321  and the 'reentrant' function type will yield much more efficient code,
13322  than using the large model.
13323  Several optimizations are disabled when the program is compiled using the
13324  large model, it is therefore recommended that the small model be used unless
13325  absolutely required.
13326 \layout Subsubsection
13327
13328 External Stack
13329 \begin_inset LatexCommand \label{sub:External-Stack}
13330
13331 \end_inset 
13332
13333
13334 \begin_inset LatexCommand \index{stack}
13335
13336 \end_inset 
13337
13338
13339 \begin_inset LatexCommand \index{External stack (mcs51)}
13340
13341 \end_inset 
13342
13343
13344 \layout Standard
13345
13346 The external stack (-
13347 \begin_inset ERT
13348 status Collapsed
13349
13350 \layout Standard
13351
13352 \backslash 
13353 /
13354 \end_inset 
13355
13356 -xstack option
13357 \begin_inset LatexCommand \index{-\/-xstack}
13358
13359 \end_inset 
13360
13361 ) is located in pdata
13362 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
13363
13364 \end_inset 
13365
13366  memory (usually at the start of the external ram segment) and is 256 bytes
13367  in size.
13368  When -
13369 \begin_inset ERT
13370 status Collapsed
13371
13372 \layout Standard
13373
13374 \backslash 
13375 /
13376 \end_inset 
13377
13378 -xstack option is used to compile the program, the parameters and local
13379  variables
13380 \begin_inset LatexCommand \index{local variables}
13381
13382 \end_inset 
13383
13384  of all reentrant functions are allocated in this area.
13385  This option is provided for programs with large stack space requirements.
13386  When used with the -
13387 \begin_inset ERT
13388 status Collapsed
13389
13390 \layout Standard
13391
13392 \backslash 
13393 /
13394 \end_inset 
13395
13396 -stack-auto
13397 \begin_inset LatexCommand \index{-\/-stack-auto}
13398
13399 \end_inset 
13400
13401  option, all parameters and local variables are allocated on the external
13402  stack (note: support libraries will need to be recompiled with the same
13403  options).
13404 \layout Standard
13405
13406 The compiler outputs the higher order address byte of the external ram segment
13407  into port P2
13408 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
13409
13410 \end_inset 
13411
13412  (see also section 
13413 \begin_inset LatexCommand \ref{sub:MCS51-variants}
13414
13415 \end_inset 
13416
13417 ), therefore when using the External Stack option, this port 
13418 \emph on 
13419 may not
13420 \emph default 
13421  be used by the application program.
13422 \layout Subsection
13423
13424 DS390 Memory Model
13425 \begin_inset LatexCommand \index{Memory model}
13426
13427 \end_inset 
13428
13429
13430 \begin_inset LatexCommand \index{DS390 memory model}
13431
13432 \end_inset 
13433
13434
13435 \layout Standard
13436
13437 The only model supported is Flat 24
13438 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
13439
13440 \end_inset 
13441
13442 .
13443  This generates code for the 24 bit contiguous addressing mode of the Dallas
13444  DS80C390 part.
13445  In this mode, up to four meg of external RAM or code space can be directly
13446  addressed.
13447  See the data sheets at www.dalsemi.com for further information on this part.
13448 \newline 
13449
13450 \newline 
13451 Note that the compiler does not generate any code to place the processor
13452  into 24 bitmode (although 
13453 \emph on 
13454 tinibios
13455 \emph default 
13456  in the ds390 libraries will do that for you).
13457  If you don't use 
13458 \emph on 
13459 tinibios
13460 \emph default 
13461
13462 \begin_inset LatexCommand \index{Tinibios (DS390)}
13463
13464 \end_inset 
13465
13466 , the boot loader or similar code must ensure that the processor is in 24
13467  bit contiguous addressing mode before calling the SDCC startup code.
13468 \newline 
13469
13470 \newline 
13471 Like the 
13472 \emph on 
13473 -
13474 \begin_inset ERT
13475 status Collapsed
13476
13477 \layout Standard
13478
13479 \backslash 
13480 /
13481 \end_inset 
13482
13483 -model-large
13484 \emph default 
13485  option, variables will by default be placed into the XDATA segment.
13486  
13487 \newline 
13488
13489 \newline 
13490 Segments may be placed anywhere in the 4 meg address space using the usual
13491  -
13492 \begin_inset ERT
13493 status Collapsed
13494
13495 \layout Standard
13496
13497 \backslash 
13498 /
13499 \end_inset 
13500
13501 -*-loc options.
13502  Note that if any segments are located above 64K, the -r flag must be passed
13503  to the linker to generate the proper segment relocations, and the Intel
13504  HEX output format must be used.
13505  The -r flag can be passed to the linker by using the option 
13506 \emph on 
13507 -Wl-r
13508 \emph default 
13509  on the SDCC command line.
13510  However, currently the linker can not handle code segments > 64k.
13511 \layout Section
13512
13513 Pragmas
13514 \begin_inset LatexCommand \index{Pragmas}
13515
13516 \end_inset 
13517
13518
13519 \layout Standard
13520
13521 SDCC supports the following #pragma directives:
13522 \layout Itemize
13523
13524 save
13525 \begin_inset LatexCommand \index{\#pragma save}
13526
13527 \end_inset 
13528
13529  - this will save all current options to the save/restore stack.
13530  See restore.
13531 \layout Itemize
13532
13533 restore
13534 \begin_inset LatexCommand \index{\#pragma restore}
13535
13536 \end_inset 
13537
13538  - will restore saved options from the last save.
13539  saves & restores can be nested.
13540  SDCC uses a save/restore stack: save pushes current options to the stack,
13541  restore pulls current options from the stack.
13542  See save.
13543 \layout Itemize
13544
13545 nogcse
13546 \begin_inset LatexCommand \index{\#pragma nogcse}
13547
13548 \end_inset 
13549
13550  - will stop global common subexpression elimination.
13551 \layout Itemize
13552
13553 noinduction
13554 \begin_inset LatexCommand \index{\#pragma noinduction}
13555
13556 \end_inset 
13557
13558  - will stop loop induction optimizations.
13559 \layout Itemize
13560
13561 nojtbound
13562 \begin_inset LatexCommand \index{\#pragma nojtbound}
13563
13564 \end_inset 
13565
13566  - will not generate code for boundary value checking, when switch statements
13567  are turned into jump-tables (dangerous).
13568  For more details see section 
13569 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
13570
13571 \end_inset 
13572
13573 .
13574 \layout Itemize
13575
13576 nooverlay
13577 \begin_inset LatexCommand \index{\#pragma nooverlay}
13578
13579 \end_inset 
13580
13581  - the compiler will not overlay the parameters and local variables of a
13582  function.
13583 \layout Itemize
13584
13585 less_pedantic
13586 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
13587
13588 \end_inset 
13589
13590  - the compiler will not warn you anymore for obvious mistakes, you'r on
13591  your own now ;-(
13592 \layout Itemize
13593
13594 noloopreverse
13595 \begin_inset LatexCommand \index{\#pragma noloopreverse}
13596
13597 \end_inset 
13598
13599  - Will not do loop reversal optimization
13600 \layout Itemize
13601
13602 exclude
13603 \begin_inset LatexCommand \index{\#pragma exclude}
13604
13605 \end_inset 
13606
13607  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables generation of
13608  pair of push/pop
13609 \begin_inset LatexCommand \index{push/pop}
13610
13611 \end_inset 
13612
13613  instruction in ISR function (using interrupt
13614 \begin_inset LatexCommand \index{interrupt}
13615
13616 \end_inset 
13617
13618  keyword).
13619  The directive should be placed immediately before the ISR function definition
13620  and it affects ALL ISR functions following it.
13621  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
13622 exclude\SpecialChar ~
13623 none
13624 \begin_inset LatexCommand \index{\#pragma exclude}
13625
13626 \end_inset 
13627
13628 .
13629 \layout Itemize
13630
13631 noiv
13632 \begin_inset LatexCommand \index{\#pragma noiv}
13633
13634 \end_inset 
13635
13636  - Do not generate interrupt
13637 \begin_inset LatexCommand \index{interrupt}
13638
13639 \end_inset 
13640
13641  vector table entries for all ISR functions defined after the pragma.
13642  This is useful in cases where the interrupt vector table must be defined
13643  manually, or when there is a secondary, manually defined interrupt vector
13644  table (e.g.
13645  for the autovector feature of the Cypress EZ-USB FX2).
13646  More elegantly this can be achieved by obmitting the optional interrupt
13647  number after the interrupt keyword, see section 
13648 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
13649
13650 \end_inset 
13651
13652 \SpecialChar ~
13653 about interrupts.
13654 \layout Itemize
13655
13656 callee_saves
13657 \begin_inset LatexCommand \index{\#pragma callee\_saves}
13658
13659 \end_inset 
13660
13661
13662 \begin_inset LatexCommand \index{function prologue}
13663
13664 \end_inset 
13665
13666  function1[,function2[,function3...]] - The compiler by default uses a caller
13667  saves convention for register saving across function calls, however this
13668  can cause unnecessary register pushing & popping
13669 \begin_inset LatexCommand \index{push/pop}
13670
13671 \end_inset 
13672
13673  when calling small functions from larger functions.
13674  This option can be used to switch off the register saving convention for
13675  the function names specified.
13676  The compiler will not save registers when calling these functions, extra
13677  code need to be manually inserted at the entry & exit for these functions
13678  to save & restore the registers used by these functions, this can SUBSTANTIALLY
13679  reduce code & improve run time performance of the generated code.
13680  In the future the compiler (with inter procedural analysis) may be able
13681  to determine the appropriate scheme to use for each function call.
13682  If -
13683 \begin_inset ERT
13684 status Collapsed
13685
13686 \layout Standard
13687
13688 \backslash 
13689 /
13690 \end_inset 
13691
13692 -callee-saves command line option is used, the function names specified
13693  in #pragma\SpecialChar ~
13694 callee_saves
13695 \begin_inset LatexCommand \index{\#pragma callee\_saves}
13696
13697 \end_inset 
13698
13699  is appended to the list of functions specified in the command line.
13700 \layout Standard
13701
13702 SDCPP supports the following #pragma directives:
13703 \layout Itemize
13704
13705 preproc_asm
13706 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
13707
13708 \end_inset 
13709
13710  (+ | -) - switch _asm _endasm block preprocessing on / off.
13711  Default is on.
13712 \layout Standard
13713
13714 The pragma's are intended to be used to turn-on or off certain optimizations
13715  which might cause the compiler to generate extra stack / data space to
13716  store compiler generated temporary variables.
13717  This usually happens in large functions.
13718  Pragma directives should be used as shown in the following example, they
13719  are used to control options & optimizations for a given function; pragmas
13720  should be placed before and/or after a function, placing pragma's inside
13721  a function body could have unpredictable results.
13722 \layout Verse
13723
13724
13725 \family typewriter 
13726 #pragma save
13727 \begin_inset LatexCommand \index{\#pragma save}
13728
13729 \end_inset 
13730
13731  \SpecialChar ~
13732 \SpecialChar ~
13733 \SpecialChar ~
13734 \SpecialChar ~
13735 \SpecialChar ~
13736 \SpecialChar ~
13737 \SpecialChar ~
13738 /* save the current settings */ 
13739 \newline 
13740 #pragma nogcse
13741 \begin_inset LatexCommand \index{\#pragma nogcse}
13742
13743 \end_inset 
13744
13745  \SpecialChar ~
13746 \SpecialChar ~
13747 \SpecialChar ~
13748 \SpecialChar ~
13749 \SpecialChar ~
13750 /* turnoff global subexpression elimination */ 
13751 \newline 
13752 #pragma noinduction
13753 \begin_inset LatexCommand \index{\#pragma noinduction}
13754
13755 \end_inset 
13756
13757  /* turn off induction optimizations */ 
13758 \newline 
13759 int foo () 
13760 \newline 
13761
13762 \newline 
13763 \SpecialChar ~
13764  \SpecialChar ~
13765  ...
13766  
13767 \newline 
13768 \SpecialChar ~
13769  \SpecialChar ~
13770  /* large code */ 
13771 \newline 
13772 \SpecialChar ~
13773  \SpecialChar ~
13774  ...
13775  
13776 \newline 
13777
13778 \newline 
13779 #pragma restore
13780 \begin_inset LatexCommand \index{\#pragma restore}
13781
13782 \end_inset 
13783
13784  /* turn the optimizations back on */
13785 \layout Standard
13786
13787 The compiler will generate a warning message when extra space is allocated.
13788  It is strongly recommended that the save and restore pragma's be used when
13789  changing options for a function.
13790 \layout Section
13791
13792 Defines Created by the Compiler
13793 \layout Standard
13794
13795 The compiler creates the following #defines
13796 \begin_inset LatexCommand \index{\#defines}
13797
13798 \end_inset 
13799
13800
13801 \begin_inset LatexCommand \index{Defines created by the compiler}
13802
13803 \end_inset 
13804
13805 :
13806 \newline 
13807
13808 \layout Standard
13809
13810
13811 \begin_inset  Tabular
13812 <lyxtabular version="3" rows="10" columns="2">
13813 <features>
13814 <column alignment="center" valignment="top" leftline="true" width="0">
13815 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
13816 <row topline="true" bottomline="true">
13817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13818 \begin_inset Text
13819
13820 \layout Standard
13821
13822
13823 \series bold 
13824 #define
13825 \end_inset 
13826 </cell>
13827 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13828 \begin_inset Text
13829
13830 \layout Standard
13831
13832
13833 \series bold 
13834 Description
13835 \end_inset 
13836 </cell>
13837 </row>
13838 <row topline="true">
13839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13840 \begin_inset Text
13841
13842 \layout Standard
13843
13844 SDCC
13845 \begin_inset LatexCommand \index{SDCC}
13846
13847 \end_inset 
13848
13849  
13850 \end_inset 
13851 </cell>
13852 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13853 \begin_inset Text
13854
13855 \layout Standard
13856
13857 this Symbol is always defined
13858 \end_inset 
13859 </cell>
13860 </row>
13861 <row topline="true">
13862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13863 \begin_inset Text
13864
13865 \layout Standard
13866
13867 SDCC_mcs51
13868 \begin_inset LatexCommand \index{SDCC\_mcs51}
13869
13870 \end_inset 
13871
13872  or SDCC_ds390
13873 \begin_inset LatexCommand \index{SDCC\_ds390}
13874
13875 \end_inset 
13876
13877  or SDCC_z80
13878 \begin_inset LatexCommand \index{SDCC\_z80}
13879
13880 \end_inset 
13881
13882 , etc
13883 \end_inset 
13884 </cell>
13885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13886 \begin_inset Text
13887
13888 \layout Standard
13889
13890 depending on the model used (e.g.: -mds390
13891 \end_inset 
13892 </cell>
13893 </row>
13894 <row topline="true">
13895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13896 \begin_inset Text
13897
13898 \layout Standard
13899
13900 __mcs51
13901 \begin_inset LatexCommand \index{\_\_mcs51}
13902
13903 \end_inset 
13904
13905 , __ds390
13906 \begin_inset LatexCommand \index{\_\_ds390}
13907
13908 \end_inset 
13909
13910 , __hc08
13911 \begin_inset LatexCommand \index{\_\_hc08}
13912
13913 \end_inset 
13914
13915 , __z80
13916 \begin_inset LatexCommand \index{\_\_z80}
13917
13918 \end_inset 
13919
13920 , etc
13921 \end_inset 
13922 </cell>
13923 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13924 \begin_inset Text
13925
13926 \layout Standard
13927
13928 depending on the model used (e.g.
13929  -mz80)
13930 \end_inset 
13931 </cell>
13932 </row>
13933 <row topline="true">
13934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13935 \begin_inset Text
13936
13937 \layout Standard
13938
13939 SDCC_STACK_AUTO
13940 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
13941
13942 \end_inset 
13943
13944
13945 \end_inset 
13946 </cell>
13947 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13948 \begin_inset Text
13949
13950 \layout Standard
13951
13952 when 
13953 \emph on 
13954 -
13955 \begin_inset ERT
13956 status Collapsed
13957
13958 \layout Standard
13959
13960 \backslash 
13961 /
13962 \end_inset 
13963
13964 -stack-auto
13965 \emph default 
13966  option is used
13967 \end_inset 
13968 </cell>
13969 </row>
13970 <row topline="true">
13971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13972 \begin_inset Text
13973
13974 \layout Standard
13975
13976 SDCC_MODEL_SMALL
13977 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
13978
13979 \end_inset 
13980
13981
13982 \end_inset 
13983 </cell>
13984 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13985 \begin_inset Text
13986
13987 \layout Standard
13988
13989 when 
13990 \emph on 
13991 -
13992 \begin_inset ERT
13993 status Collapsed
13994
13995 \layout Standard
13996
13997 \backslash 
13998 /
13999 \end_inset 
14000
14001 -model-small
14002 \emph default 
14003  is used
14004 \end_inset 
14005 </cell>
14006 </row>
14007 <row topline="true">
14008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14009 \begin_inset Text
14010
14011 \layout Standard
14012
14013 SDCC_MODEL_LARGE
14014 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
14015
14016 \end_inset 
14017
14018
14019 \end_inset 
14020 </cell>
14021 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14022 \begin_inset Text
14023
14024 \layout Standard
14025
14026 when 
14027 \emph on 
14028 -
14029 \begin_inset ERT
14030 status Collapsed
14031
14032 \layout Standard
14033
14034 \backslash 
14035 /
14036 \end_inset 
14037
14038 -model-large
14039 \emph default 
14040  is used
14041 \end_inset 
14042 </cell>
14043 </row>
14044 <row topline="true">
14045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14046 \begin_inset Text
14047
14048 \layout Standard
14049
14050 SDCC_USE_XSTACK
14051 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
14052
14053 \end_inset 
14054
14055
14056 \end_inset 
14057 </cell>
14058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14059 \begin_inset Text
14060
14061 \layout Standard
14062
14063 when 
14064 \emph on 
14065 -
14066 \begin_inset ERT
14067 status Collapsed
14068
14069 \layout Standard
14070
14071 \backslash 
14072 /
14073 \end_inset 
14074
14075 -xstack
14076 \emph default 
14077  option is used
14078 \end_inset 
14079 </cell>
14080 </row>
14081 <row topline="true">
14082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14083 \begin_inset Text
14084
14085 \layout Standard
14086
14087 SDCC_STACK_TENBIT
14088 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
14089
14090 \end_inset 
14091
14092  
14093 \end_inset 
14094 </cell>
14095 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14096 \begin_inset Text
14097
14098 \layout Standard
14099
14100 when 
14101 \emph on 
14102 -mds390
14103 \emph default 
14104  is used
14105 \end_inset 
14106 </cell>
14107 </row>
14108 <row topline="true" bottomline="true">
14109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14110 \begin_inset Text
14111
14112 \layout Standard
14113
14114 SDCC_MODEL_FLAT24
14115 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
14116
14117 \end_inset 
14118
14119
14120 \end_inset 
14121 </cell>
14122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14123 \begin_inset Text
14124
14125 \layout Standard
14126
14127 when 
14128 \emph on 
14129 -mds390
14130 \emph default 
14131  is used
14132 \end_inset 
14133 </cell>
14134 </row>
14135 </lyxtabular>
14136
14137 \end_inset 
14138
14139
14140 \layout Chapter
14141
14142 Notes on supported Processors
14143 \layout Section
14144
14145 MCS51 variants
14146 \begin_inset LatexCommand \label{sub:MCS51-variants}
14147
14148 \end_inset 
14149
14150
14151 \begin_inset LatexCommand \index{MCS51 variants}
14152
14153 \end_inset 
14154
14155
14156 \layout Standard
14157
14158 MCS51 processors are available from many vendors and come in many different
14159  flavours.
14160  While they might differ considerably in respect to Special Function Registers
14161  the core MCS51 is usually not modified or is kept compatible.
14162  
14163 \layout Subsection
14164
14165 pdata access by SFR 
14166 \layout Standard
14167
14168 With the upcome of devices with internal xdata and flash memory devices
14169  using port P2
14170 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
14171
14172 \end_inset 
14173
14174  as dedicated I/O port is becoming more popular.
14175  Switching the high byte for pdata
14176 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
14177
14178 \end_inset 
14179
14180  access which was formerly done by port P2 is then achieved by a Special
14181  Function Register
14182 \begin_inset LatexCommand \index{sfr}
14183
14184 \end_inset 
14185
14186 .
14187  In well-established MCS51 tradition the address of this 
14188 \emph on 
14189 sfr
14190 \emph default 
14191  is where the chip designers decided to put it.
14192  Needless to say that they didn't agree on a common name either.
14193  As pdata addressing is used in the startup code for the initialization
14194  of xdata variables a separate startup code should be used as described
14195  in section 
14196 \begin_inset LatexCommand \ref{sub:Startup-Code}
14197
14198 \end_inset 
14199
14200 .
14201 \layout Subsection
14202
14203 Other Features available by SFR
14204 \layout Standard
14205
14206 Some MCS51 variants offer features like Double DPTR
14207 \begin_inset LatexCommand \index{DPTR}
14208
14209 \end_inset 
14210
14211 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
14212  These are currently not used for the MCS51 port.
14213  If you absolutely need them you can fall back to inline assembly or submit
14214  a patch to SDCC.
14215 \layout Section
14216
14217 The Z80 and gbz80 port
14218 \layout Standard
14219
14220 SDCC can target both the Zilog 
14221 \begin_inset LatexCommand \index{Z80}
14222
14223 \end_inset 
14224
14225  and the Nintendo Gameboy's Z80-like gbz80
14226 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
14227
14228 \end_inset 
14229
14230 .
14231  The Z80 port is passed through the same 
14232 \emph on 
14233 regressions tests
14234 \begin_inset LatexCommand \index{Regression test}
14235
14236 \end_inset 
14237
14238
14239 \emph default 
14240  as the MCS51 and DS390 ports, so floating point support, support for long
14241  variables and bitfield support is fine.
14242  See mailing lists and forums about interrupt routines.
14243 \layout Standard
14244
14245 As always, the code is the authoritative reference - see z80/ralloc.c and
14246  z80/gen.c.
14247  The stack
14248 \begin_inset LatexCommand \index{stack}
14249
14250 \end_inset 
14251
14252  frame is similar to that generated by the IAR Z80 compiler.
14253  IX is used as the base pointer, HL is used as a temporary register, and
14254  BC and DE are available for holding variables.
14255  IY is currently unused.
14256  Return values
14257 \begin_inset LatexCommand \index{return value}
14258
14259 \end_inset 
14260
14261  are stored in HL.
14262  One bad side effect of using IX as the base pointer is that a functions
14263  stack frame is limited to 127 bytes - this will be fixed in a later version.
14264 \layout Section
14265
14266 The HC08 port
14267 \layout Standard
14268
14269 The port to the Motorola HC08
14270 \begin_inset LatexCommand \index{HC08}
14271
14272 \end_inset 
14273
14274  family has been added in October 2003, thank you Erik!
14275 \layout Section
14276
14277 The PIC14 port
14278 \layout Standard
14279
14280 The 14bit PIC
14281 \begin_inset LatexCommand \index{PIC14}
14282
14283 \end_inset 
14284
14285  port still requires a major effort from the development community.
14286  However it can work for very simple code.
14287 \layout Subsection
14288
14289 C code and 14bit PIC code page
14290 \begin_inset LatexCommand \index{code page (pic14)}
14291
14292 \end_inset 
14293
14294  and RAM banks
14295 \begin_inset LatexCommand \index{RAM bank (pic14)}
14296
14297 \end_inset 
14298
14299
14300 \layout Standard
14301
14302 The linker organizes allocation for the code page and RAM banks.
14303  It does not have intimate knowledge of the code flow.
14304  It will put all the code section of a single asm file into a single code
14305  page.
14306  In order to make use of multiple code pages, separate asm files must be
14307  used.
14308  The compiler treats all functions of a single C file as being in the same
14309  code page unless it is non static.
14310  The compiler treats all local variables of a single C file as being in
14311  the same RAM bank unless it is an extern.
14312 \newline 
14313
14314 \newline 
14315 To get the best follow these guide lines:
14316 \layout Enumerate
14317
14318 make local functions static, as non static functions require code page selection
14319  overhead.
14320 \layout Enumerate
14321
14322 Make local variables static as extern variables require RAM bank selection
14323  overhead.
14324 \layout Enumerate
14325
14326 For devices that have multiple code pages it is more efficient to use the
14327  same number of files as pages, i.e.
14328  for the 16F877 use 4 separate files and i.e.
14329  for the 16F874 use 2 separate files.
14330  This way the linker can put the code for each file into different code
14331  pages and the compiler can allocate reusable variables more efficiently
14332  and there's less page selection overhead.
14333  And as for any 8 bit micro (especially for PIC 14 as they have a very simple
14334  instruction set) use 'unsigned char' whereever possible instead of 'int'.
14335 \layout Subsection
14336
14337 Creating a device include file 
14338 \layout Standard
14339
14340 For generating a device include file use the support perl script inc2h.pl
14341  kept in directory support/script.
14342 \layout Subsection
14343
14344 Interrupt code
14345 \layout Standard
14346
14347 For the interrupt function, use the keyword 'interrupt'
14348 \begin_inset LatexCommand \index{interrupt}
14349
14350 \end_inset 
14351
14352  with level number of 0 (PIC14 only has 1 interrupt so this number is only
14353  there to avoid a syntax error - it ought to be fixed).
14354  E.g.:
14355 \layout Verse
14356
14357
14358 \family typewriter 
14359 void Intr(void) interrupt 0
14360 \newline 
14361 {
14362 \newline 
14363 \SpecialChar ~
14364 \SpecialChar ~
14365 T0IF = 0; /* Clear timer interrupt */
14366 \newline 
14367 }
14368 \layout Standard
14369
14370 Linking and assembling
14371 \newline 
14372 For assembling you can use either GPUTILS'
14373 \begin_inset LatexCommand \index{gputils (pic tools)}
14374
14375 \end_inset 
14376
14377  gpasm.exe or MPLAB's mpasmwin.exe.
14378  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
14379  If you use MPLAB and an interrupt function then the linker script file
14380  vectors section will need to be enlarged to link with mplink.
14381 \newline 
14382
14383 \newline 
14384 Here is a 
14385 \family typewriter 
14386 Makefile
14387 \family default 
14388  using GPUTILS:
14389 \layout Verse
14390
14391
14392 \family typewriter 
14393 .c.o:
14394 \newline 
14395 \SpecialChar ~
14396 \SpecialChar ~
14397 \SpecialChar ~
14398 \SpecialChar ~
14399 \SpecialChar ~
14400 \SpecialChar ~
14401 \SpecialChar ~
14402 \SpecialChar ~
14403 sdcc -S -V -mpic14 -p16F877 $< 
14404 \newline 
14405 \SpecialChar ~
14406 \SpecialChar ~
14407 \SpecialChar ~
14408 \SpecialChar ~
14409 \SpecialChar ~
14410 \SpecialChar ~
14411 \SpecialChar ~
14412 \SpecialChar ~
14413 gpasm -c $*.asm
14414 \newline 
14415
14416 \newline 
14417 $(PRJ).hex: $(OBJS) 
14418 \newline 
14419 \SpecialChar ~
14420 \SpecialChar ~
14421 \SpecialChar ~
14422 \SpecialChar ~
14423 \SpecialChar ~
14424 \SpecialChar ~
14425 \SpecialChar ~
14426 \SpecialChar ~
14427 gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS)
14428 \layout Standard
14429
14430 Here is a 
14431 \family typewriter 
14432 Makefile
14433 \family default 
14434  using MPLAB:
14435 \layout Verse
14436
14437
14438 \family typewriter 
14439 .c.o: 
14440 \newline 
14441 \SpecialChar ~
14442 \SpecialChar ~
14443 \SpecialChar ~
14444 \SpecialChar ~
14445 \SpecialChar ~
14446 \SpecialChar ~
14447 \SpecialChar ~
14448 \SpecialChar ~
14449 sdcc -S -V -mpic14 -p16F877 $< 
14450 \newline 
14451 \SpecialChar ~
14452 \SpecialChar ~
14453 \SpecialChar ~
14454 \SpecialChar ~
14455 \SpecialChar ~
14456 \SpecialChar ~
14457 \SpecialChar ~
14458 \SpecialChar ~
14459 mpasmwin /q /o $*.asm
14460 \newline 
14461
14462 \newline 
14463 $(PRJ).hex: $(OBJS) 
14464 \newline 
14465 \SpecialChar ~
14466 \SpecialChar ~
14467 \SpecialChar ~
14468 \SpecialChar ~
14469 \SpecialChar ~
14470 \SpecialChar ~
14471 \SpecialChar ~
14472 \SpecialChar ~
14473 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS)
14474 \layout Section
14475
14476 The PIC16
14477 \begin_inset LatexCommand \index{PIC16}
14478
14479 \end_inset 
14480
14481  port
14482 \layout Standard
14483
14484 The PIC16
14485 \begin_inset LatexCommand \index{PIC16}
14486
14487 \end_inset 
14488
14489  port (refered from now on as pic16) is the portion of SDCC that is responsible
14490  to produce code for the Microchip
14491 \begin_inset LatexCommand \index{Microchip}
14492
14493 \end_inset 
14494
14495 (TM) microcontrollers with 16 bit core.
14496  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
14497 \layout Subsection
14498
14499 Global Options
14500 \layout Standard
14501
14502 The pic16 port supports the standard command line arguments as supposed,
14503  with the exception of certain cases that will be mentioned in the following
14504  list:
14505 \layout List
14506 \labelwidthstring 00.00.0000
14507
14508 -
14509 \begin_inset ERT
14510 status Collapsed
14511
14512 \layout Standard
14513
14514 \backslash 
14515 /
14516 \end_inset 
14517
14518 -stack-auto Auto variables that are function parameters, will be saved on
14519  stack by default.
14520  
14521 \emph on 
14522 There is no need to specify this in the command line.
14523 \layout List
14524 \labelwidthstring 00.00.0000
14525
14526 -
14527 \begin_inset ERT
14528 status Collapsed
14529
14530 \layout Standard
14531
14532 \backslash 
14533 /
14534 \end_inset 
14535
14536 -float-reent All floating point functions are reentrant by default.
14537  
14538 \emph on 
14539 There is no need to specifiy this in the command line.
14540 \layout List
14541 \labelwidthstring 00.00.0000
14542
14543 -
14544 \begin_inset ERT
14545 status Collapsed
14546
14547 \layout Standard
14548
14549 \backslash 
14550 /
14551 \end_inset 
14552
14553 -callee-saves See -
14554 \begin_inset ERT
14555 status Collapsed
14556
14557 \layout Standard
14558
14559 \backslash 
14560 /
14561 \end_inset 
14562
14563 -all-callee-saves
14564 \layout List
14565 \labelwidthstring 00.00.0000
14566
14567 -
14568 \begin_inset ERT
14569 status Collapsed
14570
14571 \layout Standard
14572
14573 \backslash 
14574 /
14575 \end_inset 
14576
14577 -all-callee-saves All function arguments are passed on stack by default.
14578  
14579 \emph on 
14580 There is no need to specify this in the command line.
14581 \layout List
14582 \labelwidthstring 00.00.0000
14583
14584 -
14585 \begin_inset ERT
14586 status Collapsed
14587
14588 \layout Standard
14589
14590 \backslash 
14591 /
14592 \end_inset 
14593
14594 -fommit-frame-pointer Frame pointer will be omitted when the function uses
14595  no local variables.
14596 \layout Subsection
14597
14598 PIC16 Port Specific Options
14599 \layout Standard
14600
14601 The port specific options appear after the global options in the sdcc --help
14602  output.
14603 \layout Subsubsection
14604
14605 General Options
14606 \layout Standard
14607
14608 General options enable certain port features and optimizations.
14609 \layout List
14610 \labelwidthstring 00.00.0000
14611
14612 -
14613 \begin_inset ERT
14614 status Collapsed
14615
14616 \layout Standard
14617
14618 \backslash 
14619 /
14620 \end_inset 
14621
14622 -pgen-bank Instructs the port to insert BANKSEL directives before instructions
14623  that use the Bank Select Register (BSR).
14624 \layout List
14625 \labelwidthstring 00.00.0000
14626
14627 -
14628 \begin_inset ERT
14629 status Collapsed
14630
14631 \layout Standard
14632
14633 \backslash 
14634 /
14635 \end_inset 
14636
14637 -pomit-config-words Instructs the port to omit the generation of the configurati
14638 on words.
14639 \layout List
14640 \labelwidthstring 00.00.0000
14641
14642 -
14643 \begin_inset ERT
14644 status Collapsed
14645
14646 \layout Standard
14647
14648 \backslash 
14649 /
14650 \end_inset 
14651
14652 -pomit-ivt Instructs the port to omit the generation of the interrupt vectors
14653 \layout List
14654 \labelwidthstring 00.00.0000
14655
14656 -
14657 \begin_inset ERT
14658 status Collapsed
14659
14660 \layout Standard
14661
14662 \backslash 
14663 /
14664 \end_inset 
14665
14666 -pleave-reset-vector Used in conjuction with the previous command, instructs
14667  the port NOT to omit the reset vector.
14668 \layout List
14669 \labelwidthstring 00.00.0000
14670
14671 -
14672 \begin_inset ERT
14673 status Collapsed
14674
14675 \layout Standard
14676
14677 \backslash 
14678 /
14679 \end_inset 
14680
14681 -penable-stack Enables stack usage.
14682  All new development is done with stack enabled.
14683  This command line soon will be deprecated and stack will be enabled by
14684  default.
14685  For the time being it must be entered if one wants to have stack.
14686 \layout List
14687 \labelwidthstring 00.00.0000
14688
14689 -
14690 \begin_inset ERT
14691 status Collapsed
14692
14693 \layout Standard
14694
14695 \backslash 
14696 /
14697 \end_inset 
14698
14699 -stack-model=[model] Used in conjuction with the command above.
14700  Defines the stack model to be used, valid stack models are : 
14701 \begin_deeper 
14702 \layout List
14703 \labelwidthstring 00.00.0000
14704
14705
14706 \emph on 
14707 small
14708 \emph default 
14709  Selects small stack model.
14710  8 bit stack and frame pointers.
14711  Supports 256 bytes stack size.
14712 \layout List
14713 \labelwidthstring 00.00.0000
14714
14715
14716 \emph on 
14717 large
14718 \emph default 
14719  Selects large stack model.
14720  16 bit stack and frame pointers.
14721  Supports 65536 bytes stack size.
14722 \end_deeper 
14723 \layout List
14724 \labelwidthstring 00.00.0000
14725
14726 -
14727 \begin_inset ERT
14728 status Collapsed
14729
14730 \layout Standard
14731
14732 \backslash 
14733 /
14734 \end_inset 
14735
14736 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
14737  unitialized data variables with [kword].
14738  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
14739 \layout Subsubsection
14740
14741 Debugging Options
14742 \layout Standard
14743
14744 Debugging options enable extra debugging information in the output files.
14745 \layout List
14746 \labelwidthstring 00.00.0000
14747
14748 -
14749 \begin_inset ERT
14750 status Collapsed
14751
14752 \layout Standard
14753
14754 \backslash 
14755 /
14756 \end_inset 
14757
14758 -debug-xtra Similar to --debug, but dumps more information.
14759 \layout List
14760 \labelwidthstring 00.00.0000
14761
14762 -
14763 \begin_inset ERT
14764 status Collapsed
14765
14766 \layout Standard
14767
14768 \backslash 
14769 /
14770 \end_inset 
14771
14772 -debug-ralloc Force register allocator to dump <source>.d file with debugging
14773  information.
14774  <source> is the name of the file compiled.
14775 \layout List
14776 \labelwidthstring 00.00.0000
14777
14778 -
14779 \begin_inset ERT
14780 status Collapsed
14781
14782 \layout Standard
14783
14784 \backslash 
14785 /
14786 \end_inset 
14787
14788 -pcode-verbose Enable pcode debugging information in translation.
14789 \layout Subsection
14790
14791 Preprocessor Macros
14792 \layout Standard
14793
14794 PIC16 port defines the following preprocessor macros while translating a
14795  source.
14796 \layout Standard
14797 \align center 
14798
14799 \begin_inset  Tabular
14800 <lyxtabular version="3" rows="2" columns="2">
14801 <features>
14802 <column alignment="center" valignment="top" leftline="true" width="0">
14803 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
14804 <row topline="true" bottomline="true">
14805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14806 \begin_inset Text
14807
14808 \layout Standard
14809
14810 Macro
14811 \end_inset 
14812 </cell>
14813 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14814 \begin_inset Text
14815
14816 \layout Standard
14817
14818 Description
14819 \end_inset 
14820 </cell>
14821 </row>
14822 <row topline="true" bottomline="true">
14823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14824 \begin_inset Text
14825
14826 \layout Standard
14827
14828 pic18fxxxx
14829 \end_inset 
14830 </cell>
14831 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14832 \begin_inset Text
14833
14834 \layout Standard
14835
14836 MCU Identification.
14837  
14838 \emph on 
14839 xxxx
14840 \emph default 
14841  is the microcontrol identification number, i.e.
14842  452, 6620, etc
14843 \end_inset 
14844 </cell>
14845 </row>
14846 </lyxtabular>
14847
14848 \end_inset 
14849
14850
14851 \layout Subsection
14852
14853 Directories
14854 \layout Standard
14855
14856 PIC16 port uses the following directories for searching header files and
14857  libraries.
14858 \layout Standard
14859 \align center 
14860
14861 \begin_inset  Tabular
14862 <lyxtabular version="3" rows="3" columns="4">
14863 <features>
14864 <column alignment="center" valignment="top" leftline="true" width="0">
14865 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
14866 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
14867 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
14868 <row topline="true" bottomline="true">
14869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14870 \begin_inset Text
14871
14872 \layout Standard
14873
14874 Directory
14875 \end_inset 
14876 </cell>
14877 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14878 \begin_inset Text
14879
14880 \layout Standard
14881
14882 Description
14883 \end_inset 
14884 </cell>
14885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14886 \begin_inset Text
14887
14888 \layout Standard
14889
14890 Target
14891 \end_inset 
14892 </cell>
14893 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14894 \begin_inset Text
14895
14896 \layout Standard
14897
14898 Command prefix
14899 \end_inset 
14900 </cell>
14901 </row>
14902 <row topline="true" bottomline="true">
14903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14904 \begin_inset Text
14905
14906 \layout Standard
14907
14908 PREFIX/sdcc/include/pic16
14909 \end_inset 
14910 </cell>
14911 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14912 \begin_inset Text
14913
14914 \layout Standard
14915
14916 PIC16 specific headers
14917 \end_inset 
14918 </cell>
14919 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14920 \begin_inset Text
14921
14922 \layout Standard
14923
14924 Compiler
14925 \end_inset 
14926 </cell>
14927 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14928 \begin_inset Text
14929
14930 \layout Standard
14931
14932 -I
14933 \end_inset 
14934 </cell>
14935 </row>
14936 <row topline="true" bottomline="true">
14937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14938 \begin_inset Text
14939
14940 \layout Standard
14941
14942 PREFIX/sdcc/lib/pic16
14943 \end_inset 
14944 </cell>
14945 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14946 \begin_inset Text
14947
14948 \layout Standard
14949
14950 PIC16 specific libraries
14951 \end_inset 
14952 </cell>
14953 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14954 \begin_inset Text
14955
14956 \layout Standard
14957
14958 Linker
14959 \end_inset 
14960 </cell>
14961 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14962 \begin_inset Text
14963
14964 \layout Standard
14965
14966 -L
14967 \end_inset 
14968 </cell>
14969 </row>
14970 </lyxtabular>
14971
14972 \end_inset 
14973
14974
14975 \layout Subsection
14976
14977 Header Files
14978 \layout Standard
14979
14980 There is one main header file that can be included to the source files using
14981  the pic16 port.
14982  That file is the 
14983 \series bold 
14984 pic18fregs.h
14985 \series default 
14986 .
14987  This header file contains the definitions for the processor special registers,
14988  so it is necessery if the soruce accesses them.
14989  It can be included by adding the following line in the beginning of the
14990  file:
14991 \layout LyX-Code
14992
14993 #include <pic18fregs.h>
14994 \layout Standard
14995
14996 The specific microcontroller is selected within the pic18fregs.h automatically,
14997  so the same source can be used with a variety of devices.
14998 \layout Subsection
14999
15000 Libraries
15001 \layout Standard
15002
15003 The libraries that pic16 port depends on are the microcontroller device
15004  libraries which contain the symbol definitions for the microcontroller
15005  special function registers.
15006  These libraries have the format pic18fxxxx.lib, where 
15007 \emph on 
15008 xxxx
15009 \emph default 
15010  is the microcontroller identification number.
15011  The specific library is selected automatically by the compiler at link
15012  stage according to the selected device.
15013 \layout Standard
15014
15015 Libraries are created with gplib which is part of the gputils package 
15016 \begin_inset LatexCommand \url{http://gputils.sourceforge.net}
15017
15018 \end_inset 
15019
15020 .
15021 \layout Subsection
15022
15023 Memory Models
15024 \layout Standard
15025
15026 The following memory models are supported by PIC16 port:
15027 \layout Itemize
15028
15029 small model
15030 \layout Itemize
15031
15032 large model
15033 \layout Subsection
15034
15035 Stack
15036 \layout Standard
15037
15038 The stack implementation for the PIC16 port uses two indirect registers,
15039  FSR1 and FSR2.
15040 \layout List
15041 \labelwidthstring 00.00.0000
15042
15043 FSR1 is assigned as stack pointer
15044 \layout List
15045 \labelwidthstring 00.00.0000
15046
15047 FSR2 is assigned as frame pointer
15048 \layout Standard
15049
15050 The following stack models are supported by PIC16 port
15051 \layout Itemize
15052
15053 small model
15054 \layout Itemize
15055
15056 large model
15057 \layout Standard
15058
15059
15060 \noun on 
15061 Small
15062 \noun default 
15063  model means that only the FSRxL byte is used to access stack and frame,
15064  while 
15065 \emph on 
15066 \noun on 
15067 large
15068 \emph default 
15069 \noun default 
15070  uses both FSRxL and FSRxH registers.
15071  The following table shows the stack/frame pointers sizes according to stack
15072  model and the maximum space they can address:
15073 \layout Standard
15074 \align center 
15075
15076 \begin_inset  Tabular
15077 <lyxtabular version="3" rows="3" columns="3">
15078 <features>
15079 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15080 <column alignment="center" valignment="top" leftline="true" width="0">
15081 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15082 <row topline="true" bottomline="true">
15083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15084 \begin_inset Text
15085
15086 \layout Standard
15087
15088 Stack & Frame pointer sizes according to stack model
15089 \end_inset 
15090 </cell>
15091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15092 \begin_inset Text
15093
15094 \layout Standard
15095
15096 small
15097 \end_inset 
15098 </cell>
15099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15100 \begin_inset Text
15101
15102 \layout Standard
15103
15104 large
15105 \end_inset 
15106 </cell>
15107 </row>
15108 <row topline="true">
15109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15110 \begin_inset Text
15111
15112 \layout Standard
15113
15114 Stack pointer FSR1
15115 \end_inset 
15116 </cell>
15117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15118 \begin_inset Text
15119
15120 \layout Standard
15121
15122 8-bits
15123 \end_inset 
15124 </cell>
15125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15126 \begin_inset Text
15127
15128 \layout Standard
15129
15130 16-bits
15131 \end_inset 
15132 </cell>
15133 </row>
15134 <row topline="true" bottomline="true">
15135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15136 \begin_inset Text
15137
15138 \layout Standard
15139
15140 Frame pointer FSR2
15141 \end_inset 
15142 </cell>
15143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15144 \begin_inset Text
15145
15146 \layout Standard
15147
15148 8-bits
15149 \end_inset 
15150 </cell>
15151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15152 \begin_inset Text
15153
15154 \layout Standard
15155
15156 16-bits
15157 \end_inset 
15158 </cell>
15159 </row>
15160 </lyxtabular>
15161
15162 \end_inset 
15163
15164
15165 \layout Subsection
15166
15167 Pointers
15168 \layout Standard
15169 \align center 
15170
15171 \begin_inset  Tabular
15172 <lyxtabular version="3" rows="3" columns="3">
15173 <features>
15174 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15175 <column alignment="center" valignment="top" leftline="true" width="0">
15176 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15177 <row topline="true" bottomline="true">
15178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15179 \begin_inset Text
15180
15181 \layout Standard
15182
15183 Pointer sizes according to memory model
15184 \end_inset 
15185 </cell>
15186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15187 \begin_inset Text
15188
15189 \layout Standard
15190
15191 small model
15192 \end_inset 
15193 </cell>
15194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15195 \begin_inset Text
15196
15197 \layout Standard
15198
15199 large model
15200 \end_inset 
15201 </cell>
15202 </row>
15203 <row topline="true" bottomline="true">
15204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15205 \begin_inset Text
15206
15207 \layout Standard
15208
15209 code pointers
15210 \end_inset 
15211 </cell>
15212 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15213 \begin_inset Text
15214
15215 \layout Standard
15216
15217 16-bits
15218 \end_inset 
15219 </cell>
15220 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15221 \begin_inset Text
15222
15223 \layout Standard
15224
15225 24-bits
15226 \end_inset 
15227 </cell>
15228 </row>
15229 <row topline="true" bottomline="true">
15230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15231 \begin_inset Text
15232
15233 \layout Standard
15234
15235 data pointers
15236 \end_inset 
15237 </cell>
15238 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
15239 \begin_inset Text
15240
15241 \layout Standard
15242
15243 16-bits
15244 \end_inset 
15245 </cell>
15246 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15247 \begin_inset Text
15248
15249 \layout Standard
15250
15251 24-bits
15252 \end_inset 
15253 </cell>
15254 </row>
15255 </lyxtabular>
15256
15257 \end_inset 
15258
15259
15260 \layout Chapter
15261
15262 Debugging with SDCDB
15263 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
15264
15265 \end_inset 
15266
15267
15268 \begin_inset LatexCommand \index{sdcdb (debugger)}
15269
15270 \end_inset 
15271
15272  
15273 \layout Standard
15274
15275 SDCC is distributed with a source level debugger
15276 \begin_inset LatexCommand \index{Debugger}
15277
15278 \end_inset 
15279
15280 .
15281  The debugger uses a command line interface, the command repertoire of the
15282  debugger has been kept as close to gdb
15283 \begin_inset LatexCommand \index{gdb}
15284
15285 \end_inset 
15286
15287  (the GNU debugger) as possible.
15288  The configuration and build process is part of the standard compiler installati
15289 on, which also builds and installs the debugger in the target directory
15290  specified during configuration.
15291  The debugger allows you debug BOTH at the C source and at the ASM source
15292  level.
15293  Sdcdb is available on Unix platforms only.
15294 \layout Section
15295
15296 Compiling for Debugging
15297 \layout Standard
15298
15299 The \SpecialChar \-
15300 \SpecialChar \-
15301 debug option must be specified for all files for which debug information
15302  is to be generated.
15303  The complier generates a .adb file for each of these files.
15304  The linker creates the .cdb
15305 \begin_inset LatexCommand \index{<file>.cdb}
15306
15307 \end_inset 
15308
15309  file from the .adb
15310 \begin_inset LatexCommand \index{<file>.adb}
15311
15312 \end_inset 
15313
15314  files and the address information.
15315  This .cdb is used by the debugger.
15316 \layout Section
15317
15318 How the Debugger Works
15319 \layout Standard
15320
15321 When the -
15322 \begin_inset ERT
15323 status Collapsed
15324
15325 \layout Standard
15326
15327 \backslash 
15328 /
15329 \end_inset 
15330
15331 -debug option is specified the compiler generates extra symbol information
15332  some of which are put into the assembler source and some are put into the
15333  .adb file.
15334   Then the linker creates the .cdb file from the individual .adb files with
15335  the address information for the symbols.
15336  The debugger reads the symbolic information generated by the compiler &
15337  the address information generated by the linker.
15338  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
15339  execution is controlled by the debugger.
15340  When a command is issued for the debugger, it translates it into appropriate
15341  commands for the simulator.
15342 \layout Section
15343
15344 Starting the Debugger
15345 \layout Standard
15346
15347 The debugger can be started using the following command line.
15348  (Assume the file you are debugging has the file name foo).
15349 \newline 
15350
15351 \newline 
15352
15353 \family sans 
15354 \series bold 
15355 sdcdb foo
15356 \newline 
15357
15358 \family default 
15359 \series default 
15360
15361 \newline 
15362 The debugger will look for the following files.
15363 \layout Itemize
15364
15365 foo.c - the source file.
15366 \layout Itemize
15367
15368 foo.cdb - the debugger symbol information file.
15369 \layout Itemize
15370
15371 foo.ihx - the Intel hex format
15372 \begin_inset LatexCommand \index{Intel hex format}
15373
15374 \end_inset 
15375
15376  object file.
15377 \layout Section
15378
15379 Command Line Options.
15380 \layout Itemize
15381
15382 -
15383 \begin_inset ERT
15384 status Collapsed
15385
15386 \layout Standard
15387
15388 \backslash 
15389 /
15390 \end_inset 
15391
15392 -directory=<source file directory> this option can used to specify the directory
15393  search list.
15394  The debugger will look into the directory list specified for source, cdb
15395  & ihx files.
15396  The items in the directory list must be separated by ':', e.g.
15397  if the source files can be in the directories /home/src1 and /home/src2,
15398  the -
15399 \begin_inset ERT
15400 status Collapsed
15401
15402 \layout Standard
15403
15404 \backslash 
15405 /
15406 \end_inset 
15407
15408 -directory option should be -
15409 \begin_inset ERT
15410 status Collapsed
15411
15412 \layout Standard
15413
15414 \backslash 
15415 /
15416 \end_inset 
15417
15418 -directory=/home/src1:/home/src2.
15419  Note there can be no spaces in the option.
15420  
15421 \layout Itemize
15422
15423 -cd <directory> - change to the <directory>.
15424 \layout Itemize
15425
15426 -fullname - used by GUI front ends.
15427 \layout Itemize
15428
15429 -cpu <cpu-type> - this argument is passed to the simulator please see the
15430  simulator docs for details.
15431 \layout Itemize
15432
15433 -X <Clock frequency > this options is passed to the simulator please see
15434  the simulator docs for details.
15435 \layout Itemize
15436
15437 -s <serial port file> passed to simulator see the simulator docs for details.
15438 \layout Itemize
15439
15440 -S <serial in,out> passed to simulator see the simulator docs for details.
15441 \layout Itemize
15442
15443 -k <port number> passed to simulator see the simulator docs for details.
15444 \layout Section
15445
15446 Debugger Commands.
15447 \layout Standard
15448
15449 As mentioned earlier the command interface for the debugger has been deliberatel
15450 y kept as close the GNU debugger gdb, as possible.
15451  This will help the integration with existing graphical user interfaces
15452  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
15453  If you use a graphical user interface for the debugger you can skip the
15454  next sections.
15455 \layout Subsubsection*
15456
15457 break [line | file:line | function | file:function]
15458 \layout Standard
15459
15460 Set breakpoint at specified line or function:
15461 \newline 
15462
15463 \newline 
15464
15465 \family sans 
15466 \series bold 
15467 sdcdb>break 100 
15468 \newline 
15469 sdcdb>break foo.c:100
15470 \newline 
15471 sdcdb>break funcfoo
15472 \newline 
15473 sdcdb>break foo.c:funcfoo
15474 \layout Subsubsection*
15475
15476 clear [line | file:line | function | file:function ]
15477 \layout Standard
15478
15479 Clear breakpoint at specified line or function:
15480 \newline 
15481
15482 \newline 
15483
15484 \family sans 
15485 \series bold 
15486 sdcdb>clear 100
15487 \newline 
15488 sdcdb>clear foo.c:100
15489 \newline 
15490 sdcdb>clear funcfoo
15491 \newline 
15492 sdcdb>clear foo.c:funcfoo
15493 \layout Subsubsection*
15494
15495 continue
15496 \layout Standard
15497
15498 Continue program being debugged, after breakpoint.
15499 \layout Subsubsection*
15500
15501 finish
15502 \layout Standard
15503
15504 Execute till the end of the current function.
15505 \layout Subsubsection*
15506
15507 delete [n]
15508 \layout Standard
15509
15510 Delete breakpoint number 'n'.
15511  If used without any option clear ALL user defined break points.
15512 \layout Subsubsection*
15513
15514 info [break | stack | frame | registers ]
15515 \layout Itemize
15516
15517 info break - list all breakpoints
15518 \layout Itemize
15519
15520 info stack - show the function call stack.
15521 \layout Itemize
15522
15523 info frame - show information about the current execution frame.
15524 \layout Itemize
15525
15526 info registers - show content of all registers.
15527 \layout Subsubsection*
15528
15529 step
15530 \layout Standard
15531
15532 Step program until it reaches a different source line.
15533  Note: pressing <return> repeats the last command.
15534 \layout Subsubsection*
15535
15536 next
15537 \layout Standard
15538
15539 Step program, proceeding through subroutine calls.
15540 \layout Subsubsection*
15541
15542 run
15543 \layout Standard
15544
15545 Start debugged program.
15546 \layout Subsubsection*
15547
15548 ptype variable 
15549 \layout Standard
15550
15551 Print type information of the variable.
15552 \layout Subsubsection*
15553
15554 print variable
15555 \layout Standard
15556
15557 print value of variable.
15558 \layout Subsubsection*
15559
15560 file filename
15561 \layout Standard
15562
15563 load the given file name.
15564  Note this is an alternate method of loading file for debugging.
15565 \layout Subsubsection*
15566
15567 frame
15568 \layout Standard
15569
15570 print information about current frame.
15571 \layout Subsubsection*
15572
15573 set srcmode
15574 \layout Standard
15575
15576 Toggle between C source & assembly source.
15577 \layout Subsubsection*
15578
15579 ! simulator command
15580 \layout Standard
15581
15582 Send the string following '!' to the simulator, the simulator response is
15583  displayed.
15584  Note the debugger does not interpret the command being sent to the simulator,
15585  so if a command like 'go' is sent the debugger can loose its execution
15586  context and may display incorrect values.
15587 \layout Subsubsection*
15588
15589 quit
15590 \layout Standard
15591
15592 "Watch me now.
15593  Iam going Down.
15594  My name is Bobby Brown"
15595 \layout Section
15596
15597 Interfacing with XEmacs
15598 \begin_inset LatexCommand \index{XEmacs}
15599
15600 \end_inset 
15601
15602
15603 \begin_inset LatexCommand \index{Emacs}
15604
15605 \end_inset 
15606
15607 .
15608 \layout Standard
15609
15610 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
15611  sdcdb.el and sdcdbsrc.el.
15612  These two files can be found in the $(prefix)/bin directory after the installat
15613 ion is complete.
15614  These files need to be loaded into XEmacs for the interface to work.
15615  This can be done at XEmacs startup time by inserting the following into
15616  your '.xemacs' file (which can be found in your HOME directory): 
15617 \newline 
15618
15619 \newline 
15620
15621 \family typewriter 
15622 (load-file sdcdbsrc.el) 
15623 \family default 
15624
15625 \newline 
15626
15627 \newline 
15628 .xemacs is a lisp file so the () around the command is REQUIRED.
15629  The files can also be loaded dynamically while XEmacs is running, set the
15630  environment variable 'EMACSLOADPATH' to the installation bin directory
15631  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
15632  To start the interface enter the following command: 
15633 \newline 
15634
15635 \newline 
15636
15637 \family sans 
15638 \series bold 
15639 ESC-x sdcdbsrc
15640 \family default 
15641 \series default 
15642
15643 \newline 
15644
15645 \newline 
15646 You will prompted to enter the file name to be debugged.
15647  
15648 \newline 
15649
15650 \newline 
15651 The command line options that are passed to the simulator directly are bound
15652  to default values in the file sdcdbsrc.el.
15653  The variables are listed below, these values maybe changed as required.
15654 \layout Itemize
15655
15656 sdcdbsrc-cpu-type '51
15657 \layout Itemize
15658
15659 sdcdbsrc-frequency '11059200
15660 \layout Itemize
15661
15662 sdcdbsrc-serial nil
15663 \layout Standard
15664
15665 The following is a list of key mapping for the debugger interface.
15666 \layout Standard
15667
15668 \SpecialChar ~
15669
15670 \family typewriter 
15671
15672 \newline 
15673 ;; Current Listing :: 
15674 \newline 
15675 ;;key\SpecialChar ~
15676 \SpecialChar ~
15677 \SpecialChar ~
15678 \SpecialChar ~
15679 \SpecialChar ~
15680 \SpecialChar ~
15681 \SpecialChar ~
15682 \SpecialChar ~
15683 \SpecialChar ~
15684 \SpecialChar ~
15685 \SpecialChar ~
15686 \SpecialChar ~
15687 \SpecialChar ~
15688 \SpecialChar ~
15689 \SpecialChar ~
15690 binding\SpecialChar ~
15691 \SpecialChar ~
15692 \SpecialChar ~
15693 \SpecialChar ~
15694 \SpecialChar ~
15695 \SpecialChar ~
15696 \SpecialChar ~
15697 \SpecialChar ~
15698 \SpecialChar ~
15699 \SpecialChar ~
15700 \SpecialChar ~
15701 \SpecialChar ~
15702 \SpecialChar ~
15703 \SpecialChar ~
15704 \SpecialChar ~
15705 \SpecialChar ~
15706 \SpecialChar ~
15707 \SpecialChar ~
15708 \SpecialChar ~
15709 \SpecialChar ~
15710 \SpecialChar ~
15711 \SpecialChar ~
15712 Comment 
15713 \newline 
15714 ;;---\SpecialChar ~
15715 \SpecialChar ~
15716 \SpecialChar ~
15717 \SpecialChar ~
15718 \SpecialChar ~
15719 \SpecialChar ~
15720 \SpecialChar ~
15721 \SpecialChar ~
15722 \SpecialChar ~
15723 \SpecialChar ~
15724 \SpecialChar ~
15725 \SpecialChar ~
15726 \SpecialChar ~
15727 \SpecialChar ~
15728 \SpecialChar ~
15729 ------\SpecialChar ~
15730 \SpecialChar ~
15731 \SpecialChar ~
15732 \SpecialChar ~
15733 \SpecialChar ~
15734 \SpecialChar ~
15735 \SpecialChar ~
15736 \SpecialChar ~
15737 \SpecialChar ~
15738 \SpecialChar ~
15739 \SpecialChar ~
15740 \SpecialChar ~
15741 \SpecialChar ~
15742 \SpecialChar ~
15743 \SpecialChar ~
15744 \SpecialChar ~
15745 \SpecialChar ~
15746 \SpecialChar ~
15747 \SpecialChar ~
15748 \SpecialChar ~
15749 \SpecialChar ~
15750 \SpecialChar ~
15751 --------
15752 \newline 
15753 ;; 
15754 \newline 
15755 ;; n\SpecialChar ~
15756 \SpecialChar ~
15757 \SpecialChar ~
15758 \SpecialChar ~
15759 \SpecialChar ~
15760 \SpecialChar ~
15761 \SpecialChar ~
15762 \SpecialChar ~
15763 \SpecialChar ~
15764 \SpecialChar ~
15765 \SpecialChar ~
15766 \SpecialChar ~
15767 \SpecialChar ~
15768 \SpecialChar ~
15769  sdcdb-next-from-src\SpecialChar ~
15770 \SpecialChar ~
15771 \SpecialChar ~
15772 \SpecialChar ~
15773 \SpecialChar ~
15774 \SpecialChar ~
15775 \SpecialChar ~
15776 \SpecialChar ~
15777 \SpecialChar ~
15778 \SpecialChar ~
15779 SDCDB next command 
15780 \newline 
15781 ;; b\SpecialChar ~
15782 \SpecialChar ~
15783 \SpecialChar ~
15784 \SpecialChar ~
15785 \SpecialChar ~
15786 \SpecialChar ~
15787 \SpecialChar ~
15788 \SpecialChar ~
15789 \SpecialChar ~
15790 \SpecialChar ~
15791 \SpecialChar ~
15792 \SpecialChar ~
15793 \SpecialChar ~
15794 \SpecialChar ~
15795  sdcdb-back-from-src\SpecialChar ~
15796 \SpecialChar ~
15797 \SpecialChar ~
15798 \SpecialChar ~
15799 \SpecialChar ~
15800 \SpecialChar ~
15801 \SpecialChar ~
15802 \SpecialChar ~
15803 \SpecialChar ~
15804 \SpecialChar ~
15805 SDCDB back command 
15806 \newline 
15807 ;; c\SpecialChar ~
15808 \SpecialChar ~
15809 \SpecialChar ~
15810 \SpecialChar ~
15811 \SpecialChar ~
15812 \SpecialChar ~
15813 \SpecialChar ~
15814 \SpecialChar ~
15815 \SpecialChar ~
15816 \SpecialChar ~
15817 \SpecialChar ~
15818 \SpecialChar ~
15819 \SpecialChar ~
15820 \SpecialChar ~
15821  sdcdb-cont-from-src\SpecialChar ~
15822 \SpecialChar ~
15823 \SpecialChar ~
15824 \SpecialChar ~
15825 \SpecialChar ~
15826 \SpecialChar ~
15827 \SpecialChar ~
15828 \SpecialChar ~
15829 \SpecialChar ~
15830 \SpecialChar ~
15831 SDCDB continue command
15832 \newline 
15833 ;; s\SpecialChar ~
15834 \SpecialChar ~
15835 \SpecialChar ~
15836 \SpecialChar ~
15837 \SpecialChar ~
15838 \SpecialChar ~
15839 \SpecialChar ~
15840 \SpecialChar ~
15841 \SpecialChar ~
15842 \SpecialChar ~
15843 \SpecialChar ~
15844 \SpecialChar ~
15845 \SpecialChar ~
15846 \SpecialChar ~
15847  sdcdb-step-from-src\SpecialChar ~
15848 \SpecialChar ~
15849 \SpecialChar ~
15850 \SpecialChar ~
15851 \SpecialChar ~
15852 \SpecialChar ~
15853 \SpecialChar ~
15854 \SpecialChar ~
15855 \SpecialChar ~
15856 \SpecialChar ~
15857 SDCDB step command 
15858 \newline 
15859 ;; ?\SpecialChar ~
15860 \SpecialChar ~
15861 \SpecialChar ~
15862 \SpecialChar ~
15863 \SpecialChar ~
15864 \SpecialChar ~
15865 \SpecialChar ~
15866 \SpecialChar ~
15867 \SpecialChar ~
15868 \SpecialChar ~
15869 \SpecialChar ~
15870 \SpecialChar ~
15871 \SpecialChar ~
15872 \SpecialChar ~
15873  sdcdb-whatis-c-sexp\SpecialChar ~
15874 \SpecialChar ~
15875 \SpecialChar ~
15876 \SpecialChar ~
15877 \SpecialChar ~
15878 \SpecialChar ~
15879 \SpecialChar ~
15880 \SpecialChar ~
15881 \SpecialChar ~
15882 \SpecialChar ~
15883 SDCDB ptypecommand for data at 
15884 \newline 
15885 ;;\SpecialChar ~
15886 \SpecialChar ~
15887 \SpecialChar ~
15888 \SpecialChar ~
15889 \SpecialChar ~
15890 \SpecialChar ~
15891 \SpecialChar ~
15892 \SpecialChar ~
15893 \SpecialChar ~
15894 \SpecialChar ~
15895 \SpecialChar ~
15896 \SpecialChar ~
15897 \SpecialChar ~
15898 \SpecialChar ~
15899 \SpecialChar ~
15900 \SpecialChar ~
15901 \SpecialChar ~
15902 \SpecialChar ~
15903 \SpecialChar ~
15904 \SpecialChar ~
15905 \SpecialChar ~
15906 \SpecialChar ~
15907 \SpecialChar ~
15908 \SpecialChar ~
15909 \SpecialChar ~
15910 \SpecialChar ~
15911 \SpecialChar ~
15912 \SpecialChar ~
15913 \SpecialChar ~
15914 \SpecialChar ~
15915 \SpecialChar ~
15916 \SpecialChar ~
15917 \SpecialChar ~
15918 \SpecialChar ~
15919 \SpecialChar ~
15920 \SpecialChar ~
15921 \SpecialChar ~
15922 \SpecialChar ~
15923 \SpecialChar ~
15924 \SpecialChar ~
15925 \SpecialChar ~
15926 \SpecialChar ~
15927 \SpecialChar ~
15928 \SpecialChar ~
15929 \SpecialChar ~
15930 \SpecialChar ~
15931  buffer point 
15932 \newline 
15933 ;; x\SpecialChar ~
15934 \SpecialChar ~
15935 \SpecialChar ~
15936 \SpecialChar ~
15937 \SpecialChar ~
15938 \SpecialChar ~
15939 \SpecialChar ~
15940 \SpecialChar ~
15941 \SpecialChar ~
15942 \SpecialChar ~
15943 \SpecialChar ~
15944 \SpecialChar ~
15945 \SpecialChar ~
15946 \SpecialChar ~
15947  sdcdbsrc-delete\SpecialChar ~
15948 \SpecialChar ~
15949 \SpecialChar ~
15950 \SpecialChar ~
15951 \SpecialChar ~
15952 \SpecialChar ~
15953 \SpecialChar ~
15954 \SpecialChar ~
15955 \SpecialChar ~
15956 \SpecialChar ~
15957 \SpecialChar ~
15958 \SpecialChar ~
15959 \SpecialChar ~
15960 \SpecialChar ~
15961 SDCDB Delete all breakpoints if no arg 
15962 \newline 
15963 ;;\SpecialChar ~
15964 \SpecialChar ~
15965 \SpecialChar ~
15966 \SpecialChar ~
15967 \SpecialChar ~
15968 \SpecialChar ~
15969 \SpecialChar ~
15970 \SpecialChar ~
15971 \SpecialChar ~
15972 \SpecialChar ~
15973 \SpecialChar ~
15974 \SpecialChar ~
15975 \SpecialChar ~
15976 \SpecialChar ~
15977 \SpecialChar ~
15978 \SpecialChar ~
15979 \SpecialChar ~
15980 \SpecialChar ~
15981 \SpecialChar ~
15982 \SpecialChar ~
15983 \SpecialChar ~
15984 \SpecialChar ~
15985 \SpecialChar ~
15986 \SpecialChar ~
15987 \SpecialChar ~
15988 \SpecialChar ~
15989 \SpecialChar ~
15990 \SpecialChar ~
15991 \SpecialChar ~
15992 \SpecialChar ~
15993 \SpecialChar ~
15994 \SpecialChar ~
15995 \SpecialChar ~
15996 \SpecialChar ~
15997 \SpecialChar ~
15998 \SpecialChar ~
15999 \SpecialChar ~
16000 \SpecialChar ~
16001 \SpecialChar ~
16002 \SpecialChar ~
16003 \SpecialChar ~
16004 \SpecialChar ~
16005 \SpecialChar ~
16006 \SpecialChar ~
16007 \SpecialChar ~
16008 \SpecialChar ~
16009 given or delete arg (C-u arg x) 
16010 \newline 
16011 ;; m\SpecialChar ~
16012 \SpecialChar ~
16013 \SpecialChar ~
16014 \SpecialChar ~
16015 \SpecialChar ~
16016 \SpecialChar ~
16017 \SpecialChar ~
16018 \SpecialChar ~
16019 \SpecialChar ~
16020 \SpecialChar ~
16021 \SpecialChar ~
16022 \SpecialChar ~
16023 \SpecialChar ~
16024 \SpecialChar ~
16025  sdcdbsrc-frame\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 SDCDB Display current frame if no arg, 
16041 \newline 
16042 ;;\SpecialChar ~
16043 \SpecialChar ~
16044 \SpecialChar ~
16045 \SpecialChar ~
16046 \SpecialChar ~
16047 \SpecialChar ~
16048 \SpecialChar ~
16049 \SpecialChar ~
16050 \SpecialChar ~
16051 \SpecialChar ~
16052 \SpecialChar ~
16053 \SpecialChar ~
16054 \SpecialChar ~
16055 \SpecialChar ~
16056 \SpecialChar ~
16057 \SpecialChar ~
16058 \SpecialChar ~
16059 \SpecialChar ~
16060 \SpecialChar ~
16061 \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 \SpecialChar ~
16076 \SpecialChar ~
16077 \SpecialChar ~
16078 \SpecialChar ~
16079 \SpecialChar ~
16080 \SpecialChar ~
16081 \SpecialChar ~
16082 \SpecialChar ~
16083 \SpecialChar ~
16084 \SpecialChar ~
16085 \SpecialChar ~
16086 \SpecialChar ~
16087 \SpecialChar ~
16088 \SpecialChar ~
16089 given or display frame arg 
16090 \newline 
16091 ;;\SpecialChar ~
16092 \SpecialChar ~
16093 \SpecialChar ~
16094 \SpecialChar ~
16095 \SpecialChar ~
16096 \SpecialChar ~
16097 \SpecialChar ~
16098 \SpecialChar ~
16099 \SpecialChar ~
16100 \SpecialChar ~
16101 \SpecialChar ~
16102 \SpecialChar ~
16103 \SpecialChar ~
16104 \SpecialChar ~
16105 \SpecialChar ~
16106 \SpecialChar ~
16107 \SpecialChar ~
16108 \SpecialChar ~
16109 \SpecialChar ~
16110 \SpecialChar ~
16111 \SpecialChar ~
16112 \SpecialChar ~
16113 \SpecialChar ~
16114 \SpecialChar ~
16115 \SpecialChar ~
16116 \SpecialChar ~
16117 \SpecialChar ~
16118 \SpecialChar ~
16119 \SpecialChar ~
16120 \SpecialChar ~
16121 \SpecialChar ~
16122 \SpecialChar ~
16123 \SpecialChar ~
16124 \SpecialChar ~
16125 \SpecialChar ~
16126 \SpecialChar ~
16127 \SpecialChar ~
16128 \SpecialChar ~
16129 \SpecialChar ~
16130 \SpecialChar ~
16131 \SpecialChar ~
16132 \SpecialChar ~
16133 \SpecialChar ~
16134 \SpecialChar ~
16135 \SpecialChar ~
16136 \SpecialChar ~
16137 \SpecialChar ~
16138 buffer point 
16139 \newline 
16140 ;; !\SpecialChar ~
16141 \SpecialChar ~
16142 \SpecialChar ~
16143 \SpecialChar ~
16144 \SpecialChar ~
16145 \SpecialChar ~
16146 \SpecialChar ~
16147 \SpecialChar ~
16148 \SpecialChar ~
16149 \SpecialChar ~
16150 \SpecialChar ~
16151 \SpecialChar ~
16152 \SpecialChar ~
16153 \SpecialChar ~
16154  sdcdbsrc-goto-sdcdb\SpecialChar ~
16155 \SpecialChar ~
16156 \SpecialChar ~
16157 \SpecialChar ~
16158 \SpecialChar ~
16159 \SpecialChar ~
16160 \SpecialChar ~
16161 \SpecialChar ~
16162 \SpecialChar ~
16163 \SpecialChar ~
16164 Goto the SDCDB output buffer 
16165 \newline 
16166 ;; p\SpecialChar ~
16167 \SpecialChar ~
16168 \SpecialChar ~
16169 \SpecialChar ~
16170 \SpecialChar ~
16171 \SpecialChar ~
16172 \SpecialChar ~
16173 \SpecialChar ~
16174 \SpecialChar ~
16175 \SpecialChar ~
16176 \SpecialChar ~
16177 \SpecialChar ~
16178 \SpecialChar ~
16179 \SpecialChar ~
16180  sdcdb-print-c-sexp\SpecialChar ~
16181 \SpecialChar ~
16182 \SpecialChar ~
16183 \SpecialChar ~
16184 \SpecialChar ~
16185 \SpecialChar ~
16186 \SpecialChar ~
16187 \SpecialChar ~
16188 \SpecialChar ~
16189 \SpecialChar ~
16190 \SpecialChar ~
16191 SDCDB print command for data at 
16192 \newline 
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 \SpecialChar ~
16238 \SpecialChar ~
16239  buffer point 
16240 \newline 
16241 ;; g\SpecialChar ~
16242 \SpecialChar ~
16243 \SpecialChar ~
16244 \SpecialChar ~
16245 \SpecialChar ~
16246 \SpecialChar ~
16247 \SpecialChar ~
16248 \SpecialChar ~
16249 \SpecialChar ~
16250 \SpecialChar ~
16251 \SpecialChar ~
16252 \SpecialChar ~
16253 \SpecialChar ~
16254 \SpecialChar ~
16255  sdcdbsrc-goto-sdcdb\SpecialChar ~
16256 \SpecialChar ~
16257 \SpecialChar ~
16258 \SpecialChar ~
16259 \SpecialChar ~
16260 \SpecialChar ~
16261 \SpecialChar ~
16262 \SpecialChar ~
16263 \SpecialChar ~
16264 \SpecialChar ~
16265 Goto the SDCDB output buffer 
16266 \newline 
16267 ;; t\SpecialChar ~
16268 \SpecialChar ~
16269 \SpecialChar ~
16270 \SpecialChar ~
16271 \SpecialChar ~
16272 \SpecialChar ~
16273 \SpecialChar ~
16274 \SpecialChar ~
16275 \SpecialChar ~
16276 \SpecialChar ~
16277 \SpecialChar ~
16278 \SpecialChar ~
16279 \SpecialChar ~
16280 \SpecialChar ~
16281  sdcdbsrc-mode\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 Toggles Sdcdbsrc mode (turns it off) 
16298 \newline 
16299 ;; 
16300 \newline 
16301 ;; C-c C-f\SpecialChar ~
16302 \SpecialChar ~
16303 \SpecialChar ~
16304 \SpecialChar ~
16305 \SpecialChar ~
16306 \SpecialChar ~
16307 \SpecialChar ~
16308 \SpecialChar ~
16309  sdcdb-finish-from-src\SpecialChar ~
16310 \SpecialChar ~
16311 \SpecialChar ~
16312 \SpecialChar ~
16313 \SpecialChar ~
16314 \SpecialChar ~
16315 \SpecialChar ~
16316 \SpecialChar ~
16317 SDCDB finish command 
16318 \newline 
16319 ;; 
16320 \newline 
16321 ;; C-x SPC\SpecialChar ~
16322 \SpecialChar ~
16323 \SpecialChar ~
16324 \SpecialChar ~
16325 \SpecialChar ~
16326 \SpecialChar ~
16327 \SpecialChar ~
16328 \SpecialChar ~
16329  sdcdb-break\SpecialChar ~
16330 \SpecialChar ~
16331 \SpecialChar ~
16332 \SpecialChar ~
16333 \SpecialChar ~
16334 \SpecialChar ~
16335 \SpecialChar ~
16336 \SpecialChar ~
16337 \SpecialChar ~
16338 \SpecialChar ~
16339 \SpecialChar ~
16340 \SpecialChar ~
16341 \SpecialChar ~
16342 \SpecialChar ~
16343 \SpecialChar ~
16344 \SpecialChar ~
16345 \SpecialChar ~
16346 \SpecialChar ~
16347 Set break for line with point 
16348 \newline 
16349 ;; ESC t\SpecialChar ~
16350 \SpecialChar ~
16351 \SpecialChar ~
16352 \SpecialChar ~
16353 \SpecialChar ~
16354 \SpecialChar ~
16355 \SpecialChar ~
16356 \SpecialChar ~
16357 \SpecialChar ~
16358 \SpecialChar ~
16359  sdcdbsrc-mode\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 Toggle Sdcdbsrc mode 
16376 \newline 
16377 ;; ESC m\SpecialChar ~
16378 \SpecialChar ~
16379 \SpecialChar ~
16380 \SpecialChar ~
16381 \SpecialChar ~
16382 \SpecialChar ~
16383 \SpecialChar ~
16384 \SpecialChar ~
16385 \SpecialChar ~
16386 \SpecialChar ~
16387  sdcdbsrc-srcmode\SpecialChar ~
16388 \SpecialChar ~
16389 \SpecialChar ~
16390 \SpecialChar ~
16391 \SpecialChar ~
16392 \SpecialChar ~
16393 \SpecialChar ~
16394 \SpecialChar ~
16395 \SpecialChar ~
16396 \SpecialChar ~
16397 \SpecialChar ~
16398 \SpecialChar ~
16399  Toggle list mode 
16400 \newline 
16401 ;; 
16402 \newline 
16403
16404 \layout Chapter
16405 \pagebreak_top 
16406 TIPS
16407 \layout Standard
16408
16409 Here are a few guidelines that will help the compiler generate more efficient
16410  code, some of the tips are specific to this compiler others are generally
16411  good programming practice.
16412 \layout Itemize
16413
16414 Use the smallest data type to represent your data-value.
16415  If it is known in advance that the value is going to be less than 256 then
16416  use an 'unsigned char' instead of a 'short' or 'int'.
16417  Please note, that ANSI C requires both signed and unsigned chars to be
16418  promoted to 'signed int' before doing any operation.
16419  This promotion can be omitted, if the result is the same.
16420  The effect of the promotion rules together with the sign-extension is often
16421  supprising:
16422 \begin_deeper 
16423 \layout Verse
16424
16425
16426 \family typewriter 
16427 unsigned char uc = 0xfe;
16428 \newline 
16429 if (uc * uc < 0) /* this is true! */
16430 \newline 
16431 {
16432 \newline 
16433 \SpecialChar ~
16434 \SpecialChar ~
16435 \SpecialChar ~
16436 \SpecialChar ~
16437 ....
16438 \newline 
16439 }
16440 \layout Standard
16441
16442
16443 \family typewriter 
16444 uc * uc
16445 \family default 
16446  is evaluated as 
16447 \family typewriter 
16448 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
16449 \family default 
16450 .
16451  
16452 \newline 
16453 Another one:
16454 \layout Verse
16455
16456
16457 \family typewriter 
16458 (unsigned char) -12 / (signed char) -3 = ...
16459 \layout Standard
16460
16461 No, the result is not 4:
16462 \layout Verse
16463
16464
16465 \family typewriter 
16466 (int) (unsigned char) -12 / (int) (signed char) -3 =
16467 \newline 
16468 (int) (unsigned char) 0xf4 / (int) (signed char) 0xfd =
16469 \newline 
16470 (int) 0x00f4 / (int) 0xfffd =
16471 \newline 
16472 (int) 0x00f4 / (int) 0xfffd =
16473 \newline 
16474 (int) 244 / (int) -3 =
16475 \newline 
16476 (int) -81 = (int) 0xffaf;
16477 \layout Standard
16478
16479 Don't complain, that gcc gives you a different result.
16480  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
16481  Therefore the results are different.
16482 \newline 
16483 From 
16484 \begin_inset Quotes sld
16485 \end_inset 
16486
16487 comp.lang.c FAQ
16488 \begin_inset Quotes srd
16489 \end_inset 
16490
16491 :
16492 \layout Quote
16493
16494 If well-defined overflow characteristics are important and negative values
16495  are not, or if you want to steer clear of sign-extension problems when
16496  manipulating bits or bytes, use one of the corresponding unsigned types.
16497  (Beware when mixing signed and unsigned values in expressions, though.)
16498 \newline 
16499 Although character types (especially unsigned char) can be used as "tiny"
16500  integers, doing so is sometimes more trouble than it's worth, due to unpredicta
16501 ble sign extension and increased code size.
16502 \end_deeper 
16503 \layout Itemize
16504
16505 Use unsigned when it is known in advance that the value is not going to
16506  be negative.
16507  This helps especially if you are doing division or multiplication, bit-shifting
16508  or are using an array index.
16509 \layout Itemize
16510
16511 NEVER jump into a LOOP.
16512 \layout Itemize
16513
16514 Declare the variables to be local
16515 \begin_inset LatexCommand \index{local variables}
16516
16517 \end_inset 
16518
16519  whenever possible, especially loop control variables (induction).
16520 \layout Itemize
16521
16522 Since the compiler does not always do implicit integral promotion, the programme
16523 r should do an explicit cast when integral promotion is required.
16524 \layout Itemize
16525
16526 Reducing the size of division, multiplication & modulus operations can reduce
16527  code size substantially.
16528  Take the following code for example.
16529 \begin_deeper 
16530 \layout Verse
16531
16532
16533 \family typewriter 
16534 foobar(unsigned int p1, unsigned char ch)
16535 \newline 
16536 {
16537 \newline 
16538 \SpecialChar ~
16539 \SpecialChar ~
16540 \SpecialChar ~
16541 \SpecialChar ~
16542 unsigned char ch1 = p1 % ch ;
16543 \newline 
16544 \SpecialChar ~
16545 \SpecialChar ~
16546 \SpecialChar ~
16547 \SpecialChar ~
16548 ....
16549 \newline 
16550 }
16551 \layout Standard
16552
16553 For the modulus operation the variable ch will be promoted to unsigned int
16554  first then the modulus operation will be performed (this will lead to a
16555  call to support routine _moduint()), and the result will be casted to a
16556  char.
16557  If the code is changed to 
16558 \layout Verse
16559
16560
16561 \family typewriter 
16562 foobar(unsigned int p1, unsigned char ch)
16563 \newline 
16564 {
16565 \newline 
16566 \SpecialChar ~
16567 \SpecialChar ~
16568 \SpecialChar ~
16569 \SpecialChar ~
16570 unsigned char ch1 = (unsigned char)p1 % ch ;
16571 \newline 
16572 \SpecialChar ~
16573 \SpecialChar ~
16574 \SpecialChar ~
16575 \SpecialChar ~
16576 ....
16577 \newline 
16578 }
16579 \layout Standard
16580
16581 It would substantially reduce the code generated (future versions of the
16582  compiler will be smart enough to detect such optimization opportunities).
16583 \end_deeper 
16584 \layout Itemize
16585
16586 Have a look at the assembly listing to get a 
16587 \begin_inset Quotes sld
16588 \end_inset 
16589
16590 feeling
16591 \begin_inset Quotes srd
16592 \end_inset 
16593
16594  for the code generation.
16595 \layout Section
16596
16597 Tools
16598 \begin_inset LatexCommand \index{Tools}
16599
16600 \end_inset 
16601
16602  included in the distribution
16603 \layout Standard
16604 \align center 
16605
16606 \begin_inset  Tabular
16607 <lyxtabular version="3" rows="12" columns="3">
16608 <features>
16609 <column alignment="center" valignment="top" leftline="true" width="0pt">
16610 <column alignment="center" valignment="top" leftline="true" width="0pt">
16611 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
16612 <row topline="true" bottomline="true">
16613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16614 \begin_inset Text
16615
16616 \layout Standard
16617
16618 Name
16619 \end_inset 
16620 </cell>
16621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16622 \begin_inset Text
16623
16624 \layout Standard
16625
16626 Purpose
16627 \end_inset 
16628 </cell>
16629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16630 \begin_inset Text
16631
16632 \layout Standard
16633
16634 Directory
16635 \end_inset 
16636 </cell>
16637 </row>
16638 <row topline="true">
16639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16640 \begin_inset Text
16641
16642 \layout Standard
16643
16644 uCsim
16645 \end_inset 
16646 </cell>
16647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16648 \begin_inset Text
16649
16650 \layout Standard
16651
16652 Simulator for various architectures
16653 \end_inset 
16654 </cell>
16655 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16656 \begin_inset Text
16657
16658 \layout Standard
16659
16660 sdcc/sim/ucsim
16661 \end_inset 
16662 </cell>
16663 </row>
16664 <row topline="true">
16665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16666 \begin_inset Text
16667
16668 \layout Standard
16669
16670 keil2sdcc.pl
16671 \end_inset 
16672 </cell>
16673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16674 \begin_inset Text
16675
16676 \layout Standard
16677
16678 header file conversion
16679 \end_inset 
16680 </cell>
16681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16682 \begin_inset Text
16683
16684 \layout Standard
16685
16686 sdcc/support/scripts
16687 \end_inset 
16688 </cell>
16689 </row>
16690 <row topline="true">
16691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16692 \begin_inset Text
16693
16694 \layout Standard
16695
16696 mh2h.c
16697 \end_inset 
16698 </cell>
16699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16700 \begin_inset Text
16701
16702 \layout Standard
16703
16704 header file conversion
16705 \end_inset 
16706 </cell>
16707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16708 \begin_inset Text
16709
16710 \layout Standard
16711
16712 sdcc/support/scripts
16713 \end_inset 
16714 </cell>
16715 </row>
16716 <row topline="true">
16717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16718 \begin_inset Text
16719
16720 \layout Standard
16721
16722 as-gbz80
16723 \end_inset 
16724 </cell>
16725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16726 \begin_inset Text
16727
16728 \layout Standard
16729
16730 Assembler
16731 \end_inset 
16732 </cell>
16733 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16734 \begin_inset Text
16735
16736 \layout Standard
16737
16738
16739 \family roman 
16740 \series medium 
16741 \shape up 
16742 \size normal 
16743 \emph off 
16744 \bar no 
16745 \noun off 
16746 \color none
16747 sdcc/bin
16748 \end_inset 
16749 </cell>
16750 </row>
16751 <row topline="true">
16752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16753 \begin_inset Text
16754
16755 \layout Standard
16756
16757 as-z80
16758 \end_inset 
16759 </cell>
16760 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16761 \begin_inset Text
16762
16763 \layout Standard
16764
16765 Assembler
16766 \end_inset 
16767 </cell>
16768 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16769 \begin_inset Text
16770
16771 \layout Standard
16772
16773
16774 \family roman 
16775 \series medium 
16776 \shape up 
16777 \size normal 
16778 \emph off 
16779 \bar no 
16780 \noun off 
16781 \color none
16782 sdcc/bin
16783 \end_inset 
16784 </cell>
16785 </row>
16786 <row topline="true">
16787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16788 \begin_inset Text
16789
16790 \layout Standard
16791
16792 asx8051
16793 \end_inset 
16794 </cell>
16795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16796 \begin_inset Text
16797
16798 \layout Standard
16799
16800 Assembler
16801 \end_inset 
16802 </cell>
16803 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16804 \begin_inset Text
16805
16806 \layout Standard
16807
16808
16809 \family roman 
16810 \series medium 
16811 \shape up 
16812 \size normal 
16813 \emph off 
16814 \bar no 
16815 \noun off 
16816 \color none
16817 sdcc/bin
16818 \end_inset 
16819 </cell>
16820 </row>
16821 <row topline="true">
16822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16823 \begin_inset Text
16824
16825 \layout Standard
16826
16827 sdcdb
16828 \end_inset 
16829 </cell>
16830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16831 \begin_inset Text
16832
16833 \layout Standard
16834
16835 Simulator
16836 \end_inset 
16837 </cell>
16838 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16839 \begin_inset Text
16840
16841 \layout Standard
16842
16843
16844 \family roman 
16845 \series medium 
16846 \shape up 
16847 \size normal 
16848 \emph off 
16849 \bar no 
16850 \noun off 
16851 \color none
16852 sdcc/bin
16853 \end_inset 
16854 </cell>
16855 </row>
16856 <row topline="true">
16857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16858 \begin_inset Text
16859
16860 \layout Standard
16861
16862 aslink
16863 \end_inset 
16864 </cell>
16865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16866 \begin_inset Text
16867
16868 \layout Standard
16869
16870 Linker
16871 \end_inset 
16872 </cell>
16873 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16874 \begin_inset Text
16875
16876 \layout Standard
16877
16878
16879 \family roman 
16880 \series medium 
16881 \shape up 
16882 \size normal 
16883 \emph off 
16884 \bar no 
16885 \noun off 
16886 \color none
16887 sdcc/bin
16888 \end_inset 
16889 </cell>
16890 </row>
16891 <row topline="true">
16892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16893 \begin_inset Text
16894
16895 \layout Standard
16896
16897 link-z80
16898 \end_inset 
16899 </cell>
16900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16901 \begin_inset Text
16902
16903 \layout Standard
16904
16905 Linker
16906 \end_inset 
16907 </cell>
16908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16909 \begin_inset Text
16910
16911 \layout Standard
16912
16913
16914 \family roman 
16915 \series medium 
16916 \shape up 
16917 \size normal 
16918 \emph off 
16919 \bar no 
16920 \noun off 
16921 \color none
16922 sdcc/bin
16923 \end_inset 
16924 </cell>
16925 </row>
16926 <row topline="true">
16927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16928 \begin_inset Text
16929
16930 \layout Standard
16931
16932 link-gbz80
16933 \end_inset 
16934 </cell>
16935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16936 \begin_inset Text
16937
16938 \layout Standard
16939
16940 Linker
16941 \end_inset 
16942 </cell>
16943 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16944 \begin_inset Text
16945
16946 \layout Standard
16947
16948
16949 \family roman 
16950 \series medium 
16951 \shape up 
16952 \size normal 
16953 \emph off 
16954 \bar no 
16955 \noun off 
16956 \color none
16957 sdcc/bin
16958 \end_inset 
16959 </cell>
16960 </row>
16961 <row topline="true" bottomline="true">
16962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16963 \begin_inset Text
16964
16965 \layout Standard
16966
16967 packihx
16968 \end_inset 
16969 </cell>
16970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16971 \begin_inset Text
16972
16973 \layout Standard
16974
16975 ihx packer
16976 \end_inset 
16977 </cell>
16978 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16979 \begin_inset Text
16980
16981 \layout Standard
16982
16983
16984 \family roman 
16985 \series medium 
16986 \shape up 
16987 \size normal 
16988 \emph off 
16989 \bar no 
16990 \noun off 
16991 \color none
16992 sdcc/bin
16993 \end_inset 
16994 </cell>
16995 </row>
16996 </lyxtabular>
16997
16998 \end_inset 
16999
17000
17001 \newline 
17002
17003 \layout Section
17004
17005 Documentation
17006 \begin_inset LatexCommand \index{Documentation}
17007
17008 \end_inset 
17009
17010  included in the distribution
17011 \layout Standard
17012 \align center 
17013
17014 \begin_inset  Tabular
17015 <lyxtabular version="3" rows="10" columns="2">
17016 <features>
17017 <column alignment="left" valignment="top" leftline="true" width="0">
17018 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
17019 <row topline="true" bottomline="true">
17020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17021 \begin_inset Text
17022
17023 \layout Standard
17024
17025 Subject / Title
17026 \end_inset 
17027 </cell>
17028 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17029 \begin_inset Text
17030
17031 \layout Standard
17032
17033 Where to get / filename
17034 \end_inset 
17035 </cell>
17036 </row>
17037 <row topline="true">
17038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17039 \begin_inset Text
17040
17041 \layout Standard
17042
17043 SDCC Compiler User Guide
17044 \end_inset 
17045 </cell>
17046 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17047 \begin_inset Text
17048
17049 \layout Standard
17050
17051 You're reading it right now
17052 \end_inset 
17053 </cell>
17054 </row>
17055 <row topline="true">
17056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17057 \begin_inset Text
17058
17059 \layout Standard
17060
17061 Changelog of SDCC
17062 \end_inset 
17063 </cell>
17064 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17065 \begin_inset Text
17066
17067 \layout Standard
17068
17069 sdcc/Changelog
17070 \end_inset 
17071 </cell>
17072 </row>
17073 <row topline="true">
17074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17075 \begin_inset Text
17076
17077 \layout Standard
17078
17079 ASXXXX Assemblers and ASLINK Relocating Linker
17080 \end_inset 
17081 </cell>
17082 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17083 \begin_inset Text
17084
17085 \layout Standard
17086
17087 sdcc/as/doc/asxhtm.html
17088 \end_inset 
17089 </cell>
17090 </row>
17091 <row topline="true">
17092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17093 \begin_inset Text
17094
17095 \layout Standard
17096
17097 SDCC regression test
17098 \begin_inset LatexCommand \index{Regression test}
17099
17100 \end_inset 
17101
17102
17103 \end_inset 
17104 </cell>
17105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17106 \begin_inset Text
17107
17108 \layout Standard
17109
17110 sdcc/doc/test_suite_spec.pdf
17111 \end_inset 
17112 </cell>
17113 </row>
17114 <row topline="true">
17115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17116 \begin_inset Text
17117
17118 \layout Standard
17119
17120 Various notes
17121 \end_inset 
17122 </cell>
17123 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17124 \begin_inset Text
17125
17126 \layout Standard
17127
17128 sdcc/doc/*
17129 \end_inset 
17130 </cell>
17131 </row>
17132 <row topline="true">
17133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17134 \begin_inset Text
17135
17136 \layout Standard
17137
17138 Notes on debugging with sdcdb
17139 \begin_inset LatexCommand \index{sdcdb (debugger)}
17140
17141 \end_inset 
17142
17143
17144 \end_inset 
17145 </cell>
17146 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17147 \begin_inset Text
17148
17149 \layout Standard
17150
17151 sdcc/debugger/README
17152 \end_inset 
17153 </cell>
17154 </row>
17155 <row topline="true">
17156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17157 \begin_inset Text
17158
17159 \layout Standard
17160
17161 Software simulator for microcontrollers
17162 \end_inset 
17163 </cell>
17164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17165 \begin_inset Text
17166
17167 \layout Standard
17168
17169
17170 \family roman 
17171 \series medium 
17172 \shape up 
17173 \size normal 
17174 \emph off 
17175 \bar no 
17176 \noun off 
17177 \color none
17178 sdcc/sim/ucsim/doc
17179 \family default 
17180 \series default 
17181 \shape default 
17182 \size default 
17183 \emph default 
17184 \bar default 
17185 \noun default 
17186 \color default
17187 /index.html
17188 \end_inset 
17189 </cell>
17190 </row>
17191 <row topline="true">
17192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17193 \begin_inset Text
17194
17195 \layout Standard
17196
17197 Temporary notes on the pic16
17198 \begin_inset LatexCommand \index{PIC16}
17199
17200 \end_inset 
17201
17202  port
17203 \end_inset 
17204 </cell>
17205 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17206 \begin_inset Text
17207
17208 \layout Standard
17209
17210 sdcc/src/pic16/NOTES
17211 \end_inset 
17212 </cell>
17213 </row>
17214 <row topline="true" bottomline="true">
17215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17216 \begin_inset Text
17217
17218 \layout Standard
17219
17220 SDCC internal documentation (debugging file format)
17221 \end_inset 
17222 </cell>
17223 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17224 \begin_inset Text
17225
17226 \layout Standard
17227
17228 sdcc/doc/
17229 \family roman 
17230 \series medium 
17231 \shape up 
17232 \size normal 
17233 \emph off 
17234 \bar no 
17235 \noun off 
17236 \color none
17237 cdbfileformat.pd
17238 \family default 
17239 \series default 
17240 \shape default 
17241 \size default 
17242 \emph default 
17243 \bar default 
17244 \noun default 
17245 \color default
17246 f
17247 \end_inset 
17248 </cell>
17249 </row>
17250 </lyxtabular>
17251
17252 \end_inset 
17253
17254
17255 \newline 
17256
17257 \layout Section
17258
17259 Related open source tools
17260 \begin_inset LatexCommand \index{Related tools}
17261
17262 \end_inset 
17263
17264
17265 \layout Standard
17266 \align center 
17267
17268 \begin_inset  Tabular
17269 <lyxtabular version="3" rows="11" columns="3">
17270 <features>
17271 <column alignment="center" valignment="top" leftline="true" width="0pt">
17272 <column alignment="block" valignment="top" leftline="true" width="30line%">
17273 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
17274 <row topline="true" bottomline="true">
17275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17276 \begin_inset Text
17277
17278 \layout Standard
17279
17280 Name
17281 \end_inset 
17282 </cell>
17283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17284 \begin_inset Text
17285
17286 \layout Standard
17287
17288 Purpose
17289 \end_inset 
17290 </cell>
17291 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17292 \begin_inset Text
17293
17294 \layout Standard
17295
17296 Where to get
17297 \end_inset 
17298 </cell>
17299 </row>
17300 <row topline="true">
17301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17302 \begin_inset Text
17303
17304 \layout Standard
17305
17306 gpsim
17307 \begin_inset LatexCommand \index{gpsim (pic simulator)}
17308
17309 \end_inset 
17310
17311
17312 \end_inset 
17313 </cell>
17314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17315 \begin_inset Text
17316
17317 \layout Standard
17318
17319 PIC simulator
17320 \end_inset 
17321 </cell>
17322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17323 \begin_inset Text
17324
17325 \layout Standard
17326
17327
17328 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
17329
17330 \end_inset 
17331
17332
17333 \end_inset 
17334 </cell>
17335 </row>
17336 <row topline="true">
17337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17338 \begin_inset Text
17339
17340 \layout Standard
17341
17342 gputils
17343 \begin_inset LatexCommand \index{gputils (pic tools)}
17344
17345 \end_inset 
17346
17347
17348 \end_inset 
17349 </cell>
17350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17351 \begin_inset Text
17352
17353 \layout Standard
17354
17355 GNU PIC utilities
17356 \end_inset 
17357 </cell>
17358 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17359 \begin_inset Text
17360
17361 \layout Standard
17362
17363
17364 \begin_inset LatexCommand \url{http://gputils.sourceforge.net/}
17365
17366 \end_inset 
17367
17368
17369 \end_inset 
17370 </cell>
17371 </row>
17372 <row topline="true">
17373 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17374 \begin_inset Text
17375
17376 \layout Standard
17377
17378 flP5
17379 \end_inset 
17380 </cell>
17381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17382 \begin_inset Text
17383
17384 \layout Standard
17385
17386 PIC programmer
17387 \end_inset 
17388 </cell>
17389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17390 \begin_inset Text
17391
17392 \layout Standard
17393
17394
17395 \begin_inset LatexCommand \url{http://digilander.libero.it/fbradasc/FLP5.html}
17396
17397 \end_inset 
17398
17399
17400 \end_inset 
17401 </cell>
17402 </row>
17403 <row topline="true">
17404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17405 \begin_inset Text
17406
17407 \layout Standard
17408
17409 indent
17410 \begin_inset LatexCommand \index{indent (source formatting tool)}
17411
17412 \end_inset 
17413
17414
17415 \end_inset 
17416 </cell>
17417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17418 \begin_inset Text
17419
17420 \layout Standard
17421
17422 Formats C source - Master of the white spaces
17423 \end_inset 
17424 </cell>
17425 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17426 \begin_inset Text
17427
17428 \layout Standard
17429
17430
17431 \begin_inset LatexCommand \url{http://home.hccnet.nl/d.ingamells/beautify.html}
17432
17433 \end_inset 
17434
17435
17436 \end_inset 
17437 </cell>
17438 </row>
17439 <row topline="true">
17440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17441 \begin_inset Text
17442
17443 \layout Standard
17444
17445 srecord
17446 \begin_inset LatexCommand \index{srecord (tool)}
17447
17448 \end_inset 
17449
17450
17451 \end_inset 
17452 </cell>
17453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17454 \begin_inset Text
17455
17456 \layout Standard
17457
17458 Object file conversion, checksumming, ...
17459 \end_inset 
17460 </cell>
17461 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17462 \begin_inset Text
17463
17464 \layout Standard
17465
17466
17467 \begin_inset LatexCommand \url{http://srecord.sourceforge.net/}
17468
17469 \end_inset 
17470
17471
17472 \end_inset 
17473 </cell>
17474 </row>
17475 <row topline="true">
17476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17477 \begin_inset Text
17478
17479 \layout Standard
17480
17481 objdump
17482 \begin_inset LatexCommand \index{objdump (tool)}
17483
17484 \end_inset 
17485
17486
17487 \end_inset 
17488 </cell>
17489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17490 \begin_inset Text
17491
17492 \layout Standard
17493
17494 Object file conversion, ...
17495 \end_inset 
17496 </cell>
17497 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17498 \begin_inset Text
17499
17500 \layout Standard
17501
17502 Part of binutils (should be there anyway)
17503 \end_inset 
17504 </cell>
17505 </row>
17506 <row topline="true">
17507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17508 \begin_inset Text
17509
17510 \layout Standard
17511
17512 doxygen
17513 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
17514
17515 \end_inset 
17516
17517
17518 \end_inset 
17519 </cell>
17520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17521 \begin_inset Text
17522
17523 \layout Standard
17524
17525 Source code documentation system
17526 \end_inset 
17527 </cell>
17528 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17529 \begin_inset Text
17530
17531 \layout Standard
17532
17533
17534 \begin_inset LatexCommand \url{http://www.doxygen.org}
17535
17536 \end_inset 
17537
17538
17539 \end_inset 
17540 </cell>
17541 </row>
17542 <row topline="true">
17543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17544 \begin_inset Text
17545
17546 \layout Standard
17547
17548 kdevelop
17549 \end_inset 
17550 </cell>
17551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17552 \begin_inset Text
17553
17554 \layout Standard
17555
17556 IDE (has anyone tried integrating SDCC & sdcdb? Unix only)
17557 \end_inset 
17558 </cell>
17559 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17560 \begin_inset Text
17561
17562 \layout Standard
17563
17564
17565 \begin_inset LatexCommand \url{http://www.kdevelop.org}
17566
17567 \end_inset 
17568
17569
17570 \end_inset 
17571 </cell>
17572 </row>
17573 <row topline="true">
17574 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17575 \begin_inset Text
17576
17577 \layout Standard
17578
17579 splint
17580 \begin_inset LatexCommand \index{splint (syntax checking tool)}
17581
17582 \end_inset 
17583
17584
17585 \end_inset 
17586 </cell>
17587 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17588 \begin_inset Text
17589
17590 \layout Standard
17591
17592 Statically checks c sources
17593 \end_inset 
17594 </cell>
17595 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17596 \begin_inset Text
17597
17598 \layout Standard
17599
17600
17601 \begin_inset LatexCommand \url{http://www.splint.org}
17602
17603 \end_inset 
17604
17605
17606 \end_inset 
17607 </cell>
17608 </row>
17609 <row topline="true" bottomline="true">
17610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17611 \begin_inset Text
17612
17613 \layout Standard
17614
17615 ddd
17616 \begin_inset LatexCommand \index{ddd (debugger)}
17617
17618 \end_inset 
17619
17620
17621 \end_inset 
17622 </cell>
17623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17624 \begin_inset Text
17625
17626 \layout Standard
17627
17628 Debugger, serves nicely as GUI to sdcdb
17629 \begin_inset LatexCommand \index{sdcdb (debugger)}
17630
17631 \end_inset 
17632
17633  (Unix only)
17634 \end_inset 
17635 </cell>
17636 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17637 \begin_inset Text
17638
17639 \layout Standard
17640
17641
17642 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
17643
17644 \end_inset 
17645
17646
17647 \end_inset 
17648 </cell>
17649 </row>
17650 </lyxtabular>
17651
17652 \end_inset 
17653
17654
17655 \newline 
17656
17657 \layout Section
17658
17659 Related documentation / recommended reading
17660 \layout Standard
17661 \align center 
17662
17663 \begin_inset  Tabular
17664 <lyxtabular version="3" rows="6" columns="3">
17665 <features>
17666 <column alignment="center" valignment="top" leftline="true" width="0pt">
17667 <column alignment="block" valignment="top" leftline="true" width="30line%">
17668 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
17669 <row topline="true" bottomline="true">
17670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17671 \begin_inset Text
17672
17673 \layout Standard
17674
17675 Name
17676 \end_inset 
17677 </cell>
17678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17679 \begin_inset Text
17680
17681 \layout Standard
17682
17683 Subject / Title
17684 \end_inset 
17685 </cell>
17686 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17687 \begin_inset Text
17688
17689 \layout Standard
17690
17691 Where to get
17692 \end_inset 
17693 </cell>
17694 </row>
17695 <row topline="true">
17696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17697 \begin_inset Text
17698
17699 \layout Standard
17700
17701
17702 \family roman 
17703 \series medium 
17704 \shape up 
17705 \size normal 
17706 \emph off 
17707 \bar no 
17708 \noun off 
17709 \color none
17710 c-refcard.pdf
17711 \end_inset 
17712 </cell>
17713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17714 \begin_inset Text
17715
17716 \layout Standard
17717
17718 C Reference Card
17719 \begin_inset LatexCommand \index{C Reference card}
17720
17721 \end_inset 
17722
17723 , 2 pages
17724 \end_inset 
17725 </cell>
17726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17727 \begin_inset Text
17728
17729 \layout Standard
17730
17731
17732 \begin_inset LatexCommand \url{http://www.refcards.com/about/c.html}
17733
17734 \end_inset 
17735
17736
17737 \end_inset 
17738 </cell>
17739 </row>
17740 <row topline="true">
17741 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17742 \begin_inset Text
17743
17744 \layout Standard
17745
17746 c-faq
17747 \end_inset 
17748 </cell>
17749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17750 \begin_inset Text
17751
17752 \layout Standard
17753
17754 C-FAQ-list
17755 \end_inset 
17756 </cell>
17757 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17758 \begin_inset Text
17759
17760 \layout Standard
17761
17762
17763 \begin_inset LatexCommand \url{http://www.eskimo.com/~scs/C-faq/top.html}
17764
17765 \end_inset 
17766
17767
17768 \end_inset 
17769 </cell>
17770 </row>
17771 <row topline="true">
17772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17773 \begin_inset Text
17774
17775 \layout Standard
17776
17777 \end_inset 
17778 </cell>
17779 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17780 \begin_inset Text
17781
17782 \layout Standard
17783
17784 Latest datasheet of the target CPU
17785 \end_inset 
17786 </cell>
17787 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17788 \begin_inset Text
17789
17790 \layout Standard
17791
17792 vendor
17793 \end_inset 
17794 </cell>
17795 </row>
17796 <row topline="true">
17797 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17798 \begin_inset Text
17799
17800 \layout Standard
17801
17802 \end_inset 
17803 </cell>
17804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17805 \begin_inset Text
17806
17807 \layout Standard
17808
17809 Revision history of datasheet
17810 \end_inset 
17811 </cell>
17812 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17813 \begin_inset Text
17814
17815 \layout Standard
17816
17817 vendor
17818 \end_inset 
17819 </cell>
17820 </row>
17821 <row topline="true" bottomline="true">
17822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17823 \begin_inset Text
17824
17825 \layout Standard
17826
17827 S.
17828  S.
17829  Muchnick
17830 \end_inset 
17831 </cell>
17832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17833 \begin_inset Text
17834
17835 \layout Standard
17836
17837 Advanced Compiler Design and Implementation
17838 \end_inset 
17839 </cell>
17840 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17841 \begin_inset Text
17842
17843 \layout Standard
17844
17845 bookstore (very dedicated, probably read other books first)
17846 \end_inset 
17847 </cell>
17848 </row>
17849 </lyxtabular>
17850
17851 \end_inset 
17852
17853
17854 \newline 
17855
17856 \layout Section
17857
17858 Some Questions
17859 \layout Standard
17860
17861 Some questions answered, some pointers given - it might be time to in turn
17862  ask 
17863 \emph on 
17864 you
17865 \emph default 
17866  some questions: 
17867 \layout Itemize
17868
17869 can you solve your project with the selected microcontroller? Would you
17870  find out early or rather late that your target is too small/slow/whatever?
17871  Can you switch to a slightly better device if it doesn't fit?
17872 \layout Itemize
17873
17874 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
17875  and/or another programming language be more adequate? Would an operating
17876  system on the target device help?
17877 \layout Itemize
17878
17879 if you solved the problem, will the marketing department be happy?
17880 \layout Itemize
17881
17882 if the marketing department is happy, will customers be happy?
17883 \layout Itemize
17884
17885 if you're the project manager, marketing department and maybe even the customer
17886  in one person, have you tried to see the project from the outside?
17887 \layout Itemize
17888
17889 is the project done if you think it is done? Or is just that other interface/pro
17890 tocol/feature/configuration/option missing? How about website, manual(s),
17891  internationali(z|s)ation, packaging, labels, 2nd source for components,
17892  electromagnetic compatability/interference, documentation for production,
17893  production test software, update mechanism, patent issues?
17894 \layout Itemize
17895
17896 is your project adequately positioned in that magic triangle: fame, fortune,
17897  fun?
17898 \layout Standard
17899
17900 Maybe not all answers to these questions are known and some answers may
17901  even be 
17902 \emph on 
17903 no
17904 \emph default 
17905 , nevertheless knowing these questions may help you to avoid burnout
17906 \begin_inset Foot
17907 collapsed false
17908
17909 \layout Standard
17910
17911 burnout is bad for electronic devices, programmers and motorcycle tyres
17912 \end_inset 
17913
17914 .
17915  Chances are you didn't want to hear some of them...
17916 \layout Chapter
17917
17918 Support
17919 \begin_inset LatexCommand \index{Support}
17920
17921 \end_inset 
17922
17923
17924 \layout Standard
17925
17926 SDCC has grown to be a large project.
17927  The compiler alone (without the preprocessor, assembler and linker) is
17928  well over 100,000 lines of code (blank stripped).
17929  The open source nature of this project is a key to its continued growth
17930  and support.
17931  You gain the benefit and support of many active software developers and
17932  end users.
17933  Is SDCC perfect? No, that's why we need your help.
17934  The developers take pride in fixing reported bugs.
17935  You can help by reporting the bugs and helping other SDCC users.
17936  There are lots of ways to contribute, and we encourage you to take part
17937  in making SDCC a great software package.
17938  
17939 \layout Standard
17940
17941 The SDCC project is hosted on the SDCC sourceforge site at 
17942 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
17943
17944 \end_inset 
17945
17946 .
17947  You'll find the complete set of mailing lists
17948 \begin_inset LatexCommand \index{Mailing list}
17949
17950 \end_inset 
17951
17952 , forums, bug reporting system, patch submission
17953 \begin_inset LatexCommand \index{Patch submission}
17954
17955 \end_inset 
17956
17957  system, download
17958 \begin_inset LatexCommand \index{download}
17959
17960 \end_inset 
17961
17962  area and cvs code repository
17963 \begin_inset LatexCommand \index{cvs code repository}
17964
17965 \end_inset 
17966
17967  there.
17968 \layout Section
17969
17970 Reporting Bugs
17971 \begin_inset LatexCommand \index{Bug reporting}
17972
17973 \end_inset 
17974
17975
17976 \begin_inset LatexCommand \index{Reporting bugs}
17977
17978 \end_inset 
17979
17980
17981 \layout Standard
17982
17983 The recommended way of reporting bugs is using the infrastructure of the
17984  sourceforge site.
17985  You can follow the status of bug reports there and have an overview about
17986  the known bugs.
17987 \layout Standard
17988
17989 Bug reports are automatically forwarded to the developer mailing list and
17990  will be fixed ASAP.
17991  When reporting a bug, it is very useful to include a small test program
17992  (the smaller the better) which reproduces the problem.
17993  If you can isolate the problem by looking at the generated assembly code,
17994  this can be very helpful.
17995  Compiling your program with the -
17996 \begin_inset ERT
17997 status Collapsed
17998
17999 \layout Standard
18000
18001 \backslash 
18002 /
18003 \end_inset 
18004
18005 -dumpall
18006 \begin_inset LatexCommand \index{-\/-dumpall}
18007
18008 \end_inset 
18009
18010  option can sometimes be useful in locating optimization problems.
18011  When reporting a bug please maker sure you:
18012 \layout Enumerate
18013
18014 Attach the code you are compiling with SDCC.
18015  
18016 \layout Enumerate
18017
18018 Specify the exact command you use to run SDCC, or attach your Makefile.
18019  
18020 \layout Enumerate
18021
18022 Specify the SDCC version (type "
18023 \family sans 
18024 \series bold 
18025 sdcc -v
18026 \family default 
18027 \series default 
18028 "), your platform, and operating system.
18029  
18030 \layout Enumerate
18031
18032 Provide an exact copy of any error message or incorrect output.
18033  
18034 \layout Enumerate
18035
18036 Put something meaningful in the subject of your message.
18037 \layout Standard
18038
18039 Please attempt to include these 5 important parts, as applicable, in all
18040  requests for support or when reporting any problems or bugs with SDCC.
18041  Though this will make your message lengthy, it will greatly improve your
18042  chance that SDCC users and developers will be able to help you.
18043  Some SDCC developers are frustrated by bug reports without code provided
18044  that they can use to reproduce and ultimately fix the problem, so please
18045  be sure to provide sample code if you are reporting a bug! 
18046 \layout Standard
18047
18048 Please have a short check that you are using a recent version of SDCC and
18049  the bug is not yet known.
18050  This is the link for reporting bugs: 
18051 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
18052
18053 \end_inset 
18054
18055 .
18056 \layout Section
18057
18058 Requesting Features
18059 \begin_inset LatexCommand \label{sub:Requesting-Features}
18060
18061 \end_inset 
18062
18063
18064 \begin_inset LatexCommand \index{Feature request}
18065
18066 \end_inset 
18067
18068
18069 \begin_inset LatexCommand \index{Requesting features}
18070
18071 \end_inset 
18072
18073
18074 \layout Standard
18075
18076 Like bug reports feature requests are forwarded to the developer mailing
18077  list.
18078  This is the link for requesting features: 
18079 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
18080
18081 \end_inset 
18082
18083 .
18084 \layout Section
18085
18086 Submitting patches
18087 \layout Standard
18088
18089 Like bug reports contributed patches are forwarded to the developer mailing
18090  list.
18091  This is the link for submitting patches
18092 \begin_inset LatexCommand \index{Patch submission}
18093
18094 \end_inset 
18095
18096
18097 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
18098
18099 \end_inset 
18100
18101 .
18102 \layout Standard
18103
18104 You need to specify some parameters to the 
18105 \family typewriter 
18106 diff
18107 \family default 
18108  command for the patches to be useful.
18109  If you modified more than one file a patch created f.e.
18110  with 
18111 \family sans 
18112 \series bold 
18113
18114 \begin_inset Quotes sld
18115 \end_inset 
18116
18117 diff -Naur unmodified_directory modified_directory >my_changes.patch
18118 \begin_inset Quotes srd
18119 \end_inset 
18120
18121
18122 \family default 
18123 \series default 
18124  will be fine, otherwise 
18125 \family sans 
18126 \series bold 
18127
18128 \begin_inset Quotes sld
18129 \end_inset 
18130
18131 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
18132 \begin_inset Quotes srd
18133 \end_inset 
18134
18135
18136 \series default 
18137  
18138 \family default 
18139 will do.
18140 \layout Section
18141
18142 Getting Help
18143 \layout Standard
18144
18145 These links should take you directly to the 
18146 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
18147
18148 \end_inset 
18149
18150
18151 \begin_inset Foot
18152 collapsed false
18153
18154 \layout Standard
18155
18156 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
18157  automated messages (mid 2003)
18158 \end_inset 
18159
18160  and the 
18161 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
18162
18163 \end_inset 
18164
18165 , lists and forums are archived and searchable so if you are lucky someone
18166  already had a similar problem.
18167 \layout Section
18168
18169 ChangeLog
18170 \layout Standard
18171
18172 You can follow the status of the cvs version
18173 \begin_inset LatexCommand \index{version}
18174
18175 \end_inset 
18176
18177  of SDCC by watching the Changelog
18178 \begin_inset LatexCommand \index{Changelog}
18179
18180 \end_inset 
18181
18182  in the cvs-repository
18183 \newline 
18184
18185 \size footnotesize 
18186
18187 \begin_inset LatexCommand \htmlurl{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/sdcc/sdcc/ChangeLog?rev=HEAD&content-type=text/plain}
18188
18189 \end_inset 
18190
18191 .
18192 \layout Section
18193
18194 Release policy
18195 \begin_inset LatexCommand \index{Release policy}
18196
18197 \end_inset 
18198
18199
18200 \layout Standard
18201
18202 Historically there often were long delays between official releases and
18203  the sourceforge download area tends to get not updated at all.
18204  Excuses in the past might have referred to problems with live range analysis,
18205  but as this was fixed a while ago, the current problem is that another
18206  excuse has to be found.
18207  Kidding aside, we have to get better there! On the other hand there are
18208  daily snapshots available at 
18209 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
18210
18211 \end_inset 
18212
18213 , and you can always build the very last version (hopefully with many bugs
18214  fixed, and features added) from the source code available at 
18215 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
18216
18217 \end_inset 
18218
18219 .
18220 \layout Section
18221
18222 Examples
18223 \begin_inset LatexCommand \index{Examples}
18224
18225 \end_inset 
18226
18227
18228 \layout Standard
18229
18230 You'll find some small examples in the directory 
18231 \emph on 
18232 sdcc/device/examples/.
18233  
18234 \emph default 
18235 More examples and libraries are available at
18236 \emph on 
18237  The SDCC Open Knowledge Resource 
18238 \begin_inset LatexCommand \url{http://www.qsl.net/dl9sec/SDCC_OKR.html}
18239
18240 \end_inset 
18241
18242  
18243 \emph default 
18244 web site or at 
18245 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
18246
18247 \end_inset 
18248
18249 .
18250 \layout Comment
18251
18252 I did insert a reference to Paul's web site here although it seems rather
18253  dedicated to a specific 8032 board (I think it's okay because it f.e.
18254  shows LCD/Harddisc interface and has a free 8051 monitor.
18255  Independent 8032 board vendors face hard competition of heavily subsidized
18256  development boards anyway).
18257 \layout Comment
18258
18259 Maybe we should include some links to real world applications.
18260  Preferably pointer to pointers (one for each architecture) so this stays
18261  manageable here?
18262 \layout Section
18263
18264 Quality control
18265 \begin_inset LatexCommand \index{Quality control}
18266
18267 \end_inset 
18268
18269
18270 \layout Standard
18271
18272 The compiler is passed through nightly compile and build checks.
18273  The so called 
18274 \shape italic 
18275 regression tests
18276 \shape default 
18277
18278 \begin_inset LatexCommand \index{Regression test}
18279
18280 \end_inset 
18281
18282  check that SDCC itself compiles flawlessly on several platforms and checks
18283  the quality of the code generated by SDCC by running the code through simulator
18284 s.
18285  There is a separate document 
18286 \shape italic 
18287 test_suite.pdf
18288 \begin_inset LatexCommand \index{Test suite}
18289
18290 \end_inset 
18291
18292
18293 \shape default 
18294  about this.
18295 \layout Standard
18296
18297 You'll find the test code in the directory 
18298 \shape italic 
18299 sdcc/support/regression
18300 \shape default 
18301 .
18302  You can run these tests manually by running 
18303 \family sans 
18304 make
18305 \family default 
18306  in this directory (or f.e.
18307  
18308 \family sans 
18309 \series bold 
18310
18311 \begin_inset Quotes sld
18312 \end_inset 
18313
18314 make test-mcs51
18315 \begin_inset Quotes srd
18316 \end_inset 
18317
18318
18319 \family default 
18320 \series default 
18321  if you don't want to run the complete tests).
18322  The test code might also be interesting if you want to look for examples
18323 \begin_inset LatexCommand \index{Examples}
18324
18325 \end_inset 
18326
18327  checking corner cases of SDCC or if you plan to submit patches
18328 \begin_inset LatexCommand \index{Patch submission}
18329
18330 \end_inset 
18331
18332 .
18333 \layout Standard
18334
18335 The pic port uses a different set of regression tests, you'll find them
18336  in the directory 
18337 \shape italic 
18338 sdcc/src/regression
18339 \shape default 
18340 .
18341 \layout Chapter
18342 \pagebreak_top 
18343 SDCC Technical Data
18344 \layout Section
18345
18346 Optimizations
18347 \begin_inset LatexCommand \index{Optimizations}
18348
18349 \end_inset 
18350
18351
18352 \layout Standard
18353
18354 SDCC performs a host of standard optimizations in addition to some MCU specific
18355  optimizations.
18356  
18357 \layout Subsection
18358
18359 Sub-expression Elimination
18360 \begin_inset LatexCommand \index{Subexpression elimination}
18361
18362 \end_inset 
18363
18364
18365 \layout Standard
18366
18367 The compiler does local and 
18368 \emph on 
18369 g
18370 \emph default 
18371 lobal 
18372 \emph on 
18373 c
18374 \emph default 
18375 ommon 
18376 \emph on 
18377 s
18378 \emph default 
18379 ubexpression 
18380 \emph on 
18381 e
18382 \emph default 
18383 limination, e.g.: 
18384 \layout Verse
18385
18386
18387 \family typewriter 
18388 i = x + y + 1; 
18389 \newline 
18390 j = x + y;
18391 \layout Standard
18392
18393 will be translated to
18394 \layout Verse
18395
18396
18397 \family typewriter 
18398 iTemp = x + y; 
18399 \newline 
18400 i = iTemp + 1; 
18401 \newline 
18402 j = iTemp;
18403 \layout Standard
18404
18405 Some subexpressions are not as obvious as the above example, e.g.:
18406 \layout Verse
18407
18408
18409 \family typewriter 
18410 a->b[i].c = 10; 
18411 \newline 
18412 a->b[i].d = 11;
18413 \layout Standard
18414
18415 In this case the address arithmetic a->b[i] will be computed only once;
18416  the equivalent code in C would be.
18417 \layout Verse
18418
18419
18420 \family typewriter 
18421 iTemp = a->b[i]; 
18422 \newline 
18423 iTemp.c = 10; 
18424 \newline 
18425 iTemp.d = 11;
18426 \layout Standard
18427
18428 The compiler will try to keep these temporary variables in registers.
18429 \layout Subsection
18430
18431 Dead-Code Elimination
18432 \begin_inset LatexCommand \index{Dead-code elimination}
18433
18434 \end_inset 
18435
18436
18437 \layout Verse
18438
18439
18440 \family typewriter 
18441 int global;
18442 \newline 
18443
18444 \newline 
18445 void f () { 
18446 \newline 
18447 \SpecialChar ~
18448 \SpecialChar ~
18449 int i; 
18450 \newline 
18451 \SpecialChar ~
18452 \SpecialChar ~
18453 i = 1; \SpecialChar ~
18454 \SpecialChar ~
18455 \SpecialChar ~
18456 \SpecialChar ~
18457 \SpecialChar ~
18458 /* dead store */ 
18459 \newline 
18460 \SpecialChar ~
18461 \SpecialChar ~
18462 global = 1;\SpecialChar ~
18463 /* dead store */ 
18464 \newline 
18465 \SpecialChar ~
18466 \SpecialChar ~
18467 global = 2; 
18468 \newline 
18469 \SpecialChar ~
18470 \SpecialChar ~
18471 return; 
18472 \newline 
18473 \SpecialChar ~
18474 \SpecialChar ~
18475 global = 3;\SpecialChar ~
18476 /* unreachable */ 
18477 \newline 
18478 }
18479 \layout Standard
18480
18481 will be changed to
18482 \layout Verse
18483
18484
18485 \family typewriter 
18486 int global;
18487 \newline 
18488
18489 \newline 
18490 void f () {
18491 \newline 
18492 \SpecialChar ~
18493 \SpecialChar ~
18494 global = 2; 
18495 \newline 
18496 \SpecialChar ~
18497 \SpecialChar ~
18498 return; 
18499 \newline 
18500 }
18501 \layout Subsection
18502
18503 Copy-Propagation
18504 \begin_inset LatexCommand \index{Copy propagation}
18505
18506 \end_inset 
18507
18508
18509 \layout Verse
18510
18511
18512 \family typewriter 
18513 int f() { 
18514 \newline 
18515 \SpecialChar ~
18516 \SpecialChar ~
18517 int i, j; 
18518 \newline 
18519 \SpecialChar ~
18520 \SpecialChar ~
18521 i = 10; 
18522 \newline 
18523 \SpecialChar ~
18524 \SpecialChar ~
18525 j = i; 
18526 \newline 
18527 \SpecialChar ~
18528 \SpecialChar ~
18529 return j; 
18530 \newline 
18531 }
18532 \layout Standard
18533
18534 will be changed to 
18535 \layout Verse
18536
18537
18538 \family typewriter 
18539 int f() { 
18540 \newline 
18541 \SpecialChar ~
18542 \SpecialChar ~
18543 int i, j; 
18544 \newline 
18545 \SpecialChar ~
18546 \SpecialChar ~
18547 i = 10; 
18548 \newline 
18549 \SpecialChar ~
18550 \SpecialChar ~
18551 j = 10; 
18552 \newline 
18553 \SpecialChar ~
18554 \SpecialChar ~
18555 return 10; 
18556 \newline 
18557 }
18558 \layout Standard
18559
18560 Note: the dead stores created by this copy propagation will be eliminated
18561  by dead-code elimination.
18562 \layout Subsection
18563
18564 Loop Optimizations
18565 \begin_inset LatexCommand \index{Loop optimization}
18566
18567 \end_inset 
18568
18569
18570 \layout Standard
18571
18572 Two types of loop optimizations are done by SDCC loop invariant lifting
18573  and strength reduction of loop induction variables.
18574  In addition to the strength reduction the optimizer marks the induction
18575  variables and the register allocator tries to keep the induction variables
18576  in registers for the duration of the loop.
18577  Because of this preference of the register allocator
18578 \begin_inset LatexCommand \index{Register allocation}
18579
18580 \end_inset 
18581
18582 , loop induction optimization causes an increase in register pressure, which
18583  may cause unwanted spilling of other temporary variables into the stack
18584 \begin_inset LatexCommand \index{stack}
18585
18586 \end_inset 
18587
18588  / data space.
18589  The compiler will generate a warning message when it is forced to allocate
18590  extra space either on the stack or data space.
18591  If this extra space allocation is undesirable then induction optimization
18592  can be eliminated either for the entire source file (with -
18593 \begin_inset ERT
18594 status Collapsed
18595
18596 \layout Standard
18597
18598 \backslash 
18599 /
18600 \end_inset 
18601
18602 -noinduction option) or for a given function only using #pragma\SpecialChar ~
18603 noinduction
18604 \begin_inset LatexCommand \index{\#pragma noinduction}
18605
18606 \end_inset 
18607
18608 .
18609 \newline 
18610
18611 \newline 
18612 Loop Invariant:
18613 \layout Verse
18614
18615
18616 \family typewriter 
18617 for (i = 0 ; i < 100 ; i ++) 
18618 \newline 
18619 \SpecialChar ~
18620 \SpecialChar ~
18621 \SpecialChar ~
18622 \SpecialChar ~
18623 f += k + l;
18624 \layout Standard
18625
18626 changed to
18627 \layout Verse
18628
18629
18630 \family typewriter 
18631 itemp = k + l; 
18632 \newline 
18633 for (i = 0; i < 100; i++) 
18634 \newline 
18635 \SpecialChar ~
18636 \SpecialChar ~
18637 \SpecialChar ~
18638 \SpecialChar ~
18639 f += itemp;
18640 \layout Standard
18641
18642 As mentioned previously some loop invariants are not as apparent, all static
18643  address computations are also moved out of the loop.
18644 \newline 
18645
18646 \newline 
18647 Strength Reduction
18648 \begin_inset LatexCommand \index{Strength reduction}
18649
18650 \end_inset 
18651
18652 , this optimization substitutes an expression by a cheaper expression:
18653 \layout Verse
18654
18655
18656 \family typewriter 
18657 for (i=0;i < 100; i++)
18658 \newline 
18659 \SpecialChar ~
18660 \SpecialChar ~
18661 \SpecialChar ~
18662 \SpecialChar ~
18663 ar[i*5] = i*3;
18664 \layout Standard
18665
18666 changed to
18667 \layout Verse
18668
18669
18670 \family typewriter 
18671 itemp1 = 0; 
18672 \newline 
18673 itemp2 = 0; 
18674 \newline 
18675 for (i=0;i< 100;i++) { 
18676 \newline 
18677 \SpecialChar ~
18678 \SpecialChar ~
18679 \SpecialChar ~
18680 \SpecialChar ~
18681 ar[itemp1] = itemp2; 
18682 \newline 
18683 \SpecialChar ~
18684 \SpecialChar ~
18685 \SpecialChar ~
18686 \SpecialChar ~
18687 itemp1 += 5; 
18688 \newline 
18689 \SpecialChar ~
18690 \SpecialChar ~
18691 \SpecialChar ~
18692 \SpecialChar ~
18693 itemp2 += 3; 
18694 \newline 
18695 }
18696 \layout Standard
18697
18698 The more expensive multiplication
18699 \begin_inset LatexCommand \index{Multiplication}
18700
18701 \end_inset 
18702
18703  is changed to a less expensive addition.
18704 \layout Subsection
18705
18706 Loop Reversing
18707 \begin_inset LatexCommand \index{Loop reversing}
18708
18709 \end_inset 
18710
18711
18712 \layout Standard
18713
18714 This optimization is done to reduce the overhead of checking loop boundaries
18715  for every iteration.
18716  Some simple loops can be reversed and implemented using a 
18717 \begin_inset Quotes eld
18718 \end_inset 
18719
18720 decrement and jump if not zero
18721 \begin_inset Quotes erd
18722 \end_inset 
18723
18724  instruction.
18725  SDCC checks for the following criterion to determine if a loop is reversible
18726  (note: more sophisticated compilers use data-dependency analysis to make
18727  this determination, SDCC uses a more simple minded analysis).
18728 \layout Itemize
18729
18730 The 'for' loop is of the form 
18731 \newline 
18732
18733 \newline 
18734
18735 \family typewriter 
18736 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
18737  += 1])
18738 \newline 
18739 \SpecialChar ~
18740 \SpecialChar ~
18741 \SpecialChar ~
18742 \SpecialChar ~
18743 <for body>
18744 \layout Itemize
18745
18746 The <for body> does not contain 
18747 \begin_inset Quotes eld
18748 \end_inset 
18749
18750 continue
18751 \begin_inset Quotes erd
18752 \end_inset 
18753
18754  or 'break
18755 \begin_inset Quotes erd
18756 \end_inset 
18757
18758 .
18759 \layout Itemize
18760
18761 All goto's are contained within the loop.
18762 \layout Itemize
18763
18764 No function calls within the loop.
18765 \layout Itemize
18766
18767 The loop control variable <sym> is not assigned any value within the loop
18768 \layout Itemize
18769
18770 The loop control variable does NOT participate in any arithmetic operation
18771  within the loop.
18772 \layout Itemize
18773
18774 There are NO switch statements in the loop.
18775 \layout Subsection
18776
18777 Algebraic Simplifications
18778 \layout Standard
18779
18780 SDCC does numerous algebraic simplifications, the following is a small sub-set
18781  of these optimizations.
18782 \layout Verse
18783
18784
18785 \family typewriter 
18786 i = j + 0;\SpecialChar ~
18787 \SpecialChar ~
18788 \SpecialChar ~
18789 \SpecialChar ~
18790  /* changed to: */\SpecialChar ~
18791 \SpecialChar ~
18792 \SpecialChar ~
18793 \SpecialChar ~
18794  i = j; 
18795 \newline 
18796 i /= 2;\SpecialChar ~
18797 \SpecialChar ~
18798 \SpecialChar ~
18799 \SpecialChar ~
18800 \SpecialChar ~
18801 \SpecialChar ~
18802 \SpecialChar ~
18803  /* changed to: */\SpecialChar ~
18804 \SpecialChar ~
18805 \SpecialChar ~
18806 \SpecialChar ~
18807  i >>= 1; 
18808 \newline 
18809 i = j - j;\SpecialChar ~
18810 \SpecialChar ~
18811 \SpecialChar ~
18812 \SpecialChar ~
18813  /* changed to: */\SpecialChar ~
18814 \SpecialChar ~
18815 \SpecialChar ~
18816 \SpecialChar ~
18817  i = 0; 
18818 \newline 
18819 i = j / 1;\SpecialChar ~
18820 \SpecialChar ~
18821 \SpecialChar ~
18822 \SpecialChar ~
18823  /* changed to: */\SpecialChar ~
18824 \SpecialChar ~
18825 \SpecialChar ~
18826 \SpecialChar ~
18827  i = j;
18828 \layout Standard
18829
18830 Note the subexpressions
18831 \begin_inset LatexCommand \index{Subexpression}
18832
18833 \end_inset 
18834
18835  given above are generally introduced by macro expansions or as a result
18836  of copy/constant propagation.
18837 \layout Subsection
18838
18839 'switch' Statements
18840 \begin_inset LatexCommand \label{sub:'switch'-Statements}
18841
18842 \end_inset 
18843
18844
18845 \begin_inset LatexCommand \index{switch statement}
18846
18847 \end_inset 
18848
18849
18850 \layout Standard
18851
18852 SDCC changes switch statements to jump tables
18853 \begin_inset LatexCommand \index{jump tables}
18854
18855 \end_inset 
18856
18857  when the following conditions are true.
18858  
18859 \layout Itemize
18860
18861 The case labels are in numerical sequence, the labels need not be in order,
18862  and the starting number need not be one or zero.
18863 \begin_deeper 
18864 \layout Verse
18865
18866
18867 \family typewriter 
18868 switch(i) {\SpecialChar ~
18869 \SpecialChar ~
18870 \SpecialChar ~
18871 \SpecialChar ~
18872 \SpecialChar ~
18873 \SpecialChar ~
18874 \SpecialChar ~
18875 \SpecialChar ~
18876 \SpecialChar ~
18877 \SpecialChar ~
18878 \SpecialChar ~
18879 \SpecialChar ~
18880 \SpecialChar ~
18881 \SpecialChar ~
18882 \SpecialChar ~
18883 \SpecialChar ~
18884 \SpecialChar ~
18885 \SpecialChar ~
18886 \SpecialChar ~
18887 \SpecialChar ~
18888 \SpecialChar ~
18889 \SpecialChar ~
18890 \SpecialChar ~
18891 \SpecialChar ~
18892 \SpecialChar ~
18893 \SpecialChar ~
18894 switch (i) { 
18895 \newline 
18896 \SpecialChar ~
18897 \SpecialChar ~
18898 \SpecialChar ~
18899 case 4: ...\SpecialChar ~
18900 \SpecialChar ~
18901 \SpecialChar ~
18902 \SpecialChar ~
18903 \SpecialChar ~
18904 \SpecialChar ~
18905 \SpecialChar ~
18906 \SpecialChar ~
18907 \SpecialChar ~
18908 \SpecialChar ~
18909 \SpecialChar ~
18910 \SpecialChar ~
18911 \SpecialChar ~
18912 \SpecialChar ~
18913 \SpecialChar ~
18914 \SpecialChar ~
18915 \SpecialChar ~
18916 \SpecialChar ~
18917 \SpecialChar ~
18918 \SpecialChar ~
18919 \SpecialChar ~
18920 \SpecialChar ~
18921 \SpecialChar ~
18922 \SpecialChar ~
18923 \SpecialChar ~
18924 \SpecialChar ~
18925 case 0: ...
18926  
18927 \newline 
18928 \SpecialChar ~
18929 \SpecialChar ~
18930 \SpecialChar ~
18931 case 5: ...\SpecialChar ~
18932 \SpecialChar ~
18933 \SpecialChar ~
18934 \SpecialChar ~
18935 \SpecialChar ~
18936 \SpecialChar ~
18937 \SpecialChar ~
18938 \SpecialChar ~
18939 \SpecialChar ~
18940 \SpecialChar ~
18941 \SpecialChar ~
18942 \SpecialChar ~
18943 \SpecialChar ~
18944 \SpecialChar ~
18945 \SpecialChar ~
18946 \SpecialChar ~
18947 \SpecialChar ~
18948 \SpecialChar ~
18949 \SpecialChar ~
18950 \SpecialChar ~
18951 \SpecialChar ~
18952 \SpecialChar ~
18953 \SpecialChar ~
18954 \SpecialChar ~
18955 \SpecialChar ~
18956 \SpecialChar ~
18957 case 1: ...
18958  
18959 \newline 
18960 \SpecialChar ~
18961 \SpecialChar ~
18962 \SpecialChar ~
18963 case 3: ...\SpecialChar ~
18964 \SpecialChar ~
18965 \SpecialChar ~
18966 \SpecialChar ~
18967 \SpecialChar ~
18968 \SpecialChar ~
18969 \SpecialChar ~
18970 \SpecialChar ~
18971 \SpecialChar ~
18972 \SpecialChar ~
18973 \SpecialChar ~
18974 \SpecialChar ~
18975 \SpecialChar ~
18976 \SpecialChar ~
18977 \SpecialChar ~
18978 \SpecialChar ~
18979 \SpecialChar ~
18980 \SpecialChar ~
18981 \SpecialChar ~
18982 \SpecialChar ~
18983 \SpecialChar ~
18984 \SpecialChar ~
18985 \SpecialChar ~
18986 \SpecialChar ~
18987 \SpecialChar ~
18988 \SpecialChar ~
18989 case 2: ...
18990  
18991 \newline 
18992 \SpecialChar ~
18993 \SpecialChar ~
18994 \SpecialChar ~
18995 case 6: ...\SpecialChar ~
18996 \SpecialChar ~
18997 \SpecialChar ~
18998 \SpecialChar ~
18999 \SpecialChar ~
19000 \SpecialChar ~
19001 \SpecialChar ~
19002 \SpecialChar ~
19003 \SpecialChar ~
19004 \SpecialChar ~
19005 \SpecialChar ~
19006 \SpecialChar ~
19007 \SpecialChar ~
19008 \SpecialChar ~
19009 \SpecialChar ~
19010 \SpecialChar ~
19011 \SpecialChar ~
19012 \SpecialChar ~
19013 \SpecialChar ~
19014 \SpecialChar ~
19015 \SpecialChar ~
19016 \SpecialChar ~
19017 \SpecialChar ~
19018 \SpecialChar ~
19019 \SpecialChar ~
19020 \SpecialChar ~
19021 case 3: ...
19022  
19023 \newline 
19024 }\SpecialChar ~
19025 \SpecialChar ~
19026 \SpecialChar ~
19027 \SpecialChar ~
19028 \SpecialChar ~
19029 \SpecialChar ~
19030 \SpecialChar ~
19031 \SpecialChar ~
19032 \SpecialChar ~
19033 \SpecialChar ~
19034 \SpecialChar ~
19035 \SpecialChar ~
19036 \SpecialChar ~
19037 \SpecialChar ~
19038 \SpecialChar ~
19039 \SpecialChar ~
19040 \SpecialChar ~
19041 \SpecialChar ~
19042 \SpecialChar ~
19043 \SpecialChar ~
19044 \SpecialChar ~
19045 \SpecialChar ~
19046 \SpecialChar ~
19047 \SpecialChar ~
19048 \SpecialChar ~
19049 \SpecialChar ~
19050 \SpecialChar ~
19051 \SpecialChar ~
19052 \SpecialChar ~
19053 \SpecialChar ~
19054 \SpecialChar ~
19055 \SpecialChar ~
19056 \SpecialChar ~
19057 \SpecialChar ~
19058 \SpecialChar ~
19059 \SpecialChar ~
19060 }
19061 \layout Standard
19062
19063 Both the above switch statements will be implemented using a jump-table.
19064  The example to the right side is slightly more efficient as the check for
19065  the lower boundary of the jump-table is not needed.
19066 \end_deeper 
19067 \layout Itemize
19068
19069 The number of case labels is at least three, since it takes two conditional
19070  statements to handle the boundary conditions.
19071 \layout Itemize
19072
19073 The number of case labels is less than 84, since each label takes 3 bytes
19074  and a jump-table can be utmost 256 bytes long.
19075 \layout Standard
19076
19077 Switch statements which have gaps in the numeric sequence or those that
19078  have more that 84 case labels can be split into more than one switch statement
19079  for efficient code generation, e.g.:
19080 \layout Verse
19081
19082
19083 \family typewriter 
19084 switch (i) { 
19085 \newline 
19086 \SpecialChar ~
19087 \SpecialChar ~
19088 case 1: ...
19089  
19090 \newline 
19091 \SpecialChar ~
19092 \SpecialChar ~
19093 case 2: ...
19094  
19095 \newline 
19096 \SpecialChar ~
19097 \SpecialChar ~
19098 case 3: ...
19099  
19100 \newline 
19101 \SpecialChar ~
19102 \SpecialChar ~
19103 case 4: ...
19104  
19105 \newline 
19106 \SpecialChar ~
19107 \SpecialChar ~
19108 case 9: ...
19109  
19110 \newline 
19111 \SpecialChar ~
19112 \SpecialChar ~
19113 case 10: ...
19114  
19115 \newline 
19116 \SpecialChar ~
19117 \SpecialChar ~
19118 case 11: ...
19119  
19120 \newline 
19121 \SpecialChar ~
19122 \SpecialChar ~
19123 case 12: ...
19124  
19125 \newline 
19126 }
19127 \layout Standard
19128
19129 If the above switch statement is broken down into two switch statements
19130 \layout Verse
19131
19132
19133 \family typewriter 
19134 switch (i) { 
19135 \newline 
19136 \SpecialChar ~
19137 \SpecialChar ~
19138 case 1: ...
19139  
19140 \newline 
19141 \SpecialChar ~
19142 \SpecialChar ~
19143 case 2: ...
19144  
19145 \newline 
19146 \SpecialChar ~
19147 \SpecialChar ~
19148 case 3: ...
19149  
19150 \newline 
19151 \SpecialChar ~
19152 \SpecialChar ~
19153 case 4: ...
19154  
19155 \newline 
19156 }
19157 \layout Standard
19158
19159 and
19160 \layout Verse
19161
19162
19163 \family typewriter 
19164 switch (i) { 
19165 \newline 
19166 \SpecialChar ~
19167 \SpecialChar ~
19168 case 9:\SpecialChar ~
19169 \SpecialChar ~
19170 ...
19171  
19172 \newline 
19173 \SpecialChar ~
19174 \SpecialChar ~
19175 case 10:\SpecialChar ~
19176 ...
19177  
19178 \newline 
19179 \SpecialChar ~
19180 \SpecialChar ~
19181 case 11:\SpecialChar ~
19182 ...
19183  
19184 \newline 
19185 \SpecialChar ~
19186 \SpecialChar ~
19187 case 12:\SpecialChar ~
19188 ...
19189  
19190 \newline 
19191 }
19192 \layout Standard
19193
19194 then both the switch statements will be implemented using jump-tables whereas
19195  the unmodified switch statement will not be.
19196  You might also consider inserting dummy cases 0 and 5 to 8 in this example.
19197  
19198 \newline 
19199 The pragma nojtbound
19200 \begin_inset LatexCommand \index{\#pragma nojtbound}
19201
19202 \end_inset 
19203
19204  can be used to turn off checking the 
19205 \emph on 
19206 j
19207 \emph default 
19208 ump 
19209 \emph on 
19210 t
19211 \emph default 
19212 able 
19213 \emph on 
19214 bound
19215 \emph default 
19216 aries.
19217  It has no effect if a default label is supplied.
19218  Use of this pragma is dangerous: if the switch argument is not matched
19219  by a case statement the processor will happily jump into Nirvana.
19220 \layout Subsection
19221
19222 Bit-shifting Operations
19223 \begin_inset LatexCommand \index{Bit shifting}
19224
19225 \end_inset 
19226
19227 .
19228 \layout Standard
19229
19230 Bit shifting is one of the most frequently used operation in embedded programmin
19231 g.
19232  SDCC tries to implement bit-shift operations in the most efficient way
19233  possible, e.g.:
19234 \layout Verse
19235
19236
19237 \family typewriter 
19238 unsigned char i;
19239 \newline 
19240 ...
19241  
19242 \newline 
19243 i >>= 4; 
19244 \newline 
19245 ...
19246 \layout Standard
19247
19248 generates the following code:
19249 \layout Verse
19250
19251
19252 \family typewriter 
19253 mov\SpecialChar ~
19254  a,_i 
19255 \newline 
19256 swap a 
19257 \newline 
19258 anl\SpecialChar ~
19259  a,#0x0f 
19260 \newline 
19261 mov\SpecialChar ~
19262  _i,a
19263 \layout Standard
19264
19265 In general SDCC will never setup a loop if the shift count is known.
19266  Another example:
19267 \layout Verse
19268
19269
19270 \family typewriter 
19271 unsigned int i; 
19272 \newline 
19273 ...
19274  
19275 \newline 
19276 i >>= 9; 
19277 \newline 
19278 ...
19279 \layout Standard
19280
19281 will generate:
19282 \layout Verse
19283
19284
19285 \family typewriter 
19286 mov\SpecialChar ~
19287 \SpecialChar ~
19288 a,(_i + 1) 
19289 \newline 
19290 mov\SpecialChar ~
19291 \SpecialChar ~
19292 (_i + 1),#0x00 
19293 \newline 
19294 clr\SpecialChar ~
19295 \SpecialChar ~
19296
19297 \newline 
19298 rrc\SpecialChar ~
19299 \SpecialChar ~
19300
19301 \newline 
19302 mov\SpecialChar ~
19303 \SpecialChar ~
19304 _i,a
19305 \layout Subsection
19306
19307 Bit-rotation
19308 \begin_inset LatexCommand \index{Bit rotation}
19309
19310 \end_inset 
19311
19312
19313 \layout Standard
19314
19315 A special case of the bit-shift operation is bit rotation
19316 \begin_inset LatexCommand \index{rotating bits}
19317
19318 \end_inset 
19319
19320 , SDCC recognizes the following expression to be a left bit-rotation:
19321 \layout Verse
19322
19323
19324 \family typewriter 
19325 \series bold 
19326 unsigned
19327 \series default 
19328 \SpecialChar ~
19329 \SpecialChar ~
19330 char i;\SpecialChar ~
19331 \SpecialChar ~
19332 \SpecialChar ~
19333 \SpecialChar ~
19334 \SpecialChar ~
19335 \SpecialChar ~
19336 \SpecialChar ~
19337 \SpecialChar ~
19338 \SpecialChar ~
19339 \SpecialChar ~
19340 \SpecialChar ~
19341 /* unsigned is needed for rotation */ 
19342 \newline 
19343 ...
19344  
19345 \newline 
19346 i = ((i << 1) | (i >> 7)); 
19347 \family default 
19348
19349 \newline 
19350
19351 \family typewriter 
19352 ...
19353 \layout Standard
19354
19355 will generate the following code:
19356 \layout Verse
19357
19358
19359 \family typewriter 
19360 mov\SpecialChar ~
19361 \SpecialChar ~
19362 a,_i 
19363 \newline 
19364 rl\SpecialChar ~
19365 \SpecialChar ~
19366 \SpecialChar ~
19367
19368 \newline 
19369 mov\SpecialChar ~
19370 \SpecialChar ~
19371 _i,a
19372 \layout Standard
19373
19374 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
19375 ns of this case will also be recognized as bit-rotation, i.e.: 
19376 \layout Verse
19377
19378
19379 \family typewriter 
19380 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
19381 \layout Subsection
19382
19383 Nibble and Byte Swapping
19384 \layout Standard
19385
19386 Other special cases of the bit-shift operations are nibble or byte swapping
19387 \begin_inset LatexCommand \index{swapping nibbles/bytes}
19388
19389 \end_inset 
19390
19391 , SDCC recognizes the following expressions:
19392 \layout Verse
19393
19394
19395 \family typewriter 
19396 \series bold 
19397 unsigned
19398 \series default 
19399 \SpecialChar ~
19400 \SpecialChar ~
19401 char i; 
19402 \newline 
19403
19404 \series bold 
19405 unsigned
19406 \series default 
19407 \SpecialChar ~
19408 \SpecialChar ~
19409 int j; 
19410 \newline 
19411 ...
19412  
19413 \newline 
19414 i = ((i << 4) | (i >> 4)); 
19415 \family default 
19416
19417 \newline 
19418
19419 \family typewriter 
19420 j = ((j << 8) | (j >> 8)); 
19421 \layout Standard
19422
19423 and generates a swap instruction for the nibble swapping
19424 \begin_inset LatexCommand \index{Nibble swapping}
19425
19426 \end_inset 
19427
19428  or move instructions for the byte swapping
19429 \begin_inset LatexCommand \index{Byte swapping}
19430
19431 \end_inset 
19432
19433 .
19434  The 
19435 \begin_inset Quotes sld
19436 \end_inset 
19437
19438 j
19439 \begin_inset Quotes srd
19440 \end_inset 
19441
19442  example can be used to convert from little to big-endian or vice versa.
19443  If you want to change the endianness of a 
19444 \emph on 
19445 signed
19446 \emph default 
19447  integer you have to cast to 
19448 \family typewriter 
19449 (unsigned int)
19450 \family default 
19451  first.
19452 \layout Standard
19453
19454 Note that SDCC stores numbers in little-endian
19455 \begin_inset Foot
19456 collapsed false
19457
19458 \layout Standard
19459
19460 Usually 8-bit processors don't care much about endianness.
19461  This is not the case for the standard 8051 which only has an instruction
19462  to increment its 
19463 \emph on 
19464 dptr
19465 \emph default 
19466
19467 \begin_inset LatexCommand \index{DPTR}
19468
19469 \end_inset 
19470
19471 -datapointer
19472 \emph on 
19473  
19474 \emph default 
19475 so little-endian is the more efficient byte order.
19476 \end_inset 
19477
19478
19479 \begin_inset LatexCommand \index{little-endian}
19480
19481 \end_inset 
19482
19483
19484 \begin_inset LatexCommand \index{Endianness}
19485
19486 \end_inset 
19487
19488  format (i.e.
19489  lowest order first).
19490 \layout Subsection
19491
19492 Highest Order Bit
19493 \begin_inset LatexCommand \index{Highest Order Bit}
19494
19495 \end_inset 
19496
19497
19498 \layout Standard
19499
19500 It is frequently required to obtain the highest order bit of an integral
19501  type (long, int, short or char types).
19502  SDCC recognizes the following expression to yield the highest order bit
19503  and generates optimized code for it, e.g.:
19504 \layout Verse
19505
19506
19507 \family typewriter 
19508 unsigned int gint; 
19509 \newline 
19510
19511 \newline 
19512 foo () { 
19513 \newline 
19514 \SpecialChar ~
19515 \SpecialChar ~
19516 unsigned char hob; 
19517 \newline 
19518 \SpecialChar ~
19519 \SpecialChar ~
19520 ...
19521  
19522 \newline 
19523 \SpecialChar ~
19524 \SpecialChar ~
19525 hob = (gint >> 15) & 1; 
19526 \newline 
19527 \SpecialChar ~
19528 \SpecialChar ~
19529 ..
19530  
19531 \newline 
19532 }
19533 \layout Standard
19534
19535 will generate the following code:
19536 \layout Verse
19537
19538
19539 \family typewriter 
19540 \SpecialChar ~
19541 \SpecialChar ~
19542 \SpecialChar ~
19543 \SpecialChar ~
19544 \SpecialChar ~
19545 \SpecialChar ~
19546 \SpecialChar ~
19547 \SpecialChar ~
19548 \SpecialChar ~
19549 \SpecialChar ~
19550 \SpecialChar ~
19551 \SpecialChar ~
19552 \SpecialChar ~
19553 \SpecialChar ~
19554 \SpecialChar ~
19555 \SpecialChar ~
19556 \SpecialChar ~
19557 \SpecialChar ~
19558 \SpecialChar ~
19559 \SpecialChar ~
19560 \SpecialChar ~
19561 \SpecialChar ~
19562 \SpecialChar ~
19563 \SpecialChar ~
19564 \SpecialChar ~
19565  61 ;\SpecialChar ~
19566  hob.c 7 
19567 \newline 
19568 000A E5*01\SpecialChar ~
19569 \SpecialChar ~
19570 \SpecialChar ~
19571 \SpecialChar ~
19572 \SpecialChar ~
19573 \SpecialChar ~
19574 \SpecialChar ~
19575 \SpecialChar ~
19576 \SpecialChar ~
19577 \SpecialChar ~
19578 \SpecialChar ~
19579 \SpecialChar ~
19580 \SpecialChar ~
19581 \SpecialChar ~
19582 \SpecialChar ~
19583  62\SpecialChar ~
19584 \SpecialChar ~
19585 \SpecialChar ~
19586 \SpecialChar ~
19587 \SpecialChar ~
19588 \SpecialChar ~
19589 \SpecialChar ~
19590 \SpecialChar ~
19591  mov\SpecialChar ~
19592 \SpecialChar ~
19593  a,(_gint + 1) 
19594 \newline 
19595 000C 23\SpecialChar ~
19596 \SpecialChar ~
19597 \SpecialChar ~
19598 \SpecialChar ~
19599 \SpecialChar ~
19600 \SpecialChar ~
19601 \SpecialChar ~
19602 \SpecialChar ~
19603 \SpecialChar ~
19604 \SpecialChar ~
19605 \SpecialChar ~
19606 \SpecialChar ~
19607 \SpecialChar ~
19608 \SpecialChar ~
19609 \SpecialChar ~
19610 \SpecialChar ~
19611 \SpecialChar ~
19612 \SpecialChar ~
19613  63\SpecialChar ~
19614 \SpecialChar ~
19615 \SpecialChar ~
19616 \SpecialChar ~
19617 \SpecialChar ~
19618 \SpecialChar ~
19619 \SpecialChar ~
19620 \SpecialChar ~
19621  rl\SpecialChar ~
19622 \SpecialChar ~
19623 \SpecialChar ~
19624  a 
19625 \newline 
19626 000D 54 01\SpecialChar ~
19627 \SpecialChar ~
19628 \SpecialChar ~
19629 \SpecialChar ~
19630 \SpecialChar ~
19631 \SpecialChar ~
19632 \SpecialChar ~
19633 \SpecialChar ~
19634 \SpecialChar ~
19635 \SpecialChar ~
19636 \SpecialChar ~
19637 \SpecialChar ~
19638 \SpecialChar ~
19639 \SpecialChar ~
19640 \SpecialChar ~
19641  64\SpecialChar ~
19642 \SpecialChar ~
19643 \SpecialChar ~
19644 \SpecialChar ~
19645 \SpecialChar ~
19646 \SpecialChar ~
19647 \SpecialChar ~
19648 \SpecialChar ~
19649  anl\SpecialChar ~
19650 \SpecialChar ~
19651  a,#0x01 
19652 \newline 
19653 000F F5*02\SpecialChar ~
19654 \SpecialChar ~
19655 \SpecialChar ~
19656 \SpecialChar ~
19657 \SpecialChar ~
19658 \SpecialChar ~
19659 \SpecialChar ~
19660 \SpecialChar ~
19661 \SpecialChar ~
19662 \SpecialChar ~
19663 \SpecialChar ~
19664 \SpecialChar ~
19665 \SpecialChar ~
19666 \SpecialChar ~
19667 \SpecialChar ~
19668  65\SpecialChar ~
19669 \SpecialChar ~
19670 \SpecialChar ~
19671 \SpecialChar ~
19672 \SpecialChar ~
19673 \SpecialChar ~
19674 \SpecialChar ~
19675 \SpecialChar ~
19676  mov\SpecialChar ~
19677 \SpecialChar ~
19678  _foo_hob_1_1,a
19679 \layout Standard
19680
19681 Variations of this case however will 
19682 \emph on 
19683 not
19684 \emph default 
19685  be recognized.
19686  It is a standard C expression, so I heartily recommend this be the only
19687  way to get the highest order bit, (it is portable).
19688  Of course it will be recognized even if it is embedded in other expressions,
19689  e.g.:
19690 \layout Verse
19691
19692
19693 \family typewriter 
19694 xyz = gint + ((gint >> 15) & 1);
19695 \layout Standard
19696
19697 will still be recognized.
19698 \layout Subsection
19699
19700 Peephole Optimizer
19701 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
19702
19703 \end_inset 
19704
19705
19706 \begin_inset LatexCommand \index{Peephole optimizer}
19707
19708 \end_inset 
19709
19710
19711 \layout Standard
19712
19713 The compiler uses a rule based, pattern matching and re-writing mechanism
19714  for peep-hole optimization.
19715  It is inspired by 
19716 \emph on 
19717 copt
19718 \emph default 
19719  a peep-hole optimizer by Christopher W.
19720  Fraser (cwfraser@microsoft.com).
19721  A default set of rules are compiled into the compiler, additional rules
19722  may be added with the 
19723 \emph on 
19724 -
19725 \begin_inset ERT
19726 status Collapsed
19727
19728 \layout Standard
19729
19730 \backslash 
19731 /
19732 \end_inset 
19733
19734 -peep-file
19735 \begin_inset LatexCommand \index{-\/-peep-file}
19736
19737 \end_inset 
19738
19739  <filename>
19740 \emph default 
19741  option.
19742  The rule language is best illustrated with examples.
19743 \layout Verse
19744
19745
19746 \family typewriter 
19747 replace { 
19748 \newline 
19749 \SpecialChar ~
19750 \SpecialChar ~
19751 mov %1,a 
19752 \newline 
19753 \SpecialChar ~
19754 \SpecialChar ~
19755 mov a,%1
19756 \newline 
19757 } by {
19758 \newline 
19759 \SpecialChar ~
19760 \SpecialChar ~
19761 mov %1,a
19762 \newline 
19763 }
19764 \layout Standard
19765
19766 The above rule will change the following assembly
19767 \begin_inset LatexCommand \index{Assembler routines}
19768
19769 \end_inset 
19770
19771  sequence:
19772 \layout Verse
19773
19774
19775 \family typewriter 
19776 mov r1,a 
19777 \newline 
19778 mov a,r1
19779 \layout Standard
19780
19781 to
19782 \layout Verse
19783
19784
19785 \family typewriter 
19786 mov r1,a
19787 \layout Standard
19788
19789 Note: All occurrences of a 
19790 \emph on 
19791 %n
19792 \emph default 
19793  (pattern variable) must denote the same string.
19794  With the above rule, the assembly sequence:
19795 \layout Verse
19796
19797
19798 \family typewriter 
19799 mov r1,a 
19800 \newline 
19801 mov a,r2
19802 \layout Standard
19803
19804 will remain unmodified.
19805 \newline 
19806
19807 \newline 
19808 Other special case optimizations may be added by the user (via 
19809 \emph on 
19810 -
19811 \begin_inset ERT
19812 status Collapsed
19813
19814 \layout Standard
19815
19816 \backslash 
19817 /
19818 \end_inset 
19819
19820 -peep-file option
19821 \emph default 
19822 ).
19823  E.g.
19824  some variants of the 8051 MCU allow only 
19825 \family typewriter 
19826 ajmp
19827 \family default 
19828  and 
19829 \family typewriter 
19830 acall
19831 \family default 
19832 .
19833  The following two rules will change all 
19834 \family typewriter 
19835 ljmp
19836 \family default 
19837  and 
19838 \family typewriter 
19839 lcall
19840 \family default 
19841  to 
19842 \family typewriter 
19843 ajmp
19844 \family default 
19845  and 
19846 \family typewriter 
19847 acall
19848 \layout Verse
19849
19850
19851 \family typewriter 
19852 replace { lcall %1 } by { acall %1 } 
19853 \newline 
19854 replace { ljmp %1 } by { ajmp %1 }
19855 \layout Standard
19856
19857 The 
19858 \emph on 
19859 inline-assembler code
19860 \emph default 
19861  is also passed through the peep hole optimizer, thus the peephole optimizer
19862  can also be used as an assembly level macro expander.
19863  The rules themselves are MCU dependent whereas the rule language infra-structur
19864 e is MCU independent.
19865  Peephole optimization rules for other MCU can be easily programmed using
19866  the rule language.
19867 \newline 
19868
19869 \newline 
19870 The syntax for a rule is as follows:
19871 \layout Verse
19872
19873
19874 \family typewriter 
19875 rule := replace [ restart ] '{' <assembly sequence> '
19876 \backslash 
19877 n' 
19878 \newline 
19879 \SpecialChar ~
19880  \SpecialChar ~
19881  \SpecialChar ~
19882  \SpecialChar ~
19883  \SpecialChar ~
19884  \SpecialChar ~
19885  \SpecialChar ~
19886  \SpecialChar ~
19887  \SpecialChar ~
19888  \SpecialChar ~
19889  \SpecialChar ~
19890  \SpecialChar ~
19891  \SpecialChar ~
19892  \SpecialChar ~
19893  '}' by '{' '
19894 \backslash 
19895 n' 
19896 \newline 
19897 \SpecialChar ~
19898  \SpecialChar ~
19899  \SpecialChar ~
19900  \SpecialChar ~
19901  \SpecialChar ~
19902  \SpecialChar ~
19903  \SpecialChar ~
19904  \SpecialChar ~
19905  \SpecialChar ~
19906  \SpecialChar ~
19907  \SpecialChar ~
19908  \SpecialChar ~
19909  \SpecialChar ~
19910  \SpecialChar ~
19911  \SpecialChar ~
19912  \SpecialChar ~
19913  <assembly sequence> '
19914 \backslash 
19915 n' 
19916 \newline 
19917 \SpecialChar ~
19918  \SpecialChar ~
19919  \SpecialChar ~
19920  \SpecialChar ~
19921  \SpecialChar ~
19922  \SpecialChar ~
19923  \SpecialChar ~
19924  \SpecialChar ~
19925  \SpecialChar ~
19926  \SpecialChar ~
19927  \SpecialChar ~
19928  \SpecialChar ~
19929  \SpecialChar ~
19930  \SpecialChar ~
19931  '}' [if <functionName> ] '
19932 \backslash 
19933 n' 
19934 \layout Standard
19935
19936 <assembly sequence> := assembly instruction (each instruction including
19937  labels must be on a separate line).
19938 \newline 
19939
19940 \newline 
19941 The optimizer will apply to the rules one by one from the top in the sequence
19942  of their appearance, it will terminate when all rules are exhausted.
19943  If the 'restart' option is specified, then the optimizer will start matching
19944  the rules again from the top, this option for a rule is expensive (performance)
19945 , it is intended to be used in situations where a transformation will trigger
19946  the same rule again.
19947  An example of this (not a good one, it has side effects) is the following
19948  rule:
19949 \layout Verse
19950
19951
19952 \family typewriter 
19953 replace restart { 
19954 \newline 
19955 \SpecialChar ~
19956 \SpecialChar ~
19957 pop %1 
19958 \newline 
19959 \SpecialChar ~
19960 \SpecialChar ~
19961 push %1 } by { 
19962 \newline 
19963 \SpecialChar ~
19964 \SpecialChar ~
19965 ; nop 
19966 \newline 
19967 }
19968 \layout Standard
19969
19970 Note that the replace pattern cannot be a blank, but can be a comment line.
19971  Without the 'restart' option only the innermost 'pop' 'push' pair would
19972  be eliminated, i.e.:
19973 \layout Verse
19974
19975
19976 \family typewriter 
19977 pop ar1 
19978 \newline 
19979 pop ar2 
19980 \newline 
19981 push ar2 
19982 \newline 
19983 push ar1
19984 \layout Standard
19985
19986 would result in:
19987 \layout Verse
19988
19989
19990 \family typewriter 
19991 pop ar1 
19992 \newline 
19993 ; nop 
19994 \newline 
19995 push ar1
19996 \layout Standard
19997
19998
19999 \emph on 
20000 with
20001 \emph default 
20002  the restart option the rule will be applied again to the resulting code
20003  and then all the pop-push pairs will be eliminated to yield:
20004 \layout Verse
20005
20006
20007 \family typewriter 
20008 ; nop 
20009 \newline 
20010 ; nop
20011 \layout Standard
20012
20013 A conditional function can be attached to a rule.
20014  Attaching rules are somewhat more involved, let me illustrate this with
20015  an example.
20016 \layout Verse
20017
20018
20019 \family typewriter 
20020 replace { 
20021 \newline 
20022 \SpecialChar ~
20023  \SpecialChar ~
20024  \SpecialChar ~
20025 ljmp %5 
20026 \newline 
20027 %2:
20028 \newline 
20029 } by { 
20030 \newline 
20031 \SpecialChar ~
20032  \SpecialChar ~
20033  \SpecialChar ~
20034 sjmp %5 
20035 \newline 
20036 %2:
20037 \newline 
20038 } if labelInRange
20039 \layout Standard
20040
20041 The optimizer does a look-up of a function name table defined in function
20042  
20043 \emph on 
20044 callFuncByName
20045 \emph default 
20046  in the source file SDCCpeeph.c, with the name 
20047 \emph on 
20048 labelInRange
20049 \emph default 
20050 .
20051  If it finds a corresponding entry the function is called.
20052  Note there can be no parameters specified for these functions, in this
20053  case the use of 
20054 \emph on 
20055 %5
20056 \emph default 
20057  is crucial, since the function 
20058 \emph on 
20059 labelInRange
20060 \emph default 
20061  expects to find the label in that particular variable (the hash table containin
20062 g the variable bindings is passed as a parameter).
20063  If you want to code more such functions, take a close look at the function
20064  labelInRange and the calling mechanism in source file SDCCpeeph.c.
20065  Currently implemented are 
20066 \emph on 
20067 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
20068  24bitMode, portIsDS390, 24bitModeAndPortDS390 
20069 \emph default 
20070 and
20071 \emph on 
20072  notVolatile
20073 \emph default 
20074 .
20075 \layout Standard
20076
20077 I know this whole thing is a little kludgey, but maybe some day we will
20078  have some better means.
20079  If you are looking at this file, you will see the default rules that are
20080  compiled into the compiler, you can add your own rules in the default set
20081  there if you get tired of specifying the -
20082 \begin_inset ERT
20083 status Collapsed
20084
20085 \layout Standard
20086
20087 \backslash 
20088 /
20089 \end_inset 
20090
20091 -peep-file option.
20092 \layout Section
20093
20094 ANSI-Compliance
20095 \begin_inset LatexCommand \index{ANSI-compliance}
20096
20097 \end_inset 
20098
20099
20100 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
20101
20102 \end_inset 
20103
20104
20105 \layout Standard
20106
20107 Deviations from the compliance:
20108 \layout Itemize
20109
20110 functions are not always reentrant
20111 \begin_inset LatexCommand \index{reentrant}
20112
20113 \end_inset 
20114
20115 .
20116 \layout Itemize
20117
20118 structures cannot be assigned values directly, cannot be passed as function
20119  parameters or assigned to each other and cannot be a return value from
20120  a function, e.g.:
20121 \begin_deeper 
20122 \layout Verse
20123
20124
20125 \family typewriter 
20126 struct s { ...
20127  }; 
20128 \newline 
20129 struct s s1, s2; 
20130 \newline 
20131 foo() 
20132 \newline 
20133
20134 \newline 
20135 \SpecialChar ~
20136 \SpecialChar ~
20137 \SpecialChar ~
20138 \SpecialChar ~
20139 ...
20140  
20141 \newline 
20142 \SpecialChar ~
20143 \SpecialChar ~
20144 \SpecialChar ~
20145 \SpecialChar ~
20146 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
20147 \newline 
20148 \SpecialChar ~
20149 \SpecialChar ~
20150 \SpecialChar ~
20151 \SpecialChar ~
20152 ...
20153  
20154 \newline 
20155 }
20156 \newline 
20157 struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
20158  */
20159 \newline 
20160
20161 \newline 
20162 \SpecialChar ~
20163 \SpecialChar ~
20164 \SpecialChar ~
20165 \SpecialChar ~
20166 struct s rets; 
20167 \newline 
20168 \SpecialChar ~
20169 \SpecialChar ~
20170 \SpecialChar ~
20171 \SpecialChar ~
20172 ...
20173  
20174 \newline 
20175 \SpecialChar ~
20176 \SpecialChar ~
20177 \SpecialChar ~
20178 \SpecialChar ~
20179 return rets;/* is invalid in SDCC although allowed in ANSI */ 
20180 \newline 
20181 }
20182 \end_deeper 
20183 \layout Itemize
20184
20185 'long long
20186 \begin_inset LatexCommand \index{long long (not supported)}
20187
20188 \end_inset 
20189
20190 ' (64 bit integers
20191 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
20192
20193 \end_inset 
20194
20195 ) not supported.
20196 \layout Itemize
20197
20198 'double
20199 \begin_inset LatexCommand \index{double (not supported)}
20200
20201 \end_inset 
20202
20203 ' precision floating point 
20204 \begin_inset LatexCommand \index{Floating point support}
20205
20206 \end_inset 
20207
20208 not supported.
20209 \layout Itemize
20210
20211 No support for setjmp
20212 \begin_inset LatexCommand \index{setjmp (not supported)}
20213
20214 \end_inset 
20215
20216  and longjmp
20217 \begin_inset LatexCommand \index{longjmp (not supported)}
20218
20219 \end_inset 
20220
20221  (for now).
20222 \layout Itemize
20223
20224 Old K&R style
20225 \begin_inset LatexCommand \index{K\&R style}
20226
20227 \end_inset 
20228
20229  function declarations are NOT allowed.
20230 \begin_deeper 
20231 \layout Verse
20232
20233
20234 \family typewriter 
20235 foo(i,j) /* this old style of function declarations */ 
20236 \newline 
20237 int i,j; /* are valid in ANSI but not valid in SDCC */ 
20238 \newline 
20239
20240 \newline 
20241 \SpecialChar ~
20242 \SpecialChar ~
20243 \SpecialChar ~
20244 \SpecialChar ~
20245 ...
20246  
20247 \newline 
20248 }
20249 \end_deeper 
20250 \layout Itemize
20251
20252 functions declared as pointers
20253 \begin_inset LatexCommand \index{Pointer (to function)}
20254
20255 \end_inset 
20256
20257
20258 \begin_inset LatexCommand \index{function pointers}
20259
20260 \end_inset 
20261
20262  must be dereferenced during the call.
20263 \begin_deeper 
20264 \layout Verse
20265
20266
20267 \family typewriter 
20268 int (*foo)();
20269 \newline 
20270 ...
20271  
20272 \newline 
20273 /* has to be called like this */ 
20274 \newline 
20275 (*foo)(); /* ANSI standard allows calls to be made like 'foo()' */
20276 \end_deeper 
20277 \layout Section
20278
20279 Cyclomatic Complexity
20280 \begin_inset LatexCommand \index{Cyclomatic complexity}
20281
20282 \end_inset 
20283
20284
20285 \layout Standard
20286
20287 Cyclomatic complexity of a function is defined as the number of independent
20288  paths the program can take during execution of the function.
20289  This is an important number since it defines the number test cases you
20290  have to generate to validate the function.
20291  The accepted industry standard for complexity number is 10, if the cyclomatic
20292  complexity reported by SDCC exceeds 10 you should think about simplification
20293  of the function logic.
20294  Note that the complexity level is not related to the number of lines of
20295  code in a function.
20296  Large functions can have low complexity, and small functions can have large
20297  complexity levels.
20298  
20299 \newline 
20300
20301 \newline 
20302 SDCC uses the following formula to compute the complexity:
20303 \newline 
20304
20305 \layout Standard
20306
20307 complexity = (number of edges in control flow graph) - (number of nodes
20308  in control flow graph) + 2;
20309 \newline 
20310
20311 \newline 
20312 Having said that the industry standard is 10, you should be aware that in
20313  some cases it be may unavoidable to have a complexity level of less than
20314  10.
20315  For example if you have switch statement with more than 10 case labels,
20316  each case label adds one to the complexity level.
20317  The complexity level is by no means an absolute measure of the algorithmic
20318  complexity of the function, it does however provide a good starting point
20319  for which functions you might look at for further optimization.
20320 \layout Section
20321
20322 Retargetting for other Processors
20323 \layout Standard
20324
20325 The issues for retargetting the compiler are far too numerous to be covered
20326  by this document.
20327  What follows is a brief description of each of the seven phases of the
20328  compiler and its MCU dependency.
20329 \layout Itemize
20330
20331 Parsing the source and building the annotated parse tree.
20332  This phase is largely MCU independent (except for the language extensions).
20333  Syntax & semantic checks are also done in this phase, along with some initial
20334  optimizations like back patching labels and the pattern matching optimizations
20335  like bit-rotation etc.
20336 \layout Itemize
20337
20338 The second phase involves generating an intermediate code which can be easy
20339  manipulated during the later phases.
20340  This phase is entirely MCU independent.
20341  The intermediate code generation assumes the target machine has unlimited
20342  number of registers, and designates them with the name iTemp.
20343  The compiler can be made to dump a human readable form of the code generated
20344  by using the -
20345 \begin_inset ERT
20346 status Collapsed
20347
20348 \layout Standard
20349
20350 \backslash 
20351 /
20352 \end_inset 
20353
20354 -dumpraw option.
20355 \layout Itemize
20356
20357 This phase does the bulk of the standard optimizations and is also MCU independe
20358 nt.
20359  This phase can be broken down into several sub-phases:
20360 \newline 
20361
20362 \newline 
20363 Break down intermediate code (iCode) into basic blocks.
20364 \newline 
20365 Do control flow & data flow analysis on the basic blocks.
20366 \newline 
20367 Do local common subexpression elimination, then global subexpression elimination
20368 \newline 
20369 Dead code elimination
20370 \newline 
20371 Loop optimizations
20372 \newline 
20373 If loop optimizations caused any changes then do 'global subexpression eliminati
20374 on' and 'dead code elimination' again.
20375 \layout Itemize
20376
20377 This phase determines the live-ranges; by live range I mean those iTemp
20378  variables defined by the compiler that still survive after all the optimization
20379 s.
20380  Live range analysis
20381 \begin_inset LatexCommand \index{Live range analysis}
20382
20383 \end_inset 
20384
20385  is essential for register allocation, since these computation determines
20386  which of these iTemps will be assigned to registers, and for how long.
20387 \layout Itemize
20388
20389 Phase five is register allocation.
20390  There are two parts to this process.
20391 \newline 
20392
20393 \newline 
20394 The first part I call 'register packing' (for lack of a better term).
20395  In this case several MCU specific expression folding is done to reduce
20396  register pressure.
20397 \newline 
20398
20399 \newline 
20400 The second part is more MCU independent and deals with allocating registers
20401  to the remaining live ranges.
20402  A lot of MCU specific code does creep into this phase because of the limited
20403  number of index registers available in the 8051.
20404 \layout Itemize
20405
20406 The Code generation phase is (unhappily), entirely MCU dependent and very
20407  little (if any at all) of this code can be reused for other MCU.
20408  However the scheme for allocating a homogenized assembler operand for each
20409  iCode operand may be reused.
20410 \layout Itemize
20411
20412 As mentioned in the optimization section the peep-hole optimizer is rule
20413  based system, which can reprogrammed for other MCUs.
20414 \layout Chapter
20415
20416 Compiler internals
20417 \begin_inset LatexCommand \index{Compiler internals}
20418
20419 \end_inset 
20420
20421
20422 \layout Section
20423
20424 The anatomy of the compiler
20425 \begin_inset LatexCommand \label{sub:The-anatomy-of}
20426
20427 \end_inset 
20428
20429
20430 \layout Standard
20431
20432
20433 \shape italic 
20434 This is an excerpt from an article published in Circuit Cellar Magazine
20435  in august 2000.
20436  It's a little outdated (the compiler is much more efficient now and user/develo
20437 per friendly), but pretty well exposes the guts of it all.
20438 \shape default 
20439
20440 \newline 
20441
20442 \newline 
20443 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
20444  It is fairly easy to retarget for other 8-bit MCU.
20445  Here we take a look at some of the internals of the compiler.
20446  
20447 \layout Paragraph*
20448
20449 Parsing
20450 \begin_inset LatexCommand \index{Parsing}
20451
20452 \end_inset 
20453
20454  
20455 \layout Standard
20456
20457 Parsing the input source file and creating an AST (Annotated Syntax Tree
20458 \begin_inset LatexCommand \index{Annotated syntax tree}
20459
20460 \end_inset 
20461
20462 ).
20463  This phase also involves propagating types (annotating each node of the
20464  parse tree with type information) and semantic analysis.
20465  There are some MCU specific parsing rules.
20466  For example the storage classes, the extended storage classes are MCU specific
20467  while there may be a xdata storage class for 8051 there is no such storage
20468  class for z80 or Atmel AVR.
20469  SDCC allows MCU specific storage class extensions, i.e.
20470  xdata will be treated as a storage class specifier when parsing 8051 C
20471  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
20472  C code.
20473 \layout Paragraph*
20474
20475 Generating iCode
20476 \begin_inset LatexCommand \index{iCode}
20477
20478 \end_inset 
20479
20480
20481 \layout Standard
20482
20483 Intermediate code generation.
20484  In this phase the AST is broken down into three-operand form (iCode).
20485  These three operand forms are represented as doubly linked lists.
20486  ICode is the term given to the intermediate form generated by the compiler.
20487  ICode example section shows some examples of iCode generated for some simple
20488  C source functions.
20489 \layout Paragraph*
20490
20491 Optimizations
20492 \begin_inset LatexCommand \index{Optimizations}
20493
20494 \end_inset 
20495
20496 .
20497 \layout Standard
20498
20499 Bulk of the target independent optimizations is performed in this phase.
20500  The optimizations include constant propagation, common sub-expression eliminati
20501 on, loop invariant code movement, strength reduction of loop induction variables
20502  and dead-code elimination.
20503 \layout Paragraph*
20504
20505 Live range analysis
20506 \begin_inset LatexCommand \index{Live range analysis}
20507
20508 \end_inset 
20509
20510
20511 \layout Standard
20512
20513 During intermediate code generation phase, the compiler assumes the target
20514  machine has infinite number of registers and generates a lot of temporary
20515  variables.
20516  The live range computation determines the lifetime of each of these compiler-ge
20517 nerated temporaries.
20518  A picture speaks a thousand words.
20519  ICode example sections show the live range annotations for each of the
20520  operand.
20521  It is important to note here, each iCode is assigned a number in the order
20522  of its execution in the function.
20523  The live ranges are computed in terms of these numbers.
20524  The from number is the number of the iCode which first defines the operand
20525  and the to number signifies the iCode which uses this operand last.
20526 \layout Paragraph*
20527
20528 Register Allocation
20529 \begin_inset LatexCommand \index{Register allocation}
20530
20531 \end_inset 
20532
20533
20534 \layout Standard
20535
20536 The register allocation determines the type and number of registers needed
20537  by each operand.
20538  In most MCUs only a few registers can be used for indirect addressing.
20539  In case of 8051 for example the registers R0 & R1 can be used to indirectly
20540  address the internal ram and DPTR to indirectly address the external ram.
20541  The compiler will try to allocate the appropriate register to pointer variables
20542  if it can.
20543  ICode example section shows the operands annotated with the registers assigned
20544  to them.
20545  The compiler will try to keep operands in registers as much as possible;
20546  there are several schemes the compiler uses to do achieve this.
20547  When the compiler runs out of registers the compiler will check to see
20548  if there are any live operands which is not used or defined in the current
20549  basic block being processed, if there are any found then it will push that
20550  operand and use the registers in this block, the operand will then be popped
20551  at the end of the basic block.
20552  
20553 \layout Standard
20554
20555 There are other MCU specific considerations in this phase.
20556  Some MCUs have an accumulator; very short-lived operands could be assigned
20557  to the accumulator instead of a general-purpose register.
20558 \layout Paragraph*
20559
20560 Code generation
20561 \layout Standard
20562
20563 Figure II gives a table of iCode operations supported by the compiler.
20564  The code generation involves translating these operations into corresponding
20565  assembly code for the processor.
20566  This sounds overly simple but that is the essence of code generation.
20567  Some of the iCode operations are generated on a MCU specific manner for
20568  example, the z80 port does not use registers to pass parameters so the
20569  SEND and RECV iCode operations will not be generated, and it also does
20570  not support JUMPTABLES.
20571  
20572 \newline 
20573
20574 \series bold 
20575 \shape italic 
20576 \color red
20577 <Where is Figure II ?>
20578 \layout Paragraph*
20579
20580 ICode Example
20581 \begin_inset LatexCommand \index{iCode}
20582
20583 \end_inset 
20584
20585
20586 \layout Standard
20587
20588 This section shows some details of iCode.
20589  The example C code does not do anything useful; it is used as an example
20590  to illustrate the intermediate code generated by the compiler.
20591 \layout Verse
20592
20593
20594 \family typewriter 
20595 1.\SpecialChar ~
20596 xdata int * p;
20597 \newline 
20598 2.\SpecialChar ~
20599 int gint;
20600 \newline 
20601 3.\SpecialChar ~
20602 /* This function does nothing useful.
20603  It is used
20604 \newline 
20605 4.\SpecialChar ~
20606 \SpecialChar ~
20607 \SpecialChar ~
20608 \SpecialChar ~
20609 for the purpose of explaining iCode */
20610 \newline 
20611 5.\SpecialChar ~
20612 short function (data int *x)
20613 \newline 
20614 6.\SpecialChar ~
20615 {
20616 \newline 
20617 7.\SpecialChar ~
20618 \SpecialChar ~
20619 \SpecialChar ~
20620 short i=10; \SpecialChar ~
20621 \SpecialChar ~
20622 /* dead initialization eliminated */
20623 \newline 
20624 8.\SpecialChar ~
20625 \SpecialChar ~
20626 \SpecialChar ~
20627 short sum=10; /* dead initialization eliminated */
20628 \newline 
20629 9.\SpecialChar ~
20630 \SpecialChar ~
20631 \SpecialChar ~
20632 short mul;
20633 \newline 
20634 10.\SpecialChar ~
20635 \SpecialChar ~
20636 int j ;
20637 \newline 
20638 11.\SpecialChar ~
20639 \SpecialChar ~
20640 while (*x) *x++ = *p++; 
20641 \newline 
20642 12.\SpecialChar ~
20643 \SpecialChar ~
20644 \SpecialChar ~
20645 \SpecialChar ~
20646 sum = 0 ; 
20647 \newline 
20648 13.\SpecialChar ~
20649 \SpecialChar ~
20650 mul = 0;
20651 \newline 
20652 14.\SpecialChar ~
20653 \SpecialChar ~
20654 /* compiler detects i,j to be induction variables */
20655 \newline 
20656 15.\SpecialChar ~
20657 \SpecialChar ~
20658 for (i = 0, j = 10 ; i < 10 ; i++, j
20659 \family default 
20660 -
20661 \begin_inset ERT
20662 status Collapsed
20663
20664 \layout Standard
20665
20666 \backslash 
20667 /
20668 \end_inset 
20669
20670 -
20671 \family typewriter 
20672 ) {
20673 \newline 
20674 16.\SpecialChar ~
20675 \SpecialChar ~
20676 \SpecialChar ~
20677 \SpecialChar ~
20678 sum += i;
20679 \newline 
20680 17.\SpecialChar ~
20681 \SpecialChar ~
20682 \SpecialChar ~
20683 \SpecialChar ~
20684 mul += i * 3; \SpecialChar ~
20685 \SpecialChar ~
20686 /* this multiplication remains */
20687 \newline 
20688 18.\SpecialChar ~
20689 \SpecialChar ~
20690 \SpecialChar ~
20691 \SpecialChar ~
20692 gint += j * 3;\SpecialChar ~
20693 \SpecialChar ~
20694 /* this multiplication changed to addition */
20695 \newline 
20696 19.\SpecialChar ~
20697 \SpecialChar ~
20698 }
20699 \newline 
20700 20.\SpecialChar ~
20701 \SpecialChar ~
20702 return sum+mul;
20703 \newline 
20704 21.\SpecialChar ~
20705 }
20706 \layout Standard
20707
20708 In addition to the operands each iCode contains information about the filename
20709  and line it corresponds to in the source file.
20710  The first field in the listing should be interpreted as follows:
20711 \newline 
20712
20713 \shape italic 
20714 \size footnotesize 
20715 Filename(linenumber: iCode Execution sequence number : ICode hash table
20716  key : loop depth of the iCode).
20717 \shape default 
20718 \size default 
20719
20720 \newline 
20721 Then follows the human readable form of the ICode operation.
20722  Each operand of this triplet form can be of three basic types a) compiler
20723  generated temporary b) user defined variable c) a constant value.
20724  Note that local variables and parameters are replaced by compiler generated
20725  temporaries.
20726  Live ranges
20727 \begin_inset LatexCommand \index{Live range analysis}
20728
20729 \end_inset 
20730
20731  are computed only for temporaries (i.e.
20732  live ranges are not computed for global variables).
20733  Registers
20734 \begin_inset LatexCommand \index{Register allocation}
20735
20736 \end_inset 
20737
20738  are allocated for temporaries only.
20739  Operands are formatted in the following manner:
20740 \newline 
20741
20742 \shape italic 
20743 \size footnotesize 
20744 Operand Name [lr live-from : live-to ] { type information } [ registers
20745  allocated ].
20746 \shape default 
20747 \size default 
20748
20749 \newline 
20750 As mentioned earlier the live ranges are computed in terms of the execution
20751  sequence number of the iCodes, for example 
20752 \newline 
20753 the iTemp0 is live from (i.e.
20754  first defined in iCode with execution sequence number 3, and is last used
20755  in the iCode with sequence number 5).
20756  For induction variables such as iTemp21 the live range computation extends
20757  the lifetime from the start to the end of the loop.
20758 \newline 
20759 The register allocator used the live range information to allocate registers,
20760  the same registers may be used for different temporaries if their live
20761  ranges do not overlap, for example r0 is allocated to both iTemp6 and to
20762  iTemp17 since their live ranges do not overlap.
20763  In addition the allocator also takes into consideration the type and usage
20764  of a temporary, for example itemp6 is a pointer to near space and is used
20765  as to fetch data from (i.e.
20766  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
20767  Some short lived temporaries are allocated to special registers which have
20768  meaning to the code generator e.g.
20769  iTemp13 is allocated to a pseudo register CC which tells the back end that
20770  the temporary is used only for a conditional jump the code generation makes
20771  use of this information to optimize a compare and jump ICode.
20772 \newline 
20773 There are several loop optimizations
20774 \begin_inset LatexCommand \index{Loop optimization}
20775
20776 \end_inset 
20777
20778  performed by the compiler.
20779  It can detect induction variables iTemp21(i) and iTemp23(j).
20780  Also note the compiler does selective strength reduction
20781 \begin_inset LatexCommand \index{Strength reduction}
20782
20783 \end_inset 
20784
20785 , i.e.
20786  the multiplication of an induction variable in line 18 (gint = j * 3) is
20787  changed to addition, a new temporary iTemp17 is allocated and assigned
20788  a initial value, a constant 3 is then added for each iteration of the loop.
20789  The compiler does not change the multiplication
20790 \begin_inset LatexCommand \index{Multiplication}
20791
20792 \end_inset 
20793
20794  in line 17 however since the processor does support an 8 * 8 bit multiplication.
20795 \newline 
20796 Note the dead code elimination
20797 \begin_inset LatexCommand \index{Dead-code elimination}
20798
20799 \end_inset 
20800
20801  optimization eliminated the dead assignments in line 7 & 8 to I and sum
20802  respectively.
20803 \newline 
20804
20805 \layout Standard
20806
20807
20808 \size footnotesize 
20809 Sample.c (5:1:0:0) _entry($9) :
20810 \layout Standard
20811
20812
20813 \size footnotesize 
20814 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
20815 \layout Standard
20816
20817
20818 \size footnotesize 
20819 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
20820 \layout Standard
20821
20822
20823 \size footnotesize 
20824 Sample.c(11:4:53:0) preHeaderLbl0($11) :
20825 \layout Standard
20826
20827
20828 \size footnotesize 
20829 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
20830  * int}[r2]
20831 \layout Standard
20832
20833
20834 \size footnotesize 
20835 Sample.c(11:6:5:1) _whilecontinue_0($1) :
20836 \layout Standard
20837
20838
20839 \size footnotesize 
20840 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
20841  int}[r0]]
20842 \layout Standard
20843
20844
20845 \size footnotesize 
20846 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
20847 \layout Standard
20848
20849
20850 \size footnotesize 
20851 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
20852  * int}
20853 \layout Standard
20854
20855
20856 \size footnotesize 
20857 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
20858  {short}
20859 \layout Standard
20860
20861
20862 \size footnotesize 
20863 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
20864  * int}[DPTR]]
20865 \layout Standard
20866
20867
20868 \size footnotesize 
20869 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
20870 }[r2 r3]
20871 \layout Standard
20872
20873
20874 \size footnotesize 
20875 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
20876  * int}[r0] + 0x2 {short}
20877 \layout Standard
20878
20879
20880 \size footnotesize 
20881 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
20882 \layout Standard
20883
20884
20885 \size footnotesize 
20886 Sample.c(11:17:21:0)_whilebreak_0($3) :
20887 \layout Standard
20888
20889
20890 \size footnotesize 
20891 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
20892 \layout Standard
20893
20894
20895 \size footnotesize 
20896 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
20897 \layout Standard
20898
20899
20900 \size footnotesize 
20901 Sample.c(15:20:54:0)preHeaderLbl1($13) :
20902 \layout Standard
20903
20904
20905 \size footnotesize 
20906 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
20907 \layout Standard
20908
20909
20910 \size footnotesize 
20911 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
20912 \layout Standard
20913
20914
20915 \size footnotesize 
20916 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
20917 \layout Standard
20918
20919
20920 \size footnotesize 
20921 Sample.c(15:24:26:1)_forcond_0($4) :
20922 \layout Standard
20923
20924
20925 \size footnotesize 
20926 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
20927  < 0xa {short}
20928 \layout Standard
20929
20930
20931 \size footnotesize 
20932 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
20933 \layout Standard
20934
20935
20936 \size footnotesize 
20937 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
20938  + ITemp21 [lr21:38]{short}[r4]
20939 \layout Standard
20940
20941
20942 \size footnotesize 
20943 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
20944  * 0x3 {short}
20945 \layout Standard
20946
20947
20948 \size footnotesize 
20949 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
20950  + iTemp15 [lr29:30]{short}[r1]
20951 \layout Standard
20952
20953
20954 \size footnotesize 
20955 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
20956  r0]- 0x3 {short}
20957 \layout Standard
20958
20959
20960 \size footnotesize 
20961 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
20962 int}[r7 r0]
20963 \layout Standard
20964
20965
20966 \size footnotesize 
20967 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
20968  + 0x1 {short}
20969 \layout Standard
20970
20971
20972 \size footnotesize 
20973 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
20974  r6]- 0x1 {short}
20975 \layout Standard
20976
20977
20978 \size footnotesize 
20979 Sample.c(19:38:47:1) goto _forcond_0($4)
20980 \layout Standard
20981
20982
20983 \size footnotesize 
20984 Sample.c(19:39:48:0)_forbreak_0($7) :
20985 \layout Standard
20986
20987
20988 \size footnotesize 
20989 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
20990  + ITemp11 [lr19:40]{short}[r3]
20991 \layout Standard
20992
20993
20994 \size footnotesize 
20995 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
20996 \layout Standard
20997
20998
20999 \size footnotesize 
21000 Sample.c(20:42:51:0)_return($8) :
21001 \layout Standard
21002
21003
21004 \size footnotesize 
21005 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
21006 \size default 
21007
21008 \newline 
21009
21010 \newline 
21011 Finally the code generated for this function:
21012 \newline 
21013
21014 \layout Standard
21015
21016
21017 \size footnotesize 
21018 .area DSEG (DATA)
21019 \layout Standard
21020
21021
21022 \size footnotesize 
21023 _p::
21024 \layout Standard
21025
21026
21027 \size footnotesize 
21028 \SpecialChar ~
21029 \SpecialChar ~
21030 .ds 2
21031 \layout Standard
21032
21033
21034 \size footnotesize 
21035 _gint::
21036 \layout Standard
21037
21038
21039 \size footnotesize 
21040 \SpecialChar ~
21041 \SpecialChar ~
21042 .ds 2
21043 \layout Standard
21044
21045
21046 \size footnotesize 
21047 ; sample.c 5
21048 \layout Standard
21049
21050
21051 \size footnotesize 
21052 ; ----------------------------------------------
21053 \layout Standard
21054
21055
21056 \size footnotesize 
21057 ; function function
21058 \layout Standard
21059
21060
21061 \size footnotesize 
21062 ; ----------------------------------------------
21063 \layout Standard
21064
21065
21066 \size footnotesize 
21067 _function:
21068 \layout Standard
21069
21070
21071 \size footnotesize 
21072 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
21073 \layout Standard
21074
21075
21076 \size footnotesize 
21077 \SpecialChar ~
21078 \SpecialChar ~
21079 mov r2,dpl
21080 \layout Standard
21081
21082
21083 \size footnotesize 
21084 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
21085 \layout Standard
21086
21087
21088 \size footnotesize 
21089 \SpecialChar ~
21090 \SpecialChar ~
21091 mov ar0,r2
21092 \layout Standard
21093
21094
21095 \size footnotesize 
21096 ;_whilecontinue_0($1) :
21097 \layout Standard
21098
21099
21100 \size footnotesize 
21101 00101$:
21102 \layout Standard
21103
21104
21105 \size footnotesize 
21106 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
21107 \layout Standard
21108
21109
21110 \size footnotesize 
21111 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
21112 \layout Standard
21113
21114
21115 \size footnotesize 
21116 \SpecialChar ~
21117 \SpecialChar ~
21118 mov ar2,@r0
21119 \layout Standard
21120
21121
21122 \size footnotesize 
21123 \SpecialChar ~
21124 \SpecialChar ~
21125 inc r0
21126 \layout Standard
21127
21128
21129 \size footnotesize 
21130 \SpecialChar ~
21131 \SpecialChar ~
21132 mov ar3,@r0
21133 \layout Standard
21134
21135
21136 \size footnotesize 
21137 \SpecialChar ~
21138 \SpecialChar ~
21139 dec r0
21140 \layout Standard
21141
21142
21143 \size footnotesize 
21144 \SpecialChar ~
21145 \SpecialChar ~
21146 mov a,r2
21147 \layout Standard
21148
21149
21150 \size footnotesize 
21151 \SpecialChar ~
21152 \SpecialChar ~
21153 orl a,r3
21154 \layout Standard
21155
21156
21157 \size footnotesize 
21158 \SpecialChar ~
21159 \SpecialChar ~
21160 jz 00103$
21161 \layout Standard
21162
21163
21164 \size footnotesize 
21165 00114$:
21166 \layout Standard
21167
21168
21169 \size footnotesize 
21170 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
21171 \layout Standard
21172
21173
21174 \size footnotesize 
21175 \SpecialChar ~
21176 \SpecialChar ~
21177 mov dpl,_p
21178 \layout Standard
21179
21180
21181 \size footnotesize 
21182 \SpecialChar ~
21183 \SpecialChar ~
21184 mov dph,(_p + 1)
21185 \layout Standard
21186
21187
21188 \size footnotesize 
21189 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
21190 \layout Standard
21191
21192
21193 \size footnotesize 
21194 \SpecialChar ~
21195 \SpecialChar ~
21196 mov a,#0x02
21197 \layout Standard
21198
21199
21200 \size footnotesize 
21201 \SpecialChar ~
21202 \SpecialChar ~
21203 add a,_p
21204 \layout Standard
21205
21206
21207 \size footnotesize 
21208 \SpecialChar ~
21209 \SpecialChar ~
21210 mov _p,a
21211 \layout Standard
21212
21213
21214 \size footnotesize 
21215 \SpecialChar ~
21216 \SpecialChar ~
21217 clr a
21218 \layout Standard
21219
21220
21221 \size footnotesize 
21222 \SpecialChar ~
21223 \SpecialChar ~
21224 addc a,(_p + 1)
21225 \layout Standard
21226
21227
21228 \size footnotesize 
21229 \SpecialChar ~
21230 \SpecialChar ~
21231 mov (_p + 1),a
21232 \layout Standard
21233
21234
21235 \size footnotesize 
21236 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
21237 \layout Standard
21238
21239
21240 \size footnotesize 
21241 \SpecialChar ~
21242 \SpecialChar ~
21243 movx a,@dptr
21244 \layout Standard
21245
21246
21247 \size footnotesize 
21248 \SpecialChar ~
21249 \SpecialChar ~
21250 mov r2,a
21251 \layout Standard
21252
21253
21254 \size footnotesize 
21255 \SpecialChar ~
21256 \SpecialChar ~
21257 inc dptr
21258 \layout Standard
21259
21260
21261 \size footnotesize 
21262 \SpecialChar ~
21263 \SpecialChar ~
21264 movx a,@dptr
21265 \layout Standard
21266
21267
21268 \size footnotesize 
21269 \SpecialChar ~
21270 \SpecialChar ~
21271 mov r3,a
21272 \layout Standard
21273
21274
21275 \size footnotesize 
21276 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
21277 \layout Standard
21278
21279
21280 \size footnotesize 
21281 \SpecialChar ~
21282 \SpecialChar ~
21283 mov @r0,ar2
21284 \layout Standard
21285
21286
21287 \size footnotesize 
21288 \SpecialChar ~
21289 \SpecialChar ~
21290 inc r0
21291 \layout Standard
21292
21293
21294 \size footnotesize 
21295 \SpecialChar ~
21296 \SpecialChar ~
21297 mov @r0,ar3
21298 \layout Standard
21299
21300
21301 \size footnotesize 
21302 ; iTemp6 [lr5:16]{_near * int}[r0] = 
21303 \layout Standard
21304
21305
21306 \size footnotesize 
21307 ; iTemp6 [lr5:16]{_near * int}[r0] + 
21308 \layout Standard
21309
21310
21311 \size footnotesize 
21312 ; 0x2 {short}
21313 \layout Standard
21314
21315
21316 \size footnotesize 
21317 \SpecialChar ~
21318 \SpecialChar ~
21319 inc r0
21320 \layout Standard
21321
21322
21323 \size footnotesize 
21324 ; goto _whilecontinue_0($1)
21325 \layout Standard
21326
21327
21328 \size footnotesize 
21329 \SpecialChar ~
21330 \SpecialChar ~
21331 sjmp 00101$
21332 \layout Standard
21333
21334
21335 \size footnotesize 
21336 ; _whilebreak_0($3) :
21337 \layout Standard
21338
21339
21340 \size footnotesize 
21341 00103$:
21342 \layout Standard
21343
21344
21345 \size footnotesize 
21346 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
21347 \layout Standard
21348
21349
21350 \size footnotesize 
21351 \SpecialChar ~
21352 \SpecialChar ~
21353 mov r2,#0x00
21354 \layout Standard
21355
21356
21357 \size footnotesize 
21358 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
21359 \layout Standard
21360
21361
21362 \size footnotesize 
21363 \SpecialChar ~
21364 \SpecialChar ~
21365 mov r3,#0x00
21366 \layout Standard
21367
21368
21369 \size footnotesize 
21370 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
21371 \layout Standard
21372
21373
21374 \size footnotesize 
21375 \SpecialChar ~
21376 \SpecialChar ~
21377 mov r4,#0x00
21378 \layout Standard
21379
21380
21381 \size footnotesize 
21382 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
21383 \layout Standard
21384
21385
21386 \size footnotesize 
21387 \SpecialChar ~
21388 \SpecialChar ~
21389 mov r5,#0x0A
21390 \layout Standard
21391
21392
21393 \size footnotesize 
21394 \SpecialChar ~
21395 \SpecialChar ~
21396 mov r6,#0x00
21397 \layout Standard
21398
21399
21400 \size footnotesize 
21401 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
21402 \layout Standard
21403
21404
21405 \size footnotesize 
21406 \SpecialChar ~
21407 \SpecialChar ~
21408 mov r7,#0x1E
21409 \layout Standard
21410
21411
21412 \size footnotesize 
21413 \SpecialChar ~
21414 \SpecialChar ~
21415 mov r0,#0x00
21416 \layout Standard
21417
21418
21419 \size footnotesize 
21420 ; _forcond_0($4) :
21421 \layout Standard
21422
21423
21424 \size footnotesize 
21425 00104$:
21426 \layout Standard
21427
21428
21429 \size footnotesize 
21430 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
21431 \layout Standard
21432
21433
21434 \size footnotesize 
21435 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
21436 \layout Standard
21437
21438
21439 \size footnotesize 
21440 \SpecialChar ~
21441 \SpecialChar ~
21442 clr c
21443 \layout Standard
21444
21445
21446 \size footnotesize 
21447 \SpecialChar ~
21448 \SpecialChar ~
21449 mov a,r4
21450 \layout Standard
21451
21452
21453 \size footnotesize 
21454 \SpecialChar ~
21455 \SpecialChar ~
21456 xrl a,#0x80
21457 \layout Standard
21458
21459
21460 \size footnotesize 
21461 \SpecialChar ~
21462 \SpecialChar ~
21463 subb a,#0x8a
21464 \layout Standard
21465
21466
21467 \size footnotesize 
21468 \SpecialChar ~
21469 \SpecialChar ~
21470 jnc 00107$
21471 \layout Standard
21472
21473
21474 \size footnotesize 
21475 00115$:
21476 \layout Standard
21477
21478
21479 \size footnotesize 
21480 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
21481 \layout Standard
21482
21483
21484 \size footnotesize 
21485 ; iTemp21 [lr21:38]{short}[r4]
21486 \layout Standard
21487
21488
21489 \size footnotesize 
21490 \SpecialChar ~
21491 \SpecialChar ~
21492 mov a,r4
21493 \layout Standard
21494
21495
21496 \size footnotesize 
21497 \SpecialChar ~
21498 \SpecialChar ~
21499 add a,r2
21500 \layout Standard
21501
21502
21503 \size footnotesize 
21504 \SpecialChar ~
21505 \SpecialChar ~
21506 mov r2,a
21507 \layout Standard
21508
21509
21510 \size footnotesize 
21511 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
21512 \layout Standard
21513
21514
21515 \size footnotesize 
21516 \SpecialChar ~
21517 \SpecialChar ~
21518 mov b,#0x03
21519 \layout Standard
21520
21521
21522 \size footnotesize 
21523 \SpecialChar ~
21524 \SpecialChar ~
21525 mov a,r4
21526 \layout Standard
21527
21528
21529 \size footnotesize 
21530 \SpecialChar ~
21531 \SpecialChar ~
21532 mul ab
21533 \layout Standard
21534
21535
21536 \size footnotesize 
21537 \SpecialChar ~
21538 \SpecialChar ~
21539 mov r1,a
21540 \layout Standard
21541
21542
21543 \size footnotesize 
21544 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
21545 \layout Standard
21546
21547
21548 \size footnotesize 
21549 ; iTemp15 [lr29:30]{short}[r1]
21550 \layout Standard
21551
21552
21553 \size footnotesize 
21554 \SpecialChar ~
21555 \SpecialChar ~
21556 add a,r3
21557 \layout Standard
21558
21559
21560 \size footnotesize 
21561 \SpecialChar ~
21562 \SpecialChar ~
21563 mov r3,a
21564 \layout Standard
21565
21566
21567 \size footnotesize 
21568 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
21569 \layout Standard
21570
21571
21572 \size footnotesize 
21573 \SpecialChar ~
21574 \SpecialChar ~
21575 mov a,r7
21576 \layout Standard
21577
21578
21579 \size footnotesize 
21580 \SpecialChar ~
21581 \SpecialChar ~
21582 add a,#0xfd
21583 \layout Standard
21584
21585
21586 \size footnotesize 
21587 \SpecialChar ~
21588 \SpecialChar ~
21589 mov r7,a
21590 \layout Standard
21591
21592
21593 \size footnotesize 
21594 \SpecialChar ~
21595 \SpecialChar ~
21596 mov a,r0
21597 \layout Standard
21598
21599
21600 \size footnotesize 
21601 \SpecialChar ~
21602 \SpecialChar ~
21603 addc a,#0xff
21604 \layout Standard
21605
21606
21607 \size footnotesize 
21608 \SpecialChar ~
21609 \SpecialChar ~
21610 mov r0,a
21611 \layout Standard
21612
21613
21614 \size footnotesize 
21615 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
21616 \layout Standard
21617
21618
21619 \size footnotesize 
21620 \SpecialChar ~
21621 \SpecialChar ~
21622 mov a,r7
21623 \layout Standard
21624
21625
21626 \size footnotesize 
21627 \SpecialChar ~
21628 \SpecialChar ~
21629 add a,_gint
21630 \layout Standard
21631
21632
21633 \size footnotesize 
21634 \SpecialChar ~
21635 \SpecialChar ~
21636 mov _gint,a
21637 \layout Standard
21638
21639
21640 \size footnotesize 
21641 \SpecialChar ~
21642 \SpecialChar ~
21643 mov a,r0
21644 \layout Standard
21645
21646
21647 \size footnotesize 
21648 \SpecialChar ~
21649 \SpecialChar ~
21650 addc a,(_gint + 1)
21651 \layout Standard
21652
21653
21654 \size footnotesize 
21655 \SpecialChar ~
21656 \SpecialChar ~
21657 mov (_gint + 1),a
21658 \layout Standard
21659
21660
21661 \size footnotesize 
21662 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
21663 \layout Standard
21664
21665
21666 \size footnotesize 
21667 \SpecialChar ~
21668 \SpecialChar ~
21669 inc r4
21670 \layout Standard
21671
21672
21673 \size footnotesize 
21674 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
21675 \layout Standard
21676
21677
21678 \size footnotesize 
21679 \SpecialChar ~
21680 \SpecialChar ~
21681 dec r5
21682 \layout Standard
21683
21684
21685 \size footnotesize 
21686 \SpecialChar ~
21687 \SpecialChar ~
21688 cjne r5,#0xff,00104$
21689 \layout Standard
21690
21691
21692 \size footnotesize 
21693 \SpecialChar ~
21694 \SpecialChar ~
21695 dec r6
21696 \layout Standard
21697
21698
21699 \size footnotesize 
21700 ; goto _forcond_0($4)
21701 \layout Standard
21702
21703
21704 \size footnotesize 
21705 \SpecialChar ~
21706 \SpecialChar ~
21707 sjmp 00104$
21708 \layout Standard
21709
21710
21711 \size footnotesize 
21712 ; _forbreak_0($7) :
21713 \layout Standard
21714
21715
21716 \size footnotesize 
21717 00107$:
21718 \layout Standard
21719
21720
21721 \size footnotesize 
21722 ; ret iTemp24 [lr40:41]{short}
21723 \layout Standard
21724
21725
21726 \size footnotesize 
21727 \SpecialChar ~
21728 \SpecialChar ~
21729 mov a,r3
21730 \layout Standard
21731
21732
21733 \size footnotesize 
21734 \SpecialChar ~
21735 \SpecialChar ~
21736 add a,r2
21737 \layout Standard
21738
21739
21740 \size footnotesize 
21741 \SpecialChar ~
21742 \SpecialChar ~
21743 mov dpl,a
21744 \layout Standard
21745
21746
21747 \size footnotesize 
21748 ; _return($8) :
21749 \layout Standard
21750
21751
21752 \size footnotesize 
21753 00108$:
21754 \layout Standard
21755
21756
21757 \size footnotesize 
21758 \SpecialChar ~
21759 \SpecialChar ~
21760 ret
21761 \newline 
21762
21763 \layout Section
21764
21765 A few words about basic block successors, predecessors and dominators
21766 \layout Standard
21767
21768 Successors are basic blocks
21769 \begin_inset LatexCommand \index{Basic blocks}
21770
21771 \end_inset 
21772
21773  that might execute after this basic block.
21774 \newline 
21775 Predecessors are basic blocks that might execute before reaching this basic
21776  block.
21777 \newline 
21778 Dominators are basic blocks that WILL execute before reaching this basic
21779  block.
21780 \newline 
21781
21782 \layout Standard
21783
21784 [basic block 1]
21785 \layout Standard
21786
21787 if (something)
21788 \layout Standard
21789
21790 \SpecialChar ~
21791 \SpecialChar ~
21792 \SpecialChar ~
21793 \SpecialChar ~
21794 [basic block 2]
21795 \layout Standard
21796
21797 else
21798 \layout Standard
21799
21800 \SpecialChar ~
21801 \SpecialChar ~
21802 \SpecialChar ~
21803 \SpecialChar ~
21804 [basic block 3]
21805 \layout Standard
21806
21807 [basic block 4]
21808 \newline 
21809
21810 \layout Standard
21811
21812 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
21813 \layout Standard
21814
21815 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
21816 \layout Standard
21817
21818 c) domVect of [BB4] = BB1 ...
21819  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
21820  was executed.
21821 \layout Chapter
21822
21823 Acknowledgments
21824 \layout Standard
21825
21826
21827 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
21828
21829 \end_inset 
21830
21831
21832 \newline 
21833
21834 \newline 
21835
21836 \emph on 
21837 Thanks to all the other volunteer developers who have helped with coding,
21838  testing, web-page creation, distribution sets, etc.
21839  You know who you are :-)
21840 \emph default 
21841
21842 \newline 
21843
21844 \layout Standard
21845
21846 This document was initially written by Sandeep Dutta
21847 \layout Standard
21848
21849 All product names mentioned herein may be trademarks
21850 \begin_inset LatexCommand \index{Trademarks}
21851
21852 \end_inset 
21853
21854  of their respective companies.
21855  
21856 \layout Section*
21857
21858 Alphabetical index
21859 \layout Standard
21860
21861 To avoid confusion, the installation and building options for SDCC itself
21862  (chapter 2) are not part of the index.
21863 \layout Standard
21864
21865
21866 \begin_inset LatexCommand \printindex{}
21867
21868 \end_inset 
21869
21870
21871 \the_end