1 #LyX 1.5.6 created this file. For more info see http://www.lyx.org/
7 \pdfoptionpdfminorversion=3
9 pdftitle={SDCC Compiler User Guide},
10 pdfauthor={SDCC development team},
11 pdfsubject={installation, user manual},
12 pdfkeywords={68hc08 8032 8051 ansi c compiler assembler CPU DS390 embedded development free Floating Point Arithmetic Freescale GPL HC08 inline Intel ISO/IEC 9899:1990 Linux MAC OS X manual Maxim mcs51 Microchip microcontroller open source PIC Unix Windows Z80 Zilog},
13 pdfpagemode=UseOutlines,
15 linkcolor=blue] {hyperref}
19 \emergencystretch=30pt
24 \inputencoding default
27 \font_typewriter courier
28 \font_default_family default
34 \paperfontsize default
36 \papersize letterpaper
42 \paperorientation portrait
49 \paragraph_separation indent
51 \quotes_language swedish
55 \tracking_changes false
63 \begin_layout Standard
64 \begin_inset Note Note
67 \begin_layout Standard
68 Please note: double dashed longoptions (e.g.
69 --version) are written this way: -
73 \begin_layout Standard
85 \begin_layout Standard
87 three consecutive dashes would otherwise result in a long resp.
91 \begin_layout Standard
92 Architecture specific stuff (like memory models, code examples) should maybe
96 \begin_layout Standard
97 into separate sections/chapters/appendices (it is hard to document PIC or
101 \begin_layout Standard
102 a 8051 centered document) - for now simply add.
111 SDCC Compiler User Guide
126 \begin_layout Standard
127 \begin_inset Note Note
130 \begin_layout Standard
131 The above strings enclosed in $ are automatically updated by Subversion
139 \begin_layout Standard
140 \begin_inset LatexCommand tableofcontents
147 \begin_layout Chapter
151 \begin_layout Section
155 \begin_layout Standard
176 ompiler) is free open source, retargettable, optimizing ANSI-C compiler
181 designed for 8 bit Microprocessors.
182 The current version targets Intel MCS51 based Microprocessors (8031, 8032,
184 \begin_inset LatexCommand index
185 name "8031, 8032, 8051, 8052, mcs51 CPU"
189 , etc.), Dallas DS80C390 variants, Freescale (formerly Motorola) HC08 and
190 Zilog Z80 based MCUs.
191 It can be retargeted for other microprocessors, support for Microchip PIC,
192 Atmel AVR is under development.
193 The entire source code for the compiler is distributed under GPL.
195 \begin_inset LatexCommand index
196 name "asXXXX (as-gbz80, as-hc08, asx8051, as-z80)"
201 \begin_inset LatexCommand index
206 , an open source retargetable assembler & linker.
207 SDCC has extensive language extensions suitable for utilizing various microcont
208 rollers and underlying hardware effectively.
213 In addition to the MCU specific optimizations SDCC also does a host of
214 standard optimizations like:
217 \begin_layout Itemize
218 global sub expression elimination,
221 \begin_layout Itemize
222 loop optimizations (loop invariant, strength reduction of induction variables
226 \begin_layout Itemize
227 constant folding & propagation,
230 \begin_layout Itemize
234 \begin_layout Itemize
235 dead code elimination
238 \begin_layout Itemize
246 \begin_layout Standard
247 For the back-end SDCC uses a global register allocation scheme which should
248 be well suited for other 8 bit MCUs.
253 The peep hole optimizer uses a rule based substitution mechanism which
259 Supported data-types are:
262 \begin_layout Standard
264 <lyxtabular version="3" rows="8" columns="5">
266 <column alignment="center" valignment="top" leftline="true" width="0">
267 <column alignment="center" valignment="top" leftline="true" width="0">
268 <column alignment="center" valignment="top" leftline="true" width="0">
269 <column alignment="center" valignment="top" leftline="true" width="0">
270 <column alignment="block" valignment="top" leftline="true" rightline="true" width="20text%">
271 <row topline="true" bottomline="true">
272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
275 \begin_layout Standard
281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
284 \begin_layout Standard
290 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
293 \begin_layout Standard
299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
302 \begin_layout Standard
308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
311 \begin_layout Standard
319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
322 \begin_layout Standard
328 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
331 \begin_layout Standard
337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
340 \begin_layout Standard
346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
349 \begin_layout Standard
355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
358 \begin_layout Standard
366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
369 \begin_layout Standard
375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
378 \begin_layout Standard
384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
387 \begin_layout Standard
393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
396 \begin_layout Standard
402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
405 \begin_layout Standard
413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
416 \begin_layout Standard
422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
425 \begin_layout Standard
431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
434 \begin_layout Standard
440 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
443 \begin_layout Standard
449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
452 \begin_layout Standard
460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
463 \begin_layout Standard
469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
472 \begin_layout Standard
478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
481 \begin_layout Standard
487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
490 \begin_layout Standard
496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
499 \begin_layout Standard
506 <row topline="true" bottomline="true">
507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
510 \begin_layout Standard
516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
519 \begin_layout Standard
525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
528 \begin_layout Standard
534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
537 \begin_layout Standard
538 -2.147.483.648, +2.147.483.647
543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
546 \begin_layout Standard
553 <row topline="true" bottomline="true">
554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
557 \begin_layout Standard
563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
566 \begin_layout Standard
572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
575 \begin_layout Standard
581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
584 \begin_layout Standard
590 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
593 \begin_layout Standard
609 <row topline="true" bottomline="true">
610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
613 \begin_layout Standard
619 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
622 \begin_layout Standard
628 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
631 \begin_layout Standard
637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
640 \begin_layout Standard
646 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
649 \begin_layout Standard
662 The compiler also allows
664 inline assembler code
666 to be embedded anywhere in a function.
667 In addition, routines developed in assembly can also be called.
672 provides an option (-
676 \begin_layout Standard
685 -cyclomatic) to report the relative complexity of a function.
686 These functions can then be further optimized, or hand coded in assembly
692 SDCC also comes with a companion source level debugger SDCDB.
693 The debugger currently uses ucSim, a free open source simulator for 8051
694 and other micro-controllers.
698 The latest SDCC version can be downloaded from
700 \begin_inset LatexCommand url
701 target "http://sdcc.sourceforge.net/snap.php"
708 Please note: the compiler will probably always be some steps ahead of this
713 \begin_inset LatexCommand index
714 name "Status of documentation"
722 \begin_layout Standard
723 Obviously this has pros and cons
731 \begin_layout Section
735 \begin_layout Standard
736 All packages used in this compiler system are
744 ; source code for all the sub-packages (pre-processor, assemblers, linkers
745 etc.) is distributed with the package.
746 This documentation is maintained using a free open source word processor
749 This program is free software; you can redistribute it and/or modify
750 it under the terms of the GNU General Public License
751 \begin_inset LatexCommand index
752 name "GNU General Public License, GPL"
756 as published by the Free Software Foundation; either version 2, or (at
757 your option) any later version.
758 This program is distributed in the hope that it will be useful, but WITHOUT
759 ANY WARRANTY; without even the implied warranty
760 \begin_inset LatexCommand index
765 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
766 See the GNU General Public License for more details.
767 You should have received a copy of the GNU General Public License along
768 with this program; if not, write to the Free Software Foundation, 59 Temple
769 Place - Suite 330, Boston, MA 02111-1307, USA.
770 In other words, you are welcome to use, share and improve this program.
771 You are forbidden to forbid anyone else to use, share and improve what
773 Help stamp out software-hoarding!
776 \begin_layout Section
777 Typographic conventions
778 \begin_inset LatexCommand index
779 name "Typographic conventions"
786 \begin_layout Standard
787 Throughout this manual, we will use the following convention.
788 Commands you have to type in are printed in
796 Code samples are printed in
801 Interesting items and new terms are printed in
806 \begin_layout Section
808 \begin_inset LatexCommand label
809 name "sec:Compatibility-with-previous"
813 with previous versions
814 \begin_inset LatexCommand index
815 name "Compatibility with previous versions"
822 \begin_layout Standard
823 Newer versions have usually numerous bug fixes compared with the previous
825 But we also sometimes introduce some incompatibilities with older versions.
826 Not just for the fun of it, but to make the compiler more stable, efficient
828 \begin_inset LatexCommand index
829 name "ANSI-compliance"
834 \begin_inset LatexCommand ref
835 reference "sub:ANSI-Compliance"
839 for ANSI-Compliance).
841 \begin_inset Note Note
844 \begin_layout Standard
845 It would be fine to add to each item, in which version was it changed.
855 \begin_layout Itemize
856 short is now equivalent to int (16 bits), it used to be equivalent to char
857 (8 bits) which is not ANSI compliant.
858 To maintain compatibility, old programs may be compiled using the -
862 \begin_layout Standard
871 -short-is-8bits commandline option (see
872 \begin_inset LatexCommand vref
873 reference "lyx:--short-is-8bits"
880 \begin_layout Itemize
881 the default directory for gcc-builds where include, library and documentation
882 files are stored is now in /usr/local/share.
885 \begin_layout Itemize
886 char type parameters to vararg
887 \begin_inset LatexCommand index
888 name "vararg, va\\_arg"
892 functions are casted to int unless explicitly casted and
898 \begin_layout Standard
908 \begin_inset LatexCommand index
921 \begin_layout Standard
931 \begin_inset LatexCommand index
938 command line option are not defined
939 \begin_inset Marginal
942 \begin_layout Standard
967 will push a as an int and as a char resp if
973 \begin_layout Standard
983 \begin_inset LatexCommand index
996 \begin_layout Standard
1006 \begin_inset LatexCommand index
1013 command line options are not defined,
1015 will push a as two ints if
1021 \begin_layout Standard
1031 \begin_inset LatexCommand index
1044 \begin_layout Standard
1054 \begin_inset LatexCommand index
1061 command line option is defined.
1064 \begin_layout Itemize
1069 \begin_layout Standard
1078 -regextend has been removed.
1081 \begin_layout Itemize
1086 \begin_layout Standard
1095 -noregparms has been removed.
1098 \begin_layout Itemize
1103 \begin_layout Standard
1112 -stack-after-data has been removed.
1115 \begin_layout Itemize
1117 \begin_inset LatexCommand index
1123 \begin_inset LatexCommand index
1129 \begin_inset LatexCommand index
1134 types now consistently behave like the C99 _Bool type with respect to type
1136 \begin_inset LatexCommand index
1137 name "type conversion"
1142 \begin_inset LatexCommand index
1143 name "type promotion"
1148 The most common incompatibility resulting from this change is related to
1150 \begin_inset LatexCommand index
1166 \begin_inset LatexCommand index
1167 name "\\~\\/ Operator"
1171 b; /* equivalent to b=1 instead of toggling b */
1172 \begin_inset Marginal
1175 \begin_layout Standard
1188 b = !b; /* toggles b */
1192 In previous versions, both forms would have toggled the bit.
1195 \begin_layout Itemize
1196 in older versions, the preprocessor was always called with
1202 \begin_layout Standard
1212 \begin_inset LatexCommand index
1225 \begin_layout Standard
1237 This is no longer true, and can cause compilation failures on code built
1244 \begin_layout Standard
1254 \begin_inset LatexCommand index
1261 but using c99 preprocessor features, such as one-line (//) comments
1264 \begin_layout Itemize
1265 in versions older then 2.8.4 the pic16 *printf() and printf_tiny() library
1266 functions supported undocumented and not standard compliant 'b' binary
1267 format specifier ("%b", "%hb" and "%lb").
1268 The 'b' specifier is now disabled by default.
1269 It can be enabled by defining BINARY_SPECIFIER macro in files device/lib/pic16/
1270 libc/stdio/vfprintf.c and device/lib/pic16/libc/stdio/printf_tiny.c and recompilin
1274 \begin_layout Itemize
1275 in versions older then 2.8.5 the unnamed bitfield structure members participated
1276 in initialization, which is not conforming with ISO/IEC 9899:1999 standard
1277 (see section Section 6.7.8 Initialization, clause 9)
1281 Old behavior, before
1317 /* s.a = 1, s.b = 3 */
1358 /* s.a = 1, s.b = 2 */
1361 \begin_layout Section
1365 \begin_layout Standard
1366 What do you need before you start installation of SDCC? A computer, and
1367 a desire to compute.
1368 The preferred method of installation is to compile SDCC from source using
1370 For Windows some pre-compiled binary distributions are available for your
1372 You should have some experience with command line tools and compiler use.
1375 \begin_layout Section
1379 \begin_layout Standard
1380 The SDCC home page at
1381 \begin_inset LatexCommand url
1382 target "http://sdcc.sourceforge.net/"
1386 is a great place to find distribution sets.
1387 You can also find links to the user mailing lists that offer help or discuss
1388 SDCC with other SDCC users.
1389 Web links to other SDCC related sites can also be found here.
1390 This document can be found in the DOC directory of the source package as
1391 a text or HTML file.
1392 A pdf version of this document is available at
1393 \begin_inset LatexCommand url
1394 target "http://sdcc.sourceforge.net/doc/sdccman.pdf"
1399 Some of the other tools (simulator and assembler) included with SDCC contain
1400 their own documentation and can be found in the source distribution.
1401 If you want the latest unreleased software, the complete source package
1402 is available directly from Subversion on https://sdcc.svn.sourceforge.net/svnroot/
1406 \begin_layout Section
1407 Wishes for the future
1410 \begin_layout Standard
1411 There are (and always will be) some things that could be done.
1412 Here are some I can think of:
1417 \begin_layout Standard
1420 char KernelFunction3(char p) at 0x340;
1425 \begin_layout Standard
1429 \begin_inset LatexCommand index
1430 name "code banking (limited support)"
1440 If you can think of some more, please see the section
1441 \begin_inset LatexCommand ref
1442 reference "sub:Requesting-Features"
1446 about filing feature requests
1447 \begin_inset LatexCommand index
1448 name "Requesting features"
1453 \begin_inset LatexCommand index
1454 name "Feature request"
1463 \begin_layout Chapter
1465 \begin_inset LatexCommand index
1473 \begin_layout Standard
1474 For most users it is sufficient to skip to either section
1475 \begin_inset LatexCommand ref
1476 reference "sub:Building-SDCC-on-Linux"
1481 \begin_inset LatexCommand ref
1482 reference "sub:Windows-Install"
1487 More detailed instructions follow below.
1490 \begin_layout Section
1492 \begin_inset LatexCommand index
1493 name "Options SDCC configuration"
1500 \begin_layout Standard
1501 The install paths, search paths and other options are defined when running
1503 The defaults can be overridden by:
1507 \labelwidthstring 00.00.0000
1512 \begin_layout Standard
1521 -prefix see table below
1525 \labelwidthstring 00.00.0000
1530 \begin_layout Standard
1539 -exec_prefix see table below
1543 \labelwidthstring 00.00.0000
1548 \begin_layout Standard
1557 -bindir see table below
1561 \labelwidthstring 00.00.0000
1566 \begin_layout Standard
1575 -datadir see table below
1579 \labelwidthstring 00.00.0000
1584 \begin_layout Standard
1593 -datarootdir see table below
1599 \labelwidthstring 00.00.0000
1602 docdir environment variable, see table below
1606 \labelwidthstring 00.00.0000
1609 include_dir_suffix environment variable, see table below
1613 \labelwidthstring 00.00.0000
1616 lib_dir_suffix environment variable, see table below
1620 \labelwidthstring 00.00.0000
1623 sdccconf_h_dir_separator environment variable, either / or
1628 This character will only be used in sdccconf.h; don't forget it's a C-header,
1629 therefore a double-backslash is needed there.
1635 \labelwidthstring 00.00.0000
1640 \begin_layout Standard
1649 -disable-mcs51-port Excludes the Intel mcs51 port
1653 \labelwidthstring 00.00.0000
1658 \begin_layout Standard
1667 -disable-gbz80-port Excludes the Gameboy gbz80 port
1671 \labelwidthstring 00.00.0000
1676 \begin_layout Standard
1685 -disable-z80-port Excludes the z80 port
1689 \labelwidthstring 00.00.0000
1694 \begin_layout Standard
1703 -disable-avr-port Excludes the AVR port
1707 \labelwidthstring 00.00.0000
1712 \begin_layout Standard
1721 -disable-ds390-port Excludes the DS390 port
1725 \labelwidthstring 00.00.0000
1730 \begin_layout Standard
1739 -disable-hc08-port Excludes the HC08 port
1743 \labelwidthstring 00.00.0000
1748 \begin_layout Standard
1757 -disable-pic-port Excludes the PIC14 port
1761 \labelwidthstring 00.00.0000
1766 \begin_layout Standard
1775 -disable-pic16-port Excludes the PIC16 port
1779 \labelwidthstring 00.00.0000
1784 \begin_layout Standard
1793 -disable-xa51-port Excludes the XA51 port
1797 \labelwidthstring 00.00.0000
1802 \begin_layout Standard
1811 -disable-ucsim Disables configuring and building of ucsim
1815 \labelwidthstring 00.00.0000
1820 \begin_layout Standard
1829 -disable-device-lib Disables automatically building device libraries
1833 \labelwidthstring 00.00.0000
1838 \begin_layout Standard
1847 -disable-packihx Disables building packihx
1853 \labelwidthstring 00.00.0000
1858 \begin_layout Standard
1867 -enable-doc Build pdf, html and txt files from the lyx sources
1871 \labelwidthstring 00.00.0000
1876 \begin_layout Standard
1885 -enable-libgc Use the Bohem memory allocator.
1886 Lower runtime footprint.
1890 \labelwidthstring 00.00.0000
1895 \begin_layout Standard
1904 -without-ccache Do not use ccache even if available
1907 \begin_layout Standard
1908 Furthermore the environment variables CC, CFLAGS, ...
1909 the tools and their arguments can be influenced.
1910 Please see `configure -
1914 \begin_layout Standard
1923 -help' and the man/info pages of `configure' for details.
1928 standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB, STD_FP_LIB, STD_DS390_LI
1929 B, STD_XA51_LIB and the environment variables SDCC_DIR_NAME, SDCC_INCLUDE_NAME,
1930 SDCC_LIB_NAME are defined by `configure' too.
1931 At the moment it's not possible to change the default settings (it was
1932 simply never required).
1936 These configure options are compiled into the binaries,
1937 and can only be changed by rerunning 'configure' and recompiling SDCC.
1938 The configure options are written in
1942 to distinguish them from run time environment variables (see section search
1948 \begin_inset Quotes sld
1952 \begin_inset Quotes srd
1955 are used by the SDCC team to build the official Win32 binaries.
1956 The SDCC team uses Mingw32 to build the official Windows binaries, because
1960 \begin_layout Enumerate
1964 \begin_layout Enumerate
1965 a gcc compiler and last but not least
1968 \begin_layout Enumerate
1969 the binaries can be built by cross compiling on SDCC Distributed Compile
1973 \begin_layout Standard
1974 See the examples, how to pass the Win32 settings to 'configure'.
1975 The other Win32 builds using Borland, VC or whatever don't use 'configure',
1976 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
1986 \begin_layout Standard
1988 \begin_inset Tabular
1989 <lyxtabular version="3" rows="9" columns="3">
1991 <column alignment="block" valignment="top" leftline="true" width="0in">
1992 <column alignment="block" valignment="top" leftline="true" width="0in">
1993 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1994 <row topline="true" bottomline="true">
1995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1998 \begin_layout Standard
2004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2007 \begin_layout Standard
2013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2016 \begin_layout Standard
2023 <row topline="true">
2024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2027 \begin_layout Standard
2035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2038 \begin_layout Standard
2044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2047 \begin_layout Standard
2056 <row topline="true">
2057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2060 \begin_layout Standard
2068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2071 \begin_layout Standard
2079 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2082 \begin_layout Standard
2091 <row topline="true">
2092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2095 \begin_layout Standard
2103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2106 \begin_layout Standard
2116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2119 \begin_layout Standard
2132 <row topline="true">
2133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2136 \begin_layout Standard
2144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2147 \begin_layout Standard
2155 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2158 \begin_layout Standard
2167 <row topline="true">
2168 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2171 \begin_layout Standard
2179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2182 \begin_layout Standard
2192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2195 \begin_layout Standard
2204 <row topline="true">
2205 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2208 \begin_layout Standard
2216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2219 \begin_layout Standard
2229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2232 \begin_layout Standard
2245 <row topline="true">
2246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2249 \begin_layout Standard
2257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2260 \begin_layout Standard
2266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2269 \begin_layout Standard
2276 <row topline="true" bottomline="true">
2277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2280 \begin_layout Standard
2288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2291 \begin_layout Standard
2297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2300 \begin_layout Standard
2316 \begin_layout Standard
2318 'configure' also computes relative paths.
2319 This is needed for full relocatability of a binary package and to complete
2320 search paths (see section search paths below):
2325 \begin_layout Standard
2327 \begin_inset Tabular
2328 <lyxtabular version="3" rows="4" columns="3">
2330 <column alignment="block" valignment="top" leftline="true" width="0in">
2331 <column alignment="block" valignment="top" leftline="true" width="0in">
2332 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2333 <row topline="true" bottomline="true">
2334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2337 \begin_layout Standard
2343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2346 \begin_layout Standard
2352 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2355 \begin_layout Standard
2362 <row topline="true" bottomline="true">
2363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2366 \begin_layout Standard
2374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2377 \begin_layout Standard
2383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2386 \begin_layout Standard
2393 <row bottomline="true">
2394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2397 \begin_layout Standard
2405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2408 \begin_layout Standard
2414 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2417 \begin_layout Standard
2424 <row bottomline="true">
2425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2428 \begin_layout Standard
2436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2439 \begin_layout Standard
2445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2448 \begin_layout Standard
2464 \begin_layout Standard
2469 \begin_layout LyX-Code
2476 \begin_layout Standard
2486 \begin_inset Quotes srd
2490 \begin_inset Quotes srd
2497 \begin_layout Standard
2507 \begin_inset Quotes srd
2511 \begin_inset Quotes srd
2520 \begin_layout Standard
2533 \begin_layout Standard
2545 \begin_layout Standard
2546 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
2550 \begin_layout LyX-Code
2556 \begin_inset Quotes srd
2559 i586-mingw32msvc-gcc
2560 \begin_inset Quotes srd
2564 \begin_inset Quotes srd
2567 i586-mingw32msvc-g++
2568 \begin_inset Quotes srd
2576 \begin_inset Quotes srd
2579 i586-mingw32msvc-ranlib
2580 \begin_inset Quotes srd
2588 \begin_inset Quotes srd
2591 i586-mingw32msvc-strip
2592 \begin_inset Quotes srd
2603 \begin_layout Standard
2613 \begin_inset Quotes srd
2617 \begin_inset Quotes srd
2628 \begin_layout Standard
2638 \begin_inset Quotes srd
2642 \begin_inset Quotes srd
2650 \begin_inset Quotes srd
2656 \begin_inset Quotes srd
2664 \begin_inset Quotes srd
2668 \begin_inset Quotes srd
2676 \begin_inset Quotes srd
2680 \begin_inset Quotes srd
2687 sdccconf_h_dir_separator=
2688 \begin_inset Quotes srd
2700 \begin_inset Quotes srd
2711 \begin_layout Standard
2728 \begin_layout Standard
2737 -host=i586-mingw32msvc
2745 \begin_layout Standard
2754 -build=unknown-unknown-linux-gnu
2757 \begin_layout Standard
2759 \begin_inset Quotes sld
2763 \begin_inset Quotes srd
2766 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
2770 \begin_layout LyX-Code
2779 \begin_layout Standard
2789 \begin_inset Quotes srd
2793 \begin_inset Quotes srd
2804 \begin_layout Standard
2814 \begin_inset Quotes srd
2818 \begin_inset Quotes srd
2826 \begin_inset Quotes srd
2832 \begin_inset Quotes srd
2840 \begin_inset Quotes srd
2844 \begin_inset Quotes srd
2852 \begin_inset Quotes srd
2856 \begin_inset Quotes srd
2863 sdccconf_h_dir_separator=
2864 \begin_inset Quotes srd
2876 \begin_inset Quotes srd
2884 \begin_inset Quotes srd
2888 \begin_inset Quotes srd
2896 \begin_inset Quotes srd
2900 \begin_inset Quotes srd
2906 \begin_layout Standard
2907 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
2912 \begin_layout Standard
2921 -C' turns on caching, which gives a little bit extra speed.
2922 However if options are changed, it can be necessary to delete the config.cache
2926 \begin_layout Section
2928 \begin_inset LatexCommand label
2929 name "sub:Install-paths"
2934 \begin_inset LatexCommand index
2935 name "Install paths"
2942 \begin_layout Standard
2943 \begin_inset VSpace medskip
2949 \begin_layout Standard
2951 \begin_inset Tabular
2952 <lyxtabular version="3" rows="5" columns="4">
2954 <column alignment="left" valignment="top" leftline="true" width="0">
2955 <column alignment="left" valignment="top" leftline="true" width="0">
2956 <column alignment="left" valignment="top" leftline="true" width="0">
2957 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
2958 <row topline="true" bottomline="true">
2959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2962 \begin_layout Standard
2970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2973 \begin_layout Standard
2981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2984 \begin_layout Standard
2992 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2995 \begin_layout Standard
3004 <row topline="true">
3005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3008 \begin_layout Standard
3014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3017 \begin_layout Standard
3025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3028 \begin_layout Standard
3034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3037 \begin_layout Standard
3048 <row topline="true">
3049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3052 \begin_layout Standard
3058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3061 \begin_layout Standard
3064 $DATADIR/ $INCLUDE_DIR_SUFFIX
3069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3072 \begin_layout Standard
3073 /usr/local/share/sdcc/include
3078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3081 \begin_layout Standard
3092 <row topline="true">
3093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3096 \begin_layout Standard
3102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3105 \begin_layout Standard
3108 $DATADIR/$LIB_DIR_SUFFIX
3113 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3116 \begin_layout Standard
3117 /usr/local/share/sdcc/lib
3122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3125 \begin_layout Standard
3136 <row topline="true" bottomline="true">
3137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3140 \begin_layout Standard
3146 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3149 \begin_layout Standard
3157 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3160 \begin_layout Standard
3161 /usr/local/share/sdcc/doc
3166 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3169 \begin_layout Standard
3190 *compiler, preprocessor, assembler, and linker
3196 is auto-appended by the compiler, e.g.
3197 small, large, z80, ds390 etc
3200 \begin_layout Standard
3202 The install paths can still be changed during `make install' with e.g.:
3205 \begin_layout LyX-Code
3206 make install prefix=$(HOME)/local/sdcc
3209 \begin_layout Standard
3210 Of course this doesn't change the search paths compiled into the binaries.
3215 r the install path can be changed by defining DESTDIR
3216 \begin_inset LatexCommand index
3224 \begin_layout LyX-Code
3225 make install DESTDIR=$(HOME)/sdcc.rpm/
3228 \begin_layout Standard
3229 Please note that DESTDIR must have a trailing slash!
3232 \begin_layout Section
3234 \begin_inset LatexCommand label
3235 name "sub:Search-Paths"
3240 \begin_inset LatexCommand index
3248 \begin_layout Standard
3249 Some search paths or parts of them are determined by configure variables
3254 , see section above).
3255 Further search paths are determined by environment variables during runtime.
3258 The paths searched when running the compiler are as follows (the first
3264 Binary files (preprocessor, assembler and linker)
3269 \begin_layout Standard
3271 \begin_inset Tabular
3272 <lyxtabular version="3" rows="4" columns="3">
3274 <column alignment="block" valignment="top" leftline="true" width="0in">
3275 <column alignment="block" valignment="top" leftline="true" width="0in">
3276 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3277 <row topline="true" bottomline="true">
3278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3281 \begin_layout Standard
3287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3290 \begin_layout Standard
3296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3299 \begin_layout Standard
3306 <row topline="true">
3307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3310 \begin_layout Standard
3318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3321 \begin_layout Standard
3327 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3330 \begin_layout Standard
3339 <row topline="true">
3340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3343 \begin_layout Standard
3344 Path of argv[0] (if available)
3349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3352 \begin_layout Standard
3358 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3361 \begin_layout Standard
3368 <row topline="true" bottomline="true">
3369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3372 \begin_layout Standard
3378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3381 \begin_layout Standard
3387 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3390 \begin_layout Standard
3406 \begin_layout Standard
3414 \begin_layout Standard
3416 \begin_inset Tabular
3417 <lyxtabular version="3" rows="6" columns="3">
3419 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3420 <column alignment="block" valignment="top" leftline="true" width="1.5in">
3421 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
3422 <row topline="true" bottomline="true">
3423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3426 \begin_layout Standard
3432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3435 \begin_layout Standard
3441 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3444 \begin_layout Standard
3451 <row topline="true">
3452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3455 \begin_layout Standard
3460 \begin_layout Standard
3474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3477 \begin_layout Standard
3482 \begin_layout Standard
3496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3499 \begin_layout Standard
3504 \begin_layout Standard
3519 <row topline="true">
3520 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3523 \begin_layout Standard
3529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3532 \begin_layout Standard
3538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3541 \begin_layout Standard
3548 <row topline="true">
3549 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3552 \begin_layout Standard
3564 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3567 \begin_layout Standard
3577 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3580 \begin_layout Standard
3589 <row topline="true">
3590 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3593 \begin_layout Standard
3609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3612 \begin_layout Standard
3660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3663 \begin_layout Standard
3674 <row topline="true" bottomline="true">
3675 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3678 \begin_layout Standard
3692 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3695 \begin_layout Standard
3696 /usr/local/share/sdcc/
3703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3706 \begin_layout Standard
3722 \begin_layout Standard
3728 \begin_layout Standard
3737 -nostdinc disables the last two search paths.
3747 \begin_layout Standard
3748 With the exception of
3749 \begin_inset Quotes sld
3756 \begin_layout Standard
3766 \begin_inset Quotes srd
3773 is auto-appended by the compiler (e.g.
3774 small, large, z80, ds390 etc.).
3780 \begin_layout Standard
3782 \begin_inset Tabular
3783 <lyxtabular version="3" rows="6" columns="3">
3785 <column alignment="block" valignment="top" leftline="true" width="1.7in">
3786 <column alignment="block" valignment="top" leftline="true" width="1.2in">
3787 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
3788 <row topline="true" bottomline="true">
3789 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3792 \begin_layout Standard
3798 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3801 \begin_layout Standard
3807 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3810 \begin_layout Standard
3817 <row topline="true">
3818 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3821 \begin_layout Standard
3826 \begin_layout Standard
3840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3843 \begin_layout Standard
3848 \begin_layout Standard
3862 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3865 \begin_layout Standard
3870 \begin_layout Standard
3885 <row topline="true">
3886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3889 \begin_layout Standard
3899 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3902 \begin_layout Standard
3912 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3915 \begin_layout Standard
3928 <row topline="true">
3929 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3932 \begin_layout Standard
3939 $LIB_DIR_SUFFIX/<model>
3944 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3947 \begin_layout Standard
3959 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3962 \begin_layout Standard
3977 <row topline="true">
3978 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
3981 \begin_layout Standard
3992 $LIB_DIR_SUFFIX/<model>
3997 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
4000 \begin_layout Standard
4051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4054 \begin_layout Standard
4108 <row topline="true" bottomline="true">
4109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4112 \begin_layout Standard
4117 $LIB_DIR_SUFFIX/<model>
4122 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4125 \begin_layout Standard
4126 /usr/local/share/sdcc/
4135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4138 \begin_layout Standard
4154 \begin_layout Standard
4155 \begin_inset Note Note
4158 \begin_layout Standard
4159 Don't delete any of the stray spaces in the table above without checking
4160 the HTML output (last line)!
4168 \begin_layout Standard
4176 \begin_layout Standard
4185 -nostdlib disables the last two search paths.
4188 \begin_layout Section
4190 \begin_inset LatexCommand index
4191 name "Building SDCC"
4198 \begin_layout Subsection
4199 Building SDCC on Linux
4200 \begin_inset LatexCommand label
4201 name "sub:Building-SDCC-on-Linux"
4208 \begin_layout Enumerate
4211 Download the source package
4213 either from the SDCC Subversion repository or from snapshot builds
4215 , it will be named something like sdcc
4226 \begin_inset LatexCommand url
4227 target "http://sdcc.sourceforge.net/snap.php"
4234 \begin_layout Enumerate
4237 Bring up a command line terminal, such as xterm.
4240 \begin_layout Enumerate
4243 Unpack the file using a command like:
4248 "tar -xvzf sdcc-src-yyyymmdd-rrrr.tar.bz2
4249 \begin_inset Quotes srd
4255 , this will create a sub-directory called sdcc with all of the sources.
4258 \begin_layout Enumerate
4259 Change directory into the main SDCC directory, for example type:
4267 \begin_layout Enumerate
4279 This configures the package for compilation on your system.
4282 \begin_layout Enumerate
4298 All of the source packages will compile, this can take a while.
4301 \begin_layout Enumerate
4317 This copies the binary executables, the include files, the libraries and
4318 the documentation to the install directories.
4319 Proceed with section
4320 \begin_inset LatexCommand ref
4321 reference "sec:Testing-the-SDCC"
4328 \begin_layout Subsection
4329 Building SDCC on Mac OS X
4332 \begin_layout Standard
4333 Follow the instruction for Linux.
4337 On Mac OS X 10.2.x it was reported, that the
4338 default gcc (version 3.1 20020420 (prerelease)) fails to compile SDCC.
4339 Fortunately there's also gcc 2.9.x installed, which works fine.
4340 This compiler can be selected by running 'configure' with:
4343 \begin_layout LyX-Code
4344 ./configure CC=gcc2 CXX=g++2
4347 \begin_layout Standard
4348 Universal (ppc and i386) binaries can be produced on Mac OS X 10.4.x with
4350 Run 'configure' with:
4353 \begin_layout LyX-Code
4359 \begin_layout LyX-Code
4360 LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4366 \begin_layout LyX-Code
4367 CXXFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch
4373 \begin_layout LyX-Code
4374 CFLAGS = "-O2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"
4377 \begin_layout Subsection
4378 Cross compiling SDCC on Linux for Windows
4381 \begin_layout Standard
4382 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
4383 See section 'Configure Options'.
4386 \begin_layout Subsection
4387 Building SDCC using Cygwin and Mingw32
4390 \begin_layout Standard
4391 For building and installing a Cygwin executable follow the instructions
4397 \begin_inset Quotes sld
4401 \begin_inset Quotes srd
4404 Win32-binary can be built, which will not need the Cygwin-DLL.
4405 For the necessary 'configure' options see section 'configure options' or
4406 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
4411 Cygwin on Windows download setup.exe from
4412 \begin_inset LatexCommand url
4413 name "www.cygwin.com"
4414 target "http://www.cygwin.com/"
4420 \begin_inset Quotes sld
4423 default text file type
4424 \begin_inset Quotes srd
4428 \begin_inset Quotes sld
4432 \begin_inset Quotes srd
4435 and download/install at least the following packages.
4436 Some packages are selected by default, others will be automatically selected
4437 because of dependencies with the manually selected packages.
4438 Never deselect these packages!
4441 \begin_layout Itemize
4445 \begin_layout Itemize
4449 \begin_layout Itemize
4450 gcc ; version 3.x is fine, no need to use the old 2.9x
4453 \begin_layout Itemize
4454 binutils ; selected with gcc
4457 \begin_layout Itemize
4461 \begin_layout Itemize
4462 rxvt ; a nice console, which makes life much easier under windoze (see below)
4465 \begin_layout Itemize
4466 man ; not really needed for building SDCC, but you'll miss it sooner or
4470 \begin_layout Itemize
4471 less ; not really needed for building SDCC, but you'll miss it sooner or
4475 \begin_layout Itemize
4476 svn ; only if you use Subversion access
4479 \begin_layout Standard
4480 If you want to develop something you'll need:
4483 \begin_layout Itemize
4484 python ; for the regression tests
4487 \begin_layout Itemize
4488 gdb ; the gnu debugger, together with the nice GUI
4489 \begin_inset Quotes sld
4493 \begin_inset Quotes srd
4499 \begin_layout Itemize
4500 openssh ; to access the CF or commit changes
4503 \begin_layout Itemize
4504 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
4505 use autoconf-stable!
4508 \begin_layout Standard
4509 rxvt is a nice console with history.
4510 Replace in your cygwin.bat the line
4513 \begin_layout LyX-Code
4518 \begin_layout Standard
4530 \begin_layout Standard
4534 \begin_layout LyX-Code
4535 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
4538 \begin_layout LyX-Code
4539 -bg black -fg white -geometry 100x65 -e bash -
4543 \begin_layout Standard
4555 \begin_layout Standard
4556 Text selected with the mouse is automatically copied to the clipboard, pasting
4557 works with shift-insert.
4561 The other good tip is to make sure you have no //c/-styl
4562 e paths anywhere, use /cygdrive/c/ instead.
4563 Using // invokes a network lookup which is very slow.
4565 \begin_inset Quotes sld
4569 \begin_inset Quotes srd
4572 is too long, you can change it with e.g.
4575 \begin_layout LyX-Code
4579 \begin_layout Standard
4580 SDCC sources use the unix line ending LF.
4581 Life is much easier, if you store the source tree on a drive which is mounted
4583 And use an editor which can handle LF-only line endings.
4584 Make sure not to commit files with windows line endings.
4585 The tabulator spacing
4586 \begin_inset LatexCommand index
4587 name "tabulator spacing (8 columns)"
4591 used in the project is 8.
4592 Although a tabulator spacing of 8 is a sensible choice for programmers
4593 (it's a power of 2 and allows to display 8/16 bit signed variables without
4594 loosing columns) the plan is to move towards using only spaces in the source.
4597 \begin_layout Subsection
4598 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
4601 \begin_layout Standard
4604 Download the source package
4606 either from the SDCC Subversion repository or from the
4607 \begin_inset LatexCommand url
4608 name "snapshot builds"
4609 target "http://sdcc.sourceforge.net/snap.php"
4615 , it will be named something like sdcc
4619 -yyyymmdd-rrrr.tar.bz2.
4622 SDCC is distributed with all the projects, workspaces, and files you need
4623 to build it using Visual C++ 6.0/NET (except for SDCDB and ucSim).
4624 The workspace name is 'sdcc.dsw'.
4625 Please note that as it is now, all the executables are created in a folder
4629 Once built you need to copy the executables from sdcc
4633 bin before running SDCC.
4638 WARNING: Visual studio is very picky with line terminations; it expects
4639 the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
4640 When using the Subversion repository it's easiest to configure the svn
4641 client to convert automatically for you.
4642 If however you are getting a message such as "This makefile was not generated
4643 by Developer Studio etc.
4645 \begin_inset Quotes srd
4648 when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
4649 need to convert the Unix style line endings to DOS style line endings.
4650 To do so you can use the
4651 \begin_inset Quotes sld
4655 \begin_inset Quotes srd
4658 utility freely available on the internet.
4659 Doug Hawkins reported in the sdcc-user list that this works:
4667 SDCC> unix2dos sdcc.dsw
4673 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
4677 In order to build SDCC with MSVC
4678 you need win32 executables of bison.exe, flex.exe, and gawk.exe.
4679 One good place to get them is
4680 \begin_inset LatexCommand url
4682 target "http://unxutils.sourceforge.net"
4690 Download the file UnxUtils
4691 \begin_inset LatexCommand index
4697 Now you have to install the utilities and setup MSVC so it can locate the
4699 Here there are two alternatives (choose one!):
4702 \begin_layout Enumerate
4707 a) Extract UnxUtils.zip to your C:
4709 hard disk PRESERVING the original paths, otherwise bison won't work.
4710 (If you are using WinZip make certain that 'Use folder names' is selected)
4715 In the Visual C++ IDE click Tools, Options, select the Directory tab, in
4716 'Show directories for:' select 'Executable files', and in the directories
4717 window add a new path: 'C:
4727 (As a side effect, you get a bunch of Unix utilities that
4728 could be useful, such as diff and patch.)
4731 \begin_layout Enumerate
4736 This one avoids extracting a bunch of files you may not
4737 use, but requires some extra work:
4741 a) Create a directory were to put the
4742 tools needed, or use a directory already present.
4749 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and
4750 gawk.exe to such directory WITHOUT preserving the original paths.
4751 (If you are using WinZip make certain that 'Use folder names' is not selected)
4756 ) Rename bison.exe to '_bison.exe'.
4760 d) Create a batch file 'bison.bat' in 'C:
4764 ' and add these lines:
4784 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
4788 Steps 'c' and 'd' are needed
4789 because bison requires by default that the files 'bison.simple' and 'bison.hairy'
4790 reside in some weird Unix directory, '/usr/local/share/' I think.
4791 So it is necessary to tell bison where those files are located if they
4792 are not in such directory.
4793 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
4798 ) In the Visual C++ IDE click Tools, Options, select the Directory tab,
4799 in 'Show directories for:' select 'Executable files', and in the directories
4800 window add a new path: 'c:
4803 Note that you can use any other path instead of 'c:
4805 util', even the path where the Visual C++ tools are, probably: 'C:
4809 Microsoft Visual Studio
4814 So you don't have to execute step 'e' :)
4817 \begin_layout Standard
4819 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
4820 the executables from sdcc
4824 bin, and you can compile using SDCC.
4827 \begin_layout Subsection
4828 Building SDCC Using Borland
4831 \begin_layout Enumerate
4832 From the sdcc directory, run the command "make -f Makefile.bcc".
4833 This should regenerate all the .exe files in the bin directory except for
4837 \begin_layout Enumerate
4838 If you modify any source files and need to rebuild, be aware that the dependenci
4839 es may not be correctly calculated.
4840 The safest option is to delete all .obj files and run the build again.
4841 From a Cygwin BASH prompt, this can easily be done with the command (be
4842 sure you are in the sdcc directory):
4852 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
4854 ) -print -exec rm {}
4863 or on Windows NT/2000/XP from the command prompt with the command:
4870 del /s *.obj *.lib *.rul
4873 from the sdcc directory.
4876 \begin_layout Subsection
4877 Windows Install Using a ZIP Package
4880 \begin_layout Enumerate
4881 Download the binary zip package from
4882 \begin_inset LatexCommand url
4883 target "http://sdcc.sf.net/snap.php"
4887 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
4888 This should unpack to a group of sub-directories.
4889 An example directory structure after unpacking the mingw32 package is:
4894 bin for the executables, c:
4902 lib for the include and libraries.
4905 \begin_layout Enumerate
4906 Adjust your environment variable PATH to include the location of the bin
4907 directory or start sdcc using the full path.
4910 \begin_layout Subsection
4911 Windows Install Using the Setup Program
4912 \begin_inset LatexCommand label
4913 name "sub:Windows-Install"
4920 \begin_layout Standard
4921 Download the setup program
4923 sdcc-x.y.z-setup.exe
4925 for an official release from
4928 \begin_inset LatexCommand url
4929 target "http://sf.net/project/showfiles.php?group_id=599"
4933 or a setup program for one of the snapshots
4935 sdcc-yyyymmdd-xxxx-setup.exe
4938 \begin_inset LatexCommand url
4939 target "http://sdcc.sf.net/snap.php"
4944 A windows typical installer will guide you through the installation process.
4947 \begin_layout Subsection
4949 \begin_inset LatexCommand index
4957 \begin_layout Standard
4958 SDCC supports the VPATH feature provided by configure and make.
4959 It allows to separate the source and build trees.
4963 \begin_layout Standard
4990 \begin_layout Standard
4993 tar -xzf sdcc.src.tar.gz\InsetSpace ~
4994 # extract source to directory sdcc
4997 \begin_layout Standard
5000 mkdir sdcc.build\InsetSpace ~
5009 # put output in sdcc.build
5012 \begin_layout Standard
5018 \begin_layout Standard
5021 ../sdcc/configure\InsetSpace ~
5029 # configure is doing all the magic!
5032 \begin_layout Standard
5038 \begin_layout Standard
5044 will create the directory tree will all the necessary Makefiles in ~/sdcc.build.
5045 It automagically computes the variables srcdir, top_srcdir and top_buildir
5051 the generated files will be in ~/sdcc.build, while the source files stay
5054 This is not only usefull for building different binaries, e.g.
5055 when cross compiling.
5056 It also gives you a much better overview in the source tree when all the
5057 generated files are not scattered between the source files.
5058 And the best thing is: if you want to change a file you can leave the original
5059 file untouched in the source directory.
5060 Simply copy it to the build directory, edit it, enter `make clean', `rm
5061 Makefile.dep' and `make'.
5066 will do the rest for you!
5069 \begin_layout Section
5070 Building the Documentation
5073 \begin_layout Standard
5078 \begin_layout Standard
5087 -enable-doc to the configure arguments to build the documentation together
5088 with all the other stuff.
5089 You will need several tools (LyX, LaTeX, LaTeX2HTML, pdflatex, dvipdf,
5090 dvips and makeindex) to get the job done.
5091 Another possibility is to change to the doc directory and to type
5095 \begin_inset Quotes srd
5099 \begin_inset Quotes srd
5106 You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
5109 \begin_inset LatexCommand url
5110 target "http://www.lyx.org"
5114 as editor is straightforward.
5115 Prebuilt documentation in html and pdf format is available from
5116 \begin_inset LatexCommand url
5117 target "http://sdcc.sf.net/snap.php"
5124 \begin_layout Section
5125 Reading the Documentation
5126 \begin_inset LatexCommand index
5127 name "Documentation"
5134 \begin_layout Standard
5135 Currently reading the document in pdf format is recommended, as for unknown
5136 reason the hyperlinks are working there whereas in the html version they
5141 \begin_layout Standard
5142 If you should know why please drop us a note
5150 You'll find the pdf version
5151 \begin_inset LatexCommand index
5152 name "PDF version of this document"
5157 \begin_inset LatexCommand url
5158 target "http://sdcc.sf.net/doc/sdccman.pdf"
5166 \begin_inset LatexCommand index
5167 name "HTML version of this document"
5172 \begin_inset LatexCommand url
5173 target "http://sdcc.sf.net/doc/sdccman.html/index.html"
5179 This documentation is in some aspects different from a commercial documentation:
5183 \begin_layout Itemize
5184 It tries to document SDCC for several processor architectures in one document
5185 (commercially these probably would be separate documents/products).
5187 \begin_inset LatexCommand index
5188 name "Status of documentation"
5192 currently matches SDCC for mcs51 and DS390 best and does give too few informati
5194 Z80, PIC14, PIC16 and HC08.
5197 \begin_layout Itemize
5198 There are many references pointing away from this documentation.
5199 Don't let this distract you.
5201 was a reference like
5202 \begin_inset LatexCommand url
5203 target "http://www.opencores.org"
5207 together with a statement
5208 \begin_inset Quotes sld
5211 some processors which are targetted by SDCC can be implemented in a
5228 \begin_inset LatexCommand index
5229 name "FPGA (field programmable gate array)"
5234 \begin_inset Quotes srd
5238 \begin_inset LatexCommand url
5239 target "http://sf.net/projects/fpgac"
5244 \begin_inset LatexCommand index
5245 name "FpgaC ((subset of) C to FPGA compiler)"
5250 \begin_inset Quotes sld
5253 have you ever heard of an open source compiler that compiles a subset of
5255 \begin_inset Quotes srd
5258 we expect you to have a quick look there and come back.
5259 If you read this you are on the right track.
5262 \begin_layout Itemize
5263 Some sections attribute more space to problems, restrictions and warnings
5264 than to the solution.
5267 \begin_layout Itemize
5268 The installation section and the section about the debugger is intimidating.
5271 \begin_layout Itemize
5272 There are still lots of typos and there are more different writing styles
5276 \begin_layout Section
5277 Testing the SDCC Compiler
5278 \begin_inset LatexCommand label
5279 name "sec:Testing-the-SDCC"
5286 \begin_layout Standard
5287 The first thing you should do after installing your SDCC compiler is to
5296 \begin_layout Standard
5306 \begin_inset LatexCommand index
5314 at the prompt, and the program should run and output its version like:
5319 SDCC : mcs51/z80/avr/ds390/pic16/pic14/ds400/hc08 2.5.6 #4169 (May 8 2006)
5323 \begin_layout Standard
5324 If it doesn't run, or gives a message about not finding sdcc program, then
5325 you need to check over your installation.
5326 Make sure that the sdcc bin directory is in your executable search path
5327 defined by the PATH environment setting (
5332 \begin_inset LatexCommand ref
5333 reference "sub:Install-Trouble-shooting"
5340 Install trouble-shooting for suggestions
5343 Make sure that the sdcc program is in the bin folder, if not perhaps something
5344 did not install correctly.
5352 is commonly installed as described in section
5353 \begin_inset Quotes sld
5356 Install and search paths
5357 \begin_inset Quotes srd
5366 Make sure the compiler works on a very simple example.
5367 Type in the following test.c program using your favorite
5392 \begin_layout Standard
5395 Compile this using the following command:
5406 If all goes well, the compiler will generate a test.asm and test.rel file.
5407 Congratulations, you've just compiled your first program with SDCC.
5408 We used the -c option to tell SDCC not to link the generated code, just
5409 to keep things simple for this step.
5417 The next step is to try it with the linker.
5429 If all goes well the compiler will link with the libraries and produce
5430 a test.ihx output file.
5435 (no test.ihx, and the linker generates warnings), then the problem is most
5444 usr/local/share/sdcc/lib directory
5451 \begin_inset LatexCommand ref
5452 reference "sub:Install-Trouble-shooting"
5459 Install trouble-shooting for suggestions).
5467 The final test is to ensure
5475 header files and libraries.
5476 Edit test.c and change it to the following:
5494 strcpy(str1, "testing");
5499 \begin_layout Standard
5502 Compile this by typing
5511 This should generate a test.ihx output file, and it should give no warnings
5512 such as not finding the string.h file.
5513 If it cannot find the string.h file, then the problem is that
5517 cannot find the /usr/local/share/sdcc/include directory
5524 \begin_inset LatexCommand ref
5525 reference "sub:Install-Trouble-shooting"
5532 Install trouble-shooting section for suggestions).
5541 \begin_layout Standard
5553 \begin_inset LatexCommand index
5554 name "-\\/-print-search-dirs"
5558 to find exactly where SDCC is looking for the include and lib files.
5561 \begin_layout Section
5562 Install Trouble-shooting
5563 \begin_inset LatexCommand label
5564 name "sub:Install-Trouble-shooting"
5569 \begin_inset LatexCommand index
5570 name "Install trouble-shooting"
5577 \begin_layout Subsection
5578 If SDCC does not build correctly
5581 \begin_layout Standard
5582 A thing to try is starting from scratch by unpacking the .tgz source package
5583 again in an empty directory.
5591 ./configure 2>&1 | tee configure.log
5605 make 2>&1 | tee make.log
5612 If anything goes wrong, you can review the log files to locate the problem.
5613 Or a relevant part of this can be attached to an email that could be helpful
5614 when requesting help from the mailing list.
5617 \begin_layout Subsection
5619 \begin_inset Quotes sld
5623 \begin_inset Quotes srd
5629 \begin_layout Standard
5631 \begin_inset Quotes sld
5635 \begin_inset Quotes srd
5638 command is a script that analyzes your system and performs some configuration
5639 to ensure the source package compiles on your system.
5640 It will take a few minutes to run, and will compile a few tests to determine
5641 what compiler features are installed.
5644 \begin_layout Subsection
5646 \begin_inset Quotes sld
5650 \begin_inset Quotes srd
5656 \begin_layout Standard
5657 This runs the GNU make tool, which automatically compiles all the source
5658 packages into the final installed binary executables.
5661 \begin_layout Subsection
5663 \begin_inset Quotes sld
5667 \begin_inset Quotes erd
5673 \begin_layout Standard
5674 This will install the compiler, other executables libraries and include
5675 files into the appropriate directories.
5677 \begin_inset LatexCommand ref
5678 reference "sub:Install-paths"
5684 \begin_inset LatexCommand ref
5685 reference "sub:Search-Paths"
5690 about install and search paths.
5692 On most systems you will need super-user privilege
5696 \begin_layout Section
5700 \begin_layout Standard
5701 SDCC is not just a compiler, but a collection of tools by various developers.
5702 These include linkers, assemblers, simulators and other components.
5703 Here is a summary of some of the components.
5704 Note that the included simulator and assembler have separate documentation
5705 which you can find in the source package in their respective directories.
5706 As SDCC grows to include support for other processors, other packages from
5707 various developers are included and may have their own sets of documentation.
5712 might want to look at the files which are installed in <installdir>.
5713 At the time of this writing, we find the following programs for gcc-builds:
5718 In <installdir>/bin:
5721 \begin_layout Itemize
5722 sdcc - The compiler.
5725 \begin_layout Itemize
5726 sdcpp - The C preprocessor.
5729 \begin_layout Itemize
5730 asx8051 - The assembler for 8051 type processors.
5733 \begin_layout Itemize
5738 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
5741 \begin_layout Itemize
5742 aslink -The linker for 8051 type processors.
5745 \begin_layout Itemize
5750 link-gbz80 - The Z80 and GameBoy Z80 linkers.
5753 \begin_layout Itemize
5754 s51 - The ucSim 8051 simulator.
5757 \begin_layout Itemize
5758 sdcdb - The source debugger.
5761 \begin_layout Itemize
5762 packihx - A tool to pack (compress) Intel hex files.
5765 \begin_layout Standard
5766 In <installdir>/share/sdcc/include
5769 \begin_layout Itemize
5773 \begin_layout Standard
5774 In <installdir>/share/sdcc/lib
5777 \begin_layout Itemize
5778 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
5782 \begin_layout Standard
5783 In <installdir>/share/sdcc/doc
5786 \begin_layout Itemize
5790 \begin_layout Standard
5791 As development for other processors proceeds, this list will expand to include
5792 executables to support processors like AVR, PIC, etc.
5795 \begin_layout Subsection
5799 \begin_layout Standard
5800 This is the actual compiler, it in turn uses the c-preprocessor and invokes
5801 the assembler and linkage editor.
5804 \begin_layout Subsection
5805 sdcpp - The C-Preprocessor
5808 \begin_layout Standard
5810 \begin_inset LatexCommand index
5811 name "sdcpp (preprocessor)"
5815 is a modified version of the GNU cpp
5816 \begin_inset LatexCommand index
5817 name "cpp|see{sdcpp}"
5822 \begin_inset LatexCommand url
5823 target "http://gcc.gnu.org/"
5828 The C preprocessor is used to pull in #include sources, process #ifdef
5829 statements, #defines and so on.
5832 \begin_layout Subsection
5841 - The Assemblers and Linkage Editors
5844 \begin_layout Standard
5845 This is retargettable assembler & linkage editor, it was developed by Alan
5847 John Hartman created the version for 8051, and I (Sandeep) have made some
5848 enhancements and bug fixes for it to work properly with SDCC.
5851 \begin_layout Subsection
5855 \begin_layout Standard
5857 \begin_inset LatexCommand index
5862 is a free open source simulator developed by Daniel Drotos.
5863 The simulator is built as part of the build process.
5864 For more information visit Daniel's web site at:
5865 \begin_inset LatexCommand url
5866 target "http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51"
5871 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
5875 \begin_layout Subsection
5876 sdcdb - Source Level Debugger
5879 \begin_layout Standard
5881 \begin_inset LatexCommand index
5882 name "SDCDB (debugger)"
5886 is the companion source level debugger.
5887 More about SDCDB in section
5888 \begin_inset LatexCommand ref
5889 reference "cha:Debugging-with-SDCDB"
5894 The current version of the debugger uses Daniel's Simulator S51
5895 \begin_inset LatexCommand index
5900 , but can be easily changed to use other simulators.
5903 \begin_layout Chapter
5907 \begin_layout Section
5911 \begin_layout Subsection
5912 Single Source File Projects
5915 \begin_layout Standard
5916 For single source file 8051 projects the process is very simple.
5917 Compile your programs with the following command
5920 "sdcc sourcefile.c".
5924 This will compile, assemble and link your source file.
5925 Output files are as follows:
5928 \begin_layout Itemize
5930 \begin_inset LatexCommand index
5936 \begin_inset LatexCommand index
5937 name "Assembler source"
5941 file created by the compiler
5944 \begin_layout Itemize
5946 \begin_inset LatexCommand index
5952 \begin_inset LatexCommand index
5953 name "Assembler listing"
5957 file created by the Assembler
5960 \begin_layout Itemize
5962 \begin_inset LatexCommand index
5968 \begin_inset LatexCommand index
5969 name "Assembler listing"
5973 file updated with linkedit information, created by linkage editor
5976 \begin_layout Itemize
5978 \begin_inset LatexCommand index
5984 \begin_inset LatexCommand index
5985 name "Symbol listing"
5989 for the sourcefile, created by the assembler
5992 \begin_layout Itemize
5994 \begin_inset LatexCommand index
6000 \begin_inset LatexCommand index
6006 \begin_inset LatexCommand index
6011 created by the assembler, input to Linkage editor
6014 \begin_layout Itemize
6016 \begin_inset LatexCommand index
6022 \begin_inset LatexCommand index
6027 for the load module, created by the Linker
6030 \begin_layout Itemize
6032 \begin_inset LatexCommand index
6037 - A file with a summary of the memory usage
6040 \begin_layout Itemize
6042 \begin_inset LatexCommand index
6047 - The load module in Intel hex format
6048 \begin_inset LatexCommand index
6049 name "Intel hex format"
6053 (you can select the Motorola S19 format
6054 \begin_inset LatexCommand index
6055 name "Motorola S19 format"
6063 \begin_layout Standard
6073 \begin_inset LatexCommand index
6074 name "-\\/-out-fmt-s19"
6079 If you need another format you might want to use
6086 \begin_inset LatexCommand index
6087 name "objdump (tool)"
6098 \begin_inset LatexCommand index
6099 name "srecord (bin, hex, ... tool)"
6104 \begin_inset Note Note
6107 \begin_layout Standard
6114 \begin_inset LatexCommand vref
6115 reference "sub:Postprocessing-the-Intel"
6120 Both formats are documented in the documentation of srecord
6121 \begin_inset LatexCommand index
6122 name "srecord (bin, hex, ... tool)"
6129 \begin_layout Itemize
6131 \begin_inset LatexCommand index
6136 - An intermediate file containing debug information needed to create the
6141 \begin_layout Standard
6151 \begin_inset LatexCommand index
6159 \begin_layout Itemize
6161 \begin_inset LatexCommand index
6166 - An optional file (with -
6170 \begin_layout Standard
6179 -debug) containing debug information.
6180 The format is documented in cdbfileformat.pdf
6183 \begin_layout Itemize
6186 \begin_inset LatexCommand index
6187 name "<file> (no extension)"
6191 An optional AOMF or AOMF51
6192 \begin_inset LatexCommand index
6198 \begin_inset LatexCommand label
6203 file containing debug information (generated with option -
6207 \begin_layout Standard
6233 ormat is a subformat of the OMF51 format and is commonly used by third party
6235 \begin_inset LatexCommand index
6240 , simulators, emulators).
6243 \begin_layout Itemize
6245 \begin_inset LatexCommand index
6250 - Dump file to debug the compiler it self (generated with option -
6254 \begin_layout Standard
6263 -dumpall) (see section
6264 \begin_inset LatexCommand ref
6265 reference "sub:Intermediate-Dump-Options"
6271 \begin_inset LatexCommand ref
6272 reference "sub:The-anatomy-of"
6278 \begin_inset Quotes sld
6281 Anatomy of the compiler
6282 \begin_inset Quotes srd
6288 \begin_layout Subsection
6289 Postprocessing the Intel Hex
6290 \begin_inset LatexCommand index
6291 name "Intel hex format"
6296 \begin_inset LatexCommand label
6297 name "sub:Postprocessing-the-Intel"
6304 \begin_layout Standard
6305 In most cases this won't be needed but the Intel Hex file
6306 \begin_inset LatexCommand index
6311 which is generated by SDCC might include lines of varying length and the
6312 addresses within the file are not guaranteed to be strictly ascending.
6313 If your toolchain or a bootloader does not like this you can use the tool
6319 \begin_inset LatexCommand index
6320 name "packihx (tool)"
6324 which is part of the SDCC distribution:
6331 packihx sourcefile.ihx >sourcefile.hex
6338 The separately available
6343 \begin_inset LatexCommand index
6344 name "srecord (bin, hex, ... tool)"
6348 package additionally allows to set undefined locations to a predefined
6349 value, to insert checksums
6350 \begin_inset LatexCommand index
6355 of various flavours (crc, add, xor) and to perform other manipulations
6356 (convert, split, crop, offset, ...).
6364 srec_cat\InsetSpace ~
6366 sourcefile.ihx -intel\InsetSpace ~
6368 -o sourcefile.hex -intel
6375 An example for a more complex command line
6379 \begin_layout Standard
6380 the command backfills
6381 \begin_inset LatexCommand index
6382 name "backfill unused memory"
6386 unused memory with 0x12 and the overall 16 bit sum of the complete 64 kByte
6388 If the program counter on an mcs51 runs wild the backfill pattern 0x12
6389 will be interpreted as an
6397 (where an emergency routine could sit).
6410 srec_cat\InsetSpace ~
6411 sourcefile.ihx -intel\InsetSpace ~
6413 -fill 0x12 0x0000 0xfffe\InsetSpace ~
6414 -little-endian-checksum-nega
6415 tive 0xfffe 0x02 0x02\InsetSpace ~
6417 -o sourcefile.hex -intel
6426 The srecord package is available at
6427 \begin_inset LatexCommand url
6428 target "http://sf.net/projects/srecord"
6435 \begin_layout Subsection
6436 Projects with Multiple Source Files
6439 \begin_layout Standard
6440 SDCC can compile only ONE file at a time.
6441 Let us for example assume that you have a project containing the following
6446 foo1.c (contains some functions)
6448 foo2.c (contains some more functions)
6451 n.c (contains more functions and the function main)
6459 The first two files will need to be compiled separately with the commands:
6491 Then compile the source file containing the
6496 \begin_inset LatexCommand index
6501 the files together with the following command:
6509 foomain.c\InsetSpace ~
6510 foo1.rel\InsetSpace ~
6515 \begin_inset LatexCommand index
6528 can be separately compiled as well:
6539 sdcc foomain.rel foo1.rel foo2.rel
6546 The file containing the
6558 file specified in the command line, since the linkage editor processes
6559 file in the order they are presented to it.
6560 The linker is invoked from SDCC using a script file with extension .lnk
6561 \begin_inset LatexCommand index
6567 You can view this file to troubleshoot linking problems such as those arising
6568 from missing libraries.
6571 \begin_layout Subsection
6572 Projects with Additional Libraries
6573 \begin_inset LatexCommand index
6581 \begin_layout Standard
6582 Some reusable routines may be compiled into a library, see the documentation
6583 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
6587 \begin_inset LatexCommand index
6595 Libraries created in this manner can be included in the command line.
6596 Make sure you include the -L <library-path> option to tell the linker where
6597 to look for these files if they are not in the current directory.
6598 Here is an example, assuming you have the source file
6610 (if that is not the same as your current project):
6617 sdcc foomain.c foolib.lib -L mylib
6628 must be an absolute path name.
6632 The most efficient way to use libraries is
6633 to keep separate modules in separate source files.
6634 The lib file now should name all the modules.rel
6635 \begin_inset LatexCommand index
6641 For an example see the standard library file
6645 in the directory <installdir>/share/lib/small.
6648 \begin_layout Subsection
6649 Using sdcclib to Create and Manage Libraries
6650 \begin_inset LatexCommand index
6658 \begin_layout Standard
6659 Alternatively, instead of having a .rel file for each entry on the library
6660 file as described in the preceding section, sdcclib can be used to embed
6661 all the modules belonging to such library in the library file itself.
6662 This results in a larger library file, but it greatly reduces the number
6663 of disk files accessed by the linker.
6664 Additionally, the packed library file contains an index of all include
6665 modules and symbols that significantly speeds up the linking process.
6666 To display a list of options supported by sdcclib type:
6671 \begin_layout Standard
6676 \begin_inset LatexCommand index
6688 To create a new library file, start by compiling all the required modules.
6694 \begin_layout Standard
6701 \begin_layout Standard
6708 \begin_layout Standard
6715 \begin_layout Standard
6722 \begin_layout Standard
6731 \begin_layout Standard
6732 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
6734 The next step is to add the .rel files to the library file:
6739 \begin_layout Standard
6743 sdcclib libint.lib _divsint.rel
6746 \begin_inset LatexCommand index
6754 \begin_layout Standard
6758 sdcclib libint.lib _divuint.rel
6761 \begin_layout Standard
6765 sdcclib libint.lib _modsint.rel
6768 \begin_layout Standard
6772 sdcclib libint.lib _moduint.rel
6775 \begin_layout Standard
6779 sdcclib libint.lib _mulint.rel
6787 \begin_layout Standard
6796 \begin_layout Standard
6800 sdcclib libint.lib _divsint.rel _divuint.rel _modsint.rel _moduint.rel _mulint.rel
6808 \begin_layout Standard
6809 If the file already exists in the library, it will be replaced.
6810 If a list of .rel files is available, you can tell sdcclib to add those
6812 For example, if the file 'myliblist.txt' contains
6820 \begin_layout Standard
6827 \begin_layout Standard
6834 \begin_layout Standard
6841 \begin_layout Standard
6848 \begin_layout Standard
6860 \begin_layout Standard
6869 \begin_layout Standard
6873 sdcclib -l libint.lib myliblist.txt
6881 \begin_layout Standard
6882 Additionally, you can instruct sdcclib to compiles the files before adding
6883 them to the library.
6884 This is achieved using the environment variables SDCCLIB_CC and/or SDCCLIB_AS.
6893 \begin_layout Standard
6897 set SDCCLIB_CC=sdcc -c
6900 \begin_layout Standard
6904 sdcclib -l libint.lib myliblist.txt
6912 \begin_layout Standard
6913 To see what modules and symbols are included in the library, options -s
6914 and -m are available.
6922 sdcclib -s libint.lib
6925 \begin_inset LatexCommand index
6938 \begin_layout Standard
6944 \begin_layout Standard
6950 \begin_layout Standard
6958 \begin_layout Standard
6964 \begin_layout Standard
6970 \begin_layout Standard
6976 \begin_layout Standard
6982 \begin_layout Standard
6990 \begin_layout Standard
6996 \begin_layout Standard
7002 \begin_layout Standard
7010 \begin_layout Standard
7016 \begin_layout Standard
7022 \begin_layout Standard
7028 \begin_layout Standard
7036 \begin_layout Standard
7042 \begin_layout Standard
7053 \begin_layout Standard
7054 If the source files are compiled using -
7058 \begin_layout Standard
7068 \begin_inset LatexCommand index
7073 , the corresponding debug information file .adb will be include in the library
7075 The library files created with sdcclib are plain text files, so they can
7076 be viewed with a text editor.
7077 It is not recommended to modify a library file created with sdcclib using
7078 a text editor, as there are file indexes numbers located across the file
7079 used by the linker to quickly locate the required module to link.
7080 Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
7081 it can be safely deleted, since all the information required for linking
7082 is embedded in the library file itself.
7083 Library files created using sdcclib are used as described in the preceding
7085 \begin_inset VSpace bigskip
7091 \begin_layout Section
7092 Command Line Options
7093 \begin_inset LatexCommand index
7094 name "Command Line Options"
7099 \begin_inset LatexCommand label
7100 name "sec:Command-Line-Options"
7107 \begin_layout Subsection
7108 Processor Selection Options
7109 \begin_inset LatexCommand index
7110 name "Options processor selection"
7115 \begin_inset LatexCommand index
7116 name "Processor selection options"
7124 \labelwidthstring 00.00.0000
7128 \begin_inset LatexCommand index
7135 Generate code for the Intel MCS51
7136 \begin_inset LatexCommand index
7141 family of processors.
7142 This is the default processor target.
7146 \labelwidthstring 00.00.0000
7150 \begin_inset LatexCommand index
7157 Generate code for the Dallas DS80C390
7158 \begin_inset LatexCommand index
7167 \labelwidthstring 00.00.0000
7171 \begin_inset LatexCommand index
7178 Generate code for the Dallas DS80C400
7179 \begin_inset LatexCommand index
7188 \labelwidthstring 00.00.0000
7192 \begin_inset LatexCommand index
7199 Generate code for the Freescale/Motorola HC08
7200 \begin_inset LatexCommand index
7205 family of processors.
7209 \labelwidthstring 00.00.0000
7213 \begin_inset LatexCommand index
7220 Generate code for the Zilog Z80
7221 \begin_inset LatexCommand index
7226 family of processors.
7230 \labelwidthstring 00.00.0000
7234 \begin_inset LatexCommand index
7241 Generate code for the GameBoy Z80
7242 \begin_inset LatexCommand index
7243 name "gbz80 (GameBoy Z80)"
7247 processor (Not actively maintained).
7251 \labelwidthstring 00.00.0000
7255 \begin_inset LatexCommand index
7262 Generate code for the Atmel AVR
7263 \begin_inset LatexCommand index
7268 processor (Not maintained, not complete).
7269 AVR users should probably have a look at winavr
7270 \begin_inset LatexCommand url
7271 target "http://sourceforge.net/projects/winavr"
7276 \begin_inset LatexCommand url
7277 target "http://www.avrfreaks.net/index.php?name=PNphpBB2&file=index"
7281 , which is based on AVR-port of the gcc compiler.
7284 \begin_layout Standard
7285 \begin_inset Note Note
7288 \begin_layout Standard
7289 I think it is fair to direct users there for now.
7290 Open source is also about avoiding unnecessary work .
7291 But I didn't find the 'official' link.
7300 \labelwidthstring 00.00.0000
7304 \begin_inset LatexCommand index
7311 Generate code for the Microchip PIC 14
7312 \begin_inset LatexCommand index
7317 -bit processors (p16f84 and variants.
7318 In development, not complete).
7321 \begin_layout Standard
7322 \begin_inset Note Note
7325 \begin_layout Standard
7326 p16f627 p16f628 p16f84 p16f873 p16f877?
7335 \labelwidthstring 00.00.0000
7339 \begin_inset LatexCommand index
7346 Generate code for the Microchip PIC 16
7347 \begin_inset LatexCommand index
7352 -bit processors (p18f452 and variants.
7353 In development, not complete).
7357 \labelwidthstring 00.00.0000
7362 Generate code for the Toshiba TLCS-900H
7363 \begin_inset LatexCommand index
7368 processor (Not maintained, not complete).
7372 \labelwidthstring 00.00.0000
7376 \begin_inset LatexCommand index
7383 Generate code for the Phillips XA51
7384 \begin_inset LatexCommand index
7389 processor (Not maintained, not complete).
7392 \begin_layout Standard
7393 \begin_inset VSpace bigskip
7399 \begin_layout Subsection
7400 Preprocessor Options
7401 \begin_inset LatexCommand index
7402 name "Options preprocessor"
7407 \begin_inset LatexCommand index
7408 name "Preprocessor options"
7413 \begin_inset LatexCommand index
7414 name "sdcpp (preprocessor)"
7422 \labelwidthstring 00.00.0000
7426 \begin_inset LatexCommand index
7433 The additional location where the preprocessor will look for <..h> or
7434 \begin_inset Quotes eld
7438 \begin_inset Quotes erd
7445 \labelwidthstring 00.00.0000
7449 \begin_inset LatexCommand index
7450 name "-D<macro[=value]>"
7456 Command line definition of macros.
7457 Passed to the preprocessor.
7461 \labelwidthstring 00.00.0000
7465 \begin_inset LatexCommand index
7472 Tell the preprocessor to output a rule suitable for make describing the
7473 dependencies of each object file.
7474 For each source file, the preprocessor outputs one make-rule whose target
7475 is the object file name for that source file and whose dependencies are
7476 all the files `#include'd in it.
7477 This rule may be a single line or may be continued with `
7479 '-newline if it is long.
7480 The list of rules is printed on standard output instead of the preprocessed
7483 \begin_inset LatexCommand index
7492 \labelwidthstring 00.00.0000
7496 \begin_inset LatexCommand index
7503 Tell the preprocessor not to discard comments.
7504 Used with the `-E' option.
7508 \labelwidthstring 00.00.0000
7512 \begin_inset LatexCommand index
7522 Like `-M' but the output mentions only the user header files included with
7524 \begin_inset Quotes eld
7528 System header files included with `#include <file>' are omitted.
7532 \labelwidthstring 00.00.0000
7536 \begin_inset LatexCommand index
7537 name "-Aquestion(answer)"
7543 Assert the answer answer for question, in case it is tested with a preprocessor
7544 conditional such as `#if #question(answer)'.
7545 `-A-' disables the standard assertions that normally describe the target
7550 \labelwidthstring 00.00.0000
7554 \begin_inset LatexCommand index
7561 Undefine macro macro.
7562 `-U' options are evaluated after all `-D' options, but before any `-include'
7563 and `-imacros' options.
7567 \labelwidthstring 00.00.0000
7571 \begin_inset LatexCommand index
7578 Tell the preprocessor to output only a list of the macro definitions that
7579 are in effect at the end of preprocessing.
7580 Used with the `-E' option.
7584 \labelwidthstring 00.00.0000
7588 \begin_inset LatexCommand index
7595 Tell the preprocessor to pass all macro definitions into the output, in
7596 their proper sequence in the rest of the output.
7600 \labelwidthstring 00.00.0000
7604 \begin_inset LatexCommand index
7614 Like `-dD' except that the macro arguments and contents are omitted.
7615 Only `#define name' is included in the output.
7619 \labelwidthstring 00.00.0000
7622 -pedantic-parse-number
7623 \begin_inset LatexCommand index
7629 \begin_inset LatexCommand index
7630 name "-pedantic-parse-number"
7638 \begin_inset LatexCommand label
7639 name "lyx:-pedantic-parse-number"
7648 Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed properly
7649 and the macro LO_B(3) gets expanded.
7650 See also #pragma pedantic_parse_number
7651 \begin_inset LatexCommand vpageref
7652 reference "ite:pedantic_parse_number"
7657 \begin_inset LatexCommand ref
7658 reference "sec:Pragmas"
7664 Note: this functionality is not in conformance with C99 standard!
7668 \labelwidthstring 00.00.0000
7672 preprocessorOption[,preprocessorOption]
7675 \begin_inset LatexCommand index
7676 name "-Wp preprocessorOption[,preprocessorOption]"
7681 Pass the preprocessorOption to the preprocessor
7686 \begin_inset LatexCommand index
7687 name "sdcpp (preprocessor)"
7692 SDCC uses an adapted version of the preprocessor
7696 of the GNU Compiler Collection
7697 \begin_inset LatexCommand index
7698 name "gcc (GNU Compiler Collection)"
7707 \begin_inset LatexCommand url
7708 target "http://gcc.gnu.org/"
7712 ), if you need more dedicated options please refer to the GCC\InsetSpace ~
7717 \begin_inset LatexCommand htmlurl
7718 target "http://www.gnu.org/software/gcc/onlinedocs/"
7725 \begin_layout Standard
7726 \begin_inset VSpace bigskip
7732 \begin_layout Subsection
7734 \begin_inset LatexCommand index
7735 name "Options linker"
7740 \begin_inset LatexCommand index
7741 name "Linker options"
7749 \labelwidthstring 00.00.0000
7759 \begin_layout Standard
7771 \begin_inset LatexCommand index
7772 name "-\\/-lib-path <path>"
7777 \begin_inset LatexCommand index
7778 name "-L -\\/-lib-path"
7785 <absolute path to additional libraries> This option is passed to the linkage
7786 editor's additional libraries
7787 \begin_inset LatexCommand index
7793 The path name must be absolute.
7794 Additional library files may be specified in the command line.
7795 See section Compiling programs for more details.
7799 \labelwidthstring 00.00.0000
7806 \begin_layout Standard
7818 \begin_inset LatexCommand index
7819 name "-\\/-xram-loc <Value>"
7824 <Value> The start location of the external ram
7825 \begin_inset LatexCommand index
7826 name "xdata (mcs51, ds390 storage class)"
7830 , default value is 0.
7831 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7835 \begin_layout Standard
7844 -xram-loc 0x8000 or -
7848 \begin_layout Standard
7861 \labelwidthstring 00.00.0000
7868 \begin_layout Standard
7880 \begin_inset LatexCommand index
7881 name "-\\/-code-loc <Value>"
7886 <Value> The start location of the code
7887 \begin_inset LatexCommand index
7892 segment, default value 0.
7893 Note when this option is used the interrupt vector table
7894 \begin_inset LatexCommand index
7895 name "interrupt vector table"
7899 is also relocated to the given address.
7900 The value entered can be in Hexadecimal or Decimal format, e.g.: -
7904 \begin_layout Standard
7913 -code-loc 0x8000 or -
7917 \begin_layout Standard
7930 \labelwidthstring 00.00.0000
7937 \begin_layout Standard
7949 \begin_inset LatexCommand index
7950 name "-\\/-stack-loc <Value>"
7955 <Value> By default the stack
7956 \begin_inset LatexCommand index
7961 is placed after the data segment.
7962 Using this option the stack can be placed anywhere in the internal memory
7964 The value entered can be in Hexadecimal or Decimal format, e.g.
7969 \begin_layout Standard
7978 -stack-loc 0x20 or -
7982 \begin_layout Standard
7992 Since the sp register is incremented before a push or call, the initial
7993 sp will be set to one byte prior the provided value.
7994 The provided value should not overlap any other memory areas such as used
7995 register banks or the data segment and with enough space for the current
8003 \begin_layout Standard
8016 \begin_inset LatexCommand index
8017 name "-\\/-pack-iram"
8021 option (which is now a default setting) will override this setting, so
8022 you should also specify the
8028 \begin_layout Standard
8041 \begin_inset LatexCommand index
8042 name "-\\/-no-pack-iram"
8046 option if you need to manually place the stack.
8050 \labelwidthstring 00.00.0000
8057 \begin_layout Standard
8069 \begin_inset LatexCommand index
8070 name "-\\/-xstack-loc <Value>"
8075 <Value> By default the external stack
8076 \begin_inset LatexCommand index
8081 is placed after the pdata
8082 \begin_inset LatexCommand index
8083 name "pdata (mcs51, ds390 storage class)"
8088 Using this option the xstack can be placed anywhere in the external memory
8090 The value entered can be in Hexadecimal or Decimal format, e.g.
8095 \begin_layout Standard
8104 -xstack-loc 0x8000 or -
8108 \begin_layout Standard
8118 The provided value should not overlap any other memory areas such as the
8119 pdata or xdata segment and with enough space for the current application.
8123 \labelwidthstring 00.00.0000
8130 \begin_layout Standard
8142 \begin_inset LatexCommand index
8143 name "-\\/-data-loc <Value>"
8148 <Value> The start location of the internal ram data
8149 \begin_inset LatexCommand index
8150 name "data (mcs51, ds390 storage class)"
8155 The value entered can be in Hexadecimal or Decimal format, eg.
8160 \begin_layout Standard
8173 \begin_layout Standard
8183 (By default, the start location of the internal ram data segment is set
8184 as low as possible in memory, taking into account the used register banks
8185 and the bit segment at address 0x20.
8186 For example if register banks 0 and 1 are used without bit variables, the
8187 data segment will be set, if -
8191 \begin_layout Standard
8200 -data-loc is not used, to location 0x10.)
8204 \labelwidthstring 00.00.0000
8211 \begin_layout Standard
8223 \begin_inset LatexCommand index
8224 name "-\\/-idata-loc <Value>"
8229 <Value> The start location of the indirectly addressable internal ram
8230 \begin_inset LatexCommand index
8231 name "idata (mcs51, ds390 storage class)"
8235 of the 8051, default value is 0x80.
8236 The value entered can be in Hexadecimal or Decimal format, eg.
8241 \begin_layout Standard
8250 -idata-loc 0x88 or -
8254 \begin_layout Standard
8267 \labelwidthstring 00.00.0000
8274 \begin_layout Standard
8286 <Value> The start location of the bit
8287 \begin_inset LatexCommand index
8292 addressable internal ram of the 8051.
8298 Instead an option can be passed directly to the linker: -Wl\InsetSpace ~
8303 \labelwidthstring 00.00.0000
8310 \begin_layout Standard
8320 \begin_inset LatexCommand index
8321 name "-\\/-out-fmt-ihx"
8327 The linker output (final object code) is in Intel Hex format.
8328 \begin_inset LatexCommand index
8329 name "Intel hex format"
8333 This is the default option.
8334 The format itself is documented in the documentation of srecord
8335 \begin_inset LatexCommand index
8336 name "srecord (bin, hex, ... tool)"
8344 \labelwidthstring 00.00.0000
8351 \begin_layout Standard
8361 \begin_inset LatexCommand index
8362 name "-\\/-out-fmt-s19"
8368 The linker output (final object code) is in Motorola S19 format
8369 \begin_inset LatexCommand index
8370 name "Motorola S19 format"
8375 The format itself is documented in the documentation of srecord.
8379 \labelwidthstring 00.00.0000
8386 \begin_layout Standard
8396 \begin_inset LatexCommand index
8397 name "-\\/-out-fmt-s19"
8402 \begin_inset LatexCommand index
8403 name "HC08!Options!-\\/-out-fmt-elf"
8409 The linker output (final object code) is in ELF format
8410 \begin_inset LatexCommand index
8416 (Currently only supported for the HC08
8417 \begin_inset LatexCommand index
8426 \labelwidthstring 00.00.0000
8430 linkOption[,linkOption]
8433 \begin_inset LatexCommand index
8434 name "-Wl linkOption[,linkOption]"
8439 \begin_inset LatexCommand label
8440 name "lyx:-Wl option"
8445 Pass the linkOption to the linker.
8446 If a bootloader is used an option like
8447 \begin_inset Quotes sld
8452 \begin_inset Quotes srd
8455 would be typical to set the start of the code segment.
8456 Either use the double quotes around this option or use no space (e.g.
8458 See also #pragma constseg and #pragma codeseg in section
8459 \begin_inset LatexCommand ref
8460 reference "sec:Pragmas"
8465 File sdcc/as/doc/asxhtm.html has more on linker options.
8468 \begin_layout Standard
8469 \begin_inset VSpace bigskip
8475 \begin_layout Subsection
8477 \begin_inset LatexCommand index
8478 name "Options MCS51"
8483 \begin_inset LatexCommand index
8484 name "MCS51 options"
8492 \labelwidthstring 00.00.0000
8499 \begin_layout Standard
8509 \begin_inset LatexCommand index
8510 name "-\\/-model-small"
8519 Generate code for Small Model programs, see section Memory Models for more
8521 This is the default model.
8525 \labelwidthstring 00.00.0000
8532 \begin_layout Standard
8542 \begin_inset LatexCommand index
8543 name "-\\/-model-medium"
8549 Generate code for Medium model programs, see section Memory Models for
8551 If this option is used all source files in the project have to be compiled
8553 It must also be used when invoking the linker.
8557 \labelwidthstring 00.00.0000
8564 \begin_layout Standard
8574 \begin_inset LatexCommand index
8575 name "-\\/-model-large"
8581 Generate code for Large model programs, see section Memory Models for more
8583 If this option is used all source files in the project have to be compiled
8585 It must also be used when invoking the linker.
8589 \labelwidthstring 00.00.0000
8596 \begin_layout Standard
8606 \begin_inset LatexCommand index
8613 Uses a pseudo stack in the pdata
8614 \begin_inset LatexCommand index
8615 name "pdata (mcs51, ds390 storage class)"
8619 area (usually the first 256 bytes in the external ram) for allocating variables
8620 and passing parameters.
8622 \begin_inset LatexCommand ref
8623 reference "sub:External-Stack"
8628 External Stack for more details.
8632 \labelwidthstring 00.00.0000
8639 \begin_layout Standard
8652 \begin_inset LatexCommand index
8653 name "-\\/-iram-size <Value>"
8657 Causes the linker to check if the internal ram usage is within limits of
8662 \labelwidthstring 00.00.0000
8669 \begin_layout Standard
8682 \begin_inset LatexCommand index
8683 name "-\\/-xram-size <Value>"
8687 Causes the linker to check if the external ram usage is within limits of
8692 \labelwidthstring 00.00.0000
8699 \begin_layout Standard
8712 \begin_inset LatexCommand index
8713 name "-\\/-code-size <Value>"
8717 Causes the linker to check if the code memory usage is within limits of
8722 \labelwidthstring 00.00.0000
8729 \begin_layout Standard
8742 \begin_inset LatexCommand index
8743 name "-\\/-stack-size <Value>"
8747 Causes the linker to check if there is at minimum <Value> bytes for stack.
8751 \labelwidthstring 00.00.0000
8758 \begin_layout Standard
8771 \begin_inset LatexCommand index
8772 name "-\\/-pack-iram"
8776 Causes the linker to use unused register banks for data variables and pack
8777 data, idata and stack together.
8778 This is the default now.
8782 \labelwidthstring 00.00.0000
8789 \begin_layout Standard
8802 \begin_inset LatexCommand index
8803 name "-\\/-no-pack-iram"
8807 Causes the linker to use old style for allocating memory areas.
8811 \labelwidthstring 00.00.0000
8818 \begin_layout Standard
8831 \begin_inset LatexCommand index
8832 name "-\\/-acall-ajmp"
8836 Replaces the three byte instructions lcall/ljmp with the two byte instructions
8838 Only use this option if your code is in the same 2k block of memory.
8839 You may need to use this option for some 8051 derivatives which lack the
8840 lcall/ljmp instructions..
8843 \begin_layout Standard
8844 \begin_inset VSpace bigskip
8850 \begin_layout Subsection
8851 DS390 / DS400 Options
8852 \begin_inset LatexCommand index
8853 name "Options DS390"
8858 \begin_inset LatexCommand index
8867 \labelwidthstring 00.00.0000
8874 \begin_layout Standard
8886 \begin_inset LatexCommand index
8887 name "DS390!Options!-\\/-model-flat24"
8895 Generate 24-bit flat mode code.
8896 This is the one and only that the ds390 code generator supports right now
8897 and is default when using
8902 See section Memory Models for more details.
8906 \labelwidthstring 00.00.0000
8913 \begin_layout Standard
8923 \begin_inset LatexCommand index
8924 name "DS390!Options!-\\/-protect-sp-update"
8930 disable interrupts during ESP:SP updates.
8934 \labelwidthstring 00.00.0000
8941 \begin_layout Standard
8953 \begin_inset LatexCommand index
8954 name "DS390!Options!-\\/-stack-10bit"
8958 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
8959 This is the one and only that the ds390 code generator supports right now
8960 and is default when using
8965 In this mode, the stack is located in the lower 1K of the internal RAM,
8966 which is mapped to 0x400000.
8967 Note that the support is incomplete, since it still uses a single byte
8968 as the stack pointer.
8969 This means that only the lower 256 bytes of the potential 1K stack space
8970 will actually be used.
8971 However, this does allow you to reclaim the precious 256 bytes of low RAM
8972 for use for the DATA and IDATA segments.
8973 The compiler will not generate any code to put the processor into 10 bit
8975 It is important to ensure that the processor is in this mode before calling
8976 any re-entrant functions compiled with this option.
8977 In principle, this should work with the
8983 \begin_layout Standard
8993 \begin_inset LatexCommand index
8994 name "-\\/-stack-auto"
9000 option, but that has not been tested.
9001 It is incompatible with the
9007 \begin_layout Standard
9017 \begin_inset LatexCommand index
9025 It also only makes sense if the processor is in 24 bit contiguous addressing
9032 \begin_layout Standard
9041 -model-flat24 option
9046 \begin_inset Note Note
9050 \labelwidthstring 00.00.0000
9057 \begin_layout Standard
9066 -stack-8-bit - switches off the 10-bit mode
9075 \labelwidthstring 00.00.0000
9082 \begin_layout Standard
9092 \begin_inset LatexCommand index
9093 name "DS390!Options!-\\/-stack-probe"
9099 insert call to function __stack_probe at each function prologue.
9103 \labelwidthstring 00.00.0000
9110 \begin_layout Standard
9120 \begin_inset LatexCommand index
9121 name "DS390!Options!-\\/-tini-libid"
9127 <nnnn> LibraryID used in -mTININative.
9132 \labelwidthstring 00.00.0000
9139 \begin_layout Standard
9149 \begin_inset LatexCommand index
9150 name "DS390!Options!-\\/-use-accelerator"
9156 generate code for DS390 Arithmetic Accelerator.
9160 \begin_layout Standard
9161 \begin_inset VSpace bigskip
9167 \begin_layout Subsection
9169 \begin_inset LatexCommand index
9175 \begin_inset LatexCommand index
9184 \labelwidthstring 00.00.0000
9191 \begin_layout Standard
9203 \begin_inset LatexCommand index
9204 name "Z80!Options!-\\/-callee-saves-bc"
9212 Force a called function to always save BC.
9216 \labelwidthstring 00.00.0000
9223 \begin_layout Standard
9235 \begin_inset LatexCommand index
9236 name "Z80!Options!-\\/-no-std-crt0"
9240 When linking, skip the standard crt0.o object file.
9241 You must provide your own crt0.o for your system when linking.
9245 \labelwidthstring 00.00.0000
9252 \begin_layout Standard
9264 \begin_inset LatexCommand index
9265 name "Z80!Options!-\\/-portmode=<Value>"
9269 Determinate PORT I/O mode (<Value> is z80 or z180).
9273 \labelwidthstring 00.00.0000
9280 \begin_layout Standard
9292 \begin_inset LatexCommand index
9293 name "Z80!Options!-\\/-asm=<Value>"
9297 Define assembler name (<Value> is rgbds, asxxxx, isas or z80asm).
9301 \labelwidthstring 00.00.0000
9308 \begin_layout Standard
9321 \begin_inset LatexCommand index
9322 name "Z80!Options!-\\/-codeseg <Value>"
9326 Use <Value> for the code segment name.
9330 \labelwidthstring 00.00.0000
9337 \begin_layout Standard
9350 \begin_inset LatexCommand index
9351 name "Z80!Options!-\\/-constseg <Value>"
9355 Use <Value> for the const segment name.
9359 \labelwidthstring 00.00.0000
9360 \begin_inset VSpace bigskip
9366 \begin_layout Subsection
9368 \begin_inset LatexCommand index
9369 name "Options GBZ80"
9374 \begin_inset LatexCommand index
9383 \labelwidthstring 00.00.0000
9390 \begin_layout Standard
9402 \begin_inset LatexCommand index
9403 name "GBZ80!Options!-\\/-callee-saves-bc"
9411 Force a called function to always save BC.
9415 \labelwidthstring 00.00.0000
9422 \begin_layout Standard
9434 \begin_inset LatexCommand index
9435 name "Z80!Options!-\\/-no-std-crt0"
9439 When linking, skip the standard crt0.o object file.
9440 You must provide your own crt0.o for your system when linking.
9444 \labelwidthstring 00.00.0000
9451 \begin_inset LatexCommand index
9452 name "GBZ80!Options!-bo <Num>"
9456 Use code bank <Num>.
9460 \labelwidthstring 00.00.0000
9467 \begin_inset LatexCommand index
9468 name "GBZ80!Options!-ba <Num>"
9472 Use data bank <Num>.
9476 \labelwidthstring 00.00.0000
9483 \begin_layout Standard
9496 \begin_inset LatexCommand index
9497 name "GBZ80!Options!-\\/-codeseg <Value>"
9501 Use <Value> for the code segment name.
9505 \labelwidthstring 00.00.0000
9512 \begin_layout Standard
9525 \begin_inset LatexCommand index
9526 name "GBZ80!Options!-\\/-constseg <Value>"
9530 Use <Value> for the const segment name.
9533 \begin_layout Standard
9534 \begin_inset VSpace bigskip
9540 \begin_layout Subsection
9541 Optimization Options
9542 \begin_inset LatexCommand index
9543 name "Options optimization"
9548 \begin_inset LatexCommand index
9549 name "Optimization options"
9557 \labelwidthstring 00.00.0000
9564 \begin_layout Standard
9574 \begin_inset LatexCommand index
9581 Will not do global subexpression elimination, this option may be used when
9582 the compiler creates undesirably large stack/data spaces to store compiler
9592 \begin_inset LatexCommand index
9593 name "sloc (spill location)"
9598 A warning message will be generated when this happens and the compiler
9599 will indicate the number of extra bytes it allocated.
9600 It is recommended that this option NOT be used, #pragma\InsetSpace ~
9602 \begin_inset LatexCommand index
9603 name "\\#pragma nogcse"
9607 can be used to turn off global subexpression elimination
9608 \begin_inset LatexCommand index
9609 name "Subexpression elimination"
9613 for a given function only.
9617 \labelwidthstring 00.00.0000
9624 \begin_layout Standard
9634 \begin_inset LatexCommand index
9635 name "-\\/-noinvariant"
9641 Will not do loop invariant optimizations, this may be turned off for reasons
9642 explained for the previous option.
9643 For more details of loop optimizations performed see Loop Invariants in
9645 \begin_inset LatexCommand ref
9646 reference "sub:Loop-Optimizations"
9651 It is recommended that this option NOT be used, #pragma\InsetSpace ~
9653 \begin_inset LatexCommand index
9654 name "\\#pragma noinvariant"
9658 can be used to turn off invariant optimizations for a given function only.
9662 \labelwidthstring 00.00.0000
9669 \begin_layout Standard
9679 \begin_inset LatexCommand index
9680 name "-\\/-noinduction"
9686 Will not do loop induction optimizations, see section strength reduction
9688 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9690 \begin_inset LatexCommand index
9691 name "\\#pragma noinduction"
9695 can be used to turn off induction optimizations for a given function only.
9699 \labelwidthstring 00.00.0000
9706 \begin_layout Standard
9716 \begin_inset LatexCommand index
9717 name "-\\/-nojtbound"
9726 Will not generate boundary condition check when switch statements
9727 \begin_inset LatexCommand index
9728 name "switch statement"
9732 are implemented using jump-tables.
9734 \begin_inset LatexCommand ref
9735 reference "sub:'switch'-Statements"
9740 Switch Statements for more details.
9741 It is recommended that this option is NOT used, #pragma\InsetSpace ~
9743 \begin_inset LatexCommand index
9744 name "\\#pragma nojtbound"
9748 can be used to turn off boundary checking for jump tables for a given function
9753 \labelwidthstring 00.00.0000
9760 \begin_layout Standard
9770 \begin_inset LatexCommand index
9771 name "-\\/-noloopreverse"
9780 Will not do loop reversal
9781 \begin_inset LatexCommand index
9782 name "Loop reversing"
9790 \labelwidthstring 00.00.0000
9795 \begin_layout Standard
9809 \begin_inset LatexCommand index
9810 name "-\\/-nolabelopt "
9814 Will not optimize labels (makes the dumpfiles more readable).
9818 \labelwidthstring 00.00.0000
9825 \begin_layout Standard
9835 \begin_inset LatexCommand index
9836 name "-\\/-no-xinit-opt"
9842 Will not memcpy initialized data from code space into xdata space.
9843 This saves a few bytes in code space if you don't have initialized data
9844 \begin_inset LatexCommand index
9845 name "Variable initialization"
9853 \labelwidthstring 00.00.0000
9860 \begin_layout Standard
9870 \begin_inset LatexCommand index
9871 name "-\\/-nooverlay"
9877 The compiler will not overlay parameters and local variables of any function,
9878 see section Parameters and local variables for more details.
9882 \labelwidthstring 00.00.0000
9889 \begin_layout Standard
9899 \begin_inset LatexCommand index
9906 Disable peep-hole optimization with built-in rules.
9910 \labelwidthstring 00.00.0000
9917 \begin_layout Standard
9929 \begin_inset LatexCommand index
9930 name "-\\/-peep-file"
9935 <filename> This option can be used to use additional rules to be used by
9936 the peep hole optimizer.
9938 \begin_inset LatexCommand ref
9939 reference "sub:Peephole-Optimizer"
9944 Peep Hole optimizations for details on how to write these rules.
9948 \labelwidthstring 00.00.0000
9955 \begin_layout Standard
9965 \begin_inset LatexCommand index
9966 name "-\\/-peep-asm"
9972 Pass the inline assembler code through the peep hole optimizer.
9973 This can cause unexpected changes to inline assembler code, please go through
9974 the peephole optimizer
9975 \begin_inset LatexCommand index
9976 name "Peephole optimizer"
9980 rules defined in the source file tree '<target>/peeph.def' before using
9985 \labelwidthstring 00.00.0000
9992 \begin_layout Standard
10002 \begin_inset LatexCommand index
10003 name "-\\/-opt-code-speed"
10009 The compiler will optimize code generation towards fast code, possibly
10010 at the expense of code size.
10014 \labelwidthstring 00.00.0000
10021 \begin_layout Standard
10031 \begin_inset LatexCommand index
10032 name "-\\/-opt-code-size"
10038 The compiler will optimize code generation towards compact code, possibly
10039 at the expense of code speed.
10042 \begin_layout Standard
10043 \begin_inset VSpace bigskip
10049 \begin_layout Subsection
10051 \begin_inset LatexCommand index
10052 name "Options other"
10060 \labelwidthstring 00.00.0000
10068 \begin_layout Standard
10078 \begin_inset LatexCommand index
10079 name "-\\/-compile-only"
10084 \begin_inset LatexCommand index
10085 name "-c -\\/-compile-only"
10091 will compile and assemble the source, but will not call the linkage editor.
10095 \labelwidthstring 00.00.0000
10104 \begin_layout Standard
10116 \begin_inset LatexCommand index
10123 reads the preprocessed source from standard input and compiles it.
10124 The file name for the assembler output must be specified using the -o option.
10128 \labelwidthstring 00.00.0000
10132 \begin_inset LatexCommand index
10139 Run only the C preprocessor.
10140 Preprocess all the C source files specified and output the results to standard
10145 \labelwidthstring 00.00.0000
10150 \begin_inset LatexCommand index
10151 name "-o <path/file>"
10157 The output path where everything will be placed or the file name used for
10158 all generated output files.
10159 If the parameter is a path, it must have a trailing slash (or backslash
10160 for the Windows binaries) to be recognized as a path.
10161 Note for Windows users: if the path contains spaces, it should be surrounded
10163 The trailing backslash should be doubled in order to prevent escaping the
10164 final quote, for example:
10167 \begin_inset Quotes sld
10181 \begin_inset Quotes srd
10186 or put after the final quote, for example:
10189 \begin_inset Quotes sld
10199 \begin_inset Quotes srd
10207 The path using slashes for directory delimiters can be used too, for example:
10211 \begin_inset Quotes sld
10214 F:/Projects/test3/output 1/
10215 \begin_inset Quotes srd
10224 \labelwidthstring 00.00.0000
10231 \begin_layout Standard
10241 \begin_inset LatexCommand index
10242 name "-\\/-stack-auto"
10251 All functions in the source file will be compiled as
10256 \begin_inset LatexCommand index
10262 the parameters and local variables will be allocated on the stack
10263 \begin_inset LatexCommand index
10270 \begin_inset LatexCommand ref
10271 reference "sec:Parameters-and-Local-Variables"
10275 Parameters and Local Variables for more details.
10276 If this option is used all source files in the project should be compiled
10278 It automatically implies -
10284 \begin_layout Standard
10295 -int-long-reent and -
10301 \begin_layout Standard
10317 \labelwidthstring 00.00.0000
10324 \begin_layout Standard
10334 \begin_inset LatexCommand index
10335 name "-\\/-callee-saves"
10340 \begin_inset LatexCommand label
10341 name "lyx:--callee-saves-function1[,function2][,function3]..."
10345 function1[,function2][,function3]....
10348 The compiler by default uses a caller saves convention for register saving
10349 across function calls, however this can cause unnecessary register pushing
10350 and popping when calling small functions from larger functions.
10351 This option can be used to switch the register saving convention for the
10352 function names specified.
10353 The compiler will not save registers when calling these functions, no extra
10354 code will be generated at the entry and exit (function prologue
10357 \begin_inset LatexCommand index
10358 name "function prologue"
10367 \begin_inset LatexCommand index
10368 name "function epilogue"
10374 ) for these functions to save and restore the registers used by these functions,
10375 this can SUBSTANTIALLY reduce code and improve run time performance of
10376 the generated code.
10377 In the future the compiler (with inter procedural analysis) will be able
10378 to determine the appropriate scheme to use for each function call.
10379 DO NOT use this option for built-in functions such as _mulint..., if this
10380 option is used for a library function the appropriate library function
10381 needs to be recompiled with the same option.
10382 If the project consists of multiple source files then all the source file
10383 should be compiled with the same -
10387 \begin_layout Standard
10396 -callee-saves option string.
10397 Also see #pragma\InsetSpace ~
10399 \begin_inset LatexCommand index
10400 name "\\#pragma callee\\_saves"
10405 \begin_inset LatexCommand vpageref
10406 reference "ite:callee_saves-function1[,function2[,function3...]]--"
10414 \labelwidthstring 00.00.0000
10421 \begin_layout Standard
10431 \begin_inset LatexCommand index
10432 name "-\\/-all-callee-saves"
10442 \begin_layout Standard
10451 -callee-saves will be applied to all functions by default.
10455 \labelwidthstring 00.00.0000
10462 \begin_layout Standard
10472 \begin_inset LatexCommand index
10479 When this option is used the compiler will generate debug information.
10480 The debug information collected in a file with .cdb extension can be used
10482 For more information see documentation for SDCDB.
10483 Another file with no extension contains debug information in AOMF or AOMF51
10484 \begin_inset LatexCommand index
10485 name "AOMF, AOMF51"
10489 format which is commonly used by third party tools.
10493 \labelwidthstring 00.00.0000
10497 \begin_inset LatexCommand index
10507 Stop after the stage of compilation proper; do not assemble.
10508 The output is an assembler code file for the input file specified.
10512 \labelwidthstring 00.00.0000
10519 \begin_layout Standard
10529 \begin_inset LatexCommand index
10530 name "-\\/-int-long-reent"
10536 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
10537 Note by default these libraries are compiled as non-reentrant.
10538 See section Installation for more details.
10542 \labelwidthstring 00.00.0000
10549 \begin_layout Standard
10559 \begin_inset LatexCommand index
10560 name "-\\/-cyclomatic"
10566 This option will cause the compiler to generate an information message for
10567 each function in the source file.
10568 The message contains some
10572 information about the function.
10573 The number of edges and nodes the compiler detected in the control flow
10574 graph of the function, and most importantly the
10576 cyclomatic complexity
10577 \begin_inset LatexCommand index
10578 name "Cyclomatic complexity"
10584 see section on Cyclomatic Complexity for more details.
10588 \labelwidthstring 00.00.0000
10595 \begin_layout Standard
10605 \begin_inset LatexCommand index
10606 name "-\\/-float-reent"
10612 Floating point library is compiled as reentrant
10613 \begin_inset LatexCommand index
10619 See section Installation for more details.
10623 \labelwidthstring 00.00.0000
10630 \begin_layout Standard
10640 \begin_inset LatexCommand index
10641 name "-\\/-funsigned-char"
10647 The default signedness for every type is
10652 In some embedded environments the default signedness of
10661 To set the signess for characters to unsigned, use the option -
10667 \begin_layout Standard
10679 If this option is set and no signedness keyword (unsigned/signed) is given,
10680 a char will be signed.
10681 All other types are unaffected.
10685 \labelwidthstring 00.00.0000
10692 \begin_layout Standard
10702 \begin_inset LatexCommand index
10703 name "-\\/-main-return"
10709 This option can be used if the code generated is called by a monitor program
10710 or if the main routine includes an endless loop.
10711 This option results in slightly smaller code and saves two bytes of stack
10713 The return from the 'main'
10714 \begin_inset LatexCommand index
10719 function will return to the function calling main.
10720 The default setting is to lock up i.e.
10729 \labelwidthstring 00.00.0000
10736 \begin_layout Standard
10746 \begin_inset LatexCommand index
10747 name "-\\/-nostdinc"
10753 This will prevent the compiler from passing on the default include path
10754 to the preprocessor.
10758 \labelwidthstring 00.00.0000
10765 \begin_layout Standard
10775 \begin_inset LatexCommand index
10776 name "-\\/-nostdlib"
10782 This will prevent the compiler from passing on the default library
10783 \begin_inset LatexCommand index
10788 path to the linker.
10792 \labelwidthstring 00.00.0000
10799 \begin_layout Standard
10809 \begin_inset LatexCommand index
10810 name "-\\/-verbose"
10816 Shows the various actions the compiler is performing.
10820 \labelwidthstring 00.00.0000
10824 \begin_inset LatexCommand index
10831 Shows the actual commands the compiler is executing.
10835 \labelwidthstring 00.00.0000
10842 \begin_layout Standard
10852 \begin_inset LatexCommand index
10853 name "-\\/-no-c-code-in-asm"
10859 Hides your ugly and inefficient c-code from the asm file, so you can always
10860 blame the compiler :)
10864 \labelwidthstring 00.00.0000
10871 \begin_layout Standard
10881 \begin_inset LatexCommand index
10882 name "-\\/-no-gen-comments"
10888 Include code generator and peep-hole comments in the generated asm files.
10892 \labelwidthstring 00.00.0000
10899 \begin_layout Standard
10909 \begin_inset LatexCommand index
10910 name "-\\/-no-peep-comments"
10916 Don't include peep-hole comments in the generated asm files even if -
10922 \begin_layout Standard
10933 -fverbose-asm option is specified.
10937 \labelwidthstring 00.00.0000
10944 \begin_layout Standard
10954 \begin_inset LatexCommand index
10955 name "-\\/-i-code-in-asm"
10961 Include i-codes in the asm file.
10962 Sounds like noise but is most helpful for debugging the compiler itself.
10966 \labelwidthstring 00.00.0000
10973 \begin_layout Standard
10983 \begin_inset LatexCommand index
10989 \begin_inset LatexCommand index
10990 name "-\\/-less-pedantic"
10997 \begin_inset LatexCommand label
10998 name "lyx:--less-pedantic"
11002 Disable some of the more pedantic warnings
11003 \begin_inset LatexCommand index
11009 For more details, see the less_pedantic pragma
11010 \begin_inset LatexCommand vpageref
11011 reference "ite:less_pedantic"
11019 \labelwidthstring 00.00.0000
11026 \begin_layout Standard
11035 -disable-warning\InsetSpace ~
11037 \begin_inset LatexCommand index
11038 name "-\\/-disable-warning"
11044 Disable specific warning with number <nnnn>.
11048 \labelwidthstring 00.00.0000
11055 \begin_layout Standard
11065 \begin_inset LatexCommand index
11072 Treat all warnings as errors.
11076 \labelwidthstring 00.00.0000
11083 \begin_layout Standard
11093 \begin_inset LatexCommand index
11094 name "-\\/-print-search-dirs"
11100 Display the directories in the compiler's search path
11104 \labelwidthstring 00.00.0000
11111 \begin_layout Standard
11121 \begin_inset LatexCommand index
11128 Display errors and warnings using MSVC style, so you can use SDCC with
11129 the visual studio IDE
11130 \begin_inset LatexCommand index
11136 With SDCC both offering a GCC-like (the default) and a MSVC-like
11137 \begin_inset LatexCommand index
11138 name "MSVC output style"
11142 output style, integration into most programming editors should be straightforwa
11147 \labelwidthstring 00.00.0000
11154 \begin_layout Standard
11164 \begin_inset LatexCommand index
11165 name "-\\/-use-stdout"
11171 Send errors and warnings to stdout instead of stderr.
11175 \labelwidthstring 00.00.0000
11179 asmOption[,asmOption]
11182 \begin_inset LatexCommand index
11183 name "-Wa asmOption[,asmOption]"
11188 Pass the asmOption to the assembler
11189 \begin_inset LatexCommand index
11190 name "Options assembler"
11195 \begin_inset LatexCommand index
11196 name "Assembler options"
11201 See file sdcc/as/doc/asxhtm.html for assembler options.cd
11205 \labelwidthstring 00.00.0000
11212 \begin_layout Standard
11222 \begin_inset LatexCommand index
11223 name "-\\/-std-sdcc89"
11229 Generally follow the C89 standard, but allow SDCC features that conflict
11230 with the standard (default).
11234 \labelwidthstring 00.00.0000
11241 \begin_layout Standard
11251 \begin_inset LatexCommand index
11252 name "-\\/-std-c89"
11258 Follow the C89 standard and disable SDCC features that conflict with the
11263 \labelwidthstring 00.00.0000
11270 \begin_layout Standard
11280 \begin_inset LatexCommand index
11281 name "-\\/-std-sdcc99"
11287 Generally follow the C99 standard, but allow SDCC features that conflict
11288 with the standard (incomplete support).
11292 \labelwidthstring 00.00.0000
11299 \begin_layout Standard
11309 \begin_inset LatexCommand index
11310 name "-\\/-std-sdcc99"
11316 Follow the C99 standard and disable SDCC features that conflict with the
11317 standard (incomplete support).
11321 \labelwidthstring 00.00.0000
11328 \begin_layout Standard
11340 \begin_inset LatexCommand index
11341 name "-\\/-codeseg <Value>"
11346 \begin_inset LatexCommand label
11347 name "lyx:-codeseg"
11352 <Name> The name to be used for the code
11353 \begin_inset LatexCommand index
11358 segment, default CSEG.
11359 This is useful if you need to tell the compiler to put the code in a special
11360 segment so you can later on tell the linker to put this segment in a special
11362 Can be used for instance when using bank switching to put the code in a
11367 \labelwidthstring 00.00.0000
11374 \begin_layout Standard
11386 \begin_inset LatexCommand index
11387 name "-\\/-constseg <Value>"
11392 <Name> The name to be used for the const
11393 \begin_inset LatexCommand index
11398 segment, default CONST.
11399 This is useful if you need to tell the compiler to put the const data in
11400 a special segment so you can later on tell the linker to put this segment
11401 in a special place in memory.
11402 Can be used for instance when using bank switching to put the const data
11407 \labelwidthstring 00.00.0000
11414 \begin_layout Standard
11423 -fdollars-in-identifiers
11424 \begin_inset LatexCommand index
11425 name "-\\/-fdollars-in-identifiers"
11431 Permit '$' as an identifier character.
11435 \labelwidthstring 00.00.0000
11442 \begin_layout Standard
11454 \begin_inset LatexCommand index
11455 name "-\\/-more-pedantic"
11460 \begin_inset LatexCommand index
11471 a SDCC compiler option but if you want
11475 warnings you can use a separate tool dedicated to syntax checking like
11477 \begin_inset LatexCommand label
11478 name "lyx:more-pedantic-SPLINT"
11483 \begin_inset LatexCommand index
11484 name "lint (syntax checking tool)"
11489 \begin_inset LatexCommand url
11490 target "http://www.splint.org"
11495 To make your source files parseable by splint you will have to include
11501 \begin_inset LatexCommand index
11502 name "splint (syntax checking tool)"
11506 in your source file and add brackets around extended keywords (like
11509 \begin_inset Quotes sld
11522 \begin_inset Quotes srd
11530 \begin_inset Quotes sld
11533 __interrupt\InsetSpace ~
11535 \begin_inset Quotes srd
11543 Splint has an excellent on line manual at
11544 \begin_inset LatexCommand url
11545 target "http://www.splint.org/manual/"
11549 and it's capabilities go beyond pure syntax checking.
11550 You'll need to tell splint the location of SDCC's include files so a typical
11551 command line could look like this:
11555 splint\InsetSpace ~
11557 /usr/local/share/sdcc/include/mcs51/\InsetSpace ~
11563 \labelwidthstring 00.00.0000
11570 \begin_layout Standard
11582 \begin_inset LatexCommand index
11583 name "-\\/-short-is-8bits"
11588 \begin_inset LatexCommand label
11589 name "lyx:--short-is-8bits"
11593 Treat short as 8-bit (for backward compatibility with older versions of
11594 compiler - see section
11595 \begin_inset LatexCommand ref
11596 reference "sec:Compatibility-with-previous"
11603 \begin_layout Standard
11604 \begin_inset VSpace bigskip
11610 \begin_layout Subsection
11611 Intermediate Dump Options
11612 \begin_inset LatexCommand label
11613 name "sub:Intermediate-Dump-Options"
11618 \begin_inset LatexCommand index
11619 name "Options intermediate dump"
11624 \begin_inset LatexCommand index
11625 name "Intermediate dump options"
11632 \begin_layout Standard
11633 The following options are provided for the purpose of retargetting and debugging
11635 They provide a means to dump the intermediate code (iCode
11636 \begin_inset LatexCommand index
11641 ) generated by the compiler in human readable form at various stages of
11642 the compilation process.
11643 More on iCodes see chapter
11644 \begin_inset LatexCommand ref
11645 reference "sub:The-anatomy-of"
11650 \begin_inset Quotes srd
11653 The anatomy of the compiler
11654 \begin_inset Quotes srd
11661 \labelwidthstring 00.00.0000
11668 \begin_layout Standard
11678 \begin_inset LatexCommand index
11679 name "-\\/-dumpraw"
11685 This option will cause the compiler to dump the intermediate code into
11688 <source filename>.dumpraw
11690 just after the intermediate code has been generated for a function, i.e.
11691 before any optimizations are done.
11693 \begin_inset LatexCommand index
11694 name "Basic blocks"
11698 at this stage ordered in the depth first number, so they may not be in
11699 sequence of execution.
11703 \labelwidthstring 00.00.0000
11710 \begin_layout Standard
11720 \begin_inset LatexCommand index
11721 name "-\\/-dumpgcse"
11727 Will create a dump of iCodes, after global subexpression elimination
11728 \begin_inset LatexCommand index
11729 name "Global subexpression elimination"
11733 , into a file named
11735 <source filename>.dumpgcse.
11739 \labelwidthstring 00.00.0000
11746 \begin_layout Standard
11756 \begin_inset LatexCommand index
11757 name "-\\/-dumpdeadcode"
11763 Will create a dump of iCodes, after deadcode elimination
11764 \begin_inset LatexCommand index
11765 name "Dead-code elimination"
11769 , into a file named
11771 <source filename>.dumpdeadcode.
11775 \labelwidthstring 00.00.0000
11782 \begin_layout Standard
11792 \begin_inset LatexCommand index
11793 name "-\\/-dumploop"
11802 Will create a dump of iCodes, after loop optimizations
11803 \begin_inset LatexCommand index
11804 name "Loop optimization"
11808 , into a file named
11810 <source filename>.dumploop.
11814 \labelwidthstring 00.00.0000
11821 \begin_layout Standard
11831 \begin_inset LatexCommand index
11832 name "-\\/-dumprange"
11841 Will create a dump of iCodes, after live range analysis
11842 \begin_inset LatexCommand index
11843 name "Live range analysis"
11847 , into a file named
11849 <source filename>.dumprange.
11853 \labelwidthstring 00.00.0000
11860 \begin_layout Standard
11870 \begin_inset LatexCommand index
11871 name "-\\/-dumlrange"
11877 Will dump the life ranges
11878 \begin_inset LatexCommand index
11879 name "Live range analysis"
11887 \labelwidthstring 00.00.0000
11894 \begin_layout Standard
11904 \begin_inset LatexCommand index
11905 name "-\\/-dumpregassign"
11911 Will create a dump of iCodes, after register assignment
11912 \begin_inset LatexCommand index
11913 name "Register assignment"
11917 , into a file named
11919 <source filename>.dumprassgn.
11923 \labelwidthstring 00.00.0000
11930 \begin_layout Standard
11940 \begin_inset LatexCommand index
11941 name "-\\/-dumplrange"
11947 Will create a dump of the live ranges of iTemp's
11951 \labelwidthstring 00.00.0000
11958 \begin_layout Standard
11968 \begin_inset LatexCommand index
11969 name "-\\/-dumpall"
11978 Will cause all the above mentioned dumps to be created.
11981 \begin_layout Standard
11982 \begin_inset VSpace bigskip
11988 \begin_layout Subsection
11989 Redirecting output on Windows Shells
11992 \begin_layout Standard
11993 By default SDCC writes its error messages to
11994 \begin_inset Quotes sld
11998 \begin_inset Quotes srd
12002 To force all messages to
12003 \begin_inset Quotes sld
12007 \begin_inset Quotes srd
12019 \begin_layout Standard
12034 \begin_inset LatexCommand index
12035 name "-\\/-use-stdout"
12040 Additionally, if you happen to have visual studio installed in your windows
12041 machine, you can use it to compile your sources using a custom build and
12048 \begin_layout Standard
12060 \begin_inset LatexCommand index
12066 Something like this should work:
12085 \begin_layout Standard
12104 \begin_layout Standard
12116 -model-large -c $(InputPath)
12119 \begin_inset VSpace bigskip
12125 \begin_layout Section
12126 Environment variables
12127 \begin_inset LatexCommand index
12128 name "Environment variables"
12135 \begin_layout Standard
12136 SDCC recognizes the following environment variables:
12140 \labelwidthstring 00.00.0000
12144 \begin_inset LatexCommand index
12145 name "SDCC\\_LEAVE\\_SIGNALS"
12151 SDCC installs a signal handler
12152 \begin_inset LatexCommand index
12153 name "signal handler"
12157 to be able to delete temporary files after an user break (^C) or an exception.
12158 If this environment variable is set, SDCC won't install the signal handler
12159 in order to be able to debug SDCC.
12163 \labelwidthstring 00.00.0000
12169 \begin_inset LatexCommand index
12170 name "TMP, TEMP, TMPDIR"
12176 Path, where temporary files will be created.
12177 The order of the variables is the search order.
12178 In a standard *nix environment these variables are not set, and there's
12179 no need to set them.
12180 On Windows it's recommended to set one of them.
12184 \labelwidthstring 00.00.0000
12188 \begin_inset LatexCommand index
12196 \begin_inset LatexCommand ref
12197 reference "sub:Install-paths"
12203 \begin_inset Quotes sld
12207 \begin_inset Quotes srd
12214 \labelwidthstring 00.00.0000
12218 \begin_inset LatexCommand index
12219 name "SDCC\\_INCLUDE"
12226 \begin_inset LatexCommand ref
12227 reference "sub:Search-Paths"
12233 \begin_inset Quotes sld
12237 \begin_inset Quotes srd
12244 \labelwidthstring 00.00.0000
12248 \begin_inset LatexCommand index
12256 \begin_inset LatexCommand ref
12257 reference "sub:Search-Paths"
12263 \begin_inset Quotes sld
12267 \begin_inset Quotes srd
12273 \begin_layout Standard
12274 There are some more environment variables recognized by SDCC, but these
12275 are solely used for debugging purposes.
12276 They can change or disappear very quickly, and will never be documented.
12277 \begin_inset VSpace bigskip
12283 \begin_layout Section
12284 Storage Class Language Extensions
12287 \begin_layout Subsection
12288 MCS51/DS390 Storage Class
12289 \begin_inset LatexCommand index
12290 name "Storage class"
12294 Language Extensions
12297 \begin_layout Standard
12298 In addition to the ANSI storage classes SDCC allows the following MCS51
12299 specific storage classes:
12302 \begin_layout Subsubsection
12304 \begin_inset LatexCommand index
12305 name "data (mcs51, ds390 storage class)"
12310 \begin_inset LatexCommand index
12311 name "\\_\\_data (mcs51, ds390 storage class)"
12316 \begin_inset LatexCommand index
12317 name "near (storage class)"
12322 \begin_inset LatexCommand index
12323 name "\\_\\_near (storage class)"
12330 \begin_layout Standard
12335 storage class for the Small Memory model (
12343 or the more ANSI-C compliant forms
12351 can be used synonymously).
12352 Variables declared with this storage class will be allocated in the directly
12353 addressable portion of the internal RAM of a 8051, e.g.:
12356 \begin_layout Verse
12359 __data unsigned char test_data;
12362 \begin_layout Standard
12363 Writing 0x01 to this variable generates the assembly code:
12366 \begin_layout Verse
12369 75*00 01\InsetSpace ~
12377 \begin_layout Subsubsection
12379 \begin_inset LatexCommand index
12380 name "xdata (mcs51, ds390 storage class)"
12385 \begin_inset LatexCommand index
12386 name "\\_\\_xdata (mcs51, ds390 storage class)"
12391 \begin_inset LatexCommand index
12392 name "far (storage class)"
12397 \begin_inset LatexCommand index
12398 name "\\_\\_far (storage class)"
12405 \begin_layout Standard
12406 Variables declared with this storage class will be placed in the external
12412 storage class for the Large Memory model, e.g.:
12415 \begin_layout Verse
12418 __xdata unsigned char test_xdata;
12421 \begin_layout Standard
12422 Writing 0x01 to this variable generates the assembly code:
12425 \begin_layout Verse
12428 90s00r00\InsetSpace ~
12459 \begin_layout Subsubsection
12461 \begin_inset LatexCommand index
12462 name "idata (mcs51, ds390 storage class)"
12467 \begin_inset LatexCommand index
12468 name "\\_\\_idata (mcs51, ds390 storage class)"
12475 \begin_layout Standard
12476 Variables declared with this storage class will be allocated into the indirectly
12477 addressable portion of the internal ram of a 8051, e.g.:
12480 \begin_layout Verse
12483 __idata unsigned char test_idata;
12486 \begin_layout Standard
12487 Writing 0x01 to this variable generates the assembly code:
12490 \begin_layout Verse
12517 \begin_layout Standard
12518 Please note, the first 128 byte of idata physically access the same RAM
12519 as the data memory.
12520 The original 8051 had 128 byte idata memory, nowadays most devices have
12521 256 byte idata memory.
12523 \begin_inset LatexCommand index
12528 is located in idata memory.
12531 \begin_layout Subsubsection
12533 \begin_inset LatexCommand index
12534 name "pdata (mcs51, ds390 storage class)"
12539 \begin_inset LatexCommand index
12540 name "\\_\\_pdata (mcs51, ds390 storage class)"
12547 \begin_layout Standard
12548 Paged xdata access is just as straightforward as using the other addressing
12550 It is typically located at the start of xdata and has a maximum size of
12552 The following example writes 0x01 to the pdata variable.
12553 Please note, pdata access physically accesses xdata memory.
12554 The high byte of the address is determined by port P2
12555 \begin_inset LatexCommand index
12556 name "P2 (mcs51 sfr)"
12560 (or in case of some 8051 variants by a separate Special Function Register,
12562 \begin_inset LatexCommand ref
12563 reference "sub:MCS51-variants"
12572 storage class for the Medium Memory model, e.g.:
12575 \begin_layout Verse
12578 __pdata unsigned char test_pdata;
12581 \begin_layout Standard
12582 Writing 0x01 to this variable generates the assembly code:
12585 \begin_layout Verse
12594 mov r0,#_test_pdata
12616 \begin_layout Standard
12621 \begin_layout Standard
12631 \begin_inset LatexCommand index
12636 option is used the pdata memory area is followed by the xstack memory area
12637 and the sum of their sizes is limited to 256 bytes.
12640 \begin_layout Subsubsection
12642 \begin_inset LatexCommand index
12648 \begin_inset LatexCommand index
12656 \begin_layout Standard
12657 'Variables' declared with this storage class will be placed in the code
12661 \begin_layout Verse
12664 __code unsigned char test_code;
12667 \begin_layout Standard
12668 Read access to this variable generates the assembly code:
12671 \begin_layout Verse
12674 90s00r6F\InsetSpace ~
12677 mov dptr,#_test_code
12702 \begin_layout Standard
12707 indexed arrays of characters in code memory can be accessed efficiently:
12710 \begin_layout Verse
12713 __code char test_array[] = {'c','h','e','a','p'};
12716 \begin_layout Standard
12717 Read access to this array using an 8-bit unsigned index generates the assembly
12721 \begin_layout Verse
12733 \begin_layout Verse
12736 90s00r41\InsetSpace ~
12739 mov dptr,#_test_array
12742 \begin_layout Verse
12757 \begin_layout Subsubsection
12759 \begin_inset LatexCommand index
12765 \begin_inset LatexCommand index
12773 \begin_layout Standard
12774 This is a data-type and a storage class specifier.
12775 When a variable is declared as a bit, it is allocated into the bit addressable
12776 memory of 8051, e.g.:
12779 \begin_layout Verse
12785 \begin_layout Standard
12786 Writing 1 to this variable generates the assembly code:
12789 \begin_layout Verse
12803 \begin_layout Standard
12804 The bit addressable memory consists of 128 bits which are located from 0x20
12805 to 0x2f in data memory.
12808 Apart from this 8051 specific storage class most architectures support
12810 \begin_inset LatexCommand index
12819 \begin_layout Standard
12820 Not really meant as examples, but nevertheless showing what bitfields are
12821 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
12827 In accordance with ISO/IEC 9899 bits and bitfields without an explicit
12828 signed modifier are implemented as unsigned.
12831 \begin_layout Subsubsection
12833 \begin_inset LatexCommand index
12839 \begin_inset LatexCommand index
12845 \begin_inset LatexCommand index
12851 \begin_inset LatexCommand index
12857 \begin_inset LatexCommand index
12863 \begin_inset LatexCommand index
12869 \begin_inset LatexCommand index
12875 \begin_inset LatexCommand index
12883 \begin_layout Standard
12884 Like the bit keyword,
12886 sfr / sfr16 / sfr32 / sbit
12888 signify both a data-type and storage class, they are used to describe the
12909 variables of a 8051, eg:
12912 \begin_layout Verse
12916 \begin_inset LatexCommand index
12922 \begin_inset LatexCommand index
12927 (0x80) P0;\InsetSpace ~
12928 /* special function register P0 at location 0x80 */
12933 special function register combination for timer 0
12937 with the high byte at
12938 location 0x8C and the low byte at location 0x8A */
12940 __sfr16 __at (0x8C8A)
12946 \begin_inset LatexCommand index
12952 \begin_inset LatexCommand index
12957 (0xd7) CY;\InsetSpace ~
12959 \begin_inset LatexCommand index
12965 \begin_inset LatexCommand index
12973 \begin_layout Standard
12974 Special function registers which are located on an address dividable by
12975 8 are bit-addressable, an
12979 addresses a specific bit within these sfr.
12981 16 Bit and 32 bit special function
12982 register combinations which require a certain access order are better not
12992 Allthough SDCC usually accesses them Least Significant Byte (LSB) first,
12993 this is not guaranteed.
12998 \begin_layout Standard
12999 Please note, if you use a header file which was written for another compiler
13000 then the sfr / sfr16 / sfr32 / sbit Storage Class extensions will most
13006 Specifically the syntax
13009 sfr P0 = 0x80;\InsetSpace ~
13016 by SDCC to an assignment of 0x80 to a variable called P0
13019 \begin_inset Marginal
13022 \begin_layout Standard
13036 Nevertheless it is possible to write header files
13037 \begin_inset LatexCommand index
13038 name "Header files"
13043 \begin_inset LatexCommand index
13044 name "Include files"
13048 which can be shared among different compilers (see section
13049 \begin_inset LatexCommand ref
13050 reference "sec:Porting-code-to-other-compilers"
13058 \begin_layout Subsubsection
13060 \begin_inset LatexCommand index
13065 to MCS51/DS390 specific memory spaces
13068 \begin_layout Standard
13069 SDCC allows (via language extensions) pointers to explicitly point to any
13070 of the memory spaces
13071 \begin_inset LatexCommand index
13072 name "Memory model"
13077 In addition to the explicit pointers, the compiler uses (by default) generic
13078 pointers which can be used to point to any of the memory spaces.
13083 declaration examples:
13086 \begin_layout Verse
13089 /* pointer physically in internal ram pointing to object in external ram
13092 __xdata unsigned char * __data p;
13096 /* pointer physically in external ram
13097 pointing to object in internal ram */
13099 __data unsigned char * __xdata p;
13104 pointer physically in code rom pointing to data in xdata space */
13107 unsigned char * __code p;
13111 /* pointer physically in code space pointing to
13112 data in code space */
13114 __code unsigned char * __code p;
13119 physically located in xdata space */
13121 unsigned char * __xdata p;
13126 pointer physically located in default memory space */
13133 the following is a function pointer
13134 \begin_inset LatexCommand index
13135 name "function pointer"
13139 physically located in data space */
13141 char (* __data fp)(void);
13144 \begin_layout Standard
13145 Well you get the idea.
13150 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
13163 The highest order byte of the
13167 pointers contains the data space information.
13168 Assembler support routines are called whenever data is stored or retrieved
13174 These are useful for developing reusable library
13175 \begin_inset LatexCommand index
13181 Explicitly specifying the pointer
13182 \begin_inset LatexCommand index
13187 type will generate the most efficient code.
13190 \begin_layout Subsubsection
13191 Notes on MCS51 memory
13192 \begin_inset LatexCommand index
13193 name "MCS51 memory"
13200 \begin_layout Standard
13201 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
13202 RAM memory which is structured as follows:
13206 - Bytes 00-1F - 32 bytes to hold
13207 up to 4 banks of the registers R0 to R7,
13209 - Bytes 20-2F - 16 bytes to hold
13211 \begin_inset LatexCommand index
13218 - Bytes 30-7F - 80 bytes for general purpose use.
13223 \begin_layout Standard
13224 Additionally some members of the MCS51 family may have up to 128 bytes of
13225 additional, indirectly addressable, internal RAM memory (
13230 \begin_inset LatexCommand index
13231 name "idata (mcs51, ds390 storage class)"
13236 \begin_inset LatexCommand index
13237 name "\\_\\_idata (mcs51, ds390 storage class)"
13242 Furthermore, some chips may have some built in external memory (
13247 \begin_inset LatexCommand index
13248 name "xdata (mcs51, ds390 storage class)"
13253 \begin_inset LatexCommand index
13254 name "\\_\\_xdata (mcs51, ds390 storage class)"
13258 ) which should not be confused with the internal, directly addressable RAM
13264 \begin_inset LatexCommand index
13265 name "data (mcs51, ds390 storage class)"
13270 \begin_inset LatexCommand index
13271 name "\\_\\_data (mcs51, ds390 storage class)"
13276 Sometimes this built in
13280 memory has to be activated before using it (you can probably find this
13281 information on the datasheet of the microcontroller your are using, see
13283 \begin_inset LatexCommand ref
13284 reference "sub:Startup-Code"
13292 \begin_layout Standard
13293 Normally SDCC will only use the first bank
13294 \begin_inset LatexCommand index
13295 name "register bank (mcs51, ds390)"
13299 of registers (register bank 0), but it is possible to specify that other
13300 banks of registers (keyword
13307 \begin_inset LatexCommand index
13308 name "using (mcs51, ds390 register bank)"
13313 \begin_inset LatexCommand index
13314 name "\\_\\_using (mcs51, ds390 register bank)"
13320 ) should be used for example in interrupt
13321 \begin_inset LatexCommand index
13327 \begin_inset LatexCommand index
13328 name "\\_\\_interrupt"
13333 By default, the compiler will place the stack after the last byte of allocated
13334 memory for variables.
13335 For example, if the first 2 banks of registers are used, and only four
13340 variables, it will position the base of the internal stack at address 20
13342 This implies that as the stack
13343 \begin_inset LatexCommand index
13348 grows, it will use up the remaining register banks, and the 16 bytes used
13349 by the 128 bit variables, and 80 bytes for general purpose use.
13350 If any bit variables are used, the data variables will be placed in unused
13351 register banks and after the byte holding the last bit variable.
13352 For example, if register banks 0 and 1 are used, and there are 9 bit variables
13357 variables will be placed starting from address 0x10 to 0x20 and continue
13363 \begin_layout Standard
13373 \begin_inset LatexCommand index
13374 name "-\\/-data-loc <Value>"
13378 to specify the start address of the
13386 \begin_layout Standard
13396 \begin_inset LatexCommand index
13397 name "-\\/-iram-size <Value>"
13401 to specify the size of the total internal RAM (
13415 \begin_layout Standard
13416 By default the 8051 linker will place the stack after the last byte of (i)data
13422 \begin_layout Standard
13432 \begin_inset LatexCommand index
13433 name "-\\/-stack-loc <Value>"
13437 allows you to specify the start of the stack, i.e.
13438 you could start it after any data in the general purpose area.
13439 If your microcontroller has additional indirectly addressable internal
13444 ) you can place the stack on it.
13445 You may also need to use -
13449 \begin_layout Standard
13459 \begin_inset LatexCommand index
13460 name "-\\/-xdata-loc<Value>"
13464 to set the start address of the external RAM (
13472 \begin_layout Standard
13482 \begin_inset LatexCommand index
13483 name "-\\/-xram-size <Value>"
13487 to specify its size.
13488 Same goes for the code memory, using -
13492 \begin_layout Standard
13502 \begin_inset LatexCommand index
13503 name "-\\/-code-loc <Value>"
13511 \begin_layout Standard
13521 \begin_inset LatexCommand index
13522 name "-\\/-code-size <Value>"
13527 If in doubt, don't specify any options and see if the resulting memory
13528 layout is appropriate, then you can adjust it.
13531 \begin_layout Standard
13532 The linker generates two files with memory allocation information.
13533 The first, with extension .map
13534 \begin_inset LatexCommand index
13539 shows all the variables and segments.
13540 The second with extension .mem
13541 \begin_inset LatexCommand index
13546 shows the final memory layout.
13547 The linker will complain either if memory segments overlap, there is not
13548 enough memory, or there is not enough space for stack.
13549 If you get any linking warnings and/or errors related to stack or segments
13550 allocation, take a look at either the .map or .mem files to find out what
13552 The .mem file may even suggest a solution to the problem.
13553 \begin_inset VSpace bigskip
13559 \begin_layout Subsection
13560 Z80/Z180 Storage Class
13561 \begin_inset LatexCommand index
13562 name "Z80!Storage class"
13566 Language Extensions
13569 \begin_layout Subsubsection
13571 \begin_inset LatexCommand index
13577 \begin_inset LatexCommand index
13582 (in/out to 8-bit addresses)
13585 \begin_layout Standard
13587 \begin_inset LatexCommand index
13592 family has separate address spaces for memory and
13602 \begin_inset LatexCommand index
13603 name "I/O memory (Z80, Z180)"
13608 \begin_inset LatexCommand index
13609 name "Z80!I/O memory"
13614 \begin_inset LatexCommand index
13615 name "Z180!I/O memory"
13619 is accessed with special instructions, e.g.:
13622 \begin_layout Verse
13625 sfr at 0x78 IoPort;\InsetSpace ~
13627 /* define a var in I/O space at 78h called IoPort */
13631 \begin_layout Standard
13632 Writing 0x01 to this variable generates the assembly code:
13635 \begin_layout Verse
13655 \begin_layout Subsubsection
13657 \begin_inset LatexCommand index
13663 \begin_inset LatexCommand index
13668 (in/out to 16-bit addresses)
13671 \begin_layout Standard
13676 is used to support 16 bit addresses in I/O memory e.g.:
13679 \begin_layout Verse
13683 \begin_inset LatexCommand index
13689 \begin_inset LatexCommand index
13697 \begin_layout Standard
13698 Writing 0x01 to this variable generates the assembly code:
13701 \begin_layout Verse
13704 01 23 01\InsetSpace ~
13726 \begin_layout Subsubsection
13728 \begin_inset LatexCommand index
13734 \begin_inset LatexCommand index
13739 (in0/out0 to 8 bit addresses on Z180
13740 \begin_inset LatexCommand index
13746 \begin_inset LatexCommand index
13747 name "HD64180 (see Z180)"
13754 \begin_layout Standard
13755 The compiler option -
13759 \begin_layout Standard
13769 \begin_inset LatexCommand index
13770 name "Z180!Options!-\\/-portmode"
13774 =180 (80) and a compiler #pragma\InsetSpace ~
13776 \begin_inset LatexCommand index
13777 name "Z180!Pragmas!\\#pragma portmode"
13781 z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
13791 If you include the file z180.h this will be set automatically.
13792 \begin_inset VSpace bigskip
13798 \begin_layout Subsection
13800 \begin_inset LatexCommand index
13801 name "HC08!Storage class"
13805 Language Extensions
13808 \begin_layout Subsubsection
13810 \begin_inset LatexCommand index
13811 name "data (hc08 storage class)"
13816 \begin_inset LatexCommand index
13817 name "\\_\\_data (hc08 storage class)"
13824 \begin_layout Standard
13825 The data storage class declares a variable that resides in the first 256
13826 bytes of memory (the direct page).
13828 \begin_inset LatexCommand index
13833 is most efficient at accessing variables (especially pointers) stored here.
13836 \begin_layout Subsubsection
13838 \begin_inset LatexCommand index
13839 name "xdata (hc08 storage class)"
13844 \begin_inset LatexCommand index
13845 name "\\_\\_xdata (hc08 storage class)"
13852 \begin_layout Standard
13853 The xdata storage class declares a variable that can reside anywhere in
13855 This is the default if no storage class is specified.
13857 \begin_inset VSpace bigskip
13863 \begin_layout Section
13864 Other SDCC language extensions
13865 \begin_inset LatexCommand index
13866 name "Other SDCC language extensions"
13873 \begin_layout Subsection
13877 \begin_layout Standard
13878 SDCC supports the use of binary constants, such as 0b01100010.
13879 This feature is only enabled when the compiler is invoked using --std-sdccxx.
13882 \begin_layout Standard
13883 \begin_inset VSpace bigskip
13889 \begin_layout Section
13890 Absolute Addressing
13891 \begin_inset LatexCommand index
13892 name "Absolute addressing"
13899 \begin_layout Standard
13900 Data items can be assigned an absolute address with the
13903 \begin_inset LatexCommand index
13909 \begin_inset LatexCommand index
13916 keyword, in addition to a storage class, e.g.:
13919 \begin_layout Verse
13923 \begin_inset LatexCommand index
13924 name "xdata (mcs51, ds390 storage class)"
13929 \begin_inset LatexCommand index
13930 name "\\_\\_xdata (mcs51, ds390 storage class)"
13935 \begin_inset LatexCommand index
13941 \begin_inset LatexCommand index
13946 0x7ffe unsigned int chksum;
13949 \begin_layout Standard
13950 or, better conforming to ISO/IEC 9899 C:
13953 \begin_layout Verse
13956 __xdata __at (0x7ffe) unsigned int chksum;
13959 \begin_layout Standard
13960 In the above example the variable chksum will be located at 0x7ffe and 0x7fff
13961 of the external ram.
13966 reserve any space for variables declared in this way
13967 \begin_inset Marginal
13970 \begin_layout Standard
13979 (they are implemented with an equate in the assembler).
13980 Thus it is left to the programmer to make sure there are no overlaps with
13981 other variables that are declared without the absolute address.
13982 The assembler listing file (.lst
13983 \begin_inset LatexCommand index
13988 ) and the linker output files (.rst
13989 \begin_inset LatexCommand index
13995 \begin_inset LatexCommand index
14000 ) are good places to look for such overlaps.
14003 \begin_layout Standard
14004 If however you provide an initializer
14005 \begin_inset LatexCommand index
14006 name "Variable initialization"
14010 actual memory allocation will take place and overlaps will be detected
14015 \begin_layout Verse
14018 __code __at (0x7ff0) char Id[5] =
14019 \begin_inset Quotes sld
14023 \begin_inset Quotes srd
14029 \begin_layout Standard
14030 In the above example the variable Id will be located from 0x7ff0 to 0x7ff4
14034 \begin_layout Standard
14035 In case of memory mapped I/O devices the keyword
14039 has to be used to tell the compiler that accesses might not be removed:
14042 \begin_layout Verse
14046 \begin_inset LatexCommand index
14052 \begin_inset LatexCommand index
14053 name "xdata (mcs51, ds390 storage class)"
14058 \begin_inset LatexCommand index
14063 (0x8000) unsigned char PORTA_8255;
14066 \begin_layout Standard
14067 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
14072 \begin_inset LatexCommand index
14073 name "Aligned array"
14080 starts at a block (256 byte) boundary
14081 \begin_inset LatexCommand index
14082 name "block boundary"
14087 \begin_inset LatexCommand ref
14088 reference "sub:A-Step-by Assembler Introduction"
14094 Absolute addresses can be specified for variables in all
14095 storage classes, e.g.:
14098 \begin_layout Verse
14102 \begin_inset LatexCommand index
14108 \begin_inset LatexCommand index
14116 \begin_layout Standard
14117 The above example will allocate the variable at offset 0x02 in the bit-addressab
14119 There is no real advantage to assigning absolute addresses to variables
14120 in this manner, unless you want strict control over all the variables allocated.
14121 One possible use would be to write hardware portable code.
14122 For example, if you have a routine that uses one or more of the microcontroller
14123 I/O pins, and such pins are different for two different hardwares, you
14124 can declare the I/O pins in your routine using:
14127 \begin_layout Verse
14131 \begin_inset LatexCommand index
14136 __bit MOSI;\InsetSpace ~
14140 /* master out, slave in */
14142 extern volatile __bit MISO;\InsetSpace ~
14149 extern volatile __bit MCLK;\InsetSpace ~
14158 Output of a byte on a 3-wire serial bus.
14163 If needed adapt polarity of clock,
14164 polarity of data and bit order
14169 unsigned char spi_io(unsigned char out_byte)
14194 MOSI = out_byte & 0x80;
14225 /* _asm nop _endasm; */\InsetSpace ~
14233 /* for slow peripherals */
14285 \begin_layout Standard
14286 Then, someplace in the code for the first hardware you would use
14289 \begin_layout Verse
14293 \begin_inset LatexCommand index
14299 \begin_inset LatexCommand index
14304 (0x80) MOSI;\InsetSpace ~
14308 /* I/O port 0, bit 0 */
14310 __bit __at (0x81) MISO;\InsetSpace ~
14317 __bit __at (0x82) MCLK;\InsetSpace ~
14321 /* I/O port 0, bit 2 */
14324 \begin_layout Standard
14325 Similarly, for the second hardware you would use
14328 \begin_layout Verse
14331 __bit __at (0x83) MOSI;\InsetSpace ~
14335 /* I/O port 0, bit 3 */
14337 __bit __at (0x91) MISO;\InsetSpace ~
14342 I/O port 1, bit 1 */
14345 \begin_inset LatexCommand index
14350 __at (0x92) MCLK;\InsetSpace ~
14354 /* I/O port 1, bit 2 */
14357 \begin_layout Standard
14358 and you can use the same hardware dependent routine without changes, as
14359 for example in a library.
14360 This is somehow similar to sbit, but only one absolute address has to be
14361 specified in the whole project.
14362 \begin_inset VSpace bigskip
14368 \begin_layout Section
14370 \begin_inset LatexCommand index
14376 \begin_inset LatexCommand index
14377 name "function parameter"
14382 \begin_inset LatexCommand index
14383 name "local variables"
14388 \begin_inset LatexCommand label
14389 name "sec:Parameters-and-Local-Variables"
14396 \begin_layout Standard
14397 Automatic (local) variables and parameters to functions can either be placed
14398 on the stack or in data-space.
14399 The default action of the compiler is to place these variables in the internal
14400 RAM (for small model) or external RAM (for medium or large model).
14401 This in fact makes them similar to
14404 \begin_inset LatexCommand index
14411 so by default functions are non-reentrant
14412 \begin_inset LatexCommand index
14422 They can be placed on the stack
14423 \begin_inset LatexCommand index
14434 \begin_layout Standard
14444 \begin_inset LatexCommand index
14445 name "-\\/-stack-auto"
14453 #pragma\InsetSpace ~
14457 \begin_inset LatexCommand index
14458 name "\\#pragma stackauto"
14465 \begin_inset LatexCommand index
14472 keyword in the function declaration, e.g.:
14475 \begin_layout Verse
14478 unsigned char foo(char i) __reentrant
14492 \begin_layout Standard
14493 Since stack space on 8051 is limited, the
14503 \begin_layout Standard
14514 option should be used sparingly.
14515 Note that the reentrant keyword just means that the parameters & local
14516 variables will be allocated to the stack, it
14520 mean that the function is register bank
14521 \begin_inset LatexCommand index
14522 name "register bank (mcs51, ds390)"
14531 \begin_inset LatexCommand index
14532 name "local variables"
14536 can be assigned storage classes and absolute
14537 \begin_inset LatexCommand index
14538 name "Absolute addressing"
14545 \begin_layout Verse
14548 unsigned char foo()
14556 __xdata unsigned char i;
14569 \begin_inset LatexCommand index
14574 (0x31) unsigned char j;
14586 \begin_layout Standard
14587 In the above example the variable
14591 will be allocated in the external ram,
14595 in bit addressable space and
14606 \begin_layout Standard
14617 or when a function is declared as
14621 this should only be done for static variables.
14624 \begin_layout Standard
14626 \begin_inset LatexCommand index
14627 name "function parameter"
14631 however are not allowed any storage class
14632 \begin_inset LatexCommand index
14633 name "Storage class"
14637 , (storage classes for parameters will be ignored), their allocation is
14638 governed by the memory model in use, and the reentrancy options.
14641 \begin_layout Standard
14642 It is however allowed to use bit parameters in reentrant functions and also
14643 non-static local bit variables are supported.
14644 Efficient use is limited to 8 semi-bitregisters in bit space.
14645 They are pushed and popped to stack
14646 \begin_inset LatexCommand index
14651 as a single byte just like the normal registers.
14654 \begin_layout Section
14656 \begin_inset LatexCommand label
14657 name "sub:Overlaying"
14662 \begin_inset LatexCommand index
14670 \begin_layout Standard
14672 \begin_inset LatexCommand index
14677 functions SDCC will try to reduce internal ram space usage by overlaying
14678 parameters and local variables of a function (if possible).
14679 Parameters and local variables
14680 \begin_inset LatexCommand index
14681 name "local variables"
14685 of a function will be allocated to an overlayable segment if the function
14688 no other function calls and the function is non-reentrant and the memory
14690 \begin_inset LatexCommand index
14691 name "Memory model"
14698 If an explicit storage class
14699 \begin_inset LatexCommand index
14700 name "Storage class"
14704 is specified for a local variable, it will NOT be overlaid.
14707 \begin_layout Standard
14708 Note that the compiler (not the linkage editor) makes the decision for overlayin
14710 Functions that are called from an interrupt service routine
14711 \begin_inset Marginal
14714 \begin_layout Standard
14722 should be preceded by a #pragma\InsetSpace ~
14724 \begin_inset LatexCommand index
14725 name "\\#pragma nooverlay"
14729 if they are not reentrant.
14732 \begin_layout Standard
14733 Also note that the compiler does not do any processing of inline assembler
14734 code, so the compiler might incorrectly assign local variables and parameters
14735 of a function into the overlay segment if the inline assembler code calls
14736 other c-functions that might use the overlay.
14737 In that case the #pragma\InsetSpace ~
14738 nooverlay should be used.
14741 \begin_layout Standard
14742 Parameters and local variables of functions that contain 16 or 32 bit multiplica
14744 \begin_inset LatexCommand index
14745 name "Multiplication"
14750 \begin_inset LatexCommand index
14755 will NOT be overlaid since these are implemented using external functions,
14759 \begin_layout Verse
14765 \begin_inset LatexCommand index
14766 name "\\#pragma nooverlay"
14772 void set_error(unsigned char errcd)
14789 some_isr () __interrupt
14790 \begin_inset LatexCommand index
14821 \begin_layout Standard
14822 In the above example the parameter
14830 would be assigned to the overlayable segment if the #pragma\InsetSpace ~
14832 not present, this could cause unpredictable runtime behavior when called
14833 from an interrupt service routine.
14834 The #pragma\InsetSpace ~
14835 nooverlay ensures that the parameters and local variables for
14836 the function are NOT overlaid.
14837 \begin_inset VSpace bigskip
14843 \begin_layout Section
14844 Interrupt Service Routines
14845 \begin_inset LatexCommand label
14846 name "sub:Interrupt-Service-Routines"
14853 \begin_layout Subsection
14854 General Information
14857 \begin_layout Standard
14870 outines to be coded in C, with some extended keywords.
14873 \begin_layout Verse
14876 void timer_isr (void) __interrupt (1) __using (1)
14890 \begin_layout Standard
14891 The optional number following the
14894 \begin_inset LatexCommand index
14900 \begin_inset LatexCommand index
14901 name "\\_\\_interrupt"
14907 keyword is the interrupt number this routine will service.
14908 When present, the compiler will insert a call to this routine in the interrupt
14910 \begin_inset LatexCommand index
14911 name "interrupt vector table"
14915 for the interrupt number specified.
14916 If you have multiple source files in your project, interrupt service routines
14917 can be present in any of them, but a prototype of the isr MUST be present
14918 or included in the file that contains the function
14923 The optional (8051 specific) keyword
14926 \begin_inset LatexCommand index
14927 name "using (mcs51, ds390 register bank)"
14932 \begin_inset LatexCommand index
14933 name "\\_\\_using (mcs51, ds390 register bank)"
14939 can be used to tell the compiler to use the specified register bank when
14940 generating code for this function.
14943 Interrupt service routines open the door for some very interesting bugs:
14946 \begin_layout Subsubsection
14947 \begin_inset LatexCommand label
14948 name "sub:Common-interrupt-pitfall-volatile"
14952 Common interrupt pitfall: variable not declared
14957 \begin_layout Standard
14958 If an interrupt service routine changes variables which are accessed by
14959 other functions these variables have to be declared
14964 \begin_inset LatexCommand index
14971 \begin_inset LatexCommand url
14972 target "http://en.wikipedia.org/wiki/Volatile_variable"
14979 \begin_layout Subsubsection
14980 \begin_inset LatexCommand label
14981 name "sub:Common-interrupt-pitfall-non-atomic"
14985 Common interrupt pitfall:
14990 \begin_layout Standard
14991 If the access to these variables is not
14994 \begin_inset LatexCommand index
15002 the processor needs more than one instruction for the access and could
15003 be interrupted while accessing the variable) the interrupt must be disabled
15004 during the access to avoid inconsistent data.
15007 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
15008 and should be protected by disabling interrupts.
15009 You're not automatically on the safe side if you use 8 bit variables though.
15010 We need an example here: f.e.
15011 on the 8051 the harmless looking
15012 \begin_inset Quotes srd
15022 \begin_inset Quotes sld
15031 \begin_inset Quotes srd
15041 \begin_inset Quotes sld
15044 from within an interrupt routine might get lost if the interrupt occurs
15047 \begin_inset Quotes sld
15052 counter\InsetSpace ~
15057 \begin_inset Quotes srd
15060 is not atomic on the 8051 even if
15064 is located in data memory.
15066 Bugs like these are hard to reproduce and can
15067 cause a lot of trouble.
15071 \begin_layout Subsubsection
15072 \begin_inset LatexCommand label
15073 name "sub:Common-interrupt-pitfall-stack-overflow"
15077 Common interrupt pitfall:
15082 \begin_layout Standard
15083 The return address and the registers used in the interrupt service routine
15084 are saved on the stack
15085 \begin_inset LatexCommand index
15090 so there must be sufficient stack space.
15091 If there isn't variables or registers (or even the return address itself)
15098 \begin_inset LatexCommand index
15099 name "stack overflow"
15103 is most likely to happen if the interrupt occurs during the
15104 \begin_inset Quotes sld
15108 \begin_inset Quotes srd
15111 subroutine when the stack is already in use for f.e.
15112 many return addresses.
15115 \begin_layout Subsubsection
15116 \begin_inset LatexCommand label
15117 name "sub:Common-interrupt-pitfall-non-reentrant"
15121 Common interrupt pitfall:
15123 use of non-reentrant functions
15126 \begin_layout Standard
15127 A special note here, int (16 bit) and long (32 bit) integer division
15128 \begin_inset LatexCommand index
15134 \begin_inset LatexCommand index
15135 name "Multiplication"
15140 \begin_inset LatexCommand index
15146 \begin_inset LatexCommand index
15147 name "Floating point support"
15151 operations are implemented using external support routines.
15152 If an interrupt service routine needs to do any of these operations then
15153 the support routines (as mentioned in a following section) will have to
15154 be recompiled using the
15160 \begin_layout Standard
15170 \begin_inset LatexCommand index
15171 name "-\\/-stack-auto"
15177 option and the source file will need to be compiled using the
15183 \begin_layout Standard
15195 \begin_inset LatexCommand index
15196 name "-\\/-int-long-reent"
15203 Note, the type promotion
15204 \begin_inset LatexCommand index
15205 name "type promotion"
15209 required by ANSI C can cause 16 bit routines to be used
15210 \begin_inset Marginal
15213 \begin_layout Standard
15222 without the programmer being aware of it.
15227 (unsigned char)(tail-1)
15232 within the if clause in section
15233 \begin_inset LatexCommand ref
15234 reference "sub:A-Step-by Assembler Introduction"
15241 \begin_layout Standard
15242 Calling other functions from an interrupt service routine is not recommended,
15243 avoid it if possible.
15244 Note that when some function is called from an interrupt service routine
15245 it should be preceded by a #pragma\InsetSpace ~
15247 \begin_inset LatexCommand index
15248 name "\\#pragma nooverlay"
15252 if it is not reentrant.
15253 Furthermore nonreentrant functions should not be called from the main program
15254 while the interrupt service routine might be active.
15255 They also must not be called from low priority interrupt service routines
15256 while a high priority interrupt service routine might be active.
15257 You could use semaphores or make the function
15261 if all parameters are passed in registers.
15264 \begin_inset LatexCommand ref
15265 reference "sub:Overlaying"
15270 about Overlaying and section
15271 \begin_inset LatexCommand ref
15272 reference "sub:Functions-using-private-banks"
15277 about Functions using private register banks.
15278 \begin_inset VSpace bigskip
15284 \begin_layout Subsection
15285 MCS51/DS390 Interrupt Service Routines
15288 \begin_layout Standard
15290 \begin_inset LatexCommand index
15295 numbers and the corresponding address & descriptions for the Standard 8051/8052
15297 SDCC will automatically adjust the
15298 \begin_inset LatexCommand index
15299 name "interrupt vector table"
15303 to the maximum interrupt number specified.
15308 \begin_layout Standard
15310 \begin_inset Tabular
15311 <lyxtabular version="3" rows="9" columns="3">
15313 <column alignment="center" valignment="top" leftline="true" width="0in">
15314 <column alignment="left" valignment="top" leftline="true" width="0in">
15315 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
15316 <row topline="true" bottomline="true">
15317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15320 \begin_layout Standard
15326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15329 \begin_layout Standard
15335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15338 \begin_layout Standard
15345 <row topline="true">
15346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15349 \begin_layout Standard
15355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15358 \begin_layout Standard
15364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15367 \begin_layout Standard
15374 <row topline="true">
15375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15378 \begin_layout Standard
15384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15387 \begin_layout Standard
15393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15396 \begin_layout Standard
15403 <row topline="true">
15404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15407 \begin_layout Standard
15413 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15416 \begin_layout Standard
15422 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15425 \begin_layout Standard
15432 <row topline="true">
15433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15436 \begin_layout Standard
15442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15445 \begin_layout Standard
15451 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15454 \begin_layout Standard
15461 <row topline="true">
15462 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15465 \begin_layout Standard
15471 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15474 \begin_layout Standard
15480 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15483 \begin_layout Standard
15490 <row topline="true">
15491 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15494 \begin_layout Standard
15500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15503 \begin_layout Standard
15509 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15512 \begin_layout Standard
15519 <row topline="true">
15520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15523 \begin_layout Standard
15529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15532 \begin_layout Standard
15538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15541 \begin_layout Standard
15548 <row topline="true" bottomline="true">
15549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15552 \begin_layout Standard
15558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15561 \begin_layout Standard
15567 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15570 \begin_layout Standard
15586 \begin_layout Standard
15587 If the interrupt service routine is defined without
15590 \begin_inset LatexCommand index
15591 name "using (mcs51, ds390 register bank)"
15596 \begin_inset LatexCommand index
15597 name "\\_\\_using (mcs51, ds390 register bank)"
15603 a register bank or with register bank 0 (
15607 0), the compiler will save the registers used by itself on the stack upon
15608 entry and restore them at exit, however if such an interrupt service routine
15609 calls another function then the entire register bank will be saved on the
15611 This scheme may be advantageous for small interrupt service routines which
15612 have low register usage.
15615 \begin_layout Standard
15616 If the interrupt service routine is defined to be using a specific register
15621 & psw are saved and restored, if such an interrupt service routine calls
15622 another function (using another register bank) then the entire register
15623 bank of the called function will be saved on the stack
15624 \begin_inset LatexCommand index
15630 This scheme is recommended for larger interrupt service routines.
15631 \begin_inset VSpace bigskip
15637 \begin_layout Subsection
15639 \begin_inset LatexCommand index
15644 Interrupt Service Routines
15647 \begin_layout Standard
15648 Since the number of interrupts
15649 \begin_inset LatexCommand index
15650 name "HC08!interrupt"
15654 available is chip specific and the interrupt vector table always ends at
15655 the last byte of memory, the interrupt numbers corresponds to the interrupt
15656 vectors in reverse order of address.
15657 For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
15658 2 will use the interrupt vector at 0xfffa, and so on.
15659 However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
15660 this way; instead see section
15661 \begin_inset LatexCommand ref
15662 reference "sub:Startup-Code"
15666 for details on customizing startup.
15667 \begin_inset VSpace bigskip
15673 \begin_layout Subsection
15674 Z80 Interrupt Service Routines
15677 \begin_layout Standard
15679 \begin_inset LatexCommand index
15684 uses several different methods for determining the correct interrupt
15685 \begin_inset LatexCommand index
15686 name "Z80!interrupt"
15690 vector depending on the hardware implementation.
15691 Therefore, SDCC ignores the optional interrupt number and does not attempt
15692 to generate an interrupt vector table.
15695 \begin_layout Standard
15696 By default, SDCC generates code for a maskable interrupt, which uses a RETI
15697 instruction to return from the interrupt.
15698 To write an interrupt handler for the non-maskable interrupt, which needs
15699 a RETN instruction instead, add the
15706 \begin_layout Verse
15709 void nmi_isr (void) critical interrupt
15723 \begin_layout Standard
15724 However if you need to create a non-interruptable interrupt service routine
15725 you would also require the
15730 To distinguish between this and an nmi_isr you must provide an interrupt
15732 \begin_inset VSpace bigskip
15738 \begin_layout Section
15739 Enabling and Disabling Interrupts
15742 \begin_layout Subsection
15743 Critical Functions and Critical Statements
15746 \begin_layout Standard
15747 A special keyword may be associated with a block or a function declaring
15753 SDCC will generate code to disable all interrupts
15754 \begin_inset LatexCommand index
15759 upon entry to a critical function and restore the interrupt enable to the
15760 previous state before returning.
15761 Nesting critical functions will need one additional byte on the stack
15762 \begin_inset LatexCommand index
15770 \begin_layout Verse
15773 int foo () __critical
15774 \begin_inset LatexCommand index
15780 \begin_inset LatexCommand index
15781 name "\\_\\_critical"
15806 \begin_layout Standard
15807 The critical attribute maybe used with other attributes like
15817 may also be used to disable interrupts more locally:
15820 \begin_layout Verse
15826 \begin_layout Standard
15827 More than one statement could have been included in the block.
15830 \begin_layout Subsection
15831 Enabling and Disabling Interrupts directly
15834 \begin_layout Standard
15836 \begin_inset LatexCommand index
15841 can also be disabled and enabled directly (8051):
15844 \begin_layout Verse
15847 EA = 0;\InsetSpace ~
15873 \begin_layout Verse
15909 \begin_layout Verse
15912 EA = 1;\InsetSpace ~
15941 \begin_layout Verse
15980 \begin_layout Standard
15981 On other architectures which have separate opcodes for enabling and disabling
15982 interrupts you might want to make use of defines with inline assembly
15983 \begin_inset LatexCommand index
15984 name "Assembler routines"
15989 \begin_inset LatexCommand index
15990 name "HC08!interrupt"
15997 \begin_layout Verse
16001 \begin_inset LatexCommand index
16011 \begin_inset LatexCommand index
16019 \begin_layout Verse
16022 #define SEI _asm\InsetSpace ~
16029 \begin_layout Verse
16035 \begin_layout Standard
16036 Note: it is sometimes sufficient to disable only a specific interrupt source
16038 a timer or serial interrupt by manipulating an
16041 \begin_inset LatexCommand index
16042 name "interrupt mask"
16052 \begin_layout Standard
16053 Usually the time during which interrupts are disabled should be kept as
16055 This minimizes both
16060 \begin_inset LatexCommand index
16061 name "interrupt latency"
16065 (the time between the occurrence of the interrupt and the execution of
16066 the first code in the interrupt routine) and
16071 \begin_inset LatexCommand index
16072 name "interrupt jitter"
16076 (the difference between the shortest and the longest interrupt latency).
16077 These really are something different, f.e.
16078 a serial interrupt has to be served before its buffer overruns so it cares
16079 for the maximum interrupt latency, whereas it does not care about jitter.
16080 On a loudspeaker driven via a digital to analog converter which is fed
16081 by an interrupt a latency of a few milliseconds might be tolerable, whereas
16082 a much smaller jitter will be very audible.
16085 \begin_layout Standard
16086 You can reenable interrupts within an interrupt routine and on some architecture
16087 s you can make use of two (or more) levels of
16089 interrupt priorities
16092 \begin_inset LatexCommand index
16093 name "interrupt priority"
16098 On some architectures which don't support interrupt priorities these can
16099 be implemented by manipulating the interrupt mask and reenabling interrupts
16100 within the interrupt routine.
16101 Check there is sufficient space on the stack
16102 \begin_inset LatexCommand index
16107 and don't add complexity unless you have to.
16111 \begin_layout Subsection
16113 \begin_inset LatexCommand index
16118 locking (mcs51/ds390)
16121 \begin_layout Standard
16122 Some architectures (mcs51/ds390) have an atomic
16123 \begin_inset LatexCommand index
16128 bit test and clear instruction.
16129 These type of instructions are typically used in preemptive multitasking
16130 systems, where a routine f.e.
16131 claims the use of a data structure ('acquires a lock
16132 \begin_inset LatexCommand index
16137 on it'), makes some modifications and then releases the lock when the data
16138 structure is consistent again.
16139 The instruction may also be used if interrupt and non-interrupt code have
16140 to compete for a resource.
16141 With the atomic bit test and clear instruction interrupts
16142 \begin_inset LatexCommand index
16147 don't have to be disabled for the locking operation.
16151 \begin_layout Standard
16152 SDCC generates this instruction if the source follows this pattern:
16155 \begin_layout Verse
16159 \begin_inset LatexCommand index
16164 bit resource_is_free;
16168 if (resource_is_free)
16178 resource_is_free=0;
16191 resource_is_free=1;
16198 \begin_layout Standard
16199 Note, mcs51 and ds390 support only an atomic
16200 \begin_inset LatexCommand index
16209 instruction (as opposed to atomic bit test and
16214 \begin_layout Section
16215 Functions using private register banks
16216 \begin_inset LatexCommand label
16217 name "sub:Functions-using-private-banks"
16224 \begin_layout Standard
16225 Some architectures have support for quickly changing register sets.
16226 SDCC supports this feature with the
16229 \begin_inset LatexCommand index
16230 name "using (mcs51, ds390 register bank)"
16235 \begin_inset LatexCommand index
16236 name "\\_\\_using (mcs51, ds390 register bank)"
16242 attribute (which tells the compiler to use a register bank
16243 \begin_inset LatexCommand index
16244 name "register bank (mcs51, ds390)"
16248 other than the default bank zero).
16249 It should only be applied to
16252 \begin_inset LatexCommand index
16259 functions (see footnote below).
16260 This will in most circumstances make the generated ISR code more efficient
16261 since it will not have to save registers on the stack.
16264 \begin_layout Standard
16269 attribute will have no effect on the generated code for a
16273 function (but may occasionally be useful anyway
16277 \begin_layout Standard
16278 possible exception: if a function is called ONLY from 'interrupt' functions
16279 using a particular bank, it can be declared with the same 'using' attribute
16280 as the calling 'interrupt' functions.
16281 For instance, if you have several ISRs using bank one, and all of them
16282 call memcpy(), it might make sense to create a specialized version of memcpy()
16283 'using 1', since this would prevent the ISR from having to save bank zero
16284 to the stack on entry and switch to bank zero before calling the function
16293 (pending: Note, nowadays the
16297 attribute has an effect on
16301 the generated code for a
16312 \begin_layout Standard
16317 function using a non-zero bank will assume that it can trash that register
16318 bank, and will not save it.
16319 Since high-priority interrupts
16320 \begin_inset LatexCommand index
16326 \begin_inset LatexCommand index
16327 name "interrupt priority"
16331 can interrupt low-priority ones on the 8051 and friends, this means that
16332 if a high-priority ISR
16336 a particular bank occurs while processing a low-priority ISR
16340 the same bank, terrible and bad things can happen.
16341 To prevent this, no single register bank should be
16345 by both a high priority and a low priority ISR.
16346 This is probably most easily done by having all high priority ISRs use
16347 one bank and all low priority ISRs use another.
16348 If you have an ISR which can change priority at runtime, you're on your
16349 own: I suggest using the default bank zero and taking the small performance
16353 \begin_layout Standard
16354 It is most efficient if your ISR calls no other functions.
16355 If your ISR must call other functions, it is most efficient if those functions
16356 use the same bank as the ISR (see note 1 below); the next best is if the
16357 called functions use bank zero.
16358 It is very inefficient to call a function using a different, non-zero bank
16361 \begin_inset VSpace bigskip
16367 \begin_layout Section
16369 \begin_inset LatexCommand label
16370 name "sub:Startup-Code"
16375 \begin_inset LatexCommand index
16376 name "Startup code"
16383 \begin_layout Subsection
16384 MCS51/DS390 Startup Code
16387 \begin_layout Standard
16388 The compiler triggers the linker to link certain initialization modules
16389 from the runtime library
16390 \begin_inset LatexCommand index
16391 name "Runtime library"
16395 called crt<something>.
16396 Only the necessary ones are linked, for instance crtxstack.asm (GSINIT1,
16397 GSINIT5) is not linked unless the -
16403 \begin_layout Standard
16414 -xstack option is used.
16415 These modules are highly entangled by the use of special segments/areas,
16416 but a common layout is shown below:
16419 \begin_layout Verse
16427 \begin_layout Verse
16451 ljmp __sdcc_gsinit_startup
16454 \begin_layout Verse
16462 \begin_layout Verse
16474 .area GSINIT0 (CODE)
16476 __sdcc_gsinit_startup::
16486 mov sp,#__start__stack - 1
16489 \begin_layout Verse
16497 \begin_layout Verse
16509 .area GSINIT1 (CODE)
16511 __sdcc_init_xstack::
16513 ; Need to initialize in GSINIT1 in
16514 case the user's __sdcc_external_startup uses the xstack.
16524 mov __XPAGE,#(__start__x
16535 mov _spx,#__start__xstack
16538 \begin_layout Verse
16546 \begin_layout Verse
16558 .area GSINIT2 (CODE)
16568 lcall __sdcc_external_startup
16588 jz __sdcc_init_data
16599 __sdcc_program_startup
16604 \begin_layout Verse
16612 \begin_layout Verse
16624 .area GSINIT3 (CODE)
16677 mov r2,#((l_XINIT+255) >> 8)
16708 __XPAGE,#(s_XISEG >> 8)
16710 00001$:\InsetSpace ~
16774 00002$:\InsetSpace ~
16801 \begin_layout Verse
16809 \begin_layout Verse
16821 .area GSINIT4 (CODE)
16823 __mcs51_genRAMCLEAR::
16845 00004$:\InsetSpace ~
16859 ; _mcs51_genRAMCLEAR() end
16862 \begin_layout Verse
16870 \begin_layout Verse
16882 .area GSINIT4 (CODE)
16884 __mcs51_genXRAMCLEAR::
16945 mov __XPAGE,#(s_PSEG >> 8)
16957 00005$:\InsetSpace ~
17032 mov r1,#((l_XSEG + 255) >> 8)
17054 00007$:\InsetSpace ~
17091 \begin_layout Verse
17099 \begin_layout Verse
17111 .area GSINIT5 (CODE)
17113 ; Need to initialize in GSINIT5 because __mcs51_genXINIT
17116 ; and __mcs51_genRAMCLEAR modifies _spx.
17126 mov __XPAGE,#(__start__x
17137 mov _spx,#__start__xstack
17140 \begin_layout Verse
17145 (application modules)
17148 \begin_layout Verse
17160 .area GSINIT (CODE)
17163 \begin_layout Verse
17171 \begin_layout Verse
17183 .area GSFINAL (CODE)
17193 ljmp __sdcc_program_startup
17195 ;---------------------------------
17196 -----------------------
17200 ;--------------------------------------------------
17223 __sdcc_program_startup:
17236 return from main will lock up
17249 \begin_layout Standard
17250 One of these modules (crtstart.asm) contains a call to the C routine
17252 _sdcc_external_startup()
17253 \begin_inset LatexCommand index
17254 name "\\_sdcc\\_external\\_startup()"
17260 at the start of the CODE area.
17261 This routine is also in the runtime library
17262 \begin_inset LatexCommand index
17263 name "Runtime library"
17267 and returns 0 by default.
17268 If this routine returns a non-zero value, the static & global variable
17269 initialization will be skipped and the function main will be invoked.
17270 Otherwise static & global variables will be initialized before the function
17274 _sdcc_external_startup()
17276 routine to your program to override the default if you need to setup hardware
17277 or perform some other critical operation prior to static & global variable
17279 \begin_inset LatexCommand index
17280 name "Variable initialization"
17285 On some mcs51 variants xdata
17286 \begin_inset LatexCommand index
17287 name "xdata (mcs51, ds390 storage class)"
17291 memory has to be explicitly enabled before it can be accessed or if the
17293 \begin_inset LatexCommand index
17298 needs to be disabled, this is the place to do it.
17299 The startup code clears all internal data memory, 256 bytes by default,
17300 but from 0 to n-1 if
17306 \begin_layout Standard
17316 \begin_inset LatexCommand index
17317 name "-\\/-iram-size <Value>"
17324 (recommended for Chipcon CC1010).
17327 \begin_layout Standard
17328 See also the compiler options
17334 \begin_layout Standard
17350 \begin_inset LatexCommand index
17351 name "-\\/-no-xinit-opt"
17361 \begin_layout Standard
17373 \begin_inset LatexCommand index
17374 name "-\\/-main-return"
17379 \begin_inset LatexCommand ref
17380 reference "sub:MCS51-variants"
17384 about MCS51-variants.
17389 \begin_layout Standard
17390 While these initialization modules are meant as generic startup code there
17391 might be the need for customization.
17392 Let's assume the return value of
17394 _sdcc_external_startup()
17400 should not be checked (or
17402 _sdcc_external_startup()
17404 should not be called at all).
17405 The recommended way would be to copy
17411 \begin_inset LatexCommand url
17412 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/device/lib/mcs51/crtstart.asm"
17416 ) into the source directory, adapt it there, then assemble it with
17422 \begin_layout Standard
17423 \begin_inset Quotes sld
17427 \begin_inset Quotes srd
17430 are the assembler options used in
17431 \begin_inset LatexCommand url
17432 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/lib/mcs51/Makefile.in?view=markup "
17443 and when linking your project explicitly specify
17448 As a bonus a listing of the relocated object file
17455 \begin_layout Standard
17456 \begin_inset VSpace bigskip
17462 \begin_layout Subsection
17466 \begin_layout Standard
17468 \begin_inset LatexCommand index
17473 startup code follows the same scheme as the MCS51 startup code.
17474 \begin_inset VSpace bigskip
17480 \begin_layout Subsection
17484 \begin_layout Standard
17486 \begin_inset LatexCommand index
17491 the startup code is inserted by linking with crt0.o which is generated from
17492 sdcc/device/lib/z80/crt0.s.
17493 If you need a different startup code you can use the compiler option
17502 \begin_layout Standard
17517 \begin_inset LatexCommand index
17518 name "-\\/-no-std-crt0"
17522 and provide your own crt0.o.
17524 \begin_inset VSpace bigskip
17530 \begin_layout Section
17531 Inline Assembler Code
17532 \begin_inset LatexCommand index
17533 name "Assembler routines"
17540 \begin_layout Subsection
17541 A Step by Step Introduction
17542 \begin_inset LatexCommand label
17543 name "sub:A-Step-by Assembler Introduction"
17550 \begin_layout Standard
17551 Starting from a small snippet of c-code this example shows for the MCS51
17552 how to use inline assembly, access variables, a function parameter and
17553 an array in xdata memory.
17554 The example uses an MCS51 here but is easily adapted for other architectures.
17555 This is a buffer routine which should be optimized:
17558 \begin_layout Verse
17562 unsigned char __far
17563 \begin_inset LatexCommand index
17564 name "far (storage class)"
17569 \begin_inset LatexCommand index
17570 name "\\_\\_far (storage class)"
17575 \begin_inset LatexCommand index
17581 \begin_inset LatexCommand index
17586 (0x7f00) buf[0x100];
17587 \begin_inset LatexCommand index
17588 name "Aligned array"
17594 unsigned char head, tail;\InsetSpace ~
17612 \begin_inset LatexCommand index
17665 \begin_inset LatexCommand ref
17666 reference "sub:Common-interrupt-pitfall-volatile"
17684 void to_buffer( unsigned char c )
17692 if( head != (unsigned char)(tail-1)
17705 \begin_inset LatexCommand index
17706 name "promotion to signed int"
17711 \begin_inset LatexCommand index
17712 name "type promotion"
17717 \begin_inset Marginal
17720 \begin_layout Standard
17739 buf[ head++ ] = c;\InsetSpace ~
17755 /* access to a 256 byte aligned array */
17760 \begin_layout Standard
17761 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
17762 then a corresponding buffer.asm file is generated.
17763 We define a new function
17767 in file buffer.c in which we cut and paste the generated code, removing
17768 unwanted comments and some ':'.
17770 \begin_inset Quotes sld
17778 \begin_inset Quotes srd
17782 \begin_inset Quotes sld
17790 \begin_inset Quotes srd
17797 \begin_layout Standard
17798 Note, that the single underscore form (_asm and _endasm) are not C99-compatible,
17799 and for C-99 compatibility, the double-underscore form (__asm and __endasm)
17801 The latter is also used in the library functions.
17806 to the beginning and the end of the function body:
17809 \begin_layout Verse
17813 /* With a cut and paste from the .asm file, we have something to start with.
17819 function is not yet OK! (registers aren't saved) */
17821 void to_buffer_asm(
17831 \begin_inset LatexCommand index
17837 \begin_inset LatexCommand index
17852 ;buffer.c if( head != (unsigned char)(tail-1) ) \InsetSpace ~
17864 \begin_inset LatexCommand index
17865 name "promotion to signed int"
17870 \begin_inset LatexCommand index
17871 name "type promotion"
17924 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
17925 \begin_inset LatexCommand index
17926 name "Aligned array"
17992 \begin_inset LatexCommand index
17998 \begin_inset LatexCommand index
17999 name "\\_\\_endasm"
18008 \begin_layout Standard
18009 The new file buffer.c should compile with only one warning about the unreferenced
18010 function argument 'c'.
18011 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
18012 (1) and finally have:
18015 \begin_layout Verse
18019 unsigned char __far __at(0x7f00) buf[0x100];
18021 unsigned char head, tail;
18032 void to_buffer( unsigned char c )
18041 head != (unsigned char)(tail-1) )
18070 c; // to avoid warning: unreferenced function argument
18077 \begin_inset LatexCommand index
18083 \begin_inset LatexCommand index
18098 ; save used registers here.
18109 ; If we were still using r2,r3 we would have to push them here.
18112 ; if( head != (unsigned char)(tail-1) )
18156 could do an ANL a,#0x0f here to use a smaller buffer (see below)
18192 a,dpl \InsetSpace ~
18199 ; dpl holds lower byte of function argument
18211 dpl,_head \InsetSpace ~
18214 ; buf is 0x100 byte aligned so head can be used directly
18257 ; we could do an ANL _head,#0x0f here to use a
18258 smaller buffer (see above)
18270 ; restore used registers here
18277 \begin_inset LatexCommand index
18283 \begin_inset LatexCommand index
18284 name "\\_\\_endasm"
18295 \begin_layout Standard
18296 The inline assembler code can contain any valid code understood by the assembler
18297 , this includes any assembler directives and comment lines.
18298 The assembler does not like some characters like ':' or ''' in comments.
18299 You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
18300 \begin_inset LatexCommand index
18301 name "asXXXX (as-gbz80, as-hc08, asx8051, as-z80)"
18306 \begin_inset LatexCommand index
18307 name "Assembler documentation"
18312 \begin_inset LatexCommand url
18313 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html"
18321 \begin_layout Standard
18322 The compiler does not do any validation of the code within the
18325 \begin_inset LatexCommand index
18331 \begin_inset LatexCommand index
18340 \begin_inset LatexCommand index
18346 \begin_inset LatexCommand index
18347 name "\\_\\_endasm"
18356 Specifically it will not know which registers are used and thus register
18358 \begin_inset LatexCommand index
18363 has to be done manually.
18367 \begin_layout Standard
18368 It is recommended that each assembly instruction (including labels) be placed
18369 in a separate line (as the example shows).
18374 \begin_layout Standard
18386 \begin_inset LatexCommand index
18387 name "-\\/-peep-asm"
18393 command line option is used, the inline assembler code will be passed through
18394 the peephole optimizer
18395 \begin_inset LatexCommand index
18396 name "Peephole optimizer"
18401 There are only a few (if any) cases where this option makes sense, it might
18402 cause some unexpected changes in the inline assembler code.
18403 Please go through the peephole optimizer rules defined in file
18407 before using this option.
18410 \begin_layout Subsection
18412 \begin_inset LatexCommand label
18413 name "sub:Naked-Functions"
18418 \begin_inset LatexCommand index
18419 name "Naked functions"
18426 \begin_layout Standard
18427 A special keyword may be associated with a function declaring it as
18430 \begin_inset LatexCommand index
18436 \begin_inset LatexCommand index
18448 function modifier attribute prevents the compiler from generating prologue
18449 \begin_inset LatexCommand index
18450 name "function prologue"
18455 \begin_inset LatexCommand index
18456 name "function epilogue"
18460 code for that function.
18461 This means that the user is entirely responsible for such things as saving
18462 any registers that may need to be preserved, selecting the proper register
18463 bank, generating the
18467 instruction at the end, etc.
18468 Practically, this means that the contents of the function must be written
18469 in inline assembler.
18470 This is particularly useful for interrupt functions, which can have a large
18471 (and often unnecessary) prologue/epilogue.
18472 For example, compare the code generated by these two functions:
18475 \begin_layout Verse
18479 \begin_inset LatexCommand index
18484 data unsigned char counter;
18488 void simpleInterrupt(void) __interrupt
18489 \begin_inset LatexCommand index
18495 \begin_inset LatexCommand index
18496 name "\\_\\_interrupt"
18514 void nakedInterrupt(void) __interrupt (2) __naked
18523 \begin_inset LatexCommand index
18529 \begin_inset LatexCommand index
18547 _counter ; does not change flags, no need to save psw
18560 include ret or reti in _naked function.
18567 \begin_inset LatexCommand index
18573 \begin_inset LatexCommand index
18574 name "\\_\\_endasm"
18583 \begin_layout Standard
18584 For an 8051 target, the generated simpleInterrupt looks like:
18587 \begin_layout Verse
18600 example, recent versions of SDCC generate
18612 code for simpleInterrupt() and nakedInterrupt()!
18753 \begin_layout Standard
18754 whereas nakedInterrupt looks like:
18757 \begin_layout Verse
18770 _counter ; does not change flags, no need to save psw
18789 MUST explicitly include ret or reti in _naked function
18792 \begin_layout Standard
18793 The related directive #pragma exclude
18794 \begin_inset LatexCommand index
18795 name "\\#pragma exclude"
18799 allows a more fine grained control over pushing & popping
18800 \begin_inset LatexCommand index
18808 \begin_layout Standard
18809 While there is nothing preventing you from writing C code inside a
18813 function, there are many ways to shoot yourself in the foot doing this,
18814 and it is recommended that you stick to inline assembler.
18817 \begin_layout Subsection
18818 Use of Labels within Inline Assembler
18821 \begin_layout Standard
18822 SDCC allows the use of in-line assembler with a few restrictions regarding
18824 All labels defined within inline assembler code have to be of the form
18829 where nnnnn is a number less than 100 (which implies a limit of utmost
18830 100 inline assembler labels
18841 \begin_layout Standard
18842 This is a slightly more stringent rule than absolutely necessary, but stays
18843 always on the safe side.
18844 Labels in the form of nnnnn$ are local labels in the assembler, locality
18845 of which is confined within two labels of the standard form.
18846 The compiler uses the same form for labels within a function (but starting
18847 from nnnnn=00100); and places always a standard label at the beginning
18848 of a function, thus limiting the locality of labels within the scope of
18850 So, if the inline assembler part would be embedded into C-code, an improperly
18851 placed non-local label in the assembler would break up the reference space
18852 for labels created by the compiler for the C-code, leading to an assembling
18856 \begin_layout Standard
18857 The numeric part of local labels does not need to have 5 digits (although
18858 this is the form of labels output by the compiler), any valid integer will
18860 Please refer to the assemblers documentation for further details.
18868 \begin_layout Verse
18872 \begin_inset LatexCommand index
18878 \begin_inset LatexCommand index
18909 \begin_inset LatexCommand index
18915 \begin_inset LatexCommand index
18916 name "\\_\\_endasm"
18923 \begin_layout Standard
18924 Inline assembler code cannot reference any C-labels, however it can reference
18926 \begin_inset LatexCommand index
18931 defined by the inline assembler, e.g.:
18934 \begin_layout Verse
18957 ; some assembler code
18978 /* some more c code */
18980 clabel:\InsetSpace ~
18982 /* inline assembler cannot reference this
18987 \begin_layout Standard
18992 is translated by the compiler into a local label, so the locality of labels
18993 within the function is not broken.
19010 0003$: ;label (can be referenced by inline assembler only)
19017 \begin_inset LatexCommand index
19023 \begin_inset LatexCommand index
19024 name "\\_\\_endasm"
19034 /* some more c code */
19039 \begin_layout Standard
19040 In other words inline assembly code can access labels defined in inline
19041 assembly within the scope of the function.
19042 The same goes the other way, i.e.
19043 labels defines in inline assembly can not be accessed by C statements.
19046 \begin_layout Section
19047 Interfacing with Assembler Code
19048 \begin_inset LatexCommand index
19049 name "Assembler routines"
19056 \begin_layout Subsection
19057 Global Registers used for Parameter Passing
19058 \begin_inset LatexCommand index
19059 name "Parameter passing"
19066 \begin_layout Standard
19067 The compiler always uses the global registers
19070 \begin_inset LatexCommand index
19071 name "DPTR, DPH, DPL"
19076 \begin_inset LatexCommand index
19082 \begin_inset LatexCommand index
19083 name "B (mcs51, ds390 register)"
19092 \begin_inset LatexCommand index
19093 name "ACC (mcs51, ds390 register)"
19099 to pass the first (non-bit) parameter to a function, and also to pass the
19101 \begin_inset LatexCommand index
19102 name "return value"
19106 of function; according to the following scheme: one byte return value in
19111 , two byte value in
19120 three byte values (generic pointers) in
19132 , and four byte values in
19150 \begin_inset LatexCommand index
19151 name "generic pointer"
19155 contain type of accessed memory in
19176 \begin_inset Note Note
19179 \begin_layout Standard
19180 This might not be the case of certain memory models (medium???)
19188 \begin_layout Standard
19189 The second parameter onwards is either allocated on the stack (for reentrant
19194 \begin_layout Standard
19203 -stack-auto is used) or in data/xdata memory (depending on the memory model).
19206 \begin_layout Standard
19207 Bit parameters are passed in a virtual register called 'bits' in bit-addressable
19208 space for reentrant functions or allocated directly in bit memory otherwise.
19211 \begin_layout Standard
19212 Functions (with two or more parameters or bit parameters) that are called
19213 through function pointers
19214 \begin_inset LatexCommand index
19215 name "function pointers"
19219 must therefor be reentrant so the compiler knows how to pass the parameters.
19222 \begin_layout Subsection
19226 \begin_layout Standard
19227 Unless the called function is declared as
19232 \begin_inset LatexCommand index
19241 \begin_layout Standard
19251 \begin_inset LatexCommand index
19252 name "-\\/-callee-saves"
19260 \begin_layout Standard
19269 -all-callee-saves command line option or the corresponding callee_saves
19270 pragma are used, the caller will save the registers (
19274 ) around the call, so the called function can destroy they content freely.
19277 \begin_layout Standard
19278 If the called function is not declared as
19282 , the caller will swap register banks around the call, if caller and callee
19283 use different register banks (having them defined by the
19291 \begin_layout Standard
19292 The called function can also use
19308 observing that they are used for parameter/return value passing.
19311 \begin_layout Subsection
19312 Assembler Routine (non-reentrant)
19315 \begin_layout Standard
19316 In the following example
19317 \begin_inset LatexCommand index
19323 \begin_inset LatexCommand index
19324 name "Assembler routines (non-reentrant)"
19328 the function c_func calls an assembler routine asm_func, which takes two
19330 \begin_inset LatexCommand index
19331 name "function parameter"
19338 \begin_layout Verse
19341 extern int asm_func(unsigned char, unsigned char);
19345 int c_func (unsigned char
19346 i, unsigned char j)
19354 return asm_func(i,j);
19368 return c_func(10,9);
19373 \begin_layout Standard
19374 The corresponding assembler function is:
19377 \begin_layout Verse
19380 .globl _asm_func_PARM_2
19482 \begin_inset LatexCommand index
19483 name "DPTR, DPH, DPL"
19500 \begin_layout Standard
19501 The parameter naming convention is _<function_name>_PARM_<n>, where n is
19502 the parameter number starting from 1, and counting from the left.
19503 The first parameter is passed in
19519 according to the description above.
19520 The variable name for the second parameter will be _<function_name>_PARM_2.
19525 ble the assembler routine with the following command:
19532 asx8051 -losg asmfunc.asm
19539 Then compile and link the assembler routine to the C source file with the
19547 sdcc cfunc.c asmfunc.rel
19550 \begin_layout Subsection
19551 Assembler Routine (reentrant)
19554 \begin_layout Standard
19556 \begin_inset LatexCommand index
19562 \begin_inset LatexCommand index
19563 name "Assembler routines (reentrant)"
19567 the second parameter
19568 \begin_inset LatexCommand index
19569 name "function parameter"
19573 onwards will be passed on the stack, the parameters are pushed from right
19575 before the call the second leftmost parameter will be on the top of the
19576 stack (the leftmost parameter is passed in registers).
19577 Here is an example:
19580 \begin_layout Verse
19583 extern int asm_func(unsigned char, unsigned char, unsigned char) reentrant;
19588 c_func (unsigned char i, unsigned char j, unsigned char k) reentrant
19597 return asm_func(i,j,k);
19611 return c_func(10,9,8);
19616 \begin_layout Standard
19617 The corresponding (unoptimized) assembler routine is:
19620 \begin_layout Verse
19640 _bp,sp\InsetSpace ~
19646 ;stack contains: _bp, return
19647 address, second parameter, third parameter
19671 a,#0xfd\InsetSpace ~
19677 pointer to the second parameter
19701 a,#0xfc\InsetSpace ~
19707 to the rightmost parameter
19748 result (= sum of all three parameters)
19763 ;return value goes into dptr
19797 \begin_layout Standard
19798 The compiling and linking procedure remains the same, however note the extra
19799 entry & exit linkage required for the assembler code, _bp is the stack
19800 frame pointer and is used to compute the offset into the stack for parameters
19801 and local variables.
19802 \begin_inset VSpace bigskip
19808 \begin_layout Section
19810 \begin_inset LatexCommand index
19811 name "int (16 bit)"
19816 \begin_inset LatexCommand index
19817 name "long (32 bit)"
19824 \begin_layout Standard
19825 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
19826 multiplication and modulus operations are implemented by support routines.
19827 These support routines are all developed in ANSI-C to facilitate porting
19828 to other MCUs, although some model specific assembler optimizations are
19830 The following files contain the described routines, all of them can be
19831 found in <installdir>/share/sdcc/lib.
19836 \begin_layout Standard
19838 \begin_inset Tabular
19839 <lyxtabular version="3" rows="11" columns="2">
19841 <column alignment="left" valignment="top" leftline="true" width="0">
19842 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
19843 <row topline="true" bottomline="true">
19844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19847 \begin_layout Standard
19855 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19858 \begin_layout Standard
19867 <row topline="true">
19868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19871 \begin_layout Standard
19877 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19880 \begin_layout Standard
19881 16 bit multiplication
19887 <row topline="true">
19888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19891 \begin_layout Standard
19897 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19900 \begin_layout Standard
19901 signed 16 bit division (calls _divuint)
19907 <row topline="true">
19908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19911 \begin_layout Standard
19917 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19920 \begin_layout Standard
19921 unsigned 16 bit division
19927 <row topline="true">
19928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19931 \begin_layout Standard
19937 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19940 \begin_layout Standard
19941 signed 16 bit modulus (calls _moduint)
19947 <row topline="true">
19948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19951 \begin_layout Standard
19957 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19960 \begin_layout Standard
19961 unsigned 16 bit modulus
19967 <row topline="true">
19968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19971 \begin_layout Standard
19977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
19980 \begin_layout Standard
19981 32 bit multiplication
19987 <row topline="true">
19988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
19991 \begin_layout Standard
19997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20000 \begin_layout Standard
20001 signed 32 division (calls _divulong)
20007 <row topline="true">
20008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20011 \begin_layout Standard
20017 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20020 \begin_layout Standard
20021 unsigned 32 division
20027 <row topline="true">
20028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20031 \begin_layout Standard
20037 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20040 \begin_layout Standard
20041 signed 32 bit modulus (calls _modulong)
20047 <row topline="true" bottomline="true">
20048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20051 \begin_layout Standard
20057 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20060 \begin_layout Standard
20061 unsigned 32 bit modulus
20076 \begin_layout Standard
20077 Since they are compiled as
20082 \begin_inset LatexCommand index
20088 \begin_inset LatexCommand index
20093 service routines should not do any of the above operations.
20094 If this is unavoidable then the above routines will need to be compiled
20101 \begin_layout Standard
20111 \begin_inset LatexCommand index
20112 name "-\\/-stack-auto"
20118 option, after which the source program will have to be compiled with
20124 \begin_layout Standard
20134 \begin_inset LatexCommand index
20135 name "-\\/-int-long-reent"
20142 Notice that you don't have to call these routines directly.
20143 The compiler will use them automatically every time an integer operation
20147 \begin_layout Section
20148 Floating Point Support
20149 \begin_inset LatexCommand index
20150 name "Floating point support"
20157 \begin_layout Standard
20158 SDCC supports IEEE (single precision 4 bytes) floating point numbers.
20159 The floating point support routines are derived from gcc's floatlib.c and
20160 consist of the following routines:
20165 \begin_layout Standard
20169 \begin_inset Tabular
20170 <lyxtabular version="3" rows="17" columns="2">
20172 <column alignment="left" valignment="top" leftline="true" width="0">
20173 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
20174 <row topline="true" bottomline="true">
20175 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20178 \begin_layout Standard
20193 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20196 \begin_layout Standard
20203 <row topline="true">
20204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20207 \begin_layout Standard
20222 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20225 \begin_layout Standard
20235 add floating point numbers
20241 <row topline="true">
20242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20245 \begin_layout Standard
20260 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20263 \begin_layout Standard
20273 subtract floating point numbers
20279 <row topline="true">
20280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20283 \begin_layout Standard
20298 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20301 \begin_layout Standard
20311 divide floating point numbers
20317 <row topline="true">
20318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20321 \begin_layout Standard
20336 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20339 \begin_layout Standard
20349 multiply floating point numbers
20355 <row topline="true">
20356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20359 \begin_layout Standard
20374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20377 \begin_layout Standard
20387 convert floating point to unsigned char
20393 <row topline="true">
20394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20397 \begin_layout Standard
20412 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20415 \begin_layout Standard
20425 convert floating point to signed char
20431 <row topline="true">
20432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20435 \begin_layout Standard
20450 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20453 \begin_layout Standard
20463 convert floating point to unsigned int
20469 <row topline="true">
20470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20473 \begin_layout Standard
20488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20491 \begin_layout Standard
20501 convert floating point to signed int
20507 <row topline="true">
20508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20511 \begin_layout Standard
20534 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20537 \begin_layout Standard
20547 convert floating point to unsigned long
20553 <row topline="true">
20554 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20557 \begin_layout Standard
20572 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20575 \begin_layout Standard
20585 convert floating point to signed long
20591 <row topline="true">
20592 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20595 \begin_layout Standard
20610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20613 \begin_layout Standard
20623 convert unsigned char to floating point
20629 <row topline="true">
20630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20633 \begin_layout Standard
20648 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20651 \begin_layout Standard
20661 convert char to floating point number
20667 <row topline="true">
20668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20671 \begin_layout Standard
20686 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20689 \begin_layout Standard
20699 convert unsigned int to floating point
20705 <row topline="true">
20706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20709 \begin_layout Standard
20724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20727 \begin_layout Standard
20737 convert int to floating point numbers
20743 <row topline="true">
20744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20747 \begin_layout Standard
20762 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20765 \begin_layout Standard
20775 convert unsigned long to floating point number
20781 <row topline="true" bottomline="true">
20782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
20785 \begin_layout Standard
20800 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
20803 \begin_layout Standard
20813 convert long to floating point number
20828 \begin_layout Standard
20829 These support routines are developed in ANSI-C so there is room for space
20830 and speed improvement
20834 \begin_layout Standard
20835 These floating point routines (
20839 sinf(), cosf(), ...) for the mcs51 are implemented in assembler.
20846 Note if all these routines are used simultaneously the data space might
20848 For serious floating point usage the large model might be needed.
20849 Also notice that you don't have to call this routines directly.
20850 The compiler will use them automatically every time a floating point operation
20852 \begin_inset VSpace bigskip
20858 \begin_layout Section
20860 \begin_inset LatexCommand index
20868 \begin_layout Standard
20871 <pending: this is messy and incomplete - a little more information is in
20872 sdcc/doc/libdoc.txt
20877 \begin_layout Subsection
20878 Compiler support routines (_gptrget, _mulint etc.)
20881 \begin_layout Subsection
20882 Stdclib functions (puts, printf, strcat etc.)
20885 \begin_layout Subsubsection
20889 \begin_layout Paragraph
20890 getchar(), putchar()
20893 \begin_layout Standard
20894 \begin_inset LatexCommand index
20899 As usual on embedded systems you have to provide your own
20902 \begin_inset LatexCommand index
20912 \begin_inset LatexCommand index
20920 SDCC does not know whether the system connects to a serial line with or
20921 without handshake, LCD, keyboard or other device.
20935 You'll find examples for serial routines f.e.
20936 in sdcc/device/lib.
20937 For the mcs51 this minimalistic polling
20941 routine might be a start:
20944 \begin_layout Verse
20947 void putchar (char c) {
20953 while (!TI)\InsetSpace ~
20956 /* assumes UART is initialized */
20984 \begin_layout Paragraph
20988 \begin_layout Standard
20992 \begin_inset LatexCommand index
21003 does not support float (except on ds390).
21004 To enable this, recompile it with the option
21010 \begin_layout Standard
21020 \begin_inset LatexCommand index
21021 name "USE\\_FLOATS"
21027 on the command line.
21034 \begin_layout Standard
21044 \begin_inset LatexCommand index
21045 name "-\\/-model-large"
21051 for the mcs51 port, since this uses a lot of memory.
21052 To enable float support for the pic16 targets, see
21053 \begin_inset LatexCommand ref
21054 reference "sub:pic16Libraries"
21061 \begin_layout Standard
21062 If you're short on code memory you might want to use
21065 \begin_inset LatexCommand index
21066 name "printf\\_small()"
21081 For the mcs51 there additionally are assembly versions
21084 \begin_inset LatexCommand index
21085 name "printf\\_tiny() (mcs51)"
21091 (subset of printf using less than 270 bytes) and
21094 \begin_inset LatexCommand index
21095 name "printf\\_fast() (mcs51)"
21104 \begin_inset LatexCommand index
21105 name "printf\\_fast\\_f() (mcs51)"
21111 (floating-point aware version of printf_fast) which should fit the requirements
21112 of many embedded systems (printf_fast() can be customized by unsetting
21117 support long variables and field widths).
21118 Be sure to use only one of these printf options within a project.
21123 \begin_layout Standard
21124 Feature matrix of different
21131 \begin_layout Standard
21132 \begin_inset Tabular
21133 <lyxtabular version="3" rows="14" columns="7">
21134 <features islongtable="true">
21135 <column alignment="left" valignment="middle" leftline="true" width="14col%">
21136 <column alignment="center" valignment="top" leftline="true" width="0">
21137 <column alignment="center" valignment="top" leftline="true" width="12col%">
21138 <column alignment="center" valignment="top" leftline="true" width="10col%">
21139 <column alignment="center" valignment="top" leftline="true" width="0">
21140 <column alignment="center" valignment="top" leftline="true" rightline="true" width="12col%">
21141 <column alignment="center" valignment="top" rightline="true" width="0">
21142 <row topline="true" bottomline="true" endhead="true">
21143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21146 \begin_layout Standard
21155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21158 \begin_layout Standard
21160 \begin_inset LatexCommand index
21170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21173 \begin_layout Standard
21181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21184 \begin_layout Standard
21190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21193 \begin_layout Standard
21199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21202 \begin_layout Standard
21208 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21211 \begin_layout Standard
21218 <row topline="true" endhead="true">
21219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21222 \begin_layout Standard
21228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21231 \begin_layout Standard
21239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21242 \begin_layout Standard
21250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21253 \begin_layout Standard
21261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21264 \begin_layout Standard
21272 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21275 \begin_layout Standard
21283 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21286 \begin_layout Standard
21295 <row topline="true" endhead="true">
21296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21299 \begin_layout Standard
21300 \begin_inset Quotes sld
21304 \begin_inset Quotes srd
21310 \begin_layout Standard
21316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21319 \begin_layout Standard
21325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21328 \begin_layout Standard
21334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21337 \begin_layout Standard
21343 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21346 \begin_layout Standard
21352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21355 \begin_layout Standard
21361 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21364 \begin_layout Standard
21371 <row topline="true" endhead="true">
21372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21375 \begin_layout Standard
21379 \begin_layout Standard
21385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21388 \begin_layout Standard
21394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21397 \begin_layout Standard
21403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21406 \begin_layout Standard
21407 0.45k / 0.47k (+ _ltoa)
21412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21415 \begin_layout Standard
21421 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21424 \begin_layout Standard
21430 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21433 \begin_layout Standard
21440 <row topline="true">
21441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21444 \begin_layout Standard
21450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21453 \begin_layout Standard
21463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21466 \begin_layout Standard
21513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21516 \begin_layout Standard
21555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21558 \begin_layout Standard
21564 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21567 \begin_layout Standard
21573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21576 \begin_layout Standard
21583 <row topline="true">
21584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21587 \begin_layout Standard
21588 long (32 bit) support
21593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21596 \begin_layout Standard
21602 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21605 \begin_layout Standard
21611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21614 \begin_layout Standard
21620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21623 \begin_layout Standard
21629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21632 \begin_layout Standard
21647 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21650 \begin_layout Standard
21657 <row topline="true">
21658 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21661 \begin_layout Standard
21662 byte arguments on stack
21667 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21670 \begin_layout Standard
21676 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21679 \begin_layout Standard
21685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21688 \begin_layout Standard
21694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21697 \begin_layout Standard
21703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21706 \begin_layout Standard
21712 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21715 \begin_layout Standard
21722 <row topline="true">
21723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21726 \begin_layout Standard
21728 \begin_inset LatexCommand index
21729 name "Floating point support"
21738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21741 \begin_layout Standard
21747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21750 \begin_layout Standard
21756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21759 \begin_layout Standard
21765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21768 \begin_layout Standard
21774 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21777 \begin_layout Standard
21782 \begin_layout Standard
21783 Range limited to +/- 4294967040, precision limited to 8 digits past decimal
21793 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21796 \begin_layout Standard
21803 <row topline="true">
21804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21807 \begin_layout Standard
21808 float formats %e %g
21813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21816 \begin_layout Standard
21822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21825 \begin_layout Standard
21831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21834 \begin_layout Standard
21840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21843 \begin_layout Standard
21849 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21852 \begin_layout Standard
21858 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21861 \begin_layout Standard
21868 <row topline="true" bottomline="true">
21869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21872 \begin_layout Standard
21878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21881 \begin_layout Standard
21887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21890 \begin_layout Standard
21896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21899 \begin_layout Standard
21905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21908 \begin_layout Standard
21914 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21917 \begin_layout Standard
21923 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
21926 \begin_layout Standard
21933 <row bottomline="true">
21934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21937 \begin_layout Standard
21942 \begin_layout Standard
21943 Execution time of printf("%s%c%s%c%c%c", "Hello", ' ', "World", '!', '
21947 n'); standard 8051 @ 22.1184 MHz, empty putchar()
21955 \begin_layout Standard
21961 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21964 \begin_layout Standard
21970 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21973 \begin_layout Standard
21979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21982 \begin_layout Standard
21988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
21991 \begin_layout Standard
21997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22000 \begin_layout Standard
22006 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22009 \begin_layout Standard
22016 <row bottomline="true">
22017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22020 \begin_layout Standard
22025 \begin_layout Standard
22026 Execution time of printf("%d", -12345); standard 8051 @ 22.1184 MHz, empty
22035 \begin_layout Standard
22041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22044 \begin_layout Standard
22050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22053 \begin_layout Standard
22059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22062 \begin_layout Standard
22068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22071 \begin_layout Standard
22077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22080 \begin_layout Standard
22086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22089 \begin_layout Standard
22094 \begin_layout Standard
22095 printf_tiny integer speed is data dependent, worst case is 0.33 ms
22106 <row bottomline="true">
22107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22110 \begin_layout Standard
22115 \begin_layout Standard
22116 Execution time of printf("%ld", -123456789); standard 8051 @ 22.1184 MHz,
22125 \begin_layout Standard
22131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22134 \begin_layout Standard
22140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22143 \begin_layout Standard
22149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22152 \begin_layout Standard
22158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22161 \begin_layout Standard
22167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22170 \begin_layout Standard
22176 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22179 \begin_layout Standard
22186 <row bottomline="true">
22187 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22190 \begin_layout Standard
22195 \begin_layout Standard
22196 Execution time of printf("%.3f", -12345.678); standard 8051 @ 22.1184 MHz,
22205 \begin_layout Standard
22211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22214 \begin_layout Standard
22220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22223 \begin_layout Standard
22229 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22232 \begin_layout Standard
22238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22241 \begin_layout Standard
22247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
22250 \begin_layout Standard
22256 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
22259 \begin_layout Standard
22273 \begin_layout Subsubsection
22275 \begin_inset LatexCommand index
22283 \begin_layout Standard
22284 As of SDCC 2.6.2 you no longer need to call an initialization routine before
22285 using dynamic memory allocation
22286 \begin_inset LatexCommand index
22287 name "dynamic memory allocation (malloc)"
22292 \begin_inset LatexCommand index
22293 name "heap (malloc)"
22297 space of 1024 bytes is provided for malloc to allocate memory from.
22298 If you need a different heap size you need to recompile _heap.c with the
22299 required size defined in HEAP_SIZE.
22300 It is recommended to make a copy of this file into your project directory
22301 and compile it there with:
22304 \begin_layout Verse
22307 sdcc -c _heap.c -D HEAD_SIZE=2048
22310 \begin_layout Standard
22311 And then link it with:
22314 \begin_layout Verse
22317 sdcc main.rel _heap.rel
22320 \begin_layout Subsection
22321 Math functions (sinf, powf, sqrtf etc.)
22324 \begin_layout Subsubsection
22328 \begin_layout Standard
22329 See definitions in file <math.h>.
22332 \begin_layout Subsection
22336 \begin_layout Standard
22338 \begin_inset LatexCommand index
22343 included in SDCC should have a license at least as liberal as the GNU Lesser
22344 General Public License
22345 \begin_inset LatexCommand index
22346 name "GNU Lesser General Public License, LGPL"
22357 \begin_layout Standard
22358 \begin_inset Note Note
22361 \begin_layout Standard
22362 license statements for the libraries are missing.
22363 sdcc/device/lib/ser_ir.c
22366 \begin_layout Standard
22368 come with a GPL (as opposed to LGPL) License - this will not be liberal
22369 enough for many embedded programmers.
22377 \begin_layout Standard
22378 If you have ported some library or want to share experience about some code
22380 falls into any of these categories Busses (I
22381 \begin_inset Formula $^{\textrm{2}}$
22384 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
22385 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
22386 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
22387 \begin_inset LatexCommand url
22388 target "http://sourceforge.net/mail/?group_id=599"
22393 would certainly like to hear about it.
22396 \begin_layout Standard
22397 Programmers coding for embedded systems are not especially famous for being
22398 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
22399 e these references are very valuable.
22400 Let's help to create a climate where information is shared.
22401 \begin_inset VSpace bigskip
22407 \begin_layout Section
22411 \begin_layout Subsection
22412 MCS51 Memory Models
22413 \begin_inset LatexCommand index
22414 name "Memory model"
22419 \begin_inset LatexCommand index
22420 name "MCS51 memory model"
22427 \begin_layout Subsubsection
22428 Small, Medium and Large
22431 \begin_layout Standard
22432 SDCC allows three memory models for MCS51 code,
22441 Modules compiled with different memory models should
22445 be combined together or the results would be unpredictable.
22446 The library routines supplied with the compiler are compiled as small,
22448 The compiled library modules are contained in separate directories as small,
22449 medium and large so that you can link to the appropriate set.
22452 \begin_layout Standard
22453 When the medium or large model is used all variables declared without a
22454 storage class will be allocated into the external ram, this includes all
22455 parameters and local variables (for non-reentrant
22456 \begin_inset LatexCommand index
22462 When the small model is used variables without storage class are allocated
22463 in the internal ram.
22466 \begin_layout Standard
22467 Judicious usage of the processor specific storage classes
22468 \begin_inset LatexCommand index
22469 name "Storage class"
22473 and the 'reentrant' function type will yield much more efficient code,
22474 than using the large model.
22475 Several optimizations are disabled when the program is compiled using the
22476 large model, it is therefore recommended that the small model be used unless
22477 absolutely required.
22480 \begin_layout Subsubsection
22482 \begin_inset LatexCommand label
22483 name "sub:External-Stack"
22488 \begin_inset LatexCommand index
22494 \begin_inset LatexCommand index
22495 name "External stack (mcs51)"
22502 \begin_layout Standard
22503 The external stack (-
22507 \begin_layout Standard
22517 \begin_inset LatexCommand index
22522 ) is located in pdata
22523 \begin_inset LatexCommand index
22524 name "pdata (mcs51, ds390 storage class)"
22528 memory (usually at the start of the external ram segment) and uses all
22529 unused space in pdata (max.
22535 \begin_layout Standard
22544 -xstack option is used to compile the program, the parameters and local
22546 \begin_inset LatexCommand index
22547 name "local variables"
22551 of all reentrant functions are allocated in this area.
22552 This option is provided for programs with large stack space requirements.
22553 When used with the -
22557 \begin_layout Standard
22567 \begin_inset LatexCommand index
22568 name "-\\/-stack-auto"
22572 option, all parameters and local variables are allocated on the external
22573 stack (note: support libraries will need to be recompiled with the same
22575 There is a predefined target in the library makefile).
22578 \begin_layout Standard
22579 The compiler outputs the higher order address byte of the external ram segment
22581 \begin_inset LatexCommand index
22582 name "P2 (mcs51 sfr)"
22587 \begin_inset LatexCommand ref
22588 reference "sub:MCS51-variants"
22592 ), therefore when using the External Stack option, this port
22596 be used by the application program.
22599 \begin_layout Subsection
22601 \begin_inset LatexCommand index
22602 name "Memory model"
22607 \begin_inset LatexCommand index
22608 name "DS390 memory model"
22615 \begin_layout Standard
22616 The only model supported is Flat 24
22617 \begin_inset LatexCommand index
22618 name "Flat 24 (DS390 memory model)"
22623 This generates code for the 24 bit contiguous addressing mode of the Dallas
22625 In this mode, up to four meg of external RAM or code space can be directly
22627 See the data sheets at www.dalsemi.com for further information on this part.
22632 that the compiler does not generate any code to place the processor into
22633 24 bitmode (although
22637 in the ds390 libraries will do that for you).
22643 \begin_inset LatexCommand index
22644 name "Tinibios (DS390)"
22648 , the boot loader or similar code must ensure that the processor is in 24
22649 bit contiguous addressing mode before calling the SDCC startup code.
22660 \begin_layout Standard
22671 option, variables will by default be placed into the XDATA segment.
22676 Segments may be placed anywhere in the 4 meg address space using the usual
22681 \begin_layout Standard
22691 Note that if any segments are located above 64K, the -r flag must be passed
22692 to the linker to generate the proper segment relocations, and the Intel
22693 HEX output format must be used.
22694 The -r flag can be passed to the linker by using the option
22698 on the SDCC command line.
22699 However, currently the linker can not handle code segments > 64k.
22702 \begin_layout Section
22704 \begin_inset LatexCommand label
22710 \begin_inset LatexCommand index
22718 \begin_layout Standard
22719 Pragmas are used to turn on and/or off certain compiler options.
22720 Some of them are closely related to corresponding command-line options
22722 \begin_inset LatexCommand vref
22723 reference "sec:Command-Line-Options"
22729 Pragmas should be placed before and/or after a function, placing pragmas
22730 inside a function body could have unpredictable results.
22735 following #pragma directives:
22738 \begin_layout Itemize
22744 \begin_inset LatexCommand index
22745 name "\\#pragma save"
22749 - this will save most current options to the save/restore stack.
22750 See #pragma\InsetSpace ~
22754 \begin_layout Itemize
22760 \begin_inset LatexCommand index
22761 name "\\#pragma restore"
22765 - will restore saved options from the last save.
22766 saves & restores can be nested.
22767 SDCC uses a save/restore stack: save pushes current options to the stack,
22768 restore pulls current options from the stack.
22769 See #pragma\InsetSpace ~
22775 \begin_layout Itemize
22781 \begin_inset LatexCommand index
22782 name "\\#pragma callee\\_saves"
22787 \begin_inset LatexCommand index
22788 name "function prologue"
22792 function1[,function2[,function3...]]
22793 \begin_inset LatexCommand label
22794 name "ite:callee_saves-function1[,function2[,function3...]]--"
22798 - The compiler by default uses a caller saves convention for register saving
22799 across function calls, however this can cause unnecessary register pushing
22801 \begin_inset LatexCommand index
22806 when calling small functions from larger functions.
22807 This option can be used to switch off the register saving convention for
22808 the function names specified.
22809 The compiler will not save registers when calling these functions, extra
22810 code need to be manually inserted at the entry and exit for these functions
22811 to save and restore the registers used by these functions, this can SUBSTANTIAL
22812 LY reduce code and improve run time performance of the generated code.
22813 In the future the compiler (with inter procedural analysis) may be able
22814 to determine the appropriate scheme to use for each function call.
22819 \begin_layout Standard
22828 -callee-saves command line option is used (see page
22829 \begin_inset LatexCommand vpageref
22830 reference "lyx:--callee-saves-function1[,function2][,function3]..."
22834 ), the function names specified in #pragma\InsetSpace ~
22836 \begin_inset LatexCommand index
22837 name "\\#pragma callee\\_saves"
22841 is appended to the list of functions specified in the command line.
22844 \begin_layout Itemize
22850 \begin_inset LatexCommand index
22851 name "\\#pragma exclude"
22855 none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
22856 of pairs of push/pop
22857 \begin_inset LatexCommand index
22867 \begin_inset LatexCommand index
22881 The directive should be placed immediately before the ISR function definition
22882 and it affects ALL ISR functions following it.
22883 To enable the normal register saving for ISR functions use #pragma\InsetSpace ~
22884 exclude\InsetSpace ~
22886 \begin_inset LatexCommand index
22887 name "\\#pragma exclude"
22892 See also the related keyword _naked
22893 \begin_inset LatexCommand index
22899 \begin_inset LatexCommand index
22907 \begin_layout Itemize
22913 \begin_inset LatexCommand index
22919 \begin_inset LatexCommand index
22920 name "\\#pragma less\\_pedantic"
22925 \begin_inset LatexCommand label
22926 name "ite:less_pedantic"
22930 - the compiler will not warn you anymore for obvious mistakes, you're on
22932 See also the command line option -
22936 \begin_layout Standard
22946 \begin_inset LatexCommand vpageref
22947 reference "lyx:--less-pedantic"
22954 More specifically, the following warnings will be disabled:
22956 comparison is always [true/false] due to limited range of data type
22960 overflow in implicit constant conversion
22962 (158); [the (in)famous]
22964 conditional flow changed by optimizer: so said EVELYN the modified DOG
22968 function '[function name]' must return value
22973 Furthermore, warnings of less importance (of PEDANTIC and INFO warning
22974 level) are disabled, too, namely:
22977 \begin_inset Note Note
22980 \begin_layout Standard
22981 dunno what comes here - this warning appears to be unused altogether
22990 [left/right] shifting more than size of object changed to zero
22998 integer overflow in expression
23002 unmatched #pragma save and #pragma restore
23006 comparison of 'signed char' with 'unsigned char' requires promotion to int
23010 ISO C90 does not support flexible array members
23014 extended stack by [number] bytes for compiler temp(s) :in function '[function\InsetSpace ~
23018 \begin_inset Note Note
23021 \begin_layout Standard
23022 appears to be always blank - what was supposed to be here?
23031 function '[function name]', # edges [number] , # nodes [number] , cyclomatic
23032 complexity [number]
23037 \begin_layout Itemize
23043 \begin_inset LatexCommand index
23044 name "\\#pragma disable\\_warning"
23048 - the compiler will not warn you anymore about warning number <nnnn>.
23051 \begin_layout Itemize
23057 \begin_inset LatexCommand index
23058 name "\\#pragma nogcse"
23062 - will stop global common subexpression elimination.
23065 \begin_layout Itemize
23071 \begin_inset LatexCommand index
23072 name "\\#pragma noinduction"
23076 - will stop loop induction optimizations.
23079 \begin_layout Itemize
23085 \begin_inset LatexCommand index
23086 name "\\#pragma noinvariant"
23090 - will not do loop invariant optimizations.
23091 For more details see Loop Invariants in section
23092 \begin_inset LatexCommand ref
23093 reference "sub:Loop-Optimizations"
23100 \begin_layout Itemize
23106 \begin_inset LatexCommand index
23107 name "\\#pragma noiv"
23111 - Do not generate interrupt
23112 \begin_inset LatexCommand index
23118 \begin_inset LatexCommand index
23119 name "interrupt vector table"
23123 entries for all ISR functions defined after the pragma.
23124 This is useful in cases where the interrupt vector table must be defined
23125 manually, or when there is a secondary, manually defined interrupt vector
23127 for the autovector feature of the Cypress EZ-USB FX2).
23128 More elegantly this can be achieved by omitting the optional interrupt
23129 number after the interrupt keyword, see section
23130 \begin_inset LatexCommand ref
23131 reference "sub:Interrupt-Service-Routines"
23139 \begin_layout Itemize
23145 \begin_inset LatexCommand index
23146 name "\\#pragma nojtbound"
23150 - will not generate code for boundary value checking, when switch statements
23151 are turned into jump-tables (dangerous).
23152 For more details see section
23153 \begin_inset LatexCommand ref
23154 reference "sub:'switch'-Statements"
23161 \begin_layout Itemize
23167 \begin_inset LatexCommand index
23168 name "\\#pragma noloopreverse"
23172 - Will not do loop reversal optimization
23175 \begin_layout Itemize
23181 \begin_inset LatexCommand index
23182 name "\\#pragma nooverlay"
23186 - the compiler will not overlay the parameters and local variables of a
23190 \begin_layout Itemize
23196 \begin_inset LatexCommand index
23197 name "\\#pragma stackauto"
23205 \begin_layout Standard
23215 \begin_inset LatexCommand index
23216 name "-\\/-stack-auto"
23221 \begin_inset LatexCommand ref
23222 reference "sec:Parameters-and-Local-Variables"
23226 Parameters and Local Variables.
23229 \begin_layout Itemize
23235 \begin_inset LatexCommand index
23236 name "\\#pragma opt\\_code\\_speed"
23240 - The compiler will optimize code generation towards fast code, possibly
23241 at the expense of code size.
23242 Currently this has little effect.
23245 \begin_layout Itemize
23251 \begin_inset LatexCommand index
23252 name "\\#pragma opt\\_code\\_size"
23256 - The compiler will optimize code generation towards compact code, possibly
23257 at the expense of code speed.
23258 Currently this has little effect.
23261 \begin_layout Itemize
23267 \begin_inset LatexCommand index
23268 name "\\#pragma opt\\_code\\_balanced"
23272 - The compiler will attempt to generate code that is both compact and fast,
23273 as long as meeting one goal is not a detriment to the other (this is the
23278 \begin_layout Itemize
23284 \begin_inset LatexCommand index
23285 name "\\#pragma std\\_sdcc89"
23289 - Generally follow the C89 standard, but allow SDCC features that conflict
23290 with the standard (default).
23293 \begin_layout Itemize
23299 \begin_inset LatexCommand index
23300 name "\\#pragma std\\_c89"
23304 - Follow the C89 standard and disable SDCC features that conflict with the
23308 \begin_layout Itemize
23314 \begin_inset LatexCommand index
23315 name "\\#pragma std\\_sdcc99"
23319 - Generally follow the C99 standard, but allow SDCC features that conflict
23320 with the standard (incomplete support).
23323 \begin_layout Itemize
23329 \begin_inset LatexCommand index
23330 name "\\#pragma std\\_c99"
23334 - Follow the C99 standard and disable SDCC features that conflict with the
23335 standard (incomplete support).
23338 \begin_layout Itemize
23344 \begin_inset LatexCommand index
23345 name "\\#pragma codeseg"
23349 - Use this name (max.
23350 8 characters) for the code segment.
23355 \begin_layout Standard
23367 \begin_layout Itemize
23373 \begin_inset LatexCommand index
23374 name "\\#pragma constseg"
23378 - Use this name (max.
23379 8 characters) for the const segment.
23384 \begin_layout Standard
23396 \begin_layout Standard
23397 The preprocessor SDCPP
23398 \begin_inset LatexCommand index
23399 name "sdcpp (preprocessor)"
23403 supports the following #pragma directives:
23406 \begin_layout Itemize
23409 pedantic_parse_number
23412 \begin_inset LatexCommand index
23418 \begin_inset LatexCommand index
23419 name "\\#pragma pedantic\\_parse\\_number"
23424 \begin_inset LatexCommand label
23425 name "ite:pedantic_parse_number"
23429 - Pedantic parse numbers so that situations like 0xfe-LO_B(3) are parsed
23430 properly and the macro LO_B(3) gets expanded.
23436 \begin_layout Standard
23445 -pedantic-parse-number command line option
23446 \begin_inset LatexCommand vpageref
23447 reference "lyx:-pedantic-parse-number"
23454 Below is an example on how to use this pragma.
23457 Note: this functionality is not in conformance with standard!
23460 \begin_layout Verse
23463 #pragma pedantic_parse_number +
23464 \begin_inset LatexCommand index
23465 name "\\#pragma pedantic\\_parse\\_number"
23473 #define LO_B(x) ((x) & 0xff)
23477 unsigned char foo(void)
23484 unsigned char c=0xfe-LO_B(3)
23499 \begin_layout Itemize
23505 \begin_inset LatexCommand index
23506 name "\\#pragma preproc\\_asm"
23510 (+ | -) - switch _asm _endasm block preprocessing on / off.
23512 You use this pragma to define multilines of assembly code.
23513 This will prevent the preprocessor from changing the formatting required
23515 Below is an example on how to use this pragma.
23518 \begin_layout Verse
23521 #pragma preproc_asm -
23522 \begin_inset LatexCommand index
23523 name "\\#pragma preproc\\_asm"
23529 #define MYDELAY _asm
23534 nop ;my assembly comment...
23548 #pragma preproc_asm
23579 \begin_layout Itemize
23585 \begin_inset LatexCommand index
23586 name "\\#pragma sdcc\\_hash"
23590 (+ | -) - Allow "naked" hash in macro definition, for example:
23594 #define DIR_LO(x) #(x & 0xff)
23599 Below is an example on how to use this pragma.
23602 \begin_layout Verse
23605 #pragma preproc_asm +
23607 #pragma sdcc_hash +
23608 \begin_inset LatexCommand index
23609 name "\\#pragma sdcc\\_hash"
23624 mov R6_B3, #(x & 0xff)
23631 mov R7_B3, #((x >> 8) & 0xff)
23655 \begin_layout Standard
23656 Some of the pragmas are intended to be used to turn-on or off certain optimizati
23657 ons which might cause the compiler to generate extra stack and/or data space
23658 to store compiler generated temporary variables.
23659 This usually happens in large functions.
23660 Pragma directives should be used as shown in the following example, they
23661 are used to control options and optimizations for a given function.
23665 \begin_layout Verse
23669 \begin_inset LatexCommand index
23670 name "\\#pragma save"
23681 /* save the current settings */
23684 \begin_inset LatexCommand index
23685 name "\\#pragma nogcse"
23694 /* turnoff global subexpression elimination */
23696 #pragma noinduction
23697 \begin_inset LatexCommand index
23698 name "\\#pragma noinduction"
23702 /* turn off induction optimizations */
23725 \begin_inset LatexCommand index
23726 name "\\#pragma restore"
23730 /* turn the optimizations back on */
23733 \begin_layout Standard
23734 The compiler will generate a warning message when extra space is allocated.
23735 It is strongly recommended that the save and restore pragmas be used when
23736 changing options for a function.
23745 \begin_layout Section
23746 Defines Created by the Compiler
23749 \begin_layout Standard
23750 The compiler creates the following #defines
23751 \begin_inset LatexCommand index
23757 \begin_inset LatexCommand index
23758 name "Defines created by the compiler"
23767 \begin_layout Standard
23768 \begin_inset Tabular
23769 <lyxtabular version="3" rows="15" columns="2">
23771 <column alignment="left" valignment="top" leftline="true" width="3in">
23772 <column alignment="left" valignment="top" leftline="true" rightline="true" width="3in">
23773 <row topline="true" bottomline="true">
23774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23777 \begin_layout Standard
23785 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23788 \begin_layout Standard
23797 <row topline="true">
23798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23801 \begin_layout Standard
23803 \begin_inset LatexCommand index
23813 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23816 \begin_layout Standard
23818 Since version 2.5.6 the version number as an int (ex.
23825 <row topline="true">
23826 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23829 \begin_layout Standard
23831 \begin_inset LatexCommand index
23832 name "SDCC\\_mcs51"
23837 \begin_inset LatexCommand index
23838 name "SDCC\\_ds390"
23843 \begin_inset LatexCommand index
23853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23856 \begin_layout Standard
23857 depending on the model used (e.g.: -mds390)
23863 <row topline="true">
23864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23867 \begin_layout Standard
23869 \begin_inset LatexCommand index
23875 \begin_inset LatexCommand index
23881 \begin_inset LatexCommand index
23887 \begin_inset LatexCommand index
23897 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23900 \begin_layout Standard
23901 depending on the model used (e.g.
23908 <row topline="true">
23909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23912 \begin_layout Standard
23914 \begin_inset LatexCommand index
23915 name "SDCC\\_STACK\\_AUTO"
23924 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23927 \begin_layout Standard
23934 \begin_layout Standard
23951 <row topline="true">
23952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23955 \begin_layout Standard
23957 \begin_inset LatexCommand index
23958 name "SDCC\\_MODEL\\_SMALL"
23967 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
23970 \begin_layout Standard
23977 \begin_layout Standard
23994 <row topline="true">
23995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
23998 \begin_layout Standard
24000 \begin_inset LatexCommand index
24001 name "SDCC\\_MODEL\\_MEDIUM"
24010 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24013 \begin_layout Standard
24020 \begin_layout Standard
24037 <row topline="true">
24038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24041 \begin_layout Standard
24043 \begin_inset LatexCommand index
24044 name "SDCC\\_MODEL\\_LARGE"
24053 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24056 \begin_layout Standard
24063 \begin_layout Standard
24080 <row topline="true">
24081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24084 \begin_layout Standard
24086 \begin_inset LatexCommand index
24087 name "SDCC\\_USE\\_XSTACK"
24096 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24099 \begin_layout Standard
24106 \begin_layout Standard
24123 <row topline="true">
24124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24127 \begin_layout Standard
24129 \begin_inset LatexCommand index
24130 name "SDCC\\_STACK\\_TENBIT"
24139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24142 \begin_layout Standard
24153 <row topline="true">
24154 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24157 \begin_layout Standard
24159 \begin_inset LatexCommand index
24160 name "SDCC\\_MODEL\\_FLAT24"
24169 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24172 \begin_layout Standard
24183 <row topline="true">
24184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24187 \begin_layout Standard
24189 \begin_inset LatexCommand index
24190 name "SDCC\\_REVISION"
24199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24202 \begin_layout Standard
24204 SDCC svn revision number
24210 <row topline="true">
24211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24214 \begin_layout Standard
24215 SDCC_PARMS_IN_BANK1
24216 \begin_inset LatexCommand index
24217 name "SDCC\\_PARMS\\_IN\\_BANK1"
24226 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24229 \begin_layout Standard
24236 \begin_layout Standard
24253 <row topline="true">
24254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24257 \begin_layout Standard
24259 \begin_inset LatexCommand index
24260 name "SDCC\\_MODEL\\_FLAT24"
24269 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24272 \begin_layout Standard
24279 \begin_layout Standard
24296 <row topline="true" bottomline="true">
24297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24300 \begin_layout Standard
24301 SDCC_INT_LONG_REENT
24302 \begin_inset LatexCommand index
24303 name "SDCC\\_INT\\_LONG\\_REENT"
24312 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24315 \begin_layout Standard
24322 \begin_layout Standard
24346 \begin_layout Chapter
24347 Notes on supported Processors
24350 \begin_layout Section
24352 \begin_inset LatexCommand label
24353 name "sub:MCS51-variants"
24358 \begin_inset LatexCommand index
24359 name "MCS51 variants"
24366 \begin_layout Standard
24367 MCS51 processors are available from many vendors and come in many different
24369 While they might differ considerably in respect to Special Function Registers
24370 the core MCS51 is usually not modified or is kept compatible.
24374 \begin_layout Subsection
24375 pdata access by SFR
24378 \begin_layout Standard
24379 With the upcome of devices with internal xdata and flash memory devices
24381 \begin_inset LatexCommand index
24382 name "P2 (mcs51 sfr)"
24386 as dedicated I/O port is becoming more popular.
24387 Switching the high byte for pdata
24388 \begin_inset LatexCommand index
24389 name "pdata (mcs51, ds390 storage class)"
24393 access which was formerly done by port P2 is then achieved by a Special
24395 \begin_inset LatexCommand index
24401 In well-established MCS51 tradition the address of this
24405 is where the chip designers decided to put it.
24406 Needless to say that they didn't agree on a common name either.
24407 So that the startup code can correctly initialize xdata variables, you
24408 should define an sfr with the name _XPAGE
24411 \begin_inset LatexCommand index
24412 name "\\_XPAGE (mcs51)"
24418 at the appropriate location if the default, port P2, is not used for this.
24422 \begin_layout Verse
24425 __sfr __at (0x85) _XPAGE; /* Ramtron VRS51 family a.k.a.
24429 \begin_layout Verse
24432 __sfr __at (0x92) _XPAGE; /* Cypress EZ-USB family, Texas Instruments (Chipcon)
24437 \begin_layout Verse
24440 __sfr __at (0x91) _XPAGE; /* Infineon (Siemens) C500 family a.k.a.
24444 \begin_layout Verse
24447 __sfr __at (0xaf) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
24451 \begin_layout Verse
24454 __sfr __at (0xaa) _XPAGE; /* some Silicon Labs (Cygnal) chips a.k.a.
24458 \begin_layout Standard
24459 For more exotic implementations further customizations may be needed.
24461 \begin_inset LatexCommand ref
24462 reference "sub:Startup-Code"
24466 for other possibilities.
24469 \begin_layout Subsection
24470 Other Features available by SFR
24473 \begin_layout Standard
24474 Some MCS51 variants offer features like Double DPTR
24475 \begin_inset LatexCommand index
24480 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
24481 These are currently not used for the MCS51 port.
24482 If you absolutely need them you can fall back to inline assembly or submit
24486 \begin_layout Subsection
24490 \begin_layout Standard
24492 \begin_inset LatexCommand index
24493 name "Bankswitching"
24499 \begin_inset LatexCommand index
24500 name "code banking"
24504 ) is a technique to increase the code space above the 64k limit of the 8051.
24507 \begin_layout Subsubsection
24511 \begin_layout Standard
24512 \begin_inset Tabular
24513 <lyxtabular version="3" rows="3" columns="4">
24515 <column alignment="center" valignment="top" width="0">
24516 <column alignment="center" valignment="top" leftline="true" width="0">
24517 <column alignment="center" valignment="top" leftline="true" width="0">
24518 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
24519 <row topline="true" bottomline="true">
24520 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24523 \begin_layout Standard
24529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24532 \begin_layout Standard
24538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24541 \begin_layout Standard
24547 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24550 \begin_layout Standard
24557 <row topline="true" bottomline="true">
24558 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24561 \begin_layout Standard
24567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24570 \begin_layout Standard
24576 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24579 \begin_layout Standard
24585 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
24588 \begin_layout Standard
24596 <cell multicolumn="1" alignment="center" valignment="top" usebox="none">
24599 \begin_layout Standard
24600 SiLabs C8051F120 example
24605 <cell multicolumn="2" alignment="center" valignment="top" usebox="none">
24608 \begin_layout Standard
24614 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24617 \begin_layout Standard
24623 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
24626 \begin_layout Standard
24641 Usually the hardware uses some sfr (an output port or an internal sfr) to
24642 select a bank and put it in the banked area of the memory map.
24643 The selected bank usually becomes active immediately upon assignment to
24644 this sfr and when running inside a bank it will switch out this code it
24645 is currently running.
24646 Therefor you cannot jump or call directly from one bank to another and
24647 need to use a so-called trampoline in the common area.
24648 For SDCC an example trampoline is in crtbank.asm and you may need to change
24649 it to your 8051 derivative or schematic.
24650 The presented code is written for the C8051F120.
24654 When calling a banked function
24655 SDCC will put the LSB of the functions address in register R0, the MSB
24656 in R1 and the bank in R2 and then call this trampoline
24661 The current selected bank is saved on the stack, the new bank is selected
24662 and an indirect jump is made.
24663 When the banked function returns it jumps to
24667 which restores the previous bank and returns to the caller.
24670 \begin_layout Subsubsection
24674 \begin_layout Standard
24675 When writing banked software using SDCC you need to use some special keywords
24677 You also need to take over a bit of work from the linker.
24681 To create a function
24682 that can be called from another bank it requires the keyword
24687 \begin_inset LatexCommand index
24693 The caller must see this in the prototype of the callee and the callee
24694 needs it for a proper return.
24695 Called functions within the same bank as the caller do not need the
24699 keyword nor do functions in the common area.
24700 Beware: SDCC does not know or check if functions are in the same bank.
24701 This is your responsibility!
24705 Normally all functions you write end up in
24707 If you want a function explicitly to reside in the common area put it in
24709 This applies for instance to interrupt service routines as they should
24713 \begin_layout Standard
24714 Functions that need to be in a switched bank must be put in a named segment.
24715 The name can be mostly anything up to eight characters (e.g.
24717 To do this you either use -
24721 \begin_layout Standard
24730 -codeseg BANK1 (See
24731 \begin_inset LatexCommand ref
24732 reference "lyx:-codeseg"
24736 ) on the command line when compiling or #pragma codeseg BANK1 (See
24737 \begin_inset LatexCommand ref
24738 reference "sec:Pragmas"
24742 ) at the top of the C source file.
24743 The segment name always applies to the whole source file and generated
24744 object so functions for different banks need to be defined in different
24749 When linking your objects you need to tell the linker where
24750 to put your segments.
24751 To do this you use the following command line option to SDCC: -Wl-b BANK1=0x180
24753 \begin_inset LatexCommand ref
24754 reference "lyx:-Wl option"
24759 This sets the virtual start address of this segment.
24760 It sets the banknumber to 0x01 and maps the bank to 0x8000 and up.
24761 The linker will not check for overflows, again this is your responsibility.
24764 \begin_layout Standard
24765 \begin_inset VSpace bigskip
24771 \begin_layout Section
24775 \begin_layout Standard
24777 \begin_inset LatexCommand index
24783 \begin_inset LatexCommand index
24788 microcontroller has a rich set of peripherals.
24789 In its built-in ROM library it includes functions to access some of the
24790 features, among them is a TCP stack with IP4 and IP6 support.
24791 Library headers (currently in beta status) and other files are provided
24795 \begin_inset LatexCommand url
24796 target "ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html"
24802 \begin_inset VSpace bigskip
24808 \begin_layout Section
24809 The Z80 and gbz80 port
24812 \begin_layout Standard
24813 SDCC can target both the Zilog Z80
24814 \begin_inset LatexCommand index
24819 and the Nintendo Gameboy's Z80-like gbz80
24820 \begin_inset LatexCommand index
24821 name "gbz80 (GameBoy Z80)"
24826 The Z80 port is passed through the same
24829 \begin_inset LatexCommand index
24830 name "Regression test"
24837 \begin_inset LatexCommand ref
24838 reference "sec:Quality-control"
24842 ) as the MCS51 and DS390 ports, so floating point support, support for long
24843 variables and bitfield support is fine.
24844 See mailing lists and forums about interrupt routines.
24847 \begin_layout Standard
24848 As always, the code is the authoritative reference - see z80/ralloc.c and
24851 \begin_inset LatexCommand index
24856 frame is similar to that generated by the IAR Z80 compiler.
24857 IX is used as the base pointer, HL and IY are used as a temporary registers,
24858 and BC and DE are available for holding variables.
24860 \begin_inset LatexCommand index
24861 name "Z80!return value"
24865 for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
24867 The gbz80 port use the same set of registers for the return values, but
24868 in a different order of significance: E (one byte), DE (two bytes), or
24870 \begin_inset VSpace bigskip
24876 \begin_layout Section
24880 \begin_layout Standard
24881 The port to the Freescale/Motorola HC08
24882 \begin_inset LatexCommand index
24887 family has been added in October 2003, and is still undergoing some basic
24889 The code generator is complete, but the register allocation is still quite
24891 Some of the SDCC's standard C library functions have embedded non-HC08
24892 inline assembly and so are not yet usable.
24895 \begin_layout Standard
24896 The HC08 port passes the regression test suite (see section
24897 \begin_inset LatexCommand ref
24898 reference "sec:Quality-control"
24903 \begin_inset VSpace bigskip
24909 \begin_layout Section
24911 \begin_inset LatexCommand index
24919 \begin_layout Standard
24920 The PIC14 port adds support for Microchip
24921 \begin_inset LatexCommand index
24927 \begin_inset Formula $^{\text{TM}}$
24931 \begin_inset LatexCommand index
24937 \begin_inset Formula $^{\text{TM}}$
24940 MCUs with 14 bit wide instructions.
24941 This port is not yet mature and still lacks many features.
24942 However, it can work for simple code.
24945 \begin_layout Standard
24947 Currently supported devices include:
24950 \begin_layout Standard
24951 12F: 629, 635, 675, 683
24954 \begin_layout Standard
24958 \begin_layout Standard
24962 \begin_layout Standard
24963 16C: 62, 620, 620a, 621, 621a, 622, 622a, 63a, 65b
24966 \begin_layout Standard
24967 16C: 71, 710, 711, 715, 717, 72, 73b, 745, 74b, 765, 770, 771, 773, 774,
24971 \begin_layout Standard
24975 \begin_layout Standard
24976 16CR: 620a, 73, 74, 76, 77
24979 \begin_layout Standard
24980 16F: 616, 627, 627a, 628, 628a, 630, 636, 639, 648, 648a, 676, 684, 685,
24984 \begin_layout Standard
24985 16F: 716, 72, 73, 737, 74, 747, 76, 767, 77, 777, 785
24988 \begin_layout Standard
24989 16F: 818, 819, 84, 84a, 87, 870, 871, 872, 873, 873a, 874, 874a, 876, 876a,
24990 877, 877a, 88, 886, 887
24993 \begin_layout Standard
24994 16F: 913, 914, 916, 917, 946
24997 \begin_layout Standard
25001 \begin_layout Standard
25003 An up-to-date list of currently supported devices can be obtained via
25005 sdcc -mpic14 -phelp foo.c
25007 (foo.c must exist...).
25010 \begin_layout Subsection
25012 \begin_inset LatexCommand index
25013 name "code page (pic14)"
25018 \begin_inset LatexCommand index
25019 name "Memory bank (pic14)"
25026 \begin_layout Standard
25027 The linker organizes allocation for the code page and RAM banks.
25028 It does not have intimate knowledge of the code flow.
25029 It will put all the code section of a single .asm file into a single code
25031 In order to make use of multiple code pages, separate asm files must be
25033 The compiler assigns all
25037 functions of a single .c file into the same code page.
25041 To get the best results,
25042 follow these guidelines:
25045 \begin_layout Enumerate
25046 Make local functions static, as non static functions require code page selection
25049 Due to the way sdcc handles functions, place called functions prior
25050 to calling functions in the file wherever possible: Otherwise sdcc will
25051 insert unnecessary pagesel directives around the call, believing that the
25052 called function is externally defined.
25055 \begin_layout Enumerate
25056 For devices that have multiple code pages it is more efficient to use the
25057 same number of files as pages: Use up to 4 separate .c files for the 16F877,
25058 but only 2 files for the 16F874.
25059 This way the linker can put the code for each file into different code
25060 pages and there will be less page selection overhead.
25063 \begin_layout Enumerate
25064 And as for any 8 bit micro (especially for PIC14 as they have a very simple
25065 instruction set), use `unsigned char' wherever possible instead of `int'.
25068 \begin_layout Subsection
25069 Adding New Devices to the Port
25072 \begin_layout Standard
25073 Adding support for a new 14
25077 \begin_layout Standard
25086 bit PIC MCU requires the following steps:
25089 \begin_layout Enumerate
25090 Create a new device description.
25092 Each device is described in two files: pic16f*.h
25094 These files primarily define SFRs, structs to access their bits, and symbolic
25095 configuration options.
25096 Both files can be generated from gputils' .inc files using the perl script
25099 support/scripts/inc2h.pl
25102 This file also contains further instructions on how to proceed.
25105 \begin_layout Enumerate
25106 Copy the .h file into SDCC's include path and either add the .c file to your
25107 project or copy it to
25109 device/lib/pic/libdev
25112 Afterwards, rebuild and install the libraries.
25115 \begin_layout Enumerate
25116 Edit pic14devices.txt in SDCC's include path (
25118 device/include/pic/
25120 in the source tree or
25122 /usr/local/share/sdcc/include/pic
25124 after installation).
25126 You need to add a device specification here to make
25127 the memory layout (code banks, RAM, aliased memory regions, ...) known to
25129 Probably you can copy and modify an existing entry.
25130 The file format is documented at the top of the file.
25133 \begin_layout Subsection
25137 \begin_layout Standard
25138 For the interrupt function, use the keyword `__interrupt'
25139 \begin_inset LatexCommand index
25140 name "PIC14!interrupt"
25144 with level number of 0 (PIC14 only has 1 interrupt so this number is only
25145 there to avoid a syntax error - it ought to be fixed).
25149 \begin_layout Verse
25152 void Intr(void) __interrupt 0
25158 T0IF = 0; /* Clear timer interrupt */
25163 \begin_layout Subsection
25164 Linking and Assembling
25167 \begin_layout Standard
25168 For assembling you can use either GPUTILS'
25169 \begin_inset LatexCommand index
25170 name "gputils (pic tools)"
25174 gpasm.exe or MPLAB's mpasmwin.exe.
25175 GPUTILS are available from
25176 \begin_inset LatexCommand url
25177 target "http://sourceforge.net/projects/gputils"
25182 For linking you can use either GPUTILS' gplink or MPLAB's mplink.exe.
25183 If you use MPLAB and an interrupt function then the linker script file
25184 vectors section will need to be enlarged to link with mplink.
25195 \begin_layout Verse
25208 sdcc -V -mpic14 -p16f877 -c $<
25212 $(PRJ).hex: $(OBJS)
25222 gplink -m -s $(PRJ).lkr
25223 -o $(PRJ).hex $(OBJS) libsdcc.lib
25226 \begin_layout Standard
25234 \begin_layout Verse
25247 sdcc -S -V -mpic14 -p16f877 $<
25257 mpasmwin /q /o $*.asm
25261 $(PRJ).hex: $(OBJS)
25272 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib
25275 \begin_layout Standard
25276 Please note that indentations within a
25280 have to be done with a tabulator character.
25283 \begin_layout Subsection
25284 Command-Line Options
25287 \begin_layout Standard
25288 Besides the switches common to all SDCC backends, the PIC14 port accepts
25289 the following options (for an updated list see sdcc -
25293 \begin_layout Standard
25305 \begin_layout Description
25310 \begin_layout Standard
25320 \begin_inset LatexCommand index
25321 name "PIC14!Options!-\\/-debug-extra"
25325 emit debug info in assembly output
25328 \begin_layout Description
25333 \begin_layout Standard
25343 \begin_inset LatexCommand index
25344 name "PIC14!Options!-\\/-no-pcode-opt"
25348 disable (slightly faulty) optimization on pCode
25351 \begin_layout Description
25356 \begin_layout Standard
25366 \begin_inset LatexCommand index
25367 name "PIC14!Options!-\\/-stack-loc"
25371 sets the lowest address of the argument passing stack (defaults to a suitably
25372 large shared databank to reduce BANKSEL overhead)
25375 \begin_layout Description
25380 \begin_layout Standard
25390 \begin_inset LatexCommand index
25391 name "PIC14!Options!-\\/-stack-size"
25395 sets the size if the argument passing stack (default: 16, minimum: 4)
25398 \begin_layout Subsection
25399 Environment Variables
25402 \begin_layout Standard
25403 The PIC14 port recognizes the following environment variables:
25406 \begin_layout Description
25407 SDCC_PIC14_SPLIT_LOCALS If set and not empty, sdcc will allocate each temporary
25408 register (the ones called r0xNNNN) in a section of its own.
25409 By default (if this variable is unset), sdcc tries to cluster registers
25410 in sections in order to reduce the BANKSEL overhead when accessing them.
25413 \begin_layout Subsection
25417 \begin_layout Standard
25418 The PIC14 library currently only contains support routines required by the
25419 compiler to implement multiplication, division, and floating point support.
25420 No libc-like replacement is available at the moment, though many of the
25421 common sdcc library sources (in
25425 ) should also compile with the PIC14 port.
25428 \begin_layout Subsubsection
25429 error: missing definition for symbol ``__gptrget1''
25432 \begin_layout Standard
25433 The PIC14 port uses library routines to provide more complex operations
25434 like multiplication, division/modulus and (generic) pointer dereferencing.
25435 In order to add these routines to your project, you must link with PIC14's
25441 For single source file projects this is done automatically, more complex
25446 to the linker's arguments.
25447 Make sure you also add an include path for the library (using the -I switch
25451 \begin_layout Subsubsection
25452 Processor mismatch in file ``XXX''.
25455 \begin_layout Standard
25456 This warning can usually be ignored due to the very good compatibility amongst
25461 \begin_layout Standard
25471 \begin_inset LatexCommand index
25479 \begin_layout Standard
25480 You might also consider recompiling the library for your specific device
25481 by changing the ARCH=p16f877 (default target) entry in
25483 device/lib/pic/Makefile.in
25487 device/lib/pic/Makefile
25489 to reflect your device.
25490 This might even improve performance for smaller devices as unnecessary
25491 BANKSELs might be removed.
25494 \begin_layout Subsection
25498 \begin_layout Subsubsection
25502 \begin_layout Standard
25503 Functions with variable argument lists (like printf) are not yet supported.
25504 Similarly, taking the address of the first argument passed into a function
25505 does not work: It is currently passed in WREG and has no address...
25508 \begin_layout Subsubsection
25509 Regression tests fail
25512 \begin_layout Standard
25513 Though the small subset of regression tests in src/regression passes, SDCC
25514 regression test suite does not, indicating that there are still major bugs
25516 However, many smaller projects have successfully used SDCC in the past...
25519 \begin_layout Standard
25527 \begin_layout Section
25529 \begin_inset LatexCommand index
25537 \begin_layout Standard
25538 The PIC16 port adds support for Microchip
25539 \begin_inset LatexCommand index
25545 \begin_inset Formula $^{\text{TM}}$
25549 \begin_inset LatexCommand index
25555 \begin_inset Formula $^{\text{TM}}$
25558 MCUs with 16 bit wide instructions.
25559 Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx
25560 ; devices supported by the port include:
25563 \begin_layout Standard
25564 18F: 242, 248, 252, 258, 442, 448, 452, 458
25567 \begin_layout Standard
25571 \begin_layout Standard
25572 18F: 2220, 2221, 2320, 2321, 2331, 2410, 2420, 2423, 2431, 2450, 2455, 2480,
25576 \begin_layout Standard
25577 18F: (2510,) 2515, 2520, 2523, 2525, 2550, 2580, 2585, 25j10, 2610, 2620,
25581 \begin_layout Standard
25582 18F: 4220, 4221, 4320, 4321, 4331, 4410, 4420, 4423, 4431, 4450, 4455, 4480,
25586 \begin_layout Standard
25587 18F: 4510, 4515, 4520, 4523, 4525, 4550, 4580, 4585, 45j10, 4610, 4620,
25591 \begin_layout Standard
25592 18F: 6520, 6585, 6620, 6680, 66j60, 66j65, 6720, 67j60
25595 \begin_layout Standard
25596 18F: 8520, 8585, 8620, 8680, 86j60, 86j65, 8720, 87j60
25599 \begin_layout Standard
25600 18F: 96j60, 96j65, 97j60
25603 \begin_layout Standard
25605 An up-to-date list of supported devices is also available via '
25607 sdcc -mpic16 -plist
25612 \begin_layout Subsection
25616 \begin_layout Standard
25617 PIC16 port supports the standard command line arguments as supposed, with
25618 the exception of certain cases that will be mentioned in the following
25622 \begin_layout Description
25627 \begin_layout Standard
25637 \begin_inset LatexCommand index
25638 name "PIC16!Options!-\\/-callee-saves"
25646 \begin_layout Standard
25658 \begin_layout Description
25663 \begin_layout Standard
25672 -fommit-frame-pointer
25673 \begin_inset LatexCommand index
25674 name "PIC16!Options!-\\/-fommit-frame-pointer"
25678 Frame pointer will be omitted when the function uses no local variables.
25681 \begin_layout Subsection
25682 Port Specific Options
25683 \begin_inset LatexCommand index
25684 name "Options PIC16"
25691 \begin_layout Standard
25692 The port specific options appear after the global options in the sdcc -
25696 \begin_layout Standard
25708 \begin_layout Subsubsection
25709 Code Generation Options
25712 \begin_layout Standard
25713 These options influence the generated assembler code.
25716 \begin_layout Description
25721 \begin_layout Standard
25730 -pstack-model=[model] Used in conjunction with the command above.
25731 Defines the stack model to be used, valid stack models are:
25736 \labelwidthstring 00.00.0000
25741 Selects small stack model.
25742 8 bit stack and frame pointers.
25743 Supports 256 bytes stack size.
25747 \labelwidthstring 00.00.0000
25752 Selects large stack model.
25753 16 bit stack and frame pointers.
25754 Supports 65536 bytes stack size.
25758 \begin_layout Description
25763 \begin_layout Standard
25772 -pno-banksel Do not generate BANKSEL assembler directives.
25775 \begin_layout Description
25780 \begin_layout Standard
25789 -extended Enable extended instruction set/literal offset addressing mode.
25793 \begin_layout Subsubsection
25794 Optimization Options
25797 \begin_layout Description
25802 \begin_layout Standard
25811 -obanksel=n Set optimization level for inserting BANKSELs.
25818 \labelwidthstring 00.00.0000
25823 \labelwidthstring 00.00.0000
25824 1 checks previous used register and if it is the same then does not emit
25825 BANKSEL, accounts only for labels.
25829 \labelwidthstring 00.00.0000
25830 2 tries to check the location of (even different) symbols and removes BANKSELs
25831 if they are in the same bank.
25836 Important: There might be problems if the linker script has data sections
25837 across bank borders!
25841 \begin_layout Description
25846 \begin_layout Standard
25855 -denable-peeps Force the usage of peepholes.
25859 \begin_layout Description
25864 \begin_layout Standard
25873 -no-optimize-goto Do not use (conditional) BRA instead of GOTO.
25876 \begin_layout Description
25881 \begin_layout Standard
25890 -optimize-cmp Try to optimize some compares.
25893 \begin_layout Description
25898 \begin_layout Standard
25907 -optimize-df Analyze the dataflow of the generated code and improve it.
25910 \begin_layout Subsubsection
25914 \begin_layout Description
25919 \begin_layout Standard
25928 -asm= Sets the full path and name of an external assembler to call.
25931 \begin_layout Description
25936 \begin_layout Standard
25946 \begin_inset LatexCommand index
25951 compatibility option.
25952 Currently only suppresses special gpasm directives.
25955 \begin_layout Subsubsection
25959 \begin_layout Description
25964 \begin_layout Standard
25973 -link= Sets the full path and name of an external linker to call.
25976 \begin_layout Description
25981 \begin_layout Standard
25990 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
25991 unitialized data variables with [kword].
25992 Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
25995 \begin_layout Description
26000 \begin_layout Standard
26009 -ivt-loc=n Place the interrupt vector table at address
26014 Useful for bootloaders.
26017 \begin_layout Description
26022 \begin_layout Standard
26031 -nodefaultlibs Do not link default libraries when linking.
26034 \begin_layout Description
26039 \begin_layout Standard
26048 -use-crt= Use a custom run-time module instead of the defaults.
26051 \begin_layout Description
26056 \begin_layout Standard
26065 -no-crt Don't link the default run-time modules
26068 \begin_layout Subsubsection
26072 \begin_layout Standard
26073 Debugging options enable extra debugging information in the output files.
26076 \begin_layout Description
26081 \begin_layout Standard
26090 -debug-xtra Similar to -
26094 \begin_layout Standard
26104 \begin_inset LatexCommand index
26109 , but dumps more information.
26112 \begin_layout Description
26117 \begin_layout Standard
26126 -debug-ralloc Force register allocator to dump <source>.d file with debugging
26128 <source> is the name of the file being compiled.
26131 \begin_layout Description
26136 \begin_layout Standard
26145 -pcode-verbose Enable pcode debugging information in translation.
26148 \begin_layout Description
26153 \begin_layout Standard
26162 -calltree Dump call tree in .calltree file.
26165 \begin_layout Description
26170 \begin_layout Standard
26179 -gstack Trace push/pops for stack pointer overflow.
26182 \begin_layout Subsection
26183 Environment Variables
26186 \begin_layout Standard
26187 There is a number of environmental variables that can be used when running
26188 SDCC to enable certain optimizations or force a specific program behaviour.
26189 these variables are primarily for debugging purposes so they can be enabled/dis
26193 \begin_layout Standard
26194 Currently there is only two such variables available:
26197 \begin_layout Description
26198 OPTIMIZE_BITFIELD_POINTER_GET When this variable exists, reading of structure
26199 bitfields is optimized by directly loading FSR0 with the address of the
26200 bitfield structure.
26201 Normally SDCC will cast the bitfield structure to a bitfield pointer and
26203 This step saves data ram and code space for functions that make heavy use
26205 (i.e., 80 bytes of code space are saved when compiling malloc.c with this
26210 \begin_layout Description
26211 NO_REG_OPT Do not perform pCode registers optimization.
26212 This should be used for debugging purposes.
26213 If bugs in the pcode optimizer are found, users can benefit from temporarily
26214 disabling the optimizer until the bug is fixed.
26217 \begin_layout Subsection
26218 Preprocessor Macros
26221 \begin_layout Standard
26223 \begin_inset LatexCommand index
26228 port defines the following preprocessor macros while translating a source.
26231 \begin_layout Standard
26233 \begin_inset Tabular
26234 <lyxtabular version="3" rows="6" columns="2">
26236 <column alignment="center" valignment="top" leftline="true" width="0">
26237 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26238 <row topline="true" bottomline="true">
26239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26242 \begin_layout Standard
26248 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26251 \begin_layout Standard
26258 <row topline="true">
26259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26262 \begin_layout Standard
26268 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26271 \begin_layout Standard
26272 Port identification
26278 <row topline="true">
26279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26282 \begin_layout Standard
26287 \begin_layout Standard
26301 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26304 \begin_layout Standard
26305 Port identification (same as above)
26311 <row topline="true">
26312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26315 \begin_layout Standard
26321 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26324 \begin_layout Standard
26325 MCU Identification.
26330 is the microcontrol identification number, i.e.
26337 <row topline="true">
26338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26341 \begin_layout Standard
26346 \begin_layout Standard
26360 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26363 \begin_layout Standard
26364 MCU Identification (same as above)
26370 <row topline="true" bottomline="true">
26371 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26374 \begin_layout Standard
26380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26383 \begin_layout Standard
26384 nnn = SMALL or LARGE respectively according to the stack model used
26397 \begin_layout Standard
26399 In addition the following macros are defined when calling assembler:
26402 \begin_layout Standard
26404 \begin_inset Tabular
26405 <lyxtabular version="3" rows="4" columns="2">
26407 <column alignment="center" valignment="top" leftline="true" width="0">
26408 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26409 <row topline="true" bottomline="true">
26410 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26413 \begin_layout Standard
26419 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26422 \begin_layout Standard
26429 <row topline="true">
26430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26433 \begin_layout Standard
26439 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26442 \begin_layout Standard
26443 MCU Identification.
26448 is the microcontrol identification number, i.e.
26455 <row topline="true">
26456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26459 \begin_layout Standard
26465 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26468 \begin_layout Standard
26469 nnn = SMALL or LARGE respectively according to the memory model used for
26476 <row topline="true" bottomline="true">
26477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26480 \begin_layout Standard
26486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26489 \begin_layout Standard
26490 nnn = SMALL or LARGE respectively according to the stack model used
26503 \begin_layout Subsection
26507 \begin_layout Standard
26509 \begin_inset LatexCommand index
26514 port uses the following directories for searching header files and libraries.
26517 \begin_layout Standard
26519 \begin_inset Tabular
26520 <lyxtabular version="3" rows="3" columns="4">
26522 <column alignment="center" valignment="top" leftline="true" width="0">
26523 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26524 <column alignment="center" valignment="top" width="0">
26525 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
26526 <row topline="true" bottomline="true">
26527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26530 \begin_layout Standard
26536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26539 \begin_layout Standard
26545 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26548 \begin_layout Standard
26554 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26557 \begin_layout Standard
26564 <row topline="true">
26565 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26568 \begin_layout Standard
26569 PREFIX/sdcc/include/pic16
26574 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26577 \begin_layout Standard
26578 PIC16 specific headers
26583 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26586 \begin_layout Standard
26592 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26595 \begin_layout Standard
26602 <row topline="true" bottomline="true">
26603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26606 \begin_layout Standard
26607 PREFIX/sdcc/lib/pic16
26612 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26615 \begin_layout Standard
26616 PIC16 specific libraries
26621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26624 \begin_layout Standard
26630 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26633 \begin_layout Standard
26647 \begin_layout Subsection
26649 \begin_inset LatexCommand label
26650 name "sub:PIC16_Pragmas"
26657 \begin_layout Standard
26659 \begin_inset LatexCommand index
26664 port currently supports the following pragmas:
26667 \begin_layout Description
26669 \begin_inset LatexCommand index
26670 name "PIC16!Pragmas!\\#pragma stack"
26674 This forces the code generator to initialize the stack & frame pointers
26675 at a specific address.
26676 This is an ad hoc solution for cases where no STACK directive is available
26677 in the linker script or gplink is not instructed to create a stack section.
26680 stack pragma should be used only once in a project.
26681 Multiple pragmas may result in indeterminate behaviour of the program.
26685 \begin_layout Standard
26686 The old format (ie.
26687 #pragma stack 0x5ff) is deprecated and will cause the stack pointer to
26688 cross page boundaries (or even exceed the available data RAM) and crash
26690 Make sure that stack does not cross page boundaries when using the SMALL
26698 The format is as follows:
26703 \begin_layout LyX-Code
26704 #pragma stack bottom_address [stack_size]
26709 \begin_layout Standard
26714 is the lower bound of the stack section.
26715 The stack pointer initially will point at address (bottom_address+stack_size-1).
26718 \begin_layout LyX-Code
26722 \begin_layout LyX-Code
26726 \begin_layout LyX-Code
26727 /* initializes stack of 100 bytes at RAM address 0x200 */
26730 \begin_layout LyX-Code
26731 #pragma stack 0x200 100
26734 \begin_layout Standard
26735 If the stack_size field is omitted then a stack is created with the default
26737 This size might be enough for most programs, but its not enough for operations
26738 with deep function nesting or excessive stack usage.
26741 \begin_layout Description
26743 \begin_inset LatexCommand index
26744 name "PIC16!Pragmas!\\#pragma code"
26748 Force a function to a static FLASH address.
26751 \begin_layout LyX-Code
26755 \begin_layout LyX-Code
26759 \begin_layout LyX-Code
26760 /* place function test_func at 0x4000 */
26763 \begin_layout LyX-Code
26764 #pragma code test_func 0x4000
26767 \begin_layout LyX-Code
26771 \begin_layout Description
26772 library instructs the linker to use a library module.
26777 \begin_layout LyX-Code
26778 #pragma library module_name
26781 \begin_layout Standard
26786 can be any library or object file (including its path).
26787 Note that there are four reserved keywords which have special meaning.
26791 \begin_layout Standard
26793 \begin_inset Tabular
26794 <lyxtabular version="3" rows="6" columns="3">
26796 <column alignment="center" valignment="top" leftline="true" width="0">
26797 <column alignment="block" valignment="top" leftline="true" width="20page%">
26798 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
26799 <row topline="true" bottomline="true">
26800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26803 \begin_layout Standard
26809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26812 \begin_layout Standard
26818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26821 \begin_layout Standard
26828 <row topline="true">
26829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26832 \begin_layout Standard
26840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26843 \begin_layout Standard
26844 ignore all library pragmas
26849 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26852 \begin_layout Standard
26861 <row topline="true">
26862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26865 \begin_layout Standard
26873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26876 \begin_layout Standard
26882 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26885 \begin_layout Standard
26896 <row topline="true">
26897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26900 \begin_layout Standard
26908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26911 \begin_layout Standard
26912 link the Math libarary
26917 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26920 \begin_layout Standard
26931 <row topline="true">
26932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26935 \begin_layout Standard
26943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26946 \begin_layout Standard
26947 link the I/O library
26952 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26955 \begin_layout Standard
26966 <row topline="true" bottomline="true">
26967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26970 \begin_layout Standard
26978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
26981 \begin_layout Standard
26982 link the debug library
26987 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
26990 \begin_layout Standard
27007 * is the device number, i.e.
27008 452 for PIC18F452 MCU.
27011 \begin_layout Standard
27013 This feature allows for linking with specific libraries without having to
27014 explicit name them in the command line.
27019 keyword will reject all modules specified by the library pragma.
27022 \begin_layout Description
27023 udata The pragma udata instructs the compiler to emit code so that linker
27024 will place a variable at a specific memory bank.
27027 \begin_layout LyX-Code
27031 \begin_layout LyX-Code
27035 \begin_layout LyX-Code
27036 /* places variable foo at bank2 */
27039 \begin_layout LyX-Code
27040 #pragma udata bank2 foo
27043 \begin_layout LyX-Code
27047 \begin_layout Standard
27048 In order for this pragma to work extra SECTION directives should be added
27049 in the .lkr script.
27050 In the following example a sample .lkr file is shown:
27053 \begin_layout LyX-Code
27057 \begin_layout LyX-Code
27058 // Sample linker script for the PIC18F452 processor
27061 \begin_layout LyX-Code
27065 \begin_layout LyX-Code
27066 CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED
27069 \begin_layout LyX-Code
27070 CODEPAGE NAME=page START=0x2A END=0x7FFF
27073 \begin_layout LyX-Code
27074 CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED
27077 \begin_layout LyX-Code
27078 CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED
27081 \begin_layout LyX-Code
27082 CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED
27085 \begin_layout LyX-Code
27086 CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED
27089 \begin_layout LyX-Code
27090 ACCESSBANK NAME=accessram START=0x0 END=0x7F
27093 \begin_layout LyX-Code
27097 \begin_layout LyX-Code
27098 DATABANK NAME=gpr0 START=0x80 END=0xFF
27101 \begin_layout LyX-Code
27102 DATABANK NAME=gpr1 START=0x100 END=0x1FF
27105 \begin_layout LyX-Code
27106 DATABANK NAME=gpr2 START=0x200 END=0x2FF
27109 \begin_layout LyX-Code
27110 DATABANK NAME=gpr3 START=0x300 END=0x3FF
27113 \begin_layout LyX-Code
27114 DATABANK NAME=gpr4 START=0x400 END=0x4FF
27117 \begin_layout LyX-Code
27118 DATABANK NAME=gpr5 START=0x500 END=0x5FF
27121 \begin_layout LyX-Code
27122 ACCESSBANK NAME=accesssfr START=0xF80 END=0xFFF PROTECTED
27125 \begin_layout LyX-Code
27129 \begin_layout LyX-Code
27130 SECTION NAME=CONFIG ROM=config
27133 \begin_layout LyX-Code
27137 \begin_layout LyX-Code
27138 SECTION NAME=bank0 RAM=gpr0 # these SECTION directives
27141 \begin_layout LyX-Code
27142 SECTION NAME=bank1 RAM=gpr1 # should be added to link
27145 \begin_layout LyX-Code
27146 SECTION NAME=bank2 RAM=gpr2 # section name 'bank?' with
27149 \begin_layout LyX-Code
27150 SECTION NAME=bank3 RAM=gpr3 # a specific DATABANK name
27153 \begin_layout LyX-Code
27154 SECTION NAME=bank4 RAM=gpr4
27157 \begin_layout LyX-Code
27158 SECTION NAME=bank5 RAM=gpr5
27161 \begin_layout Standard
27162 The linker will recognise the section name set in the pragma statement and
27163 will position the variable at the memory bank set with the RAM field at
27164 the SECTION line in the linker script file.
27167 \begin_layout Subsection
27169 \begin_inset LatexCommand label
27170 name "sub:PIC16_Header-Files"
27177 \begin_layout Standard
27178 There is one main header file
27179 \begin_inset LatexCommand index
27180 name "PIC16!Header files"
27184 that can be included to the source files using the pic16
27185 \begin_inset LatexCommand index
27196 This header file contains the definitions for the processor special registers,
27197 so it is necessary if the source accesses them.
27198 It can be included by adding the following line in the beginning of the
27202 \begin_layout LyX-Code
27203 #include <pic18fregs.h>
27206 \begin_layout Standard
27207 The specific microcontroller is selected within the pic18fregs.h automatically,
27208 so the same source can be used with a variety of devices.
27211 \begin_layout Subsection
27213 \begin_inset LatexCommand label
27214 name "sub:pic16Libraries"
27221 \begin_layout Standard
27223 \begin_inset LatexCommand index
27224 name "PIC16!Libraries"
27229 \begin_inset LatexCommand index
27234 port depends on are the microcontroller device libraries which contain
27235 the symbol definitions for the microcontroller special function registers.
27236 These libraries have the format pic18fxxxx.lib, where
27240 is the microcontroller identification number.
27241 The specific library is selected automatically by the compiler at link
27242 stage according to the selected device.
27245 \begin_layout Standard
27247 Libraries are created with gplib which is part of the gputils package
27248 \begin_inset LatexCommand url
27249 target "http://sourceforge.net/projects/gputils"
27256 \begin_layout Subsubsection*
27257 Building the libraries
27260 \begin_layout Standard
27261 Before using SDCC/pic16 there are some libraries that need to be compiled.
27262 This process is done automatically if gputils are found at SDCC's compile
27264 Should you require to rebuild the pic16 libraries manually (e.g.
27265 in order to enable output of float values
27266 \begin_inset LatexCommand index
27267 name "Floating point support"
27275 , see below), these are the steps required to do so under Linux or Mac OS
27276 X (cygwin might work as well, but is untested):
27279 \begin_layout LyX-Code
27280 cd device/lib/pic16
27283 \begin_layout LyX-Code
27287 \begin_layout LyX-Code
27291 \begin_layout LyX-Code
27295 \begin_layout LyX-Code
27296 su -c 'make install' # install the libraries, you need the root password
27299 \begin_layout LyX-Code
27303 \begin_layout Standard
27304 If you need to install the headers too, do:
27307 \begin_layout LyX-Code
27311 \begin_layout LyX-Code
27312 su -c 'make install' # install the headers, you need the root password
27315 \begin_layout Subsubsection*
27316 Output of float values via printf()
27319 \begin_layout Standard
27320 The library is normally built without support for displaying float values,
27321 only <NO FLOAT> will appear instead of the value.
27322 To change this, rebuild the library as stated above, but call
27324 ./configure.gnu --enable-floats
27331 Also make sure that at least
27333 libc/stdio/vfprintf.c
27335 is actually recompiled, e.g.
27344 run or deleting its
27351 \begin_layout Standard
27352 The more common appraoch of compiling
27360 should also work, but is untested.
27363 \begin_layout Subsection
27364 Adding New Devices to the Port
27367 \begin_layout Standard
27368 Adding support for a new 16
27372 \begin_layout Standard
27381 bit PIC MCU requires the following steps:
27384 \begin_layout Enumerate
27385 Create picDEVICE.c and picDEVICE.h from pDEVICE.inc using
27389 perl /path/to/sdcc/support/scripts/inc2h-pic16.pl /path/to/gputils/header/pDEVICE.
27393 \begin_layout Enumerate
27396 mv picDEVICE.h /path/to/sdcc/device/include/pic16
27399 \begin_layout Enumerate
27402 mv picDEVICE.c /path/to/sdcc/device/lib/pic16/libdev
27405 \begin_layout Enumerate
27408 /path/to/sdcc/device/lib/pic16/pics.all
27412 Note: No 18f prefix here!
27415 \begin_layout Enumerate
27418 /path/to/sdcc/device/include/pic16/adc.h
27422 Add the new devices to the correct ADC style class (depending on the number
27429 if the device does not offer any ADC at all.
27432 \begin_layout Enumerate
27435 /path/to/sdcc/device/include/pic16/pic18fregs.h
27439 The file format is self-explanatory, just add
27443 #elif defined(picDEVICE)
27449 \begin_layout Standard
27460 include <picDEVICE.h>
27464 at the right place (keep the file sorted, please).
27467 \begin_layout Enumerate
27470 /path/to/sdcc/device/include/pic16devices.txt
27474 Copy and modify an existing entry or create a new one and insert it at the
27475 correct place (keep the file sorted, please).
27478 \begin_layout Enumerate
27481 /path/to/sdcc/device/lib/pic16/libdev/Makefile.am
27485 Copy an existing entry and adjust the device name.
27488 \begin_layout Enumerate
27491 /path/to/sdcc/device/lib/pic16/libio/Makefile.am
27495 Copy the record from the 18f2220 and adjust the device name.
27498 does not offer ADC, I
27499 \begin_inset Formula $^{\text{2}}$
27502 C, and/or (E)USART functionality as assumed by the library, remove the lines
27518 \begin_layout Enumerate
27537 /path/to/sdcc/device/lib/pic16
27542 \begin_layout Enumerate
27543 Recompile the pic16 libraries as described in
27544 \begin_inset LatexCommand ref
27545 reference "sub:pic16Libraries"
27552 \begin_layout Subsection
27556 \begin_layout Standard
27557 The following memory models are supported by the PIC16 port:
27560 \begin_layout Itemize
27564 \begin_layout Itemize
27568 \begin_layout Standard
27569 Memory model affects the default size of pointers within the source.
27570 The sizes are shown in the next table:
27573 \begin_layout Standard
27575 \begin_inset Tabular
27576 <lyxtabular version="3" rows="3" columns="3">
27578 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27579 <column alignment="center" valignment="top" leftline="true" width="0">
27580 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27581 <row topline="true" bottomline="true">
27582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27585 \begin_layout Standard
27586 Pointer sizes according to memory model
27591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27594 \begin_layout Standard
27600 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27603 \begin_layout Standard
27610 <row topline="true" bottomline="true">
27611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27614 \begin_layout Standard
27620 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27623 \begin_layout Standard
27629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27632 \begin_layout Standard
27639 <row topline="true" bottomline="true">
27640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27643 \begin_layout Standard
27649 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
27652 \begin_layout Standard
27658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
27661 \begin_layout Standard
27675 \begin_layout Standard
27676 It is advisable that all sources within a project are compiled with the
27678 If one wants to override the default memory model, this can be done by
27679 declaring a pointer as
27688 Far selects large memory model's pointers, while near selects small memory
27692 \begin_layout Standard
27693 The standard device libraries (see
27694 \begin_inset LatexCommand ref
27695 reference "sub:PIC16_Header-Files"
27699 ) contain no reference to pointers, so they can be used with both memory
27703 \begin_layout Subsection
27707 \begin_layout Standard
27709 \begin_inset LatexCommand index
27714 implementation for the PIC16 port uses two indirect registers, FSR1 and
27718 \begin_layout Description
27719 FSR1 is assigned as stack pointer
27722 \begin_layout Description
27723 FSR2 is assigned as frame pointer
27726 \begin_layout Standard
27727 The following stack models are supported by the PIC16 port
27730 \begin_layout Itemize
27738 \begin_layout Itemize
27746 \begin_layout Standard
27751 model means that only the FSRxL byte is used to access stack and frame,
27758 uses both FSRxL and FSRxH registers.
27759 The following table shows the stack/frame pointers sizes according to stack
27760 model and the maximum space they can address:
27763 \begin_layout Standard
27765 \begin_inset Tabular
27766 <lyxtabular version="3" rows="3" columns="3">
27768 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27769 <column alignment="center" valignment="top" leftline="true" width="0">
27770 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
27771 <row topline="true" bottomline="true">
27772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27775 \begin_layout Standard
27776 Stack & Frame pointer sizes according to stack model
27781 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27784 \begin_layout Standard
27790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27793 \begin_layout Standard
27800 <row topline="true">
27801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27804 \begin_layout Standard
27810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27813 \begin_layout Standard
27819 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27822 \begin_layout Standard
27829 <row topline="true" bottomline="true">
27830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27833 \begin_layout Standard
27839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27842 \begin_layout Standard
27848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
27851 \begin_layout Standard
27865 \begin_layout Standard
27871 stack model is currently not working properly throughout the code generator.
27872 So its use is not advised.
27873 Also there are some other points that need special care:
27878 \begin_layout Enumerate
27879 Do not create stack sections with size more than one physical bank (that
27883 \begin_layout Enumerate
27884 Stack sections should no cross physical bank limits (i.e.
27885 #pragma stack 0x50 0x100)
27888 \begin_layout Standard
27889 These limitations are caused by the fact that only FSRxL is modified when
27890 using SMALL stack model, so no more than 256 bytes of stack can be used.
27891 This problem will disappear after LARGE model is fully implemented.
27894 \begin_layout Subsection
27898 \begin_layout Standard
27899 In addition to the standard SDCC function keywords, PIC16
27900 \begin_inset LatexCommand index
27905 port makes available two more:
27908 \begin_layout Description
27910 \begin_inset LatexCommand index
27911 name "PIC16!wparam"
27915 Use the WREG to pass one byte of the first function argument.
27916 This improves speed but you may not use this for functions with arguments
27917 that are called via function pointers, otherwise the first byte of the
27918 first parameter will get lost.
27922 \begin_layout LyX-Code
27923 void func_wparam(int a) wparam
27926 \begin_layout LyX-Code
27930 \begin_layout LyX-Code
27931 /* WREG hold the lower part of a */
27934 \begin_layout LyX-Code
27935 /* the high part of a is stored in FSR2+2 (or +3 for large stack model)
27939 \begin_layout LyX-Code
27943 \begin_layout LyX-Code
27947 \begin_layout Description
27949 \begin_inset LatexCommand index
27950 name "PIC16!shadowregs"
27954 When entering/exiting an ISR, it is possible to take advantage of the PIC18F
27955 hardware shadow registers which hold the values of WREG, STATUS and BSR
27957 This can be done by adding the keyword
27965 keyword in the function's header.
27968 \begin_layout LyX-Code
27969 void isr_shadow(void) shadowregs interrupt 1
27972 \begin_layout LyX-Code
27976 \begin_layout LyX-Code
27980 \begin_layout LyX-Code
27984 \begin_layout Standard
27989 instructs the code generator not to store/restore WREG, STATUS, BSR when
27990 entering/exiting the ISR.
27993 \begin_layout Subsection
27994 Function return values
27997 \begin_layout Standard
27998 Return values from functions are placed to the appropriate registers following
27999 a modified Microchip policy optimized for SDCC.
28000 The following table shows these registers:
28003 \begin_layout Standard
28005 \begin_inset Tabular
28006 <lyxtabular version="3" rows="6" columns="2">
28008 <column alignment="center" valignment="top" leftline="true" width="0">
28009 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28010 <row topline="true" bottomline="true">
28011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28014 \begin_layout Standard
28020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28023 \begin_layout Standard
28024 destination register
28030 <row topline="true">
28031 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28034 \begin_layout Standard
28040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28043 \begin_layout Standard
28050 <row topline="true">
28051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28054 \begin_layout Standard
28060 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28063 \begin_layout Standard
28070 <row topline="true">
28071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28074 \begin_layout Standard
28080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28083 \begin_layout Standard
28090 <row topline="true">
28091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28094 \begin_layout Standard
28100 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28103 \begin_layout Standard
28104 FSR0L:PRODH:PRODL:WREG
28110 <row topline="true" bottomline="true">
28111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28114 \begin_layout Standard
28120 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28123 \begin_layout Standard
28124 on stack, FSR0 points to the beginning
28137 \begin_layout Subsection
28141 \begin_layout Standard
28143 \begin_inset LatexCommand index
28144 name "PIC16!interrupt"
28148 service routine (ISR) is declared using the
28155 \begin_layout LyX-Code
28156 void isr(void) interrupt
28161 \begin_layout LyX-Code
28165 \begin_layout LyX-Code
28169 \begin_layout LyX-Code
28173 \begin_layout Standard
28178 is the interrupt number, which for PIC18F devices can be:
28181 \begin_layout Standard
28183 \begin_inset Tabular
28184 <lyxtabular version="3" rows="4" columns="3">
28186 <column alignment="center" valignment="top" leftline="true" width="0">
28187 <column alignment="center" valignment="top" leftline="true" width="0">
28188 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28189 <row topline="true" bottomline="true">
28190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28193 \begin_layout Standard
28201 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28204 \begin_layout Standard
28210 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28213 \begin_layout Standard
28214 Interrupt Vector Address
28220 <row topline="true">
28221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28224 \begin_layout Standard
28230 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28233 \begin_layout Standard
28239 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28242 \begin_layout Standard
28249 <row topline="true">
28250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28253 \begin_layout Standard
28268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28271 \begin_layout Standard
28281 HIGH priority interrupts
28286 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28289 \begin_layout Standard
28296 <row topline="true" bottomline="true">
28297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28300 \begin_layout Standard
28306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28309 \begin_layout Standard
28310 LOW priority interrupts
28315 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28318 \begin_layout Standard
28332 \begin_layout Standard
28333 When generating assembly code for ISR the code generator places a
28339 Interrupt Vector Address
28341 which points at the generated ISR.
28342 This single GOTO instruction is part of an automatically generated
28344 interrupt entry point
28347 The actuall ISR code is placed as normally would in the code space.
28348 Upon interrupt request, the GOTO instruction is executed which jumps to
28350 When declaring interrupt functions as _naked this GOTO instruction is
28355 The whole interrupt functions is therefore placed at the Interrupt Vector
28356 Address of the specific interrupt.
28357 This is not a problem for the LOW priority interrupts, but it is a problem
28358 for the RESET and the HIGH priority interrupts because code may be written
28359 at the next interrupt's vector address and cause indeterminate program
28360 behaviour if that interrupt is raised.
28364 \begin_layout Standard
28365 This is not a problem when
28368 \begin_layout Enumerate
28369 this is a HIGH interrupt ISR and LOW interrupts are
28376 \begin_layout Enumerate
28377 when the ISR is small enough not to reach the next interrupt's vector address.
28385 \begin_layout Standard
28391 This way a function is generated similar to an ISR, but it is not assigned
28395 \begin_layout Standard
28396 When entering an interrupt, currently the PIC16
28397 \begin_inset LatexCommand index
28402 port automatically saves the following registers:
28405 \begin_layout Itemize
28409 \begin_layout Itemize
28413 \begin_layout Itemize
28417 \begin_layout Itemize
28418 PROD (PRODL and PRODH)
28421 \begin_layout Itemize
28422 FSR0 (FSR0L and FSR0H)
28425 \begin_layout Standard
28426 These registers are restored upon return from the interrupt routine.
28430 \begin_layout Standard
28431 NOTE that when the _naked attribute is specified for an interrupt routine,
28432 then NO registers are stored or restored.
28440 \begin_layout Subsection
28444 \begin_layout Standard
28445 Generic pointers are implemented in PIC16 port as 3-byte (24-bit) types.
28446 There are 3 types of generic pointers currently implemented data, code
28447 and eeprom pointers.
28448 They are differentiated by the value of the 7th and 6th bits of the upper
28452 \begin_layout Standard
28454 \begin_inset Tabular
28455 <lyxtabular version="3" rows="5" columns="5">
28457 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28458 <column alignment="center" valignment="top" width="0">
28459 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28460 <column alignment="center" valignment="top" width="0">
28461 <column alignment="left" valignment="top" rightline="true" width="0">
28462 <row topline="true" bottomline="true">
28463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28466 \begin_layout Standard
28472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28475 \begin_layout Standard
28481 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28484 \begin_layout Standard
28490 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28493 \begin_layout Standard
28494 rest of the pointer
28499 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28502 \begin_layout Standard
28509 <row topline="true" bottomline="true">
28510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28513 \begin_layout Standard
28519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28522 \begin_layout Standard
28528 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28531 \begin_layout Standard
28537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28540 \begin_layout Standard
28545 uuuuuu uuuuxxxx xxxxxxxx
28550 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28553 \begin_layout Standard
28554 a 12-bit data pointer in data RAM memory
28560 <row bottomline="true">
28561 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28564 \begin_layout Standard
28570 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28573 \begin_layout Standard
28579 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28582 \begin_layout Standard
28588 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28591 \begin_layout Standard
28596 uxxxxx xxxxxxxx xxxxxxxx
28601 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28604 \begin_layout Standard
28605 a 21-bit code pointer in FLASH memory
28611 <row bottomline="true">
28612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28615 \begin_layout Standard
28621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28624 \begin_layout Standard
28630 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28633 \begin_layout Standard
28639 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28642 \begin_layout Standard
28647 uuuuuu uuuuuuxx xxxxxxxx
28652 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28655 \begin_layout Standard
28656 a 10-bit eeprom pointer in EEPROM memory
28662 <row bottomline="true">
28663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28666 \begin_layout Standard
28672 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28675 \begin_layout Standard
28681 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28684 \begin_layout Standard
28690 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28693 \begin_layout Standard
28698 xxxxxx xxxxxxxx xxxxxxxx
28703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28706 \begin_layout Standard
28707 unimplemented pointer type
28720 \begin_layout Standard
28722 Generic pointer are read and written with a set of library functions which
28723 read/write 1, 2, 3, 4 bytes.
28726 \begin_layout Subsection
28730 \begin_layout Subsubsection
28731 Standard I/O Streams
28734 \begin_layout Standard
28739 the type FILE is defined as:
28742 \begin_layout LyX-Code
28743 typedef char * FILE;
28746 \begin_layout Standard
28747 This type is the stream type implemented I/O in the PIC18F devices.
28748 Also the standard input and output streams are declared in stdio.h:
28751 \begin_layout LyX-Code
28752 extern FILE * stdin;
28755 \begin_layout LyX-Code
28756 extern FILE * stdout;
28759 \begin_layout Standard
28760 The FILE type is actually a generic pointer which defines one more type
28761 of generic pointers, the
28766 This new type has the format:
28769 \begin_layout Standard
28772 \begin_inset Tabular
28773 <lyxtabular version="3" rows="2" columns="7">
28775 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28776 <column alignment="center" valignment="top" width="0">
28777 <column alignment="center" valignment="top" leftline="true" width="0">
28778 <column alignment="center" valignment="top" leftline="true" width="0">
28779 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28780 <column alignment="center" valignment="top" width="0">
28781 <column alignment="left" valignment="top" rightline="true" width="0">
28782 <row topline="true" bottomline="true">
28783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28786 \begin_layout Standard
28792 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28795 \begin_layout Standard
28801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28804 \begin_layout Standard
28810 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28813 \begin_layout Standard
28819 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28822 \begin_layout Standard
28828 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28831 \begin_layout Standard
28832 rest of the pointer
28837 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28840 \begin_layout Standard
28847 <row topline="true" bottomline="true">
28848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28851 \begin_layout Standard
28857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28860 \begin_layout Standard
28866 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28869 \begin_layout Standard
28875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28878 \begin_layout Standard
28884 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28887 \begin_layout Standard
28893 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28896 \begin_layout Standard
28906 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28909 \begin_layout Standard
28910 upper byte high nubble is 0x2n, the rest are zeroes
28923 \begin_layout Standard
28925 Currently implemented there are 3 types of streams defined:
28928 \begin_layout Standard
28931 \begin_inset Tabular
28932 <lyxtabular version="3" rows="4" columns="4">
28934 <column alignment="center" valignment="top" leftline="true" width="0">
28935 <column alignment="center" valignment="top" leftline="true" width="0">
28936 <column alignment="center" valignment="top" leftline="true" width="0">
28937 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
28938 <row topline="true" bottomline="true">
28939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28942 \begin_layout Standard
28948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28951 \begin_layout Standard
28957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28960 \begin_layout Standard
28966 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
28969 \begin_layout Standard
28976 <row topline="true">
28977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28980 \begin_layout Standard
28986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
28989 \begin_layout Standard
28997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29000 \begin_layout Standard
29006 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29009 \begin_layout Standard
29010 Writes/Reads characters via the USART peripheral
29016 <row topline="true">
29017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29020 \begin_layout Standard
29026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29029 \begin_layout Standard
29037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29040 \begin_layout Standard
29046 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29049 \begin_layout Standard
29050 Writes/Reads characters via the MSSP peripheral
29056 <row topline="true" bottomline="true">
29057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29060 \begin_layout Standard
29066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29069 \begin_layout Standard
29077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29080 \begin_layout Standard
29086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29089 \begin_layout Standard
29090 Writes/Reads characters via used defined functions
29103 \begin_layout Standard
29105 The stream identifiers are declared as macros in the stdio.h header.
29108 \begin_layout Standard
29110 In the libc library there exist the functions that are used to write to
29111 each of the above streams.
29115 \begin_layout Description
29120 \begin_layout Standard
29129 _stream_usart_putchar writes a character at the USART stream
29132 \begin_layout Description
29137 \begin_layout Standard
29146 _stream_mssp_putchar writes a character at the MSSP stream
29149 \begin_layout Description
29150 putchar dummy function.
29151 This writes a character to a user specified manner.
29154 \begin_layout Standard
29155 In order to increase performance
29159 is declared in stdio.h as having its parameter in WREG (it has the wparam
29161 In stdio.h exists the macro PUTCHAR(arg) that defines the putchar function
29162 in a user-friendly way.
29167 is the name of the variable that holds the character to print.
29168 An example follows:
29171 \begin_layout LyX-Code
29172 #include <pic18fregs.h>
29181 \begin_layout LyX-Code
29185 \begin_layout LyX-Code
29186 PORTA = c; /* dump character c to PORTA */
29189 \begin_layout LyX-Code
29197 \begin_layout LyX-Code
29201 \begin_layout LyX-Code
29202 stdout = STREAM_USER; /* this is not necessary, since stdout points
29205 \begin_layout LyX-Code
29206 * by default to STREAM_USER */
29209 \begin_layout LyX-Code
29211 \begin_inset Quotes sld
29214 This is a printf test
29217 \begin_inset Quotes srd
29223 \begin_layout LyX-Code
29227 \begin_layout LyX-Code
29231 \begin_layout Subsubsection
29235 \begin_layout Standard
29236 PIC16 contains an implementation of the printf-family of functions.
29237 There exist the following functions:
29240 \begin_layout LyX-Code
29241 extern unsigned int sprintf(char *buf, char *fmt, ...);
29244 \begin_layout LyX-Code
29245 extern unsigned int vsprintf(char *buf, char *fmt, va_list ap);
29248 \begin_layout LyX-Code
29252 \begin_layout LyX-Code
29253 extern unsigned int printf(char *fmt, ...);
29256 \begin_layout LyX-Code
29257 extern unsigned int vprintf(char *fmt, va_lista ap);
29260 \begin_layout LyX-Code
29264 \begin_layout LyX-Code
29265 extern unsigned int fprintf(FILE *fp, char *fmt, ...);
29268 \begin_layout LyX-Code
29269 extern unsigned int vfprintf(FILE *fp, char *fmt, va_list ap);
29272 \begin_layout Standard
29273 For sprintf and vsprintf
29277 should normally be a data pointer where the resulting string will be placed.
29278 No range checking is done so the user should allocate the necessary buffer.
29279 For fprintf and vfprintf
29283 should be a stream pointer (i.e.
29284 stdout, STREAM_MSSP, etc...).
29287 \begin_layout Subsubsection
29291 \begin_layout Standard
29292 The PIC18F family of microcontrollers supports a number of interrupt sources.
29293 A list of these interrupts is shown in the following table:
29296 \begin_layout Standard
29298 \begin_inset Tabular
29299 <lyxtabular version="3" rows="11" columns="4">
29301 <column alignment="left" valignment="top" leftline="true" width="0">
29302 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29303 <column alignment="left" valignment="top" leftline="true" width="0">
29304 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
29305 <row topline="true" bottomline="true">
29306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29309 \begin_layout Standard
29315 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29318 \begin_layout Standard
29324 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29327 \begin_layout Standard
29333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29336 \begin_layout Standard
29343 <row topline="true">
29344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29347 \begin_layout Standard
29353 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29356 \begin_layout Standard
29357 PORTB change interrupt
29362 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29365 \begin_layout Standard
29371 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29374 \begin_layout Standard
29375 EEPROM/FLASH write complete interrupt
29381 <row topline="true">
29382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29385 \begin_layout Standard
29391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29394 \begin_layout Standard
29395 INT0 external interrupt
29400 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29403 \begin_layout Standard
29409 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29412 \begin_layout Standard
29413 Bus collision interrupt
29419 <row topline="true">
29420 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29423 \begin_layout Standard
29429 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29432 \begin_layout Standard
29433 INT1 external interrupt
29438 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29441 \begin_layout Standard
29447 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29450 \begin_layout Standard
29451 Low voltage detect interrupt
29457 <row topline="true">
29458 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29461 \begin_layout Standard
29467 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29470 \begin_layout Standard
29471 INT2 external interrupt
29476 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29479 \begin_layout Standard
29485 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29488 \begin_layout Standard
29489 Parallel slave port interrupt
29495 <row topline="true">
29496 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29499 \begin_layout Standard
29505 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29508 \begin_layout Standard
29509 CCP1 module interrupt
29514 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29517 \begin_layout Standard
29523 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29526 \begin_layout Standard
29527 AD convertion complete interrupt
29533 <row topline="true">
29534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29537 \begin_layout Standard
29543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29546 \begin_layout Standard
29547 CCP2 module interrupt
29552 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29555 \begin_layout Standard
29561 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29564 \begin_layout Standard
29565 USART receive interrupt
29571 <row topline="true">
29572 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29575 \begin_layout Standard
29581 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29584 \begin_layout Standard
29585 TMR0 overflow interrupt
29590 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29593 \begin_layout Standard
29599 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29602 \begin_layout Standard
29603 USART transmit interrupt
29609 <row topline="true">
29610 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29613 \begin_layout Standard
29619 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29622 \begin_layout Standard
29623 TMR1 overflow interrupt
29628 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29631 \begin_layout Standard
29637 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29640 \begin_layout Standard
29641 SSP receive/transmit interrupt
29647 <row topline="true">
29648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29651 \begin_layout Standard
29657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29660 \begin_layout Standard
29661 TMR2 matches PR2 interrupt
29666 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29669 \begin_layout Standard
29675 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29678 \begin_layout Standard
29685 <row topline="true" bottomline="true">
29686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
29689 \begin_layout Standard
29695 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29698 \begin_layout Standard
29699 TMR3 overflow interrupt
29704 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29707 \begin_layout Standard
29713 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
29716 \begin_layout Standard
29730 \begin_layout Standard
29732 The prototypes for these names are defined in the header file
29739 \begin_layout Standard
29741 In order to simplify signal handling, a number of macros is provided:
29745 \labelwidthstring 00.00.0000
29746 DEF_INTHIGH(name) begin the definition of the interrupt dispatch table for
29747 high priority interrupts.
29752 is the function name to use.
29756 \labelwidthstring 00.00.0000
29757 DEF_INTLOW(name) begin the definition of the interrupt dispatch table fo
29758 low priority interrupt.
29763 is the function name to use.
29767 \labelwidthstring 00.00.0000
29768 DEF_HANDLER(sig,handler) define a handler for signal
29774 \labelwidthstring 00.00.0000
29775 END_DEF end the declaration of the dispatch table.
29778 \begin_layout Standard
29779 Additionally there are two more macros to simplify the declaration of the
29784 \labelwidthstring 00.00.0000
29787 SIGHANDLER(handler)
29789 this declares the function prototype for the
29797 \labelwidthstring 00.00.0000
29798 SIGHANDLERNAKED(handler) same as SIGHANDLER() but declares a naked function.
29801 \begin_layout Standard
29802 An example of using the macros above is shown below:
29805 \begin_layout LyX-Code
29806 #include <pic18fregs.h>
29809 \begin_layout LyX-Code
29810 #include <signal.h>
29814 DEF_INTHIGH(high_int)
29817 \begin_layout LyX-Code
29818 DEF_HANDLER(SIG_TMR0, _tmr0_handler)
29821 \begin_layout LyX-Code
29822 DEF_HANDLER(SIG_BCOL, _bcol_handler)
29825 \begin_layout LyX-Code
29830 SIGHANDLER(_tmr0_handler)
29833 \begin_layout LyX-Code
29837 \begin_layout LyX-Code
29838 /* action to be taken when timer 0 overflows */
29841 \begin_layout LyX-Code
29846 SIGHANDLERNAKED(_bcol_handler)
29849 \begin_layout LyX-Code
29853 \begin_layout LyX-Code
29857 \begin_layout LyX-Code
29858 /* action to be taken when bus collision occurs */
29861 \begin_layout LyX-Code
29865 \begin_layout LyX-Code
29869 \begin_layout LyX-Code
29873 \begin_layout Standard
29878 Special care should be taken when using the above scheme:
29881 \begin_layout Itemize
29882 do not place a colon (;) at the end of the DEF_* and END_DEF macros.
29885 \begin_layout Itemize
29886 when declaring SIGHANDLERNAKED handler never forget to use
29890 for proper returning.
29893 \begin_layout Subsection
29897 \begin_layout Standard
29898 Here you can find some general tips for compiling programs with SDCC/pic16.
29901 \begin_layout Subsubsection
29905 \begin_layout Standard
29907 \begin_inset LatexCommand index
29912 size (that is 64 bytes) probably is enough for many programs.
29913 One must take care that when there are many levels of function nesting,
29914 or there is excessive usage of stack, its size should be extended.
29915 An example of such a case is the printf/sprintf family of functions.
29916 If you encounter problems like not being able to print integers, then you
29917 need to set the stack size around the maximum (256 for small stack model).
29918 The following diagram shows what happens when calling printf to print an
29922 \begin_layout LyX-Code
29923 printf () --> ltoa () --> ultoa () --> divschar ()
29926 \begin_layout Standard
29927 It is should be understood that stack is easily consumed when calling complicate
29929 Using command line arguments like -
29933 \begin_layout Standard
29942 -fommit-frame-pointer might reduce stack usage by not creating unnecessery
29944 Other ways to reduce stack usage may exist.
29947 \begin_layout Subsection
29951 \begin_layout Subsubsection
29952 Extended Instruction Set
29955 \begin_layout Standard
29956 The PIC16 port emits code which is incompatible with the extended instruction
29957 set available with many newer devices.
29958 Make sure to always explicitly disable it, usually using
29961 \begin_layout Standard
29964 static __code char __at(__CONFIG4L) conf4l = /* more flags & */ _XINST_OFF_4L;
29967 \begin_layout Standard
29969 Some devices (namely 18f2455, 18f2550, 18f4455, and 18f4550) use _ENHCPU_OFF_4L
29970 instead of _XINST_OFF_4L.
29973 \begin_layout Subsubsection
29977 \begin_layout Standard
29978 The PIC16 port currently passes most but not all of the tests in SDCC's
29980 \begin_inset LatexCommand index
29981 name "Regression test (PIC16)"
29986 \begin_inset LatexCommand ref
29987 reference "sec:Quality-control"
29991 ), thus no automatic regression tests are currently performed for the PIC16
29995 \begin_layout Chapter
29999 \begin_layout Standard
30000 There are several approaches to debugging your code.
30001 This chapter is meant to show your options and to give detail on some of
30006 When writing your code:
30009 \begin_layout Itemize
30010 write your code with debugging in mind (avoid duplicating code, put conceptually
30011 similar variables into structs, use structured code, have strategic points
30012 within your code where all variables are consistent, ...)
30015 \begin_layout Itemize
30016 run a syntax-checking tool like splint
30017 \begin_inset LatexCommand index
30018 name "splint (syntax checking tool)"
30023 \begin_inset LatexCommand index
30024 name "lint (syntax checking tool)"
30032 \begin_layout Standard
30042 \begin_inset LatexCommand ref
30043 reference "lyx:more-pedantic-SPLINT"
30050 \begin_layout Itemize
30051 for the high level code use a C-compiler (like f.e.
30052 GCC) to compile run and debug the code on your host.
30057 \begin_layout Standard
30067 \begin_inset LatexCommand ref
30068 reference "lyx:more-pedantic-SPLINT"
30072 ) on how to handle syntax extensions like __xdata, __at(), ...
30076 \begin_layout Itemize
30077 use another C-compiler to compile code for your target.
30078 Always an option but not recommended:) And not very likely to help you.
30079 If you seriously consider walking this path you should at least occasionally
30080 check portability of your code.
30081 Most commercial compiler vendors will offer an evaluation version so you
30082 can test compile your code or snippets of your code.
30085 \begin_layout Standard
30086 Debugging on a simulator:
30089 \begin_layout Itemize
30090 there is a separate section about SDCDB (section
30091 \begin_inset LatexCommand ref
30092 reference "cha:Debugging-with-SDCDB"
30099 \begin_layout Itemize
30100 or (8051 specific) use a freeware/commercial simulator which interfaces
30102 \begin_inset LatexCommand index
30103 name "AOMF, AOMF51"
30108 \begin_inset LatexCommand ref
30109 reference "OMF file"
30113 ) optionally generated by SDCC.
30116 \begin_layout Standard
30117 Debugging On-target:
30120 \begin_layout Itemize
30121 use a MCU port pin to serially output debug data to the RS232 port of your
30123 You'll probably want some level shifting device typically involving a MAX232
30125 If the hardware serial port of the MCU is not available search for 'Software
30126 UART' in your favourite search machine.
30129 \begin_layout Itemize
30130 use an on-target monitor.
30131 In this context a monitor is a small program which usually accepts commands
30132 via a serial line and allows to set program counter, to single step through
30133 a program and read/write memory locations.
30134 For the 8051 good examples of monitors are paulmon and cmon51 (see section
30136 \begin_inset LatexCommand ref
30137 reference "sec:Related-open-source-tools"
30144 \begin_layout Itemize
30145 toggle MCU port pins at strategic points within your code and use an oscilloscop
30149 digital oscilloscope
30152 \begin_inset LatexCommand index
30153 name "Oscilloscope"
30157 with deep trace memory is really helpful especially if you have to debug
30158 a realtime application.
30159 If you need to monitor more pins than your oscilloscope provides you can
30160 sometimes get away with a small R-2R network.
30161 On a single channel oscilloscope you could f.e.
30162 monitor 2 push-pull driven pins by connecting one via a 10\InsetSpace ~
30164 \begin_inset Formula $\Omega$
30167 resistor and the other one by a 5\InsetSpace ~
30169 \begin_inset Formula $\Omega$
30172 resistor to the oscilloscope probe (check output drive capability of the
30173 pins you want to monitor).
30174 If you need to monitor many more pins a
30181 \begin_layout Itemize
30195 \begin_inset LatexCommand index
30196 name "ICE (in circuit emulator)"
30201 Usually very expensive.
30202 And very nice to have too.
30203 And usually locks you (for years...) to the devices the ICE can emulate.
30207 \begin_layout Itemize
30208 use a remote debugger.
30209 In most 8-bit systems the symbol information is not available on the target,
30210 and a complete debugger is too bulky for the target system.
30211 Therefore usually a debugger on the host system connects to an on-target
30212 debugging stub which accepts only primitive commands.
30215 Terms to enter into your favourite search engine could be 'remote debugging',
30216 'gdb stub' or 'inferior debugger'.
30220 \begin_layout Itemize
30221 use an on target hardware debugger.
30222 Some of the more modern MCUs include hardware support for setting break
30223 points and monitoring/changing variables by using dedicated hardware pins.
30224 This facility doesn't require additional code to run on the target and
30229 doesn't affect runtime behaviour until a breakpoint is hit.
30230 For the mcs51 most hardware debuggers use the AOMF
30231 \begin_inset LatexCommand index
30232 name "AOMF, AOMF51"
30237 \begin_inset LatexCommand ref
30238 reference "OMF file"
30246 \begin_layout Standard
30250 \begin_layout Itemize
30251 if you are not familiar with any of the following terms you're likely to
30252 run into problems rather sooner than later:
30269 As an embedded programmer you
30273 to know them so why not look them up
30277 you have problems?)
30280 \begin_layout Itemize
30281 tell someone else about your problem (actually this is a surprisingly effective
30282 means to hunt down the bug even if the listener is not familiar with your
30284 As 'failure to communicate' is probably one of the job-induced deformations
30285 of an embedded programmer this is highly encouraged.
30288 \begin_layout Section
30289 Debugging with SDCDB
30290 \begin_inset LatexCommand label
30291 name "cha:Debugging-with-SDCDB"
30296 \begin_inset LatexCommand index
30297 name "SDCDB (debugger)"
30304 \begin_layout Standard
30305 SDCC is distributed with a source level debugger
30306 \begin_inset LatexCommand index
30312 The debugger uses a command line interface, the command repertoire of the
30313 debugger has been kept as close to gdb
30314 \begin_inset LatexCommand index
30319 (the GNU debugger) as possible.
30320 The configuration and build process is part of the standard compiler installati
30321 on, which also builds and installs the debugger in the target directory
30322 specified during configuration.
30323 The debugger allows you debug BOTH at the C source and at the ASM source
30327 \begin_layout Subsection
30328 Compiling for Debugging
30331 \begin_layout Standard
30336 \begin_layout Standard
30346 \begin_inset LatexCommand index
30351 option must be specified for all files for which debug information is to
30353 The compiler generates a .adb file for each of these files.
30354 The linker creates the .cdb
30355 \begin_inset LatexCommand index
30361 \begin_inset LatexCommand index
30366 files and the address information.
30367 This .cdb is used by the debugger.
30370 \begin_layout Subsection
30371 How the Debugger Works
30374 \begin_layout Standard
30379 \begin_layout Standard
30388 -debug option is specified the compiler generates extra symbol information
30389 some of which are put into the assembler source and some are put into the
30391 Then the linker creates the .cdb file from the individual .adb files with
30392 the address information for the symbols.
30393 The debugger reads the symbolic information generated by the compiler &
30394 the address information generated by the linker.
30395 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
30396 execution is controlled by the debugger.
30397 When a command is issued for the debugger, it translates it into appropriate
30398 commands for the simulator.
30399 (Currently SDCDM only connects to the simulator but
30404 \begin_inset LatexCommand url
30405 target "http://ec2drv.sf.net/"
30409 is an effort to connect directly to the hardware.)
30412 \begin_layout Subsection
30413 Starting the Debugger SDCDB
30416 \begin_layout Standard
30417 The debugger can be started using the following command line.
30418 (Assume the file you are debugging has the file name foo).
30432 The debugger will look for the following files.
30435 \begin_layout Itemize
30436 foo.c - the source file.
30439 \begin_layout Itemize
30440 foo.cdb - the debugger symbol information file.
30443 \begin_layout Itemize
30444 foo.ihx - the Intel hex format
30445 \begin_inset LatexCommand index
30446 name "Intel hex format"
30453 \begin_layout Subsection
30454 SDCDB Command Line Options
30457 \begin_layout Itemize
30462 \begin_layout Standard
30471 -directory=<source file directory> this option can used to specify the directory
30473 The debugger will look into the directory list specified for source, cdb
30475 The items in the directory list must be separated by ':', e.g.
30476 if the source files can be in the directories /home/src1 and /home/src2,
30481 \begin_layout Standard
30490 -directory option should be -
30494 \begin_layout Standard
30503 -directory=/home/src1:/home/src2.
30504 Note there can be no spaces in the option.
30508 \begin_layout Itemize
30509 -cd <directory> - change to the <directory>.
30512 \begin_layout Itemize
30513 -fullname - used by GUI front ends.
30516 \begin_layout Itemize
30517 -cpu <cpu-type> - this argument is passed to the simulator please see the
30518 simulator docs for details.
30521 \begin_layout Itemize
30522 -X <Clock frequency > this options is passed to the simulator please see
30523 the simulator docs for details.
30526 \begin_layout Itemize
30527 -s <serial port file> passed to simulator see the simulator docs for details.
30530 \begin_layout Itemize
30531 -S <serial in,out> passed to simulator see the simulator docs for details.
30534 \begin_layout Itemize
30535 -k <port number> passed to simulator see the simulator docs for details.
30538 \begin_layout Subsection
30539 SDCDB Debugger Commands
30542 \begin_layout Standard
30543 As mentioned earlier the command interface for the debugger has been deliberatel
30544 y kept as close the GNU debugger gdb, as possible.
30545 This will help the integration with existing graphical user interfaces
30546 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
30547 If you use a graphical user interface for the debugger you can skip this
30551 \begin_layout Subsubsection*
30552 break [line | file:line | function | file:function]
30555 \begin_layout Standard
30556 Set breakpoint at specified line or function:
30565 sdcdb>break foo.c:100
30567 sdcdb>break funcfoo
30569 sdcdb>break foo.c:funcfoo
30572 \begin_layout Subsubsection*
30573 clear [line | file:line | function | file:function ]
30576 \begin_layout Standard
30577 Clear breakpoint at specified line or function:
30586 sdcdb>clear foo.c:100
30588 sdcdb>clear funcfoo
30590 sdcdb>clear foo.c:funcfoo
30593 \begin_layout Subsubsection*
30597 \begin_layout Standard
30598 Continue program being debugged, after breakpoint.
30601 \begin_layout Subsubsection*
30605 \begin_layout Standard
30606 Execute till the end of the current function.
30609 \begin_layout Subsubsection*
30613 \begin_layout Standard
30614 Delete breakpoint number 'n'.
30615 If used without any option clear ALL user defined break points.
30618 \begin_layout Subsubsection*
30619 info [break | stack | frame | registers ]
30622 \begin_layout Itemize
30623 info break - list all breakpoints
30626 \begin_layout Itemize
30627 info stack - show the function call stack.
30630 \begin_layout Itemize
30631 info frame - show information about the current execution frame.
30634 \begin_layout Itemize
30635 info registers - show content of all registers.
30638 \begin_layout Subsubsection*
30642 \begin_layout Standard
30643 Step program until it reaches a different source line.
30644 Note: pressing <return> repeats the last command.
30647 \begin_layout Subsubsection*
30651 \begin_layout Standard
30652 Step program, proceeding through subroutine calls.
30655 \begin_layout Subsubsection*
30659 \begin_layout Standard
30660 Start debugged program.
30663 \begin_layout Subsubsection*
30667 \begin_layout Standard
30668 Print type information of the variable.
30671 \begin_layout Subsubsection*
30675 \begin_layout Standard
30676 print value of variable.
30679 \begin_layout Subsubsection*
30683 \begin_layout Standard
30684 load the given file name.
30685 Note this is an alternate method of loading file for debugging.
30688 \begin_layout Subsubsection*
30692 \begin_layout Standard
30693 print information about current frame.
30696 \begin_layout Subsubsection*
30700 \begin_layout Standard
30701 Toggle between C source & assembly source.
30704 \begin_layout Subsubsection*
30705 ! simulator command
30708 \begin_layout Standard
30709 Send the string following '!' to the simulator, the simulator response is
30711 Note the debugger does not interpret the command being sent to the simulator,
30712 so if a command like 'go' is sent the debugger can loose its execution
30713 context and may display incorrect values.
30716 \begin_layout Subsubsection*
30720 \begin_layout Standard
30723 My name is Bobby Brown"
30726 \begin_layout Subsection
30727 Interfacing SDCDB with DDD
30730 \begin_layout Standard
30731 \begin_inset Note Note
30734 \begin_layout Standard
30735 The screenshot was converted from png to eps with:
30736 \begin_inset Quotes sld
30739 bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps
30740 \begin_inset Quotes srd
30743 which produces a pretty compact eps file which is free from compression
30747 \begin_layout Standard
30748 The screenshot was included in sdccman.lyx cvs version 1.120 but later removed
30749 as this broke the build system on Sourceforge (pdf-file was broken.
30750 pdflatex does not accept eps files).
30758 \begin_layout Standard
30774 \begin_inset LatexCommand url
30775 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/doc/figures/ddd_example.png"
30781 shows a screenshot of a debugging session with DDD
30782 \begin_inset LatexCommand index
30783 name "DDD (debugger)"
30787 (Unix only) on a simulated 8032.
30788 The debugging session might not run as smoothly as the screenshot suggests.
30789 The debugger allows setting of breakpoints, displaying and changing variables,
30790 single stepping through C and assembler code.
30793 The source was compiled with
30807 \begin_layout Standard
30819 -debug ddd_example.c
30832 and DDD was invoked with
30839 ddd -debugger "sdcdb -cpu 8032 ddd_example"
30842 \begin_layout Standard
30843 \begin_inset Note Note
30846 \begin_layout Standard
30847 Check that the double quotes or an apostrophe within the command line survive
30848 the LyX tool chain.
30849 Previously the apostrophes got slanted in the PDF output so a cut and paste
30858 \begin_layout Subsection
30859 Interfacing SDCDB with XEmacs
30860 \begin_inset LatexCommand index
30866 \begin_inset LatexCommand index
30874 \begin_layout Standard
30875 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
30876 sdcdb.el and sdcdbsrc.el.
30877 These two files can be found in the $(prefix)/bin directory after the installat
30879 These files need to be loaded into XEmacs for the interface to work.
30880 This can be done at XEmacs startup time by inserting the following into
30881 your '.xemacs' file (which can be found in your HOME directory):
30887 (load-file sdcdbsrc.el)
30893 .xemacs is a lisp file so the () around the command is REQUIRED.
30894 The files can also be loaded dynamically while XEmacs is running, set the
30895 environment variable 'EMACSLOADPATH' to the installation bin directory
30896 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
30897 To start the interface enter the following command:
30911 You will prompted to enter the file name to be debugged.
30916 The command line options that are passed to the simulator directly are
30917 bound to default values in the file sdcdbsrc.el.
30918 The variables are listed below, these values maybe changed as required.
30921 \begin_layout Itemize
30922 sdcdbsrc-cpu-type '51
30925 \begin_layout Itemize
30926 sdcdbsrc-frequency '11059200
30929 \begin_layout Itemize
30930 sdcdbsrc-serial nil
30933 \begin_layout Standard
30934 The following is a list of key mapping for the debugger interface.
30937 \begin_layout Standard
30960 binding\InsetSpace ~
30998 -------\InsetSpace ~
31069 sdcdb-back-from-src\InsetSpace ~
31098 rom-src\InsetSpace ~
31108 SDCDB continue command
31126 sdcdb-step-from-src\InsetSpace ~
31155 hatis-c-sexp\InsetSpace ~
31165 SDCDB ptypecommand for data at
31232 sdcdbsrc-delete\InsetSpace ~
31247 B Delete all breakpoints if no arg
31296 given or delete arg (C-u arg x)
31315 -frame\InsetSpace ~
31330 SDCDB Display current frame if no arg,
31379 given or display frame arg
31447 sdcdbsrc-goto-sdcdb\InsetSpace ~
31457 Goto the SDCDB output buffer
31476 t-c-sexp\InsetSpace ~
31487 SDCDB print command for data at
31554 sdcdbsrc-goto-sdcdb\InsetSpace ~
31565 o the SDCDB output buffer
31583 sdcdbsrc-mode\InsetSpace ~
31599 Toggles Sdcdbsrc mode (turns it
31615 sdcdb-finish-from-src\InsetSpace ~
31623 SDCDB finish command
31657 Set break for line with point
31672 sdcdbsrc-mode\InsetSpace ~
31688 Toggle Sdcdbsrc mode
31704 dbsrc-srcmode\InsetSpace ~
31728 \begin_layout Chapter
31732 \begin_layout Standard
31733 Here are a few guidelines that will help the compiler generate more efficient
31734 code, some of the tips are specific to this compiler others are generally
31735 good programming practice.
31738 \begin_layout Itemize
31739 Use the smallest data type to represent your data-value.
31740 If it is known in advance that the value is going to be less than 256 then
31741 use an 'unsigned char' instead of a 'short' or 'int'.
31742 Please note, that ANSI C requires both signed and unsigned chars to be
31743 promoted to 'signed int'
31744 \begin_inset LatexCommand index
31745 name "promotion to signed int"
31750 \begin_inset Marginal
31753 \begin_layout Standard
31762 before doing any operation.
31764 \begin_inset LatexCommand index
31765 name "type promotion"
31770 \begin_inset LatexCommand label
31771 name "type promotion"
31775 can be omitted, if the result is the same.
31776 The effect of the promotion rules together with the sign-extension is often
31781 \begin_layout Verse
31784 unsigned char uc = 0xfe;
31786 if (uc * uc < 0) /* this is true! */
31799 \begin_layout Standard
31806 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
31814 \begin_layout Verse
31817 (unsigned char) -12 / (signed char) -3 = ...
31820 \begin_layout Standard
31821 No, the result is not 4:
31824 \begin_layout Verse
31827 (int) (unsigned char) -12 / (int) (signed char) -3 =
31829 (int) (unsigned char)
31830 0xf4 / (int) (signed char) 0xfd =
31832 (int) 0x00f4 / (int) 0xfffd =
31837 (int) 244 / (int) -3 =
31839 (int) -81 = (int) 0xffaf;
31842 \begin_layout Standard
31843 Don't complain, that gcc gives you a different result.
31844 gcc uses 32 bit ints, while SDCC uses 16 bit ints.
31845 Therefore the results are different.
31848 \begin_inset Quotes sld
31852 \begin_inset Quotes srd
31858 \begin_layout Quote
31861 If well-defined overflow characteristics are important and negative values
31862 are not, or if you want to steer clear of sign-extension problems when
31863 manipulating bits or bytes, use one of the corresponding unsigned types.
31864 (Beware when mixing signed and unsigned values in expressions, though.)
31867 character types (especially unsigned char) can be used as "tiny" integers,
31868 doing so is sometimes more trouble than it's worth, due to unpredictable
31869 sign extension and increased code size.
31873 \begin_layout Itemize
31874 Use unsigned when it is known in advance that the value is not going to
31876 This helps especially if you are doing division or multiplication, bit-shifting
31877 or are using an array index.
31880 \begin_layout Itemize
31881 NEVER jump into a LOOP.
31884 \begin_layout Itemize
31885 Declare the variables to be local
31886 \begin_inset LatexCommand index
31887 name "local variables"
31891 whenever possible, especially loop control variables (induction).
31894 \begin_layout Itemize
31895 Have a look at the assembly listing to get a
31896 \begin_inset Quotes sld
31900 \begin_inset Quotes srd
31903 for the code generation.
31906 \begin_layout Section
31907 Porting code from or to other compilers
31908 \begin_inset LatexCommand label
31909 name "sec:Porting-code-to-other-compilers"
31916 \begin_layout Itemize
31917 check whether endianness of the compilers differs and adapt where needed.
31920 \begin_layout Itemize
31921 check the device specific header files
31922 \begin_inset LatexCommand index
31923 name "Header files"
31928 \begin_inset LatexCommand index
31929 name "Include files"
31933 for compiler specific syntax.
31934 Eventually include the file <compiler.h
31935 \begin_inset LatexCommand index
31936 name "compiler.h (include file)"
31941 \begin_inset LatexCommand url
31942 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/compiler.h?view=markup"
31946 to allow using common header files.
31949 \begin_inset LatexCommand url
31950 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/device/include/mcs51/cc2510fx.h?view=markup"
31957 \begin_layout Itemize
31958 check whether the startup code contains the correct initialization (watchdog,
31962 \begin_layout Itemize
31963 check whether the sizes of short, int, long match.
31966 \begin_layout Itemize
31967 check if some 16 or 32 bit hardware registers require a specific addressing
31968 order (least significant or most significant byte first) and adapt if needed
31977 relate to time and not to lower/upper memory location here, so this is
31982 the same as endianness).
31985 \begin_layout Itemize
31986 check whether the keyword
31990 is used where needed.
31991 The compilers might differ in their optimization characteristics (as different
31992 versions of the same compiler might also use more clever optimizations
31993 this is good idea anyway).
31995 \begin_inset LatexCommand ref
31996 reference "sub:Common-interrupt-pitfall-volatile"
32003 \begin_layout Itemize
32004 check that the compilers are not told to suppress warnings.
32007 \begin_layout Itemize
32008 check and convert compiler specific extensions (interrupts, memory areas,
32012 \begin_layout Itemize
32013 check for differences in type promotion.
32014 Especially check for math operations on
32023 For the sake of C99 compatibility SDCC will probably promote these to
32027 more often than other compilers.
32028 Eventually insert explicit casts to
32037 Also check that the ~\InsetSpace ~
32039 \begin_inset LatexCommand index
32040 name "\\~\\/ Operator"
32047 \begin_inset LatexCommand index
32054 variables, use the !\InsetSpace ~
32057 \begin_inset LatexCommand ref
32058 reference "type promotion"
32063 \begin_inset LatexCommand ref
32064 reference "sec:Compatibility-with-previous"
32071 \begin_layout Itemize
32072 check the assembly code generated for interrupt routines (f.e.
32073 for calls to possibly non-reentrant library functions).
32076 \begin_layout Itemize
32077 check whether timing loops result in proper timing (or preferably consider
32078 a rewrite of the code with timer based delays instead).
32081 \begin_layout Itemize
32082 check for differences in printf parameters (some compilers push (va_arg
32083 \begin_inset LatexCommand index
32084 name "vararg, va\\_arg"
32088 ) char variables as
32092 others push them as
32098 \begin_inset LatexCommand ref
32099 reference "sec:Compatibility-with-previous"
32106 \begin_layout Itemize
32107 check the resulting memory map
32108 \begin_inset LatexCommand index
32114 Usage of different memory spaces: code, stack, data (for mcs51/ds390 additional
32115 ly idata, pdata, xdata).
32116 Eventually check if unexpected library functions are included.
32119 \begin_layout Section
32121 \begin_inset LatexCommand index
32126 included in the distribution
32129 \begin_layout Standard
32131 \begin_inset Tabular
32132 <lyxtabular version="3" rows="12" columns="3">
32134 <column alignment="left" valignment="top" leftline="true" width="0pt">
32135 <column alignment="left" valignment="top" leftline="true" width="0pt">
32136 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
32137 <row topline="true" bottomline="true">
32138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32141 \begin_layout Standard
32149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32152 \begin_layout Standard
32160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32163 \begin_layout Standard
32172 <row topline="true">
32173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32176 \begin_layout Standard
32178 \begin_inset LatexCommand index
32188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32191 \begin_layout Standard
32192 Simulator for various architectures
32197 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32200 \begin_layout Standard
32207 <row topline="true">
32208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32211 \begin_layout Standard
32217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32220 \begin_layout Standard
32222 \begin_inset LatexCommand index
32223 name "Header files"
32228 \begin_inset LatexCommand index
32229 name "Include files"
32238 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32241 \begin_layout Standard
32242 sdcc/support/scripts
32248 <row topline="true">
32249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32252 \begin_layout Standard
32258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32261 \begin_layout Standard
32262 header file conversion
32267 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32270 \begin_layout Standard
32271 sdcc/support/scripts
32277 <row topline="true">
32278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32281 \begin_layout Standard
32287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32290 \begin_layout Standard
32296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32299 \begin_layout Standard
32315 <row topline="true">
32316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32319 \begin_layout Standard
32325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32328 \begin_layout Standard
32334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32337 \begin_layout Standard
32353 <row topline="true">
32354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32357 \begin_layout Standard
32363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32366 \begin_layout Standard
32372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32375 \begin_layout Standard
32391 <row topline="true">
32392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32395 \begin_layout Standard
32401 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32404 \begin_layout Standard
32410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32413 \begin_layout Standard
32429 <row topline="true">
32430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32433 \begin_layout Standard
32439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32442 \begin_layout Standard
32448 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32451 \begin_layout Standard
32467 <row topline="true">
32468 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32471 \begin_layout Standard
32477 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32480 \begin_layout Standard
32486 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32489 \begin_layout Standard
32505 <row topline="true">
32506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32509 \begin_layout Standard
32515 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32518 \begin_layout Standard
32524 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32527 \begin_layout Standard
32543 <row topline="true" bottomline="true">
32544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32547 \begin_layout Standard
32553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32556 \begin_layout Standard
32558 \begin_inset LatexCommand index
32559 name "packihx (tool)"
32568 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32571 \begin_layout Standard
32596 \begin_layout Section
32598 \begin_inset LatexCommand index
32599 name "Documentation"
32603 included in the distribution
32606 \begin_layout Standard
32608 \begin_inset Tabular
32609 <lyxtabular version="3" rows="10" columns="2">
32611 <column alignment="block" valignment="top" leftline="true" width="40col%">
32612 <column alignment="block" valignment="top" leftline="true" rightline="true" width="60col%">
32613 <row topline="true" bottomline="true" endhead="true">
32614 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32617 \begin_layout Standard
32625 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32628 \begin_layout Standard
32631 Filename / Where to get
32637 <row topline="true">
32638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32641 \begin_layout Standard
32642 SDCC Compiler User Guide
32647 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32650 \begin_layout Standard
32651 You're reading it right now
32663 \begin_inset LatexCommand url
32664 target "http://sdcc.sourceforge.net/doc/sdccman.pdf"
32674 <row topline="true">
32675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32678 \begin_layout Standard
32684 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32687 \begin_layout Standard
32700 \begin_inset LatexCommand url
32701 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/ChangeLog"
32711 <row topline="true">
32712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32715 \begin_layout Standard
32717 \begin_inset LatexCommand index
32718 name "asXXXX (as-gbz80, as-hc08, asx8051, as-z80)"
32723 \begin_inset LatexCommand index
32724 name "Assembler documentation"
32731 \begin_inset LatexCommand index
32737 \begin_inset LatexCommand index
32738 name "Linker documentation"
32747 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32750 \begin_layout Standard
32751 sdcc/as/doc/asxhtm.html
32763 \begin_inset LatexCommand url
32764 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/as/doc/asxhtm.html"
32774 <row topline="true">
32775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32778 \begin_layout Standard
32779 SDCC regression test
32780 \begin_inset LatexCommand index
32781 name "Regression test"
32790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32793 \begin_layout Standard
32794 sdcc/doc/test_suite_spec.pdf
32806 \begin_inset LatexCommand url
32807 target "http://sdcc.sourceforge.net/doc/test_suite_spec.pdf"
32817 <row topline="true">
32818 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32821 \begin_layout Standard
32827 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32830 \begin_layout Standard
32843 \begin_inset LatexCommand url
32844 target "http://sdcc.svn.sourceforge.net/viewvc/sdcc/trunk/sdcc/doc/"
32854 <row topline="true">
32855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32858 \begin_layout Standard
32859 Notes on debugging with SDCDB
32860 \begin_inset LatexCommand index
32861 name "SDCDB (debugger)"
32870 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32873 \begin_layout Standard
32874 sdcc/debugger/README
32886 \begin_inset LatexCommand url
32887 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/debugger/README"
32897 <row topline="true">
32898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32901 \begin_layout Standard
32903 \begin_inset LatexCommand index
32908 Software simulator for microcontrollers
32913 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32916 \begin_layout Standard
32946 \begin_inset LatexCommand url
32947 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/sim/ucsim/doc/index.html"
32957 <row topline="true">
32958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
32961 \begin_layout Standard
32962 Temporary notes on the pic16
32963 \begin_inset LatexCommand index
32973 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
32976 \begin_layout Standard
32977 sdcc/src/pic16/NOTES
32989 \begin_inset LatexCommand url
32990 target "http://sdcc.svn.sourceforge.net/viewvc/*checkout*/sdcc/trunk/sdcc/src/pic16/NOTES"
33000 <row topline="true" bottomline="true">
33001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33004 \begin_layout Standard
33005 SDCC internal documentation (debugging file format)
33010 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33013 \begin_layout Standard
33043 \begin_inset LatexCommand url
33044 target "http://sdcc.sourceforge.net/doc/cdbfileformat.pdf"
33063 \begin_layout Section
33064 Related open source tools
33065 \begin_inset LatexCommand label
33066 name "sec:Related-open-source-tools"
33071 \begin_inset LatexCommand index
33072 name "Related tools"
33079 \begin_layout Standard
33081 \begin_inset Tabular
33082 <lyxtabular version="3" rows="16" columns="3">
33084 <column alignment="left" valignment="top" leftline="true" width="0pt">
33085 <column alignment="block" valignment="top" leftline="true" width="30line%">
33086 <column alignment="left" valignment="top" leftline="true" rightline="true" width="40col%">
33087 <row topline="true" bottomline="true">
33088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33091 \begin_layout Standard
33099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33102 \begin_layout Standard
33110 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33113 \begin_layout Standard
33122 <row topline="true">
33123 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33126 \begin_layout Standard
33128 \begin_inset LatexCommand index
33129 name "gpsim (pic simulator)"
33138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33141 \begin_layout Standard
33147 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33150 \begin_layout Standard
33151 \begin_inset LatexCommand url
33152 target "http://www.dattalo.com/gnupic/gpsim.html"
33162 <row topline="true">
33163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33166 \begin_layout Standard
33168 \begin_inset LatexCommand index
33169 name "gputils (pic tools)"
33178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33181 \begin_layout Standard
33187 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33190 \begin_layout Standard
33191 \begin_inset LatexCommand url
33192 target "http://sourceforge.net/projects/gputils"
33202 <row topline="true">
33203 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33206 \begin_layout Standard
33212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33215 \begin_layout Standard
33221 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33224 \begin_layout Standard
33225 \begin_inset LatexCommand url
33226 target "http://freshmeat.net/projects/flp5/"
33236 <row topline="true">
33237 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33240 \begin_layout Standard
33246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33249 \begin_layout Standard
33250 Tools for Silicon Laboratories JTAG debug adapter, partly based on SDCDB
33256 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33259 \begin_layout Standard
33260 \begin_inset LatexCommand url
33261 target "http://sourceforge.net/projects/ec2drv"
33271 <row topline="true">
33272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33275 \begin_layout Standard
33277 \begin_inset LatexCommand index
33278 name "indent (source formatting tool)"
33287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33290 \begin_layout Standard
33291 Formats C source - Master of the white spaces
33296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33299 \begin_layout Standard
33300 \begin_inset LatexCommand url
33301 target "http://directory.fsf.org/GNU/indent.html"
33311 <row topline="true">
33312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33315 \begin_layout Standard
33317 \begin_inset LatexCommand index
33318 name "srecord (bin, hex, ... tool)"
33327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33330 \begin_layout Standard
33331 Object file conversion, checksumming, ...
33336 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33339 \begin_layout Standard
33340 \begin_inset LatexCommand url
33341 target "http://sourceforge.net/projects/srecord"
33351 <row topline="true">
33352 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33355 \begin_layout Standard
33357 \begin_inset LatexCommand index
33358 name "objdump (tool)"
33367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33370 \begin_layout Standard
33371 Object file conversion, ...
33376 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33379 \begin_layout Standard
33380 Part of binutils (should be there anyway)
33386 <row topline="true">
33387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33390 \begin_layout Standard
33396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33399 \begin_layout Standard
33400 8051 monitor (hex up-/download, single step, disassemble)
33405 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33408 \begin_layout Standard
33409 \begin_inset LatexCommand url
33410 target "http://sourceforge.net/projects/cmon51"
33420 <row topline="true">
33421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33424 \begin_layout Standard
33426 \begin_inset LatexCommand index
33427 name "doxygen (source documentation tool)"
33436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33439 \begin_layout Standard
33440 Source code documentation system
33445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33448 \begin_layout Standard
33449 \begin_inset LatexCommand url
33450 target "http://www.doxygen.org"
33460 <row topline="true">
33461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33464 \begin_layout Standard
33470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33473 \begin_layout Standard
33474 IDE (has anyone tried integrating SDCC & SDCDB? Unix only)
33479 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33482 \begin_layout Standard
33483 \begin_inset LatexCommand url
33484 target "http://www.kdevelop.org"
33494 <row topline="true">
33495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33498 \begin_layout Standard
33504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33507 \begin_layout Standard
33508 8051 monitor (hex up-/download, single step, disassemble)
33513 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33516 \begin_layout Standard
33517 \begin_inset LatexCommand url
33518 target "http://www.pjrc.com/tech/8051/paulmon2.html"
33528 <row topline="true">
33529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33532 \begin_layout Standard
33534 \begin_inset LatexCommand index
33535 name "splint (syntax checking tool)"
33544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33547 \begin_layout Standard
33548 Statically checks c sources (see
33549 \begin_inset LatexCommand ref
33550 reference "lyx:more-pedantic-SPLINT"
33559 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33562 \begin_layout Standard
33563 \begin_inset LatexCommand url
33564 target "http://www.splint.org"
33574 <row topline="true" bottomline="true">
33575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33578 \begin_layout Standard
33580 \begin_inset LatexCommand index
33581 name "DDD (debugger)"
33590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33593 \begin_layout Standard
33594 Debugger, serves nicely as GUI to SDCDB
33595 \begin_inset LatexCommand index
33596 name "SDCDB (debugger)"
33605 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33608 \begin_layout Standard
33609 \begin_inset LatexCommand url
33610 target "http://www.gnu.org/software/ddd/"
33620 <row bottomline="true">
33621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33624 \begin_layout Standard
33626 \begin_inset LatexCommand index
33632 \begin_inset LatexCommand index
33633 name "d52 (disassembler)"
33642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33645 \begin_layout Standard
33646 Disassembler, can count instruction cycles
33647 \begin_inset LatexCommand index
33648 name "instruction cycles (count)"
33652 , use with options -pnd
33657 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33660 \begin_layout Standard
33661 \begin_inset LatexCommand url
33662 target "http://www.8052.com/users/disasm/"
33672 <row bottomline="true">
33673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33676 \begin_layout Standard
33678 \begin_inset LatexCommand index
33688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33691 \begin_layout Standard
33692 Cross platform build system, generates Makefiles
33693 \begin_inset LatexCommand index
33698 and project workspaces
33699 \begin_inset LatexCommand index
33700 name "project workspace"
33709 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33712 \begin_layout Standard
33713 \begin_inset LatexCommand url
33714 target "http://www.cmake.org"
33722 and a dedicated wiki entry:
33723 \begin_inset LatexCommand url
33724 target "http://www.cmake.org/Wiki/CmakeSdcc"
33743 \begin_layout Section
33744 Related documentation / recommended reading
33747 \begin_layout Standard
33749 \begin_inset Tabular
33750 <lyxtabular version="3" rows="7" columns="3">
33752 <column alignment="left" valignment="top" leftline="true" width="0pt">
33753 <column alignment="left" valignment="top" leftline="true" width="0">
33754 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
33755 <row topline="true" bottomline="true">
33756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33759 \begin_layout Standard
33767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33770 \begin_layout Standard
33778 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33781 \begin_layout Standard
33790 <row topline="true">
33791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33794 \begin_layout Standard
33809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33812 \begin_layout Standard
33814 \begin_inset LatexCommand index
33815 name "C Reference card"
33824 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33827 \begin_layout Standard
33828 \begin_inset LatexCommand url
33829 target "http://refcards.com/refcards/c/index.html"
33839 <row topline="true">
33840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33843 \begin_layout Standard
33849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33852 \begin_layout Standard
33854 \begin_inset LatexCommand index
33864 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33867 \begin_layout Standard
33868 \begin_inset LatexCommand url
33869 target "http://www.c-faq.com"
33879 <row topline="true">
33880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33883 \begin_layout Standard
33889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33892 \begin_layout Standard
33893 \begin_inset Quotes sld
33897 \begin_inset Quotes srd
33905 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33908 \begin_layout Standard
33911 \begin_inset LatexCommand url
33912 target "http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899"
33922 <row topline="true">
33923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33926 \begin_layout Standard
33932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33935 \begin_layout Standard
33936 \begin_inset Quotes sld
33939 Extensions for Embedded C
33940 \begin_inset Quotes srd
33948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33951 \begin_layout Standard
33954 \begin_inset LatexCommand url
33955 target "http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf"
33965 <row topline="true">
33966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33969 \begin_layout Standard
33975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33978 \begin_layout Standard
33979 Latest datasheet of target CPU
33984 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
33987 \begin_layout Standard
33994 <row topline="true" bottomline="true">
33995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
33998 \begin_layout Standard
34004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34007 \begin_layout Standard
34008 Revision history of datasheet
34013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34016 \begin_layout Standard
34032 \begin_layout Section
34033 Application notes specifically for SDCC
34036 \begin_layout Standard
34037 SDCC makes no claims about the completeness of this list and about up-to-datenes
34038 s or correctness of the application notes
34039 \begin_inset LatexCommand index
34040 name "Application notes"
34047 \begin_layout Standard
34051 \begin_inset Tabular
34052 <lyxtabular version="3" rows="7" columns="3">
34054 <column alignment="block" valignment="top" leftline="true" width="17col%">
34055 <column alignment="block" valignment="top" leftline="true" width="27col%">
34056 <column alignment="block" valignment="top" leftline="true" rightline="true" width="57col%">
34057 <row topline="true" bottomline="true">
34058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34061 \begin_layout Standard
34070 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
34073 \begin_layout Standard
34082 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34085 \begin_layout Standard
34095 <row topline="true">
34096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34099 \begin_layout Standard
34107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34110 \begin_layout Standard
34113 Using the SDCC Compiler for the DS80C400
34114 \begin_inset LatexCommand index
34124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34127 \begin_layout Standard
34130 \begin_inset LatexCommand url
34131 target "http://pdfserv.maxim-ic.com/en/an/AN3346.pdf"
34141 <row topline="true">
34142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34145 \begin_layout Standard
34153 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none" width="30line%">
34156 \begin_layout Standard
34159 Using the Free SDCC C Compiler to Develop Firmware for the DS89C420/430/440/450
34160 \begin_inset LatexCommand index
34165 Family of Microcontrollers
34170 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34173 \begin_layout Standard
34176 \begin_inset LatexCommand url
34177 target "http://pdfserv.maxim-ic.com/en/an/AN3477.pdf"
34187 <row topline="true">
34188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34191 \begin_layout Standard
34194 Silicon Laboratories / Cygnal
34199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34202 \begin_layout Standard
34205 Integrating SDCC 8051 Tools Into The Silicon Labs IDE
34206 \begin_inset LatexCommand index
34216 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34219 \begin_layout Standard
34222 \begin_inset LatexCommand url
34223 target "http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an198.pdf"
34233 <row topline="true">
34234 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34237 \begin_layout Standard
34240 Ramtron / Goal Semiconductor
34245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34248 \begin_layout Standard
34251 Interfacing SDCC to Syn and Textpad
34256 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34259 \begin_layout Standard
34262 \begin_inset LatexCommand url
34263 target "http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp"
34273 <row topline="true">
34274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34277 \begin_layout Standard
34280 Ramtron / Goal Semiconductor
34285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34288 \begin_layout Standard
34291 Installing and Configuring SDCC and Crimson Editor
34296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34299 \begin_layout Standard
34302 \begin_inset LatexCommand url
34303 target "http://www.ramtron.com/doc/Products/Microcontroller/Support_Tools.asp"
34313 <row topline="true" bottomline="true">
34314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34317 \begin_layout Standard
34325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
34328 \begin_layout Standard
34331 MSC12xx Programming with SDCC
34336 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
34339 \begin_layout Standard
34342 \begin_inset LatexCommand url
34343 target "http://focus.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=sbaa109&fileType=pdf"
34360 \begin_layout Section
34364 \begin_layout Standard
34365 Some questions answered, some pointers given - it might be time to in turn
34373 \begin_layout Itemize
34374 can you solve your project with the selected microcontroller? Would you
34375 find out early or rather late that your target is too small/slow/whatever?
34376 Can you switch to a slightly better device if it doesn't fit?
34379 \begin_layout Itemize
34380 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
34381 and/or another programming language be more adequate? Would an operating
34382 system on the target device help?
34385 \begin_layout Itemize
34386 if you solved the problem, will the marketing department be happy?
34389 \begin_layout Itemize
34390 if the marketing department is happy, will customers be happy?
34393 \begin_layout Itemize
34394 if you're the project manager, marketing department and maybe even the customer
34395 in one person, have you tried to see the project from the outside?
34398 \begin_layout Itemize
34399 is the project done if you think it is done? Or is just that other interface/pro
34400 tocol/feature/configuration/option missing? How about website, manual(s),
34401 internationali(z|s)ation, packaging, labels, 2nd source for components,
34402 electromagnetic compatability/interference, documentation for production,
34403 production test software, update mechanism, patent issues?
34406 \begin_layout Itemize
34407 is your project adequately positioned in that magic triangle: fame, fortune,
34411 \begin_layout Standard
34412 Maybe not all answers to these questions are known and some answers may
34417 , nevertheless knowing these questions may help you to avoid burnout
34421 \begin_layout Standard
34422 burnout is bad for electronic devices, programmers and motorcycle tyres
34428 Chances are you didn't want to hear some of them...
34431 \begin_layout Chapter
34433 \begin_inset LatexCommand index
34441 \begin_layout Standard
34442 SDCC has grown to be a large project.
34443 The compiler alone (without the preprocessor, assembler and linker) is
34444 well over 150,000 lines of code (blank stripped).
34445 The open source nature of this project is a key to its continued growth
34447 You gain the benefit and support of many active software developers and
34449 Is SDCC perfect? No, that's why we need your help.
34450 The developers take pride in fixing reported bugs.
34451 You can help by reporting the bugs and helping other SDCC users.
34452 There are lots of ways to contribute, and we encourage you to take part
34453 in making SDCC a great software package.
34457 \begin_layout Standard
34458 The SDCC project is hosted on the SDCC sourceforge site at
34459 \begin_inset LatexCommand htmlurl
34460 target "http://sourceforge.net/projects/sdcc"
34465 You'll find the complete set of mailing lists
34466 \begin_inset LatexCommand index
34467 name "Mailing list(s)"
34471 , forums, bug reporting system, patch submission
34472 \begin_inset LatexCommand index
34473 name "Patch submission"
34478 \begin_inset LatexCommand index
34483 area and Subversion code repository
34484 \begin_inset LatexCommand index
34485 name "Subversion code repository"
34492 \begin_layout Section
34494 \begin_inset LatexCommand index
34495 name "Bug reporting"
34500 \begin_inset LatexCommand index
34501 name "Reporting bugs"
34508 \begin_layout Standard
34509 The recommended way of reporting bugs is using the infrastructure of the
34511 You can follow the status of bug reports there and have an overview about
34515 \begin_layout Standard
34516 Bug reports are automatically forwarded to the developer mailing list and
34517 will be fixed ASAP.
34518 When reporting a bug, it is very useful to include a small test program
34519 (the smaller the better) which reproduces the problem.
34520 If you can isolate the problem by looking at the generated assembly code,
34521 this can be very helpful.
34522 Compiling your program with the -
34526 \begin_layout Standard
34536 \begin_inset LatexCommand index
34537 name "-\\/-dumpall"
34541 option can sometimes be useful in locating optimization problems.
34542 When reporting a bug please make sure you:
34545 \begin_layout Enumerate
34546 Attach the code you are compiling with SDCC.
34550 \begin_layout Enumerate
34551 Specify the exact command you use to run SDCC, or attach your Makefile.
34555 \begin_layout Enumerate
34556 Specify the SDCC version (type "
34562 "), your platform, and operating system.
34566 \begin_layout Enumerate
34567 Provide an exact copy of any error message or incorrect output.
34571 \begin_layout Enumerate
34572 Put something meaningful in the subject of your message.
34575 \begin_layout Standard
34576 Please attempt to include these 5 important parts, as applicable, in all
34577 requests for support or when reporting any problems or bugs with SDCC.
34578 Though this will make your message lengthy, it will greatly improve your
34579 chance that SDCC users and developers will be able to help you.
34580 Some SDCC developers are frustrated by bug reports without code provided
34581 that they can use to reproduce and ultimately fix the problem, so please
34582 be sure to provide sample code if you are reporting a bug!
34585 \begin_layout Standard
34586 Please have a short check that you are using a recent version of SDCC and
34587 the bug is not yet known.
34588 This is the link for reporting bugs:
34589 \begin_inset LatexCommand htmlurl
34590 target "http://sourceforge.net/tracker/?group_id=599&atid=100599"
34595 With SDCC on average having more than 200 downloads
34596 \begin_inset LatexCommand index
34601 on sourceforge per day
34605 \begin_layout Standard
34606 220 daily downloads on average Jan-Sept 2006 and about 150 daily downloads
34607 between 2002 and 2005.
34608 This does not include other methods of distribution.
34613 there must be some users.
34614 So it's not exactly easy to find a new bug.
34615 If you find one we need it:
34617 reporting bugs is good
34622 \begin_layout Section
34623 Requesting Features
34624 \begin_inset LatexCommand label
34625 name "sub:Requesting-Features"
34630 \begin_inset LatexCommand index
34631 name "Feature request"
34636 \begin_inset LatexCommand index
34637 name "Requesting features"
34644 \begin_layout Standard
34645 Like bug reports feature requests are forwarded to the developer mailing
34647 This is the link for requesting features:
34648 \begin_inset LatexCommand htmlurl
34649 target "http://sourceforge.net/tracker/?group_id=599&atid=350599"
34656 \begin_layout Section
34660 \begin_layout Standard
34661 Like bug reports contributed patches are forwarded to the developer mailing
34663 This is the link for submitting patches
34664 \begin_inset LatexCommand index
34665 name "Patch submission"
34670 \begin_inset LatexCommand url
34671 target "http://sourceforge.net/tracker/?group_id=599&atid=300599"
34678 \begin_layout Standard
34679 You need to specify some parameters to the
34683 command for the patches to be useful.
34684 If you modified more than one file a patch created f.e.
34689 \begin_inset Quotes sld
34692 diff -Naur unmodified_directory modified_directory >my_changes.patch
34693 \begin_inset Quotes srd
34699 will be fine, otherwise
34703 \begin_inset Quotes sld
34706 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
34707 \begin_inset Quotes srd
34716 \begin_layout Section
34720 \begin_layout Standard
34721 These links should take you directly to the
34722 \begin_inset LatexCommand url
34723 name "Mailing lists"
34724 target "http://sourceforge.net/mail/?group_id=599"
34732 \begin_layout Standard
34733 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
34734 automated messages (mid 2003)
34740 \begin_inset LatexCommand url
34742 target "http://sourceforge.net/forum/?group_id=599"
34747 \begin_inset LatexCommand index
34748 name "Mailing list(s)"
34752 and forums are archived and searchable so if you are lucky someone already
34753 had a similar problem.
34754 While mails to the lists themselves are delivered promptly their web front
34755 end on sourceforge sometimes shows a severe time lag (up to several weeks),
34756 if you're seriously using SDCC please consider subscribing to the lists.
34759 \begin_layout Section
34763 \begin_layout Standard
34764 You can follow the status of the Subversion version
34765 \begin_inset LatexCommand index
34770 of SDCC by watching the Changelog
34771 \begin_inset LatexCommand index
34776 in the Subversion repository
34779 \begin_inset LatexCommand htmlurl
34780 target "http://sdcc.svn.sourceforge.net/viewcvs.cgi/*checkout*/sdcc/trunk/sdcc/ChangeLog"
34787 \begin_layout Section
34788 Subversion Source Code Repository
34791 \begin_layout Standard
34801 \begin_layout Standard
34815 or the filenames of the snapshot versions of SDCC include date and its
34817 \begin_inset LatexCommand index
34818 name "Subversion code repository"
34823 Subversion allows to download the source of recent or previous versions
34825 \begin_inset LatexCommand url
34826 target "http://sourceforge.net/svn/?group_id=599"
34830 (by number or by date).
34831 An on-line source code browser and detailled instructions are also available
34833 SDCC versions starting from 1999 up to now are available (currently the
34834 versions prior to the conversion from cvs
34835 \begin_inset LatexCommand index
34836 name "cvs|see{Subversion}"
34840 to Subversion (April 2006) are either by accessible by Subversion or by
34844 \begin_layout Section
34846 \begin_inset LatexCommand index
34847 name "Release policy"
34854 \begin_layout Standard
34855 Historically there often were long delays between official releases and
34856 the sourceforge download area tends to get not updated at all.
34857 Excuses in the past might have referred to problems with live range analysis,
34858 but as this was fixed a while ago, the current problem is that another
34859 excuse has to be found.
34860 Kidding aside, we have to get better there! On the other hand there are
34861 daily snapshots available at
34862 \begin_inset LatexCommand htmlurl
34864 target "http://sdcc.sourceforge.net/snap.php"
34868 , and you can always build the very last version (hopefully with many bugs
34869 fixed, and features added) from the source code available at
34870 \begin_inset LatexCommand htmlurl
34872 target "http://sdcc.sourceforge.net/snap.php#Source"
34878 \begin_inset LatexCommand index
34884 \begin_inset LatexCommand index
34890 \begin_inset LatexCommand url
34891 target "http://sdcc.wiki.sourceforge.net/"
34895 also holds some information about past and future releases.
34898 \begin_layout Section
34900 \begin_inset LatexCommand index
34908 \begin_layout Standard
34909 You'll find some small examples in the directory
34911 sdcc/device/examples/.
34914 More examples and libraries are available at
34916 The SDCC Open Knowledge Resource
34917 \begin_inset LatexCommand url
34918 target "http://sdccokr.dl9sec.de/"
34925 \begin_inset LatexCommand url
34926 target "http://www.pjrc.com/tech/8051/"
34933 \begin_layout Standard
34934 \begin_inset Note Note
34937 \begin_layout Standard
34938 I did insert a reference to Paul's web site here although it seems rather
34939 dedicated to a specific 8032 board (I think it's okay because it f.e.
34940 shows LCD/Harddisc interface and has a free 8051 monitor.
34941 Independent 8032 board vendors face hard competition of heavily subsidized
34942 development boards anyway).
34945 \begin_layout Standard
34946 Maybe we should include some links to real world applications.
34947 Preferably pointer to pointers (one for each architecture) so this stays
34956 \begin_layout Section
34958 \begin_inset LatexCommand label
34959 name "sec:Quality-control"
34964 \begin_inset LatexCommand index
34965 name "Quality control"
34972 \begin_layout Standard
34973 The compiler is passed through snaphot build compile and build checks.
34979 \begin_inset LatexCommand index
34980 name "Regression test"
34984 check that SDCC itself compiles flawlessly on several host platforms (i386,
34985 Opteron, 64 bit Alpha, ppc64, Mac OS X on ppc and i386, Solaris on Sparc)
34986 and checks the quality of the code generated by SDCC by running the code
34987 for several target platforms through simulators.
34988 The regression test suite comprises more than 100 files which expand to
34989 more than 500 test cases which include more than 4500 tests.
34990 The results of these tests are published daily on SDCC's snapshot page
34991 (click on the red or green symbols on the right side of
34992 \begin_inset LatexCommand url
34993 target "http://sdcc.sourceforge.net/snap.php"
35000 \begin_layout Standard
35001 There is a separate document
35004 \begin_inset LatexCommand index
35012 \begin_inset LatexCommand url
35013 target "http://sdcc.sourceforge.net/doc/test_suite_spec.pdf"
35017 about the regression test suite.
35020 \begin_layout Standard
35021 You'll find the test code in the directory
35023 sdcc/support/regression
35026 You can run these tests manually by running
35030 in this directory (or f.e.
35035 \begin_inset Quotes sld
35039 \begin_inset Quotes srd
35045 if you don't want to run the complete tests).
35046 The test code might also be interesting if you want to look for examples
35047 \begin_inset LatexCommand index
35052 checking corner cases of SDCC or if you plan to submit patches
35053 \begin_inset LatexCommand index
35054 name "Patch submission"
35061 \begin_layout Standard
35062 The PIC14 port uses a different set of regression tests
35063 \begin_inset LatexCommand index
35064 name "Regression test (PIC14)"
35068 , you'll find them in the directory
35070 sdcc/src/regression
35075 \begin_layout Section
35076 Use of SDCC in Education
35079 \begin_layout Standard
35088 \begin_layout Standard
35089 the phrase "use in education" might evoke the association "
35093 fit for use in education".
35094 This connotation is not intended but nevertheless risked as the licensing
35095 of SDCC makes it difficult to offer educational discounts
35101 If your rationales are to:
35104 \begin_layout Enumerate
35105 give students a chance to understand the
35109 steps of code generation
35112 \begin_layout Enumerate
35113 have a curriculum that can be extended for years.
35114 Then you could use an fpga board as target and your curriculum will seamlessly
35115 extend from logic synthesis (
35116 \begin_inset LatexCommand url
35117 name "http://www.opencores.org"
35118 target "opencores.org"
35123 \begin_inset LatexCommand url
35125 target "http://www.oregano.at/ip/ip01.htm"
35129 ), over assembly programming, to C to FPGA compilers (
35130 \begin_inset LatexCommand url
35132 target "http://sf.net/projects/fpgac"
35139 \begin_layout Enumerate
35140 be able to insert excursions about skills like using a revision control
35141 system, submitting/applying patches, using a type-setting (as opposed to
35142 word-processing) engine LyX/LaTeX, using
35143 \begin_inset LatexCommand url
35145 target "http://www.sf.net"
35150 \begin_inset LatexCommand url
35152 target "http://en.wikipedia.org/wiki/Netiquette"
35156 , understanding BSD/LGPL/GPL/Proprietary licensing, growth models of Open
35157 Source Software, CPU simulation, compiler regression tests
35158 \begin_inset LatexCommand index
35159 name "Regression test"
35166 And if there should be a shortage of ideas then you can always point students
35167 to the ever-growing feature request list
35168 \begin_inset LatexCommand htmlurl
35169 target "http://sourceforge.net/tracker/?group_id=599&atid=350599"
35176 \begin_layout Enumerate
35177 not tie students to a specific host platform and instead allow them to use
35182 choice (among them Alpha, i386, i386_64, Mac OS X, Mips, Sparc, Windows
35184 \begin_inset LatexCommand url
35186 target "http://www.laptop.org"
35193 \begin_layout Enumerate
35194 not encourage students to use illegal copies of educational software
35197 \begin_layout Enumerate
35198 be immune to licensing/availability/price changes of the chosen tool chain
35201 \begin_layout Enumerate
35202 be able to change to a new target platform without having to adopt a new
35206 \begin_layout Enumerate
35207 have complete control over and insight into the tool chain
35210 \begin_layout Enumerate
35211 make your students aware about the pros and cons of open source software
35215 \begin_layout Enumerate
35216 give back to the public as you are probably at least partially publicly
35220 \begin_layout Enumerate
35221 give students a chance to publicly prove their skills and to possibly see
35222 a world wide impact
35225 \begin_layout Standard
35226 then SDCC is probably among the first choices.
35227 Well, probably SDCC might be the only choice.
35232 \begin_layout Chapter
35233 SDCC Technical Data
35236 \begin_layout Section
35238 \begin_inset LatexCommand index
35239 name "Optimizations"
35246 \begin_layout Standard
35247 SDCC performs a host of standard optimizations in addition to some MCU specific
35252 \begin_layout Subsection
35253 Sub-expression Elimination
35254 \begin_inset LatexCommand index
35255 name "Subexpression elimination"
35262 \begin_layout Standard
35263 The compiler does local and
35282 \begin_layout Verse
35290 \begin_layout Standard
35291 will be translated to
35294 \begin_layout Verse
35304 \begin_layout Standard
35305 Some subexpressions are not as obvious as the above example, e.g.:
35308 \begin_layout Verse
35316 \begin_layout Standard
35317 In this case the address arithmetic a->b[i] will be computed only once;
35318 the equivalent code in C would be.
35321 \begin_layout Verse
35331 \begin_layout Standard
35332 The compiler will try to keep these temporary variables in registers.
35335 \begin_layout Subsection
35336 Dead-Code Elimination
35337 \begin_inset LatexCommand index
35338 name "Dead-code elimination"
35345 \begin_layout Verse
35360 i = 1; \InsetSpace ~
35369 global = 1;\InsetSpace ~
35383 global = 3;\InsetSpace ~
35389 \begin_layout Standard
35393 \begin_layout Verse
35409 \begin_layout Subsection
35411 \begin_inset LatexCommand index
35412 name "Copy propagation"
35419 \begin_layout Verse
35443 \begin_layout Standard
35447 \begin_layout Verse
35471 \begin_layout Standard
35472 Note: the dead stores created by this copy propagation will be eliminated
35473 by dead-code elimination.
35476 \begin_layout Subsection
35478 \begin_inset LatexCommand index
35479 name "Loop optimization"
35484 \begin_inset LatexCommand label
35485 name "sub:Loop-Optimizations"
35492 \begin_layout Standard
35493 Two types of loop optimizations are done by SDCC
35501 of loop induction variables.
35502 In addition to the strength reduction the optimizer marks the induction
35503 variables and the register allocator tries to keep the induction variables
35504 in registers for the duration of the loop.
35505 Because of this preference of the register allocator
35506 \begin_inset LatexCommand index
35507 name "Register allocation"
35511 , loop induction optimization causes an increase in register pressure, which
35512 may cause unwanted spilling of other temporary variables into the stack
35513 \begin_inset LatexCommand index
35519 The compiler will generate a warning message when it is forced to allocate
35520 extra space either on the stack or data space.
35521 If this extra space allocation is undesirable then induction optimization
35522 can be eliminated either for the entire source file (with -
35526 \begin_layout Standard
35535 -noinduction option) or for a given function only using #pragma\InsetSpace ~
35537 \begin_inset LatexCommand index
35538 name "\\#pragma noinduction"
35549 \begin_layout Verse
35552 for (i = 0 ; i < 100 ; i ++)
35561 \begin_layout Standard
35565 \begin_layout Verse
35570 for (i = 0; i < 100; i++)
35579 \begin_layout Standard
35580 As mentioned previously some loop invariants are not as apparent, all static
35581 address computations are also moved out of the loop.
35586 \begin_inset LatexCommand index
35587 name "Strength reduction"
35591 , this optimization substitutes an expression by a cheaper expression:
35594 \begin_layout Verse
35597 for (i=0;i < 100; i++)
35606 \begin_layout Standard
35610 \begin_layout Verse
35617 for (i=0;i< 100;i++) {
35623 ar[itemp1] = itemp2;
35641 \begin_layout Standard
35642 The more expensive multiplication
35643 \begin_inset LatexCommand index
35644 name "Multiplication"
35648 is changed to a less expensive addition.
35651 \begin_layout Subsection
35653 \begin_inset LatexCommand index
35654 name "Loop reversing"
35661 \begin_layout Standard
35662 This optimization is done to reduce the overhead of checking loop boundaries
35663 for every iteration.
35664 Some simple loops can be reversed and implemented using a
35665 \begin_inset Quotes eld
35668 decrement and jump if not zero
35669 \begin_inset Quotes erd
35673 SDCC checks for the following criterion to determine if a loop is reversible
35674 (note: more sophisticated compilers use data-dependency analysis to make
35675 this determination, SDCC uses a more simple minded analysis).
35678 \begin_layout Itemize
35679 The 'for' loop is of the form
35685 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
35695 \begin_layout Itemize
35696 The <for body> does not contain
35697 \begin_inset Quotes eld
35701 \begin_inset Quotes erd
35705 \begin_inset Quotes erd
35711 \begin_layout Itemize
35712 All goto's are contained within the loop.
35715 \begin_layout Itemize
35716 No function calls within the loop.
35719 \begin_layout Itemize
35720 The loop control variable <sym> is not assigned any value within the loop
35723 \begin_layout Itemize
35724 The loop control variable does NOT participate in any arithmetic operation
35728 \begin_layout Itemize
35729 There are NO switch statements in the loop.
35732 \begin_layout Subsection
35733 Algebraic Simplifications
35736 \begin_layout Standard
35737 SDCC does numerous algebraic simplifications, the following is a small sub-set
35738 of these optimizations.
35741 \begin_layout Verse
35744 i = j + 0;\InsetSpace ~
35748 /* changed to: */\InsetSpace ~
35754 i /= 2;\InsetSpace ~
35761 /* changed to: */\InsetSpace ~
35768 = j - j;\InsetSpace ~
35772 /* changed to: */\InsetSpace ~
35778 i = j / 1;\InsetSpace ~
35782 /* changed to: */\InsetSpace ~
35789 \begin_layout Standard
35790 Note the subexpressions
35791 \begin_inset LatexCommand index
35792 name "Subexpression"
35796 given above are generally introduced by macro expansions or as a result
35797 of copy/constant propagation.
35800 \begin_layout Subsection
35801 'switch' Statements
35802 \begin_inset LatexCommand label
35803 name "sub:'switch'-Statements"
35808 \begin_inset LatexCommand index
35809 name "switch statement"
35816 \begin_layout Standard
35817 SDCC can optimize switch statements to jump tables
35818 \begin_inset LatexCommand index
35824 It makes the decision based on an estimate of the generated code size.
35825 SDCC is quite liberal in the requirements for jump table generation:
35828 \begin_layout Itemize
35829 The labels need not be in order, and the starting number need not be one
35830 or zero, the case labels are in numerical sequence or not too many case
35831 labels are missing.
35835 \begin_layout Verse
35838 switch(i) {\InsetSpace ~
35869 case 4: ...\InsetSpace ~
35901 case 5: ...\InsetSpace ~
35933 case 3: ...\InsetSpace ~
35964 case 6: ...\InsetSpace ~
35996 case 7: ...\InsetSpace ~
36028 case 8: ...\InsetSpace ~
36060 case 9: ...\InsetSpace ~
36092 case 10: ...\InsetSpace ~
36123 case 11: ...\InsetSpace ~
36190 \begin_layout Standard
36191 Both the above switch statements will be implemented using a jump-table.
36192 The example to the right side is slightly more efficient as the check for
36193 the lower boundary of the jump-table is not needed.
36197 \begin_layout Itemize
36198 The number of case labels is not larger than supported by the target architectur
36202 \begin_layout Itemize
36203 If the case labels are not in numerical sequence ('gaps' between cases)
36204 SDCC checks whether a jump table with additionally inserted dummy cases
36205 is still attractive.
36209 \begin_layout Itemize
36210 If the starting number is not zero and a check for the lower boundary of
36211 the jump-table can thus be eliminated SDCC might insert dummy cases 0,
36216 \begin_layout Standard
36217 Switch statements which have large gaps in the numeric sequence or those
36218 that have too many case labels can be split into more than one switch statement
36219 for efficient code generation, e.g.:
36222 \begin_layout Verse
36300 \begin_layout Standard
36301 If the above switch statement is broken down into two switch statements
36304 \begin_layout Verse
36347 \begin_layout Standard
36351 \begin_layout Verse
36394 \begin_layout Standard
36395 then both the switch statements will be implemented using jump-tables whereas
36396 the unmodified switch statement will not be.
36399 \begin_layout Standard
36400 \begin_inset Note Note
36403 \begin_layout Standard
36404 There might be reasons which SDCC cannot know about to either favour or
36405 not favour jump tables.
36406 If the target system has to be as quick for the last switch case as for
36407 the first (pro jump table), or if the switch argument is known to be zero
36408 in the majority of the cases (contra jump table).
36416 \begin_layout Standard
36417 The pragma nojtbound
36418 \begin_inset LatexCommand index
36419 name "\\#pragma nojtbound"
36423 can be used to turn off checking the
36436 It has no effect if a default label is supplied.
36437 Use of this pragma is dangerous: if the switch
36438 \begin_inset LatexCommand index
36439 name "switch statement"
36443 argument is not matched by a case statement the processor will happily
36447 \begin_layout Subsection
36448 Bit-shifting Operations
36449 \begin_inset LatexCommand index
36450 name "Bit shifting"
36457 \begin_layout Standard
36458 Bit shifting is one of the most frequently used operation in embedded programmin
36460 SDCC tries to implement bit-shift operations in the most efficient way
36464 \begin_layout Verse
36477 \begin_layout Standard
36478 generates the following code:
36481 \begin_layout Verse
36496 \begin_layout Standard
36497 In general SDCC will never setup a loop if the shift count is known.
36501 \begin_layout Verse
36514 \begin_layout Standard
36518 \begin_layout Verse
36542 \begin_layout Subsection
36544 \begin_inset LatexCommand index
36545 name "Bit rotation"
36552 \begin_layout Standard
36553 A special case of the bit-shift operation is bit rotation
36554 \begin_inset LatexCommand index
36555 name "rotating bits"
36559 , SDCC recognizes the following expression to be a left bit-rotation:
36562 \begin_layout Verse
36570 char i;\InsetSpace ~
36581 /* unsigned is needed for rotation */
36586 i = ((i << 1) | (i >> 7));
36595 \begin_layout Standard
36596 will generate the following code:
36599 \begin_layout Verse
36616 \begin_layout Standard
36617 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
36618 ns of this case will also be recognized as bit-rotation, i.e.:
36621 \begin_layout Verse
36624 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
36627 \begin_layout Subsection
36628 Nibble and Byte Swapping
36631 \begin_layout Standard
36632 Other special cases of the bit-shift operations are nibble or byte swapping
36633 \begin_inset LatexCommand index
36634 name "swapping nibbles/bytes"
36638 , SDCC recognizes the following expressions:
36641 \begin_layout Verse
36662 i = ((i << 4) | (i >> 4));
36668 j = ((j << 8) | (j >> 8));
36671 \begin_layout Standard
36672 and generates a swap instruction for the nibble swapping
36673 \begin_inset LatexCommand index
36674 name "Nibble swapping"
36678 or move instructions for the byte swapping
36679 \begin_inset LatexCommand index
36680 name "Byte swapping"
36686 \begin_inset Quotes sld
36690 \begin_inset Quotes srd
36693 example can be used to convert from little to big-endian or vice versa.
36694 If you want to change the endianness of a
36698 integer you have to cast to
36705 \begin_layout Standard
36706 Note that SDCC stores numbers in little-endian
36710 \begin_layout Standard
36711 Usually 8-bit processors don't care much about endianness.
36712 This is not the case for the standard 8051 which only has an instruction
36718 \begin_inset LatexCommand index
36723 -datapointer so little-endian is the more efficient byte order.
36729 \begin_inset LatexCommand index
36730 name "little-endian"
36735 \begin_inset LatexCommand index
36741 lowest order first).
36744 \begin_layout Subsection
36746 \begin_inset LatexCommand index
36747 name "Highest Order Bit"
36752 \begin_inset LatexCommand index
36753 name "Any Order Bit"
36760 \begin_layout Standard
36761 It is frequently required to obtain the highest order bit of an integral
36762 type (long, int, short or char types).
36763 Also obtaining any other order bit is not uncommon.
36764 SDCC recognizes the following expressions to yield the highest order bit
36765 and generates optimized code for it, e.g.:
36768 \begin_layout Verse
36779 unsigned char hob1, aob1;
36783 bit hob2, hob3, aob2,
36793 hob1 = (gint >> 15) & 1;
36797 hob2 = (gint >> 15) & 1;
36801 hob3 = gint & 0x8000;
36806 aob1 = (gint >> 9) & 1;
36810 aob2 = (gint >> 8) & 1;
36814 aob3 = gint & 0x0800;
36824 \begin_layout Standard
36825 will generate the following code:
36828 \begin_layout Verse
36859 000A E5*01\InsetSpace ~
36886 000C 23\InsetSpace ~
36917 000D 54 01\InsetSpace ~
36945 000F F5*02\InsetSpace ~
37000 0011 E5*01\InsetSpace ~
37028 0013 33\InsetSpace ~
37058 0014 92*00\InsetSpace ~
37114 0016 E5*01\InsetSpace ~
37141 0018 33\InsetSpace ~
37171 0019 92*01\InsetSpace ~
37227 001B E5*01\InsetSpace ~
37286 001E 54 01\InsetSpace ~
37313 0020 F5*03\InsetSpace ~
37369 0022 E5*01\InsetSpace ~
37396 0024 13\InsetSpace ~
37426 0025 92*02\InsetSpace ~
37482 0027 E5*01\InsetSpace ~
37537 002B 92*03\InsetSpace ~
37565 \begin_layout Standard
37566 Other variations of these cases however will
37571 They are standard C expressions, so I heartily recommend these be the only
37572 way to get the highest order bit, (it is portable).
37573 Of course it will be recognized even if it is embedded in other expressions,
37577 \begin_layout Verse
37580 xyz = gint + ((gint >> 15) & 1);
37583 \begin_layout Standard
37584 will still be recognized.
37587 \begin_layout Subsection
37589 \begin_inset LatexCommand index
37590 name "Higher Order Byte"
37594 / Higher Order Word
37595 \begin_inset LatexCommand index
37596 name "Higher Order Word"
37603 \begin_layout Standard
37604 It is also frequently required to obtain a higher order byte or word of
37605 a larger integral type (long, int or short types).
37606 SDCC recognizes the following expressions to yield the higher order byte
37607 or word and generates optimized code for it, e.g.:
37610 \begin_layout Verse
37615 unsigned long int glong;
37623 unsigned char hob1,
37628 unsigned int how1, how2;
37637 hob1 = (gint >> 8) & 0xFF;
37641 hob2 = glong >> 24;
37645 how1 = (glong >> 16) & 0xFFFF;
37660 \begin_layout Standard
37661 will generate the following code:
37664 \begin_layout Verse
37695 0037 85*01*06\InsetSpace ~
37717 _foo_hob1_1_1,(_gint + 1)
37748 003A 85*05*07\InsetSpace ~
37770 _foo_hob2_1_1,(_glong + 3)
37800 003D 85*04*08\InsetSpace ~
37823 _foo_how1_1_1,(_glong + 2)
37825 0040 85*05*09\InsetSpace ~
37850 0043 85*03*0A\InsetSpace ~
37872 _foo_how2_1_1,(_glong + 1)
37874 0046 85*04*0B\InsetSpace ~
37897 (_foo_how2_1_1 + 1),(_glong + 2)
37900 \begin_layout Standard
37901 Again, variations of these cases may
37906 They are standard C expressions, so I heartily recommend these be the only
37907 way to get the higher order byte/word, (it is portable).
37908 Of course it will be recognized even if it is embedded in other expressions,
37912 \begin_layout Verse
37915 xyz = gint + ((gint >> 8) & 0xFF);
37918 \begin_layout Standard
37919 will still be recognized.
37922 \begin_layout Subsection
37924 \begin_inset LatexCommand label
37925 name "sub:Peephole-Optimizer"
37930 \begin_inset LatexCommand index
37931 name "Peephole optimizer"
37938 \begin_layout Standard
37939 The compiler uses a rule based, pattern matching and re-writing mechanism
37940 for peep-hole optimization.
37945 a peep-hole optimizer by Christopher W.
37946 Fraser (cwfraser\InsetSpace ~
37949 A default set of rules are compiled into the compiler, additional rules
37950 may be added with the
37956 \begin_layout Standard
37966 \begin_inset LatexCommand index
37967 name "-\\/-peep-file"
37974 The rule language is best illustrated with examples.
37977 \begin_layout Verse
37999 \begin_layout Standard
38000 The above rule will change the following assembly
38001 \begin_inset LatexCommand index
38002 name "Assembler routines"
38009 \begin_layout Verse
38017 \begin_layout Standard
38021 \begin_layout Verse
38027 \begin_layout Standard
38028 Note: All occurrences of a
38032 (pattern variable) must denote the same string.
38033 With the above rule, the assembly sequence:
38036 \begin_layout Verse
38044 \begin_layout Standard
38045 will remain unmodified.
38049 Other special case optimizations may be added by the
38056 \begin_layout Standard
38069 some variants of the 8051 MCU
38070 \begin_inset LatexCommand index
38071 name "MCS51 variants"
38084 The following two rules will change all
38101 \begin_layout Verse
38104 replace { lcall %1 } by { acall %1 }
38106 replace { ljmp %1 } by { ajmp %1 }
38109 \begin_layout Standard
38110 (NOTE: from version 2.7.3 on, you can use option -
38116 \begin_layout Standard
38128 \begin_inset LatexCommand index
38129 name "-\\/-acall-ajmp"
38133 , which also takes care of aligning the interrupt vectors properly.)
38138 \begin_layout Standard
38141 inline-assembler code
38143 is also passed through the peep hole optimizer, thus the peephole optimizer
38144 can also be used as an assembly level macro expander.
38145 The rules themselves are MCU dependent whereas the rule language infra-structur
38146 e is MCU independent.
38147 Peephole optimization rules for other MCU can be easily programmed using
38152 The syntax for a rule is as follows:
38155 \begin_layout Verse
38158 rule := replace [ restart ] '{' <assembly sequence> '
38196 <assembly sequence> '
38214 '}' [if <functionName> ] '
38219 \begin_layout Standard
38220 <assembly sequence> := assembly instruction (each instruction including
38221 labels must be on a separate line).
38225 The optimizer will apply to the rules
38226 one by one from the top in the sequence of their appearance, it will terminate
38227 when all rules are exhausted.
38228 If the 'restart' option is specified, then the optimizer will start matching
38229 the rules again from the top, this option for a rule is expensive (performance)
38230 , it is intended to be used in situations where a transformation will trigger
38231 the same rule again.
38232 An example of this (not a good one, it has side effects) is the following
38236 \begin_layout Verse
38256 \begin_layout Standard
38257 Note that the replace pattern cannot be a blank, but can be a comment line.
38258 Without the 'restart' option only the innermost 'pop' 'push' pair would
38259 be eliminated, i.e.:
38262 \begin_layout Verse
38274 \begin_layout Standard
38278 \begin_layout Verse
38288 \begin_layout Standard
38293 the restart option the rule will be applied again to the resulting code
38294 and then all the pop-push pairs will be eliminated to yield:
38297 \begin_layout Verse
38305 \begin_layout Standard
38306 A conditional function can be attached to a rule.
38307 Attaching rules are somewhat more involved, let me illustrate this with
38311 \begin_layout Verse
38335 \begin_layout Standard
38336 The optimizer does a look-up of a function name table defined in function
38341 in the source file SDCCpeeph.c, with the name
38346 If it finds a corresponding entry the function is called.
38347 Note there can be no parameters specified for these functions, in this
38352 is crucial, since the function
38356 expects to find the label in that particular variable (the hash table containin
38357 g the variable bindings is passed as a parameter).
38358 If you want to code more such functions, take a close look at the function
38359 labelInRange and the calling mechanism in source file SDCCpeeph.c.
38360 Currently implemented are
38362 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
38363 24bitMode, portIsDS390, 24bitModeAndPortDS390
38372 \begin_layout Standard
38373 I know this whole thing is a little kludgey, but maybe some day we will
38374 have some better means.
38375 If you are looking at this file, you will see the default rules that are
38376 compiled into the compiler, you can add your own rules in the default set
38377 there if you get tired of specifying the -
38381 \begin_layout Standard
38393 \begin_layout Section
38395 \begin_inset LatexCommand index
38396 name "ANSI-compliance"
38401 \begin_inset LatexCommand label
38402 name "sub:ANSI-Compliance"
38409 \begin_layout Standard
38410 The latest publicly available version of the standard
38412 ISO/IEC 9899 - Programming languages - C
38414 should be available at:
38415 \begin_inset LatexCommand url
38416 target "http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899"
38425 \begin_layout Standard
38426 Deviations from the compliance:
38429 \begin_layout Itemize
38430 functions are not reentrant
38431 \begin_inset LatexCommand index
38436 unless explicitly declared as such or the
38442 \begin_layout Standard
38452 \begin_inset LatexCommand index
38453 name "-\\/-stack-auto"
38459 command line option is specified.
38462 \begin_layout Itemize
38464 \begin_inset LatexCommand index
38470 \begin_inset LatexCommand index
38475 cannot be assigned values directly, cannot be passed as function parameters
38476 or assigned to each other and cannot be a return value
38477 \begin_inset LatexCommand index
38478 name "return value"
38482 from a function, e.g.:
38486 \begin_layout Verse
38509 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
38534 s parms) /* invalid in SDCC although allowed in ANSI */
38556 return rets; /* is invalid in SDCC although allowed in ANSI */
38562 \begin_layout Itemize
38563 initialization of structure arrays must be fully braced.
38567 \begin_layout Verse
38570 struct s { char x } a[] = {1, 2};\InsetSpace ~
38575 /* invalid in SDCC */
38578 } a[] = {{1}, {2}}; /* OK */
38582 \begin_layout Itemize
38584 \begin_inset LatexCommand index
38585 name "long long (not supported)"
38590 \begin_inset LatexCommand index
38591 name "int (64 bit) (not supported)"
38598 \begin_layout Itemize
38600 \begin_inset LatexCommand index
38601 name "double (not supported)"
38605 ' precision floating point
38606 \begin_inset LatexCommand index
38607 name "Floating point support"
38614 \begin_layout Itemize
38616 \begin_inset LatexCommand index
38621 function declarations are NOT allowed.
38625 \begin_layout Verse
38628 foo(i,j) /* this old style of function declarations */
38630 int i,j; /* is valid
38631 in ANSI but not valid in SDCC */
38646 \begin_layout Itemize
38647 Most enhancements in C99 are not supported, e.g.:
38651 \begin_layout Verse
38661 i=0; i<10; i++) /* is invalid in SDCC although allowed in C99 */
38665 \begin_layout Itemize
38666 But some have been added recently in SDCC 2.7.0.
38667 They must be considered alpha quality however.
38671 \begin_layout Verse
38676 \begin_inset LatexCommand index
38677 name "inline (not supported)"
38686 int increment (int a) { return a+1; } /* inlines the increment without function
38695 \begin_inset LatexCommand index
38696 name "inline (not supported)"
38705 p; /* accepted but ignored */
38709 \begin_layout Itemize
38710 Certain words that are valid identifiers in the standard may be reserved
38711 words in SDCC unless the
38717 \begin_layout Standard
38727 \begin_inset LatexCommand index
38728 name "-\\/-std-c89"
38740 \begin_layout Standard
38750 \begin_inset LatexCommand index
38751 name "-\\/-std-c99"
38757 command line options are used.
38758 These may include (depending on the selected processor): 'at', 'banked',
38759 'bit', 'code', 'critical', 'data', 'eeprom', 'far', 'flash', 'idata', 'interrup
38760 t', 'near', 'nonbanked', 'pdata', 'reentrant', 'sbit', 'sfr', 'shadowregs',
38761 'sram', 'using', 'wparam', 'xdata', '_overlay', '_asm', '_endasm', and
38763 Compliant equivalents of these keywords are always available in a form
38764 that begin with two underscores
38765 \begin_inset LatexCommand index
38766 name "\\_\\_ (prefix for extended keywords)"
38771 '__data' instead of 'data'.
38774 \begin_layout Itemize
38775 Integer promotion of variable arguments is not performed if the argument
38776 is explicitly taypecasted unless the
38782 \begin_layout Standard
38792 \begin_inset LatexCommand index
38793 name "-\\/-std-c89"
38805 \begin_layout Standard
38815 \begin_inset LatexCommand index
38816 name "-\\/-std-c99"
38822 command line options are used.
38826 \begin_layout Verse
38829 void vararg_func (char *str, ...) { str; }
38846 u is promoted to int before
38851 * passing to function */
38855 vararg_func ("%c", c);
38862 argument u is not promoted to int,
38867 * it is passed as char to function
38873 --std-cXX is not defined;
38878 * is promoted to int before passing
38884 if --std-cXX is defined */
38888 vararg_func ("%bc", (char)u);
38894 \begin_layout Section
38895 Cyclomatic Complexity
38896 \begin_inset LatexCommand index
38897 name "Cyclomatic complexity"
38904 \begin_layout Standard
38905 Cyclomatic complexity of a function is defined as the number of independent
38906 paths the program can take during execution of the function.
38907 This is an important number since it defines the number test cases you
38908 have to generate to validate the function.
38909 The accepted industry standard for complexity number is 10, if the cyclomatic
38910 complexity reported by SDCC exceeds 10 you should think about simplification
38911 of the function logic.
38912 Note that the complexity level is not related to the number of lines of
38913 code in a function.
38914 Large functions can have low complexity, and small functions can have large
38920 SDCC uses the following formula to compute the complexity:
38925 \begin_layout Standard
38926 complexity = (number of edges in control flow graph) - (number of nodes
38927 in control flow graph) + 2;
38931 Having said that the industry standard is 10,
38932 you should be aware that in some cases it be may unavoidable to have a
38933 complexity level of less than 10.
38934 For example if you have switch statement with more than 10 case labels,
38935 each case label adds one to the complexity level.
38936 The complexity level is by no means an absolute measure of the algorithmic
38937 complexity of the function, it does however provide a good starting point
38938 for which functions you might look at for further optimization.
38941 \begin_layout Section
38942 Retargetting for other Processors
38945 \begin_layout Standard
38946 The issues for retargetting the compiler are far too numerous to be covered
38948 What follows is a brief description of each of the seven phases of the
38949 compiler and its MCU dependency.
38952 \begin_layout Itemize
38953 Parsing the source and building the annotated parse tree.
38954 This phase is largely MCU independent (except for the language extensions).
38955 Syntax & semantic checks are also done in this phase, along with some initial
38956 optimizations like back patching labels and the pattern matching optimizations
38957 like bit-rotation etc.
38960 \begin_layout Itemize
38961 The second phase involves generating an intermediate code which can be easy
38962 manipulated during the later phases.
38963 This phase is entirely MCU independent.
38964 The intermediate code generation assumes the target machine has unlimited
38965 number of registers, and designates them with the name iTemp.
38966 The compiler can be made to dump a human readable form of the code generated
38971 \begin_layout Standard
38983 \begin_layout Itemize
38984 This phase does the bulk of the standard optimizations and is also MCU independe
38986 This phase can be broken down into several sub-phases:
38990 Break down intermediate
38991 code (iCode) into basic blocks.
38993 Do control flow & data flow analysis on the
38996 Do local common subexpression elimination, then global subexpressio
38999 Dead code elimination
39003 If loop optimizations
39004 caused any changes then do 'global subexpression elimination' and 'dead
39005 code elimination' again.
39008 \begin_layout Itemize
39009 This phase determines the live-ranges; by live range I mean those iTemp
39010 variables defined by the compiler that still survive after all the optimization
39012 Live range analysis
39013 \begin_inset LatexCommand index
39014 name "Live range analysis"
39018 is essential for register allocation, since these computation determines
39019 which of these iTemps will be assigned to registers, and for how long.
39022 \begin_layout Itemize
39023 Phase five is register allocation.
39024 There are two parts to this process.
39028 The first part I call 'register packing'
39029 (for lack of a better term).
39030 In this case several MCU specific expression folding is done to reduce
39035 The second part is more MCU independent and deals with
39036 allocating registers to the remaining live ranges.
39037 A lot of MCU specific code does creep into this phase because of the limited
39038 number of index registers available in the 8051.
39041 \begin_layout Itemize
39042 The Code generation phase is (unhappily), entirely MCU dependent and very
39043 little (if any at all) of this code can be reused for other MCU.
39044 However the scheme for allocating a homogenized assembler operand for each
39045 iCode operand may be reused.
39048 \begin_layout Itemize
39049 As mentioned in the optimization section the peep-hole optimizer is rule
39050 based system, which can reprogrammed for other MCUs.
39053 \begin_layout Standard
39054 More information is available on SDCC Wiki
39055 \begin_inset LatexCommand index
39061 \begin_inset LatexCommand url
39062 target "http://sdcc.wiki.sourceforge.net/SDCC+internals+and+porting"
39066 ) and in the thread
39067 \begin_inset LatexCommand url
39068 target "http://sf.net/mailarchive/message.php?msg_id=13954144"
39075 \begin_layout Chapter
39077 \begin_inset LatexCommand index
39078 name "Compiler internals"
39085 \begin_layout Section
39086 The anatomy of the compiler
39087 \begin_inset LatexCommand label
39088 name "sub:The-anatomy-of"
39095 \begin_layout Standard
39098 This is an excerpt from an article published in Circuit Cellar Magazine
39107 It's a little outdated (the compiler is much more efficient now and user/develo
39108 per friendly), but pretty well exposes the guts of it all.
39114 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
39115 It is fairly easy to retarget for other 8-bit MCU.
39116 Here we take a look at some of the internals of the compiler.
39120 \begin_layout Paragraph*
39122 \begin_inset LatexCommand index
39130 \begin_layout Standard
39131 Parsing the input source file and creating an AST (Annotated Syntax Tree
39132 \begin_inset LatexCommand index
39133 name "Annotated syntax tree"
39138 This phase also involves propagating types (annotating each node of the
39139 parse tree with type information) and semantic analysis.
39140 There are some MCU specific parsing rules.
39141 For example the storage classes, the extended storage classes are MCU specific
39142 while there may be a xdata storage class for 8051 there is no such storage
39143 class for z80 or Atmel AVR.
39144 SDCC allows MCU specific storage class extensions, i.e.
39145 xdata will be treated as a storage class specifier when parsing 8051 C
39146 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
39150 \begin_layout Paragraph*
39152 \begin_inset LatexCommand index
39160 \begin_layout Standard
39161 Intermediate code generation.
39162 In this phase the AST is broken down into three-operand form (iCode).
39163 These three operand forms are represented as doubly linked lists.
39164 ICode is the term given to the intermediate form generated by the compiler.
39165 ICode example section shows some examples of iCode generated for some simple
39166 C source functions.
39169 \begin_layout Paragraph*
39171 \begin_inset LatexCommand index
39172 name "Optimizations"
39179 \begin_layout Standard
39180 Bulk of the target independent optimizations is performed in this phase.
39181 The optimizations include constant propagation, common sub-expression eliminati
39182 on, loop invariant code movement, strength reduction of loop induction variables
39183 and dead-code elimination.
39186 \begin_layout Paragraph*
39187 Live range analysis
39188 \begin_inset LatexCommand index
39189 name "Live range analysis"
39196 \begin_layout Standard
39197 During intermediate code generation phase, the compiler assumes the target
39198 machine has infinite number of registers and generates a lot of temporary
39200 The live range computation determines the lifetime of each of these compiler-ge
39201 nerated temporaries.
39202 A picture speaks a thousand words.
39203 ICode example sections show the live range annotations for each of the
39205 It is important to note here, each iCode is assigned a number in the order
39206 of its execution in the function.
39207 The live ranges are computed in terms of these numbers.
39208 The from number is the number of the iCode which first defines the operand
39209 and the to number signifies the iCode which uses this operand last.
39212 \begin_layout Paragraph*
39213 Register Allocation
39214 \begin_inset LatexCommand index
39215 name "Register allocation"
39222 \begin_layout Standard
39223 The register allocation determines the type and number of registers needed
39225 In most MCUs only a few registers can be used for indirect addressing.
39226 In case of 8051 for example the registers R0 & R1 can be used to indirectly
39227 address the internal ram and DPTR to indirectly address the external ram.
39228 The compiler will try to allocate the appropriate register to pointer variables
39230 ICode example section shows the operands annotated with the registers assigned
39232 The compiler will try to keep operands in registers as much as possible;
39233 there are several schemes the compiler uses to do achieve this.
39234 When the compiler runs out of registers the compiler will check to see
39235 if there are any live operands which is not used or defined in the current
39236 basic block being processed, if there are any found then it will push that
39237 operand and use the registers in this block, the operand will then be popped
39238 at the end of the basic block.
39242 \begin_layout Standard
39243 There are other MCU specific considerations in this phase.
39244 Some MCUs have an accumulator; very short-lived operands could be assigned
39245 to the accumulator instead of a general-purpose register.
39248 \begin_layout Paragraph*
39252 \begin_layout Standard
39253 Figure II gives a table of iCode
39254 \begin_inset LatexCommand index
39259 operations supported by the compiler.
39260 The code generation involves translating these operations into corresponding
39261 assembly code for the processor.
39262 This sounds overly simple but that is the essence of code generation.
39263 Some of the iCode operations are generated on a MCU specific manner for
39264 example, the z80 port does not use registers to pass parameters so the
39265 SEND and RECV iCode operations will not be generated, and it also does
39266 not support JUMPTABLES.
39272 \begin_layout Standard
39276 \begin_inset Tabular
39277 <lyxtabular version="3" rows="39" columns="4">
39278 <features islongtable="true" headBottomDL="true">
39279 <column alignment="block" valignment="top" leftline="true" width="13col%">
39280 <column alignment="left" valignment="top" leftline="true" width="13col%">
39281 <column alignment="block" valignment="top" leftline="true" width="22col%">
39282 <column alignment="block" valignment="top" leftline="true" rightline="true" width="40col%">
39283 <row topline="true" bottomline="true" endhead="true">
39284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39287 \begin_layout Standard
39293 \begin_inset LatexCommand index
39303 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39306 \begin_layout Standard
39314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39317 \begin_layout Standard
39325 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39328 \begin_layout Standard
39337 <row topline="true">
39338 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39341 \begin_layout Standard
39349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39352 \begin_layout Standard
39355 IC_LEFT() IC_RESULT()
39360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39363 \begin_layout Standard
39371 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39374 \begin_layout Standard
39377 IC_RESULT = ! IC_LEFT;
39383 <row topline="true">
39384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39387 \begin_layout Standard
39395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39398 \begin_layout Standard
39401 IC_LEFT() IC_RESULT()
39406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39409 \begin_layout Standard
39412 Bitwise complement of
39417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39420 \begin_layout Standard
39423 IC_RESULT = ~IC_LEFT;
39429 <row topline="true">
39430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39433 \begin_layout Standard
39441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39444 \begin_layout Standard
39447 IC_LEFT() IC_RESULT()
39452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39455 \begin_layout Standard
39458 Rotate right with carry
39463 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39466 \begin_layout Standard
39469 IC_RESULT = (IC_LEFT << 1) | (IC_LEFT >> (sizeof(IC_LEFT)*8-1));
39475 <row topline="true">
39476 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39479 \begin_layout Standard
39487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39490 \begin_layout Standard
39493 IC_LEFT() IC_RESULT()
39498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39501 \begin_layout Standard
39504 Rotate left with carry
39509 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39512 \begin_layout Standard
39515 IC_RESULT = (IC_LEFT << (sizeof(LC_LEFT)*8-1) ) | (IC_LEFT >> 1);
39521 <row topline="true">
39522 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39525 \begin_layout Standard
39533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39536 \begin_layout Standard
39539 IC_LEFT() IC_RESULT()
39544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39547 \begin_layout Standard
39550 Get the highest order bit of IC_LEFT
39555 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39558 \begin_layout Standard
39561 IC_RESULT = (IC_LEFT >> (sizeof(IC_LEFT)*8 -1));
39567 <row topline="true">
39568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39571 \begin_layout Standard
39579 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39582 \begin_layout Standard
39585 IC_LEFT() IC_RESULT()
39590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39593 \begin_layout Standard
39601 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39604 \begin_layout Standard
39607 IC_RESULT = - IC_LEFT;
39613 <row topline="true">
39614 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39617 \begin_layout Standard
39625 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39628 \begin_layout Standard
39636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39639 \begin_layout Standard
39642 Push the operand into stack
39647 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39650 \begin_layout Standard
39659 <row topline="true">
39660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39663 \begin_layout Standard
39671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39674 \begin_layout Standard
39682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39685 \begin_layout Standard
39688 Pop the operand from the stack
39693 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39696 \begin_layout Standard
39705 <row topline="true">
39706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39709 \begin_layout Standard
39717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39720 \begin_layout Standard
39723 IC_LEFT() IC_RESULT()
39728 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39731 \begin_layout Standard
39734 Call the function represented by IC_LEFT
39739 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39742 \begin_layout Standard
39745 IC_RESULT = IC_LEFT();
39751 <row topline="true">
39752 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39755 \begin_layout Standard
39763 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39766 \begin_layout Standard
39769 IC_LEFT() IC_RESULT()
39774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39777 \begin_layout Standard
39780 Call via function pointer
39785 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39788 \begin_layout Standard
39791 IC_RESULT = (*IC_LEFT)();
39797 <row topline="true">
39798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39801 \begin_layout Standard
39809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39812 \begin_layout Standard
39820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39823 \begin_layout Standard
39826 Return the value in operand IC_LEFT
39831 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39834 \begin_layout Standard
39843 <row topline="true">
39844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39847 \begin_layout Standard
39855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39858 \begin_layout Standard
39866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39869 \begin_layout Standard
39877 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39880 \begin_layout Standard
39889 <row topline="true">
39890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39893 \begin_layout Standard
39901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39904 \begin_layout Standard
39912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39915 \begin_layout Standard
39923 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39926 \begin_layout Standard
39935 <row topline="true">
39936 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39939 \begin_layout Standard
39947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39950 \begin_layout Standard
39953 IC_LEFT() IC_RIGHT() IC_RESULT()
39958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39961 \begin_layout Standard
39969 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
39972 \begin_layout Standard
39975 IC_RESULT = IC_LEFT + IC_RIGHT
39981 <row topline="true">
39982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39985 \begin_layout Standard
39993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
39996 \begin_layout Standard
39999 IC_LEFT() IC_RIGHT() IC_RESULT()
40004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40007 \begin_layout Standard
40015 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40018 \begin_layout Standard
40021 IC_RESULT = IC_LEFT - IC_RIGHT
40027 <row topline="true">
40028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40031 \begin_layout Standard
40039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40042 \begin_layout Standard
40045 IC_LEFT() IC_RIGHT() IC_RESULT()
40050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40053 \begin_layout Standard
40061 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40064 \begin_layout Standard
40067 IC_RESULT = IC_LEFT * IC_RIGHT;
40073 <row topline="true">
40074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40077 \begin_layout Standard
40085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40088 \begin_layout Standard
40091 IC_LEFT() IC_RIGHT() IC_RESULT()
40096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40099 \begin_layout Standard
40107 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40110 \begin_layout Standard
40113 IC_RESULT = IC_LEFT / IC_RIGHT;
40119 <row topline="true">
40120 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40123 \begin_layout Standard
40131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40134 \begin_layout Standard
40137 IC_LEFT() IC_RIGHT() IC_RESULT()
40142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40145 \begin_layout Standard
40153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40156 \begin_layout Standard
40159 IC_RESULT = IC_LEFT % IC_RIGHT;
40165 <row topline="true">
40166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40169 \begin_layout Standard
40177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40180 \begin_layout Standard
40183 IC_LEFT() IC_RIGHT() IC_RESULT()
40188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40191 \begin_layout Standard
40199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40202 \begin_layout Standard
40205 IC_RESULT = IC_LEFT < IC_RIGHT;
40211 <row topline="true">
40212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40215 \begin_layout Standard
40223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40226 \begin_layout Standard
40229 IC_LEFT() IC_RIGHT() IC_RESULT()
40234 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40237 \begin_layout Standard
40245 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40248 \begin_layout Standard
40251 IC_RESULT = IC_LEFT > IC_RIGHT;
40257 <row topline="true">
40258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40261 \begin_layout Standard
40269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40272 \begin_layout Standard
40275 IC_LEFT() IC_RIGHT() IC_RESULT()
40280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40283 \begin_layout Standard
40291 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40294 \begin_layout Standard
40297 IC_RESULT = IC_LEFT == IC_RIGHT;
40303 <row topline="true">
40304 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40307 \begin_layout Standard
40315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40318 \begin_layout Standard
40321 IC_LEFT() IC_RIGHT() IC_RESULT()
40326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40329 \begin_layout Standard
40332 Logical and operation
40337 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40340 \begin_layout Standard
40343 IC_RESULT = IC_LEFT && IC_RIGHT;
40349 <row topline="true">
40350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40353 \begin_layout Standard
40361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40364 \begin_layout Standard
40367 IC_LEFT() IC_RIGHT() IC_RESULT()
40372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40375 \begin_layout Standard
40378 Logical or operation
40383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40386 \begin_layout Standard
40389 IC_RESULT = IC_LEFT || IC_RIGHT;
40395 <row topline="true">
40396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40399 \begin_layout Standard
40407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40410 \begin_layout Standard
40413 IC_LEFT() IC_RIGHT() IC_RESULT()
40418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40421 \begin_layout Standard
40429 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40432 \begin_layout Standard
40435 IC_RESULT = IC_LEFT ^ IC_RIGHT;
40441 <row topline="true">
40442 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40445 \begin_layout Standard
40453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40456 \begin_layout Standard
40459 IC_LEFT() IC_RIGHT() IC_RESULT()
40464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40467 \begin_layout Standard
40475 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40478 \begin_layout Standard
40481 IC_RESULT = IC_LEFT | IC_RIGHT;
40487 <row topline="true">
40488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40491 \begin_layout Standard
40499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40502 \begin_layout Standard
40505 IC_LEFT() IC_RIGHT() IC_RESULT()
40510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40513 \begin_layout Standard
40521 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40524 \begin_layout Standard
40527 IC_RESULT = IC_LEFT & IC_RIGHT;
40533 <row topline="true">
40534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40537 \begin_layout Standard
40545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40548 \begin_layout Standard
40551 IC_LEFT() IC_RIGHT() IC_RESULT()
40556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40559 \begin_layout Standard
40567 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40570 \begin_layout Standard
40573 IC_RESULT = IC_LEFT << IC_RIGHT
40579 <row topline="true">
40580 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40583 \begin_layout Standard
40591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40594 \begin_layout Standard
40597 IC_LEFT() IC_RIGHT() IC_RESULT()
40602 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40605 \begin_layout Standard
40613 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40616 \begin_layout Standard
40619 IC_RESULT = IC_LEFT >> IC_RIGHT
40625 <row topline="true">
40626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40629 \begin_layout Standard
40639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40642 \begin_layout Standard
40645 IC_LEFT() IC_RESULT()
40650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40653 \begin_layout Standard
40661 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40664 \begin_layout Standard
40667 IC_RESULT = (*IC_LEFT);
40673 <row topline="true">
40674 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40677 \begin_layout Standard
40685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40688 \begin_layout Standard
40691 IC_RIGHT() IC_RESULT()
40696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40699 \begin_layout Standard
40707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40710 \begin_layout Standard
40713 (*IC_RESULT) = IC_RIGHT;
40719 <row topline="true">
40720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40723 \begin_layout Standard
40731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40734 \begin_layout Standard
40737 IC_RIGHT() IC_RESULT()
40742 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40745 \begin_layout Standard
40753 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40756 \begin_layout Standard
40759 IC_RESULT = IC_RIGHT;
40765 <row topline="true">
40766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40769 \begin_layout Standard
40777 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40780 \begin_layout Standard
40783 IC_COND IC_TRUE IC_LABEL
40788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40791 \begin_layout Standard
40795 If true label is present then jump to true label if condition is true else
40796 jump to false label if condition is false
40801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40804 \begin_layout Standard
40807 if (IC_COND) goto IC_TRUE;
40813 If (!IC_COND) goto IC_FALSE;
40819 <row topline="true">
40820 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40823 \begin_layout Standard
40831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40834 \begin_layout Standard
40837 IC_LEFT() IC_RESULT()
40842 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40845 \begin_layout Standard
40853 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40856 \begin_layout Standard
40859 IC_RESULT = &IC_LEFT();
40865 <row topline="true">
40866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40869 \begin_layout Standard
40877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40880 \begin_layout Standard
40883 IC_JTCOND IC_JTLABELS
40888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40891 \begin_layout Standard
40894 Jump to list of labels depending on the value of JTCOND
40899 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40902 \begin_layout Standard
40911 <row topline="true">
40912 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40915 \begin_layout Standard
40923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40926 \begin_layout Standard
40929 IC_RIGHT() IC_LEFT() IC_RESULT()
40934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40937 \begin_layout Standard
40945 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40948 \begin_layout Standard
40951 IC_RESULT = (typeof IC_LEFT) IC_RIGHT;
40957 <row topline="true">
40958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40961 \begin_layout Standard
40969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40972 \begin_layout Standard
40980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
40983 \begin_layout Standard
40986 This is used for passing parameters in registers;
40988 move IC_LEFT to the next
40989 available parameter register.
40994 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
40997 \begin_layout Standard
41006 <row topline="true">
41007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41010 \begin_layout Standard
41018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41021 \begin_layout Standard
41029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41032 \begin_layout Standard
41035 This is used for receiving parameters passed in registers;
41038 in the next parameter register to IC_RESULT
41043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41046 \begin_layout Standard
41055 <row topline="true" bottomline="true">
41056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41059 \begin_layout Standard
41063 (some more have been added)
41068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41071 \begin_layout Standard
41077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
41080 \begin_layout Standard
41086 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
41089 \begin_layout Standard
41122 \begin_layout Standard
41123 \begin_inset Note Note
41126 \begin_layout Standard
41127 In the original article Figure II was announced to be downloadable on
41132 ftp://ftp.circuitcellar.com/pub/Circuit_Cellar/2000/121/dutta.ZIP
41140 \begin_layout Paragraph*
41142 \begin_inset LatexCommand index
41150 \begin_layout Standard
41151 This section shows some details of iCode.
41152 The example C code does not do anything useful; it is used as an example
41153 to illustrate the intermediate code generated by the compiler.
41156 \begin_layout Verse
41166 /* This function does nothing useful.
41173 for the purpose of explaining iCode */
41176 short function (data
41185 short i=10; \InsetSpace ~
41187 /* dead initialization eliminated */
41193 /* dead initialization eliminated */
41221 /* compiler detects i,j to be induction
41226 for (i = 0, j = 10 ; i < 10 ; i++, j
41232 \begin_layout Standard
41255 mul += i * 3; \InsetSpace ~
41257 /* this multiplication remains */
41264 j * 3;\InsetSpace ~
41266 /* this multiplication changed to addition */
41280 \begin_layout Standard
41281 In addition to the operands each iCode contains information about the filename
41282 and line it corresponds to in the source file.
41283 The first field in the listing should be interpreted as follows:
41288 Filename(linenumber: iCode Execution sequence number : ICode hash table
41289 key : loop depth of the iCode).
41294 Then follows the human readable form of the ICode operation.
41295 Each operand of this triplet form can be of three basic types a) compiler
41296 generated temporary b) user defined variable c) a constant value.
41297 Note that local variables and parameters are replaced by compiler generated
41300 \begin_inset LatexCommand index
41301 name "Live range analysis"
41305 are computed only for temporaries (i.e.
41306 live ranges are not computed for global variables).
41308 \begin_inset LatexCommand index
41309 name "Register allocation"
41313 are allocated for temporaries only.
41314 Operands are formatted in the following manner:
41319 Operand Name [lr live-from : live-to ] { type information } [ registers
41325 As mentioned earlier the live ranges are computed in terms of the execution
41326 sequence number of the iCodes, for example
41328 the iTemp0 is live from (i.e.
41329 first defined in iCode with execution sequence number 3, and is last used
41330 in the iCode with sequence number 5).
41331 For induction variables such as iTemp21 the live range computation extends
41332 the lifetime from the start to the end of the loop.
41334 The register allocator
41335 used the live range information to allocate registers, the same registers
41336 may be used for different temporaries if their live ranges do not overlap,
41337 for example r0 is allocated to both iTemp6 and to iTemp17 since their live
41338 ranges do not overlap.
41339 In addition the allocator also takes into consideration the type and usage
41340 of a temporary, for example itemp6 is a pointer to near space and is used
41341 as to fetch data from (i.e.
41342 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
41343 Some short lived temporaries are allocated to special registers which have
41344 meaning to the code generator e.g.
41345 iTemp13 is allocated to a pseudo register CC which tells the back end that
41346 the temporary is used only for a conditional jump the code generation makes
41347 use of this information to optimize a compare and jump ICode.
41351 \begin_inset LatexCommand index
41352 name "Loop optimization"
41356 performed by the compiler.
41357 It can detect induction variables iTemp21(i) and iTemp23(j).
41358 Also note the compiler does selective strength reduction
41359 \begin_inset LatexCommand index
41360 name "Strength reduction"
41365 the multiplication of an induction variable in line 18 (gint = j * 3) is
41366 changed to addition, a new temporary iTemp17 is allocated and assigned
41367 a initial value, a constant 3 is then added for each iteration of the loop.
41368 The compiler does not change the multiplication
41369 \begin_inset LatexCommand index
41370 name "Multiplication"
41374 in line 17 however since the processor does support an 8 * 8 bit multiplication.
41377 Note the dead code elimination
41378 \begin_inset LatexCommand index
41379 name "Dead-code elimination"
41383 optimization eliminated the dead assignments in line 7 & 8 to I and sum
41389 \begin_layout Standard
41392 Sample.c (5:1:0:0) _entry($9) :
41395 \begin_layout Standard
41398 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
41401 \begin_layout Standard
41404 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
41407 \begin_layout Standard
41410 Sample.c(11:4:53:0) preHeaderLbl0($11) :
41413 \begin_layout Standard
41416 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
41420 \begin_layout Standard
41423 Sample.c(11:6:5:1) _whilecontinue_0($1) :
41426 \begin_layout Standard
41429 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
41433 \begin_layout Standard
41436 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
41439 \begin_layout Standard
41442 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
41446 \begin_layout Standard
41449 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
41453 \begin_layout Standard
41456 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
41460 \begin_layout Standard
41463 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
41467 \begin_layout Standard
41470 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
41471 * int}[r0] + 0x2 {short}
41474 \begin_layout Standard
41477 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
41480 \begin_layout Standard
41483 Sample.c(11:17:21:0)_whilebreak_0($3) :
41486 \begin_layout Standard
41489 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
41492 \begin_layout Standard
41495 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
41498 \begin_layout Standard
41501 Sample.c(15:20:54:0)preHeaderLbl1($13) :
41504 \begin_layout Standard
41507 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
41510 \begin_layout Standard
41513 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
41516 \begin_layout Standard
41519 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
41522 \begin_layout Standard
41525 Sample.c(15:24:26:1)_forcond_0($4) :
41528 \begin_layout Standard
41531 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
41535 \begin_layout Standard
41538 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
41541 \begin_layout Standard
41544 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
41545 + ITemp21 [lr21:38]{short}[r4]
41548 \begin_layout Standard
41551 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
41555 \begin_layout Standard
41558 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
41559 + iTemp15 [lr29:30]{short}[r1]
41562 \begin_layout Standard
41565 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
41569 \begin_layout Standard
41572 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
41576 \begin_layout Standard
41579 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
41583 \begin_layout Standard
41586 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
41590 \begin_layout Standard
41593 Sample.c(19:38:47:1) goto _forcond_0($4)
41596 \begin_layout Standard
41599 Sample.c(19:39:48:0)_forbreak_0($7) :
41602 \begin_layout Standard
41605 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
41606 + ITemp11 [lr19:40]{short}[r3]
41609 \begin_layout Standard
41612 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
41615 \begin_layout Standard
41618 Sample.c(20:42:51:0)_return($8) :
41621 \begin_layout Standard
41624 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
41630 Finally the code generated for this function:
41635 \begin_layout Standard
41641 \begin_layout Standard
41647 \begin_layout Standard
41655 \begin_layout Standard
41661 \begin_layout Standard
41669 \begin_layout Standard
41675 \begin_layout Standard
41678 ; ----------------------------------------------
41681 \begin_layout Standard
41684 ; function function
41687 \begin_layout Standard
41690 ; ----------------------------------------------
41693 \begin_layout Standard
41699 \begin_layout Standard
41702 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
41705 \begin_layout Standard
41713 \begin_layout Standard
41716 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
41719 \begin_layout Standard
41727 \begin_layout Standard
41730 ;_whilecontinue_0($1) :
41733 \begin_layout Standard
41739 \begin_layout Standard
41742 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
41745 \begin_layout Standard
41748 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
41751 \begin_layout Standard
41759 \begin_layout Standard
41767 \begin_layout Standard
41775 \begin_layout Standard
41783 \begin_layout Standard
41791 \begin_layout Standard
41799 \begin_layout Standard
41807 \begin_layout Standard
41813 \begin_layout Standard
41816 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
41819 \begin_layout Standard
41827 \begin_layout Standard
41835 \begin_layout Standard
41838 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
41841 \begin_layout Standard
41849 \begin_layout Standard
41857 \begin_layout Standard
41865 \begin_layout Standard
41873 \begin_layout Standard
41881 \begin_layout Standard
41889 \begin_layout Standard
41892 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
41895 \begin_layout Standard
41903 \begin_layout Standard
41911 \begin_layout Standard
41919 \begin_layout Standard
41927 \begin_layout Standard
41935 \begin_layout Standard
41938 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
41941 \begin_layout Standard
41949 \begin_layout Standard
41957 \begin_layout Standard
41965 \begin_layout Standard
41968 ; iTemp6 [lr5:16]{_near * int}[r0] =
41971 \begin_layout Standard
41974 ; iTemp6 [lr5:16]{_near * int}[r0] +
41977 \begin_layout Standard
41983 \begin_layout Standard
41991 \begin_layout Standard
41994 ; goto _whilecontinue_0($1)
41997 \begin_layout Standard
42005 \begin_layout Standard
42008 ; _whilebreak_0($3) :
42011 \begin_layout Standard
42017 \begin_layout Standard
42020 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
42023 \begin_layout Standard
42031 \begin_layout Standard
42034 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
42037 \begin_layout Standard
42045 \begin_layout Standard
42048 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
42051 \begin_layout Standard
42059 \begin_layout Standard
42062 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
42065 \begin_layout Standard
42073 \begin_layout Standard
42081 \begin_layout Standard
42084 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
42087 \begin_layout Standard
42095 \begin_layout Standard
42103 \begin_layout Standard
42109 \begin_layout Standard
42115 \begin_layout Standard
42118 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
42121 \begin_layout Standard
42124 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
42127 \begin_layout Standard
42135 \begin_layout Standard
42143 \begin_layout Standard
42151 \begin_layout Standard
42159 \begin_layout Standard
42167 \begin_layout Standard
42173 \begin_layout Standard
42176 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
42179 \begin_layout Standard
42182 ; iTemp21 [lr21:38]{short}[r4]
42185 \begin_layout Standard
42193 \begin_layout Standard
42201 \begin_layout Standard
42209 \begin_layout Standard
42212 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
42215 \begin_layout Standard
42223 \begin_layout Standard
42231 \begin_layout Standard
42239 \begin_layout Standard
42247 \begin_layout Standard
42250 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
42253 \begin_layout Standard
42256 ; iTemp15 [lr29:30]{short}[r1]
42259 \begin_layout Standard
42267 \begin_layout Standard
42275 \begin_layout Standard
42278 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
42281 \begin_layout Standard
42289 \begin_layout Standard
42297 \begin_layout Standard
42305 \begin_layout Standard
42313 \begin_layout Standard
42321 \begin_layout Standard
42329 \begin_layout Standard
42332 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
42335 \begin_layout Standard
42343 \begin_layout Standard
42351 \begin_layout Standard
42359 \begin_layout Standard
42367 \begin_layout Standard
42375 \begin_layout Standard
42383 \begin_layout Standard
42386 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
42389 \begin_layout Standard
42397 \begin_layout Standard
42400 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
42403 \begin_layout Standard
42411 \begin_layout Standard
42416 cjne r5,#0xff,00104$
42419 \begin_layout Standard
42427 \begin_layout Standard
42430 ; goto _forcond_0($4)
42433 \begin_layout Standard
42441 \begin_layout Standard
42444 ; _forbreak_0($7) :
42447 \begin_layout Standard
42453 \begin_layout Standard
42456 ; ret iTemp24 [lr40:41]{short}
42459 \begin_layout Standard
42467 \begin_layout Standard
42475 \begin_layout Standard
42483 \begin_layout Standard
42489 \begin_layout Standard
42495 \begin_layout Standard
42505 \begin_layout Section
42506 A few words about basic block successors, predecessors and dominators
42509 \begin_layout Standard
42510 Successors are basic blocks
42511 \begin_inset LatexCommand index
42512 name "Basic blocks"
42516 that might execute after this basic block.
42518 Predecessors are basic blocks
42519 that might execute before reaching this basic block.
42521 Dominators are basic
42522 blocks that WILL execute before reaching this basic block.
42527 \begin_layout Standard
42531 \begin_layout Standard
42535 \begin_layout Standard
42543 \begin_layout Standard
42547 \begin_layout Standard
42555 \begin_layout Standard
42561 \begin_layout Standard
42562 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
42565 \begin_layout Standard
42566 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
42569 \begin_layout Standard
42570 c) domVect of [BB4] = BB1 ...
42571 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
42575 \begin_layout Chapter
42579 \begin_layout Standard
42580 \begin_inset LatexCommand url
42581 target "http://sdcc.sourceforge.net/#Who"
42591 Thanks to all the other volunteer developers who have helped with coding,
42592 testing, web-page creation, distribution sets, etc.
42593 You know who you are :-)
42601 Thanks to Sourceforge
42602 \begin_inset LatexCommand url
42603 target "http://www.sf.net"
42607 which has hosted the project since 1999 and donates significant download
42616 Also thanks to all SDCC Distributed Compile Farm members for donating CPU
42617 cycles and bandwidth for snapshot builds.
42622 \begin_layout Standard
42623 This document was initially written by Sandeep Dutta
42626 \begin_layout Standard
42627 All product names mentioned herein may be trademarks
42628 \begin_inset LatexCommand index
42633 of their respective companies.
42637 \begin_layout Section*
42641 \begin_layout Standard
42642 To avoid confusion, the installation and building options for SDCC itself
42643 (chapter 2) are not part of the index.
42646 \begin_layout Standard
42647 \begin_inset LatexCommand printindex