mentioned sourceforge's delay between web frontend and mailing lists,
[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 \usepackage[
7   pdftitle={SDCC Compiler User Guide},
8   pdfauthor={SDCC development team},
9   pdfsubject={installation, user manual},
10   pdfkeywords={8032, 8051, ansi, c, compiler, CPU, DS390, 
11                embedded, GPL, HC08, manual, mcs51, PIC, Z80},
12   colorlinks=true,
13   linkcolor=blue] {hyperref}
14 %
15 \sloppy
16 \tolerance=500          
17 \emergencystretch=30pt 
18 %
19 \date{}
20 \end_preamble
21 \language english
22 \inputencoding default
23 \fontscheme pslatex
24 \graphics default
25 \paperfontsize default
26 \spacing single 
27 \papersize letterpaper
28 \paperpackage a4
29 \use_geometry 1
30 \use_amsmath 0
31 \use_natbib 0
32 \use_numerical_citations 0
33 \paperorientation portrait
34 \leftmargin 30mm
35 \topmargin 20mm
36 \rightmargin 25mm
37 \bottommargin 20mm
38 \secnumdepth 3
39 \tocdepth 3
40 \paragraph_separation indent
41 \defskip medskip
42 \quotes_language swedish
43 \quotes_times 2
44 \papercolumns 1
45 \papersides 1
46 \paperpagestyle fancy
47
48 \layout Comment
49
50 Please note: double dashed longoptions (e.g.
51  --version) are written this way: -
52 \begin_inset ERT
53 status Collapsed
54
55 \layout Standard
56
57 \backslash 
58 /
59 \end_inset 
60
61 -
62 \layout Comment
63
64 Two resp.
65  three consecutive dashes simply result in a long resp.
66  extra long dash.
67 \layout Comment
68
69 Architecture specific stuff (like memory models, code examples) should maybe
70  later go
71 \layout Comment
72
73 into seperate sections/chapters/appendices (it is hard to document PIC or
74  Z80 in 
75 \layout Comment
76
77 a 8051 centered document) - for now simply add.
78 \layout Title
79
80 SDCC Compiler User Guide
81 \layout Date
82
83
84 \size normal 
85 SDCC 2.4.1
86 \size footnotesize 
87
88 \newline 
89 $Date$ 
90 \newline 
91 $Revision$
92 \layout Comment
93
94 The above strings enclosed in $ are automatically updated by cvs
95 \layout Standard
96
97
98 \begin_inset LatexCommand \tableofcontents{}
99
100 \end_inset 
101
102
103 \layout Chapter
104
105 Introduction
106 \layout Section
107
108 About SDCC
109 \layout Standard
110
111
112 \series bold 
113 SDCC
114 \series default 
115  (
116 \emph on 
117 S
118 \emph default 
119 mall 
120 \emph on 
121 D
122 \emph default 
123 evice 
124 \emph on 
125 C
126 \emph default 
127  
128 \emph on 
129 C
130 \emph default 
131 ompiler) is a Freeware, retargettable, optimizing ANSI-C compiler by 
132 \series bold 
133 Sandeep Dutta
134 \series default 
135  designed for 8 bit Microprocessors.
136  The current version targets Intel MCS51 based Microprocessors (8031, 8032,
137  8051, 8052
138 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
139
140 \end_inset 
141
142 , etc.), Dallas DS80C390 variants, Motorola HC08 and Zilog Z80 based MCUs.
143  It can be retargetted for other microprocessors, support for Microchip
144  PIC, Atmel AVR is under development.
145  The entire source code for the compiler is distributed under GPL.
146  SDCC uses ASXXXX & ASLINK, a Freeware, retargettable assembler & linker.
147  SDCC has extensive language extensions suitable for utilizing various microcont
148 rollers and underlying hardware effectively.
149  
150 \newline 
151
152 \newline 
153 In addition to the MCU specific optimizations SDCC also does a host of standard
154  optimizations like:
155 \layout Itemize
156
157 global sub expression elimination, 
158 \layout Itemize
159
160 loop optimizations (loop invariant, strength reduction of induction variables
161  and loop reversing), 
162 \layout Itemize
163
164 constant folding & propagation, 
165 \layout Itemize
166
167 copy propagation, 
168 \layout Itemize
169
170 dead code elimination 
171 \layout Itemize
172
173 jump tables for 
174 \emph on 
175 switch
176 \emph default 
177  statements.
178 \layout Standard
179
180 For the back-end SDCC uses a global register allocation scheme which should
181  be well suited for other 8 bit MCUs.
182  
183 \newline 
184
185 \newline 
186 The peep hole optimizer uses a rule based substitution mechanism which is
187  MCU independent.
188  
189 \newline 
190
191 \newline 
192 Supported data-types are:
193 \layout Itemize
194
195 char (8 bits, 1 byte), 
196 \layout Itemize
197
198 short and int (16 bits, 2 bytes), 
199 \layout Itemize
200
201 long (32 bit, 4 bytes)
202 \layout Itemize
203
204 float (4 byte IEEE).
205  
206 \layout Standard
207
208 The compiler also allows 
209 \emph on 
210 inline assembler code
211 \emph default 
212  to be embedded anywhere in a function.
213  In addition, routines developed in assembly can also be called.
214 \newline 
215
216 \newline 
217 SDCC also provides an option (-
218 \begin_inset ERT
219 status Collapsed
220
221 \layout Standard
222
223 \backslash 
224 /
225 \end_inset 
226
227 -cyclomatic) to report the relative complexity of a function.
228  These functions can then be further optimized, or hand coded in assembly
229  if needed.
230  
231 \newline 
232
233 \newline 
234 SDCC also comes with a companion source level debugger SDCDB, the debugger
235  currently uses ucSim a freeware simulator for 8051 and other micro-controllers.
236  
237 \newline 
238
239 \newline 
240 The latest version can be downloaded from 
241 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
242
243 \end_inset 
244
245 .
246
247 \series bold 
248  
249 \series default 
250 \emph on 
251 Please note: the compiler will probably always be some steps ahead of this
252  documentation
253 \series bold 
254 \emph default 
255
256 \begin_inset LatexCommand \index{Status of documentation}
257
258 \end_inset 
259
260
261 \begin_inset Foot
262 collapsed false
263
264 \layout Standard
265
266 Obviously this has pros and cons
267 \end_inset 
268
269 .
270 \layout Section
271
272 Open Source
273 \layout Standard
274
275 All packages used in this compiler system are 
276 \emph on 
277 opensource
278 \emph default 
279  and 
280 \emph on 
281 freeware
282 \emph default 
283 ; source code for all the sub-packages (pre-processor, assemblers, linkers
284  etc) is distributed with the package.
285  This documentation is maintained using a freeware word processor (LyX).
286 \newline 
287 This program is free software; you can redistribute it and/or modify it
288  under the terms of the GNU General Public License
289 \begin_inset LatexCommand \index{GNU General Public License, GPL}
290
291 \end_inset 
292
293  as published by the Free Software Foundation; either version 2, or (at
294  your option) any later version.
295  This program is distributed in the hope that it will be useful, but WITHOUT
296  ANY WARRANTY; without even the implied warranty
297 \begin_inset LatexCommand \index{warranty}
298
299 \end_inset 
300
301  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
302  See the GNU General Public License for more details.
303  You should have received a copy of the GNU General Public License along
304  with this program; if not, write to the Free Software Foundation, 59 Temple
305  Place - Suite 330, Boston, MA 02111-1307, USA.
306  In other words, you are welcome to use, share and improve this program.
307  You are forbidden to forbid anyone else to use, share and improve what
308  you give them.
309  Help stamp out software-hoarding! 
310 \layout Section
311
312 Typographic conventions
313 \begin_inset LatexCommand \index{Typographic conventions}
314
315 \end_inset 
316
317
318 \layout Standard
319
320 Throughout this manual, we will use the following convention.
321  Commands you have to type in are printed in 
322 \family sans 
323 \series bold 
324 "sans serif"
325 \series default 
326 .
327
328 \family default 
329  Code samples are printed in 
330 \family typewriter 
331 typewriter font.
332
333 \family default 
334  Interesting items and new terms are printed in 
335 \emph on 
336 italic.
337 \layout Section
338
339 Compatibility with previous versions
340 \layout Standard
341
342 This version has numerous bug fixes compared with the previous version.
343  But we also introduced some incompatibilities with older versions.
344  Not just for the fun of it, but to make the compiler more stable, efficient
345  and ANSI compliant
346 \begin_inset LatexCommand \index{ANSI-compliance}
347
348 \end_inset 
349
350  (see section 
351 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
352
353 \end_inset 
354
355  for ANSI-Compliance).
356  
357 \newline 
358
359 \layout Itemize
360
361 short is now equivalent to int (16 bits), it used to be equivalent to char
362  (8 bits) which is not ANSI compliant
363 \layout Itemize
364
365 the default directory for gcc-builds where include, library and documentation
366  files are stored is now in /usr/local/share
367 \layout Itemize
368
369 char type parameters to vararg functions are casted to int unless explicitly
370  casted, e.g.: 
371 \newline 
372
373 \family typewriter 
374 \SpecialChar ~
375 \SpecialChar ~
376 char a=3;
377 \newline 
378 \SpecialChar ~
379 \SpecialChar ~
380 printf ("%d %c
381 \backslash 
382 n", a, (char)a);
383 \family default 
384
385 \newline 
386  will push a as an int and as a char resp.
387 \layout Itemize
388
389 option -
390 \begin_inset ERT
391 status Collapsed
392
393 \layout Standard
394
395 \backslash 
396 /
397 \end_inset 
398
399 -regextend has been removed
400 \layout Itemize
401
402 option -
403 \begin_inset ERT
404 status Collapsed
405
406 \layout Standard
407
408 \backslash 
409 /
410 \end_inset 
411
412 -noregparms has been removed
413 \layout Itemize
414
415 option -
416 \begin_inset ERT
417 status Collapsed
418
419 \layout Standard
420
421 \backslash 
422 /
423 \end_inset 
424
425 -stack-after-data has been removed
426 \layout Standard
427
428
429 \emph on 
430 <pending: more incompatibilities?>
431 \layout Section
432
433 System Requirements
434 \layout Standard
435
436 What do you need before you start installation of SDCC? A computer, and
437  a desire to compute.
438  The preferred method of installation is to compile SDCC from source using
439  GNU gcc and make.
440  For Windows some pre-compiled binary distributions are available for your
441  convenience.
442  You should have some experience with command line tools and compiler use.
443 \layout Section
444
445 Other Resources
446 \layout Standard
447
448 The SDCC home page at 
449 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
450
451 \end_inset 
452
453  is a great place to find distribution sets.
454  You can also find links to the user mailing lists that offer help or discuss
455  SDCC with other SDCC users.
456  Web links to other SDCC related sites can also be found here.
457  This document can be found in the DOC directory of the source package as
458  a text or HTML file.
459  A pdf version of this document is available at 
460 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
461
462 \end_inset 
463
464 .
465  Some of the other tools (simulator and assembler) included with SDCC contain
466  their own documentation and can be found in the source distribution.
467  If you want the latest unreleased software, the complete source package
468  is available directly by anonymous CVS on cvs.sdcc.sourceforge.net.
469 \layout Section
470
471 Wishes for the future
472 \layout Standard
473
474 There are (and always will be) some things that could be done.
475  Here are some I can think of:
476 \newline 
477
478 \layout Standard
479
480
481 \family typewriter 
482 char KernelFunction3(char p) at 0x340;
483 \newline 
484
485 \layout Standard
486
487
488 \family typewriter 
489 code banking
490 \begin_inset LatexCommand \index{code banking (not supported)}
491
492 \end_inset 
493
494  support for mcs51
495 \newline 
496
497 \newline 
498
499 \family default 
500 If you can think of some more, please see the section 
501 \begin_inset LatexCommand \ref{sub:Requesting-Features}
502
503 \end_inset 
504
505  about filing feature requests
506 \begin_inset LatexCommand \index{Requesting features}
507
508 \end_inset 
509
510
511 \begin_inset LatexCommand \index{Feature request}
512
513 \end_inset 
514
515 .
516 \newline 
517
518 \layout Chapter
519
520 Installing SDCC
521 \begin_inset LatexCommand \index{Installation}
522
523 \end_inset 
524
525
526 \layout Standard
527
528 For most users it is sufficient to skip to either section 
529 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
530
531 \end_inset 
532
533  or section 
534 \begin_inset LatexCommand \ref{sub:Windows-Install}
535
536 \end_inset 
537
538 .
539  More detailled instructions follow below.
540 \layout Section
541
542 Configure Options
543 \begin_inset LatexCommand \index{Options SDCC configuration}
544
545 \end_inset 
546
547
548 \layout Standard
549
550 The install paths, search paths and other options are defined when running
551  'configure'.
552  The defaults can be overridden by:
553 \layout List
554 \labelwidthstring 00.00.0000
555
556 -
557 \begin_inset ERT
558 status Collapsed
559
560 \layout Standard
561
562 \backslash 
563 /
564 \end_inset 
565
566 -prefix see table below
567 \layout List
568 \labelwidthstring 00.00.0000
569
570 -
571 \begin_inset ERT
572 status Collapsed
573
574 \layout Standard
575
576 \backslash 
577 /
578 \end_inset 
579
580 -exec_prefix see table below
581 \layout List
582 \labelwidthstring 00.00.0000
583
584 -
585 \begin_inset ERT
586 status Collapsed
587
588 \layout Standard
589
590 \backslash 
591 /
592 \end_inset 
593
594 -bindir see table below
595 \layout List
596 \labelwidthstring 00.00.0000
597
598 -
599 \begin_inset ERT
600 status Collapsed
601
602 \layout Standard
603
604 \backslash 
605 /
606 \end_inset 
607
608 -datadir see table below
609 \layout List
610 \labelwidthstring 00.00.0000
611
612 docdir environment variable, see table below
613 \layout List
614 \labelwidthstring 00.00.0000
615
616 include_dir_suffix environment variable, see table below
617 \layout List
618 \labelwidthstring 00.00.0000
619
620 lib_dir_suffix environment variable, see table below
621 \layout List
622 \labelwidthstring 00.00.0000
623
624 sdccconf_h_dir_separator environment variable, either / or 
625 \backslash 
626
627 \backslash 
628  makes sense here.
629  This character will only be used in sdccconf.h; don't forget it's a C-header,
630  therefore a double-backslash is needed there.
631 \layout List
632 \labelwidthstring 00.00.0000
633
634 -
635 \begin_inset ERT
636 status Collapsed
637
638 \layout Standard
639
640 \backslash 
641 /
642 \end_inset 
643
644 -disable-mcs51-port Excludes the Intel mcs51 port
645 \layout List
646 \labelwidthstring 00.00.0000
647
648 -
649 \begin_inset ERT
650 status Collapsed
651
652 \layout Standard
653
654 \backslash 
655 /
656 \end_inset 
657
658 -disable-gbz80-port Excludes the Gameboy gbz80 port
659 \layout List
660 \labelwidthstring 00.00.0000
661
662 -
663 \begin_inset ERT
664 status Collapsed
665
666 \layout Standard
667
668 \backslash 
669 /
670 \end_inset 
671
672 -disable-z80-port Excludes the z80 port
673 \layout List
674 \labelwidthstring 00.00.0000
675
676 -
677 \begin_inset ERT
678 status Collapsed
679
680 \layout Standard
681
682 \backslash 
683 /
684 \end_inset 
685
686 -disable-avr-port Excludes the AVR port
687 \layout List
688 \labelwidthstring 00.00.0000
689
690 -
691 \begin_inset ERT
692 status Collapsed
693
694 \layout Standard
695
696 \backslash 
697 /
698 \end_inset 
699
700 -disable-ds390-port Excludes the DS390 port
701 \layout List
702 \labelwidthstring 00.00.0000
703
704 -
705 \begin_inset ERT
706 status Collapsed
707
708 \layout Standard
709
710 \backslash 
711 /
712 \end_inset 
713
714 -disable-hc08-port Excludes the HC08 port
715 \layout List
716 \labelwidthstring 00.00.0000
717
718 -
719 \begin_inset ERT
720 status Collapsed
721
722 \layout Standard
723
724 \backslash 
725 /
726 \end_inset 
727
728 -disable-pic-port Excludes the PIC port
729 \layout List
730 \labelwidthstring 00.00.0000
731
732 -
733 \begin_inset ERT
734 status Collapsed
735
736 \layout Standard
737
738 \backslash 
739 /
740 \end_inset 
741
742 -disable-xa51-port Excludes the XA51 port
743 \layout List
744 \labelwidthstring 00.00.0000
745
746 -
747 \begin_inset ERT
748 status Collapsed
749
750 \layout Standard
751
752 \backslash 
753 /
754 \end_inset 
755
756 -disable-ucsim Disables configuring and building of ucsim
757 \layout List
758 \labelwidthstring 00.00.0000
759
760 -
761 \begin_inset ERT
762 status Collapsed
763
764 \layout Standard
765
766 \backslash 
767 /
768 \end_inset 
769
770 -disable-device-lib-build Disables automatically building device libraries
771 \layout List
772 \labelwidthstring 00.00.0000
773
774 -
775 \begin_inset ERT
776 status Collapsed
777
778 \layout Standard
779
780 \backslash 
781 /
782 \end_inset 
783
784 -disable-packihx Disables building packihx
785 \layout List
786 \labelwidthstring 00.00.0000
787
788 -
789 \begin_inset ERT
790 status Collapsed
791
792 \layout Standard
793
794 \backslash 
795 /
796 \end_inset 
797
798 -enable-libgc Use the Bohem memory allocator.
799  Lower runtime footprint.
800 \layout Standard
801
802 Furthermore the environment variables CC, CFLAGS, ...
803  the tools and their arguments can be influenced.
804  Please see `configure -
805 \begin_inset ERT
806 status Collapsed
807
808 \layout Standard
809
810 \backslash 
811 /
812 \end_inset 
813
814 -help` and the man/info pages of `configure` for details.
815 \newline 
816
817 \newline 
818 The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB,
819  STD_FP_LIB, STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_
820 NAME, SDCC_INCLUDE_NAME, SDCC_LIB_NAME are defined by `configure` too.
821  At the moment it's not possible to change the default settings (it was
822  simply never required).
823 \newline 
824
825 \newline 
826 These configure options are compiled into the binaries, and can only be
827  changed by rerunning 'configure' and recompiling SDCC.
828  The configure options are written in 
829 \emph on 
830 italics
831 \emph default 
832  to distinguish them from run time environment variables (see section search
833  paths).
834 \newline 
835
836 \newline 
837 The settings for 
838 \begin_inset Quotes sld
839 \end_inset 
840
841 Win32 builds
842 \begin_inset Quotes srd
843 \end_inset 
844
845  are used by the SDCC team to build the official Win32 binaries.
846  The SDCC team uses Mingw32 to build the official Windows binaries, because
847  it's
848 \layout Enumerate
849
850 open source, 
851 \layout Enumerate
852
853 a gcc compiler and last but not least
854 \layout Enumerate
855
856 the binaries can be built by cross compiling on Sourceforge's compile farm.
857 \layout Standard
858
859 See the examples, how to pass the Win32 settings to 'configure'.
860  The other Win32 builds using Borland, VC or whatever don't use 'configure',
861  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
862  for Win32.
863 \newline 
864
865 \newline 
866 These defaults are:
867 \newline 
868
869 \layout Standard
870 \align center 
871
872 \begin_inset  Tabular
873 <lyxtabular version="3" rows="8" columns="3">
874 <features>
875 <column alignment="block" valignment="top" leftline="true" width="0in">
876 <column alignment="block" valignment="top" leftline="true" width="0in">
877 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
878 <row topline="true" bottomline="true">
879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
880 \begin_inset Text
881
882 \layout Standard
883
884 Variable
885 \end_inset 
886 </cell>
887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
888 \begin_inset Text
889
890 \layout Standard
891
892 default
893 \end_inset 
894 </cell>
895 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
896 \begin_inset Text
897
898 \layout Standard
899
900 Win32 builds
901 \end_inset 
902 </cell>
903 </row>
904 <row topline="true">
905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
906 \begin_inset Text
907
908 \layout Standard
909
910
911 \emph on 
912 PREFIX
913 \end_inset 
914 </cell>
915 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
916 \begin_inset Text
917
918 \layout Standard
919
920 /usr/local
921 \end_inset 
922 </cell>
923 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
924 \begin_inset Text
925
926 \layout Standard
927
928
929 \backslash 
930 sdcc
931 \end_inset 
932 </cell>
933 </row>
934 <row topline="true">
935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
936 \begin_inset Text
937
938 \layout Standard
939
940
941 \emph on 
942 EXEC_PREFIX
943 \end_inset 
944 </cell>
945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
946 \begin_inset Text
947
948 \layout Standard
949
950
951 \emph on 
952 $PREFIX
953 \end_inset 
954 </cell>
955 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
956 \begin_inset Text
957
958 \layout Standard
959
960
961 \emph on 
962 $PREFIX
963 \end_inset 
964 </cell>
965 </row>
966 <row topline="true">
967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
968 \begin_inset Text
969
970 \layout Standard
971
972
973 \emph on 
974 BINDIR
975 \end_inset 
976 </cell>
977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
978 \begin_inset Text
979
980 \layout Standard
981
982
983 \emph on 
984 $EXECPREFIX
985 \emph default 
986 /bin
987 \end_inset 
988 </cell>
989 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
990 \begin_inset Text
991
992 \layout Standard
993
994
995 \emph on 
996 $EXECPREFIX
997 \emph default 
998
999 \backslash 
1000 bin
1001 \end_inset 
1002 </cell>
1003 </row>
1004 <row topline="true">
1005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1006 \begin_inset Text
1007
1008 \layout Standard
1009
1010
1011 \emph on 
1012 DATADIR
1013 \end_inset 
1014 </cell>
1015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1016 \begin_inset Text
1017
1018 \layout Standard
1019
1020
1021 \emph on 
1022 $PREFIX
1023 \emph default 
1024 /share
1025 \end_inset 
1026 </cell>
1027 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1028 \begin_inset Text
1029
1030 \layout Standard
1031
1032
1033 \emph on 
1034 $PREFIX
1035 \end_inset 
1036 </cell>
1037 </row>
1038 <row topline="true">
1039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1040 \begin_inset Text
1041
1042 \layout Standard
1043
1044
1045 \emph on 
1046 DOCDIR
1047 \end_inset 
1048 </cell>
1049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1050 \begin_inset Text
1051
1052 \layout Standard
1053
1054
1055 \emph on 
1056 $DATADIR
1057 \emph default 
1058 /sdcc/doc
1059 \end_inset 
1060 </cell>
1061 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1062 \begin_inset Text
1063
1064 \layout Standard
1065
1066
1067 \emph on 
1068 $DATADIR
1069 \emph default 
1070
1071 \backslash 
1072 doc
1073 \end_inset 
1074 </cell>
1075 </row>
1076 <row topline="true">
1077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1078 \begin_inset Text
1079
1080 \layout Standard
1081
1082
1083 \emph on 
1084 INCLUDE_DIR_SUFFIX
1085 \end_inset 
1086 </cell>
1087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1088 \begin_inset Text
1089
1090 \layout Standard
1091
1092 sdcc/include
1093 \end_inset 
1094 </cell>
1095 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1096 \begin_inset Text
1097
1098 \layout Standard
1099
1100 include
1101 \end_inset 
1102 </cell>
1103 </row>
1104 <row topline="true" bottomline="true">
1105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1106 \begin_inset Text
1107
1108 \layout Standard
1109
1110
1111 \emph on 
1112 LIB_DIR_SUFFIX
1113 \end_inset 
1114 </cell>
1115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1116 \begin_inset Text
1117
1118 \layout Standard
1119
1120 sdcc/lib
1121 \end_inset 
1122 </cell>
1123 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1124 \begin_inset Text
1125
1126 \layout Standard
1127
1128 lib
1129 \end_inset 
1130 </cell>
1131 </row>
1132 </lyxtabular>
1133
1134 \end_inset 
1135
1136
1137 \newline 
1138
1139 \layout Standard
1140 \noindent 
1141 'configure' also computes relative paths.
1142  This is needed for full relocatability of a binary package and to complete
1143  search paths (see section search paths below):
1144 \newline 
1145  
1146 \layout Standard
1147 \align center 
1148
1149 \begin_inset  Tabular
1150 <lyxtabular version="3" rows="4" columns="3">
1151 <features>
1152 <column alignment="block" valignment="top" leftline="true" width="0in">
1153 <column alignment="block" valignment="top" leftline="true" width="0in">
1154 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1155 <row topline="true" bottomline="true">
1156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1157 \begin_inset Text
1158
1159 \layout Standard
1160
1161 Variable (computed)
1162 \end_inset 
1163 </cell>
1164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1165 \begin_inset Text
1166
1167 \layout Standard
1168
1169 default
1170 \end_inset 
1171 </cell>
1172 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1173 \begin_inset Text
1174
1175 \layout Standard
1176
1177 Win32 builds
1178 \end_inset 
1179 </cell>
1180 </row>
1181 <row topline="true" bottomline="true">
1182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1183 \begin_inset Text
1184
1185 \layout Standard
1186
1187
1188 \emph on 
1189 BIN2DATA_DIR
1190 \end_inset 
1191 </cell>
1192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1193 \begin_inset Text
1194
1195 \layout Standard
1196
1197 ../share
1198 \end_inset 
1199 </cell>
1200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1201 \begin_inset Text
1202
1203 \layout Standard
1204
1205 ..
1206 \end_inset 
1207 </cell>
1208 </row>
1209 <row bottomline="true">
1210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1211 \begin_inset Text
1212
1213 \layout Standard
1214
1215
1216 \emph on 
1217 PREFIX2BIN_DIR
1218 \end_inset 
1219 </cell>
1220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1221 \begin_inset Text
1222
1223 \layout Standard
1224
1225 bin
1226 \end_inset 
1227 </cell>
1228 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1229 \begin_inset Text
1230
1231 \layout Standard
1232
1233 bin
1234 \end_inset 
1235 </cell>
1236 </row>
1237 <row bottomline="true">
1238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1239 \begin_inset Text
1240
1241 \layout Standard
1242
1243
1244 \emph on 
1245 PREFIX2DATA_DIR
1246 \end_inset 
1247 </cell>
1248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1249 \begin_inset Text
1250
1251 \layout Standard
1252
1253 share/sdcc
1254 \end_inset 
1255 </cell>
1256 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1257 \begin_inset Text
1258
1259 \layout Standard
1260
1261 \end_inset 
1262 </cell>
1263 </row>
1264 </lyxtabular>
1265
1266 \end_inset 
1267
1268
1269 \newline 
1270
1271 \layout Standard
1272 \noindent 
1273 Examples:
1274 \layout LyX-Code
1275
1276 ./configure
1277 \newline 
1278 ./configure -
1279 \begin_inset ERT
1280 status Collapsed
1281
1282 \layout Standard
1283
1284 \backslash 
1285 /
1286 \end_inset 
1287
1288 -prefix=
1289 \begin_inset Quotes srd
1290 \end_inset 
1291
1292 /usr/bin
1293 \begin_inset Quotes srd
1294 \end_inset 
1295
1296  -
1297 \begin_inset ERT
1298 status Collapsed
1299
1300 \layout Standard
1301
1302 \backslash 
1303 /
1304 \end_inset 
1305
1306 -datadir=
1307 \begin_inset Quotes srd
1308 \end_inset 
1309
1310 /usr/share
1311 \begin_inset Quotes srd
1312 \end_inset 
1313
1314
1315 \newline 
1316 ./configure -
1317 \begin_inset ERT
1318 status Collapsed
1319
1320 \layout Standard
1321
1322 \backslash 
1323 /
1324 \end_inset 
1325
1326 -disable-avr-port -
1327 \begin_inset ERT
1328 status Collapsed
1329
1330 \layout Standard
1331
1332 \backslash 
1333 /
1334 \end_inset 
1335
1336 -disable-xa51-port
1337 \layout Standard
1338
1339 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1340 32'):
1341 \layout LyX-Code
1342
1343 ./configure 
1344 \backslash 
1345
1346 \newline 
1347 CC=
1348 \begin_inset Quotes srd
1349 \end_inset 
1350
1351 i586-mingw32msvc-gcc
1352 \begin_inset Quotes srd
1353 \end_inset 
1354
1355  CXX=
1356 \begin_inset Quotes srd
1357 \end_inset 
1358
1359 i586-mingw32msvc-g++
1360 \begin_inset Quotes srd
1361 \end_inset 
1362
1363  
1364 \backslash 
1365  
1366 \newline 
1367 RANLIB=
1368 \begin_inset Quotes srd
1369 \end_inset 
1370
1371 i586-mingw32msvc-ranlib
1372 \begin_inset Quotes srd
1373 \end_inset 
1374
1375  
1376 \backslash 
1377
1378 \newline 
1379 STRIP=
1380 \begin_inset Quotes srd
1381 \end_inset 
1382
1383 i586-mingw32msvc-strip
1384 \begin_inset Quotes srd
1385 \end_inset 
1386
1387  
1388 \backslash 
1389
1390 \newline 
1391 -
1392 \begin_inset ERT
1393 status Collapsed
1394
1395 \layout Standard
1396
1397 \backslash 
1398 /
1399 \end_inset 
1400
1401 -prefix=
1402 \begin_inset Quotes srd
1403 \end_inset 
1404
1405 /sdcc
1406 \begin_inset Quotes srd
1407 \end_inset 
1408
1409  
1410 \backslash 
1411
1412 \newline 
1413 -
1414 \begin_inset ERT
1415 status Collapsed
1416
1417 \layout Standard
1418
1419 \backslash 
1420 /
1421 \end_inset 
1422
1423 -datadir=
1424 \begin_inset Quotes srd
1425 \end_inset 
1426
1427 /sdcc
1428 \begin_inset Quotes srd
1429 \end_inset 
1430
1431  
1432 \backslash 
1433
1434 \newline 
1435 docdir=
1436 \begin_inset Quotes srd
1437 \end_inset 
1438
1439 /sdcc/doc
1440 \begin_inset Quotes srd
1441 \end_inset 
1442
1443  
1444 \backslash 
1445
1446 \newline 
1447 include_dir_suffix=
1448 \begin_inset Quotes srd
1449 \end_inset 
1450
1451 include
1452 \begin_inset Quotes srd
1453 \end_inset 
1454
1455  
1456 \backslash 
1457
1458 \newline 
1459 lib_dir_suffix=
1460 \begin_inset Quotes srd
1461 \end_inset 
1462
1463 lib
1464 \begin_inset Quotes srd
1465 \end_inset 
1466
1467  
1468 \backslash 
1469
1470 \newline 
1471 sdccconf_h_dir_separator=
1472 \begin_inset Quotes srd
1473 \end_inset 
1474
1475
1476 \backslash 
1477
1478 \backslash 
1479
1480 \backslash 
1481
1482 \backslash 
1483
1484 \begin_inset Quotes srd
1485 \end_inset 
1486
1487  
1488 \backslash 
1489
1490 \newline 
1491 -
1492 \begin_inset ERT
1493 status Collapsed
1494
1495 \layout Standard
1496
1497 \backslash 
1498 /
1499 \end_inset 
1500
1501 -disable-device-lib-build
1502 \backslash 
1503
1504 \newline 
1505 -
1506 \begin_inset ERT
1507 status Collapsed
1508
1509 \layout Standard
1510
1511 \backslash 
1512 /
1513 \end_inset 
1514
1515 -disable-ucsim
1516 \backslash 
1517
1518 \newline 
1519 -
1520 \begin_inset ERT
1521 status Collapsed
1522
1523 \layout Standard
1524
1525 \backslash 
1526 /
1527 \end_inset 
1528
1529 -host=i586-mingw32msvc -
1530 \begin_inset ERT
1531 status Collapsed
1532
1533 \layout Standard
1534
1535 \backslash 
1536 /
1537 \end_inset 
1538
1539 -build=unknown-unknown-linux-gnu
1540 \layout Standard
1541
1542 To 
1543 \begin_inset Quotes sld
1544 \end_inset 
1545
1546 cross
1547 \begin_inset Quotes srd
1548 \end_inset 
1549
1550 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
1551 ):
1552 \layout LyX-Code
1553
1554 ./configure -C 
1555 \backslash 
1556
1557 \newline 
1558 CFLAGS=
1559 \begin_inset Quotes srd
1560 \end_inset 
1561
1562 -mno-cygwin -O2
1563 \begin_inset Quotes srd
1564 \end_inset 
1565
1566  
1567 \backslash 
1568
1569 \newline 
1570 LDFLAGS=
1571 \begin_inset Quotes srd
1572 \end_inset 
1573
1574 -mno-cygwin
1575 \begin_inset Quotes srd
1576 \end_inset 
1577
1578  
1579 \backslash 
1580
1581 \newline 
1582 -
1583 \begin_inset ERT
1584 status Collapsed
1585
1586 \layout Standard
1587
1588 \backslash 
1589 /
1590 \end_inset 
1591
1592 -prefix=
1593 \begin_inset Quotes srd
1594 \end_inset 
1595
1596 /sdcc
1597 \begin_inset Quotes srd
1598 \end_inset 
1599
1600  
1601 \backslash 
1602
1603 \newline 
1604 -
1605 \begin_inset ERT
1606 status Collapsed
1607
1608 \layout Standard
1609
1610 \backslash 
1611 /
1612 \end_inset 
1613
1614 -datadir=
1615 \begin_inset Quotes srd
1616 \end_inset 
1617
1618 /sdcc
1619 \begin_inset Quotes srd
1620 \end_inset 
1621
1622  
1623 \backslash 
1624
1625 \newline 
1626 docdir=
1627 \begin_inset Quotes srd
1628 \end_inset 
1629
1630 /sdcc/doc
1631 \begin_inset Quotes srd
1632 \end_inset 
1633
1634  
1635 \backslash 
1636  
1637 \newline 
1638 include_dir_suffix=
1639 \begin_inset Quotes srd
1640 \end_inset 
1641
1642 include
1643 \begin_inset Quotes srd
1644 \end_inset 
1645
1646  
1647 \backslash 
1648
1649 \newline 
1650 lib_dir_suffix=
1651 \begin_inset Quotes srd
1652 \end_inset 
1653
1654 lib
1655 \begin_inset Quotes srd
1656 \end_inset 
1657
1658  
1659 \backslash 
1660
1661 \newline 
1662 sdccconf_h_dir_separator=
1663 \begin_inset Quotes srd
1664 \end_inset 
1665
1666
1667 \backslash 
1668
1669 \backslash 
1670
1671 \backslash 
1672
1673 \backslash 
1674
1675 \begin_inset Quotes srd
1676 \end_inset 
1677
1678  
1679 \backslash 
1680
1681 \newline 
1682 -
1683 \begin_inset ERT
1684 status Collapsed
1685
1686 \layout Standard
1687
1688 \backslash 
1689 /
1690 \end_inset 
1691
1692 -disable-ucsim
1693 \layout Standard
1694
1695 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
1696  The option '-
1697 \begin_inset ERT
1698 status Collapsed
1699
1700 \layout Standard
1701
1702 \backslash 
1703 /
1704 \end_inset 
1705
1706 -C' turns on caching, which gives a little bit extra speed.
1707  However if options are changed, it can be necessary to delete the config.cache
1708  file.
1709 \layout Section
1710
1711 Install paths
1712 \begin_inset LatexCommand \label{sub:Install-paths}
1713
1714 \end_inset 
1715
1716
1717 \begin_inset LatexCommand \index{Install paths}
1718
1719 \end_inset 
1720
1721
1722 \layout Standard
1723 \added_space_top medskip \align center 
1724
1725 \begin_inset  Tabular
1726 <lyxtabular version="3" rows="5" columns="4">
1727 <features>
1728 <column alignment="center" valignment="top" leftline="true" width="0">
1729 <column alignment="center" valignment="top" leftline="true" width="0">
1730 <column alignment="center" valignment="top" leftline="true" width="0">
1731 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
1732 <row topline="true" bottomline="true">
1733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1734 \begin_inset Text
1735
1736 \layout Standard
1737
1738
1739 \series bold 
1740 Description
1741 \end_inset 
1742 </cell>
1743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1744 \begin_inset Text
1745
1746 \layout Standard
1747
1748
1749 \series bold 
1750 Path
1751 \end_inset 
1752 </cell>
1753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1754 \begin_inset Text
1755
1756 \layout Standard
1757
1758
1759 \series bold 
1760 Default
1761 \end_inset 
1762 </cell>
1763 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1764 \begin_inset Text
1765
1766 \layout Standard
1767
1768
1769 \series bold 
1770 Win32 builds
1771 \end_inset 
1772 </cell>
1773 </row>
1774 <row topline="true">
1775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1776 \begin_inset Text
1777
1778 \layout Standard
1779
1780 Binary files*
1781 \end_inset 
1782 </cell>
1783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1784 \begin_inset Text
1785
1786 \layout Standard
1787
1788
1789 \emph on 
1790 $EXEC_PREFIX
1791 \end_inset 
1792 </cell>
1793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1794 \begin_inset Text
1795
1796 \layout Standard
1797
1798 /usr/local/bin
1799 \end_inset 
1800 </cell>
1801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1802 \begin_inset Text
1803
1804 \layout Standard
1805
1806
1807 \backslash 
1808 sdcc
1809 \backslash 
1810 bin
1811 \end_inset 
1812 </cell>
1813 </row>
1814 <row topline="true">
1815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1816 \begin_inset Text
1817
1818 \layout Standard
1819
1820 Include files
1821 \end_inset 
1822 </cell>
1823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1824 \begin_inset Text
1825
1826 \layout Standard
1827
1828
1829 \emph on 
1830 $DATADIR/ $INCLUDE_DIR_SUFFIX
1831 \end_inset 
1832 </cell>
1833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1834 \begin_inset Text
1835
1836 \layout Standard
1837
1838 /usr/local/share/sdcc/include
1839 \end_inset 
1840 </cell>
1841 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1842 \begin_inset Text
1843
1844 \layout Standard
1845
1846
1847 \backslash 
1848 sdcc
1849 \backslash 
1850 include
1851 \end_inset 
1852 </cell>
1853 </row>
1854 <row topline="true">
1855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1856 \begin_inset Text
1857
1858 \layout Standard
1859
1860 Library file**
1861 \end_inset 
1862 </cell>
1863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1864 \begin_inset Text
1865
1866 \layout Standard
1867
1868
1869 \emph on 
1870 $DATADIR/$LIB_DIR_SUFFIX
1871 \end_inset 
1872 </cell>
1873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1874 \begin_inset Text
1875
1876 \layout Standard
1877
1878 /usr/local/share/sdcc/lib
1879 \end_inset 
1880 </cell>
1881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1882 \begin_inset Text
1883
1884 \layout Standard
1885
1886
1887 \backslash 
1888 sdcc
1889 \backslash 
1890 lib
1891 \end_inset 
1892 </cell>
1893 </row>
1894 <row topline="true" bottomline="true">
1895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1896 \begin_inset Text
1897
1898 \layout Standard
1899
1900 Documentation
1901 \end_inset 
1902 </cell>
1903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1904 \begin_inset Text
1905
1906 \layout Standard
1907
1908
1909 \emph on 
1910 $DOCDIR
1911 \end_inset 
1912 </cell>
1913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1914 \begin_inset Text
1915
1916 \layout Standard
1917
1918 /usr/local/share/sdcc/doc
1919 \end_inset 
1920 </cell>
1921 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1922 \begin_inset Text
1923
1924 \layout Standard
1925
1926
1927 \backslash 
1928 sdcc
1929 \backslash 
1930 doc
1931 \end_inset 
1932 </cell>
1933 </row>
1934 </lyxtabular>
1935
1936 \end_inset 
1937
1938
1939 \layout Verse
1940
1941
1942 \size footnotesize 
1943 *compiler, preprocessor, assembler, and linker
1944 \newline 
1945 **the 
1946 \shape italic 
1947 model
1948 \shape default 
1949  is auto-appended by the compiler, e.g.
1950  small, large, z80, ds390 etc
1951 \layout Standard
1952 \noindent 
1953 The install paths can still be changed during `make install` with e.g.:
1954 \layout LyX-Code
1955
1956 make install prefix=$(HOME)/local/sdcc
1957 \layout Standard
1958
1959 Of course this doesn't change the search paths compiled into the binaries.
1960 \layout Section
1961
1962 Search Paths
1963 \begin_inset LatexCommand \label{sub:Search-Paths}
1964
1965 \end_inset 
1966
1967
1968 \begin_inset LatexCommand \index{Search path}
1969
1970 \end_inset 
1971
1972
1973 \layout Standard
1974
1975 Some search paths or parts of them are determined by configure variables
1976  (in 
1977 \emph on 
1978 italics
1979 \emph default 
1980 , see section above).
1981  Further search paths are determined by environment variables during runtime.
1982  
1983 \newline 
1984 The paths searched when running the compiler are as follows (the first catch
1985  wins):
1986 \newline 
1987
1988 \newline 
1989 1.
1990  Binary files (preprocessor, assembler and linker)
1991 \newline 
1992
1993 \layout Standard
1994 \align center 
1995
1996 \begin_inset  Tabular
1997 <lyxtabular version="3" rows="4" columns="3">
1998 <features>
1999 <column alignment="block" valignment="top" leftline="true" width="0in">
2000 <column alignment="block" valignment="top" leftline="true" width="0in">
2001 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2002 <row topline="true" bottomline="true">
2003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2004 \begin_inset Text
2005
2006 \layout Standard
2007
2008 Search path
2009 \end_inset 
2010 </cell>
2011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2012 \begin_inset Text
2013
2014 \layout Standard
2015
2016 default
2017 \end_inset 
2018 </cell>
2019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2020 \begin_inset Text
2021
2022 \layout Standard
2023
2024 Win32 builds
2025 \end_inset 
2026 </cell>
2027 </row>
2028 <row topline="true">
2029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2030 \begin_inset Text
2031
2032 \layout Standard
2033
2034 $SDCC_HOME/
2035 \emph on 
2036 $PPREFIX2BIN_DIR
2037 \end_inset 
2038 </cell>
2039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2040 \begin_inset Text
2041
2042 \layout Standard
2043
2044 $SDCC_HOME/bin
2045 \end_inset 
2046 </cell>
2047 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2048 \begin_inset Text
2049
2050 \layout Standard
2051
2052 $SDCC_HOME
2053 \backslash 
2054 bin
2055 \end_inset 
2056 </cell>
2057 </row>
2058 <row topline="true">
2059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2060 \begin_inset Text
2061
2062 \layout Standard
2063
2064 Path of argv[0] (if available)
2065 \end_inset 
2066 </cell>
2067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2068 \begin_inset Text
2069
2070 \layout Standard
2071
2072 Path of argv[0]
2073 \end_inset 
2074 </cell>
2075 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2076 \begin_inset Text
2077
2078 \layout Standard
2079
2080 Path of argv[0]
2081 \end_inset 
2082 </cell>
2083 </row>
2084 <row topline="true" bottomline="true">
2085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2086 \begin_inset Text
2087
2088 \layout Standard
2089
2090 $PATH
2091 \end_inset 
2092 </cell>
2093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2094 \begin_inset Text
2095
2096 \layout Standard
2097
2098 $PATH
2099 \end_inset 
2100 </cell>
2101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2102 \begin_inset Text
2103
2104 \layout Standard
2105
2106 $PATH
2107 \end_inset 
2108 </cell>
2109 </row>
2110 </lyxtabular>
2111
2112 \end_inset 
2113
2114  
2115 \newline 
2116
2117 \layout Standard
2118 \noindent 
2119 2.
2120  Include files
2121 \newline 
2122
2123 \layout Standard
2124 \align center 
2125
2126 \begin_inset  Tabular
2127 <lyxtabular version="3" rows="6" columns="3">
2128 <features>
2129 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2130 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2131 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2132 <row topline="true" bottomline="true">
2133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2134 \begin_inset Text
2135
2136 \layout Standard
2137
2138 Search path
2139 \end_inset 
2140 </cell>
2141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2142 \begin_inset Text
2143
2144 \layout Standard
2145
2146 default
2147 \end_inset 
2148 </cell>
2149 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2150 \begin_inset Text
2151
2152 \layout Standard
2153
2154 Win32 builds
2155 \end_inset 
2156 </cell>
2157 </row>
2158 <row topline="true">
2159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2160 \begin_inset Text
2161
2162 \layout Standard
2163
2164 -
2165 \begin_inset ERT
2166 status Collapsed
2167
2168 \layout Standard
2169
2170 \backslash 
2171 /
2172 \end_inset 
2173
2174 -I dir
2175 \end_inset 
2176 </cell>
2177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2178 \begin_inset Text
2179
2180 \layout Standard
2181
2182 -
2183 \begin_inset ERT
2184 status Collapsed
2185
2186 \layout Standard
2187
2188 \backslash 
2189 /
2190 \end_inset 
2191
2192 -I dir
2193 \end_inset 
2194 </cell>
2195 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2196 \begin_inset Text
2197
2198 \layout Standard
2199
2200 -
2201 \begin_inset ERT
2202 status Collapsed
2203
2204 \layout Standard
2205
2206 \backslash 
2207 /
2208 \end_inset 
2209
2210 -I dir
2211 \end_inset 
2212 </cell>
2213 </row>
2214 <row topline="true">
2215 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2216 \begin_inset Text
2217
2218 \layout Standard
2219
2220 $SDCC_INCLUDE
2221 \end_inset 
2222 </cell>
2223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2224 \begin_inset Text
2225
2226 \layout Standard
2227
2228 $SDCC_INCLUDE
2229 \end_inset 
2230 </cell>
2231 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2232 \begin_inset Text
2233
2234 \layout Standard
2235
2236 $SDCC_INCLUDE
2237 \end_inset 
2238 </cell>
2239 </row>
2240 <row topline="true">
2241 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2242 \begin_inset Text
2243
2244 \layout Standard
2245
2246 $SDCC_HOME/
2247 \newline 
2248
2249 \emph on 
2250 $PREFIX2DATA_DIR/
2251 \newline 
2252 $INCLUDE_DIR_SUFFIX
2253 \end_inset 
2254 </cell>
2255 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2256 \begin_inset Text
2257
2258 \layout Standard
2259
2260 $SDCC_ HOME/
2261 \newline 
2262 share/sdcc/
2263 \newline 
2264 include
2265 \end_inset 
2266 </cell>
2267 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2268 \begin_inset Text
2269
2270 \layout Standard
2271
2272 $SDCC_HOME
2273 \backslash 
2274 include
2275 \end_inset 
2276 </cell>
2277 </row>
2278 <row topline="true">
2279 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2280 \begin_inset Text
2281
2282 \layout Standard
2283
2284 path(argv[0])/
2285 \newline 
2286
2287 \emph on 
2288 $BIN2DATADIR/
2289 \emph default 
2290
2291 \newline 
2292
2293 \emph on 
2294 $INCLUDE_DIR_SUFFIX
2295 \end_inset 
2296 </cell>
2297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2298 \begin_inset Text
2299
2300 \layout Standard
2301
2302 path(argv[0])/
2303 \newline 
2304 ../sdcc/include
2305 \newline 
2306 \SpecialChar ~
2307 \SpecialChar ~
2308 \SpecialChar ~
2309 \SpecialChar ~
2310 \SpecialChar ~
2311 \SpecialChar ~
2312 \SpecialChar ~
2313 \SpecialChar ~
2314 \SpecialChar ~
2315 \SpecialChar ~
2316 \SpecialChar ~
2317 \SpecialChar ~
2318 \SpecialChar ~
2319 \SpecialChar ~
2320 \SpecialChar ~
2321 \SpecialChar ~
2322 \SpecialChar ~
2323 \SpecialChar ~
2324 \SpecialChar ~
2325 \SpecialChar ~
2326 \SpecialChar ~
2327 \SpecialChar ~
2328 \SpecialChar ~
2329 \SpecialChar ~
2330 \SpecialChar ~
2331 \SpecialChar ~
2332 \SpecialChar ~
2333 \SpecialChar ~
2334 \SpecialChar ~
2335 \SpecialChar ~
2336 \SpecialChar ~
2337 \SpecialChar ~
2338 \SpecialChar ~
2339 \SpecialChar ~
2340 \SpecialChar ~
2341 \SpecialChar ~
2342 \SpecialChar ~
2343 \SpecialChar ~
2344
2345 \end_inset 
2346 </cell>
2347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2348 \begin_inset Text
2349
2350 \layout Standard
2351
2352 path(argv[0])
2353 \backslash 
2354 ..
2355 \backslash 
2356 include
2357 \end_inset 
2358 </cell>
2359 </row>
2360 <row topline="true" bottomline="true">
2361 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2362 \begin_inset Text
2363
2364 \layout Standard
2365
2366
2367 \emph on 
2368 $DATADIR/
2369 \emph default 
2370
2371 \newline 
2372
2373 \emph on 
2374 $INCLUDE_DIR_SUFFIX
2375 \end_inset 
2376 </cell>
2377 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2378 \begin_inset Text
2379
2380 \layout Standard
2381
2382 /usr/local/share/sdcc/
2383 \newline 
2384 include
2385 \end_inset 
2386 </cell>
2387 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2388 \begin_inset Text
2389
2390 \layout Standard
2391
2392 (not on Win32)
2393 \end_inset 
2394 </cell>
2395 </row>
2396 </lyxtabular>
2397
2398 \end_inset 
2399
2400  
2401 \newline 
2402
2403 \layout Standard
2404 \noindent 
2405 The option -
2406 \begin_inset ERT
2407 status Collapsed
2408
2409 \layout Standard
2410
2411 \backslash 
2412 /
2413 \end_inset 
2414
2415 -nostdinc disables the last two search paths.
2416 \newline 
2417
2418 \newline 
2419 3.
2420  Library files 
2421 \newline 
2422
2423 \layout Standard
2424
2425 With the exception of 
2426 \begin_inset Quotes sld
2427 \end_inset 
2428
2429 -
2430 \begin_inset ERT
2431 status Collapsed
2432
2433 \layout Standard
2434
2435 \backslash 
2436 /
2437 \end_inset 
2438
2439 -L dir
2440 \begin_inset Quotes srd
2441 \end_inset 
2442
2443  the 
2444 \shape italic 
2445 model
2446 \shape default 
2447  is auto-appended by the compiler (e.g.
2448  small, large, z80, ds390 etc.).
2449  
2450 \newline 
2451
2452 \layout Standard
2453 \align center 
2454
2455 \begin_inset  Tabular
2456 <lyxtabular version="3" rows="6" columns="3">
2457 <features>
2458 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2459 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2460 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2461 <row topline="true" bottomline="true">
2462 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2463 \begin_inset Text
2464
2465 \layout Standard
2466
2467 Search path
2468 \end_inset 
2469 </cell>
2470 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2471 \begin_inset Text
2472
2473 \layout Standard
2474
2475 default
2476 \end_inset 
2477 </cell>
2478 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2479 \begin_inset Text
2480
2481 \layout Standard
2482
2483 Win32 builds
2484 \end_inset 
2485 </cell>
2486 </row>
2487 <row topline="true">
2488 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2489 \begin_inset Text
2490
2491 \layout Standard
2492
2493 -
2494 \begin_inset ERT
2495 status Collapsed
2496
2497 \layout Standard
2498
2499 \backslash 
2500 /
2501 \end_inset 
2502
2503 -L dir
2504 \end_inset 
2505 </cell>
2506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2507 \begin_inset Text
2508
2509 \layout Standard
2510
2511 -
2512 \begin_inset ERT
2513 status Collapsed
2514
2515 \layout Standard
2516
2517 \backslash 
2518 /
2519 \end_inset 
2520
2521 -L dir
2522 \end_inset 
2523 </cell>
2524 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2525 \begin_inset Text
2526
2527 \layout Standard
2528
2529 -
2530 \begin_inset ERT
2531 status Collapsed
2532
2533 \layout Standard
2534
2535 \backslash 
2536 /
2537 \end_inset 
2538
2539 -L dir
2540 \end_inset 
2541 </cell>
2542 </row>
2543 <row topline="true">
2544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2545 \begin_inset Text
2546
2547 \layout Standard
2548
2549 $SDCC_LIB/
2550 \newline 
2551
2552 \emph on 
2553 <model>
2554 \end_inset 
2555 </cell>
2556 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2557 \begin_inset Text
2558
2559 \layout Standard
2560
2561 $SDCC_LIB/
2562 \newline 
2563
2564 \emph on 
2565 <model>
2566 \end_inset 
2567 </cell>
2568 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2569 \begin_inset Text
2570
2571 \layout Standard
2572
2573 $SDCC_LIB
2574 \backslash 
2575
2576 \newline 
2577
2578 \emph on 
2579 <model>
2580 \end_inset 
2581 </cell>
2582 </row>
2583 <row topline="true">
2584 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2585 \begin_inset Text
2586
2587 \layout Standard
2588
2589 $SDCC_HOME/
2590 \newline 
2591
2592 \emph on 
2593 $PREFIX2DATA_DIR/
2594 \newline 
2595 $LIB_DIR_SUFFIX/<model>
2596 \end_inset 
2597 </cell>
2598 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2599 \begin_inset Text
2600
2601 \layout Standard
2602
2603 $SDCC_HOME/
2604 \newline 
2605 share/sdcc/
2606 \newline 
2607 lib/
2608 \emph on 
2609 <model>
2610 \end_inset 
2611 </cell>
2612 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2613 \begin_inset Text
2614
2615 \layout Standard
2616
2617 $SDCC_HOME
2618 \backslash 
2619 lib
2620 \backslash 
2621
2622 \emph on 
2623
2624 \newline 
2625 <model>
2626 \end_inset 
2627 </cell>
2628 </row>
2629 <row topline="true">
2630 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2631 \begin_inset Text
2632
2633 \layout Standard
2634
2635 path(argv[0])/
2636 \newline 
2637
2638 \emph on 
2639 $BIN2DATADIR/
2640 \emph default 
2641
2642 \newline 
2643
2644 \emph on 
2645 $LIB_DIR_SUFFIX/<model>
2646 \end_inset 
2647 </cell>
2648 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2649 \begin_inset Text
2650
2651 \layout Standard
2652
2653 path(argv[0])/
2654 \newline 
2655 ../sdcc/lib/
2656 \emph on 
2657 <model>
2658 \newline 
2659 \SpecialChar ~
2660 \SpecialChar ~
2661 \SpecialChar ~
2662 \SpecialChar ~
2663 \SpecialChar ~
2664 \SpecialChar ~
2665 \SpecialChar ~
2666 \SpecialChar ~
2667 \SpecialChar ~
2668 \SpecialChar ~
2669 \SpecialChar ~
2670 \SpecialChar ~
2671 \SpecialChar ~
2672 \SpecialChar ~
2673 \SpecialChar ~
2674 \SpecialChar ~
2675 \SpecialChar ~
2676 \SpecialChar ~
2677 \SpecialChar ~
2678 \SpecialChar ~
2679 \SpecialChar ~
2680 \SpecialChar ~
2681 \SpecialChar ~
2682 \SpecialChar ~
2683 \SpecialChar ~
2684 \SpecialChar ~
2685 \SpecialChar ~
2686 \SpecialChar ~
2687 \SpecialChar ~
2688 \SpecialChar ~
2689 \SpecialChar ~
2690 \SpecialChar ~
2691 \SpecialChar ~
2692 \SpecialChar ~
2693 \SpecialChar ~
2694 \SpecialChar ~
2695 \SpecialChar ~
2696 \SpecialChar ~
2697 \SpecialChar ~
2698
2699 \end_inset 
2700 </cell>
2701 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2702 \begin_inset Text
2703
2704 \layout Standard
2705
2706 path(argv[0])
2707 \backslash 
2708
2709 \newline 
2710 ..
2711 \backslash 
2712 lib
2713 \backslash 
2714
2715 \emph on 
2716 <model>
2717 \newline 
2718 \SpecialChar ~
2719 \SpecialChar ~
2720 \SpecialChar ~
2721 \SpecialChar ~
2722 \SpecialChar ~
2723 \SpecialChar ~
2724 \SpecialChar ~
2725 \SpecialChar ~
2726 \SpecialChar ~
2727 \SpecialChar ~
2728 \SpecialChar ~
2729 \SpecialChar ~
2730 \SpecialChar ~
2731 \SpecialChar ~
2732 \SpecialChar ~
2733 \SpecialChar ~
2734 \SpecialChar ~
2735 \SpecialChar ~
2736 \SpecialChar ~
2737 \SpecialChar ~
2738 \SpecialChar ~
2739 \SpecialChar ~
2740 \SpecialChar ~
2741 \SpecialChar ~
2742 \SpecialChar ~
2743 \SpecialChar ~
2744 \SpecialChar ~
2745 \SpecialChar ~
2746 \SpecialChar ~
2747 \SpecialChar ~
2748 \SpecialChar ~
2749 \SpecialChar ~
2750 \SpecialChar ~
2751 \SpecialChar ~
2752 \SpecialChar ~
2753
2754 \end_inset 
2755 </cell>
2756 </row>
2757 <row topline="true" bottomline="true">
2758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2759 \begin_inset Text
2760
2761 \layout Standard
2762
2763
2764 \emph on 
2765 $DATADIR/
2766 \newline 
2767 $LIB_DIR_SUFFIX/<model>
2768 \end_inset 
2769 </cell>
2770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2771 \begin_inset Text
2772
2773 \layout Standard
2774
2775 /usr/local/share/sdcc/
2776 \newline 
2777 lib/
2778 \emph on 
2779 <model>
2780 \end_inset 
2781 </cell>
2782 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2783 \begin_inset Text
2784
2785 \layout Standard
2786
2787 (not on Win32)
2788 \end_inset 
2789 </cell>
2790 </row>
2791 </lyxtabular>
2792
2793 \end_inset 
2794
2795
2796 \newline 
2797
2798 \layout Comment
2799
2800 Don't delete any of the stray spaces in the table above without checking
2801  the HTML output (last line)!
2802 \layout Standard
2803
2804 \SpecialChar ~
2805
2806 \newline 
2807 The option -
2808 \begin_inset ERT
2809 status Collapsed
2810
2811 \layout Standard
2812
2813 \backslash 
2814 /
2815 \end_inset 
2816
2817 -nostdlib disables the last two search paths.
2818 \layout Section
2819
2820 Building SDCC
2821 \begin_inset LatexCommand \index{Building SDCC}
2822
2823 \end_inset 
2824
2825
2826 \layout Subsection
2827
2828 Building SDCC on Linux
2829 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
2830
2831 \end_inset 
2832
2833
2834 \layout Enumerate
2835
2836
2837 \series medium 
2838 Download the source package
2839 \series default 
2840  either from the SDCC CVS repository or from the nightly snapshots
2841 \series medium 
2842 , it will be named something like sdcc
2843 \series default 
2844 .src
2845 \series medium 
2846 .t
2847 \series default 
2848 ar.
2849 \series medium 
2850 gz
2851 \series default 
2852  
2853 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
2854
2855 \end_inset 
2856
2857 .
2858 \layout Enumerate
2859
2860
2861 \series medium 
2862 Bring up a command line terminal, such as xterm.
2863 \layout Enumerate
2864
2865
2866 \series medium 
2867 Unpack the file using a command like: 
2868 \family sans 
2869 \series bold 
2870 "tar -xvzf sdcc.src.tar.gz
2871 \family default 
2872 \series default 
2873 "
2874 \series medium 
2875 , this will create a sub-directory called sdcc with all of the sources.
2876 \layout Enumerate
2877
2878 Change directory into the main SDCC directory, for example type: 
2879 \family sans 
2880 \series bold 
2881 "cd sdcc
2882 \series default 
2883 ".
2884 \layout Enumerate
2885
2886
2887 \series medium 
2888 Type 
2889 \family sans 
2890 \series bold 
2891 "./configure
2892 \family default 
2893 \series default 
2894 ".
2895  This configures the package for compilation on your system.
2896 \layout Enumerate
2897
2898
2899 \series medium 
2900 Type 
2901 \family sans 
2902 \series bold 
2903 "make
2904 \family default 
2905 \series default 
2906 "
2907 \series medium 
2908 .
2909
2910 \series default 
2911  All of the source packages will compile, this can take a while.
2912 \layout Enumerate
2913
2914
2915 \series medium 
2916 Type 
2917 \family sans 
2918 \series bold 
2919 "make install"
2920 \family default 
2921 \series default 
2922  as root
2923 \series medium 
2924 .
2925
2926 \series default 
2927  This copies the binary executables, the include files, the libraries and
2928  the documentation to the install directories.
2929  Proceed with section 
2930 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
2931
2932 \end_inset 
2933
2934 .
2935 \layout Subsection
2936
2937 Building SDCC on OSX 2.x
2938 \layout Standard
2939
2940 Follow the instruction for Linux.
2941 \newline 
2942
2943 \newline 
2944 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
2945 )) fails to compile SDCC.
2946  Fortunately there's also gcc 2.9.x installed, which works fine.
2947  This compiler can be selected by running 'configure' with:
2948 \layout LyX-Code
2949
2950 ./configure CC=gcc2 CXX=g++2
2951 \layout Subsection
2952
2953 Cross compiling SDCC on Linux for Windows
2954 \layout Standard
2955
2956 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
2957  See section 'Configure Options'.
2958 \layout Subsection
2959
2960 Building SDCC on Windows 
2961 \layout Standard
2962
2963 With the exception of Cygwin the SDCC binaries uCsim and sdcdb can't be
2964  built on Windows.
2965  They use Unix-sockets, which are not available on Win32.
2966 \layout Subsection
2967
2968 Building SDCC using Cygwin and Mingw32
2969 \layout Standard
2970
2971 For building and installing a Cygwin executable follow the instructions
2972  for Linux.
2973 \newline 
2974
2975 \newline 
2976 On Cygwin a 
2977 \begin_inset Quotes sld
2978 \end_inset 
2979
2980 native
2981 \begin_inset Quotes srd
2982 \end_inset 
2983
2984  Win32-binary can be built, which will not need the Cygwin-DLL.
2985  For the necessary 'configure' options see section 'configure options' or
2986  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
2987 \newline 
2988
2989 \newline 
2990 In order to install Cygwin on Windows download setup.exe from 
2991 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
2992
2993 \end_inset 
2994
2995 .
2996  Run it, set the 
2997 \begin_inset Quotes sld
2998 \end_inset 
2999
3000 default text file type
3001 \begin_inset Quotes srd
3002 \end_inset 
3003
3004  to 
3005 \begin_inset Quotes sld
3006 \end_inset 
3007
3008 unix
3009 \begin_inset Quotes srd
3010 \end_inset 
3011
3012  and download/install at least the following packages.
3013  Some packages are selected by default, others will be automatically selected
3014  because of dependencies with the manually selected packages.
3015  Never deselect these packages!
3016 \layout Itemize
3017
3018 flex
3019 \layout Itemize
3020
3021 bison
3022 \layout Itemize
3023
3024 gcc ; version 3.x is fine, no need to use the old 2.9x
3025 \layout Itemize
3026
3027 binutils ; selected with gcc
3028 \layout Itemize
3029
3030 make
3031 \layout Itemize
3032
3033 rxvt ; a nice console, which makes life much easier under windoze (see below)
3034 \layout Itemize
3035
3036 man ; not really needed for building SDCC, but you'll miss it sooner or
3037  later
3038 \layout Itemize
3039
3040 less ; not really needed for building SDCC, but you'll miss it sooner or
3041  later
3042 \layout Itemize
3043
3044 cvs ; only if you use CVS access
3045 \layout Standard
3046
3047 If you want to develop something you'll need:
3048 \layout Itemize
3049
3050 python ; for the regression tests
3051 \layout Itemize
3052
3053 gdb ; the gnu debugger, together with the nice GUI 
3054 \begin_inset Quotes sld
3055 \end_inset 
3056
3057 insight
3058 \begin_inset Quotes srd
3059 \end_inset 
3060
3061
3062 \layout Itemize
3063
3064 openssh ; to access the CF or commit changes
3065 \layout Itemize
3066
3067 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3068  use autoconf-stable!
3069 \layout Standard
3070
3071 rxvt is a nice console with history.
3072  Replace in your cygwin.bat the line
3073 \layout LyX-Code
3074
3075 bash -
3076 \begin_inset ERT
3077 status Collapsed
3078
3079 \layout Standard
3080
3081 \backslash 
3082 /
3083 \end_inset 
3084
3085 -login -i 
3086 \layout Standard
3087
3088 with (one line):
3089 \layout LyX-Code
3090
3091 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3092 \layout LyX-Code
3093
3094      -bg black -fg white -geometry 100x65 -e bash -
3095 \begin_inset ERT
3096 status Collapsed
3097
3098 \layout Standard
3099
3100 \backslash 
3101 /
3102 \end_inset 
3103
3104 -login
3105 \layout Standard
3106
3107 Text selected with the mouse is automatically copied to the clipboard, pasting
3108  works with shift-insert.
3109 \newline 
3110
3111 \newline 
3112 The other good tip is to make sure you have no //c/-style paths anywhere,
3113  use /cygdrive/c/ instead.
3114  Using // invokes a network lookup which is very slow.
3115  If you think 
3116 \begin_inset Quotes sld
3117 \end_inset 
3118
3119 cygdrive
3120 \begin_inset Quotes srd
3121 \end_inset 
3122
3123  is too long, you can change it with e.g.
3124 \layout LyX-Code
3125
3126 mount -s -u -c /mnt
3127 \layout Standard
3128
3129 SDCC sources use the unix line ending LF.
3130  Life is much easier, if you store the source tree on a drive which is mounted
3131  in binary mode.
3132  And use an editor which can handle LF-only line endings.
3133  Make sure not to commit files with windows line endings.
3134  The tabulator spacing
3135 \begin_inset LatexCommand \index{tabulator spacing (8)}
3136
3137 \end_inset 
3138
3139  used in the project is 8.
3140 \layout Subsection
3141
3142 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3143 \layout Standard
3144
3145
3146 \series medium 
3147 Download the source package
3148 \series default 
3149  either from the SDCC CVS repository or from the 
3150 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3151
3152 \end_inset 
3153
3154
3155 \series medium 
3156 , it will be named something like sdcc
3157 \series default 
3158 .src
3159 \series medium 
3160 .tgz.
3161
3162 \series default 
3163  SDCC is distributed with all the projects, workspaces, and files you need
3164  to build it using Visual C++ 6.0/NET (except for sdcdb.exe which currently
3165  doesn't build under MSVC).
3166  The workspace name is 'sdcc.dsw'.
3167  Please note that as it is now, all the executables are created in a folder
3168  called sdcc
3169 \backslash 
3170 bin_vc.
3171  Once built you need to copy the executables from sdcc
3172 \backslash 
3173 bin_vc to sdcc
3174 \backslash 
3175 bin before running SDCC.
3176  
3177 \newline 
3178
3179 \newline 
3180 WARNING: Visual studio is very picky with line terminations; it expects
3181  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
3182  If you are getting a message such as "This makefile was not generated by
3183  Developer Studio etc.
3184  etc.
3185 \begin_inset Quotes srd
3186 \end_inset 
3187
3188  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
3189  need to convert the Unix style line endings to DOS style line endings.
3190  To do so you can use the 
3191 \begin_inset Quotes sld
3192 \end_inset 
3193
3194 unix2dos
3195 \begin_inset Quotes srd
3196 \end_inset 
3197
3198  utility freely available on the internet.
3199  Doug Hawkins reported in the sdcc-user list that this works:
3200 \newline 
3201
3202 \newline 
3203 C:
3204 \backslash 
3205 Programming
3206 \backslash 
3207 SDCC> unix2dos sdcc.dsw
3208 \newline 
3209 C:
3210 \backslash 
3211 Programming
3212 \backslash 
3213 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
3214 \newline 
3215
3216 \newline 
3217 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3218  flex.exe, and gawk.exe.
3219  One good place to get them is 
3220 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3221
3222 \end_inset 
3223
3224
3225 \newline 
3226
3227 \newline 
3228 Download the file UnxUtils
3229 \begin_inset LatexCommand \index{UnxUtils}
3230
3231 \end_inset 
3232
3233 .zip.
3234  Now you have to install the utilities and setup MSVC so it can locate the
3235  required programs.
3236  Here there are two alternatives (choose one!):
3237 \layout Enumerate
3238
3239 The easy way:
3240 \newline 
3241
3242 \newline 
3243 a) Extract UnxUtils.zip to your C:
3244 \backslash 
3245  hard disk PRESERVING the original paths, otherwise bison won't work.
3246  (If you are using WinZip make certain that 'Use folder names' is selected)
3247 \newline 
3248
3249 \newline 
3250 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3251  in 'Show directories for:' select 'Executable files', and in the directories
3252  window add a new path: 'C:
3253 \backslash 
3254 user
3255 \backslash 
3256 local
3257 \backslash 
3258 wbin', click ok.
3259 \newline 
3260
3261 \newline 
3262 (As a side effect, you get a bunch of Unix utilities that could be useful,
3263  such as diff and patch.)
3264 \layout Enumerate
3265
3266 A more compact way:
3267 \newline 
3268
3269 \newline 
3270 This one avoids extracting a bunch of files you may not use, but requires
3271  some extra work:
3272 \newline 
3273
3274 \newline 
3275 a) Create a directory were to put the tools needed, or use a directory already
3276  present.
3277  Say for example 'C:
3278 \backslash 
3279 util'.
3280 \newline 
3281
3282 \newline 
3283 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3284  to such directory WITHOUT preserving the original paths.
3285  (If you are using WinZip make certain that 'Use folder names' is not selected)
3286 \newline 
3287
3288 \newline 
3289 c) Rename bison.exe to '_bison.exe'.
3290 \newline 
3291
3292 \newline 
3293 d) Create a batch file 'bison.bat' in 'C:
3294 \backslash 
3295 util
3296 \backslash 
3297 ' and add these lines: 
3298 \newline 
3299 \SpecialChar ~
3300 \SpecialChar ~
3301 set BISON_SIMPLE=C:
3302 \backslash 
3303 util
3304 \backslash 
3305 bison.simple 
3306 \newline 
3307 \SpecialChar ~
3308 \SpecialChar ~
3309 set BISON_HAIRY=C:
3310 \backslash 
3311 util
3312 \backslash 
3313 bison.hairy
3314 \newline 
3315 \SpecialChar ~
3316 \SpecialChar ~
3317 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3318 \newline 
3319
3320 \newline 
3321 Steps 'c' and 'd' are needed because bison requires by default that the
3322  files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3323  '/usr/local/share/' I think.
3324  So it is necessary to tell bison where those files are located if they
3325  are not in such directory.
3326  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3327 \newline 
3328
3329 \newline 
3330 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3331  in 'Show directories for:' select 'Executable files', and in the directories
3332  window add a new path: 'c:
3333 \backslash 
3334 util', click ok.
3335  Note that you can use any other path instead of 'c:
3336 \backslash 
3337 util', even the path where the Visual C++ tools are, probably: 'C:
3338 \backslash 
3339 Program Files
3340 \backslash 
3341 Microsoft Visual Studio
3342 \backslash 
3343 Common
3344 \backslash 
3345 Tools'.
3346  So you don't have to execute step 'e' :)
3347 \layout Standard
3348
3349 That is it.
3350  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3351  the executables from sdcc
3352 \backslash 
3353 bin_vc to sdcc
3354 \backslash 
3355 bin, and you can compile using SDCC.
3356 \layout Subsection
3357
3358 Building SDCC Using Borland
3359 \layout Enumerate
3360
3361 From the sdcc directory, run the command "make -f Makefile.bcc".
3362  This should regenerate all the .exe files in the bin directory except for
3363  sdcdb.exe (which currently doesn't build under Borland C++).
3364 \layout Enumerate
3365
3366 If you modify any source files and need to rebuild, be aware that the dependenci
3367 es may not be correctly calculated.
3368  The safest option is to delete all .obj files and run the build again.
3369  From a Cygwin BASH prompt, this can easily be done with the command (be
3370  sure you are in the sdcc directory):
3371 \newline 
3372
3373 \newline 
3374
3375 \family sans 
3376 \series bold 
3377 find .
3378  
3379 \backslash 
3380 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
3381 \backslash 
3382 ) -print -exec rm {} 
3383 \backslash 
3384 ;
3385 \family default 
3386 \series default 
3387
3388 \newline 
3389
3390 \newline 
3391 or on Windows NT/2000/XP from the command prompt with the command:
3392 \newline 
3393
3394 \family sans 
3395 \series bold 
3396
3397 \newline 
3398 del /s *.obj *.lib *.rul
3399 \family default 
3400 \series default 
3401  from the sdcc directory.
3402 \layout Subsection
3403
3404 Windows Install Using a Binary Package
3405 \begin_inset LatexCommand \label{sub:Windows-Install}
3406
3407 \end_inset 
3408
3409
3410 \layout Enumerate
3411
3412 Download the binary package from 
3413 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3414
3415 \end_inset 
3416
3417  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
3418  This should unpack to a group of sub-directories.
3419  An example directory structure after unpacking the mingw32 package is:
3420  c:
3421 \backslash 
3422 sdcc
3423 \backslash 
3424 bin for the executables, c:
3425 \backslash 
3426 sdcc
3427 \backslash 
3428 include and c:
3429 \backslash 
3430 sdcc
3431 \backslash 
3432 lib for the include and libraries.
3433 \layout Enumerate
3434
3435 Adjust your environment variable PATH to include the location of the bin
3436  directory or start sdcc using the full path.
3437 \layout Section
3438
3439 Building the Documentation
3440 \layout Standard
3441
3442 If the necessary tools (LyX, LaTeX, LaTeX2HTML) are installed it is as easy
3443  as changing into the doc directory and typing 
3444 \family sans 
3445 \series bold 
3446
3447 \begin_inset Quotes srd
3448 \end_inset 
3449
3450 make
3451 \begin_inset Quotes srd
3452 \end_inset 
3453
3454
3455 \family default 
3456 \series default 
3457  there.
3458  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
3459 x).
3460  Using LyX 
3461 \begin_inset LatexCommand \url{www.lyx.org}
3462
3463 \end_inset 
3464
3465  as editor this is straightforward.
3466  Prebuilt documentation in html and pdf format is available from 
3467 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3468
3469 \end_inset 
3470
3471 .
3472 \layout Section
3473
3474 Reading the Documentation
3475 \layout Standard
3476
3477 Currently reading the document in pdf format is recommended, as for unknown
3478  reason the hyperlinks are working there whereas in the html version they
3479  are not
3480 \begin_inset Foot
3481 collapsed false
3482
3483 \layout Standard
3484
3485 If you should know why please drop us a note
3486 \end_inset 
3487
3488 .
3489  You'll find the pdf version at 
3490 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
3491
3492 \end_inset 
3493
3494 .
3495 \newline 
3496 This documentation is in some aspects different from a commercial documentation:
3497  
3498 \layout Itemize
3499
3500 It tries to document SDCC for several processor architectures in one document
3501  (commercially these probably would be separate documents/products).
3502  This document
3503 \begin_inset LatexCommand \index{Status of documentation}
3504
3505 \end_inset 
3506
3507  currently matches SDCC for mcs51 and DS390 best and does give too few informati
3508 on about f.e.
3509  Z80, PIC14, PIC16 and HC08.
3510 \layout Itemize
3511
3512 There are many references pointing away from this documentation.
3513  Don't let this distract you.
3514  If there f.e.
3515  was a reference like 
3516 \begin_inset LatexCommand \url{www.opencores.org}
3517
3518 \end_inset 
3519
3520  together with a statement 
3521 \begin_inset Quotes sld
3522 \end_inset 
3523
3524 some processors which are targetted by SDCC can be implemented in a 
3525 \emph on 
3526 f
3527 \emph default 
3528 ield 
3529 \emph on 
3530 p
3531 \emph default 
3532 rogrammable 
3533 \emph on 
3534 g
3535 \emph default 
3536 ate 
3537 \emph on 
3538 a
3539 \emph default 
3540 rray
3541 \begin_inset LatexCommand \index{fpga (field programmable gate array)}
3542
3543 \end_inset 
3544
3545
3546 \begin_inset Quotes srd
3547 \end_inset 
3548
3549  we expect you to have a quick look there and come back.
3550  If you read this you are on the right track.
3551 \layout Itemize
3552
3553 Some sections attribute more space to problems, restrictions and warnings
3554  than to the solution.
3555 \layout Itemize
3556
3557 The installation section and the section about the debugger is intimidating.
3558 \layout Itemize
3559
3560 There are still lots of typos and there are more different writing styles
3561  than pictures.
3562 \layout Section
3563
3564 Testing the SDCC Compiler
3565 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
3566
3567 \end_inset 
3568
3569
3570 \layout Standard
3571
3572 The first thing you should do after installing your SDCC compiler is to
3573  see if it runs.
3574  Type 
3575 \family sans 
3576 \series bold 
3577 "sdcc -
3578 \begin_inset ERT
3579 status Collapsed
3580
3581 \layout Standard
3582
3583 \backslash 
3584 /
3585 \end_inset 
3586
3587 -version"
3588 \begin_inset LatexCommand \index{version}
3589
3590 \end_inset 
3591
3592
3593 \family default 
3594 \series default 
3595  at the prompt, and the program should run and tell you the version.
3596  If it doesn't run, or gives a message about not finding sdcc program, then
3597  you need to check over your installation.
3598  Make sure that the sdcc bin directory is in your executable search path
3599  defined by the PATH environment setting (
3600 \series medium 
3601 see 
3602 \series default 
3603 section 
3604 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3605
3606 \end_inset 
3607
3608 \SpecialChar ~
3609
3610 \series medium 
3611 Install trouble-shooting for suggestions
3612 \series default 
3613 ).
3614  Make sure that the sdcc program is in the bin folder, if not perhaps something
3615  did not install correctly.
3616 \newline 
3617
3618 \newline 
3619
3620 \series medium 
3621 SDCC 
3622 \series default 
3623 is commonly installed as described in section 
3624 \begin_inset Quotes sld
3625 \end_inset 
3626
3627 Install and search paths
3628 \begin_inset Quotes srd
3629 \end_inset 
3630
3631 .
3632 \newline 
3633
3634 \newline 
3635
3636 \series medium 
3637 Make sure the compiler works on a very simple example.
3638  Type in the following test.c program using your favorite 
3639 \series default 
3640 ASCII 
3641 \series medium 
3642 editor:
3643 \layout Verse
3644
3645
3646 \family typewriter 
3647 char test;
3648 \newline 
3649
3650 \newline 
3651 void main(void) {
3652 \newline 
3653 \SpecialChar ~
3654 \SpecialChar ~
3655 \SpecialChar ~
3656 \SpecialChar ~
3657 test=0;
3658 \newline 
3659 }
3660 \layout Standard
3661
3662
3663 \series medium 
3664 Compile this using the following command: 
3665 \family sans 
3666 \series bold 
3667 "sdcc -c test.c".
3668
3669 \family default 
3670 \series default 
3671  
3672 \series medium 
3673 If all goes well, the compiler will generate a test.asm and test.rel file.
3674  Congratulations, you've just compiled your first program with SDCC.
3675  We used the -c option to tell SDCC not to link the generated code, just
3676  to keep things simple for this step.
3677 \series default 
3678
3679 \newline 
3680
3681 \newline 
3682
3683 \series medium 
3684 The next step is to try it with the linker.
3685  Type in 
3686 \family sans 
3687 \series bold 
3688 "sdcc test.c
3689 \family default 
3690 \series default 
3691 "
3692 \series medium 
3693 .
3694  If all goes well the compiler will link with the libraries and produce
3695  a test.ihx output file.
3696  If this step fails
3697 \series default 
3698  
3699 \series medium 
3700 (no test.ihx, and the linker generates warnings), then the problem is most
3701  likely that 
3702 \series default 
3703 SDCC
3704 \series medium 
3705  cannot find the 
3706 \series default 
3707 /
3708 \series medium 
3709 usr/local/share/sdcc/lib directory
3710 \series default 
3711  
3712 \series medium 
3713 (see 
3714 \series default 
3715 section 
3716 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3717
3718 \end_inset 
3719
3720 \SpecialChar ~
3721
3722 \series medium 
3723 Install trouble-shooting for suggestions).
3724 \series default 
3725
3726 \newline 
3727
3728 \newline 
3729
3730 \series medium 
3731 The final test is to ensure 
3732 \series default 
3733 SDCC
3734 \series medium 
3735  can use the 
3736 \series default 
3737 standard
3738 \series medium 
3739  header files and libraries.
3740  Edit test.c and change it to the following:
3741 \layout Verse
3742
3743
3744 \family typewriter 
3745 #include <string.h>
3746 \newline 
3747
3748 \newline 
3749 char str1[10];
3750 \newline 
3751
3752 \newline 
3753 void main(void) {
3754 \newline 
3755 \SpecialChar ~
3756 \SpecialChar ~
3757 strcpy(str1, "testing");
3758 \newline 
3759 }
3760 \layout Standard
3761
3762
3763 \series medium 
3764 Compile this by typing 
3765 \family sans 
3766 \series bold 
3767 "sdcc test.c"
3768 \family default 
3769 \series medium 
3770 .
3771  This should generate a test.ihx output file, and it should give no warnings
3772  such as not finding the string.h file.
3773  If it cannot find the string.h file, then the problem is that 
3774 \series default 
3775 SDCC
3776 \series medium 
3777  cannot find the /usr/local/share/sdcc/include directory
3778 \series default 
3779  
3780 \series medium 
3781 (see the 
3782 \series default 
3783 section 
3784 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3785
3786 \end_inset 
3787
3788 \SpecialChar ~
3789
3790 \series medium 
3791 Install trouble-shooting section for suggestions).
3792
3793 \series default 
3794  Use option 
3795 \series bold 
3796 -
3797 \begin_inset ERT
3798 status Collapsed
3799
3800 \layout Standard
3801
3802 \backslash 
3803 /
3804 \end_inset 
3805
3806 -print-search-dirs
3807 \series default 
3808
3809 \begin_inset LatexCommand \index{-\/-print-search-dirs}
3810
3811 \end_inset 
3812
3813  to find exactly where SDCC is looking for the include and lib files.
3814 \layout Section
3815
3816 Install Trouble-shooting
3817 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
3818
3819 \end_inset 
3820
3821
3822 \begin_inset LatexCommand \index{Install trouble-shooting}
3823
3824 \end_inset 
3825
3826
3827 \layout Subsection
3828
3829 If SDCC does not build correctly
3830 \layout Standard
3831
3832 A thing to try is starting from scratch by unpacking the .tgz source package
3833  again in an empty directory.
3834  Configure it like:
3835 \newline 
3836
3837 \newline 
3838
3839 \family sans 
3840 \series bold 
3841 ./configure 2>&1 | tee configure.log
3842 \family default 
3843 \series default 
3844
3845 \newline 
3846
3847 \newline 
3848 and build it like:
3849 \newline 
3850
3851 \newline 
3852
3853 \family sans 
3854 \series bold 
3855 make 2>&1 | tee make.log
3856 \family default 
3857 \series default 
3858
3859 \newline 
3860
3861 \newline 
3862 If anything goes wrong, you can review the log files to locate the problem.
3863  Or a relevant part of this can be attached to an email that could be helpful
3864  when requesting help from the mailing list.
3865 \layout Subsection
3866
3867 What the 
3868 \begin_inset Quotes sld
3869 \end_inset 
3870
3871 ./configure
3872 \begin_inset Quotes srd
3873 \end_inset 
3874
3875  does
3876 \layout Standard
3877
3878 The 
3879 \begin_inset Quotes sld
3880 \end_inset 
3881
3882 ./configure
3883 \begin_inset Quotes srd
3884 \end_inset 
3885
3886  command is a script that analyzes your system and performs some configuration
3887  to ensure the source package compiles on your system.
3888  It will take a few minutes to run, and will compile a few tests to determine
3889  what compiler features are installed.
3890 \layout Subsection
3891
3892 What the 
3893 \begin_inset Quotes sld
3894 \end_inset 
3895
3896 make
3897 \begin_inset Quotes srd
3898 \end_inset 
3899
3900  does
3901 \layout Standard
3902
3903 This runs the GNU make tool, which automatically compiles all the source
3904  packages into the final installed binary executables.
3905 \layout Subsection
3906
3907 What the 
3908 \begin_inset Quotes sld
3909 \end_inset 
3910
3911 make install
3912 \begin_inset Quotes erd
3913 \end_inset 
3914
3915  command does.
3916 \layout Standard
3917
3918 This will install the compiler, other executables libraries and include
3919  files into the appropriate directories.
3920  See sections 
3921 \begin_inset LatexCommand \ref{sub:Install-paths}
3922
3923 \end_inset 
3924
3925 ,\SpecialChar ~
3926
3927 \begin_inset LatexCommand \ref{sub:Search-Paths}
3928
3929 \end_inset 
3930
3931 \SpecialChar ~
3932 about install and search paths.
3933 \newline 
3934 On most systems you will need super-user privileges to do this.
3935 \layout Section
3936
3937 Components of SDCC
3938 \layout Standard
3939
3940 SDCC is not just a compiler, but a collection of tools by various developers.
3941  These include linkers, assemblers, simulators and other components.
3942  Here is a summary of some of the components.
3943  Note that the included simulator and assembler have separate documentation
3944  which you can find in the source package in their respective directories.
3945  As SDCC grows to include support for other processors, other packages from
3946  various developers are included and may have their own sets of documentation.
3947 \newline 
3948
3949 \newline 
3950 You might want to look at the files which are installed in <installdir>.
3951  At the time of this writing, we find the following programs for gcc-builds:
3952 \newline 
3953  
3954 \newline 
3955 In <installdir>/bin:
3956 \layout Itemize
3957
3958 sdcc - The compiler.
3959 \layout Itemize
3960
3961 sdcpp - The C preprocessor.
3962 \layout Itemize
3963
3964 asx8051 - The assembler for 8051 type processors.
3965 \layout Itemize
3966
3967 as-z80
3968 \series bold 
3969
3970 \series default 
3971 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
3972 \layout Itemize
3973
3974 aslink -The linker for 8051 type processors.
3975 \layout Itemize
3976
3977 link-z80
3978 \series bold 
3979
3980 \series default 
3981 link-gbz80 - The Z80 and GameBoy Z80 linkers.
3982 \layout Itemize
3983
3984 s51 - The ucSim 8051 simulator.
3985 \layout Itemize
3986
3987 sdcdb - The source debugger.
3988 \layout Itemize
3989
3990 packihx - A tool to pack (compress) Intel hex files.
3991 \layout Standard
3992
3993 In <installdir>/share/sdcc/include
3994 \layout Itemize
3995
3996 the include files
3997 \layout Standard
3998
3999 In <installdir>/share/sdcc/lib
4000 \layout Itemize
4001
4002 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
4003  relocatables.
4004 \layout Standard
4005
4006 In <installdir>/share/sdcc/doc
4007 \layout Itemize
4008
4009 the documentation
4010 \layout Standard
4011
4012 As development for other processors proceeds, this list will expand to include
4013  executables to support processors like AVR, PIC, etc.
4014 \layout Subsection
4015
4016 sdcc - The Compiler
4017 \layout Standard
4018
4019 This is the actual compiler, it in turn uses the c-preprocessor and invokes
4020  the assembler and linkage editor.
4021 \layout Subsection
4022
4023 sdcpp - The C-Preprocessor
4024 \layout Standard
4025
4026 The preprocessor
4027 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
4028
4029 \end_inset 
4030
4031  is a modified version of the GNU preprocessor.
4032  The C preprocessor is used to pull in #include sources, process #ifdef
4033  statements, #defines and so on.
4034 \layout Subsection
4035
4036 as
4037 \emph on 
4038 xxxx
4039 \emph default 
4040 , aslink, link-
4041 \emph on 
4042 xxx
4043 \emph default 
4044  - The Assemblers and Linkage Editors
4045 \layout Standard
4046
4047 This is retargettable assembler & linkage editor, it was developed by Alan
4048  Baldwin.
4049  John Hartman created the version for 8051, and I (Sandeep) have made some
4050  enhancements and bug fixes for it to work properly with SDCC.
4051 \layout Subsection
4052
4053 s51 - The Simulator
4054 \layout Standard
4055
4056 S51
4057 \begin_inset LatexCommand \index{s51}
4058
4059 \end_inset 
4060
4061  is a freeware, opensource simulator developed by Daniel Drotos (
4062 \begin_inset LatexCommand \url{mailto:drdani@mazsola.iit.uni-miskolc.hu}
4063
4064 \end_inset 
4065
4066 ).
4067  The simulator is built as part of the build process.
4068  For more information visit Daniel's web site at: 
4069 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
4070
4071 \end_inset 
4072
4073 .
4074  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
4075  XA51 family.
4076 \layout Subsection
4077
4078 sdcdb - Source Level Debugger
4079 \layout Standard
4080
4081 Sdcdb
4082 \begin_inset LatexCommand \index{sdcdb (debugger)}
4083
4084 \end_inset 
4085
4086  is the companion source level debugger.
4087  More about sdcdb in section 
4088 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
4089
4090 \end_inset 
4091
4092 .
4093  The current version of the debugger uses Daniel's Simulator S51
4094 \begin_inset LatexCommand \index{s51}
4095
4096 \end_inset 
4097
4098 , but can be easily changed to use other simulators.
4099  
4100 \layout Chapter
4101
4102 Using SDCC
4103 \layout Section
4104
4105 Compiling
4106 \layout Subsection
4107
4108 Single Source File Projects
4109 \layout Standard
4110
4111 For single source file 8051 projects the process is very simple.
4112  Compile your programs with the following command 
4113 \family sans 
4114 \series bold 
4115 "sdcc sourcefile.c".
4116
4117 \family default 
4118 \series default 
4119  This will compile, assemble and link your source file.
4120  Output files are as follows:
4121 \layout Itemize
4122
4123 sourcefile.asm
4124 \begin_inset LatexCommand \index{<file>.asm}
4125
4126 \end_inset 
4127
4128  - Assembler source
4129 \begin_inset LatexCommand \index{Assembler source}
4130
4131 \end_inset 
4132
4133  file created by the compiler
4134 \layout Itemize
4135
4136 sourcefile.lst
4137 \begin_inset LatexCommand \index{<file>.lst}
4138
4139 \end_inset 
4140
4141  - Assembler listing
4142 \begin_inset LatexCommand \index{Assembler listing}
4143
4144 \end_inset 
4145
4146  file created by the Assembler
4147 \layout Itemize
4148
4149 sourcefile.rst
4150 \begin_inset LatexCommand \index{<file>.rst}
4151
4152 \end_inset 
4153
4154  - Assembler listing
4155 \begin_inset LatexCommand \index{Assembler listing}
4156
4157 \end_inset 
4158
4159  file updated with linkedit information, created by linkage editor
4160 \layout Itemize
4161
4162 sourcefile.sym
4163 \begin_inset LatexCommand \index{<file>.sym}
4164
4165 \end_inset 
4166
4167  - symbol listing
4168 \begin_inset LatexCommand \index{Symbol listing}
4169
4170 \end_inset 
4171
4172  for the sourcefile, created by the assembler
4173 \layout Itemize
4174
4175 sourcefile.rel
4176 \begin_inset LatexCommand \index{<file>.rel}
4177
4178 \end_inset 
4179
4180  or sourcefile.o
4181 \begin_inset LatexCommand \index{<file>.o}
4182
4183 \end_inset 
4184
4185  - Object file
4186 \begin_inset LatexCommand \index{Object file}
4187
4188 \end_inset 
4189
4190  created by the assembler, input to Linkage editor
4191 \layout Itemize
4192
4193 sourcefile.map
4194 \begin_inset LatexCommand \index{<file>.map}
4195
4196 \end_inset 
4197
4198  - The memory map
4199 \begin_inset LatexCommand \index{Memory map}
4200
4201 \end_inset 
4202
4203  for the load module, created by the Linker
4204 \layout Itemize
4205
4206 sourcefile.mem
4207 \begin_inset LatexCommand \index{<file>.mem}
4208
4209 \end_inset 
4210
4211  - A file with a summary of the memory usage
4212 \layout Itemize
4213
4214 sourcefile.ihx
4215 \begin_inset LatexCommand \index{<file>.ihx}
4216
4217 \end_inset 
4218
4219  - The load module in Intel hex format
4220 \begin_inset LatexCommand \index{Intel hex format}
4221
4222 \end_inset 
4223
4224  (you can select the Motorola S19 format
4225 \begin_inset LatexCommand \index{Motorola S19 format}
4226
4227 \end_inset 
4228
4229  with -
4230 \begin_inset ERT
4231 status Collapsed
4232
4233 \layout Standard
4234
4235 \backslash 
4236 /
4237 \end_inset 
4238
4239 -out-fmt-s19
4240 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
4241
4242 \end_inset 
4243
4244 .
4245  If you need another format you might want to use 
4246 \family sans 
4247 \shape italic 
4248 objdump
4249 \family default 
4250 \shape default 
4251
4252 \begin_inset LatexCommand \index{objdump (tool)}
4253
4254 \end_inset 
4255
4256  or
4257 \family sans 
4258 \shape italic 
4259  srecord
4260 \family default 
4261 \shape default 
4262
4263 \begin_inset LatexCommand \index{srecord (tool)}
4264
4265 \end_inset 
4266
4267 ).
4268  Both formats are documented in the documentation of srecord
4269 \begin_inset LatexCommand \index{srecord (tool)}
4270
4271 \end_inset 
4272
4273
4274 \layout Itemize
4275
4276 sourcefile.adb
4277 \begin_inset LatexCommand \index{<file>.adb}
4278
4279 \end_inset 
4280
4281  - An intermediate file containing debug information needed to create the
4282  .cdb file (with -
4283 \begin_inset ERT
4284 status Open
4285
4286 \layout Standard
4287
4288 \backslash 
4289 /
4290 \end_inset 
4291
4292 -debug
4293 \begin_inset LatexCommand \index{-\/-debug}
4294
4295 \end_inset 
4296
4297
4298 \layout Itemize
4299
4300 sourcefile.cdb
4301 \begin_inset LatexCommand \index{<file>.cdb}
4302
4303 \end_inset 
4304
4305  - An optional file (with -
4306 \begin_inset ERT
4307 status Collapsed
4308
4309 \layout Standard
4310
4311 \backslash 
4312 /
4313 \end_inset 
4314
4315 -debug) containing debug information.
4316  The format is documented in cdbfileformat.pdf.
4317 \layout Itemize
4318
4319 sourcefile.
4320  - (no extension)
4321 \begin_inset LatexCommand \index{<file> (no extension)}
4322
4323 \end_inset 
4324
4325  An optional AOMF or AOMF51
4326 \begin_inset LatexCommand \index{AOMF, AOMF51}
4327
4328 \end_inset 
4329
4330  file containing debug information (generated with option -
4331 \begin_inset ERT
4332 status Collapsed
4333
4334 \layout Standard
4335
4336 \backslash 
4337 /
4338 \end_inset 
4339
4340 -debug).
4341  The (Intel)
4342 \emph on 
4343  a
4344 \emph default 
4345 bsolute 
4346 \emph on 
4347 o
4348 \emph default 
4349 bject 
4350 \emph on 
4351 m
4352 \emph default 
4353 odule 
4354 \emph on 
4355 f
4356 \emph default 
4357 ormat is commonly used by third party tools (debuggers
4358 \begin_inset LatexCommand \index{Debugger}
4359
4360 \end_inset 
4361
4362 , simulators, emulators)
4363 \layout Itemize
4364
4365 sourcefile.dump*
4366 \begin_inset LatexCommand \index{<file>.dump*}
4367
4368 \end_inset 
4369
4370  - Dump file to debug the compiler it self (generated with option -
4371 \begin_inset ERT
4372 status Collapsed
4373
4374 \layout Standard
4375
4376 \backslash 
4377 /
4378 \end_inset 
4379
4380 -dumpall) (see section 
4381 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
4382
4383 \end_inset 
4384
4385 \SpecialChar ~
4386  and section 
4387 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
4388
4389 \end_inset 
4390
4391 \SpecialChar ~
4392
4393 \begin_inset Quotes sld
4394 \end_inset 
4395
4396 Anatomy of the compiler
4397 \begin_inset Quotes srd
4398 \end_inset 
4399
4400 ).
4401 \layout Subsection
4402
4403 Projects with Multiple Source Files
4404 \layout Standard
4405
4406 SDCC can compile only ONE file at a time.
4407  Let us for example assume that you have a project containing the following
4408  files:
4409 \newline 
4410
4411 \newline 
4412 foo1.c (contains some functions)
4413 \newline 
4414 foo2.c (contains some more functions)
4415 \newline 
4416 foomain.c (contains more functions and the function main)
4417 \newline 
4418
4419 \size footnotesize 
4420
4421 \newline 
4422
4423 \size default 
4424 The first two files will need to be compiled separately with the commands:
4425 \size footnotesize 
4426  
4427 \size default 
4428
4429 \newline 
4430
4431 \newline 
4432
4433 \family sans 
4434 \series bold 
4435 sdcc\SpecialChar ~
4436 -c\SpecialChar ~
4437 foo1.c
4438 \family default 
4439 \series default 
4440 \size footnotesize 
4441
4442 \newline 
4443
4444 \family sans 
4445 \series bold 
4446 \size default 
4447 sdcc\SpecialChar ~
4448 -c\SpecialChar ~
4449 foo2.c
4450 \family default 
4451 \series default 
4452
4453 \newline 
4454
4455 \newline 
4456 Then compile the source file containing the 
4457 \emph on 
4458 main()
4459 \emph default 
4460  function and link
4461 \begin_inset LatexCommand \index{Linker}
4462
4463 \end_inset 
4464
4465  the files together with the following command: 
4466 \newline 
4467
4468 \newline 
4469
4470 \family sans 
4471 \series bold 
4472 sdcc\SpecialChar ~
4473 foomain.c\SpecialChar ~
4474 foo1.rel\SpecialChar ~
4475 foo2.rel
4476 \family default 
4477 \series default 
4478
4479 \begin_inset LatexCommand \index{<file>.rel}
4480
4481 \end_inset 
4482
4483
4484 \newline 
4485
4486 \newline 
4487 Alternatively, 
4488 \emph on 
4489 foomain.c 
4490 \emph default 
4491 can be separately compiled as well: 
4492 \family sans 
4493 \series bold 
4494
4495 \newline 
4496
4497 \newline 
4498 sdcc\SpecialChar ~
4499 -c\SpecialChar ~
4500 foomain.c
4501 \newline 
4502 sdcc foomain.rel foo1.rel foo2.rel
4503 \newline 
4504
4505 \newline 
4506
4507 \family default 
4508 \series default 
4509 The file containing the 
4510 \emph on 
4511 main()
4512 \emph default 
4513  function
4514 \emph on 
4515  
4516 \emph default 
4517 \noun on 
4518 must
4519 \noun default 
4520  be the 
4521 \noun on 
4522 first
4523 \noun default 
4524  file specified in the command line, since the linkage editor processes
4525  file in the order they are presented to it.
4526  The linker is invoked from SDCC using a script file with extension .lnk
4527 \begin_inset LatexCommand \index{<file>.lnk}
4528
4529 \end_inset 
4530
4531 .
4532  You can view this file to troubleshoot linking problems such as those arising
4533  from missing libraries.
4534 \layout Subsection
4535
4536 Projects with Additional Libraries
4537 \begin_inset LatexCommand \index{Libraries}
4538
4539 \end_inset 
4540
4541
4542 \layout Standard
4543
4544 Some reusable routines may be compiled into a library, see the documentation
4545  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
4546  for how to create a 
4547 \emph on 
4548 .lib
4549 \begin_inset LatexCommand \index{<file>.lib}
4550
4551 \end_inset 
4552
4553
4554 \emph default 
4555  library file.
4556  Libraries created in this manner can be included in the command line.
4557  Make sure you include the -L <library-path> option to tell the linker where
4558  to look for these files if they are not in the current directory.
4559  Here is an example, assuming you have the source file 
4560 \emph on 
4561 foomain.c
4562 \emph default 
4563  and a library
4564 \emph on 
4565  foolib.lib
4566 \emph default 
4567  in the directory 
4568 \emph on 
4569 mylib
4570 \emph default 
4571  (if that is not the same as your current project):
4572 \newline 
4573
4574 \newline 
4575
4576 \family sans 
4577 \series bold 
4578 sdcc foomain.c foolib.lib -L mylib
4579 \newline 
4580
4581 \newline 
4582
4583 \family default 
4584 \series default 
4585 Note here that
4586 \emph on 
4587  mylib
4588 \emph default 
4589  must be an absolute path name.
4590 \newline 
4591
4592 \newline 
4593 The most efficient way to use libraries is to keep separate modules in separate
4594  source files.
4595  The lib file now should name all the modules.rel
4596 \begin_inset LatexCommand \index{<file>.rel}
4597
4598 \end_inset 
4599
4600  files.
4601  For an example see the standard library file 
4602 \emph on 
4603 libsdcc.lib
4604 \emph default 
4605  in the directory <installdir>/share/lib/small.
4606 \layout Subsection
4607
4608 Using sdcclib to Create and Manage Libraries
4609 \begin_inset LatexCommand \index{sdcclib}
4610
4611 \end_inset 
4612
4613
4614 \layout Standard
4615
4616 Alternatively, instead of having a .rel file for each entry on the library
4617  file as described in the preceding section, sdcclib can be used to embed
4618  all the modules belonging to such library in the library file itself.
4619  This results in a larger library file, but it greatly reduces the number
4620  of disk files accessed by the linker.
4621   Additionally, the packed library file contains an index of all include
4622  modules and symbols that significantly speeds up the linking process.
4623  To display a list of options supported by sdcclib type:
4624 \newline 
4625
4626 \layout Standard
4627
4628
4629 \family sans 
4630 \series bold 
4631 sdcclib -?
4632 \begin_inset LatexCommand \index{sdcclib}
4633
4634 \end_inset 
4635
4636
4637 \newline 
4638
4639 \newline 
4640
4641 \family default 
4642 \series default 
4643 To create a new library file, start by compiling all the required modules.
4644  For example:
4645 \newline 
4646
4647 \layout Standard
4648
4649
4650 \family sans 
4651 \series bold 
4652 sdcc -c _divsint.c
4653 \layout Standard
4654
4655
4656 \family sans 
4657 \series bold 
4658 sdcc -c _divuint.c
4659 \layout Standard
4660
4661
4662 \family sans 
4663 \series bold 
4664 sdcc -c _modsint.c
4665 \layout Standard
4666
4667
4668 \family sans 
4669 \series bold 
4670 sdcc -c _moduint.c
4671 \layout Standard
4672
4673
4674 \family sans 
4675 \series bold 
4676 sdcc -c _mulint.c
4677 \newline 
4678
4679 \layout Standard
4680
4681 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
4682  and _mulint.rel.
4683  The next step is to add the .rel files to the library file:
4684 \newline 
4685
4686 \layout Standard
4687
4688
4689 \family sans 
4690 \series bold 
4691 sdcclib libint.lib _divsint.rel
4692 \family default 
4693
4694 \begin_inset LatexCommand \index{sdcclib}
4695
4696 \end_inset 
4697
4698
4699 \layout Standard
4700
4701
4702 \family sans 
4703 \series bold 
4704 sdcclib libint.lib _divuint.rel
4705 \layout Standard
4706
4707
4708 \family sans 
4709 \series bold 
4710 sdcclib libint.lib _modsint.rel
4711 \layout Standard
4712
4713
4714 \family sans 
4715 \series bold 
4716 sdcclib libint.lib _moduint.rel
4717 \layout Standard
4718
4719
4720 \family sans 
4721 \series bold 
4722 sdcclib libint.lib _mulint.rel
4723 \series default 
4724
4725 \newline 
4726
4727 \layout Standard
4728
4729 If the file already exists in the library, it will be replaced.
4730  To see what modules and symbols are included in the library, options -s
4731  and -m are available.
4732  For example:
4733 \newline 
4734
4735 \newline 
4736
4737 \family sans 
4738 \series bold 
4739 sdcclib -s libint.lib
4740 \family default 
4741
4742 \begin_inset LatexCommand \index{sdcclib}
4743
4744 \end_inset 
4745
4746
4747 \newline 
4748
4749 \family typewriter 
4750 \series default 
4751 _divsint.rel:
4752 \layout Standard
4753
4754
4755 \family typewriter 
4756 __divsint_a_1_1
4757 \layout Standard
4758
4759
4760 \family typewriter 
4761 __divsint_PARM_2
4762 \layout Standard
4763
4764
4765 \family typewriter 
4766 __divsint
4767 \newline 
4768 _divuint.rel:
4769 \layout Standard
4770
4771
4772 \family typewriter 
4773 __divuint_a_1_1
4774 \layout Standard
4775
4776
4777 \family typewriter 
4778 __divuint_PARM_2
4779 \layout Standard
4780
4781
4782 \family typewriter 
4783 __divuint_reste_1_1
4784 \layout Standard
4785
4786
4787 \family typewriter 
4788 __divuint_count_1_1
4789 \layout Standard
4790
4791
4792 \family typewriter 
4793 __divuint
4794 \newline 
4795 _modsint.rel:
4796 \layout Standard
4797
4798
4799 \family typewriter 
4800 __modsint_a_1_1
4801 \layout Standard
4802
4803
4804 \family typewriter 
4805 __modsint_PARM_2
4806 \layout Standard
4807
4808
4809 \family typewriter 
4810 __modsint
4811 \newline 
4812 _moduint.rel:
4813 \layout Standard
4814
4815
4816 \family typewriter 
4817 __moduint_a_1_1
4818 \layout Standard
4819
4820
4821 \family typewriter 
4822 __moduint_PARM_2
4823 \layout Standard
4824
4825
4826 \family typewriter 
4827 __moduint_count_1_1
4828 \layout Standard
4829
4830
4831 \family typewriter 
4832 __moduint
4833 \newline 
4834 _mulint.rel:
4835 \layout Standard
4836
4837
4838 \family typewriter 
4839 __mulint_PARM_2
4840 \layout Standard
4841
4842
4843 \family typewriter 
4844 __mulint
4845 \family default 
4846 \series bold 
4847
4848 \newline 
4849
4850 \layout Standard
4851
4852 If the source files are compiled using -
4853 \begin_inset ERT
4854 status Open
4855
4856 \layout Standard
4857
4858 \backslash 
4859 /
4860 \end_inset 
4861
4862 -debug
4863 \begin_inset LatexCommand \index{-\/-debug}
4864
4865 \end_inset 
4866
4867 , the corresponding debug information file .adb will be include in the library
4868  file as well.
4869  The library files created with sdcclib are plain text files, so they can
4870  be viewed with a text editor.
4871  It is not recomended to modify a library file created with sdcclib using
4872  a text editor, as there are file indexes numbers located accross the file
4873  used by the linker to quickly locate the required module to link.
4874  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
4875  it can be safely deleted, since all the information required for linking
4876  is embedded in the library file itself.
4877  Library files created using sdcclib are used as described in the preceding
4878  sections.
4879 \layout Section
4880
4881 Command Line Options
4882 \begin_inset LatexCommand \index{Command Line Options}
4883
4884 \end_inset 
4885
4886
4887 \layout Subsection
4888
4889 Processor Selection Options
4890 \begin_inset LatexCommand \index{Options processor selection}
4891
4892 \end_inset 
4893
4894
4895 \begin_inset LatexCommand \index{Processor selection options}
4896
4897 \end_inset 
4898
4899
4900 \layout List
4901 \labelwidthstring 00.00.0000
4902
4903
4904 \series bold 
4905 -mmcs51
4906 \begin_inset LatexCommand \index{-mmcs51}
4907
4908 \end_inset 
4909
4910
4911 \series default 
4912  Generate code for the Intel MCS51
4913 \begin_inset LatexCommand \index{MCS51}
4914
4915 \end_inset 
4916
4917  family of processors.
4918  This is the default processor target.
4919 \layout List
4920 \labelwidthstring 00.00.0000
4921
4922
4923 \series bold 
4924 -mds390
4925 \begin_inset LatexCommand \index{-mds390}
4926
4927 \end_inset 
4928
4929
4930 \series default 
4931  Generate code for the Dallas DS80C390
4932 \begin_inset LatexCommand \index{DS80C390}
4933
4934 \end_inset 
4935
4936  processor.
4937 \layout List
4938 \labelwidthstring 00.00.0000
4939
4940
4941 \series bold 
4942 -mds400
4943 \begin_inset LatexCommand \index{-mds400}
4944
4945 \end_inset 
4946
4947
4948 \series default 
4949  Generate code for the Dallas DS80C400
4950 \begin_inset LatexCommand \index{DS80C400}
4951
4952 \end_inset 
4953
4954  processor.
4955 \layout List
4956 \labelwidthstring 00.00.0000
4957
4958
4959 \series bold 
4960 -mhc08
4961 \begin_inset LatexCommand \index{-mhc08}
4962
4963 \end_inset 
4964
4965
4966 \series default 
4967  Generate code for the Motorola HC08
4968 \begin_inset LatexCommand \index{HC08}
4969
4970 \end_inset 
4971
4972  family of processors (added Oct 2003).
4973 \layout List
4974 \labelwidthstring 00.00.0000
4975
4976
4977 \series bold 
4978 -mz80
4979 \begin_inset LatexCommand \index{-mz80}
4980
4981 \end_inset 
4982
4983
4984 \series default 
4985  Generate code for the Zilog Z80
4986 \begin_inset LatexCommand \index{Z80}
4987
4988 \end_inset 
4989
4990  family of processors.
4991 \layout List
4992 \labelwidthstring 00.00.0000
4993
4994
4995 \series bold 
4996 -mgbz80
4997 \begin_inset LatexCommand \index{-mgbz80}
4998
4999 \end_inset 
5000
5001
5002 \series default 
5003  Generate code for the GameBoy Z80
5004 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
5005
5006 \end_inset 
5007
5008  processor (Not actively maintained).
5009 \layout List
5010 \labelwidthstring 00.00.0000
5011
5012
5013 \series bold 
5014 -mavr
5015 \begin_inset LatexCommand \index{-mavr}
5016
5017 \end_inset 
5018
5019
5020 \series default 
5021  Generate code for the Atmel AVR
5022 \begin_inset LatexCommand \index{AVR}
5023
5024 \end_inset 
5025
5026  processor (In development, not complete).
5027  AVR users should probably have a look at avr-gcc 
5028 \begin_inset LatexCommand \url{ http://savannah.nongnu.org/download/avr-libc/snapshots/}
5029
5030 \end_inset 
5031
5032  or winavr 
5033 \begin_inset LatexCommand \url{http://winavr.sourceforge.net}
5034
5035 \end_inset 
5036
5037 .
5038 \layout Comment
5039
5040 I think it is fair to direct users there for now.
5041  Open source is also about avoiding unnecessary work .
5042  But I didn't find the 'official' link.
5043 \layout List
5044 \labelwidthstring 00.00.0000
5045
5046
5047 \series bold 
5048 -mpic14
5049 \begin_inset LatexCommand \index{-mpic14}
5050
5051 \end_inset 
5052
5053
5054 \series default 
5055  Generate code for the Microchip PIC 14
5056 \begin_inset LatexCommand \index{PIC14}
5057
5058 \end_inset 
5059
5060 -bit processors (p16f84 and variants.
5061  In development, not complete).
5062 \layout Comment
5063
5064 p16f627 p16f628 p16f84 p16f873 p16f877?
5065 \layout List
5066 \labelwidthstring 00.00.0000
5067
5068
5069 \series bold 
5070 -mpic16
5071 \begin_inset LatexCommand \index{-mpic16}
5072
5073 \end_inset 
5074
5075
5076 \series default 
5077  Generate code for the Microchip PIC 16
5078 \begin_inset LatexCommand \index{PIC16}
5079
5080 \end_inset 
5081
5082 -bit processors (p18f452 and variants.
5083  In development, not complete).
5084 \layout List
5085 \labelwidthstring 00.00.0000
5086
5087
5088 \series bold 
5089 -mtlcs900h
5090 \series default 
5091  Generate code for the Toshiba TLCS-900H
5092 \begin_inset LatexCommand \index{TLCS-900H}
5093
5094 \end_inset 
5095
5096  processor (Not maintained, not complete).
5097 \layout List
5098 \labelwidthstring 00.00.0000
5099
5100
5101 \series bold 
5102 -mxa51
5103 \begin_inset LatexCommand \index{-mxa51}
5104
5105 \end_inset 
5106
5107
5108 \series default 
5109  Generate code for the Phillips XA51
5110 \begin_inset LatexCommand \index{XA51}
5111
5112 \end_inset 
5113
5114  processor (Not maintained, not complete).
5115 \layout Subsection
5116
5117 Preprocessor Options
5118 \begin_inset LatexCommand \index{Options preprocessor}
5119
5120 \end_inset 
5121
5122
5123 \begin_inset LatexCommand \index{Preprocessor options}
5124
5125 \end_inset 
5126
5127
5128 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5129
5130 \end_inset 
5131
5132
5133 \layout List
5134 \labelwidthstring 00.00.0000
5135
5136
5137 \series bold 
5138 -I<path>
5139 \begin_inset LatexCommand \index{-I<path>}
5140
5141 \end_inset 
5142
5143
5144 \series default 
5145  The additional location where the pre processor will look for <..h> or 
5146 \begin_inset Quotes eld
5147 \end_inset 
5148
5149 ..h
5150 \begin_inset Quotes erd
5151 \end_inset 
5152
5153  files.
5154 \layout List
5155 \labelwidthstring 00.00.0000
5156
5157
5158 \series bold 
5159 -D<macro[=value]>
5160 \begin_inset LatexCommand \index{-D<macro[=value]>}
5161
5162 \end_inset 
5163
5164
5165 \series default 
5166  Command line definition of macros.
5167  Passed to the preprocessor.
5168 \layout List
5169 \labelwidthstring 00.00.0000
5170
5171
5172 \series bold 
5173 -M
5174 \begin_inset LatexCommand \index{-M}
5175
5176 \end_inset 
5177
5178
5179 \series default 
5180  Tell the preprocessor to output a rule suitable for make describing the
5181  dependencies of each object file.
5182  For each source file, the preprocessor outputs one make-rule whose target
5183  is the object file name for that source file and whose dependencies are
5184  all the files `#include'd in it.
5185  This rule may be a single line or may be continued with `
5186 \backslash 
5187 '-newline if it is long.
5188  The list of rules is printed on standard output instead of the preprocessed
5189  C program.
5190  `-M' implies `-E
5191 \begin_inset LatexCommand \index{-E}
5192
5193 \end_inset 
5194
5195 '.
5196 \layout List
5197 \labelwidthstring 00.00.0000
5198
5199
5200 \series bold 
5201 -C
5202 \begin_inset LatexCommand \index{-C}
5203
5204 \end_inset 
5205
5206
5207 \series default 
5208  Tell the preprocessor not to discard comments.
5209  Used with the `-E' option.
5210 \layout List
5211 \labelwidthstring 00.00.0000
5212
5213
5214 \series bold 
5215 -MM
5216 \begin_inset LatexCommand \index{-MM}
5217
5218 \end_inset 
5219
5220
5221 \size large 
5222 \bar under 
5223  
5224 \series default 
5225 \size default 
5226 \bar default 
5227 Like `-M' but the output mentions only the user header files included with
5228  `#include 
5229 \begin_inset Quotes eld
5230 \end_inset 
5231
5232 file"'.
5233  System header files included with `#include <file>' are omitted.
5234 \layout List
5235 \labelwidthstring 00.00.0000
5236
5237
5238 \series bold 
5239 -Aquestion(answer)
5240 \begin_inset LatexCommand \index{-Aquestion(answer)}
5241
5242 \end_inset 
5243
5244
5245 \series default 
5246  Assert the answer answer for question, in case it is tested with a preprocessor
5247  conditional such as `#if #question(answer)'.
5248  `-A-' disables the standard assertions that normally describe the target
5249  machine.
5250 \layout List
5251 \labelwidthstring 00.00.0000
5252
5253
5254 \series bold 
5255 -Umacro
5256 \begin_inset LatexCommand \index{-Umacro}
5257
5258 \end_inset 
5259
5260
5261 \series default 
5262  Undefine macro macro.
5263  `-U' options are evaluated after all `-D' options, but before any `-include'
5264  and `-imacros' options.
5265 \layout List
5266 \labelwidthstring 00.00.0000
5267
5268
5269 \series bold 
5270 -dM
5271 \begin_inset LatexCommand \index{-dM}
5272
5273 \end_inset 
5274
5275
5276 \series default 
5277  Tell the preprocessor to output only a list of the macro definitions that
5278  are in effect at the end of preprocessing.
5279  Used with the `-E' option.
5280 \layout List
5281 \labelwidthstring 00.00.0000
5282
5283
5284 \series bold 
5285 -dD
5286 \begin_inset LatexCommand \index{-dD}
5287
5288 \end_inset 
5289
5290
5291 \series default 
5292  Tell the preprocessor to pass all macro definitions into the output, in
5293  their proper sequence in the rest of the output.
5294 \layout List
5295 \labelwidthstring 00.00.0000
5296
5297
5298 \series bold 
5299 -dN
5300 \begin_inset LatexCommand \index{-dN}
5301
5302 \end_inset 
5303
5304
5305 \size large 
5306 \bar under 
5307  
5308 \series default 
5309 \size default 
5310 \bar default 
5311 Like `-dD' except that the macro arguments and contents are omitted.
5312  Only `#define name' is included in the output.
5313 \layout List
5314 \labelwidthstring 00.00.0000
5315
5316
5317 \series bold 
5318 -Wp\SpecialChar ~
5319 preprocessorOption[,preprocessorOption]
5320 \series default 
5321
5322 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
5323
5324 \end_inset 
5325
5326 ...
5327  Pass the preprocessorOption to the preprocessor 
5328 \family typewriter 
5329 sdcpp
5330 \family default 
5331
5332 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5333
5334 \end_inset 
5335
5336 .
5337  SDCC uses an adapted version of the preprocessor cpp of the GNU Compiler
5338  Collection (gcc), if you need more dedicated options please refer to the
5339  documentation at 
5340 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
5341
5342 \end_inset 
5343
5344 .
5345 \layout Subsection
5346
5347 Linker Options
5348 \begin_inset LatexCommand \index{Options linker}
5349
5350 \end_inset 
5351
5352
5353 \begin_inset LatexCommand \index{Linker options}
5354
5355 \end_inset 
5356
5357
5358 \layout List
5359 \labelwidthstring 00.00.0000
5360
5361
5362 \series bold 
5363 -L\SpecialChar ~
5364 -
5365 \series default 
5366
5367 \begin_inset ERT
5368 status Collapsed
5369
5370 \layout Standard
5371
5372 \backslash 
5373 /
5374 \end_inset 
5375
5376
5377 \series bold 
5378 -lib-path
5379 \begin_inset LatexCommand \index{-\/-lib-path <path>}
5380
5381 \end_inset 
5382
5383
5384 \begin_inset LatexCommand \index{-L -\/-lib-path}
5385
5386 \end_inset 
5387
5388
5389 \series default 
5390 \SpecialChar ~
5391 <absolute path to additional libraries> This option is passed to the linkage
5392  editor's additional libraries
5393 \begin_inset LatexCommand \index{Libraries}
5394
5395 \end_inset 
5396
5397  search path.
5398  The path name must be absolute.
5399  Additional library files may be specified in the command line.
5400  See section Compiling programs for more details.
5401 \layout List
5402 \labelwidthstring 00.00.0000
5403
5404
5405 \series bold 
5406 -
5407 \begin_inset ERT
5408 status Collapsed
5409
5410 \layout Standard
5411
5412 \backslash 
5413 /
5414 \end_inset 
5415
5416 -xram-loc
5417 \series default 
5418
5419 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
5420
5421 \end_inset 
5422
5423 \SpecialChar ~
5424 <Value> The start location of the external ram
5425 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
5426
5427 \end_inset 
5428
5429 , default value is 0.
5430  The value entered can be in Hexadecimal or Decimal format, e.g.: -
5431 \begin_inset ERT
5432 status Collapsed
5433
5434 \layout Standard
5435
5436 \backslash 
5437 /
5438 \end_inset 
5439
5440 -xram-loc 0x8000 or -
5441 \begin_inset ERT
5442 status Collapsed
5443
5444 \layout Standard
5445
5446 \backslash 
5447 /
5448 \end_inset 
5449
5450 -xram-loc 32768.
5451 \layout List
5452 \labelwidthstring 00.00.0000
5453
5454
5455 \series bold 
5456 -
5457 \begin_inset ERT
5458 status Collapsed
5459
5460 \layout Standard
5461
5462 \backslash 
5463 /
5464 \end_inset 
5465
5466 -code-loc
5467 \series default 
5468
5469 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
5470
5471 \end_inset 
5472
5473 \SpecialChar ~
5474 <Value> The start location of the code
5475 \begin_inset LatexCommand \index{code}
5476
5477 \end_inset 
5478
5479  segment, default value 0.
5480  Note when this option is used the interrupt vector table is also relocated
5481  to the given address.
5482  The value entered can be in Hexadecimal or Decimal format, e.g.: -
5483 \begin_inset ERT
5484 status Collapsed
5485
5486 \layout Standard
5487
5488 \backslash 
5489 /
5490 \end_inset 
5491
5492 -code-loc 0x8000 or -
5493 \begin_inset ERT
5494 status Collapsed
5495
5496 \layout Standard
5497
5498 \backslash 
5499 /
5500 \end_inset 
5501
5502 -code-loc 32768.
5503 \layout List
5504 \labelwidthstring 00.00.0000
5505
5506
5507 \series bold 
5508 -
5509 \begin_inset ERT
5510 status Collapsed
5511
5512 \layout Standard
5513
5514 \backslash 
5515 /
5516 \end_inset 
5517
5518 -stack-loc
5519 \series default 
5520
5521 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
5522
5523 \end_inset 
5524
5525 \SpecialChar ~
5526 <Value> By default the stack
5527 \begin_inset LatexCommand \index{stack}
5528
5529 \end_inset 
5530
5531  is placed after the data segment.
5532  Using this option the stack can be placed anywhere in the internal memory
5533  space of the 8051.
5534  The value entered can be in Hexadecimal or Decimal format, e.g.
5535  -
5536 \begin_inset ERT
5537 status Collapsed
5538
5539 \layout Standard
5540
5541 \backslash 
5542 /
5543 \end_inset 
5544
5545 -stack-loc 0x20 or -
5546 \begin_inset ERT
5547 status Collapsed
5548
5549 \layout Standard
5550
5551 \backslash 
5552 /
5553 \end_inset 
5554
5555 -stack-loc 32.
5556  Since the sp register is incremented before a push or call, the initial
5557  sp will be set to one byte prior the provided value.
5558  The provided value should not overlap any other memory areas such as used
5559  register banks or the data segment and with enough space for the current
5560  application.
5561 \layout List
5562 \labelwidthstring 00.00.0000
5563
5564
5565 \series bold 
5566 -
5567 \begin_inset ERT
5568 status Collapsed
5569
5570 \layout Standard
5571
5572 \backslash 
5573 /
5574 \end_inset 
5575
5576 -data-loc
5577 \series default 
5578
5579 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
5580
5581 \end_inset 
5582
5583 \SpecialChar ~
5584 <Value> The start location of the internal ram data
5585 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
5586
5587 \end_inset 
5588
5589  segment.
5590  The value entered can be in Hexadecimal or Decimal format, eg.
5591  -
5592 \begin_inset ERT
5593 status Collapsed
5594
5595 \layout Standard
5596
5597 \backslash 
5598 /
5599 \end_inset 
5600
5601 -data-loc 0x20 or -
5602 \begin_inset ERT
5603 status Collapsed
5604
5605 \layout Standard
5606
5607 \backslash 
5608 /
5609 \end_inset 
5610
5611 -data-loc 32.
5612  (By default, the start location of the internal ram data segment  is set
5613  as low as possible in memory, taking into account the used register banks
5614  and the bit segment at address 0x20.
5615  For example if register banks 0 and 1 are used without bit variables, the
5616  data segment will be set, if -
5617 \begin_inset ERT
5618 status Collapsed
5619
5620 \layout Standard
5621
5622 \backslash 
5623 /
5624 \end_inset 
5625
5626 -data-loc is not used, to location 0x10.)
5627 \layout List
5628 \labelwidthstring 00.00.0000
5629
5630
5631 \series bold 
5632 -
5633 \begin_inset ERT
5634 status Collapsed
5635
5636 \layout Standard
5637
5638 \backslash 
5639 /
5640 \end_inset 
5641
5642 -idata-loc
5643 \series default 
5644
5645 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
5646
5647 \end_inset 
5648
5649 \SpecialChar ~
5650 <Value> The start location of the indirectly addressable internal ram
5651 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
5652
5653 \end_inset 
5654
5655  of the 8051, default value is 0x80.
5656  The value entered can be in Hexadecimal or Decimal format, eg.
5657  -
5658 \begin_inset ERT
5659 status Collapsed
5660
5661 \layout Standard
5662
5663 \backslash 
5664 /
5665 \end_inset 
5666
5667 -idata-loc 0x88 or -
5668 \begin_inset ERT
5669 status Collapsed
5670
5671 \layout Standard
5672
5673 \backslash 
5674 /
5675 \end_inset 
5676
5677 -idata-loc 136.
5678 \layout List
5679 \labelwidthstring 00.00.0000
5680
5681
5682 \series bold 
5683 -
5684 \begin_inset ERT
5685 status Collapsed
5686
5687 \layout Standard
5688
5689 \backslash 
5690 /
5691 \end_inset 
5692
5693 -bit-loc
5694 \series default 
5695 \SpecialChar ~
5696 <Value> The start location of the bit
5697 \begin_inset LatexCommand \index{bit}
5698
5699 \end_inset 
5700
5701  addressable internal ram of the 8051.
5702  This is 
5703 \emph on 
5704 not
5705 \emph default 
5706  implemented yet.
5707  Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
5708 -bBSEG=<Value>.
5709 \layout List
5710 \labelwidthstring 00.00.0000
5711
5712
5713 \series bold 
5714 -
5715 \begin_inset ERT
5716 status Collapsed
5717
5718 \layout Standard
5719
5720 \backslash 
5721 /
5722 \end_inset 
5723
5724 -out-fmt-ihx
5725 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
5726
5727 \end_inset 
5728
5729
5730 \bar under 
5731  
5732 \series default 
5733 \bar default 
5734 The linker output (final object code) is in Intel Hex format.
5735 \begin_inset LatexCommand \index{Intel hex format}
5736
5737 \end_inset 
5738
5739  This is the default option.
5740  The format itself is documented in the documentation of srecord
5741 \begin_inset LatexCommand \index{srecord (tool)}
5742
5743 \end_inset 
5744
5745 .
5746 \layout List
5747 \labelwidthstring 00.00.0000
5748
5749
5750 \series bold 
5751 -
5752 \begin_inset ERT
5753 status Collapsed
5754
5755 \layout Standard
5756
5757 \backslash 
5758 /
5759 \end_inset 
5760
5761 -out-fmt-s19
5762 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5763
5764 \end_inset 
5765
5766
5767 \bar under 
5768  
5769 \series default 
5770 \bar default 
5771 The linker output (final object code) is in Motorola S19 format
5772 \begin_inset LatexCommand \index{Motorola S19 format}
5773
5774 \end_inset 
5775
5776 .
5777  The format itself is documented in the documentation of srecord.
5778 \layout List
5779 \labelwidthstring 00.00.0000
5780
5781
5782 \series bold 
5783 -Wl\SpecialChar ~
5784 linkOption[,linkOption]
5785 \series default 
5786
5787 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
5788
5789 \end_inset 
5790
5791 ...
5792  Pass the linkOption to the linker.
5793  See file sdcc/as/doc/asxhtm.html for more on linker options.
5794 \layout Subsection
5795
5796 MCS51 Options
5797 \begin_inset LatexCommand \index{Options MCS51}
5798
5799 \end_inset 
5800
5801
5802 \begin_inset LatexCommand \index{MCS51 options}
5803
5804 \end_inset 
5805
5806
5807 \layout List
5808 \labelwidthstring 00.00.0000
5809
5810
5811 \series bold 
5812 -
5813 \begin_inset ERT
5814 status Collapsed
5815
5816 \layout Standard
5817
5818 \backslash 
5819 /
5820 \end_inset 
5821
5822 -model-small
5823 \begin_inset LatexCommand \index{-\/-model-small}
5824
5825 \end_inset 
5826
5827
5828 \series default 
5829 \size large 
5830 \emph on 
5831  
5832 \size default 
5833 \emph default 
5834 Generate code for Small Model programs, see section Memory Models for more
5835  details.
5836  This is the default model.
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-large
5853 \begin_inset LatexCommand \index{-\/-model-large}
5854
5855 \end_inset 
5856
5857
5858 \series default 
5859  Generate code for Large model programs, see section Memory Models for more
5860  details.
5861  If this option is used all source files in the project have to be compiled
5862  with this option.
5863 \layout List
5864 \labelwidthstring 00.00.0000
5865
5866
5867 \series bold 
5868 -
5869 \begin_inset ERT
5870 status Collapsed
5871
5872 \layout Standard
5873
5874 \backslash 
5875 /
5876 \end_inset 
5877
5878 -xstack
5879 \begin_inset LatexCommand \index{-\/-xstack}
5880
5881 \end_inset 
5882
5883
5884 \series default 
5885  Uses a pseudo stack in the first 256 bytes in the external ram for allocating
5886  variables and passing parameters.
5887  See section 
5888 \begin_inset LatexCommand \ref{sub:External-Stack}
5889
5890 \end_inset 
5891
5892 \SpecialChar ~
5893  External Stack for more details.
5894 \layout List
5895 \labelwidthstring 00.00.0000
5896
5897
5898 \series bold 
5899 -
5900 \begin_inset ERT
5901 status Collapsed
5902
5903 \layout Standard
5904
5905 \backslash 
5906 /
5907 \end_inset 
5908
5909 -iram-size
5910 \series default 
5911 \SpecialChar ~
5912 <Value>
5913 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
5914
5915 \end_inset 
5916
5917  Causes the linker to check if the internal ram usage is within limits of
5918  the given value.
5919 \layout List
5920 \labelwidthstring 00.00.0000
5921
5922
5923 \series bold 
5924 -
5925 \begin_inset ERT
5926 status Collapsed
5927
5928 \layout Standard
5929
5930 \backslash 
5931 /
5932 \end_inset 
5933
5934 -xram-size
5935 \series default 
5936 \SpecialChar ~
5937 <Value>
5938 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
5939
5940 \end_inset 
5941
5942  Causes the linker to check if the external ram usage is within limits of
5943  the given value.
5944 \layout List
5945 \labelwidthstring 00.00.0000
5946
5947
5948 \series bold 
5949 -
5950 \begin_inset ERT
5951 status Collapsed
5952
5953 \layout Standard
5954
5955 \backslash 
5956 /
5957 \end_inset 
5958
5959 -code-size
5960 \series default 
5961 \SpecialChar ~
5962 <Value>
5963 \begin_inset LatexCommand \index{-\/-code-size <Value>}
5964
5965 \end_inset 
5966
5967  Causes the linker to check if the code memory usage is within limits of
5968  the given value.
5969 \layout List
5970 \labelwidthstring 00.00.0000
5971
5972
5973 \series bold 
5974 -
5975 \begin_inset ERT
5976 status Collapsed
5977
5978 \layout Standard
5979
5980 \backslash 
5981 /
5982 \end_inset 
5983
5984 -stack-size
5985 \series default 
5986 \SpecialChar ~
5987 <Value>
5988 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
5989
5990 \end_inset 
5991
5992  Causes the linker to check if there is at minimum <Value> bytes for stack.
5993 \layout List
5994 \labelwidthstring 00.00.0000
5995
5996
5997 \series bold 
5998 -
5999 \begin_inset ERT
6000 status Collapsed
6001
6002 \layout Standard
6003
6004 \backslash 
6005 /
6006 \end_inset 
6007
6008 -pack-iram
6009 \series default 
6010 \SpecialChar ~
6011
6012 \begin_inset LatexCommand \index{-\/-pack-iram}
6013
6014 \end_inset 
6015
6016  Causes the linker use unused register banks for data variables or stack.
6017 \layout Subsection
6018
6019 DS390 / DS400 Options
6020 \begin_inset LatexCommand \index{Options DS390}
6021
6022 \end_inset 
6023
6024
6025 \begin_inset LatexCommand \index{DS390 options}
6026
6027 \end_inset 
6028
6029
6030 \layout List
6031 \labelwidthstring 00.00.0000
6032
6033
6034 \series bold 
6035 -
6036 \begin_inset ERT
6037 status Collapsed
6038
6039 \layout Standard
6040
6041 \backslash 
6042 /
6043 \end_inset 
6044
6045 -model-flat24
6046 \series default 
6047
6048 \begin_inset LatexCommand \index{-\/-model-flat24}
6049
6050 \end_inset 
6051
6052
6053 \size large 
6054 \emph on 
6055  
6056 \size default 
6057 \emph default 
6058 Generate 24-bit flat mode code.
6059  This is the one and only that the ds390 code generator supports right now
6060  and is default when using 
6061 \emph on 
6062 -mds390
6063 \emph default 
6064 .
6065  See section Memory Models for more details.
6066 \layout List
6067 \labelwidthstring 00.00.0000
6068
6069
6070 \series bold 
6071 -
6072 \begin_inset ERT
6073 status Collapsed
6074
6075 \layout Standard
6076
6077 \backslash 
6078 /
6079 \end_inset 
6080
6081 -protect-sp-update
6082 \begin_inset LatexCommand \index{-\/-protect-sp-update}
6083
6084 \end_inset 
6085
6086
6087 \series default 
6088  disable interrupts during ESP:SP updates.
6089 \layout List
6090 \labelwidthstring 00.00.0000
6091
6092
6093 \series bold 
6094 -
6095 \begin_inset ERT
6096 status Collapsed
6097
6098 \layout Standard
6099
6100 \backslash 
6101 /
6102 \end_inset 
6103
6104 -stack-10bit
6105 \series default 
6106
6107 \begin_inset LatexCommand \index{-\/-stack-10bit}
6108
6109 \end_inset 
6110
6111  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
6112  This is the one and only that the ds390 code generator supports right now
6113  and is default when using 
6114 \emph on 
6115 -mds390
6116 \emph default 
6117 .
6118  In this mode, the stack is located in the lower 1K of the internal RAM,
6119  which is mapped to 0x400000.
6120  Note that the support is incomplete, since it still uses a single byte
6121  as the stack pointer.
6122  This means that only the lower 256 bytes of the potential 1K stack space
6123  will actually be used.
6124  However, this does allow you to reclaim the precious 256 bytes of low RAM
6125  for use for the DATA and IDATA segments.
6126  The compiler will not generate any code to put the processor into 10 bit
6127  stack mode.
6128  It is important to ensure that the processor is in this mode before calling
6129  any re-entrant functions compiled with this option.
6130  In principle, this should work with the 
6131 \emph on 
6132 -
6133 \begin_inset ERT
6134 status Collapsed
6135
6136 \layout Standard
6137
6138 \backslash 
6139 /
6140 \end_inset 
6141
6142 -stack-auto
6143 \begin_inset LatexCommand \index{-\/-stack-auto}
6144
6145 \end_inset 
6146
6147
6148 \emph default 
6149  option, but that has not been tested.
6150  It is incompatible with the 
6151 \emph on 
6152 -
6153 \begin_inset ERT
6154 status Collapsed
6155
6156 \layout Standard
6157
6158 \backslash 
6159 /
6160 \end_inset 
6161
6162 -xstack
6163 \begin_inset LatexCommand \index{-\/-xstack}
6164
6165 \end_inset 
6166
6167
6168 \emph default 
6169  option.
6170  It also only makes sense if the processor is in 24 bit contiguous addressing
6171  mode (see the 
6172 \emph on 
6173 -
6174 \begin_inset ERT
6175 status Collapsed
6176
6177 \layout Standard
6178
6179 \backslash 
6180 /
6181 \end_inset 
6182
6183 -model-flat24 option
6184 \emph default 
6185 ).
6186 \layout List
6187 \labelwidthstring 00.00.0000
6188
6189
6190 \series bold 
6191 -
6192 \begin_inset ERT
6193 status Collapsed
6194
6195 \layout Standard
6196
6197 \backslash 
6198 /
6199 \end_inset 
6200
6201 -stack-probe
6202 \begin_inset LatexCommand \index{-\/-stack-probe}
6203
6204 \end_inset 
6205
6206
6207 \series default 
6208  insert call to function __stack_probe at each function prologue.
6209 \layout List
6210 \labelwidthstring 00.00.0000
6211
6212
6213 \series bold 
6214 -
6215 \begin_inset ERT
6216 status Collapsed
6217
6218 \layout Standard
6219
6220 \backslash 
6221 /
6222 \end_inset 
6223
6224 -tini-libid
6225 \begin_inset LatexCommand \index{-\/-tini-libid}
6226
6227 \end_inset 
6228
6229
6230 \series default 
6231  <nnnn> LibraryID used in -mTININative.
6232  
6233 \layout List
6234 \labelwidthstring 00.00.0000
6235
6236
6237 \series bold 
6238 -
6239 \begin_inset ERT
6240 status Collapsed
6241
6242 \layout Standard
6243
6244 \backslash 
6245 /
6246 \end_inset 
6247
6248 -use-accelerator
6249 \begin_inset LatexCommand \index{-\/-use-accelerator}
6250
6251 \end_inset 
6252
6253
6254 \series default 
6255  generate code for DS390 Arithmetic Accelerator.
6256  
6257 \layout Subsection
6258
6259 Z80 Options
6260 \begin_inset LatexCommand \index{Options Z80}
6261
6262 \end_inset 
6263
6264
6265 \begin_inset LatexCommand \index{Z80 options}
6266
6267 \end_inset 
6268
6269
6270 \layout List
6271 \labelwidthstring 00.00.0000
6272
6273
6274 \series bold 
6275 -
6276 \begin_inset ERT
6277 status Collapsed
6278
6279 \layout Standard
6280
6281 \backslash 
6282 /
6283 \end_inset 
6284
6285 -callee-saves-bc
6286 \series default 
6287
6288 \begin_inset LatexCommand \index{-\/-callee-saves-bc}
6289
6290 \end_inset 
6291
6292
6293 \size large 
6294 \emph on 
6295  
6296 \size default 
6297 \emph default 
6298 Force a called function to always save BC.
6299 \layout List
6300 \labelwidthstring 00.00.0000
6301
6302
6303 \series bold 
6304 -
6305 \begin_inset ERT
6306 status Collapsed
6307
6308 \layout Standard
6309
6310 \backslash 
6311 /
6312 \end_inset 
6313
6314 -no-std-crt0
6315 \series default 
6316
6317 \begin_inset LatexCommand \index{-\/-no-std-crt0}
6318
6319 \end_inset 
6320
6321  When linking, skip the standard crt0.o object file.
6322  You must provide your own crt0.o for your system when linking.
6323  
6324 \layout Subsection
6325
6326 Optimization Options
6327 \begin_inset LatexCommand \index{Options optimization}
6328
6329 \end_inset 
6330
6331
6332 \begin_inset LatexCommand \index{Optimization options}
6333
6334 \end_inset 
6335
6336
6337 \layout List
6338 \labelwidthstring 00.00.0000
6339
6340
6341 \series bold 
6342 -
6343 \begin_inset ERT
6344 status Collapsed
6345
6346 \layout Standard
6347
6348 \backslash 
6349 /
6350 \end_inset 
6351
6352 -nogcse
6353 \begin_inset LatexCommand \index{-\/-nogcse}
6354
6355 \end_inset 
6356
6357
6358 \series default 
6359  Will not do global subexpression elimination, this option may be used when
6360  the compiler creates undesirably large stack/data spaces to store compiler
6361  temporaries.
6362  A warning message will be generated when this happens and the compiler
6363  will indicate the number of extra bytes it allocated.
6364  It is recommended that this option NOT be used, #pragma\SpecialChar ~
6365 nogcse
6366 \begin_inset LatexCommand \index{\#pragma nogcse}
6367
6368 \end_inset 
6369
6370  can be used to turn off global subexpression elimination
6371 \begin_inset LatexCommand \index{Subexpression elimination}
6372
6373 \end_inset 
6374
6375  for a given function only.
6376 \layout List
6377 \labelwidthstring 00.00.0000
6378
6379
6380 \series bold 
6381 -
6382 \begin_inset ERT
6383 status Collapsed
6384
6385 \layout Standard
6386
6387 \backslash 
6388 /
6389 \end_inset 
6390
6391 -noinvariant
6392 \begin_inset LatexCommand \index{-\/-noinvariant}
6393
6394 \end_inset 
6395
6396
6397 \series default 
6398  Will not do loop invariant optimizations, this may be turned off for reasons
6399  explained for the previous option.
6400  For more details of loop optimizations performed see section Loop Invariants.
6401  It is recommended that this option NOT be used, #pragma\SpecialChar ~
6402 noinvariant
6403 \begin_inset LatexCommand \index{\#pragma noinvariant}
6404
6405 \end_inset 
6406
6407  can be used to turn off invariant optimizations for a given function only.
6408 \layout List
6409 \labelwidthstring 00.00.0000
6410
6411
6412 \series bold 
6413 -
6414 \begin_inset ERT
6415 status Collapsed
6416
6417 \layout Standard
6418
6419 \backslash 
6420 /
6421 \end_inset 
6422
6423 -noinduction
6424 \begin_inset LatexCommand \index{-\/-noinduction}
6425
6426 \end_inset 
6427
6428
6429 \series default 
6430  Will not do loop induction optimizations, see section strength reduction
6431  for more details.
6432  It is recommended that this option is NOT used, #pragma\SpecialChar ~
6433 noinduction
6434 \begin_inset LatexCommand \index{\#pragma noinduction}
6435
6436 \end_inset 
6437
6438  can be used to turn off induction optimizations for a given function only.
6439 \layout List
6440 \labelwidthstring 00.00.0000
6441
6442
6443 \series bold 
6444 -
6445 \begin_inset ERT
6446 status Collapsed
6447
6448 \layout Standard
6449
6450 \backslash 
6451 /
6452 \end_inset 
6453
6454 -nojtbound
6455 \begin_inset LatexCommand \index{-\/-nojtbound}
6456
6457 \end_inset 
6458
6459
6460 \size large 
6461 \bar under 
6462  
6463 \series default 
6464 \size default 
6465 \bar default 
6466  Will not generate boundary condition check when switch statements
6467 \begin_inset LatexCommand \index{switch statement}
6468
6469 \end_inset 
6470
6471  are implemented using jump-tables.
6472  See section 
6473 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
6474
6475 \end_inset 
6476
6477 \SpecialChar ~
6478 Switch Statements for more details.
6479  It is recommended that this option is NOT used, #pragma\SpecialChar ~
6480 nojtbound
6481 \begin_inset LatexCommand \index{\#pragma nojtbound}
6482
6483 \end_inset 
6484
6485  can be used to turn off boundary checking for jump tables for a given function
6486  only.
6487 \layout List
6488 \labelwidthstring 00.00.0000
6489
6490
6491 \series bold 
6492 -
6493 \begin_inset ERT
6494 status Collapsed
6495
6496 \layout Standard
6497
6498 \backslash 
6499 /
6500 \end_inset 
6501
6502 -noloopreverse
6503 \begin_inset LatexCommand \index{-\/-noloopreverse}
6504
6505 \end_inset 
6506
6507
6508 \series default 
6509 \size large 
6510  
6511 \size default 
6512 Will not do loop reversal 
6513 \begin_inset LatexCommand \index{Loop reversing}
6514
6515 \end_inset 
6516
6517 optimization.
6518 \layout List
6519 \labelwidthstring 00.00.0000
6520
6521 -
6522 \begin_inset ERT
6523 status Collapsed
6524
6525 \layout Standard
6526
6527 \backslash 
6528 /
6529 \end_inset 
6530
6531 -
6532 \series bold 
6533 nolabelopt
6534 \series default 
6535  
6536 \begin_inset LatexCommand \index{-\/-nolabelopt }
6537
6538 \end_inset 
6539
6540 Will not optimize labels (makes the dumpfiles more readable).
6541 \layout List
6542 \labelwidthstring 00.00.0000
6543
6544
6545 \series bold 
6546 -
6547 \begin_inset ERT
6548 status Collapsed
6549
6550 \layout Standard
6551
6552 \backslash 
6553 /
6554 \end_inset 
6555
6556 -no-xinit-opt
6557 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
6558
6559 \end_inset 
6560
6561
6562 \series default 
6563  Will not memcpy initialized data from code space into xdata space.
6564  This saves a few bytes in code space if you don't have initialized data.
6565 \layout List
6566 \labelwidthstring 00.00.0000
6567
6568
6569 \series bold 
6570 -
6571 \begin_inset ERT
6572 status Collapsed
6573
6574 \layout Standard
6575
6576 \backslash 
6577 /
6578 \end_inset 
6579
6580 -nooverlay
6581 \begin_inset LatexCommand \index{-\/-nooverlay}
6582
6583 \end_inset 
6584
6585
6586 \series default 
6587   The compiler will not overlay parameters and local variables of any function,
6588  see section Parameters and local variables for more details.
6589 \layout List
6590 \labelwidthstring 00.00.0000
6591
6592
6593 \series bold 
6594 -
6595 \begin_inset ERT
6596 status Collapsed
6597
6598 \layout Standard
6599
6600 \backslash 
6601 /
6602 \end_inset 
6603
6604 -no-peep
6605 \begin_inset LatexCommand \index{-\/-no-peep}
6606
6607 \end_inset 
6608
6609
6610 \series default 
6611  Disable peep-hole optimization.
6612 \layout List
6613 \labelwidthstring 00.00.0000
6614
6615
6616 \series bold 
6617 -
6618 \begin_inset ERT
6619 status Collapsed
6620
6621 \layout Standard
6622
6623 \backslash 
6624 /
6625 \end_inset 
6626
6627 -peep-file
6628 \series default 
6629
6630 \begin_inset LatexCommand \index{-\/-peep-file}
6631
6632 \end_inset 
6633
6634 \SpecialChar ~
6635 <filename> This option can be used to use additional rules to be used by
6636  the peep hole optimizer.
6637  See section 
6638 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
6639
6640 \end_inset 
6641
6642 \SpecialChar ~
6643 Peep Hole optimizations for details on how to write these rules.
6644 \layout List
6645 \labelwidthstring 00.00.0000
6646
6647
6648 \series bold 
6649 -
6650 \begin_inset ERT
6651 status Collapsed
6652
6653 \layout Standard
6654
6655 \backslash 
6656 /
6657 \end_inset 
6658
6659 -peep-asm
6660 \begin_inset LatexCommand \index{-\/-peep-asm}
6661
6662 \end_inset 
6663
6664
6665 \series default 
6666   Pass the inline assembler code through the peep hole optimizer.
6667  This can cause unexpected changes to inline assembler code, please go through
6668  the peephole optimizer
6669 \begin_inset LatexCommand \index{Peephole optimizer}
6670
6671 \end_inset 
6672
6673  rules defined in the source file tree '<target>/peeph.def' before using
6674  this option.
6675 \layout Subsection
6676
6677 Other Options
6678 \begin_inset LatexCommand \index{Options other}
6679
6680 \end_inset 
6681
6682
6683 \layout List
6684 \labelwidthstring 00.00.0000
6685
6686
6687 \series bold 
6688 -c\SpecialChar ~
6689 -
6690 \begin_inset ERT
6691 status Collapsed
6692
6693 \layout Standard
6694
6695 \backslash 
6696 /
6697 \end_inset 
6698
6699 -compile-only
6700 \begin_inset LatexCommand \index{-\/-compile-only}
6701
6702 \end_inset 
6703
6704
6705 \begin_inset LatexCommand \index{-c -\/-compile-only}
6706
6707 \end_inset 
6708
6709
6710 \series default 
6711  will compile and assemble the source, but will not call the linkage editor.
6712 \layout List
6713 \labelwidthstring 00.00.0000
6714
6715
6716 \series bold 
6717 -
6718 \series default 
6719
6720 \begin_inset ERT
6721 status Collapsed
6722
6723 \layout Standard
6724
6725 \backslash 
6726 /
6727 \end_inset 
6728
6729
6730 \series bold 
6731 -c1mode
6732 \begin_inset LatexCommand \index{-\/-c1mode}
6733
6734 \end_inset 
6735
6736
6737 \series default 
6738  reads the preprocessed source from standard input and compiles it.
6739  The file name for the assembler output must be specified using the -o option.
6740 \layout List
6741 \labelwidthstring 00.00.0000
6742
6743
6744 \series bold 
6745 -E
6746 \begin_inset LatexCommand \index{-E}
6747
6748 \end_inset 
6749
6750
6751 \series default 
6752  Run only the C preprocessor.
6753  Preprocess all the C source files specified and output the results to standard
6754  output.
6755 \layout List
6756 \labelwidthstring 00.00.0000
6757
6758
6759 \series bold 
6760 -o\SpecialChar ~
6761 <path/file>
6762 \begin_inset LatexCommand \index{-o <path/file>}
6763
6764 \end_inset 
6765
6766  
6767 \series default 
6768 The output path resp.
6769  file where everything will be placed.
6770  If the parameter is a path, it must have a trailing slash (or backslash
6771  for the Windows binaries) to be recognized as a path.
6772  
6773 \layout List
6774 \labelwidthstring 00.00.0000
6775
6776
6777 \series bold 
6778 -
6779 \begin_inset ERT
6780 status Collapsed
6781
6782 \layout Standard
6783
6784 \backslash 
6785 /
6786 \end_inset 
6787
6788 -stack-auto
6789 \begin_inset LatexCommand \index{-\/-stack-auto}
6790
6791 \end_inset 
6792
6793
6794 \series default 
6795 \size large 
6796 \emph on 
6797  
6798 \size default 
6799 \emph default 
6800 All functions in the source file will be compiled as 
6801 \emph on 
6802 reentrant
6803 \emph default 
6804
6805 \begin_inset LatexCommand \index{reentrant}
6806
6807 \end_inset 
6808
6809 , i.e.
6810  the parameters and local variables will be allocated on the stack
6811 \begin_inset LatexCommand \index{stack}
6812
6813 \end_inset 
6814
6815 .
6816  see section Parameters and Local Variables for more details.
6817  If this option is used all source files in the project should be compiled
6818  with this option.
6819  
6820 \layout List
6821 \labelwidthstring 00.00.0000
6822
6823
6824 \series bold 
6825 -
6826 \begin_inset ERT
6827 status Collapsed
6828
6829 \layout Standard
6830
6831 \backslash 
6832 /
6833 \end_inset 
6834
6835 -callee-saves
6836 \begin_inset LatexCommand \index{-\/-callee-saves}
6837
6838 \end_inset 
6839
6840  function1[,function2][,function3]....
6841
6842 \series default 
6843  The compiler by default uses a caller saves convention for register saving
6844  across function calls, however this can cause unnecessary register pushing
6845  & popping when calling small functions from larger functions.
6846  This option can be used to switch the register saving convention for the
6847  function names specified.
6848  The compiler will not save registers when calling these functions, no extra
6849  code will be generated at the entry & exit (function prologue
6850 \series bold 
6851
6852 \begin_inset LatexCommand \index{function prologue}
6853
6854 \end_inset 
6855
6856
6857 \series default 
6858  & epilogue
6859 \series bold 
6860
6861 \begin_inset LatexCommand \index{function epilogue}
6862
6863 \end_inset 
6864
6865
6866 \series default 
6867 ) for these functions to save & restore the registers used by these functions,
6868  this can SUBSTANTIALLY reduce code & improve run time performance of the
6869  generated code.
6870  In the future the compiler (with inter procedural analysis) will be able
6871  to determine the appropriate scheme to use for each function call.
6872  DO NOT use this option for built-in functions such as _mulint..., if this
6873  option is used for a library function the appropriate library function
6874  needs to be recompiled with the same option.
6875  If the project consists of multiple source files then all the source file
6876  should be compiled with the same -
6877 \begin_inset ERT
6878 status Collapsed
6879
6880 \layout Standard
6881
6882 \backslash 
6883 /
6884 \end_inset 
6885
6886 -callee-saves option string.
6887  Also see #pragma\SpecialChar ~
6888 callee_saves
6889 \begin_inset LatexCommand \index{\#pragma callee\_saves}
6890
6891 \end_inset 
6892
6893 .
6894 \layout List
6895 \labelwidthstring 00.00.0000
6896
6897
6898 \series bold 
6899 -
6900 \begin_inset ERT
6901 status Open
6902
6903 \layout Standard
6904
6905 \backslash 
6906 /
6907 \end_inset 
6908
6909 -debug
6910 \begin_inset LatexCommand \index{-\/-debug}
6911
6912 \end_inset 
6913
6914
6915 \bar under 
6916  
6917 \series default 
6918 \bar default 
6919 When this option is used the compiler will generate debug information.
6920  The debug information collected in a file with .cdb extension can be used
6921  with the SDCDB.
6922  For more information see documentation for SDCDB.
6923  Another file with no extension contains debug information in AOMF or AOMF51
6924 \begin_inset LatexCommand \index{AOMF, AOMF51}
6925
6926 \end_inset 
6927
6928  format which is commonly used by third party tools.
6929 \layout List
6930 \labelwidthstring 00.00.0000
6931
6932
6933 \series bold 
6934 -S
6935 \begin_inset LatexCommand \index{-S}
6936
6937 \end_inset 
6938
6939
6940 \size large 
6941 \bar under 
6942  
6943 \series default 
6944 \size default 
6945 \bar default 
6946 Stop after the stage of compilation proper; do not assemble.
6947  The output is an assembler code file for the input file specified.
6948 \layout List
6949 \labelwidthstring 00.00.0000
6950
6951
6952 \series bold 
6953 -
6954 \begin_inset ERT
6955 status Collapsed
6956
6957 \layout Standard
6958
6959 \backslash 
6960 /
6961 \end_inset 
6962
6963 -int-long-reent
6964 \begin_inset LatexCommand \index{-\/-int-long-reent}
6965
6966 \end_inset 
6967
6968
6969 \series default 
6970  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
6971  Note by default these libraries are compiled as non-reentrant.
6972  See section Installation for more details.
6973 \layout List
6974 \labelwidthstring 00.00.0000
6975
6976
6977 \series bold 
6978 -
6979 \begin_inset ERT
6980 status Collapsed
6981
6982 \layout Standard
6983
6984 \backslash 
6985 /
6986 \end_inset 
6987
6988 -cyclomatic
6989 \begin_inset LatexCommand \index{-\/-cyclomatic}
6990
6991 \end_inset 
6992
6993
6994 \bar under 
6995  
6996 \series default 
6997 \bar default 
6998 This option will cause the compiler to generate an information message for
6999  each function in the source file.
7000  The message contains some 
7001 \emph on 
7002 important
7003 \emph default 
7004  information about the function.
7005  The number of edges and nodes the compiler detected in the control flow
7006  graph of the function, and most importantly the 
7007 \emph on 
7008 cyclomatic complexity
7009 \begin_inset LatexCommand \index{Cyclomatic complexity}
7010
7011 \end_inset 
7012
7013
7014 \emph default 
7015  see section on Cyclomatic Complexity for more details.
7016 \layout List
7017 \labelwidthstring 00.00.0000
7018
7019
7020 \series bold 
7021 -
7022 \begin_inset ERT
7023 status Collapsed
7024
7025 \layout Standard
7026
7027 \backslash 
7028 /
7029 \end_inset 
7030
7031 -float-reent
7032 \begin_inset LatexCommand \index{-\/-float-reent}
7033
7034 \end_inset 
7035
7036
7037 \series default 
7038  Floating point library is compiled as reentrant
7039 \begin_inset LatexCommand \index{reentrant}
7040
7041 \end_inset 
7042
7043 .
7044  See section Installation for more details.
7045 \layout List
7046 \labelwidthstring 00.00.0000
7047
7048
7049 \series bold 
7050 -
7051 \begin_inset ERT
7052 status Collapsed
7053
7054 \layout Standard
7055
7056 \backslash 
7057 /
7058 \end_inset 
7059
7060 -main-return
7061 \begin_inset LatexCommand \index{-\/-main-return}
7062
7063 \end_inset 
7064
7065
7066 \series default 
7067  This option can be used if the code generated is called by a monitor program
7068  or if the main routine includes an endless loop.
7069  This option might result in slightly smaller code and save two bytes of
7070  stack space.
7071  The return from the 'main'
7072 \begin_inset LatexCommand \index{main return}
7073
7074 \end_inset 
7075
7076  function will return to the function calling main.
7077  The default setting is to lock up i.e.
7078  generate a '
7079 \family typewriter 
7080 sjmp .
7081 \family default 
7082 '.
7083 \layout List
7084 \labelwidthstring 00.00.0000
7085
7086
7087 \series bold 
7088 -
7089 \begin_inset ERT
7090 status Collapsed
7091
7092 \layout Standard
7093
7094 \backslash 
7095 /
7096 \end_inset 
7097
7098 -nostdincl
7099 \begin_inset LatexCommand \index{-\/-nostdincl}
7100
7101 \end_inset 
7102
7103
7104 \series default 
7105  This will prevent the compiler from passing on the default include path
7106  to the preprocessor.
7107 \layout List
7108 \labelwidthstring 00.00.0000
7109
7110
7111 \series bold 
7112 -
7113 \begin_inset ERT
7114 status Collapsed
7115
7116 \layout Standard
7117
7118 \backslash 
7119 /
7120 \end_inset 
7121
7122 -nostdlib
7123 \begin_inset LatexCommand \index{-\/-nostdlib}
7124
7125 \end_inset 
7126
7127
7128 \series default 
7129  This will prevent the compiler from passing on the default library
7130 \begin_inset LatexCommand \index{Libraries}
7131
7132 \end_inset 
7133
7134  path to the linker.
7135 \layout List
7136 \labelwidthstring 00.00.0000
7137
7138
7139 \series bold 
7140 -
7141 \begin_inset ERT
7142 status Collapsed
7143
7144 \layout Standard
7145
7146 \backslash 
7147 /
7148 \end_inset 
7149
7150 -verbose
7151 \begin_inset LatexCommand \index{-\/-verbose}
7152
7153 \end_inset 
7154
7155
7156 \series default 
7157  Shows the various actions the compiler is performing.
7158 \layout List
7159 \labelwidthstring 00.00.0000
7160
7161
7162 \series bold 
7163 -V
7164 \begin_inset LatexCommand \index{-V}
7165
7166 \end_inset 
7167
7168
7169 \series default 
7170  Shows the actual commands the compiler is executing.
7171 \layout List
7172 \labelwidthstring 00.00.0000
7173
7174
7175 \series bold 
7176 -
7177 \begin_inset ERT
7178 status Collapsed
7179
7180 \layout Standard
7181
7182 \backslash 
7183 /
7184 \end_inset 
7185
7186 -no-c-code-in-asm
7187 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
7188
7189 \end_inset 
7190
7191
7192 \series default 
7193  Hides your ugly and inefficient c-code from the asm file, so you can always
7194  blame the compiler :)
7195 \layout List
7196 \labelwidthstring 00.00.0000
7197
7198
7199 \series bold 
7200 -
7201 \begin_inset ERT
7202 status Collapsed
7203
7204 \layout Standard
7205
7206 \backslash 
7207 /
7208 \end_inset 
7209
7210 -no-peep-comments
7211 \begin_inset LatexCommand \index{-\/-no-peep-comments}
7212
7213 \end_inset 
7214
7215
7216 \series default 
7217  Will not include peep-hole comments in the generated files.
7218 \layout List
7219 \labelwidthstring 00.00.0000
7220
7221
7222 \series bold 
7223 -
7224 \begin_inset ERT
7225 status Collapsed
7226
7227 \layout Standard
7228
7229 \backslash 
7230 /
7231 \end_inset 
7232
7233 -i-code-in-asm
7234 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
7235
7236 \end_inset 
7237
7238
7239 \series default 
7240  Include i-codes in the asm file.
7241  Sounds like noise but is most helpful for debugging the compiler itself.
7242 \layout List
7243 \labelwidthstring 00.00.0000
7244
7245
7246 \series bold 
7247 -
7248 \begin_inset ERT
7249 status Collapsed
7250
7251 \layout Standard
7252
7253 \backslash 
7254 /
7255 \end_inset 
7256
7257 -less-pedantic
7258 \begin_inset LatexCommand \index{-\/-less-pedantic}
7259
7260 \end_inset 
7261
7262
7263 \series default 
7264  Disable some of the more pedantic warnings
7265 \begin_inset LatexCommand \index{Warnings}
7266
7267 \end_inset 
7268
7269  (jwk burps: please be more specific here, please!).
7270  If you want rather more than less warnings you should consider using a
7271  separate tool dedicated to syntax checking like splint 
7272 \begin_inset LatexCommand \url{www.splint.org}
7273
7274 \end_inset 
7275
7276 .
7277 \layout List
7278 \labelwidthstring 00.00.0000
7279
7280
7281 \series bold 
7282 -
7283 \begin_inset ERT
7284 status Collapsed
7285
7286 \layout Standard
7287
7288 \backslash 
7289 /
7290 \end_inset 
7291
7292 -print-search-dirs
7293 \begin_inset LatexCommand \index{-\/-print-search-dirs}
7294
7295 \end_inset 
7296
7297
7298 \series default 
7299  Display the directories in the compiler's search path
7300 \layout List
7301 \labelwidthstring 00.00.0000
7302
7303
7304 \series bold 
7305 -
7306 \begin_inset ERT
7307 status Collapsed
7308
7309 \layout Standard
7310
7311 \backslash 
7312 /
7313 \end_inset 
7314
7315 -vc
7316 \begin_inset LatexCommand \index{-\/-vc}
7317
7318 \end_inset 
7319
7320
7321 \series default 
7322  Display errors and warnings using MSVC style, so you can use SDCC with
7323  visual studio.
7324 \layout List
7325 \labelwidthstring 00.00.0000
7326
7327
7328 \series bold 
7329 -
7330 \begin_inset ERT
7331 status Collapsed
7332
7333 \layout Standard
7334
7335 \backslash 
7336 /
7337 \end_inset 
7338
7339 -use-stdout
7340 \begin_inset LatexCommand \index{-\/-use-stdout}
7341
7342 \end_inset 
7343
7344
7345 \series default 
7346  Send errors and warnings to stdout instead of stderr.
7347 \layout List
7348 \labelwidthstring 00.00.0000
7349
7350
7351 \series bold 
7352 -Wa\SpecialChar ~
7353 asmOption[,asmOption]
7354 \series default 
7355
7356 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
7357
7358 \end_inset 
7359
7360 ...
7361  Pass the asmOption to the assembler
7362 \begin_inset LatexCommand \index{Options assembler}
7363
7364 \end_inset 
7365
7366
7367 \begin_inset LatexCommand \index{Assembler options}
7368
7369 \end_inset 
7370
7371 .
7372  See file sdcc/as/doc/asxhtm.html for assembler options.
7373 \layout Subsection
7374
7375 Intermediate Dump Options
7376 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
7377
7378 \end_inset 
7379
7380
7381 \begin_inset LatexCommand \index{Options intermediate dump}
7382
7383 \end_inset 
7384
7385
7386 \begin_inset LatexCommand \index{Intermediate dump options}
7387
7388 \end_inset 
7389
7390
7391 \layout Standard
7392
7393 The following options are provided for the purpose of retargetting and debugging
7394  the compiler.
7395  These provided a means to dump the intermediate code (iCode
7396 \begin_inset LatexCommand \index{iCode}
7397
7398 \end_inset 
7399
7400 ) generated by the compiler in human readable form at various stages of
7401  the compilation process.
7402  More on iCodes see chapter 
7403 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
7404
7405 \end_inset 
7406
7407  
7408 \begin_inset Quotes srd
7409 \end_inset 
7410
7411 The anatomy of the compiler
7412 \begin_inset Quotes srd
7413 \end_inset 
7414
7415 .
7416 \layout List
7417 \labelwidthstring 00.00.0000
7418
7419
7420 \series bold 
7421 -
7422 \begin_inset ERT
7423 status Collapsed
7424
7425 \layout Standard
7426
7427 \backslash 
7428 /
7429 \end_inset 
7430
7431 -dumpraw
7432 \begin_inset LatexCommand \index{-\/-dumpraw}
7433
7434 \end_inset 
7435
7436
7437 \series default 
7438  This option will cause the compiler to dump the intermediate code into
7439  a file of named 
7440 \emph on 
7441 <source filename>.dumpraw
7442 \emph default 
7443  just after the intermediate code has been generated for a function, i.e.
7444  before any optimizations are done.
7445  The basic blocks
7446 \begin_inset LatexCommand \index{Basic blocks}
7447
7448 \end_inset 
7449
7450  at this stage ordered in the depth first number, so they may not be in
7451  sequence of execution.
7452 \layout List
7453 \labelwidthstring 00.00.0000
7454
7455
7456 \series bold 
7457 -
7458 \begin_inset ERT
7459 status Collapsed
7460
7461 \layout Standard
7462
7463 \backslash 
7464 /
7465 \end_inset 
7466
7467 -dumpgcse
7468 \begin_inset LatexCommand \index{-\/-dumpgcse}
7469
7470 \end_inset 
7471
7472
7473 \series default 
7474  Will create a dump of iCode's, after global subexpression elimination
7475 \begin_inset LatexCommand \index{Global subexpression elimination}
7476
7477 \end_inset 
7478
7479 , into a file named 
7480 \emph on 
7481 <source filename>.dumpgcse.
7482 \layout List
7483 \labelwidthstring 00.00.0000
7484
7485
7486 \series bold 
7487 -
7488 \begin_inset ERT
7489 status Collapsed
7490
7491 \layout Standard
7492
7493 \backslash 
7494 /
7495 \end_inset 
7496
7497 -dumpdeadcode
7498 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
7499
7500 \end_inset 
7501
7502
7503 \series default 
7504  Will create a dump of iCode's, after deadcode elimination
7505 \begin_inset LatexCommand \index{Dead-code elimination}
7506
7507 \end_inset 
7508
7509 , into a file named 
7510 \emph on 
7511 <source filename>.dumpdeadcode.
7512 \layout List
7513 \labelwidthstring 00.00.0000
7514
7515
7516 \series bold 
7517 -
7518 \begin_inset ERT
7519 status Collapsed
7520
7521 \layout Standard
7522
7523 \backslash 
7524 /
7525 \end_inset 
7526
7527 -dumploop
7528 \begin_inset LatexCommand \index{-\/-dumploop}
7529
7530 \end_inset 
7531
7532
7533 \series default 
7534 \size large 
7535  
7536 \size default 
7537 Will create a dump of iCode's, after loop optimizations
7538 \begin_inset LatexCommand \index{Loop optimization}
7539
7540 \end_inset 
7541
7542 , into a file named 
7543 \emph on 
7544 <source filename>.dumploop.
7545 \layout List
7546 \labelwidthstring 00.00.0000
7547
7548
7549 \series bold 
7550 -
7551 \begin_inset ERT
7552 status Collapsed
7553
7554 \layout Standard
7555
7556 \backslash 
7557 /
7558 \end_inset 
7559
7560 -dumprange
7561 \begin_inset LatexCommand \index{-\/-dumprange}
7562
7563 \end_inset 
7564
7565
7566 \series default 
7567 \size large 
7568  
7569 \size default 
7570 Will create a dump of iCode's, after live range analysis
7571 \begin_inset LatexCommand \index{Live range analysis}
7572
7573 \end_inset 
7574
7575 , into a file named 
7576 \emph on 
7577 <source filename>.dumprange.
7578 \layout List
7579 \labelwidthstring 00.00.0000
7580
7581
7582 \series bold 
7583 -
7584 \begin_inset ERT
7585 status Collapsed
7586
7587 \layout Standard
7588
7589 \backslash 
7590 /
7591 \end_inset 
7592
7593 -dumlrange
7594 \begin_inset LatexCommand \index{-\/-dumlrange}
7595
7596 \end_inset 
7597
7598
7599 \series default 
7600  Will dump the life ranges
7601 \begin_inset LatexCommand \index{Live range analysis}
7602
7603 \end_inset 
7604
7605  for all symbols.
7606 \layout List
7607 \labelwidthstring 00.00.0000
7608
7609
7610 \series bold 
7611 -
7612 \begin_inset ERT
7613 status Collapsed
7614
7615 \layout Standard
7616
7617 \backslash 
7618 /
7619 \end_inset 
7620
7621 -dumpregassign
7622 \begin_inset LatexCommand \index{-\/-dumpregassign}
7623
7624 \end_inset 
7625
7626
7627 \bar under 
7628  
7629 \series default 
7630 \bar default 
7631 Will create a dump of iCode's, after register assignment
7632 \begin_inset LatexCommand \index{Register assignment}
7633
7634 \end_inset 
7635
7636 , into a file named 
7637 \emph on 
7638 <source filename>.dumprassgn.
7639 \layout List
7640 \labelwidthstring 00.00.0000
7641
7642
7643 \series bold 
7644 -
7645 \begin_inset ERT
7646 status Collapsed
7647
7648 \layout Standard
7649
7650 \backslash 
7651 /
7652 \end_inset 
7653
7654 -dumplrange
7655 \begin_inset LatexCommand \index{-\/-dumplrange}
7656
7657 \end_inset 
7658
7659
7660 \series default 
7661  Will create a dump of the live ranges of iTemp's
7662 \layout List
7663 \labelwidthstring 00.00.0000
7664
7665
7666 \series bold 
7667 -
7668 \begin_inset ERT
7669 status Collapsed
7670
7671 \layout Standard
7672
7673 \backslash 
7674 /
7675 \end_inset 
7676
7677 -dumpall
7678 \begin_inset LatexCommand \index{-\/-dumpall}
7679
7680 \end_inset 
7681
7682
7683 \size large 
7684 \bar under 
7685  
7686 \series default 
7687 \size default 
7688 \bar default 
7689 Will cause all the above mentioned dumps to be created.
7690 \layout Subsection
7691
7692 Redirecting output on Windows Shells
7693 \layout Standard
7694
7695 By default SDCC writes it's error messages to 
7696 \begin_inset Quotes sld
7697 \end_inset 
7698
7699 standard error
7700 \begin_inset Quotes srd
7701 \end_inset 
7702
7703 .
7704  To force all messages to 
7705 \begin_inset Quotes sld
7706 \end_inset 
7707
7708 standard output
7709 \begin_inset Quotes srd
7710 \end_inset 
7711
7712  use 
7713 \series bold 
7714 -
7715 \series default 
7716 \emph on 
7717
7718 \begin_inset ERT
7719 status Collapsed
7720
7721 \layout Standard
7722
7723 \backslash 
7724 /
7725 \end_inset 
7726
7727
7728 \series bold 
7729 \emph default 
7730 -
7731 \series default 
7732 use-stdout
7733 \begin_inset LatexCommand \index{-\/-use-stdout}
7734
7735 \end_inset 
7736
7737 .
7738  Additionally, if you happen to have visual studio installed in your windows
7739  machine, you can use it to compile your sources using a custom build and
7740  the SDCC -
7741 \emph on 
7742
7743 \begin_inset ERT
7744 status Collapsed
7745
7746 \layout Standard
7747
7748 \backslash 
7749 /
7750 \end_inset 
7751
7752
7753 \emph default 
7754 -vc
7755 \begin_inset LatexCommand \index{-\/-vc}
7756
7757 \end_inset 
7758
7759  option.
7760  Something like this should work:
7761 \newline 
7762
7763 \newline 
7764
7765 \series bold 
7766 c:
7767 \backslash 
7768 sdcc
7769 \backslash 
7770 bin
7771 \backslash 
7772 sdcc.exe -
7773 \series default 
7774 \emph on 
7775
7776 \begin_inset ERT
7777 status Collapsed
7778
7779 \layout Standard
7780
7781 \backslash 
7782 /
7783 \end_inset 
7784
7785
7786 \series bold 
7787 \emph default 
7788 -vc -
7789 \series default 
7790 \emph on 
7791
7792 \begin_inset ERT
7793 status Collapsed
7794
7795 \layout Standard
7796
7797 \backslash 
7798 /
7799 \end_inset 
7800
7801
7802 \series bold 
7803 \emph default 
7804 -model-large -c $(InputPath)
7805 \layout Section
7806
7807 Environment variables
7808 \begin_inset LatexCommand \index{Environment variables}
7809
7810 \end_inset 
7811
7812
7813 \layout Standard
7814
7815 SDCC recognizes the following environment variables:
7816 \layout List
7817 \labelwidthstring 00.00.0000
7818
7819
7820 \series bold 
7821 SDCC_LEAVE_SIGNALS
7822 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
7823
7824 \end_inset 
7825
7826
7827 \series default 
7828  SDCC installs a signal handler
7829 \begin_inset LatexCommand \index{signal handler}
7830
7831 \end_inset 
7832
7833  to be able to delete temporary files after an user break (^C) or an exception.
7834  If this environment variable is set, SDCC won't install the signal handler
7835  in order to be able to debug SDCC.
7836 \layout List
7837 \labelwidthstring 00.00.0000
7838
7839
7840 \series bold 
7841 TMP,\SpecialChar ~
7842 TEMP,\SpecialChar ~
7843 TMPDIR
7844 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
7845
7846 \end_inset 
7847
7848
7849 \series default 
7850  Path, where temporary files will be created.
7851  The order of the variables is the search order.
7852  In a standard *nix environment these variables are not set, and there's
7853  no need to set them.
7854  On Windows it's recommended to set one of them.
7855 \layout List
7856 \labelwidthstring 00.00.0000
7857
7858
7859 \series bold 
7860 SDCC_HOME
7861 \begin_inset LatexCommand \index{SDCC\_HOME}
7862
7863 \end_inset 
7864
7865
7866 \series default 
7867  Path, see section 
7868 \begin_inset LatexCommand \ref{sub:Install-paths}
7869
7870 \end_inset 
7871
7872 \SpecialChar ~
7873
7874 \begin_inset Quotes sld
7875 \end_inset 
7876
7877  Install Paths
7878 \begin_inset Quotes srd
7879 \end_inset 
7880
7881 .
7882 \layout List
7883 \labelwidthstring 00.00.0000
7884
7885
7886 \series bold 
7887 SDCC_INCLUDE
7888 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
7889
7890 \end_inset 
7891
7892
7893 \series default 
7894  Path, see section 
7895 \begin_inset LatexCommand \ref{sub:Search-Paths}
7896
7897 \end_inset 
7898
7899 \SpecialChar ~
7900
7901 \begin_inset Quotes sld
7902 \end_inset 
7903
7904 Search Paths
7905 \begin_inset Quotes srd
7906 \end_inset 
7907
7908 .
7909 \layout List
7910 \labelwidthstring 00.00.0000
7911
7912
7913 \series bold 
7914 SDCC_LIB
7915 \begin_inset LatexCommand \index{SDCC\_LIB}
7916
7917 \end_inset 
7918
7919
7920 \series default 
7921  Path, see section 
7922 \begin_inset LatexCommand \ref{sub:Search-Paths}
7923
7924 \end_inset 
7925
7926 \SpecialChar ~
7927
7928 \begin_inset Quotes sld
7929 \end_inset 
7930
7931 Search Paths
7932 \begin_inset Quotes srd
7933 \end_inset 
7934
7935 ..
7936 \layout Standard
7937
7938 There are some more environment variables recognized by SDCC, but these
7939  are solely used for debugging purposes.
7940  They can change or disappear very quickly, and will never be documented.
7941 \layout Section
7942
7943 Storage Class Language Extensions
7944 \layout Subsection
7945
7946 MCS51/DS390 Storage Class
7947 \begin_inset LatexCommand \index{Storage class}
7948
7949 \end_inset 
7950
7951  Language Extensions
7952 \layout Standard
7953
7954 In addition to the ANSI storage classes SDCC allows the following MCS51
7955  specific storage classes:
7956 \layout Subsubsection
7957
7958 data
7959 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7960
7961 \end_inset 
7962
7963  / near
7964 \begin_inset LatexCommand \index{near (storage class)}
7965
7966 \end_inset 
7967
7968
7969 \layout Standard
7970
7971 This is the 
7972 \series bold 
7973 default
7974 \series default 
7975  storage class for the Small Memory model (
7976 \emph on 
7977 data
7978 \emph default 
7979  and 
7980 \emph on 
7981 near
7982 \emph default 
7983  can be used synonymously).
7984  Variables declared with this storage class will be allocated in the directly
7985  addressable portion of the internal RAM of a 8051, e.g.:
7986 \layout Verse
7987
7988
7989 \family typewriter 
7990 data unsigned char test_data;
7991 \layout Standard
7992
7993 Writing 0x01 to this variable generates the assembly code:
7994 \layout Verse
7995
7996
7997 \family typewriter 
7998 75*00 01\SpecialChar ~
7999 \SpecialChar ~
8000 \SpecialChar ~
8001 mov\SpecialChar ~
8002 \SpecialChar ~
8003 _test_data,#0x01 
8004 \layout Subsubsection
8005
8006 xdata
8007 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
8008
8009 \end_inset 
8010
8011  / far
8012 \begin_inset LatexCommand \index{far (storage class)}
8013
8014 \end_inset 
8015
8016
8017 \layout Standard
8018
8019 Variables declared with this storage class will be placed in the external
8020  RAM.
8021  This is the 
8022 \series bold 
8023 default
8024 \series default 
8025  storage class for the Large Memory model, e.g.:
8026 \layout Verse
8027
8028
8029 \family typewriter 
8030 xdata unsigned char test_xdata;
8031 \layout Standard
8032
8033 Writing 0x01 to this variable generates the assembly code:
8034 \layout Verse
8035
8036
8037 \family typewriter 
8038 90s00r00\SpecialChar ~
8039 \SpecialChar ~
8040 \SpecialChar ~
8041 mov\SpecialChar ~
8042 \SpecialChar ~
8043 dptr,#_test_xdata 
8044 \newline 
8045 74\SpecialChar ~
8046 01\SpecialChar ~
8047 \SpecialChar ~
8048 \SpecialChar ~
8049 \SpecialChar ~
8050 \SpecialChar ~
8051 \SpecialChar ~
8052 mov\SpecialChar ~
8053 \SpecialChar ~
8054 a,#0x01 
8055 \newline 
8056 F0\SpecialChar ~
8057 \SpecialChar ~
8058 \SpecialChar ~
8059 \SpecialChar ~
8060 \SpecialChar ~
8061 \SpecialChar ~
8062 \SpecialChar ~
8063 \SpecialChar ~
8064 \SpecialChar ~
8065 movx\SpecialChar ~
8066 @dptr,a 
8067 \layout Subsubsection
8068
8069 idata
8070 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
8071
8072 \end_inset 
8073
8074
8075 \layout Standard
8076
8077 Variables declared with this storage class will be allocated into the indirectly
8078  addressable portion of the internal ram of a 8051, e.g.:
8079 \layout Verse
8080
8081
8082 \family typewriter 
8083 idata unsigned char test_idata;
8084 \layout Standard
8085
8086 Writing 0x01 to this variable generates the assembly code:
8087 \layout Verse
8088
8089
8090 \family typewriter 
8091 78r00\SpecialChar ~
8092 \SpecialChar ~
8093 \SpecialChar ~
8094 \SpecialChar ~
8095 \SpecialChar ~
8096 \SpecialChar ~
8097 \SpecialChar ~
8098 mov\SpecialChar ~
8099 \SpecialChar ~
8100 r0,#_test_idata
8101 \newline 
8102 76\SpecialChar ~
8103 01\SpecialChar ~
8104 \SpecialChar ~
8105 \SpecialChar ~
8106 \SpecialChar ~
8107 \SpecialChar ~
8108 \SpecialChar ~
8109 \SpecialChar ~
8110 mov\SpecialChar ~
8111 \SpecialChar ~
8112 @r0,#0x01
8113 \layout Standard
8114
8115 Please note, the first 128 byte of idata physically access the same RAM
8116  as the data memory.
8117  The original 8051 had 128 byte idata memory, nowadays most devices have
8118  256 byte idata memory.
8119  The stack
8120 \begin_inset LatexCommand \index{stack}
8121
8122 \end_inset 
8123
8124  is located in idata memory.
8125 \layout Subsubsection
8126
8127 pdata
8128 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8129
8130 \end_inset 
8131
8132
8133 \layout Standard
8134
8135 Paged xdata access is currently not as straightforward as using the other
8136  addressing modes of a 8051.
8137  The following example writes 0x01 to the address pointed to.
8138  Please note, pdata access physically accesses xdata memory.
8139  The high byte of the address is determined by port P2 
8140 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
8141
8142 \end_inset 
8143
8144 (or in case of some 8051 variants by a separate Special Function Register,
8145  see section 
8146 \begin_inset LatexCommand \ref{sub:MCS51-variants}
8147
8148 \end_inset 
8149
8150 ).
8151 \layout Verse
8152
8153
8154 \family typewriter 
8155 pdata unsigned char *test_pdata_ptr;
8156 \newline 
8157
8158 \newline 
8159 void main() 
8160 \newline 
8161
8162 \newline 
8163 \SpecialChar ~
8164 \SpecialChar ~
8165 \SpecialChar ~
8166 \SpecialChar ~
8167 test_pdata_ptr = (pdata *)0xfe; 
8168 \newline 
8169 \SpecialChar ~
8170 \SpecialChar ~
8171 \SpecialChar ~
8172 \SpecialChar ~
8173 *test_pdata_ptr = 1; 
8174 \newline 
8175
8176 \layout Standard
8177
8178 Generates the assembly code:
8179 \layout Verse
8180
8181
8182 \family typewriter 
8183 75*01 FE\SpecialChar ~
8184 \SpecialChar ~
8185 \SpecialChar ~
8186 mov\SpecialChar ~
8187  _test_pdata_ptr,#0xFE
8188 \newline 
8189 78 FE\SpecialChar ~
8190 \SpecialChar ~
8191 \SpecialChar ~
8192 \SpecialChar ~
8193 \SpecialChar ~
8194 \SpecialChar ~
8195 mov\SpecialChar ~
8196  r0,#0xFE 
8197 \newline 
8198 74 01\SpecialChar ~
8199 \SpecialChar ~
8200 \SpecialChar ~
8201 \SpecialChar ~
8202 \SpecialChar ~
8203 \SpecialChar ~
8204 mov\SpecialChar ~
8205  a,#0x01
8206 \newline 
8207 F2\SpecialChar ~
8208 \SpecialChar ~
8209 \SpecialChar ~
8210 \SpecialChar ~
8211 \SpecialChar ~
8212 \SpecialChar ~
8213 \SpecialChar ~
8214 \SpecialChar ~
8215 \SpecialChar ~
8216 movx @r0,a 
8217 \layout Standard
8218
8219 Be extremely carefull if you use pdata together with the -
8220 \begin_inset ERT
8221 status Collapsed
8222
8223 \layout Standard
8224
8225 \backslash 
8226 /
8227 \end_inset 
8228
8229 -xstack
8230 \begin_inset LatexCommand \index{-\/-xstack}
8231
8232 \end_inset 
8233
8234  option.
8235 \layout Subsubsection
8236
8237 code
8238 \begin_inset LatexCommand \index{code}
8239
8240 \end_inset 
8241
8242
8243 \layout Standard
8244
8245 'Variables' declared with this storage class will be placed in the code
8246  memory:
8247 \layout Verse
8248
8249
8250 \family typewriter 
8251 code unsigned char test_code;
8252 \layout Standard
8253
8254 Read access to this variable generates the assembly code:
8255 \layout Verse
8256
8257
8258 \family typewriter 
8259 90s00r6F\SpecialChar ~
8260 \SpecialChar ~
8261 \SpecialChar ~
8262 mov dptr,#_test_code
8263 \newline 
8264 E4\SpecialChar ~
8265 \SpecialChar ~
8266 \SpecialChar ~
8267 \SpecialChar ~
8268 \SpecialChar ~
8269 \SpecialChar ~
8270 \SpecialChar ~
8271 \SpecialChar ~
8272 \SpecialChar ~
8273 clr a
8274 \newline 
8275 93\SpecialChar ~
8276 \SpecialChar ~
8277 \SpecialChar ~
8278 \SpecialChar ~
8279 \SpecialChar ~
8280 \SpecialChar ~
8281 \SpecialChar ~
8282 \SpecialChar ~
8283 \SpecialChar ~
8284 movc a,@a+dptr 
8285 \layout Standard
8286
8287
8288 \family typewriter 
8289 char
8290 \family default 
8291  indexed arrays of characters in code memory can be accessed efficiently:
8292 \layout Verse
8293
8294
8295 \family typewriter 
8296 code char test_array[] = {'c','h','e','a','p'}; 
8297 \layout Standard
8298
8299 Read access to this array using an 8-bit unsigned index generates the assembly
8300  code:
8301 \layout Verse
8302
8303
8304 \family typewriter 
8305 E5*00\SpecialChar ~
8306 \SpecialChar ~
8307 \SpecialChar ~
8308 \SpecialChar ~
8309 \SpecialChar ~
8310 \SpecialChar ~
8311 mov a,_index 
8312 \layout Verse
8313
8314
8315 \family typewriter 
8316 90s00r41\SpecialChar ~
8317 \SpecialChar ~
8318 \SpecialChar ~
8319 mov dptr,#_test_array
8320 \layout Verse
8321
8322
8323 \family typewriter 
8324 93\SpecialChar ~
8325 \SpecialChar ~
8326 \SpecialChar ~
8327 \SpecialChar ~
8328 \SpecialChar ~
8329 \SpecialChar ~
8330 \SpecialChar ~
8331 \SpecialChar ~
8332 \SpecialChar ~
8333 movc a,@a+dptr 
8334 \layout Subsubsection
8335
8336 bit
8337 \begin_inset LatexCommand \index{bit}
8338
8339 \end_inset 
8340
8341
8342 \layout Standard
8343
8344 This is a data-type and a storage class specifier.
8345  When a variable is declared as a bit, it is allocated into the bit addressable
8346  memory of 8051, e.g.:
8347 \layout Verse
8348
8349
8350 \family typewriter 
8351 bit test_bit;
8352 \layout Standard
8353
8354 Writing 1 to this variable generates the assembly code:
8355 \layout Verse
8356
8357
8358 \family typewriter 
8359 D2*00\SpecialChar ~
8360 \SpecialChar ~
8361 \SpecialChar ~
8362 \SpecialChar ~
8363 \SpecialChar ~
8364 \SpecialChar ~
8365 \SpecialChar ~
8366 setb\SpecialChar ~
8367 _test_bit
8368 \layout Standard
8369
8370 The bit addressable memory consists of 128 bits which are located from 0x20
8371  to 0x2f in data memory.
8372  
8373 \newline 
8374 Apart from this 8051 specific storage class most architectures support ANSI-C
8375  bitfields
8376 \begin_inset LatexCommand \index{bitfields}
8377
8378 \end_inset 
8379
8380
8381 \begin_inset Foot
8382 collapsed false
8383
8384 \layout Standard
8385
8386 Not really meant as examples, but nevertheless showing what bitfields are
8387  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
8388 \end_inset 
8389
8390 .
8391  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
8392  signed modifier are implemented as unsigned.
8393 \layout Subsubsection
8394
8395 sfr
8396 \begin_inset LatexCommand \index{sfr}
8397
8398 \end_inset 
8399
8400  / sbit
8401 \begin_inset LatexCommand \index{sbit}
8402
8403 \end_inset 
8404
8405
8406 \layout Standard
8407
8408 Like the bit keyword, 
8409 \emph on 
8410 sfr / sbit 
8411 \emph default 
8412 signifies both a data-type and storage class, they are used to describe
8413  the 
8414 \emph on 
8415 s
8416 \emph default 
8417 pecial 
8418 \emph on 
8419 f
8420 \emph default 
8421 unction 
8422 \emph on 
8423 r
8424 \emph default 
8425 egisters and 
8426 \emph on 
8427 s
8428 \emph default 
8429 pecial 
8430 \emph on 
8431 bit
8432 \emph default 
8433  variables of a 8051, eg:
8434 \layout Verse
8435
8436
8437 \family typewriter 
8438 sfr at
8439 \begin_inset LatexCommand \index{at}
8440
8441 \end_inset 
8442
8443  0x80 P0;\SpecialChar ~
8444  /* special function register P0 at location 0x80 */
8445 \newline 
8446 sbit at 0xd7 CY; /* CY (Carry Flag
8447 \begin_inset LatexCommand \index{Flags}
8448
8449 \end_inset 
8450
8451
8452 \begin_inset LatexCommand \index{Carry flag}
8453
8454 \end_inset 
8455
8456 ) */
8457 \layout Standard
8458
8459 Special function registers which are located on an address dividable by
8460  8 are bit-addressable, an
8461 \emph on 
8462  sbit
8463 \emph default 
8464  addresses a specific bit within these sfr.
8465 \layout Subsubsection
8466
8467 Pointers
8468 \begin_inset LatexCommand \index{Pointer}
8469
8470 \end_inset 
8471
8472  to MCS51/DS390 specific memory spaces
8473 \layout Standard
8474
8475 SDCC allows (via language extensions) pointers to explicitly point to any
8476  of the memory spaces
8477 \begin_inset LatexCommand \index{Memory model}
8478
8479 \end_inset 
8480
8481  of the 8051.
8482  In addition to the explicit pointers, the compiler uses (by default) generic
8483  pointers which can be used to point to any of the memory spaces.
8484 \newline 
8485
8486 \newline 
8487 Pointer declaration examples:
8488 \layout Verse
8489
8490
8491 \family typewriter 
8492 /* pointer physically in internal ram pointing to object in external ram
8493  */ 
8494 \newline 
8495 xdata unsigned char * data p;
8496 \newline 
8497
8498 \newline 
8499 /* pointer physically in external ram pointing to object in internal ram
8500  */ 
8501 \newline 
8502 data unsigned char * xdata p;
8503 \newline 
8504
8505 \newline 
8506 /* pointer physically in code rom pointing to data in xdata space */ 
8507 \newline 
8508 xdata unsigned char * code p;
8509 \newline 
8510
8511 \newline 
8512 /* pointer physically in code space pointing to data in code space */ 
8513 \newline 
8514 code unsigned char * code p;
8515 \newline 
8516
8517 \newline 
8518 /* the following is a generic pointer physically located in xdata space
8519  */
8520 \newline 
8521 char * xdata p;
8522 \layout Standard
8523
8524 Well you get the idea.
8525  
8526 \newline 
8527
8528 \newline 
8529 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
8530 \emph on 
8531 generic
8532 \emph default 
8533  pointers.
8534  
8535 \size small 
8536
8537 \newline 
8538
8539 \newline 
8540
8541 \size default 
8542 The highest order byte of the 
8543 \emph on 
8544 generic
8545 \emph default 
8546  pointers contains the data space information.
8547  Assembler support routines are called whenever data is stored or retrieved
8548  using 
8549 \emph on 
8550 generic
8551 \emph default 
8552  pointers.
8553  These are useful for developing reusable library
8554 \begin_inset LatexCommand \index{Libraries}
8555
8556 \end_inset 
8557
8558  routines.
8559  Explicitly specifying the pointer type will generate the most efficient
8560  code.
8561 \layout Subsubsection
8562
8563 Notes on MCS51 memory
8564 \begin_inset LatexCommand \index{MCS51 memory}
8565
8566 \end_inset 
8567
8568  layout
8569 \layout Standard
8570
8571 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
8572  RAM memory which is structured as follows:
8573 \newline 
8574
8575 \newline 
8576 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
8577  
8578 \newline 
8579 - Bytes 20-2F - 16 bytes to hold 128 bit
8580 \begin_inset LatexCommand \index{bit}
8581
8582 \end_inset 
8583
8584  variables and, 
8585 \newline 
8586 - Bytes 30-7F - 80 bytes for general purpose use.
8587 \newline 
8588
8589 \layout Standard
8590
8591 Additionally some members of the MCS51 family may have up to 128 bytes of
8592  additional, indirectly addressable, internal RAM memory (
8593 \emph on 
8594 idata
8595 \emph default 
8596
8597 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
8598
8599 \end_inset 
8600
8601 ).
8602  Furthermore, some chips may have some built in external memory (
8603 \emph on 
8604 xdata
8605 \emph default 
8606
8607 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
8608
8609 \end_inset 
8610
8611 ) which should not be confused with the internal, directly addressable RAM
8612  memory (
8613 \emph on 
8614 data
8615 \emph default 
8616
8617 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
8618
8619 \end_inset 
8620
8621 ).
8622  Sometimes this built in 
8623 \emph on 
8624 xdata
8625 \emph default 
8626  memory has to be activated before using it (you can probably find this
8627  information on the datasheet of the microcontroller your are using, see
8628  also section 
8629 \begin_inset LatexCommand \ref{sub:Startup-Code}
8630
8631 \end_inset 
8632
8633 \SpecialChar ~
8634 Startup-Code).
8635 \layout Standard
8636
8637 Normally SDCC will only use the first bank
8638 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
8639
8640 \end_inset 
8641
8642  of registers (register bank 0), but it is possible to specify that other
8643  banks of registers should be used in interrupt
8644 \begin_inset LatexCommand \index{interrupt}
8645
8646 \end_inset 
8647
8648  routines.
8649  By default, the compiler will place the stack after the last byte of allocated
8650  memory for variables.
8651  For example, if the first 2 banks of registers are used, and only four
8652  bytes are used for 
8653 \emph on 
8654 data
8655 \emph default 
8656  variables, it will position the base of the internal stack at address 20
8657  (0x14).
8658  This implies that as the stack
8659 \begin_inset LatexCommand \index{stack}
8660
8661 \end_inset 
8662
8663  grows, it will use up the remaining register banks, and the 16 bytes used
8664  by the 128 bit variables, and 80 bytes for general purpose use.
8665  If any bit variables are used, the data variables will be placed after
8666  the byte holding the last bit variable.
8667  For example, if register banks 0 and 1 are used, and there are 9 bit variables
8668  (two bytes used), 
8669 \emph on 
8670 data
8671 \emph default 
8672  variables will be placed starting at address 0x22.
8673  You can also use -
8674 \begin_inset ERT
8675 status Collapsed
8676
8677 \layout Standard
8678
8679 \backslash 
8680 /
8681 \end_inset 
8682
8683 -data-loc
8684 \begin_inset LatexCommand \index{-\/-data-loc<Value>}
8685
8686 \end_inset 
8687
8688  to specify the start address of the 
8689 \emph on 
8690 data
8691 \emph default 
8692  and -
8693 \begin_inset ERT
8694 status Collapsed
8695
8696 \layout Standard
8697
8698 \backslash 
8699 /
8700 \end_inset 
8701
8702 -iram-size to specify the size of the total internal RAM (
8703 \emph on 
8704 data
8705 \emph default 
8706 +
8707 \emph on 
8708 idata
8709 \emph default 
8710 ).
8711  
8712 \layout Standard
8713
8714 By default the 8051 linker will place the stack after the last byte of data
8715  variables.
8716  Option -
8717 \begin_inset ERT
8718 status Collapsed
8719
8720 \layout Standard
8721
8722 \backslash 
8723 /
8724 \end_inset 
8725
8726 -stack-loc
8727 \begin_inset LatexCommand \index{-\/-stack-loc<Value>}
8728
8729 \end_inset 
8730
8731  allows you to specify the start of the stack, i.e.
8732  you could start it after any data in the general purpose area.
8733  If your microcontroller has additional indirectly addressable internal
8734  RAM (
8735 \emph on 
8736 idata
8737 \emph default 
8738 ) you can place the stack on it.
8739  You may also need to use -
8740 \begin_inset ERT
8741 status Collapsed
8742
8743 \layout Standard
8744
8745 \backslash 
8746 /
8747 \end_inset 
8748
8749 -xdata-loc
8750 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
8751
8752 \end_inset 
8753
8754  to set the start address of the external RAM (
8755 \emph on 
8756 xdata
8757 \emph default 
8758 ) and -
8759 \begin_inset ERT
8760 status Collapsed
8761
8762 \layout Standard
8763
8764 \backslash 
8765 /
8766 \end_inset 
8767
8768 -xram-size
8769 \begin_inset LatexCommand \index{-\/-data-loc}
8770
8771 \end_inset 
8772
8773  to specify its size.
8774  Same goes for the code memory, using -
8775 \begin_inset ERT
8776 status Collapsed
8777
8778 \layout Standard
8779
8780 \backslash 
8781 /
8782 \end_inset 
8783
8784 -code-loc
8785 \begin_inset LatexCommand \index{-\/-data-loc}
8786
8787 \end_inset 
8788
8789  and -
8790 \begin_inset ERT
8791 status Collapsed
8792
8793 \layout Standard
8794
8795 \backslash 
8796 /
8797 \end_inset 
8798
8799 -code-size
8800 \begin_inset LatexCommand \index{-\/-data-loc}
8801
8802 \end_inset 
8803
8804 .
8805  If in doubt, don't specify any options and see if the resulting memory
8806  layout is appropriate, then you can adjust it.
8807 \layout Standard
8808
8809 The linker generates two files with memory allocation information.
8810  The first, with extension .map
8811 \begin_inset LatexCommand \index{<file>.map}
8812
8813 \end_inset 
8814
8815  shows all the variables and segments.
8816  The second with extension .mem
8817 \begin_inset LatexCommand \index{<file>.mem}
8818
8819 \end_inset 
8820
8821  shows the final memory layout.
8822  The linker will complain either if memory segments overlap, there is not
8823  enough memory, or there is not enough space for stack.
8824  If you get any linking warnings and/or errors related to stack or segments
8825  allocation, take a look at either the .map or .mem files to find out what
8826  the problem is.
8827  The .mem file may even suggest a solution to the problem.
8828 \layout Subsection
8829
8830 Z80/Z180 Storage Class
8831 \begin_inset LatexCommand \index{Storage class}
8832
8833 \end_inset 
8834
8835  Language Extensions
8836 \layout Subsubsection
8837
8838 sfr
8839 \begin_inset LatexCommand \index{sfr}
8840
8841 \end_inset 
8842
8843  (in/out to 8-bit addresses)
8844 \layout Standard
8845
8846 The Z80
8847 \begin_inset LatexCommand \index{Z80}
8848
8849 \end_inset 
8850
8851  family has separate address spaces for memory and 
8852 \emph on 
8853 i
8854 \emph default 
8855 nput/
8856 \emph on 
8857 o
8858 \emph default 
8859 utput memory.
8860  I/O memory
8861 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
8862
8863 \end_inset 
8864
8865  is accessed with special instructions, e.g.:
8866 \layout Verse
8867
8868
8869 \family typewriter 
8870 sfr at 0x78 IoPort;\SpecialChar ~
8871 \SpecialChar ~
8872 /* define a var in I/O space at 78h called IoPort */
8873  
8874 \layout Standard
8875
8876 Writing 0x01 to this variable generates the assembly code:
8877 \layout Verse
8878
8879
8880 \family typewriter 
8881 3E 01\SpecialChar ~
8882 \SpecialChar ~
8883 \SpecialChar ~
8884 \SpecialChar ~
8885 \SpecialChar ~
8886 \SpecialChar ~
8887 ld a,#0x01
8888 \newline 
8889 D3 78\SpecialChar ~
8890 \SpecialChar ~
8891 \SpecialChar ~
8892 \SpecialChar ~
8893 \SpecialChar ~
8894 \SpecialChar ~
8895 out (_IoPort),a 
8896 \layout Subsubsection
8897
8898 banked sfr
8899 \begin_inset LatexCommand \index{sfr}
8900
8901 \end_inset 
8902
8903  (in/out to 16-bit addresses)
8904 \layout Standard
8905
8906 The keyword 
8907 \emph on 
8908 banked
8909 \emph default 
8910  is used to support 16 bit addresses in I/O memory e.g.:
8911 \layout Verse
8912
8913
8914 \family typewriter 
8915 sfr banked at
8916 \begin_inset LatexCommand \index{at}
8917
8918 \end_inset 
8919
8920  0x123 IoPort; 
8921 \layout Standard
8922
8923 Writing 0x01 to this variable generates the assembly code:
8924 \layout Verse
8925
8926
8927 \family typewriter 
8928 01 23 01\SpecialChar ~
8929 \SpecialChar ~
8930 \SpecialChar ~
8931 ld bc,#_IoPort
8932 \newline 
8933 3E 01\SpecialChar ~
8934 \SpecialChar ~
8935 \SpecialChar ~
8936 \SpecialChar ~
8937 \SpecialChar ~
8938 \SpecialChar ~
8939 ld a,#0x01 
8940 \newline 
8941 ED 79\SpecialChar ~
8942 \SpecialChar ~
8943 \SpecialChar ~
8944 \SpecialChar ~
8945 \SpecialChar ~
8946 \SpecialChar ~
8947 out (c),a 
8948 \layout Subsubsection
8949
8950 sfr
8951 \begin_inset LatexCommand \index{sfr}
8952
8953 \end_inset 
8954
8955  (in0/out0 to 8 bit addresses on Z180
8956 \begin_inset LatexCommand \index{Z180}
8957
8958 \end_inset 
8959
8960 /HD64180
8961 \begin_inset LatexCommand \index{HD64180}
8962
8963 \end_inset 
8964
8965 )
8966 \layout Standard
8967
8968 The compiler option -
8969 \begin_inset ERT
8970 status Collapsed
8971
8972 \layout Standard
8973
8974 \backslash 
8975 /
8976 \end_inset 
8977
8978 -portmode=180 (80) and a compiler #pragma\SpecialChar ~
8979 portmode
8980 \begin_inset LatexCommand \index{\#pragma portmode}
8981
8982 \end_inset 
8983
8984 =z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
8985 ns 
8986 \family typewriter 
8987 in0/out0
8988 \family default 
8989  instead of 
8990 \family typewriter 
8991 in/out
8992 \family default 
8993 .
8994  If you include the file z180.h this will be set automatically.
8995 \layout Subsection
8996
8997 HC08 Storage Class
8998 \begin_inset LatexCommand \index{Storage class}
8999
9000 \end_inset 
9001
9002  Language Extensions
9003 \layout Subsubsection
9004
9005 data
9006 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9007
9008 \end_inset 
9009
9010
9011 \layout Standard
9012
9013 The data storage class declares a variable that resides in the first 256
9014  bytes of memory (the direct page).
9015  The HC08 is most efficient at accessing variables (especially pointers)
9016  stored here.
9017 \layout Subsubsection
9018
9019 xdata
9020 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9021
9022 \end_inset 
9023
9024
9025 \layout Standard
9026
9027 The xdata storage class declares a variable that can reside anywhere in
9028  memory.
9029  This is the default if no storage class is specified.
9030  
9031 \layout Section
9032
9033 Absolute Addressing
9034 \begin_inset LatexCommand \index{Absolute addressing}
9035
9036 \end_inset 
9037
9038
9039 \layout Standard
9040
9041 Data items can be assigned an absolute address with the 
9042 \emph on 
9043 at
9044 \begin_inset LatexCommand \index{at}
9045
9046 \end_inset 
9047
9048  <address>
9049 \emph default 
9050  keyword, in addition to a storage class, e.g.:
9051 \layout Verse
9052
9053
9054 \family typewriter 
9055 xdata
9056 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9057
9058 \end_inset 
9059
9060  at
9061 \begin_inset LatexCommand \index{at}
9062
9063 \end_inset 
9064
9065  0x7ffe unsigned int chksum;
9066 \layout Standard
9067
9068 In the above example the variable chksum will located at 0x7ffe and 0x7fff
9069  of the external ram.
9070  The compiler does 
9071 \emph on 
9072 not
9073 \emph default 
9074  reserve any space for variables declared in this way (they are implemented
9075  with an equate in the assembler).
9076  Thus it is left to the programmer to make sure there are no overlaps with
9077  other variables that are declared without the absolute address.
9078  The assembler listing file (.lst
9079 \begin_inset LatexCommand \index{<file>.lst}
9080
9081 \end_inset 
9082
9083 ) and the linker output files (.rst
9084 \begin_inset LatexCommand \index{<file>.rst}
9085
9086 \end_inset 
9087
9088 ) and (.map
9089 \begin_inset LatexCommand \index{<file>.map}
9090
9091 \end_inset 
9092
9093 ) are good places to look for such overlaps.
9094  Variables with an absolute address are 
9095 \emph on 
9096 not
9097 \emph default 
9098  initialized
9099 \begin_inset LatexCommand \index{Variable initialization}
9100
9101 \end_inset 
9102
9103 .
9104 \layout Standard
9105
9106 In case of memory mapped I/O devices the keyword 
9107 \emph on 
9108 volatile
9109 \emph default 
9110  have to be used to tell the compiler that accesses might not be optimized
9111  away:
9112 \layout Verse
9113
9114
9115 \family typewriter 
9116 volatile
9117 \begin_inset LatexCommand \index{volatile}
9118
9119 \end_inset 
9120
9121  xdata
9122 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9123
9124 \end_inset 
9125
9126  at
9127 \begin_inset LatexCommand \index{at}
9128
9129 \end_inset 
9130
9131  0x8000 unsigned char PORTA_8255;
9132 \layout Standard
9133
9134 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
9135 r) array
9136 \family typewriter 
9137 \size footnotesize 
9138
9139 \begin_inset LatexCommand \index{Aligned array}
9140
9141 \end_inset 
9142
9143
9144 \family default 
9145 \size default 
9146  starts at a block (256 byte) boundary
9147 \begin_inset LatexCommand \index{block boundary}
9148
9149 \end_inset 
9150
9151  (section 
9152 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
9153
9154 \end_inset 
9155
9156  has an example).
9157 \newline 
9158 Absolute addresses can be specified for variables in all storage classes,
9159  e.g.:
9160 \layout Verse
9161
9162
9163 \family typewriter 
9164 bit
9165 \begin_inset LatexCommand \index{bit}
9166
9167 \end_inset 
9168
9169  at
9170 \begin_inset LatexCommand \index{at}
9171
9172 \end_inset 
9173
9174  0x02 bvar;
9175 \layout Standard
9176
9177 The above example will allocate the variable at offset 0x02 in the bit-addressab
9178 le space.
9179  There is no real advantage to assigning absolute addresses to variables
9180  in this manner, unless you want strict control over all the variables allocated.
9181  One possible use would be to write hardware portable code.
9182  For example, if you have a routine that uses one or more of the microcontroller
9183  I/O pins, and such pins are different for two different hardwares, you
9184  can declare the I/O pins in your routine using:
9185 \layout Verse
9186
9187
9188 \family typewriter 
9189 extern volatile bit SDI;
9190 \newline 
9191 extern volatile bit SCLK;
9192 \newline 
9193 extern volatile bit CPOL;
9194 \newline 
9195
9196 \newline 
9197 void DS1306_put(unsigned char value)
9198 \newline 
9199 {
9200 \newline 
9201 \SpecialChar ~
9202 \SpecialChar ~
9203 \SpecialChar ~
9204 \SpecialChar ~
9205 unsigned char mask=0x80;
9206 \newline 
9207
9208 \newline 
9209 \SpecialChar ~
9210 \SpecialChar ~
9211 \SpecialChar ~
9212 \SpecialChar ~
9213 while(mask)
9214 \newline 
9215 \SpecialChar ~
9216 \SpecialChar ~
9217 \SpecialChar ~
9218 \SpecialChar ~
9219 {
9220 \newline 
9221 \SpecialChar ~
9222 \SpecialChar ~
9223 \SpecialChar ~
9224 \SpecialChar ~
9225 \SpecialChar ~
9226 \SpecialChar ~
9227 \SpecialChar ~
9228 \SpecialChar ~
9229 SDI=(value & mask)?1:0;
9230 \newline 
9231 \SpecialChar ~
9232 \SpecialChar ~
9233 \SpecialChar ~
9234 \SpecialChar ~
9235 \SpecialChar ~
9236 \SpecialChar ~
9237 \SpecialChar ~
9238 \SpecialChar ~
9239 SCLK=!CPOL;
9240 \newline 
9241 \SpecialChar ~
9242 \SpecialChar ~
9243 \SpecialChar ~
9244 \SpecialChar ~
9245 \SpecialChar ~
9246 \SpecialChar ~
9247 \SpecialChar ~
9248 \SpecialChar ~
9249 SCLK=CPOL;
9250 \newline 
9251 \SpecialChar ~
9252 \SpecialChar ~
9253 \SpecialChar ~
9254 \SpecialChar ~
9255 \SpecialChar ~
9256 \SpecialChar ~
9257 \SpecialChar ~
9258 \SpecialChar ~
9259 mask/=2;
9260 \newline 
9261 \SpecialChar ~
9262 \SpecialChar ~
9263 \SpecialChar ~
9264 \SpecialChar ~
9265 }
9266 \newline 
9267 }
9268 \layout Standard
9269
9270 Then, someplace in the code for the first hardware you would use
9271 \layout Verse
9272
9273
9274 \family typewriter 
9275 bit at 0x80 SDI;\SpecialChar ~
9276 \SpecialChar ~
9277 \SpecialChar ~
9278 \SpecialChar ~
9279 /* I/O port 0, bit 0 */
9280 \newline 
9281 bit at 0x81 SCLK;\SpecialChar ~
9282 \SpecialChar ~
9283 \SpecialChar ~
9284 /* I/O port 0, bit 1 */
9285 \newline 
9286 bit CPOL;\SpecialChar ~
9287 \SpecialChar ~
9288 \SpecialChar ~
9289 \SpecialChar ~
9290 \SpecialChar ~
9291 \SpecialChar ~
9292 \SpecialChar ~
9293 \SpecialChar ~
9294 \SpecialChar ~
9295 \SpecialChar ~
9296 \SpecialChar ~
9297 /* This is a variable, let the linker allocate this one */
9298 \layout Standard
9299
9300 Similarly, for the second hardware you would use
9301 \layout Verse
9302
9303
9304 \family typewriter 
9305 bit at 0x83 SDI;\SpecialChar ~
9306 \SpecialChar ~
9307 \SpecialChar ~
9308 \SpecialChar ~
9309 /* I/O port 0, bit 3 */
9310 \newline 
9311 bit at 0x91 SCLK;\SpecialChar ~
9312 \SpecialChar ~
9313 \SpecialChar ~
9314 /* I/O port 1, bit 1 */
9315 \newline 
9316 bit
9317 \begin_inset LatexCommand \index{bit}
9318
9319 \end_inset 
9320
9321  CPOL;\SpecialChar ~
9322 \SpecialChar ~
9323 \SpecialChar ~
9324 \SpecialChar ~
9325 \SpecialChar ~
9326 \SpecialChar ~
9327 \SpecialChar ~
9328 \SpecialChar ~
9329 \SpecialChar ~
9330 \SpecialChar ~
9331 \SpecialChar ~
9332 /* This is a variable, let the linker allocate this one */
9333 \layout Standard
9334
9335 and you can use the same hardware dependent routine without changes, as
9336  for example in a library.
9337  This is somehow similar to sbit, but only one absolute address has to be
9338  specified in the whole project.
9339 \layout Section
9340
9341 Parameters
9342 \begin_inset LatexCommand \index{Parameters}
9343
9344 \end_inset 
9345
9346
9347 \begin_inset LatexCommand \index{function parameter}
9348
9349 \end_inset 
9350
9351  & Local Variables
9352 \begin_inset LatexCommand \index{local variables}
9353
9354 \end_inset 
9355
9356
9357 \layout Standard
9358
9359 Automatic (local) variables and parameters to functions can either be placed
9360  on the stack or in data-space.
9361  The default action of the compiler is to place these variables in the internal
9362  RAM (for small model) or external RAM (for large model).
9363  This in fact makes them similar to 
9364 \emph on 
9365 static
9366 \begin_inset LatexCommand \index{static}
9367
9368 \end_inset 
9369
9370
9371 \emph default 
9372  so by default functions are non-reentrant
9373 \begin_inset LatexCommand \index{reentrant}
9374
9375 \end_inset 
9376
9377 .
9378  
9379 \newline 
9380
9381 \newline 
9382 They can be placed on the stack
9383 \begin_inset LatexCommand \index{stack}
9384
9385 \end_inset 
9386
9387  either by using the
9388 \emph on 
9389  -
9390 \begin_inset ERT
9391 status Collapsed
9392
9393 \layout Standard
9394
9395 \backslash 
9396 /
9397 \end_inset 
9398
9399 -stack-auto
9400 \begin_inset LatexCommand \index{-\/-stack-auto}
9401
9402 \end_inset 
9403
9404
9405 \emph default 
9406  option or by using the 
9407 \emph on 
9408 reentrant
9409 \begin_inset LatexCommand \index{reentrant}
9410
9411 \end_inset 
9412
9413
9414 \emph default 
9415  keyword in the function declaration, e.g.:
9416 \layout Verse
9417
9418
9419 \family typewriter 
9420 unsigned char foo(char i) reentrant 
9421 \newline 
9422
9423 \newline 
9424 \SpecialChar ~
9425 \SpecialChar ~
9426 \SpecialChar ~
9427 \SpecialChar ~
9428 ...
9429  
9430 \newline 
9431 }
9432 \layout Standard
9433
9434 Since stack space on 8051 is limited, the 
9435 \emph on 
9436 reentrant 
9437 \emph default 
9438 keyword or the
9439 \emph on 
9440  -
9441 \begin_inset ERT
9442 status Collapsed
9443
9444 \layout Standard
9445
9446 \backslash 
9447 /
9448 \end_inset 
9449
9450 -stack-auto
9451 \emph default 
9452  option should be used sparingly.
9453  Note that the reentrant keyword just means that the parameters & local
9454  variables will be allocated to the stack, it 
9455 \emph on 
9456 does not
9457 \emph default 
9458  mean that the function is register bank
9459 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
9460
9461 \end_inset 
9462
9463  independent.
9464 \newline 
9465
9466 \newline 
9467 Local variables
9468 \begin_inset LatexCommand \index{local variables}
9469
9470 \end_inset 
9471
9472  can be assigned storage classes and absolute
9473 \begin_inset LatexCommand \index{Absolute addressing}
9474
9475 \end_inset 
9476
9477  addresses, e.g.: 
9478 \layout Verse
9479
9480
9481 \family typewriter 
9482 unsigned char foo() 
9483 \newline 
9484 {
9485 \newline 
9486 \SpecialChar ~
9487 \SpecialChar ~
9488 \SpecialChar ~
9489 \SpecialChar ~
9490 xdata unsigned char i;
9491 \newline 
9492 \SpecialChar ~
9493 \SpecialChar ~
9494 \SpecialChar ~
9495 \SpecialChar ~
9496 bit bvar;
9497 \newline 
9498 \SpecialChar ~
9499 \SpecialChar ~
9500 \SpecialChar ~
9501 \SpecialChar ~
9502 data at
9503 \begin_inset LatexCommand \index{at}
9504
9505 \end_inset 
9506
9507  0x31 unsigned char j;
9508 \newline 
9509 \SpecialChar ~
9510 \SpecialChar ~
9511 \SpecialChar ~
9512 \SpecialChar ~
9513 ...
9514  
9515 \newline 
9516 }
9517 \layout Standard
9518
9519 In the above example the variable 
9520 \emph on 
9521 i
9522 \emph default 
9523  will be allocated in the external ram, 
9524 \emph on 
9525 bvar
9526 \emph default 
9527  in bit addressable space and
9528 \emph on 
9529  j
9530 \emph default 
9531  in internal ram.
9532  When compiled with 
9533 \emph on 
9534 -
9535 \begin_inset ERT
9536 status Collapsed
9537
9538 \layout Standard
9539
9540 \backslash 
9541 /
9542 \end_inset 
9543
9544 -stack-auto
9545 \emph default 
9546  or when a function is declared as 
9547 \emph on 
9548 reentrant
9549 \emph default 
9550  this should only be done for static variables.
9551 \layout Standard
9552
9553 Parameters
9554 \begin_inset LatexCommand \index{function parameter}
9555
9556 \end_inset 
9557
9558  however are not allowed any storage class
9559 \begin_inset LatexCommand \index{Storage class}
9560
9561 \end_inset 
9562
9563 , (storage classes for parameters will be ignored), their allocation is
9564  governed by the memory model in use, and the reentrancy options.
9565 \layout Section
9566
9567 Overlaying
9568 \begin_inset LatexCommand \label{sub:Overlaying}
9569
9570 \end_inset 
9571
9572
9573 \begin_inset LatexCommand \index{Overlaying}
9574
9575 \end_inset 
9576
9577
9578 \layout Standard
9579
9580 For non-reentrant
9581 \begin_inset LatexCommand \index{reentrant}
9582
9583 \end_inset 
9584
9585  functions SDCC will try to reduce internal ram space usage by overlaying
9586  parameters and local variables of a function (if possible).
9587  Parameters and local variables
9588 \begin_inset LatexCommand \index{local variables}
9589
9590 \end_inset 
9591
9592  of a function will be allocated to an overlayable segment if the function
9593  has 
9594 \emph on 
9595 no other function calls and the function is non-reentrant and the memory
9596  model
9597 \begin_inset LatexCommand \index{Memory model}
9598
9599 \end_inset 
9600
9601  is small.
9602
9603 \emph default 
9604  If an explicit storage class
9605 \begin_inset LatexCommand \index{Storage class}
9606
9607 \end_inset 
9608
9609  is specified for a local variable, it will NOT be overlayed.
9610 \layout Standard
9611
9612 Note that the compiler (not the linkage editor) makes the decision for overlayin
9613 g the data items.
9614  Functions that are called from an interrupt service routine should be preceded
9615  by a #pragma\SpecialChar ~
9616 nooverlay
9617 \begin_inset LatexCommand \index{\#pragma nooverlay}
9618
9619 \end_inset 
9620
9621  if they are not reentrant.
9622 \layout Standard
9623
9624 Also note that the compiler does not do any processing of inline assembler
9625  code, so the compiler might incorrectly assign local variables and parameters
9626  of a function into the overlay segment if the inline assembler code calls
9627  other c-functions that might use the overlay.
9628  In that case the #pragma\SpecialChar ~
9629 nooverlay should be used.
9630 \layout Standard
9631
9632 Parameters and local variables of functions that contain 16 or 32 bit multiplica
9633 tion
9634 \begin_inset LatexCommand \index{Multiplication}
9635
9636 \end_inset 
9637
9638  or division
9639 \begin_inset LatexCommand \index{Division}
9640
9641 \end_inset 
9642
9643  will NOT be overlayed since these are implemented using external functions,
9644  e.g.:
9645 \layout Verse
9646
9647
9648 \family typewriter 
9649 #pragma save 
9650 \newline 
9651 #pragma nooverlay
9652 \begin_inset LatexCommand \index{\#pragma nooverlay}
9653
9654 \end_inset 
9655
9656  
9657 \newline 
9658 void set_error(unsigned char errcd) 
9659 \newline 
9660 {
9661 \newline 
9662 \SpecialChar ~
9663 \SpecialChar ~
9664 \SpecialChar ~
9665 \SpecialChar ~
9666 P3 = errcd;
9667 \newline 
9668
9669 \newline 
9670 #pragma restore 
9671 \newline 
9672
9673 \newline 
9674 void some_isr () interrupt
9675 \begin_inset LatexCommand \index{interrupt}
9676
9677 \end_inset 
9678
9679  2
9680 \newline 
9681 {
9682 \newline 
9683 \SpecialChar ~
9684 \SpecialChar ~
9685 \SpecialChar ~
9686 \SpecialChar ~
9687 ...
9688 \newline 
9689 \SpecialChar ~
9690 \SpecialChar ~
9691 \SpecialChar ~
9692 \SpecialChar ~
9693 set_error(10);
9694 \newline 
9695 \SpecialChar ~
9696 \SpecialChar ~
9697 \SpecialChar ~
9698 \SpecialChar ~
9699 ...
9700  
9701 \newline 
9702 }
9703 \layout Standard
9704
9705 In the above example the parameter 
9706 \emph on 
9707 errcd
9708 \emph default 
9709  for the function 
9710 \emph on 
9711 set_error
9712 \emph default 
9713  would be assigned to the overlayable segment if the #pragma\SpecialChar ~
9714 nooverlay was
9715  not present, this could cause unpredictable runtime behavior when called
9716  from an interrupt service routine.
9717  The #pragma\SpecialChar ~
9718 nooverlay ensures that the parameters and local variables for
9719  the function are NOT overlayed.
9720 \layout Section
9721
9722 Interrupt Service Routines
9723 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
9724
9725 \end_inset 
9726
9727
9728 \layout Subsection
9729
9730 General Information
9731 \layout Standard
9732
9733 SDCC allows 
9734 \emph on 
9735 i
9736 \emph default 
9737 nterrupt 
9738 \emph on 
9739 s
9740 \emph default 
9741 ervice 
9742 \emph on 
9743 r
9744 \emph default 
9745 outines to be coded in C, with some extended keywords.
9746 \layout Verse
9747
9748
9749 \family typewriter 
9750 void timer_isr (void) interrupt 1 using 1 
9751 \newline 
9752
9753 \newline 
9754 \SpecialChar ~
9755 \SpecialChar ~
9756 \SpecialChar ~
9757 \SpecialChar ~
9758 ...
9759  
9760 \newline 
9761 }
9762 \layout Standard
9763
9764 The optional number following the 
9765 \emph on 
9766 interrupt
9767 \begin_inset LatexCommand \index{interrupt}
9768
9769 \end_inset 
9770
9771
9772 \emph default 
9773  keyword is the interrupt number this routine will service.
9774  When present, the compiler will insert a call to this routine in the interrupt
9775  vector table for the interrupt number specified.
9776  If you have multiple source files in your project, interrupt service routines
9777  can be present in any of them, but a prototype of the isr MUST be present
9778  or included in the file that contains the function 
9779 \emph on 
9780 main
9781 \emph default 
9782 .
9783  The 
9784 \emph on 
9785 using
9786 \emph default 
9787  keyword can be used to tell the compiler to use the specified register
9788  bank (8051 specific) when generating code for this function.
9789  
9790 \newline 
9791
9792 \layout Standard
9793
9794 Interrupt service routines open the door for some very interesting bugs:
9795 \newline 
9796 If an interrupt service routine changes variables which are accessed by
9797  other functions these variables have to be declared 
9798 \emph on 
9799 volatile
9800 \emph default 
9801
9802 \begin_inset LatexCommand \index{volatile}
9803
9804 \end_inset 
9805
9806 .
9807  
9808 \layout Standard
9809
9810 If the access to these variables is not 
9811 \emph on 
9812 atomic
9813 \begin_inset LatexCommand \index{atomic access}
9814
9815 \end_inset 
9816
9817
9818 \emph default 
9819  (i.e.
9820  the processor needs more than one instruction for the access and could
9821  be interrupted while accessing the variable) the interrupt must be disabled
9822  during the access to avoid inconsistent data.
9823  Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
9824  and should be protected by disabling interrupts.
9825  You're not automatically on the safe side if you use 8 bit variables though.
9826  We need an example here: f.e.
9827  on the 8051 the harmless looking 
9828 \begin_inset Quotes srd
9829 \end_inset 
9830
9831
9832 \family typewriter 
9833 flags\SpecialChar ~
9834 |=\SpecialChar ~
9835 0x80;
9836 \family default 
9837
9838 \begin_inset Quotes sld
9839 \end_inset 
9840
9841  is not atomic if 
9842 \family typewriter 
9843 flags
9844 \family default 
9845  resides in xdata.
9846  Setting 
9847 \begin_inset Quotes srd
9848 \end_inset 
9849
9850
9851 \family typewriter 
9852 flags\SpecialChar ~
9853 |=\SpecialChar ~
9854 0x40;
9855 \family default 
9856
9857 \begin_inset Quotes sld
9858 \end_inset 
9859
9860  from within an interrupt routine might get lost if the interrupt occurs
9861  at the wrong time.
9862  
9863 \begin_inset Quotes sld
9864 \end_inset 
9865
9866
9867 \family typewriter 
9868 counter\SpecialChar ~
9869 +=\SpecialChar ~
9870 8;
9871 \family default 
9872
9873 \begin_inset Quotes srd
9874 \end_inset 
9875
9876  is not atomic on the 8051 even if 
9877 \family typewriter 
9878 counter
9879 \family default 
9880  is located in data memory.
9881  Bugs like these are hard to reproduce and can cause a lot of trouble.
9882  
9883 \layout Standard
9884
9885 The return address and the registers used in the interrupt service routine
9886  are saved on the stack
9887 \begin_inset LatexCommand \index{stack}
9888
9889 \end_inset 
9890
9891  so there must be sufficient stack space.
9892  If there isn't variables or registers (or even the return address itself)
9893  will be corrupted.
9894  This 
9895 \emph on 
9896 stack overflow
9897 \emph default 
9898
9899 \begin_inset LatexCommand \index{stack overflow}
9900
9901 \end_inset 
9902
9903  is most likely to happen if the interrupt occurs during the 
9904 \begin_inset Quotes sld
9905 \end_inset 
9906
9907 deepest
9908 \begin_inset Quotes srd
9909 \end_inset 
9910
9911  subroutine when the stack is already in use for f.e.
9912  many return addresses.
9913 \layout Standard
9914
9915 A special note here, int (16 bit) and long (32 bit) integer division
9916 \begin_inset LatexCommand \index{Division}
9917
9918 \end_inset 
9919
9920 , multiplication
9921 \begin_inset LatexCommand \index{Multiplication}
9922
9923 \end_inset 
9924
9925  & modulus
9926 \begin_inset LatexCommand \index{Modulus}
9927
9928 \end_inset 
9929
9930  and floating-point
9931 \begin_inset LatexCommand \index{Floating point support}
9932
9933 \end_inset 
9934
9935  operations are implemented using external support routines developed in
9936  ANSI-C.
9937  If an interrupt service routine needs to do any of these operations then
9938  the support routines (as mentioned in a following section) will have to
9939  be recompiled using the
9940 \emph on 
9941  -
9942 \begin_inset ERT
9943 status Collapsed
9944
9945 \layout Standard
9946
9947 \backslash 
9948 /
9949 \end_inset 
9950
9951 -stack-auto
9952 \begin_inset LatexCommand \index{-\/-stack-auto}
9953
9954 \end_inset 
9955
9956
9957 \emph default 
9958  option and the source file will need to be compiled using the 
9959 \emph on 
9960 -
9961 \begin_inset ERT
9962 status Collapsed
9963
9964 \layout Standard
9965
9966 \backslash 
9967 /
9968 \end_inset 
9969
9970 -int-long-reent
9971 \emph default 
9972
9973 \begin_inset LatexCommand \index{-\/-int-long-reent}
9974
9975 \end_inset 
9976
9977  compiler option.
9978 \layout Standard
9979
9980 Calling other functions from an interrupt service routine is not recommended,
9981  avoid it if possible.
9982  Note that when some function is called from an interrupt service routine
9983  it should be preceded by a #pragma\SpecialChar ~
9984 nooverlay
9985 \begin_inset LatexCommand \index{\#pragma nooverlay}
9986
9987 \end_inset 
9988
9989  if it is not reentrant.
9990  Furthermore nonreentrant functions should not be called from the main program
9991  while the interrupt service routine might be active.
9992  
9993 \newline 
9994
9995 \newline 
9996 Also see section 
9997 \begin_inset LatexCommand \ref{sub:Overlaying}
9998
9999 \end_inset 
10000
10001 \SpecialChar ~
10002 about Overlaying and section 
10003 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
10004
10005 \end_inset 
10006
10007 \SpecialChar ~
10008 about Functions using private register banks.
10009 \layout Subsection
10010
10011 MCS51/DS390 Interrupt Service Routines
10012 \layout Standard
10013
10014 Interrupt numbers and the corresponding address & descriptions for the Standard
10015  8051/8052 are listed below.
10016  SDCC will automatically adjust the interrupt vector table to the maximum
10017  interrupt number specified.
10018 \newline 
10019
10020 \layout Standard
10021 \align center 
10022
10023 \begin_inset  Tabular
10024 <lyxtabular version="3" rows="7" columns="3">
10025 <features>
10026 <column alignment="center" valignment="top" leftline="true" width="0in">
10027 <column alignment="center" valignment="top" leftline="true" width="0in">
10028 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0in">
10029 <row topline="true" bottomline="true">
10030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10031 \begin_inset Text
10032
10033 \layout Standard
10034
10035 Interrupt #
10036 \end_inset 
10037 </cell>
10038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10039 \begin_inset Text
10040
10041 \layout Standard
10042
10043 Description
10044 \end_inset 
10045 </cell>
10046 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10047 \begin_inset Text
10048
10049 \layout Standard
10050
10051 Vector Address
10052 \end_inset 
10053 </cell>
10054 </row>
10055 <row topline="true">
10056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10057 \begin_inset Text
10058
10059 \layout Standard
10060
10061 0
10062 \end_inset 
10063 </cell>
10064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10065 \begin_inset Text
10066
10067 \layout Standard
10068
10069 External 0
10070 \end_inset 
10071 </cell>
10072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10073 \begin_inset Text
10074
10075 \layout Standard
10076
10077 0x0003
10078 \end_inset 
10079 </cell>
10080 </row>
10081 <row topline="true">
10082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10083 \begin_inset Text
10084
10085 \layout Standard
10086
10087 1
10088 \end_inset 
10089 </cell>
10090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10091 \begin_inset Text
10092
10093 \layout Standard
10094
10095 Timer 0
10096 \end_inset 
10097 </cell>
10098 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10099 \begin_inset Text
10100
10101 \layout Standard
10102
10103 0x000B
10104 \end_inset 
10105 </cell>
10106 </row>
10107 <row topline="true">
10108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10109 \begin_inset Text
10110
10111 \layout Standard
10112
10113 2
10114 \end_inset 
10115 </cell>
10116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10117 \begin_inset Text
10118
10119 \layout Standard
10120
10121 External 1
10122 \end_inset 
10123 </cell>
10124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10125 \begin_inset Text
10126
10127 \layout Standard
10128
10129 0x0013
10130 \end_inset 
10131 </cell>
10132 </row>
10133 <row topline="true">
10134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10135 \begin_inset Text
10136
10137 \layout Standard
10138
10139 3
10140 \end_inset 
10141 </cell>
10142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10143 \begin_inset Text
10144
10145 \layout Standard
10146
10147 Timer 1
10148 \end_inset 
10149 </cell>
10150 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10151 \begin_inset Text
10152
10153 \layout Standard
10154
10155 0x001B
10156 \end_inset 
10157 </cell>
10158 </row>
10159 <row topline="true">
10160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10161 \begin_inset Text
10162
10163 \layout Standard
10164
10165 4
10166 \end_inset 
10167 </cell>
10168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10169 \begin_inset Text
10170
10171 \layout Standard
10172
10173 Serial
10174 \end_inset 
10175 </cell>
10176 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10177 \begin_inset Text
10178
10179 \layout Standard
10180
10181 0x0023
10182 \end_inset 
10183 </cell>
10184 </row>
10185 <row topline="true" bottomline="true">
10186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10187 \begin_inset Text
10188
10189 \layout Standard
10190
10191 5
10192 \end_inset 
10193 </cell>
10194 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10195 \begin_inset Text
10196
10197 \layout Standard
10198
10199 Timer 2 (8052)
10200 \end_inset 
10201 </cell>
10202 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10203 \begin_inset Text
10204
10205 \layout Standard
10206
10207 0x002B
10208 \end_inset 
10209 </cell>
10210 </row>
10211 </lyxtabular>
10212
10213 \end_inset 
10214
10215
10216 \newline 
10217
10218 \layout Standard
10219
10220 If the interrupt service routine is defined without 
10221 \emph on 
10222 using
10223 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10224
10225 \end_inset 
10226
10227
10228 \emph default 
10229  a register bank or with register bank 0 (
10230 \emph on 
10231 using
10232 \emph default 
10233  0), the compiler will save the registers used by itself on the stack upon
10234  entry and restore them at exit, however if such an interrupt service routine
10235  calls another function then the entire register bank will be saved on the
10236  stack.
10237  This scheme may be advantageous for small interrupt service routines which
10238  have low register usage.
10239 \layout Standard
10240
10241 If the interrupt service routine is defined to be using a specific register
10242  bank then only 
10243 \emph on 
10244 a, b, dptr
10245 \emph default 
10246  & psw are saved and restored, if such an interrupt service routine calls
10247  another function (using another register bank) then the entire register
10248  bank of the called function will be saved on the stack.
10249  This scheme is recommended for larger interrupt service routines.
10250 \layout Subsection
10251
10252 HC08 Interrupt Service Routines
10253 \layout Standard
10254
10255 Since the number of interrupts available is chip specific and the interrupt
10256  vector table always ends at the last byte of memory, the interrupt numbers
10257  corresponds to the interrupt vectors in reverse order of address.
10258  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
10259  2 will use the interrupt vector at 0xfffa, and so on.
10260  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
10261  this way; instead see section 
10262 \begin_inset LatexCommand \ref{sub:Startup-Code}
10263
10264 \end_inset 
10265
10266  for details on customizing startup.
10267 \layout Section
10268
10269 Enabling and Disabling Interrupts
10270 \layout Subsection
10271
10272 Critical Functions and Critical Statements
10273 \layout Standard
10274
10275 A special keyword may be associated with a block or a function declaring
10276  it as 
10277 \emph on 
10278 critical
10279 \emph default 
10280 .
10281  SDCC will generate code to disable all interrupts
10282 \begin_inset LatexCommand \index{interrupt}
10283
10284 \end_inset 
10285
10286  upon entry to a critical function and restore the interrupt enable to the
10287  previous state before returning.
10288  Nesting critical functions will need one additional byte on the stack
10289 \begin_inset LatexCommand \index{stack}
10290
10291 \end_inset 
10292
10293  for each call.
10294 \layout Verse
10295
10296
10297 \family typewriter 
10298 int foo () critical
10299 \begin_inset LatexCommand \index{critical}
10300
10301 \end_inset 
10302
10303  
10304 \newline 
10305
10306 \newline 
10307 \SpecialChar ~
10308 \SpecialChar ~
10309 \SpecialChar ~
10310 \SpecialChar ~
10311 ...
10312  
10313 \newline 
10314 \SpecialChar ~
10315 \SpecialChar ~
10316 \SpecialChar ~
10317 \SpecialChar ~
10318 ...
10319  
10320 \newline 
10321 }
10322 \layout Standard
10323
10324 The critical attribute maybe used with other attributes like 
10325 \emph on 
10326 reentrant.
10327 \emph default 
10328
10329 \newline 
10330 The keyword 
10331 \emph on 
10332 critical
10333 \emph default 
10334  may also be used to disable interrupts more locally:
10335 \layout Verse
10336
10337
10338 \family typewriter 
10339 critical{ i++; }
10340 \layout Standard
10341
10342 More than one statement could have been included in the block.
10343 \layout Subsection
10344
10345 Enabling and Disabling Interrupts directly
10346 \layout Standard
10347
10348 Interrupts
10349 \begin_inset LatexCommand \index{interrupt}
10350
10351 \end_inset 
10352
10353  can also be disabled and enabled directly (8051):
10354 \layout Verse
10355
10356
10357 \family typewriter 
10358 EA = 0;\SpecialChar ~
10359 \SpecialChar ~
10360 \SpecialChar ~
10361 \SpecialChar ~
10362 \SpecialChar ~
10363 \SpecialChar ~
10364 \SpecialChar ~
10365 \SpecialChar ~
10366 \SpecialChar ~
10367 \SpecialChar ~
10368 \SpecialChar ~
10369 \SpecialChar ~
10370 or:\SpecialChar ~
10371 \SpecialChar ~
10372 \SpecialChar ~
10373 \SpecialChar ~
10374 \SpecialChar ~
10375 \SpecialChar ~
10376 \SpecialChar ~
10377 \SpecialChar ~
10378 \SpecialChar ~
10379 \SpecialChar ~
10380 \SpecialChar ~
10381 EA_SAVE = EA;
10382 \layout Verse
10383
10384
10385 \family typewriter 
10386 ...\SpecialChar ~
10387 \SpecialChar ~
10388 \SpecialChar ~
10389 \SpecialChar ~
10390 \SpecialChar ~
10391 \SpecialChar ~
10392 \SpecialChar ~
10393 \SpecialChar ~
10394 \SpecialChar ~
10395 \SpecialChar ~
10396 \SpecialChar ~
10397 \SpecialChar ~
10398 \SpecialChar ~
10399 \SpecialChar ~
10400 \SpecialChar ~
10401 \SpecialChar ~
10402 \SpecialChar ~
10403 \SpecialChar ~
10404 \SpecialChar ~
10405 \SpecialChar ~
10406 \SpecialChar ~
10407 \SpecialChar ~
10408 \SpecialChar ~
10409 \SpecialChar ~
10410 \SpecialChar ~
10411 \SpecialChar ~
10412 \SpecialChar ~
10413 \SpecialChar ~
10414 \SpecialChar ~
10415 \SpecialChar ~
10416 EA = 0;
10417 \layout Verse
10418
10419
10420 \family typewriter 
10421 EA = 1;\SpecialChar ~
10422 \SpecialChar ~
10423 \SpecialChar ~
10424 \SpecialChar ~
10425 \SpecialChar ~
10426 \SpecialChar ~
10427 \SpecialChar ~
10428 \SpecialChar ~
10429 \SpecialChar ~
10430 \SpecialChar ~
10431 \SpecialChar ~
10432 \SpecialChar ~
10433 \SpecialChar ~
10434 \SpecialChar ~
10435 \SpecialChar ~
10436 \SpecialChar ~
10437 \SpecialChar ~
10438 \SpecialChar ~
10439 \SpecialChar ~
10440 \SpecialChar ~
10441 \SpecialChar ~
10442 \SpecialChar ~
10443 \SpecialChar ~
10444 \SpecialChar ~
10445 \SpecialChar ~
10446 \SpecialChar ~
10447 ...
10448 \layout Verse
10449
10450
10451 \family typewriter 
10452 \SpecialChar ~
10453 \SpecialChar ~
10454 \SpecialChar ~
10455 \SpecialChar ~
10456 \SpecialChar ~
10457 \SpecialChar ~
10458 \SpecialChar ~
10459 \SpecialChar ~
10460 \SpecialChar ~
10461 \SpecialChar ~
10462 \SpecialChar ~
10463 \SpecialChar ~
10464 \SpecialChar ~
10465 \SpecialChar ~
10466 \SpecialChar ~
10467 \SpecialChar ~
10468 \SpecialChar ~
10469 \SpecialChar ~
10470 \SpecialChar ~
10471 \SpecialChar ~
10472 \SpecialChar ~
10473 \SpecialChar ~
10474 \SpecialChar ~
10475 \SpecialChar ~
10476 \SpecialChar ~
10477 \SpecialChar ~
10478 \SpecialChar ~
10479 \SpecialChar ~
10480 \SpecialChar ~
10481 \SpecialChar ~
10482 \SpecialChar ~
10483 \SpecialChar ~
10484 \SpecialChar ~
10485 EA = EA_SAVE;
10486 \layout Standard
10487
10488 On other architectures which have seperate opcodes for enabling and disabling
10489  interrupts you might want to make use of defines with inline assembly
10490 \begin_inset LatexCommand \index{Assembler routines}
10491
10492 \end_inset 
10493
10494  (HC08):
10495 \layout Verse
10496
10497
10498 \family typewriter 
10499 #define CLI _asm
10500 \begin_inset LatexCommand \index{\_asm}
10501
10502 \end_inset 
10503
10504 \SpecialChar ~
10505 \SpecialChar ~
10506 cli\SpecialChar ~
10507 \SpecialChar ~
10508 _endasm
10509 \begin_inset LatexCommand \index{\_endasm}
10510
10511 \end_inset 
10512
10513
10514 \layout Verse
10515
10516
10517 \family typewriter 
10518 #define SEI _asm\SpecialChar ~
10519 \SpecialChar ~
10520 sei\SpecialChar ~
10521 \SpecialChar ~
10522 _endasm; 
10523 \layout Verse
10524
10525
10526 \family typewriter 
10527 ...
10528 \layout Standard
10529
10530 Note: it is sometimes sufficient to disable only a specific interrupt source
10531  like f.e.
10532  a timer or serial interrupt by manipulating an 
10533 \emph on 
10534 interrupt mask
10535 \begin_inset LatexCommand \index{interrupt mask}
10536
10537 \end_inset 
10538
10539
10540 \emph default 
10541  register.
10542  
10543 \layout Standard
10544
10545 Usually the time during which interrupts are disabled should be kept as
10546  short as possible.
10547  This minimizes both 
10548 \emph on 
10549 interrupt latency
10550 \emph default 
10551
10552 \begin_inset LatexCommand \index{interrupt latency}
10553
10554 \end_inset 
10555
10556  (the time between the occurrence of the interrupt and the execution of
10557  the first code in the interrupt routine) and 
10558 \emph on 
10559 interrupt jitter
10560 \emph default 
10561
10562 \begin_inset LatexCommand \index{interrupt jitter}
10563
10564 \end_inset 
10565
10566  (the difference between the shortest and the longest interrupt latency).
10567  These really are something different, f.e.
10568  a serial interrupt has to be served before its buffer overruns so it cares
10569  for the maximum interrupt latency, whereas it does not care about jitter.
10570  On a loudspeaker driven via a digital to analog converter which is fed
10571  by an interrupt a latency of a few milliseconds might be tolerable, whereas
10572  a much smaller jitter will be very audible.
10573 \layout Standard
10574
10575 You can reenable interrupts within an interrupt routine and on some architecture
10576 s you can make use of two (or more) levels of 
10577 \emph on 
10578 interrupt priorities
10579 \emph default 
10580
10581 \begin_inset LatexCommand \index{interrupt priority}
10582
10583 \end_inset 
10584
10585 .
10586  On some architectures which don't support interrupt priorities these can
10587  be implemented by manipulating the interrupt mask and reenabling interrupts
10588  within the interrupt routine.
10589  Check there is sufficient space on the stack
10590 \begin_inset LatexCommand \index{stack}
10591
10592 \end_inset 
10593
10594  and don't add complexity unless you have to.
10595  
10596 \layout Section
10597
10598 Functions using private register banks
10599 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
10600
10601 \end_inset 
10602
10603  (mcs51/ds390)
10604 \layout Standard
10605
10606 Some architectures have support for quickly changing register sets.
10607  SDCC supports this feature with the 
10608 \emph on 
10609 using
10610 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10611
10612 \end_inset 
10613
10614
10615 \emph default 
10616  attribute (which tells the compiler to use a register bank
10617 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10618
10619 \end_inset 
10620
10621  other than the default bank zero).
10622  It should only be applied to 
10623 \emph on 
10624 interrupt
10625 \begin_inset LatexCommand \index{interrupt}
10626
10627 \end_inset 
10628
10629
10630 \emph default 
10631  functions (see footnote below).
10632  This will in most circumstances make the generated ISR code more efficient
10633  since it will not have to save registers on the stack.
10634 \layout Standard
10635
10636 The 
10637 \emph on 
10638 using
10639 \emph default 
10640  attribute will have no effect on the generated code for a 
10641 \emph on 
10642 non-interrupt
10643 \emph default 
10644  function (but may occasionally be useful anyway
10645 \begin_inset Foot
10646 collapsed false
10647
10648 \layout Standard
10649
10650 possible exception: if a function is called ONLY from 'interrupt' functions
10651  using a particular bank, it can be declared with the same 'using' attribute
10652  as the calling 'interrupt' functions.
10653  For instance, if you have several ISRs using bank one, and all of them
10654  call memcpy(), it might make sense to create a specialized version of memcpy()
10655  'using 1', since this would prevent the ISR from having to save bank zero
10656  to the stack on entry and switch to bank zero before calling the function
10657 \end_inset 
10658
10659 ).
10660 \newline 
10661
10662 \emph on 
10663 (pending: I don't think this has been done yet)
10664 \layout Standard
10665
10666 An 
10667 \emph on 
10668 interrupt
10669 \emph default 
10670  function using a non-zero bank will assume that it can trash that register
10671  bank, and will not save it.
10672  Since high-priority interrupts
10673 \begin_inset LatexCommand \index{interrupt priority}
10674
10675 \end_inset 
10676
10677  can interrupt low-priority ones on the 8051 and friends, this means that
10678  if a high-priority ISR 
10679 \emph on 
10680 using
10681 \emph default 
10682  a particular bank occurs while processing a low-priority ISR 
10683 \emph on 
10684 using
10685 \emph default 
10686  the same bank, terrible and bad things can happen.
10687  To prevent this, no single register bank should be 
10688 \emph on 
10689 used
10690 \emph default 
10691  by both a high priority and a low priority ISR.
10692  This is probably most easily done by having all high priority ISRs use
10693  one bank and all low priority ISRs use another.
10694  If you have an ISR which can change priority at runtime, you're on your
10695  own: I suggest using the default bank zero and taking the small performance
10696  hit.
10697 \layout Standard
10698
10699 It is most efficient if your ISR calls no other functions.
10700  If your ISR must call other functions, it is most efficient if those functions
10701  use the same bank as the ISR (see note 1 below); the next best is if the
10702  called functions use bank zero.
10703  It is very inefficient to call a function using a different, non-zero bank
10704  from an ISR.
10705  
10706 \layout Section
10707
10708 Startup Code
10709 \begin_inset LatexCommand \label{sub:Startup-Code}
10710
10711 \end_inset 
10712
10713
10714 \begin_inset LatexCommand \index{Startup code}
10715
10716 \end_inset 
10717
10718
10719 \layout Subsection
10720
10721 MCS51/DS390 Startup Code
10722 \layout Standard
10723
10724 The compiler inserts a call to the C routine 
10725 \emph on 
10726 _sdcc_external_startup()
10727 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
10728
10729 \end_inset 
10730
10731
10732 \series bold 
10733 \emph default 
10734  
10735 \series default 
10736 at the start of the CODE area.
10737  This routine is in the runtime library
10738 \begin_inset LatexCommand \index{Runtime library}
10739
10740 \end_inset 
10741
10742 .
10743  By default this routine returns 0, if this routine returns a non-zero value,
10744  the static & global variable initialization will be skipped and the function
10745  main will be invoked.
10746  Otherwise static & global variables will be initialized before the function
10747  main is invoked.
10748  You could add a 
10749 \emph on 
10750 _sdcc_external_startup()
10751 \emph default 
10752  routine to your program to override the default if you need to setup hardware
10753  or perform some other critical operation prior to static & global variable
10754  initialization.
10755  On some mcs51 variants xdata has to be explicitly enabled before it can
10756  be accessed, this is the place to do it.
10757  The startup code clears the complete 256 byte of idata memory, this might
10758  cause problems for 128 byte devices (endless loop reported for Chipcon
10759  CC1010).
10760 \layout Standard
10761
10762 See also the compiler option 
10763 \emph on 
10764 -
10765 \begin_inset ERT
10766 status Collapsed
10767
10768 \layout Standard
10769
10770 \backslash 
10771 /
10772 \end_inset 
10773
10774 -no-xinit
10775 \emph default 
10776 -
10777 \emph on 
10778 opt
10779 \emph default 
10780
10781 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
10782
10783 \end_inset 
10784
10785  and section 
10786 \begin_inset LatexCommand \ref{sub:MCS51-variants}
10787
10788 \end_inset 
10789
10790 \SpecialChar ~
10791 about MCS51-variants.
10792 \layout Subsection
10793
10794 HC08 Startup Code
10795 \layout Standard
10796
10797 The HC08 startup code follows the same scheme as the MCS51 startup code.
10798 \layout Subsection
10799
10800 Z80 Startup Code
10801 \layout Standard
10802
10803 On the Z80 the startup code is inserted by linking with crt0.o which is generated
10804  from sdcc/device/lib/z80/crt0.s.
10805  If you need a different startup code you can use the compiler option 
10806 \emph on 
10807 -
10808 \series bold 
10809 \emph default 
10810
10811 \begin_inset ERT
10812 status Collapsed
10813
10814 \layout Standard
10815
10816 \backslash 
10817 /
10818 \end_inset 
10819
10820
10821 \series default 
10822 \emph on 
10823 -no-std-crt0
10824 \emph default 
10825
10826 \begin_inset LatexCommand \index{-\/-no-std-crt0}
10827
10828 \end_inset 
10829
10830  and provide your own crt0.o.
10831  
10832 \layout Section
10833
10834 Inline Assembler Code
10835 \begin_inset LatexCommand \index{Assembler routines}
10836
10837 \end_inset 
10838
10839
10840 \layout Subsection
10841
10842 A Step by Step Introduction
10843 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
10844
10845 \end_inset 
10846
10847
10848 \layout Standard
10849
10850 Starting from a small snippet of c-code this example shows for the MCS51
10851  how to use inline assembly, access variables, a function parameter and
10852  an array in xdata memory.
10853  The example uses an MCS51 here but is easily adapted for other architectures.
10854  This is a buffer routine which should be optimized:
10855 \layout Verse
10856
10857
10858 \family typewriter 
10859 \size footnotesize 
10860 unsigned char far
10861 \begin_inset LatexCommand \index{far (storage class)}
10862
10863 \end_inset 
10864
10865  at
10866 \begin_inset LatexCommand \index{at}
10867
10868 \end_inset 
10869
10870  0x7f00 buf[0x100];
10871 \begin_inset LatexCommand \index{Aligned array}
10872
10873 \end_inset 
10874
10875
10876 \newline 
10877 unsigned char head,tail;
10878 \newline 
10879
10880 \newline 
10881 void to_buffer( unsigned char c ) 
10882 \newline 
10883 {
10884 \newline 
10885 \SpecialChar ~
10886 \SpecialChar ~
10887 \SpecialChar ~
10888 \SpecialChar ~
10889 if( head != tail-1 ) 
10890 \newline 
10891 \SpecialChar ~
10892 \SpecialChar ~
10893 \SpecialChar ~
10894 \SpecialChar ~
10895 \SpecialChar ~
10896 \SpecialChar ~
10897 \SpecialChar ~
10898 \SpecialChar ~
10899 buf[ head++ ] = c;\SpecialChar ~
10900 \SpecialChar ~
10901 \SpecialChar ~
10902 \SpecialChar ~
10903 /* access to a 256 byte aligned array */
10904 \newline 
10905
10906 \layout Standard
10907
10908 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
10909  then a corresponding buffer.asm file is generated.
10910  We define a new function 
10911 \family typewriter 
10912 to_buffer_asm()
10913 \family default 
10914  in file buffer.c in which we cut and paste the generated code, removing
10915  unwanted comments and some ':'.
10916  Then add 
10917 \begin_inset Quotes sld
10918 \end_inset 
10919
10920 _asm
10921 \begin_inset Quotes srd
10922 \end_inset 
10923
10924  and 
10925 \begin_inset Quotes sld
10926 \end_inset 
10927
10928 _endasm;
10929 \begin_inset Quotes srd
10930 \end_inset 
10931
10932  to the beginning and the end of the function body:
10933 \layout Verse
10934
10935
10936 \family typewriter 
10937 \size footnotesize 
10938 /* With a cut and paste from the .asm file, we have something to start with.
10939 \newline 
10940 \SpecialChar ~
10941 \SpecialChar ~
10942 \SpecialChar ~
10943 The function is not yet OK! (registers aren't saved) */ 
10944 \newline 
10945 void to_buffer_asm( unsigned char c ) 
10946 \newline 
10947
10948 \newline 
10949 \SpecialChar ~
10950 \SpecialChar ~
10951 \SpecialChar ~
10952 \SpecialChar ~
10953 _asm
10954 \begin_inset LatexCommand \index{\_asm}
10955
10956 \end_inset 
10957
10958
10959 \newline 
10960 \SpecialChar ~
10961 \SpecialChar ~
10962 \SpecialChar ~
10963 \SpecialChar ~
10964 mov\SpecialChar ~
10965 \SpecialChar ~
10966 r2,dpl 
10967 \newline 
10968 ;buffer.c if( head != tail-1 ) 
10969 \newline 
10970 \SpecialChar ~
10971 \SpecialChar ~
10972 \SpecialChar ~
10973 \SpecialChar ~
10974 mov\SpecialChar ~
10975 \SpecialChar ~
10976 a,_tail 
10977 \newline 
10978 \SpecialChar ~
10979 \SpecialChar ~
10980 \SpecialChar ~
10981 \SpecialChar ~
10982 dec\SpecialChar ~
10983 \SpecialChar ~
10984
10985 \newline 
10986 \SpecialChar ~
10987 \SpecialChar ~
10988 \SpecialChar ~
10989 \SpecialChar ~
10990 mov\SpecialChar ~
10991 \SpecialChar ~
10992 r3,a 
10993 \newline 
10994 \SpecialChar ~
10995 \SpecialChar ~
10996 \SpecialChar ~
10997 \SpecialChar ~
10998 mov\SpecialChar ~
10999 \SpecialChar ~
11000 a,_head 
11001 \newline 
11002 \SpecialChar ~
11003 \SpecialChar ~
11004 \SpecialChar ~
11005 \SpecialChar ~
11006 cjne a,ar3,00106$ 
11007 \newline 
11008 \SpecialChar ~
11009 \SpecialChar ~
11010 \SpecialChar ~
11011 \SpecialChar ~
11012 ret
11013 \newline 
11014 00106$: 
11015 \newline 
11016 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
11017 \begin_inset LatexCommand \index{Aligned array}
11018
11019 \end_inset 
11020
11021
11022 \newline 
11023 \SpecialChar ~
11024 \SpecialChar ~
11025 \SpecialChar ~
11026 \SpecialChar ~
11027 mov\SpecialChar ~
11028 \SpecialChar ~
11029 r3,_head 
11030 \newline 
11031 \SpecialChar ~
11032 \SpecialChar ~
11033 \SpecialChar ~
11034 \SpecialChar ~
11035 inc\SpecialChar ~
11036 \SpecialChar ~
11037 _head 
11038 \newline 
11039 \SpecialChar ~
11040 \SpecialChar ~
11041 \SpecialChar ~
11042 \SpecialChar ~
11043 mov\SpecialChar ~
11044 \SpecialChar ~
11045 dpl,r3 
11046 \newline 
11047 \SpecialChar ~
11048 \SpecialChar ~
11049 \SpecialChar ~
11050 \SpecialChar ~
11051 mov\SpecialChar ~
11052 \SpecialChar ~
11053 dph,#(_buf >> 8) 
11054 \newline 
11055 \SpecialChar ~
11056 \SpecialChar ~
11057 \SpecialChar ~
11058 \SpecialChar ~
11059 mov\SpecialChar ~
11060 \SpecialChar ~
11061 a,r2 
11062 \newline 
11063 \SpecialChar ~
11064 \SpecialChar ~
11065 \SpecialChar ~
11066 \SpecialChar ~
11067 movx @dptr,a 
11068 \newline 
11069 00103$: 
11070 \newline 
11071 \SpecialChar ~
11072 \SpecialChar ~
11073 \SpecialChar ~
11074 \SpecialChar ~
11075 ret
11076 \newline 
11077 \SpecialChar ~
11078 \SpecialChar ~
11079 \SpecialChar ~
11080 \SpecialChar ~
11081 _endasm;
11082 \newline 
11083
11084 \layout Standard
11085
11086 The new file buffer.c should compile with only one warning about the unreferenced
11087  function argument 'c'.
11088  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
11089  (1) and finally have:
11090 \layout Verse
11091
11092
11093 \family typewriter 
11094 \size footnotesize 
11095 unsigned char far at 0x7f00 buf[0x100];
11096 \newline 
11097 unsigned char head,tail;
11098 \newline 
11099 #define USE_ASSEMBLY (1)
11100 \newline 
11101
11102 \newline 
11103 #if !USE_ASSEMBLY
11104 \newline 
11105
11106 \newline 
11107 void to_buffer( unsigned char c )
11108 \newline 
11109 {
11110 \newline 
11111 \SpecialChar ~
11112 \SpecialChar ~
11113 \SpecialChar ~
11114 \SpecialChar ~
11115 if( head != tail-1 )
11116 \newline 
11117 \SpecialChar ~
11118 \SpecialChar ~
11119 \SpecialChar ~
11120 \SpecialChar ~
11121 \SpecialChar ~
11122 \SpecialChar ~
11123 \SpecialChar ~
11124 \SpecialChar ~
11125 buf[ head++ ] = c;
11126 \newline 
11127 }
11128 \newline 
11129
11130 \newline 
11131 #else
11132 \newline 
11133
11134 \newline 
11135 void to_buffer( unsigned char c )
11136 \newline 
11137 {
11138 \newline 
11139 \SpecialChar ~
11140 \SpecialChar ~
11141 \SpecialChar ~
11142 \SpecialChar ~
11143 c; // to avoid warning: unreferenced function argument
11144 \newline 
11145 \SpecialChar ~
11146 \SpecialChar ~
11147 \SpecialChar ~
11148 \SpecialChar ~
11149 _asm
11150 \begin_inset LatexCommand \index{\_asm}
11151
11152 \end_inset 
11153
11154
11155 \newline 
11156 \SpecialChar ~
11157 \SpecialChar ~
11158 \SpecialChar ~
11159 \SpecialChar ~
11160 \SpecialChar ~
11161 \SpecialChar ~
11162 \SpecialChar ~
11163 \SpecialChar ~
11164 ; save used registers here.
11165  
11166 \newline 
11167 \SpecialChar ~
11168 \SpecialChar ~
11169 \SpecialChar ~
11170 \SpecialChar ~
11171 \SpecialChar ~
11172 \SpecialChar ~
11173 \SpecialChar ~
11174 \SpecialChar ~
11175 ; If we were still using r2,r3 we would have to push them here.
11176  
11177 \newline 
11178 ; if( head != tail-1 )
11179 \newline 
11180 \SpecialChar ~
11181 \SpecialChar ~
11182 \SpecialChar ~
11183 \SpecialChar ~
11184 \SpecialChar ~
11185 \SpecialChar ~
11186 \SpecialChar ~
11187 \SpecialChar ~
11188 mov\SpecialChar ~
11189  a,_tail
11190 \newline 
11191 \SpecialChar ~
11192 \SpecialChar ~
11193 \SpecialChar ~
11194 \SpecialChar ~
11195 \SpecialChar ~
11196 \SpecialChar ~
11197 \SpecialChar ~
11198 \SpecialChar ~
11199 dec\SpecialChar ~
11200  a
11201 \newline 
11202 \SpecialChar ~
11203 \SpecialChar ~
11204 \SpecialChar ~
11205 \SpecialChar ~
11206 \SpecialChar ~
11207 \SpecialChar ~
11208 \SpecialChar ~
11209 \SpecialChar ~
11210 xrl\SpecialChar ~
11211  a,_head
11212 \newline 
11213 \SpecialChar ~
11214 \SpecialChar ~
11215 \SpecialChar ~
11216 \SpecialChar ~
11217 \SpecialChar ~
11218 \SpecialChar ~
11219 \SpecialChar ~
11220 \SpecialChar ~
11221 ; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
11222 \newline 
11223 \SpecialChar ~
11224 \SpecialChar ~
11225 \SpecialChar ~
11226 \SpecialChar ~
11227 \SpecialChar ~
11228 \SpecialChar ~
11229 \SpecialChar ~
11230 \SpecialChar ~
11231 jz\SpecialChar ~
11232 \SpecialChar ~
11233  t_b_end$
11234 \newline 
11235 \SpecialChar ~
11236 \SpecialChar ~
11237 \SpecialChar ~
11238 \SpecialChar ~
11239 \SpecialChar ~
11240 \SpecialChar ~
11241 \SpecialChar ~
11242 \SpecialChar ~
11243 ;
11244 \newline 
11245 ; buf[ head++ ] = c;
11246 \newline 
11247 \SpecialChar ~
11248 \SpecialChar ~
11249 \SpecialChar ~
11250 \SpecialChar ~
11251 \SpecialChar ~
11252 \SpecialChar ~
11253 \SpecialChar ~
11254 \SpecialChar ~
11255 mov\SpecialChar ~
11256  a,dpl \SpecialChar ~
11257 \SpecialChar ~
11258 \SpecialChar ~
11259 \SpecialChar ~
11260 \SpecialChar ~
11261 \SpecialChar ~
11262 \SpecialChar ~
11263 ; dpl holds lower byte of function argument
11264 \newline 
11265 \SpecialChar ~
11266 \SpecialChar ~
11267 \SpecialChar ~
11268 \SpecialChar ~
11269 \SpecialChar ~
11270 \SpecialChar ~
11271 \SpecialChar ~
11272 \SpecialChar ~
11273 mov\SpecialChar ~
11274  dpl,_head \SpecialChar ~
11275 \SpecialChar ~
11276 \SpecialChar ~
11277 ; buf is 0x100 byte aligned so head can be used directly
11278 \newline 
11279 \SpecialChar ~
11280 \SpecialChar ~
11281 \SpecialChar ~
11282 \SpecialChar ~
11283 \SpecialChar ~
11284 \SpecialChar ~
11285 \SpecialChar ~
11286 \SpecialChar ~
11287 mov\SpecialChar ~
11288  dph,#(_buf>>8)
11289 \newline 
11290 \SpecialChar ~
11291 \SpecialChar ~
11292 \SpecialChar ~
11293 \SpecialChar ~
11294 \SpecialChar ~
11295 \SpecialChar ~
11296 \SpecialChar ~
11297 \SpecialChar ~
11298 movx @dptr,a
11299 \newline 
11300 \SpecialChar ~
11301 \SpecialChar ~
11302 \SpecialChar ~
11303 \SpecialChar ~
11304 \SpecialChar ~
11305 \SpecialChar ~
11306 \SpecialChar ~
11307 \SpecialChar ~
11308 inc \SpecialChar ~
11309 _head
11310 \newline 
11311 \SpecialChar ~
11312 \SpecialChar ~
11313 \SpecialChar ~
11314 \SpecialChar ~
11315 \SpecialChar ~
11316 \SpecialChar ~
11317 \SpecialChar ~
11318 \SpecialChar ~
11319 ; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)
11320 \newline 
11321 t_b_end$:
11322 \newline 
11323 \SpecialChar ~
11324 \SpecialChar ~
11325 \SpecialChar ~
11326 \SpecialChar ~
11327 \SpecialChar ~
11328 \SpecialChar ~
11329 \SpecialChar ~
11330 \SpecialChar ~
11331 ; restore used registers here 
11332 \newline 
11333 \SpecialChar ~
11334 \SpecialChar ~
11335 \SpecialChar ~
11336 \SpecialChar ~
11337 _endasm;
11338 \newline 
11339 }
11340 \newline 
11341 #endif
11342 \layout Standard
11343
11344 The inline assembler code can contain any valid code understood by the assembler
11345 , this includes any assembler directives and comment lines
11346 \begin_inset Foot
11347 collapsed false
11348
11349 \layout Standard
11350
11351 The assembler does not like some characters like ':' or ''' in comments.
11352  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
11353 \end_inset 
11354
11355 .
11356  The compiler does not do any validation of the code within the 
11357 \family typewriter 
11358 _asm
11359 \begin_inset LatexCommand \index{\_asm}
11360
11361 \end_inset 
11362
11363  ...
11364  _endasm;
11365 \family default 
11366  keyword pair.
11367  Specifically it will not know which registers are used and thus register
11368  pushing/popping
11369 \begin_inset LatexCommand \index{push/pop}
11370
11371 \end_inset 
11372
11373  has to be done manually.
11374  
11375 \layout Standard
11376
11377 It is recommended that each assembly instruction (including labels) be placed
11378  in a separate line (as the example shows).
11379  When the -
11380 \begin_inset ERT
11381 status Collapsed
11382
11383 \layout Standard
11384
11385 \backslash 
11386 /
11387 \end_inset 
11388
11389 -
11390 \emph on 
11391 peep-asm
11392 \begin_inset LatexCommand \index{-\/-peep-asm}
11393
11394 \end_inset 
11395
11396
11397 \emph default 
11398  command line option is used, the inline assembler code will be passed through
11399  the peephole optimizer
11400 \begin_inset LatexCommand \index{Peephole optimizer}
11401
11402 \end_inset 
11403
11404 .
11405  There are only a few (if any) cases where this option makes sense, it might
11406  cause some unexpected changes in the inline assembler code.
11407  Please go through the peephole optimizer rules defined in file 
11408 \emph on 
11409 SDCCpeeph.def
11410 \emph default 
11411  before using this option.
11412 \layout Subsection
11413
11414 Naked Functions
11415 \begin_inset LatexCommand \label{sub:Naked-Functions}
11416
11417 \end_inset 
11418
11419
11420 \begin_inset LatexCommand \index{Naked functions}
11421
11422 \end_inset 
11423
11424
11425 \layout Standard
11426
11427 A special keyword may be associated with a function declaring it as 
11428 \emph on 
11429 _naked
11430 \begin_inset LatexCommand \index{\_naked}
11431
11432 \end_inset 
11433
11434 .
11435  
11436 \emph default 
11437 The 
11438 \emph on 
11439 _naked
11440 \emph default 
11441  function modifier attribute prevents the compiler from generating prologue
11442 \begin_inset LatexCommand \index{function prologue}
11443
11444 \end_inset 
11445
11446  and epilogue
11447 \begin_inset LatexCommand \index{function epilogue}
11448
11449 \end_inset 
11450
11451  code for that function.
11452  This means that the user is entirely responsible for such things as saving
11453  any registers that may need to be preserved, selecting the proper register
11454  bank, generating the 
11455 \emph on 
11456 return
11457 \emph default 
11458  instruction at the end, etc.
11459  Practically, this means that the contents of the function must be written
11460  in inline assembler.
11461  This is particularly useful for interrupt functions, which can have a large
11462  (and often unnecessary) prologue/epilogue.
11463  For example, compare the code generated by these two functions:
11464 \layout Verse
11465
11466
11467 \family typewriter 
11468 volatile
11469 \begin_inset LatexCommand \index{volatile}
11470
11471 \end_inset 
11472
11473  data unsigned char counter;
11474 \newline 
11475
11476 \newline 
11477 void simpleInterrupt(void) interrupt
11478 \begin_inset LatexCommand \index{interrupt}
11479
11480 \end_inset 
11481
11482  1
11483 \newline 
11484 {
11485 \newline 
11486 \SpecialChar ~
11487 \SpecialChar ~
11488 \SpecialChar ~
11489 \SpecialChar ~
11490 counter++;
11491 \newline 
11492 }
11493 \newline 
11494
11495 \newline 
11496 void nakedInterrupt(void) interrupt 2 _naked
11497 \newline 
11498 {
11499 \newline 
11500 \SpecialChar ~
11501 \SpecialChar ~
11502 \SpecialChar ~
11503 \SpecialChar ~
11504 _asm
11505 \begin_inset LatexCommand \index{\_asm}
11506
11507 \end_inset 
11508
11509
11510 \newline 
11511 \SpecialChar ~
11512 \SpecialChar ~
11513 \SpecialChar ~
11514 \SpecialChar ~
11515 \SpecialChar ~
11516 \SpecialChar ~
11517 inc\SpecialChar ~
11518 \SpecialChar ~
11519 \SpecialChar ~
11520 \SpecialChar ~
11521 \SpecialChar ~
11522 _counter ; does not change flags, no need to save psw
11523 \newline 
11524 \SpecialChar ~
11525 \SpecialChar ~
11526 \SpecialChar ~
11527 \SpecialChar ~
11528 \SpecialChar ~
11529 \SpecialChar ~
11530 reti\SpecialChar ~
11531 \SpecialChar ~
11532 \SpecialChar ~
11533 \SpecialChar ~
11534 ; MUST explicitly include ret or reti in _naked function.
11535 \newline 
11536 \SpecialChar ~
11537 \SpecialChar ~
11538 \SpecialChar ~
11539 \SpecialChar ~
11540 _endasm
11541 \begin_inset LatexCommand \index{\_endasm}
11542
11543 \end_inset 
11544
11545 ;
11546 \newline 
11547 }
11548 \layout Standard
11549
11550 For an 8051 target, the generated simpleInterrupt looks like:
11551 \layout Verse
11552
11553
11554 \family typewriter 
11555 _simpleInterrupt:
11556 \newline 
11557 \SpecialChar ~
11558 \SpecialChar ~
11559 \SpecialChar ~
11560 \SpecialChar ~
11561 push\SpecialChar ~
11562 \SpecialChar ~
11563 \SpecialChar ~
11564 \SpecialChar ~
11565 acc
11566 \newline 
11567 \SpecialChar ~
11568 \SpecialChar ~
11569 \SpecialChar ~
11570 \SpecialChar ~
11571 push\SpecialChar ~
11572 \SpecialChar ~
11573 \SpecialChar ~
11574 \SpecialChar ~
11575 b
11576 \newline 
11577 \SpecialChar ~
11578 \SpecialChar ~
11579 \SpecialChar ~
11580 \SpecialChar ~
11581 push\SpecialChar ~
11582 \SpecialChar ~
11583 \SpecialChar ~
11584 \SpecialChar ~
11585 dpl
11586 \newline 
11587 \SpecialChar ~
11588 \SpecialChar ~
11589 \SpecialChar ~
11590 \SpecialChar ~
11591 push\SpecialChar ~
11592 \SpecialChar ~
11593 \SpecialChar ~
11594 \SpecialChar ~
11595 dph
11596 \newline 
11597 \SpecialChar ~
11598 \SpecialChar ~
11599 \SpecialChar ~
11600 \SpecialChar ~
11601 push\SpecialChar ~
11602 \SpecialChar ~
11603 \SpecialChar ~
11604 \SpecialChar ~
11605 psw
11606 \newline 
11607 \SpecialChar ~
11608 \SpecialChar ~
11609 \SpecialChar ~
11610 \SpecialChar ~
11611 mov\SpecialChar ~
11612 \SpecialChar ~
11613 \SpecialChar ~
11614 \SpecialChar ~
11615 \SpecialChar ~
11616 psw,#0x00
11617 \newline 
11618 \SpecialChar ~
11619 \SpecialChar ~
11620 \SpecialChar ~
11621 \SpecialChar ~
11622 inc\SpecialChar ~
11623 \SpecialChar ~
11624 \SpecialChar ~
11625 \SpecialChar ~
11626 \SpecialChar ~
11627 _counter
11628 \newline 
11629 \SpecialChar ~
11630 \SpecialChar ~
11631 \SpecialChar ~
11632 \SpecialChar ~
11633 pop\SpecialChar ~
11634 \SpecialChar ~
11635 \SpecialChar ~
11636 \SpecialChar ~
11637 \SpecialChar ~
11638 psw
11639 \newline 
11640 \SpecialChar ~
11641 \SpecialChar ~
11642 \SpecialChar ~
11643 \SpecialChar ~
11644 pop\SpecialChar ~
11645 \SpecialChar ~
11646 \SpecialChar ~
11647 \SpecialChar ~
11648 \SpecialChar ~
11649 dph
11650 \newline 
11651 \SpecialChar ~
11652 \SpecialChar ~
11653 \SpecialChar ~
11654 \SpecialChar ~
11655 pop\SpecialChar ~
11656 \SpecialChar ~
11657 \SpecialChar ~
11658 \SpecialChar ~
11659 \SpecialChar ~
11660 dpl
11661 \newline 
11662 \SpecialChar ~
11663 \SpecialChar ~
11664 \SpecialChar ~
11665 \SpecialChar ~
11666 pop\SpecialChar ~
11667 \SpecialChar ~
11668 \SpecialChar ~
11669 \SpecialChar ~
11670 \SpecialChar ~
11671 b
11672 \newline 
11673 \SpecialChar ~
11674 \SpecialChar ~
11675 \SpecialChar ~
11676 \SpecialChar ~
11677 pop\SpecialChar ~
11678 \SpecialChar ~
11679 \SpecialChar ~
11680 \SpecialChar ~
11681 \SpecialChar ~
11682 acc
11683 \newline 
11684 \SpecialChar ~
11685 \SpecialChar ~
11686 \SpecialChar ~
11687 \SpecialChar ~
11688 reti
11689 \layout Standard
11690
11691 whereas nakedInterrupt looks like:
11692 \layout Verse
11693
11694
11695 \family typewriter 
11696 _nakedInterrupt:
11697 \newline 
11698 \SpecialChar ~
11699 \SpecialChar ~
11700 \SpecialChar ~
11701 \SpecialChar ~
11702 inc\SpecialChar ~
11703 \SpecialChar ~
11704 \SpecialChar ~
11705 \SpecialChar ~
11706 _counter ; does not change flags, no need to save psw
11707 \newline 
11708 \SpecialChar ~
11709 \SpecialChar ~
11710 \SpecialChar ~
11711 \SpecialChar ~
11712 reti\SpecialChar ~
11713 \SpecialChar ~
11714 \SpecialChar ~
11715 \SpecialChar ~
11716 \SpecialChar ~
11717 \SpecialChar ~
11718 \SpecialChar ~
11719 \SpecialChar ~
11720 \SpecialChar ~
11721 \SpecialChar ~
11722 \SpecialChar ~
11723 \SpecialChar ~
11724 ; MUST explicitly include ret or reti in _naked function
11725 \layout Standard
11726
11727 The related directive #pragma exclude
11728 \begin_inset LatexCommand \index{\#pragma exclude}
11729
11730 \end_inset 
11731
11732  allows a more fine grained control over pushing & popping
11733 \begin_inset LatexCommand \index{push/pop}
11734
11735 \end_inset 
11736
11737  the registers.
11738 \layout Standard
11739
11740 While there is nothing preventing you from writing C code inside a 
11741 \family typewriter 
11742 _naked
11743 \family default 
11744  function, there are many ways to shoot yourself in the foot doing this,
11745  and it is recommended that you stick to inline assembler.
11746 \layout Subsection
11747
11748 Use of Labels within Inline Assembler
11749 \layout Standard
11750
11751 SDCC allows the use of in-line assembler with a few restrictions regarding
11752  labels.
11753  In older versions of the compiler all labels defined within inline assembler
11754  code 
11755 \emph on 
11756 had to be
11757 \emph default 
11758  of the form 
11759 \emph on 
11760 nnnnn$
11761 \emph default 
11762  where nnnn is a number less than 100 (which implies a limit of utmost 100
11763  inline assembler labels 
11764 \emph on 
11765 per function
11766 \emph default 
11767 \noun on 
11768 )
11769 \noun default 
11770 .
11771  
11772 \layout Verse
11773
11774
11775 \family typewriter 
11776 _asm
11777 \begin_inset LatexCommand \index{\_asm}
11778
11779 \end_inset 
11780
11781  
11782 \newline 
11783 \SpecialChar ~
11784 \SpecialChar ~
11785 \SpecialChar ~
11786 \SpecialChar ~
11787 mov\SpecialChar ~
11788 \SpecialChar ~
11789 \SpecialChar ~
11790 \SpecialChar ~
11791 \SpecialChar ~
11792 b,#10 
11793 \newline 
11794 00001$: 
11795 \newline 
11796 \SpecialChar ~
11797 \SpecialChar ~
11798 \SpecialChar ~
11799 \SpecialChar ~
11800 djnz\SpecialChar ~
11801 \SpecialChar ~
11802 \SpecialChar ~
11803 \SpecialChar ~
11804 b,00001$ 
11805 \newline 
11806 _endasm
11807 \begin_inset LatexCommand \index{\_endasm}
11808
11809 \end_inset 
11810
11811  ;
11812 \layout Standard
11813
11814 Inline assembler code cannot reference any C-Labels, however it can reference
11815  labels
11816 \begin_inset LatexCommand \index{Labels}
11817
11818 \end_inset 
11819
11820  defined by the inline assembler, e.g.:
11821 \layout Verse
11822
11823
11824 \family typewriter 
11825 foo() { 
11826 \newline 
11827 \SpecialChar ~
11828 \SpecialChar ~
11829 \SpecialChar ~
11830 \SpecialChar ~
11831 /* some c code */ 
11832 \newline 
11833 \SpecialChar ~
11834 \SpecialChar ~
11835 \SpecialChar ~
11836 \SpecialChar ~
11837 _asm 
11838 \newline 
11839 \SpecialChar ~
11840 \SpecialChar ~
11841 \SpecialChar ~
11842 \SpecialChar ~
11843 \SpecialChar ~
11844 \SpecialChar ~
11845 ; some assembler code 
11846 \newline 
11847 \SpecialChar ~
11848 \SpecialChar ~
11849 \SpecialChar ~
11850 \SpecialChar ~
11851 \SpecialChar ~
11852 \SpecialChar ~
11853 ljmp $0003 
11854 \newline 
11855 \SpecialChar ~
11856 \SpecialChar ~
11857 \SpecialChar ~
11858 \SpecialChar ~
11859 _endasm; 
11860 \newline 
11861 \SpecialChar ~
11862 \SpecialChar ~
11863 \SpecialChar ~
11864 \SpecialChar ~
11865 /* some more c code */ 
11866 \newline 
11867 clabel:\SpecialChar ~
11868 \SpecialChar ~
11869 /* inline assembler cannot reference this label */ 
11870 \newline 
11871 \SpecialChar ~
11872 \SpecialChar ~
11873 \SpecialChar ~
11874 \SpecialChar ~
11875 _asm
11876 \newline 
11877 \SpecialChar ~
11878 \SpecialChar ~
11879 \SpecialChar ~
11880 \SpecialChar ~
11881 $0003: ;label (can be referenced by inline assembler only) 
11882 \newline 
11883 \SpecialChar ~
11884 \SpecialChar ~
11885 \SpecialChar ~
11886 \SpecialChar ~
11887 _endasm ; 
11888 \newline 
11889 \SpecialChar ~
11890 \SpecialChar ~
11891 \SpecialChar ~
11892 \SpecialChar ~
11893 /* some more c code */
11894 \newline 
11895 }
11896 \layout Standard
11897
11898 In other words inline assembly code can access labels defined in inline
11899  assembly within the scope of the function.
11900  The same goes the other way, i.e.
11901  labels defines in inline assembly can not be accessed by C statements.
11902 \layout Section
11903
11904 Interfacing with Assembler Code
11905 \begin_inset LatexCommand \index{Assembler routines}
11906
11907 \end_inset 
11908
11909
11910 \layout Subsection
11911
11912 Global Registers used for Parameter Passing
11913 \begin_inset LatexCommand \index{Parameter passing}
11914
11915 \end_inset 
11916
11917
11918 \layout Standard
11919
11920 The compiler always uses the global registers 
11921 \emph on 
11922 DPL, DPH
11923 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
11924
11925 \end_inset 
11926
11927
11928 \begin_inset LatexCommand \index{DPTR}
11929
11930 \end_inset 
11931
11932 , B
11933 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
11934
11935 \end_inset 
11936
11937  
11938 \emph default 
11939 and
11940 \emph on 
11941  ACC
11942 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
11943
11944 \end_inset 
11945
11946
11947 \emph default 
11948  to pass the first parameter to a routine.
11949  The second parameter onwards is either allocated on the stack (for reentrant
11950  routines or if -
11951 \begin_inset ERT
11952 status Collapsed
11953
11954 \layout Standard
11955
11956 \backslash 
11957 /
11958 \end_inset 
11959
11960 -stack-auto is used) or in data / xdata memory (depending on the memory
11961  model).
11962  
11963 \layout Subsection
11964
11965 Assembler Routine (non-reentrant)
11966 \layout Standard
11967
11968 In the following example
11969 \begin_inset LatexCommand \index{reentrant}
11970
11971 \end_inset 
11972
11973
11974 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
11975
11976 \end_inset 
11977
11978  the function c_func calls an assembler routine asm_func, which takes two
11979  parameters
11980 \begin_inset LatexCommand \index{function parameter}
11981
11982 \end_inset 
11983
11984 .
11985 \layout Verse
11986
11987
11988 \family typewriter 
11989 extern int asm_func(unsigned char, unsigned char);
11990 \newline 
11991
11992 \newline 
11993 int c_func (unsigned char i, unsigned char j)
11994 \newline 
11995 {
11996 \newline 
11997 \SpecialChar ~
11998 \SpecialChar ~
11999 \SpecialChar ~
12000 \SpecialChar ~
12001 return asm_func(i,j);
12002 \newline 
12003 }
12004 \newline 
12005
12006 \newline 
12007 int main()
12008 \newline 
12009 {
12010 \newline 
12011 \SpecialChar ~
12012 \SpecialChar ~
12013 \SpecialChar ~
12014 \SpecialChar ~
12015 return c_func(10,9);
12016 \newline 
12017 }
12018 \layout Standard
12019
12020 The corresponding assembler function is:
12021 \layout Verse
12022
12023
12024 \family typewriter 
12025 .globl _asm_func_PARM_2 
12026 \newline 
12027 \SpecialChar ~
12028 \SpecialChar ~
12029 \SpecialChar ~
12030 \SpecialChar ~
12031 \SpecialChar ~
12032 \SpecialChar ~
12033 \SpecialChar ~
12034 \SpecialChar ~
12035 .globl _asm_func 
12036 \newline 
12037 \SpecialChar ~
12038 \SpecialChar ~
12039 \SpecialChar ~
12040 \SpecialChar ~
12041 \SpecialChar ~
12042 \SpecialChar ~
12043 \SpecialChar ~
12044 \SpecialChar ~
12045 .area OSEG 
12046 \newline 
12047 _asm_func_PARM_2:
12048 \newline 
12049 \SpecialChar ~
12050 \SpecialChar ~
12051 \SpecialChar ~
12052 \SpecialChar ~
12053 \SpecialChar ~
12054 \SpecialChar ~
12055 \SpecialChar ~
12056 \SpecialChar ~
12057 .ds    1 
12058 \newline 
12059 \SpecialChar ~
12060 \SpecialChar ~
12061 \SpecialChar ~
12062 \SpecialChar ~
12063 \SpecialChar ~
12064 \SpecialChar ~
12065 \SpecialChar ~
12066 \SpecialChar ~
12067 .area CSEG 
12068 \newline 
12069 _asm_func: 
12070 \newline 
12071 \SpecialChar ~
12072 \SpecialChar ~
12073 \SpecialChar ~
12074 \SpecialChar ~
12075 \SpecialChar ~
12076 \SpecialChar ~
12077 \SpecialChar ~
12078 \SpecialChar ~
12079 mov\SpecialChar ~
12080 \SpecialChar ~
12081 \SpecialChar ~
12082 \SpecialChar ~
12083 a,dpl 
12084 \newline 
12085 \SpecialChar ~
12086 \SpecialChar ~
12087 \SpecialChar ~
12088 \SpecialChar ~
12089 \SpecialChar ~
12090 \SpecialChar ~
12091 \SpecialChar ~
12092 \SpecialChar ~
12093 add\SpecialChar ~
12094 \SpecialChar ~
12095 \SpecialChar ~
12096 \SpecialChar ~
12097 a,_asm_func_PARM_2 
12098 \newline 
12099 \SpecialChar ~
12100 \SpecialChar ~
12101 \SpecialChar ~
12102 \SpecialChar ~
12103 \SpecialChar ~
12104 \SpecialChar ~
12105 \SpecialChar ~
12106 \SpecialChar ~
12107 mov\SpecialChar ~
12108 \SpecialChar ~
12109 \SpecialChar ~
12110 \SpecialChar ~
12111 dpl,a 
12112 \newline 
12113 \SpecialChar ~
12114 \SpecialChar ~
12115 \SpecialChar ~
12116 \SpecialChar ~
12117 \SpecialChar ~
12118 \SpecialChar ~
12119 \SpecialChar ~
12120 \SpecialChar ~
12121 mov\SpecialChar ~
12122 \SpecialChar ~
12123 \SpecialChar ~
12124 \SpecialChar ~
12125 dph
12126 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
12127
12128 \end_inset 
12129
12130 ,#0x00 
12131 \newline 
12132 \SpecialChar ~
12133 \SpecialChar ~
12134 \SpecialChar ~
12135 \SpecialChar ~
12136 \SpecialChar ~
12137 \SpecialChar ~
12138 \SpecialChar ~
12139 \SpecialChar ~
12140 ret
12141 \layout Standard
12142
12143 Note here that the return values
12144 \begin_inset LatexCommand \index{return value}
12145
12146 \end_inset 
12147
12148  are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
12149  two byte values.
12150  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
12151 b' & 'acc' for four byte values.
12152 \layout Standard
12153
12154 The parameter naming convention is _<function_name>_PARM_<n>, where n is
12155  the parameter number starting from 1, and counting from the left.
12156  The first parameter is passed in 
12157 \begin_inset Quotes eld
12158 \end_inset 
12159
12160 dpl
12161 \begin_inset Quotes erd
12162 \end_inset 
12163
12164  for a one byte parameter, 
12165 \begin_inset Quotes eld
12166 \end_inset 
12167
12168 dptr
12169 \begin_inset Quotes erd
12170 \end_inset 
12171
12172  for two bytes, 
12173 \begin_inset Quotes eld
12174 \end_inset 
12175
12176 b,dptr
12177 \begin_inset Quotes erd
12178 \end_inset 
12179
12180  for three bytes and 
12181 \begin_inset Quotes eld
12182 \end_inset 
12183
12184 acc,b,dptr
12185 \begin_inset Quotes erd
12186 \end_inset 
12187
12188  for a four bytes parameter.
12189  The variable name for the second parameter will be _<function_name>_PARM_2.
12190 \newline 
12191
12192 \newline 
12193 Assemble the assembler routine with the following command:
12194 \newline 
12195
12196 \newline 
12197
12198 \family sans 
12199 \series bold 
12200 asx8051 -losg asmfunc.asm
12201 \newline 
12202
12203 \newline 
12204
12205 \family default 
12206 \series default 
12207 Then compile and link the assembler routine to the C source file with the
12208  following command:
12209 \newline 
12210
12211 \newline 
12212
12213 \family sans 
12214 \series bold 
12215 sdcc cfunc.c asmfunc.rel
12216 \layout Subsection
12217
12218 Assembler Routine (reentrant)
12219 \layout Standard
12220
12221 In this case
12222 \begin_inset LatexCommand \index{reentrant}
12223
12224 \end_inset 
12225
12226
12227 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
12228
12229 \end_inset 
12230
12231  the second parameter
12232 \begin_inset LatexCommand \index{function parameter}
12233
12234 \end_inset 
12235
12236  onwards will be passed on the stack, the parameters are pushed from right
12237  to left i.e.
12238  after the call the leftmost parameter will be on the top of the stack.
12239  Here is an example:
12240 \layout Verse
12241
12242
12243 \family typewriter 
12244 extern int asm_func(unsigned char, unsigned char);
12245 \newline 
12246
12247 \newline 
12248 int c_func (unsigned char i, unsigned char j) reentrant 
12249 \newline 
12250
12251 \newline 
12252 \SpecialChar ~
12253 \SpecialChar ~
12254 \SpecialChar ~
12255 \SpecialChar ~
12256 return asm_func(i,j); 
12257 \newline 
12258
12259 \newline 
12260
12261 \newline 
12262 int main() 
12263 \newline 
12264
12265 \newline 
12266 \SpecialChar ~
12267 \SpecialChar ~
12268 \SpecialChar ~
12269 \SpecialChar ~
12270 return c_func(10,9); 
12271 \newline 
12272 }
12273 \layout Standard
12274
12275 The corresponding assembler routine is:
12276 \layout Verse
12277
12278
12279 \family typewriter 
12280 .globl _asm_func 
12281 \newline 
12282 _asm_func: 
12283 \newline 
12284 \SpecialChar ~
12285 \SpecialChar ~
12286 \SpecialChar ~
12287 \SpecialChar ~
12288 push  _bp 
12289 \newline 
12290 \SpecialChar ~
12291 \SpecialChar ~
12292 \SpecialChar ~
12293 \SpecialChar ~
12294 mov _bp,sp 
12295 \newline 
12296 \SpecialChar ~
12297 \SpecialChar ~
12298 \SpecialChar ~
12299 \SpecialChar ~
12300 mov r2,dpl
12301 \newline 
12302 \SpecialChar ~
12303 \SpecialChar ~
12304 \SpecialChar ~
12305 \SpecialChar ~
12306 mov a,_bp 
12307 \newline 
12308 \SpecialChar ~
12309 \SpecialChar ~
12310 \SpecialChar ~
12311 \SpecialChar ~
12312 add a,#0xfd 
12313 \newline 
12314 \SpecialChar ~
12315 \SpecialChar ~
12316 \SpecialChar ~
12317 \SpecialChar ~
12318 mov r0,a 
12319 \newline 
12320 \SpecialChar ~
12321 \SpecialChar ~
12322 \SpecialChar ~
12323 \SpecialChar ~
12324 add  a,#0xfc ;?
12325 \newline 
12326 \SpecialChar ~
12327 \SpecialChar ~
12328 \SpecialChar ~
12329 \SpecialChar ~
12330 mov  r1,a 
12331 \newline 
12332 \SpecialChar ~
12333 \SpecialChar ~
12334 \SpecialChar ~
12335 \SpecialChar ~
12336 mov  a,@r0 
12337 \newline 
12338 \SpecialChar ~
12339 \SpecialChar ~
12340 \SpecialChar ~
12341 \SpecialChar ~
12342 add  a,r2 ;?
12343 \newline 
12344 \SpecialChar ~
12345 \SpecialChar ~
12346 \SpecialChar ~
12347 \SpecialChar ~
12348 mov  dpl,a 
12349 \newline 
12350 \SpecialChar ~
12351 \SpecialChar ~
12352 \SpecialChar ~
12353 \SpecialChar ~
12354 mov  dph,#0x00 
12355 \newline 
12356 \SpecialChar ~
12357 \SpecialChar ~
12358 \SpecialChar ~
12359 \SpecialChar ~
12360 mov  sp,_bp 
12361 \newline 
12362 \SpecialChar ~
12363 \SpecialChar ~
12364 \SpecialChar ~
12365 \SpecialChar ~
12366 pop  _bp 
12367 \newline 
12368 \SpecialChar ~
12369 \SpecialChar ~
12370 \SpecialChar ~
12371 \SpecialChar ~
12372 ret
12373 \layout Standard
12374
12375 The compiling and linking procedure remains the same, however note the extra
12376  entry & exit linkage required for the assembler code, _bp is the stack
12377  frame pointer and is used to compute the offset into the stack for parameters
12378  and local variables.
12379 \layout Section
12380
12381 int (16 bit)
12382 \begin_inset LatexCommand \index{int (16 bit)}
12383
12384 \end_inset 
12385
12386  and long (32 bit)
12387 \begin_inset LatexCommand \index{long (32 bit)}
12388
12389 \end_inset 
12390
12391  Support
12392 \layout Standard
12393
12394 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
12395  multiplication and modulus operations are implemented by support routines.
12396  These support routines are all developed in ANSI-C to facilitate porting
12397  to other MCUs, although some model specific assembler optimizations are
12398  used.
12399  The following files contain the described routines, all of them can be
12400  found in <installdir>/share/sdcc/lib.
12401 \newline 
12402
12403 \layout Standard
12404 \align center 
12405
12406 \begin_inset  Tabular
12407 <lyxtabular version="3" rows="11" columns="2">
12408 <features>
12409 <column alignment="center" valignment="top" leftline="true" width="0">
12410 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
12411 <row topline="true" bottomline="true">
12412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12413 \begin_inset Text
12414
12415 \layout Standard
12416
12417
12418 \series bold 
12419 Function
12420 \end_inset 
12421 </cell>
12422 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12423 \begin_inset Text
12424
12425 \layout Standard
12426
12427
12428 \series bold 
12429 Description
12430 \end_inset 
12431 </cell>
12432 </row>
12433 <row topline="true">
12434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12435 \begin_inset Text
12436
12437 \layout Standard
12438
12439 _mulint.c 
12440 \end_inset 
12441 </cell>
12442 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12443 \begin_inset Text
12444
12445 \layout Standard
12446
12447 16 bit multiplication
12448 \end_inset 
12449 </cell>
12450 </row>
12451 <row topline="true">
12452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12453 \begin_inset Text
12454
12455 \layout Standard
12456
12457 _divsint.c 
12458 \end_inset 
12459 </cell>
12460 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12461 \begin_inset Text
12462
12463 \layout Standard
12464
12465  signed 16 bit division (calls _divuint)
12466 \end_inset 
12467 </cell>
12468 </row>
12469 <row topline="true">
12470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12471 \begin_inset Text
12472
12473 \layout Standard
12474
12475 _divuint.c 
12476 \end_inset 
12477 </cell>
12478 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12479 \begin_inset Text
12480
12481 \layout Standard
12482
12483  unsigned 16 bit division
12484 \end_inset 
12485 </cell>
12486 </row>
12487 <row topline="true">
12488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12489 \begin_inset Text
12490
12491 \layout Standard
12492
12493 _modsint.c
12494 \end_inset 
12495 </cell>
12496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12497 \begin_inset Text
12498
12499 \layout Standard
12500
12501 signed 16 bit modulus (calls _moduint)
12502 \end_inset 
12503 </cell>
12504 </row>
12505 <row topline="true">
12506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12507 \begin_inset Text
12508
12509 \layout Standard
12510
12511 _moduint.c
12512 \end_inset 
12513 </cell>
12514 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12515 \begin_inset Text
12516
12517 \layout Standard
12518
12519 unsigned 16 bit modulus
12520 \end_inset 
12521 </cell>
12522 </row>
12523 <row topline="true">
12524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12525 \begin_inset Text
12526
12527 \layout Standard
12528
12529 _mullong.c
12530 \end_inset 
12531 </cell>
12532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12533 \begin_inset Text
12534
12535 \layout Standard
12536
12537 32 bit multiplication
12538 \end_inset 
12539 </cell>
12540 </row>
12541 <row topline="true">
12542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12543 \begin_inset Text
12544
12545 \layout Standard
12546
12547 _divslong.c 
12548 \end_inset 
12549 </cell>
12550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12551 \begin_inset Text
12552
12553 \layout Standard
12554
12555  signed 32 division (calls _divulong)
12556 \end_inset 
12557 </cell>
12558 </row>
12559 <row topline="true">
12560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12561 \begin_inset Text
12562
12563 \layout Standard
12564
12565 _divulong.c 
12566 \end_inset 
12567 </cell>
12568 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12569 \begin_inset Text
12570
12571 \layout Standard
12572
12573 unsigned 32 division
12574 \end_inset 
12575 </cell>
12576 </row>
12577 <row topline="true">
12578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12579 \begin_inset Text
12580
12581 \layout Standard
12582
12583 _modslong.c
12584 \end_inset 
12585 </cell>
12586 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12587 \begin_inset Text
12588
12589 \layout Standard
12590
12591  signed 32 bit modulus (calls _modulong)
12592 \end_inset 
12593 </cell>
12594 </row>
12595 <row topline="true" bottomline="true">
12596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12597 \begin_inset Text
12598
12599 \layout Standard
12600
12601 _modulong.c
12602 \end_inset 
12603 </cell>
12604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12605 \begin_inset Text
12606
12607 \layout Standard
12608
12609 unsigned 32 bit modulus
12610 \end_inset 
12611 </cell>
12612 </row>
12613 </lyxtabular>
12614
12615 \end_inset 
12616
12617
12618 \newline 
12619
12620 \layout Standard
12621
12622 Since they are compiled as 
12623 \emph on 
12624 non-reentrant
12625 \emph default 
12626
12627 \begin_inset LatexCommand \index{reentrant}
12628
12629 \end_inset 
12630
12631 , interrupt
12632 \begin_inset LatexCommand \index{interrupt}
12633
12634 \end_inset 
12635
12636  service routines should not do any of the above operations.
12637  If this is unavoidable then the above routines will need to be compiled
12638  with the 
12639 \emph on 
12640 -
12641 \begin_inset ERT
12642 status Collapsed
12643
12644 \layout Standard
12645
12646 \backslash 
12647 /
12648 \end_inset 
12649
12650 -stack-auto
12651 \begin_inset LatexCommand \index{-\/-stack-auto}
12652
12653 \end_inset 
12654
12655
12656 \emph default 
12657  option, after which the source program will have to be compiled with 
12658 \emph on 
12659 -
12660 \begin_inset ERT
12661 status Collapsed
12662
12663 \layout Standard
12664
12665 \backslash 
12666 /
12667 \end_inset 
12668
12669 -int-long-reent
12670 \begin_inset LatexCommand \index{-\/-int-long-reent}
12671
12672 \end_inset 
12673
12674
12675 \emph default 
12676  option.
12677  Notice that you don't have to call these routines directly.
12678  The compiler will use them automatically every time an integer operation
12679  is required.
12680 \layout Section
12681
12682 Floating Point Support
12683 \begin_inset LatexCommand \index{Floating point support}
12684
12685 \end_inset 
12686
12687
12688 \layout Standard
12689
12690 SDCC supports IEEE (single precision 4 bytes) floating point numbers.The
12691  floating point support routines are derived from gcc's floatlib.c and consist
12692  of the following routines:
12693 \newline 
12694
12695 \layout Standard
12696 \align center 
12697
12698 \size footnotesize 
12699
12700 \begin_inset  Tabular
12701 <lyxtabular version="3" rows="17" columns="2">
12702 <features>
12703 <column alignment="center" valignment="top" leftline="true" width="0">
12704 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
12705 <row topline="true" bottomline="true">
12706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12707 \begin_inset Text
12708
12709 \layout Standard
12710
12711
12712 \family roman 
12713 \series medium 
12714 \shape up 
12715 \size normal 
12716 \emph off 
12717 \bar no 
12718 \noun off 
12719 \color none
12720 Function 
12721 \end_inset 
12722 </cell>
12723 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12724 \begin_inset Text
12725
12726 \layout Standard
12727
12728 Description
12729 \end_inset 
12730 </cell>
12731 </row>
12732 <row topline="true">
12733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12734 \begin_inset Text
12735
12736 \layout Standard
12737
12738
12739 \family roman 
12740 \series medium 
12741 \shape up 
12742 \size normal 
12743 \emph off 
12744 \bar no 
12745 \noun off 
12746 \color none
12747 _fsadd.c
12748 \end_inset 
12749 </cell>
12750 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12751 \begin_inset Text
12752
12753 \layout Standard
12754
12755
12756 \family roman 
12757 \series medium 
12758 \shape up 
12759 \size normal 
12760 \emph off 
12761 \bar no 
12762 \noun off 
12763 \color none
12764 add floating point numbers
12765 \end_inset 
12766 </cell>
12767 </row>
12768 <row topline="true">
12769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12770 \begin_inset Text
12771
12772 \layout Standard
12773
12774
12775 \family roman 
12776 \series medium 
12777 \shape up 
12778 \size normal 
12779 \emph off 
12780 \bar no 
12781 \noun off 
12782 \color none
12783 _fssub.c 
12784 \end_inset 
12785 </cell>
12786 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12787 \begin_inset Text
12788
12789 \layout Standard
12790
12791
12792 \family roman 
12793 \series medium 
12794 \shape up 
12795 \size normal 
12796 \emph off 
12797 \bar no 
12798 \noun off 
12799 \color none
12800 subtract floating point numbers 
12801 \end_inset 
12802 </cell>
12803 </row>
12804 <row topline="true">
12805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12806 \begin_inset Text
12807
12808 \layout Standard
12809
12810
12811 \family roman 
12812 \series medium 
12813 \shape up 
12814 \size normal 
12815 \emph off 
12816 \bar no 
12817 \noun off 
12818 \color none
12819 _fsdiv.c 
12820 \end_inset 
12821 </cell>
12822 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12823 \begin_inset Text
12824
12825 \layout Standard
12826
12827
12828 \family roman 
12829 \series medium 
12830 \shape up 
12831 \size normal 
12832 \emph off 
12833 \bar no 
12834 \noun off 
12835 \color none
12836 divide floating point numbers 
12837 \end_inset 
12838 </cell>
12839 </row>
12840 <row topline="true">
12841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12842 \begin_inset Text
12843
12844 \layout Standard
12845
12846
12847 \family roman 
12848 \series medium 
12849 \shape up 
12850 \size normal 
12851 \emph off 
12852 \bar no 
12853 \noun off 
12854 \color none
12855 _fsmul.c 
12856 \end_inset 
12857 </cell>
12858 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12859 \begin_inset Text
12860
12861 \layout Standard
12862
12863
12864 \family roman 
12865 \series medium 
12866 \shape up 
12867 \size normal 
12868 \emph off 
12869 \bar no 
12870 \noun off 
12871 \color none
12872 multiply floating point numbers 
12873 \end_inset 
12874 </cell>
12875 </row>
12876 <row topline="true">
12877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12878 \begin_inset Text
12879
12880 \layout Standard
12881
12882
12883 \family roman 
12884 \series medium 
12885 \shape up 
12886 \size normal 
12887 \emph off 
12888 \bar no 
12889 \noun off 
12890 \color none
12891 _fs2uchar.c
12892 \end_inset 
12893 </cell>
12894 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12895 \begin_inset Text
12896
12897 \layout Standard
12898
12899
12900 \family roman 
12901 \series medium 
12902 \shape up 
12903 \size normal 
12904 \emph off 
12905 \bar no 
12906 \noun off 
12907 \color none
12908 convert floating point to unsigned char
12909 \end_inset 
12910 </cell>
12911 </row>
12912 <row topline="true">
12913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12914 \begin_inset Text
12915
12916 \layout Standard
12917
12918
12919 \family roman 
12920 \series medium 
12921 \shape up 
12922 \size normal 
12923 \emph off 
12924 \bar no 
12925 \noun off 
12926 \color none
12927 _fs2char.c
12928 \end_inset 
12929 </cell>
12930 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12931 \begin_inset Text
12932
12933 \layout Standard
12934
12935
12936 \family roman 
12937 \series medium 
12938 \shape up 
12939 \size normal 
12940 \emph off 
12941 \bar no 
12942 \noun off 
12943 \color none
12944 convert floating point to signed char
12945 \end_inset 
12946 </cell>
12947 </row>
12948 <row topline="true">
12949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12950 \begin_inset Text
12951
12952 \layout Standard
12953
12954
12955 \family roman 
12956 \series medium 
12957 \shape up 
12958 \size normal 
12959 \emph off 
12960 \bar no 
12961 \noun off 
12962 \color none
12963 _fs2uint.c
12964 \end_inset 
12965 </cell>
12966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12967 \begin_inset Text
12968
12969 \layout Standard
12970
12971
12972 \family roman 
12973 \series medium 
12974 \shape up 
12975 \size normal 
12976 \emph off 
12977 \bar no 
12978 \noun off 
12979 \color none
12980 convert floating point to unsigned int
12981 \end_inset 
12982 </cell>
12983 </row>
12984 <row topline="true">
12985 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12986 \begin_inset Text
12987
12988 \layout Standard
12989
12990
12991 \family roman 
12992 \series medium 
12993 \shape up 
12994 \size normal 
12995 \emph off 
12996 \bar no 
12997 \noun off 
12998 \color none
12999 _fs2int.c
13000 \end_inset 
13001 </cell>
13002 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13003 \begin_inset Text
13004
13005 \layout Standard
13006
13007
13008 \family roman 
13009 \series medium 
13010 \shape up 
13011 \size normal 
13012 \emph off 
13013 \bar no 
13014 \noun off 
13015 \color none
13016 convert floating point to signed int
13017 \end_inset 
13018 </cell>
13019 </row>
13020 <row topline="true">
13021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13022 \begin_inset Text
13023
13024 \layout Standard
13025
13026
13027 \family roman 
13028 \series medium 
13029 \shape up 
13030 \size normal 
13031 \emph off 
13032 \bar no 
13033 \noun off 
13034 \color none
13035 _fs2ulong.
13036 \family default 
13037 \series default 
13038 \shape default 
13039 \size default 
13040 \emph default 
13041 \bar default 
13042 \noun default 
13043 \color default
13044 c
13045 \end_inset 
13046 </cell>
13047 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13048 \begin_inset Text
13049
13050 \layout Standard
13051
13052
13053 \family roman 
13054 \series medium 
13055 \shape up 
13056 \size normal 
13057 \emph off 
13058 \bar no 
13059 \noun off 
13060 \color none
13061 convert floating point to unsigned long
13062 \end_inset 
13063 </cell>
13064 </row>
13065 <row topline="true">
13066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13067 \begin_inset Text
13068
13069 \layout Standard
13070
13071
13072 \family roman 
13073 \series medium 
13074 \shape up 
13075 \size normal 
13076 \emph off 
13077 \bar no 
13078 \noun off 
13079 \color none
13080 _fs2long.c
13081 \end_inset 
13082 </cell>
13083 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13084 \begin_inset Text
13085
13086 \layout Standard
13087
13088
13089 \family roman 
13090 \series medium 
13091 \shape up 
13092 \size normal 
13093 \emph off 
13094 \bar no 
13095 \noun off 
13096 \color none
13097 convert floating point to signed long
13098 \end_inset 
13099 </cell>
13100 </row>
13101 <row topline="true">
13102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13103 \begin_inset Text
13104
13105 \layout Standard
13106
13107
13108 \family roman 
13109 \series medium 
13110 \shape up 
13111 \size normal 
13112 \emph off 
13113 \bar no 
13114 \noun off 
13115 \color none
13116 _uchar2fs.c
13117 \end_inset 
13118 </cell>
13119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13120 \begin_inset Text
13121
13122 \layout Standard
13123
13124
13125 \family roman 
13126 \series medium 
13127 \shape up 
13128 \size normal 
13129 \emph off 
13130 \bar no 
13131 \noun off 
13132 \color none
13133 convert unsigned char to floating point
13134 \end_inset 
13135 </cell>
13136 </row>
13137 <row topline="true">
13138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13139 \begin_inset Text
13140
13141 \layout Standard
13142
13143
13144 \family roman 
13145 \series medium 
13146 \shape up 
13147 \size normal 
13148 \emph off 
13149 \bar no 
13150 \noun off 
13151 \color none
13152 _char2fs.c
13153 \end_inset 
13154 </cell>
13155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13156 \begin_inset Text
13157
13158 \layout Standard
13159
13160
13161 \family roman 
13162 \series medium 
13163 \shape up 
13164 \size normal 
13165 \emph off 
13166 \bar no 
13167 \noun off 
13168 \color none
13169 convert char to floating point number
13170 \end_inset 
13171 </cell>
13172 </row>
13173 <row topline="true">
13174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13175 \begin_inset Text
13176
13177 \layout Standard
13178
13179
13180 \family roman 
13181 \series medium 
13182 \shape up 
13183 \size normal 
13184 \emph off 
13185 \bar no 
13186 \noun off 
13187 \color none
13188 _uint2fs.c
13189 \end_inset 
13190 </cell>
13191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13192 \begin_inset Text
13193
13194 \layout Standard
13195
13196
13197 \family roman 
13198 \series medium 
13199 \shape up 
13200 \size normal 
13201 \emph off 
13202 \bar no 
13203 \noun off 
13204 \color none
13205 convert unsigned int to floating point
13206 \end_inset 
13207 </cell>
13208 </row>
13209 <row topline="true">
13210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13211 \begin_inset Text
13212
13213 \layout Standard
13214
13215
13216 \family roman 
13217 \series medium 
13218 \shape up 
13219 \size normal 
13220 \emph off 
13221 \bar no 
13222 \noun off 
13223 \color none
13224 _int2fs.c
13225 \end_inset 
13226 </cell>
13227 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13228 \begin_inset Text
13229
13230 \layout Standard
13231
13232
13233 \family roman 
13234 \series medium 
13235 \shape up 
13236 \size normal 
13237 \emph off 
13238 \bar no 
13239 \noun off 
13240 \color none
13241 convert int to floating point numbers
13242 \end_inset 
13243 </cell>
13244 </row>
13245 <row topline="true">
13246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13247 \begin_inset Text
13248
13249 \layout Standard
13250
13251
13252 \family roman 
13253 \series medium 
13254 \shape up 
13255 \size normal 
13256 \emph off 
13257 \bar no 
13258 \noun off 
13259 \color none
13260 _ulong2fs.c
13261 \end_inset 
13262 </cell>
13263 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13264 \begin_inset Text
13265
13266 \layout Standard
13267
13268
13269 \family roman 
13270 \series medium 
13271 \shape up 
13272 \size normal 
13273 \emph off 
13274 \bar no 
13275 \noun off 
13276 \color none
13277 convert unsigned long to floating point number
13278 \end_inset 
13279 </cell>
13280 </row>
13281 <row topline="true" bottomline="true">
13282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13283 \begin_inset Text
13284
13285 \layout Standard
13286
13287
13288 \family roman 
13289 \series medium 
13290 \shape up 
13291 \size normal 
13292 \emph off 
13293 \bar no 
13294 \noun off 
13295 \color none
13296 _long2fs.c
13297 \end_inset 
13298 </cell>
13299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13300 \begin_inset Text
13301
13302 \layout Standard
13303
13304
13305 \family roman 
13306 \series medium 
13307 \shape up 
13308 \size normal 
13309 \emph off 
13310 \bar no 
13311 \noun off 
13312 \color none
13313 convert long to floating point number
13314 \end_inset 
13315 </cell>
13316 </row>
13317 </lyxtabular>
13318
13319 \end_inset 
13320
13321
13322 \newline 
13323
13324 \layout Standard
13325
13326 These support routines are developed in ANSI-C so there is room for space
13327  and speed improvement.
13328  Note if all these routines are used simultaneously the data space might
13329  overflow.
13330  For serious floating point usage it is recommended that the large model
13331  be used.
13332  Also notice that you don't have to call this routines directly.
13333  The compiler will use them automatically every time a floating point operation
13334  is required.
13335 \layout Section
13336
13337 Library Routines
13338 \begin_inset LatexCommand \index{Libraries}
13339
13340 \end_inset 
13341
13342
13343 \layout Standard
13344
13345
13346 \emph on 
13347 <pending: this is messy and incomplete - a little more information is in
13348  sdcc/doc/libdoc.txt
13349 \emph default 
13350  >
13351 \layout Subsection
13352
13353 Compiler support routines (_gptrget, _mulint etc.)
13354 \layout Subsection
13355
13356 Stdclib functions (puts, printf, strcat etc.)
13357 \layout Subsubsection
13358
13359 <stdio.h>
13360 \layout Standard
13361
13362
13363 \begin_inset LatexCommand \index{<stdio.h>}
13364
13365 \end_inset 
13366
13367 As usual on embedded systems you have to provide your own 
13368 \family typewriter 
13369 getchar()
13370 \begin_inset LatexCommand \index{getchar()}
13371
13372 \end_inset 
13373
13374  
13375 \family default 
13376 and 
13377 \family typewriter 
13378 putchar()
13379 \begin_inset LatexCommand \index{putchar()}
13380
13381 \end_inset 
13382
13383
13384 \family default 
13385  routines.
13386  SDCC does not know whether the system connects to a serial line with or
13387  without handshake, LCD, keyboard or other device.
13388  You'll find examples for serial routines f.e.
13389  in sdcc/device/lib.
13390 \layout Standard
13391
13392 If you're short on memory you might want to use 
13393 \family typewriter 
13394 printf_small()
13395 \family default 
13396  
13397 \emph on 
13398 instead
13399 \emph default 
13400  of
13401 \family typewriter 
13402  printf()
13403 \begin_inset LatexCommand \index{printf()}
13404
13405 \end_inset 
13406
13407 .
13408
13409 \family default 
13410  For the mcs51 there is an assembly version 
13411 \family typewriter 
13412 printf_fast()
13413 \family default 
13414  which should fit the requirements of many embedded systems (by unsetting
13415  #defines it can be customized to 
13416 \emph on 
13417 not
13418 \emph default 
13419  support long variables and field widths).
13420 \layout Subsection
13421
13422 Math functions (sin, pow, sqrt etc.)
13423 \layout Subsection
13424
13425 Other libraries
13426 \layout Standard
13427
13428 Libraries
13429 \begin_inset LatexCommand \index{Libraries}
13430
13431 \end_inset 
13432
13433  included in SDCC should have a license at least as liberal as the GNU Lesser
13434  General Public License
13435 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
13436
13437 \end_inset 
13438
13439  
13440 \emph on 
13441 LGPL
13442 \emph default 
13443 .
13444 \layout Comment
13445
13446 license statements for the libraries are missing.
13447  sdcc/device/lib/ser_ir.c
13448 \layout Comment
13449
13450 or _decdptr f.e.
13451  come with a GPL (as opposed to LGPL) License - this will not be liberal
13452  enough for many embedded programmers.
13453 \layout Standard
13454
13455 If you have ported some library or want to share experience about some code
13456  which f.e.
13457  falls into any of these categories Busses (I
13458 \begin_inset Formula $^{\textrm{2}}$
13459 \end_inset 
13460
13461 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
13462  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
13463  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
13464 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
13465
13466 \end_inset 
13467
13468 \SpecialChar ~
13469 would certainly like to hear about it.
13470  Programmers coding for embedded systems are not especially famous for being
13471  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
13472 e these references are very valuable.
13473  Let's help to create a climate where information is shared.
13474 \layout Section
13475
13476 Memory Models
13477 \layout Subsection
13478
13479 MCS51 Memory Models
13480 \begin_inset LatexCommand \index{Memory model}
13481
13482 \end_inset 
13483
13484
13485 \begin_inset LatexCommand \index{MCS51 memory model}
13486
13487 \end_inset 
13488
13489
13490 \layout Subsubsection
13491
13492 Small and Large
13493 \layout Standard
13494
13495 SDCC allows two memory models for MCS51 code, 
13496 \shape slanted 
13497 small
13498 \shape default 
13499  and 
13500 \shape slanted 
13501 large
13502 \shape default 
13503 .
13504  Modules compiled with different memory models should 
13505 \emph on 
13506 never
13507 \emph default 
13508  be combined together or the results would be unpredictable.
13509  The library routines supplied with the compiler are compiled as both small
13510  and large.
13511  The compiled library modules are contained in separate directories as small
13512  and large so that you can link to either set.
13513  
13514 \layout Standard
13515
13516 When the large model is used all variables declared without a storage class
13517  will be allocated into the external ram, this includes all parameters and
13518  local variables (for non-reentrant
13519 \begin_inset LatexCommand \index{reentrant}
13520
13521 \end_inset 
13522
13523  functions).
13524  When the small model is used variables without storage class are allocated
13525  in the internal ram.
13526 \layout Standard
13527
13528 Judicious usage of the processor specific storage classes
13529 \begin_inset LatexCommand \index{Storage class}
13530
13531 \end_inset 
13532
13533  and the 'reentrant' function type will yield much more efficient code,
13534  than using the large model.
13535  Several optimizations are disabled when the program is compiled using the
13536  large model, it is therefore recommended that the small model be used unless
13537  absolutely required.
13538 \layout Subsubsection
13539
13540 External Stack
13541 \begin_inset LatexCommand \label{sub:External-Stack}
13542
13543 \end_inset 
13544
13545
13546 \begin_inset LatexCommand \index{stack}
13547
13548 \end_inset 
13549
13550
13551 \begin_inset LatexCommand \index{External stack (mcs51)}
13552
13553 \end_inset 
13554
13555
13556 \layout Standard
13557
13558
13559 \series bold 
13560 Attention
13561 \series default 
13562 : this option wasn't maintained for a long time and is quite buggy.
13563  Small programs might work.
13564  You've been warned!
13565 \layout Standard
13566
13567 The external stack (-
13568 \begin_inset ERT
13569 status Collapsed
13570
13571 \layout Standard
13572
13573 \backslash 
13574 /
13575 \end_inset 
13576
13577 -xstack option
13578 \begin_inset LatexCommand \index{-\/-xstack}
13579
13580 \end_inset 
13581
13582 ) is located in pdata
13583 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
13584
13585 \end_inset 
13586
13587  memory (usually at the start of the external ram segment) and is 256 bytes
13588  in size.
13589  When -
13590 \begin_inset ERT
13591 status Collapsed
13592
13593 \layout Standard
13594
13595 \backslash 
13596 /
13597 \end_inset 
13598
13599 -xstack option is used to compile the program, the parameters and local
13600  variables
13601 \begin_inset LatexCommand \index{local variables}
13602
13603 \end_inset 
13604
13605  of all reentrant functions are allocated in this area.
13606  This option is provided for programs with large stack space requirements.
13607  When used with the -
13608 \begin_inset ERT
13609 status Collapsed
13610
13611 \layout Standard
13612
13613 \backslash 
13614 /
13615 \end_inset 
13616
13617 -stack-auto
13618 \begin_inset LatexCommand \index{-\/-stack-auto}
13619
13620 \end_inset 
13621
13622  option, all parameters and local variables are allocated on the external
13623  stack (note: support libraries will need to be recompiled with the same
13624  options).
13625 \layout Standard
13626
13627 The compiler outputs the higher order address byte of the external ram segment
13628  into port P2
13629 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
13630
13631 \end_inset 
13632
13633  (see also section 
13634 \begin_inset LatexCommand \ref{sub:MCS51-variants}
13635
13636 \end_inset 
13637
13638 ), therefore when using the External Stack option, this port 
13639 \emph on 
13640 may not
13641 \emph default 
13642  be used by the application program.
13643 \layout Subsection
13644
13645 DS390 Memory Model
13646 \begin_inset LatexCommand \index{Memory model}
13647
13648 \end_inset 
13649
13650
13651 \begin_inset LatexCommand \index{DS390 memory model}
13652
13653 \end_inset 
13654
13655
13656 \layout Standard
13657
13658 The only model supported is Flat 24
13659 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
13660
13661 \end_inset 
13662
13663 .
13664  This generates code for the 24 bit contiguous addressing mode of the Dallas
13665  DS80C390 part.
13666  In this mode, up to four meg of external RAM or code space can be directly
13667  addressed.
13668  See the data sheets at www.dalsemi.com for further information on this part.
13669 \newline 
13670
13671 \newline 
13672 Note that the compiler does not generate any code to place the processor
13673  into 24 bitmode (although 
13674 \emph on 
13675 tinibios
13676 \emph default 
13677  in the ds390 libraries will do that for you).
13678  If you don't use 
13679 \emph on 
13680 tinibios
13681 \emph default 
13682
13683 \begin_inset LatexCommand \index{Tinibios (DS390)}
13684
13685 \end_inset 
13686
13687 , the boot loader or similar code must ensure that the processor is in 24
13688  bit contiguous addressing mode before calling the SDCC startup code.
13689 \newline 
13690
13691 \newline 
13692 Like the 
13693 \emph on 
13694 -
13695 \begin_inset ERT
13696 status Collapsed
13697
13698 \layout Standard
13699
13700 \backslash 
13701 /
13702 \end_inset 
13703
13704 -model-large
13705 \emph default 
13706  option, variables will by default be placed into the XDATA segment.
13707  
13708 \newline 
13709
13710 \newline 
13711 Segments may be placed anywhere in the 4 meg address space using the usual
13712  -
13713 \begin_inset ERT
13714 status Collapsed
13715
13716 \layout Standard
13717
13718 \backslash 
13719 /
13720 \end_inset 
13721
13722 -*-loc options.
13723  Note that if any segments are located above 64K, the -r flag must be passed
13724  to the linker to generate the proper segment relocations, and the Intel
13725  HEX output format must be used.
13726  The -r flag can be passed to the linker by using the option 
13727 \emph on 
13728 -Wl-r
13729 \emph default 
13730  on the SDCC command line.
13731  However, currently the linker can not handle code segments > 64k.
13732 \layout Section
13733
13734 Pragmas
13735 \begin_inset LatexCommand \index{Pragmas}
13736
13737 \end_inset 
13738
13739
13740 \layout Standard
13741
13742 SDCC supports the following #pragma directives:
13743 \layout Itemize
13744
13745 save
13746 \begin_inset LatexCommand \index{\#pragma save}
13747
13748 \end_inset 
13749
13750  - this will save all current options to the save/restore stack.
13751  See restore.
13752 \layout Itemize
13753
13754 restore
13755 \begin_inset LatexCommand \index{\#pragma restore}
13756
13757 \end_inset 
13758
13759  - will restore saved options from the last save.
13760  saves & restores can be nested.
13761  SDCC uses a save/restore stack: save pushes current options to the stack,
13762  restore pulls current options from the stack.
13763  See save.
13764 \layout Itemize
13765
13766 nogcse
13767 \begin_inset LatexCommand \index{\#pragma nogcse}
13768
13769 \end_inset 
13770
13771  - will stop global common subexpression elimination.
13772 \layout Itemize
13773
13774 noinduction
13775 \begin_inset LatexCommand \index{\#pragma noinduction}
13776
13777 \end_inset 
13778
13779  - will stop loop induction optimizations.
13780 \layout Itemize
13781
13782 nojtbound
13783 \begin_inset LatexCommand \index{\#pragma nojtbound}
13784
13785 \end_inset 
13786
13787  - will not generate code for boundary value checking, when switch statements
13788  are turned into jump-tables (dangerous).
13789  For more details see section 
13790 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
13791
13792 \end_inset 
13793
13794 .
13795 \layout Itemize
13796
13797 nooverlay
13798 \begin_inset LatexCommand \index{\#pragma nooverlay}
13799
13800 \end_inset 
13801
13802  - the compiler will not overlay the parameters and local variables of a
13803  function.
13804 \layout Itemize
13805
13806 less_pedantic
13807 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
13808
13809 \end_inset 
13810
13811  - the compiler will not warn you anymore for obvious mistakes, you'r on
13812  your own now ;-(
13813 \layout Itemize
13814
13815 noloopreverse
13816 \begin_inset LatexCommand \index{\#pragma noloopreverse}
13817
13818 \end_inset 
13819
13820  - Will not do loop reversal optimization
13821 \layout Itemize
13822
13823 exclude
13824 \begin_inset LatexCommand \index{\#pragma exclude}
13825
13826 \end_inset 
13827
13828  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables generation of
13829  pair of push/pop
13830 \begin_inset LatexCommand \index{push/pop}
13831
13832 \end_inset 
13833
13834  instruction in ISR function (using interrupt
13835 \begin_inset LatexCommand \index{interrupt}
13836
13837 \end_inset 
13838
13839  keyword).
13840  The directive should be placed immediately before the ISR function definition
13841  and it affects ALL ISR functions following it.
13842  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
13843 exclude\SpecialChar ~
13844 none
13845 \begin_inset LatexCommand \index{\#pragma exclude}
13846
13847 \end_inset 
13848
13849 .
13850 \layout Itemize
13851
13852 noiv
13853 \begin_inset LatexCommand \index{\#pragma noiv}
13854
13855 \end_inset 
13856
13857  - Do not generate interrupt
13858 \begin_inset LatexCommand \index{interrupt}
13859
13860 \end_inset 
13861
13862  vector table entries for all ISR functions defined after the pragma.
13863  This is useful in cases where the interrupt vector table must be defined
13864  manually, or when there is a secondary, manually defined interrupt vector
13865  table (e.g.
13866  for the autovector feature of the Cypress EZ-USB FX2).
13867  More elegantly this can be achieved by obmitting the optional interrupt
13868  number after the interrupt keyword, see section 
13869 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
13870
13871 \end_inset 
13872
13873 \SpecialChar ~
13874 about interrupts.
13875 \layout Itemize
13876
13877 callee_saves
13878 \begin_inset LatexCommand \index{\#pragma callee\_saves}
13879
13880 \end_inset 
13881
13882
13883 \begin_inset LatexCommand \index{function prologue}
13884
13885 \end_inset 
13886
13887  function1[,function2[,function3...]] - The compiler by default uses a caller
13888  saves convention for register saving across function calls, however this
13889  can cause unnecessary register pushing & popping
13890 \begin_inset LatexCommand \index{push/pop}
13891
13892 \end_inset 
13893
13894  when calling small functions from larger functions.
13895  This option can be used to switch off the register saving convention for
13896  the function names specified.
13897  The compiler will not save registers when calling these functions, extra
13898  code need to be manually inserted at the entry & exit for these functions
13899  to save & restore the registers used by these functions, this can SUBSTANTIALLY
13900  reduce code & improve run time performance of the generated code.
13901  In the future the compiler (with inter procedural analysis) may be able
13902  to determine the appropriate scheme to use for each function call.
13903  If -
13904 \begin_inset ERT
13905 status Collapsed
13906
13907 \layout Standard
13908
13909 \backslash 
13910 /
13911 \end_inset 
13912
13913 -callee-saves command line option is used, the function names specified
13914  in #pragma\SpecialChar ~
13915 callee_saves
13916 \begin_inset LatexCommand \index{\#pragma callee\_saves}
13917
13918 \end_inset 
13919
13920  is appended to the list of functions specified in the command line.
13921 \layout Standard
13922
13923 SDCPP supports the following #pragma directives:
13924 \layout Itemize
13925
13926 preproc_asm
13927 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
13928
13929 \end_inset 
13930
13931  (+ | -) - switch _asm _endasm block preprocessing on / off.
13932  Default is on.
13933 \layout Standard
13934
13935 The pragma's are intended to be used to turn-on or off certain optimizations
13936  which might cause the compiler to generate extra stack / data space to
13937  store compiler generated temporary variables.
13938  This usually happens in large functions.
13939  Pragma directives should be used as shown in the following example, they
13940  are used to control options & optimizations for a given function; pragmas
13941  should be placed before and/or after a function, placing pragma's inside
13942  a function body could have unpredictable results.
13943 \layout Verse
13944
13945
13946 \family typewriter 
13947 #pragma save
13948 \begin_inset LatexCommand \index{\#pragma save}
13949
13950 \end_inset 
13951
13952  \SpecialChar ~
13953 \SpecialChar ~
13954 \SpecialChar ~
13955 \SpecialChar ~
13956 \SpecialChar ~
13957 \SpecialChar ~
13958 \SpecialChar ~
13959 /* save the current settings */ 
13960 \newline 
13961 #pragma nogcse
13962 \begin_inset LatexCommand \index{\#pragma nogcse}
13963
13964 \end_inset 
13965
13966  \SpecialChar ~
13967 \SpecialChar ~
13968 \SpecialChar ~
13969 \SpecialChar ~
13970 \SpecialChar ~
13971 /* turnoff global subexpression elimination */ 
13972 \newline 
13973 #pragma noinduction
13974 \begin_inset LatexCommand \index{\#pragma noinduction}
13975
13976 \end_inset 
13977
13978  /* turn off induction optimizations */ 
13979 \newline 
13980 int foo () 
13981 \newline 
13982
13983 \newline 
13984 \SpecialChar ~
13985  \SpecialChar ~
13986  ...
13987  
13988 \newline 
13989 \SpecialChar ~
13990  \SpecialChar ~
13991  /* large code */ 
13992 \newline 
13993 \SpecialChar ~
13994  \SpecialChar ~
13995  ...
13996  
13997 \newline 
13998
13999 \newline 
14000 #pragma restore
14001 \begin_inset LatexCommand \index{\#pragma restore}
14002
14003 \end_inset 
14004
14005  /* turn the optimizations back on */
14006 \layout Standard
14007
14008 The compiler will generate a warning message when extra space is allocated.
14009  It is strongly recommended that the save and restore pragma's be used when
14010  changing options for a function.
14011 \layout Section
14012
14013 Defines Created by the Compiler
14014 \layout Standard
14015
14016 The compiler creates the following #defines
14017 \begin_inset LatexCommand \index{\#defines}
14018
14019 \end_inset 
14020
14021
14022 \begin_inset LatexCommand \index{Defines created by the compiler}
14023
14024 \end_inset 
14025
14026 :
14027 \newline 
14028
14029 \layout Standard
14030
14031
14032 \begin_inset  Tabular
14033 <lyxtabular version="3" rows="10" columns="2">
14034 <features>
14035 <column alignment="center" valignment="top" leftline="true" width="0">
14036 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
14037 <row topline="true" bottomline="true">
14038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14039 \begin_inset Text
14040
14041 \layout Standard
14042
14043
14044 \series bold 
14045 #define
14046 \end_inset 
14047 </cell>
14048 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14049 \begin_inset Text
14050
14051 \layout Standard
14052
14053
14054 \series bold 
14055 Description
14056 \end_inset 
14057 </cell>
14058 </row>
14059 <row topline="true">
14060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14061 \begin_inset Text
14062
14063 \layout Standard
14064
14065 SDCC
14066 \begin_inset LatexCommand \index{SDCC}
14067
14068 \end_inset 
14069
14070  
14071 \end_inset 
14072 </cell>
14073 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14074 \begin_inset Text
14075
14076 \layout Standard
14077
14078 this Symbol is always defined
14079 \end_inset 
14080 </cell>
14081 </row>
14082 <row topline="true">
14083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14084 \begin_inset Text
14085
14086 \layout Standard
14087
14088 SDCC_mcs51
14089 \begin_inset LatexCommand \index{SDCC\_mcs51}
14090
14091 \end_inset 
14092
14093  or SDCC_ds390
14094 \begin_inset LatexCommand \index{SDCC\_ds390}
14095
14096 \end_inset 
14097
14098  or SDCC_z80
14099 \begin_inset LatexCommand \index{SDCC\_z80}
14100
14101 \end_inset 
14102
14103 , etc
14104 \end_inset 
14105 </cell>
14106 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14107 \begin_inset Text
14108
14109 \layout Standard
14110
14111 depending on the model used (e.g.: -mds390
14112 \end_inset 
14113 </cell>
14114 </row>
14115 <row topline="true">
14116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14117 \begin_inset Text
14118
14119 \layout Standard
14120
14121 __mcs51
14122 \begin_inset LatexCommand \index{\_\_mcs51}
14123
14124 \end_inset 
14125
14126 , __ds390
14127 \begin_inset LatexCommand \index{\_\_ds390}
14128
14129 \end_inset 
14130
14131 , __hc08
14132 \begin_inset LatexCommand \index{\_\_hc08}
14133
14134 \end_inset 
14135
14136 , __z80
14137 \begin_inset LatexCommand \index{\_\_z80}
14138
14139 \end_inset 
14140
14141 , etc
14142 \end_inset 
14143 </cell>
14144 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14145 \begin_inset Text
14146
14147 \layout Standard
14148
14149 depending on the model used (e.g.
14150  -mz80)
14151 \end_inset 
14152 </cell>
14153 </row>
14154 <row topline="true">
14155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14156 \begin_inset Text
14157
14158 \layout Standard
14159
14160 SDCC_STACK_AUTO
14161 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
14162
14163 \end_inset 
14164
14165
14166 \end_inset 
14167 </cell>
14168 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14169 \begin_inset Text
14170
14171 \layout Standard
14172
14173 when 
14174 \emph on 
14175 -
14176 \begin_inset ERT
14177 status Collapsed
14178
14179 \layout Standard
14180
14181 \backslash 
14182 /
14183 \end_inset 
14184
14185 -stack-auto
14186 \emph default 
14187  option is used
14188 \end_inset 
14189 </cell>
14190 </row>
14191 <row topline="true">
14192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14193 \begin_inset Text
14194
14195 \layout Standard
14196
14197 SDCC_MODEL_SMALL
14198 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
14199
14200 \end_inset 
14201
14202
14203 \end_inset 
14204 </cell>
14205 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14206 \begin_inset Text
14207
14208 \layout Standard
14209
14210 when 
14211 \emph on 
14212 -
14213 \begin_inset ERT
14214 status Collapsed
14215
14216 \layout Standard
14217
14218 \backslash 
14219 /
14220 \end_inset 
14221
14222 -model-small
14223 \emph default 
14224  is used
14225 \end_inset 
14226 </cell>
14227 </row>
14228 <row topline="true">
14229 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14230 \begin_inset Text
14231
14232 \layout Standard
14233
14234 SDCC_MODEL_LARGE
14235 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
14236
14237 \end_inset 
14238
14239
14240 \end_inset 
14241 </cell>
14242 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14243 \begin_inset Text
14244
14245 \layout Standard
14246
14247 when 
14248 \emph on 
14249 -
14250 \begin_inset ERT
14251 status Collapsed
14252
14253 \layout Standard
14254
14255 \backslash 
14256 /
14257 \end_inset 
14258
14259 -model-large
14260 \emph default 
14261  is used
14262 \end_inset 
14263 </cell>
14264 </row>
14265 <row topline="true">
14266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14267 \begin_inset Text
14268
14269 \layout Standard
14270
14271 SDCC_USE_XSTACK
14272 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
14273
14274 \end_inset 
14275
14276
14277 \end_inset 
14278 </cell>
14279 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14280 \begin_inset Text
14281
14282 \layout Standard
14283
14284 when 
14285 \emph on 
14286 -
14287 \begin_inset ERT
14288 status Collapsed
14289
14290 \layout Standard
14291
14292 \backslash 
14293 /
14294 \end_inset 
14295
14296 -xstack
14297 \emph default 
14298  option is used
14299 \end_inset 
14300 </cell>
14301 </row>
14302 <row topline="true">
14303 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14304 \begin_inset Text
14305
14306 \layout Standard
14307
14308 SDCC_STACK_TENBIT
14309 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
14310
14311 \end_inset 
14312
14313  
14314 \end_inset 
14315 </cell>
14316 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14317 \begin_inset Text
14318
14319 \layout Standard
14320
14321 when 
14322 \emph on 
14323 -mds390
14324 \emph default 
14325  is used
14326 \end_inset 
14327 </cell>
14328 </row>
14329 <row topline="true" bottomline="true">
14330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14331 \begin_inset Text
14332
14333 \layout Standard
14334
14335 SDCC_MODEL_FLAT24
14336 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
14337
14338 \end_inset 
14339
14340
14341 \end_inset 
14342 </cell>
14343 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14344 \begin_inset Text
14345
14346 \layout Standard
14347
14348 when 
14349 \emph on 
14350 -mds390
14351 \emph default 
14352  is used
14353 \end_inset 
14354 </cell>
14355 </row>
14356 </lyxtabular>
14357
14358 \end_inset 
14359
14360
14361 \layout Chapter
14362
14363 Notes on supported Processors
14364 \layout Section
14365
14366 MCS51 variants
14367 \begin_inset LatexCommand \label{sub:MCS51-variants}
14368
14369 \end_inset 
14370
14371
14372 \begin_inset LatexCommand \index{MCS51 variants}
14373
14374 \end_inset 
14375
14376
14377 \layout Standard
14378
14379 MCS51 processors are available from many vendors and come in many different
14380  flavours.
14381  While they might differ considerably in respect to Special Function Registers
14382  the core MCS51 is usually not modified or is kept compatible.
14383  
14384 \layout Subsection
14385
14386 pdata access by SFR 
14387 \layout Standard
14388
14389 With the upcome of devices with internal xdata and flash memory devices
14390  using port P2
14391 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
14392
14393 \end_inset 
14394
14395  as dedicated I/O port is becoming more popular.
14396  Switching the high byte for pdata
14397 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
14398
14399 \end_inset 
14400
14401  access which was formerly done by port P2 is then achieved by a Special
14402  Function Register
14403 \begin_inset LatexCommand \index{sfr}
14404
14405 \end_inset 
14406
14407 .
14408  In well-established MCS51 tradition the address of this 
14409 \emph on 
14410 sfr
14411 \emph default 
14412  is where the chip designers decided to put it.
14413  Needless to say that they didn't agree on a common name either.
14414  So that the startup code can correctly initialize xdata variables, you
14415  should define an sfr with the name _XPAGE
14416 \family typewriter 
14417
14418 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
14419
14420 \end_inset 
14421
14422
14423 \family default 
14424  at the appropriate location if the default, port P2, is not used for this.
14425  Some examples are:
14426 \layout Verse
14427
14428
14429 \family typewriter 
14430 sfr at 0x92 _XPAGE; /* Cypress EZ-USB family */
14431 \layout Verse
14432
14433
14434 \family typewriter 
14435 sfr at 0xaf _XPAGE; /* some Silicon Labs (Cygnal) chips */
14436 \layout Verse
14437
14438
14439 \family typewriter 
14440 sfr at 0xaa _XPAGE; /* some Silicon Labs (Cygnal) chips */
14441 \layout Standard
14442
14443 For more exotic implementations further customizations may be needed.
14444  See section 
14445 \begin_inset LatexCommand \ref{sub:Startup-Code}
14446
14447 \end_inset 
14448
14449  for other possibilities.
14450 \layout Subsection
14451
14452 Other Features available by SFR
14453 \layout Standard
14454
14455 Some MCS51 variants offer features like Double DPTR
14456 \begin_inset LatexCommand \index{DPTR}
14457
14458 \end_inset 
14459
14460 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
14461  These are currently not used for the MCS51 port.
14462  If you absolutely need them you can fall back to inline assembly or submit
14463  a patch to SDCC.
14464 \layout Section
14465
14466 The Z80 and gbz80 port
14467 \layout Standard
14468
14469 SDCC can target both the Zilog 
14470 \begin_inset LatexCommand \index{Z80}
14471
14472 \end_inset 
14473
14474  and the Nintendo Gameboy's Z80-like gbz80
14475 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
14476
14477 \end_inset 
14478
14479 .
14480  The Z80 port is passed through the same 
14481 \emph on 
14482 regressions tests
14483 \begin_inset LatexCommand \index{Regression test}
14484
14485 \end_inset 
14486
14487
14488 \emph default 
14489  as the MCS51 and DS390 ports, so floating point support, support for long
14490  variables and bitfield support is fine.
14491  See mailing lists and forums about interrupt routines.
14492 \layout Standard
14493
14494 As always, the code is the authoritative reference - see z80/ralloc.c and
14495  z80/gen.c.
14496  The stack
14497 \begin_inset LatexCommand \index{stack}
14498
14499 \end_inset 
14500
14501  frame is similar to that generated by the IAR Z80 compiler.
14502  IX is used as the base pointer, HL and IY are used as a temporary registers,
14503  and BC and DE are available for holding variables.
14504  Return values
14505 \begin_inset LatexCommand \index{return value}
14506
14507 \end_inset 
14508
14509  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
14510  bytes).
14511  The gbz80 port use the same set of registers for the return values, but
14512  in a different order of significance: E (one byte), DE (two bytes), or
14513  HLDE (four bytes).
14514 \layout Section
14515
14516 The HC08 port
14517 \layout Standard
14518
14519 The port to the Motorola HC08
14520 \begin_inset LatexCommand \index{HC08}
14521
14522 \end_inset 
14523
14524  family has been added in October 2003, and is still undergoing some basic
14525  development.
14526  The code generator is complete, but the register allocation is still quite
14527  unoptimized.
14528  Some of the SDCC's standard C library functions have embedded non-HC08
14529  inline assembly and so are not yet usable.
14530 \newline 
14531
14532 \newline 
14533
14534 \layout Section
14535
14536 The PIC14 port
14537 \layout Standard
14538
14539 The 14bit PIC
14540 \begin_inset LatexCommand \index{PIC14}
14541
14542 \end_inset 
14543
14544  port still requires a major effort from the development community.
14545  However it can work for very simple code.
14546 \layout Subsection
14547
14548 C code and 14bit PIC code page
14549 \begin_inset LatexCommand \index{code page (pic14)}
14550
14551 \end_inset 
14552
14553  and RAM banks
14554 \begin_inset LatexCommand \index{RAM bank (pic14)}
14555
14556 \end_inset 
14557
14558
14559 \layout Standard
14560
14561 The linker organizes allocation for the code page and RAM banks.
14562  It does not have intimate knowledge of the code flow.
14563  It will put all the code section of a single asm file into a single code
14564  page.
14565  In order to make use of multiple code pages, separate asm files must be
14566  used.
14567  The compiler treats all functions of a single C file as being in the same
14568  code page unless it is non static.
14569  The compiler treats all local variables of a single C file as being in
14570  the same RAM bank unless it is an extern.
14571 \newline 
14572
14573 \newline 
14574 To get the best follow these guide lines:
14575 \layout Enumerate
14576
14577 make local functions static, as non static functions require code page selection
14578  overhead.
14579 \layout Enumerate
14580
14581 Make local variables static as extern variables require RAM bank selection
14582  overhead.
14583 \layout Enumerate
14584
14585 For devices that have multiple code pages it is more efficient to use the
14586  same number of files as pages, i.e.
14587  for the 16F877 use 4 separate files and i.e.
14588  for the 16F874 use 2 separate files.
14589  This way the linker can put the code for each file into different code
14590  pages and the compiler can allocate reusable variables more efficiently
14591  and there's less page selection overhead.
14592  And as for any 8 bit micro (especially for PIC 14 as they have a very simple
14593  instruction set) use 'unsigned char' whereever possible instead of 'int'.
14594 \layout Subsection
14595
14596 Creating a device include file 
14597 \layout Standard
14598
14599 For generating a device include file use the support perl script inc2h.pl
14600  kept in directory support/script.
14601 \layout Subsection
14602
14603 Interrupt code
14604 \layout Standard
14605
14606 For the interrupt function, use the keyword 'interrupt'
14607 \begin_inset LatexCommand \index{interrupt}
14608
14609 \end_inset 
14610
14611  with level number of 0 (PIC14 only has 1 interrupt so this number is only
14612  there to avoid a syntax error - it ought to be fixed).
14613  E.g.:
14614 \layout Verse
14615
14616
14617 \family typewriter 
14618 void Intr(void) interrupt 0
14619 \newline 
14620 {
14621 \newline 
14622 \SpecialChar ~
14623 \SpecialChar ~
14624 T0IF = 0; /* Clear timer interrupt */
14625 \newline 
14626 }
14627 \layout Subsection
14628
14629 Linking and assembling
14630 \layout Standard
14631
14632 For assembling you can use either GPUTILS'
14633 \begin_inset LatexCommand \index{gputils (pic tools)}
14634
14635 \end_inset 
14636
14637  gpasm.exe or MPLAB's mpasmwin.exe.
14638  GPUTILS is available from 
14639 \begin_inset LatexCommand \url{http://gputils.sourceforge.net/}
14640
14641 \end_inset 
14642
14643 .
14644  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
14645  If you use MPLAB and an interrupt function then the linker script file
14646  vectors section will need to be enlarged to link with mplink.
14647 \newline 
14648
14649 \newline 
14650 Here is a 
14651 \family typewriter 
14652 Makefile
14653 \family default 
14654  using GPUTILS:
14655 \layout Verse
14656
14657
14658 \family typewriter 
14659 .c.o:
14660 \newline 
14661 \SpecialChar ~
14662 \SpecialChar ~
14663 \SpecialChar ~
14664 \SpecialChar ~
14665 \SpecialChar ~
14666 \SpecialChar ~
14667 \SpecialChar ~
14668 \SpecialChar ~
14669 sdcc -S -V -mpic14 -p16F877 $< 
14670 \newline 
14671 \SpecialChar ~
14672 \SpecialChar ~
14673 \SpecialChar ~
14674 \SpecialChar ~
14675 \SpecialChar ~
14676 \SpecialChar ~
14677 \SpecialChar ~
14678 \SpecialChar ~
14679 gpasm -c $*.asm
14680 \newline 
14681
14682 \newline 
14683 $(PRJ).hex: $(OBJS) 
14684 \newline 
14685 \SpecialChar ~
14686 \SpecialChar ~
14687 \SpecialChar ~
14688 \SpecialChar ~
14689 \SpecialChar ~
14690 \SpecialChar ~
14691 \SpecialChar ~
14692 \SpecialChar ~
14693 gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS)
14694 \layout Standard
14695
14696 Here is a 
14697 \family typewriter 
14698 Makefile
14699 \family default 
14700  using MPLAB:
14701 \layout Verse
14702
14703
14704 \family typewriter 
14705 .c.o: 
14706 \newline 
14707 \SpecialChar ~
14708 \SpecialChar ~
14709 \SpecialChar ~
14710 \SpecialChar ~
14711 \SpecialChar ~
14712 \SpecialChar ~
14713 \SpecialChar ~
14714 \SpecialChar ~
14715 sdcc -S -V -mpic14 -p16F877 $< 
14716 \newline 
14717 \SpecialChar ~
14718 \SpecialChar ~
14719 \SpecialChar ~
14720 \SpecialChar ~
14721 \SpecialChar ~
14722 \SpecialChar ~
14723 \SpecialChar ~
14724 \SpecialChar ~
14725 mpasmwin /q /o $*.asm
14726 \newline 
14727
14728 \newline 
14729 $(PRJ).hex: $(OBJS) 
14730 \newline 
14731 \SpecialChar ~
14732 \SpecialChar ~
14733 \SpecialChar ~
14734 \SpecialChar ~
14735 \SpecialChar ~
14736 \SpecialChar ~
14737 \SpecialChar ~
14738 \SpecialChar ~
14739 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS)
14740 \layout Standard
14741
14742 Please note that indentations within a
14743 \family typewriter 
14744  Makefile
14745 \family default 
14746  have to be done with a tabulator character.
14747 \layout Section
14748
14749 The PIC16
14750 \begin_inset LatexCommand \index{PIC16}
14751
14752 \end_inset 
14753
14754  port
14755 \layout Standard
14756
14757 The PIC16
14758 \begin_inset LatexCommand \index{PIC16}
14759
14760 \end_inset 
14761
14762  port is the portion of SDCC that is responsible to produce code for the
14763  Microchip
14764 \begin_inset LatexCommand \index{Microchip}
14765
14766 \end_inset 
14767
14768 (TM) microcontrollers with 16 bit core.
14769  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
14770 \layout Subsection
14771
14772 Global Options
14773 \layout Standard
14774
14775 PIC16 port supports the standard command line arguments as supposed, with
14776  the exception of certain cases that will be mentioned in the following
14777  list:
14778 \layout List
14779 \labelwidthstring 00.00.0000
14780
14781 -
14782 \begin_inset ERT
14783 status Collapsed
14784
14785 \layout Standard
14786
14787 \backslash 
14788 /
14789 \end_inset 
14790
14791 -stack-auto Auto variables that are function parameters, will be saved on
14792  stack by default.
14793  
14794 \emph on 
14795 There is no need to specify this in the command line.
14796 \layout List
14797 \labelwidthstring 00.00.0000
14798
14799 -
14800 \begin_inset ERT
14801 status Collapsed
14802
14803 \layout Standard
14804
14805 \backslash 
14806 /
14807 \end_inset 
14808
14809 -float-reent All floating point functions are reentrant by default.
14810  
14811 \emph on 
14812 There is no need to specifiy this in the command line.
14813 \layout List
14814 \labelwidthstring 00.00.0000
14815
14816 -
14817 \begin_inset ERT
14818 status Collapsed
14819
14820 \layout Standard
14821
14822 \backslash 
14823 /
14824 \end_inset 
14825
14826 -callee-saves See -
14827 \begin_inset ERT
14828 status Collapsed
14829
14830 \layout Standard
14831
14832 \backslash 
14833 /
14834 \end_inset 
14835
14836 -all-callee-saves
14837 \layout List
14838 \labelwidthstring 00.00.0000
14839
14840 -
14841 \begin_inset ERT
14842 status Collapsed
14843
14844 \layout Standard
14845
14846 \backslash 
14847 /
14848 \end_inset 
14849
14850 -all-callee-saves All function arguments are passed on stack by default.
14851  
14852 \emph on 
14853 There is no need to specify this in the command line.
14854 \layout List
14855 \labelwidthstring 00.00.0000
14856
14857 -
14858 \begin_inset ERT
14859 status Collapsed
14860
14861 \layout Standard
14862
14863 \backslash 
14864 /
14865 \end_inset 
14866
14867 -fommit-frame-pointer Frame pointer will be omitted when the function uses
14868  no local variables.
14869 \layout Subsection
14870
14871 Port Specific Options
14872 \begin_inset LatexCommand \index{Options PIC16}
14873
14874 \end_inset 
14875
14876
14877 \layout Standard
14878
14879 The port specific options appear after the global options in the sdcc --help
14880  output.
14881 \layout Subsubsection
14882
14883 General Options
14884 \layout Standard
14885
14886 General options enable certain port features and optimizations.
14887 \layout List
14888 \labelwidthstring 00.00.0000
14889
14890 -
14891 \begin_inset ERT
14892 status Collapsed
14893
14894 \layout Standard
14895
14896 \backslash 
14897 /
14898 \end_inset 
14899
14900 -pgen-bank Instructs the port to insert BANKSEL directives before instructions
14901  that use the Bank Select Register (BSR).
14902 \layout List
14903 \labelwidthstring 00.00.0000
14904
14905 -
14906 \begin_inset ERT
14907 status Collapsed
14908
14909 \layout Standard
14910
14911 \backslash 
14912 /
14913 \end_inset 
14914
14915 -pomit-config-words Instructs the port to omit the generation of the configurati
14916 on words.
14917 \layout List
14918 \labelwidthstring 00.00.0000
14919
14920 -
14921 \begin_inset ERT
14922 status Collapsed
14923
14924 \layout Standard
14925
14926 \backslash 
14927 /
14928 \end_inset 
14929
14930 -pomit-ivt Instructs the port to omit the generation of the interrupt vectors
14931 \layout List
14932 \labelwidthstring 00.00.0000
14933
14934 -
14935 \begin_inset ERT
14936 status Collapsed
14937
14938 \layout Standard
14939
14940 \backslash 
14941 /
14942 \end_inset 
14943
14944 -pleave-reset-vector Used in conjuction with the previous command, instructs
14945  the port NOT to omit the reset vector.
14946 \layout List
14947 \labelwidthstring 00.00.0000
14948
14949 -
14950 \begin_inset ERT
14951 status Collapsed
14952
14953 \layout Standard
14954
14955 \backslash 
14956 /
14957 \end_inset 
14958
14959 -stack-model=[model] Used in conjuction with the command above.
14960  Defines the stack model to be used, valid stack models are : 
14961 \begin_deeper 
14962 \layout List
14963 \labelwidthstring 00.00.0000
14964
14965
14966 \emph on 
14967 small
14968 \emph default 
14969  Selects small stack model.
14970  8 bit stack and frame pointers.
14971  Supports 256 bytes stack size.
14972 \layout List
14973 \labelwidthstring 00.00.0000
14974
14975
14976 \emph on 
14977 large
14978 \emph default 
14979  Selects large stack model.
14980  16 bit stack and frame pointers.
14981  Supports 65536 bytes stack size.
14982 \end_deeper 
14983 \layout List
14984 \labelwidthstring 00.00.0000
14985
14986 -
14987 \begin_inset ERT
14988 status Collapsed
14989
14990 \layout Standard
14991
14992 \backslash 
14993 /
14994 \end_inset 
14995
14996 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
14997  unitialized data variables with [kword].
14998  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
14999 \layout Subsubsection
15000
15001 Debugging Options
15002 \layout Standard
15003
15004 Debugging options enable extra debugging information in the output files.
15005 \layout List
15006 \labelwidthstring 00.00.0000
15007
15008 -
15009 \begin_inset ERT
15010 status Collapsed
15011
15012 \layout Standard
15013
15014 \backslash 
15015 /
15016 \end_inset 
15017
15018 -debug-xtra Similar to -
15019 \begin_inset ERT
15020 status Collapsed
15021
15022 \layout Standard
15023
15024 \backslash 
15025 /
15026 \end_inset 
15027
15028 -debug
15029 \begin_inset LatexCommand \index{-\/-debug}
15030
15031 \end_inset 
15032
15033 , but dumps more information.
15034 \layout List
15035 \labelwidthstring 00.00.0000
15036
15037 -
15038 \begin_inset ERT
15039 status Collapsed
15040
15041 \layout Standard
15042
15043 \backslash 
15044 /
15045 \end_inset 
15046
15047 -debug-ralloc Force register allocator to dump <source>.d file with debugging
15048  information.
15049  <source> is the name of the file compiled.
15050 \layout List
15051 \labelwidthstring 00.00.0000
15052
15053 -
15054 \begin_inset ERT
15055 status Collapsed
15056
15057 \layout Standard
15058
15059 \backslash 
15060 /
15061 \end_inset 
15062
15063 -pcode-verbose Enable pcode debugging information in translation.
15064 \layout Subsection
15065
15066 Preprocessor Macros
15067 \layout Standard
15068
15069 PIC16 port defines the following preprocessor macros while translating a
15070  source.
15071 \layout Standard
15072 \align center 
15073
15074 \begin_inset  Tabular
15075 <lyxtabular version="3" rows="2" columns="2">
15076 <features>
15077 <column alignment="center" valignment="top" leftline="true" width="0">
15078 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15079 <row topline="true" bottomline="true">
15080 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15081 \begin_inset Text
15082
15083 \layout Standard
15084
15085 Macro
15086 \end_inset 
15087 </cell>
15088 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15089 \begin_inset Text
15090
15091 \layout Standard
15092
15093 Description
15094 \end_inset 
15095 </cell>
15096 </row>
15097 <row topline="true" bottomline="true">
15098 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15099 \begin_inset Text
15100
15101 \layout Standard
15102
15103 pic18fxxxx
15104 \end_inset 
15105 </cell>
15106 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15107 \begin_inset Text
15108
15109 \layout Standard
15110
15111 MCU Identification.
15112  
15113 \emph on 
15114 xxxx
15115 \emph default 
15116  is the microcontrol identification number, i.e.
15117  452, 6620, etc
15118 \end_inset 
15119 </cell>
15120 </row>
15121 </lyxtabular>
15122
15123 \end_inset 
15124
15125
15126 \layout Subsection
15127
15128 Directories
15129 \layout Standard
15130
15131 PIC16
15132 \begin_inset LatexCommand \index{PIC16}
15133
15134 \end_inset 
15135
15136  port uses the following directories for searching header files and libraries.
15137 \layout Standard
15138 \align center 
15139
15140 \begin_inset  Tabular
15141 <lyxtabular version="3" rows="3" columns="4">
15142 <features>
15143 <column alignment="center" valignment="top" leftline="true" width="0">
15144 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15145 <column alignment="center" valignment="top" width="0">
15146 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15147 <row topline="true" bottomline="true">
15148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15149 \begin_inset Text
15150
15151 \layout Standard
15152
15153 Directory
15154 \end_inset 
15155 </cell>
15156 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15157 \begin_inset Text
15158
15159 \layout Standard
15160
15161 Description
15162 \end_inset 
15163 </cell>
15164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15165 \begin_inset Text
15166
15167 \layout Standard
15168
15169 Target
15170 \end_inset 
15171 </cell>
15172 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15173 \begin_inset Text
15174
15175 \layout Standard
15176
15177 Command prefix
15178 \end_inset 
15179 </cell>
15180 </row>
15181 <row topline="true">
15182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15183 \begin_inset Text
15184
15185 \layout Standard
15186
15187 PREFIX/sdcc/include/pic16
15188 \end_inset 
15189 </cell>
15190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15191 \begin_inset Text
15192
15193 \layout Standard
15194
15195 PIC16 specific headers
15196 \end_inset 
15197 </cell>
15198 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15199 \begin_inset Text
15200
15201 \layout Standard
15202
15203 Compiler
15204 \end_inset 
15205 </cell>
15206 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15207 \begin_inset Text
15208
15209 \layout Standard
15210
15211 -I
15212 \end_inset 
15213 </cell>
15214 </row>
15215 <row topline="true" bottomline="true">
15216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15217 \begin_inset Text
15218
15219 \layout Standard
15220
15221 PREFIX/sdcc/lib/pic16
15222 \end_inset 
15223 </cell>
15224 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15225 \begin_inset Text
15226
15227 \layout Standard
15228
15229 PIC16 specific libraries
15230 \end_inset 
15231 </cell>
15232 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15233 \begin_inset Text
15234
15235 \layout Standard
15236
15237 Linker
15238 \end_inset 
15239 </cell>
15240 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15241 \begin_inset Text
15242
15243 \layout Standard
15244
15245 -L
15246 \end_inset 
15247 </cell>
15248 </row>
15249 </lyxtabular>
15250
15251 \end_inset 
15252
15253
15254 \layout Subsection
15255
15256 Pragmas
15257 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
15258
15259 \end_inset 
15260
15261
15262 \layout Standard
15263
15264 PIC16 port currently supports the following pragmas:
15265 \layout List
15266 \labelwidthstring 00.00.0000
15267
15268 stack pragma stack forces the code generator to initialize the stack & frame
15269  pointers at a specific address.
15270  This is an adhoc solution since gplink does not support yet stack.
15271  When the gplink issue is resolved the pragma will be deprecated
15272 \begin_inset Foot
15273 collapsed true
15274
15275 \layout Standard
15276
15277
15278 \emph on 
15279 It is important to initialize the stack, otherwise strange things can happen.
15280  Stack is not initialized by default because there are some sources that
15281  do not require it.
15282  (like library sources)
15283 \end_inset 
15284
15285 .
15286 \newline 
15287 The stack pragma should be used only once in a project.
15288  Multiple pragmas may result in indeterminate behaviour of the program.
15289 \newline 
15290 If you omit setting the pragma the port emits a warning message before linking.
15291  If not initializing the stack is desired ignore the message.
15292 \layout LyX-Code
15293
15294 Example:
15295 \layout LyX-Code
15296
15297 \layout LyX-Code
15298
15299 /* initializes stack at RAM address 0x5ff */
15300 \layout LyX-Code
15301
15302 #pragma stack 0x5ff
15303 \layout LyX-Code
15304
15305 \layout Subsection
15306
15307 Header Files
15308 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
15309
15310 \end_inset 
15311
15312
15313 \layout Standard
15314
15315 There is one main header file that can be included to the source files using
15316  the pic16 port.
15317  That file is the 
15318 \series bold 
15319 pic18fregs.h
15320 \series default 
15321 .
15322  This header file contains the definitions for the processor special registers,
15323  so it is necessary if the source accesses them.
15324  It can be included by adding the following line in the beginning of the
15325  file:
15326 \layout LyX-Code
15327
15328 #include <pic18fregs.h>
15329 \layout Standard
15330
15331 The specific microcontroller is selected within the pic18fregs.h automatically,
15332  so the same source can be used with a variety of devices.
15333 \layout Subsection
15334
15335 Libraries
15336 \layout Standard
15337
15338 The libraries that PIC16
15339 \begin_inset LatexCommand \index{PIC16}
15340
15341 \end_inset 
15342
15343  port depends on are the microcontroller device libraries which contain
15344  the symbol definitions for the microcontroller special function registers.
15345  These libraries have the format pic18fxxxx.lib, where 
15346 \emph on 
15347 xxxx
15348 \emph default 
15349  is the microcontroller identification number.
15350  The specific library is selected automatically by the compiler at link
15351  stage according to the selected device.
15352 \layout Standard
15353
15354 Libraries are created with gplib which is part of the gputils package 
15355 \begin_inset LatexCommand \url{http://gputils.sourceforge.net}
15356
15357 \end_inset 
15358
15359 .
15360 \layout Subsection
15361
15362 Memory Models
15363 \layout Standard
15364
15365 The following memory models are supported by the PIC16 port:
15366 \layout Itemize
15367
15368 small model
15369 \layout Itemize
15370
15371 large model
15372 \layout Standard
15373
15374 Memory model affects the default size of pointers within the source.
15375  The sizes are shown in the next table:
15376 \layout Standard
15377 \align center 
15378
15379 \begin_inset  Tabular
15380 <lyxtabular version="3" rows="3" columns="3">
15381 <features>
15382 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15383 <column alignment="center" valignment="top" leftline="true" width="0">
15384 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15385 <row topline="true" bottomline="true">
15386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15387 \begin_inset Text
15388
15389 \layout Standard
15390
15391 Pointer sizes according to memory model
15392 \end_inset 
15393 </cell>
15394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15395 \begin_inset Text
15396
15397 \layout Standard
15398
15399 small model
15400 \end_inset 
15401 </cell>
15402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15403 \begin_inset Text
15404
15405 \layout Standard
15406
15407 large model
15408 \end_inset 
15409 </cell>
15410 </row>
15411 <row topline="true" bottomline="true">
15412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15413 \begin_inset Text
15414
15415 \layout Standard
15416
15417 code pointers
15418 \end_inset 
15419 </cell>
15420 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15421 \begin_inset Text
15422
15423 \layout Standard
15424
15425 16-bits
15426 \end_inset 
15427 </cell>
15428 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15429 \begin_inset Text
15430
15431 \layout Standard
15432
15433 24-bits
15434 \end_inset 
15435 </cell>
15436 </row>
15437 <row topline="true" bottomline="true">
15438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15439 \begin_inset Text
15440
15441 \layout Standard
15442
15443 data pointers
15444 \end_inset 
15445 </cell>
15446 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
15447 \begin_inset Text
15448
15449 \layout Standard
15450
15451 16-bits
15452 \end_inset 
15453 </cell>
15454 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15455 \begin_inset Text
15456
15457 \layout Standard
15458
15459 16-bits
15460 \end_inset 
15461 </cell>
15462 </row>
15463 </lyxtabular>
15464
15465 \end_inset 
15466
15467
15468 \layout Standard
15469
15470 It is advisable that all sources within a project are compiled with the
15471  same memory model.
15472  If one wants to override the default memory model, this can be done by
15473  declaring a pointer as 
15474 \series bold 
15475 far
15476 \series default 
15477  or 
15478 \series bold 
15479 near
15480 \series default 
15481 .
15482  Far selects large memory model's pointers, while near selects small memory
15483  model's pointers.
15484 \layout Standard
15485
15486 The standard device libraries (see 
15487 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
15488
15489 \end_inset 
15490
15491 ) contain no reference to pointers, so they can be used with both memory
15492  models.
15493 \layout Subsection
15494
15495 Stack
15496 \layout Standard
15497
15498 The stack implementation for the PIC16 port uses two indirect registers,
15499  FSR1 and FSR2.
15500 \layout List
15501 \labelwidthstring 00.00.0000
15502
15503 FSR1 is assigned as stack pointer
15504 \layout List
15505 \labelwidthstring 00.00.0000
15506
15507 FSR2 is assigned as frame pointer
15508 \layout Standard
15509
15510 The following stack models are supported by the PIC16 port
15511 \layout Itemize
15512
15513 small model
15514 \layout Itemize
15515
15516 large model
15517 \layout Standard
15518
15519
15520 \noun on 
15521 Small
15522 \noun default 
15523  model means that only the FSRxL byte is used to access stack and frame,
15524  while 
15525 \emph on 
15526 \noun on 
15527 large
15528 \emph default 
15529 \noun default 
15530  uses both FSRxL and FSRxH registers.
15531  The following table shows the stack/frame pointers sizes according to stack
15532  model and the maximum space they can address:
15533 \layout Standard
15534 \align center 
15535
15536 \begin_inset  Tabular
15537 <lyxtabular version="3" rows="3" columns="3">
15538 <features>
15539 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15540 <column alignment="center" valignment="top" leftline="true" width="0">
15541 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15542 <row topline="true" bottomline="true">
15543 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15544 \begin_inset Text
15545
15546 \layout Standard
15547
15548 Stack & Frame pointer sizes according to stack model
15549 \end_inset 
15550 </cell>
15551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15552 \begin_inset Text
15553
15554 \layout Standard
15555
15556 small
15557 \end_inset 
15558 </cell>
15559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15560 \begin_inset Text
15561
15562 \layout Standard
15563
15564 large
15565 \end_inset 
15566 </cell>
15567 </row>
15568 <row topline="true">
15569 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15570 \begin_inset Text
15571
15572 \layout Standard
15573
15574 Stack pointer FSR1
15575 \end_inset 
15576 </cell>
15577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15578 \begin_inset Text
15579
15580 \layout Standard
15581
15582 8-bits
15583 \end_inset 
15584 </cell>
15585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15586 \begin_inset Text
15587
15588 \layout Standard
15589
15590 16-bits
15591 \end_inset 
15592 </cell>
15593 </row>
15594 <row topline="true" bottomline="true">
15595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15596 \begin_inset Text
15597
15598 \layout Standard
15599
15600 Frame pointer FSR2
15601 \end_inset 
15602 </cell>
15603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15604 \begin_inset Text
15605
15606 \layout Standard
15607
15608 8-bits
15609 \end_inset 
15610 </cell>
15611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15612 \begin_inset Text
15613
15614 \layout Standard
15615
15616 16-bits
15617 \end_inset 
15618 </cell>
15619 </row>
15620 </lyxtabular>
15621
15622 \end_inset 
15623
15624
15625 \layout Standard
15626
15627
15628 \series bold 
15629 Currently stack and frame pointers should be initialized explicit by the
15630  user at the desired Data RAM position (see 
15631 \begin_inset LatexCommand \ref{sub:PIC16_Pragmas}
15632
15633 \end_inset 
15634
15635  Pragma stack).
15636  Uninitialized stack and frame pointers can result in unexpected behavior
15637  of the resulting binary.
15638 \layout Subsection
15639
15640 Function return values
15641 \layout Standard
15642
15643 Return values from functions are placed to the appropriate registers following
15644  a modified Microchip policy optimized for SDCC.
15645  The following table shows these registers:
15646 \layout Standard
15647 \align center 
15648
15649 \begin_inset  Tabular
15650 <lyxtabular version="3" rows="6" columns="2">
15651 <features>
15652 <column alignment="center" valignment="top" leftline="true" width="0">
15653 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15654 <row topline="true" bottomline="true">
15655 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15656 \begin_inset Text
15657
15658 \layout Standard
15659
15660 size
15661 \end_inset 
15662 </cell>
15663 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15664 \begin_inset Text
15665
15666 \layout Standard
15667
15668 destination register
15669 \end_inset 
15670 </cell>
15671 </row>
15672 <row topline="true">
15673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15674 \begin_inset Text
15675
15676 \layout Standard
15677
15678 8 bits
15679 \end_inset 
15680 </cell>
15681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15682 \begin_inset Text
15683
15684 \layout Standard
15685
15686 WREG
15687 \end_inset 
15688 </cell>
15689 </row>
15690 <row topline="true">
15691 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15692 \begin_inset Text
15693
15694 \layout Standard
15695
15696 16 bits
15697 \end_inset 
15698 </cell>
15699 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15700 \begin_inset Text
15701
15702 \layout Standard
15703
15704 PRODL:WREG
15705 \end_inset 
15706 </cell>
15707 </row>
15708 <row topline="true">
15709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15710 \begin_inset Text
15711
15712 \layout Standard
15713
15714 24 bits
15715 \end_inset 
15716 </cell>
15717 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15718 \begin_inset Text
15719
15720 \layout Standard
15721
15722 PRODH:PRODL:WREG
15723 \end_inset 
15724 </cell>
15725 </row>
15726 <row topline="true">
15727 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15728 \begin_inset Text
15729
15730 \layout Standard
15731
15732 32 bits
15733 \end_inset 
15734 </cell>
15735 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15736 \begin_inset Text
15737
15738 \layout Standard
15739
15740 FSR0L:PRODH:PRODL:WREG
15741 \end_inset 
15742 </cell>
15743 </row>
15744 <row topline="true" bottomline="true">
15745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15746 \begin_inset Text
15747
15748 \layout Standard
15749
15750 >32 bits
15751 \end_inset 
15752 </cell>
15753 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15754 \begin_inset Text
15755
15756 \layout Standard
15757
15758 on stack, FSR0 points to the beginning
15759 \end_inset 
15760 </cell>
15761 </row>
15762 </lyxtabular>
15763
15764 \end_inset 
15765
15766
15767 \layout Subsection
15768
15769 Interrupts
15770 \layout Standard
15771
15772 When entering an interrupt, currently the PIC16
15773 \begin_inset LatexCommand \index{PIC16}
15774
15775 \end_inset 
15776
15777  port automatically saves the following registers:
15778 \layout Itemize
15779
15780 WREG
15781 \layout Itemize
15782
15783 STATUS
15784 \layout Itemize
15785
15786 BSR
15787 \layout Itemize
15788
15789 PROD (PRODL and PRODH)
15790 \layout Itemize
15791
15792 FSR0 (FSR0L and FSR0H)
15793 \layout Standard
15794
15795 These registers are restored upon return from the interrupt routine
15796 \begin_inset Foot
15797 collapsed false
15798
15799 \layout Standard
15800
15801 NOTE that when the _naked attribute is specified for an interrupt routine,
15802  then NO registers are stored or restored.
15803 \end_inset 
15804
15805 .
15806 \layout Chapter
15807
15808 Debugging with SDCDB
15809 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
15810
15811 \end_inset 
15812
15813
15814 \begin_inset LatexCommand \index{sdcdb (debugger)}
15815
15816 \end_inset 
15817
15818  
15819 \layout Standard
15820
15821 SDCC is distributed with a source level debugger
15822 \begin_inset LatexCommand \index{Debugger}
15823
15824 \end_inset 
15825
15826 .
15827  The debugger uses a command line interface, the command repertoire of the
15828  debugger has been kept as close to gdb
15829 \begin_inset LatexCommand \index{gdb}
15830
15831 \end_inset 
15832
15833  (the GNU debugger) as possible.
15834  The configuration and build process is part of the standard compiler installati
15835 on, which also builds and installs the debugger in the target directory
15836  specified during configuration.
15837  The debugger allows you debug BOTH at the C source and at the ASM source
15838  level.
15839  Sdcdb is available on Unix platforms only.
15840 \layout Section
15841
15842 Compiling for Debugging
15843 \layout Standard
15844
15845 The -
15846 \begin_inset ERT
15847 status Collapsed
15848
15849 \layout Standard
15850
15851 \backslash 
15852 /
15853 \end_inset 
15854
15855 -debug
15856 \begin_inset LatexCommand \index{-\/-debug}
15857
15858 \end_inset 
15859
15860  option must be specified for all files for which debug information is to
15861  be generated.
15862  The complier generates a .adb file for each of these files.
15863  The linker creates the .cdb
15864 \begin_inset LatexCommand \index{<file>.cdb}
15865
15866 \end_inset 
15867
15868  file from the .adb
15869 \begin_inset LatexCommand \index{<file>.adb}
15870
15871 \end_inset 
15872
15873  files and the address information.
15874  This .cdb is used by the debugger.
15875 \layout Section
15876
15877 How the Debugger Works
15878 \layout Standard
15879
15880 When the -
15881 \begin_inset ERT
15882 status Collapsed
15883
15884 \layout Standard
15885
15886 \backslash 
15887 /
15888 \end_inset 
15889
15890 -debug option is specified the compiler generates extra symbol information
15891  some of which are put into the assembler source and some are put into the
15892  .adb file.
15893   Then the linker creates the .cdb file from the individual .adb files with
15894  the address information for the symbols.
15895  The debugger reads the symbolic information generated by the compiler &
15896  the address information generated by the linker.
15897  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
15898  execution is controlled by the debugger.
15899  When a command is issued for the debugger, it translates it into appropriate
15900  commands for the simulator.
15901 \layout Section
15902
15903 Starting the Debugger
15904 \layout Standard
15905
15906 The debugger can be started using the following command line.
15907  (Assume the file you are debugging has the file name foo).
15908 \newline 
15909
15910 \newline 
15911
15912 \family sans 
15913 \series bold 
15914 sdcdb foo
15915 \newline 
15916
15917 \family default 
15918 \series default 
15919
15920 \newline 
15921 The debugger will look for the following files.
15922 \layout Itemize
15923
15924 foo.c - the source file.
15925 \layout Itemize
15926
15927 foo.cdb - the debugger symbol information file.
15928 \layout Itemize
15929
15930 foo.ihx - the Intel hex format
15931 \begin_inset LatexCommand \index{Intel hex format}
15932
15933 \end_inset 
15934
15935  object file.
15936 \layout Section
15937
15938 Command Line Options.
15939 \layout Itemize
15940
15941 -
15942 \begin_inset ERT
15943 status Collapsed
15944
15945 \layout Standard
15946
15947 \backslash 
15948 /
15949 \end_inset 
15950
15951 -directory=<source file directory> this option can used to specify the directory
15952  search list.
15953  The debugger will look into the directory list specified for source, cdb
15954  & ihx files.
15955  The items in the directory list must be separated by ':', e.g.
15956  if the source files can be in the directories /home/src1 and /home/src2,
15957  the -
15958 \begin_inset ERT
15959 status Collapsed
15960
15961 \layout Standard
15962
15963 \backslash 
15964 /
15965 \end_inset 
15966
15967 -directory option should be -
15968 \begin_inset ERT
15969 status Collapsed
15970
15971 \layout Standard
15972
15973 \backslash 
15974 /
15975 \end_inset 
15976
15977 -directory=/home/src1:/home/src2.
15978  Note there can be no spaces in the option.
15979  
15980 \layout Itemize
15981
15982 -cd <directory> - change to the <directory>.
15983 \layout Itemize
15984
15985 -fullname - used by GUI front ends.
15986 \layout Itemize
15987
15988 -cpu <cpu-type> - this argument is passed to the simulator please see the
15989  simulator docs for details.
15990 \layout Itemize
15991
15992 -X <Clock frequency > this options is passed to the simulator please see
15993  the simulator docs for details.
15994 \layout Itemize
15995
15996 -s <serial port file> passed to simulator see the simulator docs for details.
15997 \layout Itemize
15998
15999 -S <serial in,out> passed to simulator see the simulator docs for details.
16000 \layout Itemize
16001
16002 -k <port number> passed to simulator see the simulator docs for details.
16003 \layout Section
16004
16005 Debugger Commands.
16006 \layout Standard
16007
16008 As mentioned earlier the command interface for the debugger has been deliberatel
16009 y kept as close the GNU debugger gdb, as possible.
16010  This will help the integration with existing graphical user interfaces
16011  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
16012  If you use a graphical user interface for the debugger you can skip the
16013  next sections.
16014 \layout Subsubsection*
16015
16016 break [line | file:line | function | file:function]
16017 \layout Standard
16018
16019 Set breakpoint at specified line or function:
16020 \newline 
16021
16022 \newline 
16023
16024 \family sans 
16025 \series bold 
16026 sdcdb>break 100 
16027 \newline 
16028 sdcdb>break foo.c:100
16029 \newline 
16030 sdcdb>break funcfoo
16031 \newline 
16032 sdcdb>break foo.c:funcfoo
16033 \layout Subsubsection*
16034
16035 clear [line | file:line | function | file:function ]
16036 \layout Standard
16037
16038 Clear breakpoint at specified line or function:
16039 \newline 
16040
16041 \newline 
16042
16043 \family sans 
16044 \series bold 
16045 sdcdb>clear 100
16046 \newline 
16047 sdcdb>clear foo.c:100
16048 \newline 
16049 sdcdb>clear funcfoo
16050 \newline 
16051 sdcdb>clear foo.c:funcfoo
16052 \layout Subsubsection*
16053
16054 continue
16055 \layout Standard
16056
16057 Continue program being debugged, after breakpoint.
16058 \layout Subsubsection*
16059
16060 finish
16061 \layout Standard
16062
16063 Execute till the end of the current function.
16064 \layout Subsubsection*
16065
16066 delete [n]
16067 \layout Standard
16068
16069 Delete breakpoint number 'n'.
16070  If used without any option clear ALL user defined break points.
16071 \layout Subsubsection*
16072
16073 info [break | stack | frame | registers ]
16074 \layout Itemize
16075
16076 info break - list all breakpoints
16077 \layout Itemize
16078
16079 info stack - show the function call stack.
16080 \layout Itemize
16081
16082 info frame - show information about the current execution frame.
16083 \layout Itemize
16084
16085 info registers - show content of all registers.
16086 \layout Subsubsection*
16087
16088 step
16089 \layout Standard
16090
16091 Step program until it reaches a different source line.
16092  Note: pressing <return> repeats the last command.
16093 \layout Subsubsection*
16094
16095 next
16096 \layout Standard
16097
16098 Step program, proceeding through subroutine calls.
16099 \layout Subsubsection*
16100
16101 run
16102 \layout Standard
16103
16104 Start debugged program.
16105 \layout Subsubsection*
16106
16107 ptype variable 
16108 \layout Standard
16109
16110 Print type information of the variable.
16111 \layout Subsubsection*
16112
16113 print variable
16114 \layout Standard
16115
16116 print value of variable.
16117 \layout Subsubsection*
16118
16119 file filename
16120 \layout Standard
16121
16122 load the given file name.
16123  Note this is an alternate method of loading file for debugging.
16124 \layout Subsubsection*
16125
16126 frame
16127 \layout Standard
16128
16129 print information about current frame.
16130 \layout Subsubsection*
16131
16132 set srcmode
16133 \layout Standard
16134
16135 Toggle between C source & assembly source.
16136 \layout Subsubsection*
16137
16138 ! simulator command
16139 \layout Standard
16140
16141 Send the string following '!' to the simulator, the simulator response is
16142  displayed.
16143  Note the debugger does not interpret the command being sent to the simulator,
16144  so if a command like 'go' is sent the debugger can loose its execution
16145  context and may display incorrect values.
16146 \layout Subsubsection*
16147
16148 quit
16149 \layout Standard
16150
16151 "Watch me now.
16152  Iam going Down.
16153  My name is Bobby Brown"
16154 \layout Section
16155
16156 Interfacing with XEmacs
16157 \begin_inset LatexCommand \index{XEmacs}
16158
16159 \end_inset 
16160
16161
16162 \begin_inset LatexCommand \index{Emacs}
16163
16164 \end_inset 
16165
16166 .
16167 \layout Standard
16168
16169 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
16170  sdcdb.el and sdcdbsrc.el.
16171  These two files can be found in the $(prefix)/bin directory after the installat
16172 ion is complete.
16173  These files need to be loaded into XEmacs for the interface to work.
16174  This can be done at XEmacs startup time by inserting the following into
16175  your '.xemacs' file (which can be found in your HOME directory): 
16176 \newline 
16177
16178 \newline 
16179
16180 \family typewriter 
16181 (load-file sdcdbsrc.el) 
16182 \family default 
16183
16184 \newline 
16185
16186 \newline 
16187 .xemacs is a lisp file so the () around the command is REQUIRED.
16188  The files can also be loaded dynamically while XEmacs is running, set the
16189  environment variable 'EMACSLOADPATH' to the installation bin directory
16190  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
16191  To start the interface enter the following command: 
16192 \newline 
16193
16194 \newline 
16195
16196 \family sans 
16197 \series bold 
16198 ESC-x sdcdbsrc
16199 \family default 
16200 \series default 
16201
16202 \newline 
16203
16204 \newline 
16205 You will prompted to enter the file name to be debugged.
16206  
16207 \newline 
16208
16209 \newline 
16210 The command line options that are passed to the simulator directly are bound
16211  to default values in the file sdcdbsrc.el.
16212  The variables are listed below, these values maybe changed as required.
16213 \layout Itemize
16214
16215 sdcdbsrc-cpu-type '51
16216 \layout Itemize
16217
16218 sdcdbsrc-frequency '11059200
16219 \layout Itemize
16220
16221 sdcdbsrc-serial nil
16222 \layout Standard
16223
16224 The following is a list of key mapping for the debugger interface.
16225 \layout Standard
16226
16227 \SpecialChar ~
16228
16229 \family typewriter 
16230
16231 \newline 
16232 ;;\SpecialChar ~
16233 Current Listing :: 
16234 \newline 
16235 ;;key\SpecialChar ~
16236 \SpecialChar ~
16237 \SpecialChar ~
16238 \SpecialChar ~
16239 \SpecialChar ~
16240 \SpecialChar ~
16241 \SpecialChar ~
16242 \SpecialChar ~
16243 \SpecialChar ~
16244 \SpecialChar ~
16245 \SpecialChar ~
16246 \SpecialChar ~
16247 \SpecialChar ~
16248 \SpecialChar ~
16249 binding\SpecialChar ~
16250 \SpecialChar ~
16251 \SpecialChar ~
16252 \SpecialChar ~
16253 \SpecialChar ~
16254 \SpecialChar ~
16255 \SpecialChar ~
16256 \SpecialChar ~
16257 \SpecialChar ~
16258 \SpecialChar ~
16259 \SpecialChar ~
16260 \SpecialChar ~
16261 \SpecialChar ~
16262 \SpecialChar ~
16263 \SpecialChar ~
16264 \SpecialChar ~
16265 \SpecialChar ~
16266 \SpecialChar ~
16267 \SpecialChar ~
16268 \SpecialChar ~
16269 \SpecialChar ~
16270 \SpecialChar ~
16271 Comment 
16272 \newline 
16273 ;;---\SpecialChar ~
16274 \SpecialChar ~
16275 \SpecialChar ~
16276 \SpecialChar ~
16277 \SpecialChar ~
16278 \SpecialChar ~
16279 \SpecialChar ~
16280 \SpecialChar ~
16281 \SpecialChar ~
16282 \SpecialChar ~
16283 \SpecialChar ~
16284 \SpecialChar ~
16285 \SpecialChar ~
16286 \SpecialChar ~
16287 -------\SpecialChar ~
16288 \SpecialChar ~
16289 \SpecialChar ~
16290 \SpecialChar ~
16291 \SpecialChar ~
16292 \SpecialChar ~
16293 \SpecialChar ~
16294 \SpecialChar ~
16295 \SpecialChar ~
16296 \SpecialChar ~
16297 \SpecialChar ~
16298 \SpecialChar ~
16299 \SpecialChar ~
16300 \SpecialChar ~
16301 \SpecialChar ~
16302 \SpecialChar ~
16303 \SpecialChar ~
16304 \SpecialChar ~
16305 \SpecialChar ~
16306 \SpecialChar ~
16307 \SpecialChar ~
16308 \SpecialChar ~
16309 -------
16310 \newline 
16311 ;; 
16312 \newline 
16313 ;;\SpecialChar ~
16314 n\SpecialChar ~
16315 \SpecialChar ~
16316 \SpecialChar ~
16317 \SpecialChar ~
16318 \SpecialChar ~
16319 \SpecialChar ~
16320 \SpecialChar ~
16321 \SpecialChar ~
16322 \SpecialChar ~
16323 \SpecialChar ~
16324 \SpecialChar ~
16325 \SpecialChar ~
16326 \SpecialChar ~
16327 \SpecialChar ~
16328 \SpecialChar ~
16329 sdcdb-next-from-src\SpecialChar ~
16330 \SpecialChar ~
16331 \SpecialChar ~
16332 \SpecialChar ~
16333 \SpecialChar ~
16334 \SpecialChar ~
16335 \SpecialChar ~
16336 \SpecialChar ~
16337 \SpecialChar ~
16338 \SpecialChar ~
16339 SDCDB next command 
16340 \newline 
16341 ;;\SpecialChar ~
16342 b\SpecialChar ~
16343 \SpecialChar ~
16344 \SpecialChar ~
16345 \SpecialChar ~
16346 \SpecialChar ~
16347 \SpecialChar ~
16348 \SpecialChar ~
16349 \SpecialChar ~
16350 \SpecialChar ~
16351 \SpecialChar ~
16352 \SpecialChar ~
16353 \SpecialChar ~
16354 \SpecialChar ~
16355 \SpecialChar ~
16356 \SpecialChar ~
16357 sdcdb-back-from-src\SpecialChar ~
16358 \SpecialChar ~
16359 \SpecialChar ~
16360 \SpecialChar ~
16361 \SpecialChar ~
16362 \SpecialChar ~
16363 \SpecialChar ~
16364 \SpecialChar ~
16365 \SpecialChar ~
16366 \SpecialChar ~
16367 SDCDB back command 
16368 \newline 
16369 ;;\SpecialChar ~
16370 c\SpecialChar ~
16371 \SpecialChar ~
16372 \SpecialChar ~
16373 \SpecialChar ~
16374 \SpecialChar ~
16375 \SpecialChar ~
16376 \SpecialChar ~
16377 \SpecialChar ~
16378 \SpecialChar ~
16379 \SpecialChar ~
16380 \SpecialChar ~
16381 \SpecialChar ~
16382 \SpecialChar ~
16383 \SpecialChar ~
16384 \SpecialChar ~
16385 sdcdb-cont-from-src\SpecialChar ~
16386 \SpecialChar ~
16387 \SpecialChar ~
16388 \SpecialChar ~
16389 \SpecialChar ~
16390 \SpecialChar ~
16391 \SpecialChar ~
16392 \SpecialChar ~
16393 \SpecialChar ~
16394 \SpecialChar ~
16395 SDCDB continue command
16396 \newline 
16397 ;;\SpecialChar ~
16398 s\SpecialChar ~
16399 \SpecialChar ~
16400 \SpecialChar ~
16401 \SpecialChar ~
16402 \SpecialChar ~
16403 \SpecialChar ~
16404 \SpecialChar ~
16405 \SpecialChar ~
16406 \SpecialChar ~
16407 \SpecialChar ~
16408 \SpecialChar ~
16409 \SpecialChar ~
16410 \SpecialChar ~
16411 \SpecialChar ~
16412 \SpecialChar ~
16413 sdcdb-step-from-src\SpecialChar ~
16414 \SpecialChar ~
16415 \SpecialChar ~
16416 \SpecialChar ~
16417 \SpecialChar ~
16418 \SpecialChar ~
16419 \SpecialChar ~
16420 \SpecialChar ~
16421 \SpecialChar ~
16422 \SpecialChar ~
16423 SDCDB step command 
16424 \newline 
16425 ;;\SpecialChar ~
16426 ?\SpecialChar ~
16427 \SpecialChar ~
16428 \SpecialChar ~
16429 \SpecialChar ~
16430 \SpecialChar ~
16431 \SpecialChar ~
16432 \SpecialChar ~
16433 \SpecialChar ~
16434 \SpecialChar ~
16435 \SpecialChar ~
16436 \SpecialChar ~
16437 \SpecialChar ~
16438 \SpecialChar ~
16439 \SpecialChar ~
16440 \SpecialChar ~
16441 sdcdb-whatis-c-sexp\SpecialChar ~
16442 \SpecialChar ~
16443 \SpecialChar ~
16444 \SpecialChar ~
16445 \SpecialChar ~
16446 \SpecialChar ~
16447 \SpecialChar ~
16448 \SpecialChar ~
16449 \SpecialChar ~
16450 \SpecialChar ~
16451 SDCDB ptypecommand for data at 
16452 \newline 
16453 ;;\SpecialChar ~
16454 \SpecialChar ~
16455 \SpecialChar ~
16456 \SpecialChar ~
16457 \SpecialChar ~
16458 \SpecialChar ~
16459 \SpecialChar ~
16460 \SpecialChar ~
16461 \SpecialChar ~
16462 \SpecialChar ~
16463 \SpecialChar ~
16464 \SpecialChar ~
16465 \SpecialChar ~
16466 \SpecialChar ~
16467 \SpecialChar ~
16468 \SpecialChar ~
16469 \SpecialChar ~
16470 \SpecialChar ~
16471 \SpecialChar ~
16472 \SpecialChar ~
16473 \SpecialChar ~
16474 \SpecialChar ~
16475 \SpecialChar ~
16476 \SpecialChar ~
16477 \SpecialChar ~
16478 \SpecialChar ~
16479 \SpecialChar ~
16480 \SpecialChar ~
16481 \SpecialChar ~
16482 \SpecialChar ~
16483 \SpecialChar ~
16484 \SpecialChar ~
16485 \SpecialChar ~
16486 \SpecialChar ~
16487 \SpecialChar ~
16488 \SpecialChar ~
16489 \SpecialChar ~
16490 \SpecialChar ~
16491 \SpecialChar ~
16492 \SpecialChar ~
16493 \SpecialChar ~
16494 \SpecialChar ~
16495 \SpecialChar ~
16496 \SpecialChar ~
16497 \SpecialChar ~
16498 \SpecialChar ~
16499 \SpecialChar ~
16500 buffer point 
16501 \newline 
16502 ;;\SpecialChar ~
16503 x\SpecialChar ~
16504 \SpecialChar ~
16505 \SpecialChar ~
16506 \SpecialChar ~
16507 \SpecialChar ~
16508 \SpecialChar ~
16509 \SpecialChar ~
16510 \SpecialChar ~
16511 \SpecialChar ~
16512 \SpecialChar ~
16513 \SpecialChar ~
16514 \SpecialChar ~
16515 \SpecialChar ~
16516 \SpecialChar ~
16517 \SpecialChar ~
16518 sdcdbsrc-delete\SpecialChar ~
16519 \SpecialChar ~
16520 \SpecialChar ~
16521 \SpecialChar ~
16522 \SpecialChar ~
16523 \SpecialChar ~
16524 \SpecialChar ~
16525 \SpecialChar ~
16526 \SpecialChar ~
16527 \SpecialChar ~
16528 \SpecialChar ~
16529 \SpecialChar ~
16530 \SpecialChar ~
16531 \SpecialChar ~
16532 SDCDB Delete all breakpoints if no arg 
16533 \newline 
16534 ;;\SpecialChar ~
16535 \SpecialChar ~
16536 \SpecialChar ~
16537 \SpecialChar ~
16538 \SpecialChar ~
16539 \SpecialChar ~
16540 \SpecialChar ~
16541 \SpecialChar ~
16542 \SpecialChar ~
16543 \SpecialChar ~
16544 \SpecialChar ~
16545 \SpecialChar ~
16546 \SpecialChar ~
16547 \SpecialChar ~
16548 \SpecialChar ~
16549 \SpecialChar ~
16550 \SpecialChar ~
16551 \SpecialChar ~
16552 \SpecialChar ~
16553 \SpecialChar ~
16554 \SpecialChar ~
16555 \SpecialChar ~
16556 \SpecialChar ~
16557 \SpecialChar ~
16558 \SpecialChar ~
16559 \SpecialChar ~
16560 \SpecialChar ~
16561 \SpecialChar ~
16562 \SpecialChar ~
16563 \SpecialChar ~
16564 \SpecialChar ~
16565 \SpecialChar ~
16566 \SpecialChar ~
16567 \SpecialChar ~
16568 \SpecialChar ~
16569 \SpecialChar ~
16570 \SpecialChar ~
16571 \SpecialChar ~
16572 \SpecialChar ~
16573 \SpecialChar ~
16574 \SpecialChar ~
16575 \SpecialChar ~
16576 \SpecialChar ~
16577 \SpecialChar ~
16578 \SpecialChar ~
16579 \SpecialChar ~
16580 \SpecialChar ~
16581 given or delete arg (C-u arg x) 
16582 \newline 
16583 ;;\SpecialChar ~
16584 m\SpecialChar ~
16585 \SpecialChar ~
16586 \SpecialChar ~
16587 \SpecialChar ~
16588 \SpecialChar ~
16589 \SpecialChar ~
16590 \SpecialChar ~
16591 \SpecialChar ~
16592 \SpecialChar ~
16593 \SpecialChar ~
16594 \SpecialChar ~
16595 \SpecialChar ~
16596 \SpecialChar ~
16597 \SpecialChar ~
16598 \SpecialChar ~
16599 sdcdbsrc-frame\SpecialChar ~
16600 \SpecialChar ~
16601 \SpecialChar ~
16602 \SpecialChar ~
16603 \SpecialChar ~
16604 \SpecialChar ~
16605 \SpecialChar ~
16606 \SpecialChar ~
16607 \SpecialChar ~
16608 \SpecialChar ~
16609 \SpecialChar ~
16610 \SpecialChar ~
16611 \SpecialChar ~
16612 \SpecialChar ~
16613 \SpecialChar ~
16614 SDCDB Display current frame if no arg, 
16615 \newline 
16616 ;;\SpecialChar ~
16617 \SpecialChar ~
16618 \SpecialChar ~
16619 \SpecialChar ~
16620 \SpecialChar ~
16621 \SpecialChar ~
16622 \SpecialChar ~
16623 \SpecialChar ~
16624 \SpecialChar ~
16625 \SpecialChar ~
16626 \SpecialChar ~
16627 \SpecialChar ~
16628 \SpecialChar ~
16629 \SpecialChar ~
16630 \SpecialChar ~
16631 \SpecialChar ~
16632 \SpecialChar ~
16633 \SpecialChar ~
16634 \SpecialChar ~
16635 \SpecialChar ~
16636 \SpecialChar ~
16637 \SpecialChar ~
16638 \SpecialChar ~
16639 \SpecialChar ~
16640 \SpecialChar ~
16641 \SpecialChar ~
16642 \SpecialChar ~
16643 \SpecialChar ~
16644 \SpecialChar ~
16645 \SpecialChar ~
16646 \SpecialChar ~
16647 \SpecialChar ~
16648 \SpecialChar ~
16649 \SpecialChar ~
16650 \SpecialChar ~
16651 \SpecialChar ~
16652 \SpecialChar ~
16653 \SpecialChar ~
16654 \SpecialChar ~
16655 \SpecialChar ~
16656 \SpecialChar ~
16657 \SpecialChar ~
16658 \SpecialChar ~
16659 \SpecialChar ~
16660 \SpecialChar ~
16661 \SpecialChar ~
16662 \SpecialChar ~
16663 given or display frame arg 
16664 \newline 
16665 ;;\SpecialChar ~
16666 \SpecialChar ~
16667 \SpecialChar ~
16668 \SpecialChar ~
16669 \SpecialChar ~
16670 \SpecialChar ~
16671 \SpecialChar ~
16672 \SpecialChar ~
16673 \SpecialChar ~
16674 \SpecialChar ~
16675 \SpecialChar ~
16676 \SpecialChar ~
16677 \SpecialChar ~
16678 \SpecialChar ~
16679 \SpecialChar ~
16680 \SpecialChar ~
16681 \SpecialChar ~
16682 \SpecialChar ~
16683 \SpecialChar ~
16684 \SpecialChar ~
16685 \SpecialChar ~
16686 \SpecialChar ~
16687 \SpecialChar ~
16688 \SpecialChar ~
16689 \SpecialChar ~
16690 \SpecialChar ~
16691 \SpecialChar ~
16692 \SpecialChar ~
16693 \SpecialChar ~
16694 \SpecialChar ~
16695 \SpecialChar ~
16696 \SpecialChar ~
16697 \SpecialChar ~
16698 \SpecialChar ~
16699 \SpecialChar ~
16700 \SpecialChar ~
16701 \SpecialChar ~
16702 \SpecialChar ~
16703 \SpecialChar ~
16704 \SpecialChar ~
16705 \SpecialChar ~
16706 \SpecialChar ~
16707 \SpecialChar ~
16708 \SpecialChar ~
16709 \SpecialChar ~
16710 \SpecialChar ~
16711 \SpecialChar ~
16712 buffer point 
16713 \newline 
16714 ;;\SpecialChar ~
16715 !\SpecialChar ~
16716 \SpecialChar ~
16717 \SpecialChar ~
16718 \SpecialChar ~
16719 \SpecialChar ~
16720 \SpecialChar ~
16721 \SpecialChar ~
16722 \SpecialChar ~
16723 \SpecialChar ~
16724 \SpecialChar ~
16725 \SpecialChar ~
16726 \SpecialChar ~
16727 \SpecialChar ~
16728 \SpecialChar ~
16729 \SpecialChar ~
16730 sdcdbsrc-goto-sdcdb\SpecialChar ~
16731 \SpecialChar ~
16732 \SpecialChar ~
16733 \SpecialChar ~
16734 \SpecialChar ~
16735 \SpecialChar ~
16736 \SpecialChar ~
16737 \SpecialChar ~
16738 \SpecialChar ~
16739 \SpecialChar ~
16740 Goto the SDCDB output buffer 
16741 \newline 
16742 ;;\SpecialChar ~
16743 p\SpecialChar ~
16744 \SpecialChar ~
16745 \SpecialChar ~
16746 \SpecialChar ~
16747 \SpecialChar ~
16748 \SpecialChar ~
16749 \SpecialChar ~
16750 \SpecialChar ~
16751 \SpecialChar ~
16752 \SpecialChar ~
16753 \SpecialChar ~
16754 \SpecialChar ~
16755 \SpecialChar ~
16756 \SpecialChar ~
16757 \SpecialChar ~
16758 sdcdb-print-c-sexp\SpecialChar ~
16759 \SpecialChar ~
16760 \SpecialChar ~
16761 \SpecialChar ~
16762 \SpecialChar ~
16763 \SpecialChar ~
16764 \SpecialChar ~
16765 \SpecialChar ~
16766 \SpecialChar ~
16767 \SpecialChar ~
16768 \SpecialChar ~
16769 SDCDB print command for data at 
16770 \newline 
16771 ;;\SpecialChar ~
16772 \SpecialChar ~
16773 \SpecialChar ~
16774 \SpecialChar ~
16775 \SpecialChar ~
16776 \SpecialChar ~
16777 \SpecialChar ~
16778 \SpecialChar ~
16779 \SpecialChar ~
16780 \SpecialChar ~
16781 \SpecialChar ~
16782 \SpecialChar ~
16783 \SpecialChar ~
16784 \SpecialChar ~
16785 \SpecialChar ~
16786 \SpecialChar ~
16787 \SpecialChar ~
16788 \SpecialChar ~
16789 \SpecialChar ~
16790 \SpecialChar ~
16791 \SpecialChar ~
16792 \SpecialChar ~
16793 \SpecialChar ~
16794 \SpecialChar ~
16795 \SpecialChar ~
16796 \SpecialChar ~
16797 \SpecialChar ~
16798 \SpecialChar ~
16799 \SpecialChar ~
16800 \SpecialChar ~
16801 \SpecialChar ~
16802 \SpecialChar ~
16803 \SpecialChar ~
16804 \SpecialChar ~
16805 \SpecialChar ~
16806 \SpecialChar ~
16807 \SpecialChar ~
16808 \SpecialChar ~
16809 \SpecialChar ~
16810 \SpecialChar ~
16811 \SpecialChar ~
16812 \SpecialChar ~
16813 \SpecialChar ~
16814 \SpecialChar ~
16815 \SpecialChar ~
16816 \SpecialChar ~
16817 \SpecialChar ~
16818 buffer point 
16819 \newline 
16820 ;;\SpecialChar ~
16821 g\SpecialChar ~
16822 \SpecialChar ~
16823 \SpecialChar ~
16824 \SpecialChar ~
16825 \SpecialChar ~
16826 \SpecialChar ~
16827 \SpecialChar ~
16828 \SpecialChar ~
16829 \SpecialChar ~
16830 \SpecialChar ~
16831 \SpecialChar ~
16832 \SpecialChar ~
16833 \SpecialChar ~
16834 \SpecialChar ~
16835 \SpecialChar ~
16836 sdcdbsrc-goto-sdcdb\SpecialChar ~
16837 \SpecialChar ~
16838 \SpecialChar ~
16839 \SpecialChar ~
16840 \SpecialChar ~
16841 \SpecialChar ~
16842 \SpecialChar ~
16843 \SpecialChar ~
16844 \SpecialChar ~
16845 \SpecialChar ~
16846 Goto the SDCDB output buffer 
16847 \newline 
16848 ;;\SpecialChar ~
16849 t\SpecialChar ~
16850 \SpecialChar ~
16851 \SpecialChar ~
16852 \SpecialChar ~
16853 \SpecialChar ~
16854 \SpecialChar ~
16855 \SpecialChar ~
16856 \SpecialChar ~
16857 \SpecialChar ~
16858 \SpecialChar ~
16859 \SpecialChar ~
16860 \SpecialChar ~
16861 \SpecialChar ~
16862 \SpecialChar ~
16863 \SpecialChar ~
16864 sdcdbsrc-mode\SpecialChar ~
16865 \SpecialChar ~
16866 \SpecialChar ~
16867 \SpecialChar ~
16868 \SpecialChar ~
16869 \SpecialChar ~
16870 \SpecialChar ~
16871 \SpecialChar ~
16872 \SpecialChar ~
16873 \SpecialChar ~
16874 \SpecialChar ~
16875 \SpecialChar ~
16876 \SpecialChar ~
16877 \SpecialChar ~
16878 \SpecialChar ~
16879 \SpecialChar ~
16880 Toggles Sdcdbsrc mode (turns it off) 
16881 \newline 
16882 ;; 
16883 \newline 
16884 ;;\SpecialChar ~
16885 C-c\SpecialChar ~
16886 C-f\SpecialChar ~
16887 \SpecialChar ~
16888 \SpecialChar ~
16889 \SpecialChar ~
16890 \SpecialChar ~
16891 \SpecialChar ~
16892 \SpecialChar ~
16893 \SpecialChar ~
16894 \SpecialChar ~
16895 sdcdb-finish-from-src\SpecialChar ~
16896 \SpecialChar ~
16897 \SpecialChar ~
16898 \SpecialChar ~
16899 \SpecialChar ~
16900 \SpecialChar ~
16901 \SpecialChar ~
16902 \SpecialChar ~
16903 SDCDB finish command 
16904 \newline 
16905 ;; 
16906 \newline 
16907 ;;\SpecialChar ~
16908 C-x\SpecialChar ~
16909 SPC\SpecialChar ~
16910 \SpecialChar ~
16911 \SpecialChar ~
16912 \SpecialChar ~
16913 \SpecialChar ~
16914 \SpecialChar ~
16915 \SpecialChar ~
16916 \SpecialChar ~
16917 \SpecialChar ~
16918 sdcdb-break\SpecialChar ~
16919 \SpecialChar ~
16920 \SpecialChar ~
16921 \SpecialChar ~
16922 \SpecialChar ~
16923 \SpecialChar ~
16924 \SpecialChar ~
16925 \SpecialChar ~
16926 \SpecialChar ~
16927 \SpecialChar ~
16928 \SpecialChar ~
16929 \SpecialChar ~
16930 \SpecialChar ~
16931 \SpecialChar ~
16932 \SpecialChar ~
16933 \SpecialChar ~
16934 \SpecialChar ~
16935 \SpecialChar ~
16936 Set break for line with point 
16937 \newline 
16938 ;;\SpecialChar ~
16939 ESC\SpecialChar ~
16940 t\SpecialChar ~
16941 \SpecialChar ~
16942 \SpecialChar ~
16943 \SpecialChar ~
16944 \SpecialChar ~
16945 \SpecialChar ~
16946 \SpecialChar ~
16947 \SpecialChar ~
16948 \SpecialChar ~
16949 \SpecialChar ~
16950 \SpecialChar ~
16951 sdcdbsrc-mode\SpecialChar ~
16952 \SpecialChar ~
16953 \SpecialChar ~
16954 \SpecialChar ~
16955 \SpecialChar ~
16956 \SpecialChar ~
16957 \SpecialChar ~
16958 \SpecialChar ~
16959 \SpecialChar ~
16960 \SpecialChar ~
16961 \SpecialChar ~
16962 \SpecialChar ~
16963 \SpecialChar ~
16964 \SpecialChar ~
16965 \SpecialChar ~
16966 \SpecialChar ~
16967 Toggle Sdcdbsrc mode 
16968 \newline 
16969 ;;\SpecialChar ~
16970 ESC\SpecialChar ~
16971 m\SpecialChar ~
16972 \SpecialChar ~
16973 \SpecialChar ~
16974 \SpecialChar ~
16975 \SpecialChar ~
16976 \SpecialChar ~
16977 \SpecialChar ~
16978 \SpecialChar ~
16979 \SpecialChar ~
16980 \SpecialChar ~
16981 \SpecialChar ~
16982 sdcdbsrc-srcmode\SpecialChar ~
16983 \SpecialChar ~
16984 \SpecialChar ~
16985 \SpecialChar ~
16986 \SpecialChar ~
16987 \SpecialChar ~
16988 \SpecialChar ~
16989 \SpecialChar ~
16990 \SpecialChar ~
16991 \SpecialChar ~
16992 \SpecialChar ~
16993 \SpecialChar ~
16994 \SpecialChar ~
16995 Toggle list mode 
16996 \newline 
16997 ;; 
16998 \newline 
16999
17000 \layout Chapter
17001 \pagebreak_top 
17002 TIPS
17003 \layout Standard
17004
17005 Here are a few guidelines that will help the compiler generate more efficient
17006  code, some of the tips are specific to this compiler others are generally
17007  good programming practice.
17008 \layout Itemize
17009
17010 Use the smallest data type to represent your data-value.
17011  If it is known in advance that the value is going to be less than 256 then
17012  use an 'unsigned char' instead of a 'short' or 'int'.
17013  Please note, that ANSI C requires both signed and unsigned chars to be
17014  promoted to 'signed int' before doing any operation.
17015  This promotion can be omitted, if the result is the same.
17016  The effect of the promotion rules together with the sign-extension is often
17017  surprising:
17018 \begin_deeper 
17019 \layout Verse
17020
17021
17022 \family typewriter 
17023 unsigned char uc = 0xfe;
17024 \newline 
17025 if (uc * uc < 0) /* this is true! */
17026 \newline 
17027 {
17028 \newline 
17029 \SpecialChar ~
17030 \SpecialChar ~
17031 \SpecialChar ~
17032 \SpecialChar ~
17033 ....
17034 \newline 
17035 }
17036 \layout Standard
17037
17038
17039 \family typewriter 
17040 uc * uc
17041 \family default 
17042  is evaluated as 
17043 \family typewriter 
17044 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
17045 \family default 
17046 .
17047  
17048 \newline 
17049 Another one:
17050 \layout Verse
17051
17052
17053 \family typewriter 
17054 (unsigned char) -12 / (signed char) -3 = ...
17055 \layout Standard
17056
17057 No, the result is not 4:
17058 \layout Verse
17059
17060
17061 \family typewriter 
17062 (int) (unsigned char) -12 / (int) (signed char) -3 =
17063 \newline 
17064 (int) (unsigned char) 0xf4 / (int) (signed char) 0xfd =
17065 \newline 
17066 (int) 0x00f4 / (int) 0xfffd =
17067 \newline 
17068 (int) 0x00f4 / (int) 0xfffd =
17069 \newline 
17070 (int) 244 / (int) -3 =
17071 \newline 
17072 (int) -81 = (int) 0xffaf;
17073 \layout Standard
17074
17075 Don't complain, that gcc gives you a different result.
17076  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
17077  Therefore the results are different.
17078 \newline 
17079 From 
17080 \begin_inset Quotes sld
17081 \end_inset 
17082
17083 comp.lang.c FAQ
17084 \begin_inset Quotes srd
17085 \end_inset 
17086
17087 :
17088 \layout Quote
17089
17090 If well-defined overflow characteristics are important and negative values
17091  are not, or if you want to steer clear of sign-extension problems when
17092  manipulating bits or bytes, use one of the corresponding unsigned types.
17093  (Beware when mixing signed and unsigned values in expressions, though.)
17094 \newline 
17095 Although character types (especially unsigned char) can be used as "tiny"
17096  integers, doing so is sometimes more trouble than it's worth, due to unpredicta
17097 ble sign extension and increased code size.
17098 \end_deeper 
17099 \layout Itemize
17100
17101 Use unsigned when it is known in advance that the value is not going to
17102  be negative.
17103  This helps especially if you are doing division or multiplication, bit-shifting
17104  or are using an array index.
17105 \layout Itemize
17106
17107 NEVER jump into a LOOP.
17108 \layout Itemize
17109
17110 Declare the variables to be local
17111 \begin_inset LatexCommand \index{local variables}
17112
17113 \end_inset 
17114
17115  whenever possible, especially loop control variables (induction).
17116 \layout Itemize
17117
17118 Since the compiler does not always do implicit integral promotion, the programme
17119 r should do an explicit cast when integral promotion is required.
17120 \layout Itemize
17121
17122 Reducing the size of division, multiplication & modulus operations can reduce
17123  code size substantially.
17124  Take the following code for example.
17125 \begin_deeper 
17126 \layout Verse
17127
17128
17129 \family typewriter 
17130 foobar(unsigned int p1, unsigned char ch)
17131 \newline 
17132 {
17133 \newline 
17134 \SpecialChar ~
17135 \SpecialChar ~
17136 \SpecialChar ~
17137 \SpecialChar ~
17138 unsigned char ch1 = p1 % ch ;
17139 \newline 
17140 \SpecialChar ~
17141 \SpecialChar ~
17142 \SpecialChar ~
17143 \SpecialChar ~
17144 ....
17145 \newline 
17146 }
17147 \layout Standard
17148
17149 For the modulus operation the variable ch will be promoted to unsigned int
17150  first then the modulus operation will be performed (this will lead to a
17151  call to support routine _moduint()), and the result will be casted to a
17152  char.
17153  If the code is changed to 
17154 \layout Verse
17155
17156
17157 \family typewriter 
17158 foobar(unsigned int p1, unsigned char ch)
17159 \newline 
17160 {
17161 \newline 
17162 \SpecialChar ~
17163 \SpecialChar ~
17164 \SpecialChar ~
17165 \SpecialChar ~
17166 unsigned char ch1 = (unsigned char)p1 % ch ;
17167 \newline 
17168 \SpecialChar ~
17169 \SpecialChar ~
17170 \SpecialChar ~
17171 \SpecialChar ~
17172 ....
17173 \newline 
17174 }
17175 \layout Standard
17176
17177 It would substantially reduce the code generated (future versions of the
17178  compiler will be smart enough to detect such optimization opportunities).
17179 \end_deeper 
17180 \layout Itemize
17181
17182 Have a look at the assembly listing to get a 
17183 \begin_inset Quotes sld
17184 \end_inset 
17185
17186 feeling
17187 \begin_inset Quotes srd
17188 \end_inset 
17189
17190  for the code generation.
17191 \layout Section
17192
17193 Tools
17194 \begin_inset LatexCommand \index{Tools}
17195
17196 \end_inset 
17197
17198  included in the distribution
17199 \layout Standard
17200 \align center 
17201
17202 \begin_inset  Tabular
17203 <lyxtabular version="3" rows="12" columns="3">
17204 <features>
17205 <column alignment="center" valignment="top" leftline="true" width="0pt">
17206 <column alignment="center" valignment="top" leftline="true" width="0pt">
17207 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
17208 <row topline="true" bottomline="true">
17209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17210 \begin_inset Text
17211
17212 \layout Standard
17213
17214 Name
17215 \end_inset 
17216 </cell>
17217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17218 \begin_inset Text
17219
17220 \layout Standard
17221
17222 Purpose
17223 \end_inset 
17224 </cell>
17225 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17226 \begin_inset Text
17227
17228 \layout Standard
17229
17230 Directory
17231 \end_inset 
17232 </cell>
17233 </row>
17234 <row topline="true">
17235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17236 \begin_inset Text
17237
17238 \layout Standard
17239
17240 uCsim
17241 \end_inset 
17242 </cell>
17243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17244 \begin_inset Text
17245
17246 \layout Standard
17247
17248 Simulator for various architectures
17249 \end_inset 
17250 </cell>
17251 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17252 \begin_inset Text
17253
17254 \layout Standard
17255
17256 sdcc/sim/ucsim
17257 \end_inset 
17258 </cell>
17259 </row>
17260 <row topline="true">
17261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17262 \begin_inset Text
17263
17264 \layout Standard
17265
17266 keil2sdcc.pl
17267 \end_inset 
17268 </cell>
17269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17270 \begin_inset Text
17271
17272 \layout Standard
17273
17274 header file conversion
17275 \end_inset 
17276 </cell>
17277 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17278 \begin_inset Text
17279
17280 \layout Standard
17281
17282 sdcc/support/scripts
17283 \end_inset 
17284 </cell>
17285 </row>
17286 <row topline="true">
17287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17288 \begin_inset Text
17289
17290 \layout Standard
17291
17292 mh2h.c
17293 \end_inset 
17294 </cell>
17295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17296 \begin_inset Text
17297
17298 \layout Standard
17299
17300 header file conversion
17301 \end_inset 
17302 </cell>
17303 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17304 \begin_inset Text
17305
17306 \layout Standard
17307
17308 sdcc/support/scripts
17309 \end_inset 
17310 </cell>
17311 </row>
17312 <row topline="true">
17313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17314 \begin_inset Text
17315
17316 \layout Standard
17317
17318 as-gbz80
17319 \end_inset 
17320 </cell>
17321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17322 \begin_inset Text
17323
17324 \layout Standard
17325
17326 Assembler
17327 \end_inset 
17328 </cell>
17329 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17330 \begin_inset Text
17331
17332 \layout Standard
17333
17334
17335 \family roman 
17336 \series medium 
17337 \shape up 
17338 \size normal 
17339 \emph off 
17340 \bar no 
17341 \noun off 
17342 \color none
17343 sdcc/bin
17344 \end_inset 
17345 </cell>
17346 </row>
17347 <row topline="true">
17348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17349 \begin_inset Text
17350
17351 \layout Standard
17352
17353 as-z80
17354 \end_inset 
17355 </cell>
17356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17357 \begin_inset Text
17358
17359 \layout Standard
17360
17361 Assembler
17362 \end_inset 
17363 </cell>
17364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17365 \begin_inset Text
17366
17367 \layout Standard
17368
17369
17370 \family roman 
17371 \series medium 
17372 \shape up 
17373 \size normal 
17374 \emph off 
17375 \bar no 
17376 \noun off 
17377 \color none
17378 sdcc/bin
17379 \end_inset 
17380 </cell>
17381 </row>
17382 <row topline="true">
17383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17384 \begin_inset Text
17385
17386 \layout Standard
17387
17388 asx8051
17389 \end_inset 
17390 </cell>
17391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17392 \begin_inset Text
17393
17394 \layout Standard
17395
17396 Assembler
17397 \end_inset 
17398 </cell>
17399 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17400 \begin_inset Text
17401
17402 \layout Standard
17403
17404
17405 \family roman 
17406 \series medium 
17407 \shape up 
17408 \size normal 
17409 \emph off 
17410 \bar no 
17411 \noun off 
17412 \color none
17413 sdcc/bin
17414 \end_inset 
17415 </cell>
17416 </row>
17417 <row topline="true">
17418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17419 \begin_inset Text
17420
17421 \layout Standard
17422
17423 sdcdb
17424 \end_inset 
17425 </cell>
17426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17427 \begin_inset Text
17428
17429 \layout Standard
17430
17431 Simulator
17432 \end_inset 
17433 </cell>
17434 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17435 \begin_inset Text
17436
17437 \layout Standard
17438
17439
17440 \family roman 
17441 \series medium 
17442 \shape up 
17443 \size normal 
17444 \emph off 
17445 \bar no 
17446 \noun off 
17447 \color none
17448 sdcc/bin
17449 \end_inset 
17450 </cell>
17451 </row>
17452 <row topline="true">
17453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17454 \begin_inset Text
17455
17456 \layout Standard
17457
17458 aslink
17459 \end_inset 
17460 </cell>
17461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17462 \begin_inset Text
17463
17464 \layout Standard
17465
17466 Linker
17467 \end_inset 
17468 </cell>
17469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17470 \begin_inset Text
17471
17472 \layout Standard
17473
17474
17475 \family roman 
17476 \series medium 
17477 \shape up 
17478 \size normal 
17479 \emph off 
17480 \bar no 
17481 \noun off 
17482 \color none
17483 sdcc/bin
17484 \end_inset 
17485 </cell>
17486 </row>
17487 <row topline="true">
17488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17489 \begin_inset Text
17490
17491 \layout Standard
17492
17493 link-z80
17494 \end_inset 
17495 </cell>
17496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17497 \begin_inset Text
17498
17499 \layout Standard
17500
17501 Linker
17502 \end_inset 
17503 </cell>
17504 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17505 \begin_inset Text
17506
17507 \layout Standard
17508
17509
17510 \family roman 
17511 \series medium 
17512 \shape up 
17513 \size normal 
17514 \emph off 
17515 \bar no 
17516 \noun off 
17517 \color none
17518 sdcc/bin
17519 \end_inset 
17520 </cell>
17521 </row>
17522 <row topline="true">
17523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17524 \begin_inset Text
17525
17526 \layout Standard
17527
17528 link-gbz80
17529 \end_inset 
17530 </cell>
17531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17532 \begin_inset Text
17533
17534 \layout Standard
17535
17536 Linker
17537 \end_inset 
17538 </cell>
17539 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17540 \begin_inset Text
17541
17542 \layout Standard
17543
17544
17545 \family roman 
17546 \series medium 
17547 \shape up 
17548 \size normal 
17549 \emph off 
17550 \bar no 
17551 \noun off 
17552 \color none
17553 sdcc/bin
17554 \end_inset 
17555 </cell>
17556 </row>
17557 <row topline="true" bottomline="true">
17558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17559 \begin_inset Text
17560
17561 \layout Standard
17562
17563 packihx
17564 \end_inset 
17565 </cell>
17566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17567 \begin_inset Text
17568
17569 \layout Standard
17570
17571 ihx packer
17572 \end_inset 
17573 </cell>
17574 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17575 \begin_inset Text
17576
17577 \layout Standard
17578
17579
17580 \family roman 
17581 \series medium 
17582 \shape up 
17583 \size normal 
17584 \emph off 
17585 \bar no 
17586 \noun off 
17587 \color none
17588 sdcc/bin
17589 \end_inset 
17590 </cell>
17591 </row>
17592 </lyxtabular>
17593
17594 \end_inset 
17595
17596
17597 \newline 
17598
17599 \layout Section
17600
17601 Documentation
17602 \begin_inset LatexCommand \index{Documentation}
17603
17604 \end_inset 
17605
17606  included in the distribution
17607 \layout Standard
17608 \align center 
17609
17610 \begin_inset  Tabular
17611 <lyxtabular version="3" rows="10" columns="2">
17612 <features>
17613 <column alignment="left" valignment="top" leftline="true" width="0">
17614 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
17615 <row topline="true" bottomline="true">
17616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17617 \begin_inset Text
17618
17619 \layout Standard
17620
17621 Subject / Title
17622 \end_inset 
17623 </cell>
17624 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17625 \begin_inset Text
17626
17627 \layout Standard
17628
17629 Where to get / filename
17630 \end_inset 
17631 </cell>
17632 </row>
17633 <row topline="true">
17634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17635 \begin_inset Text
17636
17637 \layout Standard
17638
17639 SDCC Compiler User Guide
17640 \end_inset 
17641 </cell>
17642 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17643 \begin_inset Text
17644
17645 \layout Standard
17646
17647 You're reading it right now
17648 \end_inset 
17649 </cell>
17650 </row>
17651 <row topline="true">
17652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17653 \begin_inset Text
17654
17655 \layout Standard
17656
17657 Changelog of SDCC
17658 \end_inset 
17659 </cell>
17660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17661 \begin_inset Text
17662
17663 \layout Standard
17664
17665 sdcc/Changelog
17666 \end_inset 
17667 </cell>
17668 </row>
17669 <row topline="true">
17670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17671 \begin_inset Text
17672
17673 \layout Standard
17674
17675 ASXXXX Assemblers and ASLINK Relocating Linker
17676 \end_inset 
17677 </cell>
17678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17679 \begin_inset Text
17680
17681 \layout Standard
17682
17683 sdcc/as/doc/asxhtm.html
17684 \end_inset 
17685 </cell>
17686 </row>
17687 <row topline="true">
17688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17689 \begin_inset Text
17690
17691 \layout Standard
17692
17693 SDCC regression test
17694 \begin_inset LatexCommand \index{Regression test}
17695
17696 \end_inset 
17697
17698
17699 \end_inset 
17700 </cell>
17701 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17702 \begin_inset Text
17703
17704 \layout Standard
17705
17706 sdcc/doc/test_suite_spec.pdf
17707 \end_inset 
17708 </cell>
17709 </row>
17710 <row topline="true">
17711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17712 \begin_inset Text
17713
17714 \layout Standard
17715
17716 Various notes
17717 \end_inset 
17718 </cell>
17719 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17720 \begin_inset Text
17721
17722 \layout Standard
17723
17724 sdcc/doc/*
17725 \end_inset 
17726 </cell>
17727 </row>
17728 <row topline="true">
17729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17730 \begin_inset Text
17731
17732 \layout Standard
17733
17734 Notes on debugging with sdcdb
17735 \begin_inset LatexCommand \index{sdcdb (debugger)}
17736
17737 \end_inset 
17738
17739
17740 \end_inset 
17741 </cell>
17742 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17743 \begin_inset Text
17744
17745 \layout Standard
17746
17747 sdcc/debugger/README
17748 \end_inset 
17749 </cell>
17750 </row>
17751 <row topline="true">
17752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17753 \begin_inset Text
17754
17755 \layout Standard
17756
17757 Software simulator for microcontrollers
17758 \end_inset 
17759 </cell>
17760 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17761 \begin_inset Text
17762
17763 \layout Standard
17764
17765
17766 \family roman 
17767 \series medium 
17768 \shape up 
17769 \size normal 
17770 \emph off 
17771 \bar no 
17772 \noun off 
17773 \color none
17774 sdcc/sim/ucsim/doc
17775 \family default 
17776 \series default 
17777 \shape default 
17778 \size default 
17779 \emph default 
17780 \bar default 
17781 \noun default 
17782 \color default
17783 /index.html
17784 \end_inset 
17785 </cell>
17786 </row>
17787 <row topline="true">
17788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17789 \begin_inset Text
17790
17791 \layout Standard
17792
17793 Temporary notes on the pic16
17794 \begin_inset LatexCommand \index{PIC16}
17795
17796 \end_inset 
17797
17798  port
17799 \end_inset 
17800 </cell>
17801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17802 \begin_inset Text
17803
17804 \layout Standard
17805
17806 sdcc/src/pic16/NOTES
17807 \end_inset 
17808 </cell>
17809 </row>
17810 <row topline="true" bottomline="true">
17811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17812 \begin_inset Text
17813
17814 \layout Standard
17815
17816 SDCC internal documentation (debugging file format)
17817 \end_inset 
17818 </cell>
17819 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17820 \begin_inset Text
17821
17822 \layout Standard
17823
17824 sdcc/doc/
17825 \family roman 
17826 \series medium 
17827 \shape up 
17828 \size normal 
17829 \emph off 
17830 \bar no 
17831 \noun off 
17832 \color none
17833 cdbfileformat.pd
17834 \family default 
17835 \series default 
17836 \shape default 
17837 \size default 
17838 \emph default 
17839 \bar default 
17840 \noun default 
17841 \color default
17842 f
17843 \end_inset 
17844 </cell>
17845 </row>
17846 </lyxtabular>
17847
17848 \end_inset 
17849
17850
17851 \newline 
17852
17853 \layout Section
17854
17855 Related open source tools
17856 \begin_inset LatexCommand \index{Related tools}
17857
17858 \end_inset 
17859
17860
17861 \layout Standard
17862 \align center 
17863
17864 \begin_inset  Tabular
17865 <lyxtabular version="3" rows="11" columns="3">
17866 <features>
17867 <column alignment="center" valignment="top" leftline="true" width="0pt">
17868 <column alignment="block" valignment="top" leftline="true" width="30line%">
17869 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
17870 <row topline="true" bottomline="true">
17871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17872 \begin_inset Text
17873
17874 \layout Standard
17875
17876 Name
17877 \end_inset 
17878 </cell>
17879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17880 \begin_inset Text
17881
17882 \layout Standard
17883
17884 Purpose
17885 \end_inset 
17886 </cell>
17887 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17888 \begin_inset Text
17889
17890 \layout Standard
17891
17892 Where to get
17893 \end_inset 
17894 </cell>
17895 </row>
17896 <row topline="true">
17897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17898 \begin_inset Text
17899
17900 \layout Standard
17901
17902 gpsim
17903 \begin_inset LatexCommand \index{gpsim (pic simulator)}
17904
17905 \end_inset 
17906
17907
17908 \end_inset 
17909 </cell>
17910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17911 \begin_inset Text
17912
17913 \layout Standard
17914
17915 PIC simulator
17916 \end_inset 
17917 </cell>
17918 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17919 \begin_inset Text
17920
17921 \layout Standard
17922
17923
17924 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
17925
17926 \end_inset 
17927
17928
17929 \end_inset 
17930 </cell>
17931 </row>
17932 <row topline="true">
17933 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17934 \begin_inset Text
17935
17936 \layout Standard
17937
17938 gputils
17939 \begin_inset LatexCommand \index{gputils (pic tools)}
17940
17941 \end_inset 
17942
17943
17944 \end_inset 
17945 </cell>
17946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17947 \begin_inset Text
17948
17949 \layout Standard
17950
17951 GNU PIC utilities
17952 \end_inset 
17953 </cell>
17954 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17955 \begin_inset Text
17956
17957 \layout Standard
17958
17959
17960 \begin_inset LatexCommand \url{http://gputils.sourceforge.net/}
17961
17962 \end_inset 
17963
17964
17965 \end_inset 
17966 </cell>
17967 </row>
17968 <row topline="true">
17969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17970 \begin_inset Text
17971
17972 \layout Standard
17973
17974 flP5
17975 \end_inset 
17976 </cell>
17977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17978 \begin_inset Text
17979
17980 \layout Standard
17981
17982 PIC programmer
17983 \end_inset 
17984 </cell>
17985 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17986 \begin_inset Text
17987
17988 \layout Standard
17989
17990
17991 \begin_inset LatexCommand \url{http://digilander.libero.it/fbradasc/FLP5.html}
17992
17993 \end_inset 
17994
17995
17996 \end_inset 
17997 </cell>
17998 </row>
17999 <row topline="true">
18000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18001 \begin_inset Text
18002
18003 \layout Standard
18004
18005 indent
18006 \begin_inset LatexCommand \index{indent (source formatting tool)}
18007
18008 \end_inset 
18009
18010
18011 \end_inset 
18012 </cell>
18013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18014 \begin_inset Text
18015
18016 \layout Standard
18017
18018 Formats C source - Master of the white spaces
18019 \end_inset 
18020 </cell>
18021 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18022 \begin_inset Text
18023
18024 \layout Standard
18025
18026
18027 \begin_inset LatexCommand \url{http://home.hccnet.nl/d.ingamells/beautify.html}
18028
18029 \end_inset 
18030
18031
18032 \end_inset 
18033 </cell>
18034 </row>
18035 <row topline="true">
18036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18037 \begin_inset Text
18038
18039 \layout Standard
18040
18041 srecord
18042 \begin_inset LatexCommand \index{srecord (tool)}
18043
18044 \end_inset 
18045
18046
18047 \end_inset 
18048 </cell>
18049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18050 \begin_inset Text
18051
18052 \layout Standard
18053
18054 Object file conversion, checksumming, ...
18055 \end_inset 
18056 </cell>
18057 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18058 \begin_inset Text
18059
18060 \layout Standard
18061
18062
18063 \begin_inset LatexCommand \url{http://srecord.sourceforge.net/}
18064
18065 \end_inset 
18066
18067
18068 \end_inset 
18069 </cell>
18070 </row>
18071 <row topline="true">
18072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18073 \begin_inset Text
18074
18075 \layout Standard
18076
18077 objdump
18078 \begin_inset LatexCommand \index{objdump (tool)}
18079
18080 \end_inset 
18081
18082
18083 \end_inset 
18084 </cell>
18085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18086 \begin_inset Text
18087
18088 \layout Standard
18089
18090 Object file conversion, ...
18091 \end_inset 
18092 </cell>
18093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18094 \begin_inset Text
18095
18096 \layout Standard
18097
18098 Part of binutils (should be there anyway)
18099 \end_inset 
18100 </cell>
18101 </row>
18102 <row topline="true">
18103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18104 \begin_inset Text
18105
18106 \layout Standard
18107
18108 doxygen
18109 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
18110
18111 \end_inset 
18112
18113
18114 \end_inset 
18115 </cell>
18116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18117 \begin_inset Text
18118
18119 \layout Standard
18120
18121 Source code documentation system
18122 \end_inset 
18123 </cell>
18124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18125 \begin_inset Text
18126
18127 \layout Standard
18128
18129
18130 \begin_inset LatexCommand \url{http://www.doxygen.org}
18131
18132 \end_inset 
18133
18134
18135 \end_inset 
18136 </cell>
18137 </row>
18138 <row topline="true">
18139 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18140 \begin_inset Text
18141
18142 \layout Standard
18143
18144 kdevelop
18145 \end_inset 
18146 </cell>
18147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18148 \begin_inset Text
18149
18150 \layout Standard
18151
18152 IDE (has anyone tried integrating SDCC & sdcdb? Unix only)
18153 \end_inset 
18154 </cell>
18155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18156 \begin_inset Text
18157
18158 \layout Standard
18159
18160
18161 \begin_inset LatexCommand \url{http://www.kdevelop.org}
18162
18163 \end_inset 
18164
18165
18166 \end_inset 
18167 </cell>
18168 </row>
18169 <row topline="true">
18170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18171 \begin_inset Text
18172
18173 \layout Standard
18174
18175 splint
18176 \begin_inset LatexCommand \index{splint (syntax checking tool)}
18177
18178 \end_inset 
18179
18180
18181 \end_inset 
18182 </cell>
18183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18184 \begin_inset Text
18185
18186 \layout Standard
18187
18188 Statically checks c sources (has anyone adapted splint for SDCC?)
18189 \end_inset 
18190 </cell>
18191 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18192 \begin_inset Text
18193
18194 \layout Standard
18195
18196
18197 \begin_inset LatexCommand \url{http://www.splint.org}
18198
18199 \end_inset 
18200
18201
18202 \end_inset 
18203 </cell>
18204 </row>
18205 <row topline="true" bottomline="true">
18206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18207 \begin_inset Text
18208
18209 \layout Standard
18210
18211 ddd
18212 \begin_inset LatexCommand \index{ddd (debugger)}
18213
18214 \end_inset 
18215
18216
18217 \end_inset 
18218 </cell>
18219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18220 \begin_inset Text
18221
18222 \layout Standard
18223
18224 Debugger, serves nicely as GUI to sdcdb
18225 \begin_inset LatexCommand \index{sdcdb (debugger)}
18226
18227 \end_inset 
18228
18229  (Unix only)
18230 \end_inset 
18231 </cell>
18232 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18233 \begin_inset Text
18234
18235 \layout Standard
18236
18237
18238 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
18239
18240 \end_inset 
18241
18242
18243 \end_inset 
18244 </cell>
18245 </row>
18246 </lyxtabular>
18247
18248 \end_inset 
18249
18250
18251 \newline 
18252
18253 \layout Section
18254
18255 Related documentation / recommended reading
18256 \layout Standard
18257 \align center 
18258
18259 \begin_inset  Tabular
18260 <lyxtabular version="3" rows="6" columns="3">
18261 <features>
18262 <column alignment="center" valignment="top" leftline="true" width="0pt">
18263 <column alignment="block" valignment="top" leftline="true" width="30line%">
18264 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
18265 <row topline="true" bottomline="true">
18266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18267 \begin_inset Text
18268
18269 \layout Standard
18270
18271 Name
18272 \end_inset 
18273 </cell>
18274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18275 \begin_inset Text
18276
18277 \layout Standard
18278
18279 Subject / Title
18280 \end_inset 
18281 </cell>
18282 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18283 \begin_inset Text
18284
18285 \layout Standard
18286
18287 Where to get
18288 \end_inset 
18289 </cell>
18290 </row>
18291 <row topline="true">
18292 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18293 \begin_inset Text
18294
18295 \layout Standard
18296
18297
18298 \family roman 
18299 \series medium 
18300 \shape up 
18301 \size normal 
18302 \emph off 
18303 \bar no 
18304 \noun off 
18305 \color none
18306 c-refcard.pdf
18307 \end_inset 
18308 </cell>
18309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18310 \begin_inset Text
18311
18312 \layout Standard
18313
18314 C Reference Card
18315 \begin_inset LatexCommand \index{C Reference card}
18316
18317 \end_inset 
18318
18319 , 2 pages
18320 \end_inset 
18321 </cell>
18322 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18323 \begin_inset Text
18324
18325 \layout Standard
18326
18327
18328 \begin_inset LatexCommand \url{http://www.refcards.com/about/c.html}
18329
18330 \end_inset 
18331
18332
18333 \end_inset 
18334 </cell>
18335 </row>
18336 <row topline="true">
18337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18338 \begin_inset Text
18339
18340 \layout Standard
18341
18342 c-faq
18343 \end_inset 
18344 </cell>
18345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18346 \begin_inset Text
18347
18348 \layout Standard
18349
18350 C-FAQ-list
18351 \end_inset 
18352 </cell>
18353 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18354 \begin_inset Text
18355
18356 \layout Standard
18357
18358
18359 \begin_inset LatexCommand \url{http://www.eskimo.com/~scs/C-faq/top.html}
18360
18361 \end_inset 
18362
18363
18364 \end_inset 
18365 </cell>
18366 </row>
18367 <row topline="true">
18368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18369 \begin_inset Text
18370
18371 \layout Standard
18372
18373 \end_inset 
18374 </cell>
18375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18376 \begin_inset Text
18377
18378 \layout Standard
18379
18380 Latest datasheet of the target CPU
18381 \end_inset 
18382 </cell>
18383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18384 \begin_inset Text
18385
18386 \layout Standard
18387
18388 vendor
18389 \end_inset 
18390 </cell>
18391 </row>
18392 <row topline="true">
18393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18394 \begin_inset Text
18395
18396 \layout Standard
18397
18398 \end_inset 
18399 </cell>
18400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18401 \begin_inset Text
18402
18403 \layout Standard
18404
18405 Revision history of datasheet
18406 \end_inset 
18407 </cell>
18408 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18409 \begin_inset Text
18410
18411 \layout Standard
18412
18413 vendor
18414 \end_inset 
18415 </cell>
18416 </row>
18417 <row topline="true" bottomline="true">
18418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18419 \begin_inset Text
18420
18421 \layout Standard
18422
18423 S.
18424  S.
18425  Muchnick
18426 \end_inset 
18427 </cell>
18428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18429 \begin_inset Text
18430
18431 \layout Standard
18432
18433 Advanced Compiler Design and Implementation
18434 \end_inset 
18435 </cell>
18436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18437 \begin_inset Text
18438
18439 \layout Standard
18440
18441 bookstore (very dedicated, probably read other books first)
18442 \end_inset 
18443 </cell>
18444 </row>
18445 </lyxtabular>
18446
18447 \end_inset 
18448
18449
18450 \newline 
18451
18452 \layout Section
18453
18454 Some Questions
18455 \layout Standard
18456
18457 Some questions answered, some pointers given - it might be time to in turn
18458  ask 
18459 \emph on 
18460 you
18461 \emph default 
18462  some questions: 
18463 \layout Itemize
18464
18465 can you solve your project with the selected microcontroller? Would you
18466  find out early or rather late that your target is too small/slow/whatever?
18467  Can you switch to a slightly better device if it doesn't fit?
18468 \layout Itemize
18469
18470 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
18471  and/or another programming language be more adequate? Would an operating
18472  system on the target device help?
18473 \layout Itemize
18474
18475 if you solved the problem, will the marketing department be happy?
18476 \layout Itemize
18477
18478 if the marketing department is happy, will customers be happy?
18479 \layout Itemize
18480
18481 if you're the project manager, marketing department and maybe even the customer
18482  in one person, have you tried to see the project from the outside?
18483 \layout Itemize
18484
18485 is the project done if you think it is done? Or is just that other interface/pro
18486 tocol/feature/configuration/option missing? How about website, manual(s),
18487  internationali(z|s)ation, packaging, labels, 2nd source for components,
18488  electromagnetic compatability/interference, documentation for production,
18489  production test software, update mechanism, patent issues?
18490 \layout Itemize
18491
18492 is your project adequately positioned in that magic triangle: fame, fortune,
18493  fun?
18494 \layout Standard
18495
18496 Maybe not all answers to these questions are known and some answers may
18497  even be 
18498 \emph on 
18499 no
18500 \emph default 
18501 , nevertheless knowing these questions may help you to avoid burnout
18502 \begin_inset Foot
18503 collapsed false
18504
18505 \layout Standard
18506
18507 burnout is bad for electronic devices, programmers and motorcycle tyres
18508 \end_inset 
18509
18510 .
18511  Chances are you didn't want to hear some of them...
18512 \layout Chapter
18513
18514 Support
18515 \begin_inset LatexCommand \index{Support}
18516
18517 \end_inset 
18518
18519
18520 \layout Standard
18521
18522 SDCC has grown to be a large project.
18523  The compiler alone (without the preprocessor, assembler and linker) is
18524  well over 100,000 lines of code (blank stripped).
18525  The open source nature of this project is a key to its continued growth
18526  and support.
18527  You gain the benefit and support of many active software developers and
18528  end users.
18529  Is SDCC perfect? No, that's why we need your help.
18530  The developers take pride in fixing reported bugs.
18531  You can help by reporting the bugs and helping other SDCC users.
18532  There are lots of ways to contribute, and we encourage you to take part
18533  in making SDCC a great software package.
18534  
18535 \layout Standard
18536
18537 The SDCC project is hosted on the SDCC sourceforge site at 
18538 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
18539
18540 \end_inset 
18541
18542 .
18543  You'll find the complete set of mailing lists
18544 \begin_inset LatexCommand \index{Mailing list(s)}
18545
18546 \end_inset 
18547
18548 , forums, bug reporting system, patch submission
18549 \begin_inset LatexCommand \index{Patch submission}
18550
18551 \end_inset 
18552
18553  system, download
18554 \begin_inset LatexCommand \index{download}
18555
18556 \end_inset 
18557
18558  area and cvs code repository
18559 \begin_inset LatexCommand \index{cvs code repository}
18560
18561 \end_inset 
18562
18563  there.
18564 \layout Section
18565
18566 Reporting Bugs
18567 \begin_inset LatexCommand \index{Bug reporting}
18568
18569 \end_inset 
18570
18571
18572 \begin_inset LatexCommand \index{Reporting bugs}
18573
18574 \end_inset 
18575
18576
18577 \layout Standard
18578
18579 The recommended way of reporting bugs is using the infrastructure of the
18580  sourceforge site.
18581  You can follow the status of bug reports there and have an overview about
18582  the known bugs.
18583 \layout Standard
18584
18585 Bug reports are automatically forwarded to the developer mailing list and
18586  will be fixed ASAP.
18587  When reporting a bug, it is very useful to include a small test program
18588  (the smaller the better) which reproduces the problem.
18589  If you can isolate the problem by looking at the generated assembly code,
18590  this can be very helpful.
18591  Compiling your program with the -
18592 \begin_inset ERT
18593 status Collapsed
18594
18595 \layout Standard
18596
18597 \backslash 
18598 /
18599 \end_inset 
18600
18601 -dumpall
18602 \begin_inset LatexCommand \index{-\/-dumpall}
18603
18604 \end_inset 
18605
18606  option can sometimes be useful in locating optimization problems.
18607  When reporting a bug please maker sure you:
18608 \layout Enumerate
18609
18610 Attach the code you are compiling with SDCC.
18611  
18612 \layout Enumerate
18613
18614 Specify the exact command you use to run SDCC, or attach your Makefile.
18615  
18616 \layout Enumerate
18617
18618 Specify the SDCC version (type "
18619 \family sans 
18620 \series bold 
18621 sdcc -v
18622 \family default 
18623 \series default 
18624 "), your platform, and operating system.
18625  
18626 \layout Enumerate
18627
18628 Provide an exact copy of any error message or incorrect output.
18629  
18630 \layout Enumerate
18631
18632 Put something meaningful in the subject of your message.
18633 \layout Standard
18634
18635 Please attempt to include these 5 important parts, as applicable, in all
18636  requests for support or when reporting any problems or bugs with SDCC.
18637  Though this will make your message lengthy, it will greatly improve your
18638  chance that SDCC users and developers will be able to help you.
18639  Some SDCC developers are frustrated by bug reports without code provided
18640  that they can use to reproduce and ultimately fix the problem, so please
18641  be sure to provide sample code if you are reporting a bug! 
18642 \layout Standard
18643
18644 Please have a short check that you are using a recent version of SDCC and
18645  the bug is not yet known.
18646  This is the link for reporting bugs: 
18647 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
18648
18649 \end_inset 
18650
18651 .
18652 \layout Section
18653
18654 Requesting Features
18655 \begin_inset LatexCommand \label{sub:Requesting-Features}
18656
18657 \end_inset 
18658
18659
18660 \begin_inset LatexCommand \index{Feature request}
18661
18662 \end_inset 
18663
18664
18665 \begin_inset LatexCommand \index{Requesting features}
18666
18667 \end_inset 
18668
18669
18670 \layout Standard
18671
18672 Like bug reports feature requests are forwarded to the developer mailing
18673  list.
18674  This is the link for requesting features: 
18675 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
18676
18677 \end_inset 
18678
18679 .
18680 \layout Section
18681
18682 Submitting patches
18683 \layout Standard
18684
18685 Like bug reports contributed patches are forwarded to the developer mailing
18686  list.
18687  This is the link for submitting patches
18688 \begin_inset LatexCommand \index{Patch submission}
18689
18690 \end_inset 
18691
18692
18693 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
18694
18695 \end_inset 
18696
18697 .
18698 \layout Standard
18699
18700 You need to specify some parameters to the 
18701 \family typewriter 
18702 diff
18703 \family default 
18704  command for the patches to be useful.
18705  If you modified more than one file a patch created f.e.
18706  with 
18707 \family sans 
18708 \series bold 
18709
18710 \begin_inset Quotes sld
18711 \end_inset 
18712
18713 diff -Naur unmodified_directory modified_directory >my_changes.patch
18714 \begin_inset Quotes srd
18715 \end_inset 
18716
18717
18718 \family default 
18719 \series default 
18720  will be fine, otherwise 
18721 \family sans 
18722 \series bold 
18723
18724 \begin_inset Quotes sld
18725 \end_inset 
18726
18727 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
18728 \begin_inset Quotes srd
18729 \end_inset 
18730
18731
18732 \series default 
18733  
18734 \family default 
18735 will do.
18736 \layout Section
18737
18738 Getting Help
18739 \layout Standard
18740
18741 These links should take you directly to the 
18742 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
18743
18744 \end_inset 
18745
18746
18747 \begin_inset Foot
18748 collapsed false
18749
18750 \layout Standard
18751
18752 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
18753  automated messages (mid 2003)
18754 \end_inset 
18755
18756  and the 
18757 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
18758
18759 \end_inset 
18760
18761 , lists
18762 \begin_inset LatexCommand \index{Mailing list(s)}
18763
18764 \end_inset 
18765
18766  and forums are archived and searchable so if you are lucky someone already
18767  had a similar problem.
18768  While mails to the lists themselves are delivered promptly their web front
18769  end on sourceforge sometimes shows a severe time lag (up to several weeks),
18770  if you're seriously using SDCC please consider subscribing to the lists.
18771 \layout Section
18772
18773 ChangeLog
18774 \layout Standard
18775
18776 You can follow the status of the cvs version
18777 \begin_inset LatexCommand \index{version}
18778
18779 \end_inset 
18780
18781  of SDCC by watching the Changelog
18782 \begin_inset LatexCommand \index{Changelog}
18783
18784 \end_inset 
18785
18786  in the cvs-repository
18787 \newline 
18788
18789 \size footnotesize 
18790
18791 \begin_inset LatexCommand \htmlurl{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/sdcc/sdcc/ChangeLog?rev=HEAD&content-type=text/plain}
18792
18793 \end_inset 
18794
18795 .
18796 \layout Section
18797
18798 Release policy
18799 \begin_inset LatexCommand \index{Release policy}
18800
18801 \end_inset 
18802
18803
18804 \layout Standard
18805
18806 Historically there often were long delays between official releases and
18807  the sourceforge download area tends to get not updated at all.
18808  Excuses in the past might have referred to problems with live range analysis,
18809  but as this was fixed a while ago, the current problem is that another
18810  excuse has to be found.
18811  Kidding aside, we have to get better there! On the other hand there are
18812  daily snapshots available at 
18813 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
18814
18815 \end_inset 
18816
18817 , and you can always build the very last version (hopefully with many bugs
18818  fixed, and features added) from the source code available at 
18819 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
18820
18821 \end_inset 
18822
18823 .
18824 \layout Section
18825
18826 Examples
18827 \begin_inset LatexCommand \index{Examples}
18828
18829 \end_inset 
18830
18831
18832 \layout Standard
18833
18834 You'll find some small examples in the directory 
18835 \emph on 
18836 sdcc/device/examples/.
18837  
18838 \emph default 
18839 More examples and libraries are available at
18840 \emph on 
18841  The SDCC Open Knowledge Resource 
18842 \begin_inset LatexCommand \url{http://www.qsl.net/dl9sec/SDCC_OKR.html}
18843
18844 \end_inset 
18845
18846  
18847 \emph default 
18848 web site or at 
18849 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
18850
18851 \end_inset 
18852
18853 .
18854 \layout Comment
18855
18856 I did insert a reference to Paul's web site here although it seems rather
18857  dedicated to a specific 8032 board (I think it's okay because it f.e.
18858  shows LCD/Harddisc interface and has a free 8051 monitor.
18859  Independent 8032 board vendors face hard competition of heavily subsidized
18860  development boards anyway).
18861 \layout Comment
18862
18863 Maybe we should include some links to real world applications.
18864  Preferably pointer to pointers (one for each architecture) so this stays
18865  manageable here?
18866 \layout Section
18867
18868 Quality control
18869 \begin_inset LatexCommand \index{Quality control}
18870
18871 \end_inset 
18872
18873
18874 \layout Standard
18875
18876 The compiler is passed through nightly compile and build checks.
18877  The so called 
18878 \shape italic 
18879 regression tests
18880 \shape default 
18881
18882 \begin_inset LatexCommand \index{Regression test}
18883
18884 \end_inset 
18885
18886  check that SDCC itself compiles flawlessly on several platforms and checks
18887  the quality of the code generated by SDCC by running the code through simulator
18888 s.
18889  There is a separate document 
18890 \shape italic 
18891 test_suite.pdf
18892 \begin_inset LatexCommand \index{Test suite}
18893
18894 \end_inset 
18895
18896
18897 \shape default 
18898  about this.
18899 \layout Standard
18900
18901 You'll find the test code in the directory 
18902 \shape italic 
18903 sdcc/support/regression
18904 \shape default 
18905 .
18906  You can run these tests manually by running 
18907 \family sans 
18908 make
18909 \family default 
18910  in this directory (or f.e.
18911  
18912 \family sans 
18913 \series bold 
18914
18915 \begin_inset Quotes sld
18916 \end_inset 
18917
18918 make test-mcs51
18919 \begin_inset Quotes srd
18920 \end_inset 
18921
18922
18923 \family default 
18924 \series default 
18925  if you don't want to run the complete tests).
18926  The test code might also be interesting if you want to look for examples
18927 \begin_inset LatexCommand \index{Examples}
18928
18929 \end_inset 
18930
18931  checking corner cases of SDCC or if you plan to submit patches
18932 \begin_inset LatexCommand \index{Patch submission}
18933
18934 \end_inset 
18935
18936 .
18937 \layout Standard
18938
18939 The pic port uses a different set of regression tests, you'll find them
18940  in the directory 
18941 \shape italic 
18942 sdcc/src/regression
18943 \shape default 
18944 .
18945 \layout Chapter
18946 \pagebreak_top 
18947 SDCC Technical Data
18948 \layout Section
18949
18950 Optimizations
18951 \begin_inset LatexCommand \index{Optimizations}
18952
18953 \end_inset 
18954
18955
18956 \layout Standard
18957
18958 SDCC performs a host of standard optimizations in addition to some MCU specific
18959  optimizations.
18960  
18961 \layout Subsection
18962
18963 Sub-expression Elimination
18964 \begin_inset LatexCommand \index{Subexpression elimination}
18965
18966 \end_inset 
18967
18968
18969 \layout Standard
18970
18971 The compiler does local and 
18972 \emph on 
18973 g
18974 \emph default 
18975 lobal 
18976 \emph on 
18977 c
18978 \emph default 
18979 ommon 
18980 \emph on 
18981 s
18982 \emph default 
18983 ubexpression 
18984 \emph on 
18985 e
18986 \emph default 
18987 limination, e.g.: 
18988 \layout Verse
18989
18990
18991 \family typewriter 
18992 i = x + y + 1; 
18993 \newline 
18994 j = x + y;
18995 \layout Standard
18996
18997 will be translated to
18998 \layout Verse
18999
19000
19001 \family typewriter 
19002 iTemp = x + y; 
19003 \newline 
19004 i = iTemp + 1; 
19005 \newline 
19006 j = iTemp;
19007 \layout Standard
19008
19009 Some subexpressions are not as obvious as the above example, e.g.:
19010 \layout Verse
19011
19012
19013 \family typewriter 
19014 a->b[i].c = 10; 
19015 \newline 
19016 a->b[i].d = 11;
19017 \layout Standard
19018
19019 In this case the address arithmetic a->b[i] will be computed only once;
19020  the equivalent code in C would be.
19021 \layout Verse
19022
19023
19024 \family typewriter 
19025 iTemp = a->b[i]; 
19026 \newline 
19027 iTemp.c = 10; 
19028 \newline 
19029 iTemp.d = 11;
19030 \layout Standard
19031
19032 The compiler will try to keep these temporary variables in registers.
19033 \layout Subsection
19034
19035 Dead-Code Elimination
19036 \begin_inset LatexCommand \index{Dead-code elimination}
19037
19038 \end_inset 
19039
19040
19041 \layout Verse
19042
19043
19044 \family typewriter 
19045 int global;
19046 \newline 
19047
19048 \newline 
19049 void f () { 
19050 \newline 
19051 \SpecialChar ~
19052 \SpecialChar ~
19053 int i; 
19054 \newline 
19055 \SpecialChar ~
19056 \SpecialChar ~
19057 i = 1; \SpecialChar ~
19058 \SpecialChar ~
19059 \SpecialChar ~
19060 \SpecialChar ~
19061 \SpecialChar ~
19062 /* dead store */ 
19063 \newline 
19064 \SpecialChar ~
19065 \SpecialChar ~
19066 global = 1;\SpecialChar ~
19067 /* dead store */ 
19068 \newline 
19069 \SpecialChar ~
19070 \SpecialChar ~
19071 global = 2; 
19072 \newline 
19073 \SpecialChar ~
19074 \SpecialChar ~
19075 return; 
19076 \newline 
19077 \SpecialChar ~
19078 \SpecialChar ~
19079 global = 3;\SpecialChar ~
19080 /* unreachable */ 
19081 \newline 
19082 }
19083 \layout Standard
19084
19085 will be changed to
19086 \layout Verse
19087
19088
19089 \family typewriter 
19090 int global;
19091 \newline 
19092
19093 \newline 
19094 void f () {
19095 \newline 
19096 \SpecialChar ~
19097 \SpecialChar ~
19098 global = 2; 
19099 \newline 
19100 \SpecialChar ~
19101 \SpecialChar ~
19102 return; 
19103 \newline 
19104 }
19105 \layout Subsection
19106
19107 Copy-Propagation
19108 \begin_inset LatexCommand \index{Copy propagation}
19109
19110 \end_inset 
19111
19112
19113 \layout Verse
19114
19115
19116 \family typewriter 
19117 int f() { 
19118 \newline 
19119 \SpecialChar ~
19120 \SpecialChar ~
19121 int i, j; 
19122 \newline 
19123 \SpecialChar ~
19124 \SpecialChar ~
19125 i = 10; 
19126 \newline 
19127 \SpecialChar ~
19128 \SpecialChar ~
19129 j = i; 
19130 \newline 
19131 \SpecialChar ~
19132 \SpecialChar ~
19133 return j; 
19134 \newline 
19135 }
19136 \layout Standard
19137
19138 will be changed to 
19139 \layout Verse
19140
19141
19142 \family typewriter 
19143 int f() { 
19144 \newline 
19145 \SpecialChar ~
19146 \SpecialChar ~
19147 int i, j; 
19148 \newline 
19149 \SpecialChar ~
19150 \SpecialChar ~
19151 i = 10; 
19152 \newline 
19153 \SpecialChar ~
19154 \SpecialChar ~
19155 j = 10; 
19156 \newline 
19157 \SpecialChar ~
19158 \SpecialChar ~
19159 return 10; 
19160 \newline 
19161 }
19162 \layout Standard
19163
19164 Note: the dead stores created by this copy propagation will be eliminated
19165  by dead-code elimination.
19166 \layout Subsection
19167
19168 Loop Optimizations
19169 \begin_inset LatexCommand \index{Loop optimization}
19170
19171 \end_inset 
19172
19173
19174 \layout Standard
19175
19176 Two types of loop optimizations are done by SDCC loop invariant lifting
19177  and strength reduction of loop induction variables.
19178  In addition to the strength reduction the optimizer marks the induction
19179  variables and the register allocator tries to keep the induction variables
19180  in registers for the duration of the loop.
19181  Because of this preference of the register allocator
19182 \begin_inset LatexCommand \index{Register allocation}
19183
19184 \end_inset 
19185
19186 , loop induction optimization causes an increase in register pressure, which
19187  may cause unwanted spilling of other temporary variables into the stack
19188 \begin_inset LatexCommand \index{stack}
19189
19190 \end_inset 
19191
19192  / data space.
19193  The compiler will generate a warning message when it is forced to allocate
19194  extra space either on the stack or data space.
19195  If this extra space allocation is undesirable then induction optimization
19196  can be eliminated either for the entire source file (with -
19197 \begin_inset ERT
19198 status Collapsed
19199
19200 \layout Standard
19201
19202 \backslash 
19203 /
19204 \end_inset 
19205
19206 -noinduction option) or for a given function only using #pragma\SpecialChar ~
19207 noinduction
19208 \begin_inset LatexCommand \index{\#pragma noinduction}
19209
19210 \end_inset 
19211
19212 .
19213 \newline 
19214
19215 \newline 
19216 Loop Invariant:
19217 \layout Verse
19218
19219
19220 \family typewriter 
19221 for (i = 0 ; i < 100 ; i ++) 
19222 \newline 
19223 \SpecialChar ~
19224 \SpecialChar ~
19225 \SpecialChar ~
19226 \SpecialChar ~
19227 f += k + l;
19228 \layout Standard
19229
19230 changed to
19231 \layout Verse
19232
19233
19234 \family typewriter 
19235 itemp = k + l; 
19236 \newline 
19237 for (i = 0; i < 100; i++) 
19238 \newline 
19239 \SpecialChar ~
19240 \SpecialChar ~
19241 \SpecialChar ~
19242 \SpecialChar ~
19243 f += itemp;
19244 \layout Standard
19245
19246 As mentioned previously some loop invariants are not as apparent, all static
19247  address computations are also moved out of the loop.
19248 \newline 
19249
19250 \newline 
19251 Strength Reduction
19252 \begin_inset LatexCommand \index{Strength reduction}
19253
19254 \end_inset 
19255
19256 , this optimization substitutes an expression by a cheaper expression:
19257 \layout Verse
19258
19259
19260 \family typewriter 
19261 for (i=0;i < 100; i++)
19262 \newline 
19263 \SpecialChar ~
19264 \SpecialChar ~
19265 \SpecialChar ~
19266 \SpecialChar ~
19267 ar[i*5] = i*3;
19268 \layout Standard
19269
19270 changed to
19271 \layout Verse
19272
19273
19274 \family typewriter 
19275 itemp1 = 0; 
19276 \newline 
19277 itemp2 = 0; 
19278 \newline 
19279 for (i=0;i< 100;i++) { 
19280 \newline 
19281 \SpecialChar ~
19282 \SpecialChar ~
19283 \SpecialChar ~
19284 \SpecialChar ~
19285 ar[itemp1] = itemp2; 
19286 \newline 
19287 \SpecialChar ~
19288 \SpecialChar ~
19289 \SpecialChar ~
19290 \SpecialChar ~
19291 itemp1 += 5; 
19292 \newline 
19293 \SpecialChar ~
19294 \SpecialChar ~
19295 \SpecialChar ~
19296 \SpecialChar ~
19297 itemp2 += 3; 
19298 \newline 
19299 }
19300 \layout Standard
19301
19302 The more expensive multiplication
19303 \begin_inset LatexCommand \index{Multiplication}
19304
19305 \end_inset 
19306
19307  is changed to a less expensive addition.
19308 \layout Subsection
19309
19310 Loop Reversing
19311 \begin_inset LatexCommand \index{Loop reversing}
19312
19313 \end_inset 
19314
19315
19316 \layout Standard
19317
19318 This optimization is done to reduce the overhead of checking loop boundaries
19319  for every iteration.
19320  Some simple loops can be reversed and implemented using a 
19321 \begin_inset Quotes eld
19322 \end_inset 
19323
19324 decrement and jump if not zero
19325 \begin_inset Quotes erd
19326 \end_inset 
19327
19328  instruction.
19329  SDCC checks for the following criterion to determine if a loop is reversible
19330  (note: more sophisticated compilers use data-dependency analysis to make
19331  this determination, SDCC uses a more simple minded analysis).
19332 \layout Itemize
19333
19334 The 'for' loop is of the form 
19335 \newline 
19336
19337 \newline 
19338
19339 \family typewriter 
19340 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
19341  += 1])
19342 \newline 
19343 \SpecialChar ~
19344 \SpecialChar ~
19345 \SpecialChar ~
19346 \SpecialChar ~
19347 <for body>
19348 \layout Itemize
19349
19350 The <for body> does not contain 
19351 \begin_inset Quotes eld
19352 \end_inset 
19353
19354 continue
19355 \begin_inset Quotes erd
19356 \end_inset 
19357
19358  or 'break
19359 \begin_inset Quotes erd
19360 \end_inset 
19361
19362 .
19363 \layout Itemize
19364
19365 All goto's are contained within the loop.
19366 \layout Itemize
19367
19368 No function calls within the loop.
19369 \layout Itemize
19370
19371 The loop control variable <sym> is not assigned any value within the loop
19372 \layout Itemize
19373
19374 The loop control variable does NOT participate in any arithmetic operation
19375  within the loop.
19376 \layout Itemize
19377
19378 There are NO switch statements in the loop.
19379 \layout Subsection
19380
19381 Algebraic Simplifications
19382 \layout Standard
19383
19384 SDCC does numerous algebraic simplifications, the following is a small sub-set
19385  of these optimizations.
19386 \layout Verse
19387
19388
19389 \family typewriter 
19390 i = j + 0;\SpecialChar ~
19391 \SpecialChar ~
19392 \SpecialChar ~
19393 \SpecialChar ~
19394  /* changed to: */\SpecialChar ~
19395 \SpecialChar ~
19396 \SpecialChar ~
19397 \SpecialChar ~
19398  i = j; 
19399 \newline 
19400 i /= 2;\SpecialChar ~
19401 \SpecialChar ~
19402 \SpecialChar ~
19403 \SpecialChar ~
19404 \SpecialChar ~
19405 \SpecialChar ~
19406 \SpecialChar ~
19407  /* changed to: */\SpecialChar ~
19408 \SpecialChar ~
19409 \SpecialChar ~
19410 \SpecialChar ~
19411  i >>= 1; 
19412 \newline 
19413 i = j - j;\SpecialChar ~
19414 \SpecialChar ~
19415 \SpecialChar ~
19416 \SpecialChar ~
19417  /* changed to: */\SpecialChar ~
19418 \SpecialChar ~
19419 \SpecialChar ~
19420 \SpecialChar ~
19421  i = 0; 
19422 \newline 
19423 i = j / 1;\SpecialChar ~
19424 \SpecialChar ~
19425 \SpecialChar ~
19426 \SpecialChar ~
19427  /* changed to: */\SpecialChar ~
19428 \SpecialChar ~
19429 \SpecialChar ~
19430 \SpecialChar ~
19431  i = j;
19432 \layout Standard
19433
19434 Note the subexpressions
19435 \begin_inset LatexCommand \index{Subexpression}
19436
19437 \end_inset 
19438
19439  given above are generally introduced by macro expansions or as a result
19440  of copy/constant propagation.
19441 \layout Subsection
19442
19443 'switch' Statements
19444 \begin_inset LatexCommand \label{sub:'switch'-Statements}
19445
19446 \end_inset 
19447
19448
19449 \begin_inset LatexCommand \index{switch statement}
19450
19451 \end_inset 
19452
19453
19454 \layout Standard
19455
19456 SDCC changes switch statements to jump tables
19457 \begin_inset LatexCommand \index{jump tables}
19458
19459 \end_inset 
19460
19461  when the following conditions are true.
19462  
19463 \layout Itemize
19464
19465 The case labels are in numerical sequence, the labels need not be in order,
19466  and the starting number need not be one or zero.
19467 \begin_deeper 
19468 \layout Verse
19469
19470
19471 \family typewriter 
19472 switch(i) {\SpecialChar ~
19473 \SpecialChar ~
19474 \SpecialChar ~
19475 \SpecialChar ~
19476 \SpecialChar ~
19477 \SpecialChar ~
19478 \SpecialChar ~
19479 \SpecialChar ~
19480 \SpecialChar ~
19481 \SpecialChar ~
19482 \SpecialChar ~
19483 \SpecialChar ~
19484 \SpecialChar ~
19485 \SpecialChar ~
19486 \SpecialChar ~
19487 \SpecialChar ~
19488 \SpecialChar ~
19489 \SpecialChar ~
19490 \SpecialChar ~
19491 \SpecialChar ~
19492 \SpecialChar ~
19493 \SpecialChar ~
19494 \SpecialChar ~
19495 \SpecialChar ~
19496 \SpecialChar ~
19497 \SpecialChar ~
19498 switch (i) { 
19499 \newline 
19500 \SpecialChar ~
19501 \SpecialChar ~
19502 \SpecialChar ~
19503 case 4: ...\SpecialChar ~
19504 \SpecialChar ~
19505 \SpecialChar ~
19506 \SpecialChar ~
19507 \SpecialChar ~
19508 \SpecialChar ~
19509 \SpecialChar ~
19510 \SpecialChar ~
19511 \SpecialChar ~
19512 \SpecialChar ~
19513 \SpecialChar ~
19514 \SpecialChar ~
19515 \SpecialChar ~
19516 \SpecialChar ~
19517 \SpecialChar ~
19518 \SpecialChar ~
19519 \SpecialChar ~
19520 \SpecialChar ~
19521 \SpecialChar ~
19522 \SpecialChar ~
19523 \SpecialChar ~
19524 \SpecialChar ~
19525 \SpecialChar ~
19526 \SpecialChar ~
19527 \SpecialChar ~
19528 \SpecialChar ~
19529 case 0: ...
19530  
19531 \newline 
19532 \SpecialChar ~
19533 \SpecialChar ~
19534 \SpecialChar ~
19535 case 5: ...\SpecialChar ~
19536 \SpecialChar ~
19537 \SpecialChar ~
19538 \SpecialChar ~
19539 \SpecialChar ~
19540 \SpecialChar ~
19541 \SpecialChar ~
19542 \SpecialChar ~
19543 \SpecialChar ~
19544 \SpecialChar ~
19545 \SpecialChar ~
19546 \SpecialChar ~
19547 \SpecialChar ~
19548 \SpecialChar ~
19549 \SpecialChar ~
19550 \SpecialChar ~
19551 \SpecialChar ~
19552 \SpecialChar ~
19553 \SpecialChar ~
19554 \SpecialChar ~
19555 \SpecialChar ~
19556 \SpecialChar ~
19557 \SpecialChar ~
19558 \SpecialChar ~
19559 \SpecialChar ~
19560 \SpecialChar ~
19561 case 1: ...
19562  
19563 \newline 
19564 \SpecialChar ~
19565 \SpecialChar ~
19566 \SpecialChar ~
19567 case 3: ...\SpecialChar ~
19568 \SpecialChar ~
19569 \SpecialChar ~
19570 \SpecialChar ~
19571 \SpecialChar ~
19572 \SpecialChar ~
19573 \SpecialChar ~
19574 \SpecialChar ~
19575 \SpecialChar ~
19576 \SpecialChar ~
19577 \SpecialChar ~
19578 \SpecialChar ~
19579 \SpecialChar ~
19580 \SpecialChar ~
19581 \SpecialChar ~
19582 \SpecialChar ~
19583 \SpecialChar ~
19584 \SpecialChar ~
19585 \SpecialChar ~
19586 \SpecialChar ~
19587 \SpecialChar ~
19588 \SpecialChar ~
19589 \SpecialChar ~
19590 \SpecialChar ~
19591 \SpecialChar ~
19592 \SpecialChar ~
19593 case 2: ...
19594  
19595 \newline 
19596 \SpecialChar ~
19597 \SpecialChar ~
19598 \SpecialChar ~
19599 case 6: ...\SpecialChar ~
19600 \SpecialChar ~
19601 \SpecialChar ~
19602 \SpecialChar ~
19603 \SpecialChar ~
19604 \SpecialChar ~
19605 \SpecialChar ~
19606 \SpecialChar ~
19607 \SpecialChar ~
19608 \SpecialChar ~
19609 \SpecialChar ~
19610 \SpecialChar ~
19611 \SpecialChar ~
19612 \SpecialChar ~
19613 \SpecialChar ~
19614 \SpecialChar ~
19615 \SpecialChar ~
19616 \SpecialChar ~
19617 \SpecialChar ~
19618 \SpecialChar ~
19619 \SpecialChar ~
19620 \SpecialChar ~
19621 \SpecialChar ~
19622 \SpecialChar ~
19623 \SpecialChar ~
19624 \SpecialChar ~
19625 case 3: ...
19626  
19627 \newline 
19628 }\SpecialChar ~
19629 \SpecialChar ~
19630 \SpecialChar ~
19631 \SpecialChar ~
19632 \SpecialChar ~
19633 \SpecialChar ~
19634 \SpecialChar ~
19635 \SpecialChar ~
19636 \SpecialChar ~
19637 \SpecialChar ~
19638 \SpecialChar ~
19639 \SpecialChar ~
19640 \SpecialChar ~
19641 \SpecialChar ~
19642 \SpecialChar ~
19643 \SpecialChar ~
19644 \SpecialChar ~
19645 \SpecialChar ~
19646 \SpecialChar ~
19647 \SpecialChar ~
19648 \SpecialChar ~
19649 \SpecialChar ~
19650 \SpecialChar ~
19651 \SpecialChar ~
19652 \SpecialChar ~
19653 \SpecialChar ~
19654 \SpecialChar ~
19655 \SpecialChar ~
19656 \SpecialChar ~
19657 \SpecialChar ~
19658 \SpecialChar ~
19659 \SpecialChar ~
19660 \SpecialChar ~
19661 \SpecialChar ~
19662 \SpecialChar ~
19663 \SpecialChar ~
19664 }
19665 \layout Standard
19666
19667 Both the above switch statements will be implemented using a jump-table.
19668  The example to the right side is slightly more efficient as the check for
19669  the lower boundary of the jump-table is not needed.
19670 \end_deeper 
19671 \layout Itemize
19672
19673 The number of case labels is at least three, since it takes two conditional
19674  statements to handle the boundary conditions.
19675 \layout Itemize
19676
19677 The number of case labels is less than 84, since each label takes 3 bytes
19678  and a jump-table can be utmost 256 bytes long.
19679 \layout Standard
19680
19681 Switch statements which have gaps in the numeric sequence or those that
19682  have more that 84 case labels can be split into more than one switch statement
19683  for efficient code generation, e.g.:
19684 \layout Verse
19685
19686
19687 \family typewriter 
19688 switch (i) { 
19689 \newline 
19690 \SpecialChar ~
19691 \SpecialChar ~
19692 case 1: ...
19693  
19694 \newline 
19695 \SpecialChar ~
19696 \SpecialChar ~
19697 case 2: ...
19698  
19699 \newline 
19700 \SpecialChar ~
19701 \SpecialChar ~
19702 case 3: ...
19703  
19704 \newline 
19705 \SpecialChar ~
19706 \SpecialChar ~
19707 case 4: ...
19708  
19709 \newline 
19710 \SpecialChar ~
19711 \SpecialChar ~
19712 case 9: ...
19713  
19714 \newline 
19715 \SpecialChar ~
19716 \SpecialChar ~
19717 case 10: ...
19718  
19719 \newline 
19720 \SpecialChar ~
19721 \SpecialChar ~
19722 case 11: ...
19723  
19724 \newline 
19725 \SpecialChar ~
19726 \SpecialChar ~
19727 case 12: ...
19728  
19729 \newline 
19730 }
19731 \layout Standard
19732
19733 If the above switch statement is broken down into two switch statements
19734 \layout Verse
19735
19736
19737 \family typewriter 
19738 switch (i) { 
19739 \newline 
19740 \SpecialChar ~
19741 \SpecialChar ~
19742 case 1: ...
19743  
19744 \newline 
19745 \SpecialChar ~
19746 \SpecialChar ~
19747 case 2: ...
19748  
19749 \newline 
19750 \SpecialChar ~
19751 \SpecialChar ~
19752 case 3: ...
19753  
19754 \newline 
19755 \SpecialChar ~
19756 \SpecialChar ~
19757 case 4: ...
19758  
19759 \newline 
19760 }
19761 \layout Standard
19762
19763 and
19764 \layout Verse
19765
19766
19767 \family typewriter 
19768 switch (i) { 
19769 \newline 
19770 \SpecialChar ~
19771 \SpecialChar ~
19772 case 9:\SpecialChar ~
19773 \SpecialChar ~
19774 ...
19775  
19776 \newline 
19777 \SpecialChar ~
19778 \SpecialChar ~
19779 case 10:\SpecialChar ~
19780 ...
19781  
19782 \newline 
19783 \SpecialChar ~
19784 \SpecialChar ~
19785 case 11:\SpecialChar ~
19786 ...
19787  
19788 \newline 
19789 \SpecialChar ~
19790 \SpecialChar ~
19791 case 12:\SpecialChar ~
19792 ...
19793  
19794 \newline 
19795 }
19796 \layout Standard
19797
19798 then both the switch statements will be implemented using jump-tables whereas
19799  the unmodified switch statement will not be.
19800  You might also consider inserting dummy cases 0 and 5 to 8 in this example.
19801  
19802 \newline 
19803 The pragma nojtbound
19804 \begin_inset LatexCommand \index{\#pragma nojtbound}
19805
19806 \end_inset 
19807
19808  can be used to turn off checking the 
19809 \emph on 
19810 j
19811 \emph default 
19812 ump 
19813 \emph on 
19814 t
19815 \emph default 
19816 able 
19817 \emph on 
19818 bound
19819 \emph default 
19820 aries.
19821  It has no effect if a default label is supplied.
19822  Use of this pragma is dangerous: if the switch argument is not matched
19823  by a case statement the processor will happily jump into Nirvana.
19824 \layout Subsection
19825
19826 Bit-shifting Operations
19827 \begin_inset LatexCommand \index{Bit shifting}
19828
19829 \end_inset 
19830
19831 .
19832 \layout Standard
19833
19834 Bit shifting is one of the most frequently used operation in embedded programmin
19835 g.
19836  SDCC tries to implement bit-shift operations in the most efficient way
19837  possible, e.g.:
19838 \layout Verse
19839
19840
19841 \family typewriter 
19842 unsigned char i;
19843 \newline 
19844 ...
19845  
19846 \newline 
19847 i >>= 4; 
19848 \newline 
19849 ...
19850 \layout Standard
19851
19852 generates the following code:
19853 \layout Verse
19854
19855
19856 \family typewriter 
19857 mov\SpecialChar ~
19858  a,_i 
19859 \newline 
19860 swap a 
19861 \newline 
19862 anl\SpecialChar ~
19863  a,#0x0f 
19864 \newline 
19865 mov\SpecialChar ~
19866  _i,a
19867 \layout Standard
19868
19869 In general SDCC will never setup a loop if the shift count is known.
19870  Another example:
19871 \layout Verse
19872
19873
19874 \family typewriter 
19875 unsigned int i; 
19876 \newline 
19877 ...
19878  
19879 \newline 
19880 i >>= 9; 
19881 \newline 
19882 ...
19883 \layout Standard
19884
19885 will generate:
19886 \layout Verse
19887
19888
19889 \family typewriter 
19890 mov\SpecialChar ~
19891 \SpecialChar ~
19892 a,(_i + 1) 
19893 \newline 
19894 mov\SpecialChar ~
19895 \SpecialChar ~
19896 (_i + 1),#0x00 
19897 \newline 
19898 clr\SpecialChar ~
19899 \SpecialChar ~
19900
19901 \newline 
19902 rrc\SpecialChar ~
19903 \SpecialChar ~
19904
19905 \newline 
19906 mov\SpecialChar ~
19907 \SpecialChar ~
19908 _i,a
19909 \layout Subsection
19910
19911 Bit-rotation
19912 \begin_inset LatexCommand \index{Bit rotation}
19913
19914 \end_inset 
19915
19916
19917 \layout Standard
19918
19919 A special case of the bit-shift operation is bit rotation
19920 \begin_inset LatexCommand \index{rotating bits}
19921
19922 \end_inset 
19923
19924 , SDCC recognizes the following expression to be a left bit-rotation:
19925 \layout Verse
19926
19927
19928 \family typewriter 
19929 \series bold 
19930 unsigned
19931 \series default 
19932 \SpecialChar ~
19933 \SpecialChar ~
19934 char i;\SpecialChar ~
19935 \SpecialChar ~
19936 \SpecialChar ~
19937 \SpecialChar ~
19938 \SpecialChar ~
19939 \SpecialChar ~
19940 \SpecialChar ~
19941 \SpecialChar ~
19942 \SpecialChar ~
19943 \SpecialChar ~
19944 \SpecialChar ~
19945 /* unsigned is needed for rotation */ 
19946 \newline 
19947 ...
19948  
19949 \newline 
19950 i = ((i << 1) | (i >> 7)); 
19951 \family default 
19952
19953 \newline 
19954
19955 \family typewriter 
19956 ...
19957 \layout Standard
19958
19959 will generate the following code:
19960 \layout Verse
19961
19962
19963 \family typewriter 
19964 mov\SpecialChar ~
19965 \SpecialChar ~
19966 a,_i 
19967 \newline 
19968 rl\SpecialChar ~
19969 \SpecialChar ~
19970 \SpecialChar ~
19971
19972 \newline 
19973 mov\SpecialChar ~
19974 \SpecialChar ~
19975 _i,a
19976 \layout Standard
19977
19978 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
19979 ns of this case will also be recognized as bit-rotation, i.e.: 
19980 \layout Verse
19981
19982
19983 \family typewriter 
19984 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
19985 \layout Subsection
19986
19987 Nibble and Byte Swapping
19988 \layout Standard
19989
19990 Other special cases of the bit-shift operations are nibble or byte swapping
19991 \begin_inset LatexCommand \index{swapping nibbles/bytes}
19992
19993 \end_inset 
19994
19995 , SDCC recognizes the following expressions:
19996 \layout Verse
19997
19998
19999 \family typewriter 
20000 \series bold 
20001 unsigned
20002 \series default 
20003 \SpecialChar ~
20004 \SpecialChar ~
20005 char i; 
20006 \newline 
20007
20008 \series bold 
20009 unsigned
20010 \series default 
20011 \SpecialChar ~
20012 \SpecialChar ~
20013 int j; 
20014 \newline 
20015 ...
20016  
20017 \newline 
20018 i = ((i << 4) | (i >> 4)); 
20019 \family default 
20020
20021 \newline 
20022
20023 \family typewriter 
20024 j = ((j << 8) | (j >> 8)); 
20025 \layout Standard
20026
20027 and generates a swap instruction for the nibble swapping
20028 \begin_inset LatexCommand \index{Nibble swapping}
20029
20030 \end_inset 
20031
20032  or move instructions for the byte swapping
20033 \begin_inset LatexCommand \index{Byte swapping}
20034
20035 \end_inset 
20036
20037 .
20038  The 
20039 \begin_inset Quotes sld
20040 \end_inset 
20041
20042 j
20043 \begin_inset Quotes srd
20044 \end_inset 
20045
20046  example can be used to convert from little to big-endian or vice versa.
20047  If you want to change the endianness of a 
20048 \emph on 
20049 signed
20050 \emph default 
20051  integer you have to cast to 
20052 \family typewriter 
20053 (unsigned int)
20054 \family default 
20055  first.
20056 \layout Standard
20057
20058 Note that SDCC stores numbers in little-endian
20059 \begin_inset Foot
20060 collapsed false
20061
20062 \layout Standard
20063
20064 Usually 8-bit processors don't care much about endianness.
20065  This is not the case for the standard 8051 which only has an instruction
20066  to increment its 
20067 \emph on 
20068 dptr
20069 \emph default 
20070
20071 \begin_inset LatexCommand \index{DPTR}
20072
20073 \end_inset 
20074
20075 -datapointer
20076 \emph on 
20077  
20078 \emph default 
20079 so little-endian is the more efficient byte order.
20080 \end_inset 
20081
20082
20083 \begin_inset LatexCommand \index{little-endian}
20084
20085 \end_inset 
20086
20087
20088 \begin_inset LatexCommand \index{Endianness}
20089
20090 \end_inset 
20091
20092  format (i.e.
20093  lowest order first).
20094 \layout Subsection
20095
20096 Highest Order Bit
20097 \begin_inset LatexCommand \index{Highest Order Bit}
20098
20099 \end_inset 
20100
20101
20102 \layout Standard
20103
20104 It is frequently required to obtain the highest order bit of an integral
20105  type (long, int, short or char types).
20106  SDCC recognizes the following expression to yield the highest order bit
20107  and generates optimized code for it, e.g.:
20108 \layout Verse
20109
20110
20111 \family typewriter 
20112 unsigned int gint; 
20113 \newline 
20114
20115 \newline 
20116 foo () { 
20117 \newline 
20118 \SpecialChar ~
20119 \SpecialChar ~
20120 unsigned char hob; 
20121 \newline 
20122 \SpecialChar ~
20123 \SpecialChar ~
20124 ...
20125  
20126 \newline 
20127 \SpecialChar ~
20128 \SpecialChar ~
20129 hob = (gint >> 15) & 1; 
20130 \newline 
20131 \SpecialChar ~
20132 \SpecialChar ~
20133 ..
20134  
20135 \newline 
20136 }
20137 \layout Standard
20138
20139 will generate the following code:
20140 \layout Verse
20141
20142
20143 \family typewriter 
20144 \SpecialChar ~
20145 \SpecialChar ~
20146 \SpecialChar ~
20147 \SpecialChar ~
20148 \SpecialChar ~
20149 \SpecialChar ~
20150 \SpecialChar ~
20151 \SpecialChar ~
20152 \SpecialChar ~
20153 \SpecialChar ~
20154 \SpecialChar ~
20155 \SpecialChar ~
20156 \SpecialChar ~
20157 \SpecialChar ~
20158 \SpecialChar ~
20159 \SpecialChar ~
20160 \SpecialChar ~
20161 \SpecialChar ~
20162 \SpecialChar ~
20163 \SpecialChar ~
20164 \SpecialChar ~
20165 \SpecialChar ~
20166 \SpecialChar ~
20167 \SpecialChar ~
20168 \SpecialChar ~
20169  61 ;\SpecialChar ~
20170  hob.c 7 
20171 \newline 
20172 000A E5*01\SpecialChar ~
20173 \SpecialChar ~
20174 \SpecialChar ~
20175 \SpecialChar ~
20176 \SpecialChar ~
20177 \SpecialChar ~
20178 \SpecialChar ~
20179 \SpecialChar ~
20180 \SpecialChar ~
20181 \SpecialChar ~
20182 \SpecialChar ~
20183 \SpecialChar ~
20184 \SpecialChar ~
20185 \SpecialChar ~
20186 \SpecialChar ~
20187  62\SpecialChar ~
20188 \SpecialChar ~
20189 \SpecialChar ~
20190 \SpecialChar ~
20191 \SpecialChar ~
20192 \SpecialChar ~
20193 \SpecialChar ~
20194 \SpecialChar ~
20195  mov\SpecialChar ~
20196 \SpecialChar ~
20197  a,(_gint + 1) 
20198 \newline 
20199 000C 23\SpecialChar ~
20200 \SpecialChar ~
20201 \SpecialChar ~
20202 \SpecialChar ~
20203 \SpecialChar ~
20204 \SpecialChar ~
20205 \SpecialChar ~
20206 \SpecialChar ~
20207 \SpecialChar ~
20208 \SpecialChar ~
20209 \SpecialChar ~
20210 \SpecialChar ~
20211 \SpecialChar ~
20212 \SpecialChar ~
20213 \SpecialChar ~
20214 \SpecialChar ~
20215 \SpecialChar ~
20216 \SpecialChar ~
20217  63\SpecialChar ~
20218 \SpecialChar ~
20219 \SpecialChar ~
20220 \SpecialChar ~
20221 \SpecialChar ~
20222 \SpecialChar ~
20223 \SpecialChar ~
20224 \SpecialChar ~
20225  rl\SpecialChar ~
20226 \SpecialChar ~
20227 \SpecialChar ~
20228  a 
20229 \newline 
20230 000D 54 01\SpecialChar ~
20231 \SpecialChar ~
20232 \SpecialChar ~
20233 \SpecialChar ~
20234 \SpecialChar ~
20235 \SpecialChar ~
20236 \SpecialChar ~
20237 \SpecialChar ~
20238 \SpecialChar ~
20239 \SpecialChar ~
20240 \SpecialChar ~
20241 \SpecialChar ~
20242 \SpecialChar ~
20243 \SpecialChar ~
20244 \SpecialChar ~
20245  64\SpecialChar ~
20246 \SpecialChar ~
20247 \SpecialChar ~
20248 \SpecialChar ~
20249 \SpecialChar ~
20250 \SpecialChar ~
20251 \SpecialChar ~
20252 \SpecialChar ~
20253  anl\SpecialChar ~
20254 \SpecialChar ~
20255  a,#0x01 
20256 \newline 
20257 000F F5*02\SpecialChar ~
20258 \SpecialChar ~
20259 \SpecialChar ~
20260 \SpecialChar ~
20261 \SpecialChar ~
20262 \SpecialChar ~
20263 \SpecialChar ~
20264 \SpecialChar ~
20265 \SpecialChar ~
20266 \SpecialChar ~
20267 \SpecialChar ~
20268 \SpecialChar ~
20269 \SpecialChar ~
20270 \SpecialChar ~
20271 \SpecialChar ~
20272  65\SpecialChar ~
20273 \SpecialChar ~
20274 \SpecialChar ~
20275 \SpecialChar ~
20276 \SpecialChar ~
20277 \SpecialChar ~
20278 \SpecialChar ~
20279 \SpecialChar ~
20280  mov\SpecialChar ~
20281 \SpecialChar ~
20282  _foo_hob_1_1,a
20283 \layout Standard
20284
20285 Variations of this case however will 
20286 \emph on 
20287 not
20288 \emph default 
20289  be recognized.
20290  It is a standard C expression, so I heartily recommend this be the only
20291  way to get the highest order bit, (it is portable).
20292  Of course it will be recognized even if it is embedded in other expressions,
20293  e.g.:
20294 \layout Verse
20295
20296
20297 \family typewriter 
20298 xyz = gint + ((gint >> 15) & 1);
20299 \layout Standard
20300
20301 will still be recognized.
20302 \layout Subsection
20303
20304 Peephole Optimizer
20305 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
20306
20307 \end_inset 
20308
20309
20310 \begin_inset LatexCommand \index{Peephole optimizer}
20311
20312 \end_inset 
20313
20314
20315 \layout Standard
20316
20317 The compiler uses a rule based, pattern matching and re-writing mechanism
20318  for peep-hole optimization.
20319  It is inspired by 
20320 \emph on 
20321 copt
20322 \emph default 
20323  a peep-hole optimizer by Christopher W.
20324  Fraser (cwfraser@microsoft.com).
20325  A default set of rules are compiled into the compiler, additional rules
20326  may be added with the 
20327 \emph on 
20328 -
20329 \begin_inset ERT
20330 status Collapsed
20331
20332 \layout Standard
20333
20334 \backslash 
20335 /
20336 \end_inset 
20337
20338 -peep-file
20339 \begin_inset LatexCommand \index{-\/-peep-file}
20340
20341 \end_inset 
20342
20343  <filename>
20344 \emph default 
20345  option.
20346  The rule language is best illustrated with examples.
20347 \layout Verse
20348
20349
20350 \family typewriter 
20351 replace { 
20352 \newline 
20353 \SpecialChar ~
20354 \SpecialChar ~
20355 mov %1,a 
20356 \newline 
20357 \SpecialChar ~
20358 \SpecialChar ~
20359 mov a,%1
20360 \newline 
20361 } by {
20362 \newline 
20363 \SpecialChar ~
20364 \SpecialChar ~
20365 mov %1,a
20366 \newline 
20367 }
20368 \layout Standard
20369
20370 The above rule will change the following assembly
20371 \begin_inset LatexCommand \index{Assembler routines}
20372
20373 \end_inset 
20374
20375  sequence:
20376 \layout Verse
20377
20378
20379 \family typewriter 
20380 mov r1,a 
20381 \newline 
20382 mov a,r1
20383 \layout Standard
20384
20385 to
20386 \layout Verse
20387
20388
20389 \family typewriter 
20390 mov r1,a
20391 \layout Standard
20392
20393 Note: All occurrences of a 
20394 \emph on 
20395 %n
20396 \emph default 
20397  (pattern variable) must denote the same string.
20398  With the above rule, the assembly sequence:
20399 \layout Verse
20400
20401
20402 \family typewriter 
20403 mov r1,a 
20404 \newline 
20405 mov a,r2
20406 \layout Standard
20407
20408 will remain unmodified.
20409 \newline 
20410
20411 \newline 
20412 Other special case optimizations may be added by the user (via 
20413 \emph on 
20414 -
20415 \begin_inset ERT
20416 status Collapsed
20417
20418 \layout Standard
20419
20420 \backslash 
20421 /
20422 \end_inset 
20423
20424 -peep-file option
20425 \emph default 
20426 ).
20427  E.g.
20428  some variants of the 8051 MCU
20429 \begin_inset LatexCommand \index{MCS51 variants}
20430
20431 \end_inset 
20432
20433  allow only 
20434 \family typewriter 
20435 ajmp
20436 \family default 
20437  and 
20438 \family typewriter 
20439 acall
20440 \family default 
20441 .
20442  The following two rules will change all 
20443 \family typewriter 
20444 ljmp
20445 \family default 
20446  and 
20447 \family typewriter 
20448 lcall
20449 \family default 
20450  to 
20451 \family typewriter 
20452 ajmp
20453 \family default 
20454  and 
20455 \family typewriter 
20456 acall
20457 \layout Verse
20458
20459
20460 \family typewriter 
20461 replace { lcall %1 } by { acall %1 } 
20462 \newline 
20463 replace { ljmp %1 } by { ajmp %1 }
20464 \layout Standard
20465
20466 The 
20467 \emph on 
20468 inline-assembler code
20469 \emph default 
20470  is also passed through the peep hole optimizer, thus the peephole optimizer
20471  can also be used as an assembly level macro expander.
20472  The rules themselves are MCU dependent whereas the rule language infra-structur
20473 e is MCU independent.
20474  Peephole optimization rules for other MCU can be easily programmed using
20475  the rule language.
20476 \newline 
20477
20478 \newline 
20479 The syntax for a rule is as follows:
20480 \layout Verse
20481
20482
20483 \family typewriter 
20484 rule := replace [ restart ] '{' <assembly sequence> '
20485 \backslash 
20486 n' 
20487 \newline 
20488 \SpecialChar ~
20489  \SpecialChar ~
20490  \SpecialChar ~
20491  \SpecialChar ~
20492  \SpecialChar ~
20493  \SpecialChar ~
20494  \SpecialChar ~
20495  \SpecialChar ~
20496  \SpecialChar ~
20497  \SpecialChar ~
20498  \SpecialChar ~
20499  \SpecialChar ~
20500  \SpecialChar ~
20501  \SpecialChar ~
20502  '}' by '{' '
20503 \backslash 
20504 n' 
20505 \newline 
20506 \SpecialChar ~
20507  \SpecialChar ~
20508  \SpecialChar ~
20509  \SpecialChar ~
20510  \SpecialChar ~
20511  \SpecialChar ~
20512  \SpecialChar ~
20513  \SpecialChar ~
20514  \SpecialChar ~
20515  \SpecialChar ~
20516  \SpecialChar ~
20517  \SpecialChar ~
20518  \SpecialChar ~
20519  \SpecialChar ~
20520  \SpecialChar ~
20521  \SpecialChar ~
20522  <assembly sequence> '
20523 \backslash 
20524 n' 
20525 \newline 
20526 \SpecialChar ~
20527  \SpecialChar ~
20528  \SpecialChar ~
20529  \SpecialChar ~
20530  \SpecialChar ~
20531  \SpecialChar ~
20532  \SpecialChar ~
20533  \SpecialChar ~
20534  \SpecialChar ~
20535  \SpecialChar ~
20536  \SpecialChar ~
20537  \SpecialChar ~
20538  \SpecialChar ~
20539  \SpecialChar ~
20540  '}' [if <functionName> ] '
20541 \backslash 
20542 n' 
20543 \layout Standard
20544
20545 <assembly sequence> := assembly instruction (each instruction including
20546  labels must be on a separate line).
20547 \newline 
20548
20549 \newline 
20550 The optimizer will apply to the rules one by one from the top in the sequence
20551  of their appearance, it will terminate when all rules are exhausted.
20552  If the 'restart' option is specified, then the optimizer will start matching
20553  the rules again from the top, this option for a rule is expensive (performance)
20554 , it is intended to be used in situations where a transformation will trigger
20555  the same rule again.
20556  An example of this (not a good one, it has side effects) is the following
20557  rule:
20558 \layout Verse
20559
20560
20561 \family typewriter 
20562 replace restart { 
20563 \newline 
20564 \SpecialChar ~
20565 \SpecialChar ~
20566 pop %1 
20567 \newline 
20568 \SpecialChar ~
20569 \SpecialChar ~
20570 push %1 } by { 
20571 \newline 
20572 \SpecialChar ~
20573 \SpecialChar ~
20574 ; nop 
20575 \newline 
20576 }
20577 \layout Standard
20578
20579 Note that the replace pattern cannot be a blank, but can be a comment line.
20580  Without the 'restart' option only the innermost 'pop' 'push' pair would
20581  be eliminated, i.e.:
20582 \layout Verse
20583
20584
20585 \family typewriter 
20586 pop ar1 
20587 \newline 
20588 pop ar2 
20589 \newline 
20590 push ar2 
20591 \newline 
20592 push ar1
20593 \layout Standard
20594
20595 would result in:
20596 \layout Verse
20597
20598
20599 \family typewriter 
20600 pop ar1 
20601 \newline 
20602 ; nop 
20603 \newline 
20604 push ar1
20605 \layout Standard
20606
20607
20608 \emph on 
20609 with
20610 \emph default 
20611  the restart option the rule will be applied again to the resulting code
20612  and then all the pop-push pairs will be eliminated to yield:
20613 \layout Verse
20614
20615
20616 \family typewriter 
20617 ; nop 
20618 \newline 
20619 ; nop
20620 \layout Standard
20621
20622 A conditional function can be attached to a rule.
20623  Attaching rules are somewhat more involved, let me illustrate this with
20624  an example.
20625 \layout Verse
20626
20627
20628 \family typewriter 
20629 replace { 
20630 \newline 
20631 \SpecialChar ~
20632  \SpecialChar ~
20633  \SpecialChar ~
20634 ljmp %5 
20635 \newline 
20636 %2:
20637 \newline 
20638 } by { 
20639 \newline 
20640 \SpecialChar ~
20641  \SpecialChar ~
20642  \SpecialChar ~
20643 sjmp %5 
20644 \newline 
20645 %2:
20646 \newline 
20647 } if labelInRange
20648 \layout Standard
20649
20650 The optimizer does a look-up of a function name table defined in function
20651  
20652 \emph on 
20653 callFuncByName
20654 \emph default 
20655  in the source file SDCCpeeph.c, with the name 
20656 \emph on 
20657 labelInRange
20658 \emph default 
20659 .
20660  If it finds a corresponding entry the function is called.
20661  Note there can be no parameters specified for these functions, in this
20662  case the use of 
20663 \emph on 
20664 %5
20665 \emph default 
20666  is crucial, since the function 
20667 \emph on 
20668 labelInRange
20669 \emph default 
20670  expects to find the label in that particular variable (the hash table containin
20671 g the variable bindings is passed as a parameter).
20672  If you want to code more such functions, take a close look at the function
20673  labelInRange and the calling mechanism in source file SDCCpeeph.c.
20674  Currently implemented are 
20675 \emph on 
20676 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
20677  24bitMode, portIsDS390, 24bitModeAndPortDS390 
20678 \emph default 
20679 and
20680 \emph on 
20681  notVolatile
20682 \emph default 
20683 .
20684 \layout Standard
20685
20686 I know this whole thing is a little kludgey, but maybe some day we will
20687  have some better means.
20688  If you are looking at this file, you will see the default rules that are
20689  compiled into the compiler, you can add your own rules in the default set
20690  there if you get tired of specifying the -
20691 \begin_inset ERT
20692 status Collapsed
20693
20694 \layout Standard
20695
20696 \backslash 
20697 /
20698 \end_inset 
20699
20700 -peep-file option.
20701 \layout Section
20702
20703 ANSI-Compliance
20704 \begin_inset LatexCommand \index{ANSI-compliance}
20705
20706 \end_inset 
20707
20708
20709 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
20710
20711 \end_inset 
20712
20713
20714 \layout Standard
20715
20716 Deviations from the compliance:
20717 \layout Itemize
20718
20719 functions are not always reentrant
20720 \begin_inset LatexCommand \index{reentrant}
20721
20722 \end_inset 
20723
20724 .
20725 \layout Itemize
20726
20727 structures cannot be assigned values directly, cannot be passed as function
20728  parameters or assigned to each other and cannot be a return value from
20729  a function, e.g.:
20730 \begin_deeper 
20731 \layout Verse
20732
20733
20734 \family typewriter 
20735 struct s { ...
20736  }; 
20737 \newline 
20738 struct s s1, s2; 
20739 \newline 
20740 foo() 
20741 \newline 
20742
20743 \newline 
20744 \SpecialChar ~
20745 \SpecialChar ~
20746 \SpecialChar ~
20747 \SpecialChar ~
20748 ...
20749  
20750 \newline 
20751 \SpecialChar ~
20752 \SpecialChar ~
20753 \SpecialChar ~
20754 \SpecialChar ~
20755 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
20756 \newline 
20757 \SpecialChar ~
20758 \SpecialChar ~
20759 \SpecialChar ~
20760 \SpecialChar ~
20761 ...
20762  
20763 \newline 
20764 }
20765 \newline 
20766 struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
20767  */
20768 \newline 
20769
20770 \newline 
20771 \SpecialChar ~
20772 \SpecialChar ~
20773 \SpecialChar ~
20774 \SpecialChar ~
20775 struct s rets; 
20776 \newline 
20777 \SpecialChar ~
20778 \SpecialChar ~
20779 \SpecialChar ~
20780 \SpecialChar ~
20781 ...
20782  
20783 \newline 
20784 \SpecialChar ~
20785 \SpecialChar ~
20786 \SpecialChar ~
20787 \SpecialChar ~
20788 return rets;/* is invalid in SDCC although allowed in ANSI */ 
20789 \newline 
20790 }
20791 \end_deeper 
20792 \layout Itemize
20793
20794 'long long
20795 \begin_inset LatexCommand \index{long long (not supported)}
20796
20797 \end_inset 
20798
20799 ' (64 bit integers
20800 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
20801
20802 \end_inset 
20803
20804 ) not supported.
20805 \layout Itemize
20806
20807 'double
20808 \begin_inset LatexCommand \index{double (not supported)}
20809
20810 \end_inset 
20811
20812 ' precision floating point 
20813 \begin_inset LatexCommand \index{Floating point support}
20814
20815 \end_inset 
20816
20817 not supported.
20818 \layout Itemize
20819
20820 No support for setjmp
20821 \begin_inset LatexCommand \index{setjmp (not supported)}
20822
20823 \end_inset 
20824
20825  and longjmp
20826 \begin_inset LatexCommand \index{longjmp (not supported)}
20827
20828 \end_inset 
20829
20830  (for now).
20831 \layout Itemize
20832
20833 Old K&R style
20834 \begin_inset LatexCommand \index{K\&R style}
20835
20836 \end_inset 
20837
20838  function declarations are NOT allowed.
20839 \begin_deeper 
20840 \layout Verse
20841
20842
20843 \family typewriter 
20844 foo(i,j) /* this old style of function declarations */ 
20845 \newline 
20846 int i,j; /* are valid in ANSI but not valid in SDCC */ 
20847 \newline 
20848
20849 \newline 
20850 \SpecialChar ~
20851 \SpecialChar ~
20852 \SpecialChar ~
20853 \SpecialChar ~
20854 ...
20855  
20856 \newline 
20857 }
20858 \end_deeper 
20859 \layout Section
20860
20861 Cyclomatic Complexity
20862 \begin_inset LatexCommand \index{Cyclomatic complexity}
20863
20864 \end_inset 
20865
20866
20867 \layout Standard
20868
20869 Cyclomatic complexity of a function is defined as the number of independent
20870  paths the program can take during execution of the function.
20871  This is an important number since it defines the number test cases you
20872  have to generate to validate the function.
20873  The accepted industry standard for complexity number is 10, if the cyclomatic
20874  complexity reported by SDCC exceeds 10 you should think about simplification
20875  of the function logic.
20876  Note that the complexity level is not related to the number of lines of
20877  code in a function.
20878  Large functions can have low complexity, and small functions can have large
20879  complexity levels.
20880  
20881 \newline 
20882
20883 \newline 
20884 SDCC uses the following formula to compute the complexity:
20885 \newline 
20886
20887 \layout Standard
20888
20889 complexity = (number of edges in control flow graph) - (number of nodes
20890  in control flow graph) + 2;
20891 \newline 
20892
20893 \newline 
20894 Having said that the industry standard is 10, you should be aware that in
20895  some cases it be may unavoidable to have a complexity level of less than
20896  10.
20897  For example if you have switch statement with more than 10 case labels,
20898  each case label adds one to the complexity level.
20899  The complexity level is by no means an absolute measure of the algorithmic
20900  complexity of the function, it does however provide a good starting point
20901  for which functions you might look at for further optimization.
20902 \layout Section
20903
20904 Retargetting for other Processors
20905 \layout Standard
20906
20907 The issues for retargetting the compiler are far too numerous to be covered
20908  by this document.
20909  What follows is a brief description of each of the seven phases of the
20910  compiler and its MCU dependency.
20911 \layout Itemize
20912
20913 Parsing the source and building the annotated parse tree.
20914  This phase is largely MCU independent (except for the language extensions).
20915  Syntax & semantic checks are also done in this phase, along with some initial
20916  optimizations like back patching labels and the pattern matching optimizations
20917  like bit-rotation etc.
20918 \layout Itemize
20919
20920 The second phase involves generating an intermediate code which can be easy
20921  manipulated during the later phases.
20922  This phase is entirely MCU independent.
20923  The intermediate code generation assumes the target machine has unlimited
20924  number of registers, and designates them with the name iTemp.
20925  The compiler can be made to dump a human readable form of the code generated
20926  by using the -
20927 \begin_inset ERT
20928 status Collapsed
20929
20930 \layout Standard
20931
20932 \backslash 
20933 /
20934 \end_inset 
20935
20936 -dumpraw option.
20937 \layout Itemize
20938
20939 This phase does the bulk of the standard optimizations and is also MCU independe
20940 nt.
20941  This phase can be broken down into several sub-phases:
20942 \newline 
20943
20944 \newline 
20945 Break down intermediate code (iCode) into basic blocks.
20946 \newline 
20947 Do control flow & data flow analysis on the basic blocks.
20948 \newline 
20949 Do local common subexpression elimination, then global subexpression elimination
20950 \newline 
20951 Dead code elimination
20952 \newline 
20953 Loop optimizations
20954 \newline 
20955 If loop optimizations caused any changes then do 'global subexpression eliminati
20956 on' and 'dead code elimination' again.
20957 \layout Itemize
20958
20959 This phase determines the live-ranges; by live range I mean those iTemp
20960  variables defined by the compiler that still survive after all the optimization
20961 s.
20962  Live range analysis
20963 \begin_inset LatexCommand \index{Live range analysis}
20964
20965 \end_inset 
20966
20967  is essential for register allocation, since these computation determines
20968  which of these iTemps will be assigned to registers, and for how long.
20969 \layout Itemize
20970
20971 Phase five is register allocation.
20972  There are two parts to this process.
20973 \newline 
20974
20975 \newline 
20976 The first part I call 'register packing' (for lack of a better term).
20977  In this case several MCU specific expression folding is done to reduce
20978  register pressure.
20979 \newline 
20980
20981 \newline 
20982 The second part is more MCU independent and deals with allocating registers
20983  to the remaining live ranges.
20984  A lot of MCU specific code does creep into this phase because of the limited
20985  number of index registers available in the 8051.
20986 \layout Itemize
20987
20988 The Code generation phase is (unhappily), entirely MCU dependent and very
20989  little (if any at all) of this code can be reused for other MCU.
20990  However the scheme for allocating a homogenized assembler operand for each
20991  iCode operand may be reused.
20992 \layout Itemize
20993
20994 As mentioned in the optimization section the peep-hole optimizer is rule
20995  based system, which can reprogrammed for other MCUs.
20996 \layout Chapter
20997
20998 Compiler internals
20999 \begin_inset LatexCommand \index{Compiler internals}
21000
21001 \end_inset 
21002
21003
21004 \layout Section
21005
21006 The anatomy of the compiler
21007 \begin_inset LatexCommand \label{sub:The-anatomy-of}
21008
21009 \end_inset 
21010
21011
21012 \layout Standard
21013
21014
21015 \shape italic 
21016 This is an excerpt from an article published in Circuit Cellar Magazine
21017  in august 2000.
21018  It's a little outdated (the compiler is much more efficient now and user/develo
21019 per friendly), but pretty well exposes the guts of it all.
21020 \shape default 
21021
21022 \newline 
21023
21024 \newline 
21025 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
21026  It is fairly easy to retarget for other 8-bit MCU.
21027  Here we take a look at some of the internals of the compiler.
21028  
21029 \layout Paragraph*
21030
21031 Parsing
21032 \begin_inset LatexCommand \index{Parsing}
21033
21034 \end_inset 
21035
21036  
21037 \layout Standard
21038
21039 Parsing the input source file and creating an AST (Annotated Syntax Tree
21040 \begin_inset LatexCommand \index{Annotated syntax tree}
21041
21042 \end_inset 
21043
21044 ).
21045  This phase also involves propagating types (annotating each node of the
21046  parse tree with type information) and semantic analysis.
21047  There are some MCU specific parsing rules.
21048  For example the storage classes, the extended storage classes are MCU specific
21049  while there may be a xdata storage class for 8051 there is no such storage
21050  class for z80 or Atmel AVR.
21051  SDCC allows MCU specific storage class extensions, i.e.
21052  xdata will be treated as a storage class specifier when parsing 8051 C
21053  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
21054  C code.
21055 \layout Paragraph*
21056
21057 Generating iCode
21058 \begin_inset LatexCommand \index{iCode}
21059
21060 \end_inset 
21061
21062
21063 \layout Standard
21064
21065 Intermediate code generation.
21066  In this phase the AST is broken down into three-operand form (iCode).
21067  These three operand forms are represented as doubly linked lists.
21068  ICode is the term given to the intermediate form generated by the compiler.
21069  ICode example section shows some examples of iCode generated for some simple
21070  C source functions.
21071 \layout Paragraph*
21072
21073 Optimizations
21074 \begin_inset LatexCommand \index{Optimizations}
21075
21076 \end_inset 
21077
21078 .
21079 \layout Standard
21080
21081 Bulk of the target independent optimizations is performed in this phase.
21082  The optimizations include constant propagation, common sub-expression eliminati
21083 on, loop invariant code movement, strength reduction of loop induction variables
21084  and dead-code elimination.
21085 \layout Paragraph*
21086
21087 Live range analysis
21088 \begin_inset LatexCommand \index{Live range analysis}
21089
21090 \end_inset 
21091
21092
21093 \layout Standard
21094
21095 During intermediate code generation phase, the compiler assumes the target
21096  machine has infinite number of registers and generates a lot of temporary
21097  variables.
21098  The live range computation determines the lifetime of each of these compiler-ge
21099 nerated temporaries.
21100  A picture speaks a thousand words.
21101  ICode example sections show the live range annotations for each of the
21102  operand.
21103  It is important to note here, each iCode is assigned a number in the order
21104  of its execution in the function.
21105  The live ranges are computed in terms of these numbers.
21106  The from number is the number of the iCode which first defines the operand
21107  and the to number signifies the iCode which uses this operand last.
21108 \layout Paragraph*
21109
21110 Register Allocation
21111 \begin_inset LatexCommand \index{Register allocation}
21112
21113 \end_inset 
21114
21115
21116 \layout Standard
21117
21118 The register allocation determines the type and number of registers needed
21119  by each operand.
21120  In most MCUs only a few registers can be used for indirect addressing.
21121  In case of 8051 for example the registers R0 & R1 can be used to indirectly
21122  address the internal ram and DPTR to indirectly address the external ram.
21123  The compiler will try to allocate the appropriate register to pointer variables
21124  if it can.
21125  ICode example section shows the operands annotated with the registers assigned
21126  to them.
21127  The compiler will try to keep operands in registers as much as possible;
21128  there are several schemes the compiler uses to do achieve this.
21129  When the compiler runs out of registers the compiler will check to see
21130  if there are any live operands which is not used or defined in the current
21131  basic block being processed, if there are any found then it will push that
21132  operand and use the registers in this block, the operand will then be popped
21133  at the end of the basic block.
21134  
21135 \layout Standard
21136
21137 There are other MCU specific considerations in this phase.
21138  Some MCUs have an accumulator; very short-lived operands could be assigned
21139  to the accumulator instead of a general-purpose register.
21140 \layout Paragraph*
21141
21142 Code generation
21143 \layout Standard
21144
21145 Figure II gives a table of iCode operations supported by the compiler.
21146  The code generation involves translating these operations into corresponding
21147  assembly code for the processor.
21148  This sounds overly simple but that is the essence of code generation.
21149  Some of the iCode operations are generated on a MCU specific manner for
21150  example, the z80 port does not use registers to pass parameters so the
21151  SEND and RECV iCode operations will not be generated, and it also does
21152  not support JUMPTABLES.
21153  
21154 \newline 
21155
21156 \series bold 
21157 \shape italic 
21158 \color red
21159 <Where is Figure II ?>
21160 \layout Paragraph*
21161
21162 ICode Example
21163 \begin_inset LatexCommand \index{iCode}
21164
21165 \end_inset 
21166
21167
21168 \layout Standard
21169
21170 This section shows some details of iCode.
21171  The example C code does not do anything useful; it is used as an example
21172  to illustrate the intermediate code generated by the compiler.
21173 \layout Verse
21174
21175
21176 \family typewriter 
21177 1.\SpecialChar ~
21178 xdata int * p;
21179 \newline 
21180 2.\SpecialChar ~
21181 int gint;
21182 \newline 
21183 3.\SpecialChar ~
21184 /* This function does nothing useful.
21185  It is used
21186 \newline 
21187 4.\SpecialChar ~
21188 \SpecialChar ~
21189 \SpecialChar ~
21190 \SpecialChar ~
21191 for the purpose of explaining iCode */
21192 \newline 
21193 5.\SpecialChar ~
21194 short function (data int *x)
21195 \newline 
21196 6.\SpecialChar ~
21197 {
21198 \newline 
21199 7.\SpecialChar ~
21200 \SpecialChar ~
21201 \SpecialChar ~
21202 short i=10; \SpecialChar ~
21203 \SpecialChar ~
21204 /* dead initialization eliminated */
21205 \newline 
21206 8.\SpecialChar ~
21207 \SpecialChar ~
21208 \SpecialChar ~
21209 short sum=10; /* dead initialization eliminated */
21210 \newline 
21211 9.\SpecialChar ~
21212 \SpecialChar ~
21213 \SpecialChar ~
21214 short mul;
21215 \newline 
21216 10.\SpecialChar ~
21217 \SpecialChar ~
21218 int j ;
21219 \newline 
21220 11.\SpecialChar ~
21221 \SpecialChar ~
21222 while (*x) *x++ = *p++; 
21223 \newline 
21224 12.\SpecialChar ~
21225 \SpecialChar ~
21226 \SpecialChar ~
21227 \SpecialChar ~
21228 sum = 0 ; 
21229 \newline 
21230 13.\SpecialChar ~
21231 \SpecialChar ~
21232 mul = 0;
21233 \newline 
21234 14.\SpecialChar ~
21235 \SpecialChar ~
21236 /* compiler detects i,j to be induction variables */
21237 \newline 
21238 15.\SpecialChar ~
21239 \SpecialChar ~
21240 for (i = 0, j = 10 ; i < 10 ; i++, j
21241 \family default 
21242 -
21243 \begin_inset ERT
21244 status Collapsed
21245
21246 \layout Standard
21247
21248 \backslash 
21249 /
21250 \end_inset 
21251
21252 -
21253 \family typewriter 
21254 ) {
21255 \newline 
21256 16.\SpecialChar ~
21257 \SpecialChar ~
21258 \SpecialChar ~
21259 \SpecialChar ~
21260 sum += i;
21261 \newline 
21262 17.\SpecialChar ~
21263 \SpecialChar ~
21264 \SpecialChar ~
21265 \SpecialChar ~
21266 mul += i * 3; \SpecialChar ~
21267 \SpecialChar ~
21268 /* this multiplication remains */
21269 \newline 
21270 18.\SpecialChar ~
21271 \SpecialChar ~
21272 \SpecialChar ~
21273 \SpecialChar ~
21274 gint += j * 3;\SpecialChar ~
21275 \SpecialChar ~
21276 /* this multiplication changed to addition */
21277 \newline 
21278 19.\SpecialChar ~
21279 \SpecialChar ~
21280 }
21281 \newline 
21282 20.\SpecialChar ~
21283 \SpecialChar ~
21284 return sum+mul;
21285 \newline 
21286 21.\SpecialChar ~
21287 }
21288 \layout Standard
21289
21290 In addition to the operands each iCode contains information about the filename
21291  and line it corresponds to in the source file.
21292  The first field in the listing should be interpreted as follows:
21293 \newline 
21294
21295 \shape italic 
21296 \size footnotesize 
21297 Filename(linenumber: iCode Execution sequence number : ICode hash table
21298  key : loop depth of the iCode).
21299 \shape default 
21300 \size default 
21301
21302 \newline 
21303 Then follows the human readable form of the ICode operation.
21304  Each operand of this triplet form can be of three basic types a) compiler
21305  generated temporary b) user defined variable c) a constant value.
21306  Note that local variables and parameters are replaced by compiler generated
21307  temporaries.
21308  Live ranges
21309 \begin_inset LatexCommand \index{Live range analysis}
21310
21311 \end_inset 
21312
21313  are computed only for temporaries (i.e.
21314  live ranges are not computed for global variables).
21315  Registers
21316 \begin_inset LatexCommand \index{Register allocation}
21317
21318 \end_inset 
21319
21320  are allocated for temporaries only.
21321  Operands are formatted in the following manner:
21322 \newline 
21323
21324 \shape italic 
21325 \size footnotesize 
21326 Operand Name [lr live-from : live-to ] { type information } [ registers
21327  allocated ].
21328 \shape default 
21329 \size default 
21330
21331 \newline 
21332 As mentioned earlier the live ranges are computed in terms of the execution
21333  sequence number of the iCodes, for example 
21334 \newline 
21335 the iTemp0 is live from (i.e.
21336  first defined in iCode with execution sequence number 3, and is last used
21337  in the iCode with sequence number 5).
21338  For induction variables such as iTemp21 the live range computation extends
21339  the lifetime from the start to the end of the loop.
21340 \newline 
21341 The register allocator used the live range information to allocate registers,
21342  the same registers may be used for different temporaries if their live
21343  ranges do not overlap, for example r0 is allocated to both iTemp6 and to
21344  iTemp17 since their live ranges do not overlap.
21345  In addition the allocator also takes into consideration the type and usage
21346  of a temporary, for example itemp6 is a pointer to near space and is used
21347  as to fetch data from (i.e.
21348  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
21349  Some short lived temporaries are allocated to special registers which have
21350  meaning to the code generator e.g.
21351  iTemp13 is allocated to a pseudo register CC which tells the back end that
21352  the temporary is used only for a conditional jump the code generation makes
21353  use of this information to optimize a compare and jump ICode.
21354 \newline 
21355 There are several loop optimizations
21356 \begin_inset LatexCommand \index{Loop optimization}
21357
21358 \end_inset 
21359
21360  performed by the compiler.
21361  It can detect induction variables iTemp21(i) and iTemp23(j).
21362  Also note the compiler does selective strength reduction
21363 \begin_inset LatexCommand \index{Strength reduction}
21364
21365 \end_inset 
21366
21367 , i.e.
21368  the multiplication of an induction variable in line 18 (gint = j * 3) is
21369  changed to addition, a new temporary iTemp17 is allocated and assigned
21370  a initial value, a constant 3 is then added for each iteration of the loop.
21371  The compiler does not change the multiplication
21372 \begin_inset LatexCommand \index{Multiplication}
21373
21374 \end_inset 
21375
21376  in line 17 however since the processor does support an 8 * 8 bit multiplication.
21377 \newline 
21378 Note the dead code elimination
21379 \begin_inset LatexCommand \index{Dead-code elimination}
21380
21381 \end_inset 
21382
21383  optimization eliminated the dead assignments in line 7 & 8 to I and sum
21384  respectively.
21385 \newline 
21386
21387 \layout Standard
21388
21389
21390 \size footnotesize 
21391 Sample.c (5:1:0:0) _entry($9) :
21392 \layout Standard
21393
21394
21395 \size footnotesize 
21396 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
21397 \layout Standard
21398
21399
21400 \size footnotesize 
21401 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
21402 \layout Standard
21403
21404
21405 \size footnotesize 
21406 Sample.c(11:4:53:0) preHeaderLbl0($11) :
21407 \layout Standard
21408
21409
21410 \size footnotesize 
21411 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
21412  * int}[r2]
21413 \layout Standard
21414
21415
21416 \size footnotesize 
21417 Sample.c(11:6:5:1) _whilecontinue_0($1) :
21418 \layout Standard
21419
21420
21421 \size footnotesize 
21422 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
21423  int}[r0]]
21424 \layout Standard
21425
21426
21427 \size footnotesize 
21428 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
21429 \layout Standard
21430
21431
21432 \size footnotesize 
21433 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
21434  * int}
21435 \layout Standard
21436
21437
21438 \size footnotesize 
21439 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
21440  {short}
21441 \layout Standard
21442
21443
21444 \size footnotesize 
21445 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
21446  * int}[DPTR]]
21447 \layout Standard
21448
21449
21450 \size footnotesize 
21451 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
21452 }[r2 r3]
21453 \layout Standard
21454
21455
21456 \size footnotesize 
21457 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
21458  * int}[r0] + 0x2 {short}
21459 \layout Standard
21460
21461
21462 \size footnotesize 
21463 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
21464 \layout Standard
21465
21466
21467 \size footnotesize 
21468 Sample.c(11:17:21:0)_whilebreak_0($3) :
21469 \layout Standard
21470
21471
21472 \size footnotesize 
21473 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
21474 \layout Standard
21475
21476
21477 \size footnotesize 
21478 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
21479 \layout Standard
21480
21481
21482 \size footnotesize 
21483 Sample.c(15:20:54:0)preHeaderLbl1($13) :
21484 \layout Standard
21485
21486
21487 \size footnotesize 
21488 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
21489 \layout Standard
21490
21491
21492 \size footnotesize 
21493 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
21494 \layout Standard
21495
21496
21497 \size footnotesize 
21498 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
21499 \layout Standard
21500
21501
21502 \size footnotesize 
21503 Sample.c(15:24:26:1)_forcond_0($4) :
21504 \layout Standard
21505
21506
21507 \size footnotesize 
21508 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
21509  < 0xa {short}
21510 \layout Standard
21511
21512
21513 \size footnotesize 
21514 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
21515 \layout Standard
21516
21517
21518 \size footnotesize 
21519 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
21520  + ITemp21 [lr21:38]{short}[r4]
21521 \layout Standard
21522
21523
21524 \size footnotesize 
21525 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
21526  * 0x3 {short}
21527 \layout Standard
21528
21529
21530 \size footnotesize 
21531 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
21532  + iTemp15 [lr29:30]{short}[r1]
21533 \layout Standard
21534
21535
21536 \size footnotesize 
21537 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
21538  r0]- 0x3 {short}
21539 \layout Standard
21540
21541
21542 \size footnotesize 
21543 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
21544 int}[r7 r0]
21545 \layout Standard
21546
21547
21548 \size footnotesize 
21549 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
21550  + 0x1 {short}
21551 \layout Standard
21552
21553
21554 \size footnotesize 
21555 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
21556  r6]- 0x1 {short}
21557 \layout Standard
21558
21559
21560 \size footnotesize 
21561 Sample.c(19:38:47:1) goto _forcond_0($4)
21562 \layout Standard
21563
21564
21565 \size footnotesize 
21566 Sample.c(19:39:48:0)_forbreak_0($7) :
21567 \layout Standard
21568
21569
21570 \size footnotesize 
21571 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
21572  + ITemp11 [lr19:40]{short}[r3]
21573 \layout Standard
21574
21575
21576 \size footnotesize 
21577 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
21578 \layout Standard
21579
21580
21581 \size footnotesize 
21582 Sample.c(20:42:51:0)_return($8) :
21583 \layout Standard
21584
21585
21586 \size footnotesize 
21587 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
21588 \size default 
21589
21590 \newline 
21591
21592 \newline 
21593 Finally the code generated for this function:
21594 \newline 
21595
21596 \layout Standard
21597
21598
21599 \size footnotesize 
21600 .area DSEG (DATA)
21601 \layout Standard
21602
21603
21604 \size footnotesize 
21605 _p::
21606 \layout Standard
21607
21608
21609 \size footnotesize 
21610 \SpecialChar ~
21611 \SpecialChar ~
21612 .ds 2
21613 \layout Standard
21614
21615
21616 \size footnotesize 
21617 _gint::
21618 \layout Standard
21619
21620
21621 \size footnotesize 
21622 \SpecialChar ~
21623 \SpecialChar ~
21624 .ds 2
21625 \layout Standard
21626
21627
21628 \size footnotesize 
21629 ; sample.c 5
21630 \layout Standard
21631
21632
21633 \size footnotesize 
21634 ; ----------------------------------------------
21635 \layout Standard
21636
21637
21638 \size footnotesize 
21639 ; function function
21640 \layout Standard
21641
21642
21643 \size footnotesize 
21644 ; ----------------------------------------------
21645 \layout Standard
21646
21647
21648 \size footnotesize 
21649 _function:
21650 \layout Standard
21651
21652
21653 \size footnotesize 
21654 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
21655 \layout Standard
21656
21657
21658 \size footnotesize 
21659 \SpecialChar ~
21660 \SpecialChar ~
21661 mov r2,dpl
21662 \layout Standard
21663
21664
21665 \size footnotesize 
21666 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
21667 \layout Standard
21668
21669
21670 \size footnotesize 
21671 \SpecialChar ~
21672 \SpecialChar ~
21673 mov ar0,r2
21674 \layout Standard
21675
21676
21677 \size footnotesize 
21678 ;_whilecontinue_0($1) :
21679 \layout Standard
21680
21681
21682 \size footnotesize 
21683 00101$:
21684 \layout Standard
21685
21686
21687 \size footnotesize 
21688 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
21689 \layout Standard
21690
21691
21692 \size footnotesize 
21693 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
21694 \layout Standard
21695
21696
21697 \size footnotesize 
21698 \SpecialChar ~
21699 \SpecialChar ~
21700 mov ar2,@r0
21701 \layout Standard
21702
21703
21704 \size footnotesize 
21705 \SpecialChar ~
21706 \SpecialChar ~
21707 inc r0
21708 \layout Standard
21709
21710
21711 \size footnotesize 
21712 \SpecialChar ~
21713 \SpecialChar ~
21714 mov ar3,@r0
21715 \layout Standard
21716
21717
21718 \size footnotesize 
21719 \SpecialChar ~
21720 \SpecialChar ~
21721 dec r0
21722 \layout Standard
21723
21724
21725 \size footnotesize 
21726 \SpecialChar ~
21727 \SpecialChar ~
21728 mov a,r2
21729 \layout Standard
21730
21731
21732 \size footnotesize 
21733 \SpecialChar ~
21734 \SpecialChar ~
21735 orl a,r3
21736 \layout Standard
21737
21738
21739 \size footnotesize 
21740 \SpecialChar ~
21741 \SpecialChar ~
21742 jz 00103$
21743 \layout Standard
21744
21745
21746 \size footnotesize 
21747 00114$:
21748 \layout Standard
21749
21750
21751 \size footnotesize 
21752 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
21753 \layout Standard
21754
21755
21756 \size footnotesize 
21757 \SpecialChar ~
21758 \SpecialChar ~
21759 mov dpl,_p
21760 \layout Standard
21761
21762
21763 \size footnotesize 
21764 \SpecialChar ~
21765 \SpecialChar ~
21766 mov dph,(_p + 1)
21767 \layout Standard
21768
21769
21770 \size footnotesize 
21771 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
21772 \layout Standard
21773
21774
21775 \size footnotesize 
21776 \SpecialChar ~
21777 \SpecialChar ~
21778 mov a,#0x02
21779 \layout Standard
21780
21781
21782 \size footnotesize 
21783 \SpecialChar ~
21784 \SpecialChar ~
21785 add a,_p
21786 \layout Standard
21787
21788
21789 \size footnotesize 
21790 \SpecialChar ~
21791 \SpecialChar ~
21792 mov _p,a
21793 \layout Standard
21794
21795
21796 \size footnotesize 
21797 \SpecialChar ~
21798 \SpecialChar ~
21799 clr a
21800 \layout Standard
21801
21802
21803 \size footnotesize 
21804 \SpecialChar ~
21805 \SpecialChar ~
21806 addc a,(_p + 1)
21807 \layout Standard
21808
21809
21810 \size footnotesize 
21811 \SpecialChar ~
21812 \SpecialChar ~
21813 mov (_p + 1),a
21814 \layout Standard
21815
21816
21817 \size footnotesize 
21818 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
21819 \layout Standard
21820
21821
21822 \size footnotesize 
21823 \SpecialChar ~
21824 \SpecialChar ~
21825 movx a,@dptr
21826 \layout Standard
21827
21828
21829 \size footnotesize 
21830 \SpecialChar ~
21831 \SpecialChar ~
21832 mov r2,a
21833 \layout Standard
21834
21835
21836 \size footnotesize 
21837 \SpecialChar ~
21838 \SpecialChar ~
21839 inc dptr
21840 \layout Standard
21841
21842
21843 \size footnotesize 
21844 \SpecialChar ~
21845 \SpecialChar ~
21846 movx a,@dptr
21847 \layout Standard
21848
21849
21850 \size footnotesize 
21851 \SpecialChar ~
21852 \SpecialChar ~
21853 mov r3,a
21854 \layout Standard
21855
21856
21857 \size footnotesize 
21858 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
21859 \layout Standard
21860
21861
21862 \size footnotesize 
21863 \SpecialChar ~
21864 \SpecialChar ~
21865 mov @r0,ar2
21866 \layout Standard
21867
21868
21869 \size footnotesize 
21870 \SpecialChar ~
21871 \SpecialChar ~
21872 inc r0
21873 \layout Standard
21874
21875
21876 \size footnotesize 
21877 \SpecialChar ~
21878 \SpecialChar ~
21879 mov @r0,ar3
21880 \layout Standard
21881
21882
21883 \size footnotesize 
21884 ; iTemp6 [lr5:16]{_near * int}[r0] = 
21885 \layout Standard
21886
21887
21888 \size footnotesize 
21889 ; iTemp6 [lr5:16]{_near * int}[r0] + 
21890 \layout Standard
21891
21892
21893 \size footnotesize 
21894 ; 0x2 {short}
21895 \layout Standard
21896
21897
21898 \size footnotesize 
21899 \SpecialChar ~
21900 \SpecialChar ~
21901 inc r0
21902 \layout Standard
21903
21904
21905 \size footnotesize 
21906 ; goto _whilecontinue_0($1)
21907 \layout Standard
21908
21909
21910 \size footnotesize 
21911 \SpecialChar ~
21912 \SpecialChar ~
21913 sjmp 00101$
21914 \layout Standard
21915
21916
21917 \size footnotesize 
21918 ; _whilebreak_0($3) :
21919 \layout Standard
21920
21921
21922 \size footnotesize 
21923 00103$:
21924 \layout Standard
21925
21926
21927 \size footnotesize 
21928 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
21929 \layout Standard
21930
21931
21932 \size footnotesize 
21933 \SpecialChar ~
21934 \SpecialChar ~
21935 mov r2,#0x00
21936 \layout Standard
21937
21938
21939 \size footnotesize 
21940 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
21941 \layout Standard
21942
21943
21944 \size footnotesize 
21945 \SpecialChar ~
21946 \SpecialChar ~
21947 mov r3,#0x00
21948 \layout Standard
21949
21950
21951 \size footnotesize 
21952 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
21953 \layout Standard
21954
21955
21956 \size footnotesize 
21957 \SpecialChar ~
21958 \SpecialChar ~
21959 mov r4,#0x00
21960 \layout Standard
21961
21962
21963 \size footnotesize 
21964 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
21965 \layout Standard
21966
21967
21968 \size footnotesize 
21969 \SpecialChar ~
21970 \SpecialChar ~
21971 mov r5,#0x0A
21972 \layout Standard
21973
21974
21975 \size footnotesize 
21976 \SpecialChar ~
21977 \SpecialChar ~
21978 mov r6,#0x00
21979 \layout Standard
21980
21981
21982 \size footnotesize 
21983 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
21984 \layout Standard
21985
21986
21987 \size footnotesize 
21988 \SpecialChar ~
21989 \SpecialChar ~
21990 mov r7,#0x1E
21991 \layout Standard
21992
21993
21994 \size footnotesize 
21995 \SpecialChar ~
21996 \SpecialChar ~
21997 mov r0,#0x00
21998 \layout Standard
21999
22000
22001 \size footnotesize 
22002 ; _forcond_0($4) :
22003 \layout Standard
22004
22005
22006 \size footnotesize 
22007 00104$:
22008 \layout Standard
22009
22010
22011 \size footnotesize 
22012 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
22013 \layout Standard
22014
22015
22016 \size footnotesize 
22017 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
22018 \layout Standard
22019
22020
22021 \size footnotesize 
22022 \SpecialChar ~
22023 \SpecialChar ~
22024 clr c
22025 \layout Standard
22026
22027
22028 \size footnotesize 
22029 \SpecialChar ~
22030 \SpecialChar ~
22031 mov a,r4
22032 \layout Standard
22033
22034
22035 \size footnotesize 
22036 \SpecialChar ~
22037 \SpecialChar ~
22038 xrl a,#0x80
22039 \layout Standard
22040
22041
22042 \size footnotesize 
22043 \SpecialChar ~
22044 \SpecialChar ~
22045 subb a,#0x8a
22046 \layout Standard
22047
22048
22049 \size footnotesize 
22050 \SpecialChar ~
22051 \SpecialChar ~
22052 jnc 00107$
22053 \layout Standard
22054
22055
22056 \size footnotesize 
22057 00115$:
22058 \layout Standard
22059
22060
22061 \size footnotesize 
22062 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
22063 \layout Standard
22064
22065
22066 \size footnotesize 
22067 ; iTemp21 [lr21:38]{short}[r4]
22068 \layout Standard
22069
22070
22071 \size footnotesize 
22072 \SpecialChar ~
22073 \SpecialChar ~
22074 mov a,r4
22075 \layout Standard
22076
22077
22078 \size footnotesize 
22079 \SpecialChar ~
22080 \SpecialChar ~
22081 add a,r2
22082 \layout Standard
22083
22084
22085 \size footnotesize 
22086 \SpecialChar ~
22087 \SpecialChar ~
22088 mov r2,a
22089 \layout Standard
22090
22091
22092 \size footnotesize 
22093 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
22094 \layout Standard
22095
22096
22097 \size footnotesize 
22098 \SpecialChar ~
22099 \SpecialChar ~
22100 mov b,#0x03
22101 \layout Standard
22102
22103
22104 \size footnotesize 
22105 \SpecialChar ~
22106 \SpecialChar ~
22107 mov a,r4
22108 \layout Standard
22109
22110
22111 \size footnotesize 
22112 \SpecialChar ~
22113 \SpecialChar ~
22114 mul ab
22115 \layout Standard
22116
22117
22118 \size footnotesize 
22119 \SpecialChar ~
22120 \SpecialChar ~
22121 mov r1,a
22122 \layout Standard
22123
22124
22125 \size footnotesize 
22126 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
22127 \layout Standard
22128
22129
22130 \size footnotesize 
22131 ; iTemp15 [lr29:30]{short}[r1]
22132 \layout Standard
22133
22134
22135 \size footnotesize 
22136 \SpecialChar ~
22137 \SpecialChar ~
22138 add a,r3
22139 \layout Standard
22140
22141
22142 \size footnotesize 
22143 \SpecialChar ~
22144 \SpecialChar ~
22145 mov r3,a
22146 \layout Standard
22147
22148
22149 \size footnotesize 
22150 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
22151 \layout Standard
22152
22153
22154 \size footnotesize 
22155 \SpecialChar ~
22156 \SpecialChar ~
22157 mov a,r7
22158 \layout Standard
22159
22160
22161 \size footnotesize 
22162 \SpecialChar ~
22163 \SpecialChar ~
22164 add a,#0xfd
22165 \layout Standard
22166
22167
22168 \size footnotesize 
22169 \SpecialChar ~
22170 \SpecialChar ~
22171 mov r7,a
22172 \layout Standard
22173
22174
22175 \size footnotesize 
22176 \SpecialChar ~
22177 \SpecialChar ~
22178 mov a,r0
22179 \layout Standard
22180
22181
22182 \size footnotesize 
22183 \SpecialChar ~
22184 \SpecialChar ~
22185 addc a,#0xff
22186 \layout Standard
22187
22188
22189 \size footnotesize 
22190 \SpecialChar ~
22191 \SpecialChar ~
22192 mov r0,a
22193 \layout Standard
22194
22195
22196 \size footnotesize 
22197 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
22198 \layout Standard
22199
22200
22201 \size footnotesize 
22202 \SpecialChar ~
22203 \SpecialChar ~
22204 mov a,r7
22205 \layout Standard
22206
22207
22208 \size footnotesize 
22209 \SpecialChar ~
22210 \SpecialChar ~
22211 add a,_gint
22212 \layout Standard
22213
22214
22215 \size footnotesize 
22216 \SpecialChar ~
22217 \SpecialChar ~
22218 mov _gint,a
22219 \layout Standard
22220
22221
22222 \size footnotesize 
22223 \SpecialChar ~
22224 \SpecialChar ~
22225 mov a,r0
22226 \layout Standard
22227
22228
22229 \size footnotesize 
22230 \SpecialChar ~
22231 \SpecialChar ~
22232 addc a,(_gint + 1)
22233 \layout Standard
22234
22235
22236 \size footnotesize 
22237 \SpecialChar ~
22238 \SpecialChar ~
22239 mov (_gint + 1),a
22240 \layout Standard
22241
22242
22243 \size footnotesize 
22244 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
22245 \layout Standard
22246
22247
22248 \size footnotesize 
22249 \SpecialChar ~
22250 \SpecialChar ~
22251 inc r4
22252 \layout Standard
22253
22254
22255 \size footnotesize 
22256 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
22257 \layout Standard
22258
22259
22260 \size footnotesize 
22261 \SpecialChar ~
22262 \SpecialChar ~
22263 dec r5
22264 \layout Standard
22265
22266
22267 \size footnotesize 
22268 \SpecialChar ~
22269 \SpecialChar ~
22270 cjne r5,#0xff,00104$
22271 \layout Standard
22272
22273
22274 \size footnotesize 
22275 \SpecialChar ~
22276 \SpecialChar ~
22277 dec r6
22278 \layout Standard
22279
22280
22281 \size footnotesize 
22282 ; goto _forcond_0($4)
22283 \layout Standard
22284
22285
22286 \size footnotesize 
22287 \SpecialChar ~
22288 \SpecialChar ~
22289 sjmp 00104$
22290 \layout Standard
22291
22292
22293 \size footnotesize 
22294 ; _forbreak_0($7) :
22295 \layout Standard
22296
22297
22298 \size footnotesize 
22299 00107$:
22300 \layout Standard
22301
22302
22303 \size footnotesize 
22304 ; ret iTemp24 [lr40:41]{short}
22305 \layout Standard
22306
22307
22308 \size footnotesize 
22309 \SpecialChar ~
22310 \SpecialChar ~
22311 mov a,r3
22312 \layout Standard
22313
22314
22315 \size footnotesize 
22316 \SpecialChar ~
22317 \SpecialChar ~
22318 add a,r2
22319 \layout Standard
22320
22321
22322 \size footnotesize 
22323 \SpecialChar ~
22324 \SpecialChar ~
22325 mov dpl,a
22326 \layout Standard
22327
22328
22329 \size footnotesize 
22330 ; _return($8) :
22331 \layout Standard
22332
22333
22334 \size footnotesize 
22335 00108$:
22336 \layout Standard
22337
22338
22339 \size footnotesize 
22340 \SpecialChar ~
22341 \SpecialChar ~
22342 ret
22343 \newline 
22344
22345 \layout Section
22346
22347 A few words about basic block successors, predecessors and dominators
22348 \layout Standard
22349
22350 Successors are basic blocks
22351 \begin_inset LatexCommand \index{Basic blocks}
22352
22353 \end_inset 
22354
22355  that might execute after this basic block.
22356 \newline 
22357 Predecessors are basic blocks that might execute before reaching this basic
22358  block.
22359 \newline 
22360 Dominators are basic blocks that WILL execute before reaching this basic
22361  block.
22362 \newline 
22363
22364 \layout Standard
22365
22366 [basic block 1]
22367 \layout Standard
22368
22369 if (something)
22370 \layout Standard
22371
22372 \SpecialChar ~
22373 \SpecialChar ~
22374 \SpecialChar ~
22375 \SpecialChar ~
22376 [basic block 2]
22377 \layout Standard
22378
22379 else
22380 \layout Standard
22381
22382 \SpecialChar ~
22383 \SpecialChar ~
22384 \SpecialChar ~
22385 \SpecialChar ~
22386 [basic block 3]
22387 \layout Standard
22388
22389 [basic block 4]
22390 \newline 
22391
22392 \layout Standard
22393
22394 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
22395 \layout Standard
22396
22397 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
22398 \layout Standard
22399
22400 c) domVect of [BB4] = BB1 ...
22401  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
22402  was executed.
22403 \layout Chapter
22404
22405 Acknowledgments
22406 \layout Standard
22407
22408
22409 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
22410
22411 \end_inset 
22412
22413
22414 \newline 
22415
22416 \newline 
22417
22418 \emph on 
22419 Thanks to all the other volunteer developers who have helped with coding,
22420  testing, web-page creation, distribution sets, etc.
22421  You know who you are :-)
22422 \emph default 
22423
22424 \newline 
22425
22426 \layout Standard
22427
22428 This document was initially written by Sandeep Dutta
22429 \layout Standard
22430
22431 All product names mentioned herein may be trademarks
22432 \begin_inset LatexCommand \index{Trademarks}
22433
22434 \end_inset 
22435
22436  of their respective companies.
22437  
22438 \layout Section*
22439
22440 Alphabetical index
22441 \layout Standard
22442
22443 To avoid confusion, the installation and building options for SDCC itself
22444  (chapter 2) are not part of the index.
22445 \layout Standard
22446
22447
22448 \begin_inset LatexCommand \printindex{}
22449
22450 \end_inset 
22451
22452
22453 \the_end