1 #LyX 1.3 created this file. For more info see http://www.lyx.org/
6 pdftitle={SDCC Compiler User Guide},
7 pdfauthor={SDCC development team},
8 pdfsubject={installation, user manual},
9 pdfkeywords={8032, 8051, ansi, c, compiler, CPU, DS390,
10 embedded, GPL, HC08, manual, mcs51, PIC, Z80},
12 linkcolor=blue] {hyperref}
16 \inputencoding default
19 \paperfontsize default
21 \papersize letterpaper
26 \use_numerical_citations 0
27 \paperorientation portrait
34 \paragraph_separation indent
36 \quotes_language swedish
44 Please note: double dashed longoptions (e.g.
45 --version) are written this way: -
59 three consecutive dashes simply result in a long resp.
63 Architecture specific stuff (like memory models, code examples) should maybe
67 into seperate sections/chapters/appendices (it is hard to document PIC or
71 a 8051 centered document)
74 SDCC Compiler User Guide
84 The above strings enclosed in $ are automatically updated by cvs
88 \begin_inset LatexCommand \tableofcontents{}
105 is a Freeware, retargettable, optimizing ANSI-C compiler by
109 designed for 8 bit Microprocessors.
110 The current version targets Intel MCS51 based Microprocessors (8031, 8032,
112 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052, mcs51 CPU}
116 , etc.), Dallas DS80C390 variants, Motorola HC08 and Zilog Z80 based MCUs.
117 It can be retargetted for other microprocessors, support for Microchip
118 PIC, Atmel AVR is under development.
119 The entire source code for the compiler is distributed under GPL.
120 SDCC uses ASXXXX & ASLINK, a Freeware, retargettable assembler & linker.
121 SDCC has extensive language extensions suitable for utilizing various microcont
122 rollers and underlying hardware effectively.
127 In addition to the MCU specific optimizations SDCC also does a host of standard
131 global sub expression elimination,
134 loop optimizations (loop invariant, strength reduction of induction variables
138 constant folding & propagation,
144 dead code elimination
154 For the back-end SDCC uses a global register allocation scheme which should
155 be well suited for other 8 bit MCUs.
160 The peep hole optimizer uses a rule based substitution mechanism which is
166 Supported data-types are:
169 char (8 bits, 1 byte),
172 short and int (16 bits, 2 bytes),
175 long (32 bit, 4 bytes)
182 The compiler also allows
184 inline assembler code
186 to be embedded anywhere in a function.
187 In addition, routines developed in assembly can also be called.
191 SDCC also provides an option (-
201 -cyclomatic) to report the relative complexity of a function.
202 These functions can then be further optimized, or hand coded in assembly
208 SDCC also comes with a companion source level debugger SDCDB, the debugger
209 currently uses ucSim a freeware simulator for 8051 and other micro-controllers.
214 The latest version can be downloaded from
215 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
225 Please note: the compiler will probably always be some steps ahead of this
230 \begin_inset LatexCommand \index{Status of documentation}
240 Obviously this has pros and cons
249 All packages used in this compiler system are
257 ; source code for all the sub-packages (pre-processor, assemblers, linkers
258 etc) is distributed with the package.
259 This documentation is maintained using a freeware word processor (LyX).
261 This program is free software; you can redistribute it and/or modify it
262 under the terms of the GNU General Public License
263 \begin_inset LatexCommand \index{GNU General Public License, GPL}
267 as published by the Free Software Foundation; either version 2, or (at
268 your option) any later version.
269 This program is distributed in the hope that it will be useful, but WITHOUT
270 ANY WARRANTY; without even the implied warranty
271 \begin_inset LatexCommand \index{warranty}
275 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
276 See the GNU General Public License for more details.
277 You should have received a copy of the GNU General Public License along
278 with this program; if not, write to the Free Software Foundation, 59 Temple
279 Place - Suite 330, Boston, MA 02111-1307, USA.
280 In other words, you are welcome to use, share and improve this program.
281 You are forbidden to forbid anyone else to use, share and improve what
283 Help stamp out software-hoarding!
286 Typographic conventions
287 \begin_inset LatexCommand \index{Typographic conventions}
294 Throughout this manual, we will use the following convention.
295 Commands you have to type in are printed in
303 Code samples are printed in
308 Interesting items and new terms are printed in
313 Compatibility with previous versions
316 This version has numerous bug fixes compared with the previous version.
317 But we also introduced some incompatibilities with older versions.
318 Not just for the fun of it, but to make the compiler more stable, efficient
320 \begin_inset LatexCommand \index{ANSI-compliance}
325 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
329 for ANSI-Compliance).
335 short is now equivalent to int (16 bits), it used to be equivalent to char
336 (8 bits) which is not ANSI compliant
339 the default directory for gcc-builds where include, library and documentation
340 files are stored is now in /usr/local/share
343 char type parameters to vararg functions are casted to int unless explicitly
360 will push a as an int and as a char resp.
373 -regextend has been removed
386 -noregparms has been removed
399 -stack-after-data has been removed
404 <pending: more incompatibilities?>
410 What do you need before you start installation of SDCC? A computer, and
412 The preferred method of installation is to compile SDCC from source using
414 For Windows some pre-compiled binary distributions are available for your
416 You should have some experience with command line tools and compiler use.
422 The SDCC home page at
423 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
427 is a great place to find distribution sets.
428 You can also find links to the user mailing lists that offer help or discuss
429 SDCC with other SDCC users.
430 Web links to other SDCC related sites can also be found here.
431 This document can be found in the DOC directory of the source package as
433 Some of the other tools (simulator and assembler) included with SDCC contain
434 their own documentation and can be found in the source distribution.
435 If you want the latest unreleased software, the complete source package
436 is available directly by anonymous CVS on cvs.sdcc.sourceforge.net.
439 Wishes for the future
442 There are (and always will be) some things that could be done.
443 Here are some I can think of:
450 char KernelFunction3(char p) at 0x340;
458 \begin_inset LatexCommand \index{code banking (not supported)}
468 If you can think of some more, please see the chapter
469 \begin_inset LatexCommand \ref{sub:Requesting-Features}
473 about filing feature requests
474 \begin_inset LatexCommand \index{Requesting features}
479 \begin_inset LatexCommand \index{Feature request}
489 \begin_inset LatexCommand \index{Installation}
496 For most users it is sufficient to skip to either section
497 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
502 \begin_inset LatexCommand \ref{sub:Windows-Install}
507 More detailled instructions follow below.
511 \begin_inset LatexCommand \index{Options SDCC configuration}
518 The install paths, search paths and other options are defined when running
520 The defaults can be overridden by:
522 \labelwidthstring 00.00.0000
534 -prefix see table below
536 \labelwidthstring 00.00.0000
548 -exec_prefix see table below
550 \labelwidthstring 00.00.0000
562 -bindir see table below
564 \labelwidthstring 00.00.0000
576 -datadir see table below
578 \labelwidthstring 00.00.0000
580 docdir environment variable, see table below
582 \labelwidthstring 00.00.0000
584 include_dir_suffix environment variable, see table below
586 \labelwidthstring 00.00.0000
588 lib_dir_suffix environment variable, see table below
590 \labelwidthstring 00.00.0000
592 sdccconf_h_dir_separator environment variable, either / or
597 This character will only be used in sdccconf.h; don't forget it's a C-header,
598 therefore a double-backslash is needed there.
600 \labelwidthstring 00.00.0000
612 -disable-mcs51-port Excludes the Intel mcs51 port
614 \labelwidthstring 00.00.0000
626 -disable-gbz80-port Excludes the Gameboy gbz80 port
628 \labelwidthstring 00.00.0000
640 -disable-z80-port Excludes the z80 port
642 \labelwidthstring 00.00.0000
654 -disable-avr-port Excludes the AVR port
656 \labelwidthstring 00.00.0000
668 -disable-ds390-port Excludes the DS390 port
670 \labelwidthstring 00.00.0000
682 -disable-hc08-port Excludes the HC08 port
684 \labelwidthstring 00.00.0000
696 -disable-pic-port Excludes the PIC port
698 \labelwidthstring 00.00.0000
710 -disable-xa51-port Excludes the XA51 port
712 \labelwidthstring 00.00.0000
724 -disable-ucsim Disables configuring and building of ucsim
726 \labelwidthstring 00.00.0000
738 -disable-device-lib-build Disables automatically building device libraries
740 \labelwidthstring 00.00.0000
752 -disable-packihx Disables building packihx
754 \labelwidthstring 00.00.0000
766 -enable-libgc Use the Bohem memory allocator.
767 Lower runtime footprint.
770 Furthermore the environment variables CC, CFLAGS, ...
771 the tools and their arguments can be influenced.
772 Please see `configure -
782 -help` and the man/info pages of `configure` for details.
786 The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB,
787 STD_FP_LIB, STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_
788 NAME, SDCC_INCLUDE_NAME, SDCC_LIB_NAME are defined by `configure` too.
789 At the moment it's not possible to change the default settings (it was
790 simply never required).
794 These configure options are compiled into the binaries, and can only be
795 changed by rerunning 'configure' and recompiling SDCC.
796 The configure options are written in
800 to distinguish them from run time environment variables (see section search
806 \begin_inset Quotes sld
810 \begin_inset Quotes srd
813 are used by the SDCC team to build the official Win32 binaries.
814 The SDCC team uses Mingw32 to build the official Windows binaries, because
821 a gcc compiler and last but not least
824 the binaries can be built by cross compiling on Sourceforge's compile farm.
827 See the examples, how to pass the Win32 settings to 'configure'.
828 The other Win32 builds using Borland, VC or whatever don't use 'configure',
829 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
841 <lyxtabular version="3" rows="8" columns="3">
843 <column alignment="block" valignment="top" leftline="true" width="0in">
844 <column alignment="block" valignment="top" leftline="true" width="0in">
845 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
846 <row topline="true" bottomline="true">
847 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
863 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
883 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
891 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
923 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
957 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
995 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1006 <row topline="true">
1007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1029 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1044 <row topline="true">
1045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1063 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1072 <row topline="true" bottomline="true">
1073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1091 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1109 'configure' also computes relative paths.
1110 This is needed for full relocatability of a binary package and to complete
1111 search paths (see section search paths below):
1117 \begin_inset Tabular
1118 <lyxtabular version="3" rows="4" columns="3">
1120 <column alignment="block" valignment="top" leftline="true" width="0in">
1121 <column alignment="block" valignment="top" leftline="true" width="0in">
1122 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1123 <row topline="true" bottomline="true">
1124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1140 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1149 <row topline="true" bottomline="true">
1150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1168 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1177 <row bottomline="true">
1178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1188 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1196 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1205 <row bottomline="true">
1206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1224 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1257 \begin_inset Quotes srd
1261 \begin_inset Quotes srd
1275 \begin_inset Quotes srd
1279 \begin_inset Quotes srd
1307 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1316 \begin_inset Quotes srd
1319 i586-mingw32msvc-gcc
1320 \begin_inset Quotes srd
1324 \begin_inset Quotes srd
1327 i586-mingw32msvc-g++
1328 \begin_inset Quotes srd
1336 \begin_inset Quotes srd
1339 i586-mingw32msvc-ranlib
1340 \begin_inset Quotes srd
1348 \begin_inset Quotes srd
1351 i586-mingw32msvc-strip
1352 \begin_inset Quotes srd
1370 \begin_inset Quotes srd
1374 \begin_inset Quotes srd
1392 \begin_inset Quotes srd
1396 \begin_inset Quotes srd
1404 \begin_inset Quotes srd
1408 \begin_inset Quotes srd
1416 \begin_inset Quotes srd
1420 \begin_inset Quotes srd
1428 \begin_inset Quotes srd
1432 \begin_inset Quotes srd
1439 sdccconf_h_dir_separator=
1440 \begin_inset Quotes srd
1452 \begin_inset Quotes srd
1469 -disable-device-lib-build
1497 -host=i586-mingw32msvc -
1507 -build=unknown-unknown-linux-gnu
1511 \begin_inset Quotes sld
1515 \begin_inset Quotes srd
1518 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
1527 \begin_inset Quotes srd
1531 \begin_inset Quotes srd
1539 \begin_inset Quotes srd
1543 \begin_inset Quotes srd
1561 \begin_inset Quotes srd
1565 \begin_inset Quotes srd
1583 \begin_inset Quotes srd
1587 \begin_inset Quotes srd
1595 \begin_inset Quotes srd
1599 \begin_inset Quotes srd
1607 \begin_inset Quotes srd
1611 \begin_inset Quotes srd
1619 \begin_inset Quotes srd
1623 \begin_inset Quotes srd
1630 sdccconf_h_dir_separator=
1631 \begin_inset Quotes srd
1643 \begin_inset Quotes srd
1663 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
1674 -C' turns on caching, which gives a little bit extra speed.
1675 However if options are changed, it can be necessary to delete the config.cache
1680 \begin_inset LatexCommand \label{sub:Install-paths}
1685 \begin_inset LatexCommand \index{Install paths}
1691 \added_space_top medskip \align center
1693 \begin_inset Tabular
1694 <lyxtabular version="3" rows="5" columns="4">
1696 <column alignment="center" valignment="top" leftline="true" width="0">
1697 <column alignment="center" valignment="top" leftline="true" width="0">
1698 <column alignment="center" valignment="top" leftline="true" width="0">
1699 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
1700 <row topline="true" bottomline="true">
1701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1721 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1731 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1742 <row topline="true">
1743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1769 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1782 <row topline="true">
1783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1798 $DATADIR/ $INCLUDE_DIR_SUFFIX
1801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1806 /usr/local/share/sdcc/include
1809 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1822 <row topline="true">
1823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1838 $DATADIR/$LIB_DIR_SUFFIX
1841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1846 /usr/local/share/sdcc/lib
1849 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1862 <row topline="true" bottomline="true">
1863 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1886 /usr/local/share/sdcc/doc
1889 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1911 *compiler, preprocessor, assembler, and linker
1917 is auto-appended by the compiler, e.g.
1918 small, large, z80, ds390 etc
1921 The install paths can still be changed during `make install` with e.g.:
1924 make install prefix=$(HOME)/local/sdcc
1927 Of course this doesn't change the search paths compiled into the binaries.
1931 \begin_inset LatexCommand \label{sub:Search-Paths}
1936 \begin_inset LatexCommand \index{Search path}
1943 Some search paths or parts of them are determined by configure variables
1948 , see section above).
1949 Further search paths are determined by environment variables during runtime.
1952 The paths searched when running the compiler are as follows (the first catch
1958 Binary files (preprocessor, assembler and linker)
1964 \begin_inset Tabular
1965 <lyxtabular version="3" rows="4" columns="3">
1967 <column alignment="block" valignment="top" leftline="true" width="0in">
1968 <column alignment="block" valignment="top" leftline="true" width="0in">
1969 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1970 <row topline="true" bottomline="true">
1971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1987 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1996 <row topline="true">
1997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2015 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2026 <row topline="true">
2027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2032 Path of argv[0] (if available)
2035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2052 <row topline="true" bottomline="true">
2053 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2069 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2094 \begin_inset Tabular
2095 <lyxtabular version="3" rows="6" columns="3">
2097 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2098 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2099 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2100 <row topline="true" bottomline="true">
2101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2117 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2126 <row topline="true">
2127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2163 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2182 <row topline="true">
2183 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2208 <row topline="true">
2209 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2223 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2235 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2246 <row topline="true">
2247 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2315 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2328 <row topline="true" bottomline="true">
2329 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2345 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2350 /usr/local/share/sdcc/
2355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2383 -nostdinc disables the last two search paths.
2393 With the exception of
2394 \begin_inset Quotes sld
2408 \begin_inset Quotes srd
2415 is auto-appended by the compiler (e.g.
2416 small, large, z80, ds390 etc.).
2423 \begin_inset Tabular
2424 <lyxtabular version="3" rows="6" columns="3">
2426 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2427 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2428 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2429 <row topline="true" bottomline="true">
2430 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2438 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2446 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2455 <row topline="true">
2456 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2492 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2511 <row topline="true">
2512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2524 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2551 <row topline="true">
2552 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2563 $LIB_DIR_SUFFIX/<model>
2566 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2580 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2597 <row topline="true">
2598 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2613 $LIB_DIR_SUFFIX/<model>
2616 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2669 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2725 <row topline="true" bottomline="true">
2726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2735 $LIB_DIR_SUFFIX/<model>
2738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2743 /usr/local/share/sdcc/
2750 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2768 Don't delete any of the stray spaces in the table above without checking
2769 the HTML output (last line)!
2785 -nostdlib disables the last two search paths.
2789 \begin_inset LatexCommand \index{Building SDCC}
2796 Building SDCC on Linux
2797 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
2806 Download the source package
2808 either from the SDCC CVS repository or from the
2809 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
2815 , it will be named something like sdcc
2828 Bring up a command line terminal, such as xterm.
2833 Unpack the file using a command like:
2836 "tar -xvzf sdcc.src.tar.gz
2841 , this will create a sub-directory called sdcc with all of the sources.
2844 Change directory into the main SDCC directory, for example type:
2861 This configures the package for compilation on your system.
2877 All of the source packages will compile, this can take a while.
2893 This copies the binary executables, the include files, the libraries and
2894 the documentation to the install directories.
2897 Building SDCC on OSX 2.x
2900 Follow the instruction for Linux.
2904 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
2905 )) fails to compile SDCC.
2906 Fortunately there's also gcc 2.9.x installed, which works fine.
2907 This compiler can be selected by running 'configure' with:
2910 ./configure CC=gcc2 CXX=g++2
2913 Cross compiling SDCC on Linux for Windows
2916 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
2917 See section 'Configure Options'.
2920 Building SDCC on Windows
2923 With the exception of Cygwin the SDCC binaries uCsim and sdcdb can't be
2925 They use Unix-sockets, which are not available on Win32.
2928 Building SDCC using Cygwin and Mingw32
2931 For building and installing a Cygwin executable follow the instructions
2937 \begin_inset Quotes sld
2941 \begin_inset Quotes srd
2944 Win32-binary can be built, which will not need the Cygwin-DLL.
2945 For the necessary 'configure' options see section 'configure options' or
2946 the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
2950 In order to install Cygwin on Windows download setup.exe from
2951 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
2957 \begin_inset Quotes sld
2960 default text file type
2961 \begin_inset Quotes srd
2965 \begin_inset Quotes sld
2969 \begin_inset Quotes srd
2972 and download/install at least the following packages.
2973 Some packages are selected by default, others will be automatically selected
2974 because of dependencies with the manually selected packages.
2975 Never deselect these packages!
2984 gcc ; version 3.x is fine, no need to use the old 2.9x
2987 binutils ; selected with gcc
2993 rxvt ; a nice console, which makes life much easier under windoze (see below)
2996 man ; not really needed for building SDCC, but you'll miss it sooner or
3000 less ; not really needed for building SDCC, but you'll miss it sooner or
3004 cvs ; only if you use CVS access
3007 If you want to develop something you'll need:
3010 python ; for the regression tests
3013 gdb ; the gnu debugger, together with the nice GUI
3014 \begin_inset Quotes sld
3018 \begin_inset Quotes srd
3024 openssh ; to access the CF or commit changes
3027 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3028 use autoconf-stable!
3031 rxvt is a nice console with history.
3032 Replace in your cygwin.bat the line
3051 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3054 -bg black -fg white -geometry 100x65 -e bash -
3067 Text selected with the mouse is automatically copied to the clipboard, pasting
3068 works with shift-insert.
3072 The other good tip is to make sure you have no //c/-style paths anywhere,
3073 use /cygdrive/c/ instead.
3074 Using // invokes a network lookup which is very slow.
3076 \begin_inset Quotes sld
3080 \begin_inset Quotes srd
3083 is too long, you can change it with e.g.
3089 SDCC sources use the unix line ending LF.
3090 Life is much easier, if you store the source tree on a drive which is mounted
3092 And use an editor which can handle LF-only line endings.
3093 Make sure not to commit files with windows line endings.
3094 The tabulator spacing used in the project is 8.
3097 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3102 Download the source package
3104 either from the SDCC CVS repository or from the
3105 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3111 , it will be named something like sdcc
3118 SDCC is distributed with all the projects, workspaces, and files you need
3119 to build it using Visual C++ 6.0/NET (except for sdcdb.exe which currently
3120 doesn't build under MSVC).
3121 The workspace name is 'sdcc.dsw'.
3122 Please note that as it is now, all the executables are created in a folder
3126 Once built you need to copy the executables from sdcc
3130 bin before running SDCC.
3135 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3136 flex.exe, and gawk.exe.
3137 One good place to get them is
3138 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3146 Download the file UnxUtils
3147 \begin_inset LatexCommand \index{UnxUtils}
3152 Now you have to install the utilities and setup MSVC so it can locate the
3154 Here there are two alternatives (choose one!):
3161 a) Extract UnxUtils.zip to your C:
3163 hard disk PRESERVING the original paths, otherwise bison won't work.
3164 (If you are using WinZip make certain that 'Use folder names' is selected)
3168 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3169 in 'Show directories for:' select 'Executable files', and in the directories
3170 window add a new path: 'C:
3180 (As a side effect, you get a bunch of Unix utilities that could be useful,
3181 such as diff and patch.)
3188 This one avoids extracting a bunch of files you may not use, but requires
3193 a) Create a directory were to put the tools needed, or use a directory already
3201 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3202 to such directory WITHOUT preserving the original paths.
3203 (If you are using WinZip make certain that 'Use folder names' is not selected)
3207 c) Rename bison.exe to '_bison.exe'.
3211 d) Create a batch file 'bison.bat' in 'C:
3215 ' and add these lines:
3235 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3239 Steps 'c' and 'd' are needed because bison requires by default that the
3240 files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3241 '/usr/local/share/' I think.
3242 So it is necessary to tell bison where those files are located if they
3243 are not in such directory.
3244 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3248 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3249 in 'Show directories for:' select 'Executable files', and in the directories
3250 window add a new path: 'c:
3253 Note that you can use any other path instead of 'c:
3255 util', even the path where the Visual C++ tools are, probably: 'C:
3259 Microsoft Visual Studio
3264 So you don't have to execute step 'e' :)
3268 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3269 the executables from sdcc
3273 bin, and you can compile using SDCC.
3276 Building SDCC Using Borland
3279 From the sdcc directory, run the command "make -f Makefile.bcc".
3280 This should regenerate all the .exe files in the bin directory except for
3281 sdcdb.exe (which currently doesn't build under Borland C++).
3284 If you modify any source files and need to rebuild, be aware that the dependenci
3285 es may not be correctly calculated.
3286 The safest option is to delete all .obj files and run the build again.
3287 From a Cygwin BASH prompt, this can easily be done with the command (be
3288 sure you are in the sdcc directory):
3298 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
3300 ) -print -exec rm {}
3309 or on Windows NT/2000/XP from the command prompt with the command:
3316 del /s *.obj *.lib *.rul
3319 from the sdcc directory.
3322 Windows Install Using a Binary Package
3323 \begin_inset LatexCommand \label{sub:Windows-Install}
3330 Download the binary package from
3331 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3335 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
3336 This should unpack to a group of sub-directories.
3337 An example directory structure after unpacking the mingw32 package is:
3342 bin for the executables, c:
3350 lib for the include and libraries.
3353 Adjust your environment variable PATH to include the location of the bin
3354 directory or start sdcc using the full path.
3357 Building the Documentation
3360 If the necessary tools (LyX, LaTeX, latex2html) are installed it is as easy
3361 as changing into the doc directory and typing
3365 \begin_inset Quotes srd
3369 \begin_inset Quotes srd
3376 If you want to avoid installing the tools you will have some success with
3377 a bootable Knoppix CD
3378 \begin_inset LatexCommand \url{http://www.knoppix.net}
3383 Prebuilt documentation in html and pdf format is available from
3384 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3391 Reading the Documentation
3394 Currently reading the document in pdf format is recommended, as for unknown
3395 reason the hyperlinks are working there whereas in the html version they
3398 This documentation is in some aspects different from a commercial documentation:
3402 It tries to document SDCC for several processor architectures in one document
3403 (commercially these probably would be separate documents/products).
3405 \begin_inset LatexCommand \index{Status of documentation}
3409 currently matches SDCC for mcs51 and DS390 best and does give too few informati
3414 There are many references pointing away from this documentation.
3415 Don't let this distract you.
3417 was a reference like
3418 \begin_inset LatexCommand \url{www.opencores.org}
3422 together with a statement
3423 \begin_inset Quotes sld
3426 some processors which are targetted by SDCC can be implemented in a
3443 \begin_inset LatexCommand \index{fpga (field programmable gate array)}
3448 \begin_inset Quotes srd
3451 we expect you to have a quick look there and come back.
3452 If you read this you are on the right track.
3455 Some sections attribute more space to problems, restrictions and warnings
3456 than to the solution.
3459 The installation section and the section about the debugger is intimidating.
3462 There are still lots of typos and there are more different writing styles
3466 Testing the SDCC Compiler
3469 The first thing you should do after installing your SDCC compiler is to
3485 \begin_inset LatexCommand \index{version}
3492 at the prompt, and the program should run and tell you the version.
3493 If it doesn't run, or gives a message about not finding sdcc program, then
3494 you need to check over your installation.
3495 Make sure that the sdcc bin directory is in your executable search path
3496 defined by the PATH environment setting (
3501 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3508 Install trouble-shooting for suggestions
3511 Make sure that the sdcc program is in the bin folder, if not perhaps something
3512 did not install correctly.
3520 is commonly installed as described in section
3521 \begin_inset Quotes sld
3524 Install and search paths
3525 \begin_inset Quotes srd
3534 Make sure the compiler works on a very simple example.
3535 Type in the following test.c program using your favorite
3561 Compile this using the following command:
3570 If all goes well, the compiler will generate a test.asm and test.rel file.
3571 Congratulations, you've just compiled your first program with SDCC.
3572 We used the -c option to tell SDCC not to link the generated code, just
3573 to keep things simple for this step.
3581 The next step is to try it with the linker.
3591 If all goes well the compiler will link with the libraries and produce
3592 a test.ihx output file.
3597 (no test.ihx, and the linker generates warnings), then the problem is most
3606 usr/local/share/sdcc/lib directory
3613 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3620 Install trouble-shooting for suggestions).
3628 The final test is to ensure
3636 header files and libraries.
3637 Edit test.c and change it to the following:
3654 strcpy(str1, "testing");
3661 Compile this by typing
3668 This should generate a test.ihx output file, and it should give no warnings
3669 such as not finding the string.h file.
3670 If it cannot find the string.h file, then the problem is that
3674 cannot find the /usr/local/share/sdcc/include directory
3681 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3688 Install trouble-shooting section for suggestions).
3706 \begin_inset LatexCommand \index{-\/-print-search-dirs}
3710 to find exactly where SDCC is looking for the include and lib files.
3713 Install Trouble-shooting
3714 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
3719 \begin_inset LatexCommand \index{Install trouble-shooting}
3726 SDCC does not build correctly.
3729 A thing to try is starting from scratch by unpacking the .tgz source package
3730 again in an empty directory.
3738 ./configure 2>&1 | tee configure.log
3752 make 2>&1 | tee make.log
3759 If anything goes wrong, you can review the log files to locate the problem.
3760 Or a relevant part of this can be attached to an email that could be helpful
3761 when requesting help from the mailing list.
3765 \begin_inset Quotes sld
3769 \begin_inset Quotes srd
3776 \begin_inset Quotes sld
3780 \begin_inset Quotes srd
3783 command is a script that analyzes your system and performs some configuration
3784 to ensure the source package compiles on your system.
3785 It will take a few minutes to run, and will compile a few tests to determine
3786 what compiler features are installed.
3790 \begin_inset Quotes sld
3794 \begin_inset Quotes srd
3800 This runs the GNU make tool, which automatically compiles all the source
3801 packages into the final installed binary executables.
3805 \begin_inset Quotes sld
3809 \begin_inset Quotes erd
3815 This will install the compiler, other executables libraries and include
3816 files into the appropriate directories.
3818 \begin_inset LatexCommand \ref{sub:Install-paths}
3824 \begin_inset LatexCommand \ref{sub:Search-Paths}
3829 about install and search paths.
3831 On most systems you will need super-user privileges to do this.
3837 SDCC is not just a compiler, but a collection of tools by various developers.
3838 These include linkers, assemblers, simulators and other components.
3839 Here is a summary of some of the components.
3840 Note that the included simulator and assembler have separate documentation
3841 which you can find in the source package in their respective directories.
3842 As SDCC grows to include support for other processors, other packages from
3843 various developers are included and may have their own sets of documentation.
3847 You might want to look at the files which are installed in <installdir>.
3848 At the time of this writing, we find the following programs for gcc-builds:
3852 In <installdir>/bin:
3855 sdcc - The compiler.
3858 sdcpp - The C preprocessor.
3861 asx8051 - The assembler for 8051 type processors.
3868 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
3871 aslink -The linker for 8051 type processors.
3878 link-gbz80 - The Z80 and GameBoy Z80 linkers.
3881 s51 - The ucSim 8051 simulator.
3884 sdcdb - The source debugger.
3887 packihx - A tool to pack (compress) Intel hex files.
3890 In <installdir>/share/sdcc/include
3896 In <installdir>/share/sdcc/lib
3899 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
3903 In <installdir>/share/sdcc/doc
3909 As development for other processors proceeds, this list will expand to include
3910 executables to support processors like AVR, PIC, etc.
3916 This is the actual compiler, it in turn uses the c-preprocessor and invokes
3917 the assembler and linkage editor.
3921 \begin_inset LatexCommand \index{sdcpp}
3925 - The C-Preprocessor
3928 The preprocessor is a modified version of the GNU preprocessor.
3929 The C preprocessor is used to pull in #include sources, process #ifdef
3930 statements, #defines and so on.
3933 asx8051, as-z80, as-gbz80, aslink, link-z80, link-gbz80 - The Assemblers
3937 This is retargettable assembler & linkage editor, it was developed by Alan
3939 John Hartman created the version for 8051, and I (Sandeep) have made some
3940 enhancements and bug fixes for it to work properly with SDCC.
3944 \begin_inset LatexCommand \index{s51}
3951 S51 is a freeware, opensource simulator developed by Daniel Drotos (
3952 \begin_inset LatexCommand \url{mailto:drdani@mazsola.iit.uni-miskolc.hu}
3957 The simulator is built as part of the build process.
3958 For more information visit Daniel's web site at:
3959 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
3964 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
3969 \begin_inset LatexCommand \index{sdcdb}
3973 - Source Level Debugger
3976 Sdcdb is the companion source level debugger.
3977 The current version of the debugger uses Daniel's Simulator S51
3978 \begin_inset LatexCommand \index{s51}
3982 , but can be easily changed to use other simulators.
3991 Single Source File Projects
3994 For single source file 8051 projects the process is very simple.
3995 Compile your programs with the following command
3998 "sdcc sourcefile.c".
4002 This will compile, assemble and link your source file.
4003 Output files are as follows
4007 \begin_inset LatexCommand \index{<file>.asm}
4012 \begin_inset LatexCommand \index{Assembler source}
4016 file created by the compiler
4020 \begin_inset LatexCommand \index{<file>.lst}
4025 \begin_inset LatexCommand \index{Assembler listing}
4029 file created by the Assembler
4033 \begin_inset LatexCommand \index{<file>.rst}
4038 \begin_inset LatexCommand \index{Assembler listing}
4042 file updated with linkedit information, created by linkage editor
4046 \begin_inset LatexCommand \index{<file>.sym}
4051 \begin_inset LatexCommand \index{Symbol listing}
4055 for the sourcefile, created by the assembler
4059 \begin_inset LatexCommand \index{<file>.rel}
4064 \begin_inset LatexCommand \index{Object file}
4068 created by the assembler, input to Linkage editor
4072 \begin_inset LatexCommand \index{<file>.map}
4077 \begin_inset LatexCommand \index{Memory map}
4081 for the load module, created by the Linker
4085 \begin_inset LatexCommand \index{<file>.mem}
4089 - A file with a summary of the memory usage
4093 \begin_inset LatexCommand \index{<file>.ihx}
4097 - The load module in Intel hex format
4098 \begin_inset LatexCommand \index{Intel hex format}
4102 (you can select the Motorola S19 format
4103 \begin_inset LatexCommand \index{Motorola S19 format}
4118 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
4123 If you need another format you might want to use
4130 \begin_inset LatexCommand \index{objdump}
4141 \begin_inset LatexCommand \index{srecord}
4149 \begin_inset LatexCommand \index{.adb}
4153 - An intermediate file containing debug information needed to create the
4165 \begin_inset LatexCommand \index{-\/-debug}
4173 \begin_inset LatexCommand \index{<file>.cdb}
4177 - An optional file (with -
4187 -debug) containing debug information
4192 \begin_inset LatexCommand \index{<file> (no extension)}
4197 \begin_inset LatexCommand \index{AOMF51}
4201 file containing debug information (with -
4212 This format is commonly used by third party tools (debuggers
4213 \begin_inset LatexCommand \index{Debugger}
4217 , simulators, emulators)
4221 \begin_inset LatexCommand \index{<file>.dump*}
4225 - Dump file to debug the compiler it self (with -
4235 -dumpall) (see section
4236 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
4242 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
4248 \begin_inset Quotes sld
4251 Anatomy of the compiler
4252 \begin_inset Quotes srd
4258 Projects with Multiple Source Files
4261 SDCC can compile only ONE file at a time.
4262 Let us for example assume that you have a project containing the following
4267 foo1.c (contains some functions)
4269 foo2.c (contains some more functions)
4271 foomain.c (contains more functions and the function main)
4279 The first two files will need to be compiled separately with the commands:
4311 Then compile the source file containing the
4316 \begin_inset LatexCommand \index{Linker}
4320 the files together with the following command:
4328 foomain.c\SpecialChar ~
4329 foo1.rel\SpecialChar ~
4334 \begin_inset LatexCommand \index{.rel}
4346 can be separately compiled as well:
4357 sdcc foomain.rel foo1.rel foo2.rel
4364 The file containing the
4379 file specified in the command line, since the linkage editor processes
4380 file in the order they are presented to it.
4381 The linker is invoked from SDCC using a script file with extension .lnk
4382 \begin_inset LatexCommand \index{.lnk}
4387 You can view this file to troubleshoot linking problems such as those arising
4388 from missing libraries.
4391 Projects with Additional Libraries
4392 \begin_inset LatexCommand \index{Libraries}
4399 Some reusable routines may be compiled into a library, see the documentation
4400 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
4404 \begin_inset LatexCommand \index{.lib}
4411 Libraries created in this manner can be included in the command line.
4412 Make sure you include the -L <library-path> option to tell the linker where
4413 to look for these files if they are not in the current directory.
4414 Here is an example, assuming you have the source file
4426 (if that is not the same as your current project):
4433 sdcc foomain.c foolib.lib -L mylib
4444 must be an absolute path name.
4448 The most efficient way to use libraries is to keep separate modules in separate
4450 The lib file now should name all the modules.rel
4451 \begin_inset LatexCommand \index{rel}
4456 For an example see the standard library file
4460 in the directory <installdir>/share/lib/small.
4463 Command Line Options
4464 \begin_inset LatexCommand \index{Command Line Options}
4471 Processor Selection Options
4472 \begin_inset LatexCommand \index{Options processor selection}
4477 \begin_inset LatexCommand \index{Processor selection options}
4483 \labelwidthstring 00.00.0000
4488 \begin_inset LatexCommand \index{-mmcs51}
4494 Generate code for the Intel MCS51
4495 \begin_inset LatexCommand \index{MCS51}
4499 family of processors.
4500 This is the default processor target.
4502 \labelwidthstring 00.00.0000
4507 \begin_inset LatexCommand \index{-mds390}
4513 Generate code for the Dallas DS80C390
4514 \begin_inset LatexCommand \index{DS80C390}
4520 \labelwidthstring 00.00.0000
4525 \begin_inset LatexCommand \index{-mds400}
4531 Generate code for the Dallas DS80C400
4532 \begin_inset LatexCommand \index{DS80C400}
4538 \labelwidthstring 00.00.0000
4543 \begin_inset LatexCommand \index{-mhc08}
4549 Generate code for the Motorola HC08
4550 \begin_inset LatexCommand \index{HC08}
4554 family of processors (added Oct 2003).
4556 \labelwidthstring 00.00.0000
4561 \begin_inset LatexCommand \index{-mz80}
4567 Generate code for the Zilog Z80
4568 \begin_inset LatexCommand \index{Z80}
4572 family of processors.
4574 \labelwidthstring 00.00.0000
4579 \begin_inset LatexCommand \index{-mgbz80}
4585 Generate code for the GameBoy Z80
4586 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
4592 \labelwidthstring 00.00.0000
4597 \begin_inset LatexCommand \index{-mavr}
4603 Generate code for the Atmel AVR
4604 \begin_inset LatexCommand \index{AVR}
4608 processor (In development, not complete).
4609 AVR users should probably have a look at avr-gcc
4610 \begin_inset LatexCommand \url{ http://savannah.nongnu.org/download/avr-libc/snapshots/}
4617 I think it is fair to direct users there for now.
4618 Open source is also about avoiding unnecessary work .
4619 But I didn't find the 'official' link.
4621 \labelwidthstring 00.00.0000
4626 \begin_inset LatexCommand \index{-mpic14}
4632 Generate code for the Microchip PIC 14
4633 \begin_inset LatexCommand \index{PIC14}
4637 -bit processors (p16f84 and variants).
4640 p16f627 p16f628 p16f84 p16f873 p16f877?
4642 \labelwidthstring 00.00.0000
4647 \begin_inset LatexCommand \index{-mpic16}
4653 Generate code for the Microchip PIC 16
4654 \begin_inset LatexCommand \index{PIC16}
4658 -bit processors (p18f452 and variants).
4660 \labelwidthstring 00.00.0000
4666 Generate code for the Toshiba TLCS-900H
4667 \begin_inset LatexCommand \index{TLCS-900H}
4671 processor (In development, not complete).
4673 \labelwidthstring 00.00.0000
4678 \begin_inset LatexCommand \index{-mxa51}
4684 Generate code for the Phillips XA51
4685 \begin_inset LatexCommand \index{XA51}
4689 processor (In development, not complete).
4692 Preprocessor Options
4693 \begin_inset LatexCommand \index{Options preprocessor}
4698 \begin_inset LatexCommand \index{Preprocessor options}
4704 \labelwidthstring 00.00.0000
4709 \begin_inset LatexCommand \index{-I<path>}
4715 The additional location where the pre processor will look for <..h> or
4716 \begin_inset Quotes eld
4720 \begin_inset Quotes erd
4725 \labelwidthstring 00.00.0000
4730 \begin_inset LatexCommand \index{-D<macro[=value]>}
4736 Command line definition of macros.
4737 Passed to the preprocessor.
4739 \labelwidthstring 00.00.0000
4744 \begin_inset LatexCommand \index{-M}
4750 Tell the preprocessor to output a rule suitable for make describing the
4751 dependencies of each object file.
4752 For each source file, the preprocessor outputs one make-rule whose target
4753 is the object file name for that source file and whose dependencies are
4754 all the files `#include'd in it.
4755 This rule may be a single line or may be continued with `
4757 '-newline if it is long.
4758 The list of rules is printed on standard output instead of the preprocessed
4761 \begin_inset LatexCommand \index{-E}
4767 \labelwidthstring 00.00.0000
4772 \begin_inset LatexCommand \index{-C}
4778 Tell the preprocessor not to discard comments.
4779 Used with the `-E' option.
4781 \labelwidthstring 00.00.0000
4786 \begin_inset LatexCommand \index{-MM}
4797 Like `-M' but the output mentions only the user header files included with
4799 \begin_inset Quotes eld
4803 System header files included with `#include <file>' are omitted.
4805 \labelwidthstring 00.00.0000
4810 \begin_inset LatexCommand \index{-Aquestion(answer)}
4816 Assert the answer answer for question, in case it is tested with a preprocessor
4817 conditional such as `#if #question(answer)'.
4818 `-A-' disables the standard assertions that normally describe the target
4821 \labelwidthstring 00.00.0000
4826 \begin_inset LatexCommand \index{-Umacro}
4832 Undefine macro macro.
4833 `-U' options are evaluated after all `-D' options, but before any `-include'
4834 and `-imacros' options.
4836 \labelwidthstring 00.00.0000
4841 \begin_inset LatexCommand \index{-dM}
4847 Tell the preprocessor to output only a list of the macro definitions that
4848 are in effect at the end of preprocessing.
4849 Used with the `-E' option.
4851 \labelwidthstring 00.00.0000
4856 \begin_inset LatexCommand \index{-dD}
4862 Tell the preprocessor to pass all macro definitions into the output, in
4863 their proper sequence in the rest of the output.
4865 \labelwidthstring 00.00.0000
4870 \begin_inset LatexCommand \index{-dN}
4881 Like `-dD' except that the macro arguments and contents are omitted.
4882 Only `#define name' is included in the output.
4884 \labelwidthstring 00.00.0000
4889 preprocessorOption[,preprocessorOption]
4892 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
4897 Pass the preprocessorOption to the preprocessor.
4901 \begin_inset LatexCommand \index{Options linker}
4906 \begin_inset LatexCommand \index{Linker options}
4912 \labelwidthstring 00.00.0000
4932 \begin_inset LatexCommand \index{-\/-lib-path <path>}
4937 \begin_inset LatexCommand \index{-L -\/-lib-path}
4944 <absolute path to additional libraries> This option is passed to the linkage
4945 editor's additional libraries
4946 \begin_inset LatexCommand \index{Libraries}
4951 The path name must be absolute.
4952 Additional library files may be specified in the command line.
4953 See section Compiling programs for more details.
4955 \labelwidthstring 00.00.0000
4972 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
4977 <Value> The start location of the external ram
4978 \begin_inset LatexCommand \index{xdata}
4982 , default value is 0.
4983 The value entered can be in Hexadecimal or Decimal format, e.g.: -
4993 -xram-loc 0x8000 or -
5005 \labelwidthstring 00.00.0000
5022 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
5027 <Value> The start location of the code
5028 \begin_inset LatexCommand \index{code}
5032 segment, default value 0.
5033 Note when this option is used the interrupt vector table is also relocated
5034 to the given address.
5035 The value entered can be in Hexadecimal or Decimal format, e.g.: -
5045 -code-loc 0x8000 or -
5057 \labelwidthstring 00.00.0000
5074 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
5079 <Value> By default the stack
5080 \begin_inset LatexCommand \index{stack}
5084 is placed after the data segment.
5085 Using this option the stack can be placed anywhere in the internal memory
5087 The value entered can be in Hexadecimal or Decimal format, e.g.
5098 -stack-loc 0x20 or -
5109 Since the sp register is incremented before a push or call, the initial
5110 sp will be set to one byte prior the provided value.
5111 The provided value should not overlap any other memory areas such as used
5112 register banks or the data segment and with enough space for the current
5115 \labelwidthstring 00.00.0000
5132 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
5137 <Value> The start location of the internal ram data
5138 \begin_inset LatexCommand \index{data}
5143 The value entered can be in Hexadecimal or Decimal format, eg.
5165 (By default, the start location of the internal ram data segment is set
5166 as low as possible in memory, taking into account the used register banks
5167 and the bit segment at address 0x20.
5168 For example if register banks 0 and 1 are used without bit variables, the
5169 data segment will be set, if -
5179 -data-loc is not used, to location 0x10.)
5181 \labelwidthstring 00.00.0000
5198 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
5203 <Value> The start location of the indirectly addressable internal ram
5204 \begin_inset LatexCommand \index{idata}
5208 of the 8051, default value is 0x80.
5209 The value entered can be in Hexadecimal or Decimal format, eg.
5220 -idata-loc 0x88 or -
5232 \labelwidthstring 00.00.0000
5249 <Value> The start location of the bit
5250 \begin_inset LatexCommand \index{bit}
5254 addressable internal ram of the 8051.
5260 Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
5263 \labelwidthstring 00.00.0000
5278 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
5287 The linker output (final object code) is in Intel Hex format.
5288 \begin_inset LatexCommand \index{Intel hex format}
5292 (This is the default option).
5294 \labelwidthstring 00.00.0000
5309 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5318 The linker output (final object code) is in Motorola S19 format
5319 \begin_inset LatexCommand \index{Motorola S19 format}
5325 \labelwidthstring 00.00.0000
5330 linkOption[,linkOption]
5333 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
5338 Pass the linkOption to the linker.
5342 \begin_inset LatexCommand \index{Options MCS51}
5347 \begin_inset LatexCommand \index{MCS51 options}
5353 \labelwidthstring 00.00.0000
5368 \begin_inset LatexCommand \index{-\/-model-small}
5379 Generate code for Small Model programs see section Memory Models for more
5381 This is the default model.
5383 \labelwidthstring 00.00.0000
5398 \begin_inset LatexCommand \index{-\/-model-large}
5404 Generate code for Large model programs see section Memory Models for more
5406 If this option is used all source files in the project have to be compiled
5409 \labelwidthstring 00.00.0000
5424 \begin_inset LatexCommand \index{-\/-xstack}
5430 Uses a pseudo stack in the first 256 bytes in the external ram for allocating
5431 variables and passing parameters.
5433 \begin_inset LatexCommand \ref{sub:External-Stack}
5438 External Stack for more details.
5440 \labelwidthstring 00.00.0000
5458 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
5462 Causes the linker to check if the internal ram usage is within limits of
5465 \labelwidthstring 00.00.0000
5483 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
5487 Causes the linker to check if the external ram usage is within limits of
5490 \labelwidthstring 00.00.0000
5508 \begin_inset LatexCommand \index{-\/-code-size <Value>}
5512 Causes the linker to check if the code memory usage is within limits of
5517 \begin_inset LatexCommand \index{Options DS390}
5522 \begin_inset LatexCommand \index{DS390 options}
5528 \labelwidthstring 00.00.0000
5545 \begin_inset LatexCommand \index{-\/-model-flat24}
5555 Generate 24-bit flat mode code.
5556 This is the one and only that the ds390 code generator supports right now
5557 and is default when using
5562 See section Memory Models for more details.
5564 \labelwidthstring 00.00.0000
5581 \begin_inset LatexCommand \index{-\/-stack-10bit}
5585 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
5586 This is the one and only that the ds390 code generator supports right now
5587 and is default when using
5592 In this mode, the stack is located in the lower 1K of the internal RAM,
5593 which is mapped to 0x400000.
5594 Note that the support is incomplete, since it still uses a single byte
5595 as the stack pointer.
5596 This means that only the lower 256 bytes of the potential 1K stack space
5597 will actually be used.
5598 However, this does allow you to reclaim the precious 256 bytes of low RAM
5599 for use for the DATA and IDATA segments.
5600 The compiler will not generate any code to put the processor into 10 bit
5602 It is important to ensure that the processor is in this mode before calling
5603 any re-entrant functions compiled with this option.
5604 In principle, this should work with the
5617 \begin_inset LatexCommand \index{-\/-stack-auto}
5623 option, but that has not been tested.
5624 It is incompatible with the
5637 \begin_inset LatexCommand \index{-\/-xstack}
5644 It also only makes sense if the processor is in 24 bit contiguous addressing
5657 -model-flat24 option
5663 \begin_inset LatexCommand \index{Options Z80}
5668 \begin_inset LatexCommand \index{Z80 options}
5674 \labelwidthstring 00.00.0000
5691 \begin_inset LatexCommand \index{-\/-callee-saves-bc}
5701 Force a called function to always save BC.
5703 \labelwidthstring 00.00.0000
5720 \begin_inset LatexCommand \index{-\/-no-std-crt0}
5724 When linking, skip the standard crt0.o object file.
5725 You must provide your own crt0.o for your system when linking.
5729 Optimization Options
5730 \begin_inset LatexCommand \index{Options optimization}
5735 \begin_inset LatexCommand \index{Optimization options}
5741 \labelwidthstring 00.00.0000
5756 \begin_inset LatexCommand \index{-\/-nogcse}
5762 Will not do global subexpression elimination, this option may be used when
5763 the compiler creates undesirably large stack/data spaces to store compiler
5765 A warning message will be generated when this happens and the compiler
5766 will indicate the number of extra bytes it allocated.
5767 It recommended that this option NOT be used, #pragma\SpecialChar ~
5769 \begin_inset LatexCommand \index{\#pragma NOGCSE}
5773 can be used to turn off global subexpression elimination
5774 \begin_inset LatexCommand \index{Subexpression elimination}
5778 for a given function only.
5780 \labelwidthstring 00.00.0000
5795 \begin_inset LatexCommand \index{-\/-noinvariant}
5801 Will not do loop invariant optimizations, this may be turned off for reasons
5802 explained for the previous option.
5803 For more details of loop optimizations performed see section Loop Invariants.It
5804 recommended that this option NOT be used, #pragma\SpecialChar ~
5806 \begin_inset LatexCommand \index{\#pragma NOINVARIANT}
5810 can be used to turn off invariant optimizations for a given function only.
5812 \labelwidthstring 00.00.0000
5827 \begin_inset LatexCommand \index{-\/-noinduction}
5833 Will not do loop induction optimizations, see section strength reduction
5834 for more details.It is recommended that this option is NOT used, #pragma\SpecialChar ~
5837 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
5841 can be used to turn off induction optimizations for a given function only.
5843 \labelwidthstring 00.00.0000
5858 \begin_inset LatexCommand \index{-\/-nojtbound}
5869 Will not generate boundary condition check when switch statements
5870 \begin_inset LatexCommand \index{switch statement}
5874 are implemented using jump-tables.
5876 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
5881 Switch Statements for more details.
5882 It is recommended that this option is NOT used, #pragma\SpecialChar ~
5884 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
5888 can be used to turn off boundary checking for jump tables for a given function
5891 \labelwidthstring 00.00.0000
5906 \begin_inset LatexCommand \index{-\/-noloopreverse}
5915 Will not do loop reversal
5916 \begin_inset LatexCommand \index{Loop reversing}
5922 \labelwidthstring 00.00.0000
5939 \begin_inset LatexCommand \index{-\/-nolabelopt }
5943 Will not optimize labels (makes the dumpfiles more readable).
5945 \labelwidthstring 00.00.0000
5960 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
5966 Will not memcpy initialized data from code space into xdata space.
5967 This saves a few bytes in code space if you don't have initialized data.
5971 \begin_inset LatexCommand \index{Options other}
5977 \labelwidthstring 00.00.0000
5993 \begin_inset LatexCommand \index{-\/-compile-only}
5998 \begin_inset LatexCommand \index{-c -\/-compile-only}
6004 will compile and assemble the source, but will not call the linkage editor.
6006 \labelwidthstring 00.00.0000
6025 \begin_inset LatexCommand \index{-\/-c1mode}
6031 reads the preprocessed source from standard input and compiles it.
6032 The file name for the assembler output must be specified using the -o option.
6034 \labelwidthstring 00.00.0000
6039 \begin_inset LatexCommand \index{-E}
6045 Run only the C preprocessor.
6046 Preprocess all the C source files specified and output the results to standard
6049 \labelwidthstring 00.00.0000
6055 \begin_inset LatexCommand \index{-o <path/file>}
6061 The output path resp.
6062 file where everything will be placed.
6063 If the parameter is a path, it must have a trailing slash (or backslash
6064 for the Windows binaries) to be recognized as a path.
6067 \labelwidthstring 00.00.0000
6082 \begin_inset LatexCommand \index{-\/-stack-auto}
6093 All functions in the source file will be compiled as
6098 \begin_inset LatexCommand \index{reentrant}
6103 the parameters and local variables will be allocated on the stack
6104 \begin_inset LatexCommand \index{stack}
6109 see section Parameters and Local Variables for more details.
6110 If this option is used all source files in the project should be compiled
6114 \labelwidthstring 00.00.0000
6129 \begin_inset LatexCommand \index{-\/-callee-saves}
6133 function1[,function2][,function3]....
6136 The compiler by default uses a caller saves convention for register saving
6137 across function calls, however this can cause unnecessary register pushing
6138 & popping when calling small functions from larger functions.
6139 This option can be used to switch the register saving convention for the
6140 function names specified.
6141 The compiler will not save registers when calling these functions, no extra
6142 code will be generated at the entry & exit (function prologue
6145 \begin_inset LatexCommand \index{function prologue}
6154 \begin_inset LatexCommand \index{function epilogue}
6160 ) for these functions to save & restore the registers used by these functions,
6161 this can SUBSTANTIALLY reduce code & improve run time performance of the
6163 In the future the compiler (with inter procedural analysis) will be able
6164 to determine the appropriate scheme to use for each function call.
6165 DO NOT use this option for built-in functions such as _mulint..., if this
6166 option is used for a library function the appropriate library function
6167 needs to be recompiled with the same option.
6168 If the project consists of multiple source files then all the source file
6169 should be compiled with the same -
6179 -callee-saves option string.
6180 Also see #pragma\SpecialChar ~
6182 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
6188 \labelwidthstring 00.00.0000
6203 \begin_inset LatexCommand \index{-\/-debug}
6212 When this option is used the compiler will generate debug information, that
6213 can be used with the SDCDB.
6214 The debug information is collected in a file with .cdb extension.
6215 For more information see documentation for SDCDB.
6217 \labelwidthstring 00.00.0000
6222 \begin_inset LatexCommand \index{-S}
6233 Stop after the stage of compilation proper; do not assemble.
6234 The output is an assembler code file for the input file specified.
6236 \labelwidthstring 00.00.0000
6251 \begin_inset LatexCommand \index{-\/-int-long-reent}
6257 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
6258 Note by default these libraries are compiled as non-reentrant.
6259 See section Installation for more details.
6261 \labelwidthstring 00.00.0000
6276 \begin_inset LatexCommand \index{-\/-cyclomatic}
6285 This option will cause the compiler to generate an information message for
6286 each function in the source file.
6287 The message contains some
6291 information about the function.
6292 The number of edges and nodes the compiler detected in the control flow
6293 graph of the function, and most importantly the
6295 cyclomatic complexity
6296 \begin_inset LatexCommand \index{Cyclomatic complexity}
6302 see section on Cyclomatic Complexity for more details.
6304 \labelwidthstring 00.00.0000
6319 \begin_inset LatexCommand \index{-\/-float-reent}
6328 Floating point library is compiled as reentrant
6329 \begin_inset LatexCommand \index{reentrant}
6334 See section Installation for more details.
6336 \labelwidthstring 00.00.0000
6351 \begin_inset LatexCommand \index{-\/-nooverlay}
6357 The compiler will not overlay parameters and local variables of any function,
6358 see section Parameters and local variables for more details.
6360 \labelwidthstring 00.00.0000
6375 \begin_inset LatexCommand \index{-\/-main-return}
6381 This option can be used when the code generated is called by a monitor
6383 The compiler will generate a 'ret' upon return from the 'main'
6384 \begin_inset LatexCommand \index{main return}
6389 The default setting is to lock up i.e.
6396 \labelwidthstring 00.00.0000
6413 \begin_inset LatexCommand \index{-\/-peep-file}
6418 <filename> This option can be used to use additional rules to be used by
6419 the peep hole optimizer.
6421 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
6426 Peep Hole optimizations for details on how to write these rules.
6428 \labelwidthstring 00.00.0000
6443 \begin_inset LatexCommand \index{-\/-no-peep}
6449 Disable peep-hole optimization.
6451 \labelwidthstring 00.00.0000
6466 \begin_inset LatexCommand \index{-\/-peep-asm}
6472 Pass the inline assembler code through the peep hole optimizer.
6473 This can cause unexpected changes to inline assembler code, please go through
6474 the peephole optimizer
6475 \begin_inset LatexCommand \index{Peephole optimizer}
6479 rules defined in the source file tree '<target>/peeph.def' before using
6482 \labelwidthstring 00.00.0000
6497 \begin_inset LatexCommand \index{-\/-nostdincl}
6503 This will prevent the compiler from passing on the default include path
6504 to the preprocessor.
6506 \labelwidthstring 00.00.0000
6521 \begin_inset LatexCommand \index{-\/-nostdlib}
6527 This will prevent the compiler from passing on the default library
6528 \begin_inset LatexCommand \index{Libraries}
6534 \labelwidthstring 00.00.0000
6549 \begin_inset LatexCommand \index{-\/-verbose}
6555 Shows the various actions the compiler is performing.
6557 \labelwidthstring 00.00.0000
6562 \begin_inset LatexCommand \index{-V}
6568 Shows the actual commands the compiler is executing.
6570 \labelwidthstring 00.00.0000
6585 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
6591 Hides your ugly and inefficient c-code from the asm file, so you can always
6592 blame the compiler :).
6594 \labelwidthstring 00.00.0000
6609 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
6615 Include i-codes in the asm file.
6616 Sounds like noise but is most helpful for debugging the compiler itself.
6618 \labelwidthstring 00.00.0000
6633 \begin_inset LatexCommand \index{-\/-less-pedantic}
6639 Disable some of the more pedantic warnings
6640 \begin_inset LatexCommand \index{Warnings}
6644 (jwk burps: please be more specific here, please!).
6645 If you want rather more than less warnings you should consider using a
6646 separate tool dedicated to syntax checking like
6647 \begin_inset LatexCommand \url{www.splint.org}
6653 \labelwidthstring 00.00.0000
6668 \begin_inset LatexCommand \index{-\/-print-search-dirs}
6674 Display the directories in the compiler's search path
6676 \labelwidthstring 00.00.0000
6691 \begin_inset LatexCommand \index{-\/-vc}
6697 Display errors and warnings using MSVC style, so you can use SDCC with
6700 \labelwidthstring 00.00.0000
6715 \begin_inset LatexCommand \index{-\/-use-stdout}
6721 Send errors and warnings to stdout instead of stderr.
6723 \labelwidthstring 00.00.0000
6728 asmOption[,asmOption]
6731 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
6736 Pass the asmOption to the assembler.
6739 Intermediate Dump Options
6740 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
6745 \begin_inset LatexCommand \index{Options intermediate dump}
6750 \begin_inset LatexCommand \index{Intermediate dump options}
6757 The following options are provided for the purpose of retargetting and debugging
6759 These provided a means to dump the intermediate code (iCode
6760 \begin_inset LatexCommand \index{iCode}
6764 ) generated by the compiler in human readable form at various stages of
6765 the compilation process.
6768 \labelwidthstring 00.00.0000
6783 \begin_inset LatexCommand \index{-\/-dumpraw}
6789 This option will cause the compiler to dump the intermediate code into
6792 <source filename>.dumpraw
6794 just after the intermediate code has been generated for a function, i.e.
6795 before any optimizations are done.
6797 \begin_inset LatexCommand \index{Basic blocks}
6801 at this stage ordered in the depth first number, so they may not be in
6802 sequence of execution.
6804 \labelwidthstring 00.00.0000
6819 \begin_inset LatexCommand \index{-\/-dumpgcse}
6825 Will create a dump of iCode's, after global subexpression elimination
6826 \begin_inset LatexCommand \index{Global subexpression elimination}
6832 <source filename>.dumpgcse.
6834 \labelwidthstring 00.00.0000
6849 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
6855 Will create a dump of iCode's, after deadcode elimination
6856 \begin_inset LatexCommand \index{Dead-code elimination}
6862 <source filename>.dumpdeadcode.
6864 \labelwidthstring 00.00.0000
6879 \begin_inset LatexCommand \index{-\/-dumploop}
6888 Will create a dump of iCode's, after loop optimizations
6889 \begin_inset LatexCommand \index{Loop optimization}
6895 <source filename>.dumploop.
6897 \labelwidthstring 00.00.0000
6912 \begin_inset LatexCommand \index{-\/-dumprange}
6921 Will create a dump of iCode's, after live range analysis
6922 \begin_inset LatexCommand \index{Live range analysis}
6928 <source filename>.dumprange.
6930 \labelwidthstring 00.00.0000
6945 \begin_inset LatexCommand \index{-\/-dumlrange}
6951 Will dump the life ranges
6952 \begin_inset LatexCommand \index{Live range analysis}
6958 \labelwidthstring 00.00.0000
6973 \begin_inset LatexCommand \index{-\/-dumpregassign}
6982 Will create a dump of iCode's, after register assignment
6983 \begin_inset LatexCommand \index{Register assignment}
6989 <source filename>.dumprassgn.
6991 \labelwidthstring 00.00.0000
7006 \begin_inset LatexCommand \index{-\/-dumplrange}
7012 Will create a dump of the live ranges of iTemp's
7014 \labelwidthstring 00.00.0000
7029 \begin_inset LatexCommand \index{-\/-dumpall}
7040 Will cause all the above mentioned dumps to be created.
7043 Redirecting output on Windows Shells
7046 By default SDCC writes it's error messages to
7047 \begin_inset Quotes sld
7051 \begin_inset Quotes srd
7055 To force all messages to
7056 \begin_inset Quotes sld
7060 \begin_inset Quotes srd
7084 \begin_inset LatexCommand \index{-\/-use-stdout}
7089 Aditionaly, if you happen to have visual studio installed in your windows
7090 machine, you can use it to compile your sources using a custom build and
7106 \begin_inset LatexCommand \index{-\/-vc}
7111 Something like this should work:
7155 -model-large -c $(InputPath)
7158 Environment variables
7159 \begin_inset LatexCommand \index{Environment variables}
7166 SDCC recognizes the following environment variables:
7168 \labelwidthstring 00.00.0000
7173 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
7179 SDCC installs a signal handler
7180 \begin_inset LatexCommand \index{signal handler}
7184 to be able to delete temporary files after an user break (^C) or an exception.
7185 If this environment variable is set, SDCC won't install the signal handler
7186 in order to be able to debug SDCC.
7188 \labelwidthstring 00.00.0000
7195 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
7201 Path, where temporary files will be created.
7202 The order of the variables is the search order.
7203 In a standard *nix environment these variables are not set, and there's
7204 no need to set them.
7205 On Windows it's recommended to set one of them.
7207 \labelwidthstring 00.00.0000
7212 \begin_inset LatexCommand \index{SDCC\_HOME}
7219 \begin_inset LatexCommand \ref{sub:Install-paths}
7225 \begin_inset Quotes sld
7229 \begin_inset Quotes srd
7234 \labelwidthstring 00.00.0000
7239 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
7246 \begin_inset LatexCommand \ref{sub:Search-Paths}
7252 \begin_inset Quotes sld
7256 \begin_inset Quotes srd
7261 \labelwidthstring 00.00.0000
7266 \begin_inset LatexCommand \index{SDCC\_LIB}
7273 \begin_inset LatexCommand \ref{sub:Search-Paths}
7279 \begin_inset Quotes sld
7283 \begin_inset Quotes srd
7289 There are some more environment variables recognized by SDCC, but these
7290 are solely used for debugging purposes.
7291 They can change or disappear very quickly, and will never be documented.
7294 MCS51/DS390 Storage Class
7295 \begin_inset LatexCommand \index{Storage class}
7302 In addition to the ANSI storage classes SDCC allows the following MCS51
7303 specific storage classes.
7307 \begin_inset LatexCommand \index{data}
7318 storage class for the Small Memory model.
7319 Variables declared with this storage class will be allocated in the directly
7320 addressable portion of the internal RAM of a 8051, e.g.:
7325 data unsigned char test_data;
7328 Writing 0x01 to this variable generates the assembly code:
7333 75*00 01\SpecialChar ~
7342 \begin_inset LatexCommand \index{xdata}
7349 Variables declared with this storage class will be placed in the external
7355 storage class for the Large Memory model, e.g.:
7360 xdata unsigned char test_xdata;
7363 Writing 0x01 to this variable generates the assembly code:
7368 90s00r00\SpecialChar ~
7400 \begin_inset LatexCommand \index{idata}
7407 Variables declared with this storage class will be allocated into the indirectly
7408 addressable portion of the internal ram of a 8051, e.g.:
7413 idata unsigned char test_idata;
7416 Writing 0x01 to this variable generates the assembly code:
7446 \begin_inset LatexCommand \index{pdata}
7453 Paged xdata access is currently not as straightforward as using the other
7454 addressing modes of a 8051.
7455 The following example writes 0x01 to the address pointed to.
7456 Please note, pdata access physically accesses xdata memory.
7457 The high byte of the address is determined by port P2 (or in case of some
7458 8051 variants by a separate Special Function Register, see section
7459 \begin_inset LatexCommand \ref{sub:MCS51-variants}
7468 pdata unsigned char *test_pdata_ptr;
7480 test_pdata_ptr = (pdata *)0xfe;
7486 *test_pdata_ptr = 1;
7491 Generates the assembly code:
7496 75*01 FE\SpecialChar ~
7500 _test_pdata_ptr,#0xFE
7532 Be extremely carefull if you use pdata together with the -
7543 \begin_inset LatexCommand \index{-\/-xstack}
7551 \begin_inset LatexCommand \index{code}
7558 'Variables' declared with this storage class will be placed in the code
7564 code unsigned char test_code;
7567 Read access to this variable generates the assembly code:
7572 90s00r6F\SpecialChar ~
7575 mov dptr,#_test_code
7601 \begin_inset LatexCommand \index{bit}
7608 This is a data-type and a storage class specifier.
7609 When a variable is declared as a bit, it is allocated into the bit addressable
7610 memory of 8051, e.g.:
7618 Writing 1 to this variable generates the assembly code:
7634 Apart from this 8051 specific storage class most architectures support ANSI-C
7636 \begin_inset LatexCommand \index{bitfields}
7646 Not really meant as examples, but nevertheless showing what bitfields are
7647 about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
7654 \begin_inset LatexCommand \index{sfr}
7659 \begin_inset LatexCommand \index{sbit}
7666 Like the bit keyword,
7670 signifies both a data-type and storage class, they are used to describe
7671 the special function registers and special bit variables of a 8051, eg:
7677 \begin_inset LatexCommand \index{at}
7681 0x80 P0;\SpecialChar ~
7682 /* special function register P0 at location 0x80 */
7684 sbit at 0xd7 CY; /* CY (Carry Flag
7685 \begin_inset LatexCommand \index{Flags}
7690 \begin_inset LatexCommand \index{Carry flag}
7698 \begin_inset LatexCommand \index{Pointers}
7702 to MCS51/DS390 specific memory spaces
7705 SDCC allows (via language extensions) pointers to explicitly point to any
7706 of the memory spaces
7707 \begin_inset LatexCommand \index{Memory model}
7712 In addition to the explicit pointers, the compiler uses (by default) generic
7713 pointers which can be used to point to any of the memory spaces.
7717 Pointer declaration examples:
7722 /* pointer physically in internal ram pointing to object in external ram
7725 xdata unsigned char * data p;
7729 /* pointer physically in external ram pointing to object in internal ram
7732 data unsigned char * xdata p;
7736 /* pointer physically in code rom pointing to data in xdata space */
7738 xdata unsigned char * code p;
7742 /* pointer physically in code space pointing to data in code space */
7744 code unsigned char * code p;
7748 /* the following is a generic pointer physically located in xdata space
7754 Well you get the idea.
7759 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
7772 The highest order byte of the
7776 pointers contains the data space information.
7777 Assembler support routines are called whenever data is stored or retrieved
7783 These are useful for developing reusable library
7784 \begin_inset LatexCommand \index{Libraries}
7789 Explicitly specifying the pointer type will generate the most efficient
7794 \begin_inset LatexCommand \index{Absolute addressing}
7801 Data items can be assigned an absolute address with the
7804 \begin_inset LatexCommand \index{at}
7810 keyword, in addition to a storage class, e.g.:
7816 \begin_inset LatexCommand \index{xdata}
7821 \begin_inset LatexCommand \index{at}
7825 0x7ffe unsigned int chksum;
7828 In the above example the variable chksum will located at 0x7ffe and 0x7fff
7829 of the external ram.
7830 The compiler does not actually reserve any space for variables declared
7831 in this way (they are implemented with an equate in the assembler).
7832 Thus it is left to the programmer to make sure there are no overlaps with
7833 other variables that are declared without the absolute address.
7834 The assembler listing file (.lst
7835 \begin_inset LatexCommand \index{<file>.lst}
7839 ) and the linker output files (.rst
7840 \begin_inset LatexCommand \index{<file>.rst}
7845 \begin_inset LatexCommand \index{<file>.map}
7849 ) are good places to look for such overlaps.
7852 In case of memory mapped I/O devices the keyword
7856 should be used to tell the compiler that accesses might not be optimized
7863 \begin_inset LatexCommand \index{volatile}
7868 \begin_inset LatexCommand \index{xdata}
7873 \begin_inset LatexCommand \index{at}
7877 0x8000 unsigned char PORTA_8255;
7880 Absolute address can be specified for variables in all storage classes,
7887 \begin_inset LatexCommand \index{bit}
7892 \begin_inset LatexCommand \index{at}
7899 The above example will allocate the variable at offset 0x02 in the bit-addressab
7901 There is no real advantage to assigning absolute addresses to variables
7902 in this manner, unless you want strict control over all the variables allocated.
7903 One possible use would be to write hardware portable code.
7904 For example, if you have a routine that uses one or more of the microcontroller
7905 I/O pins, and such pins are different for two different hardwares, you
7906 can declare the I/O pins in your routine using:
7911 extern volatile bit SDI;
7913 extern volatile bit SCLK;
7915 extern volatile bit CPOL;
7919 void DS1306_put(unsigned char value)
7927 unsigned char mask=0x80;
7951 SDI=(value & mask)?1:0;
7992 Then, someplace in the code for the first hardware you would use
7997 bit at 0x80 SDI;\SpecialChar ~
8001 /* I/O port 0, bit 0 */
8003 bit at 0x81 SCLK;\SpecialChar ~
8006 /* I/O port 0, bit 1 */
8008 bit CPOL;\SpecialChar ~
8019 /* This is a variable, let the linker allocate this one */
8022 Similarly, for the second hardware you would use
8027 bit at 0x83 SDI;\SpecialChar ~
8031 /* I/O port 0, bit 3 */
8033 bit at 0x91 SCLK;\SpecialChar ~
8036 /* I/O port 1, bit 1 */
8039 \begin_inset LatexCommand \index{bit}
8054 /* This is a variable, let the linker allocate this one */
8057 and you can use the same hardware dependent routine without changes, as
8058 for example in a library.
8059 This is somehow similar to sbit, but only one absolute address has to be
8060 specified in the whole project.
8064 \begin_inset LatexCommand \index{Parameters}
8069 \begin_inset LatexCommand \index{function parameter}
8074 \begin_inset LatexCommand \index{Local variable}
8081 Automatic (local) variables and parameters to functions can either be placed
8082 on the stack or in data-space.
8083 The default action of the compiler is to place these variables in the internal
8084 RAM (for small model) or external RAM (for large model).
8085 This in fact makes them similar to
8088 \begin_inset LatexCommand \index{static}
8094 so by default functions are non-reentrant
8095 \begin_inset LatexCommand \index{reentrant}
8104 They can be placed on the stack
8105 \begin_inset LatexCommand \index{stack}
8122 \begin_inset LatexCommand \index{-\/-stack-auto}
8128 option or by using the
8131 \begin_inset LatexCommand \index{reentrant}
8137 keyword in the function declaration, e.g.:
8142 unsigned char foo(char i) reentrant
8156 Since stack space on 8051 is limited, the
8174 option should be used sparingly.
8175 Note that the reentrant keyword just means that the parameters & local
8176 variables will be allocated to the stack, it
8180 mean that the function is register bank independent.
8184 Local variables can be assigned storage classes and absolute
8185 \begin_inset LatexCommand \index{Absolute addressing}
8202 xdata unsigned char i;
8214 data at 0x31 unsigned char j;
8226 In the above example the variable
8230 will be allocated in the external ram,
8234 in bit addressable space and
8253 or when a function is declared as
8257 this should only be done for static variables.
8261 \begin_inset LatexCommand \index{function parameter}
8265 however are not allowed any storage class
8266 \begin_inset LatexCommand \index{storage class}
8270 , (storage classes for parameters will be ignored), their allocation is
8271 governed by the memory model in use, and the reentrancy options.
8275 \begin_inset LatexCommand \label{sub:Overlaying}
8280 \begin_inset LatexCommand \index{Overlaying}
8288 \begin_inset LatexCommand \index{reentrant}
8292 functions SDCC will try to reduce internal ram space usage by overlaying
8293 parameters and local variables of a function (if possible).
8294 Parameters and local variables of a function will be allocated to an overlayabl
8295 e segment if the function has
8297 no other function calls and the function is non-reentrant and the memory
8299 \begin_inset LatexCommand \index{Memory model}
8306 If an explicit storage class
8307 \begin_inset LatexCommand \index{Storage class}
8311 is specified for a local variable, it will NOT be overlayed.
8314 Note that the compiler (not the linkage editor) makes the decision for overlayin
8316 Functions that are called from an interrupt service routine should be preceded
8317 by a #pragma\SpecialChar ~
8319 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
8323 if they are not reentrant.
8326 Also note that the compiler does not do any processing of inline assembler
8327 code, so the compiler might incorrectly assign local variables and parameters
8328 of a function into the overlay segment if the inline assembler code calls
8329 other c-functions that might use the overlay.
8330 In that case the #pragma\SpecialChar ~
8331 NOOVERLAY should be used.
8334 Parameters and local variables of functions that contain 16 or 32 bit multiplica
8336 \begin_inset LatexCommand \index{Multiplication}
8341 \begin_inset LatexCommand \index{Division}
8345 will NOT be overlayed since these are implemented using external functions,
8354 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
8360 void set_error(unsigned char errcd)
8376 void some_isr () interrupt
8377 \begin_inset LatexCommand \index{interrupt}
8407 In the above example the parameter
8415 would be assigned to the overlayable segment if the #pragma\SpecialChar ~
8417 not present, this could cause unpredictable runtime behavior when called
8419 The #pragma\SpecialChar ~
8420 NOOVERLAY ensures that the parameters and local variables for
8421 the function are NOT overlayed.
8424 Interrupt Service Routines
8425 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
8432 SDCC allows interrupt service routines to be coded in C, with some extended
8438 void timer_isr (void) interrupt 1 using 1
8452 The optional number following the
8455 \begin_inset LatexCommand \index{interrupt}
8461 keyword is the interrupt number this routine will service.
8462 When present, the compiler will insert a call to this routine in the interrupt
8463 vector table for the interrupt number specified.
8468 keyword can be used to tell the compiler to use the specified register
8469 bank (8051 specific) when generating code for this function.
8475 If you have multiple source files in your project, interrupt service routines
8476 can be present in any of them, but a prototype of the isr MUST be present
8477 or included in the file that contains the function
8484 Interrupt numbers and the corresponding address & descriptions for the Standard
8485 8051/8052 are listed below.
8486 SDCC will automatically adjust the interrupt vector table to the maximum
8487 interrupt number specified.
8493 \begin_inset Tabular
8494 <lyxtabular version="3" rows="7" columns="3">
8496 <column alignment="center" valignment="top" leftline="true" width="0in">
8497 <column alignment="center" valignment="top" leftline="true" width="0in">
8498 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0in">
8499 <row topline="true" bottomline="true">
8500 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8516 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8525 <row topline="true">
8526 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8542 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8551 <row topline="true">
8552 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8568 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8577 <row topline="true">
8578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8594 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8603 <row topline="true">
8604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8620 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8629 <row topline="true">
8630 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8646 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8655 <row topline="true" bottomline="true">
8656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8664 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8672 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8690 If the interrupt service routine is defined without
8693 \begin_inset LatexCommand \index{using}
8699 a register bank or with register bank 0 (using 0), the compiler will save
8700 the registers used by itself on the stack upon entry and restore them at
8701 exit, however if such an interrupt service routine calls another function
8702 then the entire register bank will be saved on the stack.
8703 This scheme may be advantageous for small interrupt service routines which
8704 have low register usage.
8707 If the interrupt service routine is defined to be using a specific register
8712 are save and restored, if such an interrupt service routine calls another
8713 function (using another register bank) then the entire register bank of
8714 the called function will be saved on the stack.
8715 This scheme is recommended for larger interrupt service routines.
8718 Using interrupts opens the door for some very interesting bugs:
8721 If the interrupt service routines changes variables which are accessed by
8722 other functions these variables should be declared
8727 \begin_inset LatexCommand \index{volatile}
8732 If the access to these variables is not
8735 \begin_inset LatexCommand \index{atomic access}
8742 the processor needs more than one instruction for the access and could
8743 be interrupted while accessing the variable) the interrupt must disabled
8744 during the access to avoid inconsistent data.
8745 Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
8746 and should be protected by disabling interrupts.
8747 You're not automatically on the safe side if you use 8 bit variables though.
8748 We need an example here: f.e.
8749 on the 8051 the harmless looking
8750 \begin_inset Quotes srd
8760 \begin_inset Quotes sld
8769 \begin_inset Quotes srd
8779 \begin_inset Quotes sld
8782 from within an interrupt routine might get lost if the interrupt occurs
8785 \begin_inset Quotes sld
8790 counter\SpecialChar ~
8795 \begin_inset Quotes srd
8798 is not atomic on the 8051 even if
8802 is located in data memory.
8803 Bugs like these are hard to reproduce and can cause a lot of trouble.
8807 A special note here, int (16 bit) and long (32 bit) integer division
8808 \begin_inset LatexCommand \index{Division}
8813 \begin_inset LatexCommand \index{Multiplication}
8818 \begin_inset LatexCommand \index{Modulus}
8823 \begin_inset LatexCommand \index{Floating point support}
8827 operations are implemented using external support routines developed in
8829 If an interrupt service routine needs to do any of these operations then
8830 the support routines (as mentioned in a following section) will have to
8831 be recompiled using the
8844 \begin_inset LatexCommand \index{-\/-stack-auto}
8850 option and the source file will need to be compiled using the
8865 \begin_inset LatexCommand \index{-\/-int-long-reent}
8872 Calling other functions from an interrupt service routine is not recommended,
8873 avoid it if possible.
8874 Note that when some function is called from an interrupt service routine
8875 it should be preceded by a #pragma\SpecialChar ~
8877 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
8881 if it is not reentrant.
8882 Furthermore nonreentrant functions should not be called from the main program
8883 while the interrupt service routine might be active.
8889 \begin_inset LatexCommand \ref{sub:Overlaying}
8894 about Overlaying and section
8895 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
8900 about Functions using private banks.
8903 Enabling and Disabling Interrupts
8906 Critical Functions and Critical Statements
8909 A special keyword may be associated with a function declaring it as
8914 SDCC will generate code to disable all interrupts
8915 \begin_inset LatexCommand \index{interrupt}
8919 upon entry to a critical function and restore the interrupt enable to the
8920 previous state before returning.
8921 Nesting critical functions will need one additional byte on the stack
8922 \begin_inset LatexCommand \index{stack}
8932 \begin_inset LatexCommand \index{critical}
8957 The critical attribute maybe used with other attributes like
8967 may also be used to disable interrupts more locally:
8975 More than one statement could have been included in the block.
8978 Enabling and Disabling Interrupts directly
8982 \begin_inset LatexCommand \index{interrupt}
8986 can also be disabled and enabled directly (8051):
9004 On other architectures which have seperate opcodes for enabling and disabling
9005 interrupts you might want to make use of defines with inline assembly
9006 \begin_inset LatexCommand \index{Assembler routines}
9016 \begin_inset LatexCommand \index{\_asm}
9025 \begin_inset LatexCommand \index{\_endasm}
9034 #define SEI _asm\SpecialChar ~
9046 Note: it is sometimes sufficient to disable only a specific interrupt source
9048 a timer or serial interrupt by manipulating an
9051 \begin_inset LatexCommand \index{interrupt mask}
9058 Usually the time during which interrupts are disabled should be kept as
9065 \begin_inset LatexCommand \index{interrupt latency}
9069 (the time between the occurrence of the interrupt and the execution of
9070 the first code in the interrupt routine) and
9075 \begin_inset LatexCommand \index{interrupt jitter}
9079 (the difference between the shortest and the longest interrupt latency).
9080 These really are something different, f.e.
9081 a serial interrupt has to be served before its buffer overruns so it cares
9082 for the maximum interrupt latency, whereas it does not care about jitter.
9083 On a loudspeaker driven via a digital to analog converter which is fed
9084 by an interrupt a latency of a few milliseconds might be tolerable, whereas
9085 a much smaller jitter will be very audible.
9088 You can reenable interrupts within an interrupt routine and on some architecture
9089 s you can make use of two (or more) levels of
9091 interrupt priorities
9094 \begin_inset LatexCommand \index{interrupt priority}
9099 On architectures which don't support interrupt priorities these can be
9100 implemented by manipulating the interrupt mask and reenabling interrupts
9101 within the interrupt routine.
9102 Don't add complexity unless you have to.
9106 Functions using private banks
9107 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
9112 \begin_inset LatexCommand \index{bank}
9122 \begin_inset LatexCommand \index{using}
9128 attribute (which tells the compiler to use a register bank other than the
9129 default bank zero) should only be applied to
9132 \begin_inset LatexCommand \index{interrupt}
9138 functions (see note 1 below).
9139 This will in most circumstances make the generated ISR code more efficient
9140 since it will not have to save registers on the stack.
9147 attribute will have no effect on the generated code for a
9151 function (but may occasionally be useful anyway
9157 possible exception: if a function is called ONLY from 'interrupt' functions
9158 using a particular bank, it can be declared with the same 'using' attribute
9159 as the calling 'interrupt' functions.
9160 For instance, if you have several ISRs using bank one, and all of them
9161 call memcpy(), it might make sense to create a specialized version of memcpy()
9162 'using 1', since this would prevent the ISR from having to save bank zero
9163 to the stack on entry and switch to bank zero before calling the function
9170 (pending: I don't think this has been done yet)
9177 function using a non-zero bank will assume that it can trash that register
9178 bank, and will not save it.
9179 Since high-priority interrupts
9180 \begin_inset LatexCommand \index{interrupt priority}
9184 can interrupt low-priority ones on the 8051 and friends, this means that
9185 if a high-priority ISR
9189 a particular bank occurs while processing a low-priority ISR
9193 the same bank, terrible and bad things can happen.
9194 To prevent this, no single register bank should be
9198 by both a high priority and a low priority ISR.
9199 This is probably most easily done by having all high priority ISRs use
9200 one bank and all low priority ISRs use another.
9201 If you have an ISR which can change priority at runtime, you're on your
9202 own: I suggest using the default bank zero and taking the small performance
9206 It is most efficient if your ISR calls no other functions.
9207 If your ISR must call other functions, it is most efficient if those functions
9208 use the same bank as the ISR (see note 1 below); the next best is if the
9209 called functions use bank zero.
9210 It is very inefficient to call a function using a different, non-zero bank
9216 \begin_inset LatexCommand \label{sub:Startup-Code}
9221 \begin_inset LatexCommand \index{Startup code}
9228 MCS51/DS390 Startup Code
9231 The compiler inserts a call to the C routine
9233 _sdcc_external_startup()
9234 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
9243 at the start of the CODE area.
9244 This routine is in the runtime library
9245 \begin_inset LatexCommand \index{Runtime library}
9250 By default this routine returns 0, if this routine returns a non-zero value,
9251 the static & global variable initialization will be skipped and the function
9252 main will be invoked.
9253 Otherwise static & global variables will be initialized before the function
9257 _sdcc_external_startup()
9259 routine to your program to override the default if you need to setup hardware
9260 or perform some other critical operation prior to static & global variable
9262 On some mcs51 variants xdata has to be explicitly enabled before it can
9263 be accessed, this is the place to do it.
9264 See also the compiler option
9283 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
9288 \begin_inset LatexCommand \ref{sub:MCS51-variants}
9293 about MCS51-variants.
9299 The HC08 startup code follows the same scheme as the MCS51 startup code.
9305 On the Z80 the startup code is inserted by linking with crt0.o which is generated
9306 from sdcc/device/lib/z80/crt0.s.
9307 If you need a different startup code you can use the compiler option
9328 \begin_inset LatexCommand \index{-\/-no-std-crt0}
9332 and provide your own crt0.o.
9336 Inline Assembler Code
9337 \begin_inset LatexCommand \index{Assembler routines}
9344 A Step by Step Introduction
9347 Starting from a small snippet of c-code this example shows for the MCS51
9348 how to use inline assembly, access variables, a function parameter and
9349 an array in xdata memory.
9350 This is a buffer routine which should be optimized:
9356 unsigned char xdata at 0x7f00 buf[0x100];
9358 unsigned char head,tail;
9362 void to_buffer( unsigned char c )
9370 if( head != tail-1 )
9385 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
9386 then a corresponding buffer.asm file is generated.
9387 We define a new function
9391 in file buffer.c in which we cut and paste the generated code, removing
9392 unwanted comments and some ':'.
9394 \begin_inset Quotes sld
9398 \begin_inset Quotes srd
9402 \begin_inset Quotes sld
9406 \begin_inset Quotes srd
9409 to the beginning and the end of the function body:
9415 /* With a cut and paste from the .asm file, we have something to start with.
9420 The function is not yet OK! (registers aren't saved) */
9422 void to_buffer_asm( unsigned char c )
9431 \begin_inset LatexCommand \index{\_asm}
9445 ;buffer.c if( head != tail-1 )
9487 ;buffer.c buf[ head++ ] = c;
9583 The new file buffer.c should compile with only one warning about the unreferenced
9584 function argument 'c'.
9585 Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
9592 unsigned char xdata at 0x7f00 buf[0x100];
9594 unsigned char head,tail;
9596 #define USE_ASSEMBLY
9600 #ifndef USE_ASSEMBLY
9602 void to_buffer( unsigned char c )
9610 if( head != tail-1 )
9630 void to_buffer( unsigned char c )
9638 c; // to avoid warning: unreferenced function argument
9645 \begin_inset LatexCommand \index{\_asm}
9659 ; save used registers here.
9670 ; If we were still using r2,r3 we would have to push them here.
9673 ; if( head != tail-1 )
9716 ; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
9740 ; buf[ head++ ] = c;
9751 a,dpl \SpecialChar ~
9758 ; dpl holds lower byte of function argument
9769 dpl,_head \SpecialChar ~
9772 ; buf is 0x100 byte aligned so head can be used directly
9814 ; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)
9826 ; restore used registers here
9839 The inline assembler code can contain any valid code understood by the assembler
9840 , this includes any assembler directives and comment lines
9846 The assembler does not like some characters like ':' or ''' in comments.
9850 The compiler does not do any validation of the code within the
9853 \begin_inset LatexCommand \index{\_asm}
9861 Specifically it will not know which registers are used and thus register
9863 \begin_inset LatexCommand \index{push/pop}
9867 has to be done manually.
9871 It is strongly recommended that each assembly instruction (including labels)
9872 be placed in a separate line (as the example shows).
9886 \begin_inset LatexCommand \index{-\/-peep-asm}
9892 command line option is used, the inline assembler code will be passed through
9893 the peephole optimizer
9894 \begin_inset LatexCommand \index{Peephole optimizer}
9899 There are only a few (if any) cases where this option makes sense, it might
9900 cause some unexpected changes in the inline assembler code.
9901 Please go through the peephole optimizer rules defined in file
9905 carefully before using this option.
9909 \begin_inset LatexCommand \label{sub:Naked-Functions}
9914 \begin_inset LatexCommand \index{Naked functions}
9921 A special keyword may be associated with a function declaring it as
9924 \begin_inset LatexCommand \index{\_naked}
9935 function modifier attribute prevents the compiler from generating prologue
9936 \begin_inset LatexCommand \index{function prologue}
9941 \begin_inset LatexCommand \index{function epilogue}
9945 code for that function.
9946 This means that the user is entirely responsible for such things as saving
9947 any registers that may need to be preserved, selecting the proper register
9948 bank, generating the
9952 instruction at the end, etc.
9953 Practically, this means that the contents of the function must be written
9954 in inline assembler.
9955 This is particularly useful for interrupt functions, which can have a large
9956 (and often unnecessary) prologue/epilogue.
9957 For example, compare the code generated by these two functions:
9963 \begin_inset LatexCommand \index{volatile}
9967 data unsigned char counter;
9971 void simpleInterrupt(void) interrupt
9972 \begin_inset LatexCommand \index{interrupt}
9990 void nakedInterrupt(void) interrupt 2 _naked
9999 \begin_inset LatexCommand \index{\_asm}
10028 ; MUST explicitly include ret or reti in _naked function.
10035 \begin_inset LatexCommand \index{\_endasm}
10044 For an 8051 target, the generated simpleInterrupt looks like:
10185 whereas nakedInterrupt looks like:
10209 ; MUST explicitly include ret or reti in _naked function.
10212 The #pragma directive EXCLUDE
10213 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
10217 allows a more fine grained control over pushing & popping
10218 \begin_inset LatexCommand \index{push/pop}
10225 While there is nothing preventing you from writing C code inside a _naked
10226 function, there are many ways to shoot yourself in the foot doing this,
10227 and it is recommended that you stick to inline assembler.
10230 Use of Labels within Inline Assembler
10233 SDCC allows the use of in-line assembler with a few restriction as regards
10235 In older versions of the compiler all labels defined within inline assembler
10244 where nnnn is a number less than 100 (which implies a limit of utmost 100
10245 inline assembler labels
10259 \begin_inset LatexCommand \index{\_asm}
10289 \begin_inset LatexCommand \index{\_endasm}
10296 Inline assembler code cannot reference any C-Labels, however it can reference
10298 \begin_inset LatexCommand \index{Labels}
10302 defined by the inline assembler, e.g.:
10327 ; some assembler code
10347 /* some more c code */
10349 clabel:\SpecialChar ~
10351 /* inline assembler cannot reference this label */
10363 $0003: ;label (can be reference by inline assembler only)
10375 /* some more c code */
10380 In other words inline assembly code can access labels defined in inline
10381 assembly within the scope of the function.
10382 The same goes the other way, ie.
10383 labels defines in inline assembly can not be accessed by C statements.
10386 Interfacing with Assembler Code
10387 \begin_inset LatexCommand \index{Assembler routines}
10394 Global Registers used for Parameter Passing
10395 \begin_inset LatexCommand \index{Parameter passing}
10402 The compiler always uses the global registers
10405 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
10410 \begin_inset LatexCommand \index{DPTR}
10415 \begin_inset LatexCommand \index{B (register)}
10424 \begin_inset LatexCommand \index{ACC}
10430 to pass the first parameter to a routine.
10431 The second parameter onwards is either allocated on the stack (for reentrant
10442 -stack-auto is used) or in data / xdata memory (depending on the memory
10447 Assembler Routine(non-reentrant
10448 \begin_inset LatexCommand \index{reentrant}
10453 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
10460 In the following example the function c_func calls an assembler routine
10461 asm_func, which takes two parameters
10462 \begin_inset LatexCommand \index{function parameter}
10471 extern int asm_func(unsigned char, unsigned char);
10475 int c_func (unsigned char i, unsigned char j)
10483 return asm_func(i,j);
10497 return c_func(10,9);
10502 The corresponding assembler function is:
10507 .globl _asm_func_PARM_2
10571 add a,_asm_func_PARM_2
10596 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
10613 Note here that the return values
10614 \begin_inset LatexCommand \index{return value}
10618 are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
10620 'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
10621 b' & 'acc' for four byte values.
10624 The parameter naming convention is _<function_name>_PARM_<n>, where n is
10625 the parameter number starting from 1, and counting from the left.
10626 The first parameter is passed in
10627 \begin_inset Quotes eld
10631 \begin_inset Quotes erd
10634 for One bye parameter,
10635 \begin_inset Quotes eld
10639 \begin_inset Quotes erd
10643 \begin_inset Quotes eld
10647 \begin_inset Quotes erd
10650 for three bytes and
10651 \begin_inset Quotes eld
10655 \begin_inset Quotes erd
10658 for four bytes, the variable name for the second parameter will be _<function_n
10663 Assemble the assembler routine with the following command:
10670 asx8051 -losg asmfunc.asm
10677 Then compile and link the assembler routine to the C source file with the
10685 sdcc cfunc.c asmfunc.rel
10688 Assembler Routine(reentrant
10689 \begin_inset LatexCommand \index{reentrant}
10694 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
10701 In this case the second parameter
10702 \begin_inset LatexCommand \index{function parameter}
10706 onwards will be passed on the stack, the parameters are pushed from right
10708 after the call the left most parameter will be on the top of the stack.
10709 Here is an example:
10714 extern int asm_func(unsigned char, unsigned char);
10718 int c_func (unsigned char i, unsigned char j) reentrant
10726 return asm_func(i,j);
10740 return c_func(10,9);
10745 The corresponding assembler routine is:
10851 The compiling and linking procedure remains the same, however note the extra
10852 entry & exit linkage required for the assembler code, _bp is the stack
10853 frame pointer and is used to compute the offset into the stack for parameters
10854 and local variables.
10858 \begin_inset LatexCommand \index{int (16 bit)}
10863 \begin_inset LatexCommand \index{long (32 bit)}
10870 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
10871 multiplication and modulus operations are implemented by support routines.
10872 These support routines are all developed in ANSI-C to facilitate porting
10873 to other MCUs, although some model specific assembler optimizations are
10875 The following files contain the described routines, all of them can be
10876 found in <installdir>/share/sdcc/lib.
10882 \begin_inset Tabular
10883 <lyxtabular version="3" rows="11" columns="2">
10885 <column alignment="center" valignment="top" leftline="true" width="0">
10886 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
10887 <row topline="true" bottomline="true">
10888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10898 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10909 <row topline="true">
10910 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10918 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10923 16 bit multiplication
10927 <row topline="true">
10928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10936 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10941 signed 16 bit division (calls _divuint)
10945 <row topline="true">
10946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10954 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10959 unsigned 16 bit division
10963 <row topline="true">
10964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10972 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10977 signed 16 bit modulus (calls _moduint)
10981 <row topline="true">
10982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10995 unsigned 16 bit modulus
10999 <row topline="true">
11000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11008 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11013 32 bit multiplication
11017 <row topline="true">
11018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11031 signed 32 division (calls _divulong)
11035 <row topline="true">
11036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11044 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11049 unsigned 32 division
11053 <row topline="true">
11054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11062 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11067 signed 32 bit modulus (calls _modulong)
11071 <row topline="true" bottomline="true">
11072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11085 unsigned 32 bit modulus
11098 Since they are compiled as
11103 \begin_inset LatexCommand \index{reentrant}
11108 \begin_inset LatexCommand \index{interrupt}
11112 service routines should not do any of the above operations.
11113 If this is unavoidable then the above routines will need to be compiled
11127 \begin_inset LatexCommand \index{-\/-stack-auto}
11133 option, after which the source program will have to be compiled with
11146 \begin_inset LatexCommand \index{-\/-int-long-reent}
11153 Notice that you don't have to call this routines directly.
11154 The compiler will use them automatically every time an integer operation
11158 Floating Point Support
11159 \begin_inset LatexCommand \index{Floating point support}
11166 SDCC supports IEEE (single precision 4 bytes) floating point numbers.The
11167 floating point support routines are derived from gcc's floatlib.c and consist
11168 of the following routines:
11176 \begin_inset Tabular
11177 <lyxtabular version="3" rows="17" columns="2">
11179 <column alignment="center" valignment="top" leftline="true" width="0">
11180 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
11181 <row topline="true" bottomline="true">
11182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11208 <row topline="true">
11209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11226 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11240 add floating point numbers
11244 <row topline="true">
11245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11262 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11276 subtract floating point numbers
11280 <row topline="true">
11281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11298 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11312 divide floating point numbers
11316 <row topline="true">
11317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11348 multiply floating point numbers
11352 <row topline="true">
11353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11370 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11384 convert floating point to unsigned char
11388 <row topline="true">
11389 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11406 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11420 convert floating point to signed char
11424 <row topline="true">
11425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11442 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11456 convert floating point to unsigned int
11460 <row topline="true">
11461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11478 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11492 convert floating point to signed int
11496 <row topline="true">
11497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11523 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11537 convert floating point to unsigned long
11541 <row topline="true">
11542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11559 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11573 convert floating point to signed long
11577 <row topline="true">
11578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11595 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11609 convert unsigned char to floating point
11613 <row topline="true">
11614 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11631 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11645 convert char to floating point number
11649 <row topline="true">
11650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11667 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11681 convert unsigned int to floating point
11685 <row topline="true">
11686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11717 convert int to floating point numbers
11721 <row topline="true">
11722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11739 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11753 convert unsigned long to floating point number
11757 <row topline="true" bottomline="true">
11758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11775 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11789 convert long to floating point number
11802 Note if all these routines are used simultaneously the data space might
11804 For serious floating point usage it is strongly recommended that the large
11806 Also notice that you don't have to call this routines directly.
11807 The compiler will use them automatically every time a floating point operation
11811 MCS51 Memory Models
11812 \begin_inset LatexCommand \index{Memory model}
11817 \begin_inset LatexCommand \index{MCS51 memory}
11824 SDCC allows two memory models for MCS51 code,
11833 Modules compiled with different memory models should
11837 be combined together or the results would be unpredictable.
11838 The library routines supplied with the compiler are compiled as both small
11840 The compiled library modules are contained in separate directories as small
11841 and large so that you can link to either set.
11845 When the large model is used all variables declared without a storage class
11846 will be allocated into the external ram, this includes all parameters and
11847 local variables (for non-reentrant
11848 \begin_inset LatexCommand \index{reentrant}
11853 When the small model is used variables without storage class are allocated
11854 in the internal ram.
11857 Judicious usage of the processor specific storage classes
11858 \begin_inset LatexCommand \index{Storage class}
11862 and the 'reentrant' function type will yield much more efficient code,
11863 than using the large model.
11864 Several optimizations are disabled when the program is compiled using the
11865 large model, it is therefore strongly recommended that the small model
11866 be used unless absolutely required.
11869 DS390 Memory Models
11870 \begin_inset LatexCommand \index{Memory model}
11875 \begin_inset LatexCommand \index{DS390 memory model}
11882 The only model supported is Flat 24
11883 \begin_inset LatexCommand \index{Flat 24 (memory model)}
11888 This generates code for the 24 bit contiguous addressing mode of the Dallas
11890 In this mode, up to four meg of external RAM or code space can be directly
11892 See the data sheets at www.dalsemi.com for further information on this part.
11896 Note that the compiler does not generate any code to place the processor
11897 into 24 bitmode (although
11901 in the ds390 libraries will do that for you).
11907 \begin_inset LatexCommand \index{Tinibios (DS390)}
11911 , the boot loader or similar code must ensure that the processor is in 24
11912 bit contiguous addressing mode before calling the SDCC startup code.
11930 option, variables will by default be placed into the XDATA segment.
11935 Segments may be placed anywhere in the 4 meg address space using the usual
11947 Note that if any segments are located above 64K, the -r flag must be passed
11948 to the linker to generate the proper segment relocations, and the Intel
11949 HEX output format must be used.
11950 The -r flag can be passed to the linker by using the option
11954 on the SDCC command line.
11955 However, currently the linker can not handle code segments > 64k.
11959 \begin_inset LatexCommand \index{Pragmas}
11966 SDCC supports the following #pragma directives.
11970 \begin_inset LatexCommand \index{\#pragma SAVE}
11974 - this will save all current options to the SAVE/RESTORE stack.
11979 \begin_inset LatexCommand \index{\#pragma RESTORE}
11983 - will restore saved options from the last save.
11984 SAVEs & RESTOREs can be nested.
11985 SDCC uses a SAVE/RESTORE stack: SAVE pushes current options to the stack,
11986 RESTORE pulls current options from the stack.
11991 \begin_inset LatexCommand \index{\#pragma NOGCSE}
11995 - will stop global common subexpression elimination.
11999 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
12003 - will stop loop induction optimizations.
12007 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
12011 - will not generate code for boundary value checking, when switch statements
12012 are turned into jump-tables (dangerous).
12013 For more details see section
12014 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
12022 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
12026 - the compiler will not overlay the parameters and local variables of a
12031 \begin_inset LatexCommand \index{\#pragma LESS\_PEDANTIC}
12035 - the compiler will not warn you anymore for obvious mistakes, you'r on
12040 \begin_inset LatexCommand \index{\#pragma NOLOOPREVERSE}
12044 - Will not do loop reversal optimization
12048 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
12052 NONE | {acc[,b[,dpl[,dph]]] - The exclude pragma disables generation of
12054 \begin_inset LatexCommand \index{push/pop}
12058 instruction in ISR function (using interrupt
12059 \begin_inset LatexCommand \index{interrupt}
12064 The directive should be placed immediately before the ISR function definition
12065 and it affects ALL ISR functions following it.
12066 To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
12067 EXCLUDE\SpecialChar ~
12069 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
12077 \begin_inset LatexCommand \index{\#pragma NOIV}
12081 - Do not generate interrupt vector table entries for all ISR functions
12082 defined after the pragma.
12083 This is useful in cases where the interrupt vector table must be defined
12084 manually, or when there is a secondary, manually defined interrupt vector
12086 for the autovector feature of the Cypress EZ-USB FX2).
12087 More elegantly this can be achieved by obmitting the optional interrupt
12088 number after the interrupt keyword, see section
12089 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
12098 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
12103 \begin_inset LatexCommand \index{function prologue}
12107 function1[,function2[,function3...]] - The compiler by default uses a caller
12108 saves convention for register saving across function calls, however this
12109 can cause unnecessary register pushing & popping when calling small functions
12110 from larger functions.
12111 This option can be used to switch off the register saving convention for
12112 the function names specified.
12113 The compiler will not save registers when calling these functions, extra
12114 code need to be manually inserted at the entry & exit for these functions
12115 to save & restore the registers used by these functions, this can SUBSTANTIALLY
12116 reduce code & improve run time performance of the generated code.
12117 In the future the compiler (with inter procedural analysis) may be able
12118 to determine the appropriate scheme to use for each function call.
12129 -callee-saves command line option is used, the function names specified
12130 in #pragma\SpecialChar ~
12132 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
12136 is appended to the list of functions specified in the command line.
12139 The pragma's are intended to be used to turn-on or off certain optimizations
12140 which might cause the compiler to generate extra stack / data space to
12141 store compiler generated temporary variables.
12142 This usually happens in large functions.
12143 Pragma directives should be used as shown in the following example, they
12144 are used to control options & optimizations for a given function; pragmas
12145 should be placed before and/or after a function, placing pragma's inside
12146 a function body could have unpredictable results.
12152 \begin_inset LatexCommand \index{\#pragma SAVE}
12163 /* save the current settings */
12166 \begin_inset LatexCommand \index{\#pragma NOGCSE}
12175 /* turnoff global subexpression elimination */
12177 #pragma NOINDUCTION
12178 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
12182 /* turn off induction optimizations */
12205 \begin_inset LatexCommand \index{\#pragma RESTORE}
12209 /* turn the optimizations back on */
12212 The compiler will generate a warning message when extra space is allocated.
12213 It is strongly recommended that the SAVE and RESTORE pragma's be used when
12214 changing options for a function.
12217 Defines Created by the Compiler
12218 \begin_inset LatexCommand \index{Defines created by the compiler}
12225 The compiler creates the following #defines
12226 \begin_inset LatexCommand \index{\#defines}
12236 \begin_inset Tabular
12237 <lyxtabular version="3" rows="10" columns="2">
12239 <column alignment="center" valignment="top" leftline="true" width="0">
12240 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
12241 <row topline="true" bottomline="true">
12242 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12252 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12263 <row topline="true">
12264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12270 \begin_inset LatexCommand \index{SDCC}
12277 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12282 this Symbol is always defined
12286 <row topline="true">
12287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12293 \begin_inset LatexCommand \index{SDCC\_mcs51}
12298 \begin_inset LatexCommand \index{SDCC\_ds390}
12303 \begin_inset LatexCommand \index{SDCC\_z80}
12310 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12315 depending on the model used (e.g.: -mds390
12319 <row topline="true">
12320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12326 \begin_inset LatexCommand \index{\_\_mcs51}
12331 \begin_inset LatexCommand \index{\_\_ds390}
12336 \begin_inset LatexCommand \index{\_\_hc08}
12341 \begin_inset LatexCommand \index{\_\_z80}
12348 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12353 depending on the model used (e.g.
12358 <row topline="true">
12359 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12365 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
12372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12395 <row topline="true">
12396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12402 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
12409 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12432 <row topline="true">
12433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12439 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
12446 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12469 <row topline="true">
12470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12476 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
12483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12506 <row topline="true">
12507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12513 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
12520 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12533 <row topline="true" bottomline="true">
12534 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12540 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
12547 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12569 Debugging with SDCDB
12570 \begin_inset LatexCommand \index{sdcdb}
12577 SDCC is distributed with a source level debugger
12578 \begin_inset LatexCommand \index{Debugger}
12583 The debugger uses a command line interface, the command repertoire of the
12584 debugger has been kept as close to gdb
12585 \begin_inset LatexCommand \index{gdb}
12589 (the GNU debugger) as possible.
12590 The configuration and build process is part of the standard compiler installati
12591 on, which also builds and installs the debugger in the target directory
12592 specified during configuration.
12593 The debugger allows you debug BOTH at the C source and at the ASM source
12595 Sdcdb is available on Unix platforms only.
12598 Compiling for Debugging
12601 The \SpecialChar \-
12603 debug option must be specified for all files for which debug information
12604 is to be generated.
12605 The complier generates a .adb file for each of these files.
12606 The linker creates the .cdb file from the .adb files and the address information.
12607 This .cdb is used by the debugger.
12610 How the Debugger Works
12623 -debug option is specified the compiler generates extra symbol information
12624 some of which are put into the assembler source and some are put into the
12626 Then the linker creates the .cdb file from the individual .adb files with
12627 the address information for the symbols.
12628 The debugger reads the symbolic information generated by the compiler &
12629 the address information generated by the linker.
12630 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
12631 execution is controlled by the debugger.
12632 When a command is issued for the debugger, it translates it into appropriate
12633 commands for the simulator.
12636 Starting the Debugger
12639 The debugger can be started using the following command line.
12640 (Assume the file you are debugging has the file name foo).
12654 The debugger will look for the following files.
12657 foo.c - the source file.
12660 foo.cdb - the debugger symbol information file.
12663 foo.ihx - the Intel hex format
12664 \begin_inset LatexCommand \index{Intel hex format}
12671 Command Line Options.
12684 -directory=<source file directory> this option can used to specify the directory
12686 The debugger will look into the directory list specified for source, cdb
12688 The items in the directory list must be separated by ':', e.g.
12689 if the source files can be in the directories /home/src1 and /home/src2,
12700 -directory option should be -
12710 -directory=/home/src1:/home/src2.
12711 Note there can be no spaces in the option.
12715 -cd <directory> - change to the <directory>.
12718 -fullname - used by GUI front ends.
12721 -cpu <cpu-type> - this argument is passed to the simulator please see the
12722 simulator docs for details.
12725 -X <Clock frequency > this options is passed to the simulator please see
12726 the simulator docs for details.
12729 -s <serial port file> passed to simulator see the simulator docs for details.
12732 -S <serial in,out> passed to simulator see the simulator docs for details.
12738 As mentioned earlier the command interface for the debugger has been deliberatel
12739 y kept as close the GNU debugger gdb, as possible.
12740 This will help the integration with existing graphical user interfaces
12741 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
12742 If you use a graphical user interface for the debugger you can skip the
12744 \layout Subsubsection*
12746 break [line | file:line | function | file:function]
12749 Set breakpoint at specified line or function:
12758 sdcdb>break foo.c:100
12760 sdcdb>break funcfoo
12762 sdcdb>break foo.c:funcfoo
12763 \layout Subsubsection*
12765 clear [line | file:line | function | file:function ]
12768 Clear breakpoint at specified line or function:
12777 sdcdb>clear foo.c:100
12779 sdcdb>clear funcfoo
12781 sdcdb>clear foo.c:funcfoo
12782 \layout Subsubsection*
12787 Continue program being debugged, after breakpoint.
12788 \layout Subsubsection*
12793 Execute till the end of the current function.
12794 \layout Subsubsection*
12799 Delete breakpoint number 'n'.
12800 If used without any option clear ALL user defined break points.
12801 \layout Subsubsection*
12803 info [break | stack | frame | registers ]
12806 info break - list all breakpoints
12809 info stack - show the function call stack.
12812 info frame - show information about the current execution frame.
12815 info registers - show content of all registers.
12816 \layout Subsubsection*
12821 Step program until it reaches a different source line.
12822 \layout Subsubsection*
12827 Step program, proceeding through subroutine calls.
12828 \layout Subsubsection*
12833 Start debugged program.
12834 \layout Subsubsection*
12839 Print type information of the variable.
12840 \layout Subsubsection*
12845 print value of variable.
12846 \layout Subsubsection*
12851 load the given file name.
12852 Note this is an alternate method of loading file for debugging.
12853 \layout Subsubsection*
12858 print information about current frame.
12859 \layout Subsubsection*
12864 Toggle between C source & assembly source.
12865 \layout Subsubsection*
12867 ! simulator command
12870 Send the string following '!' to the simulator, the simulator response is
12872 Note the debugger does not interpret the command being sent to the simulator,
12873 so if a command like 'go' is sent the debugger can loose its execution
12874 context and may display incorrect values.
12875 \layout Subsubsection*
12882 My name is Bobby Brown"
12885 Interfacing with XEmacs
12886 \begin_inset LatexCommand \index{XEmacs}
12891 \begin_inset LatexCommand \index{Emacs}
12898 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
12899 sdcdb.el and sdcdbsrc.el.
12900 These two files can be found in the $(prefix)/bin directory after the installat
12902 These files need to be loaded into XEmacs for the interface to work.
12903 This can be done at XEmacs startup time by inserting the following into
12904 your '.xemacs' file (which can be found in your HOME directory):
12910 (load-file sdcdbsrc.el)
12916 .xemacs is a lisp file so the () around the command is REQUIRED.
12917 The files can also be loaded dynamically while XEmacs is running, set the
12918 environment variable 'EMACSLOADPATH' to the installation bin directory
12919 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
12920 To start the interface enter the following command:
12934 You will prompted to enter the file name to be debugged.
12939 The command line options that are passed to the simulator directly are bound
12940 to default values in the file sdcdbsrc.el.
12941 The variables are listed below, these values maybe changed as required.
12944 sdcdbsrc-cpu-type '51
12947 sdcdbsrc-frequency '11059200
12950 sdcdbsrc-serial nil
12953 The following is a list of key mapping for the debugger interface.
12961 ;; Current Listing ::
12963 ;;key\SpecialChar ~
12978 binding\SpecialChar ~
13002 ;;---\SpecialChar ~
13017 ------\SpecialChar ~
13057 sdcdb-next-from-src\SpecialChar ~
13083 sdcdb-back-from-src\SpecialChar ~
13109 sdcdb-cont-from-src\SpecialChar ~
13119 SDCDB continue command
13135 sdcdb-step-from-src\SpecialChar ~
13161 sdcdb-whatis-c-sexp\SpecialChar ~
13171 SDCDB ptypecommand for data at
13235 sdcdbsrc-delete\SpecialChar ~
13249 SDCDB Delete all breakpoints if no arg
13297 given or delete arg (C-u arg x)
13313 sdcdbsrc-frame\SpecialChar ~
13328 SDCDB Display current frame if no arg,
13377 given or display frame arg
13442 sdcdbsrc-goto-sdcdb\SpecialChar ~
13452 Goto the SDCDB output buffer
13468 sdcdb-print-c-sexp\SpecialChar ~
13479 SDCDB print command for data at
13543 sdcdbsrc-goto-sdcdb\SpecialChar ~
13553 Goto the SDCDB output buffer
13569 sdcdbsrc-mode\SpecialChar ~
13585 Toggles Sdcdbsrc mode (turns it off)
13589 ;; C-c C-f\SpecialChar ~
13597 sdcdb-finish-from-src\SpecialChar ~
13605 SDCDB finish command
13609 ;; C-x SPC\SpecialChar ~
13617 sdcdb-break\SpecialChar ~
13635 Set break for line with point
13637 ;; ESC t\SpecialChar ~
13647 sdcdbsrc-mode\SpecialChar ~
13663 Toggle Sdcdbsrc mode
13665 ;; ESC m\SpecialChar ~
13675 sdcdbsrc-srcmode\SpecialChar ~
13697 Here are a few guidelines that will help the compiler generate more efficient
13698 code, some of the tips are specific to this compiler others are generally
13699 good programming practice.
13702 Use the smallest data type to represent your data-value.
13703 If it is known in advance that the value is going to be less than 256 then
13704 use an 'unsigned char' instead of a 'short' or 'int'.
13707 Use unsigned when it is known in advance that the value is not going to
13709 This helps especially if you are doing division or multiplication.
13712 NEVER jump into a LOOP.
13715 Declare the variables to be local whenever possible, especially loop control
13716 variables (induction).
13719 Since the compiler does not always do implicit integral promotion, the programme
13720 r should do an explicit cast when integral promotion is required.
13723 Reducing the size of division, multiplication & modulus operations can reduce
13724 code size substantially.
13725 Take the following code for example.
13731 foobar(unsigned int p1, unsigned char ch)
13739 unsigned char ch1 = p1 % ch ;
13750 For the modulus operation the variable ch will be promoted to unsigned int
13751 first then the modulus operation will be performed (this will lead to a
13752 call to support routine _moduint()), and the result will be casted to a
13754 If the code is changed to
13759 foobar(unsigned int p1, unsigned char ch)
13767 unsigned char ch1 = (unsigned char)p1 % ch ;
13778 It would substantially reduce the code generated (future versions of the
13779 compiler will be smart enough to detect such optimization opportunities).
13783 Have a look at the assembly listing to get a
13784 \begin_inset Quotes sld
13788 \begin_inset Quotes srd
13791 for the code generation.
13794 Notes on MCS51 memory
13795 \begin_inset LatexCommand \index{MCS51 memory}
13802 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
13803 RAM memory which is structured as follows
13807 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
13810 - Bytes 20-2F - 16 bytes to hold 128 bit
13811 \begin_inset LatexCommand \index{bit}
13817 - Bytes 30-7F - 80 bytes for general purpose use.
13822 Additionally some members of the MCS51 family may have up to 128 bytes of
13823 additional, indirectly addressable, internal RAM memory (
13828 \begin_inset LatexCommand \index{idata}
13833 Furthermore, some chips may have some built in external memory (
13838 \begin_inset LatexCommand \index{xdata}
13842 ) which should not be confused with the internal, directly addressable RAM
13848 \begin_inset LatexCommand \index{data}
13853 Sometimes this built in
13857 memory has to be activated before using it (you can probably find this
13858 information on the datasheet of the microcontroller your are using, see
13860 \begin_inset LatexCommand \ref{sub:Startup-Code}
13868 Normally SDCC will only use the first bank
13869 \begin_inset LatexCommand \index{bank}
13873 of registers (register bank 0), but it is possible to specify that other
13874 banks of registers should be used in interrupt
13875 \begin_inset LatexCommand \index{interrupt}
13880 By default, the compiler will place the stack after the last byte of allocated
13881 memory for variables.
13882 For example, if the first 2 banks of registers are used, and only four
13887 variables, it will position the base of the internal stack at address 20
13889 This implies that as the stack
13890 \begin_inset LatexCommand \index{stack}
13894 grows, it will use up the remaining register banks, and the 16 bytes used
13895 by the 128 bit variables, and 80 bytes for general purpose use.
13896 If any bit variables are used, the data variables will be placed after
13897 the byte holding the last bit variable.
13898 For example, if register banks 0 and 1 are used, and there are 9 bit variables
13903 variables will be placed starting at address 0x22.
13915 \begin_inset LatexCommand \index{-\/-data-loc}
13919 to specify the start address of the
13933 -iram-size to specify the size of the total internal RAM (
13945 By default the 8051 linker will place the stack after the last byte of data
13958 \begin_inset LatexCommand \index{-\/-stack-loc}
13962 allows you to specify the start of the stack, i.e.
13963 you could start it after any data in the general purpose area.
13964 If your microcontroller has additional indirectly addressable internal
13969 ) you can place the stack on it.
13970 You may also need to use -
13981 \begin_inset LatexCommand \index{-\/-data-loc}
13985 to set the start address of the external RAM (
14000 \begin_inset LatexCommand \index{-\/-data-loc}
14004 to specify its size.
14005 Same goes for the code memory, using -
14016 \begin_inset LatexCommand \index{-\/-data-loc}
14031 \begin_inset LatexCommand \index{-\/-data-loc}
14036 If in doubt, don't specify any options and see if the resulting memory
14037 layout is appropriate, then you can adjust it.
14040 The 8051 linker generates two files with memory allocation information.
14041 The first, with extension .map shows all the variables and segments.
14042 The second with extension .mem shows the final memory layout.
14043 The linker will complaint either if memory segments overlap, there is not
14044 enough memory, or there is not enough space for stack.
14045 If you get any linking warnings and/or errors related to stack or segments
14046 allocation, take a look at either the .map or .mem files to find out what
14048 The .mem file may even suggest a solution to the problem.
14052 \begin_inset LatexCommand \index{Tools}
14056 included in the distribution
14060 \begin_inset Tabular
14061 <lyxtabular version="3" rows="12" columns="3">
14063 <column alignment="center" valignment="top" leftline="true" width="0pt">
14064 <column alignment="center" valignment="top" leftline="true" width="0pt">
14065 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
14066 <row topline="true" bottomline="true">
14067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14083 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14092 <row topline="true">
14093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14101 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14106 Simulator for various architectures
14109 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14118 <row topline="true">
14119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14132 header file conversion
14135 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14140 sdcc/support/scripts
14144 <row topline="true">
14145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14158 header file conversion
14161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14166 sdcc/support/scripts
14170 <row topline="true">
14171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14187 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14205 <row topline="true">
14206 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14222 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14240 <row topline="true">
14241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14257 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14275 <row topline="true">
14276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14292 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14310 <row topline="true">
14311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14327 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14345 <row topline="true">
14346 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14362 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14380 <row topline="true">
14381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14389 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14397 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14415 <row topline="true" bottomline="true">
14416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14459 Related open source tools
14460 \begin_inset LatexCommand \index{Related tools}
14468 \begin_inset Tabular
14469 <lyxtabular version="3" rows="8" columns="3">
14471 <column alignment="center" valignment="top" leftline="true" width="0pt">
14472 <column alignment="block" valignment="top" leftline="true" width="30line%">
14473 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
14474 <row topline="true" bottomline="true">
14475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14491 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14500 <row topline="true">
14501 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14507 \begin_inset LatexCommand \index{gpsim}
14514 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14522 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14528 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
14536 <row topline="true">
14537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14559 \begin_inset LatexCommand \url{http://digilander.libero.it/fbradasc/FLP5.html}
14567 <row topline="true">
14568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14574 \begin_inset LatexCommand \index{srecord}
14581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14586 Object file conversion, checksumming, ...
14589 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14595 \begin_inset LatexCommand \url{http://srecord.sourceforge.net/}
14603 <row topline="true">
14604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14610 \begin_inset LatexCommand \index{objdump}
14617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14622 Object file conversion, ...
14625 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14630 Part of binutils (should be there anyway)
14634 <row topline="true">
14635 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14641 \begin_inset LatexCommand \index{doxygen}
14648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14653 Source code documentation system
14656 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14662 \begin_inset LatexCommand \url{http://www.doxygen.org}
14670 <row topline="true">
14671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14677 \begin_inset LatexCommand \index{splint}
14684 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14689 Statically checks c sources
14692 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14698 \begin_inset LatexCommand \url{http://www.splint.org}
14706 <row topline="true" bottomline="true">
14707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14713 \begin_inset LatexCommand \index{ddd}
14720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14725 Debugger, serves nicely as GUI to sdcdb
14726 \begin_inset LatexCommand \index{sdcdb}
14733 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14739 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
14756 Related documentation / recommended reading
14760 \begin_inset Tabular
14761 <lyxtabular version="3" rows="5" columns="3">
14763 <column alignment="center" valignment="top" leftline="true" width="0pt">
14764 <column alignment="block" valignment="top" leftline="true" width="30line%">
14765 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
14766 <row topline="true" bottomline="true">
14767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14792 <row topline="true">
14793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14803 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14808 Advanced Compiler Design and Implementation
14811 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14820 <row topline="true">
14821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14844 \begin_inset LatexCommand \index{C Reference card}
14851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14857 \begin_inset LatexCommand \url{http://www.refcards.com/about/c.html}
14865 <row topline="true">
14866 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14871 test_suite_spec.pdf
14874 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14879 sdcc regression test
14880 \begin_inset LatexCommand \index{Regression test}
14887 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14896 <row topline="true" bottomline="true">
14897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14928 sdcc internal documentation
14931 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14950 \begin_inset LatexCommand \index{Support}
14957 SDCC has grown to be a large project.
14958 The compiler alone (without the preprocessor, assembler and linker) is
14959 well over 100,000 lines of code (blank stripped).
14960 The open source nature of this project is a key to its continued growth
14962 You gain the benefit and support of many active software developers and
14964 Is SDCC perfect? No, that's why we need your help.
14965 The developers take pride in fixing reported bugs.
14966 You can help by reporting the bugs and helping other SDCC users.
14967 There are lots of ways to contribute, and we encourage you to take part
14968 in making SDCC a great software package.
14972 The SDCC project is hosted on the SDCC sourceforge site at
14973 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
14978 You'll find the complete set of mailing lists
14979 \begin_inset LatexCommand \index{Mailing list}
14983 , forums, bug reporting system, patch submission
14984 \begin_inset LatexCommand \index{Patch submission}
14989 \begin_inset LatexCommand \index{download}
14993 area and cvs code repository
14994 \begin_inset LatexCommand \index{cvs code repository}
15002 \begin_inset LatexCommand \index{Bug reporting}
15007 \begin_inset LatexCommand \index{Reporting bugs}
15014 The recommended way of reporting bugs is using the infrastructure of the
15016 You can follow the status of bug reports there and have an overview about
15020 Bug reports are automatically forwarded to the developer mailing list and
15021 will be fixed ASAP.
15022 When reporting a bug, it is very useful to include a small test program
15023 (the smaller the better) which reproduces the problem.
15024 If you can isolate the problem by looking at the generated assembly code,
15025 this can be very helpful.
15026 Compiling your program with the -
15037 \begin_inset LatexCommand \index{-\/-dumpall}
15041 option can sometimes be useful in locating optimization problems.
15042 When reporting a bug please maker sure you:
15045 Attach the code you are compiling with SDCC.
15049 Specify the exact command you use to run SDCC, or attach your Makefile.
15053 Specify the SDCC version (type "sdcc -v"), your platform, and operating
15058 Provide an exact copy of any error message or incorrect output.
15062 Put something meaningful in the subject of your message.
15065 Please attempt to include these 5 important parts, as applicable, in all
15066 requests for support or when reporting any problems or bugs with SDCC.
15067 Though this will make your message lengthy, it will greatly improve your
15068 chance that SDCC users and developers will be able to help you.
15069 Some SDCC developers are frustrated by bug reports without code provided
15070 that they can use to reproduce and ultimately fix the problem, so please
15071 be sure to provide sample code if you are reporting a bug!
15074 Please have a short check that you are using a recent version of SDCC and
15075 the bug is not yet known.
15076 This is the link for reporting bugs:
15077 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
15084 Requesting Features
15085 \begin_inset LatexCommand \label{sub:Requesting-Features}
15090 \begin_inset LatexCommand \index{Feature request}
15095 \begin_inset LatexCommand \index{Requesting features}
15102 Like bug reports feature requests are forwarded to the developer mailing
15104 This is the link for requesting features:
15105 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
15115 These links should take you directly to the
15116 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
15126 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
15127 automated messages (mid 2003)
15131 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
15135 , lists and forums are archived so if you are lucky someone already had
15140 \begin_inset LatexCommand \index{Changelog}
15147 You can follow the status of the cvs version
15148 \begin_inset LatexCommand \index{version}
15152 of SDCC by watching the file
15153 \begin_inset LatexCommand \htmlurl[ChangeLog]{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/sdcc/sdcc/ChangeLog?rev=HEAD&content-type=text/plain}
15157 in the cvs-repository.
15161 \begin_inset LatexCommand \index{Release policy}
15168 Historically there often were long delays between official releases and
15169 the sourceforge download area tends to get not updated at all.
15170 Current excuses might refer to problems with live range analysis, but if
15171 this is fixed, the next problem rising is that another excuse will have
15173 Kidding aside, we have to get better there! On the other hand there are
15174 daily snapshots available at
15175 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
15179 , and you can always built the very last version (hopefully with many bugs
15180 fixed, and features added) from the source code available at
15181 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
15189 \begin_inset LatexCommand \index{Examples}
15196 You'll find some small examples in the directory
15198 sdcc/device/examples/.
15201 More examples and libraries are available at
15203 The SDCC Open Knowledge Resource
15204 \begin_inset LatexCommand \url{http://www.qsl.net/dl9sec/SDCC_OKR.html}
15211 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
15218 I did insert a reference to Paul's web site here although it seems rather
15219 dedicated to a specific 8032 board (I think it's okay because it f.e.
15220 shows LCD/Harddisc interface and has a free 8051 monitor.
15221 Independent 8032 board vendors face hard competition of heavily subsidized
15222 development boards anyway).
15225 Maybe we should include some links to real world applications.
15226 Preferably pointer to pointers (one for each architecture) so this stays
15231 \begin_inset LatexCommand \index{Quality control}
15238 The compiler is passed through nightly compile and build checks.
15244 \begin_inset LatexCommand \index{Regression test}
15248 check that SDCC itself compiles flawlessly on several platforms and checks
15249 the quality of the code generated by SDCC by running the code through simulator
15251 There is a separate document
15254 \begin_inset LatexCommand \index{Test suite}
15263 You'll find the test code in the directory
15265 sdcc/support/regression
15268 You can run these tests manually by running
15272 in this directory (or f.e.
15277 if you don't want to run the complete tests).
15278 The test code might also be interesting if you want to look for examples
15279 \begin_inset LatexCommand \index{Examples}
15283 checking corner cases of SDCC or if you plan to submit patches
15284 \begin_inset LatexCommand \index{Patch submission}
15291 The pic port uses a different set of regression tests, you'll find them
15294 sdcc/src/regression
15299 SDCC Technical Data
15303 \begin_inset LatexCommand \index{Optimizations}
15310 SDCC performs a host of standard optimizations in addition to some MCU specific
15315 Sub-expression Elimination
15316 \begin_inset LatexCommand \index{Subexpression elimination}
15323 The compiler does local and global common subexpression elimination, e.g.:
15334 will be translated to
15346 Some subexpressions are not as obvious as the above example, e.g.:
15356 In this case the address arithmetic a->b[i] will be computed only once;
15357 the equivalent code in C would be.
15369 The compiler will try to keep these temporary variables in registers.
15372 Dead-Code Elimination
15373 \begin_inset LatexCommand \index{Dead-code elimination}
15394 i = 1; \SpecialChar ~
15403 global = 1;\SpecialChar ~
15416 global = 3;\SpecialChar ~
15445 \begin_inset LatexCommand \index{Copy propagation}
15501 Note: the dead stores created by this copy propagation will be eliminated
15502 by dead-code elimination.
15506 \begin_inset LatexCommand \index{Loop optimization}
15513 Two types of loop optimizations are done by SDCC loop invariant lifting
15514 and strength reduction of loop induction variables.
15515 In addition to the strength reduction the optimizer marks the induction
15516 variables and the register allocator tries to keep the induction variables
15517 in registers for the duration of the loop.
15518 Because of this preference of the register allocator
15519 \begin_inset LatexCommand \index{Register allocation}
15523 , loop induction optimization causes an increase in register pressure, which
15524 may cause unwanted spilling of other temporary variables into the stack
15525 \begin_inset LatexCommand \index{stack}
15530 The compiler will generate a warning message when it is forced to allocate
15531 extra space either on the stack or data space.
15532 If this extra space allocation is undesirable then induction optimization
15533 can be eliminated either for the entire source file (with -
15543 -noinduction option) or for a given function only using #pragma\SpecialChar ~
15545 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
15558 for (i = 0 ; i < 100 ; i ++)
15574 for (i = 0; i < 100; i++)
15583 As mentioned previously some loop invariants are not as apparent, all static
15584 address computations are also moved out of the loop.
15589 \begin_inset LatexCommand \index{Strength reduction}
15593 , this optimization substitutes an expression by a cheaper expression:
15598 for (i=0;i < 100; i++)
15616 for (i=0;i< 100;i++) {
15622 ar[itemp1] = itemp2;
15639 The more expensive multiplication
15640 \begin_inset LatexCommand \index{Multiplication}
15644 is changed to a less expensive addition.
15648 \begin_inset LatexCommand \index{Loop reversing}
15655 This optimization is done to reduce the overhead of checking loop boundaries
15656 for every iteration.
15657 Some simple loops can be reversed and implemented using a
15658 \begin_inset Quotes eld
15661 decrement and jump if not zero
15662 \begin_inset Quotes erd
15666 SDCC checks for the following criterion to determine if a loop is reversible
15667 (note: more sophisticated compilers use data-dependency analysis to make
15668 this determination, SDCC uses a more simple minded analysis).
15671 The 'for' loop is of the form
15677 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
15687 The <for body> does not contain
15688 \begin_inset Quotes eld
15692 \begin_inset Quotes erd
15696 \begin_inset Quotes erd
15702 All goto's are contained within the loop.
15705 No function calls within the loop.
15708 The loop control variable <sym> is not assigned any value within the loop
15711 The loop control variable does NOT participate in any arithmetic operation
15715 There are NO switch statements in the loop.
15718 Algebraic Simplifications
15721 SDCC does numerous algebraic simplifications, the following is a small sub-set
15722 of these optimizations.
15727 i = j + 0 ; /* changed to */ i = j;
15729 i /= 2;\SpecialChar ~
15733 /* changed to */ i >>= 1;
15735 i = j - j ; /* changed to */ i = 0;
15737 i = j / 1 ; /* changed to */ i = j;
15740 Note the subexpressions
15741 \begin_inset LatexCommand \index{Subexpression}
15745 given above are generally introduced by macro expansions or as a result
15746 of copy/constant propagation.
15749 'switch' Statements
15750 \begin_inset LatexCommand \label{sub:'switch'-Statements}
15755 \begin_inset LatexCommand \index{switch statement}
15762 SDCC changes switch statements to jump tables
15763 \begin_inset LatexCommand \index{jump tables}
15767 when the following conditions are true.
15771 The case labels are in numerical sequence, the labels need not be in order,
15772 and the starting number need not be one or zero.
15778 switch(i) {\SpecialChar ~
15809 case 4: ...\SpecialChar ~
15841 case 5: ...\SpecialChar ~
15873 case 3: ...\SpecialChar ~
15905 case 6: ...\SpecialChar ~
15973 Both the above switch statements will be implemented using a jump-table.
15974 The example to the right side is slightly more efficient as the check for
15975 the lower boundary of the jump-table is not needed.
15979 The number of case labels is at least three, since it takes two conditional
15980 statements to handle the boundary conditions.
15983 The number of case labels is less than 84, since each label takes 3 bytes
15984 and a jump-table can be utmost 256 bytes long.
15987 Switch statements which have gaps in the numeric sequence or those that
15988 have more that 84 case labels can be split into more than one switch statement
15989 for efficient code generation, e.g.:
16039 If the above switch statement is broken down into two switch statements
16078 case 9:\SpecialChar ~
16085 case 10:\SpecialChar ~
16091 case 11:\SpecialChar ~
16097 case 12:\SpecialChar ~
16104 then both the switch statements will be implemented using jump-tables whereas
16105 the unmodified switch statement will not be.
16106 You might also consider dummy cases 0 and 5 to 8 in this example.
16109 The pragma NOJTBOUND
16110 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
16114 can be used to turn off checking the
16127 It has no effect if a default label is supplied.
16128 Use of this pragma is dangerous: if the switch argument is not matched
16129 by a case statement the processor will happily jump into Nirvana.
16132 Bit-shifting Operations
16133 \begin_inset LatexCommand \index{Bit shifting}
16140 Bit shifting is one of the most frequently used operation in embedded programmin
16142 SDCC tries to implement bit-shift operations in the most efficient way
16158 generates the following code:
16175 In general SDCC will never setup a loop if the shift count is known.
16218 \begin_inset LatexCommand \index{Bit rotation}
16225 A special case of the bit-shift operation is bit rotation
16226 \begin_inset LatexCommand \index{rotating bits}
16230 , SDCC recognizes the following expression to be a left bit-rotation:
16240 char i;\SpecialChar ~
16251 /* unsigned is needed for rotation */
16256 i = ((i << 1) | (i >> 7));
16265 will generate the following code:
16284 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
16285 ns of this case will also be recognized as bit-rotation, i.e.:
16290 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
16293 Nibble and Byte Swapping
16296 Other special cases of the bit-shift operations are nibble or byte swapping
16297 \begin_inset LatexCommand \index{swapping nibbles/bytes}
16301 , SDCC recognizes the following expressions:
16324 i = ((i << 4) | (i >> 4));
16330 j = ((j << 8) | (j >> 8));
16333 and generates a swap instruction for the nibble swapping
16334 \begin_inset LatexCommand \index{Nibble swapping}
16338 or move instructions for the byte swapping
16339 \begin_inset LatexCommand \index{Byte swapping}
16345 \begin_inset Quotes sld
16349 \begin_inset Quotes srd
16352 example can be used to convert from little to big-endian or vice versa.
16353 If you want to change the endianness of a
16357 integer you have to cast to
16364 Note that SDCC stores numbers in little-endian
16370 Usually 8-bit processors don't care much about endianness.
16371 This is not the case for the standard 8051 which only has an instruction
16377 \begin_inset LatexCommand \index{DPTR}
16385 so little-endian is the more efficient byte order.
16389 \begin_inset LatexCommand \index{little-endian}
16394 \begin_inset LatexCommand \index{Endianness}
16399 lowest order first).
16403 \begin_inset LatexCommand \index{Highest Order Bit}
16410 It is frequently required to obtain the highest order bit of an integral
16411 type (long, int, short or char types).
16412 SDCC recognizes the following expression to yield the highest order bit
16413 and generates optimized code for it, e.g.:
16435 hob = (gint >> 15) & 1;
16445 will generate the following code:
16478 000A E5*01\SpecialChar ~
16505 000C 23\SpecialChar ~
16536 000D 54 01\SpecialChar ~
16563 000F F5*02\SpecialChar ~
16591 Variations of this case however will
16596 It is a standard C expression, so I heartily recommend this be the only
16597 way to get the highest order bit, (it is portable).
16598 Of course it will be recognized even if it is embedded in other expressions,
16604 xyz = gint + ((gint >> 15) & 1);
16607 will still be recognized.
16611 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
16616 \begin_inset LatexCommand \index{Peephole optimizer}
16623 The compiler uses a rule based, pattern matching and re-writing mechanism
16624 for peep-hole optimization.
16629 a peep-hole optimizer by Christopher W.
16630 Fraser (cwfraser@microsoft.com).
16631 A default set of rules are compiled into the compiler, additional rules
16632 may be added with the
16645 \begin_inset LatexCommand \index{-\/-peep-file}
16652 The rule language is best illustrated with examples.
16676 The above rule will change the following assembly
16677 \begin_inset LatexCommand \index{Assembler routines}
16699 Note: All occurrences of a
16703 (pattern variable) must denote the same string.
16704 With the above rule, the assembly sequence:
16714 will remain unmodified.
16718 Other special case optimizations may be added by the user (via
16734 some variants of the 8051 MCU allow only
16743 The following two rules will change all
16762 replace { lcall %1 } by { acall %1 }
16764 replace { ljmp %1 } by { ajmp %1 }
16769 inline-assembler code
16771 is also passed through the peep hole optimizer, thus the peephole optimizer
16772 can also be used as an assembly level macro expander.
16773 The rules themselves are MCU dependent whereas the rule language infra-structur
16774 e is MCU independent.
16775 Peephole optimization rules for other MCU can be easily programmed using
16780 The syntax for a rule is as follows:
16785 rule := replace [ restart ] '{' <assembly sequence> '
16823 <assembly sequence> '
16841 '}' [if <functionName> ] '
16846 <assembly sequence> := assembly instruction (each instruction including
16847 labels must be on a separate line).
16851 The optimizer will apply to the rules one by one from the top in the sequence
16852 of their appearance, it will terminate when all rules are exhausted.
16853 If the 'restart' option is specified, then the optimizer will start matching
16854 the rules again from the top, this option for a rule is expensive (performance)
16855 , it is intended to be used in situations where a transformation will trigger
16856 the same rule again.
16857 An example of this (not a good one, it has side effects) is the following
16880 Note that the replace pattern cannot be a blank, but can be a comment line.
16881 Without the 'restart' option only the inner most 'pop' 'push' pair would
16882 be eliminated, i.e.:
16912 the restart option the rule will be applied again to the resulting code
16913 and then all the pop-push pairs will be eliminated to yield:
16923 A conditional function can be attached to a rule.
16924 Attaching rules are somewhat more involved, let me illustrate this with
16951 The optimizer does a look-up of a function name table defined in function
16956 in the source file SDCCpeeph.c, with the name
16961 If it finds a corresponding entry the function is called.
16962 Note there can be no parameters specified for these functions, in this
16967 is crucial, since the function
16971 expects to find the label in that particular variable (the hash table containin
16972 g the variable bindings is passed as a parameter).
16973 If you want to code more such functions, take a close look at the function
16974 labelInRange and the calling mechanism in source file SDCCpeeph.c.
16975 Currently implemented are
16977 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
16978 24bitMode, portIsDS390, 24bitModeAndPortDS390
16987 I know this whole thing is a little kludgey, but maybe some day we will
16988 have some better means.
16989 If you are looking at this file, you will see the default rules that are
16990 compiled into the compiler, you can add your own rules in the default set
16991 there if you get tired of specifying the -
17011 <pending: this is messy and incomplete>
17016 Compiler support routines (_gptrget, _mulint etc)
17019 Stdclib functions (puts, printf, strcat etc)
17022 Math functions (sin, pow, sqrt etc)
17026 \begin_inset LatexCommand \index{Libraries}
17030 included in SDCC should have a license at least as liberal as the GNU Lesser
17031 General Public License
17032 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
17043 license statements for the libraries are missing.
17044 sdcc/device/lib/ser_ir.c
17048 come with a GPL (as opposed to LGPL) License - this will not be liberal
17049 enough for many embedded programmers.
17052 If you have ported some library or want to share experience about some code
17054 falls into any of these categories Busses (I
17055 \begin_inset Formula $^{\textrm{2}}$
17058 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
17059 cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
17060 Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list
17061 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
17066 would certainly like to hear about it.
17067 Programmers coding for embedded systems are not especially famous for being
17068 enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
17069 e these references are very valuable.
17073 \begin_inset LatexCommand \label{sub:External-Stack}
17078 \begin_inset LatexCommand \index{stack}
17083 \begin_inset LatexCommand \index{External stack}
17090 The external stack (-
17101 \begin_inset LatexCommand \index{-\/-xstack}
17105 ) is located at the start of the external ram segment, and is 256 bytes
17117 -xstack option is used to compile the program, the parameters and local
17118 variables of all reentrant functions are allocated in this area.
17119 This option is provided for programs with large stack space requirements.
17120 When used with the -
17131 \begin_inset LatexCommand \index{-\/-stack-auto}
17135 option, all parameters and local variables are allocated on the external
17136 stack (note support libraries will need to be recompiled with the same
17140 The compiler outputs the higher order address byte of the external ram segment
17141 into PORT P2, therefore when using the External Stack option, this port
17142 MAY NOT be used by the application program.
17146 \begin_inset LatexCommand \index{ANSI-compliance}
17151 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
17158 Deviations from the compliance:
17161 functions are not always reentrant
17162 \begin_inset LatexCommand \index{reentrant}
17169 structures cannot be assigned values directly, cannot be passed as function
17170 parameters or assigned to each other and cannot be a return value from
17197 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
17208 struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
17230 return rets;/* is invalid in SDCC although allowed in ANSI */
17237 \begin_inset LatexCommand \index{long long (not supported)}
17242 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
17250 \begin_inset LatexCommand \index{double (not supported)}
17254 ' precision floating point
17255 \begin_inset LatexCommand \index{Floating point support}
17262 No support for setjmp
17263 \begin_inset LatexCommand \index{setjmp (not supported)}
17268 \begin_inset LatexCommand \index{longjmp (not supported)}
17276 \begin_inset LatexCommand \index{K\&R style}
17280 function declarations are NOT allowed.
17286 foo(i,j) /* this old style of function declarations */
17288 int i,j; /* are valid in ANSI but not valid in SDCC */
17303 functions declared as pointers
17304 \begin_inset LatexCommand \index{Pointers}
17309 \begin_inset LatexCommand \index{function pointers}
17313 must be dereferenced during the call.
17324 /* has to be called like this */
17326 (*foo)(); /* ANSI standard allows calls to be made like 'foo()' */
17330 Cyclomatic Complexity
17331 \begin_inset LatexCommand \index{Cyclomatic complexity}
17338 Cyclomatic complexity of a function is defined as the number of independent
17339 paths the program can take during execution of the function.
17340 This is an important number since it defines the number test cases you
17341 have to generate to validate the function.
17342 The accepted industry standard for complexity number is 10, if the cyclomatic
17343 complexity reported by SDCC exceeds 10 you should think about simplification
17344 of the function logic.
17345 Note that the complexity level is not related to the number of lines of
17346 code in a function.
17347 Large functions can have low complexity, and small functions can have large
17353 SDCC uses the following formula to compute the complexity:
17358 complexity = (number of edges in control flow graph) - (number of nodes
17359 in control flow graph) + 2;
17363 Having said that the industry standard is 10, you should be aware that in
17364 some cases it be may unavoidable to have a complexity level of less than
17366 For example if you have switch statement with more than 10 case labels,
17367 each case label adds one to the complexity level.
17368 The complexity level is by no means an absolute measure of the algorithmic
17369 complexity of the function, it does however provide a good starting point
17370 for which functions you might look at for further optimization.
17377 \begin_inset LatexCommand \label{sub:MCS51-variants}
17382 \begin_inset LatexCommand \index{MCS51 variants}
17389 MCS51 processors are available from many vendors and come in many different
17391 While they might differ considerably in respect to Special Function Registers
17392 the core MCS51 is usually not modified or is kept compatible.
17394 \layout Subsubsection*
17396 pdata access by SFR
17397 \begin_inset LatexCommand \index{sfr}
17404 With the upcome of devices with internal xdata and flash memory devices
17405 using port P2 as dedicated I/O port is becoming more popular.
17406 Switching the high byte for pdata
17407 \begin_inset LatexCommand \index{pdata}
17411 access which was formerly done by port P2 is then achieved by a Special
17413 In well-established MCS51 tradition the address of this
17417 is where the chip designers decided to put it.
17418 As pdata addressing is used in the startup code for the initialization
17419 of xdata variables a separate startup code should be used as described
17421 \begin_inset LatexCommand \ref{sub:Startup-Code}
17426 \layout Subsubsection*
17428 Other Features available by SFR
17431 Some MCS51 variants offer features like Double DPTR
17432 \begin_inset LatexCommand \index{DPTR}
17436 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
17437 These are currently not used for the MCS51 port.
17438 If you absolutely need them you can fall back to inline assembly or submit
17442 The Z80 and gbz80 port
17445 SDCC can target both the Zilog
17446 \begin_inset LatexCommand \index{Z80}
17450 and the Nintendo Gameboy's Z80-like gbz80
17451 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
17456 The Z80 port is passed through the same
17459 \begin_inset LatexCommand \index{Regression test}
17465 as MCS51 and DS390 ports, so floating point support, support for long variables
17466 and bitfield support is fine.
17467 See mailing lists and forums about interrupt routines and access to I/O
17471 As always, the code is the authoritative reference - see z80/ralloc.c and
17474 \begin_inset LatexCommand \index{stack}
17478 frame is similar to that generated by the IAR Z80 compiler.
17479 IX is used as the base pointer, HL is used as a temporary register, and
17480 BC and DE are available for holding variables.
17481 IY is currently unused.
17483 \begin_inset LatexCommand \index{return value}
17488 One bad side effect of using IX as the base pointer is that a functions
17489 stack frame is limited to 127 bytes - this will be fixed in a later version.
17495 The port to the Motorola HC08
17496 \begin_inset LatexCommand \index{HC08}
17500 family has been added in October 2003, thank you Erik!
17503 Retargetting for other MCUs.
17506 The issues for retargetting the compiler are far too numerous to be covered
17508 What follows is a brief description of each of the seven phases of the
17509 compiler and its MCU dependency.
17512 Parsing the source and building the annotated parse tree.
17513 This phase is largely MCU independent (except for the language extensions).
17514 Syntax & semantic checks are also done in this phase, along with some initial
17515 optimizations like back patching labels and the pattern matching optimizations
17516 like bit-rotation etc.
17519 The second phase involves generating an intermediate code which can be easy
17520 manipulated during the later phases.
17521 This phase is entirely MCU independent.
17522 The intermediate code generation assumes the target machine has unlimited
17523 number of registers, and designates them with the name iTemp.
17524 The compiler can be made to dump a human readable form of the code generated
17538 This phase does the bulk of the standard optimizations and is also MCU independe
17540 This phase can be broken down into several sub-phases:
17544 Break down intermediate code (iCode) into basic blocks.
17546 Do control flow & data flow analysis on the basic blocks.
17548 Do local common subexpression elimination, then global subexpression elimination
17550 Dead code elimination
17554 If loop optimizations caused any changes then do 'global subexpression eliminati
17555 on' and 'dead code elimination' again.
17558 This phase determines the live-ranges; by live range I mean those iTemp
17559 variables defined by the compiler that still survive after all the optimization
17561 Live range analysis
17562 \begin_inset LatexCommand \index{Live range analysis}
17566 is essential for register allocation, since these computation determines
17567 which of these iTemps will be assigned to registers, and for how long.
17570 Phase five is register allocation.
17571 There are two parts to this process.
17575 The first part I call 'register packing' (for lack of a better term).
17576 In this case several MCU specific expression folding is done to reduce
17581 The second part is more MCU independent and deals with allocating registers
17582 to the remaining live ranges.
17583 A lot of MCU specific code does creep into this phase because of the limited
17584 number of index registers available in the 8051.
17587 The Code generation phase is (unhappily), entirely MCU dependent and very
17588 little (if any at all) of this code can be reused for other MCU.
17589 However the scheme for allocating a homogenized assembler operand for each
17590 iCode operand may be reused.
17593 As mentioned in the optimization section the peep-hole optimizer is rule
17594 based system, which can reprogrammed for other MCUs.
17598 \begin_inset LatexCommand \index{Compiler internals}
17605 The anatomy of the compiler
17606 \begin_inset LatexCommand \label{sub:The-anatomy-of}
17615 This is an excerpt from an article published in Circuit Cellar Magazine
17617 It's a little outdated (the compiler is much more efficient now and user/develo
17618 per friendly), but pretty well exposes the guts of it all.
17624 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
17625 It is fairly easy to retarget for other 8-bit MCU.
17626 Here we take a look at some of the internals of the compiler.
17631 \begin_inset LatexCommand \index{Parsing}
17638 Parsing the input source file and creating an AST (Annotated Syntax Tree
17639 \begin_inset LatexCommand \index{Annotated syntax tree}
17644 This phase also involves propagating types (annotating each node of the
17645 parse tree with type information) and semantic analysis.
17646 There are some MCU specific parsing rules.
17647 For example the storage classes, the extended storage classes are MCU specific
17648 while there may be a xdata storage class for 8051 there is no such storage
17649 class for z80 or Atmel AVR.
17650 SDCC allows MCU specific storage class extensions, i.e.
17651 xdata will be treated as a storage class specifier when parsing 8051 C
17652 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
17657 \begin_inset LatexCommand \index{iCode}
17664 Intermediate code generation.
17665 In this phase the AST is broken down into three-operand form (iCode).
17666 These three operand forms are represented as doubly linked lists.
17667 ICode is the term given to the intermediate form generated by the compiler.
17668 ICode example section shows some examples of iCode generated for some simple
17669 C source functions.
17673 \begin_inset LatexCommand \index{Optimizations}
17680 Bulk of the target independent optimizations is performed in this phase.
17681 The optimizations include constant propagation, common sub-expression eliminati
17682 on, loop invariant code movement, strength reduction of loop induction variables
17683 and dead-code elimination.
17686 Live range analysis
17687 \begin_inset LatexCommand \index{Live range analysis}
17694 During intermediate code generation phase, the compiler assumes the target
17695 machine has infinite number of registers and generates a lot of temporary
17697 The live range computation determines the lifetime of each of these compiler-ge
17698 nerated temporaries.
17699 A picture speaks a thousand words.
17700 ICode example sections show the live range annotations for each of the
17702 It is important to note here, each iCode is assigned a number in the order
17703 of its execution in the function.
17704 The live ranges are computed in terms of these numbers.
17705 The from number is the number of the iCode which first defines the operand
17706 and the to number signifies the iCode which uses this operand last.
17709 Register Allocation
17710 \begin_inset LatexCommand \index{Register allocation}
17717 The register allocation determines the type and number of registers needed
17719 In most MCUs only a few registers can be used for indirect addressing.
17720 In case of 8051 for example the registers R0 & R1 can be used to indirectly
17721 address the internal ram and DPTR to indirectly address the external ram.
17722 The compiler will try to allocate the appropriate register to pointer variables
17724 ICode example section shows the operands annotated with the registers assigned
17726 The compiler will try to keep operands in registers as much as possible;
17727 there are several schemes the compiler uses to do achieve this.
17728 When the compiler runs out of registers the compiler will check to see
17729 if there are any live operands which is not used or defined in the current
17730 basic block being processed, if there are any found then it will push that
17731 operand and use the registers in this block, the operand will then be popped
17732 at the end of the basic block.
17736 There are other MCU specific considerations in this phase.
17737 Some MCUs have an accumulator; very short-lived operands could be assigned
17738 to the accumulator instead of general-purpose register.
17744 Figure II gives a table of iCode operations supported by the compiler.
17745 The code generation involves translating these operations into corresponding
17746 assembly code for the processor.
17747 This sounds overly simple but that is the essence of code generation.
17748 Some of the iCode operations are generated on a MCU specific manner for
17749 example, the z80 port does not use registers to pass parameters so the
17750 SEND and RECV iCode operations will not be generated, and it also does
17751 not support JUMPTABLES.
17758 <Where is Figure II ?>
17762 \begin_inset LatexCommand \index{iCode}
17769 This section shows some details of iCode.
17770 The example C code does not do anything useful; it is used as an example
17771 to illustrate the intermediate code generated by the compiler.
17783 /* This function does nothing useful.
17790 for the purpose of explaining iCode */
17793 short function (data int *x)
17801 short i=10; /* dead initialization eliminated */
17806 short sum=10; /* dead initialization eliminated */
17819 while (*x) *x++ = *p++;
17833 /* compiler detects i,j to be induction variables */
17837 for (i = 0, j = 10 ; i < 10 ; i++, j
17863 mul += i * 3; /* this multiplication remains */
17869 gint += j * 3;/* this multiplication changed to addition */
17883 In addition to the operands each iCode contains information about the filename
17884 and line it corresponds to in the source file.
17885 The first field in the listing should be interpreted as follows:
17890 Filename(linenumber: iCode Execution sequence number : ICode hash table
17891 key : loop depth of the iCode).
17896 Then follows the human readable form of the ICode operation.
17897 Each operand of this triplet form can be of three basic types a) compiler
17898 generated temporary b) user defined variable c) a constant value.
17899 Note that local variables and parameters are replaced by compiler generated
17902 \begin_inset LatexCommand \index{Live range analysis}
17906 are computed only for temporaries (i.e.
17907 live ranges are not computed for global variables).
17909 \begin_inset LatexCommand \index{Register allocation}
17913 are allocated for temporaries only.
17914 Operands are formatted in the following manner:
17919 Operand Name [lr live-from : live-to ] { type information } [ registers
17925 As mentioned earlier the live ranges are computed in terms of the execution
17926 sequence number of the iCodes, for example
17928 the iTemp0 is live from (i.e.
17929 first defined in iCode with execution sequence number 3, and is last used
17930 in the iCode with sequence number 5).
17931 For induction variables such as iTemp21 the live range computation extends
17932 the lifetime from the start to the end of the loop.
17934 The register allocator used the live range information to allocate registers,
17935 the same registers may be used for different temporaries if their live
17936 ranges do not overlap, for example r0 is allocated to both iTemp6 and to
17937 iTemp17 since their live ranges do not overlap.
17938 In addition the allocator also takes into consideration the type and usage
17939 of a temporary, for example itemp6 is a pointer to near space and is used
17940 as to fetch data from (i.e.
17941 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer registers (r0).
17942 Some short lived temporaries are allocated to special registers which have
17943 meaning to the code generator e.g.
17944 iTemp13 is allocated to a pseudo register CC which tells the back end that
17945 the temporary is used only for a conditional jump the code generation makes
17946 use of this information to optimize a compare and jump ICode.
17948 There are several loop optimizations
17949 \begin_inset LatexCommand \index{Loop optimization}
17953 performed by the compiler.
17954 It can detect induction variables iTemp21(i) and iTemp23(j).
17955 Also note the compiler does selective strength reduction
17956 \begin_inset LatexCommand \index{Strength reduction}
17961 the multiplication of an induction variable in line 18 (gint = j * 3) is
17962 changed to addition, a new temporary iTemp17 is allocated and assigned
17963 a initial value, a constant 3 is then added for each iteration of the loop.
17964 The compiler does not change the multiplication
17965 \begin_inset LatexCommand \index{Multiplication}
17969 in line 17 however since the processor does support an 8 * 8 bit multiplication.
17971 Note the dead code elimination
17972 \begin_inset LatexCommand \index{Dead-code elimination}
17976 optimization eliminated the dead assignments in line 7 & 8 to I and sum
17984 Sample.c (5:1:0:0) _entry($9) :
17989 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
17994 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
17999 Sample.c(11:4:53:0) preHeaderLbl0($11) :
18004 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
18010 Sample.c(11:6:5:1) _whilecontinue_0($1) :
18015 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
18021 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
18026 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
18032 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
18038 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
18044 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
18050 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
18051 * int}[r0] + 0x2 {short}
18056 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
18061 Sample.c(11:17:21:0)_whilebreak_0($3) :
18066 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
18071 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
18076 Sample.c(15:20:54:0)preHeaderLbl1($13) :
18081 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
18086 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
18091 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
18096 Sample.c(15:24:26:1)_forcond_0($4) :
18101 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
18107 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
18112 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
18113 + ITemp21 [lr21:38]{short}[r4]
18118 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
18124 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
18125 + iTemp15 [lr29:30]{short}[r1]
18130 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
18136 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
18142 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
18148 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
18154 Sample.c(19:38:47:1) goto _forcond_0($4)
18159 Sample.c(19:39:48:0)_forbreak_0($7) :
18164 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
18165 + ITemp11 [lr19:40]{short}[r3]
18170 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
18175 Sample.c(20:42:51:0)_return($8) :
18180 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
18186 Finally the code generated for this function:
18227 ; ----------------------------------------------
18232 ; function function
18237 ; ----------------------------------------------
18247 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
18259 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
18271 ;_whilecontinue_0($1) :
18281 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
18286 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
18345 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
18364 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
18411 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
18451 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
18477 ; iTemp6 [lr5:16]{_near * int}[r0] =
18482 ; iTemp6 [lr5:16]{_near * int}[r0] +
18499 ; goto _whilecontinue_0($1)
18511 ; _whilebreak_0($3) :
18521 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
18533 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
18545 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
18557 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
18576 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
18605 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
18610 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
18655 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
18660 ; iTemp21 [lr21:38]{short}[r4]
18686 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
18719 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
18724 ; iTemp15 [lr29:30]{short}[r1]
18743 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
18790 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
18837 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
18849 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
18863 cjne r5,#0xff,00104$
18875 ; goto _forcond_0($4)
18887 ; _forbreak_0($7) :
18897 ; ret iTemp24 [lr40:41]{short}
18940 A few words about basic block successors, predecessors and dominators
18943 Successors are basic blocks
18944 \begin_inset LatexCommand \index{Basic blocks}
18948 that might execute after this basic block.
18950 Predecessors are basic blocks that might execute before reaching this basic
18953 Dominators are basic blocks that WILL execute before reaching this basic
18987 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
18990 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
18993 c) domVect of [BB4] = BB1 ...
18994 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
19002 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
19012 Thanks to all the other volunteer developers who have helped with coding,
19013 testing, web-page creation, distribution sets, etc.
19014 You know who you are :-)
19021 This document was initially written by Sandeep Dutta
19024 All product names mentioned herein may be trademarks
19025 \begin_inset LatexCommand \index{Trademarks}
19029 of their respective companies.
19036 To avoid confusion, the installation and building options for SDCC itself
19037 (chapter 2) are not part of the index.
19041 \begin_inset LatexCommand \printindex{}