* src/pic16/gen.c: fixed bug #1106975,
[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.8
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 The external stack (-
13968 \begin_inset ERT
13969 status Collapsed
13970
13971 \layout Standard
13972
13973 \backslash 
13974 /
13975 \end_inset 
13976
13977 -xstack option
13978 \begin_inset LatexCommand \index{-\/-xstack}
13979
13980 \end_inset 
13981
13982 ) is located in pdata
13983 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
13984
13985 \end_inset 
13986
13987  memory (usually at the start of the external ram segment) and uses all
13988  unused space in pdata (max.
13989  256 bytes).
13990  When -
13991 \begin_inset ERT
13992 status Collapsed
13993
13994 \layout Standard
13995
13996 \backslash 
13997 /
13998 \end_inset 
13999
14000 -xstack option is used to compile the program, the parameters and local
14001  variables
14002 \begin_inset LatexCommand \index{local variables}
14003
14004 \end_inset 
14005
14006  of all reentrant functions are allocated in this area.
14007  This option is provided for programs with large stack space requirements.
14008  When used with the -
14009 \begin_inset ERT
14010 status Collapsed
14011
14012 \layout Standard
14013
14014 \backslash 
14015 /
14016 \end_inset 
14017
14018 -stack-auto
14019 \begin_inset LatexCommand \index{-\/-stack-auto}
14020
14021 \end_inset 
14022
14023  option, all parameters and local variables are allocated on the external
14024  stack (note: support libraries will need to be recompiled with the same
14025  options.
14026  There is a predefined target in the library makefile).
14027 \layout Standard
14028
14029 The compiler outputs the higher order address byte of the external ram segment
14030  into port P2
14031 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
14032
14033 \end_inset 
14034
14035  (see also section 
14036 \begin_inset LatexCommand \ref{sub:MCS51-variants}
14037
14038 \end_inset 
14039
14040 ), therefore when using the External Stack option, this port 
14041 \emph on 
14042 may not
14043 \emph default 
14044  be used by the application program.
14045 \layout Subsection
14046
14047 DS390 Memory Model
14048 \begin_inset LatexCommand \index{Memory model}
14049
14050 \end_inset 
14051
14052
14053 \begin_inset LatexCommand \index{DS390 memory model}
14054
14055 \end_inset 
14056
14057
14058 \layout Standard
14059
14060 The only model supported is Flat 24
14061 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
14062
14063 \end_inset 
14064
14065 .
14066  This generates code for the 24 bit contiguous addressing mode of the Dallas
14067  DS80C390 part.
14068  In this mode, up to four meg of external RAM or code space can be directly
14069  addressed.
14070  See the data sheets at www.dalsemi.com for further information on this part.
14071 \newline 
14072
14073 \newline 
14074 Note that the compiler does not generate any code to place the processor
14075  into 24 bitmode (although 
14076 \emph on 
14077 tinibios
14078 \emph default 
14079  in the ds390 libraries will do that for you).
14080  If you don't use 
14081 \emph on 
14082 tinibios
14083 \emph default 
14084
14085 \begin_inset LatexCommand \index{Tinibios (DS390)}
14086
14087 \end_inset 
14088
14089 , the boot loader or similar code must ensure that the processor is in 24
14090  bit contiguous addressing mode before calling the SDCC startup code.
14091 \newline 
14092
14093 \newline 
14094 Like the 
14095 \emph on 
14096 -
14097 \begin_inset ERT
14098 status Collapsed
14099
14100 \layout Standard
14101
14102 \backslash 
14103 /
14104 \end_inset 
14105
14106 -model-large
14107 \emph default 
14108  option, variables will by default be placed into the XDATA segment.
14109  
14110 \newline 
14111
14112 \newline 
14113 Segments may be placed anywhere in the 4 meg address space using the usual
14114  -
14115 \begin_inset ERT
14116 status Collapsed
14117
14118 \layout Standard
14119
14120 \backslash 
14121 /
14122 \end_inset 
14123
14124 -*-loc options.
14125  Note that if any segments are located above 64K, the -r flag must be passed
14126  to the linker to generate the proper segment relocations, and the Intel
14127  HEX output format must be used.
14128  The -r flag can be passed to the linker by using the option 
14129 \emph on 
14130 -Wl-r
14131 \emph default 
14132  on the SDCC command line.
14133  However, currently the linker can not handle code segments > 64k.
14134 \layout Section
14135
14136 Pragmas
14137 \begin_inset LatexCommand \index{Pragmas}
14138
14139 \end_inset 
14140
14141
14142 \layout Standard
14143
14144 SDCC supports the following #pragma directives:
14145 \layout Itemize
14146
14147 save
14148 \begin_inset LatexCommand \index{\#pragma save}
14149
14150 \end_inset 
14151
14152  - this will save all current options to the save/restore stack.
14153  See #pragma\SpecialChar ~
14154 restore.
14155 \layout Itemize
14156
14157 restore
14158 \begin_inset LatexCommand \index{\#pragma restore}
14159
14160 \end_inset 
14161
14162  - will restore saved options from the last save.
14163  saves & restores can be nested.
14164  SDCC uses a save/restore stack: save pushes current options to the stack,
14165  restore pulls current options from the stack.
14166  See #pragma\SpecialChar ~
14167 save.
14168 \newline 
14169
14170 \layout Itemize
14171
14172 callee_saves
14173 \begin_inset LatexCommand \index{\#pragma callee\_saves}
14174
14175 \end_inset 
14176
14177
14178 \begin_inset LatexCommand \index{function prologue}
14179
14180 \end_inset 
14181
14182  function1[,function2[,function3...]] - The compiler by default uses a caller
14183  saves convention for register saving across function calls, however this
14184  can cause unnecessary register pushing & popping
14185 \begin_inset LatexCommand \index{push/pop}
14186
14187 \end_inset 
14188
14189  when calling small functions from larger functions.
14190  This option can be used to switch off the register saving convention for
14191  the function names specified.
14192  The compiler will not save registers when calling these functions, extra
14193  code need to be manually inserted at the entry & exit for these functions
14194  to save & restore the registers used by these functions, this can SUBSTANTIALLY
14195  reduce code & improve run time performance of the generated code.
14196  In the future the compiler (with inter procedural analysis) may be able
14197  to determine the appropriate scheme to use for each function call.
14198  If -
14199 \begin_inset ERT
14200 status Collapsed
14201
14202 \layout Standard
14203
14204 \backslash 
14205 /
14206 \end_inset 
14207
14208 -callee-saves command line option is used, the function names specified
14209  in #pragma\SpecialChar ~
14210 callee_saves
14211 \begin_inset LatexCommand \index{\#pragma callee\_saves}
14212
14213 \end_inset 
14214
14215  is appended to the list of functions specified in the command line.
14216 \layout Itemize
14217
14218 exclude
14219 \begin_inset LatexCommand \index{\#pragma exclude}
14220
14221 \end_inset 
14222
14223  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
14224  of pairs of push/pop
14225 \begin_inset LatexCommand \index{push/pop}
14226
14227 \end_inset 
14228
14229  instructions in 
14230 \emph on 
14231 I
14232 \emph default 
14233 nterrupt
14234 \begin_inset LatexCommand \index{interrupt}
14235
14236 \end_inset 
14237
14238  
14239 \emph on 
14240 S
14241 \emph default 
14242 ervice 
14243 \emph on 
14244 R
14245 \emph default 
14246 outines.
14247  The directive should be placed immediately before the ISR function definition
14248  and it affects ALL ISR functions following it.
14249  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
14250 exclude\SpecialChar ~
14251 none
14252 \begin_inset LatexCommand \index{\#pragma exclude}
14253
14254 \end_inset 
14255
14256 .
14257  See also the related keyword _naked
14258 \begin_inset LatexCommand \index{\_naked}
14259
14260 \end_inset 
14261
14262 .
14263 \layout Itemize
14264
14265 less_pedantic
14266 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
14267
14268 \end_inset 
14269
14270  - the compiler will not warn you anymore for obvious mistakes, you'r on
14271  your own now ;-(
14272 \layout Itemize
14273
14274 disable_warning <nnnn>
14275 \begin_inset LatexCommand \index{\#pragma disable\_warning}
14276
14277 \end_inset 
14278
14279  - the compiler will not warn you anymore about warning number <nnnn>.
14280 \layout Itemize
14281
14282 nogcse
14283 \begin_inset LatexCommand \index{\#pragma nogcse}
14284
14285 \end_inset 
14286
14287  - will stop global common subexpression elimination.
14288 \layout Itemize
14289
14290 noinduction
14291 \begin_inset LatexCommand \index{\#pragma noinduction}
14292
14293 \end_inset 
14294
14295  - will stop loop induction optimizations.
14296 \layout Itemize
14297
14298 noinvariant
14299 \begin_inset LatexCommand \index{\#pragma noinvariant}
14300
14301 \end_inset 
14302
14303  - will not do loop invariant optimizations.
14304  For more details see Loop Invariants in section
14305 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
14306
14307 \end_inset 
14308
14309 .
14310 \layout Itemize
14311
14312 noiv
14313 \begin_inset LatexCommand \index{\#pragma noiv}
14314
14315 \end_inset 
14316
14317  - Do not generate interrupt
14318 \begin_inset LatexCommand \index{interrupt}
14319
14320 \end_inset 
14321
14322  vector table entries for all ISR functions defined after the pragma.
14323  This is useful in cases where the interrupt vector table must be defined
14324  manually, or when there is a secondary, manually defined interrupt vector
14325  table (e.g.
14326  for the autovector feature of the Cypress EZ-USB FX2).
14327  More elegantly this can be achieved by obmitting the optional interrupt
14328  number after the interrupt keyword, see section 
14329 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
14330
14331 \end_inset 
14332
14333 \SpecialChar ~
14334 about interrupts.
14335 \layout Itemize
14336
14337 nojtbound
14338 \begin_inset LatexCommand \index{\#pragma nojtbound}
14339
14340 \end_inset 
14341
14342  - will not generate code for boundary value checking, when switch statements
14343  are turned into jump-tables (dangerous).
14344  For more details see section 
14345 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
14346
14347 \end_inset 
14348
14349 .
14350 \layout Itemize
14351
14352 noloopreverse
14353 \begin_inset LatexCommand \index{\#pragma noloopreverse}
14354
14355 \end_inset 
14356
14357  - Will not do loop reversal optimization
14358 \layout Itemize
14359
14360 nooverlay
14361 \begin_inset LatexCommand \index{\#pragma nooverlay}
14362
14363 \end_inset 
14364
14365  - the compiler will not overlay the parameters and local variables of a
14366  function.
14367 \layout Itemize
14368
14369 stackauto
14370 \begin_inset LatexCommand \index{\#pragma stackauto}
14371
14372 \end_inset 
14373
14374 - See option -
14375 \begin_inset ERT
14376 status Collapsed
14377
14378 \layout Standard
14379
14380 \backslash 
14381 /
14382 \end_inset 
14383
14384 -stack-auto
14385 \begin_inset LatexCommand \index{-\/-stack-auto}
14386
14387 \end_inset 
14388
14389  and section 
14390 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
14391
14392 \end_inset 
14393
14394  Parameters and Local Variables.
14395 \layout Itemize
14396
14397 opt_code_speed 
14398 \begin_inset LatexCommand \index{\#pragma opt\_code\_speed}
14399
14400 \end_inset 
14401
14402 - The compiler will optimize code generation towards fast code, possibly
14403  at the expense of code size.
14404 \layout Itemize
14405
14406 opt_code_size 
14407 \begin_inset LatexCommand \index{\#pragma opt\_code\_size}
14408
14409 \end_inset 
14410
14411 - The compiler will optimize code generation towards compact code, possibly
14412  at the expense of code speed.
14413 \layout Itemize
14414
14415 opt_code_balanced 
14416 \begin_inset LatexCommand \index{\#pragma opt\_code\_balanced}
14417
14418 \end_inset 
14419
14420 - The compiler will attempt to generate code that is both compact and fast,
14421  as long as meeting one goal is not a detriment to the other (this is the
14422  default).
14423  
14424 \layout Standard
14425
14426 SDCPP supports the following #pragma directives:
14427 \layout Itemize
14428
14429 preproc_asm
14430 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
14431
14432 \end_inset 
14433
14434  (+ | -) - switch _asm _endasm block preprocessing on / off.
14435  Default is on.
14436 \layout Standard
14437
14438 The pragma's are intended to be used to turn-on or off certain optimizations
14439  which might cause the compiler to generate extra stack / data space to
14440  store compiler generated temporary variables.
14441  This usually happens in large functions.
14442  Pragma directives should be used as shown in the following example, they
14443  are used to control options & optimizations for a given function; pragmas
14444  should be placed before and/or after a function, placing pragma's inside
14445  a function body could have unpredictable results.
14446 \layout Verse
14447
14448
14449 \family typewriter 
14450 #pragma save
14451 \begin_inset LatexCommand \index{\#pragma save}
14452
14453 \end_inset 
14454
14455  \SpecialChar ~
14456 \SpecialChar ~
14457 \SpecialChar ~
14458 \SpecialChar ~
14459 \SpecialChar ~
14460 \SpecialChar ~
14461 \SpecialChar ~
14462 /* save the current settings */ 
14463 \newline 
14464 #pragma nogcse
14465 \begin_inset LatexCommand \index{\#pragma nogcse}
14466
14467 \end_inset 
14468
14469  \SpecialChar ~
14470 \SpecialChar ~
14471 \SpecialChar ~
14472 \SpecialChar ~
14473 \SpecialChar ~
14474 /* turnoff global subexpression elimination */ 
14475 \newline 
14476 #pragma noinduction
14477 \begin_inset LatexCommand \index{\#pragma noinduction}
14478
14479 \end_inset 
14480
14481  /* turn off induction optimizations */ 
14482 \newline 
14483 int foo () 
14484 \newline 
14485
14486 \newline 
14487 \SpecialChar ~
14488  \SpecialChar ~
14489  ...
14490  
14491 \newline 
14492 \SpecialChar ~
14493  \SpecialChar ~
14494  /* large code */ 
14495 \newline 
14496 \SpecialChar ~
14497  \SpecialChar ~
14498  ...
14499  
14500 \newline 
14501
14502 \newline 
14503 #pragma restore
14504 \begin_inset LatexCommand \index{\#pragma restore}
14505
14506 \end_inset 
14507
14508  /* turn the optimizations back on */
14509 \layout Standard
14510
14511 The compiler will generate a warning message when extra space is allocated.
14512  It is strongly recommended that the save and restore pragma's be used when
14513  changing options for a function.
14514 \layout Section
14515
14516 Defines Created by the Compiler
14517 \layout Standard
14518
14519 The compiler creates the following #defines
14520 \begin_inset LatexCommand \index{\#defines}
14521
14522 \end_inset 
14523
14524
14525 \begin_inset LatexCommand \index{Defines created by the compiler}
14526
14527 \end_inset 
14528
14529 :
14530 \newline 
14531
14532 \layout Standard
14533
14534
14535 \begin_inset  Tabular
14536 <lyxtabular version="3" rows="10" columns="2">
14537 <features>
14538 <column alignment="center" valignment="top" leftline="true" width="0">
14539 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
14540 <row topline="true" bottomline="true">
14541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14542 \begin_inset Text
14543
14544 \layout Standard
14545
14546
14547 \series bold 
14548 #define
14549 \end_inset 
14550 </cell>
14551 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14552 \begin_inset Text
14553
14554 \layout Standard
14555
14556
14557 \series bold 
14558 Description
14559 \end_inset 
14560 </cell>
14561 </row>
14562 <row topline="true">
14563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14564 \begin_inset Text
14565
14566 \layout Standard
14567
14568 SDCC
14569 \begin_inset LatexCommand \index{SDCC}
14570
14571 \end_inset 
14572
14573  
14574 \end_inset 
14575 </cell>
14576 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14577 \begin_inset Text
14578
14579 \layout Standard
14580
14581 this Symbol is always defined
14582 \end_inset 
14583 </cell>
14584 </row>
14585 <row topline="true">
14586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14587 \begin_inset Text
14588
14589 \layout Standard
14590
14591 SDCC_mcs51
14592 \begin_inset LatexCommand \index{SDCC\_mcs51}
14593
14594 \end_inset 
14595
14596  or SDCC_ds390
14597 \begin_inset LatexCommand \index{SDCC\_ds390}
14598
14599 \end_inset 
14600
14601  or SDCC_z80
14602 \begin_inset LatexCommand \index{SDCC\_z80}
14603
14604 \end_inset 
14605
14606 , etc
14607 \end_inset 
14608 </cell>
14609 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14610 \begin_inset Text
14611
14612 \layout Standard
14613
14614 depending on the model used (e.g.: -mds390
14615 \end_inset 
14616 </cell>
14617 </row>
14618 <row topline="true">
14619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14620 \begin_inset Text
14621
14622 \layout Standard
14623
14624 __mcs51
14625 \begin_inset LatexCommand \index{\_\_mcs51}
14626
14627 \end_inset 
14628
14629 , __ds390
14630 \begin_inset LatexCommand \index{\_\_ds390}
14631
14632 \end_inset 
14633
14634 , __hc08
14635 \begin_inset LatexCommand \index{\_\_hc08}
14636
14637 \end_inset 
14638
14639 , __z80
14640 \begin_inset LatexCommand \index{\_\_z80}
14641
14642 \end_inset 
14643
14644 , etc
14645 \end_inset 
14646 </cell>
14647 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14648 \begin_inset Text
14649
14650 \layout Standard
14651
14652 depending on the model used (e.g.
14653  -mz80)
14654 \end_inset 
14655 </cell>
14656 </row>
14657 <row topline="true">
14658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14659 \begin_inset Text
14660
14661 \layout Standard
14662
14663 SDCC_STACK_AUTO
14664 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
14665
14666 \end_inset 
14667
14668
14669 \end_inset 
14670 </cell>
14671 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14672 \begin_inset Text
14673
14674 \layout Standard
14675
14676 when 
14677 \emph on 
14678 -
14679 \begin_inset ERT
14680 status Collapsed
14681
14682 \layout Standard
14683
14684 \backslash 
14685 /
14686 \end_inset 
14687
14688 -stack-auto
14689 \emph default 
14690  option is used
14691 \end_inset 
14692 </cell>
14693 </row>
14694 <row topline="true">
14695 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14696 \begin_inset Text
14697
14698 \layout Standard
14699
14700 SDCC_MODEL_SMALL
14701 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
14702
14703 \end_inset 
14704
14705
14706 \end_inset 
14707 </cell>
14708 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14709 \begin_inset Text
14710
14711 \layout Standard
14712
14713 when 
14714 \emph on 
14715 -
14716 \begin_inset ERT
14717 status Collapsed
14718
14719 \layout Standard
14720
14721 \backslash 
14722 /
14723 \end_inset 
14724
14725 -model-small
14726 \emph default 
14727  is used
14728 \end_inset 
14729 </cell>
14730 </row>
14731 <row topline="true">
14732 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14733 \begin_inset Text
14734
14735 \layout Standard
14736
14737 SDCC_MODEL_LARGE
14738 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
14739
14740 \end_inset 
14741
14742
14743 \end_inset 
14744 </cell>
14745 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14746 \begin_inset Text
14747
14748 \layout Standard
14749
14750 when 
14751 \emph on 
14752 -
14753 \begin_inset ERT
14754 status Collapsed
14755
14756 \layout Standard
14757
14758 \backslash 
14759 /
14760 \end_inset 
14761
14762 -model-large
14763 \emph default 
14764  is used
14765 \end_inset 
14766 </cell>
14767 </row>
14768 <row topline="true">
14769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14770 \begin_inset Text
14771
14772 \layout Standard
14773
14774 SDCC_USE_XSTACK
14775 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
14776
14777 \end_inset 
14778
14779
14780 \end_inset 
14781 </cell>
14782 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14783 \begin_inset Text
14784
14785 \layout Standard
14786
14787 when 
14788 \emph on 
14789 -
14790 \begin_inset ERT
14791 status Collapsed
14792
14793 \layout Standard
14794
14795 \backslash 
14796 /
14797 \end_inset 
14798
14799 -xstack
14800 \emph default 
14801  option is used
14802 \end_inset 
14803 </cell>
14804 </row>
14805 <row topline="true">
14806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14807 \begin_inset Text
14808
14809 \layout Standard
14810
14811 SDCC_STACK_TENBIT
14812 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
14813
14814 \end_inset 
14815
14816  
14817 \end_inset 
14818 </cell>
14819 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14820 \begin_inset Text
14821
14822 \layout Standard
14823
14824 when 
14825 \emph on 
14826 -mds390
14827 \emph default 
14828  is used
14829 \end_inset 
14830 </cell>
14831 </row>
14832 <row topline="true" bottomline="true">
14833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14834 \begin_inset Text
14835
14836 \layout Standard
14837
14838 SDCC_MODEL_FLAT24
14839 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
14840
14841 \end_inset 
14842
14843
14844 \end_inset 
14845 </cell>
14846 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14847 \begin_inset Text
14848
14849 \layout Standard
14850
14851 when 
14852 \emph on 
14853 -mds390
14854 \emph default 
14855  is used
14856 \end_inset 
14857 </cell>
14858 </row>
14859 </lyxtabular>
14860
14861 \end_inset 
14862
14863
14864 \layout Chapter
14865
14866 Notes on supported Processors
14867 \layout Section
14868
14869 MCS51 variants
14870 \begin_inset LatexCommand \label{sub:MCS51-variants}
14871
14872 \end_inset 
14873
14874
14875 \begin_inset LatexCommand \index{MCS51 variants}
14876
14877 \end_inset 
14878
14879
14880 \layout Standard
14881
14882 MCS51 processors are available from many vendors and come in many different
14883  flavours.
14884  While they might differ considerably in respect to Special Function Registers
14885  the core MCS51 is usually not modified or is kept compatible.
14886  
14887 \layout Subsection
14888
14889 pdata access by SFR 
14890 \layout Standard
14891
14892 With the upcome of devices with internal xdata and flash memory devices
14893  using port P2
14894 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
14895
14896 \end_inset 
14897
14898  as dedicated I/O port is becoming more popular.
14899  Switching the high byte for pdata
14900 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
14901
14902 \end_inset 
14903
14904  access which was formerly done by port P2 is then achieved by a Special
14905  Function Register
14906 \begin_inset LatexCommand \index{sfr}
14907
14908 \end_inset 
14909
14910 .
14911  In well-established MCS51 tradition the address of this 
14912 \emph on 
14913 sfr
14914 \emph default 
14915  is where the chip designers decided to put it.
14916  Needless to say that they didn't agree on a common name either.
14917  So that the startup code can correctly initialize xdata variables, you
14918  should define an sfr with the name _XPAGE
14919 \family typewriter 
14920
14921 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
14922
14923 \end_inset 
14924
14925
14926 \family default 
14927  at the appropriate location if the default, port P2, is not used for this.
14928  Some examples are:
14929 \layout Verse
14930
14931
14932 \family typewriter 
14933 sfr at 0x92 _XPAGE; /* Cypress EZ-USB family */
14934 \layout Verse
14935
14936
14937 \family typewriter 
14938 sfr at 0xaf _XPAGE; /* some Silicon Labs (Cygnal) chips */
14939 \layout Verse
14940
14941
14942 \family typewriter 
14943 sfr at 0xaa _XPAGE; /* some Silicon Labs (Cygnal) chips */
14944 \layout Standard
14945
14946 For more exotic implementations further customizations may be needed.
14947  See section 
14948 \begin_inset LatexCommand \ref{sub:Startup-Code}
14949
14950 \end_inset 
14951
14952  for other possibilities.
14953 \layout Subsection
14954
14955 Other Features available by SFR
14956 \layout Standard
14957
14958 Some MCS51 variants offer features like Double DPTR
14959 \begin_inset LatexCommand \index{DPTR}
14960
14961 \end_inset 
14962
14963 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
14964  These are currently not used for the MCS51 port.
14965  If you absolutely need them you can fall back to inline assembly or submit
14966  a patch to SDCC.
14967 \layout Section
14968
14969 DS400 port
14970 \layout Standard
14971
14972 The DS80C400 microcontroller has a rich set of peripherals.
14973  In its built-in ROM library it includes functions to access some of the
14974  features, among them is a TCP stack with IP4 and IP6 support.
14975  Library headers (currently in beta status) and other files are provided
14976  at 
14977 \size footnotesize 
14978
14979 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
14980
14981 \end_inset 
14982
14983 .
14984  
14985 \layout Section
14986
14987 The Z80 and gbz80 port
14988 \layout Standard
14989
14990 SDCC can target both the Zilog 
14991 \begin_inset LatexCommand \index{Z80}
14992
14993 \end_inset 
14994
14995  and the Nintendo Gameboy's Z80-like gbz80
14996 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
14997
14998 \end_inset 
14999
15000 .
15001  The Z80 port is passed through the same 
15002 \emph on 
15003 regressions tests
15004 \begin_inset LatexCommand \index{Regression test}
15005
15006 \end_inset 
15007
15008
15009 \emph default 
15010  as the MCS51 and DS390 ports, so floating point support, support for long
15011  variables and bitfield support is fine.
15012  See mailing lists and forums about interrupt routines.
15013 \layout Standard
15014
15015 As always, the code is the authoritative reference - see z80/ralloc.c and
15016  z80/gen.c.
15017  The stack
15018 \begin_inset LatexCommand \index{stack}
15019
15020 \end_inset 
15021
15022  frame is similar to that generated by the IAR Z80 compiler.
15023  IX is used as the base pointer, HL and IY are used as a temporary registers,
15024  and BC and DE are available for holding variables.
15025  Return values
15026 \begin_inset LatexCommand \index{return value}
15027
15028 \end_inset 
15029
15030  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
15031  bytes).
15032  The gbz80 port use the same set of registers for the return values, but
15033  in a different order of significance: E (one byte), DE (two bytes), or
15034  HLDE (four bytes).
15035 \layout Section
15036
15037 The HC08 port
15038 \layout Standard
15039
15040 The port to the Motorola HC08
15041 \begin_inset LatexCommand \index{HC08}
15042
15043 \end_inset 
15044
15045  family has been added in October 2003, and is still undergoing some basic
15046  development.
15047  The code generator is complete, but the register allocation is still quite
15048  unoptimized.
15049  Some of the SDCC's standard C library functions have embedded non-HC08
15050  inline assembly and so are not yet usable.
15051 \newline 
15052
15053 \newline 
15054
15055 \layout Section
15056
15057 The PIC14 port
15058 \layout Standard
15059
15060 The 14bit PIC
15061 \begin_inset LatexCommand \index{PIC14}
15062
15063 \end_inset 
15064
15065  port still requires a major effort from the development community.
15066  However it can work for very simple code.
15067 \layout Subsection
15068
15069 C code and 14bit PIC code page
15070 \begin_inset LatexCommand \index{code page (pic14)}
15071
15072 \end_inset 
15073
15074  and RAM banks
15075 \begin_inset LatexCommand \index{RAM bank (pic14)}
15076
15077 \end_inset 
15078
15079
15080 \layout Standard
15081
15082 The linker organizes allocation for the code page and RAM banks.
15083  It does not have intimate knowledge of the code flow.
15084  It will put all the code section of a single asm file into a single code
15085  page.
15086  In order to make use of multiple code pages, separate asm files must be
15087  used.
15088  The compiler treats all functions of a single C file as being in the same
15089  code page unless it is non static.
15090  The compiler treats all local variables of a single C file as being in
15091  the same RAM bank unless it is an extern.
15092 \newline 
15093
15094 \newline 
15095 To get the best follow these guide lines:
15096 \layout Enumerate
15097
15098 make local functions static, as non static functions require code page selection
15099  overhead.
15100 \layout Enumerate
15101
15102 Make local variables static as extern variables require RAM bank selection
15103  overhead.
15104 \layout Enumerate
15105
15106 For devices that have multiple code pages it is more efficient to use the
15107  same number of files as pages, i.e.
15108  for the 16F877 use 4 separate files and i.e.
15109  for the 16F874 use 2 separate files.
15110  This way the linker can put the code for each file into different code
15111  pages and the compiler can allocate reusable variables more efficiently
15112  and there's less page selection overhead.
15113  And as for any 8 bit micro (especially for PIC 14 as they have a very simple
15114  instruction set) use 'unsigned char' whereever possible instead of 'int'.
15115 \layout Subsection
15116
15117 Creating a device include file 
15118 \layout Standard
15119
15120 For generating a device include file use the support perl script inc2h.pl
15121  kept in directory support/script.
15122 \layout Subsection
15123
15124 Interrupt code
15125 \layout Standard
15126
15127 For the interrupt function, use the keyword 'interrupt'
15128 \begin_inset LatexCommand \index{interrupt}
15129
15130 \end_inset 
15131
15132  with level number of 0 (PIC14 only has 1 interrupt so this number is only
15133  there to avoid a syntax error - it ought to be fixed).
15134  E.g.:
15135 \layout Verse
15136
15137
15138 \family typewriter 
15139 void Intr(void) interrupt 0
15140 \newline 
15141 {
15142 \newline 
15143 \SpecialChar ~
15144 \SpecialChar ~
15145 T0IF = 0; /* Clear timer interrupt */
15146 \newline 
15147 }
15148 \layout Subsection
15149
15150 Linking and assembling
15151 \layout Standard
15152
15153 For assembling you can use either GPUTILS'
15154 \begin_inset LatexCommand \index{gputils (pic tools)}
15155
15156 \end_inset 
15157
15158  gpasm.exe or MPLAB's mpasmwin.exe.
15159  GPUTILS is available from 
15160 \begin_inset LatexCommand \url{http://gputils.sourceforge.net/}
15161
15162 \end_inset 
15163
15164 .
15165  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
15166  If you use MPLAB and an interrupt function then the linker script file
15167  vectors section will need to be enlarged to link with mplink.
15168 \newline 
15169
15170 \newline 
15171 Here is a 
15172 \family typewriter 
15173 Makefile
15174 \family default 
15175  using GPUTILS:
15176 \layout Verse
15177
15178
15179 \family typewriter 
15180 .c.o:
15181 \newline 
15182 \SpecialChar ~
15183 \SpecialChar ~
15184 \SpecialChar ~
15185 \SpecialChar ~
15186 \SpecialChar ~
15187 \SpecialChar ~
15188 \SpecialChar ~
15189 \SpecialChar ~
15190 sdcc -S -V -mpic14 -p16F877 $< 
15191 \newline 
15192 \SpecialChar ~
15193 \SpecialChar ~
15194 \SpecialChar ~
15195 \SpecialChar ~
15196 \SpecialChar ~
15197 \SpecialChar ~
15198 \SpecialChar ~
15199 \SpecialChar ~
15200 gpasm -c $*.asm
15201 \newline 
15202
15203 \newline 
15204 $(PRJ).hex: $(OBJS) 
15205 \newline 
15206 \SpecialChar ~
15207 \SpecialChar ~
15208 \SpecialChar ~
15209 \SpecialChar ~
15210 \SpecialChar ~
15211 \SpecialChar ~
15212 \SpecialChar ~
15213 \SpecialChar ~
15214 gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS)
15215 \layout Standard
15216
15217 Here is a 
15218 \family typewriter 
15219 Makefile
15220 \family default 
15221  using MPLAB:
15222 \layout Verse
15223
15224
15225 \family typewriter 
15226 .c.o: 
15227 \newline 
15228 \SpecialChar ~
15229 \SpecialChar ~
15230 \SpecialChar ~
15231 \SpecialChar ~
15232 \SpecialChar ~
15233 \SpecialChar ~
15234 \SpecialChar ~
15235 \SpecialChar ~
15236 sdcc -S -V -mpic14 -p16F877 $< 
15237 \newline 
15238 \SpecialChar ~
15239 \SpecialChar ~
15240 \SpecialChar ~
15241 \SpecialChar ~
15242 \SpecialChar ~
15243 \SpecialChar ~
15244 \SpecialChar ~
15245 \SpecialChar ~
15246 mpasmwin /q /o $*.asm
15247 \newline 
15248
15249 \newline 
15250 $(PRJ).hex: $(OBJS) 
15251 \newline 
15252 \SpecialChar ~
15253 \SpecialChar ~
15254 \SpecialChar ~
15255 \SpecialChar ~
15256 \SpecialChar ~
15257 \SpecialChar ~
15258 \SpecialChar ~
15259 \SpecialChar ~
15260 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS)
15261 \layout Standard
15262
15263 Please note that indentations within a
15264 \family typewriter 
15265  Makefile
15266 \family default 
15267  have to be done with a tabulator character.
15268 \layout Section
15269
15270 The PIC16
15271 \begin_inset LatexCommand \index{PIC16}
15272
15273 \end_inset 
15274
15275  port
15276 \layout Standard
15277
15278 The PIC16
15279 \begin_inset LatexCommand \index{PIC16}
15280
15281 \end_inset 
15282
15283  port is the portion of SDCC that is responsible to produce code for the
15284  Microchip
15285 \begin_inset LatexCommand \index{Microchip}
15286
15287 \end_inset 
15288
15289 (TM) microcontrollers with 16 bit core.
15290  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
15291 \layout Subsection
15292
15293 Global Options
15294 \layout Standard
15295
15296 PIC16 port supports the standard command line arguments as supposed, with
15297  the exception of certain cases that will be mentioned in the following
15298  list:
15299 \layout List
15300 \labelwidthstring 00.00.0000
15301
15302 -
15303 \begin_inset ERT
15304 status Collapsed
15305
15306 \layout Standard
15307
15308 \backslash 
15309 /
15310 \end_inset 
15311
15312 -callee-saves See -
15313 \begin_inset ERT
15314 status Collapsed
15315
15316 \layout Standard
15317
15318 \backslash 
15319 /
15320 \end_inset 
15321
15322 -all-callee-saves
15323 \layout List
15324 \labelwidthstring 00.00.0000
15325
15326 -
15327 \begin_inset ERT
15328 status Collapsed
15329
15330 \layout Standard
15331
15332 \backslash 
15333 /
15334 \end_inset 
15335
15336 -all-callee-saves All function arguments are passed on stack by default.
15337  
15338 \emph on 
15339 There is no need to specify this in the command line.
15340 \layout List
15341 \labelwidthstring 00.00.0000
15342
15343 -
15344 \begin_inset ERT
15345 status Collapsed
15346
15347 \layout Standard
15348
15349 \backslash 
15350 /
15351 \end_inset 
15352
15353 -fommit-frame-pointer Frame pointer will be omitted when the function uses
15354  no local variables.
15355 \layout Subsection
15356
15357 Port Specific Options
15358 \begin_inset LatexCommand \index{Options PIC16}
15359
15360 \end_inset 
15361
15362
15363 \layout Standard
15364
15365 The port specific options appear after the global options in the sdcc --help
15366  output.
15367 \layout Subsubsection
15368
15369 General Options
15370 \layout Standard
15371
15372 General options enable certain port features and optimizations.
15373 \layout List
15374 \labelwidthstring 00.00.0000
15375
15376 -
15377 \begin_inset ERT
15378 status Collapsed
15379
15380 \layout Standard
15381
15382 \backslash 
15383 /
15384 \end_inset 
15385
15386 -stack-model=[model] Used in conjuction with the command above.
15387  Defines the stack model to be used, valid stack models are : 
15388 \begin_deeper 
15389 \layout List
15390 \labelwidthstring 00.00.0000
15391
15392
15393 \emph on 
15394 small
15395 \emph default 
15396  Selects small stack model.
15397  8 bit stack and frame pointers.
15398  Supports 256 bytes stack size.
15399 \layout List
15400 \labelwidthstring 00.00.0000
15401
15402
15403 \emph on 
15404 large
15405 \emph default 
15406  Selects large stack model.
15407  16 bit stack and frame pointers.
15408  Supports 65536 bytes stack size.
15409 \end_deeper 
15410 \layout List
15411 \labelwidthstring 00.00.0000
15412
15413 -
15414 \begin_inset ERT
15415 status Collapsed
15416
15417 \layout Standard
15418
15419 \backslash 
15420 /
15421 \end_inset 
15422
15423 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
15424  unitialized data variables with [kword].
15425  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
15426 \layout List
15427 \labelwidthstring 00.00.0000
15428
15429 -
15430 \begin_inset ERT
15431 status Collapsed
15432
15433 \layout Standard
15434
15435 \backslash 
15436 /
15437 \end_inset 
15438
15439 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
15440  Useful for bootloaders.
15441 \layout List
15442 \labelwidthstring 00.00.0000
15443
15444 -
15445 \begin_inset ERT
15446 status Collapsed
15447
15448 \layout Standard
15449
15450 \backslash 
15451 /
15452 \end_inset 
15453
15454 -asm= sets the full path and name of an external assembler to call.
15455 \layout List
15456 \labelwidthstring 00.00.0000
15457
15458 -
15459 \begin_inset ERT
15460 status Collapsed
15461
15462 \layout Standard
15463
15464 \backslash 
15465 /
15466 \end_inset 
15467
15468 -link= sets the full path and name of an external linker to call.
15469 \layout List
15470 \labelwidthstring 00.00.0000
15471
15472 -
15473 \begin_inset ERT
15474 status Collapsed
15475
15476 \layout Standard
15477
15478 \backslash 
15479 /
15480 \end_inset 
15481
15482 -mplab-comp MPLAB compatibility option.
15483  Currently only suppresses special gpasm directives.
15484 \layout Subsubsection
15485
15486 Optimization Options
15487 \layout Standard
15488
15489 -
15490 \begin_inset ERT
15491 status Collapsed
15492
15493 \layout Standard
15494
15495 \backslash 
15496 /
15497 \end_inset 
15498
15499 -optimize-goto Try to use (conditional) BRA instead of GOTO
15500 \layout List
15501 \labelwidthstring 00.00.0000
15502
15503 -
15504 \begin_inset ERT
15505 status Collapsed
15506
15507 \layout Standard
15508
15509 \backslash 
15510 /
15511 \end_inset 
15512
15513 -obanksel=nn Set optimization level for inserting BANKSELs.
15514 \newline 
15515
15516 \begin_deeper 
15517 \layout List
15518 \labelwidthstring 00.00.0000
15519
15520 0 is no optimization
15521 \layout List
15522 \labelwidthstring 00.00.0000
15523
15524 1 checks previous used register and if it is the same then does not emit
15525  BANKSEL, accounts only for labels.
15526 \layout List
15527 \labelwidthstring 00.00.0000
15528
15529 2 tries to check the location of (even different) symbols and removes BANKSELs
15530  if they are in the same bank.
15531  Important: This will only work properly if the linker script does not have
15532  sections across bank borders!
15533 \end_deeper 
15534 \layout Subsubsection
15535
15536 Linking Options
15537 \layout List
15538 \labelwidthstring 00.00.0000
15539
15540 -
15541 \begin_inset ERT
15542 status Collapsed
15543
15544 \layout Standard
15545
15546 \backslash 
15547 /
15548 \end_inset 
15549
15550 -nodefaultlibs do not link default libraries when linking
15551 \layout List
15552 \labelwidthstring 00.00.0000
15553
15554 -
15555 \begin_inset ERT
15556 status Collapsed
15557
15558 \layout Standard
15559
15560 \backslash 
15561 /
15562 \end_inset 
15563
15564 -use-crt= Use a custom run-time module instead of the defaults.
15565 \layout List
15566 \labelwidthstring 00.00.0000
15567
15568 -
15569 \begin_inset ERT
15570 status Collapsed
15571
15572 \layout Standard
15573
15574 \backslash 
15575 /
15576 \end_inset 
15577
15578 -no-crt Don't link the default run-time modules
15579 \layout Subsubsection
15580
15581 Debugging Options
15582 \layout Standard
15583
15584 Debugging options enable extra debugging information in the output files.
15585 \layout List
15586 \labelwidthstring 00.00.0000
15587
15588 -
15589 \begin_inset ERT
15590 status Collapsed
15591
15592 \layout Standard
15593
15594 \backslash 
15595 /
15596 \end_inset 
15597
15598 -debug-xtra Similar to -
15599 \begin_inset ERT
15600 status Collapsed
15601
15602 \layout Standard
15603
15604 \backslash 
15605 /
15606 \end_inset 
15607
15608 -debug
15609 \begin_inset LatexCommand \index{-\/-debug}
15610
15611 \end_inset 
15612
15613 , but dumps more information.
15614 \layout List
15615 \labelwidthstring 00.00.0000
15616
15617 -
15618 \begin_inset ERT
15619 status Collapsed
15620
15621 \layout Standard
15622
15623 \backslash 
15624 /
15625 \end_inset 
15626
15627 -debug-ralloc Force register allocator to dump <source>.d file with debugging
15628  information.
15629  <source> is the name of the file compiled.
15630 \layout List
15631 \labelwidthstring 00.00.0000
15632
15633 -
15634 \begin_inset ERT
15635 status Collapsed
15636
15637 \layout Standard
15638
15639 \backslash 
15640 /
15641 \end_inset 
15642
15643 -pcode-verbose Enable pcode debugging information in translation.
15644 \layout List
15645 \labelwidthstring 00.00.0000
15646
15647 -
15648 \begin_inset ERT
15649 status Collapsed
15650
15651 \layout Standard
15652
15653 \backslash 
15654 /
15655 \end_inset 
15656
15657 -denable-peeps Force the usage of peepholes.
15658  Use with care.
15659 \layout List
15660 \labelwidthstring 00.00.0000
15661
15662 -
15663 \begin_inset ERT
15664 status Collapsed
15665
15666 \layout Standard
15667
15668 \backslash 
15669 /
15670 \end_inset 
15671
15672 -gstack Trace push/pops for stack pointer overflow
15673 \layout List
15674 \labelwidthstring 00.00.0000
15675
15676 -
15677 \begin_inset ERT
15678 status Collapsed
15679
15680 \layout Standard
15681
15682 \backslash 
15683 /
15684 \end_inset 
15685
15686 -call-tree dump call tree in .calltree file
15687 \layout Subsection
15688
15689 Preprocessor Macros
15690 \layout Standard
15691
15692 PIC16 port defines the following preprocessor macros while translating a
15693  source.
15694 \layout Standard
15695 \align center 
15696
15697 \begin_inset  Tabular
15698 <lyxtabular version="3" rows="2" columns="2">
15699 <features>
15700 <column alignment="center" valignment="top" leftline="true" width="0">
15701 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15702 <row topline="true" bottomline="true">
15703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15704 \begin_inset Text
15705
15706 \layout Standard
15707
15708 Macro
15709 \end_inset 
15710 </cell>
15711 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15712 \begin_inset Text
15713
15714 \layout Standard
15715
15716 Description
15717 \end_inset 
15718 </cell>
15719 </row>
15720 <row topline="true" bottomline="true">
15721 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15722 \begin_inset Text
15723
15724 \layout Standard
15725
15726 pic18fxxxx
15727 \end_inset 
15728 </cell>
15729 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15730 \begin_inset Text
15731
15732 \layout Standard
15733
15734 MCU Identification.
15735  
15736 \emph on 
15737 xxxx
15738 \emph default 
15739  is the microcontrol identification number, i.e.
15740  452, 6620, etc
15741 \end_inset 
15742 </cell>
15743 </row>
15744 </lyxtabular>
15745
15746 \end_inset 
15747
15748
15749 \layout Subsection
15750
15751 Directories
15752 \layout Standard
15753
15754 PIC16
15755 \begin_inset LatexCommand \index{PIC16}
15756
15757 \end_inset 
15758
15759  port uses the following directories for searching header files and libraries.
15760 \layout Standard
15761 \align center 
15762
15763 \begin_inset  Tabular
15764 <lyxtabular version="3" rows="3" columns="4">
15765 <features>
15766 <column alignment="center" valignment="top" leftline="true" width="0">
15767 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15768 <column alignment="center" valignment="top" width="0">
15769 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15770 <row topline="true" bottomline="true">
15771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15772 \begin_inset Text
15773
15774 \layout Standard
15775
15776 Directory
15777 \end_inset 
15778 </cell>
15779 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15780 \begin_inset Text
15781
15782 \layout Standard
15783
15784 Description
15785 \end_inset 
15786 </cell>
15787 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15788 \begin_inset Text
15789
15790 \layout Standard
15791
15792 Target
15793 \end_inset 
15794 </cell>
15795 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15796 \begin_inset Text
15797
15798 \layout Standard
15799
15800 Command prefix
15801 \end_inset 
15802 </cell>
15803 </row>
15804 <row topline="true">
15805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15806 \begin_inset Text
15807
15808 \layout Standard
15809
15810 PREFIX/sdcc/include/pic16
15811 \end_inset 
15812 </cell>
15813 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15814 \begin_inset Text
15815
15816 \layout Standard
15817
15818 PIC16 specific headers
15819 \end_inset 
15820 </cell>
15821 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15822 \begin_inset Text
15823
15824 \layout Standard
15825
15826 Compiler
15827 \end_inset 
15828 </cell>
15829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15830 \begin_inset Text
15831
15832 \layout Standard
15833
15834 -I
15835 \end_inset 
15836 </cell>
15837 </row>
15838 <row topline="true" bottomline="true">
15839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15840 \begin_inset Text
15841
15842 \layout Standard
15843
15844 PREFIX/sdcc/lib/pic16
15845 \end_inset 
15846 </cell>
15847 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15848 \begin_inset Text
15849
15850 \layout Standard
15851
15852 PIC16 specific libraries
15853 \end_inset 
15854 </cell>
15855 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15856 \begin_inset Text
15857
15858 \layout Standard
15859
15860 Linker
15861 \end_inset 
15862 </cell>
15863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15864 \begin_inset Text
15865
15866 \layout Standard
15867
15868 -L
15869 \end_inset 
15870 </cell>
15871 </row>
15872 </lyxtabular>
15873
15874 \end_inset 
15875
15876
15877 \layout Subsection
15878
15879 Pragmas
15880 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
15881
15882 \end_inset 
15883
15884
15885 \layout Standard
15886
15887 PIC16 port currently supports the following pragmas:
15888 \layout List
15889 \labelwidthstring 00.00.0000
15890
15891 stack pragma stack forces the code generator to initialize the stack & frame
15892  pointers at a specific address.
15893  This is an adhoc solution for cases where no STACK directive is available
15894  in the linker script or gplink is not instructed to create a stack section.
15895 \newline 
15896 The stack pragma should be used only once in a project.
15897  Multiple pragmas may result in indeterminate behaviour of the program.
15898 \newline 
15899 The format is as follows:
15900 \layout LyX-Code
15901
15902 #pragma stack bottom_address [stack_size]
15903 \layout Standard
15904
15905
15906 \emph on 
15907 bottom_address
15908 \emph default 
15909  is the lower bound of the stack section.
15910  The stack pointer initially will point at address (bottom_address+stack_size-1).
15911 \layout LyX-Code
15912
15913 Example:
15914 \layout LyX-Code
15915
15916 \layout LyX-Code
15917
15918 /* initializes stack of 100 bytes at RAM address 0x200 */
15919 \layout LyX-Code
15920
15921 #pragma stack 0x200 100
15922 \layout List
15923 \labelwidthstring 00.00.0000
15924
15925 wparam use the WREG to pass one byte of the first function argument.
15926  This improves speed but you may not use this for functions with arguments
15927  that are called via function pointers, otherwise one byte of the first
15928  parameter will get lost.
15929  This pragma should be placed in the header file to propagate the calling
15930  convention to all callers.
15931 \layout LyX-Code
15932
15933 #pragma wparam function1[, function2, ...]
15934 \layout LyX-Code
15935
15936 \layout LyX-Code
15937
15938 Example:
15939 \layout LyX-Code
15940
15941 \layout LyX-Code
15942
15943 /* pass one byte via stack and one byte via WREG */
15944 \layout LyX-Code
15945
15946 #pragma wparam foo
15947 \layout LyX-Code
15948
15949 void foo(int x);
15950 \layout Standard
15951
15952 The same effect with 
15953 \emph on 
15954 wparam pragma
15955 \emph default 
15956  can be achieved with the function attribute 
15957 \emph on 
15958 wparam
15959 \emph default 
15960 .
15961  Usage:
15962 \layout LyX-Code
15963
15964 void func_wparam(int a) wparam
15965 \layout LyX-Code
15966
15967 {
15968 \layout LyX-Code
15969
15970 ...
15971 \layout LyX-Code
15972
15973 }
15974 \layout Standard
15975
15976 Limitations of wparam pragma apply for wparam function attribute, too.
15977 \layout List
15978 \labelwidthstring 00.00.0000
15979
15980 code place a function symbol at static FLASH address
15981 \layout LyX-Code
15982
15983 Example:
15984 \layout LyX-Code
15985
15986 \layout LyX-Code
15987
15988 /* place function test_func at 0x4000 */
15989 \layout LyX-Code
15990
15991 #pragma code test_func 0x4000
15992 \layout LyX-Code
15993
15994 \layout List
15995 \labelwidthstring 00.00.0000
15996
15997 library instructs the linker to use a library module.
15998 \newline 
15999 Usage:
16000 \layout LyX-Code
16001
16002 #pragma library module_name
16003 \layout Standard
16004
16005
16006 \emph on 
16007 module_name
16008 \emph default 
16009  can be any library or object file (including its path).
16010  Note that there are four reserved keywords which have special meaning.
16011  These are:
16012 \layout Standard
16013 \align center 
16014
16015 \begin_inset  Tabular
16016 <lyxtabular version="3" rows="6" columns="3">
16017 <features>
16018 <column alignment="center" valignment="top" leftline="true" width="0">
16019 <column alignment="block" valignment="top" leftline="true" width="20page%">
16020 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
16021 <row topline="true" bottomline="true">
16022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16023 \begin_inset Text
16024
16025 \layout Standard
16026
16027 Keyword
16028 \end_inset 
16029 </cell>
16030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16031 \begin_inset Text
16032
16033 \layout Standard
16034
16035 Description
16036 \end_inset 
16037 </cell>
16038 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16039 \begin_inset Text
16040
16041 \layout Standard
16042
16043 Module to link
16044 \end_inset 
16045 </cell>
16046 </row>
16047 <row topline="true">
16048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16049 \begin_inset Text
16050
16051 \layout Standard
16052
16053
16054 \series bold 
16055 ignore
16056 \end_inset 
16057 </cell>
16058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16059 \begin_inset Text
16060
16061 \layout Standard
16062
16063 ignore all library pragmas
16064 \end_inset 
16065 </cell>
16066 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16067 \begin_inset Text
16068
16069 \layout Standard
16070
16071
16072 \emph on 
16073 (none)
16074 \end_inset 
16075 </cell>
16076 </row>
16077 <row topline="true">
16078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16079 \begin_inset Text
16080
16081 \layout Standard
16082
16083
16084 \series bold 
16085 c
16086 \end_inset 
16087 </cell>
16088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16089 \begin_inset Text
16090
16091 \layout Standard
16092
16093 link the C library
16094 \end_inset 
16095 </cell>
16096 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16097 \begin_inset Text
16098
16099 \layout Standard
16100
16101
16102 \emph on 
16103 libc18f
16104 \emph default 
16105 .lib
16106 \end_inset 
16107 </cell>
16108 </row>
16109 <row topline="true">
16110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16111 \begin_inset Text
16112
16113 \layout Standard
16114
16115
16116 \series bold 
16117 math
16118 \end_inset 
16119 </cell>
16120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16121 \begin_inset Text
16122
16123 \layout Standard
16124
16125 link the Math libarary
16126 \end_inset 
16127 </cell>
16128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16129 \begin_inset Text
16130
16131 \layout Standard
16132
16133
16134 \emph on 
16135 libm18f
16136 \emph default 
16137 .lib
16138 \end_inset 
16139 </cell>
16140 </row>
16141 <row topline="true">
16142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16143 \begin_inset Text
16144
16145 \layout Standard
16146
16147
16148 \series bold 
16149 io
16150 \end_inset 
16151 </cell>
16152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16153 \begin_inset Text
16154
16155 \layout Standard
16156
16157 link the I/O library
16158 \end_inset 
16159 </cell>
16160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16161 \begin_inset Text
16162
16163 \layout Standard
16164
16165
16166 \emph on 
16167 libio18f*
16168 \emph default 
16169 .lib
16170 \end_inset 
16171 </cell>
16172 </row>
16173 <row topline="true" bottomline="true">
16174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16175 \begin_inset Text
16176
16177 \layout Standard
16178
16179
16180 \series bold 
16181 debug
16182 \end_inset 
16183 </cell>
16184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16185 \begin_inset Text
16186
16187 \layout Standard
16188
16189 link the debug library
16190 \end_inset 
16191 </cell>
16192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16193 \begin_inset Text
16194
16195 \layout Standard
16196
16197
16198 \emph on 
16199 libdebug
16200 \emph default 
16201 .lib
16202 \end_inset 
16203 </cell>
16204 </row>
16205 </lyxtabular>
16206
16207 \end_inset 
16208
16209
16210 \newline 
16211 * is the device number, i.e.
16212  452 for PIC18F452 MCU.
16213 \layout Standard
16214
16215 This feature allows for linking with specific libraries withoug having to
16216  explicit name them in the command line.
16217  Note that the 
16218 \noun on 
16219 ignore
16220 \noun default 
16221  keyword will reject all modules specified by the library pragma.
16222 \layout List
16223 \labelwidthstring 00.00.0000
16224
16225 udata pragma udata instructs the compiler to emit code so that linker will
16226  place a variable at a specific memory bank
16227 \layout LyX-Code
16228
16229 Example:
16230 \layout LyX-Code
16231
16232 \layout LyX-Code
16233
16234 /* places variable foo at bank2 */
16235 \layout LyX-Code
16236
16237 #pragma udata bank2 foo
16238 \layout LyX-Code
16239
16240 char foo;
16241 \layout Standard
16242
16243 In order for this pragma to work extra SECTION directives should be added
16244  in the .lkr script.
16245  In the following example a sample .lkr file is shown:
16246 \layout LyX-Code
16247
16248 \layout LyX-Code
16249
16250 // Sample linker script for the PIC18F452 processor
16251 \layout LyX-Code
16252
16253 LIBPATH .
16254 \layout LyX-Code
16255
16256 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
16257 \layout LyX-Code
16258
16259 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
16260 \layout LyX-Code
16261
16262 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
16263 \layout LyX-Code
16264
16265 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
16266 \layout LyX-Code
16267
16268 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
16269 \layout LyX-Code
16270
16271 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
16272 \layout LyX-Code
16273
16274 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
16275 \layout LyX-Code
16276
16277 \layout LyX-Code
16278
16279 DATABANK   NAME=gpr0       START=0x80           END=0xFF
16280 \layout LyX-Code
16281
16282 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
16283 \layout LyX-Code
16284
16285 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
16286 \layout LyX-Code
16287
16288 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
16289 \layout LyX-Code
16290
16291 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
16292 \layout LyX-Code
16293
16294 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
16295 \layout LyX-Code
16296
16297 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
16298 \layout LyX-Code
16299
16300 \layout LyX-Code
16301
16302 SECTION    NAME=CONFIG     ROM=config
16303 \layout LyX-Code
16304
16305 \layout LyX-Code
16306
16307 SECTION    NAME=bank0      RAM=gpr0       # these SECTION directives
16308 \layout LyX-Code
16309
16310 SECTION    NAME=bank1      RAM=gpr1       # should be added to link
16311 \layout LyX-Code
16312
16313 SECTION    NAME=bank2      RAM=gpr2       # section name 'bank?' with
16314 \layout LyX-Code
16315
16316 SECTION    NAME=bank3      RAM=gpr3       # a specific DATABANK name
16317 \layout LyX-Code
16318
16319 SECTION    NAME=bank4      RAM=gpr4
16320 \layout LyX-Code
16321
16322 SECTION    NAME=bank5      RAM=gpr5
16323 \layout Standard
16324
16325 The linker will recognise the section name set in the pragma statement and
16326  will position the variable at the memory bank set with the RAM field at
16327  the SECTION line in the linker script file.
16328 \layout Subsection
16329
16330 Header Files
16331 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
16332
16333 \end_inset 
16334
16335
16336 \layout Standard
16337
16338 There is one main header file that can be included to the source files using
16339  the pic16 port.
16340  That file is the 
16341 \series bold 
16342 pic18fregs.h
16343 \series default 
16344 .
16345  This header file contains the definitions for the processor special registers,
16346  so it is necessary if the source accesses them.
16347  It can be included by adding the following line in the beginning of the
16348  file:
16349 \layout LyX-Code
16350
16351 #include <pic18fregs.h>
16352 \layout Standard
16353
16354 The specific microcontroller is selected within the pic18fregs.h automatically,
16355  so the same source can be used with a variety of devices.
16356 \layout Subsection
16357
16358 Libraries
16359 \layout Standard
16360
16361 The libraries that PIC16
16362 \begin_inset LatexCommand \index{PIC16}
16363
16364 \end_inset 
16365
16366  port depends on are the microcontroller device libraries which contain
16367  the symbol definitions for the microcontroller special function registers.
16368  These libraries have the format pic18fxxxx.lib, where 
16369 \emph on 
16370 xxxx
16371 \emph default 
16372  is the microcontroller identification number.
16373  The specific library is selected automatically by the compiler at link
16374  stage according to the selected device.
16375 \layout Standard
16376
16377 Libraries are created with gplib which is part of the gputils package 
16378 \begin_inset LatexCommand \url{http://gputils.sourceforge.net}
16379
16380 \end_inset 
16381
16382 .
16383 \layout Subsubsection
16384
16385 Building the libraries
16386 \layout Standard
16387
16388 Before using SDCC/pic16 there are some libraries that need to be compiled.
16389  This process is not done automatically by SDCC since not all users use
16390  SDCC for pic16 projects.
16391  So each user should compile the libraries separately.
16392 \layout Standard
16393
16394 The steps to compile the pic16 libraries under Linux are:
16395 \layout LyX-Code
16396
16397 cd device/lib/pic16
16398 \layout LyX-Code
16399
16400 ./configure
16401 \layout LyX-Code
16402
16403 make
16404 \layout LyX-Code
16405
16406 cd ..
16407 \layout LyX-Code
16408
16409 make model-pic16
16410 \layout LyX-Code
16411
16412 su -c 'make install'     # install the libraries, you need the root password
16413 \layout Standard
16414
16415 If you need to install the headers to, do:
16416 \layout LyX-Code
16417
16418 cd device/include
16419 \layout LyX-Code
16420
16421 su -c 'make install'     # install the headers, you need the root password
16422 \layout Standard
16423
16424 There exist a special target to build the I/O libraries.
16425  This target is not automatically build because it will build the I/O library
16426  for 
16427 \emph on 
16428 every
16429 \emph default 
16430  supported device.
16431  This way building will take quite a lot of time.
16432  Users are advised to edit the device/lib/pic16/pics.build file and then
16433  execute:
16434 \layout LyX-Code
16435
16436 make lib-io
16437 \layout Subsection
16438
16439 Memory Models
16440 \layout Standard
16441
16442 The following memory models are supported by the PIC16 port:
16443 \layout Itemize
16444
16445 small model
16446 \layout Itemize
16447
16448 large model
16449 \layout Standard
16450
16451 Memory model affects the default size of pointers within the source.
16452  The sizes are shown in the next table:
16453 \layout Standard
16454 \align center 
16455
16456 \begin_inset  Tabular
16457 <lyxtabular version="3" rows="3" columns="3">
16458 <features>
16459 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
16460 <column alignment="center" valignment="top" leftline="true" width="0">
16461 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
16462 <row topline="true" bottomline="true">
16463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16464 \begin_inset Text
16465
16466 \layout Standard
16467
16468 Pointer sizes according to memory model
16469 \end_inset 
16470 </cell>
16471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16472 \begin_inset Text
16473
16474 \layout Standard
16475
16476 small model
16477 \end_inset 
16478 </cell>
16479 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16480 \begin_inset Text
16481
16482 \layout Standard
16483
16484 large model
16485 \end_inset 
16486 </cell>
16487 </row>
16488 <row topline="true" bottomline="true">
16489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16490 \begin_inset Text
16491
16492 \layout Standard
16493
16494 code pointers
16495 \end_inset 
16496 </cell>
16497 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16498 \begin_inset Text
16499
16500 \layout Standard
16501
16502 16-bits
16503 \end_inset 
16504 </cell>
16505 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16506 \begin_inset Text
16507
16508 \layout Standard
16509
16510 24-bits
16511 \end_inset 
16512 </cell>
16513 </row>
16514 <row topline="true" bottomline="true">
16515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16516 \begin_inset Text
16517
16518 \layout Standard
16519
16520 data pointers
16521 \end_inset 
16522 </cell>
16523 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
16524 \begin_inset Text
16525
16526 \layout Standard
16527
16528 16-bits
16529 \end_inset 
16530 </cell>
16531 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16532 \begin_inset Text
16533
16534 \layout Standard
16535
16536 16-bits
16537 \end_inset 
16538 </cell>
16539 </row>
16540 </lyxtabular>
16541
16542 \end_inset 
16543
16544
16545 \layout Standard
16546
16547 It is advisable that all sources within a project are compiled with the
16548  same memory model.
16549  If one wants to override the default memory model, this can be done by
16550  declaring a pointer as 
16551 \series bold 
16552 far
16553 \series default 
16554  or 
16555 \series bold 
16556 near
16557 \series default 
16558 .
16559  Far selects large memory model's pointers, while near selects small memory
16560  model's pointers.
16561 \layout Standard
16562
16563 The standard device libraries (see 
16564 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
16565
16566 \end_inset 
16567
16568 ) contain no reference to pointers, so they can be used with both memory
16569  models.
16570 \layout Subsection
16571
16572 Stack
16573 \layout Standard
16574
16575 The stack implementation for the PIC16 port uses two indirect registers,
16576  FSR1 and FSR2.
16577 \layout List
16578 \labelwidthstring 00.00.0000
16579
16580 FSR1 is assigned as stack pointer
16581 \layout List
16582 \labelwidthstring 00.00.0000
16583
16584 FSR2 is assigned as frame pointer
16585 \layout Standard
16586
16587 The following stack models are supported by the PIC16 port
16588 \layout Itemize
16589
16590
16591 \noun on 
16592 small
16593 \noun default 
16594  model
16595 \layout Itemize
16596
16597
16598 \noun on 
16599 large
16600 \noun default 
16601  model
16602 \layout Standard
16603
16604
16605 \noun on 
16606 Small
16607 \noun default 
16608  model means that only the FSRxL byte is used to access stack and frame,
16609  while 
16610 \emph on 
16611 \noun on 
16612 large
16613 \emph default 
16614 \noun default 
16615  uses both FSRxL and FSRxH registers.
16616  The following table shows the stack/frame pointers sizes according to stack
16617  model and the maximum space they can address:
16618 \layout Standard
16619 \align center 
16620
16621 \begin_inset  Tabular
16622 <lyxtabular version="3" rows="3" columns="3">
16623 <features>
16624 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
16625 <column alignment="center" valignment="top" leftline="true" width="0">
16626 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
16627 <row topline="true" bottomline="true">
16628 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16629 \begin_inset Text
16630
16631 \layout Standard
16632
16633 Stack & Frame pointer sizes according to stack model
16634 \end_inset 
16635 </cell>
16636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16637 \begin_inset Text
16638
16639 \layout Standard
16640
16641 small
16642 \end_inset 
16643 </cell>
16644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16645 \begin_inset Text
16646
16647 \layout Standard
16648
16649 large
16650 \end_inset 
16651 </cell>
16652 </row>
16653 <row topline="true">
16654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16655 \begin_inset Text
16656
16657 \layout Standard
16658
16659 Stack pointer FSR1
16660 \end_inset 
16661 </cell>
16662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16663 \begin_inset Text
16664
16665 \layout Standard
16666
16667 8-bits
16668 \end_inset 
16669 </cell>
16670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16671 \begin_inset Text
16672
16673 \layout Standard
16674
16675 16-bits
16676 \end_inset 
16677 </cell>
16678 </row>
16679 <row topline="true" bottomline="true">
16680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16681 \begin_inset Text
16682
16683 \layout Standard
16684
16685 Frame pointer FSR2
16686 \end_inset 
16687 </cell>
16688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16689 \begin_inset Text
16690
16691 \layout Standard
16692
16693 8-bits
16694 \end_inset 
16695 </cell>
16696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16697 \begin_inset Text
16698
16699 \layout Standard
16700
16701 16-bits
16702 \end_inset 
16703 </cell>
16704 </row>
16705 </lyxtabular>
16706
16707 \end_inset 
16708
16709
16710 \layout Standard
16711
16712
16713 \noun on 
16714 Large 
16715 \noun default 
16716 stack model is currently not working properly throughout the code generator.
16717  So its use is not advised.
16718  Also there are some other points that need special care:
16719 \newline 
16720
16721 \layout Enumerate
16722
16723 Do not create stack sections with size more than one physical bank (that
16724  is 256 bytes)
16725 \layout Enumerate
16726
16727 Stack sections should no cross physical bank limits (i.e.
16728  #pragma stack 0x50 0x100)
16729 \layout Standard
16730
16731 These limitations are caused by the fact that only FSRxL is modified when
16732  using SMALL stack model, so no more than 256 bytes of stack can be used.
16733  This problem will disappear after LARGE model is fully implemented.
16734 \layout Subsection
16735
16736 Function return values
16737 \layout Standard
16738
16739 Return values from functions are placed to the appropriate registers following
16740  a modified Microchip policy optimized for SDCC.
16741  The following table shows these registers:
16742 \layout Standard
16743 \align center 
16744
16745 \begin_inset  Tabular
16746 <lyxtabular version="3" rows="6" columns="2">
16747 <features>
16748 <column alignment="center" valignment="top" leftline="true" width="0">
16749 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
16750 <row topline="true" bottomline="true">
16751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16752 \begin_inset Text
16753
16754 \layout Standard
16755
16756 size
16757 \end_inset 
16758 </cell>
16759 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16760 \begin_inset Text
16761
16762 \layout Standard
16763
16764 destination register
16765 \end_inset 
16766 </cell>
16767 </row>
16768 <row topline="true">
16769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16770 \begin_inset Text
16771
16772 \layout Standard
16773
16774 8 bits
16775 \end_inset 
16776 </cell>
16777 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16778 \begin_inset Text
16779
16780 \layout Standard
16781
16782 WREG
16783 \end_inset 
16784 </cell>
16785 </row>
16786 <row topline="true">
16787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16788 \begin_inset Text
16789
16790 \layout Standard
16791
16792 16 bits
16793 \end_inset 
16794 </cell>
16795 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16796 \begin_inset Text
16797
16798 \layout Standard
16799
16800 PRODL:WREG
16801 \end_inset 
16802 </cell>
16803 </row>
16804 <row topline="true">
16805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16806 \begin_inset Text
16807
16808 \layout Standard
16809
16810 24 bits
16811 \end_inset 
16812 </cell>
16813 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16814 \begin_inset Text
16815
16816 \layout Standard
16817
16818 PRODH:PRODL:WREG
16819 \end_inset 
16820 </cell>
16821 </row>
16822 <row topline="true">
16823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16824 \begin_inset Text
16825
16826 \layout Standard
16827
16828 32 bits
16829 \end_inset 
16830 </cell>
16831 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16832 \begin_inset Text
16833
16834 \layout Standard
16835
16836 FSR0L:PRODH:PRODL:WREG
16837 \end_inset 
16838 </cell>
16839 </row>
16840 <row topline="true" bottomline="true">
16841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16842 \begin_inset Text
16843
16844 \layout Standard
16845
16846 >32 bits
16847 \end_inset 
16848 </cell>
16849 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16850 \begin_inset Text
16851
16852 \layout Standard
16853
16854 on stack, FSR0 points to the beginning
16855 \end_inset 
16856 </cell>
16857 </row>
16858 </lyxtabular>
16859
16860 \end_inset 
16861
16862
16863 \layout Subsection
16864
16865 Interrupts
16866 \layout Standard
16867
16868 An interrupt servive routine (ISR) is declared using the 
16869 \emph on 
16870 interrupt
16871 \emph default 
16872  keyword.
16873 \layout LyX-Code
16874
16875 void isr(void) interrupt 
16876 \emph on 
16877 n
16878 \layout LyX-Code
16879
16880 {
16881 \layout LyX-Code
16882
16883 ...
16884 \layout LyX-Code
16885
16886 }
16887 \layout Standard
16888
16889
16890 \emph on 
16891 n
16892 \emph default 
16893  is the interrupt number, which for PIC18F devices can be:
16894 \layout Standard
16895 \align center 
16896
16897 \begin_inset  Tabular
16898 <lyxtabular version="3" rows="4" columns="3">
16899 <features>
16900 <column alignment="center" valignment="top" leftline="true" width="0">
16901 <column alignment="center" valignment="top" leftline="true" width="0">
16902 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
16903 <row topline="true" bottomline="true">
16904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16905 \begin_inset Text
16906
16907 \layout Standard
16908
16909
16910 \emph on 
16911 n
16912 \end_inset 
16913 </cell>
16914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16915 \begin_inset Text
16916
16917 \layout Standard
16918
16919 Interrupt Vector
16920 \end_inset 
16921 </cell>
16922 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16923 \begin_inset Text
16924
16925 \layout Standard
16926
16927 Interrupt Vector Address
16928 \end_inset 
16929 </cell>
16930 </row>
16931 <row topline="true">
16932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16933 \begin_inset Text
16934
16935 \layout Standard
16936
16937 0
16938 \end_inset 
16939 </cell>
16940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16941 \begin_inset Text
16942
16943 \layout Standard
16944
16945 RESET vector
16946 \end_inset 
16947 </cell>
16948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16949 \begin_inset Text
16950
16951 \layout Standard
16952
16953 0x000000
16954 \end_inset 
16955 </cell>
16956 </row>
16957 <row topline="true">
16958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16959 \begin_inset Text
16960
16961 \layout Standard
16962
16963
16964 \family roman 
16965 \series medium 
16966 \shape up 
16967 \size normal 
16968 \emph off 
16969 \bar no 
16970 \noun off 
16971 \color none
16972 1
16973 \end_inset 
16974 </cell>
16975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16976 \begin_inset Text
16977
16978 \layout Standard
16979
16980
16981 \family roman 
16982 \series medium 
16983 \shape up 
16984 \size normal 
16985 \emph off 
16986 \bar no 
16987 \noun off 
16988 \color none
16989 HIGH priority interrupts
16990 \end_inset 
16991 </cell>
16992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16993 \begin_inset Text
16994
16995 \layout Standard
16996
16997 0x000008
16998 \end_inset 
16999 </cell>
17000 </row>
17001 <row topline="true" bottomline="true">
17002 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17003 \begin_inset Text
17004
17005 \layout Standard
17006
17007 2
17008 \end_inset 
17009 </cell>
17010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17011 \begin_inset Text
17012
17013 \layout Standard
17014
17015 LOW priority interrupts
17016 \end_inset 
17017 </cell>
17018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17019 \begin_inset Text
17020
17021 \layout Standard
17022
17023 0x000018
17024 \end_inset 
17025 </cell>
17026 </row>
17027 </lyxtabular>
17028
17029 \end_inset 
17030
17031
17032 \layout Standard
17033
17034 When generating assembly code for ISR the code generator places a 
17035 \noun on 
17036 goto 
17037 \noun default 
17038 instruction at the 
17039 \emph on 
17040 Interrupt Vector Address
17041 \emph default 
17042  which points at the genetated ISR.
17043 \layout Standard
17044
17045
17046 \emph on 
17047 n
17048 \emph default 
17049  is possible to be omitted.
17050  This way a function is generated similar to an ISR, but it is not assigned
17051  to any interrupt.
17052 \layout Standard
17053
17054 When entering an interrupt, currently the PIC16
17055 \begin_inset LatexCommand \index{PIC16}
17056
17057 \end_inset 
17058
17059  port automatically saves the following registers:
17060 \layout Itemize
17061
17062 WREG
17063 \layout Itemize
17064
17065 STATUS
17066 \layout Itemize
17067
17068 BSR
17069 \layout Itemize
17070
17071 PROD (PRODL and PRODH)
17072 \layout Itemize
17073
17074 FSR0 (FSR0L and FSR0H)
17075 \layout Standard
17076
17077 These registers are restored upon return from the interrupt routine.
17078 \layout Subsubsection
17079
17080 Using Shadow Registers
17081 \layout Standard
17082
17083 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
17084  core shadow registers which hold the values of WREG, STATUS and BSR registers.
17085  This can be done by adding the keyword 
17086 \emph on 
17087 shadowregs
17088 \emph default 
17089  before the 
17090 \emph on 
17091 interrupt
17092 \emph default 
17093  keyword in the function's header.
17094 \layout LyX-Code
17095
17096 void isr_shadow(void) shadowregs interrupt 1
17097 \layout LyX-Code
17098
17099 {
17100 \layout LyX-Code
17101
17102 ...
17103 \layout LyX-Code
17104
17105 }
17106 \layout Standard
17107
17108
17109 \emph on 
17110 shadowregs
17111 \emph default 
17112  instructs the code generator not to store/restore WREG, STATUS, BSR when
17113  entering/exiting the ISR.
17114 \layout Standard
17115
17116
17117 \begin_inset Foot
17118 collapsed false
17119
17120 \layout Standard
17121
17122 NOTE that when the _naked attribute is specified for an interrupt routine,
17123  then NO registers are stored or restored.
17124 \end_inset 
17125
17126 .
17127 \layout Chapter
17128
17129 Debugging with SDCDB
17130 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
17131
17132 \end_inset 
17133
17134
17135 \begin_inset LatexCommand \index{sdcdb (debugger)}
17136
17137 \end_inset 
17138
17139  
17140 \layout Standard
17141
17142 SDCC is distributed with a source level debugger
17143 \begin_inset LatexCommand \index{Debugger}
17144
17145 \end_inset 
17146
17147 .
17148  The debugger uses a command line interface, the command repertoire of the
17149  debugger has been kept as close to gdb
17150 \begin_inset LatexCommand \index{gdb}
17151
17152 \end_inset 
17153
17154  (the GNU debugger) as possible.
17155  The configuration and build process is part of the standard compiler installati
17156 on, which also builds and installs the debugger in the target directory
17157  specified during configuration.
17158  The debugger allows you debug BOTH at the C source and at the ASM source
17159  level.
17160  Sdcdb is available on Unix platforms only.
17161 \layout Section
17162
17163 Compiling for Debugging
17164 \layout Standard
17165
17166 The -
17167 \begin_inset ERT
17168 status Collapsed
17169
17170 \layout Standard
17171
17172 \backslash 
17173 /
17174 \end_inset 
17175
17176 -debug
17177 \begin_inset LatexCommand \index{-\/-debug}
17178
17179 \end_inset 
17180
17181  option must be specified for all files for which debug information is to
17182  be generated.
17183  The complier generates a .adb file for each of these files.
17184  The linker creates the .cdb
17185 \begin_inset LatexCommand \index{<file>.cdb}
17186
17187 \end_inset 
17188
17189  file from the .adb
17190 \begin_inset LatexCommand \index{<file>.adb}
17191
17192 \end_inset 
17193
17194  files and the address information.
17195  This .cdb is used by the debugger.
17196 \layout Section
17197
17198 How the Debugger Works
17199 \layout Standard
17200
17201 When the -
17202 \begin_inset ERT
17203 status Collapsed
17204
17205 \layout Standard
17206
17207 \backslash 
17208 /
17209 \end_inset 
17210
17211 -debug option is specified the compiler generates extra symbol information
17212  some of which are put into the assembler source and some are put into the
17213  .adb file.
17214   Then the linker creates the .cdb file from the individual .adb files with
17215  the address information for the symbols.
17216  The debugger reads the symbolic information generated by the compiler &
17217  the address information generated by the linker.
17218  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
17219  execution is controlled by the debugger.
17220  When a command is issued for the debugger, it translates it into appropriate
17221  commands for the simulator.
17222 \layout Section
17223
17224 Starting the Debugger
17225 \layout Standard
17226
17227 The debugger can be started using the following command line.
17228  (Assume the file you are debugging has the file name foo).
17229 \newline 
17230
17231 \newline 
17232
17233 \family sans 
17234 \series bold 
17235 sdcdb foo
17236 \newline 
17237
17238 \family default 
17239 \series default 
17240
17241 \newline 
17242 The debugger will look for the following files.
17243 \layout Itemize
17244
17245 foo.c - the source file.
17246 \layout Itemize
17247
17248 foo.cdb - the debugger symbol information file.
17249 \layout Itemize
17250
17251 foo.ihx - the Intel hex format
17252 \begin_inset LatexCommand \index{Intel hex format}
17253
17254 \end_inset 
17255
17256  object file.
17257 \layout Section
17258
17259 Command Line Options.
17260 \layout Itemize
17261
17262 -
17263 \begin_inset ERT
17264 status Collapsed
17265
17266 \layout Standard
17267
17268 \backslash 
17269 /
17270 \end_inset 
17271
17272 -directory=<source file directory> this option can used to specify the directory
17273  search list.
17274  The debugger will look into the directory list specified for source, cdb
17275  & ihx files.
17276  The items in the directory list must be separated by ':', e.g.
17277  if the source files can be in the directories /home/src1 and /home/src2,
17278  the -
17279 \begin_inset ERT
17280 status Collapsed
17281
17282 \layout Standard
17283
17284 \backslash 
17285 /
17286 \end_inset 
17287
17288 -directory option should be -
17289 \begin_inset ERT
17290 status Collapsed
17291
17292 \layout Standard
17293
17294 \backslash 
17295 /
17296 \end_inset 
17297
17298 -directory=/home/src1:/home/src2.
17299  Note there can be no spaces in the option.
17300  
17301 \layout Itemize
17302
17303 -cd <directory> - change to the <directory>.
17304 \layout Itemize
17305
17306 -fullname - used by GUI front ends.
17307 \layout Itemize
17308
17309 -cpu <cpu-type> - this argument is passed to the simulator please see the
17310  simulator docs for details.
17311 \layout Itemize
17312
17313 -X <Clock frequency > this options is passed to the simulator please see
17314  the simulator docs for details.
17315 \layout Itemize
17316
17317 -s <serial port file> passed to simulator see the simulator docs for details.
17318 \layout Itemize
17319
17320 -S <serial in,out> passed to simulator see the simulator docs for details.
17321 \layout Itemize
17322
17323 -k <port number> passed to simulator see the simulator docs for details.
17324 \layout Section
17325
17326 Debugger Commands.
17327 \layout Standard
17328
17329 As mentioned earlier the command interface for the debugger has been deliberatel
17330 y kept as close the GNU debugger gdb, as possible.
17331  This will help the integration with existing graphical user interfaces
17332  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
17333  If you use a graphical user interface for the debugger you can skip the
17334  next sections.
17335 \layout Subsubsection*
17336
17337 break [line | file:line | function | file:function]
17338 \layout Standard
17339
17340 Set breakpoint at specified line or function:
17341 \newline 
17342
17343 \newline 
17344
17345 \family sans 
17346 \series bold 
17347 sdcdb>break 100 
17348 \newline 
17349 sdcdb>break foo.c:100
17350 \newline 
17351 sdcdb>break funcfoo
17352 \newline 
17353 sdcdb>break foo.c:funcfoo
17354 \layout Subsubsection*
17355
17356 clear [line | file:line | function | file:function ]
17357 \layout Standard
17358
17359 Clear breakpoint at specified line or function:
17360 \newline 
17361
17362 \newline 
17363
17364 \family sans 
17365 \series bold 
17366 sdcdb>clear 100
17367 \newline 
17368 sdcdb>clear foo.c:100
17369 \newline 
17370 sdcdb>clear funcfoo
17371 \newline 
17372 sdcdb>clear foo.c:funcfoo
17373 \layout Subsubsection*
17374
17375 continue
17376 \layout Standard
17377
17378 Continue program being debugged, after breakpoint.
17379 \layout Subsubsection*
17380
17381 finish
17382 \layout Standard
17383
17384 Execute till the end of the current function.
17385 \layout Subsubsection*
17386
17387 delete [n]
17388 \layout Standard
17389
17390 Delete breakpoint number 'n'.
17391  If used without any option clear ALL user defined break points.
17392 \layout Subsubsection*
17393
17394 info [break | stack | frame | registers ]
17395 \layout Itemize
17396
17397 info break - list all breakpoints
17398 \layout Itemize
17399
17400 info stack - show the function call stack.
17401 \layout Itemize
17402
17403 info frame - show information about the current execution frame.
17404 \layout Itemize
17405
17406 info registers - show content of all registers.
17407 \layout Subsubsection*
17408
17409 step
17410 \layout Standard
17411
17412 Step program until it reaches a different source line.
17413  Note: pressing <return> repeats the last command.
17414 \layout Subsubsection*
17415
17416 next
17417 \layout Standard
17418
17419 Step program, proceeding through subroutine calls.
17420 \layout Subsubsection*
17421
17422 run
17423 \layout Standard
17424
17425 Start debugged program.
17426 \layout Subsubsection*
17427
17428 ptype variable 
17429 \layout Standard
17430
17431 Print type information of the variable.
17432 \layout Subsubsection*
17433
17434 print variable
17435 \layout Standard
17436
17437 print value of variable.
17438 \layout Subsubsection*
17439
17440 file filename
17441 \layout Standard
17442
17443 load the given file name.
17444  Note this is an alternate method of loading file for debugging.
17445 \layout Subsubsection*
17446
17447 frame
17448 \layout Standard
17449
17450 print information about current frame.
17451 \layout Subsubsection*
17452
17453 set srcmode
17454 \layout Standard
17455
17456 Toggle between C source & assembly source.
17457 \layout Subsubsection*
17458
17459 ! simulator command
17460 \layout Standard
17461
17462 Send the string following '!' to the simulator, the simulator response is
17463  displayed.
17464  Note the debugger does not interpret the command being sent to the simulator,
17465  so if a command like 'go' is sent the debugger can loose its execution
17466  context and may display incorrect values.
17467 \layout Subsubsection*
17468
17469 quit
17470 \layout Standard
17471
17472 "Watch me now.
17473  Iam going Down.
17474  My name is Bobby Brown"
17475 \layout Section
17476
17477 Interfacing with XEmacs
17478 \begin_inset LatexCommand \index{XEmacs}
17479
17480 \end_inset 
17481
17482
17483 \begin_inset LatexCommand \index{Emacs}
17484
17485 \end_inset 
17486
17487 .
17488 \layout Standard
17489
17490 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
17491  sdcdb.el and sdcdbsrc.el.
17492  These two files can be found in the $(prefix)/bin directory after the installat
17493 ion is complete.
17494  These files need to be loaded into XEmacs for the interface to work.
17495  This can be done at XEmacs startup time by inserting the following into
17496  your '.xemacs' file (which can be found in your HOME directory): 
17497 \newline 
17498
17499 \newline 
17500
17501 \family typewriter 
17502 (load-file sdcdbsrc.el) 
17503 \family default 
17504
17505 \newline 
17506
17507 \newline 
17508 .xemacs is a lisp file so the () around the command is REQUIRED.
17509  The files can also be loaded dynamically while XEmacs is running, set the
17510  environment variable 'EMACSLOADPATH' to the installation bin directory
17511  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
17512  To start the interface enter the following command: 
17513 \newline 
17514
17515 \newline 
17516
17517 \family sans 
17518 \series bold 
17519 ESC-x sdcdbsrc
17520 \family default 
17521 \series default 
17522
17523 \newline 
17524
17525 \newline 
17526 You will prompted to enter the file name to be debugged.
17527  
17528 \newline 
17529
17530 \newline 
17531 The command line options that are passed to the simulator directly are bound
17532  to default values in the file sdcdbsrc.el.
17533  The variables are listed below, these values maybe changed as required.
17534 \layout Itemize
17535
17536 sdcdbsrc-cpu-type '51
17537 \layout Itemize
17538
17539 sdcdbsrc-frequency '11059200
17540 \layout Itemize
17541
17542 sdcdbsrc-serial nil
17543 \layout Standard
17544
17545 The following is a list of key mapping for the debugger interface.
17546 \layout Standard
17547
17548 \SpecialChar ~
17549
17550 \family typewriter 
17551
17552 \newline 
17553 ;;\SpecialChar ~
17554 Current Listing :: 
17555 \newline 
17556 ;;key\SpecialChar ~
17557 \SpecialChar ~
17558 \SpecialChar ~
17559 \SpecialChar ~
17560 \SpecialChar ~
17561 \SpecialChar ~
17562 \SpecialChar ~
17563 \SpecialChar ~
17564 \SpecialChar ~
17565 \SpecialChar ~
17566 \SpecialChar ~
17567 \SpecialChar ~
17568 \SpecialChar ~
17569 \SpecialChar ~
17570 binding\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 Comment 
17593 \newline 
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 \SpecialChar ~
17614 \SpecialChar ~
17615 \SpecialChar ~
17616 \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 -------
17631 \newline 
17632 ;; 
17633 \newline 
17634 ;;\SpecialChar ~
17635 n\SpecialChar ~
17636 \SpecialChar ~
17637 \SpecialChar ~
17638 \SpecialChar ~
17639 \SpecialChar ~
17640 \SpecialChar ~
17641 \SpecialChar ~
17642 \SpecialChar ~
17643 \SpecialChar ~
17644 \SpecialChar ~
17645 \SpecialChar ~
17646 \SpecialChar ~
17647 \SpecialChar ~
17648 \SpecialChar ~
17649 \SpecialChar ~
17650 sdcdb-next-from-src\SpecialChar ~
17651 \SpecialChar ~
17652 \SpecialChar ~
17653 \SpecialChar ~
17654 \SpecialChar ~
17655 \SpecialChar ~
17656 \SpecialChar ~
17657 \SpecialChar ~
17658 \SpecialChar ~
17659 \SpecialChar ~
17660 SDCDB next command 
17661 \newline 
17662 ;;\SpecialChar ~
17663 b\SpecialChar ~
17664 \SpecialChar ~
17665 \SpecialChar ~
17666 \SpecialChar ~
17667 \SpecialChar ~
17668 \SpecialChar ~
17669 \SpecialChar ~
17670 \SpecialChar ~
17671 \SpecialChar ~
17672 \SpecialChar ~
17673 \SpecialChar ~
17674 \SpecialChar ~
17675 \SpecialChar ~
17676 \SpecialChar ~
17677 \SpecialChar ~
17678 sdcdb-back-from-src\SpecialChar ~
17679 \SpecialChar ~
17680 \SpecialChar ~
17681 \SpecialChar ~
17682 \SpecialChar ~
17683 \SpecialChar ~
17684 \SpecialChar ~
17685 \SpecialChar ~
17686 \SpecialChar ~
17687 \SpecialChar ~
17688 SDCDB back command 
17689 \newline 
17690 ;;\SpecialChar ~
17691 c\SpecialChar ~
17692 \SpecialChar ~
17693 \SpecialChar ~
17694 \SpecialChar ~
17695 \SpecialChar ~
17696 \SpecialChar ~
17697 \SpecialChar ~
17698 \SpecialChar ~
17699 \SpecialChar ~
17700 \SpecialChar ~
17701 \SpecialChar ~
17702 \SpecialChar ~
17703 \SpecialChar ~
17704 \SpecialChar ~
17705 \SpecialChar ~
17706 sdcdb-cont-from-src\SpecialChar ~
17707 \SpecialChar ~
17708 \SpecialChar ~
17709 \SpecialChar ~
17710 \SpecialChar ~
17711 \SpecialChar ~
17712 \SpecialChar ~
17713 \SpecialChar ~
17714 \SpecialChar ~
17715 \SpecialChar ~
17716 SDCDB continue command
17717 \newline 
17718 ;;\SpecialChar ~
17719 s\SpecialChar ~
17720 \SpecialChar ~
17721 \SpecialChar ~
17722 \SpecialChar ~
17723 \SpecialChar ~
17724 \SpecialChar ~
17725 \SpecialChar ~
17726 \SpecialChar ~
17727 \SpecialChar ~
17728 \SpecialChar ~
17729 \SpecialChar ~
17730 \SpecialChar ~
17731 \SpecialChar ~
17732 \SpecialChar ~
17733 \SpecialChar ~
17734 sdcdb-step-from-src\SpecialChar ~
17735 \SpecialChar ~
17736 \SpecialChar ~
17737 \SpecialChar ~
17738 \SpecialChar ~
17739 \SpecialChar ~
17740 \SpecialChar ~
17741 \SpecialChar ~
17742 \SpecialChar ~
17743 \SpecialChar ~
17744 SDCDB step command 
17745 \newline 
17746 ;;\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 sdcdb-whatis-c-sexp\SpecialChar ~
17763 \SpecialChar ~
17764 \SpecialChar ~
17765 \SpecialChar ~
17766 \SpecialChar ~
17767 \SpecialChar ~
17768 \SpecialChar ~
17769 \SpecialChar ~
17770 \SpecialChar ~
17771 \SpecialChar ~
17772 SDCDB ptypecommand for data at 
17773 \newline 
17774 ;;\SpecialChar ~
17775 \SpecialChar ~
17776 \SpecialChar ~
17777 \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 \SpecialChar ~
17791 \SpecialChar ~
17792 \SpecialChar ~
17793 \SpecialChar ~
17794 \SpecialChar ~
17795 \SpecialChar ~
17796 \SpecialChar ~
17797 \SpecialChar ~
17798 \SpecialChar ~
17799 \SpecialChar ~
17800 \SpecialChar ~
17801 \SpecialChar ~
17802 \SpecialChar ~
17803 \SpecialChar ~
17804 \SpecialChar ~
17805 \SpecialChar ~
17806 \SpecialChar ~
17807 \SpecialChar ~
17808 \SpecialChar ~
17809 \SpecialChar ~
17810 \SpecialChar ~
17811 \SpecialChar ~
17812 \SpecialChar ~
17813 \SpecialChar ~
17814 \SpecialChar ~
17815 \SpecialChar ~
17816 \SpecialChar ~
17817 \SpecialChar ~
17818 \SpecialChar ~
17819 \SpecialChar ~
17820 \SpecialChar ~
17821 buffer point 
17822 \newline 
17823 ;;\SpecialChar ~
17824 x\SpecialChar ~
17825 \SpecialChar ~
17826 \SpecialChar ~
17827 \SpecialChar ~
17828 \SpecialChar ~
17829 \SpecialChar ~
17830 \SpecialChar ~
17831 \SpecialChar ~
17832 \SpecialChar ~
17833 \SpecialChar ~
17834 \SpecialChar ~
17835 \SpecialChar ~
17836 \SpecialChar ~
17837 \SpecialChar ~
17838 \SpecialChar ~
17839 sdcdbsrc-delete\SpecialChar ~
17840 \SpecialChar ~
17841 \SpecialChar ~
17842 \SpecialChar ~
17843 \SpecialChar ~
17844 \SpecialChar ~
17845 \SpecialChar ~
17846 \SpecialChar ~
17847 \SpecialChar ~
17848 \SpecialChar ~
17849 \SpecialChar ~
17850 \SpecialChar ~
17851 \SpecialChar ~
17852 \SpecialChar ~
17853 SDCDB Delete all breakpoints if no arg 
17854 \newline 
17855 ;;\SpecialChar ~
17856 \SpecialChar ~
17857 \SpecialChar ~
17858 \SpecialChar ~
17859 \SpecialChar ~
17860 \SpecialChar ~
17861 \SpecialChar ~
17862 \SpecialChar ~
17863 \SpecialChar ~
17864 \SpecialChar ~
17865 \SpecialChar ~
17866 \SpecialChar ~
17867 \SpecialChar ~
17868 \SpecialChar ~
17869 \SpecialChar ~
17870 \SpecialChar ~
17871 \SpecialChar ~
17872 \SpecialChar ~
17873 \SpecialChar ~
17874 \SpecialChar ~
17875 \SpecialChar ~
17876 \SpecialChar ~
17877 \SpecialChar ~
17878 \SpecialChar ~
17879 \SpecialChar ~
17880 \SpecialChar ~
17881 \SpecialChar ~
17882 \SpecialChar ~
17883 \SpecialChar ~
17884 \SpecialChar ~
17885 \SpecialChar ~
17886 \SpecialChar ~
17887 \SpecialChar ~
17888 \SpecialChar ~
17889 \SpecialChar ~
17890 \SpecialChar ~
17891 \SpecialChar ~
17892 \SpecialChar ~
17893 \SpecialChar ~
17894 \SpecialChar ~
17895 \SpecialChar ~
17896 \SpecialChar ~
17897 \SpecialChar ~
17898 \SpecialChar ~
17899 \SpecialChar ~
17900 \SpecialChar ~
17901 \SpecialChar ~
17902 given or delete arg (C-u arg x) 
17903 \newline 
17904 ;;\SpecialChar ~
17905 m\SpecialChar ~
17906 \SpecialChar ~
17907 \SpecialChar ~
17908 \SpecialChar ~
17909 \SpecialChar ~
17910 \SpecialChar ~
17911 \SpecialChar ~
17912 \SpecialChar ~
17913 \SpecialChar ~
17914 \SpecialChar ~
17915 \SpecialChar ~
17916 \SpecialChar ~
17917 \SpecialChar ~
17918 \SpecialChar ~
17919 \SpecialChar ~
17920 sdcdbsrc-frame\SpecialChar ~
17921 \SpecialChar ~
17922 \SpecialChar ~
17923 \SpecialChar ~
17924 \SpecialChar ~
17925 \SpecialChar ~
17926 \SpecialChar ~
17927 \SpecialChar ~
17928 \SpecialChar ~
17929 \SpecialChar ~
17930 \SpecialChar ~
17931 \SpecialChar ~
17932 \SpecialChar ~
17933 \SpecialChar ~
17934 \SpecialChar ~
17935 SDCDB Display current frame if no arg, 
17936 \newline 
17937 ;;\SpecialChar ~
17938 \SpecialChar ~
17939 \SpecialChar ~
17940 \SpecialChar ~
17941 \SpecialChar ~
17942 \SpecialChar ~
17943 \SpecialChar ~
17944 \SpecialChar ~
17945 \SpecialChar ~
17946 \SpecialChar ~
17947 \SpecialChar ~
17948 \SpecialChar ~
17949 \SpecialChar ~
17950 \SpecialChar ~
17951 \SpecialChar ~
17952 \SpecialChar ~
17953 \SpecialChar ~
17954 \SpecialChar ~
17955 \SpecialChar ~
17956 \SpecialChar ~
17957 \SpecialChar ~
17958 \SpecialChar ~
17959 \SpecialChar ~
17960 \SpecialChar ~
17961 \SpecialChar ~
17962 \SpecialChar ~
17963 \SpecialChar ~
17964 \SpecialChar ~
17965 \SpecialChar ~
17966 \SpecialChar ~
17967 \SpecialChar ~
17968 \SpecialChar ~
17969 \SpecialChar ~
17970 \SpecialChar ~
17971 \SpecialChar ~
17972 \SpecialChar ~
17973 \SpecialChar ~
17974 \SpecialChar ~
17975 \SpecialChar ~
17976 \SpecialChar ~
17977 \SpecialChar ~
17978 \SpecialChar ~
17979 \SpecialChar ~
17980 \SpecialChar ~
17981 \SpecialChar ~
17982 \SpecialChar ~
17983 \SpecialChar ~
17984 given or display frame arg 
17985 \newline 
17986 ;;\SpecialChar ~
17987 \SpecialChar ~
17988 \SpecialChar ~
17989 \SpecialChar ~
17990 \SpecialChar ~
17991 \SpecialChar ~
17992 \SpecialChar ~
17993 \SpecialChar ~
17994 \SpecialChar ~
17995 \SpecialChar ~
17996 \SpecialChar ~
17997 \SpecialChar ~
17998 \SpecialChar ~
17999 \SpecialChar ~
18000 \SpecialChar ~
18001 \SpecialChar ~
18002 \SpecialChar ~
18003 \SpecialChar ~
18004 \SpecialChar ~
18005 \SpecialChar ~
18006 \SpecialChar ~
18007 \SpecialChar ~
18008 \SpecialChar ~
18009 \SpecialChar ~
18010 \SpecialChar ~
18011 \SpecialChar ~
18012 \SpecialChar ~
18013 \SpecialChar ~
18014 \SpecialChar ~
18015 \SpecialChar ~
18016 \SpecialChar ~
18017 \SpecialChar ~
18018 \SpecialChar ~
18019 \SpecialChar ~
18020 \SpecialChar ~
18021 \SpecialChar ~
18022 \SpecialChar ~
18023 \SpecialChar ~
18024 \SpecialChar ~
18025 \SpecialChar ~
18026 \SpecialChar ~
18027 \SpecialChar ~
18028 \SpecialChar ~
18029 \SpecialChar ~
18030 \SpecialChar ~
18031 \SpecialChar ~
18032 \SpecialChar ~
18033 buffer point 
18034 \newline 
18035 ;;\SpecialChar ~
18036 !\SpecialChar ~
18037 \SpecialChar ~
18038 \SpecialChar ~
18039 \SpecialChar ~
18040 \SpecialChar ~
18041 \SpecialChar ~
18042 \SpecialChar ~
18043 \SpecialChar ~
18044 \SpecialChar ~
18045 \SpecialChar ~
18046 \SpecialChar ~
18047 \SpecialChar ~
18048 \SpecialChar ~
18049 \SpecialChar ~
18050 \SpecialChar ~
18051 sdcdbsrc-goto-sdcdb\SpecialChar ~
18052 \SpecialChar ~
18053 \SpecialChar ~
18054 \SpecialChar ~
18055 \SpecialChar ~
18056 \SpecialChar ~
18057 \SpecialChar ~
18058 \SpecialChar ~
18059 \SpecialChar ~
18060 \SpecialChar ~
18061 Goto the SDCDB output buffer 
18062 \newline 
18063 ;;\SpecialChar ~
18064 p\SpecialChar ~
18065 \SpecialChar ~
18066 \SpecialChar ~
18067 \SpecialChar ~
18068 \SpecialChar ~
18069 \SpecialChar ~
18070 \SpecialChar ~
18071 \SpecialChar ~
18072 \SpecialChar ~
18073 \SpecialChar ~
18074 \SpecialChar ~
18075 \SpecialChar ~
18076 \SpecialChar ~
18077 \SpecialChar ~
18078 \SpecialChar ~
18079 sdcdb-print-c-sexp\SpecialChar ~
18080 \SpecialChar ~
18081 \SpecialChar ~
18082 \SpecialChar ~
18083 \SpecialChar ~
18084 \SpecialChar ~
18085 \SpecialChar ~
18086 \SpecialChar ~
18087 \SpecialChar ~
18088 \SpecialChar ~
18089 \SpecialChar ~
18090 SDCDB print command for data at 
18091 \newline 
18092 ;;\SpecialChar ~
18093 \SpecialChar ~
18094 \SpecialChar ~
18095 \SpecialChar ~
18096 \SpecialChar ~
18097 \SpecialChar ~
18098 \SpecialChar ~
18099 \SpecialChar ~
18100 \SpecialChar ~
18101 \SpecialChar ~
18102 \SpecialChar ~
18103 \SpecialChar ~
18104 \SpecialChar ~
18105 \SpecialChar ~
18106 \SpecialChar ~
18107 \SpecialChar ~
18108 \SpecialChar ~
18109 \SpecialChar ~
18110 \SpecialChar ~
18111 \SpecialChar ~
18112 \SpecialChar ~
18113 \SpecialChar ~
18114 \SpecialChar ~
18115 \SpecialChar ~
18116 \SpecialChar ~
18117 \SpecialChar ~
18118 \SpecialChar ~
18119 \SpecialChar ~
18120 \SpecialChar ~
18121 \SpecialChar ~
18122 \SpecialChar ~
18123 \SpecialChar ~
18124 \SpecialChar ~
18125 \SpecialChar ~
18126 \SpecialChar ~
18127 \SpecialChar ~
18128 \SpecialChar ~
18129 \SpecialChar ~
18130 \SpecialChar ~
18131 \SpecialChar ~
18132 \SpecialChar ~
18133 \SpecialChar ~
18134 \SpecialChar ~
18135 \SpecialChar ~
18136 \SpecialChar ~
18137 \SpecialChar ~
18138 \SpecialChar ~
18139 buffer point 
18140 \newline 
18141 ;;\SpecialChar ~
18142 g\SpecialChar ~
18143 \SpecialChar ~
18144 \SpecialChar ~
18145 \SpecialChar ~
18146 \SpecialChar ~
18147 \SpecialChar ~
18148 \SpecialChar ~
18149 \SpecialChar ~
18150 \SpecialChar ~
18151 \SpecialChar ~
18152 \SpecialChar ~
18153 \SpecialChar ~
18154 \SpecialChar ~
18155 \SpecialChar ~
18156 \SpecialChar ~
18157 sdcdbsrc-goto-sdcdb\SpecialChar ~
18158 \SpecialChar ~
18159 \SpecialChar ~
18160 \SpecialChar ~
18161 \SpecialChar ~
18162 \SpecialChar ~
18163 \SpecialChar ~
18164 \SpecialChar ~
18165 \SpecialChar ~
18166 \SpecialChar ~
18167 Goto the SDCDB output buffer 
18168 \newline 
18169 ;;\SpecialChar ~
18170 t\SpecialChar ~
18171 \SpecialChar ~
18172 \SpecialChar ~
18173 \SpecialChar ~
18174 \SpecialChar ~
18175 \SpecialChar ~
18176 \SpecialChar ~
18177 \SpecialChar ~
18178 \SpecialChar ~
18179 \SpecialChar ~
18180 \SpecialChar ~
18181 \SpecialChar ~
18182 \SpecialChar ~
18183 \SpecialChar ~
18184 \SpecialChar ~
18185 sdcdbsrc-mode\SpecialChar ~
18186 \SpecialChar ~
18187 \SpecialChar ~
18188 \SpecialChar ~
18189 \SpecialChar ~
18190 \SpecialChar ~
18191 \SpecialChar ~
18192 \SpecialChar ~
18193 \SpecialChar ~
18194 \SpecialChar ~
18195 \SpecialChar ~
18196 \SpecialChar ~
18197 \SpecialChar ~
18198 \SpecialChar ~
18199 \SpecialChar ~
18200 \SpecialChar ~
18201 Toggles Sdcdbsrc mode (turns it off) 
18202 \newline 
18203 ;; 
18204 \newline 
18205 ;;\SpecialChar ~
18206 C-c\SpecialChar ~
18207 C-f\SpecialChar ~
18208 \SpecialChar ~
18209 \SpecialChar ~
18210 \SpecialChar ~
18211 \SpecialChar ~
18212 \SpecialChar ~
18213 \SpecialChar ~
18214 \SpecialChar ~
18215 \SpecialChar ~
18216 sdcdb-finish-from-src\SpecialChar ~
18217 \SpecialChar ~
18218 \SpecialChar ~
18219 \SpecialChar ~
18220 \SpecialChar ~
18221 \SpecialChar ~
18222 \SpecialChar ~
18223 \SpecialChar ~
18224 SDCDB finish command 
18225 \newline 
18226 ;; 
18227 \newline 
18228 ;;\SpecialChar ~
18229 C-x\SpecialChar ~
18230 SPC\SpecialChar ~
18231 \SpecialChar ~
18232 \SpecialChar ~
18233 \SpecialChar ~
18234 \SpecialChar ~
18235 \SpecialChar ~
18236 \SpecialChar ~
18237 \SpecialChar ~
18238 \SpecialChar ~
18239 sdcdb-break\SpecialChar ~
18240 \SpecialChar ~
18241 \SpecialChar ~
18242 \SpecialChar ~
18243 \SpecialChar ~
18244 \SpecialChar ~
18245 \SpecialChar ~
18246 \SpecialChar ~
18247 \SpecialChar ~
18248 \SpecialChar ~
18249 \SpecialChar ~
18250 \SpecialChar ~
18251 \SpecialChar ~
18252 \SpecialChar ~
18253 \SpecialChar ~
18254 \SpecialChar ~
18255 \SpecialChar ~
18256 \SpecialChar ~
18257 Set break for line with point 
18258 \newline 
18259 ;;\SpecialChar ~
18260 ESC\SpecialChar ~
18261 t\SpecialChar ~
18262 \SpecialChar ~
18263 \SpecialChar ~
18264 \SpecialChar ~
18265 \SpecialChar ~
18266 \SpecialChar ~
18267 \SpecialChar ~
18268 \SpecialChar ~
18269 \SpecialChar ~
18270 \SpecialChar ~
18271 \SpecialChar ~
18272 sdcdbsrc-mode\SpecialChar ~
18273 \SpecialChar ~
18274 \SpecialChar ~
18275 \SpecialChar ~
18276 \SpecialChar ~
18277 \SpecialChar ~
18278 \SpecialChar ~
18279 \SpecialChar ~
18280 \SpecialChar ~
18281 \SpecialChar ~
18282 \SpecialChar ~
18283 \SpecialChar ~
18284 \SpecialChar ~
18285 \SpecialChar ~
18286 \SpecialChar ~
18287 \SpecialChar ~
18288 Toggle Sdcdbsrc mode 
18289 \newline 
18290 ;;\SpecialChar ~
18291 ESC\SpecialChar ~
18292 m\SpecialChar ~
18293 \SpecialChar ~
18294 \SpecialChar ~
18295 \SpecialChar ~
18296 \SpecialChar ~
18297 \SpecialChar ~
18298 \SpecialChar ~
18299 \SpecialChar ~
18300 \SpecialChar ~
18301 \SpecialChar ~
18302 \SpecialChar ~
18303 sdcdbsrc-srcmode\SpecialChar ~
18304 \SpecialChar ~
18305 \SpecialChar ~
18306 \SpecialChar ~
18307 \SpecialChar ~
18308 \SpecialChar ~
18309 \SpecialChar ~
18310 \SpecialChar ~
18311 \SpecialChar ~
18312 \SpecialChar ~
18313 \SpecialChar ~
18314 \SpecialChar ~
18315 \SpecialChar ~
18316 Toggle list mode 
18317 \newline 
18318 ;; 
18319 \newline 
18320
18321 \layout Chapter
18322 \pagebreak_top 
18323 TIPS
18324 \layout Standard
18325
18326 Here are a few guidelines that will help the compiler generate more efficient
18327  code, some of the tips are specific to this compiler others are generally
18328  good programming practice.
18329 \layout Itemize
18330
18331 Use the smallest data type to represent your data-value.
18332  If it is known in advance that the value is going to be less than 256 then
18333  use an 'unsigned char' instead of a 'short' or 'int'.
18334  Please note, that ANSI C requires both signed and unsigned chars to be
18335  promoted to 'signed int' before doing any operation.
18336  This promotion can be omitted, if the result is the same.
18337  The effect of the promotion rules together with the sign-extension is often
18338  surprising:
18339 \begin_deeper 
18340 \layout Verse
18341
18342
18343 \family typewriter 
18344 unsigned char uc = 0xfe;
18345 \newline 
18346 if (uc * uc < 0) /* this is true! */
18347 \newline 
18348 {
18349 \newline 
18350 \SpecialChar ~
18351 \SpecialChar ~
18352 \SpecialChar ~
18353 \SpecialChar ~
18354 ....
18355 \newline 
18356 }
18357 \layout Standard
18358
18359
18360 \family typewriter 
18361 uc * uc
18362 \family default 
18363  is evaluated as 
18364 \family typewriter 
18365 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
18366 \family default 
18367 .
18368  
18369 \newline 
18370 Another one:
18371 \layout Verse
18372
18373
18374 \family typewriter 
18375 (unsigned char) -12 / (signed char) -3 = ...
18376 \layout Standard
18377
18378 No, the result is not 4:
18379 \layout Verse
18380
18381
18382 \family typewriter 
18383 (int) (unsigned char) -12 / (int) (signed char) -3 =
18384 \newline 
18385 (int) (unsigned char) 0xf4 / (int) (signed char) 0xfd =
18386 \newline 
18387 (int) 0x00f4 / (int) 0xfffd =
18388 \newline 
18389 (int) 0x00f4 / (int) 0xfffd =
18390 \newline 
18391 (int) 244 / (int) -3 =
18392 \newline 
18393 (int) -81 = (int) 0xffaf;
18394 \layout Standard
18395
18396 Don't complain, that gcc gives you a different result.
18397  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
18398  Therefore the results are different.
18399 \newline 
18400 From 
18401 \begin_inset Quotes sld
18402 \end_inset 
18403
18404 comp.lang.c FAQ
18405 \begin_inset Quotes srd
18406 \end_inset 
18407
18408 :
18409 \layout Quote
18410
18411 If well-defined overflow characteristics are important and negative values
18412  are not, or if you want to steer clear of sign-extension problems when
18413  manipulating bits or bytes, use one of the corresponding unsigned types.
18414  (Beware when mixing signed and unsigned values in expressions, though.)
18415 \newline 
18416 Although character types (especially unsigned char) can be used as "tiny"
18417  integers, doing so is sometimes more trouble than it's worth, due to unpredicta
18418 ble sign extension and increased code size.
18419 \end_deeper 
18420 \layout Itemize
18421
18422 Use unsigned when it is known in advance that the value is not going to
18423  be negative.
18424  This helps especially if you are doing division or multiplication, bit-shifting
18425  or are using an array index.
18426 \layout Itemize
18427
18428 NEVER jump into a LOOP.
18429 \layout Itemize
18430
18431 Declare the variables to be local
18432 \begin_inset LatexCommand \index{local variables}
18433
18434 \end_inset 
18435
18436  whenever possible, especially loop control variables (induction).
18437 \layout Itemize
18438
18439 Since the compiler does not always do implicit integral promotion, the programme
18440 r should do an explicit cast when integral promotion is required.
18441 \layout Itemize
18442
18443 Reducing the size of division, multiplication & modulus operations can reduce
18444  code size substantially.
18445  Take the following code for example.
18446 \begin_deeper 
18447 \layout Verse
18448
18449
18450 \family typewriter 
18451 foobar(unsigned int p1, unsigned char ch)
18452 \newline 
18453 {
18454 \newline 
18455 \SpecialChar ~
18456 \SpecialChar ~
18457 \SpecialChar ~
18458 \SpecialChar ~
18459 unsigned char ch1 = p1 % ch ;
18460 \newline 
18461 \SpecialChar ~
18462 \SpecialChar ~
18463 \SpecialChar ~
18464 \SpecialChar ~
18465 ....
18466 \newline 
18467 }
18468 \layout Standard
18469
18470 For the modulus operation the variable ch will be promoted to unsigned int
18471  first then the modulus operation will be performed (this will lead to a
18472  call to support routine _moduint()), and the result will be casted to a
18473  char.
18474  If the code is changed to 
18475 \layout Verse
18476
18477
18478 \family typewriter 
18479 foobar(unsigned int p1, unsigned char ch)
18480 \newline 
18481 {
18482 \newline 
18483 \SpecialChar ~
18484 \SpecialChar ~
18485 \SpecialChar ~
18486 \SpecialChar ~
18487 unsigned char ch1 = (unsigned char)p1 % ch ;
18488 \newline 
18489 \SpecialChar ~
18490 \SpecialChar ~
18491 \SpecialChar ~
18492 \SpecialChar ~
18493 ....
18494 \newline 
18495 }
18496 \layout Standard
18497
18498 It would substantially reduce the code generated (future versions of the
18499  compiler will be smart enough to detect such optimization opportunities).
18500 \end_deeper 
18501 \layout Itemize
18502
18503 Have a look at the assembly listing to get a 
18504 \begin_inset Quotes sld
18505 \end_inset 
18506
18507 feeling
18508 \begin_inset Quotes srd
18509 \end_inset 
18510
18511  for the code generation.
18512 \layout Section
18513
18514 Tools
18515 \begin_inset LatexCommand \index{Tools}
18516
18517 \end_inset 
18518
18519  included in the distribution
18520 \layout Standard
18521 \align center 
18522
18523 \begin_inset  Tabular
18524 <lyxtabular version="3" rows="12" columns="3">
18525 <features>
18526 <column alignment="center" valignment="top" leftline="true" width="0pt">
18527 <column alignment="center" valignment="top" leftline="true" width="0pt">
18528 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
18529 <row topline="true" bottomline="true">
18530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18531 \begin_inset Text
18532
18533 \layout Standard
18534
18535 Name
18536 \end_inset 
18537 </cell>
18538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18539 \begin_inset Text
18540
18541 \layout Standard
18542
18543 Purpose
18544 \end_inset 
18545 </cell>
18546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18547 \begin_inset Text
18548
18549 \layout Standard
18550
18551 Directory
18552 \end_inset 
18553 </cell>
18554 </row>
18555 <row topline="true">
18556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18557 \begin_inset Text
18558
18559 \layout Standard
18560
18561 uCsim
18562 \end_inset 
18563 </cell>
18564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18565 \begin_inset Text
18566
18567 \layout Standard
18568
18569 Simulator for various architectures
18570 \end_inset 
18571 </cell>
18572 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18573 \begin_inset Text
18574
18575 \layout Standard
18576
18577 sdcc/sim/ucsim
18578 \end_inset 
18579 </cell>
18580 </row>
18581 <row topline="true">
18582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18583 \begin_inset Text
18584
18585 \layout Standard
18586
18587 keil2sdcc.pl
18588 \end_inset 
18589 </cell>
18590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18591 \begin_inset Text
18592
18593 \layout Standard
18594
18595 header file conversion
18596 \end_inset 
18597 </cell>
18598 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18599 \begin_inset Text
18600
18601 \layout Standard
18602
18603 sdcc/support/scripts
18604 \end_inset 
18605 </cell>
18606 </row>
18607 <row topline="true">
18608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18609 \begin_inset Text
18610
18611 \layout Standard
18612
18613 mh2h.c
18614 \end_inset 
18615 </cell>
18616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18617 \begin_inset Text
18618
18619 \layout Standard
18620
18621 header file conversion
18622 \end_inset 
18623 </cell>
18624 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18625 \begin_inset Text
18626
18627 \layout Standard
18628
18629 sdcc/support/scripts
18630 \end_inset 
18631 </cell>
18632 </row>
18633 <row topline="true">
18634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18635 \begin_inset Text
18636
18637 \layout Standard
18638
18639 as-gbz80
18640 \end_inset 
18641 </cell>
18642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18643 \begin_inset Text
18644
18645 \layout Standard
18646
18647 Assembler
18648 \end_inset 
18649 </cell>
18650 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18651 \begin_inset Text
18652
18653 \layout Standard
18654
18655
18656 \family roman 
18657 \series medium 
18658 \shape up 
18659 \size normal 
18660 \emph off 
18661 \bar no 
18662 \noun off 
18663 \color none
18664 sdcc/bin
18665 \end_inset 
18666 </cell>
18667 </row>
18668 <row topline="true">
18669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18670 \begin_inset Text
18671
18672 \layout Standard
18673
18674 as-z80
18675 \end_inset 
18676 </cell>
18677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18678 \begin_inset Text
18679
18680 \layout Standard
18681
18682 Assembler
18683 \end_inset 
18684 </cell>
18685 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18686 \begin_inset Text
18687
18688 \layout Standard
18689
18690
18691 \family roman 
18692 \series medium 
18693 \shape up 
18694 \size normal 
18695 \emph off 
18696 \bar no 
18697 \noun off 
18698 \color none
18699 sdcc/bin
18700 \end_inset 
18701 </cell>
18702 </row>
18703 <row topline="true">
18704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18705 \begin_inset Text
18706
18707 \layout Standard
18708
18709 asx8051
18710 \end_inset 
18711 </cell>
18712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18713 \begin_inset Text
18714
18715 \layout Standard
18716
18717 Assembler
18718 \end_inset 
18719 </cell>
18720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18721 \begin_inset Text
18722
18723 \layout Standard
18724
18725
18726 \family roman 
18727 \series medium 
18728 \shape up 
18729 \size normal 
18730 \emph off 
18731 \bar no 
18732 \noun off 
18733 \color none
18734 sdcc/bin
18735 \end_inset 
18736 </cell>
18737 </row>
18738 <row topline="true">
18739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18740 \begin_inset Text
18741
18742 \layout Standard
18743
18744 sdcdb
18745 \end_inset 
18746 </cell>
18747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18748 \begin_inset Text
18749
18750 \layout Standard
18751
18752 Simulator
18753 \end_inset 
18754 </cell>
18755 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18756 \begin_inset Text
18757
18758 \layout Standard
18759
18760
18761 \family roman 
18762 \series medium 
18763 \shape up 
18764 \size normal 
18765 \emph off 
18766 \bar no 
18767 \noun off 
18768 \color none
18769 sdcc/bin
18770 \end_inset 
18771 </cell>
18772 </row>
18773 <row topline="true">
18774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18775 \begin_inset Text
18776
18777 \layout Standard
18778
18779 aslink
18780 \end_inset 
18781 </cell>
18782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18783 \begin_inset Text
18784
18785 \layout Standard
18786
18787 Linker
18788 \end_inset 
18789 </cell>
18790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18791 \begin_inset Text
18792
18793 \layout Standard
18794
18795
18796 \family roman 
18797 \series medium 
18798 \shape up 
18799 \size normal 
18800 \emph off 
18801 \bar no 
18802 \noun off 
18803 \color none
18804 sdcc/bin
18805 \end_inset 
18806 </cell>
18807 </row>
18808 <row topline="true">
18809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18810 \begin_inset Text
18811
18812 \layout Standard
18813
18814 link-z80
18815 \end_inset 
18816 </cell>
18817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18818 \begin_inset Text
18819
18820 \layout Standard
18821
18822 Linker
18823 \end_inset 
18824 </cell>
18825 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18826 \begin_inset Text
18827
18828 \layout Standard
18829
18830
18831 \family roman 
18832 \series medium 
18833 \shape up 
18834 \size normal 
18835 \emph off 
18836 \bar no 
18837 \noun off 
18838 \color none
18839 sdcc/bin
18840 \end_inset 
18841 </cell>
18842 </row>
18843 <row topline="true">
18844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18845 \begin_inset Text
18846
18847 \layout Standard
18848
18849 link-gbz80
18850 \end_inset 
18851 </cell>
18852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18853 \begin_inset Text
18854
18855 \layout Standard
18856
18857 Linker
18858 \end_inset 
18859 </cell>
18860 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18861 \begin_inset Text
18862
18863 \layout Standard
18864
18865
18866 \family roman 
18867 \series medium 
18868 \shape up 
18869 \size normal 
18870 \emph off 
18871 \bar no 
18872 \noun off 
18873 \color none
18874 sdcc/bin
18875 \end_inset 
18876 </cell>
18877 </row>
18878 <row topline="true" bottomline="true">
18879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18880 \begin_inset Text
18881
18882 \layout Standard
18883
18884 packihx
18885 \end_inset 
18886 </cell>
18887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18888 \begin_inset Text
18889
18890 \layout Standard
18891
18892 ihx packer
18893 \end_inset 
18894 </cell>
18895 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18896 \begin_inset Text
18897
18898 \layout Standard
18899
18900
18901 \family roman 
18902 \series medium 
18903 \shape up 
18904 \size normal 
18905 \emph off 
18906 \bar no 
18907 \noun off 
18908 \color none
18909 sdcc/bin
18910 \end_inset 
18911 </cell>
18912 </row>
18913 </lyxtabular>
18914
18915 \end_inset 
18916
18917
18918 \newline 
18919
18920 \layout Section
18921
18922 Documentation
18923 \begin_inset LatexCommand \index{Documentation}
18924
18925 \end_inset 
18926
18927  included in the distribution
18928 \layout Standard
18929 \align center 
18930
18931 \begin_inset  Tabular
18932 <lyxtabular version="3" rows="10" columns="2">
18933 <features>
18934 <column alignment="left" valignment="top" leftline="true" width="0">
18935 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
18936 <row topline="true" bottomline="true">
18937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18938 \begin_inset Text
18939
18940 \layout Standard
18941
18942 Subject / Title
18943 \end_inset 
18944 </cell>
18945 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18946 \begin_inset Text
18947
18948 \layout Standard
18949
18950 Where to get / filename
18951 \end_inset 
18952 </cell>
18953 </row>
18954 <row topline="true">
18955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18956 \begin_inset Text
18957
18958 \layout Standard
18959
18960 SDCC Compiler User Guide
18961 \end_inset 
18962 </cell>
18963 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18964 \begin_inset Text
18965
18966 \layout Standard
18967
18968 You're reading it right now
18969 \end_inset 
18970 </cell>
18971 </row>
18972 <row topline="true">
18973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18974 \begin_inset Text
18975
18976 \layout Standard
18977
18978 Changelog of SDCC
18979 \end_inset 
18980 </cell>
18981 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18982 \begin_inset Text
18983
18984 \layout Standard
18985
18986 sdcc/Changelog
18987 \end_inset 
18988 </cell>
18989 </row>
18990 <row topline="true">
18991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18992 \begin_inset Text
18993
18994 \layout Standard
18995
18996 ASXXXX
18997 \begin_inset LatexCommand \index{asXXXX (as-gbz80, as-hc08, asx8051, as-z80)}
18998
18999 \end_inset 
19000
19001
19002 \begin_inset LatexCommand \index{Assembler documentation}
19003
19004 \end_inset 
19005
19006  Assemblers and ASLINK
19007 \begin_inset LatexCommand \index{aslink}
19008
19009 \end_inset 
19010
19011
19012 \begin_inset LatexCommand \index{Linker documentation}
19013
19014 \end_inset 
19015
19016  Relocating Linker
19017 \end_inset 
19018 </cell>
19019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19020 \begin_inset Text
19021
19022 \layout Standard
19023
19024 sdcc/as/doc/asxhtm.html
19025 \end_inset 
19026 </cell>
19027 </row>
19028 <row topline="true">
19029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19030 \begin_inset Text
19031
19032 \layout Standard
19033
19034 SDCC regression test
19035 \begin_inset LatexCommand \index{Regression test}
19036
19037 \end_inset 
19038
19039
19040 \end_inset 
19041 </cell>
19042 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19043 \begin_inset Text
19044
19045 \layout Standard
19046
19047 sdcc/doc/test_suite_spec.pdf
19048 \end_inset 
19049 </cell>
19050 </row>
19051 <row topline="true">
19052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19053 \begin_inset Text
19054
19055 \layout Standard
19056
19057 Various notes
19058 \end_inset 
19059 </cell>
19060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19061 \begin_inset Text
19062
19063 \layout Standard
19064
19065 sdcc/doc/*
19066 \end_inset 
19067 </cell>
19068 </row>
19069 <row topline="true">
19070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19071 \begin_inset Text
19072
19073 \layout Standard
19074
19075 Notes on debugging with sdcdb
19076 \begin_inset LatexCommand \index{sdcdb (debugger)}
19077
19078 \end_inset 
19079
19080
19081 \end_inset 
19082 </cell>
19083 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19084 \begin_inset Text
19085
19086 \layout Standard
19087
19088 sdcc/debugger/README
19089 \end_inset 
19090 </cell>
19091 </row>
19092 <row topline="true">
19093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19094 \begin_inset Text
19095
19096 \layout Standard
19097
19098 Software simulator for microcontrollers
19099 \end_inset 
19100 </cell>
19101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19102 \begin_inset Text
19103
19104 \layout Standard
19105
19106
19107 \family roman 
19108 \series medium 
19109 \shape up 
19110 \size normal 
19111 \emph off 
19112 \bar no 
19113 \noun off 
19114 \color none
19115 sdcc/sim/ucsim/doc
19116 \family default 
19117 \series default 
19118 \shape default 
19119 \size default 
19120 \emph default 
19121 \bar default 
19122 \noun default 
19123 \color default
19124 /index.html
19125 \end_inset 
19126 </cell>
19127 </row>
19128 <row topline="true">
19129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19130 \begin_inset Text
19131
19132 \layout Standard
19133
19134 Temporary notes on the pic16
19135 \begin_inset LatexCommand \index{PIC16}
19136
19137 \end_inset 
19138
19139  port
19140 \end_inset 
19141 </cell>
19142 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19143 \begin_inset Text
19144
19145 \layout Standard
19146
19147 sdcc/src/pic16/NOTES
19148 \end_inset 
19149 </cell>
19150 </row>
19151 <row topline="true" bottomline="true">
19152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19153 \begin_inset Text
19154
19155 \layout Standard
19156
19157 SDCC internal documentation (debugging file format)
19158 \end_inset 
19159 </cell>
19160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19161 \begin_inset Text
19162
19163 \layout Standard
19164
19165 sdcc/doc/
19166 \family roman 
19167 \series medium 
19168 \shape up 
19169 \size normal 
19170 \emph off 
19171 \bar no 
19172 \noun off 
19173 \color none
19174 cdbfileformat.pd
19175 \family default 
19176 \series default 
19177 \shape default 
19178 \size default 
19179 \emph default 
19180 \bar default 
19181 \noun default 
19182 \color default
19183 f
19184 \end_inset 
19185 </cell>
19186 </row>
19187 </lyxtabular>
19188
19189 \end_inset 
19190
19191
19192 \newline 
19193
19194 \layout Section
19195
19196 Related open source tools
19197 \begin_inset LatexCommand \index{Related tools}
19198
19199 \end_inset 
19200
19201
19202 \layout Standard
19203 \align center 
19204
19205 \begin_inset  Tabular
19206 <lyxtabular version="3" rows="11" columns="3">
19207 <features>
19208 <column alignment="center" valignment="top" leftline="true" width="0pt">
19209 <column alignment="block" valignment="top" leftline="true" width="30line%">
19210 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
19211 <row topline="true" bottomline="true">
19212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19213 \begin_inset Text
19214
19215 \layout Standard
19216
19217 Name
19218 \end_inset 
19219 </cell>
19220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19221 \begin_inset Text
19222
19223 \layout Standard
19224
19225 Purpose
19226 \end_inset 
19227 </cell>
19228 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19229 \begin_inset Text
19230
19231 \layout Standard
19232
19233 Where to get
19234 \end_inset 
19235 </cell>
19236 </row>
19237 <row topline="true">
19238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19239 \begin_inset Text
19240
19241 \layout Standard
19242
19243 gpsim
19244 \begin_inset LatexCommand \index{gpsim (pic simulator)}
19245
19246 \end_inset 
19247
19248
19249 \end_inset 
19250 </cell>
19251 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19252 \begin_inset Text
19253
19254 \layout Standard
19255
19256 PIC simulator
19257 \end_inset 
19258 </cell>
19259 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19260 \begin_inset Text
19261
19262 \layout Standard
19263
19264
19265 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
19266
19267 \end_inset 
19268
19269
19270 \end_inset 
19271 </cell>
19272 </row>
19273 <row topline="true">
19274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19275 \begin_inset Text
19276
19277 \layout Standard
19278
19279 gputils
19280 \begin_inset LatexCommand \index{gputils (pic tools)}
19281
19282 \end_inset 
19283
19284
19285 \end_inset 
19286 </cell>
19287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19288 \begin_inset Text
19289
19290 \layout Standard
19291
19292 GNU PIC utilities
19293 \end_inset 
19294 </cell>
19295 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19296 \begin_inset Text
19297
19298 \layout Standard
19299
19300
19301 \begin_inset LatexCommand \url{http://gputils.sourceforge.net/}
19302
19303 \end_inset 
19304
19305
19306 \end_inset 
19307 </cell>
19308 </row>
19309 <row topline="true">
19310 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19311 \begin_inset Text
19312
19313 \layout Standard
19314
19315 flP5
19316 \end_inset 
19317 </cell>
19318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19319 \begin_inset Text
19320
19321 \layout Standard
19322
19323 PIC programmer
19324 \end_inset 
19325 </cell>
19326 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19327 \begin_inset Text
19328
19329 \layout Standard
19330
19331
19332 \begin_inset LatexCommand \url{http://digilander.libero.it/fbradasc/FLP5.html}
19333
19334 \end_inset 
19335
19336
19337 \end_inset 
19338 </cell>
19339 </row>
19340 <row topline="true">
19341 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19342 \begin_inset Text
19343
19344 \layout Standard
19345
19346 indent
19347 \begin_inset LatexCommand \index{indent (source formatting tool)}
19348
19349 \end_inset 
19350
19351
19352 \end_inset 
19353 </cell>
19354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19355 \begin_inset Text
19356
19357 \layout Standard
19358
19359 Formats C source - Master of the white spaces
19360 \end_inset 
19361 </cell>
19362 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19363 \begin_inset Text
19364
19365 \layout Standard
19366
19367
19368 \begin_inset LatexCommand \url{http://home.hccnet.nl/d.ingamells/beautify.html}
19369
19370 \end_inset 
19371
19372
19373 \end_inset 
19374 </cell>
19375 </row>
19376 <row topline="true">
19377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19378 \begin_inset Text
19379
19380 \layout Standard
19381
19382 srecord
19383 \begin_inset LatexCommand \index{srecord (tool)}
19384
19385 \end_inset 
19386
19387
19388 \end_inset 
19389 </cell>
19390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19391 \begin_inset Text
19392
19393 \layout Standard
19394
19395 Object file conversion, checksumming, ...
19396 \end_inset 
19397 </cell>
19398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19399 \begin_inset Text
19400
19401 \layout Standard
19402
19403
19404 \begin_inset LatexCommand \url{http://srecord.sourceforge.net/}
19405
19406 \end_inset 
19407
19408
19409 \end_inset 
19410 </cell>
19411 </row>
19412 <row topline="true">
19413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19414 \begin_inset Text
19415
19416 \layout Standard
19417
19418 objdump
19419 \begin_inset LatexCommand \index{objdump (tool)}
19420
19421 \end_inset 
19422
19423
19424 \end_inset 
19425 </cell>
19426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19427 \begin_inset Text
19428
19429 \layout Standard
19430
19431 Object file conversion, ...
19432 \end_inset 
19433 </cell>
19434 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19435 \begin_inset Text
19436
19437 \layout Standard
19438
19439 Part of binutils (should be there anyway)
19440 \end_inset 
19441 </cell>
19442 </row>
19443 <row topline="true">
19444 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19445 \begin_inset Text
19446
19447 \layout Standard
19448
19449 doxygen
19450 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
19451
19452 \end_inset 
19453
19454
19455 \end_inset 
19456 </cell>
19457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19458 \begin_inset Text
19459
19460 \layout Standard
19461
19462 Source code documentation system
19463 \end_inset 
19464 </cell>
19465 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19466 \begin_inset Text
19467
19468 \layout Standard
19469
19470
19471 \begin_inset LatexCommand \url{http://www.doxygen.org}
19472
19473 \end_inset 
19474
19475
19476 \end_inset 
19477 </cell>
19478 </row>
19479 <row topline="true">
19480 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19481 \begin_inset Text
19482
19483 \layout Standard
19484
19485 kdevelop
19486 \end_inset 
19487 </cell>
19488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19489 \begin_inset Text
19490
19491 \layout Standard
19492
19493 IDE (has anyone tried integrating SDCC & sdcdb? Unix only)
19494 \end_inset 
19495 </cell>
19496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19497 \begin_inset Text
19498
19499 \layout Standard
19500
19501
19502 \begin_inset LatexCommand \url{http://www.kdevelop.org}
19503
19504 \end_inset 
19505
19506
19507 \end_inset 
19508 </cell>
19509 </row>
19510 <row topline="true">
19511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19512 \begin_inset Text
19513
19514 \layout Standard
19515
19516 splint
19517 \begin_inset LatexCommand \index{splint (syntax checking tool)}
19518
19519 \end_inset 
19520
19521
19522 \end_inset 
19523 </cell>
19524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19525 \begin_inset Text
19526
19527 \layout Standard
19528
19529 Statically checks c sources (has anyone adapted splint for SDCC?)
19530 \end_inset 
19531 </cell>
19532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19533 \begin_inset Text
19534
19535 \layout Standard
19536
19537
19538 \begin_inset LatexCommand \url{http://www.splint.org}
19539
19540 \end_inset 
19541
19542
19543 \end_inset 
19544 </cell>
19545 </row>
19546 <row topline="true" bottomline="true">
19547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19548 \begin_inset Text
19549
19550 \layout Standard
19551
19552 ddd
19553 \begin_inset LatexCommand \index{ddd (debugger)}
19554
19555 \end_inset 
19556
19557
19558 \end_inset 
19559 </cell>
19560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19561 \begin_inset Text
19562
19563 \layout Standard
19564
19565 Debugger, serves nicely as GUI to sdcdb
19566 \begin_inset LatexCommand \index{sdcdb (debugger)}
19567
19568 \end_inset 
19569
19570  (Unix only)
19571 \end_inset 
19572 </cell>
19573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19574 \begin_inset Text
19575
19576 \layout Standard
19577
19578
19579 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
19580
19581 \end_inset 
19582
19583
19584 \end_inset 
19585 </cell>
19586 </row>
19587 </lyxtabular>
19588
19589 \end_inset 
19590
19591
19592 \newline 
19593
19594 \layout Section
19595
19596 Related documentation / recommended reading
19597 \layout Standard
19598 \align center 
19599
19600 \begin_inset  Tabular
19601 <lyxtabular version="3" rows="6" columns="3">
19602 <features>
19603 <column alignment="center" valignment="top" leftline="true" width="0pt">
19604 <column alignment="block" valignment="top" leftline="true" width="30line%">
19605 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
19606 <row topline="true" bottomline="true">
19607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19608 \begin_inset Text
19609
19610 \layout Standard
19611
19612 Name
19613 \end_inset 
19614 </cell>
19615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19616 \begin_inset Text
19617
19618 \layout Standard
19619
19620 Subject / Title
19621 \end_inset 
19622 </cell>
19623 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19624 \begin_inset Text
19625
19626 \layout Standard
19627
19628 Where to get
19629 \end_inset 
19630 </cell>
19631 </row>
19632 <row topline="true">
19633 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19634 \begin_inset Text
19635
19636 \layout Standard
19637
19638
19639 \family roman 
19640 \series medium 
19641 \shape up 
19642 \size normal 
19643 \emph off 
19644 \bar no 
19645 \noun off 
19646 \color none
19647 c-refcard.pdf
19648 \end_inset 
19649 </cell>
19650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19651 \begin_inset Text
19652
19653 \layout Standard
19654
19655 C Reference Card
19656 \begin_inset LatexCommand \index{C Reference card}
19657
19658 \end_inset 
19659
19660 , 2 pages
19661 \end_inset 
19662 </cell>
19663 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19664 \begin_inset Text
19665
19666 \layout Standard
19667
19668
19669 \begin_inset LatexCommand \url{http://www.refcards.com/about/c.html}
19670
19671 \end_inset 
19672
19673
19674 \end_inset 
19675 </cell>
19676 </row>
19677 <row topline="true">
19678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19679 \begin_inset Text
19680
19681 \layout Standard
19682
19683 c-faq
19684 \end_inset 
19685 </cell>
19686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19687 \begin_inset Text
19688
19689 \layout Standard
19690
19691 C-FAQ-list
19692 \end_inset 
19693 </cell>
19694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19695 \begin_inset Text
19696
19697 \layout Standard
19698
19699
19700 \begin_inset LatexCommand \url{http://www.eskimo.com/~scs/C-faq/top.html}
19701
19702 \end_inset 
19703
19704
19705 \end_inset 
19706 </cell>
19707 </row>
19708 <row topline="true">
19709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19710 \begin_inset Text
19711
19712 \layout Standard
19713
19714 \end_inset 
19715 </cell>
19716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19717 \begin_inset Text
19718
19719 \layout Standard
19720
19721 Latest datasheet of the target CPU
19722 \end_inset 
19723 </cell>
19724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19725 \begin_inset Text
19726
19727 \layout Standard
19728
19729 vendor
19730 \end_inset 
19731 </cell>
19732 </row>
19733 <row topline="true">
19734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19735 \begin_inset Text
19736
19737 \layout Standard
19738
19739 \end_inset 
19740 </cell>
19741 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19742 \begin_inset Text
19743
19744 \layout Standard
19745
19746 Revision history of datasheet
19747 \end_inset 
19748 </cell>
19749 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19750 \begin_inset Text
19751
19752 \layout Standard
19753
19754 vendor
19755 \end_inset 
19756 </cell>
19757 </row>
19758 <row topline="true" bottomline="true">
19759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19760 \begin_inset Text
19761
19762 \layout Standard
19763
19764 S.
19765  S.
19766  Muchnick
19767 \end_inset 
19768 </cell>
19769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19770 \begin_inset Text
19771
19772 \layout Standard
19773
19774 Advanced Compiler Design and Implementation
19775 \end_inset 
19776 </cell>
19777 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19778 \begin_inset Text
19779
19780 \layout Standard
19781
19782 bookstore (very dedicated, probably read other books first)
19783 \end_inset 
19784 </cell>
19785 </row>
19786 </lyxtabular>
19787
19788 \end_inset 
19789
19790
19791 \newline 
19792
19793 \layout Section
19794
19795 Some Questions
19796 \layout Standard
19797
19798 Some questions answered, some pointers given - it might be time to in turn
19799  ask 
19800 \emph on 
19801 you
19802 \emph default 
19803  some questions: 
19804 \layout Itemize
19805
19806 can you solve your project with the selected microcontroller? Would you
19807  find out early or rather late that your target is too small/slow/whatever?
19808  Can you switch to a slightly better device if it doesn't fit?
19809 \layout Itemize
19810
19811 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
19812  and/or another programming language be more adequate? Would an operating
19813  system on the target device help?
19814 \layout Itemize
19815
19816 if you solved the problem, will the marketing department be happy?
19817 \layout Itemize
19818
19819 if the marketing department is happy, will customers be happy?
19820 \layout Itemize
19821
19822 if you're the project manager, marketing department and maybe even the customer
19823  in one person, have you tried to see the project from the outside?
19824 \layout Itemize
19825
19826 is the project done if you think it is done? Or is just that other interface/pro
19827 tocol/feature/configuration/option missing? How about website, manual(s),
19828  internationali(z|s)ation, packaging, labels, 2nd source for components,
19829  electromagnetic compatability/interference, documentation for production,
19830  production test software, update mechanism, patent issues?
19831 \layout Itemize
19832
19833 is your project adequately positioned in that magic triangle: fame, fortune,
19834  fun?
19835 \layout Standard
19836
19837 Maybe not all answers to these questions are known and some answers may
19838  even be 
19839 \emph on 
19840 no
19841 \emph default 
19842 , nevertheless knowing these questions may help you to avoid burnout
19843 \begin_inset Foot
19844 collapsed false
19845
19846 \layout Standard
19847
19848 burnout is bad for electronic devices, programmers and motorcycle tyres
19849 \end_inset 
19850
19851 .
19852  Chances are you didn't want to hear some of them...
19853 \layout Chapter
19854
19855 Support
19856 \begin_inset LatexCommand \index{Support}
19857
19858 \end_inset 
19859
19860
19861 \layout Standard
19862
19863 SDCC has grown to be a large project.
19864  The compiler alone (without the preprocessor, assembler and linker) is
19865  well over 100,000 lines of code (blank stripped).
19866  The open source nature of this project is a key to its continued growth
19867  and support.
19868  You gain the benefit and support of many active software developers and
19869  end users.
19870  Is SDCC perfect? No, that's why we need your help.
19871  The developers take pride in fixing reported bugs.
19872  You can help by reporting the bugs and helping other SDCC users.
19873  There are lots of ways to contribute, and we encourage you to take part
19874  in making SDCC a great software package.
19875  
19876 \layout Standard
19877
19878 The SDCC project is hosted on the SDCC sourceforge site at 
19879 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
19880
19881 \end_inset 
19882
19883 .
19884  You'll find the complete set of mailing lists
19885 \begin_inset LatexCommand \index{Mailing list(s)}
19886
19887 \end_inset 
19888
19889 , forums, bug reporting system, patch submission
19890 \begin_inset LatexCommand \index{Patch submission}
19891
19892 \end_inset 
19893
19894  system, download
19895 \begin_inset LatexCommand \index{download}
19896
19897 \end_inset 
19898
19899  area and cvs code repository
19900 \begin_inset LatexCommand \index{cvs code repository}
19901
19902 \end_inset 
19903
19904  there.
19905 \layout Section
19906
19907 Reporting Bugs
19908 \begin_inset LatexCommand \index{Bug reporting}
19909
19910 \end_inset 
19911
19912
19913 \begin_inset LatexCommand \index{Reporting bugs}
19914
19915 \end_inset 
19916
19917
19918 \layout Standard
19919
19920 The recommended way of reporting bugs is using the infrastructure of the
19921  sourceforge site.
19922  You can follow the status of bug reports there and have an overview about
19923  the known bugs.
19924 \layout Standard
19925
19926 Bug reports are automatically forwarded to the developer mailing list and
19927  will be fixed ASAP.
19928  When reporting a bug, it is very useful to include a small test program
19929  (the smaller the better) which reproduces the problem.
19930  If you can isolate the problem by looking at the generated assembly code,
19931  this can be very helpful.
19932  Compiling your program with the -
19933 \begin_inset ERT
19934 status Collapsed
19935
19936 \layout Standard
19937
19938 \backslash 
19939 /
19940 \end_inset 
19941
19942 -dumpall
19943 \begin_inset LatexCommand \index{-\/-dumpall}
19944
19945 \end_inset 
19946
19947  option can sometimes be useful in locating optimization problems.
19948  When reporting a bug please maker sure you:
19949 \layout Enumerate
19950
19951 Attach the code you are compiling with SDCC.
19952  
19953 \layout Enumerate
19954
19955 Specify the exact command you use to run SDCC, or attach your Makefile.
19956  
19957 \layout Enumerate
19958
19959 Specify the SDCC version (type "
19960 \family sans 
19961 \series bold 
19962 sdcc -v
19963 \family default 
19964 \series default 
19965 "), your platform, and operating system.
19966  
19967 \layout Enumerate
19968
19969 Provide an exact copy of any error message or incorrect output.
19970  
19971 \layout Enumerate
19972
19973 Put something meaningful in the subject of your message.
19974 \layout Standard
19975
19976 Please attempt to include these 5 important parts, as applicable, in all
19977  requests for support or when reporting any problems or bugs with SDCC.
19978  Though this will make your message lengthy, it will greatly improve your
19979  chance that SDCC users and developers will be able to help you.
19980  Some SDCC developers are frustrated by bug reports without code provided
19981  that they can use to reproduce and ultimately fix the problem, so please
19982  be sure to provide sample code if you are reporting a bug! 
19983 \layout Standard
19984
19985 Please have a short check that you are using a recent version of SDCC and
19986  the bug is not yet known.
19987  This is the link for reporting bugs: 
19988 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
19989
19990 \end_inset 
19991
19992 .
19993 \layout Section
19994
19995 Requesting Features
19996 \begin_inset LatexCommand \label{sub:Requesting-Features}
19997
19998 \end_inset 
19999
20000
20001 \begin_inset LatexCommand \index{Feature request}
20002
20003 \end_inset 
20004
20005
20006 \begin_inset LatexCommand \index{Requesting features}
20007
20008 \end_inset 
20009
20010
20011 \layout Standard
20012
20013 Like bug reports feature requests are forwarded to the developer mailing
20014  list.
20015  This is the link for requesting features: 
20016 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
20017
20018 \end_inset 
20019
20020 .
20021 \layout Section
20022
20023 Submitting patches
20024 \layout Standard
20025
20026 Like bug reports contributed patches are forwarded to the developer mailing
20027  list.
20028  This is the link for submitting patches
20029 \begin_inset LatexCommand \index{Patch submission}
20030
20031 \end_inset 
20032
20033
20034 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
20035
20036 \end_inset 
20037
20038 .
20039 \layout Standard
20040
20041 You need to specify some parameters to the 
20042 \family typewriter 
20043 diff
20044 \family default 
20045  command for the patches to be useful.
20046  If you modified more than one file a patch created f.e.
20047  with 
20048 \family sans 
20049 \series bold 
20050
20051 \begin_inset Quotes sld
20052 \end_inset 
20053
20054 diff -Naur unmodified_directory modified_directory >my_changes.patch
20055 \begin_inset Quotes srd
20056 \end_inset 
20057
20058
20059 \family default 
20060 \series default 
20061  will be fine, otherwise 
20062 \family sans 
20063 \series bold 
20064
20065 \begin_inset Quotes sld
20066 \end_inset 
20067
20068 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
20069 \begin_inset Quotes srd
20070 \end_inset 
20071
20072
20073 \series default 
20074  
20075 \family default 
20076 will do.
20077 \layout Section
20078
20079 Getting Help
20080 \layout Standard
20081
20082 These links should take you directly to the 
20083 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
20084
20085 \end_inset 
20086
20087
20088 \begin_inset Foot
20089 collapsed false
20090
20091 \layout Standard
20092
20093 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
20094  automated messages (mid 2003)
20095 \end_inset 
20096
20097  and the 
20098 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
20099
20100 \end_inset 
20101
20102 , lists
20103 \begin_inset LatexCommand \index{Mailing list(s)}
20104
20105 \end_inset 
20106
20107  and forums are archived and searchable so if you are lucky someone already
20108  had a similar problem.
20109  While mails to the lists themselves are delivered promptly their web front
20110  end on sourceforge sometimes shows a severe time lag (up to several weeks),
20111  if you're seriously using SDCC please consider subscribing to the lists.
20112 \layout Section
20113
20114 ChangeLog
20115 \layout Standard
20116
20117 You can follow the status of the cvs version
20118 \begin_inset LatexCommand \index{version}
20119
20120 \end_inset 
20121
20122  of SDCC by watching the Changelog
20123 \begin_inset LatexCommand \index{Changelog}
20124
20125 \end_inset 
20126
20127  in the cvs-repository
20128 \newline 
20129
20130 \size footnotesize 
20131
20132 \begin_inset LatexCommand \htmlurl{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/sdcc/sdcc/ChangeLog?rev=HEAD&content-type=text/plain}
20133
20134 \end_inset 
20135
20136 .
20137 \layout Section
20138
20139 Release policy
20140 \begin_inset LatexCommand \index{Release policy}
20141
20142 \end_inset 
20143
20144
20145 \layout Standard
20146
20147 Historically there often were long delays between official releases and
20148  the sourceforge download area tends to get not updated at all.
20149  Excuses in the past might have referred to problems with live range analysis,
20150  but as this was fixed a while ago, the current problem is that another
20151  excuse has to be found.
20152  Kidding aside, we have to get better there! On the other hand there are
20153  daily snapshots available at 
20154 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
20155
20156 \end_inset 
20157
20158 , and you can always build the very last version (hopefully with many bugs
20159  fixed, and features added) from the source code available at 
20160 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
20161
20162 \end_inset 
20163
20164 .
20165 \layout Section
20166
20167 Examples
20168 \begin_inset LatexCommand \index{Examples}
20169
20170 \end_inset 
20171
20172
20173 \layout Standard
20174
20175 You'll find some small examples in the directory 
20176 \emph on 
20177 sdcc/device/examples/.
20178  
20179 \emph default 
20180 More examples and libraries are available at
20181 \emph on 
20182  The SDCC Open Knowledge Resource 
20183 \begin_inset LatexCommand \url{http://www.qsl.net/dl9sec/SDCC_OKR.html}
20184
20185 \end_inset 
20186
20187  
20188 \emph default 
20189 web site or at 
20190 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
20191
20192 \end_inset 
20193
20194 .
20195 \layout Comment
20196
20197 I did insert a reference to Paul's web site here although it seems rather
20198  dedicated to a specific 8032 board (I think it's okay because it f.e.
20199  shows LCD/Harddisc interface and has a free 8051 monitor.
20200  Independent 8032 board vendors face hard competition of heavily subsidized
20201  development boards anyway).
20202 \layout Comment
20203
20204 Maybe we should include some links to real world applications.
20205  Preferably pointer to pointers (one for each architecture) so this stays
20206  manageable here?
20207 \layout Section
20208
20209 Quality control
20210 \begin_inset LatexCommand \index{Quality control}
20211
20212 \end_inset 
20213
20214
20215 \layout Standard
20216
20217 The compiler is passed through nightly compile and build checks.
20218  The so called 
20219 \shape italic 
20220 regression tests
20221 \shape default 
20222
20223 \begin_inset LatexCommand \index{Regression test}
20224
20225 \end_inset 
20226
20227  check that SDCC itself compiles flawlessly on several platforms and checks
20228  the quality of the code generated by SDCC by running the code through simulator
20229 s.
20230  There is a separate document 
20231 \shape italic 
20232 test_suite.pdf
20233 \begin_inset LatexCommand \index{Test suite}
20234
20235 \end_inset 
20236
20237
20238 \shape default 
20239  about this.
20240 \layout Standard
20241
20242 You'll find the test code in the directory 
20243 \shape italic 
20244 sdcc/support/regression
20245 \shape default 
20246 .
20247  You can run these tests manually by running 
20248 \family sans 
20249 make
20250 \family default 
20251  in this directory (or f.e.
20252  
20253 \family sans 
20254 \series bold 
20255
20256 \begin_inset Quotes sld
20257 \end_inset 
20258
20259 make test-mcs51
20260 \begin_inset Quotes srd
20261 \end_inset 
20262
20263
20264 \family default 
20265 \series default 
20266  if you don't want to run the complete tests).
20267  The test code might also be interesting if you want to look for examples
20268 \begin_inset LatexCommand \index{Examples}
20269
20270 \end_inset 
20271
20272  checking corner cases of SDCC or if you plan to submit patches
20273 \begin_inset LatexCommand \index{Patch submission}
20274
20275 \end_inset 
20276
20277 .
20278 \layout Standard
20279
20280 The pic port uses a different set of regression tests, you'll find them
20281  in the directory 
20282 \shape italic 
20283 sdcc/src/regression
20284 \shape default 
20285 .
20286 \layout Chapter
20287 \pagebreak_top 
20288 SDCC Technical Data
20289 \layout Section
20290
20291 Optimizations
20292 \begin_inset LatexCommand \index{Optimizations}
20293
20294 \end_inset 
20295
20296
20297 \layout Standard
20298
20299 SDCC performs a host of standard optimizations in addition to some MCU specific
20300  optimizations.
20301  
20302 \layout Subsection
20303
20304 Sub-expression Elimination
20305 \begin_inset LatexCommand \index{Subexpression elimination}
20306
20307 \end_inset 
20308
20309
20310 \layout Standard
20311
20312 The compiler does local and 
20313 \emph on 
20314 g
20315 \emph default 
20316 lobal 
20317 \emph on 
20318 c
20319 \emph default 
20320 ommon 
20321 \emph on 
20322 s
20323 \emph default 
20324 ubexpression 
20325 \emph on 
20326 e
20327 \emph default 
20328 limination, e.g.: 
20329 \layout Verse
20330
20331
20332 \family typewriter 
20333 i = x + y + 1; 
20334 \newline 
20335 j = x + y;
20336 \layout Standard
20337
20338 will be translated to
20339 \layout Verse
20340
20341
20342 \family typewriter 
20343 iTemp = x + y; 
20344 \newline 
20345 i = iTemp + 1; 
20346 \newline 
20347 j = iTemp;
20348 \layout Standard
20349
20350 Some subexpressions are not as obvious as the above example, e.g.:
20351 \layout Verse
20352
20353
20354 \family typewriter 
20355 a->b[i].c = 10; 
20356 \newline 
20357 a->b[i].d = 11;
20358 \layout Standard
20359
20360 In this case the address arithmetic a->b[i] will be computed only once;
20361  the equivalent code in C would be.
20362 \layout Verse
20363
20364
20365 \family typewriter 
20366 iTemp = a->b[i]; 
20367 \newline 
20368 iTemp.c = 10; 
20369 \newline 
20370 iTemp.d = 11;
20371 \layout Standard
20372
20373 The compiler will try to keep these temporary variables in registers.
20374 \layout Subsection
20375
20376 Dead-Code Elimination
20377 \begin_inset LatexCommand \index{Dead-code elimination}
20378
20379 \end_inset 
20380
20381
20382 \layout Verse
20383
20384
20385 \family typewriter 
20386 int global;
20387 \newline 
20388
20389 \newline 
20390 void f () { 
20391 \newline 
20392 \SpecialChar ~
20393 \SpecialChar ~
20394 int i; 
20395 \newline 
20396 \SpecialChar ~
20397 \SpecialChar ~
20398 i = 1; \SpecialChar ~
20399 \SpecialChar ~
20400 \SpecialChar ~
20401 \SpecialChar ~
20402 \SpecialChar ~
20403 /* dead store */ 
20404 \newline 
20405 \SpecialChar ~
20406 \SpecialChar ~
20407 global = 1;\SpecialChar ~
20408 /* dead store */ 
20409 \newline 
20410 \SpecialChar ~
20411 \SpecialChar ~
20412 global = 2; 
20413 \newline 
20414 \SpecialChar ~
20415 \SpecialChar ~
20416 return; 
20417 \newline 
20418 \SpecialChar ~
20419 \SpecialChar ~
20420 global = 3;\SpecialChar ~
20421 /* unreachable */ 
20422 \newline 
20423 }
20424 \layout Standard
20425
20426 will be changed to
20427 \layout Verse
20428
20429
20430 \family typewriter 
20431 int global;
20432 \newline 
20433
20434 \newline 
20435 void f () {
20436 \newline 
20437 \SpecialChar ~
20438 \SpecialChar ~
20439 global = 2; 
20440 \newline 
20441 }
20442 \layout Subsection
20443
20444 Copy-Propagation
20445 \begin_inset LatexCommand \index{Copy propagation}
20446
20447 \end_inset 
20448
20449
20450 \layout Verse
20451
20452
20453 \family typewriter 
20454 int f() { 
20455 \newline 
20456 \SpecialChar ~
20457 \SpecialChar ~
20458 int i, j; 
20459 \newline 
20460 \SpecialChar ~
20461 \SpecialChar ~
20462 i = 10; 
20463 \newline 
20464 \SpecialChar ~
20465 \SpecialChar ~
20466 j = i; 
20467 \newline 
20468 \SpecialChar ~
20469 \SpecialChar ~
20470 return j; 
20471 \newline 
20472 }
20473 \layout Standard
20474
20475 will be changed to 
20476 \layout Verse
20477
20478
20479 \family typewriter 
20480 int f() { 
20481 \newline 
20482 \SpecialChar ~
20483 \SpecialChar ~
20484 int i, j; 
20485 \newline 
20486 \SpecialChar ~
20487 \SpecialChar ~
20488 i = 10; 
20489 \newline 
20490 \SpecialChar ~
20491 \SpecialChar ~
20492 j = 10; 
20493 \newline 
20494 \SpecialChar ~
20495 \SpecialChar ~
20496 return 10; 
20497 \newline 
20498 }
20499 \layout Standard
20500
20501 Note: the dead stores created by this copy propagation will be eliminated
20502  by dead-code elimination.
20503 \layout Subsection
20504
20505 Loop Optimizations
20506 \begin_inset LatexCommand \index{Loop optimization}
20507
20508 \end_inset 
20509
20510
20511 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
20512
20513 \end_inset 
20514
20515
20516 \layout Standard
20517
20518 Two types of loop optimizations are done by SDCC 
20519 \emph on 
20520 loop invariant
20521 \emph default 
20522  lifting and
20523 \emph on 
20524  strength reduction
20525 \emph default 
20526  of loop induction variables.
20527  In addition to the strength reduction the optimizer marks the induction
20528  variables and the register allocator tries to keep the induction variables
20529  in registers for the duration of the loop.
20530  Because of this preference of the register allocator
20531 \begin_inset LatexCommand \index{Register allocation}
20532
20533 \end_inset 
20534
20535 , loop induction optimization causes an increase in register pressure, which
20536  may cause unwanted spilling of other temporary variables into the stack
20537 \begin_inset LatexCommand \index{stack}
20538
20539 \end_inset 
20540
20541  / data space.
20542  The compiler will generate a warning message when it is forced to allocate
20543  extra space either on the stack or data space.
20544  If this extra space allocation is undesirable then induction optimization
20545  can be eliminated either for the entire source file (with -
20546 \begin_inset ERT
20547 status Collapsed
20548
20549 \layout Standard
20550
20551 \backslash 
20552 /
20553 \end_inset 
20554
20555 -noinduction option) or for a given function only using #pragma\SpecialChar ~
20556 noinduction
20557 \begin_inset LatexCommand \index{\#pragma noinduction}
20558
20559 \end_inset 
20560
20561 .
20562 \newline 
20563
20564 \newline 
20565 Loop Invariant:
20566 \layout Verse
20567
20568
20569 \family typewriter 
20570 for (i = 0 ; i < 100 ; i ++) 
20571 \newline 
20572 \SpecialChar ~
20573 \SpecialChar ~
20574 \SpecialChar ~
20575 \SpecialChar ~
20576 f += k + l;
20577 \layout Standard
20578
20579 changed to
20580 \layout Verse
20581
20582
20583 \family typewriter 
20584 itemp = k + l; 
20585 \newline 
20586 for (i = 0; i < 100; i++) 
20587 \newline 
20588 \SpecialChar ~
20589 \SpecialChar ~
20590 \SpecialChar ~
20591 \SpecialChar ~
20592 f += itemp;
20593 \layout Standard
20594
20595 As mentioned previously some loop invariants are not as apparent, all static
20596  address computations are also moved out of the loop.
20597 \newline 
20598
20599 \newline 
20600 Strength Reduction
20601 \begin_inset LatexCommand \index{Strength reduction}
20602
20603 \end_inset 
20604
20605 , this optimization substitutes an expression by a cheaper expression:
20606 \layout Verse
20607
20608
20609 \family typewriter 
20610 for (i=0;i < 100; i++)
20611 \newline 
20612 \SpecialChar ~
20613 \SpecialChar ~
20614 \SpecialChar ~
20615 \SpecialChar ~
20616 ar[i*5] = i*3;
20617 \layout Standard
20618
20619 changed to
20620 \layout Verse
20621
20622
20623 \family typewriter 
20624 itemp1 = 0; 
20625 \newline 
20626 itemp2 = 0; 
20627 \newline 
20628 for (i=0;i< 100;i++) { 
20629 \newline 
20630 \SpecialChar ~
20631 \SpecialChar ~
20632 \SpecialChar ~
20633 \SpecialChar ~
20634 ar[itemp1] = itemp2; 
20635 \newline 
20636 \SpecialChar ~
20637 \SpecialChar ~
20638 \SpecialChar ~
20639 \SpecialChar ~
20640 itemp1 += 5; 
20641 \newline 
20642 \SpecialChar ~
20643 \SpecialChar ~
20644 \SpecialChar ~
20645 \SpecialChar ~
20646 itemp2 += 3; 
20647 \newline 
20648 }
20649 \layout Standard
20650
20651 The more expensive multiplication
20652 \begin_inset LatexCommand \index{Multiplication}
20653
20654 \end_inset 
20655
20656  is changed to a less expensive addition.
20657 \layout Subsection
20658
20659 Loop Reversing
20660 \begin_inset LatexCommand \index{Loop reversing}
20661
20662 \end_inset 
20663
20664
20665 \layout Standard
20666
20667 This optimization is done to reduce the overhead of checking loop boundaries
20668  for every iteration.
20669  Some simple loops can be reversed and implemented using a 
20670 \begin_inset Quotes eld
20671 \end_inset 
20672
20673 decrement and jump if not zero
20674 \begin_inset Quotes erd
20675 \end_inset 
20676
20677  instruction.
20678  SDCC checks for the following criterion to determine if a loop is reversible
20679  (note: more sophisticated compilers use data-dependency analysis to make
20680  this determination, SDCC uses a more simple minded analysis).
20681 \layout Itemize
20682
20683 The 'for' loop is of the form 
20684 \newline 
20685
20686 \newline 
20687
20688 \family typewriter 
20689 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
20690  += 1])
20691 \newline 
20692 \SpecialChar ~
20693 \SpecialChar ~
20694 \SpecialChar ~
20695 \SpecialChar ~
20696 <for body>
20697 \layout Itemize
20698
20699 The <for body> does not contain 
20700 \begin_inset Quotes eld
20701 \end_inset 
20702
20703 continue
20704 \begin_inset Quotes erd
20705 \end_inset 
20706
20707  or 'break
20708 \begin_inset Quotes erd
20709 \end_inset 
20710
20711 .
20712 \layout Itemize
20713
20714 All goto's are contained within the loop.
20715 \layout Itemize
20716
20717 No function calls within the loop.
20718 \layout Itemize
20719
20720 The loop control variable <sym> is not assigned any value within the loop
20721 \layout Itemize
20722
20723 The loop control variable does NOT participate in any arithmetic operation
20724  within the loop.
20725 \layout Itemize
20726
20727 There are NO switch statements in the loop.
20728 \layout Subsection
20729
20730 Algebraic Simplifications
20731 \layout Standard
20732
20733 SDCC does numerous algebraic simplifications, the following is a small sub-set
20734  of these optimizations.
20735 \layout Verse
20736
20737
20738 \family typewriter 
20739 i = j + 0;\SpecialChar ~
20740 \SpecialChar ~
20741 \SpecialChar ~
20742 \SpecialChar ~
20743  /* changed to: */\SpecialChar ~
20744 \SpecialChar ~
20745 \SpecialChar ~
20746 \SpecialChar ~
20747  i = j; 
20748 \newline 
20749 i /= 2;\SpecialChar ~
20750 \SpecialChar ~
20751 \SpecialChar ~
20752 \SpecialChar ~
20753 \SpecialChar ~
20754 \SpecialChar ~
20755 \SpecialChar ~
20756  /* changed to: */\SpecialChar ~
20757 \SpecialChar ~
20758 \SpecialChar ~
20759 \SpecialChar ~
20760  i >>= 1; 
20761 \newline 
20762 i = j - j;\SpecialChar ~
20763 \SpecialChar ~
20764 \SpecialChar ~
20765 \SpecialChar ~
20766  /* changed to: */\SpecialChar ~
20767 \SpecialChar ~
20768 \SpecialChar ~
20769 \SpecialChar ~
20770  i = 0; 
20771 \newline 
20772 i = j / 1;\SpecialChar ~
20773 \SpecialChar ~
20774 \SpecialChar ~
20775 \SpecialChar ~
20776  /* changed to: */\SpecialChar ~
20777 \SpecialChar ~
20778 \SpecialChar ~
20779 \SpecialChar ~
20780  i = j;
20781 \layout Standard
20782
20783 Note the subexpressions
20784 \begin_inset LatexCommand \index{Subexpression}
20785
20786 \end_inset 
20787
20788  given above are generally introduced by macro expansions or as a result
20789  of copy/constant propagation.
20790 \layout Subsection
20791
20792 'switch' Statements
20793 \begin_inset LatexCommand \label{sub:'switch'-Statements}
20794
20795 \end_inset 
20796
20797
20798 \begin_inset LatexCommand \index{switch statement}
20799
20800 \end_inset 
20801
20802
20803 \layout Standard
20804
20805 SDCC can optimize switch statements to jump tables
20806 \begin_inset LatexCommand \index{jump tables}
20807
20808 \end_inset 
20809
20810 .
20811  It makes the decision based on an estimate of the generated code size.
20812  SDCC is quite liberal in the requirements for jump table generation: 
20813 \layout Itemize
20814
20815 The labels need not be in order, and the starting number need not be one
20816  or zero, the case labels are in numerical sequence or not too many case
20817  labels are missing.
20818 \begin_deeper 
20819 \layout Verse
20820
20821
20822 \family typewriter 
20823 switch(i) {\SpecialChar ~
20824 \SpecialChar ~
20825 \SpecialChar ~
20826 \SpecialChar ~
20827 \SpecialChar ~
20828 \SpecialChar ~
20829 \SpecialChar ~
20830 \SpecialChar ~
20831 \SpecialChar ~
20832 \SpecialChar ~
20833 \SpecialChar ~
20834 \SpecialChar ~
20835 \SpecialChar ~
20836 \SpecialChar ~
20837 \SpecialChar ~
20838 \SpecialChar ~
20839 \SpecialChar ~
20840 \SpecialChar ~
20841 \SpecialChar ~
20842 \SpecialChar ~
20843 \SpecialChar ~
20844 \SpecialChar ~
20845 \SpecialChar ~
20846 \SpecialChar ~
20847 \SpecialChar ~
20848 \SpecialChar ~
20849 switch (i) { 
20850 \newline 
20851 \SpecialChar ~
20852 \SpecialChar ~
20853 \SpecialChar ~
20854 case 4: ...\SpecialChar ~
20855 \SpecialChar ~
20856 \SpecialChar ~
20857 \SpecialChar ~
20858 \SpecialChar ~
20859 \SpecialChar ~
20860 \SpecialChar ~
20861 \SpecialChar ~
20862 \SpecialChar ~
20863 \SpecialChar ~
20864 \SpecialChar ~
20865 \SpecialChar ~
20866 \SpecialChar ~
20867 \SpecialChar ~
20868 \SpecialChar ~
20869 \SpecialChar ~
20870 \SpecialChar ~
20871 \SpecialChar ~
20872 \SpecialChar ~
20873 \SpecialChar ~
20874 \SpecialChar ~
20875 \SpecialChar ~
20876 \SpecialChar ~
20877 \SpecialChar ~
20878 \SpecialChar ~
20879 \SpecialChar ~
20880 case 0: ...
20881  
20882 \newline 
20883 \SpecialChar ~
20884 \SpecialChar ~
20885 \SpecialChar ~
20886 case 5: ...\SpecialChar ~
20887 \SpecialChar ~
20888 \SpecialChar ~
20889 \SpecialChar ~
20890 \SpecialChar ~
20891 \SpecialChar ~
20892 \SpecialChar ~
20893 \SpecialChar ~
20894 \SpecialChar ~
20895 \SpecialChar ~
20896 \SpecialChar ~
20897 \SpecialChar ~
20898 \SpecialChar ~
20899 \SpecialChar ~
20900 \SpecialChar ~
20901 \SpecialChar ~
20902 \SpecialChar ~
20903 \SpecialChar ~
20904 \SpecialChar ~
20905 \SpecialChar ~
20906 \SpecialChar ~
20907 \SpecialChar ~
20908 \SpecialChar ~
20909 \SpecialChar ~
20910 \SpecialChar ~
20911 \SpecialChar ~
20912 case 1: ...
20913  
20914 \newline 
20915 \SpecialChar ~
20916 \SpecialChar ~
20917 \SpecialChar ~
20918 case 3: ...\SpecialChar ~
20919 \SpecialChar ~
20920 \SpecialChar ~
20921 \SpecialChar ~
20922 \SpecialChar ~
20923 \SpecialChar ~
20924 \SpecialChar ~
20925 \SpecialChar ~
20926 \SpecialChar ~
20927 \SpecialChar ~
20928 \SpecialChar ~
20929 \SpecialChar ~
20930 \SpecialChar ~
20931 \SpecialChar ~
20932 \SpecialChar ~
20933 \SpecialChar ~
20934 \SpecialChar ~
20935 \SpecialChar ~
20936 \SpecialChar ~
20937 \SpecialChar ~
20938 \SpecialChar ~
20939 \SpecialChar ~
20940 \SpecialChar ~
20941 \SpecialChar ~
20942 \SpecialChar ~
20943 \SpecialChar ~
20944
20945 \newline 
20946 \SpecialChar ~
20947 \SpecialChar ~
20948 \SpecialChar ~
20949 case 6: ...\SpecialChar ~
20950 \SpecialChar ~
20951 \SpecialChar ~
20952 \SpecialChar ~
20953 \SpecialChar ~
20954 \SpecialChar ~
20955 \SpecialChar ~
20956 \SpecialChar ~
20957 \SpecialChar ~
20958 \SpecialChar ~
20959 \SpecialChar ~
20960 \SpecialChar ~
20961 \SpecialChar ~
20962 \SpecialChar ~
20963 \SpecialChar ~
20964 \SpecialChar ~
20965 \SpecialChar ~
20966 \SpecialChar ~
20967 \SpecialChar ~
20968 \SpecialChar ~
20969 \SpecialChar ~
20970 \SpecialChar ~
20971 \SpecialChar ~
20972 \SpecialChar ~
20973 \SpecialChar ~
20974 \SpecialChar ~
20975 case 3: ...
20976  
20977 \newline 
20978 \SpecialChar ~
20979 \SpecialChar ~
20980 \SpecialChar ~
20981 case 7: ...\SpecialChar ~
20982 \SpecialChar ~
20983 \SpecialChar ~
20984 \SpecialChar ~
20985 \SpecialChar ~
20986 \SpecialChar ~
20987 \SpecialChar ~
20988 \SpecialChar ~
20989 \SpecialChar ~
20990 \SpecialChar ~
20991 \SpecialChar ~
20992 \SpecialChar ~
20993 \SpecialChar ~
20994 \SpecialChar ~
20995 \SpecialChar ~
20996 \SpecialChar ~
20997 \SpecialChar ~
20998 \SpecialChar ~
20999 \SpecialChar ~
21000 \SpecialChar ~
21001 \SpecialChar ~
21002 \SpecialChar ~
21003 \SpecialChar ~
21004 \SpecialChar ~
21005 \SpecialChar ~
21006 \SpecialChar ~
21007 case 4: ...
21008  
21009 \newline 
21010 \SpecialChar ~
21011 \SpecialChar ~
21012 \SpecialChar ~
21013 case 8: ...\SpecialChar ~
21014 \SpecialChar ~
21015 \SpecialChar ~
21016 \SpecialChar ~
21017 \SpecialChar ~
21018 \SpecialChar ~
21019 \SpecialChar ~
21020 \SpecialChar ~
21021 \SpecialChar ~
21022 \SpecialChar ~
21023 \SpecialChar ~
21024 \SpecialChar ~
21025 \SpecialChar ~
21026 \SpecialChar ~
21027 \SpecialChar ~
21028 \SpecialChar ~
21029 \SpecialChar ~
21030 \SpecialChar ~
21031 \SpecialChar ~
21032 \SpecialChar ~
21033 \SpecialChar ~
21034 \SpecialChar ~
21035 \SpecialChar ~
21036 \SpecialChar ~
21037 \SpecialChar ~
21038 \SpecialChar ~
21039 case 5: ...
21040  
21041 \newline 
21042 \SpecialChar ~
21043 \SpecialChar ~
21044 \SpecialChar ~
21045 case 9: ...\SpecialChar ~
21046 \SpecialChar ~
21047 \SpecialChar ~
21048 \SpecialChar ~
21049 \SpecialChar ~
21050 \SpecialChar ~
21051 \SpecialChar ~
21052 \SpecialChar ~
21053 \SpecialChar ~
21054 \SpecialChar ~
21055 \SpecialChar ~
21056 \SpecialChar ~
21057 \SpecialChar ~
21058 \SpecialChar ~
21059 \SpecialChar ~
21060 \SpecialChar ~
21061 \SpecialChar ~
21062 \SpecialChar ~
21063 \SpecialChar ~
21064 \SpecialChar ~
21065 \SpecialChar ~
21066 \SpecialChar ~
21067 \SpecialChar ~
21068 \SpecialChar ~
21069 \SpecialChar ~
21070 \SpecialChar ~
21071 case 6: ...
21072  
21073 \newline 
21074 \SpecialChar ~
21075 \SpecialChar ~
21076 \SpecialChar ~
21077 case 10: ...\SpecialChar ~
21078 \SpecialChar ~
21079 \SpecialChar ~
21080 \SpecialChar ~
21081 \SpecialChar ~
21082 \SpecialChar ~
21083 \SpecialChar ~
21084 \SpecialChar ~
21085 \SpecialChar ~
21086 \SpecialChar ~
21087 \SpecialChar ~
21088 \SpecialChar ~
21089 \SpecialChar ~
21090 \SpecialChar ~
21091 \SpecialChar ~
21092 \SpecialChar ~
21093 \SpecialChar ~
21094 \SpecialChar ~
21095 \SpecialChar ~
21096 \SpecialChar ~
21097 \SpecialChar ~
21098 \SpecialChar ~
21099 \SpecialChar ~
21100 \SpecialChar ~
21101 \SpecialChar ~
21102 case 7: ...
21103  
21104 \newline 
21105 \SpecialChar ~
21106 \SpecialChar ~
21107 \SpecialChar ~
21108 case 11: ...\SpecialChar ~
21109 \SpecialChar ~
21110 \SpecialChar ~
21111 \SpecialChar ~
21112 \SpecialChar ~
21113 \SpecialChar ~
21114 \SpecialChar ~
21115 \SpecialChar ~
21116 \SpecialChar ~
21117 \SpecialChar ~
21118 \SpecialChar ~
21119 \SpecialChar ~
21120 \SpecialChar ~
21121 \SpecialChar ~
21122 \SpecialChar ~
21123 \SpecialChar ~
21124 \SpecialChar ~
21125 \SpecialChar ~
21126 \SpecialChar ~
21127 \SpecialChar ~
21128 \SpecialChar ~
21129 \SpecialChar ~
21130 \SpecialChar ~
21131 \SpecialChar ~
21132 \SpecialChar ~
21133 case 8: ...
21134  
21135 \newline 
21136 }\SpecialChar ~
21137 \SpecialChar ~
21138 \SpecialChar ~
21139 \SpecialChar ~
21140 \SpecialChar ~
21141 \SpecialChar ~
21142 \SpecialChar ~
21143 \SpecialChar ~
21144 \SpecialChar ~
21145 \SpecialChar ~
21146 \SpecialChar ~
21147 \SpecialChar ~
21148 \SpecialChar ~
21149 \SpecialChar ~
21150 \SpecialChar ~
21151 \SpecialChar ~
21152 \SpecialChar ~
21153 \SpecialChar ~
21154 \SpecialChar ~
21155 \SpecialChar ~
21156 \SpecialChar ~
21157 \SpecialChar ~
21158 \SpecialChar ~
21159 \SpecialChar ~
21160 \SpecialChar ~
21161 \SpecialChar ~
21162 \SpecialChar ~
21163 \SpecialChar ~
21164 \SpecialChar ~
21165 \SpecialChar ~
21166 \SpecialChar ~
21167 \SpecialChar ~
21168 \SpecialChar ~
21169 \SpecialChar ~
21170 \SpecialChar ~
21171 \SpecialChar ~
21172 }
21173 \layout Standard
21174
21175 Both the above switch statements will be implemented using a jump-table.
21176  The example to the right side is slightly more efficient as the check for
21177  the lower boundary of the jump-table is not needed.
21178 \end_deeper 
21179 \layout Itemize
21180
21181 The number of case labels is not larger than supported by the target architectur
21182 e.
21183 \layout Itemize
21184
21185 If the case labels are not in numerical sequence ('gaps' between cases)
21186  SDCC checks whether a jump table with additionally inserted dummy cases
21187  is still attractive.
21188  
21189 \layout Itemize
21190
21191 If the starting number is not zero and a check for the lower boundary of
21192  the jump-table can thus be eliminated SDCC might insert dummy cases 0,
21193  ...
21194  .
21195 \layout Standard
21196
21197 Switch statements which have large gaps in the numeric sequence or those
21198  that have too many case labels can be split into more than one switch statement
21199  for efficient code generation, e.g.:
21200 \layout Verse
21201
21202
21203 \family typewriter 
21204 switch (i) { 
21205 \newline 
21206 \SpecialChar ~
21207 \SpecialChar ~
21208 case 1: ...
21209  
21210 \newline 
21211 \SpecialChar ~
21212 \SpecialChar ~
21213 case 2: ...
21214  
21215 \newline 
21216 \SpecialChar ~
21217 \SpecialChar ~
21218 case 3: ...
21219  
21220 \newline 
21221 \SpecialChar ~
21222 \SpecialChar ~
21223 case 4: ...
21224  
21225 \newline 
21226 \SpecialChar ~
21227 \SpecialChar ~
21228 case 5: ...
21229  
21230 \newline 
21231 \SpecialChar ~
21232 \SpecialChar ~
21233 case 6: ...
21234  
21235 \newline 
21236 \SpecialChar ~
21237 \SpecialChar ~
21238 case 7: ...
21239  
21240 \newline 
21241 \SpecialChar ~
21242 \SpecialChar ~
21243 case 101: ...
21244  
21245 \newline 
21246 \SpecialChar ~
21247 \SpecialChar ~
21248 case 102: ...
21249  
21250 \newline 
21251 \SpecialChar ~
21252 \SpecialChar ~
21253 case 103: ...
21254  
21255 \newline 
21256 \SpecialChar ~
21257 \SpecialChar ~
21258 case 104: ...
21259  
21260 \newline 
21261 \SpecialChar ~
21262 \SpecialChar ~
21263 case 105: ...
21264  
21265 \newline 
21266 \SpecialChar ~
21267 \SpecialChar ~
21268 case 106: ...
21269  
21270 \newline 
21271 \SpecialChar ~
21272 \SpecialChar ~
21273 case 107: ...
21274  
21275 \newline 
21276 }
21277 \layout Standard
21278
21279 If the above switch statement is broken down into two switch statements
21280 \layout Verse
21281
21282
21283 \family typewriter 
21284 switch (i) { 
21285 \newline 
21286 \SpecialChar ~
21287 \SpecialChar ~
21288 case 1: ...
21289  
21290 \newline 
21291 \SpecialChar ~
21292 \SpecialChar ~
21293 case 2: ...
21294  
21295 \newline 
21296 \SpecialChar ~
21297 \SpecialChar ~
21298 case 3: ...
21299  
21300 \newline 
21301 \SpecialChar ~
21302 \SpecialChar ~
21303 case 4: ...
21304  
21305 \newline 
21306 \SpecialChar ~
21307 \SpecialChar ~
21308 case 5: ...
21309  
21310 \newline 
21311 \SpecialChar ~
21312 \SpecialChar ~
21313 case 6: ...
21314  
21315 \newline 
21316 \SpecialChar ~
21317 \SpecialChar ~
21318 case 7: ...
21319  
21320 \newline 
21321 }
21322 \layout Standard
21323
21324 and
21325 \layout Verse
21326
21327
21328 \family typewriter 
21329 switch (i) { 
21330 \newline 
21331 \SpecialChar ~
21332 \SpecialChar ~
21333 case 101: ...
21334  
21335 \newline 
21336 \SpecialChar ~
21337 \SpecialChar ~
21338 case 102: ...
21339  
21340 \newline 
21341 \SpecialChar ~
21342 \SpecialChar ~
21343 case 103: ...
21344  
21345 \newline 
21346 \SpecialChar ~
21347 \SpecialChar ~
21348 case 104: ...
21349  
21350 \newline 
21351 \SpecialChar ~
21352 \SpecialChar ~
21353 case 105: ...
21354  
21355 \newline 
21356 \SpecialChar ~
21357 \SpecialChar ~
21358 case 106: ...
21359  
21360 \newline 
21361 \SpecialChar ~
21362 \SpecialChar ~
21363 case 107: ...
21364  
21365 \newline 
21366 }
21367 \layout Standard
21368
21369 then both the switch statements will be implemented using jump-tables whereas
21370  the unmodified switch statement will not be.
21371 \layout Comment
21372
21373 There might be reasons which SDCC cannot know about to either favour or
21374  not favour jump tables.
21375  If the target system has to be as quick for the last switch case as for
21376  the first (pro jump table), or if the switch argument is known to be zero
21377  in the majority of the cases (contra jump table).
21378 \layout Standard
21379
21380 The pragma nojtbound
21381 \begin_inset LatexCommand \index{\#pragma nojtbound}
21382
21383 \end_inset 
21384
21385  can be used to turn off checking the 
21386 \emph on 
21387 j
21388 \emph default 
21389 ump 
21390 \emph on 
21391 t
21392 \emph default 
21393 able 
21394 \emph on 
21395 bound
21396 \emph default 
21397 aries.
21398  It has no effect if a default label is supplied.
21399  Use of this pragma is dangerous: if the switch argument is not matched
21400  by a case statement the processor will happily jump into Nirvana.
21401 \layout Subsection
21402
21403 Bit-shifting Operations
21404 \begin_inset LatexCommand \index{Bit shifting}
21405
21406 \end_inset 
21407
21408 .
21409 \layout Standard
21410
21411 Bit shifting is one of the most frequently used operation in embedded programmin
21412 g.
21413  SDCC tries to implement bit-shift operations in the most efficient way
21414  possible, e.g.:
21415 \layout Verse
21416
21417
21418 \family typewriter 
21419 unsigned char i;
21420 \newline 
21421 ...
21422  
21423 \newline 
21424 i >>= 4; 
21425 \newline 
21426 ...
21427 \layout Standard
21428
21429 generates the following code:
21430 \layout Verse
21431
21432
21433 \family typewriter 
21434 mov\SpecialChar ~
21435  a,_i 
21436 \newline 
21437 swap a 
21438 \newline 
21439 anl\SpecialChar ~
21440  a,#0x0f 
21441 \newline 
21442 mov\SpecialChar ~
21443  _i,a
21444 \layout Standard
21445
21446 In general SDCC will never setup a loop if the shift count is known.
21447  Another example:
21448 \layout Verse
21449
21450
21451 \family typewriter 
21452 unsigned int i; 
21453 \newline 
21454 ...
21455  
21456 \newline 
21457 i >>= 9; 
21458 \newline 
21459 ...
21460 \layout Standard
21461
21462 will generate:
21463 \layout Verse
21464
21465
21466 \family typewriter 
21467 mov\SpecialChar ~
21468 \SpecialChar ~
21469 a,(_i + 1) 
21470 \newline 
21471 mov\SpecialChar ~
21472 \SpecialChar ~
21473 (_i + 1),#0x00 
21474 \newline 
21475 clr\SpecialChar ~
21476 \SpecialChar ~
21477
21478 \newline 
21479 rrc\SpecialChar ~
21480 \SpecialChar ~
21481
21482 \newline 
21483 mov\SpecialChar ~
21484 \SpecialChar ~
21485 _i,a
21486 \layout Subsection
21487
21488 Bit-rotation
21489 \begin_inset LatexCommand \index{Bit rotation}
21490
21491 \end_inset 
21492
21493
21494 \layout Standard
21495
21496 A special case of the bit-shift operation is bit rotation
21497 \begin_inset LatexCommand \index{rotating bits}
21498
21499 \end_inset 
21500
21501 , SDCC recognizes the following expression to be a left bit-rotation:
21502 \layout Verse
21503
21504
21505 \family typewriter 
21506 \series bold 
21507 unsigned
21508 \series default 
21509 \SpecialChar ~
21510 \SpecialChar ~
21511 char i;\SpecialChar ~
21512 \SpecialChar ~
21513 \SpecialChar ~
21514 \SpecialChar ~
21515 \SpecialChar ~
21516 \SpecialChar ~
21517 \SpecialChar ~
21518 \SpecialChar ~
21519 \SpecialChar ~
21520 \SpecialChar ~
21521 \SpecialChar ~
21522 /* unsigned is needed for rotation */ 
21523 \newline 
21524 ...
21525  
21526 \newline 
21527 i = ((i << 1) | (i >> 7)); 
21528 \family default 
21529
21530 \newline 
21531
21532 \family typewriter 
21533 ...
21534 \layout Standard
21535
21536 will generate the following code:
21537 \layout Verse
21538
21539
21540 \family typewriter 
21541 mov\SpecialChar ~
21542 \SpecialChar ~
21543 a,_i 
21544 \newline 
21545 rl\SpecialChar ~
21546 \SpecialChar ~
21547 \SpecialChar ~
21548
21549 \newline 
21550 mov\SpecialChar ~
21551 \SpecialChar ~
21552 _i,a
21553 \layout Standard
21554
21555 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
21556 ns of this case will also be recognized as bit-rotation, i.e.: 
21557 \layout Verse
21558
21559
21560 \family typewriter 
21561 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
21562 \layout Subsection
21563
21564 Nibble and Byte Swapping
21565 \layout Standard
21566
21567 Other special cases of the bit-shift operations are nibble or byte swapping
21568 \begin_inset LatexCommand \index{swapping nibbles/bytes}
21569
21570 \end_inset 
21571
21572 , SDCC recognizes the following expressions:
21573 \layout Verse
21574
21575
21576 \family typewriter 
21577 \series bold 
21578 unsigned
21579 \series default 
21580 \SpecialChar ~
21581 \SpecialChar ~
21582 char i; 
21583 \newline 
21584
21585 \series bold 
21586 unsigned
21587 \series default 
21588 \SpecialChar ~
21589 \SpecialChar ~
21590 int j; 
21591 \newline 
21592 ...
21593  
21594 \newline 
21595 i = ((i << 4) | (i >> 4)); 
21596 \family default 
21597
21598 \newline 
21599
21600 \family typewriter 
21601 j = ((j << 8) | (j >> 8)); 
21602 \layout Standard
21603
21604 and generates a swap instruction for the nibble swapping
21605 \begin_inset LatexCommand \index{Nibble swapping}
21606
21607 \end_inset 
21608
21609  or move instructions for the byte swapping
21610 \begin_inset LatexCommand \index{Byte swapping}
21611
21612 \end_inset 
21613
21614 .
21615  The 
21616 \begin_inset Quotes sld
21617 \end_inset 
21618
21619 j
21620 \begin_inset Quotes srd
21621 \end_inset 
21622
21623  example can be used to convert from little to big-endian or vice versa.
21624  If you want to change the endianness of a 
21625 \emph on 
21626 signed
21627 \emph default 
21628  integer you have to cast to 
21629 \family typewriter 
21630 (unsigned int)
21631 \family default 
21632  first.
21633 \layout Standard
21634
21635 Note that SDCC stores numbers in little-endian
21636 \begin_inset Foot
21637 collapsed false
21638
21639 \layout Standard
21640
21641 Usually 8-bit processors don't care much about endianness.
21642  This is not the case for the standard 8051 which only has an instruction
21643  to increment its 
21644 \emph on 
21645 dptr
21646 \emph default 
21647
21648 \begin_inset LatexCommand \index{DPTR}
21649
21650 \end_inset 
21651
21652 -datapointer
21653 \emph on 
21654  
21655 \emph default 
21656 so little-endian is the more efficient byte order.
21657 \end_inset 
21658
21659
21660 \begin_inset LatexCommand \index{little-endian}
21661
21662 \end_inset 
21663
21664
21665 \begin_inset LatexCommand \index{Endianness}
21666
21667 \end_inset 
21668
21669  format (i.e.
21670  lowest order first).
21671 \layout Subsection
21672
21673 Highest Order Bit
21674 \begin_inset LatexCommand \index{Highest Order Bit}
21675
21676 \end_inset 
21677
21678
21679 \layout Standard
21680
21681 It is frequently required to obtain the highest order bit of an integral
21682  type (long, int, short or char types).
21683  SDCC recognizes the following expression to yield the highest order bit
21684  and generates optimized code for it, e.g.:
21685 \layout Verse
21686
21687
21688 \family typewriter 
21689 unsigned int gint; 
21690 \newline 
21691
21692 \newline 
21693 foo () { 
21694 \newline 
21695 \SpecialChar ~
21696 \SpecialChar ~
21697 unsigned char hob; 
21698 \newline 
21699 \SpecialChar ~
21700 \SpecialChar ~
21701 ...
21702  
21703 \newline 
21704 \SpecialChar ~
21705 \SpecialChar ~
21706 hob = (gint >> 15) & 1; 
21707 \newline 
21708 \SpecialChar ~
21709 \SpecialChar ~
21710 ..
21711  
21712 \newline 
21713 }
21714 \layout Standard
21715
21716 will generate the following code:
21717 \layout Verse
21718
21719
21720 \family typewriter 
21721 \SpecialChar ~
21722 \SpecialChar ~
21723 \SpecialChar ~
21724 \SpecialChar ~
21725 \SpecialChar ~
21726 \SpecialChar ~
21727 \SpecialChar ~
21728 \SpecialChar ~
21729 \SpecialChar ~
21730 \SpecialChar ~
21731 \SpecialChar ~
21732 \SpecialChar ~
21733 \SpecialChar ~
21734 \SpecialChar ~
21735 \SpecialChar ~
21736 \SpecialChar ~
21737 \SpecialChar ~
21738 \SpecialChar ~
21739 \SpecialChar ~
21740 \SpecialChar ~
21741 \SpecialChar ~
21742 \SpecialChar ~
21743 \SpecialChar ~
21744 \SpecialChar ~
21745 \SpecialChar ~
21746  61 ;\SpecialChar ~
21747  hob.c 7 
21748 \newline 
21749 000A E5*01\SpecialChar ~
21750 \SpecialChar ~
21751 \SpecialChar ~
21752 \SpecialChar ~
21753 \SpecialChar ~
21754 \SpecialChar ~
21755 \SpecialChar ~
21756 \SpecialChar ~
21757 \SpecialChar ~
21758 \SpecialChar ~
21759 \SpecialChar ~
21760 \SpecialChar ~
21761 \SpecialChar ~
21762 \SpecialChar ~
21763 \SpecialChar ~
21764  62\SpecialChar ~
21765 \SpecialChar ~
21766 \SpecialChar ~
21767 \SpecialChar ~
21768 \SpecialChar ~
21769 \SpecialChar ~
21770 \SpecialChar ~
21771 \SpecialChar ~
21772  mov\SpecialChar ~
21773 \SpecialChar ~
21774  a,(_gint + 1) 
21775 \newline 
21776 000C 23\SpecialChar ~
21777 \SpecialChar ~
21778 \SpecialChar ~
21779 \SpecialChar ~
21780 \SpecialChar ~
21781 \SpecialChar ~
21782 \SpecialChar ~
21783 \SpecialChar ~
21784 \SpecialChar ~
21785 \SpecialChar ~
21786 \SpecialChar ~
21787 \SpecialChar ~
21788 \SpecialChar ~
21789 \SpecialChar ~
21790 \SpecialChar ~
21791 \SpecialChar ~
21792 \SpecialChar ~
21793 \SpecialChar ~
21794  63\SpecialChar ~
21795 \SpecialChar ~
21796 \SpecialChar ~
21797 \SpecialChar ~
21798 \SpecialChar ~
21799 \SpecialChar ~
21800 \SpecialChar ~
21801 \SpecialChar ~
21802  rl\SpecialChar ~
21803 \SpecialChar ~
21804 \SpecialChar ~
21805  a 
21806 \newline 
21807 000D 54 01\SpecialChar ~
21808 \SpecialChar ~
21809 \SpecialChar ~
21810 \SpecialChar ~
21811 \SpecialChar ~
21812 \SpecialChar ~
21813 \SpecialChar ~
21814 \SpecialChar ~
21815 \SpecialChar ~
21816 \SpecialChar ~
21817 \SpecialChar ~
21818 \SpecialChar ~
21819 \SpecialChar ~
21820 \SpecialChar ~
21821 \SpecialChar ~
21822  64\SpecialChar ~
21823 \SpecialChar ~
21824 \SpecialChar ~
21825 \SpecialChar ~
21826 \SpecialChar ~
21827 \SpecialChar ~
21828 \SpecialChar ~
21829 \SpecialChar ~
21830  anl\SpecialChar ~
21831 \SpecialChar ~
21832  a,#0x01 
21833 \newline 
21834 000F F5*02\SpecialChar ~
21835 \SpecialChar ~
21836 \SpecialChar ~
21837 \SpecialChar ~
21838 \SpecialChar ~
21839 \SpecialChar ~
21840 \SpecialChar ~
21841 \SpecialChar ~
21842 \SpecialChar ~
21843 \SpecialChar ~
21844 \SpecialChar ~
21845 \SpecialChar ~
21846 \SpecialChar ~
21847 \SpecialChar ~
21848 \SpecialChar ~
21849  65\SpecialChar ~
21850 \SpecialChar ~
21851 \SpecialChar ~
21852 \SpecialChar ~
21853 \SpecialChar ~
21854 \SpecialChar ~
21855 \SpecialChar ~
21856 \SpecialChar ~
21857  mov\SpecialChar ~
21858 \SpecialChar ~
21859  _foo_hob_1_1,a
21860 \layout Standard
21861
21862 Variations of this case however will 
21863 \emph on 
21864 not
21865 \emph default 
21866  be recognized.
21867  It is a standard C expression, so I heartily recommend this be the only
21868  way to get the highest order bit, (it is portable).
21869  Of course it will be recognized even if it is embedded in other expressions,
21870  e.g.:
21871 \layout Verse
21872
21873
21874 \family typewriter 
21875 xyz = gint + ((gint >> 15) & 1);
21876 \layout Standard
21877
21878 will still be recognized.
21879 \layout Subsection
21880
21881 Peephole Optimizer
21882 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
21883
21884 \end_inset 
21885
21886
21887 \begin_inset LatexCommand \index{Peephole optimizer}
21888
21889 \end_inset 
21890
21891
21892 \layout Standard
21893
21894 The compiler uses a rule based, pattern matching and re-writing mechanism
21895  for peep-hole optimization.
21896  It is inspired by 
21897 \emph on 
21898 copt
21899 \emph default 
21900  a peep-hole optimizer by Christopher W.
21901  Fraser (cwfraser@microsoft.com).
21902  A default set of rules are compiled into the compiler, additional rules
21903  may be added with the 
21904 \emph on 
21905 -
21906 \begin_inset ERT
21907 status Collapsed
21908
21909 \layout Standard
21910
21911 \backslash 
21912 /
21913 \end_inset 
21914
21915 -peep-file
21916 \begin_inset LatexCommand \index{-\/-peep-file}
21917
21918 \end_inset 
21919
21920  <filename>
21921 \emph default 
21922  option.
21923  The rule language is best illustrated with examples.
21924 \layout Verse
21925
21926
21927 \family typewriter 
21928 replace { 
21929 \newline 
21930 \SpecialChar ~
21931 \SpecialChar ~
21932 mov %1,a 
21933 \newline 
21934 \SpecialChar ~
21935 \SpecialChar ~
21936 mov a,%1
21937 \newline 
21938 } by {
21939 \newline 
21940 \SpecialChar ~
21941 \SpecialChar ~
21942 mov %1,a
21943 \newline 
21944 }
21945 \layout Standard
21946
21947 The above rule will change the following assembly
21948 \begin_inset LatexCommand \index{Assembler routines}
21949
21950 \end_inset 
21951
21952  sequence:
21953 \layout Verse
21954
21955
21956 \family typewriter 
21957 mov r1,a 
21958 \newline 
21959 mov a,r1
21960 \layout Standard
21961
21962 to
21963 \layout Verse
21964
21965
21966 \family typewriter 
21967 mov r1,a
21968 \layout Standard
21969
21970 Note: All occurrences of a 
21971 \emph on 
21972 %n
21973 \emph default 
21974  (pattern variable) must denote the same string.
21975  With the above rule, the assembly sequence:
21976 \layout Verse
21977
21978
21979 \family typewriter 
21980 mov r1,a 
21981 \newline 
21982 mov a,r2
21983 \layout Standard
21984
21985 will remain unmodified.
21986 \newline 
21987
21988 \newline 
21989 Other special case optimizations may be added by the user (via 
21990 \emph on 
21991 -
21992 \begin_inset ERT
21993 status Collapsed
21994
21995 \layout Standard
21996
21997 \backslash 
21998 /
21999 \end_inset 
22000
22001 -peep-file option
22002 \emph default 
22003 ).
22004  E.g.
22005  some variants of the 8051 MCU
22006 \begin_inset LatexCommand \index{MCS51 variants}
22007
22008 \end_inset 
22009
22010  allow only 
22011 \family typewriter 
22012 ajmp
22013 \family default 
22014  and 
22015 \family typewriter 
22016 acall
22017 \family default 
22018 .
22019  The following two rules will change all 
22020 \family typewriter 
22021 ljmp
22022 \family default 
22023  and 
22024 \family typewriter 
22025 lcall
22026 \family default 
22027  to 
22028 \family typewriter 
22029 ajmp
22030 \family default 
22031  and 
22032 \family typewriter 
22033 acall
22034 \layout Verse
22035
22036
22037 \family typewriter 
22038 replace { lcall %1 } by { acall %1 } 
22039 \newline 
22040 replace { ljmp %1 } by { ajmp %1 }
22041 \layout Standard
22042
22043 The 
22044 \emph on 
22045 inline-assembler code
22046 \emph default 
22047  is also passed through the peep hole optimizer, thus the peephole optimizer
22048  can also be used as an assembly level macro expander.
22049  The rules themselves are MCU dependent whereas the rule language infra-structur
22050 e is MCU independent.
22051  Peephole optimization rules for other MCU can be easily programmed using
22052  the rule language.
22053 \newline 
22054
22055 \newline 
22056 The syntax for a rule is as follows:
22057 \layout Verse
22058
22059
22060 \family typewriter 
22061 rule := replace [ restart ] '{' <assembly sequence> '
22062 \backslash 
22063 n' 
22064 \newline 
22065 \SpecialChar ~
22066  \SpecialChar ~
22067  \SpecialChar ~
22068  \SpecialChar ~
22069  \SpecialChar ~
22070  \SpecialChar ~
22071  \SpecialChar ~
22072  \SpecialChar ~
22073  \SpecialChar ~
22074  \SpecialChar ~
22075  \SpecialChar ~
22076  \SpecialChar ~
22077  \SpecialChar ~
22078  \SpecialChar ~
22079  '}' by '{' '
22080 \backslash 
22081 n' 
22082 \newline 
22083 \SpecialChar ~
22084  \SpecialChar ~
22085  \SpecialChar ~
22086  \SpecialChar ~
22087  \SpecialChar ~
22088  \SpecialChar ~
22089  \SpecialChar ~
22090  \SpecialChar ~
22091  \SpecialChar ~
22092  \SpecialChar ~
22093  \SpecialChar ~
22094  \SpecialChar ~
22095  \SpecialChar ~
22096  \SpecialChar ~
22097  \SpecialChar ~
22098  \SpecialChar ~
22099  <assembly sequence> '
22100 \backslash 
22101 n' 
22102 \newline 
22103 \SpecialChar ~
22104  \SpecialChar ~
22105  \SpecialChar ~
22106  \SpecialChar ~
22107  \SpecialChar ~
22108  \SpecialChar ~
22109  \SpecialChar ~
22110  \SpecialChar ~
22111  \SpecialChar ~
22112  \SpecialChar ~
22113  \SpecialChar ~
22114  \SpecialChar ~
22115  \SpecialChar ~
22116  \SpecialChar ~
22117  '}' [if <functionName> ] '
22118 \backslash 
22119 n' 
22120 \layout Standard
22121
22122 <assembly sequence> := assembly instruction (each instruction including
22123  labels must be on a separate line).
22124 \newline 
22125
22126 \newline 
22127 The optimizer will apply to the rules one by one from the top in the sequence
22128  of their appearance, it will terminate when all rules are exhausted.
22129  If the 'restart' option is specified, then the optimizer will start matching
22130  the rules again from the top, this option for a rule is expensive (performance)
22131 , it is intended to be used in situations where a transformation will trigger
22132  the same rule again.
22133  An example of this (not a good one, it has side effects) is the following
22134  rule:
22135 \layout Verse
22136
22137
22138 \family typewriter 
22139 replace restart { 
22140 \newline 
22141 \SpecialChar ~
22142 \SpecialChar ~
22143 pop %1 
22144 \newline 
22145 \SpecialChar ~
22146 \SpecialChar ~
22147 push %1 } by { 
22148 \newline 
22149 \SpecialChar ~
22150 \SpecialChar ~
22151 ; nop 
22152 \newline 
22153 }
22154 \layout Standard
22155
22156 Note that the replace pattern cannot be a blank, but can be a comment line.
22157  Without the 'restart' option only the innermost 'pop' 'push' pair would
22158  be eliminated, i.e.:
22159 \layout Verse
22160
22161
22162 \family typewriter 
22163 pop ar1 
22164 \newline 
22165 pop ar2 
22166 \newline 
22167 push ar2 
22168 \newline 
22169 push ar1
22170 \layout Standard
22171
22172 would result in:
22173 \layout Verse
22174
22175
22176 \family typewriter 
22177 pop ar1 
22178 \newline 
22179 ; nop 
22180 \newline 
22181 push ar1
22182 \layout Standard
22183
22184
22185 \emph on 
22186 with
22187 \emph default 
22188  the restart option the rule will be applied again to the resulting code
22189  and then all the pop-push pairs will be eliminated to yield:
22190 \layout Verse
22191
22192
22193 \family typewriter 
22194 ; nop 
22195 \newline 
22196 ; nop
22197 \layout Standard
22198
22199 A conditional function can be attached to a rule.
22200  Attaching rules are somewhat more involved, let me illustrate this with
22201  an example.
22202 \layout Verse
22203
22204
22205 \family typewriter 
22206 replace { 
22207 \newline 
22208 \SpecialChar ~
22209  \SpecialChar ~
22210  \SpecialChar ~
22211 ljmp %5 
22212 \newline 
22213 %2:
22214 \newline 
22215 } by { 
22216 \newline 
22217 \SpecialChar ~
22218  \SpecialChar ~
22219  \SpecialChar ~
22220 sjmp %5 
22221 \newline 
22222 %2:
22223 \newline 
22224 } if labelInRange
22225 \layout Standard
22226
22227 The optimizer does a look-up of a function name table defined in function
22228  
22229 \emph on 
22230 callFuncByName
22231 \emph default 
22232  in the source file SDCCpeeph.c, with the name 
22233 \emph on 
22234 labelInRange
22235 \emph default 
22236 .
22237  If it finds a corresponding entry the function is called.
22238  Note there can be no parameters specified for these functions, in this
22239  case the use of 
22240 \emph on 
22241 %5
22242 \emph default 
22243  is crucial, since the function 
22244 \emph on 
22245 labelInRange
22246 \emph default 
22247  expects to find the label in that particular variable (the hash table containin
22248 g the variable bindings is passed as a parameter).
22249  If you want to code more such functions, take a close look at the function
22250  labelInRange and the calling mechanism in source file SDCCpeeph.c.
22251  Currently implemented are 
22252 \emph on 
22253 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
22254  24bitMode, portIsDS390, 24bitModeAndPortDS390 
22255 \emph default 
22256 and
22257 \emph on 
22258  notVolatile
22259 \emph default 
22260 .
22261 \layout Standard
22262
22263 I know this whole thing is a little kludgey, but maybe some day we will
22264  have some better means.
22265  If you are looking at this file, you will see the default rules that are
22266  compiled into the compiler, you can add your own rules in the default set
22267  there if you get tired of specifying the -
22268 \begin_inset ERT
22269 status Collapsed
22270
22271 \layout Standard
22272
22273 \backslash 
22274 /
22275 \end_inset 
22276
22277 -peep-file option.
22278 \layout Section
22279
22280 ANSI-Compliance
22281 \begin_inset LatexCommand \index{ANSI-compliance}
22282
22283 \end_inset 
22284
22285
22286 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
22287
22288 \end_inset 
22289
22290
22291 \layout Standard
22292
22293 Deviations from the compliance:
22294 \layout Itemize
22295
22296 functions are not always reentrant
22297 \begin_inset LatexCommand \index{reentrant}
22298
22299 \end_inset 
22300
22301 .
22302 \layout Itemize
22303
22304 structures cannot be assigned values directly, cannot be passed as function
22305  parameters or assigned to each other and cannot be a return value from
22306  a function, e.g.:
22307 \begin_deeper 
22308 \layout Verse
22309
22310
22311 \family typewriter 
22312 struct s { ...
22313  }; 
22314 \newline 
22315 struct s s1, s2; 
22316 \newline 
22317 foo() 
22318 \newline 
22319
22320 \newline 
22321 \SpecialChar ~
22322 \SpecialChar ~
22323 \SpecialChar ~
22324 \SpecialChar ~
22325 ...
22326  
22327 \newline 
22328 \SpecialChar ~
22329 \SpecialChar ~
22330 \SpecialChar ~
22331 \SpecialChar ~
22332 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
22333 \newline 
22334 \SpecialChar ~
22335 \SpecialChar ~
22336 \SpecialChar ~
22337 \SpecialChar ~
22338 ...
22339  
22340 \newline 
22341 }
22342 \newline 
22343 struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
22344  */
22345 \newline 
22346
22347 \newline 
22348 \SpecialChar ~
22349 \SpecialChar ~
22350 \SpecialChar ~
22351 \SpecialChar ~
22352 struct s rets; 
22353 \newline 
22354 \SpecialChar ~
22355 \SpecialChar ~
22356 \SpecialChar ~
22357 \SpecialChar ~
22358 ...
22359  
22360 \newline 
22361 \SpecialChar ~
22362 \SpecialChar ~
22363 \SpecialChar ~
22364 \SpecialChar ~
22365 return rets;/* is invalid in SDCC although allowed in ANSI */ 
22366 \newline 
22367 }
22368 \end_deeper 
22369 \layout Itemize
22370
22371 'long long
22372 \begin_inset LatexCommand \index{long long (not supported)}
22373
22374 \end_inset 
22375
22376 ' (64 bit integers
22377 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
22378
22379 \end_inset 
22380
22381 ) not supported.
22382 \layout Itemize
22383
22384 'double
22385 \begin_inset LatexCommand \index{double (not supported)}
22386
22387 \end_inset 
22388
22389 ' precision floating point 
22390 \begin_inset LatexCommand \index{Floating point support}
22391
22392 \end_inset 
22393
22394 not supported.
22395 \layout Itemize
22396
22397 No support for setjmp
22398 \begin_inset LatexCommand \index{setjmp (not supported)}
22399
22400 \end_inset 
22401
22402  and longjmp
22403 \begin_inset LatexCommand \index{longjmp (not supported)}
22404
22405 \end_inset 
22406
22407  (for now).
22408 \layout Itemize
22409
22410 Old K&R style
22411 \begin_inset LatexCommand \index{K\&R style}
22412
22413 \end_inset 
22414
22415  function declarations are NOT allowed.
22416 \begin_deeper 
22417 \layout Verse
22418
22419
22420 \family typewriter 
22421 foo(i,j) /* this old style of function declarations */ 
22422 \newline 
22423 int i,j; /* are valid in ANSI but not valid in SDCC */ 
22424 \newline 
22425
22426 \newline 
22427 \SpecialChar ~
22428 \SpecialChar ~
22429 \SpecialChar ~
22430 \SpecialChar ~
22431 ...
22432  
22433 \newline 
22434 }
22435 \end_deeper 
22436 \layout Section
22437
22438 Cyclomatic Complexity
22439 \begin_inset LatexCommand \index{Cyclomatic complexity}
22440
22441 \end_inset 
22442
22443
22444 \layout Standard
22445
22446 Cyclomatic complexity of a function is defined as the number of independent
22447  paths the program can take during execution of the function.
22448  This is an important number since it defines the number test cases you
22449  have to generate to validate the function.
22450  The accepted industry standard for complexity number is 10, if the cyclomatic
22451  complexity reported by SDCC exceeds 10 you should think about simplification
22452  of the function logic.
22453  Note that the complexity level is not related to the number of lines of
22454  code in a function.
22455  Large functions can have low complexity, and small functions can have large
22456  complexity levels.
22457  
22458 \newline 
22459
22460 \newline 
22461 SDCC uses the following formula to compute the complexity:
22462 \newline 
22463
22464 \layout Standard
22465
22466 complexity = (number of edges in control flow graph) - (number of nodes
22467  in control flow graph) + 2;
22468 \newline 
22469
22470 \newline 
22471 Having said that the industry standard is 10, you should be aware that in
22472  some cases it be may unavoidable to have a complexity level of less than
22473  10.
22474  For example if you have switch statement with more than 10 case labels,
22475  each case label adds one to the complexity level.
22476  The complexity level is by no means an absolute measure of the algorithmic
22477  complexity of the function, it does however provide a good starting point
22478  for which functions you might look at for further optimization.
22479 \layout Section
22480
22481 Retargetting for other Processors
22482 \layout Standard
22483
22484 The issues for retargetting the compiler are far too numerous to be covered
22485  by this document.
22486  What follows is a brief description of each of the seven phases of the
22487  compiler and its MCU dependency.
22488 \layout Itemize
22489
22490 Parsing the source and building the annotated parse tree.
22491  This phase is largely MCU independent (except for the language extensions).
22492  Syntax & semantic checks are also done in this phase, along with some initial
22493  optimizations like back patching labels and the pattern matching optimizations
22494  like bit-rotation etc.
22495 \layout Itemize
22496
22497 The second phase involves generating an intermediate code which can be easy
22498  manipulated during the later phases.
22499  This phase is entirely MCU independent.
22500  The intermediate code generation assumes the target machine has unlimited
22501  number of registers, and designates them with the name iTemp.
22502  The compiler can be made to dump a human readable form of the code generated
22503  by using the -
22504 \begin_inset ERT
22505 status Collapsed
22506
22507 \layout Standard
22508
22509 \backslash 
22510 /
22511 \end_inset 
22512
22513 -dumpraw option.
22514 \layout Itemize
22515
22516 This phase does the bulk of the standard optimizations and is also MCU independe
22517 nt.
22518  This phase can be broken down into several sub-phases:
22519 \newline 
22520
22521 \newline 
22522 Break down intermediate code (iCode) into basic blocks.
22523 \newline 
22524 Do control flow & data flow analysis on the basic blocks.
22525 \newline 
22526 Do local common subexpression elimination, then global subexpression elimination
22527 \newline 
22528 Dead code elimination
22529 \newline 
22530 Loop optimizations
22531 \newline 
22532 If loop optimizations caused any changes then do 'global subexpression eliminati
22533 on' and 'dead code elimination' again.
22534 \layout Itemize
22535
22536 This phase determines the live-ranges; by live range I mean those iTemp
22537  variables defined by the compiler that still survive after all the optimization
22538 s.
22539  Live range analysis
22540 \begin_inset LatexCommand \index{Live range analysis}
22541
22542 \end_inset 
22543
22544  is essential for register allocation, since these computation determines
22545  which of these iTemps will be assigned to registers, and for how long.
22546 \layout Itemize
22547
22548 Phase five is register allocation.
22549  There are two parts to this process.
22550 \newline 
22551
22552 \newline 
22553 The first part I call 'register packing' (for lack of a better term).
22554  In this case several MCU specific expression folding is done to reduce
22555  register pressure.
22556 \newline 
22557
22558 \newline 
22559 The second part is more MCU independent and deals with allocating registers
22560  to the remaining live ranges.
22561  A lot of MCU specific code does creep into this phase because of the limited
22562  number of index registers available in the 8051.
22563 \layout Itemize
22564
22565 The Code generation phase is (unhappily), entirely MCU dependent and very
22566  little (if any at all) of this code can be reused for other MCU.
22567  However the scheme for allocating a homogenized assembler operand for each
22568  iCode operand may be reused.
22569 \layout Itemize
22570
22571 As mentioned in the optimization section the peep-hole optimizer is rule
22572  based system, which can reprogrammed for other MCUs.
22573 \layout Chapter
22574
22575 Compiler internals
22576 \begin_inset LatexCommand \index{Compiler internals}
22577
22578 \end_inset 
22579
22580
22581 \layout Section
22582
22583 The anatomy of the compiler
22584 \begin_inset LatexCommand \label{sub:The-anatomy-of}
22585
22586 \end_inset 
22587
22588
22589 \layout Standard
22590
22591
22592 \shape italic 
22593 This is an excerpt from an article published in Circuit Cellar Magazine
22594  in august 2000.
22595  It's a little outdated (the compiler is much more efficient now and user/develo
22596 per friendly), but pretty well exposes the guts of it all.
22597 \shape default 
22598
22599 \newline 
22600
22601 \newline 
22602 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
22603  It is fairly easy to retarget for other 8-bit MCU.
22604  Here we take a look at some of the internals of the compiler.
22605  
22606 \layout Paragraph*
22607
22608 Parsing
22609 \begin_inset LatexCommand \index{Parsing}
22610
22611 \end_inset 
22612
22613  
22614 \layout Standard
22615
22616 Parsing the input source file and creating an AST (Annotated Syntax Tree
22617 \begin_inset LatexCommand \index{Annotated syntax tree}
22618
22619 \end_inset 
22620
22621 ).
22622  This phase also involves propagating types (annotating each node of the
22623  parse tree with type information) and semantic analysis.
22624  There are some MCU specific parsing rules.
22625  For example the storage classes, the extended storage classes are MCU specific
22626  while there may be a xdata storage class for 8051 there is no such storage
22627  class for z80 or Atmel AVR.
22628  SDCC allows MCU specific storage class extensions, i.e.
22629  xdata will be treated as a storage class specifier when parsing 8051 C
22630  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
22631  C code.
22632 \layout Paragraph*
22633
22634 Generating iCode
22635 \begin_inset LatexCommand \index{iCode}
22636
22637 \end_inset 
22638
22639
22640 \layout Standard
22641
22642 Intermediate code generation.
22643  In this phase the AST is broken down into three-operand form (iCode).
22644  These three operand forms are represented as doubly linked lists.
22645  ICode is the term given to the intermediate form generated by the compiler.
22646  ICode example section shows some examples of iCode generated for some simple
22647  C source functions.
22648 \layout Paragraph*
22649
22650 Optimizations
22651 \begin_inset LatexCommand \index{Optimizations}
22652
22653 \end_inset 
22654
22655 .
22656 \layout Standard
22657
22658 Bulk of the target independent optimizations is performed in this phase.
22659  The optimizations include constant propagation, common sub-expression eliminati
22660 on, loop invariant code movement, strength reduction of loop induction variables
22661  and dead-code elimination.
22662 \layout Paragraph*
22663
22664 Live range analysis
22665 \begin_inset LatexCommand \index{Live range analysis}
22666
22667 \end_inset 
22668
22669
22670 \layout Standard
22671
22672 During intermediate code generation phase, the compiler assumes the target
22673  machine has infinite number of registers and generates a lot of temporary
22674  variables.
22675  The live range computation determines the lifetime of each of these compiler-ge
22676 nerated temporaries.
22677  A picture speaks a thousand words.
22678  ICode example sections show the live range annotations for each of the
22679  operand.
22680  It is important to note here, each iCode is assigned a number in the order
22681  of its execution in the function.
22682  The live ranges are computed in terms of these numbers.
22683  The from number is the number of the iCode which first defines the operand
22684  and the to number signifies the iCode which uses this operand last.
22685 \layout Paragraph*
22686
22687 Register Allocation
22688 \begin_inset LatexCommand \index{Register allocation}
22689
22690 \end_inset 
22691
22692
22693 \layout Standard
22694
22695 The register allocation determines the type and number of registers needed
22696  by each operand.
22697  In most MCUs only a few registers can be used for indirect addressing.
22698  In case of 8051 for example the registers R0 & R1 can be used to indirectly
22699  address the internal ram and DPTR to indirectly address the external ram.
22700  The compiler will try to allocate the appropriate register to pointer variables
22701  if it can.
22702  ICode example section shows the operands annotated with the registers assigned
22703  to them.
22704  The compiler will try to keep operands in registers as much as possible;
22705  there are several schemes the compiler uses to do achieve this.
22706  When the compiler runs out of registers the compiler will check to see
22707  if there are any live operands which is not used or defined in the current
22708  basic block being processed, if there are any found then it will push that
22709  operand and use the registers in this block, the operand will then be popped
22710  at the end of the basic block.
22711  
22712 \layout Standard
22713
22714 There are other MCU specific considerations in this phase.
22715  Some MCUs have an accumulator; very short-lived operands could be assigned
22716  to the accumulator instead of a general-purpose register.
22717 \layout Paragraph*
22718
22719 Code generation
22720 \layout Standard
22721
22722 Figure II gives a table of iCode operations supported by the compiler.
22723  The code generation involves translating these operations into corresponding
22724  assembly code for the processor.
22725  This sounds overly simple but that is the essence of code generation.
22726  Some of the iCode operations are generated on a MCU specific manner for
22727  example, the z80 port does not use registers to pass parameters so the
22728  SEND and RECV iCode operations will not be generated, and it also does
22729  not support JUMPTABLES.
22730  
22731 \newline 
22732
22733 \series bold 
22734 \shape italic 
22735 \color red
22736 <Where is Figure II?>
22737 \layout Comment
22738
22739 In the original article Figure II was announced to be downloadable on 
22740 \shape italic 
22741 Circuit Cellar
22742 \shape default 
22743 's web site.
22744  Unfortunately it never seemed to have shown up there, so: where is Figure
22745  II?
22746 \layout Paragraph*
22747
22748 ICode Example
22749 \begin_inset LatexCommand \index{iCode}
22750
22751 \end_inset 
22752
22753
22754 \layout Standard
22755
22756 This section shows some details of iCode.
22757  The example C code does not do anything useful; it is used as an example
22758  to illustrate the intermediate code generated by the compiler.
22759 \layout Verse
22760
22761
22762 \family typewriter 
22763 1.\SpecialChar ~
22764 xdata int * p;
22765 \newline 
22766 2.\SpecialChar ~
22767 int gint;
22768 \newline 
22769 3.\SpecialChar ~
22770 /* This function does nothing useful.
22771  It is used
22772 \newline 
22773 4.\SpecialChar ~
22774 \SpecialChar ~
22775 \SpecialChar ~
22776 \SpecialChar ~
22777 for the purpose of explaining iCode */
22778 \newline 
22779 5.\SpecialChar ~
22780 short function (data int *x)
22781 \newline 
22782 6.\SpecialChar ~
22783 {
22784 \newline 
22785 7.\SpecialChar ~
22786 \SpecialChar ~
22787 \SpecialChar ~
22788 short i=10; \SpecialChar ~
22789 \SpecialChar ~
22790 /* dead initialization eliminated */
22791 \newline 
22792 8.\SpecialChar ~
22793 \SpecialChar ~
22794 \SpecialChar ~
22795 short sum=10; /* dead initialization eliminated */
22796 \newline 
22797 9.\SpecialChar ~
22798 \SpecialChar ~
22799 \SpecialChar ~
22800 short mul;
22801 \newline 
22802 10.\SpecialChar ~
22803 \SpecialChar ~
22804 int j ;
22805 \newline 
22806 11.\SpecialChar ~
22807 \SpecialChar ~
22808 while (*x) *x++ = *p++; 
22809 \newline 
22810 12.\SpecialChar ~
22811 \SpecialChar ~
22812 \SpecialChar ~
22813 \SpecialChar ~
22814 sum = 0 ; 
22815 \newline 
22816 13.\SpecialChar ~
22817 \SpecialChar ~
22818 mul = 0;
22819 \newline 
22820 14.\SpecialChar ~
22821 \SpecialChar ~
22822 /* compiler detects i,j to be induction variables */
22823 \newline 
22824 15.\SpecialChar ~
22825 \SpecialChar ~
22826 for (i = 0, j = 10 ; i < 10 ; i++, j
22827 \family default 
22828 -
22829 \begin_inset ERT
22830 status Collapsed
22831
22832 \layout Standard
22833
22834 \backslash 
22835 /
22836 \end_inset 
22837
22838 -
22839 \family typewriter 
22840 ) {
22841 \newline 
22842 16.\SpecialChar ~
22843 \SpecialChar ~
22844 \SpecialChar ~
22845 \SpecialChar ~
22846 sum += i;
22847 \newline 
22848 17.\SpecialChar ~
22849 \SpecialChar ~
22850 \SpecialChar ~
22851 \SpecialChar ~
22852 mul += i * 3; \SpecialChar ~
22853 \SpecialChar ~
22854 /* this multiplication remains */
22855 \newline 
22856 18.\SpecialChar ~
22857 \SpecialChar ~
22858 \SpecialChar ~
22859 \SpecialChar ~
22860 gint += j * 3;\SpecialChar ~
22861 \SpecialChar ~
22862 /* this multiplication changed to addition */
22863 \newline 
22864 19.\SpecialChar ~
22865 \SpecialChar ~
22866 }
22867 \newline 
22868 20.\SpecialChar ~
22869 \SpecialChar ~
22870 return sum+mul;
22871 \newline 
22872 21.\SpecialChar ~
22873 }
22874 \layout Standard
22875
22876 In addition to the operands each iCode contains information about the filename
22877  and line it corresponds to in the source file.
22878  The first field in the listing should be interpreted as follows:
22879 \newline 
22880
22881 \shape italic 
22882 \size footnotesize 
22883 Filename(linenumber: iCode Execution sequence number : ICode hash table
22884  key : loop depth of the iCode).
22885 \shape default 
22886 \size default 
22887
22888 \newline 
22889 Then follows the human readable form of the ICode operation.
22890  Each operand of this triplet form can be of three basic types a) compiler
22891  generated temporary b) user defined variable c) a constant value.
22892  Note that local variables and parameters are replaced by compiler generated
22893  temporaries.
22894  Live ranges
22895 \begin_inset LatexCommand \index{Live range analysis}
22896
22897 \end_inset 
22898
22899  are computed only for temporaries (i.e.
22900  live ranges are not computed for global variables).
22901  Registers
22902 \begin_inset LatexCommand \index{Register allocation}
22903
22904 \end_inset 
22905
22906  are allocated for temporaries only.
22907  Operands are formatted in the following manner:
22908 \newline 
22909
22910 \shape italic 
22911 \size footnotesize 
22912 Operand Name [lr live-from : live-to ] { type information } [ registers
22913  allocated ].
22914 \shape default 
22915 \size default 
22916
22917 \newline 
22918 As mentioned earlier the live ranges are computed in terms of the execution
22919  sequence number of the iCodes, for example 
22920 \newline 
22921 the iTemp0 is live from (i.e.
22922  first defined in iCode with execution sequence number 3, and is last used
22923  in the iCode with sequence number 5).
22924  For induction variables such as iTemp21 the live range computation extends
22925  the lifetime from the start to the end of the loop.
22926 \newline 
22927 The register allocator used the live range information to allocate registers,
22928  the same registers may be used for different temporaries if their live
22929  ranges do not overlap, for example r0 is allocated to both iTemp6 and to
22930  iTemp17 since their live ranges do not overlap.
22931  In addition the allocator also takes into consideration the type and usage
22932  of a temporary, for example itemp6 is a pointer to near space and is used
22933  as to fetch data from (i.e.
22934  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
22935  Some short lived temporaries are allocated to special registers which have
22936  meaning to the code generator e.g.
22937  iTemp13 is allocated to a pseudo register CC which tells the back end that
22938  the temporary is used only for a conditional jump the code generation makes
22939  use of this information to optimize a compare and jump ICode.
22940 \newline 
22941 There are several loop optimizations
22942 \begin_inset LatexCommand \index{Loop optimization}
22943
22944 \end_inset 
22945
22946  performed by the compiler.
22947  It can detect induction variables iTemp21(i) and iTemp23(j).
22948  Also note the compiler does selective strength reduction
22949 \begin_inset LatexCommand \index{Strength reduction}
22950
22951 \end_inset 
22952
22953 , i.e.
22954  the multiplication of an induction variable in line 18 (gint = j * 3) is
22955  changed to addition, a new temporary iTemp17 is allocated and assigned
22956  a initial value, a constant 3 is then added for each iteration of the loop.
22957  The compiler does not change the multiplication
22958 \begin_inset LatexCommand \index{Multiplication}
22959
22960 \end_inset 
22961
22962  in line 17 however since the processor does support an 8 * 8 bit multiplication.
22963 \newline 
22964 Note the dead code elimination
22965 \begin_inset LatexCommand \index{Dead-code elimination}
22966
22967 \end_inset 
22968
22969  optimization eliminated the dead assignments in line 7 & 8 to I and sum
22970  respectively.
22971 \newline 
22972
22973 \layout Standard
22974
22975
22976 \size footnotesize 
22977 Sample.c (5:1:0:0) _entry($9) :
22978 \layout Standard
22979
22980
22981 \size footnotesize 
22982 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
22983 \layout Standard
22984
22985
22986 \size footnotesize 
22987 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
22988 \layout Standard
22989
22990
22991 \size footnotesize 
22992 Sample.c(11:4:53:0) preHeaderLbl0($11) :
22993 \layout Standard
22994
22995
22996 \size footnotesize 
22997 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
22998  * int}[r2]
22999 \layout Standard
23000
23001
23002 \size footnotesize 
23003 Sample.c(11:6:5:1) _whilecontinue_0($1) :
23004 \layout Standard
23005
23006
23007 \size footnotesize 
23008 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
23009  int}[r0]]
23010 \layout Standard
23011
23012
23013 \size footnotesize 
23014 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
23015 \layout Standard
23016
23017
23018 \size footnotesize 
23019 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
23020  * int}
23021 \layout Standard
23022
23023
23024 \size footnotesize 
23025 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
23026  {short}
23027 \layout Standard
23028
23029
23030 \size footnotesize 
23031 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
23032  * int}[DPTR]]
23033 \layout Standard
23034
23035
23036 \size footnotesize 
23037 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
23038 }[r2 r3]
23039 \layout Standard
23040
23041
23042 \size footnotesize 
23043 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
23044  * int}[r0] + 0x2 {short}
23045 \layout Standard
23046
23047
23048 \size footnotesize 
23049 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
23050 \layout Standard
23051
23052
23053 \size footnotesize 
23054 Sample.c(11:17:21:0)_whilebreak_0($3) :
23055 \layout Standard
23056
23057
23058 \size footnotesize 
23059 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
23060 \layout Standard
23061
23062
23063 \size footnotesize 
23064 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
23065 \layout Standard
23066
23067
23068 \size footnotesize 
23069 Sample.c(15:20:54:0)preHeaderLbl1($13) :
23070 \layout Standard
23071
23072
23073 \size footnotesize 
23074 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
23075 \layout Standard
23076
23077
23078 \size footnotesize 
23079 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
23080 \layout Standard
23081
23082
23083 \size footnotesize 
23084 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
23085 \layout Standard
23086
23087
23088 \size footnotesize 
23089 Sample.c(15:24:26:1)_forcond_0($4) :
23090 \layout Standard
23091
23092
23093 \size footnotesize 
23094 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
23095  < 0xa {short}
23096 \layout Standard
23097
23098
23099 \size footnotesize 
23100 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
23101 \layout Standard
23102
23103
23104 \size footnotesize 
23105 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
23106  + ITemp21 [lr21:38]{short}[r4]
23107 \layout Standard
23108
23109
23110 \size footnotesize 
23111 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
23112  * 0x3 {short}
23113 \layout Standard
23114
23115
23116 \size footnotesize 
23117 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
23118  + iTemp15 [lr29:30]{short}[r1]
23119 \layout Standard
23120
23121
23122 \size footnotesize 
23123 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
23124  r0]- 0x3 {short}
23125 \layout Standard
23126
23127
23128 \size footnotesize 
23129 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
23130 int}[r7 r0]
23131 \layout Standard
23132
23133
23134 \size footnotesize 
23135 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
23136  + 0x1 {short}
23137 \layout Standard
23138
23139
23140 \size footnotesize 
23141 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
23142  r6]- 0x1 {short}
23143 \layout Standard
23144
23145
23146 \size footnotesize 
23147 Sample.c(19:38:47:1) goto _forcond_0($4)
23148 \layout Standard
23149
23150
23151 \size footnotesize 
23152 Sample.c(19:39:48:0)_forbreak_0($7) :
23153 \layout Standard
23154
23155
23156 \size footnotesize 
23157 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
23158  + ITemp11 [lr19:40]{short}[r3]
23159 \layout Standard
23160
23161
23162 \size footnotesize 
23163 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
23164 \layout Standard
23165
23166
23167 \size footnotesize 
23168 Sample.c(20:42:51:0)_return($8) :
23169 \layout Standard
23170
23171
23172 \size footnotesize 
23173 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
23174 \size default 
23175
23176 \newline 
23177
23178 \newline 
23179 Finally the code generated for this function:
23180 \newline 
23181
23182 \layout Standard
23183
23184
23185 \size footnotesize 
23186 .area DSEG (DATA)
23187 \layout Standard
23188
23189
23190 \size footnotesize 
23191 _p::
23192 \layout Standard
23193
23194
23195 \size footnotesize 
23196 \SpecialChar ~
23197 \SpecialChar ~
23198 .ds 2
23199 \layout Standard
23200
23201
23202 \size footnotesize 
23203 _gint::
23204 \layout Standard
23205
23206
23207 \size footnotesize 
23208 \SpecialChar ~
23209 \SpecialChar ~
23210 .ds 2
23211 \layout Standard
23212
23213
23214 \size footnotesize 
23215 ; sample.c 5
23216 \layout Standard
23217
23218
23219 \size footnotesize 
23220 ; ----------------------------------------------
23221 \layout Standard
23222
23223
23224 \size footnotesize 
23225 ; function function
23226 \layout Standard
23227
23228
23229 \size footnotesize 
23230 ; ----------------------------------------------
23231 \layout Standard
23232
23233
23234 \size footnotesize 
23235 _function:
23236 \layout Standard
23237
23238
23239 \size footnotesize 
23240 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
23241 \layout Standard
23242
23243
23244 \size footnotesize 
23245 \SpecialChar ~
23246 \SpecialChar ~
23247 mov r2,dpl
23248 \layout Standard
23249
23250
23251 \size footnotesize 
23252 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
23253 \layout Standard
23254
23255
23256 \size footnotesize 
23257 \SpecialChar ~
23258 \SpecialChar ~
23259 mov ar0,r2
23260 \layout Standard
23261
23262
23263 \size footnotesize 
23264 ;_whilecontinue_0($1) :
23265 \layout Standard
23266
23267
23268 \size footnotesize 
23269 00101$:
23270 \layout Standard
23271
23272
23273 \size footnotesize 
23274 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
23275 \layout Standard
23276
23277
23278 \size footnotesize 
23279 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
23280 \layout Standard
23281
23282
23283 \size footnotesize 
23284 \SpecialChar ~
23285 \SpecialChar ~
23286 mov ar2,@r0
23287 \layout Standard
23288
23289
23290 \size footnotesize 
23291 \SpecialChar ~
23292 \SpecialChar ~
23293 inc r0
23294 \layout Standard
23295
23296
23297 \size footnotesize 
23298 \SpecialChar ~
23299 \SpecialChar ~
23300 mov ar3,@r0
23301 \layout Standard
23302
23303
23304 \size footnotesize 
23305 \SpecialChar ~
23306 \SpecialChar ~
23307 dec r0
23308 \layout Standard
23309
23310
23311 \size footnotesize 
23312 \SpecialChar ~
23313 \SpecialChar ~
23314 mov a,r2
23315 \layout Standard
23316
23317
23318 \size footnotesize 
23319 \SpecialChar ~
23320 \SpecialChar ~
23321 orl a,r3
23322 \layout Standard
23323
23324
23325 \size footnotesize 
23326 \SpecialChar ~
23327 \SpecialChar ~
23328 jz 00103$
23329 \layout Standard
23330
23331
23332 \size footnotesize 
23333 00114$:
23334 \layout Standard
23335
23336
23337 \size footnotesize 
23338 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
23339 \layout Standard
23340
23341
23342 \size footnotesize 
23343 \SpecialChar ~
23344 \SpecialChar ~
23345 mov dpl,_p
23346 \layout Standard
23347
23348
23349 \size footnotesize 
23350 \SpecialChar ~
23351 \SpecialChar ~
23352 mov dph,(_p + 1)
23353 \layout Standard
23354
23355
23356 \size footnotesize 
23357 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
23358 \layout Standard
23359
23360
23361 \size footnotesize 
23362 \SpecialChar ~
23363 \SpecialChar ~
23364 mov a,#0x02
23365 \layout Standard
23366
23367
23368 \size footnotesize 
23369 \SpecialChar ~
23370 \SpecialChar ~
23371 add a,_p
23372 \layout Standard
23373
23374
23375 \size footnotesize 
23376 \SpecialChar ~
23377 \SpecialChar ~
23378 mov _p,a
23379 \layout Standard
23380
23381
23382 \size footnotesize 
23383 \SpecialChar ~
23384 \SpecialChar ~
23385 clr a
23386 \layout Standard
23387
23388
23389 \size footnotesize 
23390 \SpecialChar ~
23391 \SpecialChar ~
23392 addc a,(_p + 1)
23393 \layout Standard
23394
23395
23396 \size footnotesize 
23397 \SpecialChar ~
23398 \SpecialChar ~
23399 mov (_p + 1),a
23400 \layout Standard
23401
23402
23403 \size footnotesize 
23404 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
23405 \layout Standard
23406
23407
23408 \size footnotesize 
23409 \SpecialChar ~
23410 \SpecialChar ~
23411 movx a,@dptr
23412 \layout Standard
23413
23414
23415 \size footnotesize 
23416 \SpecialChar ~
23417 \SpecialChar ~
23418 mov r2,a
23419 \layout Standard
23420
23421
23422 \size footnotesize 
23423 \SpecialChar ~
23424 \SpecialChar ~
23425 inc dptr
23426 \layout Standard
23427
23428
23429 \size footnotesize 
23430 \SpecialChar ~
23431 \SpecialChar ~
23432 movx a,@dptr
23433 \layout Standard
23434
23435
23436 \size footnotesize 
23437 \SpecialChar ~
23438 \SpecialChar ~
23439 mov r3,a
23440 \layout Standard
23441
23442
23443 \size footnotesize 
23444 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
23445 \layout Standard
23446
23447
23448 \size footnotesize 
23449 \SpecialChar ~
23450 \SpecialChar ~
23451 mov @r0,ar2
23452 \layout Standard
23453
23454
23455 \size footnotesize 
23456 \SpecialChar ~
23457 \SpecialChar ~
23458 inc r0
23459 \layout Standard
23460
23461
23462 \size footnotesize 
23463 \SpecialChar ~
23464 \SpecialChar ~
23465 mov @r0,ar3
23466 \layout Standard
23467
23468
23469 \size footnotesize 
23470 ; iTemp6 [lr5:16]{_near * int}[r0] = 
23471 \layout Standard
23472
23473
23474 \size footnotesize 
23475 ; iTemp6 [lr5:16]{_near * int}[r0] + 
23476 \layout Standard
23477
23478
23479 \size footnotesize 
23480 ; 0x2 {short}
23481 \layout Standard
23482
23483
23484 \size footnotesize 
23485 \SpecialChar ~
23486 \SpecialChar ~
23487 inc r0
23488 \layout Standard
23489
23490
23491 \size footnotesize 
23492 ; goto _whilecontinue_0($1)
23493 \layout Standard
23494
23495
23496 \size footnotesize 
23497 \SpecialChar ~
23498 \SpecialChar ~
23499 sjmp 00101$
23500 \layout Standard
23501
23502
23503 \size footnotesize 
23504 ; _whilebreak_0($3) :
23505 \layout Standard
23506
23507
23508 \size footnotesize 
23509 00103$:
23510 \layout Standard
23511
23512
23513 \size footnotesize 
23514 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
23515 \layout Standard
23516
23517
23518 \size footnotesize 
23519 \SpecialChar ~
23520 \SpecialChar ~
23521 mov r2,#0x00
23522 \layout Standard
23523
23524
23525 \size footnotesize 
23526 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
23527 \layout Standard
23528
23529
23530 \size footnotesize 
23531 \SpecialChar ~
23532 \SpecialChar ~
23533 mov r3,#0x00
23534 \layout Standard
23535
23536
23537 \size footnotesize 
23538 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
23539 \layout Standard
23540
23541
23542 \size footnotesize 
23543 \SpecialChar ~
23544 \SpecialChar ~
23545 mov r4,#0x00
23546 \layout Standard
23547
23548
23549 \size footnotesize 
23550 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
23551 \layout Standard
23552
23553
23554 \size footnotesize 
23555 \SpecialChar ~
23556 \SpecialChar ~
23557 mov r5,#0x0A
23558 \layout Standard
23559
23560
23561 \size footnotesize 
23562 \SpecialChar ~
23563 \SpecialChar ~
23564 mov r6,#0x00
23565 \layout Standard
23566
23567
23568 \size footnotesize 
23569 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
23570 \layout Standard
23571
23572
23573 \size footnotesize 
23574 \SpecialChar ~
23575 \SpecialChar ~
23576 mov r7,#0x1E
23577 \layout Standard
23578
23579
23580 \size footnotesize 
23581 \SpecialChar ~
23582 \SpecialChar ~
23583 mov r0,#0x00
23584 \layout Standard
23585
23586
23587 \size footnotesize 
23588 ; _forcond_0($4) :
23589 \layout Standard
23590
23591
23592 \size footnotesize 
23593 00104$:
23594 \layout Standard
23595
23596
23597 \size footnotesize 
23598 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
23599 \layout Standard
23600
23601
23602 \size footnotesize 
23603 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
23604 \layout Standard
23605
23606
23607 \size footnotesize 
23608 \SpecialChar ~
23609 \SpecialChar ~
23610 clr c
23611 \layout Standard
23612
23613
23614 \size footnotesize 
23615 \SpecialChar ~
23616 \SpecialChar ~
23617 mov a,r4
23618 \layout Standard
23619
23620
23621 \size footnotesize 
23622 \SpecialChar ~
23623 \SpecialChar ~
23624 xrl a,#0x80
23625 \layout Standard
23626
23627
23628 \size footnotesize 
23629 \SpecialChar ~
23630 \SpecialChar ~
23631 subb a,#0x8a
23632 \layout Standard
23633
23634
23635 \size footnotesize 
23636 \SpecialChar ~
23637 \SpecialChar ~
23638 jnc 00107$
23639 \layout Standard
23640
23641
23642 \size footnotesize 
23643 00115$:
23644 \layout Standard
23645
23646
23647 \size footnotesize 
23648 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
23649 \layout Standard
23650
23651
23652 \size footnotesize 
23653 ; iTemp21 [lr21:38]{short}[r4]
23654 \layout Standard
23655
23656
23657 \size footnotesize 
23658 \SpecialChar ~
23659 \SpecialChar ~
23660 mov a,r4
23661 \layout Standard
23662
23663
23664 \size footnotesize 
23665 \SpecialChar ~
23666 \SpecialChar ~
23667 add a,r2
23668 \layout Standard
23669
23670
23671 \size footnotesize 
23672 \SpecialChar ~
23673 \SpecialChar ~
23674 mov r2,a
23675 \layout Standard
23676
23677
23678 \size footnotesize 
23679 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
23680 \layout Standard
23681
23682
23683 \size footnotesize 
23684 \SpecialChar ~
23685 \SpecialChar ~
23686 mov b,#0x03
23687 \layout Standard
23688
23689
23690 \size footnotesize 
23691 \SpecialChar ~
23692 \SpecialChar ~
23693 mov a,r4
23694 \layout Standard
23695
23696
23697 \size footnotesize 
23698 \SpecialChar ~
23699 \SpecialChar ~
23700 mul ab
23701 \layout Standard
23702
23703
23704 \size footnotesize 
23705 \SpecialChar ~
23706 \SpecialChar ~
23707 mov r1,a
23708 \layout Standard
23709
23710
23711 \size footnotesize 
23712 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
23713 \layout Standard
23714
23715
23716 \size footnotesize 
23717 ; iTemp15 [lr29:30]{short}[r1]
23718 \layout Standard
23719
23720
23721 \size footnotesize 
23722 \SpecialChar ~
23723 \SpecialChar ~
23724 add a,r3
23725 \layout Standard
23726
23727
23728 \size footnotesize 
23729 \SpecialChar ~
23730 \SpecialChar ~
23731 mov r3,a
23732 \layout Standard
23733
23734
23735 \size footnotesize 
23736 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
23737 \layout Standard
23738
23739
23740 \size footnotesize 
23741 \SpecialChar ~
23742 \SpecialChar ~
23743 mov a,r7
23744 \layout Standard
23745
23746
23747 \size footnotesize 
23748 \SpecialChar ~
23749 \SpecialChar ~
23750 add a,#0xfd
23751 \layout Standard
23752
23753
23754 \size footnotesize 
23755 \SpecialChar ~
23756 \SpecialChar ~
23757 mov r7,a
23758 \layout Standard
23759
23760
23761 \size footnotesize 
23762 \SpecialChar ~
23763 \SpecialChar ~
23764 mov a,r0
23765 \layout Standard
23766
23767
23768 \size footnotesize 
23769 \SpecialChar ~
23770 \SpecialChar ~
23771 addc a,#0xff
23772 \layout Standard
23773
23774
23775 \size footnotesize 
23776 \SpecialChar ~
23777 \SpecialChar ~
23778 mov r0,a
23779 \layout Standard
23780
23781
23782 \size footnotesize 
23783 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
23784 \layout Standard
23785
23786
23787 \size footnotesize 
23788 \SpecialChar ~
23789 \SpecialChar ~
23790 mov a,r7
23791 \layout Standard
23792
23793
23794 \size footnotesize 
23795 \SpecialChar ~
23796 \SpecialChar ~
23797 add a,_gint
23798 \layout Standard
23799
23800
23801 \size footnotesize 
23802 \SpecialChar ~
23803 \SpecialChar ~
23804 mov _gint,a
23805 \layout Standard
23806
23807
23808 \size footnotesize 
23809 \SpecialChar ~
23810 \SpecialChar ~
23811 mov a,r0
23812 \layout Standard
23813
23814
23815 \size footnotesize 
23816 \SpecialChar ~
23817 \SpecialChar ~
23818 addc a,(_gint + 1)
23819 \layout Standard
23820
23821
23822 \size footnotesize 
23823 \SpecialChar ~
23824 \SpecialChar ~
23825 mov (_gint + 1),a
23826 \layout Standard
23827
23828
23829 \size footnotesize 
23830 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
23831 \layout Standard
23832
23833
23834 \size footnotesize 
23835 \SpecialChar ~
23836 \SpecialChar ~
23837 inc r4
23838 \layout Standard
23839
23840
23841 \size footnotesize 
23842 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
23843 \layout Standard
23844
23845
23846 \size footnotesize 
23847 \SpecialChar ~
23848 \SpecialChar ~
23849 dec r5
23850 \layout Standard
23851
23852
23853 \size footnotesize 
23854 \SpecialChar ~
23855 \SpecialChar ~
23856 cjne r5,#0xff,00104$
23857 \layout Standard
23858
23859
23860 \size footnotesize 
23861 \SpecialChar ~
23862 \SpecialChar ~
23863 dec r6
23864 \layout Standard
23865
23866
23867 \size footnotesize 
23868 ; goto _forcond_0($4)
23869 \layout Standard
23870
23871
23872 \size footnotesize 
23873 \SpecialChar ~
23874 \SpecialChar ~
23875 sjmp 00104$
23876 \layout Standard
23877
23878
23879 \size footnotesize 
23880 ; _forbreak_0($7) :
23881 \layout Standard
23882
23883
23884 \size footnotesize 
23885 00107$:
23886 \layout Standard
23887
23888
23889 \size footnotesize 
23890 ; ret iTemp24 [lr40:41]{short}
23891 \layout Standard
23892
23893
23894 \size footnotesize 
23895 \SpecialChar ~
23896 \SpecialChar ~
23897 mov a,r3
23898 \layout Standard
23899
23900
23901 \size footnotesize 
23902 \SpecialChar ~
23903 \SpecialChar ~
23904 add a,r2
23905 \layout Standard
23906
23907
23908 \size footnotesize 
23909 \SpecialChar ~
23910 \SpecialChar ~
23911 mov dpl,a
23912 \layout Standard
23913
23914
23915 \size footnotesize 
23916 ; _return($8) :
23917 \layout Standard
23918
23919
23920 \size footnotesize 
23921 00108$:
23922 \layout Standard
23923
23924
23925 \size footnotesize 
23926 \SpecialChar ~
23927 \SpecialChar ~
23928 ret
23929 \newline 
23930
23931 \layout Section
23932
23933 A few words about basic block successors, predecessors and dominators
23934 \layout Standard
23935
23936 Successors are basic blocks
23937 \begin_inset LatexCommand \index{Basic blocks}
23938
23939 \end_inset 
23940
23941  that might execute after this basic block.
23942 \newline 
23943 Predecessors are basic blocks that might execute before reaching this basic
23944  block.
23945 \newline 
23946 Dominators are basic blocks that WILL execute before reaching this basic
23947  block.
23948 \newline 
23949
23950 \layout Standard
23951
23952 [basic block 1]
23953 \layout Standard
23954
23955 if (something)
23956 \layout Standard
23957
23958 \SpecialChar ~
23959 \SpecialChar ~
23960 \SpecialChar ~
23961 \SpecialChar ~
23962 [basic block 2]
23963 \layout Standard
23964
23965 else
23966 \layout Standard
23967
23968 \SpecialChar ~
23969 \SpecialChar ~
23970 \SpecialChar ~
23971 \SpecialChar ~
23972 [basic block 3]
23973 \layout Standard
23974
23975 [basic block 4]
23976 \newline 
23977
23978 \layout Standard
23979
23980 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
23981 \layout Standard
23982
23983 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
23984 \layout Standard
23985
23986 c) domVect of [BB4] = BB1 ...
23987  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
23988  was executed.
23989 \layout Chapter
23990
23991 Acknowledgments
23992 \layout Standard
23993
23994
23995 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
23996
23997 \end_inset 
23998
23999
24000 \newline 
24001
24002 \newline 
24003
24004 \emph on 
24005 Thanks to all the other volunteer developers who have helped with coding,
24006  testing, web-page creation, distribution sets, etc.
24007  You know who you are :-)
24008 \emph default 
24009
24010 \newline 
24011
24012 \layout Standard
24013
24014 This document was initially written by Sandeep Dutta
24015 \layout Standard
24016
24017 All product names mentioned herein may be trademarks
24018 \begin_inset LatexCommand \index{Trademarks}
24019
24020 \end_inset 
24021
24022  of their respective companies.
24023  
24024 \layout Section*
24025
24026 Alphabetical index
24027 \layout Standard
24028
24029 To avoid confusion, the installation and building options for SDCC itself
24030  (chapter 2) are not part of the index.
24031 \layout Standard
24032
24033
24034 \begin_inset LatexCommand \printindex{}
24035
24036 \end_inset 
24037
24038
24039 \the_end