* src/SDCCmain.c (linkEdit): don't suppress crt0 if --nostdlib is used
[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
6
7 \usepackage[
8   pdftitle={SDCC Compiler User Guide},
9   pdfauthor={SDCC development team},
10   pdfsubject={installation, user manual},
11   pdfkeywords={8032, 8051, ansi, c, compiler, CPU, DS390, 
12                embedded, GPL, HC08, manual, mcs51, PIC, Z80},
13   colorlinks=true,
14   linkcolor=blue] {hyperref}
15 %
16 \sloppy
17 \tolerance=500          
18 \emergencystretch=30pt 
19 %
20 \date{}
21 \end_preamble
22 \language english
23 \inputencoding default
24 \fontscheme pslatex
25 \graphics default
26 \paperfontsize default
27 \spacing single 
28 \papersize letterpaper
29 \paperpackage a4
30 \use_geometry 1
31 \use_amsmath 0
32 \use_natbib 0
33 \use_numerical_citations 0
34 \paperorientation portrait
35 \leftmargin 30mm
36 \topmargin 20mm
37 \rightmargin 25mm
38 \bottommargin 20mm
39 \secnumdepth 3
40 \tocdepth 3
41 \paragraph_separation indent
42 \defskip medskip
43 \quotes_language swedish
44 \quotes_times 2
45 \papercolumns 1
46 \papersides 1
47 \paperpagestyle fancy
48
49 \layout Comment
50
51 Please note: double dashed longoptions (e.g.
52  --version) are written this way: -
53 \begin_inset ERT
54 status Collapsed
55
56 \layout Standard
57
58 \backslash 
59 /
60 \end_inset 
61
62 -
63 \layout Comment
64
65 Two resp.
66  three consecutive dashes simply result in a long resp.
67  extra long dash.
68 \layout Comment
69
70 Architecture specific stuff (like memory models, code examples) should maybe
71  later go
72 \layout Comment
73
74 into seperate sections/chapters/appendices (it is hard to document PIC or
75  Z80 in 
76 \layout Comment
77
78 a 8051 centered document) - for now simply add.
79 \layout Title
80
81 SDCC Compiler User Guide
82 \layout Date
83
84
85 \size normal 
86 SDCC 2.4.6
87 \size footnotesize 
88
89 \newline 
90 $Date$ 
91 \newline 
92 $Revision$
93 \layout Comment
94
95 The above strings enclosed in $ are automatically updated by cvs
96 \layout Standard
97
98
99 \begin_inset LatexCommand \tableofcontents{}
100
101 \end_inset 
102
103
104 \layout Chapter
105
106 Introduction
107 \layout Section
108
109 About SDCC
110 \layout Standard
111
112
113 \series bold 
114 SDCC
115 \series default 
116  (
117 \emph on 
118 S
119 \emph default 
120 mall 
121 \emph on 
122 D
123 \emph default 
124 evice 
125 \emph on 
126 C
127 \emph default 
128  
129 \emph on 
130 C
131 \emph default 
132 ompiler) is an open source, retargettable, optimizing ANSI-C compiler by
133  
134 \series bold 
135 Sandeep Dutta
136 \series default 
137  designed for 8 bit Microprocessors.
138  The current version targets Intel MCS51 based Microprocessors (8031, 8032,
139  8051, 8052
140 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
141
142 \end_inset 
143
144 , etc.), Dallas DS80C390 variants, Motorola HC08 and Zilog Z80 based MCUs.
145  It can be retargetted for other microprocessors, support for Microchip
146  PIC, Atmel AVR is under development.
147  The entire source code for the compiler is distributed under GPL.
148  SDCC uses ASXXXX
149 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
150
151 \end_inset 
152
153  & ASLINK
154 \begin_inset LatexCommand \index{aslink}
155
156 \end_inset 
157
158 , an open source retargettable assembler & linker.
159  SDCC has extensive language extensions suitable for utilizing various microcont
160 rollers and underlying hardware effectively.
161  
162 \newline 
163
164 \newline 
165 In addition to the MCU specific optimizations SDCC also does a host of standard
166  optimizations like:
167 \layout Itemize
168
169 global sub expression elimination, 
170 \layout Itemize
171
172 loop optimizations (loop invariant, strength reduction of induction variables
173  and loop reversing), 
174 \layout Itemize
175
176 constant folding & propagation, 
177 \layout Itemize
178
179 copy propagation, 
180 \layout Itemize
181
182 dead code elimination 
183 \layout Itemize
184
185 jump tables for 
186 \emph on 
187 switch
188 \emph default 
189  statements.
190 \layout Standard
191
192 For the back-end SDCC uses a global register allocation scheme which should
193  be well suited for other 8 bit MCUs.
194  
195 \newline 
196
197 \newline 
198 The peep hole optimizer uses a rule based substitution mechanism which is
199  MCU independent.
200  
201 \newline 
202
203 \newline 
204 Supported data-types are:
205 \layout Itemize
206
207 char (8 bits, 1 byte), 
208 \layout Itemize
209
210 short and int (16 bits, 2 bytes), 
211 \layout Itemize
212
213 long (32 bit, 4 bytes)
214 \layout Itemize
215
216 float (4 byte IEEE).
217  
218 \layout Standard
219
220 The compiler also allows 
221 \emph on 
222 inline assembler code
223 \emph default 
224  to be embedded anywhere in a function.
225  In addition, routines developed in assembly can also be called.
226 \newline 
227
228 \newline 
229 SDCC also provides an option (-
230 \begin_inset ERT
231 status Collapsed
232
233 \layout Standard
234
235 \backslash 
236 /
237 \end_inset 
238
239 -cyclomatic) to report the relative complexity of a function.
240  These functions can then be further optimized, or hand coded in assembly
241  if needed.
242  
243 \newline 
244
245 \newline 
246 SDCC also comes with a companion source level debugger SDCDB, the debugger
247  currently uses ucSim a freeware simulator for 8051 and other micro-controllers.
248  
249 \newline 
250
251 \newline 
252 The latest version can be downloaded from 
253 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
254
255 \end_inset 
256
257 .
258
259 \series bold 
260  
261 \series default 
262 \emph on 
263 Please note: the compiler will probably always be some steps ahead of this
264  documentation
265 \series bold 
266 \emph default 
267
268 \begin_inset LatexCommand \index{Status of documentation}
269
270 \end_inset 
271
272
273 \begin_inset Foot
274 collapsed false
275
276 \layout Standard
277
278 Obviously this has pros and cons
279 \end_inset 
280
281 .
282 \layout Section
283
284 Open Source
285 \layout Standard
286
287 All packages used in this compiler system are 
288 \emph on 
289 open source
290 \emph default 
291  and 
292 \emph on 
293 freeware
294 \emph default 
295 ; source code for all the sub-packages (pre-processor, assemblers, linkers
296  etc) is distributed with the package.
297  This documentation is maintained using a freeware word processor (LyX).
298 \newline 
299 This program is free software; you can redistribute it and/or modify it
300  under the terms of the GNU General Public License
301 \begin_inset LatexCommand \index{GNU General Public License, GPL}
302
303 \end_inset 
304
305  as published by the Free Software Foundation; either version 2, or (at
306  your option) any later version.
307  This program is distributed in the hope that it will be useful, but WITHOUT
308  ANY WARRANTY; without even the implied warranty
309 \begin_inset LatexCommand \index{warranty}
310
311 \end_inset 
312
313  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
314  See the GNU General Public License for more details.
315  You should have received a copy of the GNU General Public License along
316  with this program; if not, write to the Free Software Foundation, 59 Temple
317  Place - Suite 330, Boston, MA 02111-1307, USA.
318  In other words, you are welcome to use, share and improve this program.
319  You are forbidden to forbid anyone else to use, share and improve what
320  you give them.
321  Help stamp out software-hoarding! 
322 \layout Section
323
324 Typographic conventions
325 \begin_inset LatexCommand \index{Typographic conventions}
326
327 \end_inset 
328
329
330 \layout Standard
331
332 Throughout this manual, we will use the following convention.
333  Commands you have to type in are printed in 
334 \family sans 
335 \series bold 
336 "sans serif"
337 \series default 
338 .
339
340 \family default 
341  Code samples are printed in 
342 \family typewriter 
343 typewriter font.
344
345 \family default 
346  Interesting items and new terms are printed in 
347 \emph on 
348 italic.
349 \layout Section
350
351 Compatibility with previous versions
352 \layout Standard
353
354 This version has numerous bug fixes compared with the previous version.
355  But we also introduced some incompatibilities with older versions.
356  Not just for the fun of it, but to make the compiler more stable, efficient
357  and ANSI compliant
358 \begin_inset LatexCommand \index{ANSI-compliance}
359
360 \end_inset 
361
362  (see section 
363 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
364
365 \end_inset 
366
367  for ANSI-Compliance).
368  
369 \newline 
370
371 \layout Itemize
372
373 short is now equivalent to int (16 bits), it used to be equivalent to char
374  (8 bits) which is not ANSI compliant
375 \layout Itemize
376
377 the default directory for gcc-builds where include, library and documentation
378  files are stored is now in /usr/local/share
379 \layout Itemize
380
381 char type parameters to vararg functions are casted to int unless explicitly
382  casted, e.g.: 
383 \newline 
384
385 \family typewriter 
386 \SpecialChar ~
387 \SpecialChar ~
388 char a=3;
389 \newline 
390 \SpecialChar ~
391 \SpecialChar ~
392 printf ("%d %c
393 \backslash 
394 n", a, (char)a);
395 \family default 
396
397 \newline 
398  will push a as an int and as a char resp.
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 -regextend 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 -noregparms has been removed
425 \layout Itemize
426
427 option -
428 \begin_inset ERT
429 status Collapsed
430
431 \layout Standard
432
433 \backslash 
434 /
435 \end_inset 
436
437 -stack-after-data has been removed
438 \layout Standard
439
440
441 \emph on 
442 <pending: more incompatibilities?>
443 \layout Section
444
445 System Requirements
446 \layout Standard
447
448 What do you need before you start installation of SDCC? A computer, and
449  a desire to compute.
450  The preferred method of installation is to compile SDCC from source using
451  GNU gcc and make.
452  For Windows some pre-compiled binary distributions are available for your
453  convenience.
454  You should have some experience with command line tools and compiler use.
455 \layout Section
456
457 Other Resources
458 \layout Standard
459
460 The SDCC home page at 
461 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
462
463 \end_inset 
464
465  is a great place to find distribution sets.
466  You can also find links to the user mailing lists that offer help or discuss
467  SDCC with other SDCC users.
468  Web links to other SDCC related sites can also be found here.
469  This document can be found in the DOC directory of the source package as
470  a text or HTML file.
471  A pdf version of this document is available at 
472 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
473
474 \end_inset 
475
476 .
477  Some of the other tools (simulator and assembler) included with SDCC contain
478  their own documentation and can be found in the source distribution.
479  If you want the latest unreleased software, the complete source package
480  is available directly by anonymous CVS on cvs.sdcc.sourceforge.net.
481 \layout Section
482
483 Wishes for the future
484 \layout Standard
485
486 There are (and always will be) some things that could be done.
487  Here are some I can think of:
488 \newline 
489
490 \layout Standard
491
492
493 \family typewriter 
494 char KernelFunction3(char p) at 0x340;
495 \newline 
496
497 \layout Standard
498
499
500 \family typewriter 
501 code banking
502 \begin_inset LatexCommand \index{code banking (not supported)}
503
504 \end_inset 
505
506  support for mcs51
507 \newline 
508
509 \newline 
510
511 \family default 
512 If you can think of some more, please see the section 
513 \begin_inset LatexCommand \ref{sub:Requesting-Features}
514
515 \end_inset 
516
517  about filing feature requests
518 \begin_inset LatexCommand \index{Requesting features}
519
520 \end_inset 
521
522
523 \begin_inset LatexCommand \index{Feature request}
524
525 \end_inset 
526
527 .
528 \newline 
529
530 \layout Chapter
531
532 Installing SDCC
533 \begin_inset LatexCommand \index{Installation}
534
535 \end_inset 
536
537
538 \layout Standard
539
540 For most users it is sufficient to skip to either section 
541 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
542
543 \end_inset 
544
545  or section 
546 \begin_inset LatexCommand \ref{sub:Windows-Install}
547
548 \end_inset 
549
550 .
551  More detailled instructions follow below.
552 \layout Section
553
554 Configure Options
555 \begin_inset LatexCommand \index{Options SDCC configuration}
556
557 \end_inset 
558
559
560 \layout Standard
561
562 The install paths, search paths and other options are defined when running
563  'configure'.
564  The defaults can be overridden by:
565 \layout List
566 \labelwidthstring 00.00.0000
567
568 -
569 \begin_inset ERT
570 status Collapsed
571
572 \layout Standard
573
574 \backslash 
575 /
576 \end_inset 
577
578 -prefix see table below
579 \layout List
580 \labelwidthstring 00.00.0000
581
582 -
583 \begin_inset ERT
584 status Collapsed
585
586 \layout Standard
587
588 \backslash 
589 /
590 \end_inset 
591
592 -exec_prefix see table below
593 \layout List
594 \labelwidthstring 00.00.0000
595
596 -
597 \begin_inset ERT
598 status Collapsed
599
600 \layout Standard
601
602 \backslash 
603 /
604 \end_inset 
605
606 -bindir see table below
607 \layout List
608 \labelwidthstring 00.00.0000
609
610 -
611 \begin_inset ERT
612 status Collapsed
613
614 \layout Standard
615
616 \backslash 
617 /
618 \end_inset 
619
620 -datadir see table below
621 \layout List
622 \labelwidthstring 00.00.0000
623
624 docdir environment variable, see table below
625 \layout List
626 \labelwidthstring 00.00.0000
627
628 include_dir_suffix environment variable, see table below
629 \layout List
630 \labelwidthstring 00.00.0000
631
632 lib_dir_suffix environment variable, see table below
633 \layout List
634 \labelwidthstring 00.00.0000
635
636 sdccconf_h_dir_separator environment variable, either / or 
637 \backslash 
638
639 \backslash 
640  makes sense here.
641  This character will only be used in sdccconf.h; don't forget it's a C-header,
642  therefore a double-backslash is needed there.
643 \layout List
644 \labelwidthstring 00.00.0000
645
646 -
647 \begin_inset ERT
648 status Collapsed
649
650 \layout Standard
651
652 \backslash 
653 /
654 \end_inset 
655
656 -disable-mcs51-port Excludes the Intel mcs51 port
657 \layout List
658 \labelwidthstring 00.00.0000
659
660 -
661 \begin_inset ERT
662 status Collapsed
663
664 \layout Standard
665
666 \backslash 
667 /
668 \end_inset 
669
670 -disable-gbz80-port Excludes the Gameboy gbz80 port
671 \layout List
672 \labelwidthstring 00.00.0000
673
674 -
675 \begin_inset ERT
676 status Collapsed
677
678 \layout Standard
679
680 \backslash 
681 /
682 \end_inset 
683
684 -disable-z80-port Excludes the z80 port
685 \layout List
686 \labelwidthstring 00.00.0000
687
688 -
689 \begin_inset ERT
690 status Collapsed
691
692 \layout Standard
693
694 \backslash 
695 /
696 \end_inset 
697
698 -disable-avr-port Excludes the AVR port
699 \layout List
700 \labelwidthstring 00.00.0000
701
702 -
703 \begin_inset ERT
704 status Collapsed
705
706 \layout Standard
707
708 \backslash 
709 /
710 \end_inset 
711
712 -disable-ds390-port Excludes the DS390 port
713 \layout List
714 \labelwidthstring 00.00.0000
715
716 -
717 \begin_inset ERT
718 status Collapsed
719
720 \layout Standard
721
722 \backslash 
723 /
724 \end_inset 
725
726 -disable-hc08-port Excludes the HC08 port
727 \layout List
728 \labelwidthstring 00.00.0000
729
730 -
731 \begin_inset ERT
732 status Collapsed
733
734 \layout Standard
735
736 \backslash 
737 /
738 \end_inset 
739
740 -disable-pic-port Excludes the PIC port
741 \layout List
742 \labelwidthstring 00.00.0000
743
744 -
745 \begin_inset ERT
746 status Collapsed
747
748 \layout Standard
749
750 \backslash 
751 /
752 \end_inset 
753
754 -disable-xa51-port Excludes the XA51 port
755 \layout List
756 \labelwidthstring 00.00.0000
757
758 -
759 \begin_inset ERT
760 status Collapsed
761
762 \layout Standard
763
764 \backslash 
765 /
766 \end_inset 
767
768 -disable-ucsim Disables configuring and building of ucsim
769 \layout List
770 \labelwidthstring 00.00.0000
771
772 -
773 \begin_inset ERT
774 status Collapsed
775
776 \layout Standard
777
778 \backslash 
779 /
780 \end_inset 
781
782 -disable-device-lib-build Disables automatically building device libraries
783 \layout List
784 \labelwidthstring 00.00.0000
785
786 -
787 \begin_inset ERT
788 status Collapsed
789
790 \layout Standard
791
792 \backslash 
793 /
794 \end_inset 
795
796 -disable-packihx Disables building packihx
797 \layout List
798 \labelwidthstring 00.00.0000
799
800 -
801 \begin_inset ERT
802 status Collapsed
803
804 \layout Standard
805
806 \backslash 
807 /
808 \end_inset 
809
810 -enable-libgc Use the Bohem memory allocator.
811  Lower runtime footprint.
812 \layout Standard
813
814 Furthermore the environment variables CC, CFLAGS, ...
815  the tools and their arguments can be influenced.
816  Please see `configure -
817 \begin_inset ERT
818 status Collapsed
819
820 \layout Standard
821
822 \backslash 
823 /
824 \end_inset 
825
826 -help` and the man/info pages of `configure` for details.
827 \newline 
828
829 \newline 
830 The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB,
831  STD_FP_LIB, STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_
832 NAME, SDCC_INCLUDE_NAME, SDCC_LIB_NAME are defined by `configure` too.
833  At the moment it's not possible to change the default settings (it was
834  simply never required).
835 \newline 
836
837 \newline 
838 These configure options are compiled into the binaries, and can only be
839  changed by rerunning 'configure' and recompiling SDCC.
840  The configure options are written in 
841 \emph on 
842 italics
843 \emph default 
844  to distinguish them from run time environment variables (see section search
845  paths).
846 \newline 
847
848 \newline 
849 The settings for 
850 \begin_inset Quotes sld
851 \end_inset 
852
853 Win32 builds
854 \begin_inset Quotes srd
855 \end_inset 
856
857  are used by the SDCC team to build the official Win32 binaries.
858  The SDCC team uses Mingw32 to build the official Windows binaries, because
859  it's
860 \layout Enumerate
861
862 open source, 
863 \layout Enumerate
864
865 a gcc compiler and last but not least
866 \layout Enumerate
867
868 the binaries can be built by cross compiling on Sourceforge's compile farm.
869 \layout Standard
870
871 See the examples, how to pass the Win32 settings to 'configure'.
872  The other Win32 builds using Borland, VC or whatever don't use 'configure',
873  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
874  for Win32.
875 \newline 
876
877 \newline 
878 These defaults are:
879 \newline 
880
881 \layout Standard
882 \align center 
883
884 \begin_inset  Tabular
885 <lyxtabular version="3" rows="8" columns="3">
886 <features>
887 <column alignment="block" valignment="top" leftline="true" width="0in">
888 <column alignment="block" valignment="top" leftline="true" width="0in">
889 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
890 <row topline="true" bottomline="true">
891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
892 \begin_inset Text
893
894 \layout Standard
895
896 Variable
897 \end_inset 
898 </cell>
899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
900 \begin_inset Text
901
902 \layout Standard
903
904 default
905 \end_inset 
906 </cell>
907 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
908 \begin_inset Text
909
910 \layout Standard
911
912 Win32 builds
913 \end_inset 
914 </cell>
915 </row>
916 <row topline="true">
917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
918 \begin_inset Text
919
920 \layout Standard
921
922
923 \emph on 
924 PREFIX
925 \end_inset 
926 </cell>
927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
928 \begin_inset Text
929
930 \layout Standard
931
932 /usr/local
933 \end_inset 
934 </cell>
935 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
936 \begin_inset Text
937
938 \layout Standard
939
940
941 \backslash 
942 sdcc
943 \end_inset 
944 </cell>
945 </row>
946 <row topline="true">
947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
948 \begin_inset Text
949
950 \layout Standard
951
952
953 \emph on 
954 EXEC_PREFIX
955 \end_inset 
956 </cell>
957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
958 \begin_inset Text
959
960 \layout Standard
961
962
963 \emph on 
964 $PREFIX
965 \end_inset 
966 </cell>
967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
968 \begin_inset Text
969
970 \layout Standard
971
972
973 \emph on 
974 $PREFIX
975 \end_inset 
976 </cell>
977 </row>
978 <row topline="true">
979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
980 \begin_inset Text
981
982 \layout Standard
983
984
985 \emph on 
986 BINDIR
987 \end_inset 
988 </cell>
989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
990 \begin_inset Text
991
992 \layout Standard
993
994
995 \emph on 
996 $EXECPREFIX
997 \emph default 
998 /bin
999 \end_inset 
1000 </cell>
1001 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1002 \begin_inset Text
1003
1004 \layout Standard
1005
1006
1007 \emph on 
1008 $EXECPREFIX
1009 \emph default 
1010
1011 \backslash 
1012 bin
1013 \end_inset 
1014 </cell>
1015 </row>
1016 <row topline="true">
1017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1018 \begin_inset Text
1019
1020 \layout Standard
1021
1022
1023 \emph on 
1024 DATADIR
1025 \end_inset 
1026 </cell>
1027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1028 \begin_inset Text
1029
1030 \layout Standard
1031
1032
1033 \emph on 
1034 $PREFIX
1035 \emph default 
1036 /share
1037 \end_inset 
1038 </cell>
1039 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1040 \begin_inset Text
1041
1042 \layout Standard
1043
1044
1045 \emph on 
1046 $PREFIX
1047 \end_inset 
1048 </cell>
1049 </row>
1050 <row topline="true">
1051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1052 \begin_inset Text
1053
1054 \layout Standard
1055
1056
1057 \emph on 
1058 DOCDIR
1059 \end_inset 
1060 </cell>
1061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1062 \begin_inset Text
1063
1064 \layout Standard
1065
1066
1067 \emph on 
1068 $DATADIR
1069 \emph default 
1070 /sdcc/doc
1071 \end_inset 
1072 </cell>
1073 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1074 \begin_inset Text
1075
1076 \layout Standard
1077
1078
1079 \emph on 
1080 $DATADIR
1081 \emph default 
1082
1083 \backslash 
1084 doc
1085 \end_inset 
1086 </cell>
1087 </row>
1088 <row topline="true">
1089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1090 \begin_inset Text
1091
1092 \layout Standard
1093
1094
1095 \emph on 
1096 INCLUDE_DIR_SUFFIX
1097 \end_inset 
1098 </cell>
1099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1100 \begin_inset Text
1101
1102 \layout Standard
1103
1104 sdcc/include
1105 \end_inset 
1106 </cell>
1107 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1108 \begin_inset Text
1109
1110 \layout Standard
1111
1112 include
1113 \end_inset 
1114 </cell>
1115 </row>
1116 <row topline="true" bottomline="true">
1117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1118 \begin_inset Text
1119
1120 \layout Standard
1121
1122
1123 \emph on 
1124 LIB_DIR_SUFFIX
1125 \end_inset 
1126 </cell>
1127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1128 \begin_inset Text
1129
1130 \layout Standard
1131
1132 sdcc/lib
1133 \end_inset 
1134 </cell>
1135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1136 \begin_inset Text
1137
1138 \layout Standard
1139
1140 lib
1141 \end_inset 
1142 </cell>
1143 </row>
1144 </lyxtabular>
1145
1146 \end_inset 
1147
1148
1149 \newline 
1150
1151 \layout Standard
1152 \noindent 
1153 'configure' also computes relative paths.
1154  This is needed for full relocatability of a binary package and to complete
1155  search paths (see section search paths below):
1156 \newline 
1157  
1158 \layout Standard
1159 \align center 
1160
1161 \begin_inset  Tabular
1162 <lyxtabular version="3" rows="4" columns="3">
1163 <features>
1164 <column alignment="block" valignment="top" leftline="true" width="0in">
1165 <column alignment="block" valignment="top" leftline="true" width="0in">
1166 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1167 <row topline="true" bottomline="true">
1168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1169 \begin_inset Text
1170
1171 \layout Standard
1172
1173 Variable (computed)
1174 \end_inset 
1175 </cell>
1176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1177 \begin_inset Text
1178
1179 \layout Standard
1180
1181 default
1182 \end_inset 
1183 </cell>
1184 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1185 \begin_inset Text
1186
1187 \layout Standard
1188
1189 Win32 builds
1190 \end_inset 
1191 </cell>
1192 </row>
1193 <row topline="true" bottomline="true">
1194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1195 \begin_inset Text
1196
1197 \layout Standard
1198
1199
1200 \emph on 
1201 BIN2DATA_DIR
1202 \end_inset 
1203 </cell>
1204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1205 \begin_inset Text
1206
1207 \layout Standard
1208
1209 ../share
1210 \end_inset 
1211 </cell>
1212 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1213 \begin_inset Text
1214
1215 \layout Standard
1216
1217 ..
1218 \end_inset 
1219 </cell>
1220 </row>
1221 <row bottomline="true">
1222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1223 \begin_inset Text
1224
1225 \layout Standard
1226
1227
1228 \emph on 
1229 PREFIX2BIN_DIR
1230 \end_inset 
1231 </cell>
1232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1233 \begin_inset Text
1234
1235 \layout Standard
1236
1237 bin
1238 \end_inset 
1239 </cell>
1240 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1241 \begin_inset Text
1242
1243 \layout Standard
1244
1245 bin
1246 \end_inset 
1247 </cell>
1248 </row>
1249 <row bottomline="true">
1250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1251 \begin_inset Text
1252
1253 \layout Standard
1254
1255
1256 \emph on 
1257 PREFIX2DATA_DIR
1258 \end_inset 
1259 </cell>
1260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1261 \begin_inset Text
1262
1263 \layout Standard
1264
1265 share/sdcc
1266 \end_inset 
1267 </cell>
1268 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1269 \begin_inset Text
1270
1271 \layout Standard
1272
1273 \end_inset 
1274 </cell>
1275 </row>
1276 </lyxtabular>
1277
1278 \end_inset 
1279
1280
1281 \newline 
1282
1283 \layout Standard
1284 \noindent 
1285 Examples:
1286 \layout LyX-Code
1287
1288 ./configure
1289 \newline 
1290 ./configure -
1291 \begin_inset ERT
1292 status Collapsed
1293
1294 \layout Standard
1295
1296 \backslash 
1297 /
1298 \end_inset 
1299
1300 -prefix=
1301 \begin_inset Quotes srd
1302 \end_inset 
1303
1304 /usr/bin
1305 \begin_inset Quotes srd
1306 \end_inset 
1307
1308  -
1309 \begin_inset ERT
1310 status Collapsed
1311
1312 \layout Standard
1313
1314 \backslash 
1315 /
1316 \end_inset 
1317
1318 -datadir=
1319 \begin_inset Quotes srd
1320 \end_inset 
1321
1322 /usr/share
1323 \begin_inset Quotes srd
1324 \end_inset 
1325
1326
1327 \newline 
1328 ./configure -
1329 \begin_inset ERT
1330 status Collapsed
1331
1332 \layout Standard
1333
1334 \backslash 
1335 /
1336 \end_inset 
1337
1338 -disable-avr-port -
1339 \begin_inset ERT
1340 status Collapsed
1341
1342 \layout Standard
1343
1344 \backslash 
1345 /
1346 \end_inset 
1347
1348 -disable-xa51-port
1349 \layout Standard
1350
1351 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1352 32'):
1353 \layout LyX-Code
1354
1355 ./configure 
1356 \backslash 
1357
1358 \newline 
1359 CC=
1360 \begin_inset Quotes srd
1361 \end_inset 
1362
1363 i586-mingw32msvc-gcc
1364 \begin_inset Quotes srd
1365 \end_inset 
1366
1367  CXX=
1368 \begin_inset Quotes srd
1369 \end_inset 
1370
1371 i586-mingw32msvc-g++
1372 \begin_inset Quotes srd
1373 \end_inset 
1374
1375  
1376 \backslash 
1377  
1378 \newline 
1379 RANLIB=
1380 \begin_inset Quotes srd
1381 \end_inset 
1382
1383 i586-mingw32msvc-ranlib
1384 \begin_inset Quotes srd
1385 \end_inset 
1386
1387  
1388 \backslash 
1389
1390 \newline 
1391 STRIP=
1392 \begin_inset Quotes srd
1393 \end_inset 
1394
1395 i586-mingw32msvc-strip
1396 \begin_inset Quotes srd
1397 \end_inset 
1398
1399  
1400 \backslash 
1401
1402 \newline 
1403 -
1404 \begin_inset ERT
1405 status Collapsed
1406
1407 \layout Standard
1408
1409 \backslash 
1410 /
1411 \end_inset 
1412
1413 -prefix=
1414 \begin_inset Quotes srd
1415 \end_inset 
1416
1417 /sdcc
1418 \begin_inset Quotes srd
1419 \end_inset 
1420
1421  
1422 \backslash 
1423
1424 \newline 
1425 -
1426 \begin_inset ERT
1427 status Collapsed
1428
1429 \layout Standard
1430
1431 \backslash 
1432 /
1433 \end_inset 
1434
1435 -datadir=
1436 \begin_inset Quotes srd
1437 \end_inset 
1438
1439 /sdcc
1440 \begin_inset Quotes srd
1441 \end_inset 
1442
1443  
1444 \backslash 
1445
1446 \newline 
1447 docdir=
1448 \begin_inset Quotes srd
1449 \end_inset 
1450
1451 /sdcc/doc
1452 \begin_inset Quotes srd
1453 \end_inset 
1454
1455  
1456 \backslash 
1457
1458 \newline 
1459 include_dir_suffix=
1460 \begin_inset Quotes srd
1461 \end_inset 
1462
1463 include
1464 \begin_inset Quotes srd
1465 \end_inset 
1466
1467  
1468 \backslash 
1469
1470 \newline 
1471 lib_dir_suffix=
1472 \begin_inset Quotes srd
1473 \end_inset 
1474
1475 lib
1476 \begin_inset Quotes srd
1477 \end_inset 
1478
1479  
1480 \backslash 
1481
1482 \newline 
1483 sdccconf_h_dir_separator=
1484 \begin_inset Quotes srd
1485 \end_inset 
1486
1487
1488 \backslash 
1489
1490 \backslash 
1491
1492 \backslash 
1493
1494 \backslash 
1495
1496 \begin_inset Quotes srd
1497 \end_inset 
1498
1499  
1500 \backslash 
1501
1502 \newline 
1503 -
1504 \begin_inset ERT
1505 status Collapsed
1506
1507 \layout Standard
1508
1509 \backslash 
1510 /
1511 \end_inset 
1512
1513 -disable-device-lib-build
1514 \backslash 
1515
1516 \newline 
1517 -
1518 \begin_inset ERT
1519 status Collapsed
1520
1521 \layout Standard
1522
1523 \backslash 
1524 /
1525 \end_inset 
1526
1527 -disable-ucsim
1528 \backslash 
1529
1530 \newline 
1531 -
1532 \begin_inset ERT
1533 status Collapsed
1534
1535 \layout Standard
1536
1537 \backslash 
1538 /
1539 \end_inset 
1540
1541 -host=i586-mingw32msvc -
1542 \begin_inset ERT
1543 status Collapsed
1544
1545 \layout Standard
1546
1547 \backslash 
1548 /
1549 \end_inset 
1550
1551 -build=unknown-unknown-linux-gnu
1552 \layout Standard
1553
1554 To 
1555 \begin_inset Quotes sld
1556 \end_inset 
1557
1558 cross
1559 \begin_inset Quotes srd
1560 \end_inset 
1561
1562 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
1563 ):
1564 \layout LyX-Code
1565
1566 ./configure -C 
1567 \backslash 
1568
1569 \newline 
1570 CFLAGS=
1571 \begin_inset Quotes srd
1572 \end_inset 
1573
1574 -mno-cygwin -O2
1575 \begin_inset Quotes srd
1576 \end_inset 
1577
1578  
1579 \backslash 
1580
1581 \newline 
1582 LDFLAGS=
1583 \begin_inset Quotes srd
1584 \end_inset 
1585
1586 -mno-cygwin
1587 \begin_inset Quotes srd
1588 \end_inset 
1589
1590  
1591 \backslash 
1592
1593 \newline 
1594 -
1595 \begin_inset ERT
1596 status Collapsed
1597
1598 \layout Standard
1599
1600 \backslash 
1601 /
1602 \end_inset 
1603
1604 -prefix=
1605 \begin_inset Quotes srd
1606 \end_inset 
1607
1608 /sdcc
1609 \begin_inset Quotes srd
1610 \end_inset 
1611
1612  
1613 \backslash 
1614
1615 \newline 
1616 -
1617 \begin_inset ERT
1618 status Collapsed
1619
1620 \layout Standard
1621
1622 \backslash 
1623 /
1624 \end_inset 
1625
1626 -datadir=
1627 \begin_inset Quotes srd
1628 \end_inset 
1629
1630 /sdcc
1631 \begin_inset Quotes srd
1632 \end_inset 
1633
1634  
1635 \backslash 
1636
1637 \newline 
1638 docdir=
1639 \begin_inset Quotes srd
1640 \end_inset 
1641
1642 /sdcc/doc
1643 \begin_inset Quotes srd
1644 \end_inset 
1645
1646  
1647 \backslash 
1648  
1649 \newline 
1650 include_dir_suffix=
1651 \begin_inset Quotes srd
1652 \end_inset 
1653
1654 include
1655 \begin_inset Quotes srd
1656 \end_inset 
1657
1658  
1659 \backslash 
1660
1661 \newline 
1662 lib_dir_suffix=
1663 \begin_inset Quotes srd
1664 \end_inset 
1665
1666 lib
1667 \begin_inset Quotes srd
1668 \end_inset 
1669
1670  
1671 \backslash 
1672
1673 \newline 
1674 sdccconf_h_dir_separator=
1675 \begin_inset Quotes srd
1676 \end_inset 
1677
1678
1679 \backslash 
1680
1681 \backslash 
1682
1683 \backslash 
1684
1685 \backslash 
1686
1687 \begin_inset Quotes srd
1688 \end_inset 
1689
1690  
1691 \backslash 
1692
1693 \newline 
1694 -
1695 \begin_inset ERT
1696 status Collapsed
1697
1698 \layout Standard
1699
1700 \backslash 
1701 /
1702 \end_inset 
1703
1704 -disable-ucsim
1705 \layout Standard
1706
1707 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
1708  The option '-
1709 \begin_inset ERT
1710 status Collapsed
1711
1712 \layout Standard
1713
1714 \backslash 
1715 /
1716 \end_inset 
1717
1718 -C' turns on caching, which gives a little bit extra speed.
1719  However if options are changed, it can be necessary to delete the config.cache
1720  file.
1721 \layout Section
1722
1723 Install paths
1724 \begin_inset LatexCommand \label{sub:Install-paths}
1725
1726 \end_inset 
1727
1728
1729 \begin_inset LatexCommand \index{Install paths}
1730
1731 \end_inset 
1732
1733
1734 \layout Standard
1735 \added_space_top medskip \align center 
1736
1737 \begin_inset  Tabular
1738 <lyxtabular version="3" rows="5" columns="4">
1739 <features>
1740 <column alignment="center" valignment="top" leftline="true" width="0">
1741 <column alignment="center" valignment="top" leftline="true" width="0">
1742 <column alignment="center" valignment="top" leftline="true" width="0">
1743 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
1744 <row topline="true" bottomline="true">
1745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1746 \begin_inset Text
1747
1748 \layout Standard
1749
1750
1751 \series bold 
1752 Description
1753 \end_inset 
1754 </cell>
1755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1756 \begin_inset Text
1757
1758 \layout Standard
1759
1760
1761 \series bold 
1762 Path
1763 \end_inset 
1764 </cell>
1765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1766 \begin_inset Text
1767
1768 \layout Standard
1769
1770
1771 \series bold 
1772 Default
1773 \end_inset 
1774 </cell>
1775 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1776 \begin_inset Text
1777
1778 \layout Standard
1779
1780
1781 \series bold 
1782 Win32 builds
1783 \end_inset 
1784 </cell>
1785 </row>
1786 <row topline="true">
1787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1788 \begin_inset Text
1789
1790 \layout Standard
1791
1792 Binary files*
1793 \end_inset 
1794 </cell>
1795 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1796 \begin_inset Text
1797
1798 \layout Standard
1799
1800
1801 \emph on 
1802 $EXEC_PREFIX
1803 \end_inset 
1804 </cell>
1805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1806 \begin_inset Text
1807
1808 \layout Standard
1809
1810 /usr/local/bin
1811 \end_inset 
1812 </cell>
1813 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1814 \begin_inset Text
1815
1816 \layout Standard
1817
1818
1819 \backslash 
1820 sdcc
1821 \backslash 
1822 bin
1823 \end_inset 
1824 </cell>
1825 </row>
1826 <row topline="true">
1827 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1828 \begin_inset Text
1829
1830 \layout Standard
1831
1832 Include files
1833 \end_inset 
1834 </cell>
1835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1836 \begin_inset Text
1837
1838 \layout Standard
1839
1840
1841 \emph on 
1842 $DATADIR/ $INCLUDE_DIR_SUFFIX
1843 \end_inset 
1844 </cell>
1845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1846 \begin_inset Text
1847
1848 \layout Standard
1849
1850 /usr/local/share/sdcc/include
1851 \end_inset 
1852 </cell>
1853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1854 \begin_inset Text
1855
1856 \layout Standard
1857
1858
1859 \backslash 
1860 sdcc
1861 \backslash 
1862 include
1863 \end_inset 
1864 </cell>
1865 </row>
1866 <row topline="true">
1867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1868 \begin_inset Text
1869
1870 \layout Standard
1871
1872 Library file**
1873 \end_inset 
1874 </cell>
1875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1876 \begin_inset Text
1877
1878 \layout Standard
1879
1880
1881 \emph on 
1882 $DATADIR/$LIB_DIR_SUFFIX
1883 \end_inset 
1884 </cell>
1885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1886 \begin_inset Text
1887
1888 \layout Standard
1889
1890 /usr/local/share/sdcc/lib
1891 \end_inset 
1892 </cell>
1893 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1894 \begin_inset Text
1895
1896 \layout Standard
1897
1898
1899 \backslash 
1900 sdcc
1901 \backslash 
1902 lib
1903 \end_inset 
1904 </cell>
1905 </row>
1906 <row topline="true" bottomline="true">
1907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1908 \begin_inset Text
1909
1910 \layout Standard
1911
1912 Documentation
1913 \end_inset 
1914 </cell>
1915 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1916 \begin_inset Text
1917
1918 \layout Standard
1919
1920
1921 \emph on 
1922 $DOCDIR
1923 \end_inset 
1924 </cell>
1925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1926 \begin_inset Text
1927
1928 \layout Standard
1929
1930 /usr/local/share/sdcc/doc
1931 \end_inset 
1932 </cell>
1933 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1934 \begin_inset Text
1935
1936 \layout Standard
1937
1938
1939 \backslash 
1940 sdcc
1941 \backslash 
1942 doc
1943 \end_inset 
1944 </cell>
1945 </row>
1946 </lyxtabular>
1947
1948 \end_inset 
1949
1950
1951 \layout Verse
1952
1953
1954 \size footnotesize 
1955 *compiler, preprocessor, assembler, and linker
1956 \newline 
1957 **the 
1958 \shape italic 
1959 model
1960 \shape default 
1961  is auto-appended by the compiler, e.g.
1962  small, large, z80, ds390 etc
1963 \layout Standard
1964 \noindent 
1965 The install paths can still be changed during `make install` with e.g.:
1966 \layout LyX-Code
1967
1968 make install prefix=$(HOME)/local/sdcc
1969 \layout Standard
1970
1971 Of course this doesn't change the search paths compiled into the binaries.
1972 \newline 
1973
1974 \newline 
1975 Moreover the install path can be changed by defining DESTDIR
1976 \begin_inset LatexCommand \index{DESTDIR}
1977
1978 \end_inset 
1979
1980 :
1981 \layout LyX-Code
1982
1983 make install DESTDIR=$(HOME)/sdcc.rpm/
1984 \layout Standard
1985
1986 Please note that DESTDIR must have a trailing slash!
1987 \layout Section
1988
1989 Search Paths
1990 \begin_inset LatexCommand \label{sub:Search-Paths}
1991
1992 \end_inset 
1993
1994
1995 \begin_inset LatexCommand \index{Search path}
1996
1997 \end_inset 
1998
1999
2000 \layout Standard
2001
2002 Some search paths or parts of them are determined by configure variables
2003  (in 
2004 \emph on 
2005 italics
2006 \emph default 
2007 , see section above).
2008  Further search paths are determined by environment variables during runtime.
2009  
2010 \newline 
2011 The paths searched when running the compiler are as follows (the first catch
2012  wins):
2013 \newline 
2014
2015 \newline 
2016 1.
2017  Binary files (preprocessor, assembler and linker)
2018 \newline 
2019
2020 \layout Standard
2021 \align center 
2022
2023 \begin_inset  Tabular
2024 <lyxtabular version="3" rows="4" columns="3">
2025 <features>
2026 <column alignment="block" valignment="top" leftline="true" width="0in">
2027 <column alignment="block" valignment="top" leftline="true" width="0in">
2028 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2029 <row topline="true" bottomline="true">
2030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2031 \begin_inset Text
2032
2033 \layout Standard
2034
2035 Search path
2036 \end_inset 
2037 </cell>
2038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2039 \begin_inset Text
2040
2041 \layout Standard
2042
2043 default
2044 \end_inset 
2045 </cell>
2046 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2047 \begin_inset Text
2048
2049 \layout Standard
2050
2051 Win32 builds
2052 \end_inset 
2053 </cell>
2054 </row>
2055 <row topline="true">
2056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2057 \begin_inset Text
2058
2059 \layout Standard
2060
2061 $SDCC_HOME/
2062 \emph on 
2063 $PPREFIX2BIN_DIR
2064 \end_inset 
2065 </cell>
2066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2067 \begin_inset Text
2068
2069 \layout Standard
2070
2071 $SDCC_HOME/bin
2072 \end_inset 
2073 </cell>
2074 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2075 \begin_inset Text
2076
2077 \layout Standard
2078
2079 $SDCC_HOME
2080 \backslash 
2081 bin
2082 \end_inset 
2083 </cell>
2084 </row>
2085 <row topline="true">
2086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2087 \begin_inset Text
2088
2089 \layout Standard
2090
2091 Path of argv[0] (if available)
2092 \end_inset 
2093 </cell>
2094 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2095 \begin_inset Text
2096
2097 \layout Standard
2098
2099 Path of argv[0]
2100 \end_inset 
2101 </cell>
2102 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2103 \begin_inset Text
2104
2105 \layout Standard
2106
2107 Path of argv[0]
2108 \end_inset 
2109 </cell>
2110 </row>
2111 <row topline="true" bottomline="true">
2112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2113 \begin_inset Text
2114
2115 \layout Standard
2116
2117 $PATH
2118 \end_inset 
2119 </cell>
2120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2121 \begin_inset Text
2122
2123 \layout Standard
2124
2125 $PATH
2126 \end_inset 
2127 </cell>
2128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2129 \begin_inset Text
2130
2131 \layout Standard
2132
2133 $PATH
2134 \end_inset 
2135 </cell>
2136 </row>
2137 </lyxtabular>
2138
2139 \end_inset 
2140
2141  
2142 \newline 
2143
2144 \layout Standard
2145 \noindent 
2146 2.
2147  Include files
2148 \newline 
2149
2150 \layout Standard
2151 \align center 
2152
2153 \begin_inset  Tabular
2154 <lyxtabular version="3" rows="6" columns="3">
2155 <features>
2156 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2157 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2158 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2159 <row topline="true" bottomline="true">
2160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2161 \begin_inset Text
2162
2163 \layout Standard
2164
2165 Search path
2166 \end_inset 
2167 </cell>
2168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2169 \begin_inset Text
2170
2171 \layout Standard
2172
2173 default
2174 \end_inset 
2175 </cell>
2176 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2177 \begin_inset Text
2178
2179 \layout Standard
2180
2181 Win32 builds
2182 \end_inset 
2183 </cell>
2184 </row>
2185 <row topline="true">
2186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2187 \begin_inset Text
2188
2189 \layout Standard
2190
2191 -
2192 \begin_inset ERT
2193 status Collapsed
2194
2195 \layout Standard
2196
2197 \backslash 
2198 /
2199 \end_inset 
2200
2201 -I dir
2202 \end_inset 
2203 </cell>
2204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2205 \begin_inset Text
2206
2207 \layout Standard
2208
2209 -
2210 \begin_inset ERT
2211 status Collapsed
2212
2213 \layout Standard
2214
2215 \backslash 
2216 /
2217 \end_inset 
2218
2219 -I dir
2220 \end_inset 
2221 </cell>
2222 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2223 \begin_inset Text
2224
2225 \layout Standard
2226
2227 -
2228 \begin_inset ERT
2229 status Collapsed
2230
2231 \layout Standard
2232
2233 \backslash 
2234 /
2235 \end_inset 
2236
2237 -I dir
2238 \end_inset 
2239 </cell>
2240 </row>
2241 <row topline="true">
2242 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2243 \begin_inset Text
2244
2245 \layout Standard
2246
2247 $SDCC_INCLUDE
2248 \end_inset 
2249 </cell>
2250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2251 \begin_inset Text
2252
2253 \layout Standard
2254
2255 $SDCC_INCLUDE
2256 \end_inset 
2257 </cell>
2258 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2259 \begin_inset Text
2260
2261 \layout Standard
2262
2263 $SDCC_INCLUDE
2264 \end_inset 
2265 </cell>
2266 </row>
2267 <row topline="true">
2268 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2269 \begin_inset Text
2270
2271 \layout Standard
2272
2273 $SDCC_HOME/
2274 \newline 
2275
2276 \emph on 
2277 $PREFIX2DATA_DIR/
2278 \newline 
2279 $INCLUDE_DIR_SUFFIX
2280 \end_inset 
2281 </cell>
2282 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2283 \begin_inset Text
2284
2285 \layout Standard
2286
2287 $SDCC_ HOME/
2288 \newline 
2289 share/sdcc/
2290 \newline 
2291 include
2292 \end_inset 
2293 </cell>
2294 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2295 \begin_inset Text
2296
2297 \layout Standard
2298
2299 $SDCC_HOME
2300 \backslash 
2301 include
2302 \end_inset 
2303 </cell>
2304 </row>
2305 <row topline="true">
2306 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2307 \begin_inset Text
2308
2309 \layout Standard
2310
2311 path(argv[0])/
2312 \newline 
2313
2314 \emph on 
2315 $BIN2DATADIR/
2316 \emph default 
2317
2318 \newline 
2319
2320 \emph on 
2321 $INCLUDE_DIR_SUFFIX
2322 \end_inset 
2323 </cell>
2324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2325 \begin_inset Text
2326
2327 \layout Standard
2328
2329 path(argv[0])/
2330 \newline 
2331 ../sdcc/include
2332 \newline 
2333 \SpecialChar ~
2334 \SpecialChar ~
2335 \SpecialChar ~
2336 \SpecialChar ~
2337 \SpecialChar ~
2338 \SpecialChar ~
2339 \SpecialChar ~
2340 \SpecialChar ~
2341 \SpecialChar ~
2342 \SpecialChar ~
2343 \SpecialChar ~
2344 \SpecialChar ~
2345 \SpecialChar ~
2346 \SpecialChar ~
2347 \SpecialChar ~
2348 \SpecialChar ~
2349 \SpecialChar ~
2350 \SpecialChar ~
2351 \SpecialChar ~
2352 \SpecialChar ~
2353 \SpecialChar ~
2354 \SpecialChar ~
2355 \SpecialChar ~
2356 \SpecialChar ~
2357 \SpecialChar ~
2358 \SpecialChar ~
2359 \SpecialChar ~
2360 \SpecialChar ~
2361 \SpecialChar ~
2362 \SpecialChar ~
2363 \SpecialChar ~
2364 \SpecialChar ~
2365 \SpecialChar ~
2366 \SpecialChar ~
2367 \SpecialChar ~
2368 \SpecialChar ~
2369 \SpecialChar ~
2370 \SpecialChar ~
2371
2372 \end_inset 
2373 </cell>
2374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2375 \begin_inset Text
2376
2377 \layout Standard
2378
2379 path(argv[0])
2380 \backslash 
2381 ..
2382 \backslash 
2383 include
2384 \end_inset 
2385 </cell>
2386 </row>
2387 <row topline="true" bottomline="true">
2388 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2389 \begin_inset Text
2390
2391 \layout Standard
2392
2393
2394 \emph on 
2395 $DATADIR/
2396 \emph default 
2397
2398 \newline 
2399
2400 \emph on 
2401 $INCLUDE_DIR_SUFFIX
2402 \end_inset 
2403 </cell>
2404 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2405 \begin_inset Text
2406
2407 \layout Standard
2408
2409 /usr/local/share/sdcc/
2410 \newline 
2411 include
2412 \end_inset 
2413 </cell>
2414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2415 \begin_inset Text
2416
2417 \layout Standard
2418
2419 (not on Win32)
2420 \end_inset 
2421 </cell>
2422 </row>
2423 </lyxtabular>
2424
2425 \end_inset 
2426
2427  
2428 \newline 
2429
2430 \layout Standard
2431 \noindent 
2432 The option -
2433 \begin_inset ERT
2434 status Collapsed
2435
2436 \layout Standard
2437
2438 \backslash 
2439 /
2440 \end_inset 
2441
2442 -nostdinc disables the last two search paths.
2443 \newline 
2444
2445 \newline 
2446 3.
2447  Library files 
2448 \newline 
2449
2450 \layout Standard
2451
2452 With the exception of 
2453 \begin_inset Quotes sld
2454 \end_inset 
2455
2456 -
2457 \begin_inset ERT
2458 status Collapsed
2459
2460 \layout Standard
2461
2462 \backslash 
2463 /
2464 \end_inset 
2465
2466 -L dir
2467 \begin_inset Quotes srd
2468 \end_inset 
2469
2470  the 
2471 \shape italic 
2472 model
2473 \shape default 
2474  is auto-appended by the compiler (e.g.
2475  small, large, z80, ds390 etc.).
2476  
2477 \newline 
2478
2479 \layout Standard
2480 \align center 
2481
2482 \begin_inset  Tabular
2483 <lyxtabular version="3" rows="6" columns="3">
2484 <features>
2485 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2486 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2487 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2488 <row topline="true" bottomline="true">
2489 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2490 \begin_inset Text
2491
2492 \layout Standard
2493
2494 Search path
2495 \end_inset 
2496 </cell>
2497 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2498 \begin_inset Text
2499
2500 \layout Standard
2501
2502 default
2503 \end_inset 
2504 </cell>
2505 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2506 \begin_inset Text
2507
2508 \layout Standard
2509
2510 Win32 builds
2511 \end_inset 
2512 </cell>
2513 </row>
2514 <row topline="true">
2515 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2516 \begin_inset Text
2517
2518 \layout Standard
2519
2520 -
2521 \begin_inset ERT
2522 status Collapsed
2523
2524 \layout Standard
2525
2526 \backslash 
2527 /
2528 \end_inset 
2529
2530 -L dir
2531 \end_inset 
2532 </cell>
2533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2534 \begin_inset Text
2535
2536 \layout Standard
2537
2538 -
2539 \begin_inset ERT
2540 status Collapsed
2541
2542 \layout Standard
2543
2544 \backslash 
2545 /
2546 \end_inset 
2547
2548 -L dir
2549 \end_inset 
2550 </cell>
2551 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2552 \begin_inset Text
2553
2554 \layout Standard
2555
2556 -
2557 \begin_inset ERT
2558 status Collapsed
2559
2560 \layout Standard
2561
2562 \backslash 
2563 /
2564 \end_inset 
2565
2566 -L dir
2567 \end_inset 
2568 </cell>
2569 </row>
2570 <row topline="true">
2571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2572 \begin_inset Text
2573
2574 \layout Standard
2575
2576 $SDCC_LIB/
2577 \newline 
2578
2579 \emph on 
2580 <model>
2581 \end_inset 
2582 </cell>
2583 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2584 \begin_inset Text
2585
2586 \layout Standard
2587
2588 $SDCC_LIB/
2589 \newline 
2590
2591 \emph on 
2592 <model>
2593 \end_inset 
2594 </cell>
2595 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2596 \begin_inset Text
2597
2598 \layout Standard
2599
2600 $SDCC_LIB
2601 \backslash 
2602
2603 \newline 
2604
2605 \emph on 
2606 <model>
2607 \end_inset 
2608 </cell>
2609 </row>
2610 <row topline="true">
2611 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2612 \begin_inset Text
2613
2614 \layout Standard
2615
2616 $SDCC_HOME/
2617 \newline 
2618
2619 \emph on 
2620 $PREFIX2DATA_DIR/
2621 \newline 
2622 $LIB_DIR_SUFFIX/<model>
2623 \end_inset 
2624 </cell>
2625 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2626 \begin_inset Text
2627
2628 \layout Standard
2629
2630 $SDCC_HOME/
2631 \newline 
2632 share/sdcc/
2633 \newline 
2634 lib/
2635 \emph on 
2636 <model>
2637 \end_inset 
2638 </cell>
2639 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2640 \begin_inset Text
2641
2642 \layout Standard
2643
2644 $SDCC_HOME
2645 \backslash 
2646 lib
2647 \backslash 
2648
2649 \emph on 
2650
2651 \newline 
2652 <model>
2653 \end_inset 
2654 </cell>
2655 </row>
2656 <row topline="true">
2657 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2658 \begin_inset Text
2659
2660 \layout Standard
2661
2662 path(argv[0])/
2663 \newline 
2664
2665 \emph on 
2666 $BIN2DATADIR/
2667 \emph default 
2668
2669 \newline 
2670
2671 \emph on 
2672 $LIB_DIR_SUFFIX/<model>
2673 \end_inset 
2674 </cell>
2675 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2676 \begin_inset Text
2677
2678 \layout Standard
2679
2680 path(argv[0])/
2681 \newline 
2682 ../sdcc/lib/
2683 \emph on 
2684 <model>
2685 \newline 
2686 \SpecialChar ~
2687 \SpecialChar ~
2688 \SpecialChar ~
2689 \SpecialChar ~
2690 \SpecialChar ~
2691 \SpecialChar ~
2692 \SpecialChar ~
2693 \SpecialChar ~
2694 \SpecialChar ~
2695 \SpecialChar ~
2696 \SpecialChar ~
2697 \SpecialChar ~
2698 \SpecialChar ~
2699 \SpecialChar ~
2700 \SpecialChar ~
2701 \SpecialChar ~
2702 \SpecialChar ~
2703 \SpecialChar ~
2704 \SpecialChar ~
2705 \SpecialChar ~
2706 \SpecialChar ~
2707 \SpecialChar ~
2708 \SpecialChar ~
2709 \SpecialChar ~
2710 \SpecialChar ~
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
2726 \end_inset 
2727 </cell>
2728 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2729 \begin_inset Text
2730
2731 \layout Standard
2732
2733 path(argv[0])
2734 \backslash 
2735
2736 \newline 
2737 ..
2738 \backslash 
2739 lib
2740 \backslash 
2741
2742 \emph on 
2743 <model>
2744 \newline 
2745 \SpecialChar ~
2746 \SpecialChar ~
2747 \SpecialChar ~
2748 \SpecialChar ~
2749 \SpecialChar ~
2750 \SpecialChar ~
2751 \SpecialChar ~
2752 \SpecialChar ~
2753 \SpecialChar ~
2754 \SpecialChar ~
2755 \SpecialChar ~
2756 \SpecialChar ~
2757 \SpecialChar ~
2758 \SpecialChar ~
2759 \SpecialChar ~
2760 \SpecialChar ~
2761 \SpecialChar ~
2762 \SpecialChar ~
2763 \SpecialChar ~
2764 \SpecialChar ~
2765 \SpecialChar ~
2766 \SpecialChar ~
2767 \SpecialChar ~
2768 \SpecialChar ~
2769 \SpecialChar ~
2770 \SpecialChar ~
2771 \SpecialChar ~
2772 \SpecialChar ~
2773 \SpecialChar ~
2774 \SpecialChar ~
2775 \SpecialChar ~
2776 \SpecialChar ~
2777 \SpecialChar ~
2778 \SpecialChar ~
2779 \SpecialChar ~
2780
2781 \end_inset 
2782 </cell>
2783 </row>
2784 <row topline="true" bottomline="true">
2785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2786 \begin_inset Text
2787
2788 \layout Standard
2789
2790
2791 \emph on 
2792 $DATADIR/
2793 \newline 
2794 $LIB_DIR_SUFFIX/<model>
2795 \end_inset 
2796 </cell>
2797 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2798 \begin_inset Text
2799
2800 \layout Standard
2801
2802 /usr/local/share/sdcc/
2803 \newline 
2804 lib/
2805 \emph on 
2806 <model>
2807 \end_inset 
2808 </cell>
2809 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2810 \begin_inset Text
2811
2812 \layout Standard
2813
2814 (not on Win32)
2815 \end_inset 
2816 </cell>
2817 </row>
2818 </lyxtabular>
2819
2820 \end_inset 
2821
2822
2823 \newline 
2824
2825 \layout Comment
2826
2827 Don't delete any of the stray spaces in the table above without checking
2828  the HTML output (last line)!
2829 \layout Standard
2830
2831 \SpecialChar ~
2832
2833 \newline 
2834 The option -
2835 \begin_inset ERT
2836 status Collapsed
2837
2838 \layout Standard
2839
2840 \backslash 
2841 /
2842 \end_inset 
2843
2844 -nostdlib disables the last two search paths.
2845 \layout Section
2846
2847 Building SDCC
2848 \begin_inset LatexCommand \index{Building SDCC}
2849
2850 \end_inset 
2851
2852
2853 \layout Subsection
2854
2855 Building SDCC on Linux
2856 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
2857
2858 \end_inset 
2859
2860
2861 \layout Enumerate
2862
2863
2864 \series medium 
2865 Download the source package
2866 \series default 
2867  either from the SDCC CVS repository or from the nightly snapshots
2868 \series medium 
2869 , it will be named something like sdcc
2870 \series default 
2871 .src
2872 \series medium 
2873 .t
2874 \series default 
2875 ar.
2876 \series medium 
2877 gz
2878 \series default 
2879  
2880 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
2881
2882 \end_inset 
2883
2884 .
2885 \layout Enumerate
2886
2887
2888 \series medium 
2889 Bring up a command line terminal, such as xterm.
2890 \layout Enumerate
2891
2892
2893 \series medium 
2894 Unpack the file using a command like: 
2895 \family sans 
2896 \series bold 
2897 "tar -xvzf sdcc.src.tar.gz
2898 \family default 
2899 \series default 
2900 "
2901 \series medium 
2902 , this will create a sub-directory called sdcc with all of the sources.
2903 \layout Enumerate
2904
2905 Change directory into the main SDCC directory, for example type: 
2906 \family sans 
2907 \series bold 
2908 "cd sdcc
2909 \series default 
2910 ".
2911 \layout Enumerate
2912
2913
2914 \series medium 
2915 Type 
2916 \family sans 
2917 \series bold 
2918 "./configure
2919 \family default 
2920 \series default 
2921 ".
2922  This configures the package for compilation on your system.
2923 \layout Enumerate
2924
2925
2926 \series medium 
2927 Type 
2928 \family sans 
2929 \series bold 
2930 "make
2931 \family default 
2932 \series default 
2933 "
2934 \series medium 
2935 .
2936
2937 \series default 
2938  All of the source packages will compile, this can take a while.
2939 \layout Enumerate
2940
2941
2942 \series medium 
2943 Type 
2944 \family sans 
2945 \series bold 
2946 "make install"
2947 \family default 
2948 \series default 
2949  as root
2950 \series medium 
2951 .
2952
2953 \series default 
2954  This copies the binary executables, the include files, the libraries and
2955  the documentation to the install directories.
2956  Proceed with section 
2957 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
2958
2959 \end_inset 
2960
2961 .
2962 \layout Subsection
2963
2964 Building SDCC on OSX 2.x
2965 \layout Standard
2966
2967 Follow the instruction for Linux.
2968 \newline 
2969
2970 \newline 
2971 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
2972 )) fails to compile SDCC.
2973  Fortunately there's also gcc 2.9.x installed, which works fine.
2974  This compiler can be selected by running 'configure' with:
2975 \layout LyX-Code
2976
2977 ./configure CC=gcc2 CXX=g++2
2978 \layout Subsection
2979
2980 Cross compiling SDCC on Linux for Windows
2981 \layout Standard
2982
2983 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
2984  See section 'Configure Options'.
2985 \layout Subsection
2986
2987 Building SDCC on Windows 
2988 \layout Standard
2989
2990 With the exception of Cygwin the SDCC binaries uCsim and sdcdb can't be
2991  built on Windows.
2992  They use Unix-sockets, which are not available on Win32.
2993 \layout Subsection
2994
2995 Building SDCC using Cygwin and Mingw32
2996 \layout Standard
2997
2998 For building and installing a Cygwin executable follow the instructions
2999  for Linux.
3000 \newline 
3001
3002 \newline 
3003 On Cygwin a 
3004 \begin_inset Quotes sld
3005 \end_inset 
3006
3007 native
3008 \begin_inset Quotes srd
3009 \end_inset 
3010
3011  Win32-binary can be built, which will not need the Cygwin-DLL.
3012  For the necessary 'configure' options see section 'configure options' or
3013  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3014 \newline 
3015
3016 \newline 
3017 In order to install Cygwin on Windows download setup.exe from 
3018 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3019
3020 \end_inset 
3021
3022 .
3023  Run it, set the 
3024 \begin_inset Quotes sld
3025 \end_inset 
3026
3027 default text file type
3028 \begin_inset Quotes srd
3029 \end_inset 
3030
3031  to 
3032 \begin_inset Quotes sld
3033 \end_inset 
3034
3035 unix
3036 \begin_inset Quotes srd
3037 \end_inset 
3038
3039  and download/install at least the following packages.
3040  Some packages are selected by default, others will be automatically selected
3041  because of dependencies with the manually selected packages.
3042  Never deselect these packages!
3043 \layout Itemize
3044
3045 flex
3046 \layout Itemize
3047
3048 bison
3049 \layout Itemize
3050
3051 gcc ; version 3.x is fine, no need to use the old 2.9x
3052 \layout Itemize
3053
3054 binutils ; selected with gcc
3055 \layout Itemize
3056
3057 make
3058 \layout Itemize
3059
3060 rxvt ; a nice console, which makes life much easier under windoze (see below)
3061 \layout Itemize
3062
3063 man ; not really needed for building SDCC, but you'll miss it sooner or
3064  later
3065 \layout Itemize
3066
3067 less ; not really needed for building SDCC, but you'll miss it sooner or
3068  later
3069 \layout Itemize
3070
3071 cvs ; only if you use CVS access
3072 \layout Standard
3073
3074 If you want to develop something you'll need:
3075 \layout Itemize
3076
3077 python ; for the regression tests
3078 \layout Itemize
3079
3080 gdb ; the gnu debugger, together with the nice GUI 
3081 \begin_inset Quotes sld
3082 \end_inset 
3083
3084 insight
3085 \begin_inset Quotes srd
3086 \end_inset 
3087
3088
3089 \layout Itemize
3090
3091 openssh ; to access the CF or commit changes
3092 \layout Itemize
3093
3094 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3095  use autoconf-stable!
3096 \layout Standard
3097
3098 rxvt is a nice console with history.
3099  Replace in your cygwin.bat the line
3100 \layout LyX-Code
3101
3102 bash -
3103 \begin_inset ERT
3104 status Collapsed
3105
3106 \layout Standard
3107
3108 \backslash 
3109 /
3110 \end_inset 
3111
3112 -login -i 
3113 \layout Standard
3114
3115 with (one line):
3116 \layout LyX-Code
3117
3118 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3119 \layout LyX-Code
3120
3121      -bg black -fg white -geometry 100x65 -e bash -
3122 \begin_inset ERT
3123 status Collapsed
3124
3125 \layout Standard
3126
3127 \backslash 
3128 /
3129 \end_inset 
3130
3131 -login
3132 \layout Standard
3133
3134 Text selected with the mouse is automatically copied to the clipboard, pasting
3135  works with shift-insert.
3136 \newline 
3137
3138 \newline 
3139 The other good tip is to make sure you have no //c/-style paths anywhere,
3140  use /cygdrive/c/ instead.
3141  Using // invokes a network lookup which is very slow.
3142  If you think 
3143 \begin_inset Quotes sld
3144 \end_inset 
3145
3146 cygdrive
3147 \begin_inset Quotes srd
3148 \end_inset 
3149
3150  is too long, you can change it with e.g.
3151 \layout LyX-Code
3152
3153 mount -s -u -c /mnt
3154 \layout Standard
3155
3156 SDCC sources use the unix line ending LF.
3157  Life is much easier, if you store the source tree on a drive which is mounted
3158  in binary mode.
3159  And use an editor which can handle LF-only line endings.
3160  Make sure not to commit files with windows line endings.
3161  The tabulator spacing
3162 \begin_inset LatexCommand \index{tabulator spacing (8 columns)}
3163
3164 \end_inset 
3165
3166  used in the project is 8.
3167  Although a tabulator spacing of 8 is a sensible choice for programmers
3168  (it's a power of 2 and allows to display 8/16 bit signed variables without
3169  loosing columns) the plan is to move towards using only spaces in the source.
3170 \layout Subsection
3171
3172 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3173 \layout Standard
3174
3175
3176 \series medium 
3177 Download the source package
3178 \series default 
3179  either from the SDCC CVS repository or from the 
3180 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3181
3182 \end_inset 
3183
3184
3185 \series medium 
3186 , it will be named something like sdcc
3187 \series default 
3188 .src
3189 \series medium 
3190 .tgz.
3191
3192 \series default 
3193  SDCC is distributed with all the projects, workspaces, and files you need
3194  to build it using Visual C++ 6.0/NET (except for sdcdb.exe which currently
3195  doesn't build under MSVC).
3196  The workspace name is 'sdcc.dsw'.
3197  Please note that as it is now, all the executables are created in a folder
3198  called sdcc
3199 \backslash 
3200 bin_vc.
3201  Once built you need to copy the executables from sdcc
3202 \backslash 
3203 bin_vc to sdcc
3204 \backslash 
3205 bin before running SDCC.
3206  
3207 \newline 
3208
3209 \newline 
3210 WARNING: Visual studio is very picky with line terminations; it expects
3211  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
3212  If you are getting a message such as "This makefile was not generated by
3213  Developer Studio etc.
3214  etc.
3215 \begin_inset Quotes srd
3216 \end_inset 
3217
3218  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
3219  need to convert the Unix style line endings to DOS style line endings.
3220  To do so you can use the 
3221 \begin_inset Quotes sld
3222 \end_inset 
3223
3224 unix2dos
3225 \begin_inset Quotes srd
3226 \end_inset 
3227
3228  utility freely available on the internet.
3229  Doug Hawkins reported in the sdcc-user list that this works:
3230 \newline 
3231
3232 \newline 
3233 C:
3234 \backslash 
3235 Programming
3236 \backslash 
3237 SDCC> unix2dos sdcc.dsw
3238 \newline 
3239 C:
3240 \backslash 
3241 Programming
3242 \backslash 
3243 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
3244 \newline 
3245
3246 \newline 
3247 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3248  flex.exe, and gawk.exe.
3249  One good place to get them is 
3250 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3251
3252 \end_inset 
3253
3254
3255 \newline 
3256
3257 \newline 
3258 Download the file UnxUtils
3259 \begin_inset LatexCommand \index{UnxUtils}
3260
3261 \end_inset 
3262
3263 .zip.
3264  Now you have to install the utilities and setup MSVC so it can locate the
3265  required programs.
3266  Here there are two alternatives (choose one!):
3267 \layout Enumerate
3268
3269 The easy way:
3270 \newline 
3271
3272 \newline 
3273 a) Extract UnxUtils.zip to your C:
3274 \backslash 
3275  hard disk PRESERVING the original paths, otherwise bison won't work.
3276  (If you are using WinZip make certain that 'Use folder names' is selected)
3277 \newline 
3278
3279 \newline 
3280 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3281  in 'Show directories for:' select 'Executable files', and in the directories
3282  window add a new path: 'C:
3283 \backslash 
3284 user
3285 \backslash 
3286 local
3287 \backslash 
3288 wbin', click ok.
3289 \newline 
3290
3291 \newline 
3292 (As a side effect, you get a bunch of Unix utilities that could be useful,
3293  such as diff and patch.)
3294 \layout Enumerate
3295
3296 A more compact way:
3297 \newline 
3298
3299 \newline 
3300 This one avoids extracting a bunch of files you may not use, but requires
3301  some extra work:
3302 \newline 
3303
3304 \newline 
3305 a) Create a directory were to put the tools needed, or use a directory already
3306  present.
3307  Say for example 'C:
3308 \backslash 
3309 util'.
3310 \newline 
3311
3312 \newline 
3313 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3314  to such directory WITHOUT preserving the original paths.
3315  (If you are using WinZip make certain that 'Use folder names' is not selected)
3316 \newline 
3317
3318 \newline 
3319 c) Rename bison.exe to '_bison.exe'.
3320 \newline 
3321
3322 \newline 
3323 d) Create a batch file 'bison.bat' in 'C:
3324 \backslash 
3325 util
3326 \backslash 
3327 ' and add these lines: 
3328 \newline 
3329 \SpecialChar ~
3330 \SpecialChar ~
3331 set BISON_SIMPLE=C:
3332 \backslash 
3333 util
3334 \backslash 
3335 bison.simple 
3336 \newline 
3337 \SpecialChar ~
3338 \SpecialChar ~
3339 set BISON_HAIRY=C:
3340 \backslash 
3341 util
3342 \backslash 
3343 bison.hairy
3344 \newline 
3345 \SpecialChar ~
3346 \SpecialChar ~
3347 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3348 \newline 
3349
3350 \newline 
3351 Steps 'c' and 'd' are needed because bison requires by default that the
3352  files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3353  '/usr/local/share/' I think.
3354  So it is necessary to tell bison where those files are located if they
3355  are not in such directory.
3356  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3357 \newline 
3358
3359 \newline 
3360 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3361  in 'Show directories for:' select 'Executable files', and in the directories
3362  window add a new path: 'c:
3363 \backslash 
3364 util', click ok.
3365  Note that you can use any other path instead of 'c:
3366 \backslash 
3367 util', even the path where the Visual C++ tools are, probably: 'C:
3368 \backslash 
3369 Program Files
3370 \backslash 
3371 Microsoft Visual Studio
3372 \backslash 
3373 Common
3374 \backslash 
3375 Tools'.
3376  So you don't have to execute step 'e' :)
3377 \layout Standard
3378
3379 That is it.
3380  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3381  the executables from sdcc
3382 \backslash 
3383 bin_vc to sdcc
3384 \backslash 
3385 bin, and you can compile using SDCC.
3386 \layout Subsection
3387
3388 Building SDCC Using Borland
3389 \layout Enumerate
3390
3391 From the sdcc directory, run the command "make -f Makefile.bcc".
3392  This should regenerate all the .exe files in the bin directory except for
3393  sdcdb.exe (which currently doesn't build under Borland C++).
3394 \layout Enumerate
3395
3396 If you modify any source files and need to rebuild, be aware that the dependenci
3397 es may not be correctly calculated.
3398  The safest option is to delete all .obj files and run the build again.
3399  From a Cygwin BASH prompt, this can easily be done with the command (be
3400  sure you are in the sdcc directory):
3401 \newline 
3402
3403 \newline 
3404
3405 \family sans 
3406 \series bold 
3407 find .
3408  
3409 \backslash 
3410 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
3411 \backslash 
3412 ) -print -exec rm {} 
3413 \backslash 
3414 ;
3415 \family default 
3416 \series default 
3417
3418 \newline 
3419
3420 \newline 
3421 or on Windows NT/2000/XP from the command prompt with the command:
3422 \newline 
3423
3424 \family sans 
3425 \series bold 
3426
3427 \newline 
3428 del /s *.obj *.lib *.rul
3429 \family default 
3430 \series default 
3431  from the sdcc directory.
3432 \layout Subsection
3433
3434 Windows Install Using a Binary Package
3435 \begin_inset LatexCommand \label{sub:Windows-Install}
3436
3437 \end_inset 
3438
3439
3440 \layout Enumerate
3441
3442 Download the binary package from 
3443 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3444
3445 \end_inset 
3446
3447  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
3448  This should unpack to a group of sub-directories.
3449  An example directory structure after unpacking the mingw32 package is:
3450  c:
3451 \backslash 
3452 sdcc
3453 \backslash 
3454 bin for the executables, c:
3455 \backslash 
3456 sdcc
3457 \backslash 
3458 include and c:
3459 \backslash 
3460 sdcc
3461 \backslash 
3462 lib for the include and libraries.
3463 \layout Enumerate
3464
3465 Adjust your environment variable PATH to include the location of the bin
3466  directory or start sdcc using the full path.
3467 \layout Section
3468
3469 Building the Documentation
3470 \layout Standard
3471
3472 If the necessary tools (LyX, LaTeX, LaTeX2HTML) are installed it is as easy
3473  as changing into the doc directory and typing 
3474 \family sans 
3475 \series bold 
3476
3477 \begin_inset Quotes srd
3478 \end_inset 
3479
3480 make
3481 \begin_inset Quotes srd
3482 \end_inset 
3483
3484
3485 \family default 
3486 \series default 
3487  there.
3488  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
3489 x).
3490  Using LyX 
3491 \begin_inset LatexCommand \url{www.lyx.org}
3492
3493 \end_inset 
3494
3495  as editor this is straightforward.
3496  Prebuilt documentation in html and pdf format is available from 
3497 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3498
3499 \end_inset 
3500
3501 .
3502 \layout Section
3503
3504 Reading the Documentation
3505 \layout Standard
3506
3507 Currently reading the document in pdf format is recommended, as for unknown
3508  reason the hyperlinks are working there whereas in the html version they
3509  are not
3510 \begin_inset Foot
3511 collapsed false
3512
3513 \layout Standard
3514
3515 If you should know why please drop us a note
3516 \end_inset 
3517
3518 .
3519  You'll find the pdf version at 
3520 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
3521
3522 \end_inset 
3523
3524 .
3525 \newline 
3526 This documentation is in some aspects different from a commercial documentation:
3527  
3528 \layout Itemize
3529
3530 It tries to document SDCC for several processor architectures in one document
3531  (commercially these probably would be separate documents/products).
3532  This document
3533 \begin_inset LatexCommand \index{Status of documentation}
3534
3535 \end_inset 
3536
3537  currently matches SDCC for mcs51 and DS390 best and does give too few informati
3538 on about f.e.
3539  Z80, PIC14, PIC16 and HC08.
3540 \layout Itemize
3541
3542 There are many references pointing away from this documentation.
3543  Don't let this distract you.
3544  If there f.e.
3545  was a reference like 
3546 \begin_inset LatexCommand \url{www.opencores.org}
3547
3548 \end_inset 
3549
3550  together with a statement 
3551 \begin_inset Quotes sld
3552 \end_inset 
3553
3554 some processors which are targetted by SDCC can be implemented in a 
3555 \emph on 
3556 f
3557 \emph default 
3558 ield 
3559 \emph on 
3560 p
3561 \emph default 
3562 rogrammable 
3563 \emph on 
3564 g
3565 \emph default 
3566 ate 
3567 \emph on 
3568 a
3569 \emph default 
3570 rray
3571 \begin_inset LatexCommand \index{fpga (field programmable gate array)}
3572
3573 \end_inset 
3574
3575
3576 \begin_inset Quotes srd
3577 \end_inset 
3578
3579  we expect you to have a quick look there and come back.
3580  If you read this you are on the right track.
3581 \layout Itemize
3582
3583 Some sections attribute more space to problems, restrictions and warnings
3584  than to the solution.
3585 \layout Itemize
3586
3587 The installation section and the section about the debugger is intimidating.
3588 \layout Itemize
3589
3590 There are still lots of typos and there are more different writing styles
3591  than pictures.
3592 \layout Section
3593
3594 Testing the SDCC Compiler
3595 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
3596
3597 \end_inset 
3598
3599
3600 \layout Standard
3601
3602 The first thing you should do after installing your SDCC compiler is to
3603  see if it runs.
3604  Type 
3605 \family sans 
3606 \series bold 
3607 "sdcc -
3608 \begin_inset ERT
3609 status Collapsed
3610
3611 \layout Standard
3612
3613 \backslash 
3614 /
3615 \end_inset 
3616
3617 -version"
3618 \begin_inset LatexCommand \index{version}
3619
3620 \end_inset 
3621
3622
3623 \family default 
3624 \series default 
3625  at the prompt, and the program should run and tell you the version.
3626  If it doesn't run, or gives a message about not finding sdcc program, then
3627  you need to check over your installation.
3628  Make sure that the sdcc bin directory is in your executable search path
3629  defined by the PATH environment setting (
3630 \series medium 
3631 see 
3632 \series default 
3633 section 
3634 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3635
3636 \end_inset 
3637
3638 \SpecialChar ~
3639
3640 \series medium 
3641 Install trouble-shooting for suggestions
3642 \series default 
3643 ).
3644  Make sure that the sdcc program is in the bin folder, if not perhaps something
3645  did not install correctly.
3646 \newline 
3647
3648 \newline 
3649
3650 \series medium 
3651 SDCC 
3652 \series default 
3653 is commonly installed as described in section 
3654 \begin_inset Quotes sld
3655 \end_inset 
3656
3657 Install and search paths
3658 \begin_inset Quotes srd
3659 \end_inset 
3660
3661 .
3662 \newline 
3663
3664 \newline 
3665
3666 \series medium 
3667 Make sure the compiler works on a very simple example.
3668  Type in the following test.c program using your favorite 
3669 \series default 
3670 ASCII 
3671 \series medium 
3672 editor:
3673 \layout Verse
3674
3675
3676 \family typewriter 
3677 char test;
3678 \newline 
3679
3680 \newline 
3681 void main(void) {
3682 \newline 
3683 \SpecialChar ~
3684 \SpecialChar ~
3685 \SpecialChar ~
3686 \SpecialChar ~
3687 test=0;
3688 \newline 
3689 }
3690 \layout Standard
3691
3692
3693 \series medium 
3694 Compile this using the following command: 
3695 \family sans 
3696 \series bold 
3697 "sdcc -c test.c".
3698
3699 \family default 
3700 \series default 
3701  
3702 \series medium 
3703 If all goes well, the compiler will generate a test.asm and test.rel file.
3704  Congratulations, you've just compiled your first program with SDCC.
3705  We used the -c option to tell SDCC not to link the generated code, just
3706  to keep things simple for this step.
3707 \series default 
3708
3709 \newline 
3710
3711 \newline 
3712
3713 \series medium 
3714 The next step is to try it with the linker.
3715  Type in 
3716 \family sans 
3717 \series bold 
3718 "sdcc test.c
3719 \family default 
3720 \series default 
3721 "
3722 \series medium 
3723 .
3724  If all goes well the compiler will link with the libraries and produce
3725  a test.ihx output file.
3726  If this step fails
3727 \series default 
3728  
3729 \series medium 
3730 (no test.ihx, and the linker generates warnings), then the problem is most
3731  likely that 
3732 \series default 
3733 SDCC
3734 \series medium 
3735  cannot find the 
3736 \series default 
3737 /
3738 \series medium 
3739 usr/local/share/sdcc/lib directory
3740 \series default 
3741  
3742 \series medium 
3743 (see 
3744 \series default 
3745 section 
3746 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3747
3748 \end_inset 
3749
3750 \SpecialChar ~
3751
3752 \series medium 
3753 Install trouble-shooting for suggestions).
3754 \series default 
3755
3756 \newline 
3757
3758 \newline 
3759
3760 \series medium 
3761 The final test is to ensure 
3762 \series default 
3763 SDCC
3764 \series medium 
3765  can use the 
3766 \series default 
3767 standard
3768 \series medium 
3769  header files and libraries.
3770  Edit test.c and change it to the following:
3771 \layout Verse
3772
3773
3774 \family typewriter 
3775 #include <string.h>
3776 \newline 
3777
3778 \newline 
3779 char str1[10];
3780 \newline 
3781
3782 \newline 
3783 void main(void) {
3784 \newline 
3785 \SpecialChar ~
3786 \SpecialChar ~
3787 strcpy(str1, "testing");
3788 \newline 
3789 }
3790 \layout Standard
3791
3792
3793 \series medium 
3794 Compile this by typing 
3795 \family sans 
3796 \series bold 
3797 "sdcc test.c"
3798 \family default 
3799 \series medium 
3800 .
3801  This should generate a test.ihx output file, and it should give no warnings
3802  such as not finding the string.h file.
3803  If it cannot find the string.h file, then the problem is that 
3804 \series default 
3805 SDCC
3806 \series medium 
3807  cannot find the /usr/local/share/sdcc/include directory
3808 \series default 
3809  
3810 \series medium 
3811 (see the 
3812 \series default 
3813 section 
3814 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3815
3816 \end_inset 
3817
3818 \SpecialChar ~
3819
3820 \series medium 
3821 Install trouble-shooting section for suggestions).
3822
3823 \series default 
3824  Use option 
3825 \series bold 
3826 -
3827 \begin_inset ERT
3828 status Collapsed
3829
3830 \layout Standard
3831
3832 \backslash 
3833 /
3834 \end_inset 
3835
3836 -print-search-dirs
3837 \series default 
3838
3839 \begin_inset LatexCommand \index{-\/-print-search-dirs}
3840
3841 \end_inset 
3842
3843  to find exactly where SDCC is looking for the include and lib files.
3844 \layout Section
3845
3846 Install Trouble-shooting
3847 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
3848
3849 \end_inset 
3850
3851
3852 \begin_inset LatexCommand \index{Install trouble-shooting}
3853
3854 \end_inset 
3855
3856
3857 \layout Subsection
3858
3859 If SDCC does not build correctly
3860 \layout Standard
3861
3862 A thing to try is starting from scratch by unpacking the .tgz source package
3863  again in an empty directory.
3864  Configure it like:
3865 \newline 
3866
3867 \newline 
3868
3869 \family sans 
3870 \series bold 
3871 ./configure 2>&1 | tee configure.log
3872 \family default 
3873 \series default 
3874
3875 \newline 
3876
3877 \newline 
3878 and build it like:
3879 \newline 
3880
3881 \newline 
3882
3883 \family sans 
3884 \series bold 
3885 make 2>&1 | tee make.log
3886 \family default 
3887 \series default 
3888
3889 \newline 
3890
3891 \newline 
3892 If anything goes wrong, you can review the log files to locate the problem.
3893  Or a relevant part of this can be attached to an email that could be helpful
3894  when requesting help from the mailing list.
3895 \layout Subsection
3896
3897 What the 
3898 \begin_inset Quotes sld
3899 \end_inset 
3900
3901 ./configure
3902 \begin_inset Quotes srd
3903 \end_inset 
3904
3905  does
3906 \layout Standard
3907
3908 The 
3909 \begin_inset Quotes sld
3910 \end_inset 
3911
3912 ./configure
3913 \begin_inset Quotes srd
3914 \end_inset 
3915
3916  command is a script that analyzes your system and performs some configuration
3917  to ensure the source package compiles on your system.
3918  It will take a few minutes to run, and will compile a few tests to determine
3919  what compiler features are installed.
3920 \layout Subsection
3921
3922 What the 
3923 \begin_inset Quotes sld
3924 \end_inset 
3925
3926 make
3927 \begin_inset Quotes srd
3928 \end_inset 
3929
3930  does
3931 \layout Standard
3932
3933 This runs the GNU make tool, which automatically compiles all the source
3934  packages into the final installed binary executables.
3935 \layout Subsection
3936
3937 What the 
3938 \begin_inset Quotes sld
3939 \end_inset 
3940
3941 make install
3942 \begin_inset Quotes erd
3943 \end_inset 
3944
3945  command does.
3946 \layout Standard
3947
3948 This will install the compiler, other executables libraries and include
3949  files into the appropriate directories.
3950  See sections 
3951 \begin_inset LatexCommand \ref{sub:Install-paths}
3952
3953 \end_inset 
3954
3955 ,\SpecialChar ~
3956
3957 \begin_inset LatexCommand \ref{sub:Search-Paths}
3958
3959 \end_inset 
3960
3961 \SpecialChar ~
3962 about install and search paths.
3963 \newline 
3964 On most systems you will need super-user privileges to do this.
3965 \layout Section
3966
3967 Components of SDCC
3968 \layout Standard
3969
3970 SDCC is not just a compiler, but a collection of tools by various developers.
3971  These include linkers, assemblers, simulators and other components.
3972  Here is a summary of some of the components.
3973  Note that the included simulator and assembler have separate documentation
3974  which you can find in the source package in their respective directories.
3975  As SDCC grows to include support for other processors, other packages from
3976  various developers are included and may have their own sets of documentation.
3977 \newline 
3978
3979 \newline 
3980 You might want to look at the files which are installed in <installdir>.
3981  At the time of this writing, we find the following programs for gcc-builds:
3982 \newline 
3983  
3984 \newline 
3985 In <installdir>/bin:
3986 \layout Itemize
3987
3988 sdcc - The compiler.
3989 \layout Itemize
3990
3991 sdcpp - The C preprocessor.
3992 \layout Itemize
3993
3994 asx8051 - The assembler for 8051 type processors.
3995 \layout Itemize
3996
3997 as-z80
3998 \series bold 
3999
4000 \series default 
4001 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
4002 \layout Itemize
4003
4004 aslink -The linker for 8051 type processors.
4005 \layout Itemize
4006
4007 link-z80
4008 \series bold 
4009
4010 \series default 
4011 link-gbz80 - The Z80 and GameBoy Z80 linkers.
4012 \layout Itemize
4013
4014 s51 - The ucSim 8051 simulator.
4015 \layout Itemize
4016
4017 sdcdb - The source debugger.
4018 \layout Itemize
4019
4020 packihx - A tool to pack (compress) Intel hex files.
4021 \layout Standard
4022
4023 In <installdir>/share/sdcc/include
4024 \layout Itemize
4025
4026 the include files
4027 \layout Standard
4028
4029 In <installdir>/share/sdcc/lib
4030 \layout Itemize
4031
4032 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
4033  relocatables.
4034 \layout Standard
4035
4036 In <installdir>/share/sdcc/doc
4037 \layout Itemize
4038
4039 the documentation
4040 \layout Standard
4041
4042 As development for other processors proceeds, this list will expand to include
4043  executables to support processors like AVR, PIC, etc.
4044 \layout Subsection
4045
4046 sdcc - The Compiler
4047 \layout Standard
4048
4049 This is the actual compiler, it in turn uses the c-preprocessor and invokes
4050  the assembler and linkage editor.
4051 \layout Subsection
4052
4053 sdcpp - The C-Preprocessor
4054 \layout Standard
4055
4056 The preprocessor
4057 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
4058
4059 \end_inset 
4060
4061  is a modified version of the GNU preprocessor.
4062  The C preprocessor is used to pull in #include sources, process #ifdef
4063  statements, #defines and so on.
4064 \layout Subsection
4065
4066 as
4067 \emph on 
4068 xxxx
4069 \emph default 
4070 , aslink, link-
4071 \emph on 
4072 xxx
4073 \emph default 
4074  - The Assemblers and Linkage Editors
4075 \layout Standard
4076
4077 This is retargettable assembler & linkage editor, it was developed by Alan
4078  Baldwin.
4079  John Hartman created the version for 8051, and I (Sandeep) have made some
4080  enhancements and bug fixes for it to work properly with SDCC.
4081 \layout Subsection
4082
4083 s51 - The Simulator
4084 \layout Standard
4085
4086 S51
4087 \begin_inset LatexCommand \index{s51}
4088
4089 \end_inset 
4090
4091  is a freeware, opensource simulator developed by Daniel Drotos (
4092 \begin_inset LatexCommand \url{mailto:drdani@mazsola.iit.uni-miskolc.hu}
4093
4094 \end_inset 
4095
4096 ).
4097  The simulator is built as part of the build process.
4098  For more information visit Daniel's web site at: 
4099 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
4100
4101 \end_inset 
4102
4103 .
4104  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
4105  XA51 family.
4106 \layout Subsection
4107
4108 sdcdb - Source Level Debugger
4109 \layout Standard
4110
4111 Sdcdb
4112 \begin_inset LatexCommand \index{sdcdb (debugger)}
4113
4114 \end_inset 
4115
4116  is the companion source level debugger.
4117  More about sdcdb in section 
4118 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
4119
4120 \end_inset 
4121
4122 .
4123  The current version of the debugger uses Daniel's Simulator S51
4124 \begin_inset LatexCommand \index{s51}
4125
4126 \end_inset 
4127
4128 , but can be easily changed to use other simulators.
4129  
4130 \layout Chapter
4131
4132 Using SDCC
4133 \layout Section
4134
4135 Compiling
4136 \layout Subsection
4137
4138 Single Source File Projects
4139 \layout Standard
4140
4141 For single source file 8051 projects the process is very simple.
4142  Compile your programs with the following command 
4143 \family sans 
4144 \series bold 
4145 "sdcc sourcefile.c".
4146
4147 \family default 
4148 \series default 
4149  This will compile, assemble and link your source file.
4150  Output files are as follows:
4151 \layout Itemize
4152
4153 sourcefile.asm
4154 \begin_inset LatexCommand \index{<file>.asm}
4155
4156 \end_inset 
4157
4158  - Assembler source
4159 \begin_inset LatexCommand \index{Assembler source}
4160
4161 \end_inset 
4162
4163  file created by the compiler
4164 \layout Itemize
4165
4166 sourcefile.lst
4167 \begin_inset LatexCommand \index{<file>.lst}
4168
4169 \end_inset 
4170
4171  - Assembler listing
4172 \begin_inset LatexCommand \index{Assembler listing}
4173
4174 \end_inset 
4175
4176  file created by the Assembler
4177 \layout Itemize
4178
4179 sourcefile.rst
4180 \begin_inset LatexCommand \index{<file>.rst}
4181
4182 \end_inset 
4183
4184  - Assembler listing
4185 \begin_inset LatexCommand \index{Assembler listing}
4186
4187 \end_inset 
4188
4189  file updated with linkedit information, created by linkage editor
4190 \layout Itemize
4191
4192 sourcefile.sym
4193 \begin_inset LatexCommand \index{<file>.sym}
4194
4195 \end_inset 
4196
4197  - symbol listing
4198 \begin_inset LatexCommand \index{Symbol listing}
4199
4200 \end_inset 
4201
4202  for the sourcefile, created by the assembler
4203 \layout Itemize
4204
4205 sourcefile.rel
4206 \begin_inset LatexCommand \index{<file>.rel}
4207
4208 \end_inset 
4209
4210  or sourcefile.o
4211 \begin_inset LatexCommand \index{<file>.o}
4212
4213 \end_inset 
4214
4215  - Object file
4216 \begin_inset LatexCommand \index{Object file}
4217
4218 \end_inset 
4219
4220  created by the assembler, input to Linkage editor
4221 \layout Itemize
4222
4223 sourcefile.map
4224 \begin_inset LatexCommand \index{<file>.map}
4225
4226 \end_inset 
4227
4228  - The memory map
4229 \begin_inset LatexCommand \index{Memory map}
4230
4231 \end_inset 
4232
4233  for the load module, created by the Linker
4234 \layout Itemize
4235
4236 sourcefile.mem
4237 \begin_inset LatexCommand \index{<file>.mem}
4238
4239 \end_inset 
4240
4241  - A file with a summary of the memory usage
4242 \layout Itemize
4243
4244 sourcefile.ihx
4245 \begin_inset LatexCommand \index{<file>.ihx}
4246
4247 \end_inset 
4248
4249  - The load module in Intel hex format
4250 \begin_inset LatexCommand \index{Intel hex format}
4251
4252 \end_inset 
4253
4254  (you can select the Motorola S19 format
4255 \begin_inset LatexCommand \index{Motorola S19 format}
4256
4257 \end_inset 
4258
4259  with -
4260 \begin_inset ERT
4261 status Collapsed
4262
4263 \layout Standard
4264
4265 \backslash 
4266 /
4267 \end_inset 
4268
4269 -out-fmt-s19
4270 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
4271
4272 \end_inset 
4273
4274 .
4275  If you need another format you might want to use 
4276 \family sans 
4277 \shape italic 
4278 objdump
4279 \family default 
4280 \shape default 
4281
4282 \begin_inset LatexCommand \index{objdump (tool)}
4283
4284 \end_inset 
4285
4286  or
4287 \family sans 
4288 \shape italic 
4289  srecord
4290 \family default 
4291 \shape default 
4292
4293 \begin_inset LatexCommand \index{srecord (tool)}
4294
4295 \end_inset 
4296
4297 ).
4298  Both formats are documented in the documentation of srecord
4299 \begin_inset LatexCommand \index{srecord (tool)}
4300
4301 \end_inset 
4302
4303
4304 \layout Itemize
4305
4306 sourcefile.adb
4307 \begin_inset LatexCommand \index{<file>.adb}
4308
4309 \end_inset 
4310
4311  - An intermediate file containing debug information needed to create the
4312  .cdb file (with -
4313 \begin_inset ERT
4314 status Open
4315
4316 \layout Standard
4317
4318 \backslash 
4319 /
4320 \end_inset 
4321
4322 -debug
4323 \begin_inset LatexCommand \index{-\/-debug}
4324
4325 \end_inset 
4326
4327
4328 \layout Itemize
4329
4330 sourcefile.cdb
4331 \begin_inset LatexCommand \index{<file>.cdb}
4332
4333 \end_inset 
4334
4335  - An optional file (with -
4336 \begin_inset ERT
4337 status Collapsed
4338
4339 \layout Standard
4340
4341 \backslash 
4342 /
4343 \end_inset 
4344
4345 -debug) containing debug information.
4346  The format is documented in cdbfileformat.pdf.
4347 \layout Itemize
4348
4349 sourcefile.
4350  - (no extension)
4351 \begin_inset LatexCommand \index{<file> (no extension)}
4352
4353 \end_inset 
4354
4355  An optional AOMF or AOMF51
4356 \begin_inset LatexCommand \index{AOMF, AOMF51}
4357
4358 \end_inset 
4359
4360  file containing debug information (generated with option -
4361 \begin_inset ERT
4362 status Collapsed
4363
4364 \layout Standard
4365
4366 \backslash 
4367 /
4368 \end_inset 
4369
4370 -debug).
4371  The (Intel)
4372 \emph on 
4373  a
4374 \emph default 
4375 bsolute 
4376 \emph on 
4377 o
4378 \emph default 
4379 bject 
4380 \emph on 
4381 m
4382 \emph default 
4383 odule 
4384 \emph on 
4385 f
4386 \emph default 
4387 ormat is commonly used by third party tools (debuggers
4388 \begin_inset LatexCommand \index{Debugger}
4389
4390 \end_inset 
4391
4392 , simulators, emulators)
4393 \layout Itemize
4394
4395 sourcefile.dump*
4396 \begin_inset LatexCommand \index{<file>.dump*}
4397
4398 \end_inset 
4399
4400  - Dump file to debug the compiler it self (generated with option -
4401 \begin_inset ERT
4402 status Collapsed
4403
4404 \layout Standard
4405
4406 \backslash 
4407 /
4408 \end_inset 
4409
4410 -dumpall) (see section 
4411 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
4412
4413 \end_inset 
4414
4415 \SpecialChar ~
4416  and section 
4417 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
4418
4419 \end_inset 
4420
4421 \SpecialChar ~
4422
4423 \begin_inset Quotes sld
4424 \end_inset 
4425
4426 Anatomy of the compiler
4427 \begin_inset Quotes srd
4428 \end_inset 
4429
4430 ).
4431 \layout Subsection
4432
4433 Projects with Multiple Source Files
4434 \layout Standard
4435
4436 SDCC can compile only ONE file at a time.
4437  Let us for example assume that you have a project containing the following
4438  files:
4439 \newline 
4440
4441 \newline 
4442 foo1.c (contains some functions)
4443 \newline 
4444 foo2.c (contains some more functions)
4445 \newline 
4446 foomain.c (contains more functions and the function main)
4447 \newline 
4448
4449 \size footnotesize 
4450
4451 \newline 
4452
4453 \size default 
4454 The first two files will need to be compiled separately with the commands:
4455 \size footnotesize 
4456  
4457 \size default 
4458
4459 \newline 
4460
4461 \newline 
4462
4463 \family sans 
4464 \series bold 
4465 sdcc\SpecialChar ~
4466 -c\SpecialChar ~
4467 foo1.c
4468 \family default 
4469 \series default 
4470 \size footnotesize 
4471
4472 \newline 
4473
4474 \family sans 
4475 \series bold 
4476 \size default 
4477 sdcc\SpecialChar ~
4478 -c\SpecialChar ~
4479 foo2.c
4480 \family default 
4481 \series default 
4482
4483 \newline 
4484
4485 \newline 
4486 Then compile the source file containing the 
4487 \emph on 
4488 main()
4489 \emph default 
4490  function and link
4491 \begin_inset LatexCommand \index{Linker}
4492
4493 \end_inset 
4494
4495  the files together with the following command: 
4496 \newline 
4497
4498 \newline 
4499
4500 \family sans 
4501 \series bold 
4502 sdcc\SpecialChar ~
4503 foomain.c\SpecialChar ~
4504 foo1.rel\SpecialChar ~
4505 foo2.rel
4506 \family default 
4507 \series default 
4508
4509 \begin_inset LatexCommand \index{<file>.rel}
4510
4511 \end_inset 
4512
4513
4514 \newline 
4515
4516 \newline 
4517 Alternatively, 
4518 \emph on 
4519 foomain.c 
4520 \emph default 
4521 can be separately compiled as well: 
4522 \family sans 
4523 \series bold 
4524
4525 \newline 
4526
4527 \newline 
4528 sdcc\SpecialChar ~
4529 -c\SpecialChar ~
4530 foomain.c
4531 \newline 
4532 sdcc foomain.rel foo1.rel foo2.rel
4533 \newline 
4534
4535 \newline 
4536
4537 \family default 
4538 \series default 
4539 The file containing the 
4540 \emph on 
4541 main()
4542 \emph default 
4543  function
4544 \emph on 
4545  
4546 \emph default 
4547 \noun on 
4548 must
4549 \noun default 
4550  be the 
4551 \noun on 
4552 first
4553 \noun default 
4554  file specified in the command line, since the linkage editor processes
4555  file in the order they are presented to it.
4556  The linker is invoked from SDCC using a script file with extension .lnk
4557 \begin_inset LatexCommand \index{<file>.lnk}
4558
4559 \end_inset 
4560
4561 .
4562  You can view this file to troubleshoot linking problems such as those arising
4563  from missing libraries.
4564 \layout Subsection
4565
4566 Projects with Additional Libraries
4567 \begin_inset LatexCommand \index{Libraries}
4568
4569 \end_inset 
4570
4571
4572 \layout Standard
4573
4574 Some reusable routines may be compiled into a library, see the documentation
4575  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
4576  for how to create a 
4577 \emph on 
4578 .lib
4579 \begin_inset LatexCommand \index{<file>.lib}
4580
4581 \end_inset 
4582
4583
4584 \emph default 
4585  library file.
4586  Libraries created in this manner can be included in the command line.
4587  Make sure you include the -L <library-path> option to tell the linker where
4588  to look for these files if they are not in the current directory.
4589  Here is an example, assuming you have the source file 
4590 \emph on 
4591 foomain.c
4592 \emph default 
4593  and a library
4594 \emph on 
4595  foolib.lib
4596 \emph default 
4597  in the directory 
4598 \emph on 
4599 mylib
4600 \emph default 
4601  (if that is not the same as your current project):
4602 \newline 
4603
4604 \newline 
4605
4606 \family sans 
4607 \series bold 
4608 sdcc foomain.c foolib.lib -L mylib
4609 \newline 
4610
4611 \newline 
4612
4613 \family default 
4614 \series default 
4615 Note here that
4616 \emph on 
4617  mylib
4618 \emph default 
4619  must be an absolute path name.
4620 \newline 
4621
4622 \newline 
4623 The most efficient way to use libraries is to keep separate modules in separate
4624  source files.
4625  The lib file now should name all the modules.rel
4626 \begin_inset LatexCommand \index{<file>.rel}
4627
4628 \end_inset 
4629
4630  files.
4631  For an example see the standard library file 
4632 \emph on 
4633 libsdcc.lib
4634 \emph default 
4635  in the directory <installdir>/share/lib/small.
4636 \layout Subsection
4637
4638 Using sdcclib to Create and Manage Libraries
4639 \begin_inset LatexCommand \index{sdcclib}
4640
4641 \end_inset 
4642
4643
4644 \layout Standard
4645
4646 Alternatively, instead of having a .rel file for each entry on the library
4647  file as described in the preceding section, sdcclib can be used to embed
4648  all the modules belonging to such library in the library file itself.
4649  This results in a larger library file, but it greatly reduces the number
4650  of disk files accessed by the linker.
4651   Additionally, the packed library file contains an index of all include
4652  modules and symbols that significantly speeds up the linking process.
4653  To display a list of options supported by sdcclib type:
4654 \newline 
4655
4656 \layout Standard
4657
4658
4659 \family sans 
4660 \series bold 
4661 sdcclib -?
4662 \begin_inset LatexCommand \index{sdcclib}
4663
4664 \end_inset 
4665
4666
4667 \newline 
4668
4669 \newline 
4670
4671 \family default 
4672 \series default 
4673 To create a new library file, start by compiling all the required modules.
4674  For example:
4675 \newline 
4676
4677 \layout Standard
4678
4679
4680 \family sans 
4681 \series bold 
4682 sdcc -c _divsint.c
4683 \layout Standard
4684
4685
4686 \family sans 
4687 \series bold 
4688 sdcc -c _divuint.c
4689 \layout Standard
4690
4691
4692 \family sans 
4693 \series bold 
4694 sdcc -c _modsint.c
4695 \layout Standard
4696
4697
4698 \family sans 
4699 \series bold 
4700 sdcc -c _moduint.c
4701 \layout Standard
4702
4703
4704 \family sans 
4705 \series bold 
4706 sdcc -c _mulint.c
4707 \newline 
4708
4709 \layout Standard
4710
4711 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
4712  and _mulint.rel.
4713  The next step is to add the .rel files to the library file:
4714 \newline 
4715
4716 \layout Standard
4717
4718
4719 \family sans 
4720 \series bold 
4721 sdcclib libint.lib _divsint.rel
4722 \family default 
4723
4724 \begin_inset LatexCommand \index{sdcclib}
4725
4726 \end_inset 
4727
4728
4729 \layout Standard
4730
4731
4732 \family sans 
4733 \series bold 
4734 sdcclib libint.lib _divuint.rel
4735 \layout Standard
4736
4737
4738 \family sans 
4739 \series bold 
4740 sdcclib libint.lib _modsint.rel
4741 \layout Standard
4742
4743
4744 \family sans 
4745 \series bold 
4746 sdcclib libint.lib _moduint.rel
4747 \layout Standard
4748
4749
4750 \family sans 
4751 \series bold 
4752 sdcclib libint.lib _mulint.rel
4753 \series default 
4754
4755 \newline 
4756
4757 \layout Standard
4758
4759 If the file already exists in the library, it will be replaced.
4760  To see what modules and symbols are included in the library, options -s
4761  and -m are available.
4762  For example:
4763 \newline 
4764
4765 \newline 
4766
4767 \family sans 
4768 \series bold 
4769 sdcclib -s libint.lib
4770 \family default 
4771
4772 \begin_inset LatexCommand \index{sdcclib}
4773
4774 \end_inset 
4775
4776
4777 \newline 
4778
4779 \family typewriter 
4780 \series default 
4781 _divsint.rel:
4782 \layout Standard
4783
4784
4785 \family typewriter 
4786 __divsint_a_1_1
4787 \layout Standard
4788
4789
4790 \family typewriter 
4791 __divsint_PARM_2
4792 \layout Standard
4793
4794
4795 \family typewriter 
4796 __divsint
4797 \newline 
4798 _divuint.rel:
4799 \layout Standard
4800
4801
4802 \family typewriter 
4803 __divuint_a_1_1
4804 \layout Standard
4805
4806
4807 \family typewriter 
4808 __divuint_PARM_2
4809 \layout Standard
4810
4811
4812 \family typewriter 
4813 __divuint_reste_1_1
4814 \layout Standard
4815
4816
4817 \family typewriter 
4818 __divuint_count_1_1
4819 \layout Standard
4820
4821
4822 \family typewriter 
4823 __divuint
4824 \newline 
4825 _modsint.rel:
4826 \layout Standard
4827
4828
4829 \family typewriter 
4830 __modsint_a_1_1
4831 \layout Standard
4832
4833
4834 \family typewriter 
4835 __modsint_PARM_2
4836 \layout Standard
4837
4838
4839 \family typewriter 
4840 __modsint
4841 \newline 
4842 _moduint.rel:
4843 \layout Standard
4844
4845
4846 \family typewriter 
4847 __moduint_a_1_1
4848 \layout Standard
4849
4850
4851 \family typewriter 
4852 __moduint_PARM_2
4853 \layout Standard
4854
4855
4856 \family typewriter 
4857 __moduint_count_1_1
4858 \layout Standard
4859
4860
4861 \family typewriter 
4862 __moduint
4863 \newline 
4864 _mulint.rel:
4865 \layout Standard
4866
4867
4868 \family typewriter 
4869 __mulint_PARM_2
4870 \layout Standard
4871
4872
4873 \family typewriter 
4874 __mulint
4875 \family default 
4876 \series bold 
4877
4878 \newline 
4879
4880 \layout Standard
4881
4882 If the source files are compiled using -
4883 \begin_inset ERT
4884 status Open
4885
4886 \layout Standard
4887
4888 \backslash 
4889 /
4890 \end_inset 
4891
4892 -debug
4893 \begin_inset LatexCommand \index{-\/-debug}
4894
4895 \end_inset 
4896
4897 , the corresponding debug information file .adb will be include in the library
4898  file as well.
4899  The library files created with sdcclib are plain text files, so they can
4900  be viewed with a text editor.
4901  It is not recomended to modify a library file created with sdcclib using
4902  a text editor, as there are file indexes numbers located accross the file
4903  used by the linker to quickly locate the required module to link.
4904  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
4905  it can be safely deleted, since all the information required for linking
4906  is embedded in the library file itself.
4907  Library files created using sdcclib are used as described in the preceding
4908  sections.
4909 \layout Section
4910
4911 Command Line Options
4912 \begin_inset LatexCommand \index{Command Line Options}
4913
4914 \end_inset 
4915
4916
4917 \layout Subsection
4918
4919 Processor Selection Options
4920 \begin_inset LatexCommand \index{Options processor selection}
4921
4922 \end_inset 
4923
4924
4925 \begin_inset LatexCommand \index{Processor selection options}
4926
4927 \end_inset 
4928
4929
4930 \layout List
4931 \labelwidthstring 00.00.0000
4932
4933
4934 \series bold 
4935 -mmcs51
4936 \begin_inset LatexCommand \index{-mmcs51}
4937
4938 \end_inset 
4939
4940
4941 \series default 
4942  Generate code for the Intel MCS51
4943 \begin_inset LatexCommand \index{MCS51}
4944
4945 \end_inset 
4946
4947  family of processors.
4948  This is the default processor target.
4949 \layout List
4950 \labelwidthstring 00.00.0000
4951
4952
4953 \series bold 
4954 -mds390
4955 \begin_inset LatexCommand \index{-mds390}
4956
4957 \end_inset 
4958
4959
4960 \series default 
4961  Generate code for the Dallas DS80C390
4962 \begin_inset LatexCommand \index{DS80C390}
4963
4964 \end_inset 
4965
4966  processor.
4967 \layout List
4968 \labelwidthstring 00.00.0000
4969
4970
4971 \series bold 
4972 -mds400
4973 \begin_inset LatexCommand \index{-mds400}
4974
4975 \end_inset 
4976
4977
4978 \series default 
4979  Generate code for the Dallas DS80C400
4980 \begin_inset LatexCommand \index{DS80C400}
4981
4982 \end_inset 
4983
4984  processor.
4985 \layout List
4986 \labelwidthstring 00.00.0000
4987
4988
4989 \series bold 
4990 -mhc08
4991 \begin_inset LatexCommand \index{-mhc08}
4992
4993 \end_inset 
4994
4995
4996 \series default 
4997  Generate code for the Motorola HC08
4998 \begin_inset LatexCommand \index{HC08}
4999
5000 \end_inset 
5001
5002  family of processors (added Oct 2003).
5003 \layout List
5004 \labelwidthstring 00.00.0000
5005
5006
5007 \series bold 
5008 -mz80
5009 \begin_inset LatexCommand \index{-mz80}
5010
5011 \end_inset 
5012
5013
5014 \series default 
5015  Generate code for the Zilog Z80
5016 \begin_inset LatexCommand \index{Z80}
5017
5018 \end_inset 
5019
5020  family of processors.
5021 \layout List
5022 \labelwidthstring 00.00.0000
5023
5024
5025 \series bold 
5026 -mgbz80
5027 \begin_inset LatexCommand \index{-mgbz80}
5028
5029 \end_inset 
5030
5031
5032 \series default 
5033  Generate code for the GameBoy Z80
5034 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
5035
5036 \end_inset 
5037
5038  processor (Not actively maintained).
5039 \layout List
5040 \labelwidthstring 00.00.0000
5041
5042
5043 \series bold 
5044 -mavr
5045 \begin_inset LatexCommand \index{-mavr}
5046
5047 \end_inset 
5048
5049
5050 \series default 
5051  Generate code for the Atmel AVR
5052 \begin_inset LatexCommand \index{AVR}
5053
5054 \end_inset 
5055
5056  processor (In development, not complete).
5057  AVR users should probably have a look at avr-gcc 
5058 \begin_inset LatexCommand \url{ http://savannah.nongnu.org/download/avr-libc/snapshots/}
5059
5060 \end_inset 
5061
5062  or winavr 
5063 \begin_inset LatexCommand \url{http://winavr.sourceforge.net}
5064
5065 \end_inset 
5066
5067 .
5068 \layout Comment
5069
5070 I think it is fair to direct users there for now.
5071  Open source is also about avoiding unnecessary work .
5072  But I didn't find the 'official' link.
5073 \layout List
5074 \labelwidthstring 00.00.0000
5075
5076
5077 \series bold 
5078 -mpic14
5079 \begin_inset LatexCommand \index{-mpic14}
5080
5081 \end_inset 
5082
5083
5084 \series default 
5085  Generate code for the Microchip PIC 14
5086 \begin_inset LatexCommand \index{PIC14}
5087
5088 \end_inset 
5089
5090 -bit processors (p16f84 and variants.
5091  In development, not complete).
5092 \layout Comment
5093
5094 p16f627 p16f628 p16f84 p16f873 p16f877?
5095 \layout List
5096 \labelwidthstring 00.00.0000
5097
5098
5099 \series bold 
5100 -mpic16
5101 \begin_inset LatexCommand \index{-mpic16}
5102
5103 \end_inset 
5104
5105
5106 \series default 
5107  Generate code for the Microchip PIC 16
5108 \begin_inset LatexCommand \index{PIC16}
5109
5110 \end_inset 
5111
5112 -bit processors (p18f452 and variants.
5113  In development, not complete).
5114 \layout List
5115 \labelwidthstring 00.00.0000
5116
5117
5118 \series bold 
5119 -mtlcs900h
5120 \series default 
5121  Generate code for the Toshiba TLCS-900H
5122 \begin_inset LatexCommand \index{TLCS-900H}
5123
5124 \end_inset 
5125
5126  processor (Not maintained, not complete).
5127 \layout List
5128 \labelwidthstring 00.00.0000
5129
5130
5131 \series bold 
5132 -mxa51
5133 \begin_inset LatexCommand \index{-mxa51}
5134
5135 \end_inset 
5136
5137
5138 \series default 
5139  Generate code for the Phillips XA51
5140 \begin_inset LatexCommand \index{XA51}
5141
5142 \end_inset 
5143
5144  processor (Not maintained, not complete).
5145 \layout Subsection
5146
5147 Preprocessor Options
5148 \begin_inset LatexCommand \index{Options preprocessor}
5149
5150 \end_inset 
5151
5152
5153 \begin_inset LatexCommand \index{Preprocessor options}
5154
5155 \end_inset 
5156
5157
5158 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5159
5160 \end_inset 
5161
5162
5163 \layout List
5164 \labelwidthstring 00.00.0000
5165
5166
5167 \series bold 
5168 -I<path>
5169 \begin_inset LatexCommand \index{-I<path>}
5170
5171 \end_inset 
5172
5173
5174 \series default 
5175  The additional location where the pre processor will look for <..h> or 
5176 \begin_inset Quotes eld
5177 \end_inset 
5178
5179 ..h
5180 \begin_inset Quotes erd
5181 \end_inset 
5182
5183  files.
5184 \layout List
5185 \labelwidthstring 00.00.0000
5186
5187
5188 \series bold 
5189 -D<macro[=value]>
5190 \begin_inset LatexCommand \index{-D<macro[=value]>}
5191
5192 \end_inset 
5193
5194
5195 \series default 
5196  Command line definition of macros.
5197  Passed to the preprocessor.
5198 \layout List
5199 \labelwidthstring 00.00.0000
5200
5201
5202 \series bold 
5203 -M
5204 \begin_inset LatexCommand \index{-M}
5205
5206 \end_inset 
5207
5208
5209 \series default 
5210  Tell the preprocessor to output a rule suitable for make describing the
5211  dependencies of each object file.
5212  For each source file, the preprocessor outputs one make-rule whose target
5213  is the object file name for that source file and whose dependencies are
5214  all the files `#include'd in it.
5215  This rule may be a single line or may be continued with `
5216 \backslash 
5217 '-newline if it is long.
5218  The list of rules is printed on standard output instead of the preprocessed
5219  C program.
5220  `-M' implies `-E
5221 \begin_inset LatexCommand \index{-E}
5222
5223 \end_inset 
5224
5225 '.
5226 \layout List
5227 \labelwidthstring 00.00.0000
5228
5229
5230 \series bold 
5231 -C
5232 \begin_inset LatexCommand \index{-C}
5233
5234 \end_inset 
5235
5236
5237 \series default 
5238  Tell the preprocessor not to discard comments.
5239  Used with the `-E' option.
5240 \layout List
5241 \labelwidthstring 00.00.0000
5242
5243
5244 \series bold 
5245 -MM
5246 \begin_inset LatexCommand \index{-MM}
5247
5248 \end_inset 
5249
5250
5251 \size large 
5252 \bar under 
5253  
5254 \series default 
5255 \size default 
5256 \bar default 
5257 Like `-M' but the output mentions only the user header files included with
5258  `#include 
5259 \begin_inset Quotes eld
5260 \end_inset 
5261
5262 file"'.
5263  System header files included with `#include <file>' are omitted.
5264 \layout List
5265 \labelwidthstring 00.00.0000
5266
5267
5268 \series bold 
5269 -Aquestion(answer)
5270 \begin_inset LatexCommand \index{-Aquestion(answer)}
5271
5272 \end_inset 
5273
5274
5275 \series default 
5276  Assert the answer answer for question, in case it is tested with a preprocessor
5277  conditional such as `#if #question(answer)'.
5278  `-A-' disables the standard assertions that normally describe the target
5279  machine.
5280 \layout List
5281 \labelwidthstring 00.00.0000
5282
5283
5284 \series bold 
5285 -Umacro
5286 \begin_inset LatexCommand \index{-Umacro}
5287
5288 \end_inset 
5289
5290
5291 \series default 
5292  Undefine macro macro.
5293  `-U' options are evaluated after all `-D' options, but before any `-include'
5294  and `-imacros' options.
5295 \layout List
5296 \labelwidthstring 00.00.0000
5297
5298
5299 \series bold 
5300 -dM
5301 \begin_inset LatexCommand \index{-dM}
5302
5303 \end_inset 
5304
5305
5306 \series default 
5307  Tell the preprocessor to output only a list of the macro definitions that
5308  are in effect at the end of preprocessing.
5309  Used with the `-E' option.
5310 \layout List
5311 \labelwidthstring 00.00.0000
5312
5313
5314 \series bold 
5315 -dD
5316 \begin_inset LatexCommand \index{-dD}
5317
5318 \end_inset 
5319
5320
5321 \series default 
5322  Tell the preprocessor to pass all macro definitions into the output, in
5323  their proper sequence in the rest of the output.
5324 \layout List
5325 \labelwidthstring 00.00.0000
5326
5327
5328 \series bold 
5329 -dN
5330 \begin_inset LatexCommand \index{-dN}
5331
5332 \end_inset 
5333
5334
5335 \size large 
5336 \bar under 
5337  
5338 \series default 
5339 \size default 
5340 \bar default 
5341 Like `-dD' except that the macro arguments and contents are omitted.
5342  Only `#define name' is included in the output.
5343 \layout List
5344 \labelwidthstring 00.00.0000
5345
5346
5347 \series bold 
5348 -Wp\SpecialChar ~
5349 preprocessorOption[,preprocessorOption]
5350 \series default 
5351
5352 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
5353
5354 \end_inset 
5355
5356 ...
5357  Pass the preprocessorOption to the preprocessor 
5358 \family typewriter 
5359 sdcpp
5360 \family default 
5361
5362 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5363
5364 \end_inset 
5365
5366 .
5367  SDCC uses an adapted version of the preprocessor cpp of the GNU Compiler
5368  Collection (gcc), if you need more dedicated options please refer to the
5369  documentation at 
5370 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
5371
5372 \end_inset 
5373
5374 .
5375 \layout Subsection
5376
5377 Linker Options
5378 \begin_inset LatexCommand \index{Options linker}
5379
5380 \end_inset 
5381
5382
5383 \begin_inset LatexCommand \index{Linker options}
5384
5385 \end_inset 
5386
5387
5388 \layout List
5389 \labelwidthstring 00.00.0000
5390
5391
5392 \series bold 
5393 -L\SpecialChar ~
5394 -
5395 \series default 
5396
5397 \begin_inset ERT
5398 status Collapsed
5399
5400 \layout Standard
5401
5402 \backslash 
5403 /
5404 \end_inset 
5405
5406
5407 \series bold 
5408 -lib-path
5409 \begin_inset LatexCommand \index{-\/-lib-path <path>}
5410
5411 \end_inset 
5412
5413
5414 \begin_inset LatexCommand \index{-L -\/-lib-path}
5415
5416 \end_inset 
5417
5418
5419 \series default 
5420 \SpecialChar ~
5421 <absolute path to additional libraries> This option is passed to the linkage
5422  editor's additional libraries
5423 \begin_inset LatexCommand \index{Libraries}
5424
5425 \end_inset 
5426
5427  search path.
5428  The path name must be absolute.
5429  Additional library files may be specified in the command line.
5430  See section Compiling programs for more details.
5431 \layout List
5432 \labelwidthstring 00.00.0000
5433
5434
5435 \series bold 
5436 -
5437 \begin_inset ERT
5438 status Collapsed
5439
5440 \layout Standard
5441
5442 \backslash 
5443 /
5444 \end_inset 
5445
5446 -xram-loc
5447 \series default 
5448
5449 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
5450
5451 \end_inset 
5452
5453 \SpecialChar ~
5454 <Value> The start location of the external ram
5455 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
5456
5457 \end_inset 
5458
5459 , default value is 0.
5460  The value entered can be in Hexadecimal or Decimal format, e.g.: -
5461 \begin_inset ERT
5462 status Collapsed
5463
5464 \layout Standard
5465
5466 \backslash 
5467 /
5468 \end_inset 
5469
5470 -xram-loc 0x8000 or -
5471 \begin_inset ERT
5472 status Collapsed
5473
5474 \layout Standard
5475
5476 \backslash 
5477 /
5478 \end_inset 
5479
5480 -xram-loc 32768.
5481 \layout List
5482 \labelwidthstring 00.00.0000
5483
5484
5485 \series bold 
5486 -
5487 \begin_inset ERT
5488 status Collapsed
5489
5490 \layout Standard
5491
5492 \backslash 
5493 /
5494 \end_inset 
5495
5496 -code-loc
5497 \series default 
5498
5499 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
5500
5501 \end_inset 
5502
5503 \SpecialChar ~
5504 <Value> The start location of the code
5505 \begin_inset LatexCommand \index{code}
5506
5507 \end_inset 
5508
5509  segment, default value 0.
5510  Note when this option is used the interrupt vector table is also relocated
5511  to the given address.
5512  The value entered can be in Hexadecimal or Decimal format, e.g.: -
5513 \begin_inset ERT
5514 status Collapsed
5515
5516 \layout Standard
5517
5518 \backslash 
5519 /
5520 \end_inset 
5521
5522 -code-loc 0x8000 or -
5523 \begin_inset ERT
5524 status Collapsed
5525
5526 \layout Standard
5527
5528 \backslash 
5529 /
5530 \end_inset 
5531
5532 -code-loc 32768.
5533 \layout List
5534 \labelwidthstring 00.00.0000
5535
5536
5537 \series bold 
5538 -
5539 \begin_inset ERT
5540 status Collapsed
5541
5542 \layout Standard
5543
5544 \backslash 
5545 /
5546 \end_inset 
5547
5548 -stack-loc
5549 \series default 
5550
5551 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
5552
5553 \end_inset 
5554
5555 \SpecialChar ~
5556 <Value> By default the stack
5557 \begin_inset LatexCommand \index{stack}
5558
5559 \end_inset 
5560
5561  is placed after the data segment.
5562  Using this option the stack can be placed anywhere in the internal memory
5563  space of the 8051.
5564  The value entered can be in Hexadecimal or Decimal format, e.g.
5565  -
5566 \begin_inset ERT
5567 status Collapsed
5568
5569 \layout Standard
5570
5571 \backslash 
5572 /
5573 \end_inset 
5574
5575 -stack-loc 0x20 or -
5576 \begin_inset ERT
5577 status Collapsed
5578
5579 \layout Standard
5580
5581 \backslash 
5582 /
5583 \end_inset 
5584
5585 -stack-loc 32.
5586  Since the sp register is incremented before a push or call, the initial
5587  sp will be set to one byte prior the provided value.
5588  The provided value should not overlap any other memory areas such as used
5589  register banks or the data segment and with enough space for the current
5590  application.
5591 \layout List
5592 \labelwidthstring 00.00.0000
5593
5594
5595 \series bold 
5596 -
5597 \begin_inset ERT
5598 status Collapsed
5599
5600 \layout Standard
5601
5602 \backslash 
5603 /
5604 \end_inset 
5605
5606 -data-loc
5607 \series default 
5608
5609 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
5610
5611 \end_inset 
5612
5613 \SpecialChar ~
5614 <Value> The start location of the internal ram data
5615 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
5616
5617 \end_inset 
5618
5619  segment.
5620  The value entered can be in Hexadecimal or Decimal format, eg.
5621  -
5622 \begin_inset ERT
5623 status Collapsed
5624
5625 \layout Standard
5626
5627 \backslash 
5628 /
5629 \end_inset 
5630
5631 -data-loc 0x20 or -
5632 \begin_inset ERT
5633 status Collapsed
5634
5635 \layout Standard
5636
5637 \backslash 
5638 /
5639 \end_inset 
5640
5641 -data-loc 32.
5642  (By default, the start location of the internal ram data segment  is set
5643  as low as possible in memory, taking into account the used register banks
5644  and the bit segment at address 0x20.
5645  For example if register banks 0 and 1 are used without bit variables, the
5646  data segment will be set, if -
5647 \begin_inset ERT
5648 status Collapsed
5649
5650 \layout Standard
5651
5652 \backslash 
5653 /
5654 \end_inset 
5655
5656 -data-loc is not used, to location 0x10.)
5657 \layout List
5658 \labelwidthstring 00.00.0000
5659
5660
5661 \series bold 
5662 -
5663 \begin_inset ERT
5664 status Collapsed
5665
5666 \layout Standard
5667
5668 \backslash 
5669 /
5670 \end_inset 
5671
5672 -idata-loc
5673 \series default 
5674
5675 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
5676
5677 \end_inset 
5678
5679 \SpecialChar ~
5680 <Value> The start location of the indirectly addressable internal ram
5681 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
5682
5683 \end_inset 
5684
5685  of the 8051, default value is 0x80.
5686  The value entered can be in Hexadecimal or Decimal format, eg.
5687  -
5688 \begin_inset ERT
5689 status Collapsed
5690
5691 \layout Standard
5692
5693 \backslash 
5694 /
5695 \end_inset 
5696
5697 -idata-loc 0x88 or -
5698 \begin_inset ERT
5699 status Collapsed
5700
5701 \layout Standard
5702
5703 \backslash 
5704 /
5705 \end_inset 
5706
5707 -idata-loc 136.
5708 \layout List
5709 \labelwidthstring 00.00.0000
5710
5711
5712 \series bold 
5713 -
5714 \begin_inset ERT
5715 status Collapsed
5716
5717 \layout Standard
5718
5719 \backslash 
5720 /
5721 \end_inset 
5722
5723 -bit-loc
5724 \series default 
5725 \SpecialChar ~
5726 <Value> The start location of the bit
5727 \begin_inset LatexCommand \index{bit}
5728
5729 \end_inset 
5730
5731  addressable internal ram of the 8051.
5732  This is 
5733 \emph on 
5734 not
5735 \emph default 
5736  implemented yet.
5737  Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
5738 -bBSEG=<Value>.
5739 \layout List
5740 \labelwidthstring 00.00.0000
5741
5742
5743 \series bold 
5744 -
5745 \begin_inset ERT
5746 status Collapsed
5747
5748 \layout Standard
5749
5750 \backslash 
5751 /
5752 \end_inset 
5753
5754 -out-fmt-ihx
5755 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
5756
5757 \end_inset 
5758
5759
5760 \bar under 
5761  
5762 \series default 
5763 \bar default 
5764 The linker output (final object code) is in Intel Hex format.
5765 \begin_inset LatexCommand \index{Intel hex format}
5766
5767 \end_inset 
5768
5769  This is the default option.
5770  The format itself is documented in the documentation of srecord
5771 \begin_inset LatexCommand \index{srecord (tool)}
5772
5773 \end_inset 
5774
5775 .
5776 \layout List
5777 \labelwidthstring 00.00.0000
5778
5779
5780 \series bold 
5781 -
5782 \begin_inset ERT
5783 status Collapsed
5784
5785 \layout Standard
5786
5787 \backslash 
5788 /
5789 \end_inset 
5790
5791 -out-fmt-s19
5792 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5793
5794 \end_inset 
5795
5796
5797 \bar under 
5798  
5799 \series default 
5800 \bar default 
5801 The linker output (final object code) is in Motorola S19 format
5802 \begin_inset LatexCommand \index{Motorola S19 format}
5803
5804 \end_inset 
5805
5806 .
5807  The format itself is documented in the documentation of srecord.
5808 \layout List
5809 \labelwidthstring 00.00.0000
5810
5811
5812 \series bold 
5813 -Wl\SpecialChar ~
5814 linkOption[,linkOption]
5815 \series default 
5816
5817 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
5818
5819 \end_inset 
5820
5821 ...
5822  Pass the linkOption to the linker.
5823  See file sdcc/as/doc/asxhtm.html for more on linker options.
5824 \layout Subsection
5825
5826 MCS51 Options
5827 \begin_inset LatexCommand \index{Options MCS51}
5828
5829 \end_inset 
5830
5831
5832 \begin_inset LatexCommand \index{MCS51 options}
5833
5834 \end_inset 
5835
5836
5837 \layout List
5838 \labelwidthstring 00.00.0000
5839
5840
5841 \series bold 
5842 -
5843 \begin_inset ERT
5844 status Collapsed
5845
5846 \layout Standard
5847
5848 \backslash 
5849 /
5850 \end_inset 
5851
5852 -model-small
5853 \begin_inset LatexCommand \index{-\/-model-small}
5854
5855 \end_inset 
5856
5857
5858 \series default 
5859 \size large 
5860 \emph on 
5861  
5862 \size default 
5863 \emph default 
5864 Generate code for Small Model programs, see section Memory Models for more
5865  details.
5866  This is the default model.
5867 \layout List
5868 \labelwidthstring 00.00.0000
5869
5870
5871 \series bold 
5872 -
5873 \begin_inset ERT
5874 status Collapsed
5875
5876 \layout Standard
5877
5878 \backslash 
5879 /
5880 \end_inset 
5881
5882 -model-large
5883 \begin_inset LatexCommand \index{-\/-model-large}
5884
5885 \end_inset 
5886
5887
5888 \series default 
5889  Generate code for Large model programs, see section Memory Models for more
5890  details.
5891  If this option is used all source files in the project have to be compiled
5892  with this option.
5893 \layout List
5894 \labelwidthstring 00.00.0000
5895
5896
5897 \series bold 
5898 -
5899 \begin_inset ERT
5900 status Collapsed
5901
5902 \layout Standard
5903
5904 \backslash 
5905 /
5906 \end_inset 
5907
5908 -xstack
5909 \begin_inset LatexCommand \index{-\/-xstack}
5910
5911 \end_inset 
5912
5913
5914 \series default 
5915  Uses a pseudo stack in the first 256 bytes in the external ram for allocating
5916  variables and passing parameters.
5917  See section 
5918 \begin_inset LatexCommand \ref{sub:External-Stack}
5919
5920 \end_inset 
5921
5922 \SpecialChar ~
5923  External Stack for more details.
5924 \layout List
5925 \labelwidthstring 00.00.0000
5926
5927
5928 \series bold 
5929 -
5930 \begin_inset ERT
5931 status Collapsed
5932
5933 \layout Standard
5934
5935 \backslash 
5936 /
5937 \end_inset 
5938
5939 -iram-size
5940 \series default 
5941 \SpecialChar ~
5942 <Value>
5943 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
5944
5945 \end_inset 
5946
5947  Causes the linker to check if the internal ram usage is within limits of
5948  the given value.
5949 \layout List
5950 \labelwidthstring 00.00.0000
5951
5952
5953 \series bold 
5954 -
5955 \begin_inset ERT
5956 status Collapsed
5957
5958 \layout Standard
5959
5960 \backslash 
5961 /
5962 \end_inset 
5963
5964 -xram-size
5965 \series default 
5966 \SpecialChar ~
5967 <Value>
5968 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
5969
5970 \end_inset 
5971
5972  Causes the linker to check if the external ram usage is within limits of
5973  the given value.
5974 \layout List
5975 \labelwidthstring 00.00.0000
5976
5977
5978 \series bold 
5979 -
5980 \begin_inset ERT
5981 status Collapsed
5982
5983 \layout Standard
5984
5985 \backslash 
5986 /
5987 \end_inset 
5988
5989 -code-size
5990 \series default 
5991 \SpecialChar ~
5992 <Value>
5993 \begin_inset LatexCommand \index{-\/-code-size <Value>}
5994
5995 \end_inset 
5996
5997  Causes the linker to check if the code memory usage is within limits of
5998  the given value.
5999 \layout List
6000 \labelwidthstring 00.00.0000
6001
6002
6003 \series bold 
6004 -
6005 \begin_inset ERT
6006 status Collapsed
6007
6008 \layout Standard
6009
6010 \backslash 
6011 /
6012 \end_inset 
6013
6014 -stack-size
6015 \series default 
6016 \SpecialChar ~
6017 <Value>
6018 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
6019
6020 \end_inset 
6021
6022  Causes the linker to check if there is at minimum <Value> bytes for stack.
6023 \layout List
6024 \labelwidthstring 00.00.0000
6025
6026
6027 \series bold 
6028 -
6029 \begin_inset ERT
6030 status Collapsed
6031
6032 \layout Standard
6033
6034 \backslash 
6035 /
6036 \end_inset 
6037
6038 -pack-iram
6039 \series default 
6040 \SpecialChar ~
6041
6042 \begin_inset LatexCommand \index{-\/-pack-iram}
6043
6044 \end_inset 
6045
6046  Causes the linker to use unused register banks for data variables and pack
6047  data, idata and stack together.
6048  This is the default now.
6049 \layout List
6050 \labelwidthstring 00.00.0000
6051
6052
6053 \series bold 
6054 -
6055 \begin_inset ERT
6056 status Collapsed
6057
6058 \layout Standard
6059
6060 \backslash 
6061 /
6062 \end_inset 
6063
6064 -no-pack-iram
6065 \series default 
6066 \SpecialChar ~
6067
6068 \begin_inset LatexCommand \index{-\/-pack-iram}
6069
6070 \end_inset 
6071
6072  Causes the linker to use old style for allocating memory areas.
6073 \layout Subsection
6074
6075 DS390 / DS400 Options
6076 \begin_inset LatexCommand \index{Options DS390}
6077
6078 \end_inset 
6079
6080
6081 \begin_inset LatexCommand \index{DS390 options}
6082
6083 \end_inset 
6084
6085
6086 \layout List
6087 \labelwidthstring 00.00.0000
6088
6089
6090 \series bold 
6091 -
6092 \begin_inset ERT
6093 status Collapsed
6094
6095 \layout Standard
6096
6097 \backslash 
6098 /
6099 \end_inset 
6100
6101 -model-flat24
6102 \series default 
6103
6104 \begin_inset LatexCommand \index{-\/-model-flat24}
6105
6106 \end_inset 
6107
6108
6109 \size large 
6110 \emph on 
6111  
6112 \size default 
6113 \emph default 
6114 Generate 24-bit flat mode code.
6115  This is the one and only that the ds390 code generator supports right now
6116  and is default when using 
6117 \emph on 
6118 -mds390
6119 \emph default 
6120 .
6121  See section Memory Models for more details.
6122 \layout List
6123 \labelwidthstring 00.00.0000
6124
6125
6126 \series bold 
6127 -
6128 \begin_inset ERT
6129 status Collapsed
6130
6131 \layout Standard
6132
6133 \backslash 
6134 /
6135 \end_inset 
6136
6137 -protect-sp-update
6138 \begin_inset LatexCommand \index{-\/-protect-sp-update}
6139
6140 \end_inset 
6141
6142
6143 \series default 
6144  disable interrupts during ESP:SP updates.
6145 \layout List
6146 \labelwidthstring 00.00.0000
6147
6148
6149 \series bold 
6150 -
6151 \begin_inset ERT
6152 status Collapsed
6153
6154 \layout Standard
6155
6156 \backslash 
6157 /
6158 \end_inset 
6159
6160 -stack-10bit
6161 \series default 
6162
6163 \begin_inset LatexCommand \index{-\/-stack-10bit}
6164
6165 \end_inset 
6166
6167  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
6168  This is the one and only that the ds390 code generator supports right now
6169  and is default when using 
6170 \emph on 
6171 -mds390
6172 \emph default 
6173 .
6174  In this mode, the stack is located in the lower 1K of the internal RAM,
6175  which is mapped to 0x400000.
6176  Note that the support is incomplete, since it still uses a single byte
6177  as the stack pointer.
6178  This means that only the lower 256 bytes of the potential 1K stack space
6179  will actually be used.
6180  However, this does allow you to reclaim the precious 256 bytes of low RAM
6181  for use for the DATA and IDATA segments.
6182  The compiler will not generate any code to put the processor into 10 bit
6183  stack mode.
6184  It is important to ensure that the processor is in this mode before calling
6185  any re-entrant functions compiled with this option.
6186  In principle, this should work with the 
6187 \emph on 
6188 -
6189 \begin_inset ERT
6190 status Collapsed
6191
6192 \layout Standard
6193
6194 \backslash 
6195 /
6196 \end_inset 
6197
6198 -stack-auto
6199 \begin_inset LatexCommand \index{-\/-stack-auto}
6200
6201 \end_inset 
6202
6203
6204 \emph default 
6205  option, but that has not been tested.
6206  It is incompatible with the 
6207 \emph on 
6208 -
6209 \begin_inset ERT
6210 status Collapsed
6211
6212 \layout Standard
6213
6214 \backslash 
6215 /
6216 \end_inset 
6217
6218 -xstack
6219 \begin_inset LatexCommand \index{-\/-xstack}
6220
6221 \end_inset 
6222
6223
6224 \emph default 
6225  option.
6226  It also only makes sense if the processor is in 24 bit contiguous addressing
6227  mode (see the 
6228 \emph on 
6229 -
6230 \begin_inset ERT
6231 status Collapsed
6232
6233 \layout Standard
6234
6235 \backslash 
6236 /
6237 \end_inset 
6238
6239 -model-flat24 option
6240 \emph default 
6241 ).
6242 \layout List
6243 \labelwidthstring 00.00.0000
6244
6245
6246 \series bold 
6247 -
6248 \begin_inset ERT
6249 status Collapsed
6250
6251 \layout Standard
6252
6253 \backslash 
6254 /
6255 \end_inset 
6256
6257 -stack-probe
6258 \begin_inset LatexCommand \index{-\/-stack-probe}
6259
6260 \end_inset 
6261
6262
6263 \series default 
6264  insert call to function __stack_probe at each function prologue.
6265 \layout List
6266 \labelwidthstring 00.00.0000
6267
6268
6269 \series bold 
6270 -
6271 \begin_inset ERT
6272 status Collapsed
6273
6274 \layout Standard
6275
6276 \backslash 
6277 /
6278 \end_inset 
6279
6280 -tini-libid
6281 \begin_inset LatexCommand \index{-\/-tini-libid}
6282
6283 \end_inset 
6284
6285
6286 \series default 
6287  <nnnn> LibraryID used in -mTININative.
6288  
6289 \layout List
6290 \labelwidthstring 00.00.0000
6291
6292
6293 \series bold 
6294 -
6295 \begin_inset ERT
6296 status Collapsed
6297
6298 \layout Standard
6299
6300 \backslash 
6301 /
6302 \end_inset 
6303
6304 -use-accelerator
6305 \begin_inset LatexCommand \index{-\/-use-accelerator}
6306
6307 \end_inset 
6308
6309
6310 \series default 
6311  generate code for DS390 Arithmetic Accelerator.
6312  
6313 \layout Subsection
6314
6315 Z80 Options
6316 \begin_inset LatexCommand \index{Options Z80}
6317
6318 \end_inset 
6319
6320
6321 \begin_inset LatexCommand \index{Z80 options}
6322
6323 \end_inset 
6324
6325
6326 \layout List
6327 \labelwidthstring 00.00.0000
6328
6329
6330 \series bold 
6331 -
6332 \begin_inset ERT
6333 status Collapsed
6334
6335 \layout Standard
6336
6337 \backslash 
6338 /
6339 \end_inset 
6340
6341 -callee-saves-bc
6342 \series default 
6343
6344 \begin_inset LatexCommand \index{-\/-callee-saves-bc}
6345
6346 \end_inset 
6347
6348
6349 \size large 
6350 \emph on 
6351  
6352 \size default 
6353 \emph default 
6354 Force a called function to always save BC.
6355 \layout List
6356 \labelwidthstring 00.00.0000
6357
6358
6359 \series bold 
6360 -
6361 \begin_inset ERT
6362 status Collapsed
6363
6364 \layout Standard
6365
6366 \backslash 
6367 /
6368 \end_inset 
6369
6370 -no-std-crt0
6371 \series default 
6372
6373 \begin_inset LatexCommand \index{-\/-no-std-crt0}
6374
6375 \end_inset 
6376
6377  When linking, skip the standard crt0.o object file.
6378  You must provide your own crt0.o for your system when linking.
6379  
6380 \layout Subsection
6381
6382 Optimization Options
6383 \begin_inset LatexCommand \index{Options optimization}
6384
6385 \end_inset 
6386
6387
6388 \begin_inset LatexCommand \index{Optimization options}
6389
6390 \end_inset 
6391
6392
6393 \layout List
6394 \labelwidthstring 00.00.0000
6395
6396
6397 \series bold 
6398 -
6399 \begin_inset ERT
6400 status Collapsed
6401
6402 \layout Standard
6403
6404 \backslash 
6405 /
6406 \end_inset 
6407
6408 -nogcse
6409 \begin_inset LatexCommand \index{-\/-nogcse}
6410
6411 \end_inset 
6412
6413
6414 \series default 
6415  Will not do global subexpression elimination, this option may be used when
6416  the compiler creates undesirably large stack/data spaces to store compiler
6417  temporaries.
6418  A warning message will be generated when this happens and the compiler
6419  will indicate the number of extra bytes it allocated.
6420  It is recommended that this option NOT be used, #pragma\SpecialChar ~
6421 nogcse
6422 \begin_inset LatexCommand \index{\#pragma nogcse}
6423
6424 \end_inset 
6425
6426  can be used to turn off global subexpression elimination
6427 \begin_inset LatexCommand \index{Subexpression elimination}
6428
6429 \end_inset 
6430
6431  for a given function only.
6432 \layout List
6433 \labelwidthstring 00.00.0000
6434
6435
6436 \series bold 
6437 -
6438 \begin_inset ERT
6439 status Collapsed
6440
6441 \layout Standard
6442
6443 \backslash 
6444 /
6445 \end_inset 
6446
6447 -noinvariant
6448 \begin_inset LatexCommand \index{-\/-noinvariant}
6449
6450 \end_inset 
6451
6452
6453 \series default 
6454  Will not do loop invariant optimizations, this may be turned off for reasons
6455  explained for the previous option.
6456  For more details of loop optimizations performed see Loop Invariants in
6457  section 
6458 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
6459
6460 \end_inset 
6461
6462 .
6463  It is recommended that this option NOT be used, #pragma\SpecialChar ~
6464 noinvariant
6465 \begin_inset LatexCommand \index{\#pragma noinvariant}
6466
6467 \end_inset 
6468
6469  can be used to turn off invariant optimizations for a given function only.
6470 \layout List
6471 \labelwidthstring 00.00.0000
6472
6473
6474 \series bold 
6475 -
6476 \begin_inset ERT
6477 status Collapsed
6478
6479 \layout Standard
6480
6481 \backslash 
6482 /
6483 \end_inset 
6484
6485 -noinduction
6486 \begin_inset LatexCommand \index{-\/-noinduction}
6487
6488 \end_inset 
6489
6490
6491 \series default 
6492  Will not do loop induction optimizations, see section strength reduction
6493  for more details.
6494  It is recommended that this option is NOT used, #pragma\SpecialChar ~
6495 noinduction
6496 \begin_inset LatexCommand \index{\#pragma noinduction}
6497
6498 \end_inset 
6499
6500  can be used to turn off induction optimizations for a given function only.
6501 \layout List
6502 \labelwidthstring 00.00.0000
6503
6504
6505 \series bold 
6506 -
6507 \begin_inset ERT
6508 status Collapsed
6509
6510 \layout Standard
6511
6512 \backslash 
6513 /
6514 \end_inset 
6515
6516 -nojtbound
6517 \begin_inset LatexCommand \index{-\/-nojtbound}
6518
6519 \end_inset 
6520
6521
6522 \size large 
6523 \bar under 
6524  
6525 \series default 
6526 \size default 
6527 \bar default 
6528  Will not generate boundary condition check when switch statements
6529 \begin_inset LatexCommand \index{switch statement}
6530
6531 \end_inset 
6532
6533  are implemented using jump-tables.
6534  See section 
6535 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
6536
6537 \end_inset 
6538
6539 \SpecialChar ~
6540 Switch Statements for more details.
6541  It is recommended that this option is NOT used, #pragma\SpecialChar ~
6542 nojtbound
6543 \begin_inset LatexCommand \index{\#pragma nojtbound}
6544
6545 \end_inset 
6546
6547  can be used to turn off boundary checking for jump tables for a given function
6548  only.
6549 \layout List
6550 \labelwidthstring 00.00.0000
6551
6552
6553 \series bold 
6554 -
6555 \begin_inset ERT
6556 status Collapsed
6557
6558 \layout Standard
6559
6560 \backslash 
6561 /
6562 \end_inset 
6563
6564 -noloopreverse
6565 \begin_inset LatexCommand \index{-\/-noloopreverse}
6566
6567 \end_inset 
6568
6569
6570 \series default 
6571 \size large 
6572  
6573 \size default 
6574 Will not do loop reversal 
6575 \begin_inset LatexCommand \index{Loop reversing}
6576
6577 \end_inset 
6578
6579 optimization.
6580 \layout List
6581 \labelwidthstring 00.00.0000
6582
6583 -
6584 \begin_inset ERT
6585 status Collapsed
6586
6587 \layout Standard
6588
6589 \backslash 
6590 /
6591 \end_inset 
6592
6593 -
6594 \series bold 
6595 nolabelopt
6596 \series default 
6597  
6598 \begin_inset LatexCommand \index{-\/-nolabelopt }
6599
6600 \end_inset 
6601
6602 Will not optimize labels (makes the dumpfiles more readable).
6603 \layout List
6604 \labelwidthstring 00.00.0000
6605
6606
6607 \series bold 
6608 -
6609 \begin_inset ERT
6610 status Collapsed
6611
6612 \layout Standard
6613
6614 \backslash 
6615 /
6616 \end_inset 
6617
6618 -no-xinit-opt
6619 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
6620
6621 \end_inset 
6622
6623
6624 \series default 
6625  Will not memcpy initialized data from code space into xdata space.
6626  This saves a few bytes in code space if you don't have initialized data.
6627 \layout List
6628 \labelwidthstring 00.00.0000
6629
6630
6631 \series bold 
6632 -
6633 \begin_inset ERT
6634 status Collapsed
6635
6636 \layout Standard
6637
6638 \backslash 
6639 /
6640 \end_inset 
6641
6642 -nooverlay
6643 \begin_inset LatexCommand \index{-\/-nooverlay}
6644
6645 \end_inset 
6646
6647
6648 \series default 
6649   The compiler will not overlay parameters and local variables of any function,
6650  see section Parameters and local variables for more details.
6651 \layout List
6652 \labelwidthstring 00.00.0000
6653
6654
6655 \series bold 
6656 -
6657 \begin_inset ERT
6658 status Collapsed
6659
6660 \layout Standard
6661
6662 \backslash 
6663 /
6664 \end_inset 
6665
6666 -no-peep
6667 \begin_inset LatexCommand \index{-\/-no-peep}
6668
6669 \end_inset 
6670
6671
6672 \series default 
6673  Disable peep-hole optimization.
6674 \layout List
6675 \labelwidthstring 00.00.0000
6676
6677
6678 \series bold 
6679 -
6680 \begin_inset ERT
6681 status Collapsed
6682
6683 \layout Standard
6684
6685 \backslash 
6686 /
6687 \end_inset 
6688
6689 -peep-file
6690 \series default 
6691
6692 \begin_inset LatexCommand \index{-\/-peep-file}
6693
6694 \end_inset 
6695
6696 \SpecialChar ~
6697 <filename> This option can be used to use additional rules to be used by
6698  the peep hole optimizer.
6699  See section 
6700 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
6701
6702 \end_inset 
6703
6704 \SpecialChar ~
6705 Peep Hole optimizations for details on how to write these rules.
6706 \layout List
6707 \labelwidthstring 00.00.0000
6708
6709
6710 \series bold 
6711 -
6712 \begin_inset ERT
6713 status Collapsed
6714
6715 \layout Standard
6716
6717 \backslash 
6718 /
6719 \end_inset 
6720
6721 -peep-asm
6722 \begin_inset LatexCommand \index{-\/-peep-asm}
6723
6724 \end_inset 
6725
6726
6727 \series default 
6728  Pass the inline assembler code through the peep hole optimizer.
6729  This can cause unexpected changes to inline assembler code, please go through
6730  the peephole optimizer
6731 \begin_inset LatexCommand \index{Peephole optimizer}
6732
6733 \end_inset 
6734
6735  rules defined in the source file tree '<target>/peeph.def' before using
6736  this option.
6737 \layout List
6738 \labelwidthstring 00.00.0000
6739
6740
6741 \series bold 
6742 -
6743 \begin_inset ERT
6744 status Collapsed
6745
6746 \layout Standard
6747
6748 \backslash 
6749 /
6750 \end_inset 
6751
6752 -opt-code-speed
6753 \begin_inset LatexCommand \index{-\/-opt-code-speed}
6754
6755 \end_inset 
6756
6757
6758 \series default 
6759  The compiler will optimize code generation towards fast code, possibly
6760  at the expense of code size.
6761 \layout List
6762 \labelwidthstring 00.00.0000
6763
6764
6765 \series bold 
6766 -
6767 \begin_inset ERT
6768 status Collapsed
6769
6770 \layout Standard
6771
6772 \backslash 
6773 /
6774 \end_inset 
6775
6776 -opt-code-size
6777 \begin_inset LatexCommand \index{-\/-opt-code-size}
6778
6779 \end_inset 
6780
6781
6782 \series default 
6783  The compiler will optimize code generation towards compact code, possibly
6784  at the expense of code speed.
6785 \layout Subsection
6786
6787 Other Options
6788 \begin_inset LatexCommand \index{Options other}
6789
6790 \end_inset 
6791
6792
6793 \layout List
6794 \labelwidthstring 00.00.0000
6795
6796
6797 \series bold 
6798 -c\SpecialChar ~
6799 -
6800 \begin_inset ERT
6801 status Collapsed
6802
6803 \layout Standard
6804
6805 \backslash 
6806 /
6807 \end_inset 
6808
6809 -compile-only
6810 \begin_inset LatexCommand \index{-\/-compile-only}
6811
6812 \end_inset 
6813
6814
6815 \begin_inset LatexCommand \index{-c -\/-compile-only}
6816
6817 \end_inset 
6818
6819
6820 \series default 
6821  will compile and assemble the source, but will not call the linkage editor.
6822 \layout List
6823 \labelwidthstring 00.00.0000
6824
6825
6826 \series bold 
6827 -
6828 \series default 
6829
6830 \begin_inset ERT
6831 status Collapsed
6832
6833 \layout Standard
6834
6835 \backslash 
6836 /
6837 \end_inset 
6838
6839
6840 \series bold 
6841 -c1mode
6842 \begin_inset LatexCommand \index{-\/-c1mode}
6843
6844 \end_inset 
6845
6846
6847 \series default 
6848  reads the preprocessed source from standard input and compiles it.
6849  The file name for the assembler output must be specified using the -o option.
6850 \layout List
6851 \labelwidthstring 00.00.0000
6852
6853
6854 \series bold 
6855 -E
6856 \begin_inset LatexCommand \index{-E}
6857
6858 \end_inset 
6859
6860
6861 \series default 
6862  Run only the C preprocessor.
6863  Preprocess all the C source files specified and output the results to standard
6864  output.
6865 \layout List
6866 \labelwidthstring 00.00.0000
6867
6868
6869 \series bold 
6870 -o\SpecialChar ~
6871 <path/file>
6872 \begin_inset LatexCommand \index{-o <path/file>}
6873
6874 \end_inset 
6875
6876  
6877 \series default 
6878 The output path resp.
6879  file where everything will be placed.
6880  If the parameter is a path, it must have a trailing slash (or backslash
6881  for the Windows binaries) to be recognized as a path.
6882  
6883 \layout List
6884 \labelwidthstring 00.00.0000
6885
6886
6887 \series bold 
6888 -
6889 \begin_inset ERT
6890 status Collapsed
6891
6892 \layout Standard
6893
6894 \backslash 
6895 /
6896 \end_inset 
6897
6898 -stack-auto
6899 \begin_inset LatexCommand \index{-\/-stack-auto}
6900
6901 \end_inset 
6902
6903
6904 \series default 
6905 \size large 
6906 \emph on 
6907  
6908 \size default 
6909 \emph default 
6910 All functions in the source file will be compiled as 
6911 \emph on 
6912 reentrant
6913 \emph default 
6914
6915 \begin_inset LatexCommand \index{reentrant}
6916
6917 \end_inset 
6918
6919 , i.e.
6920  the parameters and local variables will be allocated on the stack
6921 \begin_inset LatexCommand \index{stack}
6922
6923 \end_inset 
6924
6925 .
6926  See section 
6927 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
6928
6929 \end_inset 
6930
6931  Parameters and Local Variables for more details.
6932  If this option is used all source files in the project should be compiled
6933  with this option.
6934  It automatically implies --int-long-reent and --float-reent.
6935  
6936 \layout List
6937 \labelwidthstring 00.00.0000
6938
6939
6940 \series bold 
6941 -
6942 \begin_inset ERT
6943 status Collapsed
6944
6945 \layout Standard
6946
6947 \backslash 
6948 /
6949 \end_inset 
6950
6951 -callee-saves
6952 \begin_inset LatexCommand \index{-\/-callee-saves}
6953
6954 \end_inset 
6955
6956  function1[,function2][,function3]....
6957
6958 \series default 
6959  The compiler by default uses a caller saves convention for register saving
6960  across function calls, however this can cause unnecessary register pushing
6961  & popping when calling small functions from larger functions.
6962  This option can be used to switch the register saving convention for the
6963  function names specified.
6964  The compiler will not save registers when calling these functions, no extra
6965  code will be generated at the entry & exit (function prologue
6966 \series bold 
6967
6968 \begin_inset LatexCommand \index{function prologue}
6969
6970 \end_inset 
6971
6972
6973 \series default 
6974  & epilogue
6975 \series bold 
6976
6977 \begin_inset LatexCommand \index{function epilogue}
6978
6979 \end_inset 
6980
6981
6982 \series default 
6983 ) for these functions to save & restore the registers used by these functions,
6984  this can SUBSTANTIALLY reduce code & improve run time performance of the
6985  generated code.
6986  In the future the compiler (with inter procedural analysis) will be able
6987  to determine the appropriate scheme to use for each function call.
6988  DO NOT use this option for built-in functions such as _mulint..., if this
6989  option is used for a library function the appropriate library function
6990  needs to be recompiled with the same option.
6991  If the project consists of multiple source files then all the source file
6992  should be compiled with the same -
6993 \begin_inset ERT
6994 status Collapsed
6995
6996 \layout Standard
6997
6998 \backslash 
6999 /
7000 \end_inset 
7001
7002 -callee-saves option string.
7003  Also see #pragma\SpecialChar ~
7004 callee_saves
7005 \begin_inset LatexCommand \index{\#pragma callee\_saves}
7006
7007 \end_inset 
7008
7009 .
7010 \layout List
7011 \labelwidthstring 00.00.0000
7012
7013
7014 \series bold 
7015 -
7016 \begin_inset ERT
7017 status Collapsed
7018
7019 \layout Standard
7020
7021 \backslash 
7022 /
7023 \end_inset 
7024
7025 -debug
7026 \begin_inset LatexCommand \index{-\/-debug}
7027
7028 \end_inset 
7029
7030
7031 \bar under 
7032  
7033 \series default 
7034 \bar default 
7035 When this option is used the compiler will generate debug information.
7036  The debug information collected in a file with .cdb extension can be used
7037  with the SDCDB.
7038  For more information see documentation for SDCDB.
7039  Another file with no extension contains debug information in AOMF or AOMF51
7040 \begin_inset LatexCommand \index{AOMF, AOMF51}
7041
7042 \end_inset 
7043
7044  format which is commonly used by third party tools.
7045 \layout List
7046 \labelwidthstring 00.00.0000
7047
7048
7049 \series bold 
7050 -S
7051 \begin_inset LatexCommand \index{-S}
7052
7053 \end_inset 
7054
7055
7056 \size large 
7057 \bar under 
7058  
7059 \series default 
7060 \size default 
7061 \bar default 
7062 Stop after the stage of compilation proper; do not assemble.
7063  The output is an assembler code file for the input file specified.
7064 \layout List
7065 \labelwidthstring 00.00.0000
7066
7067
7068 \series bold 
7069 -
7070 \begin_inset ERT
7071 status Collapsed
7072
7073 \layout Standard
7074
7075 \backslash 
7076 /
7077 \end_inset 
7078
7079 -int-long-reent
7080 \begin_inset LatexCommand \index{-\/-int-long-reent}
7081
7082 \end_inset 
7083
7084
7085 \series default 
7086  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
7087  Note by default these libraries are compiled as non-reentrant.
7088  See section Installation for more details.
7089 \layout List
7090 \labelwidthstring 00.00.0000
7091
7092
7093 \series bold 
7094 -
7095 \begin_inset ERT
7096 status Collapsed
7097
7098 \layout Standard
7099
7100 \backslash 
7101 /
7102 \end_inset 
7103
7104 -cyclomatic
7105 \begin_inset LatexCommand \index{-\/-cyclomatic}
7106
7107 \end_inset 
7108
7109
7110 \bar under 
7111  
7112 \series default 
7113 \bar default 
7114 This option will cause the compiler to generate an information message for
7115  each function in the source file.
7116  The message contains some 
7117 \emph on 
7118 important
7119 \emph default 
7120  information about the function.
7121  The number of edges and nodes the compiler detected in the control flow
7122  graph of the function, and most importantly the 
7123 \emph on 
7124 cyclomatic complexity
7125 \begin_inset LatexCommand \index{Cyclomatic complexity}
7126
7127 \end_inset 
7128
7129
7130 \emph default 
7131  see section on Cyclomatic Complexity for more details.
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 -float-reent
7148 \begin_inset LatexCommand \index{-\/-float-reent}
7149
7150 \end_inset 
7151
7152
7153 \series default 
7154  Floating point library is compiled as reentrant
7155 \begin_inset LatexCommand \index{reentrant}
7156
7157 \end_inset 
7158
7159 .
7160  See section Installation for more details.
7161 \layout List
7162 \labelwidthstring 00.00.0000
7163
7164
7165 \series bold 
7166 -
7167 \begin_inset ERT
7168 status Collapsed
7169
7170 \layout Standard
7171
7172 \backslash 
7173 /
7174 \end_inset 
7175
7176 -main-return
7177 \begin_inset LatexCommand \index{-\/-main-return}
7178
7179 \end_inset 
7180
7181
7182 \series default 
7183  This option can be used if the code generated is called by a monitor program
7184  or if the main routine includes an endless loop.
7185  This option might result in slightly smaller code and save two bytes of
7186  stack space.
7187  The return from the 'main'
7188 \begin_inset LatexCommand \index{main return}
7189
7190 \end_inset 
7191
7192  function will return to the function calling main.
7193  The default setting is to lock up i.e.
7194  generate a '
7195 \family typewriter 
7196 sjmp .
7197 \family default 
7198 '.
7199 \layout List
7200 \labelwidthstring 00.00.0000
7201
7202
7203 \series bold 
7204 -
7205 \begin_inset ERT
7206 status Collapsed
7207
7208 \layout Standard
7209
7210 \backslash 
7211 /
7212 \end_inset 
7213
7214 -nostdinc
7215 \begin_inset LatexCommand \index{-\/-nostdinc}
7216
7217 \end_inset 
7218
7219
7220 \series default 
7221  This will prevent the compiler from passing on the default include path
7222  to the preprocessor.
7223 \layout List
7224 \labelwidthstring 00.00.0000
7225
7226
7227 \series bold 
7228 -
7229 \begin_inset ERT
7230 status Collapsed
7231
7232 \layout Standard
7233
7234 \backslash 
7235 /
7236 \end_inset 
7237
7238 -nostdlib
7239 \begin_inset LatexCommand \index{-\/-nostdlib}
7240
7241 \end_inset 
7242
7243
7244 \series default 
7245  This will prevent the compiler from passing on the default library
7246 \begin_inset LatexCommand \index{Libraries}
7247
7248 \end_inset 
7249
7250  path to the linker.
7251 \layout List
7252 \labelwidthstring 00.00.0000
7253
7254
7255 \series bold 
7256 -
7257 \begin_inset ERT
7258 status Collapsed
7259
7260 \layout Standard
7261
7262 \backslash 
7263 /
7264 \end_inset 
7265
7266 -verbose
7267 \begin_inset LatexCommand \index{-\/-verbose}
7268
7269 \end_inset 
7270
7271
7272 \series default 
7273  Shows the various actions the compiler is performing.
7274 \layout List
7275 \labelwidthstring 00.00.0000
7276
7277
7278 \series bold 
7279 -V
7280 \begin_inset LatexCommand \index{-V}
7281
7282 \end_inset 
7283
7284
7285 \series default 
7286  Shows the actual commands the compiler is executing.
7287 \layout List
7288 \labelwidthstring 00.00.0000
7289
7290
7291 \series bold 
7292 -
7293 \begin_inset ERT
7294 status Collapsed
7295
7296 \layout Standard
7297
7298 \backslash 
7299 /
7300 \end_inset 
7301
7302 -no-c-code-in-asm
7303 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
7304
7305 \end_inset 
7306
7307
7308 \series default 
7309  Hides your ugly and inefficient c-code from the asm file, so you can always
7310  blame the compiler :)
7311 \layout List
7312 \labelwidthstring 00.00.0000
7313
7314
7315 \series bold 
7316 -
7317 \begin_inset ERT
7318 status Collapsed
7319
7320 \layout Standard
7321
7322 \backslash 
7323 /
7324 \end_inset 
7325
7326 -no-peep-comments
7327 \begin_inset LatexCommand \index{-\/-no-peep-comments}
7328
7329 \end_inset 
7330
7331
7332 \series default 
7333  Will not include peep-hole comments in the generated files.
7334 \layout List
7335 \labelwidthstring 00.00.0000
7336
7337
7338 \series bold 
7339 -
7340 \begin_inset ERT
7341 status Collapsed
7342
7343 \layout Standard
7344
7345 \backslash 
7346 /
7347 \end_inset 
7348
7349 -i-code-in-asm
7350 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
7351
7352 \end_inset 
7353
7354
7355 \series default 
7356  Include i-codes in the asm file.
7357  Sounds like noise but is most helpful for debugging the compiler itself.
7358 \layout List
7359 \labelwidthstring 00.00.0000
7360
7361
7362 \series bold 
7363 -
7364 \begin_inset ERT
7365 status Collapsed
7366
7367 \layout Standard
7368
7369 \backslash 
7370 /
7371 \end_inset 
7372
7373 -less-pedantic
7374 \begin_inset LatexCommand \index{-\/-less-pedantic}
7375
7376 \end_inset 
7377
7378
7379 \series default 
7380  Disable some of the more pedantic warnings
7381 \begin_inset LatexCommand \index{Warnings}
7382
7383 \end_inset 
7384
7385  (jwk burps: please be more specific here, please!).
7386  If you want rather more than less warnings you should consider using a
7387  separate tool dedicated to syntax checking like splint 
7388 \begin_inset LatexCommand \url{www.splint.org}
7389
7390 \end_inset 
7391
7392 .
7393 \layout List
7394 \labelwidthstring 00.00.0000
7395
7396
7397 \series bold 
7398 -
7399 \begin_inset ERT
7400 status Collapsed
7401
7402 \layout Standard
7403
7404 \backslash 
7405 /
7406 \end_inset 
7407
7408 -disable-warning\SpecialChar ~
7409 <nnnn>
7410 \begin_inset LatexCommand \index{-\/-disable-warning}
7411
7412 \end_inset 
7413
7414
7415 \series default 
7416  Disable specific warning with number <nnnn>.
7417 \layout List
7418 \labelwidthstring 00.00.0000
7419
7420
7421 \series bold 
7422 -
7423 \begin_inset ERT
7424 status Collapsed
7425
7426 \layout Standard
7427
7428 \backslash 
7429 /
7430 \end_inset 
7431
7432 -print-search-dirs
7433 \begin_inset LatexCommand \index{-\/-print-search-dirs}
7434
7435 \end_inset 
7436
7437
7438 \series default 
7439  Display the directories in the compiler's search path
7440 \layout List
7441 \labelwidthstring 00.00.0000
7442
7443
7444 \series bold 
7445 -
7446 \begin_inset ERT
7447 status Collapsed
7448
7449 \layout Standard
7450
7451 \backslash 
7452 /
7453 \end_inset 
7454
7455 -vc
7456 \begin_inset LatexCommand \index{-\/-vc}
7457
7458 \end_inset 
7459
7460
7461 \series default 
7462  Display errors and warnings using MSVC style, so you can use SDCC with
7463  visual studio.
7464 \layout List
7465 \labelwidthstring 00.00.0000
7466
7467
7468 \series bold 
7469 -
7470 \begin_inset ERT
7471 status Collapsed
7472
7473 \layout Standard
7474
7475 \backslash 
7476 /
7477 \end_inset 
7478
7479 -use-stdout
7480 \begin_inset LatexCommand \index{-\/-use-stdout}
7481
7482 \end_inset 
7483
7484
7485 \series default 
7486  Send errors and warnings to stdout instead of stderr.
7487 \layout List
7488 \labelwidthstring 00.00.0000
7489
7490
7491 \series bold 
7492 -Wa\SpecialChar ~
7493 asmOption[,asmOption]
7494 \series default 
7495
7496 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
7497
7498 \end_inset 
7499
7500 ...
7501  Pass the asmOption to the assembler
7502 \begin_inset LatexCommand \index{Options assembler}
7503
7504 \end_inset 
7505
7506
7507 \begin_inset LatexCommand \index{Assembler options}
7508
7509 \end_inset 
7510
7511 .
7512  See file sdcc/as/doc/asxhtm.html for assembler options.
7513 \layout Subsection
7514
7515 Intermediate Dump Options
7516 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
7517
7518 \end_inset 
7519
7520
7521 \begin_inset LatexCommand \index{Options intermediate dump}
7522
7523 \end_inset 
7524
7525
7526 \begin_inset LatexCommand \index{Intermediate dump options}
7527
7528 \end_inset 
7529
7530
7531 \layout Standard
7532
7533 The following options are provided for the purpose of retargetting and debugging
7534  the compiler.
7535  These provided a means to dump the intermediate code (iCode
7536 \begin_inset LatexCommand \index{iCode}
7537
7538 \end_inset 
7539
7540 ) generated by the compiler in human readable form at various stages of
7541  the compilation process.
7542  More on iCodes see chapter 
7543 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
7544
7545 \end_inset 
7546
7547  
7548 \begin_inset Quotes srd
7549 \end_inset 
7550
7551 The anatomy of the compiler
7552 \begin_inset Quotes srd
7553 \end_inset 
7554
7555 .
7556 \layout List
7557 \labelwidthstring 00.00.0000
7558
7559
7560 \series bold 
7561 -
7562 \begin_inset ERT
7563 status Collapsed
7564
7565 \layout Standard
7566
7567 \backslash 
7568 /
7569 \end_inset 
7570
7571 -dumpraw
7572 \begin_inset LatexCommand \index{-\/-dumpraw}
7573
7574 \end_inset 
7575
7576
7577 \series default 
7578  This option will cause the compiler to dump the intermediate code into
7579  a file of named 
7580 \emph on 
7581 <source filename>.dumpraw
7582 \emph default 
7583  just after the intermediate code has been generated for a function, i.e.
7584  before any optimizations are done.
7585  The basic blocks
7586 \begin_inset LatexCommand \index{Basic blocks}
7587
7588 \end_inset 
7589
7590  at this stage ordered in the depth first number, so they may not be in
7591  sequence of execution.
7592 \layout List
7593 \labelwidthstring 00.00.0000
7594
7595
7596 \series bold 
7597 -
7598 \begin_inset ERT
7599 status Collapsed
7600
7601 \layout Standard
7602
7603 \backslash 
7604 /
7605 \end_inset 
7606
7607 -dumpgcse
7608 \begin_inset LatexCommand \index{-\/-dumpgcse}
7609
7610 \end_inset 
7611
7612
7613 \series default 
7614  Will create a dump of iCode's, after global subexpression elimination
7615 \begin_inset LatexCommand \index{Global subexpression elimination}
7616
7617 \end_inset 
7618
7619 , into a file named 
7620 \emph on 
7621 <source filename>.dumpgcse.
7622 \layout List
7623 \labelwidthstring 00.00.0000
7624
7625
7626 \series bold 
7627 -
7628 \begin_inset ERT
7629 status Collapsed
7630
7631 \layout Standard
7632
7633 \backslash 
7634 /
7635 \end_inset 
7636
7637 -dumpdeadcode
7638 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
7639
7640 \end_inset 
7641
7642
7643 \series default 
7644  Will create a dump of iCode's, after deadcode elimination
7645 \begin_inset LatexCommand \index{Dead-code elimination}
7646
7647 \end_inset 
7648
7649 , into a file named 
7650 \emph on 
7651 <source filename>.dumpdeadcode.
7652 \layout List
7653 \labelwidthstring 00.00.0000
7654
7655
7656 \series bold 
7657 -
7658 \begin_inset ERT
7659 status Collapsed
7660
7661 \layout Standard
7662
7663 \backslash 
7664 /
7665 \end_inset 
7666
7667 -dumploop
7668 \begin_inset LatexCommand \index{-\/-dumploop}
7669
7670 \end_inset 
7671
7672
7673 \series default 
7674 \size large 
7675  
7676 \size default 
7677 Will create a dump of iCode's, after loop optimizations
7678 \begin_inset LatexCommand \index{Loop optimization}
7679
7680 \end_inset 
7681
7682 , into a file named 
7683 \emph on 
7684 <source filename>.dumploop.
7685 \layout List
7686 \labelwidthstring 00.00.0000
7687
7688
7689 \series bold 
7690 -
7691 \begin_inset ERT
7692 status Collapsed
7693
7694 \layout Standard
7695
7696 \backslash 
7697 /
7698 \end_inset 
7699
7700 -dumprange
7701 \begin_inset LatexCommand \index{-\/-dumprange}
7702
7703 \end_inset 
7704
7705
7706 \series default 
7707 \size large 
7708  
7709 \size default 
7710 Will create a dump of iCode's, after live range analysis
7711 \begin_inset LatexCommand \index{Live range analysis}
7712
7713 \end_inset 
7714
7715 , into a file named 
7716 \emph on 
7717 <source filename>.dumprange.
7718 \layout List
7719 \labelwidthstring 00.00.0000
7720
7721
7722 \series bold 
7723 -
7724 \begin_inset ERT
7725 status Collapsed
7726
7727 \layout Standard
7728
7729 \backslash 
7730 /
7731 \end_inset 
7732
7733 -dumlrange
7734 \begin_inset LatexCommand \index{-\/-dumlrange}
7735
7736 \end_inset 
7737
7738
7739 \series default 
7740  Will dump the life ranges
7741 \begin_inset LatexCommand \index{Live range analysis}
7742
7743 \end_inset 
7744
7745  for all symbols.
7746 \layout List
7747 \labelwidthstring 00.00.0000
7748
7749
7750 \series bold 
7751 -
7752 \begin_inset ERT
7753 status Collapsed
7754
7755 \layout Standard
7756
7757 \backslash 
7758 /
7759 \end_inset 
7760
7761 -dumpregassign
7762 \begin_inset LatexCommand \index{-\/-dumpregassign}
7763
7764 \end_inset 
7765
7766
7767 \bar under 
7768  
7769 \series default 
7770 \bar default 
7771 Will create a dump of iCode's, after register assignment
7772 \begin_inset LatexCommand \index{Register assignment}
7773
7774 \end_inset 
7775
7776 , into a file named 
7777 \emph on 
7778 <source filename>.dumprassgn.
7779 \layout List
7780 \labelwidthstring 00.00.0000
7781
7782
7783 \series bold 
7784 -
7785 \begin_inset ERT
7786 status Collapsed
7787
7788 \layout Standard
7789
7790 \backslash 
7791 /
7792 \end_inset 
7793
7794 -dumplrange
7795 \begin_inset LatexCommand \index{-\/-dumplrange}
7796
7797 \end_inset 
7798
7799
7800 \series default 
7801  Will create a dump of the live ranges of iTemp's
7802 \layout List
7803 \labelwidthstring 00.00.0000
7804
7805
7806 \series bold 
7807 -
7808 \begin_inset ERT
7809 status Collapsed
7810
7811 \layout Standard
7812
7813 \backslash 
7814 /
7815 \end_inset 
7816
7817 -dumpall
7818 \begin_inset LatexCommand \index{-\/-dumpall}
7819
7820 \end_inset 
7821
7822
7823 \size large 
7824 \bar under 
7825  
7826 \series default 
7827 \size default 
7828 \bar default 
7829 Will cause all the above mentioned dumps to be created.
7830 \layout Subsection
7831
7832 Redirecting output on Windows Shells
7833 \layout Standard
7834
7835 By default SDCC writes it's error messages to 
7836 \begin_inset Quotes sld
7837 \end_inset 
7838
7839 standard error
7840 \begin_inset Quotes srd
7841 \end_inset 
7842
7843 .
7844  To force all messages to 
7845 \begin_inset Quotes sld
7846 \end_inset 
7847
7848 standard output
7849 \begin_inset Quotes srd
7850 \end_inset 
7851
7852  use 
7853 \series bold 
7854 -
7855 \series default 
7856 \emph on 
7857
7858 \begin_inset ERT
7859 status Collapsed
7860
7861 \layout Standard
7862
7863 \backslash 
7864 /
7865 \end_inset 
7866
7867
7868 \series bold 
7869 \emph default 
7870 -
7871 \series default 
7872 use-stdout
7873 \begin_inset LatexCommand \index{-\/-use-stdout}
7874
7875 \end_inset 
7876
7877 .
7878  Additionally, if you happen to have visual studio installed in your windows
7879  machine, you can use it to compile your sources using a custom build and
7880  the SDCC -
7881 \emph on 
7882
7883 \begin_inset ERT
7884 status Collapsed
7885
7886 \layout Standard
7887
7888 \backslash 
7889 /
7890 \end_inset 
7891
7892
7893 \emph default 
7894 -vc
7895 \begin_inset LatexCommand \index{-\/-vc}
7896
7897 \end_inset 
7898
7899  option.
7900  Something like this should work:
7901 \newline 
7902
7903 \newline 
7904
7905 \series bold 
7906 c:
7907 \backslash 
7908 sdcc
7909 \backslash 
7910 bin
7911 \backslash 
7912 sdcc.exe -
7913 \series default 
7914 \emph on 
7915
7916 \begin_inset ERT
7917 status Collapsed
7918
7919 \layout Standard
7920
7921 \backslash 
7922 /
7923 \end_inset 
7924
7925
7926 \series bold 
7927 \emph default 
7928 -vc -
7929 \series default 
7930 \emph on 
7931
7932 \begin_inset ERT
7933 status Collapsed
7934
7935 \layout Standard
7936
7937 \backslash 
7938 /
7939 \end_inset 
7940
7941
7942 \series bold 
7943 \emph default 
7944 -model-large -c $(InputPath)
7945 \layout Section
7946
7947 Environment variables
7948 \begin_inset LatexCommand \index{Environment variables}
7949
7950 \end_inset 
7951
7952
7953 \layout Standard
7954
7955 SDCC recognizes the following environment variables:
7956 \layout List
7957 \labelwidthstring 00.00.0000
7958
7959
7960 \series bold 
7961 SDCC_LEAVE_SIGNALS
7962 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
7963
7964 \end_inset 
7965
7966
7967 \series default 
7968  SDCC installs a signal handler
7969 \begin_inset LatexCommand \index{signal handler}
7970
7971 \end_inset 
7972
7973  to be able to delete temporary files after an user break (^C) or an exception.
7974  If this environment variable is set, SDCC won't install the signal handler
7975  in order to be able to debug SDCC.
7976 \layout List
7977 \labelwidthstring 00.00.0000
7978
7979
7980 \series bold 
7981 TMP,\SpecialChar ~
7982 TEMP,\SpecialChar ~
7983 TMPDIR
7984 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
7985
7986 \end_inset 
7987
7988
7989 \series default 
7990  Path, where temporary files will be created.
7991  The order of the variables is the search order.
7992  In a standard *nix environment these variables are not set, and there's
7993  no need to set them.
7994  On Windows it's recommended to set one of them.
7995 \layout List
7996 \labelwidthstring 00.00.0000
7997
7998
7999 \series bold 
8000 SDCC_HOME
8001 \begin_inset LatexCommand \index{SDCC\_HOME}
8002
8003 \end_inset 
8004
8005
8006 \series default 
8007  Path, see section 
8008 \begin_inset LatexCommand \ref{sub:Install-paths}
8009
8010 \end_inset 
8011
8012 \SpecialChar ~
8013
8014 \begin_inset Quotes sld
8015 \end_inset 
8016
8017  Install Paths
8018 \begin_inset Quotes srd
8019 \end_inset 
8020
8021 .
8022 \layout List
8023 \labelwidthstring 00.00.0000
8024
8025
8026 \series bold 
8027 SDCC_INCLUDE
8028 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
8029
8030 \end_inset 
8031
8032
8033 \series default 
8034  Path, see section 
8035 \begin_inset LatexCommand \ref{sub:Search-Paths}
8036
8037 \end_inset 
8038
8039 \SpecialChar ~
8040
8041 \begin_inset Quotes sld
8042 \end_inset 
8043
8044 Search Paths
8045 \begin_inset Quotes srd
8046 \end_inset 
8047
8048 .
8049 \layout List
8050 \labelwidthstring 00.00.0000
8051
8052
8053 \series bold 
8054 SDCC_LIB
8055 \begin_inset LatexCommand \index{SDCC\_LIB}
8056
8057 \end_inset 
8058
8059
8060 \series default 
8061  Path, see section 
8062 \begin_inset LatexCommand \ref{sub:Search-Paths}
8063
8064 \end_inset 
8065
8066 \SpecialChar ~
8067
8068 \begin_inset Quotes sld
8069 \end_inset 
8070
8071 Search Paths
8072 \begin_inset Quotes srd
8073 \end_inset 
8074
8075 ..
8076 \layout Standard
8077
8078 There are some more environment variables recognized by SDCC, but these
8079  are solely used for debugging purposes.
8080  They can change or disappear very quickly, and will never be documented.
8081 \layout Section
8082
8083 Storage Class Language Extensions
8084 \layout Subsection
8085
8086 MCS51/DS390 Storage Class
8087 \begin_inset LatexCommand \index{Storage class}
8088
8089 \end_inset 
8090
8091  Language Extensions
8092 \layout Standard
8093
8094 In addition to the ANSI storage classes SDCC allows the following MCS51
8095  specific storage classes:
8096 \layout Subsubsection
8097
8098 data
8099 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
8100
8101 \end_inset 
8102
8103  / near
8104 \begin_inset LatexCommand \index{near (storage class)}
8105
8106 \end_inset 
8107
8108
8109 \layout Standard
8110
8111 This is the 
8112 \series bold 
8113 default
8114 \series default 
8115  storage class for the Small Memory model (
8116 \emph on 
8117 data
8118 \emph default 
8119  and 
8120 \emph on 
8121 near
8122 \emph default 
8123  can be used synonymously).
8124  Variables declared with this storage class will be allocated in the directly
8125  addressable portion of the internal RAM of a 8051, e.g.:
8126 \layout Verse
8127
8128
8129 \family typewriter 
8130 data unsigned char test_data;
8131 \layout Standard
8132
8133 Writing 0x01 to this variable generates the assembly code:
8134 \layout Verse
8135
8136
8137 \family typewriter 
8138 75*00 01\SpecialChar ~
8139 \SpecialChar ~
8140 \SpecialChar ~
8141 mov\SpecialChar ~
8142 \SpecialChar ~
8143 _test_data,#0x01 
8144 \layout Subsubsection
8145
8146 xdata
8147 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
8148
8149 \end_inset 
8150
8151  / far
8152 \begin_inset LatexCommand \index{far (storage class)}
8153
8154 \end_inset 
8155
8156
8157 \layout Standard
8158
8159 Variables declared with this storage class will be placed in the external
8160  RAM.
8161  This is the 
8162 \series bold 
8163 default
8164 \series default 
8165  storage class for the Large Memory model, e.g.:
8166 \layout Verse
8167
8168
8169 \family typewriter 
8170 xdata unsigned char test_xdata;
8171 \layout Standard
8172
8173 Writing 0x01 to this variable generates the assembly code:
8174 \layout Verse
8175
8176
8177 \family typewriter 
8178 90s00r00\SpecialChar ~
8179 \SpecialChar ~
8180 \SpecialChar ~
8181 mov\SpecialChar ~
8182 \SpecialChar ~
8183 dptr,#_test_xdata 
8184 \newline 
8185 74\SpecialChar ~
8186 01\SpecialChar ~
8187 \SpecialChar ~
8188 \SpecialChar ~
8189 \SpecialChar ~
8190 \SpecialChar ~
8191 \SpecialChar ~
8192 mov\SpecialChar ~
8193 \SpecialChar ~
8194 a,#0x01 
8195 \newline 
8196 F0\SpecialChar ~
8197 \SpecialChar ~
8198 \SpecialChar ~
8199 \SpecialChar ~
8200 \SpecialChar ~
8201 \SpecialChar ~
8202 \SpecialChar ~
8203 \SpecialChar ~
8204 \SpecialChar ~
8205 movx\SpecialChar ~
8206 @dptr,a 
8207 \layout Subsubsection
8208
8209 idata
8210 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
8211
8212 \end_inset 
8213
8214
8215 \layout Standard
8216
8217 Variables declared with this storage class will be allocated into the indirectly
8218  addressable portion of the internal ram of a 8051, e.g.:
8219 \layout Verse
8220
8221
8222 \family typewriter 
8223 idata unsigned char test_idata;
8224 \layout Standard
8225
8226 Writing 0x01 to this variable generates the assembly code:
8227 \layout Verse
8228
8229
8230 \family typewriter 
8231 78r00\SpecialChar ~
8232 \SpecialChar ~
8233 \SpecialChar ~
8234 \SpecialChar ~
8235 \SpecialChar ~
8236 \SpecialChar ~
8237 \SpecialChar ~
8238 mov\SpecialChar ~
8239 \SpecialChar ~
8240 r0,#_test_idata
8241 \newline 
8242 76\SpecialChar ~
8243 01\SpecialChar ~
8244 \SpecialChar ~
8245 \SpecialChar ~
8246 \SpecialChar ~
8247 \SpecialChar ~
8248 \SpecialChar ~
8249 \SpecialChar ~
8250 mov\SpecialChar ~
8251 \SpecialChar ~
8252 @r0,#0x01
8253 \layout Standard
8254
8255 Please note, the first 128 byte of idata physically access the same RAM
8256  as the data memory.
8257  The original 8051 had 128 byte idata memory, nowadays most devices have
8258  256 byte idata memory.
8259  The stack
8260 \begin_inset LatexCommand \index{stack}
8261
8262 \end_inset 
8263
8264  is located in idata memory.
8265 \layout Subsubsection
8266
8267 pdata
8268 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8269
8270 \end_inset 
8271
8272
8273 \layout Standard
8274
8275 Paged xdata access is just as straightforward as using the other addressing
8276  modes of a 8051.
8277  It is typically located at the start of xdata and has a maximum size of
8278  256 bytes.
8279  The following example writes 0x01 to the address pointed to.
8280  Please note, pdata access physically accesses xdata memory.
8281  The high byte of the address is determined by port P2 
8282 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
8283
8284 \end_inset 
8285
8286 (or in case of some 8051 variants by a separate Special Function Register,
8287  see section 
8288 \begin_inset LatexCommand \ref{sub:MCS51-variants}
8289
8290 \end_inset 
8291
8292 ).
8293 \layout Verse
8294
8295
8296 \family typewriter 
8297 pdata unsigned char *test_pdata_ptr;
8298 \newline 
8299
8300 \newline 
8301 void main() 
8302 \newline 
8303
8304 \newline 
8305 \SpecialChar ~
8306 \SpecialChar ~
8307 \SpecialChar ~
8308 \SpecialChar ~
8309 test_pdata_ptr = (pdata *)0xfe; 
8310 \newline 
8311 \SpecialChar ~
8312 \SpecialChar ~
8313 \SpecialChar ~
8314 \SpecialChar ~
8315 *test_pdata_ptr = 1; 
8316 \newline 
8317
8318 \layout Standard
8319
8320 Generates the assembly code:
8321 \layout Verse
8322
8323
8324 \family typewriter 
8325 75*01 FE\SpecialChar ~
8326 \SpecialChar ~
8327 \SpecialChar ~
8328 mov\SpecialChar ~
8329  _test_pdata_ptr,#0xFE
8330 \newline 
8331 78 FE\SpecialChar ~
8332 \SpecialChar ~
8333 \SpecialChar ~
8334 \SpecialChar ~
8335 \SpecialChar ~
8336 \SpecialChar ~
8337 mov\SpecialChar ~
8338  r0,#0xFE 
8339 \newline 
8340 74 01\SpecialChar ~
8341 \SpecialChar ~
8342 \SpecialChar ~
8343 \SpecialChar ~
8344 \SpecialChar ~
8345 \SpecialChar ~
8346 mov\SpecialChar ~
8347  a,#0x01
8348 \newline 
8349 F2\SpecialChar ~
8350 \SpecialChar ~
8351 \SpecialChar ~
8352 \SpecialChar ~
8353 \SpecialChar ~
8354 \SpecialChar ~
8355 \SpecialChar ~
8356 \SpecialChar ~
8357 \SpecialChar ~
8358 movx @r0,a 
8359 \layout Standard
8360
8361 If the -
8362 \begin_inset ERT
8363 status Collapsed
8364
8365 \layout Standard
8366
8367 \backslash 
8368 /
8369 \end_inset 
8370
8371 -xstack
8372 \begin_inset LatexCommand \index{-\/-xstack}
8373
8374 \end_inset 
8375
8376  option is used the pdata memory area is followed by the xstack memory area
8377  and the sum of their sizes is limited to 256 bytes.
8378 \layout Subsubsection
8379
8380 code
8381 \begin_inset LatexCommand \index{code}
8382
8383 \end_inset 
8384
8385
8386 \layout Standard
8387
8388 'Variables' declared with this storage class will be placed in the code
8389  memory:
8390 \layout Verse
8391
8392
8393 \family typewriter 
8394 code unsigned char test_code;
8395 \layout Standard
8396
8397 Read access to this variable generates the assembly code:
8398 \layout Verse
8399
8400
8401 \family typewriter 
8402 90s00r6F\SpecialChar ~
8403 \SpecialChar ~
8404 \SpecialChar ~
8405 mov dptr,#_test_code
8406 \newline 
8407 E4\SpecialChar ~
8408 \SpecialChar ~
8409 \SpecialChar ~
8410 \SpecialChar ~
8411 \SpecialChar ~
8412 \SpecialChar ~
8413 \SpecialChar ~
8414 \SpecialChar ~
8415 \SpecialChar ~
8416 clr a
8417 \newline 
8418 93\SpecialChar ~
8419 \SpecialChar ~
8420 \SpecialChar ~
8421 \SpecialChar ~
8422 \SpecialChar ~
8423 \SpecialChar ~
8424 \SpecialChar ~
8425 \SpecialChar ~
8426 \SpecialChar ~
8427 movc a,@a+dptr 
8428 \layout Standard
8429
8430
8431 \family typewriter 
8432 char
8433 \family default 
8434  indexed arrays of characters in code memory can be accessed efficiently:
8435 \layout Verse
8436
8437
8438 \family typewriter 
8439 code char test_array[] = {'c','h','e','a','p'}; 
8440 \layout Standard
8441
8442 Read access to this array using an 8-bit unsigned index generates the assembly
8443  code:
8444 \layout Verse
8445
8446
8447 \family typewriter 
8448 E5*00\SpecialChar ~
8449 \SpecialChar ~
8450 \SpecialChar ~
8451 \SpecialChar ~
8452 \SpecialChar ~
8453 \SpecialChar ~
8454 mov a,_index 
8455 \layout Verse
8456
8457
8458 \family typewriter 
8459 90s00r41\SpecialChar ~
8460 \SpecialChar ~
8461 \SpecialChar ~
8462 mov dptr,#_test_array
8463 \layout Verse
8464
8465
8466 \family typewriter 
8467 93\SpecialChar ~
8468 \SpecialChar ~
8469 \SpecialChar ~
8470 \SpecialChar ~
8471 \SpecialChar ~
8472 \SpecialChar ~
8473 \SpecialChar ~
8474 \SpecialChar ~
8475 \SpecialChar ~
8476 movc a,@a+dptr 
8477 \layout Subsubsection
8478
8479 bit
8480 \begin_inset LatexCommand \index{bit}
8481
8482 \end_inset 
8483
8484
8485 \layout Standard
8486
8487 This is a data-type and a storage class specifier.
8488  When a variable is declared as a bit, it is allocated into the bit addressable
8489  memory of 8051, e.g.:
8490 \layout Verse
8491
8492
8493 \family typewriter 
8494 bit test_bit;
8495 \layout Standard
8496
8497 Writing 1 to this variable generates the assembly code:
8498 \layout Verse
8499
8500
8501 \family typewriter 
8502 D2*00\SpecialChar ~
8503 \SpecialChar ~
8504 \SpecialChar ~
8505 \SpecialChar ~
8506 \SpecialChar ~
8507 \SpecialChar ~
8508 \SpecialChar ~
8509 setb\SpecialChar ~
8510 _test_bit
8511 \layout Standard
8512
8513 The bit addressable memory consists of 128 bits which are located from 0x20
8514  to 0x2f in data memory.
8515  
8516 \newline 
8517 Apart from this 8051 specific storage class most architectures support ANSI-C
8518  bitfields
8519 \begin_inset LatexCommand \index{bitfields}
8520
8521 \end_inset 
8522
8523
8524 \begin_inset Foot
8525 collapsed false
8526
8527 \layout Standard
8528
8529 Not really meant as examples, but nevertheless showing what bitfields are
8530  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
8531 \end_inset 
8532
8533 .
8534  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
8535  signed modifier are implemented as unsigned.
8536 \layout Subsubsection
8537
8538 sfr
8539 \begin_inset LatexCommand \index{sfr}
8540
8541 \end_inset 
8542
8543  / sbit
8544 \begin_inset LatexCommand \index{sbit}
8545
8546 \end_inset 
8547
8548
8549 \layout Standard
8550
8551 Like the bit keyword, 
8552 \emph on 
8553 sfr / sbit 
8554 \emph default 
8555 signifies both a data-type and storage class, they are used to describe
8556  the 
8557 \emph on 
8558 s
8559 \emph default 
8560 pecial 
8561 \emph on 
8562 f
8563 \emph default 
8564 unction 
8565 \emph on 
8566 r
8567 \emph default 
8568 egisters and 
8569 \emph on 
8570 s
8571 \emph default 
8572 pecial 
8573 \emph on 
8574 bit
8575 \emph default 
8576  variables of a 8051, eg:
8577 \layout Verse
8578
8579
8580 \family typewriter 
8581 sfr at
8582 \begin_inset LatexCommand \index{at}
8583
8584 \end_inset 
8585
8586  0x80 P0;\SpecialChar ~
8587  /* special function register P0 at location 0x80 */
8588 \newline 
8589 sbit at 0xd7 CY; /* CY (Carry Flag
8590 \begin_inset LatexCommand \index{Flags}
8591
8592 \end_inset 
8593
8594
8595 \begin_inset LatexCommand \index{Carry flag}
8596
8597 \end_inset 
8598
8599 ) */
8600 \layout Standard
8601
8602 Special function registers which are located on an address dividable by
8603  8 are bit-addressable, an
8604 \emph on 
8605  sbit
8606 \emph default 
8607  addresses a specific bit within these sfr.
8608 \layout Subsubsection
8609
8610 Pointers
8611 \begin_inset LatexCommand \index{Pointer}
8612
8613 \end_inset 
8614
8615  to MCS51/DS390 specific memory spaces
8616 \layout Standard
8617
8618 SDCC allows (via language extensions) pointers to explicitly point to any
8619  of the memory spaces
8620 \begin_inset LatexCommand \index{Memory model}
8621
8622 \end_inset 
8623
8624  of the 8051.
8625  In addition to the explicit pointers, the compiler uses (by default) generic
8626  pointers which can be used to point to any of the memory spaces.
8627 \newline 
8628
8629 \newline 
8630 Pointer declaration examples:
8631 \layout Verse
8632
8633
8634 \family typewriter 
8635 /* pointer physically in internal ram pointing to object in external ram
8636  */ 
8637 \newline 
8638 xdata unsigned char * data p;
8639 \newline 
8640
8641 \newline 
8642 /* pointer physically in external ram pointing to object in internal ram
8643  */ 
8644 \newline 
8645 data unsigned char * xdata p;
8646 \newline 
8647
8648 \newline 
8649 /* pointer physically in code rom pointing to data in xdata space */ 
8650 \newline 
8651 xdata unsigned char * code p;
8652 \newline 
8653
8654 \newline 
8655 /* pointer physically in code space pointing to data in code space */ 
8656 \newline 
8657 code unsigned char * code p;
8658 \newline 
8659
8660 \newline 
8661 /* the following is a generic pointer physically located in xdata space
8662  */
8663 \newline 
8664 char * xdata p;
8665 \layout Standard
8666
8667 Well you get the idea.
8668  
8669 \newline 
8670
8671 \newline 
8672 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
8673 \emph on 
8674 generic
8675 \emph default 
8676  pointers.
8677  
8678 \size small 
8679
8680 \newline 
8681
8682 \newline 
8683
8684 \size default 
8685 The highest order byte of the 
8686 \emph on 
8687 generic
8688 \emph default 
8689  pointers contains the data space information.
8690  Assembler support routines are called whenever data is stored or retrieved
8691  using 
8692 \emph on 
8693 generic
8694 \emph default 
8695  pointers.
8696  These are useful for developing reusable library
8697 \begin_inset LatexCommand \index{Libraries}
8698
8699 \end_inset 
8700
8701  routines.
8702  Explicitly specifying the pointer type will generate the most efficient
8703  code.
8704 \layout Subsubsection
8705
8706 Notes on MCS51 memory
8707 \begin_inset LatexCommand \index{MCS51 memory}
8708
8709 \end_inset 
8710
8711  layout
8712 \layout Standard
8713
8714 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
8715  RAM memory which is structured as follows:
8716 \newline 
8717
8718 \newline 
8719 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
8720  
8721 \newline 
8722 - Bytes 20-2F - 16 bytes to hold 128 bit
8723 \begin_inset LatexCommand \index{bit}
8724
8725 \end_inset 
8726
8727  variables and, 
8728 \newline 
8729 - Bytes 30-7F - 80 bytes for general purpose use.
8730 \newline 
8731
8732 \layout Standard
8733
8734 Additionally some members of the MCS51 family may have up to 128 bytes of
8735  additional, indirectly addressable, internal RAM memory (
8736 \emph on 
8737 idata
8738 \emph default 
8739
8740 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
8741
8742 \end_inset 
8743
8744 ).
8745  Furthermore, some chips may have some built in external memory (
8746 \emph on 
8747 xdata
8748 \emph default 
8749
8750 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
8751
8752 \end_inset 
8753
8754 ) which should not be confused with the internal, directly addressable RAM
8755  memory (
8756 \emph on 
8757 data
8758 \emph default 
8759
8760 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
8761
8762 \end_inset 
8763
8764 ).
8765  Sometimes this built in 
8766 \emph on 
8767 xdata
8768 \emph default 
8769  memory has to be activated before using it (you can probably find this
8770  information on the datasheet of the microcontroller your are using, see
8771  also section 
8772 \begin_inset LatexCommand \ref{sub:Startup-Code}
8773
8774 \end_inset 
8775
8776 \SpecialChar ~
8777 Startup-Code).
8778 \layout Standard
8779
8780 Normally SDCC will only use the first bank
8781 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
8782
8783 \end_inset 
8784
8785  of registers (register bank 0), but it is possible to specify that other
8786  banks of registers should be used in interrupt
8787 \begin_inset LatexCommand \index{interrupt}
8788
8789 \end_inset 
8790
8791  routines.
8792  By default, the compiler will place the stack after the last byte of allocated
8793  memory for variables.
8794  For example, if the first 2 banks of registers are used, and only four
8795  bytes are used for 
8796 \emph on 
8797 data
8798 \emph default 
8799  variables, it will position the base of the internal stack at address 20
8800  (0x14).
8801  This implies that as the stack
8802 \begin_inset LatexCommand \index{stack}
8803
8804 \end_inset 
8805
8806  grows, it will use up the remaining register banks, and the 16 bytes used
8807  by the 128 bit variables, and 80 bytes for general purpose use.
8808  If any bit variables are used, the data variables will be placed in unused
8809  register banks and after the byte holding the last bit variable.
8810  For example, if register banks 0 and 1 are used, and there are 9 bit variables
8811  (two bytes used), 
8812 \emph on 
8813 data
8814 \emph default 
8815  variables will be placed starting from address 0x10 to 0x20 and continue
8816  at address 0x22.
8817  You can also use -
8818 \begin_inset ERT
8819 status Collapsed
8820
8821 \layout Standard
8822
8823 \backslash 
8824 /
8825 \end_inset 
8826
8827 -data-loc
8828 \begin_inset LatexCommand \index{-\/-data-loc<Value>}
8829
8830 \end_inset 
8831
8832  to specify the start address of the 
8833 \emph on 
8834 data
8835 \emph default 
8836  and -
8837 \begin_inset ERT
8838 status Collapsed
8839
8840 \layout Standard
8841
8842 \backslash 
8843 /
8844 \end_inset 
8845
8846 -iram-size to specify the size of the total internal RAM (
8847 \emph on 
8848 data
8849 \emph default 
8850 +
8851 \emph on 
8852 idata
8853 \emph default 
8854 ).
8855  
8856 \layout Standard
8857
8858 By default the 8051 linker will place the stack after the last byte of (i)data
8859  variables.
8860  Option -
8861 \begin_inset ERT
8862 status Collapsed
8863
8864 \layout Standard
8865
8866 \backslash 
8867 /
8868 \end_inset 
8869
8870 -stack-loc
8871 \begin_inset LatexCommand \index{-\/-stack-loc<Value>}
8872
8873 \end_inset 
8874
8875  allows you to specify the start of the stack, i.e.
8876  you could start it after any data in the general purpose area.
8877  If your microcontroller has additional indirectly addressable internal
8878  RAM (
8879 \emph on 
8880 idata
8881 \emph default 
8882 ) you can place the stack on it.
8883  You may also need to use -
8884 \begin_inset ERT
8885 status Collapsed
8886
8887 \layout Standard
8888
8889 \backslash 
8890 /
8891 \end_inset 
8892
8893 -xdata-loc
8894 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
8895
8896 \end_inset 
8897
8898  to set the start address of the external RAM (
8899 \emph on 
8900 xdata
8901 \emph default 
8902 ) and -
8903 \begin_inset ERT
8904 status Collapsed
8905
8906 \layout Standard
8907
8908 \backslash 
8909 /
8910 \end_inset 
8911
8912 -xram-size
8913 \begin_inset LatexCommand \index{-\/-data-loc}
8914
8915 \end_inset 
8916
8917  to specify its size.
8918  Same goes for the code memory, using -
8919 \begin_inset ERT
8920 status Collapsed
8921
8922 \layout Standard
8923
8924 \backslash 
8925 /
8926 \end_inset 
8927
8928 -code-loc
8929 \begin_inset LatexCommand \index{-\/-data-loc}
8930
8931 \end_inset 
8932
8933  and -
8934 \begin_inset ERT
8935 status Collapsed
8936
8937 \layout Standard
8938
8939 \backslash 
8940 /
8941 \end_inset 
8942
8943 -code-size
8944 \begin_inset LatexCommand \index{-\/-data-loc}
8945
8946 \end_inset 
8947
8948 .
8949  If in doubt, don't specify any options and see if the resulting memory
8950  layout is appropriate, then you can adjust it.
8951 \layout Standard
8952
8953 The linker generates two files with memory allocation information.
8954  The first, with extension .map
8955 \begin_inset LatexCommand \index{<file>.map}
8956
8957 \end_inset 
8958
8959  shows all the variables and segments.
8960  The second with extension .mem
8961 \begin_inset LatexCommand \index{<file>.mem}
8962
8963 \end_inset 
8964
8965  shows the final memory layout.
8966  The linker will complain either if memory segments overlap, there is not
8967  enough memory, or there is not enough space for stack.
8968  If you get any linking warnings and/or errors related to stack or segments
8969  allocation, take a look at either the .map or .mem files to find out what
8970  the problem is.
8971  The .mem file may even suggest a solution to the problem.
8972 \layout Subsection
8973
8974 Z80/Z180 Storage Class
8975 \begin_inset LatexCommand \index{Storage class}
8976
8977 \end_inset 
8978
8979  Language Extensions
8980 \layout Subsubsection
8981
8982 sfr
8983 \begin_inset LatexCommand \index{sfr}
8984
8985 \end_inset 
8986
8987  (in/out to 8-bit addresses)
8988 \layout Standard
8989
8990 The Z80
8991 \begin_inset LatexCommand \index{Z80}
8992
8993 \end_inset 
8994
8995  family has separate address spaces for memory and 
8996 \emph on 
8997 i
8998 \emph default 
8999 nput/
9000 \emph on 
9001 o
9002 \emph default 
9003 utput memory.
9004  I/O memory
9005 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
9006
9007 \end_inset 
9008
9009  is accessed with special instructions, e.g.:
9010 \layout Verse
9011
9012
9013 \family typewriter 
9014 sfr at 0x78 IoPort;\SpecialChar ~
9015 \SpecialChar ~
9016 /* define a var in I/O space at 78h called IoPort */
9017  
9018 \layout Standard
9019
9020 Writing 0x01 to this variable generates the assembly code:
9021 \layout Verse
9022
9023
9024 \family typewriter 
9025 3E 01\SpecialChar ~
9026 \SpecialChar ~
9027 \SpecialChar ~
9028 \SpecialChar ~
9029 \SpecialChar ~
9030 \SpecialChar ~
9031 ld a,#0x01
9032 \newline 
9033 D3 78\SpecialChar ~
9034 \SpecialChar ~
9035 \SpecialChar ~
9036 \SpecialChar ~
9037 \SpecialChar ~
9038 \SpecialChar ~
9039 out (_IoPort),a 
9040 \layout Subsubsection
9041
9042 banked sfr
9043 \begin_inset LatexCommand \index{sfr}
9044
9045 \end_inset 
9046
9047  (in/out to 16-bit addresses)
9048 \layout Standard
9049
9050 The keyword 
9051 \emph on 
9052 banked
9053 \emph default 
9054  is used to support 16 bit addresses in I/O memory e.g.:
9055 \layout Verse
9056
9057
9058 \family typewriter 
9059 sfr banked at
9060 \begin_inset LatexCommand \index{at}
9061
9062 \end_inset 
9063
9064  0x123 IoPort; 
9065 \layout Standard
9066
9067 Writing 0x01 to this variable generates the assembly code:
9068 \layout Verse
9069
9070
9071 \family typewriter 
9072 01 23 01\SpecialChar ~
9073 \SpecialChar ~
9074 \SpecialChar ~
9075 ld bc,#_IoPort
9076 \newline 
9077 3E 01\SpecialChar ~
9078 \SpecialChar ~
9079 \SpecialChar ~
9080 \SpecialChar ~
9081 \SpecialChar ~
9082 \SpecialChar ~
9083 ld a,#0x01 
9084 \newline 
9085 ED 79\SpecialChar ~
9086 \SpecialChar ~
9087 \SpecialChar ~
9088 \SpecialChar ~
9089 \SpecialChar ~
9090 \SpecialChar ~
9091 out (c),a 
9092 \layout Subsubsection
9093
9094 sfr
9095 \begin_inset LatexCommand \index{sfr}
9096
9097 \end_inset 
9098
9099  (in0/out0 to 8 bit addresses on Z180
9100 \begin_inset LatexCommand \index{Z180}
9101
9102 \end_inset 
9103
9104 /HD64180
9105 \begin_inset LatexCommand \index{HD64180}
9106
9107 \end_inset 
9108
9109 )
9110 \layout Standard
9111
9112 The compiler option -
9113 \begin_inset ERT
9114 status Collapsed
9115
9116 \layout Standard
9117
9118 \backslash 
9119 /
9120 \end_inset 
9121
9122 -portmode=180 (80) and a compiler #pragma\SpecialChar ~
9123 portmode
9124 \begin_inset LatexCommand \index{\#pragma portmode}
9125
9126 \end_inset 
9127
9128 =z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
9129 ns 
9130 \family typewriter 
9131 in0/out0
9132 \family default 
9133  instead of 
9134 \family typewriter 
9135 in/out
9136 \family default 
9137 .
9138  If you include the file z180.h this will be set automatically.
9139 \layout Subsection
9140
9141 HC08 Storage Class
9142 \begin_inset LatexCommand \index{Storage class}
9143
9144 \end_inset 
9145
9146  Language Extensions
9147 \layout Subsubsection
9148
9149 data
9150 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9151
9152 \end_inset 
9153
9154
9155 \layout Standard
9156
9157 The data storage class declares a variable that resides in the first 256
9158  bytes of memory (the direct page).
9159  The HC08 is most efficient at accessing variables (especially pointers)
9160  stored here.
9161 \layout Subsubsection
9162
9163 xdata
9164 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9165
9166 \end_inset 
9167
9168
9169 \layout Standard
9170
9171 The xdata storage class declares a variable that can reside anywhere in
9172  memory.
9173  This is the default if no storage class is specified.
9174  
9175 \layout Section
9176
9177 Absolute Addressing
9178 \begin_inset LatexCommand \index{Absolute addressing}
9179
9180 \end_inset 
9181
9182
9183 \layout Standard
9184
9185 Data items can be assigned an absolute address with the 
9186 \emph on 
9187 at
9188 \begin_inset LatexCommand \index{at}
9189
9190 \end_inset 
9191
9192  <address>
9193 \emph default 
9194  keyword, in addition to a storage class, e.g.:
9195 \layout Verse
9196
9197
9198 \family typewriter 
9199 xdata
9200 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9201
9202 \end_inset 
9203
9204  at
9205 \begin_inset LatexCommand \index{at}
9206
9207 \end_inset 
9208
9209  0x7ffe unsigned int chksum;
9210 \layout Standard
9211
9212 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
9213  of the external ram.
9214  The compiler does 
9215 \emph on 
9216 not
9217 \emph default 
9218  reserve any space for variables declared in this way (they are implemented
9219  with an equate in the assembler).
9220  Thus it is left to the programmer to make sure there are no overlaps with
9221  other variables that are declared without the absolute address.
9222  The assembler listing file (.lst
9223 \begin_inset LatexCommand \index{<file>.lst}
9224
9225 \end_inset 
9226
9227 ) and the linker output files (.rst
9228 \begin_inset LatexCommand \index{<file>.rst}
9229
9230 \end_inset 
9231
9232 ) and (.map
9233 \begin_inset LatexCommand \index{<file>.map}
9234
9235 \end_inset 
9236
9237 ) are good places to look for such overlaps.
9238  Variables with an absolute address are 
9239 \emph on 
9240 not
9241 \emph default 
9242  initialized
9243 \begin_inset LatexCommand \index{Variable initialization}
9244
9245 \end_inset 
9246
9247 .
9248 \layout Standard
9249
9250 In case of memory mapped I/O devices the keyword 
9251 \emph on 
9252 volatile
9253 \emph default 
9254  has to be used to tell the compiler that accesses might not be removed:
9255 \layout Verse
9256
9257
9258 \family typewriter 
9259 volatile
9260 \begin_inset LatexCommand \index{volatile}
9261
9262 \end_inset 
9263
9264  xdata
9265 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9266
9267 \end_inset 
9268
9269  at
9270 \begin_inset LatexCommand \index{at}
9271
9272 \end_inset 
9273
9274  0x8000 unsigned char PORTA_8255;
9275 \layout Standard
9276
9277 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
9278 r) array
9279 \family typewriter 
9280 \size footnotesize 
9281
9282 \begin_inset LatexCommand \index{Aligned array}
9283
9284 \end_inset 
9285
9286
9287 \family default 
9288 \size default 
9289  starts at a block (256 byte) boundary
9290 \begin_inset LatexCommand \index{block boundary}
9291
9292 \end_inset 
9293
9294  (section 
9295 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
9296
9297 \end_inset 
9298
9299  has an example).
9300 \newline 
9301 Absolute addresses can be specified for variables in all storage classes,
9302  e.g.:
9303 \layout Verse
9304
9305
9306 \family typewriter 
9307 bit
9308 \begin_inset LatexCommand \index{bit}
9309
9310 \end_inset 
9311
9312  at
9313 \begin_inset LatexCommand \index{at}
9314
9315 \end_inset 
9316
9317  0x02 bvar;
9318 \layout Standard
9319
9320 The above example will allocate the variable at offset 0x02 in the bit-addressab
9321 le space.
9322  There is no real advantage to assigning absolute addresses to variables
9323  in this manner, unless you want strict control over all the variables allocated.
9324  One possible use would be to write hardware portable code.
9325  For example, if you have a routine that uses one or more of the microcontroller
9326  I/O pins, and such pins are different for two different hardwares, you
9327  can declare the I/O pins in your routine using:
9328 \layout Verse
9329
9330
9331 \family typewriter 
9332 extern volatile bit MOSI;\SpecialChar ~
9333 \SpecialChar ~
9334 \SpecialChar ~
9335 \SpecialChar ~
9336 /* master out, slave in */
9337 \newline 
9338 extern volatile bit MISO;\SpecialChar ~
9339 \SpecialChar ~
9340 \SpecialChar ~
9341 \SpecialChar ~
9342 /* master in, slave out */
9343 \newline 
9344 extern volatile bit MCLK;\SpecialChar ~
9345 \SpecialChar ~
9346 \SpecialChar ~
9347 \SpecialChar ~
9348 /* master clock */
9349 \newline 
9350
9351 \newline 
9352 /* Input and Output of a byte on a 3-wire serial bus.
9353 \newline 
9354 \SpecialChar ~
9355 \SpecialChar ~
9356 \SpecialChar ~
9357 If needed adapt polarity of clock, polarity of data and bit order
9358 \newline 
9359 \SpecialChar ~
9360 */
9361 \newline 
9362 unsigned char spi_io(unsigned char out_byte) 
9363 \newline 
9364
9365 \newline 
9366 \SpecialChar ~
9367 \SpecialChar ~
9368 \SpecialChar ~
9369 \SpecialChar ~
9370 unsigned char i=8;
9371 \newline 
9372 \SpecialChar ~
9373 \SpecialChar ~
9374 \SpecialChar ~
9375 \SpecialChar ~
9376 do { 
9377 \newline 
9378 \SpecialChar ~
9379 \SpecialChar ~
9380 \SpecialChar ~
9381 \SpecialChar ~
9382 \SpecialChar ~
9383 \SpecialChar ~
9384 \SpecialChar ~
9385 \SpecialChar ~
9386 MOSI = out_byte & 0x80; 
9387 \newline 
9388 \SpecialChar ~
9389 \SpecialChar ~
9390 \SpecialChar ~
9391 \SpecialChar ~
9392 \SpecialChar ~
9393 \SpecialChar ~
9394 \SpecialChar ~
9395 \SpecialChar ~
9396 out_byte <<= 1;
9397 \newline 
9398 \SpecialChar ~
9399 \SpecialChar ~
9400 \SpecialChar ~
9401 \SpecialChar ~
9402 \SpecialChar ~
9403 \SpecialChar ~
9404 \SpecialChar ~
9405 \SpecialChar ~
9406 MCLK = 1; 
9407 \newline 
9408 \SpecialChar ~
9409 \SpecialChar ~
9410 \SpecialChar ~
9411 \SpecialChar ~
9412 \SpecialChar ~
9413 \SpecialChar ~
9414 \SpecialChar ~
9415 \SpecialChar ~
9416 /* _asm nop _endasm; */\SpecialChar ~
9417 \SpecialChar ~
9418 \SpecialChar ~
9419 \SpecialChar ~
9420 \SpecialChar ~
9421 \SpecialChar ~
9422 \SpecialChar ~
9423 \SpecialChar ~
9424 /* for slow peripherals */
9425 \newline 
9426 \SpecialChar ~
9427 \SpecialChar ~
9428 \SpecialChar ~
9429 \SpecialChar ~
9430 \SpecialChar ~
9431 \SpecialChar ~
9432 \SpecialChar ~
9433 \SpecialChar ~
9434 if(MISO) 
9435 \newline 
9436 \SpecialChar ~
9437 \SpecialChar ~
9438 \SpecialChar ~
9439 \SpecialChar ~
9440 \SpecialChar ~
9441 \SpecialChar ~
9442 \SpecialChar ~
9443 \SpecialChar ~
9444 \SpecialChar ~
9445 \SpecialChar ~
9446 \SpecialChar ~
9447 \SpecialChar ~
9448 out_byte += 1; 
9449 \newline 
9450 \SpecialChar ~
9451 \SpecialChar ~
9452 \SpecialChar ~
9453 \SpecialChar ~
9454 \SpecialChar ~
9455 \SpecialChar ~
9456 \SpecialChar ~
9457 \SpecialChar ~
9458 MCLK = 0; 
9459 \newline 
9460 \SpecialChar ~
9461 \SpecialChar ~
9462 \SpecialChar ~
9463 \SpecialChar ~
9464 } while(--i);
9465 \newline 
9466 \SpecialChar ~
9467 \SpecialChar ~
9468 \SpecialChar ~
9469 \SpecialChar ~
9470 return out_byte; 
9471 \newline 
9472 }
9473 \layout Standard
9474
9475 Then, someplace in the code for the first hardware you would use
9476 \layout Verse
9477
9478
9479 \family typewriter 
9480 bit at 0x80 MOSI;\SpecialChar ~
9481 \SpecialChar ~
9482 \SpecialChar ~
9483 \SpecialChar ~
9484 /* I/O port 0, bit 0 */
9485 \newline 
9486 bit at 0x81 MISO;\SpecialChar ~
9487 \SpecialChar ~
9488 \SpecialChar ~
9489 \SpecialChar ~
9490 /* I/O port 0, bit 1 */
9491 \newline 
9492 bit at 0x82 MCLK;\SpecialChar ~
9493 \SpecialChar ~
9494 \SpecialChar ~
9495 \SpecialChar ~
9496 /* I/O port 0, bit 2 */
9497 \layout Standard
9498
9499 Similarly, for the second hardware you would use
9500 \layout Verse
9501
9502
9503 \family typewriter 
9504 bit at 0x83 MOSI;\SpecialChar ~
9505 \SpecialChar ~
9506 \SpecialChar ~
9507 \SpecialChar ~
9508 /* I/O port 0, bit 3 */
9509 \newline 
9510 bit at 0x91 MISO;\SpecialChar ~
9511 \SpecialChar ~
9512 \SpecialChar ~
9513 \SpecialChar ~
9514 /* I/O port 1, bit 1 */
9515 \newline 
9516 bit
9517 \begin_inset LatexCommand \index{bit}
9518
9519 \end_inset 
9520
9521  at 0x92 MCLK;\SpecialChar ~
9522 \SpecialChar ~
9523 \SpecialChar ~
9524 \SpecialChar ~
9525 /* I/O port 1, bit 2 */
9526 \layout Standard
9527
9528 and you can use the same hardware dependent routine without changes, as
9529  for example in a library.
9530  This is somehow similar to sbit, but only one absolute address has to be
9531  specified in the whole project.
9532 \layout Section
9533
9534 Parameters
9535 \begin_inset LatexCommand \index{Parameters}
9536
9537 \end_inset 
9538
9539
9540 \begin_inset LatexCommand \index{function parameter}
9541
9542 \end_inset 
9543
9544  & Local Variables
9545 \begin_inset LatexCommand \index{local variables}
9546
9547 \end_inset 
9548
9549
9550 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
9551
9552 \end_inset 
9553
9554
9555 \layout Standard
9556
9557 Automatic (local) variables and parameters to functions can either be placed
9558  on the stack or in data-space.
9559  The default action of the compiler is to place these variables in the internal
9560  RAM (for small model) or external RAM (for large model).
9561  This in fact makes them similar to 
9562 \emph on 
9563 static
9564 \begin_inset LatexCommand \index{static}
9565
9566 \end_inset 
9567
9568
9569 \emph default 
9570  so by default functions are non-reentrant
9571 \begin_inset LatexCommand \index{reentrant}
9572
9573 \end_inset 
9574
9575 .
9576  
9577 \newline 
9578
9579 \newline 
9580 They can be placed on the stack
9581 \begin_inset LatexCommand \index{stack}
9582
9583 \end_inset 
9584
9585  by using the
9586 \emph on 
9587  -
9588 \begin_inset ERT
9589 status Collapsed
9590
9591 \layout Standard
9592
9593 \backslash 
9594 /
9595 \end_inset 
9596
9597 -stack-auto
9598 \begin_inset LatexCommand \index{-\/-stack-auto}
9599
9600 \end_inset 
9601
9602
9603 \emph default 
9604  option, by using 
9605 \emph on 
9606 #pragma\SpecialChar ~
9607 stackauto
9608 \emph default 
9609
9610 \begin_inset LatexCommand \index{\#pragma stackauto}
9611
9612 \end_inset 
9613
9614  or by using the 
9615 \emph on 
9616 reentrant
9617 \begin_inset LatexCommand \index{reentrant}
9618
9619 \end_inset 
9620
9621
9622 \emph default 
9623  keyword in the function declaration, e.g.:
9624 \layout Verse
9625
9626
9627 \family typewriter 
9628 unsigned char foo(char i) reentrant 
9629 \newline 
9630
9631 \newline 
9632 \SpecialChar ~
9633 \SpecialChar ~
9634 \SpecialChar ~
9635 \SpecialChar ~
9636 ...
9637  
9638 \newline 
9639 }
9640 \layout Standard
9641
9642 Since stack space on 8051 is limited, the 
9643 \emph on 
9644 reentrant 
9645 \emph default 
9646 keyword or the
9647 \emph on 
9648  -
9649 \begin_inset ERT
9650 status Collapsed
9651
9652 \layout Standard
9653
9654 \backslash 
9655 /
9656 \end_inset 
9657
9658 -stack-auto
9659 \emph default 
9660  option should be used sparingly.
9661  Note that the reentrant keyword just means that the parameters & local
9662  variables will be allocated to the stack, it 
9663 \emph on 
9664 does not
9665 \emph default 
9666  mean that the function is register bank
9667 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
9668
9669 \end_inset 
9670
9671  independent.
9672 \newline 
9673
9674 \newline 
9675 Local variables
9676 \begin_inset LatexCommand \index{local variables}
9677
9678 \end_inset 
9679
9680  can be assigned storage classes and absolute
9681 \begin_inset LatexCommand \index{Absolute addressing}
9682
9683 \end_inset 
9684
9685  addresses, e.g.: 
9686 \layout Verse
9687
9688
9689 \family typewriter 
9690 unsigned char foo() 
9691 \newline 
9692 {
9693 \newline 
9694 \SpecialChar ~
9695 \SpecialChar ~
9696 \SpecialChar ~
9697 \SpecialChar ~
9698 xdata unsigned char i;
9699 \newline 
9700 \SpecialChar ~
9701 \SpecialChar ~
9702 \SpecialChar ~
9703 \SpecialChar ~
9704 bit bvar;
9705 \newline 
9706 \SpecialChar ~
9707 \SpecialChar ~
9708 \SpecialChar ~
9709 \SpecialChar ~
9710 data at
9711 \begin_inset LatexCommand \index{at}
9712
9713 \end_inset 
9714
9715  0x31 unsigned char j;
9716 \newline 
9717 \SpecialChar ~
9718 \SpecialChar ~
9719 \SpecialChar ~
9720 \SpecialChar ~
9721 ...
9722  
9723 \newline 
9724 }
9725 \layout Standard
9726
9727 In the above example the variable 
9728 \emph on 
9729 i
9730 \emph default 
9731  will be allocated in the external ram, 
9732 \emph on 
9733 bvar
9734 \emph default 
9735  in bit addressable space and
9736 \emph on 
9737  j
9738 \emph default 
9739  in internal ram.
9740  When compiled with 
9741 \emph on 
9742 -
9743 \begin_inset ERT
9744 status Collapsed
9745
9746 \layout Standard
9747
9748 \backslash 
9749 /
9750 \end_inset 
9751
9752 -stack-auto
9753 \emph default 
9754  or when a function is declared as 
9755 \emph on 
9756 reentrant
9757 \emph default 
9758  this should only be done for static variables.
9759 \layout Standard
9760
9761 Parameters
9762 \begin_inset LatexCommand \index{function parameter}
9763
9764 \end_inset 
9765
9766  however are not allowed any storage class
9767 \begin_inset LatexCommand \index{Storage class}
9768
9769 \end_inset 
9770
9771 , (storage classes for parameters will be ignored), their allocation is
9772  governed by the memory model in use, and the reentrancy options.
9773 \layout Section
9774
9775 Overlaying
9776 \begin_inset LatexCommand \label{sub:Overlaying}
9777
9778 \end_inset 
9779
9780
9781 \begin_inset LatexCommand \index{Overlaying}
9782
9783 \end_inset 
9784
9785
9786 \layout Standard
9787
9788 For non-reentrant
9789 \begin_inset LatexCommand \index{reentrant}
9790
9791 \end_inset 
9792
9793  functions SDCC will try to reduce internal ram space usage by overlaying
9794  parameters and local variables of a function (if possible).
9795  Parameters and local variables
9796 \begin_inset LatexCommand \index{local variables}
9797
9798 \end_inset 
9799
9800  of a function will be allocated to an overlayable segment if the function
9801  has 
9802 \emph on 
9803 no other function calls and the function is non-reentrant and the memory
9804  model
9805 \begin_inset LatexCommand \index{Memory model}
9806
9807 \end_inset 
9808
9809  is small.
9810
9811 \emph default 
9812  If an explicit storage class
9813 \begin_inset LatexCommand \index{Storage class}
9814
9815 \end_inset 
9816
9817  is specified for a local variable, it will NOT be overlayed.
9818 \layout Standard
9819
9820 Note that the compiler (not the linkage editor) makes the decision for overlayin
9821 g the data items.
9822  Functions that are called from an interrupt service routine should be preceded
9823  by a #pragma\SpecialChar ~
9824 nooverlay
9825 \begin_inset LatexCommand \index{\#pragma nooverlay}
9826
9827 \end_inset 
9828
9829  if they are not reentrant.
9830 \layout Standard
9831
9832 Also note that the compiler does not do any processing of inline assembler
9833  code, so the compiler might incorrectly assign local variables and parameters
9834  of a function into the overlay segment if the inline assembler code calls
9835  other c-functions that might use the overlay.
9836  In that case the #pragma\SpecialChar ~
9837 nooverlay should be used.
9838 \layout Standard
9839
9840 Parameters and local variables of functions that contain 16 or 32 bit multiplica
9841 tion
9842 \begin_inset LatexCommand \index{Multiplication}
9843
9844 \end_inset 
9845
9846  or division
9847 \begin_inset LatexCommand \index{Division}
9848
9849 \end_inset 
9850
9851  will NOT be overlayed since these are implemented using external functions,
9852  e.g.:
9853 \layout Verse
9854
9855
9856 \family typewriter 
9857 #pragma save 
9858 \newline 
9859 #pragma nooverlay
9860 \begin_inset LatexCommand \index{\#pragma nooverlay}
9861
9862 \end_inset 
9863
9864  
9865 \newline 
9866 void set_error(unsigned char errcd) 
9867 \newline 
9868 {
9869 \newline 
9870 \SpecialChar ~
9871 \SpecialChar ~
9872 \SpecialChar ~
9873 \SpecialChar ~
9874 P3 = errcd;
9875 \newline 
9876
9877 \newline 
9878 #pragma restore 
9879 \newline 
9880
9881 \newline 
9882 void some_isr () interrupt
9883 \begin_inset LatexCommand \index{interrupt}
9884
9885 \end_inset 
9886
9887  2
9888 \newline 
9889 {
9890 \newline 
9891 \SpecialChar ~
9892 \SpecialChar ~
9893 \SpecialChar ~
9894 \SpecialChar ~
9895 ...
9896 \newline 
9897 \SpecialChar ~
9898 \SpecialChar ~
9899 \SpecialChar ~
9900 \SpecialChar ~
9901 set_error(10);
9902 \newline 
9903 \SpecialChar ~
9904 \SpecialChar ~
9905 \SpecialChar ~
9906 \SpecialChar ~
9907 ...
9908  
9909 \newline 
9910 }
9911 \layout Standard
9912
9913 In the above example the parameter 
9914 \emph on 
9915 errcd
9916 \emph default 
9917  for the function 
9918 \emph on 
9919 set_error
9920 \emph default 
9921  would be assigned to the overlayable segment if the #pragma\SpecialChar ~
9922 nooverlay was
9923  not present, this could cause unpredictable runtime behavior when called
9924  from an interrupt service routine.
9925  The #pragma\SpecialChar ~
9926 nooverlay ensures that the parameters and local variables for
9927  the function are NOT overlayed.
9928 \layout Section
9929
9930 Interrupt Service Routines
9931 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
9932
9933 \end_inset 
9934
9935
9936 \layout Subsection
9937
9938 General Information
9939 \layout Standard
9940
9941 SDCC allows 
9942 \emph on 
9943 i
9944 \emph default 
9945 nterrupt 
9946 \emph on 
9947 s
9948 \emph default 
9949 ervice 
9950 \emph on 
9951 r
9952 \emph default 
9953 outines to be coded in C, with some extended keywords.
9954 \layout Verse
9955
9956
9957 \family typewriter 
9958 void timer_isr (void) interrupt 1 using 1 
9959 \newline 
9960
9961 \newline 
9962 \SpecialChar ~
9963 \SpecialChar ~
9964 \SpecialChar ~
9965 \SpecialChar ~
9966 ...
9967  
9968 \newline 
9969 }
9970 \layout Standard
9971
9972 The optional number following the 
9973 \emph on 
9974 interrupt
9975 \begin_inset LatexCommand \index{interrupt}
9976
9977 \end_inset 
9978
9979
9980 \emph default 
9981  keyword is the interrupt number this routine will service.
9982  When present, the compiler will insert a call to this routine in the interrupt
9983  vector table for the interrupt number specified.
9984  If you have multiple source files in your project, interrupt service routines
9985  can be present in any of them, but a prototype of the isr MUST be present
9986  or included in the file that contains the function 
9987 \emph on 
9988 main
9989 \emph default 
9990 .
9991  The 
9992 \emph on 
9993 using
9994 \emph default 
9995  keyword can be used to tell the compiler to use the specified register
9996  bank (8051 specific) when generating code for this function.
9997  
9998 \newline 
9999
10000 \layout Standard
10001
10002 Interrupt service routines open the door for some very interesting bugs:
10003 \newline 
10004 If an interrupt service routine changes variables which are accessed by
10005  other functions these variables have to be declared 
10006 \emph on 
10007 volatile
10008 \emph default 
10009
10010 \begin_inset LatexCommand \index{volatile}
10011
10012 \end_inset 
10013
10014 .
10015  
10016 \layout Standard
10017
10018 If the access to these variables is not 
10019 \emph on 
10020 atomic
10021 \begin_inset LatexCommand \index{atomic}
10022
10023 \end_inset 
10024
10025
10026 \emph default 
10027  (i.e.
10028  the processor needs more than one instruction for the access and could
10029  be interrupted while accessing the variable) the interrupt must be disabled
10030  during the access to avoid inconsistent data.
10031  Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
10032  and should be protected by disabling interrupts.
10033  You're not automatically on the safe side if you use 8 bit variables though.
10034  We need an example here: f.e.
10035  on the 8051 the harmless looking 
10036 \begin_inset Quotes srd
10037 \end_inset 
10038
10039
10040 \family typewriter 
10041 flags\SpecialChar ~
10042 |=\SpecialChar ~
10043 0x80;
10044 \family default 
10045
10046 \begin_inset Quotes sld
10047 \end_inset 
10048
10049  is not atomic if 
10050 \family typewriter 
10051 flags
10052 \family default 
10053  resides in xdata.
10054  Setting 
10055 \begin_inset Quotes srd
10056 \end_inset 
10057
10058
10059 \family typewriter 
10060 flags\SpecialChar ~
10061 |=\SpecialChar ~
10062 0x40;
10063 \family default 
10064
10065 \begin_inset Quotes sld
10066 \end_inset 
10067
10068  from within an interrupt routine might get lost if the interrupt occurs
10069  at the wrong time.
10070  
10071 \begin_inset Quotes sld
10072 \end_inset 
10073
10074
10075 \family typewriter 
10076 counter\SpecialChar ~
10077 +=\SpecialChar ~
10078 8;
10079 \family default 
10080
10081 \begin_inset Quotes srd
10082 \end_inset 
10083
10084  is not atomic on the 8051 even if 
10085 \family typewriter 
10086 counter
10087 \family default 
10088  is located in data memory.
10089  Bugs like these are hard to reproduce and can cause a lot of trouble.
10090  
10091 \layout Standard
10092
10093 The return address and the registers used in the interrupt service routine
10094  are saved on the stack
10095 \begin_inset LatexCommand \index{stack}
10096
10097 \end_inset 
10098
10099  so there must be sufficient stack space.
10100  If there isn't variables or registers (or even the return address itself)
10101  will be corrupted.
10102  This 
10103 \emph on 
10104 stack overflow
10105 \emph default 
10106
10107 \begin_inset LatexCommand \index{stack overflow}
10108
10109 \end_inset 
10110
10111  is most likely to happen if the interrupt occurs during the 
10112 \begin_inset Quotes sld
10113 \end_inset 
10114
10115 deepest
10116 \begin_inset Quotes srd
10117 \end_inset 
10118
10119  subroutine when the stack is already in use for f.e.
10120  many return addresses.
10121 \layout Standard
10122
10123 A special note here, int (16 bit) and long (32 bit) integer division
10124 \begin_inset LatexCommand \index{Division}
10125
10126 \end_inset 
10127
10128 , multiplication
10129 \begin_inset LatexCommand \index{Multiplication}
10130
10131 \end_inset 
10132
10133  & modulus
10134 \begin_inset LatexCommand \index{Modulus}
10135
10136 \end_inset 
10137
10138  and floating-point
10139 \begin_inset LatexCommand \index{Floating point support}
10140
10141 \end_inset 
10142
10143  operations are implemented using external support routines developed in
10144  ANSI-C.
10145  If an interrupt service routine needs to do any of these operations then
10146  the support routines (as mentioned in a following section) will have to
10147  be recompiled using the
10148 \emph on 
10149  -
10150 \begin_inset ERT
10151 status Collapsed
10152
10153 \layout Standard
10154
10155 \backslash 
10156 /
10157 \end_inset 
10158
10159 -stack-auto
10160 \begin_inset LatexCommand \index{-\/-stack-auto}
10161
10162 \end_inset 
10163
10164
10165 \emph default 
10166  option and the source file will need to be compiled using the 
10167 \emph on 
10168 -
10169 \begin_inset ERT
10170 status Collapsed
10171
10172 \layout Standard
10173
10174 \backslash 
10175 /
10176 \end_inset 
10177
10178 -int-long-reent
10179 \emph default 
10180
10181 \begin_inset LatexCommand \index{-\/-int-long-reent}
10182
10183 \end_inset 
10184
10185  compiler option.
10186 \layout Standard
10187
10188 Calling other functions from an interrupt service routine is not recommended,
10189  avoid it if possible.
10190  Note that when some function is called from an interrupt service routine
10191  it should be preceded by a #pragma\SpecialChar ~
10192 nooverlay
10193 \begin_inset LatexCommand \index{\#pragma nooverlay}
10194
10195 \end_inset 
10196
10197  if it is not reentrant.
10198  Furthermore nonreentrant functions should not be called from the main program
10199  while the interrupt service routine might be active.
10200  
10201 \newline 
10202
10203 \newline 
10204 Also see section 
10205 \begin_inset LatexCommand \ref{sub:Overlaying}
10206
10207 \end_inset 
10208
10209 \SpecialChar ~
10210 about Overlaying and section 
10211 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
10212
10213 \end_inset 
10214
10215 \SpecialChar ~
10216 about Functions using private register banks.
10217 \layout Subsection
10218
10219 MCS51/DS390 Interrupt Service Routines
10220 \layout Standard
10221
10222 Interrupt numbers and the corresponding address & descriptions for the Standard
10223  8051/8052 are listed below.
10224  SDCC will automatically adjust the interrupt vector table to the maximum
10225  interrupt number specified.
10226 \newline 
10227
10228 \layout Standard
10229 \align center 
10230
10231 \begin_inset  Tabular
10232 <lyxtabular version="3" rows="7" columns="3">
10233 <features>
10234 <column alignment="center" valignment="top" leftline="true" width="0in">
10235 <column alignment="center" valignment="top" leftline="true" width="0in">
10236 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0in">
10237 <row topline="true" bottomline="true">
10238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10239 \begin_inset Text
10240
10241 \layout Standard
10242
10243 Interrupt #
10244 \end_inset 
10245 </cell>
10246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10247 \begin_inset Text
10248
10249 \layout Standard
10250
10251 Description
10252 \end_inset 
10253 </cell>
10254 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10255 \begin_inset Text
10256
10257 \layout Standard
10258
10259 Vector Address
10260 \end_inset 
10261 </cell>
10262 </row>
10263 <row topline="true">
10264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10265 \begin_inset Text
10266
10267 \layout Standard
10268
10269 0
10270 \end_inset 
10271 </cell>
10272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10273 \begin_inset Text
10274
10275 \layout Standard
10276
10277 External 0
10278 \end_inset 
10279 </cell>
10280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10281 \begin_inset Text
10282
10283 \layout Standard
10284
10285 0x0003
10286 \end_inset 
10287 </cell>
10288 </row>
10289 <row topline="true">
10290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10291 \begin_inset Text
10292
10293 \layout Standard
10294
10295 1
10296 \end_inset 
10297 </cell>
10298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10299 \begin_inset Text
10300
10301 \layout Standard
10302
10303 Timer 0
10304 \end_inset 
10305 </cell>
10306 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10307 \begin_inset Text
10308
10309 \layout Standard
10310
10311 0x000B
10312 \end_inset 
10313 </cell>
10314 </row>
10315 <row topline="true">
10316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10317 \begin_inset Text
10318
10319 \layout Standard
10320
10321 2
10322 \end_inset 
10323 </cell>
10324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10325 \begin_inset Text
10326
10327 \layout Standard
10328
10329 External 1
10330 \end_inset 
10331 </cell>
10332 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10333 \begin_inset Text
10334
10335 \layout Standard
10336
10337 0x0013
10338 \end_inset 
10339 </cell>
10340 </row>
10341 <row topline="true">
10342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10343 \begin_inset Text
10344
10345 \layout Standard
10346
10347 3
10348 \end_inset 
10349 </cell>
10350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10351 \begin_inset Text
10352
10353 \layout Standard
10354
10355 Timer 1
10356 \end_inset 
10357 </cell>
10358 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10359 \begin_inset Text
10360
10361 \layout Standard
10362
10363 0x001B
10364 \end_inset 
10365 </cell>
10366 </row>
10367 <row topline="true">
10368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10369 \begin_inset Text
10370
10371 \layout Standard
10372
10373 4
10374 \end_inset 
10375 </cell>
10376 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10377 \begin_inset Text
10378
10379 \layout Standard
10380
10381 Serial
10382 \end_inset 
10383 </cell>
10384 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10385 \begin_inset Text
10386
10387 \layout Standard
10388
10389 0x0023
10390 \end_inset 
10391 </cell>
10392 </row>
10393 <row topline="true" bottomline="true">
10394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10395 \begin_inset Text
10396
10397 \layout Standard
10398
10399 5
10400 \end_inset 
10401 </cell>
10402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10403 \begin_inset Text
10404
10405 \layout Standard
10406
10407 Timer 2 (8052)
10408 \end_inset 
10409 </cell>
10410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10411 \begin_inset Text
10412
10413 \layout Standard
10414
10415 0x002B
10416 \end_inset 
10417 </cell>
10418 </row>
10419 </lyxtabular>
10420
10421 \end_inset 
10422
10423
10424 \newline 
10425
10426 \layout Standard
10427
10428 If the interrupt service routine is defined without 
10429 \emph on 
10430 using
10431 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10432
10433 \end_inset 
10434
10435
10436 \emph default 
10437  a register bank or with register bank 0 (
10438 \emph on 
10439 using
10440 \emph default 
10441  0), the compiler will save the registers used by itself on the stack upon
10442  entry and restore them at exit, however if such an interrupt service routine
10443  calls another function then the entire register bank will be saved on the
10444  stack.
10445  This scheme may be advantageous for small interrupt service routines which
10446  have low register usage.
10447 \layout Standard
10448
10449 If the interrupt service routine is defined to be using a specific register
10450  bank then only 
10451 \emph on 
10452 a, b, dptr
10453 \emph default 
10454  & psw are saved and restored, if such an interrupt service routine calls
10455  another function (using another register bank) then the entire register
10456  bank of the called function will be saved on the stack.
10457  This scheme is recommended for larger interrupt service routines.
10458 \layout Subsection
10459
10460 HC08 Interrupt Service Routines
10461 \layout Standard
10462
10463 Since the number of interrupts available is chip specific and the interrupt
10464  vector table always ends at the last byte of memory, the interrupt numbers
10465  corresponds to the interrupt vectors in reverse order of address.
10466  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
10467  2 will use the interrupt vector at 0xfffa, and so on.
10468  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
10469  this way; instead see section 
10470 \begin_inset LatexCommand \ref{sub:Startup-Code}
10471
10472 \end_inset 
10473
10474  for details on customizing startup.
10475 \layout Subsection
10476
10477 Z80 Interrupt Service Routines
10478 \layout Standard
10479
10480 The Z80 uses several different methods for determining the correct interrupt
10481  vector depending on the hardware implementation.
10482  Therefore, SDCC ignores the optional interrupt number and does not attempt
10483  to generate an interrupt vector table.
10484 \layout Standard
10485
10486 By default, SDCC generates code for a maskable interrupt, which uses an
10487  RETI instruction to return from the interrupt.
10488  To write an interrupt handler for the non-maskable interrupt, which needs
10489  an RETN instruction instead, add the 
10490 \emph on 
10491 critical
10492 \emph default 
10493  keyword:
10494 \layout Verse
10495
10496
10497 \family typewriter 
10498 void nmi_isr (void) critical interrupt
10499 \newline 
10500
10501 \newline 
10502 \SpecialChar ~
10503 \SpecialChar ~
10504 \SpecialChar ~
10505 \SpecialChar ~
10506 ...
10507  
10508 \newline 
10509 }
10510 \layout Section
10511
10512 Enabling and Disabling Interrupts
10513 \layout Subsection
10514
10515 Critical Functions and Critical Statements
10516 \layout Standard
10517
10518 A special keyword may be associated with a block or a function declaring
10519  it as 
10520 \emph on 
10521 critical
10522 \emph default 
10523 .
10524  SDCC will generate code to disable all interrupts
10525 \begin_inset LatexCommand \index{interrupt}
10526
10527 \end_inset 
10528
10529  upon entry to a critical function and restore the interrupt enable to the
10530  previous state before returning.
10531  Nesting critical functions will need one additional byte on the stack
10532 \begin_inset LatexCommand \index{stack}
10533
10534 \end_inset 
10535
10536  for each call.
10537 \layout Verse
10538
10539
10540 \family typewriter 
10541 int foo () critical
10542 \begin_inset LatexCommand \index{critical}
10543
10544 \end_inset 
10545
10546  
10547 \newline 
10548
10549 \newline 
10550 \SpecialChar ~
10551 \SpecialChar ~
10552 \SpecialChar ~
10553 \SpecialChar ~
10554 ...
10555  
10556 \newline 
10557 \SpecialChar ~
10558 \SpecialChar ~
10559 \SpecialChar ~
10560 \SpecialChar ~
10561 ...
10562  
10563 \newline 
10564 }
10565 \layout Standard
10566
10567 The critical attribute maybe used with other attributes like 
10568 \emph on 
10569 reentrant.
10570 \emph default 
10571
10572 \newline 
10573 The keyword 
10574 \emph on 
10575 critical
10576 \emph default 
10577  may also be used to disable interrupts more locally:
10578 \layout Verse
10579
10580
10581 \family typewriter 
10582 critical{ i++; }
10583 \layout Standard
10584
10585 More than one statement could have been included in the block.
10586 \layout Subsection
10587
10588 Enabling and Disabling Interrupts directly
10589 \layout Standard
10590
10591 Interrupts
10592 \begin_inset LatexCommand \index{interrupt}
10593
10594 \end_inset 
10595
10596  can also be disabled and enabled directly (8051):
10597 \layout Verse
10598
10599
10600 \family typewriter 
10601 EA = 0;\SpecialChar ~
10602 \SpecialChar ~
10603 \SpecialChar ~
10604 \SpecialChar ~
10605 \SpecialChar ~
10606 \SpecialChar ~
10607 \SpecialChar ~
10608 \SpecialChar ~
10609 \SpecialChar ~
10610 \SpecialChar ~
10611 \SpecialChar ~
10612 \SpecialChar ~
10613 or:\SpecialChar ~
10614 \SpecialChar ~
10615 \SpecialChar ~
10616 \SpecialChar ~
10617 \SpecialChar ~
10618 \SpecialChar ~
10619 \SpecialChar ~
10620 \SpecialChar ~
10621 \SpecialChar ~
10622 \SpecialChar ~
10623 \SpecialChar ~
10624 EA_SAVE = EA;
10625 \layout Verse
10626
10627
10628 \family typewriter 
10629 ...\SpecialChar ~
10630 \SpecialChar ~
10631 \SpecialChar ~
10632 \SpecialChar ~
10633 \SpecialChar ~
10634 \SpecialChar ~
10635 \SpecialChar ~
10636 \SpecialChar ~
10637 \SpecialChar ~
10638 \SpecialChar ~
10639 \SpecialChar ~
10640 \SpecialChar ~
10641 \SpecialChar ~
10642 \SpecialChar ~
10643 \SpecialChar ~
10644 \SpecialChar ~
10645 \SpecialChar ~
10646 \SpecialChar ~
10647 \SpecialChar ~
10648 \SpecialChar ~
10649 \SpecialChar ~
10650 \SpecialChar ~
10651 \SpecialChar ~
10652 \SpecialChar ~
10653 \SpecialChar ~
10654 \SpecialChar ~
10655 \SpecialChar ~
10656 \SpecialChar ~
10657 \SpecialChar ~
10658 \SpecialChar ~
10659 EA = 0;
10660 \layout Verse
10661
10662
10663 \family typewriter 
10664 EA = 1;\SpecialChar ~
10665 \SpecialChar ~
10666 \SpecialChar ~
10667 \SpecialChar ~
10668 \SpecialChar ~
10669 \SpecialChar ~
10670 \SpecialChar ~
10671 \SpecialChar ~
10672 \SpecialChar ~
10673 \SpecialChar ~
10674 \SpecialChar ~
10675 \SpecialChar ~
10676 \SpecialChar ~
10677 \SpecialChar ~
10678 \SpecialChar ~
10679 \SpecialChar ~
10680 \SpecialChar ~
10681 \SpecialChar ~
10682 \SpecialChar ~
10683 \SpecialChar ~
10684 \SpecialChar ~
10685 \SpecialChar ~
10686 \SpecialChar ~
10687 \SpecialChar ~
10688 \SpecialChar ~
10689 \SpecialChar ~
10690 ...
10691 \layout Verse
10692
10693
10694 \family typewriter 
10695 \SpecialChar ~
10696 \SpecialChar ~
10697 \SpecialChar ~
10698 \SpecialChar ~
10699 \SpecialChar ~
10700 \SpecialChar ~
10701 \SpecialChar ~
10702 \SpecialChar ~
10703 \SpecialChar ~
10704 \SpecialChar ~
10705 \SpecialChar ~
10706 \SpecialChar ~
10707 \SpecialChar ~
10708 \SpecialChar ~
10709 \SpecialChar ~
10710 \SpecialChar ~
10711 \SpecialChar ~
10712 \SpecialChar ~
10713 \SpecialChar ~
10714 \SpecialChar ~
10715 \SpecialChar ~
10716 \SpecialChar ~
10717 \SpecialChar ~
10718 \SpecialChar ~
10719 \SpecialChar ~
10720 \SpecialChar ~
10721 \SpecialChar ~
10722 \SpecialChar ~
10723 \SpecialChar ~
10724 \SpecialChar ~
10725 \SpecialChar ~
10726 \SpecialChar ~
10727 \SpecialChar ~
10728 EA = EA_SAVE;
10729 \layout Standard
10730
10731 On other architectures which have seperate opcodes for enabling and disabling
10732  interrupts you might want to make use of defines with inline assembly
10733 \begin_inset LatexCommand \index{Assembler routines}
10734
10735 \end_inset 
10736
10737  (HC08):
10738 \layout Verse
10739
10740
10741 \family typewriter 
10742 #define CLI _asm
10743 \begin_inset LatexCommand \index{\_asm}
10744
10745 \end_inset 
10746
10747 \SpecialChar ~
10748 \SpecialChar ~
10749 cli\SpecialChar ~
10750 \SpecialChar ~
10751 _endasm
10752 \begin_inset LatexCommand \index{\_endasm}
10753
10754 \end_inset 
10755
10756
10757 \layout Verse
10758
10759
10760 \family typewriter 
10761 #define SEI _asm\SpecialChar ~
10762 \SpecialChar ~
10763 sei\SpecialChar ~
10764 \SpecialChar ~
10765 _endasm; 
10766 \layout Verse
10767
10768
10769 \family typewriter 
10770 ...
10771 \layout Standard
10772
10773 Note: it is sometimes sufficient to disable only a specific interrupt source
10774  like f.e.
10775  a timer or serial interrupt by manipulating an 
10776 \emph on 
10777 interrupt mask
10778 \begin_inset LatexCommand \index{interrupt mask}
10779
10780 \end_inset 
10781
10782
10783 \emph default 
10784  register.
10785  
10786 \layout Standard
10787
10788 Usually the time during which interrupts are disabled should be kept as
10789  short as possible.
10790  This minimizes both 
10791 \emph on 
10792 interrupt latency
10793 \emph default 
10794
10795 \begin_inset LatexCommand \index{interrupt latency}
10796
10797 \end_inset 
10798
10799  (the time between the occurrence of the interrupt and the execution of
10800  the first code in the interrupt routine) and 
10801 \emph on 
10802 interrupt jitter
10803 \emph default 
10804
10805 \begin_inset LatexCommand \index{interrupt jitter}
10806
10807 \end_inset 
10808
10809  (the difference between the shortest and the longest interrupt latency).
10810  These really are something different, f.e.
10811  a serial interrupt has to be served before its buffer overruns so it cares
10812  for the maximum interrupt latency, whereas it does not care about jitter.
10813  On a loudspeaker driven via a digital to analog converter which is fed
10814  by an interrupt a latency of a few milliseconds might be tolerable, whereas
10815  a much smaller jitter will be very audible.
10816 \layout Standard
10817
10818 You can reenable interrupts within an interrupt routine and on some architecture
10819 s you can make use of two (or more) levels of 
10820 \emph on 
10821 interrupt priorities
10822 \emph default 
10823
10824 \begin_inset LatexCommand \index{interrupt priority}
10825
10826 \end_inset 
10827
10828 .
10829  On some architectures which don't support interrupt priorities these can
10830  be implemented by manipulating the interrupt mask and reenabling interrupts
10831  within the interrupt routine.
10832  Check there is sufficient space on the stack
10833 \begin_inset LatexCommand \index{stack}
10834
10835 \end_inset 
10836
10837  and don't add complexity unless you have to.
10838  
10839 \layout Subsection
10840
10841 Semaphore
10842 \begin_inset LatexCommand \index{semaphore}
10843
10844 \end_inset 
10845
10846  locking (mcs51/ds390)
10847 \layout Standard
10848
10849 Some architectures (mcs51/ds390) have an atomic
10850 \begin_inset LatexCommand \index{atomic}
10851
10852 \end_inset 
10853
10854  bit test and
10855 \emph on 
10856  
10857 \emph default 
10858 clear
10859 \emph on 
10860  
10861 \emph default 
10862 instruction.
10863  These type of instructions are typically used in preemptive multitasking
10864  systems, where a routine f.e.
10865  claims the use of a data structure ('acquires a lock
10866 \begin_inset LatexCommand \index{lock}
10867
10868 \end_inset 
10869
10870  on it'), makes some modifications and then releases the lock when the data
10871  structure is consistent again.
10872  The instruction may also be used if interrupt and non-interrupt code have
10873  to compete for a resource.
10874  With the atomic bit test and clear instruction interrupts
10875 \begin_inset LatexCommand \index{interrupt}
10876
10877 \end_inset 
10878
10879  don't have to be disabled for the locking operation.
10880  
10881 \layout Standard
10882
10883 SDCC generates this instruction if the source follows this pattern:
10884 \layout Verse
10885
10886
10887 \family typewriter 
10888 volatile bit resource_is_free; 
10889 \newline 
10890
10891 \newline 
10892 if (resource_is_free) 
10893 \newline 
10894 \SpecialChar ~
10895 \SpecialChar ~
10896
10897 \newline 
10898 \SpecialChar ~
10899 \SpecialChar ~
10900 \SpecialChar ~
10901 \SpecialChar ~
10902 resource_is_free=0; 
10903 \newline 
10904 \SpecialChar ~
10905 \SpecialChar ~
10906 \SpecialChar ~
10907 \SpecialChar ~
10908 ...
10909  
10910 \newline 
10911 \SpecialChar ~
10912 \SpecialChar ~
10913 \SpecialChar ~
10914 \SpecialChar ~
10915 resource_is_free=1;
10916 \newline 
10917 \SpecialChar ~
10918 \SpecialChar ~
10919
10920 \layout Standard
10921
10922 Note, mcs51 and ds390 support only an atomic
10923 \begin_inset LatexCommand \index{atomic}
10924
10925 \end_inset 
10926
10927  bit test and 
10928 \emph on 
10929 clear
10930 \emph default 
10931  instruction (as opposed to atomic bit test and 
10932 \emph on 
10933 set).
10934 \layout Section
10935
10936 Functions using private register banks
10937 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
10938
10939 \end_inset 
10940
10941  (mcs51/ds390)
10942 \layout Standard
10943
10944 Some architectures have support for quickly changing register sets.
10945  SDCC supports this feature with the 
10946 \emph on 
10947 using
10948 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10949
10950 \end_inset 
10951
10952
10953 \emph default 
10954  attribute (which tells the compiler to use a register bank
10955 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10956
10957 \end_inset 
10958
10959  other than the default bank zero).
10960  It should only be applied to 
10961 \emph on 
10962 interrupt
10963 \begin_inset LatexCommand \index{interrupt}
10964
10965 \end_inset 
10966
10967
10968 \emph default 
10969  functions (see footnote below).
10970  This will in most circumstances make the generated ISR code more efficient
10971  since it will not have to save registers on the stack.
10972 \layout Standard
10973
10974 The 
10975 \emph on 
10976 using
10977 \emph default 
10978  attribute will have no effect on the generated code for a 
10979 \emph on 
10980 non-interrupt
10981 \emph default 
10982  function (but may occasionally be useful anyway
10983 \begin_inset Foot
10984 collapsed false
10985
10986 \layout Standard
10987
10988 possible exception: if a function is called ONLY from 'interrupt' functions
10989  using a particular bank, it can be declared with the same 'using' attribute
10990  as the calling 'interrupt' functions.
10991  For instance, if you have several ISRs using bank one, and all of them
10992  call memcpy(), it might make sense to create a specialized version of memcpy()
10993  'using 1', since this would prevent the ISR from having to save bank zero
10994  to the stack on entry and switch to bank zero before calling the function
10995 \end_inset 
10996
10997 ).
10998 \newline 
10999
11000 \emph on 
11001 (pending: I don't think this has been done yet)
11002 \layout Standard
11003
11004 An 
11005 \emph on 
11006 interrupt
11007 \emph default 
11008  function using a non-zero bank will assume that it can trash that register
11009  bank, and will not save it.
11010  Since high-priority interrupts
11011 \begin_inset LatexCommand \index{interrupt priority}
11012
11013 \end_inset 
11014
11015  can interrupt low-priority ones on the 8051 and friends, this means that
11016  if a high-priority ISR 
11017 \emph on 
11018 using
11019 \emph default 
11020  a particular bank occurs while processing a low-priority ISR 
11021 \emph on 
11022 using
11023 \emph default 
11024  the same bank, terrible and bad things can happen.
11025  To prevent this, no single register bank should be 
11026 \emph on 
11027 used
11028 \emph default 
11029  by both a high priority and a low priority ISR.
11030  This is probably most easily done by having all high priority ISRs use
11031  one bank and all low priority ISRs use another.
11032  If you have an ISR which can change priority at runtime, you're on your
11033  own: I suggest using the default bank zero and taking the small performance
11034  hit.
11035 \layout Standard
11036
11037 It is most efficient if your ISR calls no other functions.
11038  If your ISR must call other functions, it is most efficient if those functions
11039  use the same bank as the ISR (see note 1 below); the next best is if the
11040  called functions use bank zero.
11041  It is very inefficient to call a function using a different, non-zero bank
11042  from an ISR.
11043  
11044 \layout Section
11045
11046 Startup Code
11047 \begin_inset LatexCommand \label{sub:Startup-Code}
11048
11049 \end_inset 
11050
11051
11052 \begin_inset LatexCommand \index{Startup code}
11053
11054 \end_inset 
11055
11056
11057 \layout Subsection
11058
11059 MCS51/DS390 Startup Code
11060 \layout Standard
11061
11062 The compiler inserts a call to the C routine 
11063 \emph on 
11064 _sdcc_external_startup()
11065 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
11066
11067 \end_inset 
11068
11069
11070 \series bold 
11071 \emph default 
11072  
11073 \series default 
11074 at the start of the CODE area.
11075  This routine is in the runtime library
11076 \begin_inset LatexCommand \index{Runtime library}
11077
11078 \end_inset 
11079
11080 .
11081  By default this routine returns 0, if this routine returns a non-zero value,
11082  the static & global variable initialization will be skipped and the function
11083  main will be invoked.
11084  Otherwise static & global variables will be initialized before the function
11085  main is invoked.
11086  You could add a 
11087 \emph on 
11088 _sdcc_external_startup()
11089 \emph default 
11090  routine to your program to override the default if you need to setup hardware
11091  or perform some other critical operation prior to static & global variable
11092  initialization.
11093  On some mcs51 variants xdata has to be explicitly enabled before it can
11094  be accessed or if the watchdog needs to be disabled, this is the place
11095  to do it.
11096  The startup code clears all internal data memory, 256 bytes by default,
11097  but from 0 to n-1 if 
11098 \emph on 
11099 -
11100 \begin_inset ERT
11101 status Collapsed
11102
11103 \layout Standard
11104
11105 \backslash 
11106 /
11107 \end_inset 
11108
11109 -iram-size
11110 \begin_inset LatexCommand \index{-\/-iram-size}
11111
11112 \end_inset 
11113
11114 n
11115 \emph default 
11116  is used.
11117  (recommended for Chipcon CC1010).
11118 \layout Standard
11119
11120 See also the compiler option 
11121 \emph on 
11122 -
11123 \begin_inset ERT
11124 status Collapsed
11125
11126 \layout Standard
11127
11128 \backslash 
11129 /
11130 \end_inset 
11131
11132 -no-xinit
11133 \emph default 
11134 -
11135 \emph on 
11136 opt
11137 \emph default 
11138
11139 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
11140
11141 \end_inset 
11142
11143  and section 
11144 \begin_inset LatexCommand \ref{sub:MCS51-variants}
11145
11146 \end_inset 
11147
11148 \SpecialChar ~
11149 about MCS51-variants.
11150 \layout Subsection
11151
11152 HC08 Startup Code
11153 \layout Standard
11154
11155 The HC08 startup code follows the same scheme as the MCS51 startup code.
11156 \layout Subsection
11157
11158 Z80 Startup Code
11159 \layout Standard
11160
11161 On the Z80 the startup code is inserted by linking with crt0.o which is generated
11162  from sdcc/device/lib/z80/crt0.s.
11163  If you need a different startup code you can use the compiler option 
11164 \emph on 
11165 -
11166 \series bold 
11167 \emph default 
11168
11169 \begin_inset ERT
11170 status Collapsed
11171
11172 \layout Standard
11173
11174 \backslash 
11175 /
11176 \end_inset 
11177
11178
11179 \series default 
11180 \emph on 
11181 -no-std-crt0
11182 \emph default 
11183
11184 \begin_inset LatexCommand \index{-\/-no-std-crt0}
11185
11186 \end_inset 
11187
11188  and provide your own crt0.o.
11189  
11190 \layout Section
11191
11192 Inline Assembler Code
11193 \begin_inset LatexCommand \index{Assembler routines}
11194
11195 \end_inset 
11196
11197
11198 \layout Subsection
11199
11200 A Step by Step Introduction
11201 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
11202
11203 \end_inset 
11204
11205
11206 \layout Standard
11207
11208 Starting from a small snippet of c-code this example shows for the MCS51
11209  how to use inline assembly, access variables, a function parameter and
11210  an array in xdata memory.
11211  The example uses an MCS51 here but is easily adapted for other architectures.
11212  This is a buffer routine which should be optimized:
11213 \layout Verse
11214
11215
11216 \family typewriter 
11217 \size footnotesize 
11218 unsigned char far
11219 \begin_inset LatexCommand \index{far (storage class)}
11220
11221 \end_inset 
11222
11223  at
11224 \begin_inset LatexCommand \index{at}
11225
11226 \end_inset 
11227
11228  0x7f00 buf[0x100];
11229 \begin_inset LatexCommand \index{Aligned array}
11230
11231 \end_inset 
11232
11233
11234 \newline 
11235 unsigned char head,tail;
11236 \newline 
11237
11238 \newline 
11239 void to_buffer( unsigned char c ) 
11240 \newline 
11241 {
11242 \newline 
11243 \SpecialChar ~
11244 \SpecialChar ~
11245 \SpecialChar ~
11246 \SpecialChar ~
11247 if( head != tail-1 ) 
11248 \newline 
11249 \SpecialChar ~
11250 \SpecialChar ~
11251 \SpecialChar ~
11252 \SpecialChar ~
11253 \SpecialChar ~
11254 \SpecialChar ~
11255 \SpecialChar ~
11256 \SpecialChar ~
11257 buf[ head++ ] = c;\SpecialChar ~
11258 \SpecialChar ~
11259 \SpecialChar ~
11260 \SpecialChar ~
11261 /* access to a 256 byte aligned array */
11262 \newline 
11263
11264 \layout Standard
11265
11266 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
11267  then a corresponding buffer.asm file is generated.
11268  We define a new function 
11269 \family typewriter 
11270 to_buffer_asm()
11271 \family default 
11272  in file buffer.c in which we cut and paste the generated code, removing
11273  unwanted comments and some ':'.
11274  Then add 
11275 \begin_inset Quotes sld
11276 \end_inset 
11277
11278 _asm
11279 \begin_inset Quotes srd
11280 \end_inset 
11281
11282  and 
11283 \begin_inset Quotes sld
11284 \end_inset 
11285
11286 _endasm;
11287 \begin_inset Quotes srd
11288 \end_inset 
11289
11290  to the beginning and the end of the function body:
11291 \layout Verse
11292
11293
11294 \family typewriter 
11295 \size footnotesize 
11296 /* With a cut and paste from the .asm file, we have something to start with.
11297 \newline 
11298 \SpecialChar ~
11299 \SpecialChar ~
11300 \SpecialChar ~
11301 The function is not yet OK! (registers aren't saved) */ 
11302 \newline 
11303 void to_buffer_asm( unsigned char c ) 
11304 \newline 
11305
11306 \newline 
11307 \SpecialChar ~
11308 \SpecialChar ~
11309 \SpecialChar ~
11310 \SpecialChar ~
11311 _asm
11312 \begin_inset LatexCommand \index{\_asm}
11313
11314 \end_inset 
11315
11316
11317 \newline 
11318 \SpecialChar ~
11319 \SpecialChar ~
11320 \SpecialChar ~
11321 \SpecialChar ~
11322 mov\SpecialChar ~
11323 \SpecialChar ~
11324 r2,dpl 
11325 \newline 
11326 ;buffer.c if( head != tail-1 ) 
11327 \newline 
11328 \SpecialChar ~
11329 \SpecialChar ~
11330 \SpecialChar ~
11331 \SpecialChar ~
11332 mov\SpecialChar ~
11333 \SpecialChar ~
11334 a,_tail 
11335 \newline 
11336 \SpecialChar ~
11337 \SpecialChar ~
11338 \SpecialChar ~
11339 \SpecialChar ~
11340 dec\SpecialChar ~
11341 \SpecialChar ~
11342
11343 \newline 
11344 \SpecialChar ~
11345 \SpecialChar ~
11346 \SpecialChar ~
11347 \SpecialChar ~
11348 mov\SpecialChar ~
11349 \SpecialChar ~
11350 r3,a 
11351 \newline 
11352 \SpecialChar ~
11353 \SpecialChar ~
11354 \SpecialChar ~
11355 \SpecialChar ~
11356 mov\SpecialChar ~
11357 \SpecialChar ~
11358 a,_head 
11359 \newline 
11360 \SpecialChar ~
11361 \SpecialChar ~
11362 \SpecialChar ~
11363 \SpecialChar ~
11364 cjne a,ar3,00106$ 
11365 \newline 
11366 \SpecialChar ~
11367 \SpecialChar ~
11368 \SpecialChar ~
11369 \SpecialChar ~
11370 ret
11371 \newline 
11372 00106$: 
11373 \newline 
11374 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
11375 \begin_inset LatexCommand \index{Aligned array}
11376
11377 \end_inset 
11378
11379
11380 \newline 
11381 \SpecialChar ~
11382 \SpecialChar ~
11383 \SpecialChar ~
11384 \SpecialChar ~
11385 mov\SpecialChar ~
11386 \SpecialChar ~
11387 r3,_head 
11388 \newline 
11389 \SpecialChar ~
11390 \SpecialChar ~
11391 \SpecialChar ~
11392 \SpecialChar ~
11393 inc\SpecialChar ~
11394 \SpecialChar ~
11395 _head 
11396 \newline 
11397 \SpecialChar ~
11398 \SpecialChar ~
11399 \SpecialChar ~
11400 \SpecialChar ~
11401 mov\SpecialChar ~
11402 \SpecialChar ~
11403 dpl,r3 
11404 \newline 
11405 \SpecialChar ~
11406 \SpecialChar ~
11407 \SpecialChar ~
11408 \SpecialChar ~
11409 mov\SpecialChar ~
11410 \SpecialChar ~
11411 dph,#(_buf >> 8) 
11412 \newline 
11413 \SpecialChar ~
11414 \SpecialChar ~
11415 \SpecialChar ~
11416 \SpecialChar ~
11417 mov\SpecialChar ~
11418 \SpecialChar ~
11419 a,r2 
11420 \newline 
11421 \SpecialChar ~
11422 \SpecialChar ~
11423 \SpecialChar ~
11424 \SpecialChar ~
11425 movx @dptr,a 
11426 \newline 
11427 00103$: 
11428 \newline 
11429 \SpecialChar ~
11430 \SpecialChar ~
11431 \SpecialChar ~
11432 \SpecialChar ~
11433 ret
11434 \newline 
11435 \SpecialChar ~
11436 \SpecialChar ~
11437 \SpecialChar ~
11438 \SpecialChar ~
11439 _endasm;
11440 \newline 
11441
11442 \layout Standard
11443
11444 The new file buffer.c should compile with only one warning about the unreferenced
11445  function argument 'c'.
11446  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
11447  (1) and finally have:
11448 \layout Verse
11449
11450
11451 \family typewriter 
11452 \size footnotesize 
11453 unsigned char far at 0x7f00 buf[0x100];
11454 \newline 
11455 unsigned char head,tail;
11456 \newline 
11457 #define USE_ASSEMBLY (1)
11458 \newline 
11459
11460 \newline 
11461 #if !USE_ASSEMBLY
11462 \newline 
11463
11464 \newline 
11465 void to_buffer( unsigned char c )
11466 \newline 
11467 {
11468 \newline 
11469 \SpecialChar ~
11470 \SpecialChar ~
11471 \SpecialChar ~
11472 \SpecialChar ~
11473 if( head != tail-1 )
11474 \newline 
11475 \SpecialChar ~
11476 \SpecialChar ~
11477 \SpecialChar ~
11478 \SpecialChar ~
11479 \SpecialChar ~
11480 \SpecialChar ~
11481 \SpecialChar ~
11482 \SpecialChar ~
11483 buf[ head++ ] = c;
11484 \newline 
11485 }
11486 \newline 
11487
11488 \newline 
11489 #else
11490 \newline 
11491
11492 \newline 
11493 void to_buffer( unsigned char c )
11494 \newline 
11495 {
11496 \newline 
11497 \SpecialChar ~
11498 \SpecialChar ~
11499 \SpecialChar ~
11500 \SpecialChar ~
11501 c; // to avoid warning: unreferenced function argument
11502 \newline 
11503 \SpecialChar ~
11504 \SpecialChar ~
11505 \SpecialChar ~
11506 \SpecialChar ~
11507 _asm
11508 \begin_inset LatexCommand \index{\_asm}
11509
11510 \end_inset 
11511
11512
11513 \newline 
11514 \SpecialChar ~
11515 \SpecialChar ~
11516 \SpecialChar ~
11517 \SpecialChar ~
11518 \SpecialChar ~
11519 \SpecialChar ~
11520 \SpecialChar ~
11521 \SpecialChar ~
11522 ; save used registers here.
11523  
11524 \newline 
11525 \SpecialChar ~
11526 \SpecialChar ~
11527 \SpecialChar ~
11528 \SpecialChar ~
11529 \SpecialChar ~
11530 \SpecialChar ~
11531 \SpecialChar ~
11532 \SpecialChar ~
11533 ; If we were still using r2,r3 we would have to push them here.
11534  
11535 \newline 
11536 ; if( head != tail-1 )
11537 \newline 
11538 \SpecialChar ~
11539 \SpecialChar ~
11540 \SpecialChar ~
11541 \SpecialChar ~
11542 \SpecialChar ~
11543 \SpecialChar ~
11544 \SpecialChar ~
11545 \SpecialChar ~
11546 mov\SpecialChar ~
11547  a,_tail
11548 \newline 
11549 \SpecialChar ~
11550 \SpecialChar ~
11551 \SpecialChar ~
11552 \SpecialChar ~
11553 \SpecialChar ~
11554 \SpecialChar ~
11555 \SpecialChar ~
11556 \SpecialChar ~
11557 dec\SpecialChar ~
11558  a
11559 \newline 
11560 \SpecialChar ~
11561 \SpecialChar ~
11562 \SpecialChar ~
11563 \SpecialChar ~
11564 \SpecialChar ~
11565 \SpecialChar ~
11566 \SpecialChar ~
11567 \SpecialChar ~
11568 xrl\SpecialChar ~
11569  a,_head
11570 \newline 
11571 \SpecialChar ~
11572 \SpecialChar ~
11573 \SpecialChar ~
11574 \SpecialChar ~
11575 \SpecialChar ~
11576 \SpecialChar ~
11577 \SpecialChar ~
11578 \SpecialChar ~
11579 ; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
11580 \newline 
11581 \SpecialChar ~
11582 \SpecialChar ~
11583 \SpecialChar ~
11584 \SpecialChar ~
11585 \SpecialChar ~
11586 \SpecialChar ~
11587 \SpecialChar ~
11588 \SpecialChar ~
11589 jz\SpecialChar ~
11590 \SpecialChar ~
11591  t_b_end$
11592 \newline 
11593 \SpecialChar ~
11594 \SpecialChar ~
11595 \SpecialChar ~
11596 \SpecialChar ~
11597 \SpecialChar ~
11598 \SpecialChar ~
11599 \SpecialChar ~
11600 \SpecialChar ~
11601 ;
11602 \newline 
11603 ; buf[ head++ ] = c;
11604 \newline 
11605 \SpecialChar ~
11606 \SpecialChar ~
11607 \SpecialChar ~
11608 \SpecialChar ~
11609 \SpecialChar ~
11610 \SpecialChar ~
11611 \SpecialChar ~
11612 \SpecialChar ~
11613 mov\SpecialChar ~
11614  a,dpl \SpecialChar ~
11615 \SpecialChar ~
11616 \SpecialChar ~
11617 \SpecialChar ~
11618 \SpecialChar ~
11619 \SpecialChar ~
11620 \SpecialChar ~
11621 ; dpl holds lower byte of function argument
11622 \newline 
11623 \SpecialChar ~
11624 \SpecialChar ~
11625 \SpecialChar ~
11626 \SpecialChar ~
11627 \SpecialChar ~
11628 \SpecialChar ~
11629 \SpecialChar ~
11630 \SpecialChar ~
11631 mov\SpecialChar ~
11632  dpl,_head \SpecialChar ~
11633 \SpecialChar ~
11634 \SpecialChar ~
11635 ; buf is 0x100 byte aligned so head can be used directly
11636 \newline 
11637 \SpecialChar ~
11638 \SpecialChar ~
11639 \SpecialChar ~
11640 \SpecialChar ~
11641 \SpecialChar ~
11642 \SpecialChar ~
11643 \SpecialChar ~
11644 \SpecialChar ~
11645 mov\SpecialChar ~
11646  dph,#(_buf>>8)
11647 \newline 
11648 \SpecialChar ~
11649 \SpecialChar ~
11650 \SpecialChar ~
11651 \SpecialChar ~
11652 \SpecialChar ~
11653 \SpecialChar ~
11654 \SpecialChar ~
11655 \SpecialChar ~
11656 movx @dptr,a
11657 \newline 
11658 \SpecialChar ~
11659 \SpecialChar ~
11660 \SpecialChar ~
11661 \SpecialChar ~
11662 \SpecialChar ~
11663 \SpecialChar ~
11664 \SpecialChar ~
11665 \SpecialChar ~
11666 inc \SpecialChar ~
11667 _head
11668 \newline 
11669 \SpecialChar ~
11670 \SpecialChar ~
11671 \SpecialChar ~
11672 \SpecialChar ~
11673 \SpecialChar ~
11674 \SpecialChar ~
11675 \SpecialChar ~
11676 \SpecialChar ~
11677 ; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)
11678 \newline 
11679 t_b_end$:
11680 \newline 
11681 \SpecialChar ~
11682 \SpecialChar ~
11683 \SpecialChar ~
11684 \SpecialChar ~
11685 \SpecialChar ~
11686 \SpecialChar ~
11687 \SpecialChar ~
11688 \SpecialChar ~
11689 ; restore used registers here 
11690 \newline 
11691 \SpecialChar ~
11692 \SpecialChar ~
11693 \SpecialChar ~
11694 \SpecialChar ~
11695 _endasm;
11696 \newline 
11697 }
11698 \newline 
11699 #endif
11700 \layout Standard
11701
11702 The inline assembler code can contain any valid code understood by the assembler
11703 , this includes any assembler directives and comment lines
11704 \begin_inset Foot
11705 collapsed false
11706
11707 \layout Standard
11708
11709 The assembler does not like some characters like ':' or ''' in comments.
11710  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
11711 \end_inset 
11712
11713 .
11714  The compiler does not do any validation of the code within the 
11715 \family typewriter 
11716 _asm
11717 \begin_inset LatexCommand \index{\_asm}
11718
11719 \end_inset 
11720
11721  ...
11722  _endasm;
11723 \family default 
11724  keyword pair.
11725  Specifically it will not know which registers are used and thus register
11726  pushing/popping
11727 \begin_inset LatexCommand \index{push/pop}
11728
11729 \end_inset 
11730
11731  has to be done manually.
11732  
11733 \layout Standard
11734
11735 It is recommended that each assembly instruction (including labels) be placed
11736  in a separate line (as the example shows).
11737  When the -
11738 \begin_inset ERT
11739 status Collapsed
11740
11741 \layout Standard
11742
11743 \backslash 
11744 /
11745 \end_inset 
11746
11747 -
11748 \emph on 
11749 peep-asm
11750 \begin_inset LatexCommand \index{-\/-peep-asm}
11751
11752 \end_inset 
11753
11754
11755 \emph default 
11756  command line option is used, the inline assembler code will be passed through
11757  the peephole optimizer
11758 \begin_inset LatexCommand \index{Peephole optimizer}
11759
11760 \end_inset 
11761
11762 .
11763  There are only a few (if any) cases where this option makes sense, it might
11764  cause some unexpected changes in the inline assembler code.
11765  Please go through the peephole optimizer rules defined in file 
11766 \emph on 
11767 SDCCpeeph.def
11768 \emph default 
11769  before using this option.
11770 \layout Subsection
11771
11772 Naked Functions
11773 \begin_inset LatexCommand \label{sub:Naked-Functions}
11774
11775 \end_inset 
11776
11777
11778 \begin_inset LatexCommand \index{Naked functions}
11779
11780 \end_inset 
11781
11782
11783 \layout Standard
11784
11785 A special keyword may be associated with a function declaring it as 
11786 \emph on 
11787 _naked
11788 \begin_inset LatexCommand \index{\_naked}
11789
11790 \end_inset 
11791
11792 .
11793  
11794 \emph default 
11795 The 
11796 \emph on 
11797 _naked
11798 \emph default 
11799  function modifier attribute prevents the compiler from generating prologue
11800 \begin_inset LatexCommand \index{function prologue}
11801
11802 \end_inset 
11803
11804  and epilogue
11805 \begin_inset LatexCommand \index{function epilogue}
11806
11807 \end_inset 
11808
11809  code for that function.
11810  This means that the user is entirely responsible for such things as saving
11811  any registers that may need to be preserved, selecting the proper register
11812  bank, generating the 
11813 \emph on 
11814 return
11815 \emph default 
11816  instruction at the end, etc.
11817  Practically, this means that the contents of the function must be written
11818  in inline assembler.
11819  This is particularly useful for interrupt functions, which can have a large
11820  (and often unnecessary) prologue/epilogue.
11821  For example, compare the code generated by these two functions:
11822 \layout Verse
11823
11824
11825 \family typewriter 
11826 volatile
11827 \begin_inset LatexCommand \index{volatile}
11828
11829 \end_inset 
11830
11831  data unsigned char counter;
11832 \newline 
11833
11834 \newline 
11835 void simpleInterrupt(void) interrupt
11836 \begin_inset LatexCommand \index{interrupt}
11837
11838 \end_inset 
11839
11840  1
11841 \newline 
11842 {
11843 \newline 
11844 \SpecialChar ~
11845 \SpecialChar ~
11846 \SpecialChar ~
11847 \SpecialChar ~
11848 counter++;
11849 \newline 
11850 }
11851 \newline 
11852
11853 \newline 
11854 void nakedInterrupt(void) interrupt 2 _naked
11855 \newline 
11856 {
11857 \newline 
11858 \SpecialChar ~
11859 \SpecialChar ~
11860 \SpecialChar ~
11861 \SpecialChar ~
11862 _asm
11863 \begin_inset LatexCommand \index{\_asm}
11864
11865 \end_inset 
11866
11867
11868 \newline 
11869 \SpecialChar ~
11870 \SpecialChar ~
11871 \SpecialChar ~
11872 \SpecialChar ~
11873 \SpecialChar ~
11874 \SpecialChar ~
11875 inc\SpecialChar ~
11876 \SpecialChar ~
11877 \SpecialChar ~
11878 \SpecialChar ~
11879 \SpecialChar ~
11880 _counter ; does not change flags, no need to save psw
11881 \newline 
11882 \SpecialChar ~
11883 \SpecialChar ~
11884 \SpecialChar ~
11885 \SpecialChar ~
11886 \SpecialChar ~
11887 \SpecialChar ~
11888 reti\SpecialChar ~
11889 \SpecialChar ~
11890 \SpecialChar ~
11891 \SpecialChar ~
11892 ; MUST explicitly include ret or reti in _naked function.
11893 \newline 
11894 \SpecialChar ~
11895 \SpecialChar ~
11896 \SpecialChar ~
11897 \SpecialChar ~
11898 _endasm
11899 \begin_inset LatexCommand \index{\_endasm}
11900
11901 \end_inset 
11902
11903 ;
11904 \newline 
11905 }
11906 \layout Standard
11907
11908 For an 8051 target, the generated simpleInterrupt looks like:
11909 \layout Verse
11910
11911
11912 \family typewriter 
11913 _simpleInterrupt:
11914 \newline 
11915 \SpecialChar ~
11916 \SpecialChar ~
11917 \SpecialChar ~
11918 \SpecialChar ~
11919 push\SpecialChar ~
11920 \SpecialChar ~
11921 \SpecialChar ~
11922 \SpecialChar ~
11923 acc
11924 \newline 
11925 \SpecialChar ~
11926 \SpecialChar ~
11927 \SpecialChar ~
11928 \SpecialChar ~
11929 push\SpecialChar ~
11930 \SpecialChar ~
11931 \SpecialChar ~
11932 \SpecialChar ~
11933 b
11934 \newline 
11935 \SpecialChar ~
11936 \SpecialChar ~
11937 \SpecialChar ~
11938 \SpecialChar ~
11939 push\SpecialChar ~
11940 \SpecialChar ~
11941 \SpecialChar ~
11942 \SpecialChar ~
11943 dpl
11944 \newline 
11945 \SpecialChar ~
11946 \SpecialChar ~
11947 \SpecialChar ~
11948 \SpecialChar ~
11949 push\SpecialChar ~
11950 \SpecialChar ~
11951 \SpecialChar ~
11952 \SpecialChar ~
11953 dph
11954 \newline 
11955 \SpecialChar ~
11956 \SpecialChar ~
11957 \SpecialChar ~
11958 \SpecialChar ~
11959 push\SpecialChar ~
11960 \SpecialChar ~
11961 \SpecialChar ~
11962 \SpecialChar ~
11963 psw
11964 \newline 
11965 \SpecialChar ~
11966 \SpecialChar ~
11967 \SpecialChar ~
11968 \SpecialChar ~
11969 mov\SpecialChar ~
11970 \SpecialChar ~
11971 \SpecialChar ~
11972 \SpecialChar ~
11973 \SpecialChar ~
11974 psw,#0x00
11975 \newline 
11976 \SpecialChar ~
11977 \SpecialChar ~
11978 \SpecialChar ~
11979 \SpecialChar ~
11980 inc\SpecialChar ~
11981 \SpecialChar ~
11982 \SpecialChar ~
11983 \SpecialChar ~
11984 \SpecialChar ~
11985 _counter
11986 \newline 
11987 \SpecialChar ~
11988 \SpecialChar ~
11989 \SpecialChar ~
11990 \SpecialChar ~
11991 pop\SpecialChar ~
11992 \SpecialChar ~
11993 \SpecialChar ~
11994 \SpecialChar ~
11995 \SpecialChar ~
11996 psw
11997 \newline 
11998 \SpecialChar ~
11999 \SpecialChar ~
12000 \SpecialChar ~
12001 \SpecialChar ~
12002 pop\SpecialChar ~
12003 \SpecialChar ~
12004 \SpecialChar ~
12005 \SpecialChar ~
12006 \SpecialChar ~
12007 dph
12008 \newline 
12009 \SpecialChar ~
12010 \SpecialChar ~
12011 \SpecialChar ~
12012 \SpecialChar ~
12013 pop\SpecialChar ~
12014 \SpecialChar ~
12015 \SpecialChar ~
12016 \SpecialChar ~
12017 \SpecialChar ~
12018 dpl
12019 \newline 
12020 \SpecialChar ~
12021 \SpecialChar ~
12022 \SpecialChar ~
12023 \SpecialChar ~
12024 pop\SpecialChar ~
12025 \SpecialChar ~
12026 \SpecialChar ~
12027 \SpecialChar ~
12028 \SpecialChar ~
12029 b
12030 \newline 
12031 \SpecialChar ~
12032 \SpecialChar ~
12033 \SpecialChar ~
12034 \SpecialChar ~
12035 pop\SpecialChar ~
12036 \SpecialChar ~
12037 \SpecialChar ~
12038 \SpecialChar ~
12039 \SpecialChar ~
12040 acc
12041 \newline 
12042 \SpecialChar ~
12043 \SpecialChar ~
12044 \SpecialChar ~
12045 \SpecialChar ~
12046 reti
12047 \layout Standard
12048
12049 whereas nakedInterrupt looks like:
12050 \layout Verse
12051
12052
12053 \family typewriter 
12054 _nakedInterrupt:
12055 \newline 
12056 \SpecialChar ~
12057 \SpecialChar ~
12058 \SpecialChar ~
12059 \SpecialChar ~
12060 inc\SpecialChar ~
12061 \SpecialChar ~
12062 \SpecialChar ~
12063 \SpecialChar ~
12064 _counter ; does not change flags, no need to save psw
12065 \newline 
12066 \SpecialChar ~
12067 \SpecialChar ~
12068 \SpecialChar ~
12069 \SpecialChar ~
12070 reti\SpecialChar ~
12071 \SpecialChar ~
12072 \SpecialChar ~
12073 \SpecialChar ~
12074 \SpecialChar ~
12075 \SpecialChar ~
12076 \SpecialChar ~
12077 \SpecialChar ~
12078 \SpecialChar ~
12079 \SpecialChar ~
12080 \SpecialChar ~
12081 \SpecialChar ~
12082 ; MUST explicitly include ret or reti in _naked function
12083 \layout Standard
12084
12085 The related directive #pragma exclude
12086 \begin_inset LatexCommand \index{\#pragma exclude}
12087
12088 \end_inset 
12089
12090  allows a more fine grained control over pushing & popping
12091 \begin_inset LatexCommand \index{push/pop}
12092
12093 \end_inset 
12094
12095  the registers.
12096 \layout Standard
12097
12098 While there is nothing preventing you from writing C code inside a 
12099 \family typewriter 
12100 _naked
12101 \family default 
12102  function, there are many ways to shoot yourself in the foot doing this,
12103  and it is recommended that you stick to inline assembler.
12104 \layout Subsection
12105
12106 Use of Labels within Inline Assembler
12107 \layout Standard
12108
12109 SDCC allows the use of in-line assembler with a few restrictions regarding
12110  labels.
12111  In older versions of the compiler all labels defined within inline assembler
12112  code 
12113 \emph on 
12114 had to be
12115 \emph default 
12116  of the form 
12117 \emph on 
12118 nnnnn$
12119 \emph default 
12120  where nnnn is a number less than 100 (which implies a limit of utmost 100
12121  inline assembler labels 
12122 \emph on 
12123 per function
12124 \emph default 
12125 \noun on 
12126 )
12127 \noun default 
12128 .
12129  
12130 \layout Verse
12131
12132
12133 \family typewriter 
12134 _asm
12135 \begin_inset LatexCommand \index{\_asm}
12136
12137 \end_inset 
12138
12139  
12140 \newline 
12141 \SpecialChar ~
12142 \SpecialChar ~
12143 \SpecialChar ~
12144 \SpecialChar ~
12145 mov\SpecialChar ~
12146 \SpecialChar ~
12147 \SpecialChar ~
12148 \SpecialChar ~
12149 \SpecialChar ~
12150 b,#10 
12151 \newline 
12152 00001$: 
12153 \newline 
12154 \SpecialChar ~
12155 \SpecialChar ~
12156 \SpecialChar ~
12157 \SpecialChar ~
12158 djnz\SpecialChar ~
12159 \SpecialChar ~
12160 \SpecialChar ~
12161 \SpecialChar ~
12162 b,00001$ 
12163 \newline 
12164 _endasm
12165 \begin_inset LatexCommand \index{\_endasm}
12166
12167 \end_inset 
12168
12169  ;
12170 \layout Standard
12171
12172 Inline assembler code cannot reference any C-Labels, however it can reference
12173  labels
12174 \begin_inset LatexCommand \index{Labels}
12175
12176 \end_inset 
12177
12178  defined by the inline assembler, e.g.:
12179 \layout Verse
12180
12181
12182 \family typewriter 
12183 foo() { 
12184 \newline 
12185 \SpecialChar ~
12186 \SpecialChar ~
12187 \SpecialChar ~
12188 \SpecialChar ~
12189 /* some c code */ 
12190 \newline 
12191 \SpecialChar ~
12192 \SpecialChar ~
12193 \SpecialChar ~
12194 \SpecialChar ~
12195 _asm 
12196 \newline 
12197 \SpecialChar ~
12198 \SpecialChar ~
12199 \SpecialChar ~
12200 \SpecialChar ~
12201 \SpecialChar ~
12202 \SpecialChar ~
12203 ; some assembler code 
12204 \newline 
12205 \SpecialChar ~
12206 \SpecialChar ~
12207 \SpecialChar ~
12208 \SpecialChar ~
12209 \SpecialChar ~
12210 \SpecialChar ~
12211 ljmp $0003 
12212 \newline 
12213 \SpecialChar ~
12214 \SpecialChar ~
12215 \SpecialChar ~
12216 \SpecialChar ~
12217 _endasm; 
12218 \newline 
12219 \SpecialChar ~
12220 \SpecialChar ~
12221 \SpecialChar ~
12222 \SpecialChar ~
12223 /* some more c code */ 
12224 \newline 
12225 clabel:\SpecialChar ~
12226 \SpecialChar ~
12227 /* inline assembler cannot reference this label */ 
12228 \newline 
12229 \SpecialChar ~
12230 \SpecialChar ~
12231 \SpecialChar ~
12232 \SpecialChar ~
12233 _asm
12234 \newline 
12235 \SpecialChar ~
12236 \SpecialChar ~
12237 \SpecialChar ~
12238 \SpecialChar ~
12239 $0003: ;label (can be referenced by inline assembler only) 
12240 \newline 
12241 \SpecialChar ~
12242 \SpecialChar ~
12243 \SpecialChar ~
12244 \SpecialChar ~
12245 _endasm ; 
12246 \newline 
12247 \SpecialChar ~
12248 \SpecialChar ~
12249 \SpecialChar ~
12250 \SpecialChar ~
12251 /* some more c code */
12252 \newline 
12253 }
12254 \layout Standard
12255
12256 In other words inline assembly code can access labels defined in inline
12257  assembly within the scope of the function.
12258  The same goes the other way, i.e.
12259  labels defines in inline assembly can not be accessed by C statements.
12260 \layout Section
12261
12262 Interfacing with Assembler Code
12263 \begin_inset LatexCommand \index{Assembler routines}
12264
12265 \end_inset 
12266
12267
12268 \layout Subsection
12269
12270 Global Registers used for Parameter Passing
12271 \begin_inset LatexCommand \index{Parameter passing}
12272
12273 \end_inset 
12274
12275
12276 \layout Standard
12277
12278 The compiler always uses the global registers 
12279 \emph on 
12280 DPL, DPH
12281 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
12282
12283 \end_inset 
12284
12285
12286 \begin_inset LatexCommand \index{DPTR}
12287
12288 \end_inset 
12289
12290 , B
12291 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
12292
12293 \end_inset 
12294
12295  
12296 \emph default 
12297 and
12298 \emph on 
12299  ACC
12300 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
12301
12302 \end_inset 
12303
12304
12305 \emph default 
12306  to pass the first parameter to a routine.
12307  The second parameter onwards is either allocated on the stack (for reentrant
12308  routines or if -
12309 \begin_inset ERT
12310 status Collapsed
12311
12312 \layout Standard
12313
12314 \backslash 
12315 /
12316 \end_inset 
12317
12318 -stack-auto is used) or in data / xdata memory (depending on the memory
12319  model).
12320  
12321 \layout Subsection
12322
12323 Assembler Routine (non-reentrant)
12324 \layout Standard
12325
12326 In the following example
12327 \begin_inset LatexCommand \index{reentrant}
12328
12329 \end_inset 
12330
12331
12332 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
12333
12334 \end_inset 
12335
12336  the function c_func calls an assembler routine asm_func, which takes two
12337  parameters
12338 \begin_inset LatexCommand \index{function parameter}
12339
12340 \end_inset 
12341
12342 .
12343 \layout Verse
12344
12345
12346 \family typewriter 
12347 extern int asm_func(unsigned char, unsigned char);
12348 \newline 
12349
12350 \newline 
12351 int c_func (unsigned char i, unsigned char j)
12352 \newline 
12353 {
12354 \newline 
12355 \SpecialChar ~
12356 \SpecialChar ~
12357 \SpecialChar ~
12358 \SpecialChar ~
12359 return asm_func(i,j);
12360 \newline 
12361 }
12362 \newline 
12363
12364 \newline 
12365 int main()
12366 \newline 
12367 {
12368 \newline 
12369 \SpecialChar ~
12370 \SpecialChar ~
12371 \SpecialChar ~
12372 \SpecialChar ~
12373 return c_func(10,9);
12374 \newline 
12375 }
12376 \layout Standard
12377
12378 The corresponding assembler function is:
12379 \layout Verse
12380
12381
12382 \family typewriter 
12383 .globl _asm_func_PARM_2 
12384 \newline 
12385 \SpecialChar ~
12386 \SpecialChar ~
12387 \SpecialChar ~
12388 \SpecialChar ~
12389 \SpecialChar ~
12390 \SpecialChar ~
12391 \SpecialChar ~
12392 \SpecialChar ~
12393 .globl _asm_func 
12394 \newline 
12395 \SpecialChar ~
12396 \SpecialChar ~
12397 \SpecialChar ~
12398 \SpecialChar ~
12399 \SpecialChar ~
12400 \SpecialChar ~
12401 \SpecialChar ~
12402 \SpecialChar ~
12403 .area OSEG 
12404 \newline 
12405 _asm_func_PARM_2:
12406 \newline 
12407 \SpecialChar ~
12408 \SpecialChar ~
12409 \SpecialChar ~
12410 \SpecialChar ~
12411 \SpecialChar ~
12412 \SpecialChar ~
12413 \SpecialChar ~
12414 \SpecialChar ~
12415 .ds    1 
12416 \newline 
12417 \SpecialChar ~
12418 \SpecialChar ~
12419 \SpecialChar ~
12420 \SpecialChar ~
12421 \SpecialChar ~
12422 \SpecialChar ~
12423 \SpecialChar ~
12424 \SpecialChar ~
12425 .area CSEG 
12426 \newline 
12427 _asm_func: 
12428 \newline 
12429 \SpecialChar ~
12430 \SpecialChar ~
12431 \SpecialChar ~
12432 \SpecialChar ~
12433 \SpecialChar ~
12434 \SpecialChar ~
12435 \SpecialChar ~
12436 \SpecialChar ~
12437 mov\SpecialChar ~
12438 \SpecialChar ~
12439 \SpecialChar ~
12440 \SpecialChar ~
12441 a,dpl 
12442 \newline 
12443 \SpecialChar ~
12444 \SpecialChar ~
12445 \SpecialChar ~
12446 \SpecialChar ~
12447 \SpecialChar ~
12448 \SpecialChar ~
12449 \SpecialChar ~
12450 \SpecialChar ~
12451 add\SpecialChar ~
12452 \SpecialChar ~
12453 \SpecialChar ~
12454 \SpecialChar ~
12455 a,_asm_func_PARM_2 
12456 \newline 
12457 \SpecialChar ~
12458 \SpecialChar ~
12459 \SpecialChar ~
12460 \SpecialChar ~
12461 \SpecialChar ~
12462 \SpecialChar ~
12463 \SpecialChar ~
12464 \SpecialChar ~
12465 mov\SpecialChar ~
12466 \SpecialChar ~
12467 \SpecialChar ~
12468 \SpecialChar ~
12469 dpl,a 
12470 \newline 
12471 \SpecialChar ~
12472 \SpecialChar ~
12473 \SpecialChar ~
12474 \SpecialChar ~
12475 \SpecialChar ~
12476 \SpecialChar ~
12477 \SpecialChar ~
12478 \SpecialChar ~
12479 mov\SpecialChar ~
12480 \SpecialChar ~
12481 \SpecialChar ~
12482 \SpecialChar ~
12483 dph
12484 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
12485
12486 \end_inset 
12487
12488 ,#0x00 
12489 \newline 
12490 \SpecialChar ~
12491 \SpecialChar ~
12492 \SpecialChar ~
12493 \SpecialChar ~
12494 \SpecialChar ~
12495 \SpecialChar ~
12496 \SpecialChar ~
12497 \SpecialChar ~
12498 ret
12499 \layout Standard
12500
12501 Note here that the return values
12502 \begin_inset LatexCommand \index{return value}
12503
12504 \end_inset 
12505
12506  are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
12507  two byte values.
12508  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
12509 b' & 'acc' for four byte values.
12510 \layout Standard
12511
12512 The parameter naming convention is _<function_name>_PARM_<n>, where n is
12513  the parameter number starting from 1, and counting from the left.
12514  The first parameter is passed in 
12515 \begin_inset Quotes eld
12516 \end_inset 
12517
12518 dpl
12519 \begin_inset Quotes erd
12520 \end_inset 
12521
12522  for a one byte parameter, 
12523 \begin_inset Quotes eld
12524 \end_inset 
12525
12526 dptr
12527 \begin_inset Quotes erd
12528 \end_inset 
12529
12530  for two bytes, 
12531 \begin_inset Quotes eld
12532 \end_inset 
12533
12534 b,dptr
12535 \begin_inset Quotes erd
12536 \end_inset 
12537
12538  for three bytes and 
12539 \begin_inset Quotes eld
12540 \end_inset 
12541
12542 acc,b,dptr
12543 \begin_inset Quotes erd
12544 \end_inset 
12545
12546  for a four bytes parameter.
12547  The variable name for the second parameter will be _<function_name>_PARM_2.
12548 \newline 
12549
12550 \newline 
12551 Assemble the assembler routine with the following command:
12552 \newline 
12553
12554 \newline 
12555
12556 \family sans 
12557 \series bold 
12558 asx8051 -losg asmfunc.asm
12559 \newline 
12560
12561 \newline 
12562
12563 \family default 
12564 \series default 
12565 Then compile and link the assembler routine to the C source file with the
12566  following command:
12567 \newline 
12568
12569 \newline 
12570
12571 \family sans 
12572 \series bold 
12573 sdcc cfunc.c asmfunc.rel
12574 \layout Subsection
12575
12576 Assembler Routine (reentrant)
12577 \layout Standard
12578
12579 In this case
12580 \begin_inset LatexCommand \index{reentrant}
12581
12582 \end_inset 
12583
12584
12585 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
12586
12587 \end_inset 
12588
12589  the second parameter
12590 \begin_inset LatexCommand \index{function parameter}
12591
12592 \end_inset 
12593
12594  onwards will be passed on the stack, the parameters are pushed from right
12595  to left i.e.
12596  after the call the leftmost parameter will be on the top of the stack.
12597  Here is an example:
12598 \layout Verse
12599
12600
12601 \family typewriter 
12602 extern int asm_func(unsigned char, unsigned char);
12603 \newline 
12604
12605 \newline 
12606 int c_func (unsigned char i, unsigned char j) reentrant 
12607 \newline 
12608
12609 \newline 
12610 \SpecialChar ~
12611 \SpecialChar ~
12612 \SpecialChar ~
12613 \SpecialChar ~
12614 return asm_func(i,j); 
12615 \newline 
12616
12617 \newline 
12618
12619 \newline 
12620 int main() 
12621 \newline 
12622
12623 \newline 
12624 \SpecialChar ~
12625 \SpecialChar ~
12626 \SpecialChar ~
12627 \SpecialChar ~
12628 return c_func(10,9); 
12629 \newline 
12630 }
12631 \layout Standard
12632
12633 The corresponding assembler routine is:
12634 \layout Verse
12635
12636
12637 \family typewriter 
12638 .globl _asm_func 
12639 \newline 
12640 _asm_func: 
12641 \newline 
12642 \SpecialChar ~
12643 \SpecialChar ~
12644 \SpecialChar ~
12645 \SpecialChar ~
12646 push  _bp 
12647 \newline 
12648 \SpecialChar ~
12649 \SpecialChar ~
12650 \SpecialChar ~
12651 \SpecialChar ~
12652 mov _bp,sp 
12653 \newline 
12654 \SpecialChar ~
12655 \SpecialChar ~
12656 \SpecialChar ~
12657 \SpecialChar ~
12658 mov r2,dpl
12659 \newline 
12660 \SpecialChar ~
12661 \SpecialChar ~
12662 \SpecialChar ~
12663 \SpecialChar ~
12664 mov a,_bp 
12665 \newline 
12666 \SpecialChar ~
12667 \SpecialChar ~
12668 \SpecialChar ~
12669 \SpecialChar ~
12670 add a,#0xfd 
12671 \newline 
12672 \SpecialChar ~
12673 \SpecialChar ~
12674 \SpecialChar ~
12675 \SpecialChar ~
12676 mov r0,a 
12677 \newline 
12678 \SpecialChar ~
12679 \SpecialChar ~
12680 \SpecialChar ~
12681 \SpecialChar ~
12682 add  a,#0xfc ;?
12683 \newline 
12684 \SpecialChar ~
12685 \SpecialChar ~
12686 \SpecialChar ~
12687 \SpecialChar ~
12688 mov  r1,a 
12689 \newline 
12690 \SpecialChar ~
12691 \SpecialChar ~
12692 \SpecialChar ~
12693 \SpecialChar ~
12694 mov  a,@r0 
12695 \newline 
12696 \SpecialChar ~
12697 \SpecialChar ~
12698 \SpecialChar ~
12699 \SpecialChar ~
12700 add  a,r2 ;?
12701 \newline 
12702 \SpecialChar ~
12703 \SpecialChar ~
12704 \SpecialChar ~
12705 \SpecialChar ~
12706 mov  dpl,a 
12707 \newline 
12708 \SpecialChar ~
12709 \SpecialChar ~
12710 \SpecialChar ~
12711 \SpecialChar ~
12712 mov  dph,#0x00 
12713 \newline 
12714 \SpecialChar ~
12715 \SpecialChar ~
12716 \SpecialChar ~
12717 \SpecialChar ~
12718 mov  sp,_bp 
12719 \newline 
12720 \SpecialChar ~
12721 \SpecialChar ~
12722 \SpecialChar ~
12723 \SpecialChar ~
12724 pop  _bp 
12725 \newline 
12726 \SpecialChar ~
12727 \SpecialChar ~
12728 \SpecialChar ~
12729 \SpecialChar ~
12730 ret
12731 \layout Standard
12732
12733 The compiling and linking procedure remains the same, however note the extra
12734  entry & exit linkage required for the assembler code, _bp is the stack
12735  frame pointer and is used to compute the offset into the stack for parameters
12736  and local variables.
12737 \layout Section
12738
12739 int (16 bit)
12740 \begin_inset LatexCommand \index{int (16 bit)}
12741
12742 \end_inset 
12743
12744  and long (32 bit)
12745 \begin_inset LatexCommand \index{long (32 bit)}
12746
12747 \end_inset 
12748
12749  Support
12750 \layout Standard
12751
12752 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
12753  multiplication and modulus operations are implemented by support routines.
12754  These support routines are all developed in ANSI-C to facilitate porting
12755  to other MCUs, although some model specific assembler optimizations are
12756  used.
12757  The following files contain the described routines, all of them can be
12758  found in <installdir>/share/sdcc/lib.
12759 \newline 
12760
12761 \layout Standard
12762 \align center 
12763
12764 \begin_inset  Tabular
12765 <lyxtabular version="3" rows="11" columns="2">
12766 <features>
12767 <column alignment="center" valignment="top" leftline="true" width="0">
12768 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
12769 <row topline="true" bottomline="true">
12770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12771 \begin_inset Text
12772
12773 \layout Standard
12774
12775
12776 \series bold 
12777 Function
12778 \end_inset 
12779 </cell>
12780 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12781 \begin_inset Text
12782
12783 \layout Standard
12784
12785
12786 \series bold 
12787 Description
12788 \end_inset 
12789 </cell>
12790 </row>
12791 <row topline="true">
12792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12793 \begin_inset Text
12794
12795 \layout Standard
12796
12797 _mulint.c 
12798 \end_inset 
12799 </cell>
12800 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12801 \begin_inset Text
12802
12803 \layout Standard
12804
12805 16 bit multiplication
12806 \end_inset 
12807 </cell>
12808 </row>
12809 <row topline="true">
12810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12811 \begin_inset Text
12812
12813 \layout Standard
12814
12815 _divsint.c 
12816 \end_inset 
12817 </cell>
12818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12819 \begin_inset Text
12820
12821 \layout Standard
12822
12823  signed 16 bit division (calls _divuint)
12824 \end_inset 
12825 </cell>
12826 </row>
12827 <row topline="true">
12828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12829 \begin_inset Text
12830
12831 \layout Standard
12832
12833 _divuint.c 
12834 \end_inset 
12835 </cell>
12836 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12837 \begin_inset Text
12838
12839 \layout Standard
12840
12841  unsigned 16 bit division
12842 \end_inset 
12843 </cell>
12844 </row>
12845 <row topline="true">
12846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12847 \begin_inset Text
12848
12849 \layout Standard
12850
12851 _modsint.c
12852 \end_inset 
12853 </cell>
12854 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12855 \begin_inset Text
12856
12857 \layout Standard
12858
12859 signed 16 bit modulus (calls _moduint)
12860 \end_inset 
12861 </cell>
12862 </row>
12863 <row topline="true">
12864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12865 \begin_inset Text
12866
12867 \layout Standard
12868
12869 _moduint.c
12870 \end_inset 
12871 </cell>
12872 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12873 \begin_inset Text
12874
12875 \layout Standard
12876
12877 unsigned 16 bit modulus
12878 \end_inset 
12879 </cell>
12880 </row>
12881 <row topline="true">
12882 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12883 \begin_inset Text
12884
12885 \layout Standard
12886
12887 _mullong.c
12888 \end_inset 
12889 </cell>
12890 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12891 \begin_inset Text
12892
12893 \layout Standard
12894
12895 32 bit multiplication
12896 \end_inset 
12897 </cell>
12898 </row>
12899 <row topline="true">
12900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12901 \begin_inset Text
12902
12903 \layout Standard
12904
12905 _divslong.c 
12906 \end_inset 
12907 </cell>
12908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12909 \begin_inset Text
12910
12911 \layout Standard
12912
12913  signed 32 division (calls _divulong)
12914 \end_inset 
12915 </cell>
12916 </row>
12917 <row topline="true">
12918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12919 \begin_inset Text
12920
12921 \layout Standard
12922
12923 _divulong.c 
12924 \end_inset 
12925 </cell>
12926 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12927 \begin_inset Text
12928
12929 \layout Standard
12930
12931 unsigned 32 division
12932 \end_inset 
12933 </cell>
12934 </row>
12935 <row topline="true">
12936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12937 \begin_inset Text
12938
12939 \layout Standard
12940
12941 _modslong.c
12942 \end_inset 
12943 </cell>
12944 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12945 \begin_inset Text
12946
12947 \layout Standard
12948
12949  signed 32 bit modulus (calls _modulong)
12950 \end_inset 
12951 </cell>
12952 </row>
12953 <row topline="true" bottomline="true">
12954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12955 \begin_inset Text
12956
12957 \layout Standard
12958
12959 _modulong.c
12960 \end_inset 
12961 </cell>
12962 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12963 \begin_inset Text
12964
12965 \layout Standard
12966
12967 unsigned 32 bit modulus
12968 \end_inset 
12969 </cell>
12970 </row>
12971 </lyxtabular>
12972
12973 \end_inset 
12974
12975
12976 \newline 
12977
12978 \layout Standard
12979
12980 Since they are compiled as 
12981 \emph on 
12982 non-reentrant
12983 \emph default 
12984
12985 \begin_inset LatexCommand \index{reentrant}
12986
12987 \end_inset 
12988
12989 , interrupt
12990 \begin_inset LatexCommand \index{interrupt}
12991
12992 \end_inset 
12993
12994  service routines should not do any of the above operations.
12995  If this is unavoidable then the above routines will need to be compiled
12996  with the 
12997 \emph on 
12998 -
12999 \begin_inset ERT
13000 status Collapsed
13001
13002 \layout Standard
13003
13004 \backslash 
13005 /
13006 \end_inset 
13007
13008 -stack-auto
13009 \begin_inset LatexCommand \index{-\/-stack-auto}
13010
13011 \end_inset 
13012
13013
13014 \emph default 
13015  option, after which the source program will have to be compiled with 
13016 \emph on 
13017 -
13018 \begin_inset ERT
13019 status Collapsed
13020
13021 \layout Standard
13022
13023 \backslash 
13024 /
13025 \end_inset 
13026
13027 -int-long-reent
13028 \begin_inset LatexCommand \index{-\/-int-long-reent}
13029
13030 \end_inset 
13031
13032
13033 \emph default 
13034  option.
13035  Notice that you don't have to call these routines directly.
13036  The compiler will use them automatically every time an integer operation
13037  is required.
13038 \layout Section
13039
13040 Floating Point Support
13041 \begin_inset LatexCommand \index{Floating point support}
13042
13043 \end_inset 
13044
13045
13046 \layout Standard
13047
13048 SDCC supports IEEE (single precision 4 bytes) floating point numbers.The
13049  floating point support routines are derived from gcc's floatlib.c and consist
13050  of the following routines:
13051 \newline 
13052
13053 \layout Standard
13054 \align center 
13055
13056 \size footnotesize 
13057
13058 \begin_inset  Tabular
13059 <lyxtabular version="3" rows="17" columns="2">
13060 <features>
13061 <column alignment="center" valignment="top" leftline="true" width="0">
13062 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
13063 <row topline="true" bottomline="true">
13064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13065 \begin_inset Text
13066
13067 \layout Standard
13068
13069
13070 \family roman 
13071 \series medium 
13072 \shape up 
13073 \size normal 
13074 \emph off 
13075 \bar no 
13076 \noun off 
13077 \color none
13078 Function 
13079 \end_inset 
13080 </cell>
13081 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13082 \begin_inset Text
13083
13084 \layout Standard
13085
13086 Description
13087 \end_inset 
13088 </cell>
13089 </row>
13090 <row topline="true">
13091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13092 \begin_inset Text
13093
13094 \layout Standard
13095
13096
13097 \family roman 
13098 \series medium 
13099 \shape up 
13100 \size normal 
13101 \emph off 
13102 \bar no 
13103 \noun off 
13104 \color none
13105 _fsadd.c
13106 \end_inset 
13107 </cell>
13108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13109 \begin_inset Text
13110
13111 \layout Standard
13112
13113
13114 \family roman 
13115 \series medium 
13116 \shape up 
13117 \size normal 
13118 \emph off 
13119 \bar no 
13120 \noun off 
13121 \color none
13122 add floating point numbers
13123 \end_inset 
13124 </cell>
13125 </row>
13126 <row topline="true">
13127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13128 \begin_inset Text
13129
13130 \layout Standard
13131
13132
13133 \family roman 
13134 \series medium 
13135 \shape up 
13136 \size normal 
13137 \emph off 
13138 \bar no 
13139 \noun off 
13140 \color none
13141 _fssub.c 
13142 \end_inset 
13143 </cell>
13144 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13145 \begin_inset Text
13146
13147 \layout Standard
13148
13149
13150 \family roman 
13151 \series medium 
13152 \shape up 
13153 \size normal 
13154 \emph off 
13155 \bar no 
13156 \noun off 
13157 \color none
13158 subtract floating point numbers 
13159 \end_inset 
13160 </cell>
13161 </row>
13162 <row topline="true">
13163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13164 \begin_inset Text
13165
13166 \layout Standard
13167
13168
13169 \family roman 
13170 \series medium 
13171 \shape up 
13172 \size normal 
13173 \emph off 
13174 \bar no 
13175 \noun off 
13176 \color none
13177 _fsdiv.c 
13178 \end_inset 
13179 </cell>
13180 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13181 \begin_inset Text
13182
13183 \layout Standard
13184
13185
13186 \family roman 
13187 \series medium 
13188 \shape up 
13189 \size normal 
13190 \emph off 
13191 \bar no 
13192 \noun off 
13193 \color none
13194 divide floating point numbers 
13195 \end_inset 
13196 </cell>
13197 </row>
13198 <row topline="true">
13199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13200 \begin_inset Text
13201
13202 \layout Standard
13203
13204
13205 \family roman 
13206 \series medium 
13207 \shape up 
13208 \size normal 
13209 \emph off 
13210 \bar no 
13211 \noun off 
13212 \color none
13213 _fsmul.c 
13214 \end_inset 
13215 </cell>
13216 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13217 \begin_inset Text
13218
13219 \layout Standard
13220
13221
13222 \family roman 
13223 \series medium 
13224 \shape up 
13225 \size normal 
13226 \emph off 
13227 \bar no 
13228 \noun off 
13229 \color none
13230 multiply floating point numbers 
13231 \end_inset 
13232 </cell>
13233 </row>
13234 <row topline="true">
13235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13236 \begin_inset Text
13237
13238 \layout Standard
13239
13240
13241 \family roman 
13242 \series medium 
13243 \shape up 
13244 \size normal 
13245 \emph off 
13246 \bar no 
13247 \noun off 
13248 \color none
13249 _fs2uchar.c
13250 \end_inset 
13251 </cell>
13252 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13253 \begin_inset Text
13254
13255 \layout Standard
13256
13257
13258 \family roman 
13259 \series medium 
13260 \shape up 
13261 \size normal 
13262 \emph off 
13263 \bar no 
13264 \noun off 
13265 \color none
13266 convert floating point to unsigned char
13267 \end_inset 
13268 </cell>
13269 </row>
13270 <row topline="true">
13271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13272 \begin_inset Text
13273
13274 \layout Standard
13275
13276
13277 \family roman 
13278 \series medium 
13279 \shape up 
13280 \size normal 
13281 \emph off 
13282 \bar no 
13283 \noun off 
13284 \color none
13285 _fs2char.c
13286 \end_inset 
13287 </cell>
13288 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13289 \begin_inset Text
13290
13291 \layout Standard
13292
13293
13294 \family roman 
13295 \series medium 
13296 \shape up 
13297 \size normal 
13298 \emph off 
13299 \bar no 
13300 \noun off 
13301 \color none
13302 convert floating point to signed char
13303 \end_inset 
13304 </cell>
13305 </row>
13306 <row topline="true">
13307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13308 \begin_inset Text
13309
13310 \layout Standard
13311
13312
13313 \family roman 
13314 \series medium 
13315 \shape up 
13316 \size normal 
13317 \emph off 
13318 \bar no 
13319 \noun off 
13320 \color none
13321 _fs2uint.c
13322 \end_inset 
13323 </cell>
13324 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13325 \begin_inset Text
13326
13327 \layout Standard
13328
13329
13330 \family roman 
13331 \series medium 
13332 \shape up 
13333 \size normal 
13334 \emph off 
13335 \bar no 
13336 \noun off 
13337 \color none
13338 convert floating point to unsigned int
13339 \end_inset 
13340 </cell>
13341 </row>
13342 <row topline="true">
13343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13344 \begin_inset Text
13345
13346 \layout Standard
13347
13348
13349 \family roman 
13350 \series medium 
13351 \shape up 
13352 \size normal 
13353 \emph off 
13354 \bar no 
13355 \noun off 
13356 \color none
13357 _fs2int.c
13358 \end_inset 
13359 </cell>
13360 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13361 \begin_inset Text
13362
13363 \layout Standard
13364
13365
13366 \family roman 
13367 \series medium 
13368 \shape up 
13369 \size normal 
13370 \emph off 
13371 \bar no 
13372 \noun off 
13373 \color none
13374 convert floating point to signed int
13375 \end_inset 
13376 </cell>
13377 </row>
13378 <row topline="true">
13379 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13380 \begin_inset Text
13381
13382 \layout Standard
13383
13384
13385 \family roman 
13386 \series medium 
13387 \shape up 
13388 \size normal 
13389 \emph off 
13390 \bar no 
13391 \noun off 
13392 \color none
13393 _fs2ulong.
13394 \family default 
13395 \series default 
13396 \shape default 
13397 \size default 
13398 \emph default 
13399 \bar default 
13400 \noun default 
13401 \color default
13402 c
13403 \end_inset 
13404 </cell>
13405 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13406 \begin_inset Text
13407
13408 \layout Standard
13409
13410
13411 \family roman 
13412 \series medium 
13413 \shape up 
13414 \size normal 
13415 \emph off 
13416 \bar no 
13417 \noun off 
13418 \color none
13419 convert floating point to unsigned long
13420 \end_inset 
13421 </cell>
13422 </row>
13423 <row topline="true">
13424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13425 \begin_inset Text
13426
13427 \layout Standard
13428
13429
13430 \family roman 
13431 \series medium 
13432 \shape up 
13433 \size normal 
13434 \emph off 
13435 \bar no 
13436 \noun off 
13437 \color none
13438 _fs2long.c
13439 \end_inset 
13440 </cell>
13441 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13442 \begin_inset Text
13443
13444 \layout Standard
13445
13446
13447 \family roman 
13448 \series medium 
13449 \shape up 
13450 \size normal 
13451 \emph off 
13452 \bar no 
13453 \noun off 
13454 \color none
13455 convert floating point to signed long
13456 \end_inset 
13457 </cell>
13458 </row>
13459 <row topline="true">
13460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13461 \begin_inset Text
13462
13463 \layout Standard
13464
13465
13466 \family roman 
13467 \series medium 
13468 \shape up 
13469 \size normal 
13470 \emph off 
13471 \bar no 
13472 \noun off 
13473 \color none
13474 _uchar2fs.c
13475 \end_inset 
13476 </cell>
13477 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13478 \begin_inset Text
13479
13480 \layout Standard
13481
13482
13483 \family roman 
13484 \series medium 
13485 \shape up 
13486 \size normal 
13487 \emph off 
13488 \bar no 
13489 \noun off 
13490 \color none
13491 convert unsigned char to floating point
13492 \end_inset 
13493 </cell>
13494 </row>
13495 <row topline="true">
13496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13497 \begin_inset Text
13498
13499 \layout Standard
13500
13501
13502 \family roman 
13503 \series medium 
13504 \shape up 
13505 \size normal 
13506 \emph off 
13507 \bar no 
13508 \noun off 
13509 \color none
13510 _char2fs.c
13511 \end_inset 
13512 </cell>
13513 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13514 \begin_inset Text
13515
13516 \layout Standard
13517
13518
13519 \family roman 
13520 \series medium 
13521 \shape up 
13522 \size normal 
13523 \emph off 
13524 \bar no 
13525 \noun off 
13526 \color none
13527 convert char to floating point number
13528 \end_inset 
13529 </cell>
13530 </row>
13531 <row topline="true">
13532 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13533 \begin_inset Text
13534
13535 \layout Standard
13536
13537
13538 \family roman 
13539 \series medium 
13540 \shape up 
13541 \size normal 
13542 \emph off 
13543 \bar no 
13544 \noun off 
13545 \color none
13546 _uint2fs.c
13547 \end_inset 
13548 </cell>
13549 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13550 \begin_inset Text
13551
13552 \layout Standard
13553
13554
13555 \family roman 
13556 \series medium 
13557 \shape up 
13558 \size normal 
13559 \emph off 
13560 \bar no 
13561 \noun off 
13562 \color none
13563 convert unsigned int to floating point
13564 \end_inset 
13565 </cell>
13566 </row>
13567 <row topline="true">
13568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13569 \begin_inset Text
13570
13571 \layout Standard
13572
13573
13574 \family roman 
13575 \series medium 
13576 \shape up 
13577 \size normal 
13578 \emph off 
13579 \bar no 
13580 \noun off 
13581 \color none
13582 _int2fs.c
13583 \end_inset 
13584 </cell>
13585 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13586 \begin_inset Text
13587
13588 \layout Standard
13589
13590
13591 \family roman 
13592 \series medium 
13593 \shape up 
13594 \size normal 
13595 \emph off 
13596 \bar no 
13597 \noun off 
13598 \color none
13599 convert int to floating point numbers
13600 \end_inset 
13601 </cell>
13602 </row>
13603 <row topline="true">
13604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13605 \begin_inset Text
13606
13607 \layout Standard
13608
13609
13610 \family roman 
13611 \series medium 
13612 \shape up 
13613 \size normal 
13614 \emph off 
13615 \bar no 
13616 \noun off 
13617 \color none
13618 _ulong2fs.c
13619 \end_inset 
13620 </cell>
13621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13622 \begin_inset Text
13623
13624 \layout Standard
13625
13626
13627 \family roman 
13628 \series medium 
13629 \shape up 
13630 \size normal 
13631 \emph off 
13632 \bar no 
13633 \noun off 
13634 \color none
13635 convert unsigned long to floating point number
13636 \end_inset 
13637 </cell>
13638 </row>
13639 <row topline="true" bottomline="true">
13640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13641 \begin_inset Text
13642
13643 \layout Standard
13644
13645
13646 \family roman 
13647 \series medium 
13648 \shape up 
13649 \size normal 
13650 \emph off 
13651 \bar no 
13652 \noun off 
13653 \color none
13654 _long2fs.c
13655 \end_inset 
13656 </cell>
13657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13658 \begin_inset Text
13659
13660 \layout Standard
13661
13662
13663 \family roman 
13664 \series medium 
13665 \shape up 
13666 \size normal 
13667 \emph off 
13668 \bar no 
13669 \noun off 
13670 \color none
13671 convert long to floating point number
13672 \end_inset 
13673 </cell>
13674 </row>
13675 </lyxtabular>
13676
13677 \end_inset 
13678
13679
13680 \newline 
13681
13682 \layout Standard
13683
13684 These support routines are developed in ANSI-C so there is room for space
13685  and speed improvement.
13686  Note if all these routines are used simultaneously the data space might
13687  overflow.
13688  For serious floating point usage it is recommended that the large model
13689  be used.
13690  Also notice that you don't have to call this routines directly.
13691  The compiler will use them automatically every time a floating point operation
13692  is required.
13693 \layout Section
13694
13695 Library Routines
13696 \begin_inset LatexCommand \index{Libraries}
13697
13698 \end_inset 
13699
13700
13701 \layout Standard
13702
13703
13704 \emph on 
13705 <pending: this is messy and incomplete - a little more information is in
13706  sdcc/doc/libdoc.txt
13707 \emph default 
13708  >
13709 \layout Subsection
13710
13711 Compiler support routines (_gptrget, _mulint etc.)
13712 \layout Subsection
13713
13714 Stdclib functions (puts, printf, strcat etc.)
13715 \layout Subsubsection
13716
13717 <stdio.h>
13718 \layout Standard
13719
13720
13721 \begin_inset LatexCommand \index{<stdio.h>}
13722
13723 \end_inset 
13724
13725 As usual on embedded systems you have to provide your own 
13726 \family typewriter 
13727 getchar()
13728 \begin_inset LatexCommand \index{getchar()}
13729
13730 \end_inset 
13731
13732  
13733 \family default 
13734 and 
13735 \family typewriter 
13736 putchar()
13737 \begin_inset LatexCommand \index{putchar()}
13738
13739 \end_inset 
13740
13741
13742 \family default 
13743  routines.
13744  SDCC does not know whether the system connects to a serial line with or
13745  without handshake, LCD, keyboard or other device.
13746  You'll find examples for serial routines f.e.
13747  in sdcc/device/lib.
13748 \layout Standard
13749
13750 The default
13751 \family typewriter 
13752  printf()
13753 \begin_inset LatexCommand \index{printf()}
13754
13755 \end_inset 
13756
13757
13758 \family default 
13759 implementation in
13760 \family typewriter 
13761  printf_large.c
13762 \family default 
13763  does not support float (except on ds390).
13764  To enable this recompile it with the option 
13765 \emph on 
13766 -
13767 \begin_inset ERT
13768 status Collapsed
13769
13770 \layout Standard
13771
13772 \backslash 
13773 /
13774 \end_inset 
13775
13776 DUSE_FLOATS=1
13777 \begin_inset LatexCommand \index{USE\_FLOATS}
13778
13779 \end_inset 
13780
13781
13782 \emph default 
13783  on the command line.
13784  Use
13785 \emph on 
13786 -
13787 \begin_inset ERT
13788 status Collapsed
13789
13790 \layout Standard
13791
13792 \backslash 
13793 /
13794 \end_inset 
13795
13796 -model-large
13797 \begin_inset LatexCommand \index{-\/-model-large}
13798
13799 \end_inset 
13800
13801
13802 \emph default 
13803  for the mcs51 port, since this uses a lot of memory.
13804 \layout Standard
13805
13806 If you're short on memory you might want to use 
13807 \family typewriter 
13808 printf_small()
13809 \family default 
13810  
13811 \emph on 
13812 instead
13813 \emph default 
13814  of
13815 \family typewriter 
13816  printf().
13817
13818 \family default 
13819  For the mcs51 there is an assembly version 
13820 \family typewriter 
13821 printf_fast()
13822 \family default 
13823  which should fit the requirements of many embedded systems (by unsetting
13824  #defines it can be customized to 
13825 \emph on 
13826 not
13827 \emph default 
13828  support long variables and field widths).
13829 \layout Subsection
13830
13831 Math functions (sin, pow, sqrt etc.)
13832 \layout Subsection
13833
13834 Other libraries
13835 \layout Standard
13836
13837 Libraries
13838 \begin_inset LatexCommand \index{Libraries}
13839
13840 \end_inset 
13841
13842  included in SDCC should have a license at least as liberal as the GNU Lesser
13843  General Public License
13844 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
13845
13846 \end_inset 
13847
13848  
13849 \emph on 
13850 LGPL
13851 \emph default 
13852 .
13853 \layout Comment
13854
13855 license statements for the libraries are missing.
13856  sdcc/device/lib/ser_ir.c
13857 \layout Comment
13858
13859 or _decdptr f.e.
13860  come with a GPL (as opposed to LGPL) License - this will not be liberal
13861  enough for many embedded programmers.
13862 \layout Standard
13863
13864 If you have ported some library or want to share experience about some code
13865  which f.e.
13866  falls into any of these categories Busses (I
13867 \begin_inset Formula $^{\textrm{2}}$
13868 \end_inset 
13869
13870 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
13871  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
13872  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
13873 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
13874
13875 \end_inset 
13876
13877 \SpecialChar ~
13878 would certainly like to hear about it.
13879  Programmers coding for embedded systems are not especially famous for being
13880  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
13881 e these references are very valuable.
13882  Let's help to create a climate where information is shared.
13883 \layout Section
13884
13885 Memory Models
13886 \layout Subsection
13887
13888 MCS51 Memory Models
13889 \begin_inset LatexCommand \index{Memory model}
13890
13891 \end_inset 
13892
13893
13894 \begin_inset LatexCommand \index{MCS51 memory model}
13895
13896 \end_inset 
13897
13898
13899 \layout Subsubsection
13900
13901 Small and Large
13902 \layout Standard
13903
13904 SDCC allows two memory models for MCS51 code, 
13905 \shape slanted 
13906 small
13907 \shape default 
13908  and 
13909 \shape slanted 
13910 large
13911 \shape default 
13912 .
13913  Modules compiled with different memory models should 
13914 \emph on 
13915 never
13916 \emph default 
13917  be combined together or the results would be unpredictable.
13918  The library routines supplied with the compiler are compiled as both small
13919  and large.
13920  The compiled library modules are contained in separate directories as small
13921  and large so that you can link to either set.
13922  
13923 \layout Standard
13924
13925 When the large model is used all variables declared without a storage class
13926  will be allocated into the external ram, this includes all parameters and
13927  local variables (for non-reentrant
13928 \begin_inset LatexCommand \index{reentrant}
13929
13930 \end_inset 
13931
13932  functions).
13933  When the small model is used variables without storage class are allocated
13934  in the internal ram.
13935 \layout Standard
13936
13937 Judicious usage of the processor specific storage classes
13938 \begin_inset LatexCommand \index{Storage class}
13939
13940 \end_inset 
13941
13942  and the 'reentrant' function type will yield much more efficient code,
13943  than using the large model.
13944  Several optimizations are disabled when the program is compiled using the
13945  large model, it is therefore recommended that the small model be used unless
13946  absolutely required.
13947 \layout Subsubsection
13948
13949 External Stack
13950 \begin_inset LatexCommand \label{sub:External-Stack}
13951
13952 \end_inset 
13953
13954
13955 \begin_inset LatexCommand \index{stack}
13956
13957 \end_inset 
13958
13959
13960 \begin_inset LatexCommand \index{External stack (mcs51)}
13961
13962 \end_inset 
13963
13964
13965 \layout Standard
13966
13967
13968 \series bold 
13969 Attention
13970 \series default 
13971 : this option wasn't maintained for a long time and is quite buggy.
13972  Small programs might work.
13973  You've been warned!
13974 \layout Standard
13975
13976 The external stack (-
13977 \begin_inset ERT
13978 status Collapsed
13979
13980 \layout Standard
13981
13982 \backslash 
13983 /
13984 \end_inset 
13985
13986 -xstack option
13987 \begin_inset LatexCommand \index{-\/-xstack}
13988
13989 \end_inset 
13990
13991 ) is located in pdata
13992 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
13993
13994 \end_inset 
13995
13996  memory (usually at the start of the external ram segment) and is 256 bytes
13997  in size.
13998  When -
13999 \begin_inset ERT
14000 status Collapsed
14001
14002 \layout Standard
14003
14004 \backslash 
14005 /
14006 \end_inset 
14007
14008 -xstack option is used to compile the program, the parameters and local
14009  variables
14010 \begin_inset LatexCommand \index{local variables}
14011
14012 \end_inset 
14013
14014  of all reentrant functions are allocated in this area.
14015  This option is provided for programs with large stack space requirements.
14016  When used with the -
14017 \begin_inset ERT
14018 status Collapsed
14019
14020 \layout Standard
14021
14022 \backslash 
14023 /
14024 \end_inset 
14025
14026 -stack-auto
14027 \begin_inset LatexCommand \index{-\/-stack-auto}
14028
14029 \end_inset 
14030
14031  option, all parameters and local variables are allocated on the external
14032  stack (note: support libraries will need to be recompiled with the same
14033  options).
14034 \layout Standard
14035
14036 The compiler outputs the higher order address byte of the external ram segment
14037  into port P2
14038 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
14039
14040 \end_inset 
14041
14042  (see also section 
14043 \begin_inset LatexCommand \ref{sub:MCS51-variants}
14044
14045 \end_inset 
14046
14047 ), therefore when using the External Stack option, this port 
14048 \emph on 
14049 may not
14050 \emph default 
14051  be used by the application program.
14052 \layout Subsection
14053
14054 DS390 Memory Model
14055 \begin_inset LatexCommand \index{Memory model}
14056
14057 \end_inset 
14058
14059
14060 \begin_inset LatexCommand \index{DS390 memory model}
14061
14062 \end_inset 
14063
14064
14065 \layout Standard
14066
14067 The only model supported is Flat 24
14068 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
14069
14070 \end_inset 
14071
14072 .
14073  This generates code for the 24 bit contiguous addressing mode of the Dallas
14074  DS80C390 part.
14075  In this mode, up to four meg of external RAM or code space can be directly
14076  addressed.
14077  See the data sheets at www.dalsemi.com for further information on this part.
14078 \newline 
14079
14080 \newline 
14081 Note that the compiler does not generate any code to place the processor
14082  into 24 bitmode (although 
14083 \emph on 
14084 tinibios
14085 \emph default 
14086  in the ds390 libraries will do that for you).
14087  If you don't use 
14088 \emph on 
14089 tinibios
14090 \emph default 
14091
14092 \begin_inset LatexCommand \index{Tinibios (DS390)}
14093
14094 \end_inset 
14095
14096 , the boot loader or similar code must ensure that the processor is in 24
14097  bit contiguous addressing mode before calling the SDCC startup code.
14098 \newline 
14099
14100 \newline 
14101 Like the 
14102 \emph on 
14103 -
14104 \begin_inset ERT
14105 status Collapsed
14106
14107 \layout Standard
14108
14109 \backslash 
14110 /
14111 \end_inset 
14112
14113 -model-large
14114 \emph default 
14115  option, variables will by default be placed into the XDATA segment.
14116  
14117 \newline 
14118
14119 \newline 
14120 Segments may be placed anywhere in the 4 meg address space using the usual
14121  -
14122 \begin_inset ERT
14123 status Collapsed
14124
14125 \layout Standard
14126
14127 \backslash 
14128 /
14129 \end_inset 
14130
14131 -*-loc options.
14132  Note that if any segments are located above 64K, the -r flag must be passed
14133  to the linker to generate the proper segment relocations, and the Intel
14134  HEX output format must be used.
14135  The -r flag can be passed to the linker by using the option 
14136 \emph on 
14137 -Wl-r
14138 \emph default 
14139  on the SDCC command line.
14140  However, currently the linker can not handle code segments > 64k.
14141 \layout Section
14142
14143 Pragmas
14144 \begin_inset LatexCommand \index{Pragmas}
14145
14146 \end_inset 
14147
14148
14149 \layout Standard
14150
14151 SDCC supports the following #pragma directives:
14152 \layout Itemize
14153
14154 save
14155 \begin_inset LatexCommand \index{\#pragma save}
14156
14157 \end_inset 
14158
14159  - this will save all current options to the save/restore stack.
14160  See #pragma\SpecialChar ~
14161 restore.
14162 \layout Itemize
14163
14164 restore
14165 \begin_inset LatexCommand \index{\#pragma restore}
14166
14167 \end_inset 
14168
14169  - will restore saved options from the last save.
14170  saves & restores can be nested.
14171  SDCC uses a save/restore stack: save pushes current options to the stack,
14172  restore pulls current options from the stack.
14173  See #pragma\SpecialChar ~
14174 save.
14175 \newline 
14176
14177 \layout Itemize
14178
14179 callee_saves
14180 \begin_inset LatexCommand \index{\#pragma callee\_saves}
14181
14182 \end_inset 
14183
14184
14185 \begin_inset LatexCommand \index{function prologue}
14186
14187 \end_inset 
14188
14189  function1[,function2[,function3...]] - The compiler by default uses a caller
14190  saves convention for register saving across function calls, however this
14191  can cause unnecessary register pushing & popping
14192 \begin_inset LatexCommand \index{push/pop}
14193
14194 \end_inset 
14195
14196  when calling small functions from larger functions.
14197  This option can be used to switch off the register saving convention for
14198  the function names specified.
14199  The compiler will not save registers when calling these functions, extra
14200  code need to be manually inserted at the entry & exit for these functions
14201  to save & restore the registers used by these functions, this can SUBSTANTIALLY
14202  reduce code & improve run time performance of the generated code.
14203  In the future the compiler (with inter procedural analysis) may be able
14204  to determine the appropriate scheme to use for each function call.
14205  If -
14206 \begin_inset ERT
14207 status Collapsed
14208
14209 \layout Standard
14210
14211 \backslash 
14212 /
14213 \end_inset 
14214
14215 -callee-saves command line option is used, the function names specified
14216  in #pragma\SpecialChar ~
14217 callee_saves
14218 \begin_inset LatexCommand \index{\#pragma callee\_saves}
14219
14220 \end_inset 
14221
14222  is appended to the list of functions specified in the command line.
14223 \layout Itemize
14224
14225 exclude
14226 \begin_inset LatexCommand \index{\#pragma exclude}
14227
14228 \end_inset 
14229
14230  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
14231  of pairs of push/pop
14232 \begin_inset LatexCommand \index{push/pop}
14233
14234 \end_inset 
14235
14236  instructions in 
14237 \emph on 
14238 I
14239 \emph default 
14240 nterrupt
14241 \begin_inset LatexCommand \index{interrupt}
14242
14243 \end_inset 
14244
14245  
14246 \emph on 
14247 S
14248 \emph default 
14249 ervice 
14250 \emph on 
14251 R
14252 \emph default 
14253 outines.
14254  The directive should be placed immediately before the ISR function definition
14255  and it affects ALL ISR functions following it.
14256  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
14257 exclude\SpecialChar ~
14258 none
14259 \begin_inset LatexCommand \index{\#pragma exclude}
14260
14261 \end_inset 
14262
14263 .
14264  See also the related keyword _naked
14265 \begin_inset LatexCommand \index{\_naked}
14266
14267 \end_inset 
14268
14269 .
14270 \layout Itemize
14271
14272 less_pedantic
14273 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
14274
14275 \end_inset 
14276
14277  - the compiler will not warn you anymore for obvious mistakes, you'r on
14278  your own now ;-(
14279 \layout Itemize
14280
14281 disable_warning <nnnn>
14282 \begin_inset LatexCommand \index{\#pragma disable\_warning}
14283
14284 \end_inset 
14285
14286  - the compiler will not warn you anymore about warning number <nnnn>.
14287 \layout Itemize
14288
14289 nogcse
14290 \begin_inset LatexCommand \index{\#pragma nogcse}
14291
14292 \end_inset 
14293
14294  - will stop global common subexpression elimination.
14295 \layout Itemize
14296
14297 noinduction
14298 \begin_inset LatexCommand \index{\#pragma noinduction}
14299
14300 \end_inset 
14301
14302  - will stop loop induction optimizations.
14303 \layout Itemize
14304
14305 noinvariant
14306 \begin_inset LatexCommand \index{\#pragma noinvariant}
14307
14308 \end_inset 
14309
14310  - will not do loop invariant optimizations.
14311  For more details see Loop Invariants in section
14312 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
14313
14314 \end_inset 
14315
14316 .
14317 \layout Itemize
14318
14319 noiv
14320 \begin_inset LatexCommand \index{\#pragma noiv}
14321
14322 \end_inset 
14323
14324  - Do not generate interrupt
14325 \begin_inset LatexCommand \index{interrupt}
14326
14327 \end_inset 
14328
14329  vector table entries for all ISR functions defined after the pragma.
14330  This is useful in cases where the interrupt vector table must be defined
14331  manually, or when there is a secondary, manually defined interrupt vector
14332  table (e.g.
14333  for the autovector feature of the Cypress EZ-USB FX2).
14334  More elegantly this can be achieved by obmitting the optional interrupt
14335  number after the interrupt keyword, see section 
14336 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
14337
14338 \end_inset 
14339
14340 \SpecialChar ~
14341 about interrupts.
14342 \layout Itemize
14343
14344 nojtbound
14345 \begin_inset LatexCommand \index{\#pragma nojtbound}
14346
14347 \end_inset 
14348
14349  - will not generate code for boundary value checking, when switch statements
14350  are turned into jump-tables (dangerous).
14351  For more details see section 
14352 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
14353
14354 \end_inset 
14355
14356 .
14357 \layout Itemize
14358
14359 noloopreverse
14360 \begin_inset LatexCommand \index{\#pragma noloopreverse}
14361
14362 \end_inset 
14363
14364  - Will not do loop reversal optimization
14365 \layout Itemize
14366
14367 nooverlay
14368 \begin_inset LatexCommand \index{\#pragma nooverlay}
14369
14370 \end_inset 
14371
14372  - the compiler will not overlay the parameters and local variables of a
14373  function.
14374 \layout Itemize
14375
14376 stackauto
14377 \begin_inset LatexCommand \index{\#pragma stackauto}
14378
14379 \end_inset 
14380
14381 - See option -
14382 \begin_inset ERT
14383 status Collapsed
14384
14385 \layout Standard
14386
14387 \backslash 
14388 /
14389 \end_inset 
14390
14391 -stack-auto
14392 \begin_inset LatexCommand \index{-\/-stack-auto}
14393
14394 \end_inset 
14395
14396  and section 
14397 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
14398
14399 \end_inset 
14400
14401  Parameters and Local Variables.
14402 \layout Itemize
14403
14404 opt_code_speed 
14405 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
14406
14407 \end_inset 
14408
14409 - The compiler will optimize code generation towards fast code, possibly
14410  at the expense of code size.
14411 \layout Itemize
14412
14413 opt_code_size 
14414 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
14415
14416 \end_inset 
14417
14418 - The compiler will optimize code generation towards compact code, possibly
14419  at the expense of code speed.
14420 \layout Itemize
14421
14422 opt_code_balanced 
14423 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
14424
14425 \end_inset 
14426
14427 - The compiler will attempt to generate code that is both compact and fast,
14428  as long as meeting one goal is not a detriment to the other (this is the
14429  default).
14430  
14431 \layout Standard
14432
14433 SDCPP supports the following #pragma directives:
14434 \layout Itemize
14435
14436 preproc_asm
14437 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
14438
14439 \end_inset 
14440
14441  (+ | -) - switch _asm _endasm block preprocessing on / off.
14442  Default is on.
14443 \layout Standard
14444
14445 The pragma's are intended to be used to turn-on or off certain optimizations
14446  which might cause the compiler to generate extra stack / data space to
14447  store compiler generated temporary variables.
14448  This usually happens in large functions.
14449  Pragma directives should be used as shown in the following example, they
14450  are used to control options & optimizations for a given function; pragmas
14451  should be placed before and/or after a function, placing pragma's inside
14452  a function body could have unpredictable results.
14453 \layout Verse
14454
14455
14456 \family typewriter 
14457 #pragma save
14458 \begin_inset LatexCommand \index{\#pragma save}
14459
14460 \end_inset 
14461
14462  \SpecialChar ~
14463 \SpecialChar ~
14464 \SpecialChar ~
14465 \SpecialChar ~
14466 \SpecialChar ~
14467 \SpecialChar ~
14468 \SpecialChar ~
14469 /* save the current settings */ 
14470 \newline 
14471 #pragma nogcse
14472 \begin_inset LatexCommand \index{\#pragma nogcse}
14473
14474 \end_inset 
14475
14476  \SpecialChar ~
14477 \SpecialChar ~
14478 \SpecialChar ~
14479 \SpecialChar ~
14480 \SpecialChar ~
14481 /* turnoff global subexpression elimination */ 
14482 \newline 
14483 #pragma noinduction
14484 \begin_inset LatexCommand \index{\#pragma noinduction}
14485
14486 \end_inset 
14487
14488  /* turn off induction optimizations */ 
14489 \newline 
14490 int foo () 
14491 \newline 
14492
14493 \newline 
14494 \SpecialChar ~
14495  \SpecialChar ~
14496  ...
14497  
14498 \newline 
14499 \SpecialChar ~
14500  \SpecialChar ~
14501  /* large code */ 
14502 \newline 
14503 \SpecialChar ~
14504  \SpecialChar ~
14505  ...
14506  
14507 \newline 
14508
14509 \newline 
14510 #pragma restore
14511 \begin_inset LatexCommand \index{\#pragma restore}
14512
14513 \end_inset 
14514
14515  /* turn the optimizations back on */
14516 \layout Standard
14517
14518 The compiler will generate a warning message when extra space is allocated.
14519  It is strongly recommended that the save and restore pragma's be used when
14520  changing options for a function.
14521 \layout Section
14522
14523 Defines Created by the Compiler
14524 \layout Standard
14525
14526 The compiler creates the following #defines
14527 \begin_inset LatexCommand \index{\#defines}
14528
14529 \end_inset 
14530
14531
14532 \begin_inset LatexCommand \index{Defines created by the compiler}
14533
14534 \end_inset 
14535
14536 :
14537 \newline 
14538
14539 \layout Standard
14540
14541
14542 \begin_inset  Tabular
14543 <lyxtabular version="3" rows="10" columns="2">
14544 <features>
14545 <column alignment="center" valignment="top" leftline="true" width="0">
14546 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
14547 <row topline="true" bottomline="true">
14548 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14549 \begin_inset Text
14550
14551 \layout Standard
14552
14553
14554 \series bold 
14555 #define
14556 \end_inset 
14557 </cell>
14558 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14559 \begin_inset Text
14560
14561 \layout Standard
14562
14563
14564 \series bold 
14565 Description
14566 \end_inset 
14567 </cell>
14568 </row>
14569 <row topline="true">
14570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14571 \begin_inset Text
14572
14573 \layout Standard
14574
14575 SDCC
14576 \begin_inset LatexCommand \index{SDCC}
14577
14578 \end_inset 
14579
14580  
14581 \end_inset 
14582 </cell>
14583 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14584 \begin_inset Text
14585
14586 \layout Standard
14587
14588 this Symbol is always defined
14589 \end_inset 
14590 </cell>
14591 </row>
14592 <row topline="true">
14593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14594 \begin_inset Text
14595
14596 \layout Standard
14597
14598 SDCC_mcs51
14599 \begin_inset LatexCommand \index{SDCC\_mcs51}
14600
14601 \end_inset 
14602
14603  or SDCC_ds390
14604 \begin_inset LatexCommand \index{SDCC\_ds390}
14605
14606 \end_inset 
14607
14608  or SDCC_z80
14609 \begin_inset LatexCommand \index{SDCC\_z80}
14610
14611 \end_inset 
14612
14613 , etc
14614 \end_inset 
14615 </cell>
14616 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14617 \begin_inset Text
14618
14619 \layout Standard
14620
14621 depending on the model used (e.g.: -mds390
14622 \end_inset 
14623 </cell>
14624 </row>
14625 <row topline="true">
14626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14627 \begin_inset Text
14628
14629 \layout Standard
14630
14631 __mcs51
14632 \begin_inset LatexCommand \index{\_\_mcs51}
14633
14634 \end_inset 
14635
14636 , __ds390
14637 \begin_inset LatexCommand \index{\_\_ds390}
14638
14639 \end_inset 
14640
14641 , __hc08
14642 \begin_inset LatexCommand \index{\_\_hc08}
14643
14644 \end_inset 
14645
14646 , __z80
14647 \begin_inset LatexCommand \index{\_\_z80}
14648
14649 \end_inset 
14650
14651 , etc
14652 \end_inset 
14653 </cell>
14654 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14655 \begin_inset Text
14656
14657 \layout Standard
14658
14659 depending on the model used (e.g.
14660  -mz80)
14661 \end_inset 
14662 </cell>
14663 </row>
14664 <row topline="true">
14665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14666 \begin_inset Text
14667
14668 \layout Standard
14669
14670 SDCC_STACK_AUTO
14671 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
14672
14673 \end_inset 
14674
14675
14676 \end_inset 
14677 </cell>
14678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14679 \begin_inset Text
14680
14681 \layout Standard
14682
14683 when 
14684 \emph on 
14685 -
14686 \begin_inset ERT
14687 status Collapsed
14688
14689 \layout Standard
14690
14691 \backslash 
14692 /
14693 \end_inset 
14694
14695 -stack-auto
14696 \emph default 
14697  option is used
14698 \end_inset 
14699 </cell>
14700 </row>
14701 <row topline="true">
14702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14703 \begin_inset Text
14704
14705 \layout Standard
14706
14707 SDCC_MODEL_SMALL
14708 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
14709
14710 \end_inset 
14711
14712
14713 \end_inset 
14714 </cell>
14715 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14716 \begin_inset Text
14717
14718 \layout Standard
14719
14720 when 
14721 \emph on 
14722 -
14723 \begin_inset ERT
14724 status Collapsed
14725
14726 \layout Standard
14727
14728 \backslash 
14729 /
14730 \end_inset 
14731
14732 -model-small
14733 \emph default 
14734  is used
14735 \end_inset 
14736 </cell>
14737 </row>
14738 <row topline="true">
14739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14740 \begin_inset Text
14741
14742 \layout Standard
14743
14744 SDCC_MODEL_LARGE
14745 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
14746
14747 \end_inset 
14748
14749
14750 \end_inset 
14751 </cell>
14752 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14753 \begin_inset Text
14754
14755 \layout Standard
14756
14757 when 
14758 \emph on 
14759 -
14760 \begin_inset ERT
14761 status Collapsed
14762
14763 \layout Standard
14764
14765 \backslash 
14766 /
14767 \end_inset 
14768
14769 -model-large
14770 \emph default 
14771  is used
14772 \end_inset 
14773 </cell>
14774 </row>
14775 <row topline="true">
14776 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14777 \begin_inset Text
14778
14779 \layout Standard
14780
14781 SDCC_USE_XSTACK
14782 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
14783
14784 \end_inset 
14785
14786
14787 \end_inset 
14788 </cell>
14789 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14790 \begin_inset Text
14791
14792 \layout Standard
14793
14794 when 
14795 \emph on 
14796 -
14797 \begin_inset ERT
14798 status Collapsed
14799
14800 \layout Standard
14801
14802 \backslash 
14803 /
14804 \end_inset 
14805
14806 -xstack
14807 \emph default 
14808  option is used
14809 \end_inset 
14810 </cell>
14811 </row>
14812 <row topline="true">
14813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14814 \begin_inset Text
14815
14816 \layout Standard
14817
14818 SDCC_STACK_TENBIT
14819 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
14820
14821 \end_inset 
14822
14823  
14824 \end_inset 
14825 </cell>
14826 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14827 \begin_inset Text
14828
14829 \layout Standard
14830
14831 when 
14832 \emph on 
14833 -mds390
14834 \emph default 
14835  is used
14836 \end_inset 
14837 </cell>
14838 </row>
14839 <row topline="true" bottomline="true">
14840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14841 \begin_inset Text
14842
14843 \layout Standard
14844
14845 SDCC_MODEL_FLAT24
14846 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
14847
14848 \end_inset 
14849
14850
14851 \end_inset 
14852 </cell>
14853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14854 \begin_inset Text
14855
14856 \layout Standard
14857
14858 when 
14859 \emph on 
14860 -mds390
14861 \emph default 
14862  is used
14863 \end_inset 
14864 </cell>
14865 </row>
14866 </lyxtabular>
14867
14868 \end_inset 
14869
14870
14871 \layout Chapter
14872
14873 Notes on supported Processors
14874 \layout Section
14875
14876 MCS51 variants
14877 \begin_inset LatexCommand \label{sub:MCS51-variants}
14878
14879 \end_inset 
14880
14881
14882 \begin_inset LatexCommand \index{MCS51 variants}
14883
14884 \end_inset 
14885
14886
14887 \layout Standard
14888
14889 MCS51 processors are available from many vendors and come in many different
14890  flavours.
14891  While they might differ considerably in respect to Special Function Registers
14892  the core MCS51 is usually not modified or is kept compatible.
14893  
14894 \layout Subsection
14895
14896 pdata access by SFR 
14897 \layout Standard
14898
14899 With the upcome of devices with internal xdata and flash memory devices
14900  using port P2
14901 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
14902
14903 \end_inset 
14904
14905  as dedicated I/O port is becoming more popular.
14906  Switching the high byte for pdata
14907 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
14908
14909 \end_inset 
14910
14911  access which was formerly done by port P2 is then achieved by a Special
14912  Function Register
14913 \begin_inset LatexCommand \index{sfr}
14914
14915 \end_inset 
14916
14917 .
14918  In well-established MCS51 tradition the address of this 
14919 \emph on 
14920 sfr
14921 \emph default 
14922  is where the chip designers decided to put it.
14923  Needless to say that they didn't agree on a common name either.
14924  So that the startup code can correctly initialize xdata variables, you
14925  should define an sfr with the name _XPAGE
14926 \family typewriter 
14927
14928 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
14929
14930 \end_inset 
14931
14932
14933 \family default 
14934  at the appropriate location if the default, port P2, is not used for this.
14935  Some examples are:
14936 \layout Verse
14937
14938
14939 \family typewriter 
14940 sfr at 0x92 _XPAGE; /* Cypress EZ-USB family */
14941 \layout Verse
14942
14943
14944 \family typewriter 
14945 sfr at 0xaf _XPAGE; /* some Silicon Labs (Cygnal) chips */
14946 \layout Verse
14947
14948
14949 \family typewriter 
14950 sfr at 0xaa _XPAGE; /* some Silicon Labs (Cygnal) chips */
14951 \layout Standard
14952
14953 For more exotic implementations further customizations may be needed.
14954  See section 
14955 \begin_inset LatexCommand \ref{sub:Startup-Code}
14956
14957 \end_inset 
14958
14959  for other possibilities.
14960 \layout Subsection
14961
14962 Other Features available by SFR
14963 \layout Standard
14964
14965 Some MCS51 variants offer features like Double DPTR
14966 \begin_inset LatexCommand \index{DPTR}
14967
14968 \end_inset 
14969
14970 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
14971  These are currently not used for the MCS51 port.
14972  If you absolutely need them you can fall back to inline assembly or submit
14973  a patch to SDCC.
14974 \layout Section
14975
14976 DS400 port
14977 \layout Standard
14978
14979 The DS80C400 microcontroller has a rich set of peripherals.
14980  In its built-in ROM library it includes functions to access some of the
14981  features, among them is a TCP stack with IP4 and IP6 support.
14982  Library headers (currently in beta status) and other files are provided
14983  at 
14984 \size footnotesize 
14985
14986 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
14987
14988 \end_inset 
14989
14990 .
14991  
14992 \layout Section
14993
14994 The Z80 and gbz80 port
14995 \layout Standard
14996
14997 SDCC can target both the Zilog 
14998 \begin_inset LatexCommand \index{Z80}
14999
15000 \end_inset 
15001
15002  and the Nintendo Gameboy's Z80-like gbz80
15003 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
15004
15005 \end_inset 
15006
15007 .
15008  The Z80 port is passed through the same 
15009 \emph on 
15010 regressions tests
15011 \begin_inset LatexCommand \index{Regression test}
15012
15013 \end_inset 
15014
15015
15016 \emph default 
15017  as the MCS51 and DS390 ports, so floating point support, support for long
15018  variables and bitfield support is fine.
15019  See mailing lists and forums about interrupt routines.
15020 \layout Standard
15021
15022 As always, the code is the authoritative reference - see z80/ralloc.c and
15023  z80/gen.c.
15024  The stack
15025 \begin_inset LatexCommand \index{stack}
15026
15027 \end_inset 
15028
15029  frame is similar to that generated by the IAR Z80 compiler.
15030  IX is used as the base pointer, HL and IY are used as a temporary registers,
15031  and BC and DE are available for holding variables.
15032  Return values
15033 \begin_inset LatexCommand \index{return value}
15034
15035 \end_inset 
15036
15037  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
15038  bytes).
15039  The gbz80 port use the same set of registers for the return values, but
15040  in a different order of significance: E (one byte), DE (two bytes), or
15041  HLDE (four bytes).
15042 \layout Section
15043
15044 The HC08 port
15045 \layout Standard
15046
15047 The port to the Motorola HC08
15048 \begin_inset LatexCommand \index{HC08}
15049
15050 \end_inset 
15051
15052  family has been added in October 2003, and is still undergoing some basic
15053  development.
15054  The code generator is complete, but the register allocation is still quite
15055  unoptimized.
15056  Some of the SDCC's standard C library functions have embedded non-HC08
15057  inline assembly and so are not yet usable.
15058 \newline 
15059
15060 \newline 
15061
15062 \layout Section
15063
15064 The PIC14 port
15065 \layout Standard
15066
15067 The 14bit PIC
15068 \begin_inset LatexCommand \index{PIC14}
15069
15070 \end_inset 
15071
15072  port still requires a major effort from the development community.
15073  However it can work for very simple code.
15074 \layout Subsection
15075
15076 C code and 14bit PIC code page
15077 \begin_inset LatexCommand \index{code page (pic14)}
15078
15079 \end_inset 
15080
15081  and RAM banks
15082 \begin_inset LatexCommand \index{RAM bank (pic14)}
15083
15084 \end_inset 
15085
15086
15087 \layout Standard
15088
15089 The linker organizes allocation for the code page and RAM banks.
15090  It does not have intimate knowledge of the code flow.
15091  It will put all the code section of a single asm file into a single code
15092  page.
15093  In order to make use of multiple code pages, separate asm files must be
15094  used.
15095  The compiler treats all functions of a single C file as being in the same
15096  code page unless it is non static.
15097  The compiler treats all local variables of a single C file as being in
15098  the same RAM bank unless it is an extern.
15099 \newline 
15100
15101 \newline 
15102 To get the best follow these guide lines:
15103 \layout Enumerate
15104
15105 make local functions static, as non static functions require code page selection
15106  overhead.
15107 \layout Enumerate
15108
15109 Make local variables static as extern variables require RAM bank selection
15110  overhead.
15111 \layout Enumerate
15112
15113 For devices that have multiple code pages it is more efficient to use the
15114  same number of files as pages, i.e.
15115  for the 16F877 use 4 separate files and i.e.
15116  for the 16F874 use 2 separate files.
15117  This way the linker can put the code for each file into different code
15118  pages and the compiler can allocate reusable variables more efficiently
15119  and there's less page selection overhead.
15120  And as for any 8 bit micro (especially for PIC 14 as they have a very simple
15121  instruction set) use 'unsigned char' whereever possible instead of 'int'.
15122 \layout Subsection
15123
15124 Creating a device include file 
15125 \layout Standard
15126
15127 For generating a device include file use the support perl script inc2h.pl
15128  kept in directory support/script.
15129 \layout Subsection
15130
15131 Interrupt code
15132 \layout Standard
15133
15134 For the interrupt function, use the keyword 'interrupt'
15135 \begin_inset LatexCommand \index{interrupt}
15136
15137 \end_inset 
15138
15139  with level number of 0 (PIC14 only has 1 interrupt so this number is only
15140  there to avoid a syntax error - it ought to be fixed).
15141  E.g.:
15142 \layout Verse
15143
15144
15145 \family typewriter 
15146 void Intr(void) interrupt 0
15147 \newline 
15148 {
15149 \newline 
15150 \SpecialChar ~
15151 \SpecialChar ~
15152 T0IF = 0; /* Clear timer interrupt */
15153 \newline 
15154 }
15155 \layout Subsection
15156
15157 Linking and assembling
15158 \layout Standard
15159
15160 For assembling you can use either GPUTILS'
15161 \begin_inset LatexCommand \index{gputils (pic tools)}
15162
15163 \end_inset 
15164
15165  gpasm.exe or MPLAB's mpasmwin.exe.
15166  GPUTILS is available from 
15167 \begin_inset LatexCommand \url{http://gputils.sourceforge.net/}
15168
15169 \end_inset 
15170
15171 .
15172  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
15173  If you use MPLAB and an interrupt function then the linker script file
15174  vectors section will need to be enlarged to link with mplink.
15175 \newline 
15176
15177 \newline 
15178 Here is a 
15179 \family typewriter 
15180 Makefile
15181 \family default 
15182  using GPUTILS:
15183 \layout Verse
15184
15185
15186 \family typewriter 
15187 .c.o:
15188 \newline 
15189 \SpecialChar ~
15190 \SpecialChar ~
15191 \SpecialChar ~
15192 \SpecialChar ~
15193 \SpecialChar ~
15194 \SpecialChar ~
15195 \SpecialChar ~
15196 \SpecialChar ~
15197 sdcc -S -V -mpic14 -p16F877 $< 
15198 \newline 
15199 \SpecialChar ~
15200 \SpecialChar ~
15201 \SpecialChar ~
15202 \SpecialChar ~
15203 \SpecialChar ~
15204 \SpecialChar ~
15205 \SpecialChar ~
15206 \SpecialChar ~
15207 gpasm -c $*.asm
15208 \newline 
15209
15210 \newline 
15211 $(PRJ).hex: $(OBJS) 
15212 \newline 
15213 \SpecialChar ~
15214 \SpecialChar ~
15215 \SpecialChar ~
15216 \SpecialChar ~
15217 \SpecialChar ~
15218 \SpecialChar ~
15219 \SpecialChar ~
15220 \SpecialChar ~
15221 gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS)
15222 \layout Standard
15223
15224 Here is a 
15225 \family typewriter 
15226 Makefile
15227 \family default 
15228  using MPLAB:
15229 \layout Verse
15230
15231
15232 \family typewriter 
15233 .c.o: 
15234 \newline 
15235 \SpecialChar ~
15236 \SpecialChar ~
15237 \SpecialChar ~
15238 \SpecialChar ~
15239 \SpecialChar ~
15240 \SpecialChar ~
15241 \SpecialChar ~
15242 \SpecialChar ~
15243 sdcc -S -V -mpic14 -p16F877 $< 
15244 \newline 
15245 \SpecialChar ~
15246 \SpecialChar ~
15247 \SpecialChar ~
15248 \SpecialChar ~
15249 \SpecialChar ~
15250 \SpecialChar ~
15251 \SpecialChar ~
15252 \SpecialChar ~
15253 mpasmwin /q /o $*.asm
15254 \newline 
15255
15256 \newline 
15257 $(PRJ).hex: $(OBJS) 
15258 \newline 
15259 \SpecialChar ~
15260 \SpecialChar ~
15261 \SpecialChar ~
15262 \SpecialChar ~
15263 \SpecialChar ~
15264 \SpecialChar ~
15265 \SpecialChar ~
15266 \SpecialChar ~
15267 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS)
15268 \layout Standard
15269
15270 Please note that indentations within a
15271 \family typewriter 
15272  Makefile
15273 \family default 
15274  have to be done with a tabulator character.
15275 \layout Section
15276
15277 The PIC16
15278 \begin_inset LatexCommand \index{PIC16}
15279
15280 \end_inset 
15281
15282  port
15283 \layout Standard
15284
15285 The PIC16
15286 \begin_inset LatexCommand \index{PIC16}
15287
15288 \end_inset 
15289
15290  port is the portion of SDCC that is responsible to produce code for the
15291  Microchip
15292 \begin_inset LatexCommand \index{Microchip}
15293
15294 \end_inset 
15295
15296 (TM) microcontrollers with 16 bit core.
15297  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
15298 \layout Subsection
15299
15300 Global Options
15301 \layout Standard
15302
15303 PIC16 port supports the standard command line arguments as supposed, with
15304  the exception of certain cases that will be mentioned in the following
15305  list:
15306 \layout List
15307 \labelwidthstring 00.00.0000
15308
15309 -
15310 \begin_inset ERT
15311 status Collapsed
15312
15313 \layout Standard
15314
15315 \backslash 
15316 /
15317 \end_inset 
15318
15319 -callee-saves See -
15320 \begin_inset ERT
15321 status Collapsed
15322
15323 \layout Standard
15324
15325 \backslash 
15326 /
15327 \end_inset 
15328
15329 -all-callee-saves
15330 \layout List
15331 \labelwidthstring 00.00.0000
15332
15333 -
15334 \begin_inset ERT
15335 status Collapsed
15336
15337 \layout Standard
15338
15339 \backslash 
15340 /
15341 \end_inset 
15342
15343 -all-callee-saves All function arguments are passed on stack by default.
15344  
15345 \emph on 
15346 There is no need to specify this in the command line.
15347 \layout List
15348 \labelwidthstring 00.00.0000
15349
15350 -
15351 \begin_inset ERT
15352 status Collapsed
15353
15354 \layout Standard
15355
15356 \backslash 
15357 /
15358 \end_inset 
15359
15360 -fommit-frame-pointer Frame pointer will be omitted when the function uses
15361  no local variables.
15362 \layout Subsection
15363
15364 Port Specific Options
15365 \begin_inset LatexCommand \index{Options PIC16}
15366
15367 \end_inset 
15368
15369
15370 \layout Standard
15371
15372 The port specific options appear after the global options in the sdcc --help
15373  output.
15374 \layout Subsubsection
15375
15376 General Options
15377 \layout Standard
15378
15379 General options enable certain port features and optimizations.
15380 \layout List
15381 \labelwidthstring 00.00.0000
15382
15383 -
15384 \begin_inset ERT
15385 status Collapsed
15386
15387 \layout Standard
15388
15389 \backslash 
15390 /
15391 \end_inset 
15392
15393 -nodefaultlibs do not link default libraries when linking.
15394 \layout List
15395 \labelwidthstring 00.00.0000
15396
15397 -
15398 \begin_inset ERT
15399 status Collapsed
15400
15401 \layout Standard
15402
15403 \backslash 
15404 /
15405 \end_inset 
15406
15407 -obanksel=# Set optimization level for inserting BANKSELs.
15408 \begin_deeper 
15409 \layout List
15410 \labelwidthstring 00.00.0000
15411
15412 0 is no optimization
15413 \layout List
15414 \labelwidthstring 00.00.0000
15415
15416 1 checkes previous used register and if it is the same then doesn't emit
15417  BANKSEL, accounts only for labels.
15418 \end_deeper 
15419 \layout List
15420 \labelwidthstring 00.00.0000
15421
15422 -
15423 \begin_inset ERT
15424 status Collapsed
15425
15426 \layout Standard
15427
15428 \backslash 
15429 /
15430 \end_inset 
15431
15432 -pomit-config-words Omit the generation of the configuration words.
15433 \layout List
15434 \labelwidthstring 00.00.0000
15435
15436 -
15437 \begin_inset ERT
15438 status Collapsed
15439
15440 \layout Standard
15441
15442 \backslash 
15443 /
15444 \end_inset 
15445
15446 -pomit-ivt Omit the generation of the interrupt vectors.
15447 \layout List
15448 \labelwidthstring 00.00.0000
15449
15450 -
15451 \begin_inset ERT
15452 status Collapsed
15453
15454 \layout Standard
15455
15456 \backslash 
15457 /
15458 \end_inset 
15459
15460 -pleave-reset-vector Used in conjuction with -
15461 \begin_inset ERT
15462 status Collapsed
15463
15464 \layout Standard
15465
15466 \backslash 
15467 /
15468 \end_inset 
15469
15470 -pomit-ivt, instructs the port NOT to omit the reset vector.
15471 \layout List
15472 \labelwidthstring 00.00.0000
15473
15474 -
15475 \begin_inset ERT
15476 status Collapsed
15477
15478 \layout Standard
15479
15480 \backslash 
15481 /
15482 \end_inset 
15483
15484 -stack-model=[model] Used in conjuction with the command above.
15485  Defines the stack model to be used, valid stack models are : 
15486 \begin_deeper 
15487 \layout List
15488 \labelwidthstring 00.00.0000
15489
15490
15491 \emph on 
15492 small
15493 \emph default 
15494  Selects small stack model.
15495  8 bit stack and frame pointers.
15496  Supports 256 bytes stack size.
15497 \layout List
15498 \labelwidthstring 00.00.0000
15499
15500
15501 \emph on 
15502 large
15503 \emph default 
15504  Selects large stack model.
15505  16 bit stack and frame pointers.
15506  Supports 65536 bytes stack size.
15507 \end_deeper 
15508 \layout List
15509 \labelwidthstring 00.00.0000
15510
15511 -
15512 \begin_inset ERT
15513 status Collapsed
15514
15515 \layout Standard
15516
15517 \backslash 
15518 /
15519 \end_inset 
15520
15521 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
15522  unitialized data variables with [kword].
15523  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
15524 \layout List
15525 \labelwidthstring 00.00.0000
15526
15527 -
15528 \begin_inset ERT
15529 status Collapsed
15530
15531 \layout Standard
15532
15533 \backslash 
15534 /
15535 \end_inset 
15536
15537 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
15538  Useful for bootloaders.
15539 \layout List
15540 \labelwidthstring 00.00.0000
15541
15542 -
15543 \begin_inset ERT
15544 status Collapsed
15545
15546 \layout Standard
15547
15548 \backslash 
15549 /
15550 \end_inset 
15551
15552 -asm= sets the full path and name of an external assembler to call.
15553 \layout List
15554 \labelwidthstring 00.00.0000
15555
15556 -
15557 \begin_inset ERT
15558 status Collapsed
15559
15560 \layout Standard
15561
15562 \backslash 
15563 /
15564 \end_inset 
15565
15566 -link= sets the full path and name of an external linker to call.
15567 \layout List
15568 \labelwidthstring 00.00.0000
15569
15570 -
15571 \begin_inset ERT
15572 status Collapsed
15573
15574 \layout Standard
15575
15576 \backslash 
15577 /
15578 \end_inset 
15579
15580 -call-tree dump call tree in .calltree file
15581 \layout List
15582 \labelwidthstring 00.00.0000
15583
15584 -
15585 \begin_inset ERT
15586 status Collapsed
15587
15588 \layout Standard
15589
15590 \backslash 
15591 /
15592 \end_inset 
15593
15594 -mplab-comp MPLAB compatibility option.
15595  Currently only suppresses special gpasm directives.
15596 \layout List
15597 \labelwidthstring 00.00.0000
15598
15599 -
15600 \begin_inset ERT
15601 status Collapsed
15602
15603 \layout Standard
15604
15605 \backslash 
15606 /
15607 \end_inset 
15608
15609 -use-crt= Use a custom run-time module instead of the defaults.
15610 \layout List
15611 \labelwidthstring 00.00.0000
15612
15613 -
15614 \begin_inset ERT
15615 status Collapsed
15616
15617 \layout Standard
15618
15619 \backslash 
15620 /
15621 \end_inset 
15622
15623 -no-crt Don't link the default run-time modules
15624 \layout List
15625 \labelwidthstring 00.00.0000
15626
15627 -
15628 \begin_inset ERT
15629 status Collapsed
15630
15631 \layout Standard
15632
15633 \backslash 
15634 /
15635 \end_inset 
15636
15637 -flr-support When entering/leaving a function, call support functions to
15638  store/restore used registers
15639 \layout Subsubsection
15640
15641 Debugging Options
15642 \layout Standard
15643
15644 Debugging options enable extra debugging information in the output files.
15645 \layout List
15646 \labelwidthstring 00.00.0000
15647
15648 -
15649 \begin_inset ERT
15650 status Collapsed
15651
15652 \layout Standard
15653
15654 \backslash 
15655 /
15656 \end_inset 
15657
15658 -debug-xtra Similar to -
15659 \begin_inset ERT
15660 status Collapsed
15661
15662 \layout Standard
15663
15664 \backslash 
15665 /
15666 \end_inset 
15667
15668 -debug
15669 \begin_inset LatexCommand \index{-\/-debug}
15670
15671 \end_inset 
15672
15673 , but dumps more information.
15674 \layout List
15675 \labelwidthstring 00.00.0000
15676
15677 -
15678 \begin_inset ERT
15679 status Collapsed
15680
15681 \layout Standard
15682
15683 \backslash 
15684 /
15685 \end_inset 
15686
15687 -debug-ralloc Force register allocator to dump <source>.d file with debugging
15688  information.
15689  <source> is the name of the file compiled.
15690 \layout List
15691 \labelwidthstring 00.00.0000
15692
15693 -
15694 \begin_inset ERT
15695 status Collapsed
15696
15697 \layout Standard
15698
15699 \backslash 
15700 /
15701 \end_inset 
15702
15703 -pcode-verbose Enable pcode debugging information in translation.
15704 \layout List
15705 \labelwidthstring 00.00.0000
15706
15707 -
15708 \begin_inset ERT
15709 status Collapsed
15710
15711 \layout Standard
15712
15713 \backslash 
15714 /
15715 \end_inset 
15716
15717 -denable-peeps Force the usage of peepholes.
15718  Use with care.
15719 \layout List
15720 \labelwidthstring 00.00.0000
15721
15722 -
15723 \begin_inset ERT
15724 status Collapsed
15725
15726 \layout Standard
15727
15728 \backslash 
15729 /
15730 \end_inset 
15731
15732 -gstack Trace push/pops for stack pointer overflow
15733 \layout Subsection
15734
15735 Preprocessor Macros
15736 \layout Standard
15737
15738 PIC16 port defines the following preprocessor macros while translating a
15739  source.
15740 \layout Standard
15741 \align center 
15742
15743 \begin_inset  Tabular
15744 <lyxtabular version="3" rows="2" columns="2">
15745 <features>
15746 <column alignment="center" valignment="top" leftline="true" width="0">
15747 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15748 <row topline="true" bottomline="true">
15749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15750 \begin_inset Text
15751
15752 \layout Standard
15753
15754 Macro
15755 \end_inset 
15756 </cell>
15757 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15758 \begin_inset Text
15759
15760 \layout Standard
15761
15762 Description
15763 \end_inset 
15764 </cell>
15765 </row>
15766 <row topline="true" bottomline="true">
15767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15768 \begin_inset Text
15769
15770 \layout Standard
15771
15772 pic18fxxxx
15773 \end_inset 
15774 </cell>
15775 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15776 \begin_inset Text
15777
15778 \layout Standard
15779
15780 MCU Identification.
15781  
15782 \emph on 
15783 xxxx
15784 \emph default 
15785  is the microcontrol identification number, i.e.
15786  452, 6620, etc
15787 \end_inset 
15788 </cell>
15789 </row>
15790 </lyxtabular>
15791
15792 \end_inset 
15793
15794
15795 \layout Subsection
15796
15797 Directories
15798 \layout Standard
15799
15800 PIC16
15801 \begin_inset LatexCommand \index{PIC16}
15802
15803 \end_inset 
15804
15805  port uses the following directories for searching header files and libraries.
15806 \layout Standard
15807 \align center 
15808
15809 \begin_inset  Tabular
15810 <lyxtabular version="3" rows="3" columns="4">
15811 <features>
15812 <column alignment="center" valignment="top" leftline="true" width="0">
15813 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15814 <column alignment="center" valignment="top" width="0">
15815 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15816 <row topline="true" bottomline="true">
15817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15818 \begin_inset Text
15819
15820 \layout Standard
15821
15822 Directory
15823 \end_inset 
15824 </cell>
15825 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15826 \begin_inset Text
15827
15828 \layout Standard
15829
15830 Description
15831 \end_inset 
15832 </cell>
15833 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15834 \begin_inset Text
15835
15836 \layout Standard
15837
15838 Target
15839 \end_inset 
15840 </cell>
15841 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15842 \begin_inset Text
15843
15844 \layout Standard
15845
15846 Command prefix
15847 \end_inset 
15848 </cell>
15849 </row>
15850 <row topline="true">
15851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15852 \begin_inset Text
15853
15854 \layout Standard
15855
15856 PREFIX/sdcc/include/pic16
15857 \end_inset 
15858 </cell>
15859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15860 \begin_inset Text
15861
15862 \layout Standard
15863
15864 PIC16 specific headers
15865 \end_inset 
15866 </cell>
15867 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15868 \begin_inset Text
15869
15870 \layout Standard
15871
15872 Compiler
15873 \end_inset 
15874 </cell>
15875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15876 \begin_inset Text
15877
15878 \layout Standard
15879
15880 -I
15881 \end_inset 
15882 </cell>
15883 </row>
15884 <row topline="true" bottomline="true">
15885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15886 \begin_inset Text
15887
15888 \layout Standard
15889
15890 PREFIX/sdcc/lib/pic16
15891 \end_inset 
15892 </cell>
15893 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15894 \begin_inset Text
15895
15896 \layout Standard
15897
15898 PIC16 specific libraries
15899 \end_inset 
15900 </cell>
15901 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15902 \begin_inset Text
15903
15904 \layout Standard
15905
15906 Linker
15907 \end_inset 
15908 </cell>
15909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15910 \begin_inset Text
15911
15912 \layout Standard
15913
15914 -L
15915 \end_inset 
15916 </cell>
15917 </row>
15918 </lyxtabular>
15919
15920 \end_inset 
15921
15922
15923 \layout Subsection
15924
15925 Pragmas
15926 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
15927
15928 \end_inset 
15929
15930
15931 \layout Standard
15932
15933 PIC16 port currently supports the following pragmas:
15934 \layout List
15935 \labelwidthstring 00.00.0000
15936
15937 stack pragma stack forces the code generator to initialize the stack & frame
15938  pointers at a specific address.
15939  This is an adhoc solution since gplink does not support yet stack.
15940  When the gplink issue is resolved the pragma will be deprecated
15941 \begin_inset Foot
15942 collapsed true
15943
15944 \layout Standard
15945
15946
15947 \emph on 
15948 It is important to initialize the stack, otherwise strange things can happen.
15949  Stack is not initialized by default because there are some sources that
15950  do not require it.
15951  (like library sources)
15952 \end_inset 
15953
15954 .
15955 \newline 
15956 The stack pragma should be used only once in a project.
15957  Multiple pragmas may result in indeterminate behaviour of the program.
15958 \layout LyX-Code
15959
15960 Example:
15961 \layout LyX-Code
15962
15963 \layout LyX-Code
15964
15965 /* initializes stack at RAM address 0x5ff */
15966 \layout LyX-Code
15967
15968 #pragma stack 0x5ff
15969 \layout List
15970 \labelwidthstring 00.00.0000
15971
15972 code place a function symbol at static FLASH address
15973 \layout LyX-Code
15974
15975 Example:
15976 \layout LyX-Code
15977
15978 \layout LyX-Code
15979
15980 /* place function test_func at 0x4000 */
15981 \layout LyX-Code
15982
15983 #pragma code test_func 0x4000
15984 \layout List
15985 \labelwidthstring 00.00.0000
15986
15987 udata pragma udata instructs the compiler to emit code so that linker will
15988  place a variable at a specific memory bank
15989 \layout LyX-Code
15990
15991 Example:
15992 \layout LyX-Code
15993
15994 \layout LyX-Code
15995
15996 /* places variable foo at bank2 */
15997 \layout LyX-Code
15998
15999 #pragma udata bank2 foo
16000 \layout LyX-Code
16001
16002 char foo;
16003 \layout Standard
16004
16005 In order for this pragma to work there are some changes that must be made
16006  in the .lkr script used in link stage.
16007  In the following example a sample .lkr file is shown:
16008 \layout LyX-Code
16009
16010 \layout LyX-Code
16011
16012 // Sample linker script for the PIC18F452 processor
16013 \layout LyX-Code
16014
16015 LIBPATH .
16016 \layout LyX-Code
16017
16018 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
16019 \layout LyX-Code
16020
16021 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
16022 \layout LyX-Code
16023
16024 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
16025 \layout LyX-Code
16026
16027 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
16028 \layout LyX-Code
16029
16030 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
16031 \layout LyX-Code
16032
16033 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
16034 \layout LyX-Code
16035
16036 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
16037 \layout LyX-Code
16038
16039 \layout LyX-Code
16040
16041 DATABANK   NAME=gpr0       START=0x80           END=0xFF
16042 \layout LyX-Code
16043
16044 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
16045 \layout LyX-Code
16046
16047 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
16048 \layout LyX-Code
16049
16050 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
16051 \layout LyX-Code
16052
16053 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
16054 \layout LyX-Code
16055
16056 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
16057 \layout LyX-Code
16058
16059 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
16060 \layout LyX-Code
16061
16062 \layout LyX-Code
16063
16064 SECTION    NAME=CONFIG     ROM=config
16065 \layout LyX-Code
16066
16067 \layout LyX-Code
16068
16069 SECTION    NAME=bank0      RAM=gpr0
16070 \layout LyX-Code
16071
16072 SECTION    NAME=bank1      RAM=gpr1
16073 \layout LyX-Code
16074
16075 SECTION    NAME=bank2      RAM=gpr2
16076 \layout LyX-Code
16077
16078 SECTION    NAME=bank3      RAM=gpr3
16079 \layout LyX-Code
16080
16081 SECTION    NAME=bank4      RAM=gpr4
16082 \layout LyX-Code
16083
16084 SECTION    NAME=bank5      RAM=gpr5
16085 \layout Standard
16086
16087 The linker will recognise the section name set in the pragma statement and
16088  will position the variable at the memory bank set with the RAM field at
16089  the SECTION line in the linker script file.
16090 \layout Subsection
16091
16092 Header Files
16093 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
16094
16095 \end_inset 
16096
16097
16098 \layout Standard
16099
16100 There is one main header file that can be included to the source files using
16101  the pic16 port.
16102  That file is the 
16103 \series bold 
16104 pic18fregs.h
16105 \series default 
16106 .
16107  This header file contains the definitions for the processor special registers,
16108  so it is necessary if the source accesses them.
16109  It can be included by adding the following line in the beginning of the
16110  file:
16111 \layout LyX-Code
16112
16113 #include <pic18fregs.h>
16114 \layout Standard
16115
16116 The specific microcontroller is selected within the pic18fregs.h automatically,
16117  so the same source can be used with a variety of devices.
16118 \layout Subsection
16119
16120 Libraries
16121 \layout Standard
16122
16123 The libraries that PIC16
16124 \begin_inset LatexCommand \index{PIC16}
16125
16126 \end_inset 
16127
16128  port depends on are the microcontroller device libraries which contain
16129  the symbol definitions for the microcontroller special function registers.
16130  These libraries have the format pic18fxxxx.lib, where 
16131 \emph on 
16132 xxxx
16133 \emph default 
16134  is the microcontroller identification number.
16135  The specific library is selected automatically by the compiler at link
16136  stage according to the selected device.
16137 \layout Standard
16138
16139 Libraries are created with gplib which is part of the gputils package 
16140 \begin_inset LatexCommand \url{http://gputils.sourceforge.net}
16141
16142 \end_inset 
16143
16144 .
16145 \layout Subsection
16146
16147 Memory Models
16148 \layout Standard
16149
16150 The following memory models are supported by the PIC16 port:
16151 \layout Itemize
16152
16153 small model
16154 \layout Itemize
16155
16156 large model
16157 \layout Standard
16158
16159 Memory model affects the default size of pointers within the source.
16160  The sizes are shown in the next table:
16161 \layout Standard
16162 \align center 
16163
16164 \begin_inset  Tabular
16165 <lyxtabular version="3" rows="3" columns="3">
16166 <features>
16167 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
16168 <column alignment="center" valignment="top" leftline="true" width="0">
16169 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
16170 <row topline="true" bottomline="true">
16171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16172 \begin_inset Text
16173
16174 \layout Standard
16175
16176 Pointer sizes according to memory model
16177 \end_inset 
16178 </cell>
16179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16180 \begin_inset Text
16181
16182 \layout Standard
16183
16184 small model
16185 \end_inset 
16186 </cell>
16187 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16188 \begin_inset Text
16189
16190 \layout Standard
16191
16192 large model
16193 \end_inset 
16194 </cell>
16195 </row>
16196 <row topline="true" bottomline="true">
16197 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16198 \begin_inset Text
16199
16200 \layout Standard
16201
16202 code pointers
16203 \end_inset 
16204 </cell>
16205 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16206 \begin_inset Text
16207
16208 \layout Standard
16209
16210 16-bits
16211 \end_inset 
16212 </cell>
16213 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16214 \begin_inset Text
16215
16216 \layout Standard
16217
16218 24-bits
16219 \end_inset 
16220 </cell>
16221 </row>
16222 <row topline="true" bottomline="true">
16223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16224 \begin_inset Text
16225
16226 \layout Standard
16227
16228 data pointers
16229 \end_inset 
16230 </cell>
16231 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
16232 \begin_inset Text
16233
16234 \layout Standard
16235
16236 16-bits
16237 \end_inset 
16238 </cell>
16239 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16240 \begin_inset Text
16241
16242 \layout Standard
16243
16244 16-bits
16245 \end_inset 
16246 </cell>
16247 </row>
16248 </lyxtabular>
16249
16250 \end_inset 
16251
16252
16253 \layout Standard
16254
16255 It is advisable that all sources within a project are compiled with the
16256  same memory model.
16257  If one wants to override the default memory model, this can be done by
16258  declaring a pointer as 
16259 \series bold 
16260 far
16261 \series default 
16262  or 
16263 \series bold 
16264 near
16265 \series default 
16266 .
16267  Far selects large memory model's pointers, while near selects small memory
16268  model's pointers.
16269 \layout Standard
16270
16271 The standard device libraries (see 
16272 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
16273
16274 \end_inset 
16275
16276 ) contain no reference to pointers, so they can be used with both memory
16277  models.
16278 \layout Subsection
16279
16280 Stack
16281 \layout Standard
16282
16283 The stack implementation for the PIC16 port uses two indirect registers,
16284  FSR1 and FSR2.
16285 \layout List
16286 \labelwidthstring 00.00.0000
16287
16288 FSR1 is assigned as stack pointer
16289 \layout List
16290 \labelwidthstring 00.00.0000
16291
16292 FSR2 is assigned as frame pointer
16293 \layout Standard
16294
16295 The following stack models are supported by the PIC16 port
16296 \layout Itemize
16297
16298 small model
16299 \layout Itemize
16300
16301 large model
16302 \layout Standard
16303
16304
16305 \noun on 
16306 Small
16307 \noun default 
16308  model means that only the FSRxL byte is used to access stack and frame,
16309  while 
16310 \emph on 
16311 \noun on 
16312 large
16313 \emph default 
16314 \noun default 
16315  uses both FSRxL and FSRxH registers.
16316  The following table shows the stack/frame pointers sizes according to stack
16317  model and the maximum space they can address:
16318 \layout Standard
16319 \align center 
16320
16321 \begin_inset  Tabular
16322 <lyxtabular version="3" rows="3" columns="3">
16323 <features>
16324 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
16325 <column alignment="center" valignment="top" leftline="true" width="0">
16326 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
16327 <row topline="true" bottomline="true">
16328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16329 \begin_inset Text
16330
16331 \layout Standard
16332
16333 Stack & Frame pointer sizes according to stack model
16334 \end_inset 
16335 </cell>
16336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16337 \begin_inset Text
16338
16339 \layout Standard
16340
16341 small
16342 \end_inset 
16343 </cell>
16344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16345 \begin_inset Text
16346
16347 \layout Standard
16348
16349 large
16350 \end_inset 
16351 </cell>
16352 </row>
16353 <row topline="true">
16354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16355 \begin_inset Text
16356
16357 \layout Standard
16358
16359 Stack pointer FSR1
16360 \end_inset 
16361 </cell>
16362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16363 \begin_inset Text
16364
16365 \layout Standard
16366
16367 8-bits
16368 \end_inset 
16369 </cell>
16370 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16371 \begin_inset Text
16372
16373 \layout Standard
16374
16375 16-bits
16376 \end_inset 
16377 </cell>
16378 </row>
16379 <row topline="true" bottomline="true">
16380 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16381 \begin_inset Text
16382
16383 \layout Standard
16384
16385 Frame pointer FSR2
16386 \end_inset 
16387 </cell>
16388 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16389 \begin_inset Text
16390
16391 \layout Standard
16392
16393 8-bits
16394 \end_inset 
16395 </cell>
16396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16397 \begin_inset Text
16398
16399 \layout Standard
16400
16401 16-bits
16402 \end_inset 
16403 </cell>
16404 </row>
16405 </lyxtabular>
16406
16407 \end_inset 
16408
16409
16410 \layout Standard
16411
16412
16413 \series bold 
16414 Currently stack and frame pointers should be initialized explicit by the
16415  user at the desired Data RAM position (see 
16416 \begin_inset LatexCommand \ref{sub:PIC16_Pragmas}
16417
16418 \end_inset 
16419
16420  Pragma stack).
16421  Uninitialized stack and frame pointers can result in unexpected behavior
16422  of the resulting binary.
16423 \layout Subsection
16424
16425 Function return values
16426 \layout Standard
16427
16428 Return values from functions are placed to the appropriate registers following
16429  a modified Microchip policy optimized for SDCC.
16430  The following table shows these registers:
16431 \layout Standard
16432 \align center 
16433
16434 \begin_inset  Tabular
16435 <lyxtabular version="3" rows="6" columns="2">
16436 <features>
16437 <column alignment="center" valignment="top" leftline="true" width="0">
16438 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
16439 <row topline="true" bottomline="true">
16440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16441 \begin_inset Text
16442
16443 \layout Standard
16444
16445 size
16446 \end_inset 
16447 </cell>
16448 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16449 \begin_inset Text
16450
16451 \layout Standard
16452
16453 destination register
16454 \end_inset 
16455 </cell>
16456 </row>
16457 <row topline="true">
16458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16459 \begin_inset Text
16460
16461 \layout Standard
16462
16463 8 bits
16464 \end_inset 
16465 </cell>
16466 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16467 \begin_inset Text
16468
16469 \layout Standard
16470
16471 WREG
16472 \end_inset 
16473 </cell>
16474 </row>
16475 <row topline="true">
16476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16477 \begin_inset Text
16478
16479 \layout Standard
16480
16481 16 bits
16482 \end_inset 
16483 </cell>
16484 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16485 \begin_inset Text
16486
16487 \layout Standard
16488
16489 PRODL:WREG
16490 \end_inset 
16491 </cell>
16492 </row>
16493 <row topline="true">
16494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16495 \begin_inset Text
16496
16497 \layout Standard
16498
16499 24 bits
16500 \end_inset 
16501 </cell>
16502 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16503 \begin_inset Text
16504
16505 \layout Standard
16506
16507 PRODH:PRODL:WREG
16508 \end_inset 
16509 </cell>
16510 </row>
16511 <row topline="true">
16512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16513 \begin_inset Text
16514
16515 \layout Standard
16516
16517 32 bits
16518 \end_inset 
16519 </cell>
16520 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16521 \begin_inset Text
16522
16523 \layout Standard
16524
16525 FSR0L:PRODH:PRODL:WREG
16526 \end_inset 
16527 </cell>
16528 </row>
16529 <row topline="true" bottomline="true">
16530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16531 \begin_inset Text
16532
16533 \layout Standard
16534
16535 >32 bits
16536 \end_inset 
16537 </cell>
16538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16539 \begin_inset Text
16540
16541 \layout Standard
16542
16543 on stack, FSR0 points to the beginning
16544 \end_inset 
16545 </cell>
16546 </row>
16547 </lyxtabular>
16548
16549 \end_inset 
16550
16551
16552 \layout Subsection
16553
16554 Interrupts
16555 \layout Standard
16556
16557 When entering an interrupt, currently the PIC16
16558 \begin_inset LatexCommand \index{PIC16}
16559
16560 \end_inset 
16561
16562  port automatically saves the following registers:
16563 \layout Itemize
16564
16565 WREG
16566 \layout Itemize
16567
16568 STATUS
16569 \layout Itemize
16570
16571 BSR
16572 \layout Itemize
16573
16574 PROD (PRODL and PRODH)
16575 \layout Itemize
16576
16577 FSR0 (FSR0L and FSR0H)
16578 \layout Standard
16579
16580 These registers are restored upon return from the interrupt routine.
16581  
16582 \layout Standard
16583
16584 When entering a high priority interrupt WREG, STATUS and BSR are not explicit
16585  saved by software.
16586  The hardware shadow registers for WREG, STATUS and BSR are used in these
16587  cases.
16588 \layout Standard
16589
16590
16591 \begin_inset Foot
16592 collapsed false
16593
16594 \layout Standard
16595
16596 NOTE that when the _naked attribute is specified for an interrupt routine,
16597  then NO registers are stored or restored.
16598 \end_inset 
16599
16600 .
16601 \layout Chapter
16602
16603 Debugging with SDCDB
16604 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
16605
16606 \end_inset 
16607
16608
16609 \begin_inset LatexCommand \index{sdcdb (debugger)}
16610
16611 \end_inset 
16612
16613  
16614 \layout Standard
16615
16616 SDCC is distributed with a source level debugger
16617 \begin_inset LatexCommand \index{Debugger}
16618
16619 \end_inset 
16620
16621 .
16622  The debugger uses a command line interface, the command repertoire of the
16623  debugger has been kept as close to gdb
16624 \begin_inset LatexCommand \index{gdb}
16625
16626 \end_inset 
16627
16628  (the GNU debugger) as possible.
16629  The configuration and build process is part of the standard compiler installati
16630 on, which also builds and installs the debugger in the target directory
16631  specified during configuration.
16632  The debugger allows you debug BOTH at the C source and at the ASM source
16633  level.
16634  Sdcdb is available on Unix platforms only.
16635 \layout Section
16636
16637 Compiling for Debugging
16638 \layout Standard
16639
16640 The -
16641 \begin_inset ERT
16642 status Collapsed
16643
16644 \layout Standard
16645
16646 \backslash 
16647 /
16648 \end_inset 
16649
16650 -debug
16651 \begin_inset LatexCommand \index{-\/-debug}
16652
16653 \end_inset 
16654
16655  option must be specified for all files for which debug information is to
16656  be generated.
16657  The complier generates a .adb file for each of these files.
16658  The linker creates the .cdb
16659 \begin_inset LatexCommand \index{<file>.cdb}
16660
16661 \end_inset 
16662
16663  file from the .adb
16664 \begin_inset LatexCommand \index{<file>.adb}
16665
16666 \end_inset 
16667
16668  files and the address information.
16669  This .cdb is used by the debugger.
16670 \layout Section
16671
16672 How the Debugger Works
16673 \layout Standard
16674
16675 When the -
16676 \begin_inset ERT
16677 status Collapsed
16678
16679 \layout Standard
16680
16681 \backslash 
16682 /
16683 \end_inset 
16684
16685 -debug option is specified the compiler generates extra symbol information
16686  some of which are put into the assembler source and some are put into the
16687  .adb file.
16688   Then the linker creates the .cdb file from the individual .adb files with
16689  the address information for the symbols.
16690  The debugger reads the symbolic information generated by the compiler &
16691  the address information generated by the linker.
16692  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
16693  execution is controlled by the debugger.
16694  When a command is issued for the debugger, it translates it into appropriate
16695  commands for the simulator.
16696 \layout Section
16697
16698 Starting the Debugger
16699 \layout Standard
16700
16701 The debugger can be started using the following command line.
16702  (Assume the file you are debugging has the file name foo).
16703 \newline 
16704
16705 \newline 
16706
16707 \family sans 
16708 \series bold 
16709 sdcdb foo
16710 \newline 
16711
16712 \family default 
16713 \series default 
16714
16715 \newline 
16716 The debugger will look for the following files.
16717 \layout Itemize
16718
16719 foo.c - the source file.
16720 \layout Itemize
16721
16722 foo.cdb - the debugger symbol information file.
16723 \layout Itemize
16724
16725 foo.ihx - the Intel hex format
16726 \begin_inset LatexCommand \index{Intel hex format}
16727
16728 \end_inset 
16729
16730  object file.
16731 \layout Section
16732
16733 Command Line Options.
16734 \layout Itemize
16735
16736 -
16737 \begin_inset ERT
16738 status Collapsed
16739
16740 \layout Standard
16741
16742 \backslash 
16743 /
16744 \end_inset 
16745
16746 -directory=<source file directory> this option can used to specify the directory
16747  search list.
16748  The debugger will look into the directory list specified for source, cdb
16749  & ihx files.
16750  The items in the directory list must be separated by ':', e.g.
16751  if the source files can be in the directories /home/src1 and /home/src2,
16752  the -
16753 \begin_inset ERT
16754 status Collapsed
16755
16756 \layout Standard
16757
16758 \backslash 
16759 /
16760 \end_inset 
16761
16762 -directory option should be -
16763 \begin_inset ERT
16764 status Collapsed
16765
16766 \layout Standard
16767
16768 \backslash 
16769 /
16770 \end_inset 
16771
16772 -directory=/home/src1:/home/src2.
16773  Note there can be no spaces in the option.
16774  
16775 \layout Itemize
16776
16777 -cd <directory> - change to the <directory>.
16778 \layout Itemize
16779
16780 -fullname - used by GUI front ends.
16781 \layout Itemize
16782
16783 -cpu <cpu-type> - this argument is passed to the simulator please see the
16784  simulator docs for details.
16785 \layout Itemize
16786
16787 -X <Clock frequency > this options is passed to the simulator please see
16788  the simulator docs for details.
16789 \layout Itemize
16790
16791 -s <serial port file> passed to simulator see the simulator docs for details.
16792 \layout Itemize
16793
16794 -S <serial in,out> passed to simulator see the simulator docs for details.
16795 \layout Itemize
16796
16797 -k <port number> passed to simulator see the simulator docs for details.
16798 \layout Section
16799
16800 Debugger Commands.
16801 \layout Standard
16802
16803 As mentioned earlier the command interface for the debugger has been deliberatel
16804 y kept as close the GNU debugger gdb, as possible.
16805  This will help the integration with existing graphical user interfaces
16806  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
16807  If you use a graphical user interface for the debugger you can skip the
16808  next sections.
16809 \layout Subsubsection*
16810
16811 break [line | file:line | function | file:function]
16812 \layout Standard
16813
16814 Set breakpoint at specified line or function:
16815 \newline 
16816
16817 \newline 
16818
16819 \family sans 
16820 \series bold 
16821 sdcdb>break 100 
16822 \newline 
16823 sdcdb>break foo.c:100
16824 \newline 
16825 sdcdb>break funcfoo
16826 \newline 
16827 sdcdb>break foo.c:funcfoo
16828 \layout Subsubsection*
16829
16830 clear [line | file:line | function | file:function ]
16831 \layout Standard
16832
16833 Clear breakpoint at specified line or function:
16834 \newline 
16835
16836 \newline 
16837
16838 \family sans 
16839 \series bold 
16840 sdcdb>clear 100
16841 \newline 
16842 sdcdb>clear foo.c:100
16843 \newline 
16844 sdcdb>clear funcfoo
16845 \newline 
16846 sdcdb>clear foo.c:funcfoo
16847 \layout Subsubsection*
16848
16849 continue
16850 \layout Standard
16851
16852 Continue program being debugged, after breakpoint.
16853 \layout Subsubsection*
16854
16855 finish
16856 \layout Standard
16857
16858 Execute till the end of the current function.
16859 \layout Subsubsection*
16860
16861 delete [n]
16862 \layout Standard
16863
16864 Delete breakpoint number 'n'.
16865  If used without any option clear ALL user defined break points.
16866 \layout Subsubsection*
16867
16868 info [break | stack | frame | registers ]
16869 \layout Itemize
16870
16871 info break - list all breakpoints
16872 \layout Itemize
16873
16874 info stack - show the function call stack.
16875 \layout Itemize
16876
16877 info frame - show information about the current execution frame.
16878 \layout Itemize
16879
16880 info registers - show content of all registers.
16881 \layout Subsubsection*
16882
16883 step
16884 \layout Standard
16885
16886 Step program until it reaches a different source line.
16887  Note: pressing <return> repeats the last command.
16888 \layout Subsubsection*
16889
16890 next
16891 \layout Standard
16892
16893 Step program, proceeding through subroutine calls.
16894 \layout Subsubsection*
16895
16896 run
16897 \layout Standard
16898
16899 Start debugged program.
16900 \layout Subsubsection*
16901
16902 ptype variable 
16903 \layout Standard
16904
16905 Print type information of the variable.
16906 \layout Subsubsection*
16907
16908 print variable
16909 \layout Standard
16910
16911 print value of variable.
16912 \layout Subsubsection*
16913
16914 file filename
16915 \layout Standard
16916
16917 load the given file name.
16918  Note this is an alternate method of loading file for debugging.
16919 \layout Subsubsection*
16920
16921 frame
16922 \layout Standard
16923
16924 print information about current frame.
16925 \layout Subsubsection*
16926
16927 set srcmode
16928 \layout Standard
16929
16930 Toggle between C source & assembly source.
16931 \layout Subsubsection*
16932
16933 ! simulator command
16934 \layout Standard
16935
16936 Send the string following '!' to the simulator, the simulator response is
16937  displayed.
16938  Note the debugger does not interpret the command being sent to the simulator,
16939  so if a command like 'go' is sent the debugger can loose its execution
16940  context and may display incorrect values.
16941 \layout Subsubsection*
16942
16943 quit
16944 \layout Standard
16945
16946 "Watch me now.
16947  Iam going Down.
16948  My name is Bobby Brown"
16949 \layout Section
16950
16951 Interfacing with XEmacs
16952 \begin_inset LatexCommand \index{XEmacs}
16953
16954 \end_inset 
16955
16956
16957 \begin_inset LatexCommand \index{Emacs}
16958
16959 \end_inset 
16960
16961 .
16962 \layout Standard
16963
16964 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
16965  sdcdb.el and sdcdbsrc.el.
16966  These two files can be found in the $(prefix)/bin directory after the installat
16967 ion is complete.
16968  These files need to be loaded into XEmacs for the interface to work.
16969  This can be done at XEmacs startup time by inserting the following into
16970  your '.xemacs' file (which can be found in your HOME directory): 
16971 \newline 
16972
16973 \newline 
16974
16975 \family typewriter 
16976 (load-file sdcdbsrc.el) 
16977 \family default 
16978
16979 \newline 
16980
16981 \newline 
16982 .xemacs is a lisp file so the () around the command is REQUIRED.
16983  The files can also be loaded dynamically while XEmacs is running, set the
16984  environment variable 'EMACSLOADPATH' to the installation bin directory
16985  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
16986  To start the interface enter the following command: 
16987 \newline 
16988
16989 \newline 
16990
16991 \family sans 
16992 \series bold 
16993 ESC-x sdcdbsrc
16994 \family default 
16995 \series default 
16996
16997 \newline 
16998
16999 \newline 
17000 You will prompted to enter the file name to be debugged.
17001  
17002 \newline 
17003
17004 \newline 
17005 The command line options that are passed to the simulator directly are bound
17006  to default values in the file sdcdbsrc.el.
17007  The variables are listed below, these values maybe changed as required.
17008 \layout Itemize
17009
17010 sdcdbsrc-cpu-type '51
17011 \layout Itemize
17012
17013 sdcdbsrc-frequency '11059200
17014 \layout Itemize
17015
17016 sdcdbsrc-serial nil
17017 \layout Standard
17018
17019 The following is a list of key mapping for the debugger interface.
17020 \layout Standard
17021
17022 \SpecialChar ~
17023
17024 \family typewriter 
17025
17026 \newline 
17027 ;;\SpecialChar ~
17028 Current Listing :: 
17029 \newline 
17030 ;;key\SpecialChar ~
17031 \SpecialChar ~
17032 \SpecialChar ~
17033 \SpecialChar ~
17034 \SpecialChar ~
17035 \SpecialChar ~
17036 \SpecialChar ~
17037 \SpecialChar ~
17038 \SpecialChar ~
17039 \SpecialChar ~
17040 \SpecialChar ~
17041 \SpecialChar ~
17042 \SpecialChar ~
17043 \SpecialChar ~
17044 binding\SpecialChar ~
17045 \SpecialChar ~
17046 \SpecialChar ~
17047 \SpecialChar ~
17048 \SpecialChar ~
17049 \SpecialChar ~
17050 \SpecialChar ~
17051 \SpecialChar ~
17052 \SpecialChar ~
17053 \SpecialChar ~
17054 \SpecialChar ~
17055 \SpecialChar ~
17056 \SpecialChar ~
17057 \SpecialChar ~
17058 \SpecialChar ~
17059 \SpecialChar ~
17060 \SpecialChar ~
17061 \SpecialChar ~
17062 \SpecialChar ~
17063 \SpecialChar ~
17064 \SpecialChar ~
17065 \SpecialChar ~
17066 Comment 
17067 \newline 
17068 ;;---\SpecialChar ~
17069 \SpecialChar ~
17070 \SpecialChar ~
17071 \SpecialChar ~
17072 \SpecialChar ~
17073 \SpecialChar ~
17074 \SpecialChar ~
17075 \SpecialChar ~
17076 \SpecialChar ~
17077 \SpecialChar ~
17078 \SpecialChar ~
17079 \SpecialChar ~
17080 \SpecialChar ~
17081 \SpecialChar ~
17082 -------\SpecialChar ~
17083 \SpecialChar ~
17084 \SpecialChar ~
17085 \SpecialChar ~
17086 \SpecialChar ~
17087 \SpecialChar ~
17088 \SpecialChar ~
17089 \SpecialChar ~
17090 \SpecialChar ~
17091 \SpecialChar ~
17092 \SpecialChar ~
17093 \SpecialChar ~
17094 \SpecialChar ~
17095 \SpecialChar ~
17096 \SpecialChar ~
17097 \SpecialChar ~
17098 \SpecialChar ~
17099 \SpecialChar ~
17100 \SpecialChar ~
17101 \SpecialChar ~
17102 \SpecialChar ~
17103 \SpecialChar ~
17104 -------
17105 \newline 
17106 ;; 
17107 \newline 
17108 ;;\SpecialChar ~
17109 n\SpecialChar ~
17110 \SpecialChar ~
17111 \SpecialChar ~
17112 \SpecialChar ~
17113 \SpecialChar ~
17114 \SpecialChar ~
17115 \SpecialChar ~
17116 \SpecialChar ~
17117 \SpecialChar ~
17118 \SpecialChar ~
17119 \SpecialChar ~
17120 \SpecialChar ~
17121 \SpecialChar ~
17122 \SpecialChar ~
17123 \SpecialChar ~
17124 sdcdb-next-from-src\SpecialChar ~
17125 \SpecialChar ~
17126 \SpecialChar ~
17127 \SpecialChar ~
17128 \SpecialChar ~
17129 \SpecialChar ~
17130 \SpecialChar ~
17131 \SpecialChar ~
17132 \SpecialChar ~
17133 \SpecialChar ~
17134 SDCDB next command 
17135 \newline 
17136 ;;\SpecialChar ~
17137 b\SpecialChar ~
17138 \SpecialChar ~
17139 \SpecialChar ~
17140 \SpecialChar ~
17141 \SpecialChar ~
17142 \SpecialChar ~
17143 \SpecialChar ~
17144 \SpecialChar ~
17145 \SpecialChar ~
17146 \SpecialChar ~
17147 \SpecialChar ~
17148 \SpecialChar ~
17149 \SpecialChar ~
17150 \SpecialChar ~
17151 \SpecialChar ~
17152 sdcdb-back-from-src\SpecialChar ~
17153 \SpecialChar ~
17154 \SpecialChar ~
17155 \SpecialChar ~
17156 \SpecialChar ~
17157 \SpecialChar ~
17158 \SpecialChar ~
17159 \SpecialChar ~
17160 \SpecialChar ~
17161 \SpecialChar ~
17162 SDCDB back command 
17163 \newline 
17164 ;;\SpecialChar ~
17165 c\SpecialChar ~
17166 \SpecialChar ~
17167 \SpecialChar ~
17168 \SpecialChar ~
17169 \SpecialChar ~
17170 \SpecialChar ~
17171 \SpecialChar ~
17172 \SpecialChar ~
17173 \SpecialChar ~
17174 \SpecialChar ~
17175 \SpecialChar ~
17176 \SpecialChar ~
17177 \SpecialChar ~
17178 \SpecialChar ~
17179 \SpecialChar ~
17180 sdcdb-cont-from-src\SpecialChar ~
17181 \SpecialChar ~
17182 \SpecialChar ~
17183 \SpecialChar ~
17184 \SpecialChar ~
17185 \SpecialChar ~
17186 \SpecialChar ~
17187 \SpecialChar ~
17188 \SpecialChar ~
17189 \SpecialChar ~
17190 SDCDB continue command
17191 \newline 
17192 ;;\SpecialChar ~
17193 s\SpecialChar ~
17194 \SpecialChar ~
17195 \SpecialChar ~
17196 \SpecialChar ~
17197 \SpecialChar ~
17198 \SpecialChar ~
17199 \SpecialChar ~
17200 \SpecialChar ~
17201 \SpecialChar ~
17202 \SpecialChar ~
17203 \SpecialChar ~
17204 \SpecialChar ~
17205 \SpecialChar ~
17206 \SpecialChar ~
17207 \SpecialChar ~
17208 sdcdb-step-from-src\SpecialChar ~
17209 \SpecialChar ~
17210 \SpecialChar ~
17211 \SpecialChar ~
17212 \SpecialChar ~
17213 \SpecialChar ~
17214 \SpecialChar ~
17215 \SpecialChar ~
17216 \SpecialChar ~
17217 \SpecialChar ~
17218 SDCDB step command 
17219 \newline 
17220 ;;\SpecialChar ~
17221 ?\SpecialChar ~
17222 \SpecialChar ~
17223 \SpecialChar ~
17224 \SpecialChar ~
17225 \SpecialChar ~
17226 \SpecialChar ~
17227 \SpecialChar ~
17228 \SpecialChar ~
17229 \SpecialChar ~
17230 \SpecialChar ~
17231 \SpecialChar ~
17232 \SpecialChar ~
17233 \SpecialChar ~
17234 \SpecialChar ~
17235 \SpecialChar ~
17236 sdcdb-whatis-c-sexp\SpecialChar ~
17237 \SpecialChar ~
17238 \SpecialChar ~
17239 \SpecialChar ~
17240 \SpecialChar ~
17241 \SpecialChar ~
17242 \SpecialChar ~
17243 \SpecialChar ~
17244 \SpecialChar ~
17245 \SpecialChar ~
17246 SDCDB ptypecommand for data at 
17247 \newline 
17248 ;;\SpecialChar ~
17249 \SpecialChar ~
17250 \SpecialChar ~
17251 \SpecialChar ~
17252 \SpecialChar ~
17253 \SpecialChar ~
17254 \SpecialChar ~
17255 \SpecialChar ~
17256 \SpecialChar ~
17257 \SpecialChar ~
17258 \SpecialChar ~
17259 \SpecialChar ~
17260 \SpecialChar ~
17261 \SpecialChar ~
17262 \SpecialChar ~
17263 \SpecialChar ~
17264 \SpecialChar ~
17265 \SpecialChar ~
17266 \SpecialChar ~
17267 \SpecialChar ~
17268 \SpecialChar ~
17269 \SpecialChar ~
17270 \SpecialChar ~
17271 \SpecialChar ~
17272 \SpecialChar ~
17273 \SpecialChar ~
17274 \SpecialChar ~
17275 \SpecialChar ~
17276 \SpecialChar ~
17277 \SpecialChar ~
17278 \SpecialChar ~
17279 \SpecialChar ~
17280 \SpecialChar ~
17281 \SpecialChar ~
17282 \SpecialChar ~
17283 \SpecialChar ~
17284 \SpecialChar ~
17285 \SpecialChar ~
17286 \SpecialChar ~
17287 \SpecialChar ~
17288 \SpecialChar ~
17289 \SpecialChar ~
17290 \SpecialChar ~
17291 \SpecialChar ~
17292 \SpecialChar ~
17293 \SpecialChar ~
17294 \SpecialChar ~
17295 buffer point 
17296 \newline 
17297 ;;\SpecialChar ~
17298 x\SpecialChar ~
17299 \SpecialChar ~
17300 \SpecialChar ~
17301 \SpecialChar ~
17302 \SpecialChar ~
17303 \SpecialChar ~
17304 \SpecialChar ~
17305 \SpecialChar ~
17306 \SpecialChar ~
17307 \SpecialChar ~
17308 \SpecialChar ~
17309 \SpecialChar ~
17310 \SpecialChar ~
17311 \SpecialChar ~
17312 \SpecialChar ~
17313 sdcdbsrc-delete\SpecialChar ~
17314 \SpecialChar ~
17315 \SpecialChar ~
17316 \SpecialChar ~
17317 \SpecialChar ~
17318 \SpecialChar ~
17319 \SpecialChar ~
17320 \SpecialChar ~
17321 \SpecialChar ~
17322 \SpecialChar ~
17323 \SpecialChar ~
17324 \SpecialChar ~
17325 \SpecialChar ~
17326 \SpecialChar ~
17327 SDCDB Delete all breakpoints if no arg 
17328 \newline 
17329 ;;\SpecialChar ~
17330 \SpecialChar ~
17331 \SpecialChar ~
17332 \SpecialChar ~
17333 \SpecialChar ~
17334 \SpecialChar ~
17335 \SpecialChar ~
17336 \SpecialChar ~
17337 \SpecialChar ~
17338 \SpecialChar ~
17339 \SpecialChar ~
17340 \SpecialChar ~
17341 \SpecialChar ~
17342 \SpecialChar ~
17343 \SpecialChar ~
17344 \SpecialChar ~
17345 \SpecialChar ~
17346 \SpecialChar ~
17347 \SpecialChar ~
17348 \SpecialChar ~
17349 \SpecialChar ~
17350 \SpecialChar ~
17351 \SpecialChar ~
17352 \SpecialChar ~
17353 \SpecialChar ~
17354 \SpecialChar ~
17355 \SpecialChar ~
17356 \SpecialChar ~
17357 \SpecialChar ~
17358 \SpecialChar ~
17359 \SpecialChar ~
17360 \SpecialChar ~
17361 \SpecialChar ~
17362 \SpecialChar ~
17363 \SpecialChar ~
17364 \SpecialChar ~
17365 \SpecialChar ~
17366 \SpecialChar ~
17367 \SpecialChar ~
17368 \SpecialChar ~
17369 \SpecialChar ~
17370 \SpecialChar ~
17371 \SpecialChar ~
17372 \SpecialChar ~
17373 \SpecialChar ~
17374 \SpecialChar ~
17375 \SpecialChar ~
17376 given or delete arg (C-u arg x) 
17377 \newline 
17378 ;;\SpecialChar ~
17379 m\SpecialChar ~
17380 \SpecialChar ~
17381 \SpecialChar ~
17382 \SpecialChar ~
17383 \SpecialChar ~
17384 \SpecialChar ~
17385 \SpecialChar ~
17386 \SpecialChar ~
17387 \SpecialChar ~
17388 \SpecialChar ~
17389 \SpecialChar ~
17390 \SpecialChar ~
17391 \SpecialChar ~
17392 \SpecialChar ~
17393 \SpecialChar ~
17394 sdcdbsrc-frame\SpecialChar ~
17395 \SpecialChar ~
17396 \SpecialChar ~
17397 \SpecialChar ~
17398 \SpecialChar ~
17399 \SpecialChar ~
17400 \SpecialChar ~
17401 \SpecialChar ~
17402 \SpecialChar ~
17403 \SpecialChar ~
17404 \SpecialChar ~
17405 \SpecialChar ~
17406 \SpecialChar ~
17407 \SpecialChar ~
17408 \SpecialChar ~
17409 SDCDB Display current frame if no arg, 
17410 \newline 
17411 ;;\SpecialChar ~
17412 \SpecialChar ~
17413 \SpecialChar ~
17414 \SpecialChar ~
17415 \SpecialChar ~
17416 \SpecialChar ~
17417 \SpecialChar ~
17418 \SpecialChar ~
17419 \SpecialChar ~
17420 \SpecialChar ~
17421 \SpecialChar ~
17422 \SpecialChar ~
17423 \SpecialChar ~
17424 \SpecialChar ~
17425 \SpecialChar ~
17426 \SpecialChar ~
17427 \SpecialChar ~
17428 \SpecialChar ~
17429 \SpecialChar ~
17430 \SpecialChar ~
17431 \SpecialChar ~
17432 \SpecialChar ~
17433 \SpecialChar ~
17434 \SpecialChar ~
17435 \SpecialChar ~
17436 \SpecialChar ~
17437 \SpecialChar ~
17438 \SpecialChar ~
17439 \SpecialChar ~
17440 \SpecialChar ~
17441 \SpecialChar ~
17442 \SpecialChar ~
17443 \SpecialChar ~
17444 \SpecialChar ~
17445 \SpecialChar ~
17446 \SpecialChar ~
17447 \SpecialChar ~
17448 \SpecialChar ~
17449 \SpecialChar ~
17450 \SpecialChar ~
17451 \SpecialChar ~
17452 \SpecialChar ~
17453 \SpecialChar ~
17454 \SpecialChar ~
17455 \SpecialChar ~
17456 \SpecialChar ~
17457 \SpecialChar ~
17458 given or display frame arg 
17459 \newline 
17460 ;;\SpecialChar ~
17461 \SpecialChar ~
17462 \SpecialChar ~
17463 \SpecialChar ~
17464 \SpecialChar ~
17465 \SpecialChar ~
17466 \SpecialChar ~
17467 \SpecialChar ~
17468 \SpecialChar ~
17469 \SpecialChar ~
17470 \SpecialChar ~
17471 \SpecialChar ~
17472 \SpecialChar ~
17473 \SpecialChar ~
17474 \SpecialChar ~
17475 \SpecialChar ~
17476 \SpecialChar ~
17477 \SpecialChar ~
17478 \SpecialChar ~
17479 \SpecialChar ~
17480 \SpecialChar ~
17481 \SpecialChar ~
17482 \SpecialChar ~
17483 \SpecialChar ~
17484 \SpecialChar ~
17485 \SpecialChar ~
17486 \SpecialChar ~
17487 \SpecialChar ~
17488 \SpecialChar ~
17489 \SpecialChar ~
17490 \SpecialChar ~
17491 \SpecialChar ~
17492 \SpecialChar ~
17493 \SpecialChar ~
17494 \SpecialChar ~
17495 \SpecialChar ~
17496 \SpecialChar ~
17497 \SpecialChar ~
17498 \SpecialChar ~
17499 \SpecialChar ~
17500 \SpecialChar ~
17501 \SpecialChar ~
17502 \SpecialChar ~
17503 \SpecialChar ~
17504 \SpecialChar ~
17505 \SpecialChar ~
17506 \SpecialChar ~
17507 buffer point 
17508 \newline 
17509 ;;\SpecialChar ~
17510 !\SpecialChar ~
17511 \SpecialChar ~
17512 \SpecialChar ~
17513 \SpecialChar ~
17514 \SpecialChar ~
17515 \SpecialChar ~
17516 \SpecialChar ~
17517 \SpecialChar ~
17518 \SpecialChar ~
17519 \SpecialChar ~
17520 \SpecialChar ~
17521 \SpecialChar ~
17522 \SpecialChar ~
17523 \SpecialChar ~
17524 \SpecialChar ~
17525 sdcdbsrc-goto-sdcdb\SpecialChar ~
17526 \SpecialChar ~
17527 \SpecialChar ~
17528 \SpecialChar ~
17529 \SpecialChar ~
17530 \SpecialChar ~
17531 \SpecialChar ~
17532 \SpecialChar ~
17533 \SpecialChar ~
17534 \SpecialChar ~
17535 Goto the SDCDB output buffer 
17536 \newline 
17537 ;;\SpecialChar ~
17538 p\SpecialChar ~
17539 \SpecialChar ~
17540 \SpecialChar ~
17541 \SpecialChar ~
17542 \SpecialChar ~
17543 \SpecialChar ~
17544 \SpecialChar ~
17545 \SpecialChar ~
17546 \SpecialChar ~
17547 \SpecialChar ~
17548 \SpecialChar ~
17549 \SpecialChar ~
17550 \SpecialChar ~
17551 \SpecialChar ~
17552 \SpecialChar ~
17553 sdcdb-print-c-sexp\SpecialChar ~
17554 \SpecialChar ~
17555 \SpecialChar ~
17556 \SpecialChar ~
17557 \SpecialChar ~
17558 \SpecialChar ~
17559 \SpecialChar ~
17560 \SpecialChar ~
17561 \SpecialChar ~
17562 \SpecialChar ~
17563 \SpecialChar ~
17564 SDCDB print command for data at 
17565 \newline 
17566 ;;\SpecialChar ~
17567 \SpecialChar ~
17568 \SpecialChar ~
17569 \SpecialChar ~
17570 \SpecialChar ~
17571 \SpecialChar ~
17572 \SpecialChar ~
17573 \SpecialChar ~
17574 \SpecialChar ~
17575 \SpecialChar ~
17576 \SpecialChar ~
17577 \SpecialChar ~
17578 \SpecialChar ~
17579 \SpecialChar ~
17580 \SpecialChar ~
17581 \SpecialChar ~
17582 \SpecialChar ~
17583 \SpecialChar ~
17584 \SpecialChar ~
17585 \SpecialChar ~
17586 \SpecialChar ~
17587 \SpecialChar ~
17588 \SpecialChar ~
17589 \SpecialChar ~
17590 \SpecialChar ~
17591 \SpecialChar ~
17592 \SpecialChar ~
17593 \SpecialChar ~
17594 \SpecialChar ~
17595 \SpecialChar ~
17596 \SpecialChar ~
17597 \SpecialChar ~
17598 \SpecialChar ~
17599 \SpecialChar ~
17600 \SpecialChar ~
17601 \SpecialChar ~
17602 \SpecialChar ~
17603 \SpecialChar ~
17604 \SpecialChar ~
17605 \SpecialChar ~
17606 \SpecialChar ~
17607 \SpecialChar ~
17608 \SpecialChar ~
17609 \SpecialChar ~
17610 \SpecialChar ~
17611 \SpecialChar ~
17612 \SpecialChar ~
17613 buffer point 
17614 \newline 
17615 ;;\SpecialChar ~
17616 g\SpecialChar ~
17617 \SpecialChar ~
17618 \SpecialChar ~
17619 \SpecialChar ~
17620 \SpecialChar ~
17621 \SpecialChar ~
17622 \SpecialChar ~
17623 \SpecialChar ~
17624 \SpecialChar ~
17625 \SpecialChar ~
17626 \SpecialChar ~
17627 \SpecialChar ~
17628 \SpecialChar ~
17629 \SpecialChar ~
17630 \SpecialChar ~
17631 sdcdbsrc-goto-sdcdb\SpecialChar ~
17632 \SpecialChar ~
17633 \SpecialChar ~
17634 \SpecialChar ~
17635 \SpecialChar ~
17636 \SpecialChar ~
17637 \SpecialChar ~
17638 \SpecialChar ~
17639 \SpecialChar ~
17640 \SpecialChar ~
17641 Goto the SDCDB output buffer 
17642 \newline 
17643 ;;\SpecialChar ~
17644 t\SpecialChar ~
17645 \SpecialChar ~
17646 \SpecialChar ~
17647 \SpecialChar ~
17648 \SpecialChar ~
17649 \SpecialChar ~
17650 \SpecialChar ~
17651 \SpecialChar ~
17652 \SpecialChar ~
17653 \SpecialChar ~
17654 \SpecialChar ~
17655 \SpecialChar ~
17656 \SpecialChar ~
17657 \SpecialChar ~
17658 \SpecialChar ~
17659 sdcdbsrc-mode\SpecialChar ~
17660 \SpecialChar ~
17661 \SpecialChar ~
17662 \SpecialChar ~
17663 \SpecialChar ~
17664 \SpecialChar ~
17665 \SpecialChar ~
17666 \SpecialChar ~
17667 \SpecialChar ~
17668 \SpecialChar ~
17669 \SpecialChar ~
17670 \SpecialChar ~
17671 \SpecialChar ~
17672 \SpecialChar ~
17673 \SpecialChar ~
17674 \SpecialChar ~
17675 Toggles Sdcdbsrc mode (turns it off) 
17676 \newline 
17677 ;; 
17678 \newline 
17679 ;;\SpecialChar ~
17680 C-c\SpecialChar ~
17681 C-f\SpecialChar ~
17682 \SpecialChar ~
17683 \SpecialChar ~
17684 \SpecialChar ~
17685 \SpecialChar ~
17686 \SpecialChar ~
17687 \SpecialChar ~
17688 \SpecialChar ~
17689 \SpecialChar ~
17690 sdcdb-finish-from-src\SpecialChar ~
17691 \SpecialChar ~
17692 \SpecialChar ~
17693 \SpecialChar ~
17694 \SpecialChar ~
17695 \SpecialChar ~
17696 \SpecialChar ~
17697 \SpecialChar ~
17698 SDCDB finish command 
17699 \newline 
17700 ;; 
17701 \newline 
17702 ;;\SpecialChar ~
17703 C-x\SpecialChar ~
17704 SPC\SpecialChar ~
17705 \SpecialChar ~
17706 \SpecialChar ~
17707 \SpecialChar ~
17708 \SpecialChar ~
17709 \SpecialChar ~
17710 \SpecialChar ~
17711 \SpecialChar ~
17712 \SpecialChar ~
17713 sdcdb-break\SpecialChar ~
17714 \SpecialChar ~
17715 \SpecialChar ~
17716 \SpecialChar ~
17717 \SpecialChar ~
17718 \SpecialChar ~
17719 \SpecialChar ~
17720 \SpecialChar ~
17721 \SpecialChar ~
17722 \SpecialChar ~
17723 \SpecialChar ~
17724 \SpecialChar ~
17725 \SpecialChar ~
17726 \SpecialChar ~
17727 \SpecialChar ~
17728 \SpecialChar ~
17729 \SpecialChar ~
17730 \SpecialChar ~
17731 Set break for line with point 
17732 \newline 
17733 ;;\SpecialChar ~
17734 ESC\SpecialChar ~
17735 t\SpecialChar ~
17736 \SpecialChar ~
17737 \SpecialChar ~
17738 \SpecialChar ~
17739 \SpecialChar ~
17740 \SpecialChar ~
17741 \SpecialChar ~
17742 \SpecialChar ~
17743 \SpecialChar ~
17744 \SpecialChar ~
17745 \SpecialChar ~
17746 sdcdbsrc-mode\SpecialChar ~
17747 \SpecialChar ~
17748 \SpecialChar ~
17749 \SpecialChar ~
17750 \SpecialChar ~
17751 \SpecialChar ~
17752 \SpecialChar ~
17753 \SpecialChar ~
17754 \SpecialChar ~
17755 \SpecialChar ~
17756 \SpecialChar ~
17757 \SpecialChar ~
17758 \SpecialChar ~
17759 \SpecialChar ~
17760 \SpecialChar ~
17761 \SpecialChar ~
17762 Toggle Sdcdbsrc mode 
17763 \newline 
17764 ;;\SpecialChar ~
17765 ESC\SpecialChar ~
17766 m\SpecialChar ~
17767 \SpecialChar ~
17768 \SpecialChar ~
17769 \SpecialChar ~
17770 \SpecialChar ~
17771 \SpecialChar ~
17772 \SpecialChar ~
17773 \SpecialChar ~
17774 \SpecialChar ~
17775 \SpecialChar ~
17776 \SpecialChar ~
17777 sdcdbsrc-srcmode\SpecialChar ~
17778 \SpecialChar ~
17779 \SpecialChar ~
17780 \SpecialChar ~
17781 \SpecialChar ~
17782 \SpecialChar ~
17783 \SpecialChar ~
17784 \SpecialChar ~
17785 \SpecialChar ~
17786 \SpecialChar ~
17787 \SpecialChar ~
17788 \SpecialChar ~
17789 \SpecialChar ~
17790 Toggle list mode 
17791 \newline 
17792 ;; 
17793 \newline 
17794
17795 \layout Chapter
17796 \pagebreak_top 
17797 TIPS
17798 \layout Standard
17799
17800 Here are a few guidelines that will help the compiler generate more efficient
17801  code, some of the tips are specific to this compiler others are generally
17802  good programming practice.
17803 \layout Itemize
17804
17805 Use the smallest data type to represent your data-value.
17806  If it is known in advance that the value is going to be less than 256 then
17807  use an 'unsigned char' instead of a 'short' or 'int'.
17808  Please note, that ANSI C requires both signed and unsigned chars to be
17809  promoted to 'signed int' before doing any operation.
17810  This promotion can be omitted, if the result is the same.
17811  The effect of the promotion rules together with the sign-extension is often
17812  surprising:
17813 \begin_deeper 
17814 \layout Verse
17815
17816
17817 \family typewriter 
17818 unsigned char uc = 0xfe;
17819 \newline 
17820 if (uc * uc < 0) /* this is true! */
17821 \newline 
17822 {
17823 \newline 
17824 \SpecialChar ~
17825 \SpecialChar ~
17826 \SpecialChar ~
17827 \SpecialChar ~
17828 ....
17829 \newline 
17830 }
17831 \layout Standard
17832
17833
17834 \family typewriter 
17835 uc * uc
17836 \family default 
17837  is evaluated as 
17838 \family typewriter 
17839 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
17840 \family default 
17841 .
17842  
17843 \newline 
17844 Another one:
17845 \layout Verse
17846
17847
17848 \family typewriter 
17849 (unsigned char) -12 / (signed char) -3 = ...
17850 \layout Standard
17851
17852 No, the result is not 4:
17853 \layout Verse
17854
17855
17856 \family typewriter 
17857 (int) (unsigned char) -12 / (int) (signed char) -3 =
17858 \newline 
17859 (int) (unsigned char) 0xf4 / (int) (signed char) 0xfd =
17860 \newline 
17861 (int) 0x00f4 / (int) 0xfffd =
17862 \newline 
17863 (int) 0x00f4 / (int) 0xfffd =
17864 \newline 
17865 (int) 244 / (int) -3 =
17866 \newline 
17867 (int) -81 = (int) 0xffaf;
17868 \layout Standard
17869
17870 Don't complain, that gcc gives you a different result.
17871  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
17872  Therefore the results are different.
17873 \newline 
17874 From 
17875 \begin_inset Quotes sld
17876 \end_inset 
17877
17878 comp.lang.c FAQ
17879 \begin_inset Quotes srd
17880 \end_inset 
17881
17882 :
17883 \layout Quote
17884
17885 If well-defined overflow characteristics are important and negative values
17886  are not, or if you want to steer clear of sign-extension problems when
17887  manipulating bits or bytes, use one of the corresponding unsigned types.
17888  (Beware when mixing signed and unsigned values in expressions, though.)
17889 \newline 
17890 Although character types (especially unsigned char) can be used as "tiny"
17891  integers, doing so is sometimes more trouble than it's worth, due to unpredicta
17892 ble sign extension and increased code size.
17893 \end_deeper 
17894 \layout Itemize
17895
17896 Use unsigned when it is known in advance that the value is not going to
17897  be negative.
17898  This helps especially if you are doing division or multiplication, bit-shifting
17899  or are using an array index.
17900 \layout Itemize
17901
17902 NEVER jump into a LOOP.
17903 \layout Itemize
17904
17905 Declare the variables to be local
17906 \begin_inset LatexCommand \index{local variables}
17907
17908 \end_inset 
17909
17910  whenever possible, especially loop control variables (induction).
17911 \layout Itemize
17912
17913 Since the compiler does not always do implicit integral promotion, the programme
17914 r should do an explicit cast when integral promotion is required.
17915 \layout Itemize
17916
17917 Reducing the size of division, multiplication & modulus operations can reduce
17918  code size substantially.
17919  Take the following code for example.
17920 \begin_deeper 
17921 \layout Verse
17922
17923
17924 \family typewriter 
17925 foobar(unsigned int p1, unsigned char ch)
17926 \newline 
17927 {
17928 \newline 
17929 \SpecialChar ~
17930 \SpecialChar ~
17931 \SpecialChar ~
17932 \SpecialChar ~
17933 unsigned char ch1 = p1 % ch ;
17934 \newline 
17935 \SpecialChar ~
17936 \SpecialChar ~
17937 \SpecialChar ~
17938 \SpecialChar ~
17939 ....
17940 \newline 
17941 }
17942 \layout Standard
17943
17944 For the modulus operation the variable ch will be promoted to unsigned int
17945  first then the modulus operation will be performed (this will lead to a
17946  call to support routine _moduint()), and the result will be casted to a
17947  char.
17948  If the code is changed to 
17949 \layout Verse
17950
17951
17952 \family typewriter 
17953 foobar(unsigned int p1, unsigned char ch)
17954 \newline 
17955 {
17956 \newline 
17957 \SpecialChar ~
17958 \SpecialChar ~
17959 \SpecialChar ~
17960 \SpecialChar ~
17961 unsigned char ch1 = (unsigned char)p1 % ch ;
17962 \newline 
17963 \SpecialChar ~
17964 \SpecialChar ~
17965 \SpecialChar ~
17966 \SpecialChar ~
17967 ....
17968 \newline 
17969 }
17970 \layout Standard
17971
17972 It would substantially reduce the code generated (future versions of the
17973  compiler will be smart enough to detect such optimization opportunities).
17974 \end_deeper 
17975 \layout Itemize
17976
17977 Have a look at the assembly listing to get a 
17978 \begin_inset Quotes sld
17979 \end_inset 
17980
17981 feeling
17982 \begin_inset Quotes srd
17983 \end_inset 
17984
17985  for the code generation.
17986 \layout Section
17987
17988 Tools
17989 \begin_inset LatexCommand \index{Tools}
17990
17991 \end_inset 
17992
17993  included in the distribution
17994 \layout Standard
17995 \align center 
17996
17997 \begin_inset  Tabular
17998 <lyxtabular version="3" rows="12" columns="3">
17999 <features>
18000 <column alignment="center" valignment="top" leftline="true" width="0pt">
18001 <column alignment="center" valignment="top" leftline="true" width="0pt">
18002 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
18003 <row topline="true" bottomline="true">
18004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18005 \begin_inset Text
18006
18007 \layout Standard
18008
18009 Name
18010 \end_inset 
18011 </cell>
18012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18013 \begin_inset Text
18014
18015 \layout Standard
18016
18017 Purpose
18018 \end_inset 
18019 </cell>
18020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18021 \begin_inset Text
18022
18023 \layout Standard
18024
18025 Directory
18026 \end_inset 
18027 </cell>
18028 </row>
18029 <row topline="true">
18030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18031 \begin_inset Text
18032
18033 \layout Standard
18034
18035 uCsim
18036 \end_inset 
18037 </cell>
18038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18039 \begin_inset Text
18040
18041 \layout Standard
18042
18043 Simulator for various architectures
18044 \end_inset 
18045 </cell>
18046 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18047 \begin_inset Text
18048
18049 \layout Standard
18050
18051 sdcc/sim/ucsim
18052 \end_inset 
18053 </cell>
18054 </row>
18055 <row topline="true">
18056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18057 \begin_inset Text
18058
18059 \layout Standard
18060
18061 keil2sdcc.pl
18062 \end_inset 
18063 </cell>
18064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18065 \begin_inset Text
18066
18067 \layout Standard
18068
18069 header file conversion
18070 \end_inset 
18071 </cell>
18072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18073 \begin_inset Text
18074
18075 \layout Standard
18076
18077 sdcc/support/scripts
18078 \end_inset 
18079 </cell>
18080 </row>
18081 <row topline="true">
18082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18083 \begin_inset Text
18084
18085 \layout Standard
18086
18087 mh2h.c
18088 \end_inset 
18089 </cell>
18090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18091 \begin_inset Text
18092
18093 \layout Standard
18094
18095 header file conversion
18096 \end_inset 
18097 </cell>
18098 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18099 \begin_inset Text
18100
18101 \layout Standard
18102
18103 sdcc/support/scripts
18104 \end_inset 
18105 </cell>
18106 </row>
18107 <row topline="true">
18108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18109 \begin_inset Text
18110
18111 \layout Standard
18112
18113 as-gbz80
18114 \end_inset 
18115 </cell>
18116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18117 \begin_inset Text
18118
18119 \layout Standard
18120
18121 Assembler
18122 \end_inset 
18123 </cell>
18124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18125 \begin_inset Text
18126
18127 \layout Standard
18128
18129
18130 \family roman 
18131 \series medium 
18132 \shape up 
18133 \size normal 
18134 \emph off 
18135 \bar no 
18136 \noun off 
18137 \color none
18138 sdcc/bin
18139 \end_inset 
18140 </cell>
18141 </row>
18142 <row topline="true">
18143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18144 \begin_inset Text
18145
18146 \layout Standard
18147
18148 as-z80
18149 \end_inset 
18150 </cell>
18151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18152 \begin_inset Text
18153
18154 \layout Standard
18155
18156 Assembler
18157 \end_inset 
18158 </cell>
18159 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18160 \begin_inset Text
18161
18162 \layout Standard
18163
18164
18165 \family roman 
18166 \series medium 
18167 \shape up 
18168 \size normal 
18169 \emph off 
18170 \bar no 
18171 \noun off 
18172 \color none
18173 sdcc/bin
18174 \end_inset 
18175 </cell>
18176 </row>
18177 <row topline="true">
18178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18179 \begin_inset Text
18180
18181 \layout Standard
18182
18183 asx8051
18184 \end_inset 
18185 </cell>
18186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18187 \begin_inset Text
18188
18189 \layout Standard
18190
18191 Assembler
18192 \end_inset 
18193 </cell>
18194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18195 \begin_inset Text
18196
18197 \layout Standard
18198
18199
18200 \family roman 
18201 \series medium 
18202 \shape up 
18203 \size normal 
18204 \emph off 
18205 \bar no 
18206 \noun off 
18207 \color none
18208 sdcc/bin
18209 \end_inset 
18210 </cell>
18211 </row>
18212 <row topline="true">
18213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18214 \begin_inset Text
18215
18216 \layout Standard
18217
18218 sdcdb
18219 \end_inset 
18220 </cell>
18221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18222 \begin_inset Text
18223
18224 \layout Standard
18225
18226 Simulator
18227 \end_inset 
18228 </cell>
18229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18230 \begin_inset Text
18231
18232 \layout Standard
18233
18234
18235 \family roman 
18236 \series medium 
18237 \shape up 
18238 \size normal 
18239 \emph off 
18240 \bar no 
18241 \noun off 
18242 \color none
18243 sdcc/bin
18244 \end_inset 
18245 </cell>
18246 </row>
18247 <row topline="true">
18248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18249 \begin_inset Text
18250
18251 \layout Standard
18252
18253 aslink
18254 \end_inset 
18255 </cell>
18256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18257 \begin_inset Text
18258
18259 \layout Standard
18260
18261 Linker
18262 \end_inset 
18263 </cell>
18264 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18265 \begin_inset Text
18266
18267 \layout Standard
18268
18269
18270 \family roman 
18271 \series medium 
18272 \shape up 
18273 \size normal 
18274 \emph off 
18275 \bar no 
18276 \noun off 
18277 \color none
18278 sdcc/bin
18279 \end_inset 
18280 </cell>
18281 </row>
18282 <row topline="true">
18283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18284 \begin_inset Text
18285
18286 \layout Standard
18287
18288 link-z80
18289 \end_inset 
18290 </cell>
18291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18292 \begin_inset Text
18293
18294 \layout Standard
18295
18296 Linker
18297 \end_inset 
18298 </cell>
18299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18300 \begin_inset Text
18301
18302 \layout Standard
18303
18304
18305 \family roman 
18306 \series medium 
18307 \shape up 
18308 \size normal 
18309 \emph off 
18310 \bar no 
18311 \noun off 
18312 \color none
18313 sdcc/bin
18314 \end_inset 
18315 </cell>
18316 </row>
18317 <row topline="true">
18318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18319 \begin_inset Text
18320
18321 \layout Standard
18322
18323 link-gbz80
18324 \end_inset 
18325 </cell>
18326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18327 \begin_inset Text
18328
18329 \layout Standard
18330
18331 Linker
18332 \end_inset 
18333 </cell>
18334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18335 \begin_inset Text
18336
18337 \layout Standard
18338
18339
18340 \family roman 
18341 \series medium 
18342 \shape up 
18343 \size normal 
18344 \emph off 
18345 \bar no 
18346 \noun off 
18347 \color none
18348 sdcc/bin
18349 \end_inset 
18350 </cell>
18351 </row>
18352 <row topline="true" bottomline="true">
18353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18354 \begin_inset Text
18355
18356 \layout Standard
18357
18358 packihx
18359 \end_inset 
18360 </cell>
18361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18362 \begin_inset Text
18363
18364 \layout Standard
18365
18366 ihx packer
18367 \end_inset 
18368 </cell>
18369 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18370 \begin_inset Text
18371
18372 \layout Standard
18373
18374
18375 \family roman 
18376 \series medium 
18377 \shape up 
18378 \size normal 
18379 \emph off 
18380 \bar no 
18381 \noun off 
18382 \color none
18383 sdcc/bin
18384 \end_inset 
18385 </cell>
18386 </row>
18387 </lyxtabular>
18388
18389 \end_inset 
18390
18391
18392 \newline 
18393
18394 \layout Section
18395
18396 Documentation
18397 \begin_inset LatexCommand \index{Documentation}
18398
18399 \end_inset 
18400
18401  included in the distribution
18402 \layout Standard
18403 \align center 
18404
18405 \begin_inset  Tabular
18406 <lyxtabular version="3" rows="10" columns="2">
18407 <features>
18408 <column alignment="left" valignment="top" leftline="true" width="0">
18409 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
18410 <row topline="true" bottomline="true">
18411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18412 \begin_inset Text
18413
18414 \layout Standard
18415
18416 Subject / Title
18417 \end_inset 
18418 </cell>
18419 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18420 \begin_inset Text
18421
18422 \layout Standard
18423
18424 Where to get / filename
18425 \end_inset 
18426 </cell>
18427 </row>
18428 <row topline="true">
18429 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18430 \begin_inset Text
18431
18432 \layout Standard
18433
18434 SDCC Compiler User Guide
18435 \end_inset 
18436 </cell>
18437 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18438 \begin_inset Text
18439
18440 \layout Standard
18441
18442 You're reading it right now
18443 \end_inset 
18444 </cell>
18445 </row>
18446 <row topline="true">
18447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18448 \begin_inset Text
18449
18450 \layout Standard
18451
18452 Changelog of SDCC
18453 \end_inset 
18454 </cell>
18455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18456 \begin_inset Text
18457
18458 \layout Standard
18459
18460 sdcc/Changelog
18461 \end_inset 
18462 </cell>
18463 </row>
18464 <row topline="true">
18465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18466 \begin_inset Text
18467
18468 \layout Standard
18469
18470 ASXXXX
18471 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
18472
18473 \end_inset 
18474
18475
18476 \begin_inset LatexCommand \index{Assembler documentation}
18477
18478 \end_inset 
18479
18480  Assemblers and ASLINK
18481 \begin_inset LatexCommand \index{aslink}
18482
18483 \end_inset 
18484
18485
18486 \begin_inset LatexCommand \index{Linker documentation}
18487
18488 \end_inset 
18489
18490  Relocating Linker
18491 \end_inset 
18492 </cell>
18493 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18494 \begin_inset Text
18495
18496 \layout Standard
18497
18498 sdcc/as/doc/asxhtm.html
18499 \end_inset 
18500 </cell>
18501 </row>
18502 <row topline="true">
18503 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18504 \begin_inset Text
18505
18506 \layout Standard
18507
18508 SDCC regression test
18509 \begin_inset LatexCommand \index{Regression test}
18510
18511 \end_inset 
18512
18513
18514 \end_inset 
18515 </cell>
18516 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18517 \begin_inset Text
18518
18519 \layout Standard
18520
18521 sdcc/doc/test_suite_spec.pdf
18522 \end_inset 
18523 </cell>
18524 </row>
18525 <row topline="true">
18526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18527 \begin_inset Text
18528
18529 \layout Standard
18530
18531 Various notes
18532 \end_inset 
18533 </cell>
18534 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18535 \begin_inset Text
18536
18537 \layout Standard
18538
18539 sdcc/doc/*
18540 \end_inset 
18541 </cell>
18542 </row>
18543 <row topline="true">
18544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18545 \begin_inset Text
18546
18547 \layout Standard
18548
18549 Notes on debugging with sdcdb
18550 \begin_inset LatexCommand \index{sdcdb (debugger)}
18551
18552 \end_inset 
18553
18554
18555 \end_inset 
18556 </cell>
18557 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18558 \begin_inset Text
18559
18560 \layout Standard
18561
18562 sdcc/debugger/README
18563 \end_inset 
18564 </cell>
18565 </row>
18566 <row topline="true">
18567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18568 \begin_inset Text
18569
18570 \layout Standard
18571
18572 Software simulator for microcontrollers
18573 \end_inset 
18574 </cell>
18575 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18576 \begin_inset Text
18577
18578 \layout Standard
18579
18580
18581 \family roman 
18582 \series medium 
18583 \shape up 
18584 \size normal 
18585 \emph off 
18586 \bar no 
18587 \noun off 
18588 \color none
18589 sdcc/sim/ucsim/doc
18590 \family default 
18591 \series default 
18592 \shape default 
18593 \size default 
18594 \emph default 
18595 \bar default 
18596 \noun default 
18597 \color default
18598 /index.html
18599 \end_inset 
18600 </cell>
18601 </row>
18602 <row topline="true">
18603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18604 \begin_inset Text
18605
18606 \layout Standard
18607
18608 Temporary notes on the pic16
18609 \begin_inset LatexCommand \index{PIC16}
18610
18611 \end_inset 
18612
18613  port
18614 \end_inset 
18615 </cell>
18616 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18617 \begin_inset Text
18618
18619 \layout Standard
18620
18621 sdcc/src/pic16/NOTES
18622 \end_inset 
18623 </cell>
18624 </row>
18625 <row topline="true" bottomline="true">
18626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18627 \begin_inset Text
18628
18629 \layout Standard
18630
18631 SDCC internal documentation (debugging file format)
18632 \end_inset 
18633 </cell>
18634 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18635 \begin_inset Text
18636
18637 \layout Standard
18638
18639 sdcc/doc/
18640 \family roman 
18641 \series medium 
18642 \shape up 
18643 \size normal 
18644 \emph off 
18645 \bar no 
18646 \noun off 
18647 \color none
18648 cdbfileformat.pd
18649 \family default 
18650 \series default 
18651 \shape default 
18652 \size default 
18653 \emph default 
18654 \bar default 
18655 \noun default 
18656 \color default
18657 f
18658 \end_inset 
18659 </cell>
18660 </row>
18661 </lyxtabular>
18662
18663 \end_inset 
18664
18665
18666 \newline 
18667
18668 \layout Section
18669
18670 Related open source tools
18671 \begin_inset LatexCommand \index{Related tools}
18672
18673 \end_inset 
18674
18675
18676 \layout Standard
18677 \align center 
18678
18679 \begin_inset  Tabular
18680 <lyxtabular version="3" rows="11" columns="3">
18681 <features>
18682 <column alignment="center" valignment="top" leftline="true" width="0pt">
18683 <column alignment="block" valignment="top" leftline="true" width="30line%">
18684 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
18685 <row topline="true" bottomline="true">
18686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18687 \begin_inset Text
18688
18689 \layout Standard
18690
18691 Name
18692 \end_inset 
18693 </cell>
18694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18695 \begin_inset Text
18696
18697 \layout Standard
18698
18699 Purpose
18700 \end_inset 
18701 </cell>
18702 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18703 \begin_inset Text
18704
18705 \layout Standard
18706
18707 Where to get
18708 \end_inset 
18709 </cell>
18710 </row>
18711 <row topline="true">
18712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18713 \begin_inset Text
18714
18715 \layout Standard
18716
18717 gpsim
18718 \begin_inset LatexCommand \index{gpsim (pic simulator)}
18719
18720 \end_inset 
18721
18722
18723 \end_inset 
18724 </cell>
18725 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18726 \begin_inset Text
18727
18728 \layout Standard
18729
18730 PIC simulator
18731 \end_inset 
18732 </cell>
18733 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18734 \begin_inset Text
18735
18736 \layout Standard
18737
18738
18739 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
18740
18741 \end_inset 
18742
18743
18744 \end_inset 
18745 </cell>
18746 </row>
18747 <row topline="true">
18748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18749 \begin_inset Text
18750
18751 \layout Standard
18752
18753 gputils
18754 \begin_inset LatexCommand \index{gputils (pic tools)}
18755
18756 \end_inset 
18757
18758
18759 \end_inset 
18760 </cell>
18761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18762 \begin_inset Text
18763
18764 \layout Standard
18765
18766 GNU PIC utilities
18767 \end_inset 
18768 </cell>
18769 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18770 \begin_inset Text
18771
18772 \layout Standard
18773
18774
18775 \begin_inset LatexCommand \url{http://gputils.sourceforge.net/}
18776
18777 \end_inset 
18778
18779
18780 \end_inset 
18781 </cell>
18782 </row>
18783 <row topline="true">
18784 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18785 \begin_inset Text
18786
18787 \layout Standard
18788
18789 flP5
18790 \end_inset 
18791 </cell>
18792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18793 \begin_inset Text
18794
18795 \layout Standard
18796
18797 PIC programmer
18798 \end_inset 
18799 </cell>
18800 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18801 \begin_inset Text
18802
18803 \layout Standard
18804
18805
18806 \begin_inset LatexCommand \url{http://digilander.libero.it/fbradasc/FLP5.html}
18807
18808 \end_inset 
18809
18810
18811 \end_inset 
18812 </cell>
18813 </row>
18814 <row topline="true">
18815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18816 \begin_inset Text
18817
18818 \layout Standard
18819
18820 indent
18821 \begin_inset LatexCommand \index{indent (source formatting tool)}
18822
18823 \end_inset 
18824
18825
18826 \end_inset 
18827 </cell>
18828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18829 \begin_inset Text
18830
18831 \layout Standard
18832
18833 Formats C source - Master of the white spaces
18834 \end_inset 
18835 </cell>
18836 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18837 \begin_inset Text
18838
18839 \layout Standard
18840
18841
18842 \begin_inset LatexCommand \url{http://home.hccnet.nl/d.ingamells/beautify.html}
18843
18844 \end_inset 
18845
18846
18847 \end_inset 
18848 </cell>
18849 </row>
18850 <row topline="true">
18851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18852 \begin_inset Text
18853
18854 \layout Standard
18855
18856 srecord
18857 \begin_inset LatexCommand \index{srecord (tool)}
18858
18859 \end_inset 
18860
18861
18862 \end_inset 
18863 </cell>
18864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18865 \begin_inset Text
18866
18867 \layout Standard
18868
18869 Object file conversion, checksumming, ...
18870 \end_inset 
18871 </cell>
18872 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18873 \begin_inset Text
18874
18875 \layout Standard
18876
18877
18878 \begin_inset LatexCommand \url{http://srecord.sourceforge.net/}
18879
18880 \end_inset 
18881
18882
18883 \end_inset 
18884 </cell>
18885 </row>
18886 <row topline="true">
18887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18888 \begin_inset Text
18889
18890 \layout Standard
18891
18892 objdump
18893 \begin_inset LatexCommand \index{objdump (tool)}
18894
18895 \end_inset 
18896
18897
18898 \end_inset 
18899 </cell>
18900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18901 \begin_inset Text
18902
18903 \layout Standard
18904
18905 Object file conversion, ...
18906 \end_inset 
18907 </cell>
18908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18909 \begin_inset Text
18910
18911 \layout Standard
18912
18913 Part of binutils (should be there anyway)
18914 \end_inset 
18915 </cell>
18916 </row>
18917 <row topline="true">
18918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18919 \begin_inset Text
18920
18921 \layout Standard
18922
18923 doxygen
18924 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
18925
18926 \end_inset 
18927
18928
18929 \end_inset 
18930 </cell>
18931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18932 \begin_inset Text
18933
18934 \layout Standard
18935
18936 Source code documentation system
18937 \end_inset 
18938 </cell>
18939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18940 \begin_inset Text
18941
18942 \layout Standard
18943
18944
18945 \begin_inset LatexCommand \url{http://www.doxygen.org}
18946
18947 \end_inset 
18948
18949
18950 \end_inset 
18951 </cell>
18952 </row>
18953 <row topline="true">
18954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18955 \begin_inset Text
18956
18957 \layout Standard
18958
18959 kdevelop
18960 \end_inset 
18961 </cell>
18962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18963 \begin_inset Text
18964
18965 \layout Standard
18966
18967 IDE (has anyone tried integrating SDCC & sdcdb? Unix only)
18968 \end_inset 
18969 </cell>
18970 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18971 \begin_inset Text
18972
18973 \layout Standard
18974
18975
18976 \begin_inset LatexCommand \url{http://www.kdevelop.org}
18977
18978 \end_inset 
18979
18980
18981 \end_inset 
18982 </cell>
18983 </row>
18984 <row topline="true">
18985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18986 \begin_inset Text
18987
18988 \layout Standard
18989
18990 splint
18991 \begin_inset LatexCommand \index{splint (syntax checking tool)}
18992
18993 \end_inset 
18994
18995
18996 \end_inset 
18997 </cell>
18998 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18999 \begin_inset Text
19000
19001 \layout Standard
19002
19003 Statically checks c sources (has anyone adapted splint for SDCC?)
19004 \end_inset 
19005 </cell>
19006 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19007 \begin_inset Text
19008
19009 \layout Standard
19010
19011
19012 \begin_inset LatexCommand \url{http://www.splint.org}
19013
19014 \end_inset 
19015
19016
19017 \end_inset 
19018 </cell>
19019 </row>
19020 <row topline="true" bottomline="true">
19021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19022 \begin_inset Text
19023
19024 \layout Standard
19025
19026 ddd
19027 \begin_inset LatexCommand \index{ddd (debugger)}
19028
19029 \end_inset 
19030
19031
19032 \end_inset 
19033 </cell>
19034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19035 \begin_inset Text
19036
19037 \layout Standard
19038
19039 Debugger, serves nicely as GUI to sdcdb
19040 \begin_inset LatexCommand \index{sdcdb (debugger)}
19041
19042 \end_inset 
19043
19044  (Unix only)
19045 \end_inset 
19046 </cell>
19047 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19048 \begin_inset Text
19049
19050 \layout Standard
19051
19052
19053 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
19054
19055 \end_inset 
19056
19057
19058 \end_inset 
19059 </cell>
19060 </row>
19061 </lyxtabular>
19062
19063 \end_inset 
19064
19065
19066 \newline 
19067
19068 \layout Section
19069
19070 Related documentation / recommended reading
19071 \layout Standard
19072 \align center 
19073
19074 \begin_inset  Tabular
19075 <lyxtabular version="3" rows="6" columns="3">
19076 <features>
19077 <column alignment="center" valignment="top" leftline="true" width="0pt">
19078 <column alignment="block" valignment="top" leftline="true" width="30line%">
19079 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
19080 <row topline="true" bottomline="true">
19081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19082 \begin_inset Text
19083
19084 \layout Standard
19085
19086 Name
19087 \end_inset 
19088 </cell>
19089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19090 \begin_inset Text
19091
19092 \layout Standard
19093
19094 Subject / Title
19095 \end_inset 
19096 </cell>
19097 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19098 \begin_inset Text
19099
19100 \layout Standard
19101
19102 Where to get
19103 \end_inset 
19104 </cell>
19105 </row>
19106 <row topline="true">
19107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19108 \begin_inset Text
19109
19110 \layout Standard
19111
19112
19113 \family roman 
19114 \series medium 
19115 \shape up 
19116 \size normal 
19117 \emph off 
19118 \bar no 
19119 \noun off 
19120 \color none
19121 c-refcard.pdf
19122 \end_inset 
19123 </cell>
19124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19125 \begin_inset Text
19126
19127 \layout Standard
19128
19129 C Reference Card
19130 \begin_inset LatexCommand \index{C Reference card}
19131
19132 \end_inset 
19133
19134 , 2 pages
19135 \end_inset 
19136 </cell>
19137 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19138 \begin_inset Text
19139
19140 \layout Standard
19141
19142
19143 \begin_inset LatexCommand \url{http://www.refcards.com/about/c.html}
19144
19145 \end_inset 
19146
19147
19148 \end_inset 
19149 </cell>
19150 </row>
19151 <row topline="true">
19152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19153 \begin_inset Text
19154
19155 \layout Standard
19156
19157 c-faq
19158 \end_inset 
19159 </cell>
19160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19161 \begin_inset Text
19162
19163 \layout Standard
19164
19165 C-FAQ-list
19166 \end_inset 
19167 </cell>
19168 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19169 \begin_inset Text
19170
19171 \layout Standard
19172
19173
19174 \begin_inset LatexCommand \url{http://www.eskimo.com/~scs/C-faq/top.html}
19175
19176 \end_inset 
19177
19178
19179 \end_inset 
19180 </cell>
19181 </row>
19182 <row topline="true">
19183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19184 \begin_inset Text
19185
19186 \layout Standard
19187
19188 \end_inset 
19189 </cell>
19190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19191 \begin_inset Text
19192
19193 \layout Standard
19194
19195 Latest datasheet of the target CPU
19196 \end_inset 
19197 </cell>
19198 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19199 \begin_inset Text
19200
19201 \layout Standard
19202
19203 vendor
19204 \end_inset 
19205 </cell>
19206 </row>
19207 <row topline="true">
19208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19209 \begin_inset Text
19210
19211 \layout Standard
19212
19213 \end_inset 
19214 </cell>
19215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19216 \begin_inset Text
19217
19218 \layout Standard
19219
19220 Revision history of datasheet
19221 \end_inset 
19222 </cell>
19223 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19224 \begin_inset Text
19225
19226 \layout Standard
19227
19228 vendor
19229 \end_inset 
19230 </cell>
19231 </row>
19232 <row topline="true" bottomline="true">
19233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19234 \begin_inset Text
19235
19236 \layout Standard
19237
19238 S.
19239  S.
19240  Muchnick
19241 \end_inset 
19242 </cell>
19243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19244 \begin_inset Text
19245
19246 \layout Standard
19247
19248 Advanced Compiler Design and Implementation
19249 \end_inset 
19250 </cell>
19251 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19252 \begin_inset Text
19253
19254 \layout Standard
19255
19256 bookstore (very dedicated, probably read other books first)
19257 \end_inset 
19258 </cell>
19259 </row>
19260 </lyxtabular>
19261
19262 \end_inset 
19263
19264
19265 \newline 
19266
19267 \layout Section
19268
19269 Some Questions
19270 \layout Standard
19271
19272 Some questions answered, some pointers given - it might be time to in turn
19273  ask 
19274 \emph on 
19275 you
19276 \emph default 
19277  some questions: 
19278 \layout Itemize
19279
19280 can you solve your project with the selected microcontroller? Would you
19281  find out early or rather late that your target is too small/slow/whatever?
19282  Can you switch to a slightly better device if it doesn't fit?
19283 \layout Itemize
19284
19285 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
19286  and/or another programming language be more adequate? Would an operating
19287  system on the target device help?
19288 \layout Itemize
19289
19290 if you solved the problem, will the marketing department be happy?
19291 \layout Itemize
19292
19293 if the marketing department is happy, will customers be happy?
19294 \layout Itemize
19295
19296 if you're the project manager, marketing department and maybe even the customer
19297  in one person, have you tried to see the project from the outside?
19298 \layout Itemize
19299
19300 is the project done if you think it is done? Or is just that other interface/pro
19301 tocol/feature/configuration/option missing? How about website, manual(s),
19302  internationali(z|s)ation, packaging, labels, 2nd source for components,
19303  electromagnetic compatability/interference, documentation for production,
19304  production test software, update mechanism, patent issues?
19305 \layout Itemize
19306
19307 is your project adequately positioned in that magic triangle: fame, fortune,
19308  fun?
19309 \layout Standard
19310
19311 Maybe not all answers to these questions are known and some answers may
19312  even be 
19313 \emph on 
19314 no
19315 \emph default 
19316 , nevertheless knowing these questions may help you to avoid burnout
19317 \begin_inset Foot
19318 collapsed false
19319
19320 \layout Standard
19321
19322 burnout is bad for electronic devices, programmers and motorcycle tyres
19323 \end_inset 
19324
19325 .
19326  Chances are you didn't want to hear some of them...
19327 \layout Chapter
19328
19329 Support
19330 \begin_inset LatexCommand \index{Support}
19331
19332 \end_inset 
19333
19334
19335 \layout Standard
19336
19337 SDCC has grown to be a large project.
19338  The compiler alone (without the preprocessor, assembler and linker) is
19339  well over 100,000 lines of code (blank stripped).
19340  The open source nature of this project is a key to its continued growth
19341  and support.
19342  You gain the benefit and support of many active software developers and
19343  end users.
19344  Is SDCC perfect? No, that's why we need your help.
19345  The developers take pride in fixing reported bugs.
19346  You can help by reporting the bugs and helping other SDCC users.
19347  There are lots of ways to contribute, and we encourage you to take part
19348  in making SDCC a great software package.
19349  
19350 \layout Standard
19351
19352 The SDCC project is hosted on the SDCC sourceforge site at 
19353 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
19354
19355 \end_inset 
19356
19357 .
19358  You'll find the complete set of mailing lists
19359 \begin_inset LatexCommand \index{Mailing list(s)}
19360
19361 \end_inset 
19362
19363 , forums, bug reporting system, patch submission
19364 \begin_inset LatexCommand \index{Patch submission}
19365
19366 \end_inset 
19367
19368  system, download
19369 \begin_inset LatexCommand \index{download}
19370
19371 \end_inset 
19372
19373  area and cvs code repository
19374 \begin_inset LatexCommand \index{cvs code repository}
19375
19376 \end_inset 
19377
19378  there.
19379 \layout Section
19380
19381 Reporting Bugs
19382 \begin_inset LatexCommand \index{Bug reporting}
19383
19384 \end_inset 
19385
19386
19387 \begin_inset LatexCommand \index{Reporting bugs}
19388
19389 \end_inset 
19390
19391
19392 \layout Standard
19393
19394 The recommended way of reporting bugs is using the infrastructure of the
19395  sourceforge site.
19396  You can follow the status of bug reports there and have an overview about
19397  the known bugs.
19398 \layout Standard
19399
19400 Bug reports are automatically forwarded to the developer mailing list and
19401  will be fixed ASAP.
19402  When reporting a bug, it is very useful to include a small test program
19403  (the smaller the better) which reproduces the problem.
19404  If you can isolate the problem by looking at the generated assembly code,
19405  this can be very helpful.
19406  Compiling your program with the -
19407 \begin_inset ERT
19408 status Collapsed
19409
19410 \layout Standard
19411
19412 \backslash 
19413 /
19414 \end_inset 
19415
19416 -dumpall
19417 \begin_inset LatexCommand \index{-\/-dumpall}
19418
19419 \end_inset 
19420
19421  option can sometimes be useful in locating optimization problems.
19422  When reporting a bug please maker sure you:
19423 \layout Enumerate
19424
19425 Attach the code you are compiling with SDCC.
19426  
19427 \layout Enumerate
19428
19429 Specify the exact command you use to run SDCC, or attach your Makefile.
19430  
19431 \layout Enumerate
19432
19433 Specify the SDCC version (type "
19434 \family sans 
19435 \series bold 
19436 sdcc -v
19437 \family default 
19438 \series default 
19439 "), your platform, and operating system.
19440  
19441 \layout Enumerate
19442
19443 Provide an exact copy of any error message or incorrect output.
19444  
19445 \layout Enumerate
19446
19447 Put something meaningful in the subject of your message.
19448 \layout Standard
19449
19450 Please attempt to include these 5 important parts, as applicable, in all
19451  requests for support or when reporting any problems or bugs with SDCC.
19452  Though this will make your message lengthy, it will greatly improve your
19453  chance that SDCC users and developers will be able to help you.
19454  Some SDCC developers are frustrated by bug reports without code provided
19455  that they can use to reproduce and ultimately fix the problem, so please
19456  be sure to provide sample code if you are reporting a bug! 
19457 \layout Standard
19458
19459 Please have a short check that you are using a recent version of SDCC and
19460  the bug is not yet known.
19461  This is the link for reporting bugs: 
19462 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
19463
19464 \end_inset 
19465
19466 .
19467 \layout Section
19468
19469 Requesting Features
19470 \begin_inset LatexCommand \label{sub:Requesting-Features}
19471
19472 \end_inset 
19473
19474
19475 \begin_inset LatexCommand \index{Feature request}
19476
19477 \end_inset 
19478
19479
19480 \begin_inset LatexCommand \index{Requesting features}
19481
19482 \end_inset 
19483
19484
19485 \layout Standard
19486
19487 Like bug reports feature requests are forwarded to the developer mailing
19488  list.
19489  This is the link for requesting features: 
19490 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
19491
19492 \end_inset 
19493
19494 .
19495 \layout Section
19496
19497 Submitting patches
19498 \layout Standard
19499
19500 Like bug reports contributed patches are forwarded to the developer mailing
19501  list.
19502  This is the link for submitting patches
19503 \begin_inset LatexCommand \index{Patch submission}
19504
19505 \end_inset 
19506
19507
19508 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
19509
19510 \end_inset 
19511
19512 .
19513 \layout Standard
19514
19515 You need to specify some parameters to the 
19516 \family typewriter 
19517 diff
19518 \family default 
19519  command for the patches to be useful.
19520  If you modified more than one file a patch created f.e.
19521  with 
19522 \family sans 
19523 \series bold 
19524
19525 \begin_inset Quotes sld
19526 \end_inset 
19527
19528 diff -Naur unmodified_directory modified_directory >my_changes.patch
19529 \begin_inset Quotes srd
19530 \end_inset 
19531
19532
19533 \family default 
19534 \series default 
19535  will be fine, otherwise 
19536 \family sans 
19537 \series bold 
19538
19539 \begin_inset Quotes sld
19540 \end_inset 
19541
19542 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
19543 \begin_inset Quotes srd
19544 \end_inset 
19545
19546
19547 \series default 
19548  
19549 \family default 
19550 will do.
19551 \layout Section
19552
19553 Getting Help
19554 \layout Standard
19555
19556 These links should take you directly to the 
19557 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
19558
19559 \end_inset 
19560
19561
19562 \begin_inset Foot
19563 collapsed false
19564
19565 \layout Standard
19566
19567 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
19568  automated messages (mid 2003)
19569 \end_inset 
19570
19571  and the 
19572 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
19573
19574 \end_inset 
19575
19576 , lists
19577 \begin_inset LatexCommand \index{Mailing list(s)}
19578
19579 \end_inset 
19580
19581  and forums are archived and searchable so if you are lucky someone already
19582  had a similar problem.
19583  While mails to the lists themselves are delivered promptly their web front
19584  end on sourceforge sometimes shows a severe time lag (up to several weeks),
19585  if you're seriously using SDCC please consider subscribing to the lists.
19586 \layout Section
19587
19588 ChangeLog
19589 \layout Standard
19590
19591 You can follow the status of the cvs version
19592 \begin_inset LatexCommand \index{version}
19593
19594 \end_inset 
19595
19596  of SDCC by watching the Changelog
19597 \begin_inset LatexCommand \index{Changelog}
19598
19599 \end_inset 
19600
19601  in the cvs-repository
19602 \newline 
19603
19604 \size footnotesize 
19605
19606 \begin_inset LatexCommand \htmlurl{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/sdcc/sdcc/ChangeLog?rev=HEAD&content-type=text/plain}
19607
19608 \end_inset 
19609
19610 .
19611 \layout Section
19612
19613 Release policy
19614 \begin_inset LatexCommand \index{Release policy}
19615
19616 \end_inset 
19617
19618
19619 \layout Standard
19620
19621 Historically there often were long delays between official releases and
19622  the sourceforge download area tends to get not updated at all.
19623  Excuses in the past might have referred to problems with live range analysis,
19624  but as this was fixed a while ago, the current problem is that another
19625  excuse has to be found.
19626  Kidding aside, we have to get better there! On the other hand there are
19627  daily snapshots available at 
19628 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
19629
19630 \end_inset 
19631
19632 , and you can always build the very last version (hopefully with many bugs
19633  fixed, and features added) from the source code available at 
19634 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
19635
19636 \end_inset 
19637
19638 .
19639 \layout Section
19640
19641 Examples
19642 \begin_inset LatexCommand \index{Examples}
19643
19644 \end_inset 
19645
19646
19647 \layout Standard
19648
19649 You'll find some small examples in the directory 
19650 \emph on 
19651 sdcc/device/examples/.
19652  
19653 \emph default 
19654 More examples and libraries are available at
19655 \emph on 
19656  The SDCC Open Knowledge Resource 
19657 \begin_inset LatexCommand \url{http://www.qsl.net/dl9sec/SDCC_OKR.html}
19658
19659 \end_inset 
19660
19661  
19662 \emph default 
19663 web site or at 
19664 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
19665
19666 \end_inset 
19667
19668 .
19669 \layout Comment
19670
19671 I did insert a reference to Paul's web site here although it seems rather
19672  dedicated to a specific 8032 board (I think it's okay because it f.e.
19673  shows LCD/Harddisc interface and has a free 8051 monitor.
19674  Independent 8032 board vendors face hard competition of heavily subsidized
19675  development boards anyway).
19676 \layout Comment
19677
19678 Maybe we should include some links to real world applications.
19679  Preferably pointer to pointers (one for each architecture) so this stays
19680  manageable here?
19681 \layout Section
19682
19683 Quality control
19684 \begin_inset LatexCommand \index{Quality control}
19685
19686 \end_inset 
19687
19688
19689 \layout Standard
19690
19691 The compiler is passed through nightly compile and build checks.
19692  The so called 
19693 \shape italic 
19694 regression tests
19695 \shape default 
19696
19697 \begin_inset LatexCommand \index{Regression test}
19698
19699 \end_inset 
19700
19701  check that SDCC itself compiles flawlessly on several platforms and checks
19702  the quality of the code generated by SDCC by running the code through simulator
19703 s.
19704  There is a separate document 
19705 \shape italic 
19706 test_suite.pdf
19707 \begin_inset LatexCommand \index{Test suite}
19708
19709 \end_inset 
19710
19711
19712 \shape default 
19713  about this.
19714 \layout Standard
19715
19716 You'll find the test code in the directory 
19717 \shape italic 
19718 sdcc/support/regression
19719 \shape default 
19720 .
19721  You can run these tests manually by running 
19722 \family sans 
19723 make
19724 \family default 
19725  in this directory (or f.e.
19726  
19727 \family sans 
19728 \series bold 
19729
19730 \begin_inset Quotes sld
19731 \end_inset 
19732
19733 make test-mcs51
19734 \begin_inset Quotes srd
19735 \end_inset 
19736
19737
19738 \family default 
19739 \series default 
19740  if you don't want to run the complete tests).
19741  The test code might also be interesting if you want to look for examples
19742 \begin_inset LatexCommand \index{Examples}
19743
19744 \end_inset 
19745
19746  checking corner cases of SDCC or if you plan to submit patches
19747 \begin_inset LatexCommand \index{Patch submission}
19748
19749 \end_inset 
19750
19751 .
19752 \layout Standard
19753
19754 The pic port uses a different set of regression tests, you'll find them
19755  in the directory 
19756 \shape italic 
19757 sdcc/src/regression
19758 \shape default 
19759 .
19760 \layout Chapter
19761 \pagebreak_top 
19762 SDCC Technical Data
19763 \layout Section
19764
19765 Optimizations
19766 \begin_inset LatexCommand \index{Optimizations}
19767
19768 \end_inset 
19769
19770
19771 \layout Standard
19772
19773 SDCC performs a host of standard optimizations in addition to some MCU specific
19774  optimizations.
19775  
19776 \layout Subsection
19777
19778 Sub-expression Elimination
19779 \begin_inset LatexCommand \index{Subexpression elimination}
19780
19781 \end_inset 
19782
19783
19784 \layout Standard
19785
19786 The compiler does local and 
19787 \emph on 
19788 g
19789 \emph default 
19790 lobal 
19791 \emph on 
19792 c
19793 \emph default 
19794 ommon 
19795 \emph on 
19796 s
19797 \emph default 
19798 ubexpression 
19799 \emph on 
19800 e
19801 \emph default 
19802 limination, e.g.: 
19803 \layout Verse
19804
19805
19806 \family typewriter 
19807 i = x + y + 1; 
19808 \newline 
19809 j = x + y;
19810 \layout Standard
19811
19812 will be translated to
19813 \layout Verse
19814
19815
19816 \family typewriter 
19817 iTemp = x + y; 
19818 \newline 
19819 i = iTemp + 1; 
19820 \newline 
19821 j = iTemp;
19822 \layout Standard
19823
19824 Some subexpressions are not as obvious as the above example, e.g.:
19825 \layout Verse
19826
19827
19828 \family typewriter 
19829 a->b[i].c = 10; 
19830 \newline 
19831 a->b[i].d = 11;
19832 \layout Standard
19833
19834 In this case the address arithmetic a->b[i] will be computed only once;
19835  the equivalent code in C would be.
19836 \layout Verse
19837
19838
19839 \family typewriter 
19840 iTemp = a->b[i]; 
19841 \newline 
19842 iTemp.c = 10; 
19843 \newline 
19844 iTemp.d = 11;
19845 \layout Standard
19846
19847 The compiler will try to keep these temporary variables in registers.
19848 \layout Subsection
19849
19850 Dead-Code Elimination
19851 \begin_inset LatexCommand \index{Dead-code elimination}
19852
19853 \end_inset 
19854
19855
19856 \layout Verse
19857
19858
19859 \family typewriter 
19860 int global;
19861 \newline 
19862
19863 \newline 
19864 void f () { 
19865 \newline 
19866 \SpecialChar ~
19867 \SpecialChar ~
19868 int i; 
19869 \newline 
19870 \SpecialChar ~
19871 \SpecialChar ~
19872 i = 1; \SpecialChar ~
19873 \SpecialChar ~
19874 \SpecialChar ~
19875 \SpecialChar ~
19876 \SpecialChar ~
19877 /* dead store */ 
19878 \newline 
19879 \SpecialChar ~
19880 \SpecialChar ~
19881 global = 1;\SpecialChar ~
19882 /* dead store */ 
19883 \newline 
19884 \SpecialChar ~
19885 \SpecialChar ~
19886 global = 2; 
19887 \newline 
19888 \SpecialChar ~
19889 \SpecialChar ~
19890 return; 
19891 \newline 
19892 \SpecialChar ~
19893 \SpecialChar ~
19894 global = 3;\SpecialChar ~
19895 /* unreachable */ 
19896 \newline 
19897 }
19898 \layout Standard
19899
19900 will be changed to
19901 \layout Verse
19902
19903
19904 \family typewriter 
19905 int global;
19906 \newline 
19907
19908 \newline 
19909 void f () {
19910 \newline 
19911 \SpecialChar ~
19912 \SpecialChar ~
19913 global = 2; 
19914 \newline 
19915 }
19916 \layout Subsection
19917
19918 Copy-Propagation
19919 \begin_inset LatexCommand \index{Copy propagation}
19920
19921 \end_inset 
19922
19923
19924 \layout Verse
19925
19926
19927 \family typewriter 
19928 int f() { 
19929 \newline 
19930 \SpecialChar ~
19931 \SpecialChar ~
19932 int i, j; 
19933 \newline 
19934 \SpecialChar ~
19935 \SpecialChar ~
19936 i = 10; 
19937 \newline 
19938 \SpecialChar ~
19939 \SpecialChar ~
19940 j = i; 
19941 \newline 
19942 \SpecialChar ~
19943 \SpecialChar ~
19944 return j; 
19945 \newline 
19946 }
19947 \layout Standard
19948
19949 will be changed to 
19950 \layout Verse
19951
19952
19953 \family typewriter 
19954 int f() { 
19955 \newline 
19956 \SpecialChar ~
19957 \SpecialChar ~
19958 int i, j; 
19959 \newline 
19960 \SpecialChar ~
19961 \SpecialChar ~
19962 i = 10; 
19963 \newline 
19964 \SpecialChar ~
19965 \SpecialChar ~
19966 j = 10; 
19967 \newline 
19968 \SpecialChar ~
19969 \SpecialChar ~
19970 return 10; 
19971 \newline 
19972 }
19973 \layout Standard
19974
19975 Note: the dead stores created by this copy propagation will be eliminated
19976  by dead-code elimination.
19977 \layout Subsection
19978
19979 Loop Optimizations
19980 \begin_inset LatexCommand \index{Loop optimization}
19981
19982 \end_inset 
19983
19984
19985 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
19986
19987 \end_inset 
19988
19989
19990 \layout Standard
19991
19992 Two types of loop optimizations are done by SDCC 
19993 \emph on 
19994 loop invariant
19995 \emph default 
19996  lifting and
19997 \emph on 
19998  strength reduction
19999 \emph default 
20000  of loop induction variables.
20001  In addition to the strength reduction the optimizer marks the induction
20002  variables and the register allocator tries to keep the induction variables
20003  in registers for the duration of the loop.
20004  Because of this preference of the register allocator
20005 \begin_inset LatexCommand \index{Register allocation}
20006
20007 \end_inset 
20008
20009 , loop induction optimization causes an increase in register pressure, which
20010  may cause unwanted spilling of other temporary variables into the stack
20011 \begin_inset LatexCommand \index{stack}
20012
20013 \end_inset 
20014
20015  / data space.
20016  The compiler will generate a warning message when it is forced to allocate
20017  extra space either on the stack or data space.
20018  If this extra space allocation is undesirable then induction optimization
20019  can be eliminated either for the entire source file (with -
20020 \begin_inset ERT
20021 status Collapsed
20022
20023 \layout Standard
20024
20025 \backslash 
20026 /
20027 \end_inset 
20028
20029 -noinduction option) or for a given function only using #pragma\SpecialChar ~
20030 noinduction
20031 \begin_inset LatexCommand \index{\#pragma noinduction}
20032
20033 \end_inset 
20034
20035 .
20036 \newline 
20037
20038 \newline 
20039 Loop Invariant:
20040 \layout Verse
20041
20042
20043 \family typewriter 
20044 for (i = 0 ; i < 100 ; i ++) 
20045 \newline 
20046 \SpecialChar ~
20047 \SpecialChar ~
20048 \SpecialChar ~
20049 \SpecialChar ~
20050 f += k + l;
20051 \layout Standard
20052
20053 changed to
20054 \layout Verse
20055
20056
20057 \family typewriter 
20058 itemp = k + l; 
20059 \newline 
20060 for (i = 0; i < 100; i++) 
20061 \newline 
20062 \SpecialChar ~
20063 \SpecialChar ~
20064 \SpecialChar ~
20065 \SpecialChar ~
20066 f += itemp;
20067 \layout Standard
20068
20069 As mentioned previously some loop invariants are not as apparent, all static
20070  address computations are also moved out of the loop.
20071 \newline 
20072
20073 \newline 
20074 Strength Reduction
20075 \begin_inset LatexCommand \index{Strength reduction}
20076
20077 \end_inset 
20078
20079 , this optimization substitutes an expression by a cheaper expression:
20080 \layout Verse
20081
20082
20083 \family typewriter 
20084 for (i=0;i < 100; i++)
20085 \newline 
20086 \SpecialChar ~
20087 \SpecialChar ~
20088 \SpecialChar ~
20089 \SpecialChar ~
20090 ar[i*5] = i*3;
20091 \layout Standard
20092
20093 changed to
20094 \layout Verse
20095
20096
20097 \family typewriter 
20098 itemp1 = 0; 
20099 \newline 
20100 itemp2 = 0; 
20101 \newline 
20102 for (i=0;i< 100;i++) { 
20103 \newline 
20104 \SpecialChar ~
20105 \SpecialChar ~
20106 \SpecialChar ~
20107 \SpecialChar ~
20108 ar[itemp1] = itemp2; 
20109 \newline 
20110 \SpecialChar ~
20111 \SpecialChar ~
20112 \SpecialChar ~
20113 \SpecialChar ~
20114 itemp1 += 5; 
20115 \newline 
20116 \SpecialChar ~
20117 \SpecialChar ~
20118 \SpecialChar ~
20119 \SpecialChar ~
20120 itemp2 += 3; 
20121 \newline 
20122 }
20123 \layout Standard
20124
20125 The more expensive multiplication
20126 \begin_inset LatexCommand \index{Multiplication}
20127
20128 \end_inset 
20129
20130  is changed to a less expensive addition.
20131 \layout Subsection
20132
20133 Loop Reversing
20134 \begin_inset LatexCommand \index{Loop reversing}
20135
20136 \end_inset 
20137
20138
20139 \layout Standard
20140
20141 This optimization is done to reduce the overhead of checking loop boundaries
20142  for every iteration.
20143  Some simple loops can be reversed and implemented using a 
20144 \begin_inset Quotes eld
20145 \end_inset 
20146
20147 decrement and jump if not zero
20148 \begin_inset Quotes erd
20149 \end_inset 
20150
20151  instruction.
20152  SDCC checks for the following criterion to determine if a loop is reversible
20153  (note: more sophisticated compilers use data-dependency analysis to make
20154  this determination, SDCC uses a more simple minded analysis).
20155 \layout Itemize
20156
20157 The 'for' loop is of the form 
20158 \newline 
20159
20160 \newline 
20161
20162 \family typewriter 
20163 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
20164  += 1])
20165 \newline 
20166 \SpecialChar ~
20167 \SpecialChar ~
20168 \SpecialChar ~
20169 \SpecialChar ~
20170 <for body>
20171 \layout Itemize
20172
20173 The <for body> does not contain 
20174 \begin_inset Quotes eld
20175 \end_inset 
20176
20177 continue
20178 \begin_inset Quotes erd
20179 \end_inset 
20180
20181  or 'break
20182 \begin_inset Quotes erd
20183 \end_inset 
20184
20185 .
20186 \layout Itemize
20187
20188 All goto's are contained within the loop.
20189 \layout Itemize
20190
20191 No function calls within the loop.
20192 \layout Itemize
20193
20194 The loop control variable <sym> is not assigned any value within the loop
20195 \layout Itemize
20196
20197 The loop control variable does NOT participate in any arithmetic operation
20198  within the loop.
20199 \layout Itemize
20200
20201 There are NO switch statements in the loop.
20202 \layout Subsection
20203
20204 Algebraic Simplifications
20205 \layout Standard
20206
20207 SDCC does numerous algebraic simplifications, the following is a small sub-set
20208  of these optimizations.
20209 \layout Verse
20210
20211
20212 \family typewriter 
20213 i = j + 0;\SpecialChar ~
20214 \SpecialChar ~
20215 \SpecialChar ~
20216 \SpecialChar ~
20217  /* changed to: */\SpecialChar ~
20218 \SpecialChar ~
20219 \SpecialChar ~
20220 \SpecialChar ~
20221  i = j; 
20222 \newline 
20223 i /= 2;\SpecialChar ~
20224 \SpecialChar ~
20225 \SpecialChar ~
20226 \SpecialChar ~
20227 \SpecialChar ~
20228 \SpecialChar ~
20229 \SpecialChar ~
20230  /* changed to: */\SpecialChar ~
20231 \SpecialChar ~
20232 \SpecialChar ~
20233 \SpecialChar ~
20234  i >>= 1; 
20235 \newline 
20236 i = j - j;\SpecialChar ~
20237 \SpecialChar ~
20238 \SpecialChar ~
20239 \SpecialChar ~
20240  /* changed to: */\SpecialChar ~
20241 \SpecialChar ~
20242 \SpecialChar ~
20243 \SpecialChar ~
20244  i = 0; 
20245 \newline 
20246 i = j / 1;\SpecialChar ~
20247 \SpecialChar ~
20248 \SpecialChar ~
20249 \SpecialChar ~
20250  /* changed to: */\SpecialChar ~
20251 \SpecialChar ~
20252 \SpecialChar ~
20253 \SpecialChar ~
20254  i = j;
20255 \layout Standard
20256
20257 Note the subexpressions
20258 \begin_inset LatexCommand \index{Subexpression}
20259
20260 \end_inset 
20261
20262  given above are generally introduced by macro expansions or as a result
20263  of copy/constant propagation.
20264 \layout Subsection
20265
20266 'switch' Statements
20267 \begin_inset LatexCommand \label{sub:'switch'-Statements}
20268
20269 \end_inset 
20270
20271
20272 \begin_inset LatexCommand \index{switch statement}
20273
20274 \end_inset 
20275
20276
20277 \layout Standard
20278
20279 SDCC can optimize switch statements to jump tables
20280 \begin_inset LatexCommand \index{jump tables}
20281
20282 \end_inset 
20283
20284 .
20285  It makes the decision based on an estimate of the generated code size.
20286  SDCC is quite liberal in the requirements for jump table generation: 
20287 \layout Itemize
20288
20289 The labels need not be in order, and the starting number need not be one
20290  or zero, the case labels are in numerical sequence or not too many case
20291  labels are missing.
20292 \begin_deeper 
20293 \layout Verse
20294
20295
20296 \family typewriter 
20297 switch(i) {\SpecialChar ~
20298 \SpecialChar ~
20299 \SpecialChar ~
20300 \SpecialChar ~
20301 \SpecialChar ~
20302 \SpecialChar ~
20303 \SpecialChar ~
20304 \SpecialChar ~
20305 \SpecialChar ~
20306 \SpecialChar ~
20307 \SpecialChar ~
20308 \SpecialChar ~
20309 \SpecialChar ~
20310 \SpecialChar ~
20311 \SpecialChar ~
20312 \SpecialChar ~
20313 \SpecialChar ~
20314 \SpecialChar ~
20315 \SpecialChar ~
20316 \SpecialChar ~
20317 \SpecialChar ~
20318 \SpecialChar ~
20319 \SpecialChar ~
20320 \SpecialChar ~
20321 \SpecialChar ~
20322 \SpecialChar ~
20323 switch (i) { 
20324 \newline 
20325 \SpecialChar ~
20326 \SpecialChar ~
20327 \SpecialChar ~
20328 case 4: ...\SpecialChar ~
20329 \SpecialChar ~
20330 \SpecialChar ~
20331 \SpecialChar ~
20332 \SpecialChar ~
20333 \SpecialChar ~
20334 \SpecialChar ~
20335 \SpecialChar ~
20336 \SpecialChar ~
20337 \SpecialChar ~
20338 \SpecialChar ~
20339 \SpecialChar ~
20340 \SpecialChar ~
20341 \SpecialChar ~
20342 \SpecialChar ~
20343 \SpecialChar ~
20344 \SpecialChar ~
20345 \SpecialChar ~
20346 \SpecialChar ~
20347 \SpecialChar ~
20348 \SpecialChar ~
20349 \SpecialChar ~
20350 \SpecialChar ~
20351 \SpecialChar ~
20352 \SpecialChar ~
20353 \SpecialChar ~
20354 case 0: ...
20355  
20356 \newline 
20357 \SpecialChar ~
20358 \SpecialChar ~
20359 \SpecialChar ~
20360 case 5: ...\SpecialChar ~
20361 \SpecialChar ~
20362 \SpecialChar ~
20363 \SpecialChar ~
20364 \SpecialChar ~
20365 \SpecialChar ~
20366 \SpecialChar ~
20367 \SpecialChar ~
20368 \SpecialChar ~
20369 \SpecialChar ~
20370 \SpecialChar ~
20371 \SpecialChar ~
20372 \SpecialChar ~
20373 \SpecialChar ~
20374 \SpecialChar ~
20375 \SpecialChar ~
20376 \SpecialChar ~
20377 \SpecialChar ~
20378 \SpecialChar ~
20379 \SpecialChar ~
20380 \SpecialChar ~
20381 \SpecialChar ~
20382 \SpecialChar ~
20383 \SpecialChar ~
20384 \SpecialChar ~
20385 \SpecialChar ~
20386 case 1: ...
20387  
20388 \newline 
20389 \SpecialChar ~
20390 \SpecialChar ~
20391 \SpecialChar ~
20392 case 3: ...\SpecialChar ~
20393 \SpecialChar ~
20394 \SpecialChar ~
20395 \SpecialChar ~
20396 \SpecialChar ~
20397 \SpecialChar ~
20398 \SpecialChar ~
20399 \SpecialChar ~
20400 \SpecialChar ~
20401 \SpecialChar ~
20402 \SpecialChar ~
20403 \SpecialChar ~
20404 \SpecialChar ~
20405 \SpecialChar ~
20406 \SpecialChar ~
20407 \SpecialChar ~
20408 \SpecialChar ~
20409 \SpecialChar ~
20410 \SpecialChar ~
20411 \SpecialChar ~
20412 \SpecialChar ~
20413 \SpecialChar ~
20414 \SpecialChar ~
20415 \SpecialChar ~
20416 \SpecialChar ~
20417 \SpecialChar ~
20418
20419 \newline 
20420 \SpecialChar ~
20421 \SpecialChar ~
20422 \SpecialChar ~
20423 case 6: ...\SpecialChar ~
20424 \SpecialChar ~
20425 \SpecialChar ~
20426 \SpecialChar ~
20427 \SpecialChar ~
20428 \SpecialChar ~
20429 \SpecialChar ~
20430 \SpecialChar ~
20431 \SpecialChar ~
20432 \SpecialChar ~
20433 \SpecialChar ~
20434 \SpecialChar ~
20435 \SpecialChar ~
20436 \SpecialChar ~
20437 \SpecialChar ~
20438 \SpecialChar ~
20439 \SpecialChar ~
20440 \SpecialChar ~
20441 \SpecialChar ~
20442 \SpecialChar ~
20443 \SpecialChar ~
20444 \SpecialChar ~
20445 \SpecialChar ~
20446 \SpecialChar ~
20447 \SpecialChar ~
20448 \SpecialChar ~
20449 case 3: ...
20450  
20451 \newline 
20452 \SpecialChar ~
20453 \SpecialChar ~
20454 \SpecialChar ~
20455 case 7: ...\SpecialChar ~
20456 \SpecialChar ~
20457 \SpecialChar ~
20458 \SpecialChar ~
20459 \SpecialChar ~
20460 \SpecialChar ~
20461 \SpecialChar ~
20462 \SpecialChar ~
20463 \SpecialChar ~
20464 \SpecialChar ~
20465 \SpecialChar ~
20466 \SpecialChar ~
20467 \SpecialChar ~
20468 \SpecialChar ~
20469 \SpecialChar ~
20470 \SpecialChar ~
20471 \SpecialChar ~
20472 \SpecialChar ~
20473 \SpecialChar ~
20474 \SpecialChar ~
20475 \SpecialChar ~
20476 \SpecialChar ~
20477 \SpecialChar ~
20478 \SpecialChar ~
20479 \SpecialChar ~
20480 \SpecialChar ~
20481 case 4: ...
20482  
20483 \newline 
20484 \SpecialChar ~
20485 \SpecialChar ~
20486 \SpecialChar ~
20487 case 8: ...\SpecialChar ~
20488 \SpecialChar ~
20489 \SpecialChar ~
20490 \SpecialChar ~
20491 \SpecialChar ~
20492 \SpecialChar ~
20493 \SpecialChar ~
20494 \SpecialChar ~
20495 \SpecialChar ~
20496 \SpecialChar ~
20497 \SpecialChar ~
20498 \SpecialChar ~
20499 \SpecialChar ~
20500 \SpecialChar ~
20501 \SpecialChar ~
20502 \SpecialChar ~
20503 \SpecialChar ~
20504 \SpecialChar ~
20505 \SpecialChar ~
20506 \SpecialChar ~
20507 \SpecialChar ~
20508 \SpecialChar ~
20509 \SpecialChar ~
20510 \SpecialChar ~
20511 \SpecialChar ~
20512 \SpecialChar ~
20513 case 5: ...
20514  
20515 \newline 
20516 \SpecialChar ~
20517 \SpecialChar ~
20518 \SpecialChar ~
20519 case 9: ...\SpecialChar ~
20520 \SpecialChar ~
20521 \SpecialChar ~
20522 \SpecialChar ~
20523 \SpecialChar ~
20524 \SpecialChar ~
20525 \SpecialChar ~
20526 \SpecialChar ~
20527 \SpecialChar ~
20528 \SpecialChar ~
20529 \SpecialChar ~
20530 \SpecialChar ~
20531 \SpecialChar ~
20532 \SpecialChar ~
20533 \SpecialChar ~
20534 \SpecialChar ~
20535 \SpecialChar ~
20536 \SpecialChar ~
20537 \SpecialChar ~
20538 \SpecialChar ~
20539 \SpecialChar ~
20540 \SpecialChar ~
20541 \SpecialChar ~
20542 \SpecialChar ~
20543 \SpecialChar ~
20544 \SpecialChar ~
20545 case 6: ...
20546  
20547 \newline 
20548 \SpecialChar ~
20549 \SpecialChar ~
20550 \SpecialChar ~
20551 case 10: ...\SpecialChar ~
20552 \SpecialChar ~
20553 \SpecialChar ~
20554 \SpecialChar ~
20555 \SpecialChar ~
20556 \SpecialChar ~
20557 \SpecialChar ~
20558 \SpecialChar ~
20559 \SpecialChar ~
20560 \SpecialChar ~
20561 \SpecialChar ~
20562 \SpecialChar ~
20563 \SpecialChar ~
20564 \SpecialChar ~
20565 \SpecialChar ~
20566 \SpecialChar ~
20567 \SpecialChar ~
20568 \SpecialChar ~
20569 \SpecialChar ~
20570 \SpecialChar ~
20571 \SpecialChar ~
20572 \SpecialChar ~
20573 \SpecialChar ~
20574 \SpecialChar ~
20575 \SpecialChar ~
20576 case 7: ...
20577  
20578 \newline 
20579 \SpecialChar ~
20580 \SpecialChar ~
20581 \SpecialChar ~
20582 case 11: ...\SpecialChar ~
20583 \SpecialChar ~
20584 \SpecialChar ~
20585 \SpecialChar ~
20586 \SpecialChar ~
20587 \SpecialChar ~
20588 \SpecialChar ~
20589 \SpecialChar ~
20590 \SpecialChar ~
20591 \SpecialChar ~
20592 \SpecialChar ~
20593 \SpecialChar ~
20594 \SpecialChar ~
20595 \SpecialChar ~
20596 \SpecialChar ~
20597 \SpecialChar ~
20598 \SpecialChar ~
20599 \SpecialChar ~
20600 \SpecialChar ~
20601 \SpecialChar ~
20602 \SpecialChar ~
20603 \SpecialChar ~
20604 \SpecialChar ~
20605 \SpecialChar ~
20606 \SpecialChar ~
20607 case 8: ...
20608  
20609 \newline 
20610 }\SpecialChar ~
20611 \SpecialChar ~
20612 \SpecialChar ~
20613 \SpecialChar ~
20614 \SpecialChar ~
20615 \SpecialChar ~
20616 \SpecialChar ~
20617 \SpecialChar ~
20618 \SpecialChar ~
20619 \SpecialChar ~
20620 \SpecialChar ~
20621 \SpecialChar ~
20622 \SpecialChar ~
20623 \SpecialChar ~
20624 \SpecialChar ~
20625 \SpecialChar ~
20626 \SpecialChar ~
20627 \SpecialChar ~
20628 \SpecialChar ~
20629 \SpecialChar ~
20630 \SpecialChar ~
20631 \SpecialChar ~
20632 \SpecialChar ~
20633 \SpecialChar ~
20634 \SpecialChar ~
20635 \SpecialChar ~
20636 \SpecialChar ~
20637 \SpecialChar ~
20638 \SpecialChar ~
20639 \SpecialChar ~
20640 \SpecialChar ~
20641 \SpecialChar ~
20642 \SpecialChar ~
20643 \SpecialChar ~
20644 \SpecialChar ~
20645 \SpecialChar ~
20646 }
20647 \layout Standard
20648
20649 Both the above switch statements will be implemented using a jump-table.
20650  The example to the right side is slightly more efficient as the check for
20651  the lower boundary of the jump-table is not needed.
20652 \end_deeper 
20653 \layout Itemize
20654
20655 The number of case labels is not larger than supported by the target architectur
20656 e.
20657 \layout Itemize
20658
20659 If the case labels are not in numerical sequence ('gaps' between cases)
20660  SDCC checks whether a jump table with additionally inserted dummy cases
20661  is still attractive.
20662  
20663 \layout Itemize
20664
20665 If the starting number is not zero and a check for the lower boundary of
20666  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
20667  ...
20668  .
20669 \layout Standard
20670
20671 Switch statements which have large gaps in the numeric sequence or those
20672  that have too many case labels can be split into more than one switch statement
20673  for efficient code generation, e.g.:
20674 \layout Verse
20675
20676
20677 \family typewriter 
20678 switch (i) { 
20679 \newline 
20680 \SpecialChar ~
20681 \SpecialChar ~
20682 case 1: ...
20683  
20684 \newline 
20685 \SpecialChar ~
20686 \SpecialChar ~
20687 case 2: ...
20688  
20689 \newline 
20690 \SpecialChar ~
20691 \SpecialChar ~
20692 case 3: ...
20693  
20694 \newline 
20695 \SpecialChar ~
20696 \SpecialChar ~
20697 case 4: ...
20698  
20699 \newline 
20700 \SpecialChar ~
20701 \SpecialChar ~
20702 case 5: ...
20703  
20704 \newline 
20705 \SpecialChar ~
20706 \SpecialChar ~
20707 case 6: ...
20708  
20709 \newline 
20710 \SpecialChar ~
20711 \SpecialChar ~
20712 case 7: ...
20713  
20714 \newline 
20715 \SpecialChar ~
20716 \SpecialChar ~
20717 case 101: ...
20718  
20719 \newline 
20720 \SpecialChar ~
20721 \SpecialChar ~
20722 case 102: ...
20723  
20724 \newline 
20725 \SpecialChar ~
20726 \SpecialChar ~
20727 case 103: ...
20728  
20729 \newline 
20730 \SpecialChar ~
20731 \SpecialChar ~
20732 case 104: ...
20733  
20734 \newline 
20735 \SpecialChar ~
20736 \SpecialChar ~
20737 case 105: ...
20738  
20739 \newline 
20740 \SpecialChar ~
20741 \SpecialChar ~
20742 case 106: ...
20743  
20744 \newline 
20745 \SpecialChar ~
20746 \SpecialChar ~
20747 case 107: ...
20748  
20749 \newline 
20750 }
20751 \layout Standard
20752
20753 If the above switch statement is broken down into two switch statements
20754 \layout Verse
20755
20756
20757 \family typewriter 
20758 switch (i) { 
20759 \newline 
20760 \SpecialChar ~
20761 \SpecialChar ~
20762 case 1: ...
20763  
20764 \newline 
20765 \SpecialChar ~
20766 \SpecialChar ~
20767 case 2: ...
20768  
20769 \newline 
20770 \SpecialChar ~
20771 \SpecialChar ~
20772 case 3: ...
20773  
20774 \newline 
20775 \SpecialChar ~
20776 \SpecialChar ~
20777 case 4: ...
20778  
20779 \newline 
20780 \SpecialChar ~
20781 \SpecialChar ~
20782 case 5: ...
20783  
20784 \newline 
20785 \SpecialChar ~
20786 \SpecialChar ~
20787 case 6: ...
20788  
20789 \newline 
20790 \SpecialChar ~
20791 \SpecialChar ~
20792 case 7: ...
20793  
20794 \newline 
20795 }
20796 \layout Standard
20797
20798 and
20799 \layout Verse
20800
20801
20802 \family typewriter 
20803 switch (i) { 
20804 \newline 
20805 \SpecialChar ~
20806 \SpecialChar ~
20807 case 101: ...
20808  
20809 \newline 
20810 \SpecialChar ~
20811 \SpecialChar ~
20812 case 102: ...
20813  
20814 \newline 
20815 \SpecialChar ~
20816 \SpecialChar ~
20817 case 103: ...
20818  
20819 \newline 
20820 \SpecialChar ~
20821 \SpecialChar ~
20822 case 104: ...
20823  
20824 \newline 
20825 \SpecialChar ~
20826 \SpecialChar ~
20827 case 105: ...
20828  
20829 \newline 
20830 \SpecialChar ~
20831 \SpecialChar ~
20832 case 106: ...
20833  
20834 \newline 
20835 \SpecialChar ~
20836 \SpecialChar ~
20837 case 107: ...
20838  
20839 \newline 
20840 }
20841 \layout Standard
20842
20843 then both the switch statements will be implemented using jump-tables whereas
20844  the unmodified switch statement will not be.
20845 \layout Comment
20846
20847 There might be reasons which SDCC cannot know about to either favour or
20848  not favour jump tables.
20849  If the target system has to be as quick for the last switch case as for
20850  the first (pro jump table), or if the switch argument is known to be zero
20851  in the majority of the cases (contra jump table).
20852 \layout Standard
20853
20854 The pragma nojtbound
20855 \begin_inset LatexCommand \index{\#pragma nojtbound}
20856
20857 \end_inset 
20858
20859  can be used to turn off checking the 
20860 \emph on 
20861 j
20862 \emph default 
20863 ump 
20864 \emph on 
20865 t
20866 \emph default 
20867 able 
20868 \emph on 
20869 bound
20870 \emph default 
20871 aries.
20872  It has no effect if a default label is supplied.
20873  Use of this pragma is dangerous: if the switch argument is not matched
20874  by a case statement the processor will happily jump into Nirvana.
20875 \layout Subsection
20876
20877 Bit-shifting Operations
20878 \begin_inset LatexCommand \index{Bit shifting}
20879
20880 \end_inset 
20881
20882 .
20883 \layout Standard
20884
20885 Bit shifting is one of the most frequently used operation in embedded programmin
20886 g.
20887  SDCC tries to implement bit-shift operations in the most efficient way
20888  possible, e.g.:
20889 \layout Verse
20890
20891
20892 \family typewriter 
20893 unsigned char i;
20894 \newline 
20895 ...
20896  
20897 \newline 
20898 i >>= 4; 
20899 \newline 
20900 ...
20901 \layout Standard
20902
20903 generates the following code:
20904 \layout Verse
20905
20906
20907 \family typewriter 
20908 mov\SpecialChar ~
20909  a,_i 
20910 \newline 
20911 swap a 
20912 \newline 
20913 anl\SpecialChar ~
20914  a,#0x0f 
20915 \newline 
20916 mov\SpecialChar ~
20917  _i,a
20918 \layout Standard
20919
20920 In general SDCC will never setup a loop if the shift count is known.
20921  Another example:
20922 \layout Verse
20923
20924
20925 \family typewriter 
20926 unsigned int i; 
20927 \newline 
20928 ...
20929  
20930 \newline 
20931 i >>= 9; 
20932 \newline 
20933 ...
20934 \layout Standard
20935
20936 will generate:
20937 \layout Verse
20938
20939
20940 \family typewriter 
20941 mov\SpecialChar ~
20942 \SpecialChar ~
20943 a,(_i + 1) 
20944 \newline 
20945 mov\SpecialChar ~
20946 \SpecialChar ~
20947 (_i + 1),#0x00 
20948 \newline 
20949 clr\SpecialChar ~
20950 \SpecialChar ~
20951
20952 \newline 
20953 rrc\SpecialChar ~
20954 \SpecialChar ~
20955
20956 \newline 
20957 mov\SpecialChar ~
20958 \SpecialChar ~
20959 _i,a
20960 \layout Subsection
20961
20962 Bit-rotation
20963 \begin_inset LatexCommand \index{Bit rotation}
20964
20965 \end_inset 
20966
20967
20968 \layout Standard
20969
20970 A special case of the bit-shift operation is bit rotation
20971 \begin_inset LatexCommand \index{rotating bits}
20972
20973 \end_inset 
20974
20975 , SDCC recognizes the following expression to be a left bit-rotation:
20976 \layout Verse
20977
20978
20979 \family typewriter 
20980 \series bold 
20981 unsigned
20982 \series default 
20983 \SpecialChar ~
20984 \SpecialChar ~
20985 char i;\SpecialChar ~
20986 \SpecialChar ~
20987 \SpecialChar ~
20988 \SpecialChar ~
20989 \SpecialChar ~
20990 \SpecialChar ~
20991 \SpecialChar ~
20992 \SpecialChar ~
20993 \SpecialChar ~
20994 \SpecialChar ~
20995 \SpecialChar ~
20996 /* unsigned is needed for rotation */ 
20997 \newline 
20998 ...
20999  
21000 \newline 
21001 i = ((i << 1) | (i >> 7)); 
21002 \family default 
21003
21004 \newline 
21005
21006 \family typewriter 
21007 ...
21008 \layout Standard
21009
21010 will generate the following code:
21011 \layout Verse
21012
21013
21014 \family typewriter 
21015 mov\SpecialChar ~
21016 \SpecialChar ~
21017 a,_i 
21018 \newline 
21019 rl\SpecialChar ~
21020 \SpecialChar ~
21021 \SpecialChar ~
21022
21023 \newline 
21024 mov\SpecialChar ~
21025 \SpecialChar ~
21026 _i,a
21027 \layout Standard
21028
21029 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
21030 ns of this case will also be recognized as bit-rotation, i.e.: 
21031 \layout Verse
21032
21033
21034 \family typewriter 
21035 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
21036 \layout Subsection
21037
21038 Nibble and Byte Swapping
21039 \layout Standard
21040
21041 Other special cases of the bit-shift operations are nibble or byte swapping
21042 \begin_inset LatexCommand \index{swapping nibbles/bytes}
21043
21044 \end_inset 
21045
21046 , SDCC recognizes the following expressions:
21047 \layout Verse
21048
21049
21050 \family typewriter 
21051 \series bold 
21052 unsigned
21053 \series default 
21054 \SpecialChar ~
21055 \SpecialChar ~
21056 char i; 
21057 \newline 
21058
21059 \series bold 
21060 unsigned
21061 \series default 
21062 \SpecialChar ~
21063 \SpecialChar ~
21064 int j; 
21065 \newline 
21066 ...
21067  
21068 \newline 
21069 i = ((i << 4) | (i >> 4)); 
21070 \family default 
21071
21072 \newline 
21073
21074 \family typewriter 
21075 j = ((j << 8) | (j >> 8)); 
21076 \layout Standard
21077
21078 and generates a swap instruction for the nibble swapping
21079 \begin_inset LatexCommand \index{Nibble swapping}
21080
21081 \end_inset 
21082
21083  or move instructions for the byte swapping
21084 \begin_inset LatexCommand \index{Byte swapping}
21085
21086 \end_inset 
21087
21088 .
21089  The 
21090 \begin_inset Quotes sld
21091 \end_inset 
21092
21093 j
21094 \begin_inset Quotes srd
21095 \end_inset 
21096
21097  example can be used to convert from little to big-endian or vice versa.
21098  If you want to change the endianness of a 
21099 \emph on 
21100 signed
21101 \emph default 
21102  integer you have to cast to 
21103 \family typewriter 
21104 (unsigned int)
21105 \family default 
21106  first.
21107 \layout Standard
21108
21109 Note that SDCC stores numbers in little-endian
21110 \begin_inset Foot
21111 collapsed false
21112
21113 \layout Standard
21114
21115 Usually 8-bit processors don't care much about endianness.
21116  This is not the case for the standard 8051 which only has an instruction
21117  to increment its 
21118 \emph on 
21119 dptr
21120 \emph default 
21121
21122 \begin_inset LatexCommand \index{DPTR}
21123
21124 \end_inset 
21125
21126 -datapointer
21127 \emph on 
21128  
21129 \emph default 
21130 so little-endian is the more efficient byte order.
21131 \end_inset 
21132
21133
21134 \begin_inset LatexCommand \index{little-endian}
21135
21136 \end_inset 
21137
21138
21139 \begin_inset LatexCommand \index{Endianness}
21140
21141 \end_inset 
21142
21143  format (i.e.
21144  lowest order first).
21145 \layout Subsection
21146
21147 Highest Order Bit
21148 \begin_inset LatexCommand \index{Highest Order Bit}
21149
21150 \end_inset 
21151
21152
21153 \layout Standard
21154
21155 It is frequently required to obtain the highest order bit of an integral
21156  type (long, int, short or char types).
21157  SDCC recognizes the following expression to yield the highest order bit
21158  and generates optimized code for it, e.g.:
21159 \layout Verse
21160
21161
21162 \family typewriter 
21163 unsigned int gint; 
21164 \newline 
21165
21166 \newline 
21167 foo () { 
21168 \newline 
21169 \SpecialChar ~
21170 \SpecialChar ~
21171 unsigned char hob; 
21172 \newline 
21173 \SpecialChar ~
21174 \SpecialChar ~
21175 ...
21176  
21177 \newline 
21178 \SpecialChar ~
21179 \SpecialChar ~
21180 hob = (gint >> 15) & 1; 
21181 \newline 
21182 \SpecialChar ~
21183 \SpecialChar ~
21184 ..
21185  
21186 \newline 
21187 }
21188 \layout Standard
21189
21190 will generate the following code:
21191 \layout Verse
21192
21193
21194 \family typewriter 
21195 \SpecialChar ~
21196 \SpecialChar ~
21197 \SpecialChar ~
21198 \SpecialChar ~
21199 \SpecialChar ~
21200 \SpecialChar ~
21201 \SpecialChar ~
21202 \SpecialChar ~
21203 \SpecialChar ~
21204 \SpecialChar ~
21205 \SpecialChar ~
21206 \SpecialChar ~
21207 \SpecialChar ~
21208 \SpecialChar ~
21209 \SpecialChar ~
21210 \SpecialChar ~
21211 \SpecialChar ~
21212 \SpecialChar ~
21213 \SpecialChar ~
21214 \SpecialChar ~
21215 \SpecialChar ~
21216 \SpecialChar ~
21217 \SpecialChar ~
21218 \SpecialChar ~
21219 \SpecialChar ~
21220  61 ;\SpecialChar ~
21221  hob.c 7 
21222 \newline 
21223 000A E5*01\SpecialChar ~
21224 \SpecialChar ~
21225 \SpecialChar ~
21226 \SpecialChar ~
21227 \SpecialChar ~
21228 \SpecialChar ~
21229 \SpecialChar ~
21230 \SpecialChar ~
21231 \SpecialChar ~
21232 \SpecialChar ~
21233 \SpecialChar ~
21234 \SpecialChar ~
21235 \SpecialChar ~
21236 \SpecialChar ~
21237 \SpecialChar ~
21238  62\SpecialChar ~
21239 \SpecialChar ~
21240 \SpecialChar ~
21241 \SpecialChar ~
21242 \SpecialChar ~
21243 \SpecialChar ~
21244 \SpecialChar ~
21245 \SpecialChar ~
21246  mov\SpecialChar ~
21247 \SpecialChar ~
21248  a,(_gint + 1) 
21249 \newline 
21250 000C 23\SpecialChar ~
21251 \SpecialChar ~
21252 \SpecialChar ~
21253 \SpecialChar ~
21254 \SpecialChar ~
21255 \SpecialChar ~
21256 \SpecialChar ~
21257 \SpecialChar ~
21258 \SpecialChar ~
21259 \SpecialChar ~
21260 \SpecialChar ~
21261 \SpecialChar ~
21262 \SpecialChar ~
21263 \SpecialChar ~
21264 \SpecialChar ~
21265 \SpecialChar ~
21266 \SpecialChar ~
21267 \SpecialChar ~
21268  63\SpecialChar ~
21269 \SpecialChar ~
21270 \SpecialChar ~
21271 \SpecialChar ~
21272 \SpecialChar ~
21273 \SpecialChar ~
21274 \SpecialChar ~
21275 \SpecialChar ~
21276  rl\SpecialChar ~
21277 \SpecialChar ~
21278 \SpecialChar ~
21279  a 
21280 \newline 
21281 000D 54 01\SpecialChar ~
21282 \SpecialChar ~
21283 \SpecialChar ~
21284 \SpecialChar ~
21285 \SpecialChar ~
21286 \SpecialChar ~
21287 \SpecialChar ~
21288 \SpecialChar ~
21289 \SpecialChar ~
21290 \SpecialChar ~
21291 \SpecialChar ~
21292 \SpecialChar ~
21293 \SpecialChar ~
21294 \SpecialChar ~
21295 \SpecialChar ~
21296  64\SpecialChar ~
21297 \SpecialChar ~
21298 \SpecialChar ~
21299 \SpecialChar ~
21300 \SpecialChar ~
21301 \SpecialChar ~
21302 \SpecialChar ~
21303 \SpecialChar ~
21304  anl\SpecialChar ~
21305 \SpecialChar ~
21306  a,#0x01 
21307 \newline 
21308 000F F5*02\SpecialChar ~
21309 \SpecialChar ~
21310 \SpecialChar ~
21311 \SpecialChar ~
21312 \SpecialChar ~
21313 \SpecialChar ~
21314 \SpecialChar ~
21315 \SpecialChar ~
21316 \SpecialChar ~
21317 \SpecialChar ~
21318 \SpecialChar ~
21319 \SpecialChar ~
21320 \SpecialChar ~
21321 \SpecialChar ~
21322 \SpecialChar ~
21323  65\SpecialChar ~
21324 \SpecialChar ~
21325 \SpecialChar ~
21326 \SpecialChar ~
21327 \SpecialChar ~
21328 \SpecialChar ~
21329 \SpecialChar ~
21330 \SpecialChar ~
21331  mov\SpecialChar ~
21332 \SpecialChar ~
21333  _foo_hob_1_1,a
21334 \layout Standard
21335
21336 Variations of this case however will 
21337 \emph on 
21338 not
21339 \emph default 
21340  be recognized.
21341  It is a standard C expression, so I heartily recommend this be the only
21342  way to get the highest order bit, (it is portable).
21343  Of course it will be recognized even if it is embedded in other expressions,
21344  e.g.:
21345 \layout Verse
21346
21347
21348 \family typewriter 
21349 xyz = gint + ((gint >> 15) & 1);
21350 \layout Standard
21351
21352 will still be recognized.
21353 \layout Subsection
21354
21355 Peephole Optimizer
21356 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
21357
21358 \end_inset 
21359
21360
21361 \begin_inset LatexCommand \index{Peephole optimizer}
21362
21363 \end_inset 
21364
21365
21366 \layout Standard
21367
21368 The compiler uses a rule based, pattern matching and re-writing mechanism
21369  for peep-hole optimization.
21370  It is inspired by 
21371 \emph on 
21372 copt
21373 \emph default 
21374  a peep-hole optimizer by Christopher W.
21375  Fraser (cwfraser@microsoft.com).
21376  A default set of rules are compiled into the compiler, additional rules
21377  may be added with the 
21378 \emph on 
21379 -
21380 \begin_inset ERT
21381 status Collapsed
21382
21383 \layout Standard
21384
21385 \backslash 
21386 /
21387 \end_inset 
21388
21389 -peep-file
21390 \begin_inset LatexCommand \index{-\/-peep-file}
21391
21392 \end_inset 
21393
21394  <filename>
21395 \emph default 
21396  option.
21397  The rule language is best illustrated with examples.
21398 \layout Verse
21399
21400
21401 \family typewriter 
21402 replace { 
21403 \newline 
21404 \SpecialChar ~
21405 \SpecialChar ~
21406 mov %1,a 
21407 \newline 
21408 \SpecialChar ~
21409 \SpecialChar ~
21410 mov a,%1
21411 \newline 
21412 } by {
21413 \newline 
21414 \SpecialChar ~
21415 \SpecialChar ~
21416 mov %1,a
21417 \newline 
21418 }
21419 \layout Standard
21420
21421 The above rule will change the following assembly
21422 \begin_inset LatexCommand \index{Assembler routines}
21423
21424 \end_inset 
21425
21426  sequence:
21427 \layout Verse
21428
21429
21430 \family typewriter 
21431 mov r1,a 
21432 \newline 
21433 mov a,r1
21434 \layout Standard
21435
21436 to
21437 \layout Verse
21438
21439
21440 \family typewriter 
21441 mov r1,a
21442 \layout Standard
21443
21444 Note: All occurrences of a 
21445 \emph on 
21446 %n
21447 \emph default 
21448  (pattern variable) must denote the same string.
21449  With the above rule, the assembly sequence:
21450 \layout Verse
21451
21452
21453 \family typewriter 
21454 mov r1,a 
21455 \newline 
21456 mov a,r2
21457 \layout Standard
21458
21459 will remain unmodified.
21460 \newline 
21461
21462 \newline 
21463 Other special case optimizations may be added by the user (via 
21464 \emph on 
21465 -
21466 \begin_inset ERT
21467 status Collapsed
21468
21469 \layout Standard
21470
21471 \backslash 
21472 /
21473 \end_inset 
21474
21475 -peep-file option
21476 \emph default 
21477 ).
21478  E.g.
21479  some variants of the 8051 MCU
21480 \begin_inset LatexCommand \index{MCS51 variants}
21481
21482 \end_inset 
21483
21484  allow only 
21485 \family typewriter 
21486 ajmp
21487 \family default 
21488  and 
21489 \family typewriter 
21490 acall
21491 \family default 
21492 .
21493  The following two rules will change all 
21494 \family typewriter 
21495 ljmp
21496 \family default 
21497  and 
21498 \family typewriter 
21499 lcall
21500 \family default 
21501  to 
21502 \family typewriter 
21503 ajmp
21504 \family default 
21505  and 
21506 \family typewriter 
21507 acall
21508 \layout Verse
21509
21510
21511 \family typewriter 
21512 replace { lcall %1 } by { acall %1 } 
21513 \newline 
21514 replace { ljmp %1 } by { ajmp %1 }
21515 \layout Standard
21516
21517 The 
21518 \emph on 
21519 inline-assembler code
21520 \emph default 
21521  is also passed through the peep hole optimizer, thus the peephole optimizer
21522  can also be used as an assembly level macro expander.
21523  The rules themselves are MCU dependent whereas the rule language infra-structur
21524 e is MCU independent.
21525  Peephole optimization rules for other MCU can be easily programmed using
21526  the rule language.
21527 \newline 
21528
21529 \newline 
21530 The syntax for a rule is as follows:
21531 \layout Verse
21532
21533
21534 \family typewriter 
21535 rule := replace [ restart ] '{' <assembly sequence> '
21536 \backslash 
21537 n' 
21538 \newline 
21539 \SpecialChar ~
21540  \SpecialChar ~
21541  \SpecialChar ~
21542  \SpecialChar ~
21543  \SpecialChar ~
21544  \SpecialChar ~
21545  \SpecialChar ~
21546  \SpecialChar ~
21547  \SpecialChar ~
21548  \SpecialChar ~
21549  \SpecialChar ~
21550  \SpecialChar ~
21551  \SpecialChar ~
21552  \SpecialChar ~
21553  '}' by '{' '
21554 \backslash 
21555 n' 
21556 \newline 
21557 \SpecialChar ~
21558  \SpecialChar ~
21559  \SpecialChar ~
21560  \SpecialChar ~
21561  \SpecialChar ~
21562  \SpecialChar ~
21563  \SpecialChar ~
21564  \SpecialChar ~
21565  \SpecialChar ~
21566  \SpecialChar ~
21567  \SpecialChar ~
21568  \SpecialChar ~
21569  \SpecialChar ~
21570  \SpecialChar ~
21571  \SpecialChar ~
21572  \SpecialChar ~
21573  <assembly sequence> '
21574 \backslash 
21575 n' 
21576 \newline 
21577 \SpecialChar ~
21578  \SpecialChar ~
21579  \SpecialChar ~
21580  \SpecialChar ~
21581  \SpecialChar ~
21582  \SpecialChar ~
21583  \SpecialChar ~
21584  \SpecialChar ~
21585  \SpecialChar ~
21586  \SpecialChar ~
21587  \SpecialChar ~
21588  \SpecialChar ~
21589  \SpecialChar ~
21590  \SpecialChar ~
21591  '}' [if <functionName> ] '
21592 \backslash 
21593 n' 
21594 \layout Standard
21595
21596 <assembly sequence> := assembly instruction (each instruction including
21597  labels must be on a separate line).
21598 \newline 
21599
21600 \newline 
21601 The optimizer will apply to the rules one by one from the top in the sequence
21602  of their appearance, it will terminate when all rules are exhausted.
21603  If the 'restart' option is specified, then the optimizer will start matching
21604  the rules again from the top, this option for a rule is expensive (performance)
21605 , it is intended to be used in situations where a transformation will trigger
21606  the same rule again.
21607  An example of this (not a good one, it has side effects) is the following
21608  rule:
21609 \layout Verse
21610
21611
21612 \family typewriter 
21613 replace restart { 
21614 \newline 
21615 \SpecialChar ~
21616 \SpecialChar ~
21617 pop %1 
21618 \newline 
21619 \SpecialChar ~
21620 \SpecialChar ~
21621 push %1 } by { 
21622 \newline 
21623 \SpecialChar ~
21624 \SpecialChar ~
21625 ; nop 
21626 \newline 
21627 }
21628 \layout Standard
21629
21630 Note that the replace pattern cannot be a blank, but can be a comment line.
21631  Without the 'restart' option only the innermost 'pop' 'push' pair would
21632  be eliminated, i.e.:
21633 \layout Verse
21634
21635
21636 \family typewriter 
21637 pop ar1 
21638 \newline 
21639 pop ar2 
21640 \newline 
21641 push ar2 
21642 \newline 
21643 push ar1
21644 \layout Standard
21645
21646 would result in:
21647 \layout Verse
21648
21649
21650 \family typewriter 
21651 pop ar1 
21652 \newline 
21653 ; nop 
21654 \newline 
21655 push ar1
21656 \layout Standard
21657
21658
21659 \emph on 
21660 with
21661 \emph default 
21662  the restart option the rule will be applied again to the resulting code
21663  and then all the pop-push pairs will be eliminated to yield:
21664 \layout Verse
21665
21666
21667 \family typewriter 
21668 ; nop 
21669 \newline 
21670 ; nop
21671 \layout Standard
21672
21673 A conditional function can be attached to a rule.
21674  Attaching rules are somewhat more involved, let me illustrate this with
21675  an example.
21676 \layout Verse
21677
21678
21679 \family typewriter 
21680 replace { 
21681 \newline 
21682 \SpecialChar ~
21683  \SpecialChar ~
21684  \SpecialChar ~
21685 ljmp %5 
21686 \newline 
21687 %2:
21688 \newline 
21689 } by { 
21690 \newline 
21691 \SpecialChar ~
21692  \SpecialChar ~
21693  \SpecialChar ~
21694 sjmp %5 
21695 \newline 
21696 %2:
21697 \newline 
21698 } if labelInRange
21699 \layout Standard
21700
21701 The optimizer does a look-up of a function name table defined in function
21702  
21703 \emph on 
21704 callFuncByName
21705 \emph default 
21706  in the source file SDCCpeeph.c, with the name 
21707 \emph on 
21708 labelInRange
21709 \emph default 
21710 .
21711  If it finds a corresponding entry the function is called.
21712  Note there can be no parameters specified for these functions, in this
21713  case the use of 
21714 \emph on 
21715 %5
21716 \emph default 
21717  is crucial, since the function 
21718 \emph on 
21719 labelInRange
21720 \emph default 
21721  expects to find the label in that particular variable (the hash table containin
21722 g the variable bindings is passed as a parameter).
21723  If you want to code more such functions, take a close look at the function
21724  labelInRange and the calling mechanism in source file SDCCpeeph.c.
21725  Currently implemented are 
21726 \emph on 
21727 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
21728  24bitMode, portIsDS390, 24bitModeAndPortDS390 
21729 \emph default 
21730 and
21731 \emph on 
21732  notVolatile
21733 \emph default 
21734 .
21735 \layout Standard
21736
21737 I know this whole thing is a little kludgey, but maybe some day we will
21738  have some better means.
21739  If you are looking at this file, you will see the default rules that are
21740  compiled into the compiler, you can add your own rules in the default set
21741  there if you get tired of specifying the -
21742 \begin_inset ERT
21743 status Collapsed
21744
21745 \layout Standard
21746
21747 \backslash 
21748 /
21749 \end_inset 
21750
21751 -peep-file option.
21752 \layout Section
21753
21754 ANSI-Compliance
21755 \begin_inset LatexCommand \index{ANSI-compliance}
21756
21757 \end_inset 
21758
21759
21760 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
21761
21762 \end_inset 
21763
21764
21765 \layout Standard
21766
21767 Deviations from the compliance:
21768 \layout Itemize
21769
21770 functions are not always reentrant
21771 \begin_inset LatexCommand \index{reentrant}
21772
21773 \end_inset 
21774
21775 .
21776 \layout Itemize
21777
21778 structures cannot be assigned values directly, cannot be passed as function
21779  parameters or assigned to each other and cannot be a return value from
21780  a function, e.g.:
21781 \begin_deeper 
21782 \layout Verse
21783
21784
21785 \family typewriter 
21786 struct s { ...
21787  }; 
21788 \newline 
21789 struct s s1, s2; 
21790 \newline 
21791 foo() 
21792 \newline 
21793
21794 \newline 
21795 \SpecialChar ~
21796 \SpecialChar ~
21797 \SpecialChar ~
21798 \SpecialChar ~
21799 ...
21800  
21801 \newline 
21802 \SpecialChar ~
21803 \SpecialChar ~
21804 \SpecialChar ~
21805 \SpecialChar ~
21806 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
21807 \newline 
21808 \SpecialChar ~
21809 \SpecialChar ~
21810 \SpecialChar ~
21811 \SpecialChar ~
21812 ...
21813  
21814 \newline 
21815 }
21816 \newline 
21817 struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
21818  */
21819 \newline 
21820
21821 \newline 
21822 \SpecialChar ~
21823 \SpecialChar ~
21824 \SpecialChar ~
21825 \SpecialChar ~
21826 struct s rets; 
21827 \newline 
21828 \SpecialChar ~
21829 \SpecialChar ~
21830 \SpecialChar ~
21831 \SpecialChar ~
21832 ...
21833  
21834 \newline 
21835 \SpecialChar ~
21836 \SpecialChar ~
21837 \SpecialChar ~
21838 \SpecialChar ~
21839 return rets;/* is invalid in SDCC although allowed in ANSI */ 
21840 \newline 
21841 }
21842 \end_deeper 
21843 \layout Itemize
21844
21845 'long long
21846 \begin_inset LatexCommand \index{long long (not supported)}
21847
21848 \end_inset 
21849
21850 ' (64 bit integers
21851 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
21852
21853 \end_inset 
21854
21855 ) not supported.
21856 \layout Itemize
21857
21858 'double
21859 \begin_inset LatexCommand \index{double (not supported)}
21860
21861 \end_inset 
21862
21863 ' precision floating point 
21864 \begin_inset LatexCommand \index{Floating point support}
21865
21866 \end_inset 
21867
21868 not supported.
21869 \layout Itemize
21870
21871 No support for setjmp
21872 \begin_inset LatexCommand \index{setjmp (not supported)}
21873
21874 \end_inset 
21875
21876  and longjmp
21877 \begin_inset LatexCommand \index{longjmp (not supported)}
21878
21879 \end_inset 
21880
21881  (for now).
21882 \layout Itemize
21883
21884 Old K&R style
21885 \begin_inset LatexCommand \index{K\&R style}
21886
21887 \end_inset 
21888
21889  function declarations are NOT allowed.
21890 \begin_deeper 
21891 \layout Verse
21892
21893
21894 \family typewriter 
21895 foo(i,j) /* this old style of function declarations */ 
21896 \newline 
21897 int i,j; /* are valid in ANSI but not valid in SDCC */ 
21898 \newline 
21899
21900 \newline 
21901 \SpecialChar ~
21902 \SpecialChar ~
21903 \SpecialChar ~
21904 \SpecialChar ~
21905 ...
21906  
21907 \newline 
21908 }
21909 \end_deeper 
21910 \layout Section
21911
21912 Cyclomatic Complexity
21913 \begin_inset LatexCommand \index{Cyclomatic complexity}
21914
21915 \end_inset 
21916
21917
21918 \layout Standard
21919
21920 Cyclomatic complexity of a function is defined as the number of independent
21921  paths the program can take during execution of the function.
21922  This is an important number since it defines the number test cases you
21923  have to generate to validate the function.
21924  The accepted industry standard for complexity number is 10, if the cyclomatic
21925  complexity reported by SDCC exceeds 10 you should think about simplification
21926  of the function logic.
21927  Note that the complexity level is not related to the number of lines of
21928  code in a function.
21929  Large functions can have low complexity, and small functions can have large
21930  complexity levels.
21931  
21932 \newline 
21933
21934 \newline 
21935 SDCC uses the following formula to compute the complexity:
21936 \newline 
21937
21938 \layout Standard
21939
21940 complexity = (number of edges in control flow graph) - (number of nodes
21941  in control flow graph) + 2;
21942 \newline 
21943
21944 \newline 
21945 Having said that the industry standard is 10, you should be aware that in
21946  some cases it be may unavoidable to have a complexity level of less than
21947  10.
21948  For example if you have switch statement with more than 10 case labels,
21949  each case label adds one to the complexity level.
21950  The complexity level is by no means an absolute measure of the algorithmic
21951  complexity of the function, it does however provide a good starting point
21952  for which functions you might look at for further optimization.
21953 \layout Section
21954
21955 Retargetting for other Processors
21956 \layout Standard
21957
21958 The issues for retargetting the compiler are far too numerous to be covered
21959  by this document.
21960  What follows is a brief description of each of the seven phases of the
21961  compiler and its MCU dependency.
21962 \layout Itemize
21963
21964 Parsing the source and building the annotated parse tree.
21965  This phase is largely MCU independent (except for the language extensions).
21966  Syntax & semantic checks are also done in this phase, along with some initial
21967  optimizations like back patching labels and the pattern matching optimizations
21968  like bit-rotation etc.
21969 \layout Itemize
21970
21971 The second phase involves generating an intermediate code which can be easy
21972  manipulated during the later phases.
21973  This phase is entirely MCU independent.
21974  The intermediate code generation assumes the target machine has unlimited
21975  number of registers, and designates them with the name iTemp.
21976  The compiler can be made to dump a human readable form of the code generated
21977  by using the -
21978 \begin_inset ERT
21979 status Collapsed
21980
21981 \layout Standard
21982
21983 \backslash 
21984 /
21985 \end_inset 
21986
21987 -dumpraw option.
21988 \layout Itemize
21989
21990 This phase does the bulk of the standard optimizations and is also MCU independe
21991 nt.
21992  This phase can be broken down into several sub-phases:
21993 \newline 
21994
21995 \newline 
21996 Break down intermediate code (iCode) into basic blocks.
21997 \newline 
21998 Do control flow & data flow analysis on the basic blocks.
21999 \newline 
22000 Do local common subexpression elimination, then global subexpression elimination
22001 \newline 
22002 Dead code elimination
22003 \newline 
22004 Loop optimizations
22005 \newline 
22006 If loop optimizations caused any changes then do 'global subexpression eliminati
22007 on' and 'dead code elimination' again.
22008 \layout Itemize
22009
22010 This phase determines the live-ranges; by live range I mean those iTemp
22011  variables defined by the compiler that still survive after all the optimization
22012 s.
22013  Live range analysis
22014 \begin_inset LatexCommand \index{Live range analysis}
22015
22016 \end_inset 
22017
22018  is essential for register allocation, since these computation determines
22019  which of these iTemps will be assigned to registers, and for how long.
22020 \layout Itemize
22021
22022 Phase five is register allocation.
22023  There are two parts to this process.
22024 \newline 
22025
22026 \newline 
22027 The first part I call 'register packing' (for lack of a better term).
22028  In this case several MCU specific expression folding is done to reduce
22029  register pressure.
22030 \newline 
22031
22032 \newline 
22033 The second part is more MCU independent and deals with allocating registers
22034  to the remaining live ranges.
22035  A lot of MCU specific code does creep into this phase because of the limited
22036  number of index registers available in the 8051.
22037 \layout Itemize
22038
22039 The Code generation phase is (unhappily), entirely MCU dependent and very
22040  little (if any at all) of this code can be reused for other MCU.
22041  However the scheme for allocating a homogenized assembler operand for each
22042  iCode operand may be reused.
22043 \layout Itemize
22044
22045 As mentioned in the optimization section the peep-hole optimizer is rule
22046  based system, which can reprogrammed for other MCUs.
22047 \layout Chapter
22048
22049 Compiler internals
22050 \begin_inset LatexCommand \index{Compiler internals}
22051
22052 \end_inset 
22053
22054
22055 \layout Section
22056
22057 The anatomy of the compiler
22058 \begin_inset LatexCommand \label{sub:The-anatomy-of}
22059
22060 \end_inset 
22061
22062
22063 \layout Standard
22064
22065
22066 \shape italic 
22067 This is an excerpt from an article published in Circuit Cellar Magazine
22068  in august 2000.
22069  It's a little outdated (the compiler is much more efficient now and user/develo
22070 per friendly), but pretty well exposes the guts of it all.
22071 \shape default 
22072
22073 \newline 
22074
22075 \newline 
22076 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
22077  It is fairly easy to retarget for other 8-bit MCU.
22078  Here we take a look at some of the internals of the compiler.
22079  
22080 \layout Paragraph*
22081
22082 Parsing
22083 \begin_inset LatexCommand \index{Parsing}
22084
22085 \end_inset 
22086
22087  
22088 \layout Standard
22089
22090 Parsing the input source file and creating an AST (Annotated Syntax Tree
22091 \begin_inset LatexCommand \index{Annotated syntax tree}
22092
22093 \end_inset 
22094
22095 ).
22096  This phase also involves propagating types (annotating each node of the
22097  parse tree with type information) and semantic analysis.
22098  There are some MCU specific parsing rules.
22099  For example the storage classes, the extended storage classes are MCU specific
22100  while there may be a xdata storage class for 8051 there is no such storage
22101  class for z80 or Atmel AVR.
22102  SDCC allows MCU specific storage class extensions, i.e.
22103  xdata will be treated as a storage class specifier when parsing 8051 C
22104  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
22105  C code.
22106 \layout Paragraph*
22107
22108 Generating iCode
22109 \begin_inset LatexCommand \index{iCode}
22110
22111 \end_inset 
22112
22113
22114 \layout Standard
22115
22116 Intermediate code generation.
22117  In this phase the AST is broken down into three-operand form (iCode).
22118  These three operand forms are represented as doubly linked lists.
22119  ICode is the term given to the intermediate form generated by the compiler.
22120  ICode example section shows some examples of iCode generated for some simple
22121  C source functions.
22122 \layout Paragraph*
22123
22124 Optimizations
22125 \begin_inset LatexCommand \index{Optimizations}
22126
22127 \end_inset 
22128
22129 .
22130 \layout Standard
22131
22132 Bulk of the target independent optimizations is performed in this phase.
22133  The optimizations include constant propagation, common sub-expression eliminati
22134 on, loop invariant code movement, strength reduction of loop induction variables
22135  and dead-code elimination.
22136 \layout Paragraph*
22137
22138 Live range analysis
22139 \begin_inset LatexCommand \index{Live range analysis}
22140
22141 \end_inset 
22142
22143
22144 \layout Standard
22145
22146 During intermediate code generation phase, the compiler assumes the target
22147  machine has infinite number of registers and generates a lot of temporary
22148  variables.
22149  The live range computation determines the lifetime of each of these compiler-ge
22150 nerated temporaries.
22151  A picture speaks a thousand words.
22152  ICode example sections show the live range annotations for each of the
22153  operand.
22154  It is important to note here, each iCode is assigned a number in the order
22155  of its execution in the function.
22156  The live ranges are computed in terms of these numbers.
22157  The from number is the number of the iCode which first defines the operand
22158  and the to number signifies the iCode which uses this operand last.
22159 \layout Paragraph*
22160
22161 Register Allocation
22162 \begin_inset LatexCommand \index{Register allocation}
22163
22164 \end_inset 
22165
22166
22167 \layout Standard
22168
22169 The register allocation determines the type and number of registers needed
22170  by each operand.
22171  In most MCUs only a few registers can be used for indirect addressing.
22172  In case of 8051 for example the registers R0 & R1 can be used to indirectly
22173  address the internal ram and DPTR to indirectly address the external ram.
22174  The compiler will try to allocate the appropriate register to pointer variables
22175  if it can.
22176  ICode example section shows the operands annotated with the registers assigned
22177  to them.
22178  The compiler will try to keep operands in registers as much as possible;
22179  there are several schemes the compiler uses to do achieve this.
22180  When the compiler runs out of registers the compiler will check to see
22181  if there are any live operands which is not used or defined in the current
22182  basic block being processed, if there are any found then it will push that
22183  operand and use the registers in this block, the operand will then be popped
22184  at the end of the basic block.
22185  
22186 \layout Standard
22187
22188 There are other MCU specific considerations in this phase.
22189  Some MCUs have an accumulator; very short-lived operands could be assigned
22190  to the accumulator instead of a general-purpose register.
22191 \layout Paragraph*
22192
22193 Code generation
22194 \layout Standard
22195
22196 Figure II gives a table of iCode operations supported by the compiler.
22197  The code generation involves translating these operations into corresponding
22198  assembly code for the processor.
22199  This sounds overly simple but that is the essence of code generation.
22200  Some of the iCode operations are generated on a MCU specific manner for
22201  example, the z80 port does not use registers to pass parameters so the
22202  SEND and RECV iCode operations will not be generated, and it also does
22203  not support JUMPTABLES.
22204  
22205 \newline 
22206
22207 \series bold 
22208 \shape italic 
22209 \color red
22210 <Where is Figure II?>
22211 \layout Comment
22212
22213 In the original article Figure II was announced to be downloadable on 
22214 \shape italic 
22215 Circuit Cellar
22216 \shape default 
22217 's web site.
22218  Unfortunately it never seemed to have shown up there, so: where is Figure
22219  II?
22220 \layout Paragraph*
22221
22222 ICode Example
22223 \begin_inset LatexCommand \index{iCode}
22224
22225 \end_inset 
22226
22227
22228 \layout Standard
22229
22230 This section shows some details of iCode.
22231  The example C code does not do anything useful; it is used as an example
22232  to illustrate the intermediate code generated by the compiler.
22233 \layout Verse
22234
22235
22236 \family typewriter 
22237 1.\SpecialChar ~
22238 xdata int * p;
22239 \newline 
22240 2.\SpecialChar ~
22241 int gint;
22242 \newline 
22243 3.\SpecialChar ~
22244 /* This function does nothing useful.
22245  It is used
22246 \newline 
22247 4.\SpecialChar ~
22248 \SpecialChar ~
22249 \SpecialChar ~
22250 \SpecialChar ~
22251 for the purpose of explaining iCode */
22252 \newline 
22253 5.\SpecialChar ~
22254 short function (data int *x)
22255 \newline 
22256 6.\SpecialChar ~
22257 {
22258 \newline 
22259 7.\SpecialChar ~
22260 \SpecialChar ~
22261 \SpecialChar ~
22262 short i=10; \SpecialChar ~
22263 \SpecialChar ~
22264 /* dead initialization eliminated */
22265 \newline 
22266 8.\SpecialChar ~
22267 \SpecialChar ~
22268 \SpecialChar ~
22269 short sum=10; /* dead initialization eliminated */
22270 \newline 
22271 9.\SpecialChar ~
22272 \SpecialChar ~
22273 \SpecialChar ~
22274 short mul;
22275 \newline 
22276 10.\SpecialChar ~
22277 \SpecialChar ~
22278 int j ;
22279 \newline 
22280 11.\SpecialChar ~
22281 \SpecialChar ~
22282 while (*x) *x++ = *p++; 
22283 \newline 
22284 12.\SpecialChar ~
22285 \SpecialChar ~
22286 \SpecialChar ~
22287 \SpecialChar ~
22288 sum = 0 ; 
22289 \newline 
22290 13.\SpecialChar ~
22291 \SpecialChar ~
22292 mul = 0;
22293 \newline 
22294 14.\SpecialChar ~
22295 \SpecialChar ~
22296 /* compiler detects i,j to be induction variables */
22297 \newline 
22298 15.\SpecialChar ~
22299 \SpecialChar ~
22300 for (i = 0, j = 10 ; i < 10 ; i++, j
22301 \family default 
22302 -
22303 \begin_inset ERT
22304 status Collapsed
22305
22306 \layout Standard
22307
22308 \backslash 
22309 /
22310 \end_inset 
22311
22312 -
22313 \family typewriter 
22314 ) {
22315 \newline 
22316 16.\SpecialChar ~
22317 \SpecialChar ~
22318 \SpecialChar ~
22319 \SpecialChar ~
22320 sum += i;
22321 \newline 
22322 17.\SpecialChar ~
22323 \SpecialChar ~
22324 \SpecialChar ~
22325 \SpecialChar ~
22326 mul += i * 3; \SpecialChar ~
22327 \SpecialChar ~
22328 /* this multiplication remains */
22329 \newline 
22330 18.\SpecialChar ~
22331 \SpecialChar ~
22332 \SpecialChar ~
22333 \SpecialChar ~
22334 gint += j * 3;\SpecialChar ~
22335 \SpecialChar ~
22336 /* this multiplication changed to addition */
22337 \newline 
22338 19.\SpecialChar ~
22339 \SpecialChar ~
22340 }
22341 \newline 
22342 20.\SpecialChar ~
22343 \SpecialChar ~
22344 return sum+mul;
22345 \newline 
22346 21.\SpecialChar ~
22347 }
22348 \layout Standard
22349
22350 In addition to the operands each iCode contains information about the filename
22351  and line it corresponds to in the source file.
22352  The first field in the listing should be interpreted as follows:
22353 \newline 
22354
22355 \shape italic 
22356 \size footnotesize 
22357 Filename(linenumber: iCode Execution sequence number : ICode hash table
22358  key : loop depth of the iCode).
22359 \shape default 
22360 \size default 
22361
22362 \newline 
22363 Then follows the human readable form of the ICode operation.
22364  Each operand of this triplet form can be of three basic types a) compiler
22365  generated temporary b) user defined variable c) a constant value.
22366  Note that local variables and parameters are replaced by compiler generated
22367  temporaries.
22368  Live ranges
22369 \begin_inset LatexCommand \index{Live range analysis}
22370
22371 \end_inset 
22372
22373  are computed only for temporaries (i.e.
22374  live ranges are not computed for global variables).
22375  Registers
22376 \begin_inset LatexCommand \index{Register allocation}
22377
22378 \end_inset 
22379
22380  are allocated for temporaries only.
22381  Operands are formatted in the following manner:
22382 \newline 
22383
22384 \shape italic 
22385 \size footnotesize 
22386 Operand Name [lr live-from : live-to ] { type information } [ registers
22387  allocated ].
22388 \shape default 
22389 \size default 
22390
22391 \newline 
22392 As mentioned earlier the live ranges are computed in terms of the execution
22393  sequence number of the iCodes, for example 
22394 \newline 
22395 the iTemp0 is live from (i.e.
22396  first defined in iCode with execution sequence number 3, and is last used
22397  in the iCode with sequence number 5).
22398  For induction variables such as iTemp21 the live range computation extends
22399  the lifetime from the start to the end of the loop.
22400 \newline 
22401 The register allocator used the live range information to allocate registers,
22402  the same registers may be used for different temporaries if their live
22403  ranges do not overlap, for example r0 is allocated to both iTemp6 and to
22404  iTemp17 since their live ranges do not overlap.
22405  In addition the allocator also takes into consideration the type and usage
22406  of a temporary, for example itemp6 is a pointer to near space and is used
22407  as to fetch data from (i.e.
22408  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
22409  Some short lived temporaries are allocated to special registers which have
22410  meaning to the code generator e.g.
22411  iTemp13 is allocated to a pseudo register CC which tells the back end that
22412  the temporary is used only for a conditional jump the code generation makes
22413  use of this information to optimize a compare and jump ICode.
22414 \newline 
22415 There are several loop optimizations
22416 \begin_inset LatexCommand \index{Loop optimization}
22417
22418 \end_inset 
22419
22420  performed by the compiler.
22421  It can detect induction variables iTemp21(i) and iTemp23(j).
22422  Also note the compiler does selective strength reduction
22423 \begin_inset LatexCommand \index{Strength reduction}
22424
22425 \end_inset 
22426
22427 , i.e.
22428  the multiplication of an induction variable in line 18 (gint = j * 3) is
22429  changed to addition, a new temporary iTemp17 is allocated and assigned
22430  a initial value, a constant 3 is then added for each iteration of the loop.
22431  The compiler does not change the multiplication
22432 \begin_inset LatexCommand \index{Multiplication}
22433
22434 \end_inset 
22435
22436  in line 17 however since the processor does support an 8 * 8 bit multiplication.
22437 \newline 
22438 Note the dead code elimination
22439 \begin_inset LatexCommand \index{Dead-code elimination}
22440
22441 \end_inset 
22442
22443  optimization eliminated the dead assignments in line 7 & 8 to I and sum
22444  respectively.
22445 \newline 
22446
22447 \layout Standard
22448
22449
22450 \size footnotesize 
22451 Sample.c (5:1:0:0) _entry($9) :
22452 \layout Standard
22453
22454
22455 \size footnotesize 
22456 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
22457 \layout Standard
22458
22459
22460 \size footnotesize 
22461 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
22462 \layout Standard
22463
22464
22465 \size footnotesize 
22466 Sample.c(11:4:53:0) preHeaderLbl0($11) :
22467 \layout Standard
22468
22469
22470 \size footnotesize 
22471 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
22472  * int}[r2]
22473 \layout Standard
22474
22475
22476 \size footnotesize 
22477 Sample.c(11:6:5:1) _whilecontinue_0($1) :
22478 \layout Standard
22479
22480
22481 \size footnotesize 
22482 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
22483  int}[r0]]
22484 \layout Standard
22485
22486
22487 \size footnotesize 
22488 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
22489 \layout Standard
22490
22491
22492 \size footnotesize 
22493 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
22494  * int}
22495 \layout Standard
22496
22497
22498 \size footnotesize 
22499 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
22500  {short}
22501 \layout Standard
22502
22503
22504 \size footnotesize 
22505 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
22506  * int}[DPTR]]
22507 \layout Standard
22508
22509
22510 \size footnotesize 
22511 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
22512 }[r2 r3]
22513 \layout Standard
22514
22515
22516 \size footnotesize 
22517 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
22518  * int}[r0] + 0x2 {short}
22519 \layout Standard
22520
22521
22522 \size footnotesize 
22523 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
22524 \layout Standard
22525
22526
22527 \size footnotesize 
22528 Sample.c(11:17:21:0)_whilebreak_0($3) :
22529 \layout Standard
22530
22531
22532 \size footnotesize 
22533 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
22534 \layout Standard
22535
22536
22537 \size footnotesize 
22538 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
22539 \layout Standard
22540
22541
22542 \size footnotesize 
22543 Sample.c(15:20:54:0)preHeaderLbl1($13) :
22544 \layout Standard
22545
22546
22547 \size footnotesize 
22548 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
22549 \layout Standard
22550
22551
22552 \size footnotesize 
22553 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
22554 \layout Standard
22555
22556
22557 \size footnotesize 
22558 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
22559 \layout Standard
22560
22561
22562 \size footnotesize 
22563 Sample.c(15:24:26:1)_forcond_0($4) :
22564 \layout Standard
22565
22566
22567 \size footnotesize 
22568 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
22569  < 0xa {short}
22570 \layout Standard
22571
22572
22573 \size footnotesize 
22574 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
22575 \layout Standard
22576
22577
22578 \size footnotesize 
22579 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
22580  + ITemp21 [lr21:38]{short}[r4]
22581 \layout Standard
22582
22583
22584 \size footnotesize 
22585 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
22586  * 0x3 {short}
22587 \layout Standard
22588
22589
22590 \size footnotesize 
22591 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
22592  + iTemp15 [lr29:30]{short}[r1]
22593 \layout Standard
22594
22595
22596 \size footnotesize 
22597 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
22598  r0]- 0x3 {short}
22599 \layout Standard
22600
22601
22602 \size footnotesize 
22603 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
22604 int}[r7 r0]
22605 \layout Standard
22606
22607
22608 \size footnotesize 
22609 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
22610  + 0x1 {short}
22611 \layout Standard
22612
22613
22614 \size footnotesize 
22615 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
22616  r6]- 0x1 {short}
22617 \layout Standard
22618
22619
22620 \size footnotesize 
22621 Sample.c(19:38:47:1) goto _forcond_0($4)
22622 \layout Standard
22623
22624
22625 \size footnotesize 
22626 Sample.c(19:39:48:0)_forbreak_0($7) :
22627 \layout Standard
22628
22629
22630 \size footnotesize 
22631 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
22632  + ITemp11 [lr19:40]{short}[r3]
22633 \layout Standard
22634
22635
22636 \size footnotesize 
22637 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
22638 \layout Standard
22639
22640
22641 \size footnotesize 
22642 Sample.c(20:42:51:0)_return($8) :
22643 \layout Standard
22644
22645
22646 \size footnotesize 
22647 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
22648 \size default 
22649
22650 \newline 
22651
22652 \newline 
22653 Finally the code generated for this function:
22654 \newline 
22655
22656 \layout Standard
22657
22658
22659 \size footnotesize 
22660 .area DSEG (DATA)
22661 \layout Standard
22662
22663
22664 \size footnotesize 
22665 _p::
22666 \layout Standard
22667
22668
22669 \size footnotesize 
22670 \SpecialChar ~
22671 \SpecialChar ~
22672 .ds 2
22673 \layout Standard
22674
22675
22676 \size footnotesize 
22677 _gint::
22678 \layout Standard
22679
22680
22681 \size footnotesize 
22682 \SpecialChar ~
22683 \SpecialChar ~
22684 .ds 2
22685 \layout Standard
22686
22687
22688 \size footnotesize 
22689 ; sample.c 5
22690 \layout Standard
22691
22692
22693 \size footnotesize 
22694 ; ----------------------------------------------
22695 \layout Standard
22696
22697
22698 \size footnotesize 
22699 ; function function
22700 \layout Standard
22701
22702
22703 \size footnotesize 
22704 ; ----------------------------------------------
22705 \layout Standard
22706
22707
22708 \size footnotesize 
22709 _function:
22710 \layout Standard
22711
22712
22713 \size footnotesize 
22714 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
22715 \layout Standard
22716
22717
22718 \size footnotesize 
22719 \SpecialChar ~
22720 \SpecialChar ~
22721 mov r2,dpl
22722 \layout Standard
22723
22724
22725 \size footnotesize 
22726 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
22727 \layout Standard
22728
22729
22730 \size footnotesize 
22731 \SpecialChar ~
22732 \SpecialChar ~
22733 mov ar0,r2
22734 \layout Standard
22735
22736
22737 \size footnotesize 
22738 ;_whilecontinue_0($1) :
22739 \layout Standard
22740
22741
22742 \size footnotesize 
22743 00101$:
22744 \layout Standard
22745
22746
22747 \size footnotesize 
22748 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
22749 \layout Standard
22750
22751
22752 \size footnotesize 
22753 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
22754 \layout Standard
22755
22756
22757 \size footnotesize 
22758 \SpecialChar ~
22759 \SpecialChar ~
22760 mov ar2,@r0
22761 \layout Standard
22762
22763
22764 \size footnotesize 
22765 \SpecialChar ~
22766 \SpecialChar ~
22767 inc r0
22768 \layout Standard
22769
22770
22771 \size footnotesize 
22772 \SpecialChar ~
22773 \SpecialChar ~
22774 mov ar3,@r0
22775 \layout Standard
22776
22777
22778 \size footnotesize 
22779 \SpecialChar ~
22780 \SpecialChar ~
22781 dec r0
22782 \layout Standard
22783
22784
22785 \size footnotesize 
22786 \SpecialChar ~
22787 \SpecialChar ~
22788 mov a,r2
22789 \layout Standard
22790
22791
22792 \size footnotesize 
22793 \SpecialChar ~
22794 \SpecialChar ~
22795 orl a,r3
22796 \layout Standard
22797
22798
22799 \size footnotesize 
22800 \SpecialChar ~
22801 \SpecialChar ~
22802 jz 00103$
22803 \layout Standard
22804
22805
22806 \size footnotesize 
22807 00114$:
22808 \layout Standard
22809
22810
22811 \size footnotesize 
22812 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
22813 \layout Standard
22814
22815
22816 \size footnotesize 
22817 \SpecialChar ~
22818 \SpecialChar ~
22819 mov dpl,_p
22820 \layout Standard
22821
22822
22823 \size footnotesize 
22824 \SpecialChar ~
22825 \SpecialChar ~
22826 mov dph,(_p + 1)
22827 \layout Standard
22828
22829
22830 \size footnotesize 
22831 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
22832 \layout Standard
22833
22834
22835 \size footnotesize 
22836 \SpecialChar ~
22837 \SpecialChar ~
22838 mov a,#0x02
22839 \layout Standard
22840
22841
22842 \size footnotesize 
22843 \SpecialChar ~
22844 \SpecialChar ~
22845 add a,_p
22846 \layout Standard
22847
22848
22849 \size footnotesize 
22850 \SpecialChar ~
22851 \SpecialChar ~
22852 mov _p,a
22853 \layout Standard
22854
22855
22856 \size footnotesize 
22857 \SpecialChar ~
22858 \SpecialChar ~
22859 clr a
22860 \layout Standard
22861
22862
22863 \size footnotesize 
22864 \SpecialChar ~
22865 \SpecialChar ~
22866 addc a,(_p + 1)
22867 \layout Standard
22868
22869
22870 \size footnotesize 
22871 \SpecialChar ~
22872 \SpecialChar ~
22873 mov (_p + 1),a
22874 \layout Standard
22875
22876
22877 \size footnotesize 
22878 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
22879 \layout Standard
22880
22881
22882 \size footnotesize 
22883 \SpecialChar ~
22884 \SpecialChar ~
22885 movx a,@dptr
22886 \layout Standard
22887
22888
22889 \size footnotesize 
22890 \SpecialChar ~
22891 \SpecialChar ~
22892 mov r2,a
22893 \layout Standard
22894
22895
22896 \size footnotesize 
22897 \SpecialChar ~
22898 \SpecialChar ~
22899 inc dptr
22900 \layout Standard
22901
22902
22903 \size footnotesize 
22904 \SpecialChar ~
22905 \SpecialChar ~
22906 movx a,@dptr
22907 \layout Standard
22908
22909
22910 \size footnotesize 
22911 \SpecialChar ~
22912 \SpecialChar ~
22913 mov r3,a
22914 \layout Standard
22915
22916
22917 \size footnotesize 
22918 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
22919 \layout Standard
22920
22921
22922 \size footnotesize 
22923 \SpecialChar ~
22924 \SpecialChar ~
22925 mov @r0,ar2
22926 \layout Standard
22927
22928
22929 \size footnotesize 
22930 \SpecialChar ~
22931 \SpecialChar ~
22932 inc r0
22933 \layout Standard
22934
22935
22936 \size footnotesize 
22937 \SpecialChar ~
22938 \SpecialChar ~
22939 mov @r0,ar3
22940 \layout Standard
22941
22942
22943 \size footnotesize 
22944 ; iTemp6 [lr5:16]{_near * int}[r0] = 
22945 \layout Standard
22946
22947
22948 \size footnotesize 
22949 ; iTemp6 [lr5:16]{_near * int}[r0] + 
22950 \layout Standard
22951
22952
22953 \size footnotesize 
22954 ; 0x2 {short}
22955 \layout Standard
22956
22957
22958 \size footnotesize 
22959 \SpecialChar ~
22960 \SpecialChar ~
22961 inc r0
22962 \layout Standard
22963
22964
22965 \size footnotesize 
22966 ; goto _whilecontinue_0($1)
22967 \layout Standard
22968
22969
22970 \size footnotesize 
22971 \SpecialChar ~
22972 \SpecialChar ~
22973 sjmp 00101$
22974 \layout Standard
22975
22976
22977 \size footnotesize 
22978 ; _whilebreak_0($3) :
22979 \layout Standard
22980
22981
22982 \size footnotesize 
22983 00103$:
22984 \layout Standard
22985
22986
22987 \size footnotesize 
22988 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
22989 \layout Standard
22990
22991
22992 \size footnotesize 
22993 \SpecialChar ~
22994 \SpecialChar ~
22995 mov r2,#0x00
22996 \layout Standard
22997
22998
22999 \size footnotesize 
23000 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
23001 \layout Standard
23002
23003
23004 \size footnotesize 
23005 \SpecialChar ~
23006 \SpecialChar ~
23007 mov r3,#0x00
23008 \layout Standard
23009
23010
23011 \size footnotesize 
23012 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
23013 \layout Standard
23014
23015
23016 \size footnotesize 
23017 \SpecialChar ~
23018 \SpecialChar ~
23019 mov r4,#0x00
23020 \layout Standard
23021
23022
23023 \size footnotesize 
23024 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
23025 \layout Standard
23026
23027
23028 \size footnotesize 
23029 \SpecialChar ~
23030 \SpecialChar ~
23031 mov r5,#0x0A
23032 \layout Standard
23033
23034
23035 \size footnotesize 
23036 \SpecialChar ~
23037 \SpecialChar ~
23038 mov r6,#0x00
23039 \layout Standard
23040
23041
23042 \size footnotesize 
23043 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
23044 \layout Standard
23045
23046
23047 \size footnotesize 
23048 \SpecialChar ~
23049 \SpecialChar ~
23050 mov r7,#0x1E
23051 \layout Standard
23052
23053
23054 \size footnotesize 
23055 \SpecialChar ~
23056 \SpecialChar ~
23057 mov r0,#0x00
23058 \layout Standard
23059
23060
23061 \size footnotesize 
23062 ; _forcond_0($4) :
23063 \layout Standard
23064
23065
23066 \size footnotesize 
23067 00104$:
23068 \layout Standard
23069
23070
23071 \size footnotesize 
23072 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
23073 \layout Standard
23074
23075
23076 \size footnotesize 
23077 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
23078 \layout Standard
23079
23080
23081 \size footnotesize 
23082 \SpecialChar ~
23083 \SpecialChar ~
23084 clr c
23085 \layout Standard
23086
23087
23088 \size footnotesize 
23089 \SpecialChar ~
23090 \SpecialChar ~
23091 mov a,r4
23092 \layout Standard
23093
23094
23095 \size footnotesize 
23096 \SpecialChar ~
23097 \SpecialChar ~
23098 xrl a,#0x80
23099 \layout Standard
23100
23101
23102 \size footnotesize 
23103 \SpecialChar ~
23104 \SpecialChar ~
23105 subb a,#0x8a
23106 \layout Standard
23107
23108
23109 \size footnotesize 
23110 \SpecialChar ~
23111 \SpecialChar ~
23112 jnc 00107$
23113 \layout Standard
23114
23115
23116 \size footnotesize 
23117 00115$:
23118 \layout Standard
23119
23120
23121 \size footnotesize 
23122 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
23123 \layout Standard
23124
23125
23126 \size footnotesize 
23127 ; iTemp21 [lr21:38]{short}[r4]
23128 \layout Standard
23129
23130
23131 \size footnotesize 
23132 \SpecialChar ~
23133 \SpecialChar ~
23134 mov a,r4
23135 \layout Standard
23136
23137
23138 \size footnotesize 
23139 \SpecialChar ~
23140 \SpecialChar ~
23141 add a,r2
23142 \layout Standard
23143
23144
23145 \size footnotesize 
23146 \SpecialChar ~
23147 \SpecialChar ~
23148 mov r2,a
23149 \layout Standard
23150
23151
23152 \size footnotesize 
23153 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
23154 \layout Standard
23155
23156
23157 \size footnotesize 
23158 \SpecialChar ~
23159 \SpecialChar ~
23160 mov b,#0x03
23161 \layout Standard
23162
23163
23164 \size footnotesize 
23165 \SpecialChar ~
23166 \SpecialChar ~
23167 mov a,r4
23168 \layout Standard
23169
23170
23171 \size footnotesize 
23172 \SpecialChar ~
23173 \SpecialChar ~
23174 mul ab
23175 \layout Standard
23176
23177
23178 \size footnotesize 
23179 \SpecialChar ~
23180 \SpecialChar ~
23181 mov r1,a
23182 \layout Standard
23183
23184
23185 \size footnotesize 
23186 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
23187 \layout Standard
23188
23189
23190 \size footnotesize 
23191 ; iTemp15 [lr29:30]{short}[r1]
23192 \layout Standard
23193
23194
23195 \size footnotesize 
23196 \SpecialChar ~
23197 \SpecialChar ~
23198 add a,r3
23199 \layout Standard
23200
23201
23202 \size footnotesize 
23203 \SpecialChar ~
23204 \SpecialChar ~
23205 mov r3,a
23206 \layout Standard
23207
23208
23209 \size footnotesize 
23210 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
23211 \layout Standard
23212
23213
23214 \size footnotesize 
23215 \SpecialChar ~
23216 \SpecialChar ~
23217 mov a,r7
23218 \layout Standard
23219
23220
23221 \size footnotesize 
23222 \SpecialChar ~
23223 \SpecialChar ~
23224 add a,#0xfd
23225 \layout Standard
23226
23227
23228 \size footnotesize 
23229 \SpecialChar ~
23230 \SpecialChar ~
23231 mov r7,a
23232 \layout Standard
23233
23234
23235 \size footnotesize 
23236 \SpecialChar ~
23237 \SpecialChar ~
23238 mov a,r0
23239 \layout Standard
23240
23241
23242 \size footnotesize 
23243 \SpecialChar ~
23244 \SpecialChar ~
23245 addc a,#0xff
23246 \layout Standard
23247
23248
23249 \size footnotesize 
23250 \SpecialChar ~
23251 \SpecialChar ~
23252 mov r0,a
23253 \layout Standard
23254
23255
23256 \size footnotesize 
23257 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
23258 \layout Standard
23259
23260
23261 \size footnotesize 
23262 \SpecialChar ~
23263 \SpecialChar ~
23264 mov a,r7
23265 \layout Standard
23266
23267
23268 \size footnotesize 
23269 \SpecialChar ~
23270 \SpecialChar ~
23271 add a,_gint
23272 \layout Standard
23273
23274
23275 \size footnotesize 
23276 \SpecialChar ~
23277 \SpecialChar ~
23278 mov _gint,a
23279 \layout Standard
23280
23281
23282 \size footnotesize 
23283 \SpecialChar ~
23284 \SpecialChar ~
23285 mov a,r0
23286 \layout Standard
23287
23288
23289 \size footnotesize 
23290 \SpecialChar ~
23291 \SpecialChar ~
23292 addc a,(_gint + 1)
23293 \layout Standard
23294
23295
23296 \size footnotesize 
23297 \SpecialChar ~
23298 \SpecialChar ~
23299 mov (_gint + 1),a
23300 \layout Standard
23301
23302
23303 \size footnotesize 
23304 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
23305 \layout Standard
23306
23307
23308 \size footnotesize 
23309 \SpecialChar ~
23310 \SpecialChar ~
23311 inc r4
23312 \layout Standard
23313
23314
23315 \size footnotesize 
23316 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
23317 \layout Standard
23318
23319
23320 \size footnotesize 
23321 \SpecialChar ~
23322 \SpecialChar ~
23323 dec r5
23324 \layout Standard
23325
23326
23327 \size footnotesize 
23328 \SpecialChar ~
23329 \SpecialChar ~
23330 cjne r5,#0xff,00104$
23331 \layout Standard
23332
23333
23334 \size footnotesize 
23335 \SpecialChar ~
23336 \SpecialChar ~
23337 dec r6
23338 \layout Standard
23339
23340
23341 \size footnotesize 
23342 ; goto _forcond_0($4)
23343 \layout Standard
23344
23345
23346 \size footnotesize 
23347 \SpecialChar ~
23348 \SpecialChar ~
23349 sjmp 00104$
23350 \layout Standard
23351
23352
23353 \size footnotesize 
23354 ; _forbreak_0($7) :
23355 \layout Standard
23356
23357
23358 \size footnotesize 
23359 00107$:
23360 \layout Standard
23361
23362
23363 \size footnotesize 
23364 ; ret iTemp24 [lr40:41]{short}
23365 \layout Standard
23366
23367
23368 \size footnotesize 
23369 \SpecialChar ~
23370 \SpecialChar ~
23371 mov a,r3
23372 \layout Standard
23373
23374
23375 \size footnotesize 
23376 \SpecialChar ~
23377 \SpecialChar ~
23378 add a,r2
23379 \layout Standard
23380
23381
23382 \size footnotesize 
23383 \SpecialChar ~
23384 \SpecialChar ~
23385 mov dpl,a
23386 \layout Standard
23387
23388
23389 \size footnotesize 
23390 ; _return($8) :
23391 \layout Standard
23392
23393
23394 \size footnotesize 
23395 00108$:
23396 \layout Standard
23397
23398
23399 \size footnotesize 
23400 \SpecialChar ~
23401 \SpecialChar ~
23402 ret
23403 \newline 
23404
23405 \layout Section
23406
23407 A few words about basic block successors, predecessors and dominators
23408 \layout Standard
23409
23410 Successors are basic blocks
23411 \begin_inset LatexCommand \index{Basic blocks}
23412
23413 \end_inset 
23414
23415  that might execute after this basic block.
23416 \newline 
23417 Predecessors are basic blocks that might execute before reaching this basic
23418  block.
23419 \newline 
23420 Dominators are basic blocks that WILL execute before reaching this basic
23421  block.
23422 \newline 
23423
23424 \layout Standard
23425
23426 [basic block 1]
23427 \layout Standard
23428
23429 if (something)
23430 \layout Standard
23431
23432 \SpecialChar ~
23433 \SpecialChar ~
23434 \SpecialChar ~
23435 \SpecialChar ~
23436 [basic block 2]
23437 \layout Standard
23438
23439 else
23440 \layout Standard
23441
23442 \SpecialChar ~
23443 \SpecialChar ~
23444 \SpecialChar ~
23445 \SpecialChar ~
23446 [basic block 3]
23447 \layout Standard
23448
23449 [basic block 4]
23450 \newline 
23451
23452 \layout Standard
23453
23454 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
23455 \layout Standard
23456
23457 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
23458 \layout Standard
23459
23460 c) domVect of [BB4] = BB1 ...
23461  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
23462  was executed.
23463 \layout Chapter
23464
23465 Acknowledgments
23466 \layout Standard
23467
23468
23469 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
23470
23471 \end_inset 
23472
23473
23474 \newline 
23475
23476 \newline 
23477
23478 \emph on 
23479 Thanks to all the other volunteer developers who have helped with coding,
23480  testing, web-page creation, distribution sets, etc.
23481  You know who you are :-)
23482 \emph default 
23483
23484 \newline 
23485
23486 \layout Standard
23487
23488 This document was initially written by Sandeep Dutta
23489 \layout Standard
23490
23491 All product names mentioned herein may be trademarks
23492 \begin_inset LatexCommand \index{Trademarks}
23493
23494 \end_inset 
23495
23496  of their respective companies.
23497  
23498 \layout Section*
23499
23500 Alphabetical index
23501 \layout Standard
23502
23503 To avoid confusion, the installation and building options for SDCC itself
23504  (chapter 2) are not part of the index.
23505 \layout Standard
23506
23507
23508 \begin_inset LatexCommand \printindex{}
23509
23510 \end_inset 
23511
23512
23513 \the_end