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, manual, mcs51, PIC, small, Z80},
12 linkcolor=blue] {hyperref}
16 \inputencoding default
19 \paperfontsize default
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 SDCC Compiler User Guide
69 The strings enclosed in $ are automatically updated by cvs:
74 cvs: $Revision$ $Date$
78 \begin_inset LatexCommand \tableofcontents{}
95 is a Freeware, retargettable, optimizing ANSI-C compiler by
99 designed for 8 bit Microprocessors.
100 The current version targets Intel MCS51 based Microprocessors (8031, 8032,
102 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052 CPU}
106 , etc), Zilog Z80 based MCUs, and the Dallas DS80C390 variant.
107 It can be retargetted for other microprocessors, support for PIC, AVR and
108 186 is under development.
109 The entire source code for the compiler is distributed under GPL.
110 SDCC uses ASXXXX & ASLINK, a Freeware, retargettable assembler & linker.
111 SDCC has extensive language extensions suitable for utilizing various microcont
112 rollers and underlying hardware effectively.
117 In addition to the MCU specific optimizations SDCC also does a host of standard
121 global sub expression elimination,
124 loop optimizations (loop invariant, strength reduction of induction variables
128 constant folding & propagation,
134 dead code elimination
144 For the back-end SDCC uses a global register allocation scheme which should
145 be well suited for other 8 bit MCUs.
150 The peep hole optimizer uses a rule based substitution mechanism which is
156 Supported data-types are:
159 char (8 bits, 1 byte),
162 short and int (16 bits, 2 bytes),
165 long (32 bit, 4 bytes)
172 The compiler also allows
174 inline assembler code
176 to be embedded anywhere in a function.
177 In addition, routines developed in assembly can also be called.
181 SDCC also provides an option (-
191 -cyclomatic) to report the relative complexity of a function.
192 These functions can then be further optimized, or hand coded in assembly
198 SDCC also comes with a companion source level debugger SDCDB, the debugger
199 currently uses ucSim a freeware simulator for 8051 and other micro-controllers.
204 The latest version can be downloaded from
205 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
215 Please note: the compiler will probably always be some steps ahead of this
220 \begin_inset LatexCommand \index{Status of documentation}
230 Obviously this has pros and cons
239 All packages used in this compiler system are
247 ; source code for all the sub-packages (pre-processor, assemblers, linkers
248 etc) is distributed with the package.
249 This documentation is maintained using a freeware word processor (LyX).
251 This program is free software; you can redistribute it and/or modify it
252 under the terms of the GNU General Public License
253 \begin_inset LatexCommand \index{GNU General Public License, GPL}
257 as published by the Free Software Foundation; either version 2, or (at
258 your option) any later version.
259 This program is distributed in the hope that it will be useful, but WITHOUT
260 ANY WARRANTY; without even the implied warranty
261 \begin_inset LatexCommand \index{warranty}
265 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
266 See the GNU General Public License for more details.
267 You should have received a copy of the GNU General Public License along
268 with this program; if not, write to the Free Software Foundation, 59 Temple
269 Place - Suite 330, Boston, MA 02111-1307, USA.
270 In other words, you are welcome to use, share and improve this program.
271 You are forbidden to forbid anyone else to use, share and improve what
273 Help stamp out software-hoarding!
276 Typographic conventions
277 \begin_inset LatexCommand \index{Typographic conventions}
284 Throughout this manual, we will use the following convention.
285 Commands you have to type in are printed in
293 Code samples are printed in
298 Interesting items and new terms are printed in
303 Compatibility with previous versions
306 This version has numerous bug fixes compared with the previous version.
307 But we also introduced some incompatibilities with older versions.
308 Not just for the fun of it, but to make the compiler more stable, efficient
310 \begin_inset LatexCommand \index{ANSI-compliance}
320 short is now equivalent to int (16 bits), it used to be equivalent to char
321 (8 bits) which is not ANSI compliant
324 the default directory for gcc-builds where include, library and documentation
325 files are stored is now in /usr/local/share
328 char type parameters to vararg functions are casted to int unless explicitly
345 will push a as an int and as a char resp.
358 -regextend has been removed
371 -noregparms has been removed
384 -stack-after-data has been removed
389 <pending: more incompatibilities?>
395 What do you need before you start installation of SDCC? A computer, and
397 The preferred method of installation is to compile SDCC from source using
399 For Windows some pre-compiled binary distributions are available for your
401 You should have some experience with command line tools and compiler use.
407 The SDCC home page at
408 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
412 is a great place to find distribution sets.
413 You can also find links to the user mailing lists that offer help or discuss
414 SDCC with other SDCC users.
415 Web links to other SDCC related sites can also be found here.
416 This document can be found in the DOC directory of the source package as
418 Some of the other tools (simulator and assembler) included with SDCC contain
419 their own documentation and can be found in the source distribution.
420 If you want the latest unreleased software, the complete source package
421 is available directly by anonymous CVS on cvs.sdcc.sourceforge.net.
424 ANSI C reference / related tools / recommended reading / compiler building:
428 Wishes for the future
431 There are (and always will be) some things that could be done.
432 Here are some I can think of:
439 char KernelFunction3(char p) at 0x340;
447 \begin_inset LatexCommand \index{code banking (not supported)}
455 If you can think of some more, please see the chapter 9 about filing feature
457 \begin_inset LatexCommand \index{Requesting features}
462 \begin_inset LatexCommand \index{Feature request}
472 \begin_inset LatexCommand \index{Installation}
480 \begin_inset LatexCommand \index{Options SDCC configuration}
487 The install paths, search paths and other options are defined when running
489 The defaults can be overridden by:
491 \labelwidthstring 00.00.0000
503 -prefix see table below
505 \labelwidthstring 00.00.0000
517 -exec_prefix see table below
519 \labelwidthstring 00.00.0000
531 -bindir see table below
533 \labelwidthstring 00.00.0000
545 -datadir see table below
547 \labelwidthstring 00.00.0000
549 docdir environment variable, see table below
551 \labelwidthstring 00.00.0000
553 include_dir_suffix environment variable, see table below
555 \labelwidthstring 00.00.0000
557 lib_dir_suffix environment variable, see table below
559 \labelwidthstring 00.00.0000
561 sdccconf_h_dir_separator environment variable, either / or
566 This character will only be used in sdccconf.h; don't forget it's a C-header,
567 therefore a double-backslash is needed there.
569 \labelwidthstring 00.00.0000
581 -disable-mcs51-port Excludes the Intel mcs51 port
583 \labelwidthstring 00.00.0000
595 -disable-gbz80-port Excludes the Gameboy gbz80 port
597 \labelwidthstring 00.00.0000
609 -z80-port Excludes the z80 port
611 \labelwidthstring 00.00.0000
623 -disable-avr-port Excludes the AVR port
625 \labelwidthstring 00.00.0000
637 -disable-ds390-port Excludes the DS390 port
639 \labelwidthstring 00.00.0000
651 -disable-pic-port Excludes the PIC port
653 \labelwidthstring 00.00.0000
665 -disable-xa51-port Excludes the XA51 port
667 \labelwidthstring 00.00.0000
679 -disable-ucsim Disables configuring and building of ucsim
681 \labelwidthstring 00.00.0000
693 -disable-device-lib-build Disables automatically building device libraries
695 \labelwidthstring 00.00.0000
707 -disable-packihx Disables building packihx
709 \labelwidthstring 00.00.0000
721 -enable-libgc Use the Bohem memory allocator.
722 Lower runtime footprint.
725 Furthermore the environment variables CC, CFLAGS, ...
726 the tools and their arguments can be influenced.
727 Please see `configure -
737 -help` and the man/info pages of `configure` for details.
741 The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB,
742 STD_FP_LIB, STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_
743 NAME, SDCC_INCLUDE_NAME, SDCC_LIB_NAME are defined by `configure` too.
744 At the moment it's not possible to change the default settings (it was
745 simply never required.
749 These configure options are compiled into the binaries, and can only be
750 changed by rerunning 'configure' and recompiling SDCC.
751 The configure options are written in
755 to distinguish them from run time environment variables (see section search
761 \begin_inset Quotes sld
765 \begin_inset Quotes srd
768 are used by the SDCC team to build the official Win32 binaries.
769 The SDCC team uses Mingw32 to build the official Windows binaries, because
776 a gcc compiler and last but not least
779 the binaries can be built by cross compiling on Sourceforge's compile farm.
782 See the examples, how to pass the Win32 settings to 'configure'.
783 The other Win32 builds using Borland, VC or whatever don't use 'configure',
784 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
796 <lyxtabular version="3" rows="8" columns="3">
798 <column alignment="block" valignment="top" leftline="true" width="0in">
799 <column alignment="block" valignment="top" leftline="true" width="0in">
800 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
801 <row topline="true" bottomline="true">
802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
846 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
878 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
912 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
950 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
984 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1027 <row topline="true" bottomline="true">
1028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1046 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1064 'configure' also computes relative paths.
1065 This is needed for full relocatability of a binary package and to complete
1066 search paths (see section search paths below):
1072 \begin_inset Tabular
1073 <lyxtabular version="3" rows="4" columns="3">
1075 <column alignment="block" valignment="top" leftline="true" width="0in">
1076 <column alignment="block" valignment="top" leftline="true" width="0in">
1077 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1078 <row topline="true" bottomline="true">
1079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1095 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1104 <row topline="true" bottomline="true">
1105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1123 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1134 <row bottomline="true">
1135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1162 <row bottomline="true">
1163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1181 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1214 \begin_inset Quotes srd
1218 \begin_inset Quotes srd
1232 \begin_inset Quotes srd
1236 \begin_inset Quotes srd
1264 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1273 \begin_inset Quotes srd
1276 i586-mingw32msvc-gcc
1277 \begin_inset Quotes srd
1281 \begin_inset Quotes srd
1284 i586-mingw32msvc-g++
1285 \begin_inset Quotes srd
1293 \begin_inset Quotes srd
1296 i586-mingw32msvc-ranlib
1297 \begin_inset Quotes srd
1305 \begin_inset Quotes srd
1308 i586-mingw32msvc-strip
1309 \begin_inset Quotes srd
1327 \begin_inset Quotes srd
1331 \begin_inset Quotes srd
1349 \begin_inset Quotes srd
1353 \begin_inset Quotes srd
1361 \begin_inset Quotes srd
1365 \begin_inset Quotes srd
1373 \begin_inset Quotes srd
1377 \begin_inset Quotes srd
1385 \begin_inset Quotes srd
1389 \begin_inset Quotes srd
1396 sdccconf_h_dir_separator=
1397 \begin_inset Quotes srd
1409 \begin_inset Quotes srd
1426 -disable-device-lib-build
1454 -host=i586-mingw32msvc -
1464 -build=unknown-unknown-linux-gnu
1468 \begin_inset Quotes sld
1472 \begin_inset Quotes srd
1475 compile on Cygwin for Mingw32(see also sdcc/support/scripts/sdcc_cygwin_mingw32)
1484 \begin_inset Quotes srd
1488 \begin_inset Quotes srd
1496 \begin_inset Quotes srd
1500 \begin_inset Quotes srd
1518 \begin_inset Quotes srd
1522 \begin_inset Quotes srd
1540 \begin_inset Quotes srd
1544 \begin_inset Quotes srd
1552 \begin_inset Quotes srd
1556 \begin_inset Quotes srd
1564 \begin_inset Quotes srd
1568 \begin_inset Quotes srd
1576 \begin_inset Quotes srd
1580 \begin_inset Quotes srd
1587 sdccconf_h_dir_separator=
1588 \begin_inset Quotes srd
1600 \begin_inset Quotes srd
1620 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
1631 -C' turns on caching, which gives a little bit extra speed.
1632 However if options are changed, it can be necessary to delete the config.cache
1637 \begin_inset LatexCommand \index{Install paths}
1643 \added_space_top medskip \align center
1645 \begin_inset Tabular
1646 <lyxtabular version="3" rows="5" columns="4">
1648 <column alignment="center" valignment="top" leftline="true" width="0(null)">
1649 <column alignment="center" valignment="top" leftline="true" width="0(null)">
1650 <column alignment="center" valignment="top" leftline="true" width="0(null)">
1651 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
1652 <row topline="true" bottomline="true">
1653 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1683 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1694 <row topline="true">
1695 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1721 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1734 <row topline="true">
1735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1750 $DATADIR/ $INCLUDE_DIR_SUFFIX
1753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1758 /usr/local/share/sdcc/include
1761 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1774 <row topline="true">
1775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1790 $DATADIR/$LIB_DIR_SUFFIX
1793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1798 /usr/local/share/sdcc/lib
1801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1814 <row topline="true" bottomline="true">
1815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1838 /usr/local/share/sdcc/doc
1841 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1863 *compiler, preprocessor, assembler, and linker
1869 is auto-appended by the compiler, e.g.
1870 small, large, z80, ds390 etc
1873 The install paths can still be changed during `make install` with e.g.:
1876 make install prefix=$(HOME)/local/sdcc
1879 Of course this doesn't change the search paths compiled into the binaries.
1883 \begin_inset LatexCommand \index{Search path}
1890 Some search paths or parts of them are determined by configure variables
1895 , see section above).
1896 Further search paths are determined by environment variables during runtime.
1899 The paths searched when running the compiler are as follows (the first catch
1905 Binary files (preprocessor, assembler and linker)
1911 \begin_inset Tabular
1912 <lyxtabular version="3" rows="4" columns="3">
1914 <column alignment="block" valignment="top" leftline="true" width="0in">
1915 <column alignment="block" valignment="top" leftline="true" width="0in">
1916 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1917 <row topline="true" bottomline="true">
1918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1934 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1943 <row topline="true">
1944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1962 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1973 <row topline="true">
1974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1979 Path of argv[0] (if available)
1982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1999 <row topline="true" bottomline="true">
2000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2041 \begin_inset Tabular
2042 <lyxtabular version="3" rows="6" columns="3">
2044 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2045 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2046 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2047 <row topline="true" bottomline="true">
2048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2064 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2073 <row topline="true">
2074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2110 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2129 <row topline="true">
2130 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2146 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2155 <row topline="true">
2156 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2170 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2193 <row topline="true">
2194 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2262 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2275 <row topline="true" bottomline="true">
2276 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2292 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2297 /usr/local/share/sdcc/
2302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2330 -nostdinc disables the last two search paths.
2340 With the exception of
2341 \begin_inset Quotes sld
2355 \begin_inset Quotes srd
2362 is auto-appended by the compiler (e.g.
2363 small, large, z80, ds390 etc.).
2370 \begin_inset Tabular
2371 <lyxtabular version="3" rows="6" columns="3">
2373 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2374 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2375 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2376 <row topline="true" bottomline="true">
2377 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2385 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2402 <row topline="true">
2403 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2439 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2458 <row topline="true">
2459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2471 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2498 <row topline="true">
2499 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2510 $LIB_DIR_SUFFIX/<model>
2513 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2527 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2544 <row topline="true">
2545 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2560 $LIB_DIR_SUFFIX/<model>
2563 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2616 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2672 <row topline="true" bottomline="true">
2673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2682 $LIB_DIR_SUFFIX/<model>
2685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2690 /usr/local/share/sdcc/
2697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2715 Don't delete any of the stray spaces in the table above without checking
2716 the HTML output (last line)!
2732 -nostdlib disables the last two search paths.
2736 \begin_inset LatexCommand \index{Building SDCC}
2741 \layout Subsubsection
2743 Building SDCC on Linux
2748 Download the source package
2750 either from the SDCC CVS repository or from the
2751 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
2757 , it will be named something like sdcc
2770 Bring up a command line terminal, such as xterm.
2775 Unpack the file using a command like:
2778 "tar -xzf sdcc.src.tar.gz
2783 , this will create a sub-directory called sdcc with all of the sources.
2786 Change directory into the main SDCC directory, for example type:
2803 This configures the package for compilation on your system.
2819 All of the source packages will compile, this can take a while.
2835 This copies the binary executables, the include files, the libraries and
2836 the documentation to the install directories.
2837 \layout Subsubsection
2839 Building SDCC on OSX 2.x
2842 Follow the instruction for Linux.
2846 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
2847 )) fails to compile SDCC.
2848 Fortunately there's also gcc 2.9.x installed, which works fine.
2849 This compiler can be selected by running 'configure' with:
2852 ./configure CC=gcc2 CXX=g++2
2853 \layout Subsubsection
2855 Cross compiling SDCC on Linux for Windows
2858 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
2859 See section 'Configure Options'.
2860 \layout Subsubsection
2862 Building SDCC on Windows
2865 With the exception of Cygwin the SDCC binaries uCsim and sdcdb can't be
2867 They use Unix-sockets, which are not available on Win32.
2868 \layout Subsubsection
2870 Windows Install Using a Binary Package
2873 Download the binary package and unpack it using your favorite unpacking
2874 tool (gunzip, WinZip, etc).
2875 This should unpack to a group of sub-directories.
2876 An example directory structure after unpacking the mingw32 package is:
2881 bin for the executables, c:
2889 lib for the include and libraries.
2892 Adjust your environment variable PATH to include the location of the bin
2893 directory or start sdcc using the full path.
2894 \layout Subsubsection
2896 Building SDCC using Cygwin and Mingw32
2899 For building and installing a Cygwin executable follow the instructions
2905 \begin_inset Quotes sld
2909 \begin_inset Quotes srd
2912 Win32-binary can be built, which will not need the Cygwin-DLL.
2913 For the necessary 'configure' options see section 'configure options' or
2914 the script 'sdcc/support/scripts/sdcc_cygwinmingw32'.
2918 In order to install Cygwin on Windows download setup.exe from
2919 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
2925 \begin_inset Quotes sld
2928 default text file type
2929 \begin_inset Quotes srd
2933 \begin_inset Quotes sld
2937 \begin_inset Quotes srd
2940 and download/install at least the following packages.
2941 Some packages are selected by default, others will be automatically selected
2942 because of dependencies with the manually selected packages.
2943 Never deselect these packages!
2952 gcc ; version 3.x is fine, no need to use the old 2.9x
2955 binutils ; selected with gcc
2961 rxvt ; a nice console, which makes life much easier under windoze (see below)
2964 man ; not really needed for building SDCC, but you'll miss it sooner or
2968 less ; not really needed for building SDCC, but you'll miss it sooner or
2972 cvs ; only if you use CVS access
2975 If you want to develop something you'll need:
2978 python ; for the regression tests
2981 gdb ; the gnu debugger, together with the nice GUI
2982 \begin_inset Quotes sld
2986 \begin_inset Quotes srd
2992 openssh ; to access the CF or commit changes
2995 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
2996 use autoconf-stable!
2999 rxvt is a nice console with history.
3000 Replace in your cygwin.bat the line
3019 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3022 -bg black -fg white -geometry 100x65 -e bash -
3035 Text selected with the mouse is automatically copied to the clipboard, pasting
3036 works with shift-insert.
3040 The other good tip is to make sure you have no //c/-style paths anywhere,
3041 use /cygdrive/c/ instead.
3042 Using // invokes a network lookup which is very slow.
3044 \begin_inset Quotes sld
3048 \begin_inset Quotes srd
3051 is too long, you can change it with e.g.
3057 SDCC sources use the unix line ending LF.
3058 Life is much easier, if you store the source tree on a drive, which is
3059 mount in binary mode.
3060 And use an editor which can handle LF-only line endings.
3061 Make sure not to commit files with windows line endings.
3062 \layout Subsubsection
3064 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3069 Download the source package
3071 either from the SDCC CVS repository or from the
3072 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3078 , it will be named something like sdcc
3085 SDCC is distributed with all the projects, workspaces, and files you need
3086 to build it using Visual C++ 6.0/NET (except for sdcdb.exe which currently
3087 doesn't build under MSVC).
3088 The workspace name is 'sdcc.dsw'.
3089 Please note that as it is now, all the executables are created in a folder
3093 Once built you need to copy the executables from sdcc
3097 bin before running SDCC.
3102 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3103 flex.exe, and gawk.exe.
3104 One good place to get them is
3105 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3113 Download the file UnxUtils
3114 \begin_inset LatexCommand \index{UnxUtils}
3119 Now you have to install the utilities and setup MSVC so it can locate the
3121 Here there are two alternatives (choose one!):
3128 a) Extract UnxUtils.zip to your C:
3130 hard disk PRESERVING the original paths, otherwise bison won't work.
3131 (If you are using WinZip make certain that 'Use folder names' is selected)
3135 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3136 in 'Show directories for:' select 'Executable files', and in the directories
3137 window add a new path: 'C:
3147 (As a side effect, you get a bunch of Unix utilities that could be useful,
3148 such as diff and patch.)
3155 This one avoids extracting a bunch of files you may not use, but requires
3160 a) Create a directory were to put the tools needed, or use a directory already
3168 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3169 to such directory WITHOUT preserving the original paths.
3170 (If you are using WinZip make certain that 'Use folder names' is not selected)
3174 c) Rename bison.exe to '_bison.exe'.
3178 d) Create a batch file 'bison.bat' in 'C:
3182 ' and add these lines:
3202 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3206 Steps 'c' and 'd' are needed because bison requires by default that the
3207 files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3208 '/usr/local/share/' I think.
3209 So it is necessary to tell bison where those files are located if they
3210 are not in such directory.
3211 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3215 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3216 in 'Show directories for:' select 'Executable files', and in the directories
3217 window add a new path: 'c:
3220 Note that you can use any other path instead of 'c:
3222 util', even the path where the Visual C++ tools are, probably: 'C:
3226 Microsoft Visual Studio
3231 So you don't have to execute step 'e' :)
3235 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3236 the executables from sdcc
3240 bin, and you can compile using sdcc.
3241 \layout Subsubsection
3243 Building SDCC Using Borland
3246 From the sdcc directory, run the command "make -f Makefile.bcc".
3247 This should regenerate all the .exe files in the bin directory except for
3248 sdcdb.exe (which currently doesn't build under Borland C++).
3251 If you modify any source files and need to rebuild, be aware that the dependenci
3252 es may not be correctly calculated.
3253 The safest option is to delete all .obj files and run the build again.
3254 From a Cygwin BASH prompt, this can easily be done with the command:
3264 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
3266 ) -print -exec rm {}
3275 or on Windows NT/2000/XP from the command prompt with the command:
3282 del /s *.obj *.lib *.rul
3285 from the sdcc directory.
3288 Building the Documentation
3295 Testing out the SDCC Compiler
3298 The first thing you should do after installing your SDCC compiler is to
3314 \begin_inset LatexCommand \index{version}
3321 at the prompt, and the program should run and tell you the version.
3322 If it doesn't run, or gives a message about not finding sdcc program, then
3323 you need to check over your installation.
3324 Make sure that the sdcc bin directory is in your executable search path
3325 defined by the PATH environment setting (see the Trouble-shooting section
3327 Make sure that the sdcc program is in the bin folder, if not perhaps something
3328 did not install correctly.
3336 is commonly installed as described in section
3337 \begin_inset Quotes sld
3340 Install and search paths
3341 \begin_inset Quotes srd
3350 Make sure the compiler works on a very simple example.
3351 Type in the following test.c program using your favorite
3377 Compile this using the following command:
3386 If all goes well, the compiler will generate a test.asm and test.rel file.
3387 Congratulations, you've just compiled your first program with SDCC.
3388 We used the -c option to tell SDCC not to link the generated code, just
3389 to keep things simple for this step.
3397 The next step is to try it with the linker.
3407 If all goes well the compiler will link with the libraries and produce
3408 a test.ihx output file.
3413 (no test.ihx, and the linker generates warnings), then the problem is most
3414 likely that sdcc cannot find the
3418 usr/local/share/sdcc/lib directory
3422 (see the Install trouble-shooting section for suggestions).
3430 The final test is to ensure sdcc can use the
3434 header files and libraries.
3435 Edit test.c and change it to the following:
3452 strcpy(str1, "testing");
3459 Compile this by typing
3466 This should generate a test.ihx output file, and it should give no warnings
3467 such as not finding the string.h file.
3468 If it cannot find the string.h file, then the problem is that sdcc cannot
3469 find the /usr/local/share/sdcc/include directory
3473 (see the Install trouble-shooting section for suggestions).
3491 \begin_inset LatexCommand \index{-\/-print-search-dirs}
3495 to find exactly where SDCC is looking for the include and lib files.
3498 Install Trouble-shooting
3499 \begin_inset LatexCommand \index{Install trouble-shooting}
3504 \layout Subsubsection
3506 SDCC does not build correctly.
3509 A thing to try is starting from scratch by unpacking the .tgz source package
3510 again in an empty directory.
3518 ./configure 2>&1 | tee configure.log
3532 make 2>&1 | tee make.log
3539 If anything goes wrong, you can review the log files to locate the problem.
3540 Or a relevant part of this can be attached to an email that could be helpful
3541 when requesting help from the mailing list.
3542 \layout Subsubsection
3545 \begin_inset Quotes sld
3549 \begin_inset Quotes srd
3556 \begin_inset Quotes sld
3560 \begin_inset Quotes srd
3563 command is a script that analyzes your system and performs some configuration
3564 to ensure the source package compiles on your system.
3565 It will take a few minutes to run, and will compile a few tests to determine
3566 what compiler features are installed.
3567 \layout Subsubsection
3570 \begin_inset Quotes sld
3574 \begin_inset Quotes srd
3580 This runs the GNU make tool, which automatically compiles all the source
3581 packages into the final installed binary executables.
3582 \layout Subsubsection
3585 \begin_inset Quotes sld
3589 \begin_inset Quotes erd
3595 This will install the compiler, other executables libraries and include
3596 files in to the appropriate directories.
3598 \begin_inset Quotes sld
3601 Install and Search PATHS
3602 \begin_inset Quotes srd
3607 On most systems you will need super-user privileges to do this.
3613 SDCC is not just a compiler, but a collection of tools by various developers.
3614 These include linkers, assemblers, simulators and other components.
3615 Here is a summary of some of the components.
3616 Note that the included simulator and assembler have separate documentation
3617 which you can find in the source package in their respective directories.
3618 As SDCC grows to include support for other processors, other packages from
3619 various developers are included and may have their own sets of documentation.
3623 You might want to look at the files which are installed in <installdir>.
3624 At the time of this writing, we find the following programs for gcc-builds:
3628 In <installdir>/bin:
3631 sdcc - The compiler.
3634 sdcpp - The C preprocessor.
3637 asx8051 - The assembler for 8051 type processors.
3644 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
3647 aslink -The linker for 8051 type processors.
3654 link-gbz80 - The Z80 and GameBoy Z80 linkers.
3657 s51 - The ucSim 8051 simulator.
3660 sdcdb - The source debugger.
3663 packihx - A tool to pack (compress) Intel hex files.
3666 In <installdir>/share/sdcc/include
3672 In <installdir>/share/sdcc/lib
3675 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
3679 In <installdir>/share/sdcc/doc
3685 As development for other processors proceeds, this list will expand to include
3686 executables to support processors like AVR, PIC, etc.
3687 \layout Subsubsection
3692 This is the actual compiler, it in turn uses the c-preprocessor and invokes
3693 the assembler and linkage editor.
3694 \layout Subsubsection
3697 \begin_inset LatexCommand \index{sdcpp}
3701 - The C-Preprocessor
3704 The preprocessor is a modified version of the GNU preprocessor.
3705 The C preprocessor is used to pull in #include sources, process #ifdef
3706 statements, #defines and so on.
3707 \layout Subsubsection
3709 asx8051, as-z80, as-gbz80, aslink, link-z80, link-gbz80 - The Assemblers
3713 This is retargettable assembler & linkage editor, it was developed by Alan
3715 John Hartman created the version for 8051, and I (Sandeep) have made some
3716 enhancements and bug fixes for it to work properly with the SDCC.
3717 \layout Subsubsection
3720 \begin_inset LatexCommand \index{s51}
3727 S51 is a freeware, opensource simulator developed by Daniel Drotos (
3728 \begin_inset LatexCommand \url{mailto:drdani@mazsola.iit.uni-miskolc.hu}
3733 The simulator is built as part of the build process.
3734 For more information visit Daniel's web site at:
3735 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
3740 It currently support the core mcs51, the Dallas DS80C390 and the Phillips
3742 \layout Subsubsection
3745 \begin_inset LatexCommand \index{sdcdb}
3749 - Source Level Debugger
3752 Sdcdb is the companion source level debugger.
3753 The current version of the debugger uses Daniel's Simulator S51, but can
3754 be easily changed to use other simulators.
3761 \layout Subsubsection
3763 Single Source File Projects
3766 For single source file 8051 projects the process is very simple.
3767 Compile your programs with the following command
3770 "sdcc sourcefile.c".
3774 This will compile, assemble and link your source file.
3775 Output files are as follows
3779 \begin_inset LatexCommand \index{.asm}
3784 \begin_inset LatexCommand \index{Assembler source}
3788 file created by the compiler
3792 \begin_inset LatexCommand \index{.lst}
3797 \begin_inset LatexCommand \index{Assembler listing}
3801 file created by the Assembler
3805 \begin_inset LatexCommand \index{.rst}
3810 \begin_inset LatexCommand \index{Assembler listing}
3814 file updated with linkedit information, created by linkage editor
3818 \begin_inset LatexCommand \index{.sym}
3823 \begin_inset LatexCommand \index{Symbol listing}
3827 for the sourcefile, created by the assembler
3831 \begin_inset LatexCommand \index{.rel}
3836 \begin_inset LatexCommand \index{Object file}
3840 created by the assembler, input to Linkage editor
3844 \begin_inset LatexCommand \index{.map}
3849 \begin_inset LatexCommand \index{Memory map}
3853 for the load module, created by the Linker
3857 \begin_inset LatexCommand \index{.mem}
3861 - A file with a summary of the memory usage
3865 \begin_inset LatexCommand \index{.ihx}
3869 - The load module in Intel hex format
3870 \begin_inset LatexCommand \index{Intel hex format}
3874 (you can select the Motorola S19 format
3875 \begin_inset LatexCommand \index{Motorola S19 format}
3890 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
3895 If you need another format you might want to use objdump
3896 \begin_inset LatexCommand \index{objdump}
3901 \begin_inset LatexCommand \index{srecord}
3909 \begin_inset LatexCommand \index{.adb}
3913 - An intermediate file containing debug information needed to create the
3925 \begin_inset LatexCommand \index{-\/-debug}
3933 \begin_inset LatexCommand \index{.cdb}
3937 - An optional file (with -
3947 -debug) containing debug information
3952 \begin_inset LatexCommand \index{. (no extension)}
3956 An optional AOMF51 file containing debug information (with -
3970 \begin_inset LatexCommand \index{.dump*}
3974 - Dump file to debug the compiler it self (with -
3984 -dumpall) (see section
3985 \begin_inset Quotes sld
3988 Anatomy of the compiler
3989 \begin_inset Quotes srd
3993 \layout Subsubsection
3995 Projects with Multiple Source Files
3998 SDCC can compile only ONE file at a time.
3999 Let us for example assume that you have a project containing the following
4004 foo1.c (contains some functions)
4006 foo2.c (contains some more functions)
4008 foomain.c (contains more functions and the function main)
4016 The first two files will need to be compiled separately with the commands:
4048 Then compile the source file containing the
4053 \begin_inset LatexCommand \index{Linker}
4057 the files together with the following command:
4065 foomain.c\SpecialChar ~
4066 foo1.rel\SpecialChar ~
4071 \begin_inset LatexCommand \index{.rel}
4083 can be separately compiled as well:
4094 sdcc foomain.rel foo1.rel foo2.rel
4101 The file containing the
4116 file specified in the command line, since the linkage editor processes
4117 file in the order they are presented to it.
4118 The linker is invoked from sdcc using a script file with extension .lnk
4119 \begin_inset LatexCommand \index{.lnk}
4124 You can view this file to troubleshoot linking problems such as those arising
4125 from missing libraries.
4126 \layout Subsubsection
4128 Projects with Additional Libraries
4129 \begin_inset LatexCommand \index{Libraries}
4136 Some reusable routines may be compiled into a library, see the documentation
4137 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
4141 \begin_inset LatexCommand \index{.lib}
4148 Libraries created in this manner can be included in the command line.
4149 Make sure you include the -L <library-path> option to tell the linker where
4150 to look for these files if they are not in the current directory.
4151 Here is an example, assuming you have the source file
4163 (if that is not the same as your current project):
4170 sdcc foomain.c foolib.lib -L mylib
4181 must be an absolute path name.
4185 The most efficient way to use libraries is to keep separate modules in separate
4187 The lib file now should name all the modules.rel
4188 \begin_inset LatexCommand \index{rel}
4193 For an example see the standard library file
4197 in the directory <installdir>/share/lib/small.
4200 Command Line Options
4201 \begin_inset LatexCommand \index{Command Line Options}
4206 \layout Subsubsection
4208 Processor Selection Options
4209 \begin_inset LatexCommand \index{Options processor selection}
4214 \begin_inset LatexCommand \index{Processor selection options}
4220 \labelwidthstring 00.00.0000
4225 \begin_inset LatexCommand \index{-mmcs51}
4231 Generate code for the MCS51
4232 \begin_inset LatexCommand \index{MCS51}
4236 family of processors.
4237 This is the default processor target.
4239 \labelwidthstring 00.00.0000
4244 \begin_inset LatexCommand \index{-mds390}
4250 Generate code for the DS80C390
4251 \begin_inset LatexCommand \index{DS80C390}
4257 \labelwidthstring 00.00.0000
4262 \begin_inset LatexCommand \index{-mds400}
4268 Generate code for the DS80C400
4269 \begin_inset LatexCommand \index{DS80C400}
4275 \labelwidthstring 00.00.0000
4280 \begin_inset LatexCommand \index{-mz80}
4286 Generate code for the Z80
4287 \begin_inset LatexCommand \index{Z80}
4291 family of processors.
4293 \labelwidthstring 00.00.0000
4298 \begin_inset LatexCommand \index{-mgbz80}
4304 Generate code for the GameBoy Z80
4305 \begin_inset LatexCommand \index{GameBoy Z80}
4311 \labelwidthstring 00.00.0000
4316 \begin_inset LatexCommand \index{-mavr}
4322 Generate code for the Atmel AVR
4323 \begin_inset LatexCommand \index{AVR}
4327 processor (In development, not complete).
4328 AVR users should probably have a look at avr-gcc
4329 \begin_inset LatexCommand \url[FIXME: official URL?]{ http://savannah.nongnu.org/download/avr-libc/snapshots/}
4336 I think it is fair to direct users there for now.
4337 Open source is also about avoiding unnecessary work .
4338 But I didn't find the 'official' link.
4340 \labelwidthstring 00.00.0000
4345 \begin_inset LatexCommand \index{-mpic14}
4351 Generate code for the PIC 14
4352 \begin_inset LatexCommand \index{PIC14}
4356 -bit processors (In development, not complete).
4359 p16f627 p16f628 p16f84 p16f873 p16f877?
4361 \labelwidthstring 00.00.0000
4367 Generate code for the Toshiba TLCS-900H
4368 \begin_inset LatexCommand \index{TLCS-900H}
4372 processor (In development, not complete).
4374 \labelwidthstring 00.00.0000
4379 \begin_inset LatexCommand \index{-mxa51}
4385 Generate code for the Phillips XA51
4386 \begin_inset LatexCommand \index{XA51}
4390 processor (In development, not complete).
4391 \layout Subsubsection
4393 Preprocessor Options
4394 \begin_inset LatexCommand \index{Options preprocessor}
4399 \begin_inset LatexCommand \index{Preprocessor options}
4405 \labelwidthstring 00.00.0000
4410 \begin_inset LatexCommand \index{-I<path>}
4416 The additional location where the pre processor will look for <..h> or
4417 \begin_inset Quotes eld
4421 \begin_inset Quotes erd
4426 \labelwidthstring 00.00.0000
4431 \begin_inset LatexCommand \index{-D<macro[=value]>}
4437 Command line definition of macros.
4438 Passed to the pre processor.
4440 \labelwidthstring 00.00.0000
4445 \begin_inset LatexCommand \index{-M}
4451 Tell the preprocessor to output a rule suitable for make describing the
4452 dependencies of each object file.
4453 For each source file, the preprocessor outputs one make-rule whose target
4454 is the object file name for that source file and whose dependencies are
4455 all the files `#include'd in it.
4456 This rule may be a single line or may be continued with `
4458 '-newline if it is long.
4459 The list of rules is printed on standard output instead of the preprocessed
4463 \labelwidthstring 00.00.0000
4468 \begin_inset LatexCommand \index{-C}
4474 Tell the preprocessor not to discard comments.
4475 Used with the `-E' option.
4477 \labelwidthstring 00.00.0000
4482 \begin_inset LatexCommand \index{-MM}
4493 Like `-M' but the output mentions only the user header files included with
4495 \begin_inset Quotes eld
4499 System header files included with `#include <file>' are omitted.
4501 \labelwidthstring 00.00.0000
4506 \begin_inset LatexCommand \index{-Aquestion(answer)}
4512 Assert the answer answer for question, in case it is tested with a preprocessor
4513 conditional such as `#if #question(answer)'.
4514 `-A-' disables the standard assertions that normally describe the target
4517 \labelwidthstring 00.00.0000
4523 (answer) Assert the answer answer for question, in case it is tested with
4524 a preprocessor conditional such as `#if #question(answer)'.
4525 `-A-' disables the standard assertions that normally describe the target
4528 \labelwidthstring 00.00.0000
4533 \begin_inset LatexCommand \index{-Umacro}
4539 Undefine macro macro.
4540 `-U' options are evaluated after all `-D' options, but before any `-include'
4541 and `-imacros' options.
4543 \labelwidthstring 00.00.0000
4548 \begin_inset LatexCommand \index{-dM}
4554 Tell the preprocessor to output only a list of the macro definitions that
4555 are in effect at the end of preprocessing.
4556 Used with the `-E' option.
4558 \labelwidthstring 00.00.0000
4563 \begin_inset LatexCommand \index{-dD}
4569 Tell the preprocessor to pass all macro definitions into the output, in
4570 their proper sequence in the rest of the output.
4572 \labelwidthstring 00.00.0000
4577 \begin_inset LatexCommand \index{-dN}
4588 Like `-dD' except that the macro arguments and contents are omitted.
4589 Only `#define name' is included in the output.
4590 \layout Subsubsection
4593 \begin_inset LatexCommand \index{Options linker}
4598 \begin_inset LatexCommand \index{Linker options}
4604 \labelwidthstring 00.00.0000
4624 \begin_inset LatexCommand \index{-\/-lib-path}
4629 \begin_inset LatexCommand \index{-L -\/-lib-path}
4638 <absolute path to additional libraries> This option is passed to the linkage
4639 editor's additional libraries
4640 \begin_inset LatexCommand \index{Libraries}
4645 The path name must be absolute.
4646 Additional library files may be specified in the command line.
4647 See section Compiling programs for more details.
4649 \labelwidthstring 00.00.0000
4666 \begin_inset LatexCommand \index{-\/-xram-loc}
4670 <Value> The start location of the external ram
4671 \begin_inset LatexCommand \index{xdata}
4675 , default value is 0.
4676 The value entered can be in Hexadecimal or Decimal format, e.g.: -
4686 -xram-loc 0x8000 or -
4698 \labelwidthstring 00.00.0000
4715 \begin_inset LatexCommand \index{-\/-code-loc}
4719 <Value> The start location of the code
4720 \begin_inset LatexCommand \index{code}
4724 segment, default value 0.
4725 Note when this option is used the interrupt vector table is also relocated
4726 to the given address.
4727 The value entered can be in Hexadecimal or Decimal format, e.g.: -
4737 -code-loc 0x8000 or -
4749 \labelwidthstring 00.00.0000
4766 \begin_inset LatexCommand \index{-\/-stack-loc}
4770 <Value> By default the stack
4771 \begin_inset LatexCommand \index{stack}
4775 is placed after the data segment.
4776 Using this option the stack can be placed anywhere in the internal memory
4778 The value entered can be in Hexadecimal or Decimal format, e.g.
4789 -stack-loc 0x20 or -
4800 Since the sp register is incremented before a push or call, the initial
4801 sp will be set to one byte prior the provided value.
4802 The provided value should not overlap any other memory areas such as used
4803 register banks or the data segment and with enough space for the current
4806 \labelwidthstring 00.00.0000
4823 \begin_inset LatexCommand \index{-\/-data-loc}
4827 <Value> The start location of the internal ram data
4828 \begin_inset LatexCommand \index{data}
4833 The value entered can be in Hexadecimal or Decimal format, eg.
4855 (By default, the start location of the internal ram data segment is set
4856 as low as possible in memory, taking into account the used register banks
4857 and the bit segment at address 0x20.
4858 For example if register banks 0 and 1 are used without bit variables, the
4859 data segment will be set, if -
4869 -data-loc is not used, to location 0x10.)
4871 \labelwidthstring 00.00.0000
4888 \begin_inset LatexCommand \index{-\/-idata-loc}
4892 <Value> The start location of the indirectly addressable internal ram
4893 \begin_inset LatexCommand \index{idata}
4897 , default value is 0x80.
4898 The value entered can be in Hexadecimal or Decimal format, eg.
4909 -idata-loc 0x88 or -
4921 \labelwidthstring 00.00.0000
4936 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
4945 The linker output (final object code) is in Intel Hex format.
4946 \begin_inset LatexCommand \index{Intel hex format}
4950 (This is the default option).
4952 \labelwidthstring 00.00.0000
4967 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
4976 The linker output (final object code) is in Motorola S19 format
4977 \begin_inset LatexCommand \index{Motorola S19 format}
4982 \layout Subsubsection
4985 \begin_inset LatexCommand \index{Options MCS51}
4990 \begin_inset LatexCommand \index{MCS51 options}
4996 \labelwidthstring 00.00.0000
5011 \begin_inset LatexCommand \index{-\/-model-large}
5017 Generate code for Large model programs see section Memory Models for more
5019 If this option is used all source files in the project should be compiled
5021 In addition the standard library routines are compiled with small model,
5022 they will need to be recompiled.
5024 \labelwidthstring 00.00.0000
5039 \begin_inset LatexCommand \index{-\/-model-small}
5050 Generate code for Small Model programs see section Memory Models for more
5052 This is the default model.
5053 \layout Subsubsection
5056 \begin_inset LatexCommand \index{Options DS390}
5061 \begin_inset LatexCommand \index{DS390 options}
5067 \labelwidthstring 00.00.0000
5084 \begin_inset LatexCommand \index{-\/-model-flat24}
5094 Generate 24-bit flat mode code.
5095 This is the one and only that the ds390 code generator supports right now
5096 and is default when using
5101 See section Memory Models for more details.
5103 \labelwidthstring 00.00.0000
5120 \begin_inset LatexCommand \index{-\/-stack-10bit}
5124 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
5125 This is the one and only that the ds390 code generator supports right now
5126 and is default when using
5131 In this mode, the stack is located in the lower 1K of the internal RAM,
5132 which is mapped to 0x400000.
5133 Note that the support is incomplete, since it still uses a single byte
5134 as the stack pointer.
5135 This means that only the lower 256 bytes of the potential 1K stack space
5136 will actually be used.
5137 However, this does allow you to reclaim the precious 256 bytes of low RAM
5138 for use for the DATA and IDATA segments.
5139 The compiler will not generate any code to put the processor into 10 bit
5141 It is important to ensure that the processor is in this mode before calling
5142 any re-entrant functions compiled with this option.
5143 In principle, this should work with the
5156 \begin_inset LatexCommand \index{-\/-stack-auto}
5162 option, but that has not been tested.
5163 It is incompatible with the
5176 \begin_inset LatexCommand \index{-\/-xstack}
5183 It also only makes sense if the processor is in 24 bit contiguous addressing
5196 -model-flat24 option
5199 \layout Subsubsection
5201 Optimization Options
5202 \begin_inset LatexCommand \index{Options optimization}
5207 \begin_inset LatexCommand \index{Optimization options}
5213 \labelwidthstring 00.00.0000
5228 \begin_inset LatexCommand \index{-\/-nogcse}
5234 Will not do global subexpression elimination, this option may be used when
5235 the compiler creates undesirably large stack/data spaces to store compiler
5237 A warning message will be generated when this happens and the compiler
5238 will indicate the number of extra bytes it allocated.
5239 It recommended that this option NOT be used, #pragma\SpecialChar ~
5241 \begin_inset LatexCommand \index{\#pragma NOGCSE}
5245 can be used to turn off global subexpression elimination
5246 \begin_inset LatexCommand \index{Subexpression elimination}
5250 for a given function only.
5252 \labelwidthstring 00.00.0000
5267 \begin_inset LatexCommand \index{-\/-noinvariant}
5273 Will not do loop invariant optimizations, this may be turned off for reasons
5274 explained for the previous option.
5275 For more details of loop optimizations performed see section Loop Invariants.It
5276 recommended that this option NOT be used, #pragma\SpecialChar ~
5278 \begin_inset LatexCommand \index{\#pragma NOINVARIANT}
5282 can be used to turn off invariant optimizations for a given function only.
5284 \labelwidthstring 00.00.0000
5299 \begin_inset LatexCommand \index{-\/-noinduction}
5305 Will not do loop induction optimizations, see section strength reduction
5306 for more details.It is recommended that this option is NOT used, #pragma\SpecialChar ~
5309 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
5313 can be used to turn off induction optimizations for a given function only.
5315 \labelwidthstring 00.00.0000
5330 \begin_inset LatexCommand \index{-\/-nojtbound}
5341 Will not generate boundary condition check when switch statements
5342 \begin_inset LatexCommand \index{switch statement}
5346 are implemented using jump-tables.
5347 See section Switch Statements for more details.
5348 It is recommended that this option is NOT used, #pragma\SpecialChar ~
5350 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
5354 can be used to turn off boundary checking for jump tables for a given function
5357 \labelwidthstring 00.00.0000
5372 \begin_inset LatexCommand \index{-\/-noloopreverse}
5381 Will not do loop reversal
5382 \begin_inset LatexCommand \index{Loop reversing}
5388 \labelwidthstring 00.00.0000
5405 \begin_inset LatexCommand \index{-\/-nolabelopt }
5409 Will not optimize labels (makes the dumpfiles more readable).
5411 \labelwidthstring 00.00.0000
5426 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
5432 Will not memcpy initialized data in far space from code space.
5433 This saves a few bytes in code space if you don't have initialized data.
5434 \layout Subsubsection
5437 \begin_inset LatexCommand \index{Options other}
5443 \labelwidthstring 00.00.0000
5459 \begin_inset LatexCommand \index{-\/-compile-only}
5464 \begin_inset LatexCommand \index{-c -\/-compile-only}
5470 will compile and assemble the source, but will not call the linkage editor.
5472 \labelwidthstring 00.00.0000
5491 \begin_inset LatexCommand \index{-\/-c1mode}
5497 reads the preprocessed source from standard input and compiles it.
5498 The file name for the assembler output must be specified using the -o option.
5500 \labelwidthstring 00.00.0000
5505 \begin_inset LatexCommand \index{-E}
5511 Run only the C preprocessor.
5512 Preprocess all the C source files specified and output the results to standard
5515 \labelwidthstring 00.00.0000
5521 \begin_inset LatexCommand \index{-o <path/file>}
5527 The output path resp.
5528 file where everything will be placed.
5529 If the parameter is a path, it must have a trailing slash (or backslash
5530 for the Windows binaries) to be recognized as a path.
5533 \labelwidthstring 00.00.0000
5548 \begin_inset LatexCommand \index{-\/-stack-auto}
5559 All functions in the source file will be compiled as
5564 \begin_inset LatexCommand \index{reentrant}
5569 the parameters and local variables will be allocated on the stack
5570 \begin_inset LatexCommand \index{stack}
5575 see section Parameters and Local Variables for more details.
5576 If this option is used all source files in the project should be compiled
5580 \labelwidthstring 00.00.0000
5595 \begin_inset LatexCommand \index{-\/-xstack}
5601 Uses a pseudo stack in the first 256 bytes in the external ram for allocating
5602 variables and passing parameters.
5603 See section on external stack for more details.
5605 \labelwidthstring 00.00.0000
5620 \begin_inset LatexCommand \index{-\/-callee-saves}
5625 \begin_inset LatexCommand \index{function prologue}
5629 function1[,function2][,function3]....
5632 The compiler by default uses a caller saves convention for register saving
5633 across function calls, however this can cause unnecessary register pushing
5634 & popping when calling small functions from larger functions.
5635 This option can be used to switch the register saving convention for the
5636 function names specified.
5637 The compiler will not save registers when calling these functions, no extra
5638 code will be generated at the entry & exit for these functions to save
5639 & restore the registers used by these functions, this can SUBSTANTIALLY
5640 reduce code & improve run time performance of the generated code.
5641 In the future the compiler (with inter procedural analysis) will be able
5642 to determine the appropriate scheme to use for each function call.
5643 DO NOT use this option for built-in functions such as _mulint..., if this
5644 option is used for a library function the appropriate library function
5645 needs to be recompiled with the same option.
5646 If the project consists of multiple source files then all the source file
5647 should be compiled with the same -
5657 -callee-saves option string.
5658 Also see #pragma\SpecialChar ~
5660 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
5666 \labelwidthstring 00.00.0000
5681 \begin_inset LatexCommand \index{-\/-debug}
5690 When this option is used the compiler will generate debug information, that
5691 can be used with the SDCDB.
5692 The debug information is collected in a file with .cdb extension.
5693 For more information see documentation for SDCDB.
5695 \labelwidthstring 00.00.0000
5712 \begin_inset LatexCommand \index{-\/-peep-file}
5716 <filename> This option can be used to use additional rules to be used by
5717 the peep hole optimizer.
5718 See section Peep Hole optimizations for details on how to write these rules.
5720 \labelwidthstring 00.00.0000
5725 \begin_inset LatexCommand \index{-S}
5736 Stop after the stage of compilation proper; do not assemble.
5737 The output is an assembler code file for the input file specified.
5739 \labelwidthstring 00.00.0000
5743 -Wa_asmOption[,asmOption]
5746 \begin_inset LatexCommand \index{-Wa\_asmOption[,asmOption]}
5751 Pass the asmOption to the assembler.
5753 \labelwidthstring 00.00.0000
5757 -Wl_linkOption[,linkOption]
5760 \begin_inset LatexCommand \index{-Wl\_linkOption[,linkOption]}
5765 Pass the linkOption to the linker.
5767 \labelwidthstring 00.00.0000
5782 \begin_inset LatexCommand \index{-\/-int-long-reent}
5788 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
5789 Note by default these libraries are compiled as non-reentrant.
5790 See section Installation for more details.
5792 \labelwidthstring 00.00.0000
5807 \begin_inset LatexCommand \index{-\/-cyclomatic}
5816 This option will cause the compiler to generate an information message for
5817 each function in the source file.
5818 The message contains some
5822 information about the function.
5823 The number of edges and nodes the compiler detected in the control flow
5824 graph of the function, and most importantly the
5826 cyclomatic complexity
5827 \begin_inset LatexCommand \index{Cyclomatic complexity}
5833 see section on Cyclomatic Complexity for more details.
5835 \labelwidthstring 00.00.0000
5850 \begin_inset LatexCommand \index{-\/-float-reent}
5859 Floating point library is compiled as reentrant
5860 \begin_inset LatexCommand \index{reentrant}
5864 .See section Installation for more details.
5866 \labelwidthstring 00.00.0000
5881 \begin_inset LatexCommand \index{-\/-nooverlay}
5887 The compiler will not overlay parameters and local variables of any function,
5888 see section Parameters and local variables for more details.
5890 \labelwidthstring 00.00.0000
5905 \begin_inset LatexCommand \index{-\/-main-return}
5911 This option can be used when the code generated is called by a monitor
5913 The compiler will generate a 'ret' upon return from the 'main'
5914 \begin_inset LatexCommand \index{main return}
5919 The default option is to lock up i.e.
5922 \labelwidthstring 00.00.0000
5937 \begin_inset LatexCommand \index{-\/-no-peep}
5943 Disable peep-hole optimization.
5945 \labelwidthstring 00.00.0000
5960 \begin_inset LatexCommand \index{-\/-peep-asm}
5966 Pass the inline assembler code through the peep hole optimizer.
5967 This can cause unexpected changes to inline assembler code, please go through
5968 the peephole optimizer
5969 \begin_inset LatexCommand \index{Peephole optimizer}
5973 rules defined in the source file tree '<target>/peeph.def' before using
5976 \labelwidthstring 00.00.0000
5993 \begin_inset LatexCommand \index{-\/-iram-size<Value>}
5997 Causes the linker to check if the internal ram usage is within limits of
6000 \labelwidthstring 00.00.0000
6017 \begin_inset LatexCommand \index{-\/-xram-size<Value>}
6021 Causes the linker to check if the external ram usage is within limits of
6024 \labelwidthstring 00.00.0000
6041 \begin_inset LatexCommand \index{-\/-code-size<Value>}
6045 Causes the linker to check if the code usage is within limits of the given
6048 \labelwidthstring 00.00.0000
6063 \begin_inset LatexCommand \index{-\/-nostdincl}
6069 This will prevent the compiler from passing on the default include path
6070 to the preprocessor.
6072 \labelwidthstring 00.00.0000
6087 \begin_inset LatexCommand \index{-\/-nostdlib}
6093 This will prevent the compiler from passing on the default library
6094 \begin_inset LatexCommand \index{Libraries}
6100 \labelwidthstring 00.00.0000
6115 \begin_inset LatexCommand \index{-\/-verbose}
6121 Shows the various actions the compiler is performing.
6123 \labelwidthstring 00.00.0000
6128 \begin_inset LatexCommand \index{-V}
6134 Shows the actual commands the compiler is executing.
6136 \labelwidthstring 00.00.0000
6151 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
6157 Hides your ugly and inefficient c-code from the asm file, so you can always
6158 blame the compiler :).
6160 \labelwidthstring 00.00.0000
6175 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
6181 Include i-codes in the asm file.
6182 Sounds like noise but is most helpful for debugging the compiler itself.
6184 \labelwidthstring 00.00.0000
6199 \begin_inset LatexCommand \index{-\/-less-pedantic}
6205 Disable some of the more pedantic warnings (jwk burps: please be more specific
6208 \labelwidthstring 00.00.0000
6223 \begin_inset LatexCommand \index{-\/-print-search-dirs}
6229 Display the directories in the compiler's search path
6231 \labelwidthstring 00.00.0000
6246 \begin_inset LatexCommand \index{-\/-vc}
6252 Display the errors and warnings using MSVC style, so you can use SDCC with
6254 \layout Subsubsection
6256 Intermediate Dump Options
6257 \begin_inset LatexCommand \index{Options intermediate dump}
6262 \begin_inset LatexCommand \index{Intermediate dump options}
6269 The following options are provided for the purpose of retargetting and debugging
6271 These provided a means to dump the intermediate code (iCode
6272 \begin_inset LatexCommand \index{iCode}
6276 ) generated by the compiler in human readable form at various stages of
6277 the compilation process.
6280 \labelwidthstring 00.00.0000
6295 \begin_inset LatexCommand \index{-\/-dumpraw}
6301 This option will cause the compiler to dump the intermediate code into
6304 <source filename>.dumpraw
6306 just after the intermediate code has been generated for a function, i.e.
6307 before any optimizations are done.
6309 \begin_inset LatexCommand \index{Basic blocks}
6313 at this stage ordered in the depth first number, so they may not be in
6314 sequence of execution.
6316 \labelwidthstring 00.00.0000
6331 \begin_inset LatexCommand \index{-\/-dumpgcse}
6337 Will create a dump of iCode's, after global subexpression elimination
6338 \begin_inset LatexCommand \index{Global subexpression elimination}
6344 <source filename>.dumpgcse.
6346 \labelwidthstring 00.00.0000
6361 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
6367 Will create a dump of iCode's, after deadcode elimination
6368 \begin_inset LatexCommand \index{Dead-code elimination}
6374 <source filename>.dumpdeadcode.
6376 \labelwidthstring 00.00.0000
6391 \begin_inset LatexCommand \index{-\/-dumploop}
6400 Will create a dump of iCode's, after loop optimizations
6401 \begin_inset LatexCommand \index{Loop optimization}
6407 <source filename>.dumploop.
6409 \labelwidthstring 00.00.0000
6424 \begin_inset LatexCommand \index{-\/-dumprange}
6433 Will create a dump of iCode's, after live range analysis
6434 \begin_inset LatexCommand \index{Live range analysis}
6440 <source filename>.dumprange.
6442 \labelwidthstring 00.00.0000
6457 \begin_inset LatexCommand \index{-\/-dumlrange}
6463 Will dump the life ranges
6464 \begin_inset LatexCommand \index{Live range analysis}
6470 \labelwidthstring 00.00.0000
6485 \begin_inset LatexCommand \index{-\/-dumpregassign}
6494 Will create a dump of iCode's, after register assignment
6495 \begin_inset LatexCommand \index{Register assignment}
6501 <source filename>.dumprassgn.
6503 \labelwidthstring 00.00.0000
6518 \begin_inset LatexCommand \index{-\/-dumplrange}
6524 Will create a dump of the live ranges of iTemp's
6526 \labelwidthstring 00.00.0000
6541 \begin_inset LatexCommand \index{-\/-dumpall}
6552 Will cause all the above mentioned dumps to be created.
6555 Environment variables
6556 \begin_inset LatexCommand \index{Environment variables}
6563 SDCC recognizes the following environment variables:
6565 \labelwidthstring 00.00.0000
6570 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
6576 SDCC installs a signal handler
6577 \begin_inset LatexCommand \index{signal handler}
6581 to be able to delete temporary files after an user break (^C) or an exception.
6582 If this environment variable is set, SDCC won't install the signal handler
6583 in order to be able to debug SDCC.
6585 \labelwidthstring 00.00.0000
6590 \begin_inset LatexCommand \index{TMP}
6596 \begin_inset LatexCommand \index{TEMP}
6602 \begin_inset LatexCommand \index{TMPDIR}
6608 Path, where temporary files will be created.
6609 The order of the variables is the search order.
6610 In a standard *nix environment these variables are not set, and there's
6611 no need to set them.
6612 On Windows it's recommended to set one of them.
6614 \labelwidthstring 00.00.0000
6619 \begin_inset LatexCommand \index{SDCC\_HOME}
6626 \begin_inset Quotes sld
6629 2.3 Install and search paths
6630 \begin_inset Quotes srd
6635 \labelwidthstring 00.00.0000
6640 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
6647 \begin_inset Quotes sld
6650 2.3 Install and search paths
6651 \begin_inset Quotes srd
6656 \labelwidthstring 00.00.0000
6661 \begin_inset LatexCommand \index{SDCC\_LIB}
6668 \begin_inset Quotes sld
6671 2.3 Install and search paths
6672 \begin_inset Quotes srd
6678 There are some more environment variables recognized by SDCC, but these
6679 are solely used for debugging purposes.
6680 They can change or disappear very quickly, and will never be documented.
6683 MCS51/DS390 Storage Class
6684 \begin_inset LatexCommand \index{Storage class}
6691 In addition to the ANSI storage classes SDCC allows the following MCS51
6692 specific storage classes.
6693 \layout Subsubsection
6696 \begin_inset LatexCommand \index{xdata}
6703 Variables declared with this storage class will be placed in the extern
6709 storage class for Large Memory model, e.g.:
6714 xdata unsigned char xduc;
6715 \layout Subsubsection
6718 \begin_inset LatexCommand \index{data}
6729 storage class for Small Memory model.
6730 Variables declared with this storage class will be allocated in the internal
6737 \layout Subsubsection
6740 \begin_inset LatexCommand \index{idata}
6747 Variables declared with this storage class will be allocated into the indirectly
6748 addressable portion of the internal ram of a 8051, e.g.:
6754 \layout Subsubsection
6757 \begin_inset LatexCommand \index{bit}
6764 This is a data-type and a storage class specifier.
6765 When a variable is declared as a bit, it is allocated into the bit addressable
6766 memory of 8051, e.g.:
6772 \layout Subsubsection
6775 \begin_inset LatexCommand \index{sfr}
6780 \begin_inset LatexCommand \index{sbit}
6787 Like the bit keyword,
6791 signifies both a data-type and storage class, they are used to describe
6792 the special function registers and special bit variables of a 8051, eg:
6797 sfr at 0x80 P0; /* special function register P0 at location 0x80 */
6799 sbit at 0xd7 CY; /* CY (Carry Flag
6800 \begin_inset LatexCommand \index{Flags}
6805 \begin_inset LatexCommand \index{Carry flag}
6813 \begin_inset LatexCommand \index{Pointers}
6820 SDCC allows (via language extensions) pointers to explicitly point to any
6821 of the memory spaces
6822 \begin_inset LatexCommand \index{Memory model}
6827 In addition to the explicit pointers, the compiler uses (by default) generic
6828 pointers which can be used to point to any of the memory spaces.
6832 Pointer declaration examples:
6837 /* pointer physically in xternal ram pointing to object in internal ram
6840 data unsigned char * xdata p;
6844 /* pointer physically in code rom pointing to data in xdata space */
6846 xdata unsigned char * code p;
6850 /* pointer physically in code space pointing to data in code space */
6852 code unsigned char * code p;
6856 /* the following is a generic pointer physically located in xdata space
6862 Well you get the idea.
6867 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
6880 The highest order byte of the
6884 pointers contains the data space information.
6885 Assembler support routines are called whenever data is stored or retrieved
6891 These are useful for developing reusable library
6892 \begin_inset LatexCommand \index{Libraries}
6897 Explicitly specifying the pointer type will generate the most efficient
6902 \begin_inset LatexCommand \index{Parameters}
6907 \begin_inset LatexCommand \index{Local variable}
6914 Automatic (local) variables and parameters to functions can either be placed
6915 on the stack or in data-space.
6916 The default action of the compiler is to place these variables in the internal
6917 RAM (for small model) or external RAM (for large model).
6918 This in fact makes them
6921 \begin_inset LatexCommand \index{static}
6927 so by default functions are non-reentrant
6928 \begin_inset LatexCommand \index{reentrant}
6936 They can be placed on the stack
6937 \begin_inset LatexCommand \index{stack}
6954 \begin_inset LatexCommand \index{-\/-stack-auto}
6960 option or by using the
6963 \begin_inset LatexCommand \index{reentrant}
6969 keyword in the function declaration, e.g.:
6974 unsigned char foo(char i) reentrant
6984 Since stack space on 8051 is limited, the
7002 option should be used sparingly.
7003 Note that the reentrant keyword just means that the parameters & local
7004 variables will be allocated to the stack, it
7008 mean that the function is register bank independent.
7012 Local variables can be assigned storage classes and absolute
7013 \begin_inset LatexCommand \index{Absolute addressing}
7022 unsigned char foo() {
7028 xdata unsigned char i;
7040 data at 0x31 unsigned char j;
7052 In the above example the variable
7056 will be allocated in the external ram,
7060 in bit addressable space and
7079 or when a function is declared as
7083 this should only be done for static variables.
7086 Parameters however are not allowed any storage class, (storage classes for
7087 parameters will be ignored), their allocation is governed by the memory
7088 model in use, and the reentrancy options.
7092 \begin_inset LatexCommand \index{Overlaying}
7100 \begin_inset LatexCommand \index{reentrant}
7104 functions SDCC will try to reduce internal ram space usage by overlaying
7105 parameters and local variables of a function (if possible).
7106 Parameters and local variables of a function will be allocated to an overlayabl
7107 e segment if the function has
7109 no other function calls and the function is non-reentrant and the memory
7111 \begin_inset LatexCommand \index{Memory model}
7118 If an explicit storage class
7119 \begin_inset LatexCommand \index{Storage class}
7123 is specified for a local variable, it will NOT be overlayed.
7126 Note that the compiler (not the linkage editor) makes the decision for overlayin
7128 Functions that are called from an interrupt service routine should be preceded
7129 by a #pragma\SpecialChar ~
7131 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
7135 if they are not reentrant.
7138 Also note that the compiler does not do any processing of inline
7139 \begin_inset LatexCommand \index{inline}
7143 assembler code, so the compiler might incorrectly assign local variables
7144 and parameters of a function into the overlay segment if the inline assembler
7145 code calls other c-functions that might use the overlay.
7146 In that case the #pragma\SpecialChar ~
7147 NOOVERLAY should be used.
7150 Parameters and Local variables of functions that contain 16 or 32 bit multiplica
7152 \begin_inset LatexCommand \index{Multiplication}
7157 \begin_inset LatexCommand \index{Division}
7161 will NOT be overlayed since these are implemented using external functions,
7170 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
7176 void set_error(unsigned char errcd)
7192 void some_isr () interrupt
7193 \begin_inset LatexCommand \index{interrupt}
7198 \begin_inset LatexCommand \index{using}
7228 In the above example the parameter
7236 would be assigned to the overlayable segment if the #pragma\SpecialChar ~
7238 not present, this could cause unpredictable runtime behavior when called
7240 The #pragma\SpecialChar ~
7241 NOOVERLAY ensures that the parameters and local variables for
7242 the function are NOT overlayed.
7245 Interrupt Service Routines
7248 SDCC allows interrupt service routines to be coded in C, with some extended
7254 void timer_isr (void) interrupt 2 using 1
7264 The number following the
7267 \begin_inset LatexCommand \index{interrupt}
7273 keyword is the interrupt number this routine will service.
7274 The compiler will insert a call to this routine in the interrupt vector
7275 table for the interrupt number specified.
7280 keyword is used to tell the compiler to use the specified register bank
7281 (8051 specific) when generating code for this function.
7282 Note that when some function is called from an interrupt service routine
7283 it should be preceded by a #pragma\SpecialChar ~
7285 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
7289 if it is not reentrant.
7290 A special note here, int (16 bit) and long (32 bit) integer division
7291 \begin_inset LatexCommand \index{Division}
7296 \begin_inset LatexCommand \index{Multiplication}
7301 \begin_inset LatexCommand \index{Modulus}
7305 operations are implemented using external support routines developed in
7306 ANSI-C, if an interrupt service routine needs to do any of these operations
7307 then the support routines (as mentioned in a following section) will have
7308 to be recompiled using the
7321 \begin_inset LatexCommand \index{-\/-stack-auto}
7327 option and the source file will need to be compiled using the
7342 \begin_inset LatexCommand \index{-\/-int-long-rent}
7349 If you have multiple source files in your project, interrupt service routines
7350 can be present in any of them, but a prototype of the isr MUST be present
7351 or included in the file that contains the function
7358 Interrupt Numbers and the corresponding address & descriptions for the Standard
7359 8051 are listed below.
7360 SDCC will automatically adjust the interrupt vector table to the maximum
7361 interrupt number specified.
7367 \begin_inset Tabular
7368 <lyxtabular version="3" rows="6" columns="3">
7370 <column alignment="center" valignment="top" leftline="true" width="0in">
7371 <column alignment="center" valignment="top" leftline="true" width="0in">
7372 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0in">
7373 <row topline="true" bottomline="true">
7374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7390 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7399 <row topline="true">
7400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7416 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7425 <row topline="true">
7426 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7442 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7451 <row topline="true">
7452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7460 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7468 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7477 <row topline="true">
7478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7494 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7503 <row topline="true" bottomline="true">
7504 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7512 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7520 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7538 If the interrupt service routine is defined without
7541 \begin_inset LatexCommand \index{using}
7547 a register bank or with register bank 0 (using 0), the compiler will save
7548 the registers used by itself on the stack upon entry and restore them at
7549 exit, however if such an interrupt service routine calls another function
7550 then the entire register bank will be saved on the stack.
7551 This scheme may be advantageous for small interrupt service routines which
7552 have low register usage.
7555 If the interrupt service routine is defined to be using a specific register
7560 are save and restored, if such an interrupt service routine calls another
7561 function (using another register bank) then the entire register bank of
7562 the called function will be saved on the stack.
7563 This scheme is recommended for larger interrupt service routines.
7566 Calling other functions from an interrupt service routine is not recommended,
7567 avoid it if possible.
7571 Also see the _naked modifier.
7579 <TODO: this isn't implemented at all!>
7585 A special keyword may be associated with a function declaring it as
7590 SDCC will generate code to disable all interrupts upon entry to a critical
7591 function and enable them back before returning.
7592 Note that nesting critical functions may cause unpredictable results.
7610 The critical attribute maybe used with other attributes like
7616 \begin_inset LatexCommand \index{Naked functions}
7623 A special keyword may be associated with a function declaring it as
7626 \begin_inset LatexCommand \index{\_naked}
7637 function modifier attribute prevents the compiler from generating prologue
7638 \begin_inset LatexCommand \index{function prologue}
7643 \begin_inset LatexCommand \index{function epilogue}
7647 code for that function.
7648 This means that the user is entirely responsible for such things as saving
7649 any registers that may need to be preserved, selecting the proper register
7650 bank, generating the
7654 instruction at the end, etc.
7655 Practically, this means that the contents of the function must be written
7656 in inline assembler.
7657 This is particularly useful for interrupt functions, which can have a large
7658 (and often unnecessary) prologue/epilogue.
7659 For example, compare the code generated by these two functions:
7664 data unsigned char counter;
7666 void simpleInterrupt(void) interrupt
7667 \begin_inset LatexCommand \index{interrupt}
7685 void nakedInterrupt(void) interrupt 2 _naked
7694 \begin_inset LatexCommand \index{\_asm}
7723 ; MUST explicitly include ret in _naked function.
7730 \begin_inset LatexCommand \index{\_endasm}
7739 For an 8051 target, the generated simpleInterrupt looks like:
7880 whereas nakedInterrupt looks like:
7904 ; MUST explicitly include ret(i) in _naked function.
7907 While there is nothing preventing you from writing C code inside a _naked
7908 function, there are many ways to shoot yourself in the foot doing this,
7909 and it is recommended that you stick to inline assembler.
7912 Functions using private banks
7913 \begin_inset LatexCommand \index{bank}
7923 \begin_inset LatexCommand \index{using}
7929 attribute (which tells the compiler to use a register bank other than the
7930 default bank zero) should only be applied to
7933 \begin_inset LatexCommand \index{interrupt}
7939 functions (see note 1 below).
7940 This will in most circumstances make the generated ISR code more efficient
7941 since it will not have to save registers on the stack.
7948 attribute will have no effect on the generated code for a
7952 function (but may occasionally be useful anyway
7958 possible exception: if a function is called ONLY from 'interrupt' functions
7959 using a particular bank, it can be declared with the same 'using' attribute
7960 as the calling 'interrupt' functions.
7961 For instance, if you have several ISRs using bank one, and all of them
7962 call memcpy(), it might make sense to create a specialized version of memcpy()
7963 'using 1', since this would prevent the ISR from having to save bank zero
7964 to the stack on entry and switch to bank zero before calling the function
7971 (pending: I don't think this has been done yet)
7978 function using a non-zero bank will assume that it can trash that register
7979 bank, and will not save it.
7980 Since high-priority interrupts
7981 \begin_inset LatexCommand \index{interrupt priority}
7985 can interrupt low-priority ones on the 8051 and friends, this means that
7986 if a high-priority ISR
7990 a particular bank occurs while processing a low-priority ISR
7994 the same bank, terrible and bad things can happen.
7995 To prevent this, no single register bank should be
7999 by both a high priority and a low priority ISR.
8000 This is probably most easily done by having all high priority ISRs use
8001 one bank and all low priority ISRs use another.
8002 If you have an ISR which can change priority at runtime, you're on your
8003 own: I suggest using the default bank zero and taking the small performance
8007 It is most efficient if your ISR calls no other functions.
8008 If your ISR must call other functions, it is most efficient if those functions
8009 use the same bank as the ISR (see note 1 below); the next best is if the
8010 called functions use bank zero.
8011 It is very inefficient to call a function using a different, non-zero bank
8017 \begin_inset LatexCommand \index{Absolute addressing}
8024 Data items can be assigned an absolute address with the
8027 \begin_inset LatexCommand \index{at}
8033 keyword, in addition to a storage class, e.g.:
8039 \begin_inset LatexCommand \index{xdata}
8044 \begin_inset LatexCommand \index{at}
8048 0x8000 unsigned char PORTA_8255 ;
8051 In the above example the PORTA_8255 will be allocated to the location 0x8000
8052 of the external ram.
8053 Note that this feature is provided to give the programmer access to
8057 devices attached to the controller.
8058 The compiler does not actually reserve any space for variables declared
8059 in this way (they are implemented with an equate in the assembler).
8060 Thus it is left to the programmer to make sure there are no overlaps with
8061 other variables that are declared without the absolute address.
8062 The assembler listing file (.lst
8063 \begin_inset LatexCommand \index{.lst}
8067 ) and the linker output files (.rst
8068 \begin_inset LatexCommand \index{.rst}
8073 \begin_inset LatexCommand \index{.map}
8077 ) are a good places to look for such overlaps.
8081 Absolute address can be specified for variables in all storage classes,
8088 \begin_inset LatexCommand \index{bit}
8093 \begin_inset LatexCommand \index{at}
8100 The above example will allocate the variable at offset 0x02 in the bit-addressab
8102 There is no real advantage to assigning absolute addresses to variables
8103 in this manner, unless you want strict control over all the variables allocated.
8104 One possible use would be to write hardware portable code.
8105 For example, if you have a routine that uses one or more of the microcontroller
8106 I/O pins, and such pins are different for two different hardwares, you
8107 can declare the I/O pins in you routine using
8120 void DS1306_put(unsigned char value)
8128 unsigned char mask=0x80;
8152 SDI=(value & mask)?1:0;
8193 Then, someplace in the code for the first hardware you would use
8198 bit at 0x80 SDI;\SpecialChar ~
8202 /*I/O port 0, bit 0*/
8204 bit at 0x81 SCLK;\SpecialChar ~
8207 /*I/O port 0, bit 1*/
8209 bit CPOL;\SpecialChar ~
8220 /*This is a variable, let the linker allocate this one*/
8223 Similarly, for the second hardware you would use
8228 bit at 0x83 SDI;\SpecialChar ~
8232 /*I/O port 0, bit 3*/
8234 bit at 0x91 SCLK;\SpecialChar ~
8237 /*I/O port 1, bit 1*/
8239 bit CPOL;\SpecialChar ~
8250 /*This is a variable, let the linker allocate this one*/
8253 and you can use the same hardware dependent routine without changes, as
8254 for example in a library.
8255 This is somehow similar to sbit, but only one absolute address has to be
8256 specified in the whole project.
8260 \begin_inset LatexCommand \index{Startup code}
8267 The compiler inserts a call to the C routine
8269 _sdcc_external_startup()
8270 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
8279 at the start of the CODE area.
8280 This routine is in the runtime library
8281 \begin_inset LatexCommand \index{Runtime library}
8286 By default this routine returns 0, if this routine returns a non-zero value,
8287 the static & global variable initialization will be skipped and the function
8288 main will be invoked Other wise static & global variables will be initialized
8289 before the function main is invoked.
8292 _sdcc_external_startup()
8294 routine to your program to override the default if you need to setup hardware
8295 or perform some other critical operation prior to static & global variable
8299 Inline Assembler Code
8300 \begin_inset LatexCommand \index{Assembler routines}
8307 SDCC allows the use of in-line assembler with a few restriction as regards
8309 All labels defined within inline assembler code
8317 where nnnn is a number less than 100 (which implies a limit of utmost 100
8318 inline assembler labels
8326 It is strongly recommended that each assembly instruction (including labels)
8327 be placed in a separate line (as the example shows).
8341 \begin_inset LatexCommand \index{-\/-peep-asm}
8347 command line option is used, the inline assembler code will be passed through
8348 the peephole optimizer
8349 \begin_inset LatexCommand \index{Peephole optimizer}
8354 This might cause some unexpected changes in the inline assembler code.
8355 Please go through the peephole optimizer rules defined in file
8359 carefully before using this option.
8365 \begin_inset LatexCommand \index{\_asm}
8395 \begin_inset LatexCommand \index{\_endasm}
8402 The inline assembler code can contain any valid code understood by the assembler
8403 , this includes any assembler directives and comment lines.
8404 The compiler does not do any validation of the code within the
8414 Inline assembler code cannot reference any C-Labels, however it can reference
8416 \begin_inset LatexCommand \index{Labels}
8420 defined by the inline assembler, e.g.:
8445 ; some assembler code
8465 /* some more c code */
8467 clabel:\SpecialChar ~
8469 /* inline assembler cannot reference this label */
8481 $0003: ;label (can be reference by inline assembler only)
8493 /* some more c code */
8498 In other words inline assembly code can access labels defined in inline
8499 assembly within the scope of the function.
8500 The same goes the other way, ie.
8501 labels defines in inline assembly CANNOT be accessed by C statements.
8505 \begin_inset LatexCommand \index{int (16 bit)}
8510 \begin_inset LatexCommand \index{long (32 bit)}
8517 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
8518 multiplication and modulus operations are implemented by support routines.
8519 These support routines are all developed in ANSI-C to facilitate porting
8520 to other MCUs, although some model specific assembler optimizations are
8522 The following files contain the described routine, all of them can be found
8523 in <installdir>/share/sdcc/lib.
8529 \begin_inset Tabular
8530 <lyxtabular version="3" rows="11" columns="2">
8532 <column alignment="center" valignment="top" leftline="true" width="0(null)">
8533 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
8534 <row topline="true" bottomline="true">
8535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8545 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8556 <row topline="true">
8557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8565 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8570 16 bit multiplication
8574 <row topline="true">
8575 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8583 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8588 signed 16 bit division (calls _divuint)
8592 <row topline="true">
8593 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8601 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8606 unsigned 16 bit division
8610 <row topline="true">
8611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8619 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8624 signed 16 bit modulus (calls _moduint)
8628 <row topline="true">
8629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8637 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8642 unsigned 16 bit modulus
8646 <row topline="true">
8647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8655 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8660 32 bit multiplication
8664 <row topline="true">
8665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8673 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8678 signed 32 division (calls _divulong)
8682 <row topline="true">
8683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8691 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8696 unsigned 32 division
8700 <row topline="true">
8701 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8709 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8714 signed 32 bit modulus (calls _modulong)
8718 <row topline="true" bottomline="true">
8719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8727 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8732 unsigned 32 bit modulus
8745 Since they are compiled as
8750 \begin_inset LatexCommand \index{reentrant}
8755 \begin_inset LatexCommand \index{interrupt}
8759 service routines should not do any of the above operations.
8760 If this is unavoidable then the above routines will need to be compiled
8774 \begin_inset LatexCommand \index{-\/-stack-auto}
8780 option, after which the source program will have to be compiled with
8793 \begin_inset LatexCommand \index{-\/-int-long-rent}
8800 Notice that you don't have to call this routines directly.
8801 The compiler will use them automatically every time a integer operation
8805 Floating Point Support
8806 \begin_inset LatexCommand \index{Floating point support}
8813 SDCC supports IEEE (single precision 4 bytes) floating point numbers.The
8814 floating point support routines are derived from gcc's floatlib.c and consists
8815 of the following routines:
8823 \begin_inset Tabular
8824 <lyxtabular version="3" rows="17" columns="2">
8826 <column alignment="center" valignment="top" leftline="true" width="0(null)">
8827 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
8828 <row topline="true" bottomline="true">
8829 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8846 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8855 <row topline="true">
8856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8873 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8887 add floating point numbers
8891 <row topline="true">
8892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8909 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8923 subtract floating point numbers
8927 <row topline="true">
8928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8945 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8959 divide floating point numbers
8963 <row topline="true">
8964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8981 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8995 multiply floating point numbers
8999 <row topline="true">
9000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9017 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9031 convert floating point to unsigned char
9035 <row topline="true">
9036 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9053 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9067 convert floating point to signed char
9071 <row topline="true">
9072 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9089 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9103 convert floating point to unsigned int
9107 <row topline="true">
9108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9125 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9139 convert floating point to signed int
9143 <row topline="true">
9144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9170 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9184 convert floating point to unsigned long
9188 <row topline="true">
9189 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9206 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9220 convert floating point to signed long
9224 <row topline="true">
9225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9242 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9256 convert unsigned char to floating point
9260 <row topline="true">
9261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9278 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9292 convert char to floating point number
9296 <row topline="true">
9297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9314 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9328 convert unsigned int to floating point
9332 <row topline="true">
9333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9364 convert int to floating point numbers
9368 <row topline="true">
9369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9386 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9400 convert unsigned long to floating point number
9404 <row topline="true" bottomline="true">
9405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9422 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9436 convert long to floating point number
9449 Note if all these routines are used simultaneously the data space might
9451 For serious floating point usage it is strongly recommended that the large
9453 Also notice that you don't have to call this routines directly.
9454 The compiler will use them automatically every time a floating point operation
9459 \begin_inset LatexCommand \index{Memory model}
9464 \begin_inset LatexCommand \index{MCS51 memory}
9471 SDCC allows two memory models for MCS51 code, small and large.
9472 Modules compiled with different memory models should
9476 be combined together or the results would be unpredictable.
9477 The library routines supplied with the compiler are compiled as both small
9479 The compiled library modules are contained in separate directories as small
9480 and large so that you can link to either set.
9484 When the large model is used all variables declared without a storage class
9485 will be allocated into the external ram, this includes all parameters and
9486 local variables (for non-reentrant
9487 \begin_inset LatexCommand \index{reentrant}
9492 When the small model is used variables without storage class are allocated
9493 in the internal ram.
9496 Judicious usage of the processor specific storage classes
9497 \begin_inset LatexCommand \index{Storage class}
9501 and the 'reentrant' function type will yield much more efficient code,
9502 than using the large model.
9503 Several optimizations are disabled when the program is compiled using the
9504 large model, it is therefore strongly recommended that the small model
9505 be used unless absolutely required.
9509 \begin_inset LatexCommand \index{Memory model}
9514 \begin_inset LatexCommand \index{DS390 memory model}
9521 The only model supported is Flat 24
9522 \begin_inset LatexCommand \index{Flat 24 (memory model)}
9527 This generates code for the 24 bit contiguous addressing mode of the Dallas
9529 In this mode, up to four meg of external RAM or code space can be directly
9531 See the data sheets at www.dalsemi.com for further information on this part.
9535 In older versions of the compiler, this option was used with the MCS51 code
9541 Now, however, the '390 has it's own code generator, selected by the
9550 Note that the compiler does not generate any code to place the processor
9551 into 24 bitmode (although
9555 in the ds390 libraries will do that for you).
9561 \begin_inset LatexCommand \index{Tinibios (DS390)}
9565 , the boot loader or similar code must ensure that the processor is in 24
9566 bit contiguous addressing mode before calling the SDCC startup code.
9584 option, variables will by default be placed into the XDATA segment.
9589 Segments may be placed anywhere in the 4 meg address space using the usual
9601 Note that if any segments are located above 64K, the -r flag must be passed
9602 to the linker to generate the proper segment relocations, and the Intel
9603 HEX output format must be used.
9604 The -r flag can be passed to the linker by using the option
9608 on the sdcc command line.
9609 However, currently the linker can not handle code segments > 64k.
9612 Defines Created by the Compiler
9613 \begin_inset LatexCommand \index{Defines created by the compiler}
9620 The compiler creates the following #defines
9621 \begin_inset LatexCommand \index{\#defines}
9631 \begin_inset Tabular
9632 <lyxtabular version="3" rows="10" columns="2">
9634 <column alignment="center" valignment="top" leftline="true" width="0(null)">
9635 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
9636 <row topline="true" bottomline="true">
9637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9647 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9658 <row topline="true">
9659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9665 \begin_inset LatexCommand \index{SDCC}
9672 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9677 this Symbol is always defined
9681 <row topline="true">
9682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9688 \begin_inset LatexCommand \index{SDCC\_mcs51}
9693 \begin_inset LatexCommand \index{SDCC\_ds390}
9698 \begin_inset LatexCommand \index{SDCC\_z80}
9705 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9710 depending on the model used (e.g.: -mds390
9714 <row topline="true">
9715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9721 \begin_inset LatexCommand \index{\_\_mcs51}
9726 \begin_inset LatexCommand \index{\_\_ds390}
9731 \begin_inset LatexCommand \index{\_\_z80}
9738 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9743 depending on the model used (e.g.
9748 <row topline="true">
9749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9755 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
9762 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9785 <row topline="true">
9786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9792 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
9799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9822 <row topline="true">
9823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9829 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
9836 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9859 <row topline="true">
9860 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9866 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
9873 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9896 <row topline="true">
9897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9903 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
9910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9923 <row topline="true" bottomline="true">
9924 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9930 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
9937 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9959 Redirecting output on Windows Shells
9962 SDCC writes it's error messages to
9963 \begin_inset Quotes sld
9967 \begin_inset Quotes srd
9971 The windows 95/98/me shell (command or cmd) can't redirect it to a file.
9972 The solution is to use a reasonable shell or a helper program like redir.exe:
9976 \begin_inset LatexCommand \url{http://www.cygwin.com/ml/cygwin/1999-02/msg00603.html}
9984 \begin_inset LatexCommand \url{ftp://ftp.xraylith.wisc.edu/pub/khan/gnu-win32/mingw32/misc/redir.zip}
9992 \begin_inset LatexCommand \url{ftp://ftp.xraylith.wisc.edu/pub/khan/gnu-win32/mingw32/misc/README.redir}
10000 If you are using a windows NT/2K/XP shell, you can redirect the
10001 \begin_inset Quotes sld
10005 \begin_inset Quotes srd
10008 output to a file using
10009 \begin_inset Quotes sld
10013 \begin_inset Quotes srd
10023 sdcc -c foo.c 2> foo.err
10030 \begin_inset Quotes sld
10034 \begin_inset Quotes srd
10037 output of SDCC to a file you can use
10038 \begin_inset Quotes sld
10042 \begin_inset Quotes srd
10046 I you happen to have visual studio installed in your windows machine, you
10047 can use it to compile your sources using a custom build and the SDCC -
10062 \begin_inset LatexCommand \index{-\/-vc}
10067 Something like this should work:
10111 -model-large -c $(InputPath)
10114 SDCC Technical Data
10118 \begin_inset LatexCommand \index{Optimizations}
10125 SDCC performs a host of standard optimizations in addition to some MCU specific
10128 \layout Subsubsection
10130 Sub-expression Elimination
10131 \begin_inset LatexCommand \index{Subexpression elimination}
10138 The compiler does local and global common subexpression elimination, e.g.:
10149 will be translated to
10161 Some subexpressions are not as obvious as the above example, e.g.:
10171 In this case the address arithmetic a->b[i] will be computed only once;
10172 the equivalent code in C would be.
10184 The compiler will try to keep these temporary variables in registers.
10185 \layout Subsubsection
10187 Dead-Code Elimination
10188 \begin_inset LatexCommand \index{Dead-code elimination}
10207 i = 1; \SpecialChar ~
10212 global = 1;\SpecialChar ~
10225 global = 3;\SpecialChar ~
10236 int global; void f ()
10249 \layout Subsubsection
10252 \begin_inset LatexCommand \index{Copy propagation}
10308 Note: the dead stores created by this copy propagation will be eliminated
10309 by dead-code elimination.
10310 \layout Subsubsection
10313 \begin_inset LatexCommand \index{Loop optimization}
10320 Two types of loop optimizations are done by SDCC loop invariant lifting
10321 and strength reduction of loop induction variables.
10322 In addition to the strength reduction the optimizer marks the induction
10323 variables and the register allocator tries to keep the induction variables
10324 in registers for the duration of the loop.
10325 Because of this preference of the register allocator
10326 \begin_inset LatexCommand \index{Register allocation}
10330 , loop induction optimization causes an increase in register pressure, which
10331 may cause unwanted spilling of other temporary variables into the stack
10332 \begin_inset LatexCommand \index{stack}
10337 The compiler will generate a warning message when it is forced to allocate
10338 extra space either on the stack or data space.
10339 If this extra space allocation is undesirable then induction optimization
10340 can be eliminated either for the entire source file (with -
10350 -noinduction option) or for a given function only using #pragma\SpecialChar ~
10352 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
10365 for (i = 0 ; i < 100 ; i ++)
10379 for (i = 0; i < 100; i++)
10386 As mentioned previously some loop invariants are not as apparent, all static
10387 address computations are also moved out of the loop.
10392 \begin_inset LatexCommand \index{Strength reduction}
10396 , this optimization substitutes an expression by a cheaper expression:
10401 for (i=0;i < 100; i++)
10417 for (i=0;i< 100;i++) {
10423 ar[itemp1] = itemp2;
10440 The more expensive multiplication
10441 \begin_inset LatexCommand \index{Multiplication}
10445 is changed to a less expensive addition.
10446 \layout Subsubsection
10449 \begin_inset LatexCommand \index{Loop reversing}
10456 This optimization is done to reduce the overhead of checking loop boundaries
10457 for every iteration.
10458 Some simple loops can be reversed and implemented using a
10459 \begin_inset Quotes eld
10462 decrement and jump if not zero
10463 \begin_inset Quotes erd
10467 SDCC checks for the following criterion to determine if a loop is reversible
10468 (note: more sophisticated compilers use data-dependency analysis to make
10469 this determination, SDCC uses a more simple minded analysis).
10472 The 'for' loop is of the form
10478 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
10488 The <for body> does not contain
10489 \begin_inset Quotes eld
10493 \begin_inset Quotes erd
10497 \begin_inset Quotes erd
10503 All goto's are contained within the loop.
10506 No function calls within the loop.
10509 The loop control variable <sym> is not assigned any value within the loop
10512 The loop control variable does NOT participate in any arithmetic operation
10516 There are NO switch statements in the loop.
10517 \layout Subsubsection
10519 Algebraic Simplifications
10522 SDCC does numerous algebraic simplifications, the following is a small sub-set
10523 of these optimizations.
10528 i = j + 0 ; /* changed to */ i = j;
10530 i /= 2; /* changed to */ i >>= 1;
10532 i = j - j ; /* changed to */ i = 0;
10534 i = j / 1 ; /* changed to */ i = j;
10537 Note the subexpressions
10538 \begin_inset LatexCommand \index{Subexpression}
10542 given above are generally introduced by macro expansions or as a result
10543 of copy/constant propagation.
10544 \layout Subsubsection
10546 'switch' Statements
10547 \begin_inset LatexCommand \index{switch statement}
10554 SDCC changes switch statements to jump tables
10555 \begin_inset LatexCommand \index{jump tables}
10559 when the following conditions are true.
10563 The case labels are in numerical sequence, the labels need not be in order,
10564 and the starting number need not be one or zero.
10570 switch(i) {\SpecialChar ~
10601 case 4: ...\SpecialChar ~
10633 case 5: ...\SpecialChar ~
10665 case 3: ...\SpecialChar ~
10697 case 6: ...\SpecialChar ~
10765 Both the above switch statements will be implemented using a jump-table.
10769 The number of case labels is at least three, since it takes two conditional
10770 statements to handle the boundary conditions.
10773 The number of case labels is less than 84, since each label takes 3 bytes
10774 and a jump-table can be utmost 256 bytes long.
10778 Switch statements which have gaps in the numeric sequence or those that
10779 have more that 84 case labels can be split into more than one switch statement
10780 for efficient code generation, e.g.:
10830 If the above switch statement is broken down into two switch statements
10869 case 9: \SpecialChar ~
10885 case 12:\SpecialChar ~
10892 then both the switch statements will be implemented using jump-tables whereas
10893 the unmodified switch statement will not be.
10894 \layout Subsubsection
10896 Bit-shifting Operations
10897 \begin_inset LatexCommand \index{Bit shifting}
10904 Bit shifting is one of the most frequently used operation in embedded programmin
10906 SDCC tries to implement bit-shift operations in the most efficient way
10922 generates the following code:
10936 In general SDCC will never setup a loop if the shift count is known.
10968 Note that SDCC stores numbers in little-endian format (i.e.
10969 lowest order first).
10970 \layout Subsubsection
10973 \begin_inset LatexCommand \index{Bit rotation}
10980 A special case of the bit-shift operation is bit rotation, SDCC recognizes
10981 the following expression to be a left bit-rotation:
10991 i = ((i << 1) | (i >> 7));
11000 will generate the following code:
11012 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
11013 ns of this case will also be recognized as bit-rotation, i.e.:
11018 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
11019 \layout Subsubsection
11022 \begin_inset LatexCommand \index{Highest Order Bit}
11029 It is frequently required to obtain the highest order bit of an integral
11030 type (long, int, short or char types).
11031 SDCC recognizes the following expression to yield the highest order bit
11032 and generates optimized code for it, e.g.:
11052 hob = (gint >> 15) & 1;
11062 will generate the following code:
11095 000A E5*01\SpecialChar ~
11121 000C 33\SpecialChar ~
11150 000D E4\SpecialChar ~
11179 000E 13\SpecialChar ~
11208 000F F5*02\SpecialChar ~
11235 Variations of this case however will
11240 It is a standard C expression, so I heartily recommend this be the only
11241 way to get the highest order bit, (it is portable).
11242 Of course it will be recognized even if it is embedded in other expressions,
11248 xyz = gint + ((gint >> 15) & 1);
11251 will still be recognized.
11252 \layout Subsubsection
11255 \begin_inset LatexCommand \index{Peephole optimizer}
11262 The compiler uses a rule based, pattern matching and re-writing mechanism
11263 for peep-hole optimization.
11268 a peep-hole optimizer by Christopher W.
11269 Fraser (cwfraser@microsoft.com).
11270 A default set of rules are compiled into the compiler, additional rules
11271 may be added with the
11284 \begin_inset LatexCommand \index{-\/-peep-file}
11291 The rule language is best illustrated with examples.
11315 The above rule will change the following assembly
11316 \begin_inset LatexCommand \index{Assembler routines}
11338 Note: All occurrences of a
11342 (pattern variable) must denote the same string.
11343 With the above rule, the assembly sequence:
11353 will remain unmodified.
11357 Other special case optimizations may be added by the user (via
11373 some variants of the 8051 MCU allow only
11382 The following two rules will change all
11401 replace { lcall %1 } by { acall %1 }
11403 replace { ljmp %1 } by { ajmp %1 }
11408 inline-assembler code
11410 is also passed through the peep hole optimizer, thus the peephole optimizer
11411 can also be used as an assembly level macro expander.
11412 The rules themselves are MCU dependent whereas the rule language infra-structur
11413 e is MCU independent.
11414 Peephole optimization rules for other MCU can be easily programmed using
11419 The syntax for a rule is as follows:
11424 rule := replace [ restart ] '{' <assembly sequence> '
11462 <assembly sequence> '
11480 '}' [if <functionName> ] '
11485 <assembly sequence> := assembly instruction (each instruction including
11486 labels must be on a separate line).
11490 The optimizer will apply to the rules one by one from the top in the sequence
11491 of their appearance, it will terminate when all rules are exhausted.
11492 If the 'restart' option is specified, then the optimizer will start matching
11493 the rules again from the top, this option for a rule is expensive (performance)
11494 , it is intended to be used in situations where a transformation will trigger
11495 the same rule again.
11496 An example of this (not a good one, it has side effects) is the following
11519 Note that the replace pattern cannot be a blank, but can be a comment line.
11520 Without the 'restart' option only the inner most 'pop' 'push' pair would
11521 be eliminated, i.e.:
11551 the restart option the rule will be applied again to the resulting code
11552 and then all the pop-push pairs will be eliminated to yield:
11562 A conditional function can be attached to a rule.
11563 Attaching rules are somewhat more involved, let me illustrate this with
11590 The optimizer does a look-up of a function name table defined in function
11595 in the source file SDCCpeeph.c, with the name
11600 If it finds a corresponding entry the function is called.
11601 Note there can be no parameters specified for these functions, in this
11606 is crucial, since the function
11610 expects to find the label in that particular variable (the hash table containin
11611 g the variable bindings is passed as a parameter).
11612 If you want to code more such functions, take a close look at the function
11613 labelInRange and the calling mechanism in source file SDCCpeeph.c.
11614 I know this whole thing is a little kludgey, but maybe some day we will
11615 have some better means.
11616 If you are looking at this file, you will also see the default rules that
11617 are compiled into the compiler, you can add your own rules in the default
11618 set there if you get tired of specifying the -
11632 \begin_inset LatexCommand \index{Pragmas}
11639 SDCC supports the following #pragma directives.
11643 \begin_inset LatexCommand \index{\#pragma SAVE}
11647 - this will save all current options to the SAVE/RESTORE stack.
11652 \begin_inset LatexCommand \index{\#pragma RESTORE}
11656 - will restore saved options from the last save.
11657 SAVEs & RESTOREs can be nested.
11658 SDCC uses a SAVE/RESTORE stack: SAVE pushes current options to the stack,
11659 RESTORE pulls current options from the stack.
11664 \begin_inset LatexCommand \index{\#pragma NOGCSE}
11668 - will stop global subexpression elimination.
11672 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
11676 - will stop loop induction optimizations.
11680 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
11684 - will not generate code for boundary value checking, when switch statements
11685 are turned into jump-tables.
11689 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
11693 - the compiler will not overlay the parameters and local variables of a
11698 \begin_inset LatexCommand \index{\#pragma LESS\_PEDANTIC}
11702 - the compiler will not warn you anymore for obvious mistakes, you'r on
11707 \begin_inset LatexCommand \index{\#pragma NOLOOPREVERSE}
11711 - Will not do loop reversal optimization
11715 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
11719 NONE | {acc[,b[,dpl[,dph]]] - The exclude pragma disables generation of
11721 \begin_inset LatexCommand \index{push/pop}
11725 instruction in ISR function (using interrupt
11726 \begin_inset LatexCommand \index{interrupt}
11731 The directive should be placed immediately before the ISR function definition
11732 and it affects ALL ISR functions following it.
11733 To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
11734 EXCLUDE\SpecialChar ~
11736 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
11744 \begin_inset LatexCommand \index{\#pragma NOIV}
11748 - Do not generate interrupt vector table entries for all ISR functions
11749 defined after the pragma.
11750 This is useful in cases where the interrupt vector table must be defined
11751 manually, or when there is a secondary, manually defined interrupt vector
11753 for the autovector feature of the Cypress EZ-USB FX2).
11757 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
11762 \begin_inset LatexCommand \index{function prologue}
11766 function1[,function2[,function3...]] - The compiler by default uses a caller
11767 saves convention for register saving across function calls, however this
11768 can cause unnecessary register pushing & popping when calling small functions
11769 from larger functions.
11770 This option can be used to switch off the register saving convention for
11771 the function names specified.
11772 The compiler will not save registers when calling these functions, extra
11773 code need to be manually inserted at the entry & exit for these functions
11774 to save & restore the registers used by these functions, this can SUBSTANTIALLY
11775 reduce code & improve run time performance of the generated code.
11776 In the future the compiler (with inter procedural analysis) may be able
11777 to determine the appropriate scheme to use for each function call.
11788 -callee-saves command line option is used, the function names specified
11789 in #pragma\SpecialChar ~
11791 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
11795 is appended to the list of functions specified in the command line.
11798 The pragma's are intended to be used to turn-off certain optimizations which
11799 might cause the compiler to generate extra stack / data space to store
11800 compiler generated temporary variables.
11801 This usually happens in large functions.
11802 Pragma directives should be used as shown in the following example, they
11803 are used to control options & optimizations for a given function; pragmas
11804 should be placed before and/or after a function, placing pragma's inside
11805 a function body could have unpredictable results.
11811 \begin_inset LatexCommand \index{\#pragma SAVE}
11815 /* save the current settings */
11818 \begin_inset LatexCommand \index{\#pragma NOGCSE}
11822 /* turnoff global subexpression elimination */
11824 #pragma NOINDUCTION
11825 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
11829 /* turn off induction optimizations */
11852 \begin_inset LatexCommand \index{\#pragma RESTORE}
11856 /* turn the optimizations back on */
11859 The compiler will generate a warning message when extra space is allocated.
11860 It is strongly recommended that the SAVE and RESTORE pragma's be used when
11861 changing options for a function.
11866 <pending: this is messy and incomplete>
11871 Compiler support routines (_gptrget, _mulint etc)
11874 Stdclib functions (puts, printf, strcat etc)
11877 Math functions (sin, pow, sqrt etc)
11880 license statements for the libraries are missing
11883 Interfacing with Assembly Routines
11884 \begin_inset LatexCommand \index{Assembler routines}
11889 \layout Subsubsection
11891 Global Registers used for Parameter Passing
11892 \begin_inset LatexCommand \index{Parameter passing}
11899 The compiler always uses the global registers
11902 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
11907 \begin_inset LatexCommand \index{B (register)}
11916 \begin_inset LatexCommand \index{ACC}
11922 to pass the first parameter to a routine.
11923 The second parameter onwards is either allocated on the stack (for reentrant
11934 -stack-auto is used) or in the internal / external ram (depending on the
11937 \layout Subsubsection
11939 Assembler Routine(non-reentrant
11940 \begin_inset LatexCommand \index{reentrant}
11945 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
11952 In the following example the function c_func calls an assembler routine
11953 asm_func, which takes two parameters.
11958 extern int asm_func(unsigned char, unsigned char);
11962 int c_func (unsigned char i, unsigned char j)
11970 return asm_func(i,j);
11984 return c_func(10,9);
11989 The corresponding assembler function is:
11994 .globl _asm_func_PARM_2
12058 add a,_asm_func_PARM_2
12083 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
12100 Note here that the return values are placed in 'dpl' - One byte return value,
12101 'dpl' LSB & 'dph' MSB for two byte values.
12102 'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
12103 b' & 'acc' for four byte values.
12106 The parameter naming convention is _<function_name>_PARM_<n>, where n is
12107 the parameter number starting from 1, and counting from the left.
12108 The first parameter is passed in
12109 \begin_inset Quotes eld
12113 \begin_inset Quotes erd
12116 for One bye parameter,
12117 \begin_inset Quotes eld
12121 \begin_inset Quotes erd
12125 \begin_inset Quotes eld
12129 \begin_inset Quotes erd
12132 for three bytes and
12133 \begin_inset Quotes eld
12137 \begin_inset Quotes erd
12140 for four bytes, the variable name for the second parameter will be _<function_n
12145 Assemble the assembler routine with the following command:
12152 asx8051 -losg asmfunc.asm
12159 Then compile and link the assembler routine to the C source file with the
12167 sdcc cfunc.c asmfunc.rel
12168 \layout Subsubsection
12170 Assembler Routine(reentrant
12171 \begin_inset LatexCommand \index{reentrant}
12176 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
12183 In this case the second parameter onwards will be passed on the stack, the
12184 parameters are pushed from right to left i.e.
12185 after the call the left most parameter will be on the top of the stack.
12186 Here is an example:
12191 extern int asm_func(unsigned char, unsigned char);
12195 int c_func (unsigned char i, unsigned char j) reentrant
12203 return asm_func(i,j);
12217 return c_func(10,9);
12222 The corresponding assembler routine is:
12328 The compiling and linking procedure remains the same, however note the extra
12329 entry & exit linkage required for the assembler code, _bp is the stack
12330 frame pointer and is used to compute the offset into the stack for parameters
12331 and local variables.
12335 \begin_inset LatexCommand \index{stack}
12340 \begin_inset LatexCommand \index{External stack}
12347 The external stack is located at the start of the external ram segment,
12348 and is 256 bytes in size.
12359 -xstack option is used to compile the program, the parameters and local
12360 variables of all reentrant functions are allocated in this area.
12361 This option is provided for programs with large stack space requirements.
12362 When used with the -
12372 -stack-auto option, all parameters and local variables are allocated on
12373 the external stack (note support libraries will need to be recompiled with
12377 The compiler outputs the higher order address byte of the external ram segment
12378 into PORT P2, therefore when using the External Stack option, this port
12379 MAY NOT be used by the application program.
12383 \begin_inset LatexCommand \index{ANSI-compliance}
12390 Deviations from the compliance:
12393 functions are not always reentrant.
12396 structures cannot be assigned values directly, cannot be passed as function
12397 parameters or assigned to each other and cannot be a return value from
12424 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
12435 struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
12457 return rets;/* is invalid in SDCC although allowed in ANSI */
12464 \begin_inset LatexCommand \index{long long (not supported)}
12469 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
12477 \begin_inset LatexCommand \index{double (not supported)}
12481 ' precision floating point
12482 \begin_inset LatexCommand \index{Floating point support}
12489 No support for setjmp and longjmp (for now).
12493 \begin_inset LatexCommand \index{K\&R style}
12497 function declarations are NOT allowed.
12503 foo(i,j) /* this old style of function declarations */
12505 int i,j; /* are valid in ANSI but not valid in SDCC */
12520 functions declared as pointers must be dereferenced during the call.
12531 /* has to be called like this */
12533 (*foo)(); /* ANSI standard allows calls to be made like 'foo()' */
12537 Cyclomatic Complexity
12538 \begin_inset LatexCommand \index{Cyclomatic complexity}
12545 Cyclomatic complexity of a function is defined as the number of independent
12546 paths the program can take during execution of the function.
12547 This is an important number since it defines the number test cases you
12548 have to generate to validate the function.
12549 The accepted industry standard for complexity number is 10, if the cyclomatic
12550 complexity reported by SDCC exceeds 10 you should think about simplification
12551 of the function logic.
12552 Note that the complexity level is not related to the number of lines of
12553 code in a function.
12554 Large functions can have low complexity, and small functions can have large
12560 SDCC uses the following formula to compute the complexity:
12565 complexity = (number of edges in control flow graph) - (number of nodes
12566 in control flow graph) + 2;
12570 Having said that the industry standard is 10, you should be aware that in
12571 some cases it be may unavoidable to have a complexity level of less than
12573 For example if you have switch statement with more than 10 case labels,
12574 each case label adds one to the complexity level.
12575 The complexity level is by no means an absolute measure of the algorithmic
12576 complexity of the function, it does however provide a good starting point
12577 for which functions you might look at for further optimization.
12583 Here are a few guidelines that will help the compiler generate more efficient
12584 code, some of the tips are specific to this compiler others are generally
12585 good programming practice.
12588 Use the smallest data type to represent your data-value.
12589 If it is known in advance that the value is going to be less than 256 then
12590 use an 'unsigned char' instead of a 'short' or 'int'.
12593 Use unsigned when it is known in advance that the value is not going to
12595 This helps especially if you are doing division or multiplication.
12598 NEVER jump into a LOOP.
12601 Declare the variables to be local whenever possible, especially loop control
12602 variables (induction).
12605 Since the compiler does not always do implicit integral promotion, the programme
12606 r should do an explicit cast when integral promotion is required.
12609 Reducing the size of division, multiplication & modulus operations can reduce
12610 code size substantially.
12611 Take the following code for example.
12617 foobar(unsigned int p1, unsigned char ch)
12625 unsigned char ch1 = p1 % ch ;
12636 For the modulus operation the variable ch will be promoted to unsigned int
12637 first then the modulus operation will be performed (this will lead to a
12638 call to support routine _moduint()), and the result will be casted to a
12640 If the code is changed to
12645 foobar(unsigned int p1, unsigned char ch)
12653 unsigned char ch1 = (unsigned char)p1 % ch ;
12664 It would substantially reduce the code generated (future versions of the
12665 compiler will be smart enough to detect such optimization opportunities).
12669 Notes on MCS51 memory
12670 \begin_inset LatexCommand \index{MCS51 memory}
12677 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12678 RAM memory which is structured as follows
12682 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
12685 - Bytes 20-2F - 16 bytes to hold 128 bit variables and,
12687 - Bytes 30-7F - 80 bytes for general purpose use.
12692 Additionally some members of the MCS51 family may have up to 128 bytes of
12693 additional, indirectly addressable, internal RAM memory (
12698 Furthermore, some chips may have some built in external memory (
12702 ) which should not be confused with the internal, directly addressable RAM
12708 Usually this built in
12712 memory has to be activated before using it (you can probably find this
12713 information on the datasheet of the microcontroller your are using).
12716 Normally SDCC will only use the first bank
12717 \begin_inset LatexCommand \index{bank}
12721 of registers (register bank 0), but it is possible to specify that other
12722 banks of registers should be used in interrupt
12723 \begin_inset LatexCommand \index{interrupt}
12728 By default, the compiler will place the stack after the last byte of allocated
12729 memory for variables.
12730 For example, if the first 2 banks of registers are used, and only four
12735 variables, it will position the base of the internal stack at address 20
12737 This implies that as the stack
12738 \begin_inset LatexCommand \index{stack}
12742 grows, it will use up the remaining register banks, and the 16 bytes used
12743 by the 128 bit variables, and 80 bytes for general purpose use.
12744 If any bit variables are used, the data variables will be placed after
12745 the byte holding the last bit variable.
12746 For example, if register banks 0 and 1 are used, and there are 9 bit variables
12751 variables will be placed starting at address 0x22.
12763 \begin_inset LatexCommand \index{-\/-data-loc}
12767 to specify the start address of the
12781 -iram-size to specify the size of the total internal RAM (
12793 By default the 8051 linker will place the stack after the last byte of data
12806 \begin_inset LatexCommand \index{-\/-stack-loc}
12810 allows you to specify the start of the stack, i.e.
12811 you could start it after any data in the general purpose area.
12812 If your microcontroller has additional indirectly addressable internal
12817 ) you can place the stack on it.
12818 You may also need to use -
12829 \begin_inset LatexCommand \index{-\/-data-loc}
12833 to set the start address of the external RAM (
12848 \begin_inset LatexCommand \index{-\/-data-loc}
12852 to specify its size.
12853 Same goes for the code memory, using -
12864 \begin_inset LatexCommand \index{-\/-data-loc}
12879 \begin_inset LatexCommand \index{-\/-data-loc}
12884 If in doubt, don't specify any options and see if the resulting memory
12885 layout is appropriate, then you can adjust it.
12888 The 8051 linker generates two files with memory allocation information.
12889 The first, with extension .map shows all the variables and segments.
12890 The second with extension .mem shows the final memory layout.
12891 The linker will complaint either if memory segments overlap, there is not
12892 enough memory, or there is not enough space for stack.
12893 If you get any linking warnings and/or errors related to stack or segments
12894 allocation, take a look at either the .map or .mem files to find out what
12896 The .mem file may even suggest a solution to the problem.
12900 \begin_inset LatexCommand \index{Tools}
12904 included in the distribution
12910 \begin_inset Tabular
12911 <lyxtabular version="3" rows="12" columns="3">
12913 <column alignment="center" valignment="top" leftline="true" width="0pt">
12914 <column alignment="center" valignment="top" leftline="true" width="0pt">
12915 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
12916 <row topline="true" bottomline="true">
12917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12933 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12942 <row topline="true">
12943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12956 Simulator for various architectures
12959 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12968 <row topline="true">
12969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12982 header file conversion
12985 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12990 sdcc/support/scripts
12994 <row topline="true">
12995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13008 header file conversion
13011 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13016 sdcc/support/scripts
13020 <row topline="true">
13021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13037 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13055 <row topline="true">
13056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13090 <row topline="true">
13091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13107 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13125 <row topline="true">
13126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13142 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13160 <row topline="true">
13161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13195 <row topline="true">
13196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13212 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13230 <row topline="true">
13231 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13239 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13247 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13265 <row topline="true" bottomline="true">
13266 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13274 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13282 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13309 Related open source tools
13310 \begin_inset LatexCommand \index{Related tools}
13320 \begin_inset Tabular
13321 <lyxtabular version="3" rows="7" columns="3">
13323 <column alignment="center" valignment="top" leftline="true" width="0pt">
13324 <column alignment="center" valignment="top" leftline="true" width="0pt">
13325 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
13326 <row topline="true" bottomline="true">
13327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13343 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13352 <row topline="true">
13353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13359 \begin_inset LatexCommand \index{gpsim}
13366 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13380 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
13388 <row topline="true">
13389 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13395 \begin_inset LatexCommand \index{srecord}
13402 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13407 Object file conversion, checksumming, ...
13410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13416 \begin_inset LatexCommand \url{http://srecord.sourceforge.net/}
13424 <row topline="true">
13425 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13431 \begin_inset LatexCommand \index{objdump}
13438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13443 Object file conversion, ...
13446 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13451 Part of binutils (should be there anyway)
13455 <row topline="true">
13456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13462 \begin_inset LatexCommand \index{doxygen}
13469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13474 Source code documentation system
13477 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13483 \begin_inset LatexCommand \url{http://www.doxygen.org}
13491 <row topline="true">
13492 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13498 \begin_inset LatexCommand \index{splint}
13505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13510 Statically checks c sources
13513 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13519 \begin_inset LatexCommand \url{http://www.splint.org}
13527 <row topline="true" bottomline="true">
13528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13534 \begin_inset LatexCommand \index{ddd}
13541 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13546 Debugger, serves nicely as GUI to sdcdb
13547 \begin_inset LatexCommand \index{sdcdb}
13554 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13560 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
13577 Related documentation / recommended reading
13583 \begin_inset Tabular
13584 <lyxtabular version="3" rows="5" columns="3">
13586 <column alignment="center" valignment="top" leftline="true" width="0pt">
13587 <column alignment="center" valignment="top" leftline="true" width="0pt">
13588 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
13589 <row topline="true" bottomline="true">
13590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13606 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13615 <row topline="true">
13616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13631 Advanced Compiler Design and Implementation
13634 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13643 <row topline="true">
13644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13667 \begin_inset LatexCommand \index{C Reference card}
13674 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13680 \begin_inset LatexCommand \url{http://www.refcards.com/about/c.html}
13688 <row topline="true">
13689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13694 test_suite_spec.pdf
13697 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13702 sdcc regression test
13703 \begin_inset LatexCommand \index{Regression test}
13710 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13719 <row topline="true" bottomline="true">
13720 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13751 sdcc internal documentation
13754 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13772 Retargetting for other MCUs.
13775 The issues for retargetting the compiler are far too numerous to be covered
13777 What follows is a brief description of each of the seven phases of the
13778 compiler and its MCU dependency.
13781 Parsing the source and building the annotated parse tree.
13782 This phase is largely MCU independent (except for the language extensions).
13783 Syntax & semantic checks are also done in this phase, along with some initial
13784 optimizations like back patching labels and the pattern matching optimizations
13785 like bit-rotation etc.
13788 The second phase involves generating an intermediate code which can be easy
13789 manipulated during the later phases.
13790 This phase is entirely MCU independent.
13791 The intermediate code generation assumes the target machine has unlimited
13792 number of registers, and designates them with the name iTemp.
13793 The compiler can be made to dump a human readable form of the code generated
13807 This phase does the bulk of the standard optimizations and is also MCU independe
13809 This phase can be broken down into several sub-phases:
13813 Break down intermediate code (iCode) into basic blocks.
13815 Do control flow & data flow analysis on the basic blocks.
13817 Do local common subexpression elimination, then global subexpression elimination
13819 Dead code elimination
13823 If loop optimizations caused any changes then do 'global subexpression eliminati
13824 on' and 'dead code elimination' again.
13827 This phase determines the live-ranges; by live range I mean those iTemp
13828 variables defined by the compiler that still survive after all the optimization
13830 Live range analysis
13831 \begin_inset LatexCommand \index{Live range analysis}
13835 is essential for register allocation, since these computation determines
13836 which of these iTemps will be assigned to registers, and for how long.
13839 Phase five is register allocation.
13840 There are two parts to this process.
13844 The first part I call 'register packing' (for lack of a better term).
13845 In this case several MCU specific expression folding is done to reduce
13850 The second part is more MCU independent and deals with allocating registers
13851 to the remaining live ranges.
13852 A lot of MCU specific code does creep into this phase because of the limited
13853 number of index registers available in the 8051.
13856 The Code generation phase is (unhappily), entirely MCU dependent and very
13857 little (if any at all) of this code can be reused for other MCU.
13858 However the scheme for allocating a homogenized assembler operand for each
13859 iCode operand may be reused.
13862 As mentioned in the optimization section the peep-hole optimizer is rule
13863 based system, which can reprogrammed for other MCUs.
13867 \begin_inset LatexCommand \index{sdcdb}
13871 - Source Level Debugger
13872 \begin_inset LatexCommand \index{Debugger}
13879 SDCC is distributed with a source level debugger.
13880 The debugger uses a command line interface, the command repertoire of the
13881 debugger has been kept as close to gdb
13882 \begin_inset LatexCommand \index{gdb}
13886 (the GNU debugger) as possible.
13887 The configuration and build process is part of the standard compiler installati
13888 on, which also builds and installs the debugger in the target directory
13889 specified during configuration.
13890 The debugger allows you debug BOTH at the C source and at the ASM source
13894 Compiling for Debugging
13897 The \SpecialChar \-
13899 debug option must be specified for all files for which debug information
13900 is to be generated.
13901 The complier generates a .adb file for each of these files.
13902 The linker creates the .cdb file from the .adb files and the address information.
13903 This .cdb is used by the debugger.
13906 How the Debugger Works
13919 -debug option is specified the compiler generates extra symbol information
13920 some of which are put into the the assembler source and some are put into
13922 Then the linker creates the .cdb file from the individual .adb files with
13923 the address information for the symbols.
13924 The debugger reads the symbolic information generated by the compiler &
13925 the address information generated by the linker.
13926 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
13927 execution is controlled by the debugger.
13928 When a command is issued for the debugger, it translates it into appropriate
13929 commands for the simulator.
13932 Starting the Debugger
13935 The debugger can be started using the following command line.
13936 (Assume the file you are debugging has the file name foo).
13950 The debugger will look for the following files.
13953 foo.c - the source file.
13956 foo.cdb - the debugger symbol information file.
13959 foo.ihx - the Intel hex format
13960 \begin_inset LatexCommand \index{Intel hex format}
13967 Command Line Options.
13980 -directory=<source file directory> this option can used to specify the directory
13982 The debugger will look into the directory list specified for source, cdb
13984 The items in the directory list must be separated by ':', e.g.
13985 if the source files can be in the directories /home/src1 and /home/src2,
13996 -directory option should be -
14006 -directory=/home/src1:/home/src2.
14007 Note there can be no spaces in the option.
14011 -cd <directory> - change to the <directory>.
14014 -fullname - used by GUI front ends.
14017 -cpu <cpu-type> - this argument is passed to the simulator please see the
14018 simulator docs for details.
14021 -X <Clock frequency > this options is passed to the simulator please see
14022 the simulator docs for details.
14025 -s <serial port file> passed to simulator see the simulator docs for details.
14028 -S <serial in,out> passed to simulator see the simulator docs for details.
14034 As mention earlier the command interface for the debugger has been deliberately
14035 kept as close the GNU debugger gdb, as possible.
14036 This will help the integration with existing graphical user interfaces
14037 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
14038 \layout Subsubsection
14040 break [line | file:line | function | file:function]
14043 Set breakpoint at specified line or function:
14052 sdcdb>break foo.c:100
14054 sdcdb>break funcfoo
14056 sdcdb>break foo.c:funcfoo
14057 \layout Subsubsection
14059 clear [line | file:line | function | file:function ]
14062 Clear breakpoint at specified line or function:
14071 sdcdb>clear foo.c:100
14073 sdcdb>clear funcfoo
14075 sdcdb>clear foo.c:funcfoo
14076 \layout Subsubsection
14081 Continue program being debugged, after breakpoint.
14082 \layout Subsubsection
14087 Execute till the end of the current function.
14088 \layout Subsubsection
14093 Delete breakpoint number 'n'.
14094 If used without any option clear ALL user defined break points.
14095 \layout Subsubsection
14097 info [break | stack | frame | registers ]
14100 info break - list all breakpoints
14103 info stack - show the function call stack.
14106 info frame - show information about the current execution frame.
14109 info registers - show content of all registers.
14110 \layout Subsubsection
14115 Step program until it reaches a different source line.
14116 \layout Subsubsection
14121 Step program, proceeding through subroutine calls.
14122 \layout Subsubsection
14127 Start debugged program.
14128 \layout Subsubsection
14133 Print type information of the variable.
14134 \layout Subsubsection
14139 print value of variable.
14140 \layout Subsubsection
14145 load the given file name.
14146 Note this is an alternate method of loading file for debugging.
14147 \layout Subsubsection
14152 print information about current frame.
14153 \layout Subsubsection
14158 Toggle between C source & assembly source.
14159 \layout Subsubsection
14161 ! simulator command
14164 Send the string following '!' to the simulator, the simulator response is
14166 Note the debugger does not interpret the command being sent to the simulator,
14167 so if a command like 'go' is sent the debugger can loose its execution
14168 context and may display incorrect values.
14169 \layout Subsubsection
14176 My name is Bobby Brown"
14179 Interfacing with XEmacs
14180 \begin_inset LatexCommand \index{XEmacs}
14185 \begin_inset LatexCommand \index{Emacs}
14192 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
14193 sdcdb.el and sdcdbsrc.el.
14194 These two files can be found in the $(prefix)/bin directory after the installat
14196 These files need to be loaded into XEmacs for the interface to work.
14197 This can be done at XEmacs startup time by inserting the following into
14198 your '.xemacs' file (which can be found in your HOME directory):
14204 (load-file sdcdbsrc.el)
14210 .xemacs is a lisp file so the () around the command is REQUIRED.
14211 The files can also be loaded dynamically while XEmacs is running, set the
14212 environment variable 'EMACSLOADPATH' to the installation bin directory
14213 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
14214 To start the interface enter the following command:
14228 You will prompted to enter the file name to be debugged.
14233 The command line options that are passed to the simulator directly are bound
14234 to default values in the file sdcdbsrc.el.
14235 The variables are listed below, these values maybe changed as required.
14238 sdcdbsrc-cpu-type '51
14241 sdcdbsrc-frequency '11059200
14244 sdcdbsrc-serial nil
14247 The following is a list of key mapping for the debugger interface.
14255 ;; Current Listing ::
14257 ;;key\SpecialChar ~
14272 binding\SpecialChar ~
14296 ;;---\SpecialChar ~
14311 ------\SpecialChar ~
14351 sdcdb-next-from-src\SpecialChar ~
14377 sdcdb-back-from-src\SpecialChar ~
14403 sdcdb-cont-from-src\SpecialChar ~
14413 SDCDB continue command
14429 sdcdb-step-from-src\SpecialChar ~
14455 sdcdb-whatis-c-sexp\SpecialChar ~
14465 SDCDB ptypecommand for data at
14529 sdcdbsrc-delete\SpecialChar ~
14543 SDCDB Delete all breakpoints if no arg
14591 given or delete arg (C-u arg x)
14607 sdcdbsrc-frame\SpecialChar ~
14622 SDCDB Display current frame if no arg,
14671 given or display frame arg
14736 sdcdbsrc-goto-sdcdb\SpecialChar ~
14746 Goto the SDCDB output buffer
14762 sdcdb-print-c-sexp\SpecialChar ~
14773 SDCDB print command for data at
14837 sdcdbsrc-goto-sdcdb\SpecialChar ~
14847 Goto the SDCDB output buffer
14863 sdcdbsrc-mode\SpecialChar ~
14879 Toggles Sdcdbsrc mode (turns it off)
14883 ;; C-c C-f\SpecialChar ~
14891 sdcdb-finish-from-src\SpecialChar ~
14899 SDCDB finish command
14903 ;; C-x SPC\SpecialChar ~
14911 sdcdb-break\SpecialChar ~
14929 Set break for line with point
14931 ;; ESC t\SpecialChar ~
14941 sdcdbsrc-mode\SpecialChar ~
14957 Toggle Sdcdbsrc mode
14959 ;; ESC m\SpecialChar ~
14969 sdcdbsrc-srcmode\SpecialChar ~
14993 The Z80 and gbz80 port
14996 SDCC can target both the Zilog Z80 and the Nintendo Gameboy's Z80-like gbz80.
14997 The port is incomplete - long support is incomplete (mul, div and mod are
14998 unimplemented), and both float and bitfield support is missing.
14999 Apart from that the code generated is correct.
15002 As always, the code is the authoritave reference - see z80/ralloc.c and z80/gen.c.
15003 The stack frame is similar to that generated by the IAR Z80 compiler.
15004 IX is used as the base pointer, HL is used as a temporary register, and
15005 BC and DE are available for holding variables.
15006 IY is currently unused.
15007 Return values are stored in HL.
15008 One bad side effect of using IX as the base pointer is that a functions
15009 stack frame is limited to 127 bytes - this will be fixed in a later version.
15013 \begin_inset LatexCommand \index{Support}
15020 SDCC has grown to be a large project.
15021 The compiler alone (without the preprocessor, assembler and linker) is
15022 about 40,000 lines of code (blank stripped).
15023 The open source nature of this project is a key to its continued growth
15025 You gain the benefit and support of many active software developers and
15027 Is SDCC perfect? No, that's why we need your help.
15028 The developers take pride in fixing reported bugs.
15029 You can help by reporting the bugs and helping other SDCC users.
15030 There are lots of ways to contribute, and we encourage you to take part
15031 in making SDCC a great software package.
15035 The SDCC project is hosted on the sdcc sourceforge site at
15036 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
15041 You'll find the complete set of mailing lists
15042 \begin_inset LatexCommand \index{Mailing list}
15046 , forums, bug reporting system, patch submission
15047 \begin_inset LatexCommand \index{Patch submission}
15052 \begin_inset LatexCommand \index{download}
15056 area and cvs code repository
15057 \begin_inset LatexCommand \index{cvs code repository}
15065 \begin_inset LatexCommand \index{Bugs}
15070 \begin_inset LatexCommand \index{Reporting bugs}
15077 The recommended way of reporting bugs is using the infrastructure of the
15079 You can follow the status of bug reports there and have an overview about
15083 Bug reports are automatically forwarded to the developer mailing list and
15084 will be fixed ASAP.
15085 When reporting a bug, it is very useful to include a small test program
15086 (the smaller the better) which reproduces the problem.
15087 If you can isolate the problem by looking at the generated assembly code,
15088 this can be very helpful.
15089 Compiling your program with the -
15100 \begin_inset LatexCommand \index{-\/-dumpall}
15104 option can sometimes be useful in locating optimization problems.
15105 When reporting a bug please maker sure you:
15108 Attach the code you are compiling with SDCC.
15112 Specify the exact command you use to run SDCC, or attach your Makefile.
15116 Specify the SDCC version (type "sdcc -v"), your platform, and operating
15121 Provide an exact copy of any error message or incorrect output.
15125 Put something meaningful in the subject of your message.
15128 Please attempt to include these 5 important parts, as applicable, in all
15129 requests for support or when reporting any problems or bugs with SDCC.
15130 Though this will make your message lengthy, it will greatly improve your
15131 chance that SDCC users and developers will be able to help you.
15132 Some SDCC developers are frustrated by bug reports without code provided
15133 that they can use to reproduce and ultimately fix the problem, so please
15134 be sure to provide sample code if you are reporting a bug!
15137 Please have a short check that you are using a recent version of SDCC and
15138 the bug is not yet known.
15139 This is the link for reporting bugs:
15140 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
15147 Requesting Features
15148 \begin_inset LatexCommand \index{Feature request}
15153 \begin_inset LatexCommand \index{Requesting features}
15160 Like bug reports feature requests are forwarded to the developer mailing
15162 This is the link for requesting features:
15163 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
15173 These links should take you directly to the
15174 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
15184 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
15185 automated messages (mid 2003)
15189 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
15193 , lists and forums are archived so if you are lucky someone already had
15198 \begin_inset LatexCommand \index{Changelog}
15205 You can follow the status of the cvs version
15206 \begin_inset LatexCommand \index{version}
15210 of SDCC by watching the file
15211 \begin_inset LatexCommand \htmlurl[ChangeLog]{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/sdcc/sdcc/ChangeLog?rev=HEAD&content-type=text/plain}
15215 in the cvs-repository.
15219 \begin_inset LatexCommand \index{Release policy}
15226 Historically there often were long delays between official releases and
15227 the sourceforge download area tends to get not updated at all.
15228 Current excuses might refer to problems with live range analysis, but if
15229 this is fixed, the next problem rising is that another excuse will have
15231 Kidding aside, we have to get better there! On the other hand there are
15232 daily snapshots available at
15233 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
15237 , and you can always built the very last version (hopefully with many bugs
15238 fixed, and features added) from the source code available at
15239 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
15247 \begin_inset LatexCommand \index{Examples}
15254 You'll find some small examples in the directory sdcc/device/examples/
15257 Maybe we should include some links to real world applications.
15258 Preferably pointer to pointers (one for each architecture) so this stays
15263 \begin_inset LatexCommand \index{Quality control}
15270 The compiler is passed through nightly compile and build checks.
15276 \begin_inset LatexCommand \index{Regression test}
15280 check that SDCC itself compiles flawlessly on several platforms and checks
15281 the quality of the code generated by SDCC by running the code through simulator
15283 There is a separate document
15286 \begin_inset LatexCommand \index{Test suite}
15295 You'll find the test code in the directory
15297 sdcc/support/regression
15300 You can run these tests manually by running
15304 in this directory (or f.e.
15309 if you don't want to run the complete tests).
15310 The test code might also be interesting if you want to look for examples
15311 \begin_inset LatexCommand \index{Examples}
15315 checking corner cases of SDCC or if you plan to submit patches
15316 \begin_inset LatexCommand \index{Patch submission}
15323 The pic port uses a different set of regression tests, you'll find them
15326 sdcc/src/regression
15332 \begin_inset LatexCommand \index{Compiler internals}
15339 The anatomy of the compiler
15344 This is an excerpt from an article published in Circuit Cellar Magazine
15346 It's a little outdated (the compiler is much more efficient now and user/develo
15347 per friendly), but pretty well exposes the guts of it all.
15353 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
15354 It is fairly easy to retarget for other 8-bit MCU.
15355 Here we take a look at some of the internals of the compiler.
15360 \begin_inset LatexCommand \index{Parsing}
15367 Parsing the input source file and creating an AST (Annotated Syntax Tree
15368 \begin_inset LatexCommand \index{Annotated syntax tree}
15373 This phase also involves propagating types (annotating each node of the
15374 parse tree with type information) and semantic analysis.
15375 There are some MCU specific parsing rules.
15376 For example the storage classes, the extended storage classes are MCU specific
15377 while there may be a xdata storage class for 8051 there is no such storage
15378 class for z80 or Atmel AVR.
15379 SDCC allows MCU specific storage class extensions, i.e.
15380 xdata will be treated as a storage class specifier when parsing 8051 C
15381 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
15386 \begin_inset LatexCommand \index{iCode}
15393 Intermediate code generation.
15394 In this phase the AST is broken down into three-operand form (iCode).
15395 These three operand forms are represented as doubly linked lists.
15396 ICode is the term given to the intermediate form generated by the compiler.
15397 ICode example section shows some examples of iCode generated for some simple
15398 C source functions.
15402 \begin_inset LatexCommand \index{Optimizations}
15409 Bulk of the target independent optimizations is performed in this phase.
15410 The optimizations include constant propagation, common sub-expression eliminati
15411 on, loop invariant code movement, strength reduction of loop induction variables
15412 and dead-code elimination.
15415 Live range analysis
15416 \begin_inset LatexCommand \index{Live range analysis}
15423 During intermediate code generation phase, the compiler assumes the target
15424 machine has infinite number of registers and generates a lot of temporary
15426 The live range computation determines the lifetime of each of these compiler-ge
15427 nerated temporaries.
15428 A picture speaks a thousand words.
15429 ICode example sections show the live range annotations for each of the
15431 It is important to note here, each iCode is assigned a number in the order
15432 of its execution in the function.
15433 The live ranges are computed in terms of these numbers.
15434 The from number is the number of the iCode which first defines the operand
15435 and the to number signifies the iCode which uses this operand last.
15438 Register Allocation
15439 \begin_inset LatexCommand \index{Register allocation}
15446 The register allocation determines the type and number of registers needed
15448 In most MCUs only a few registers can be used for indirect addressing.
15449 In case of 8051 for example the registers R0 & R1 can be used to indirectly
15450 address the internal ram and DPTR to indirectly address the external ram.
15451 The compiler will try to allocate the appropriate register to pointer variables
15453 ICode example section shows the operands annotated with the registers assigned
15455 The compiler will try to keep operands in registers as much as possible;
15456 there are several schemes the compiler uses to do achieve this.
15457 When the compiler runs out of registers the compiler will check to see
15458 if there are any live operands which is not used or defined in the current
15459 basic block being processed, if there are any found then it will push that
15460 operand and use the registers in this block, the operand will then be popped
15461 at the end of the basic block.
15465 There are other MCU specific considerations in this phase.
15466 Some MCUs have an accumulator; very short-lived operands could be assigned
15467 to the accumulator instead of general-purpose register.
15473 Figure II gives a table of iCode operations supported by the compiler.
15474 The code generation involves translating these operations into corresponding
15475 assembly code for the processor.
15476 This sounds overly simple but that is the essence of code generation.
15477 Some of the iCode operations are generated on a MCU specific manner for
15478 example, the z80 port does not use registers to pass parameters so the
15479 SEND and RECV iCode operations will not be generated, and it also does
15480 not support JUMPTABLES.
15487 <Where is Figure II ?>
15491 \begin_inset LatexCommand \index{iCode}
15498 This section shows some details of iCode.
15499 The example C code does not do anything useful; it is used as an example
15500 to illustrate the intermediate code generated by the compiler.
15512 /* This function does nothing useful.
15519 for the purpose of explaining iCode */
15522 short function (data int *x)
15530 short i=10; /* dead initialization eliminated */
15535 short sum=10; /* dead initialization eliminated */
15548 while (*x) *x++ = *p++;
15562 /* compiler detects i,j to be induction variables */
15566 for (i = 0, j = 10 ; i < 10 ; i++, j
15592 mul += i * 3; /* this multiplication remains */
15598 gint += j * 3;/* this multiplication changed to addition */
15612 In addition to the operands each iCode contains information about the filename
15613 and line it corresponds to in the source file.
15614 The first field in the listing should be interpreted as follows:
15619 Filename(linenumber: iCode Execution sequence number : ICode hash table
15620 key : loop depth of the iCode).
15625 Then follows the human readable form of the ICode operation.
15626 Each operand of this triplet form can be of three basic types a) compiler
15627 generated temporary b) user defined variable c) a constant value.
15628 Note that local variables and parameters are replaced by compiler generated
15631 \begin_inset LatexCommand \index{Live range analysis}
15635 are computed only for temporaries (i.e.
15636 live ranges are not computed for global variables).
15638 \begin_inset LatexCommand \index{Register allocation}
15642 are allocated for temporaries only.
15643 Operands are formatted in the following manner:
15648 Operand Name [lr live-from : live-to ] { type information } [ registers
15654 As mentioned earlier the live ranges are computed in terms of the execution
15655 sequence number of the iCodes, for example
15657 the iTemp0 is live from (i.e.
15658 first defined in iCode with execution sequence number 3, and is last used
15659 in the iCode with sequence number 5).
15660 For induction variables such as iTemp21 the live range computation extends
15661 the lifetime from the start to the end of the loop.
15663 The register allocator used the live range information to allocate registers,
15664 the same registers may be used for different temporaries if their live
15665 ranges do not overlap, for example r0 is allocated to both iTemp6 and to
15666 iTemp17 since their live ranges do not overlap.
15667 In addition the allocator also takes into consideration the type and usage
15668 of a temporary, for example itemp6 is a pointer to near space and is used
15669 as to fetch data from (i.e.
15670 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer registers (r0).
15671 Some short lived temporaries are allocated to special registers which have
15672 meaning to the code generator e.g.
15673 iTemp13 is allocated to a pseudo register CC which tells the back end that
15674 the temporary is used only for a conditional jump the code generation makes
15675 use of this information to optimize a compare and jump ICode.
15677 There are several loop optimizations
15678 \begin_inset LatexCommand \index{Loop optimization}
15682 performed by the compiler.
15683 It can detect induction variables iTemp21(i) and iTemp23(j).
15684 Also note the compiler does selective strength reduction
15685 \begin_inset LatexCommand \index{Strength reduction}
15690 the multiplication of an induction variable in line 18 (gint = j * 3) is
15691 changed to addition, a new temporary iTemp17 is allocated and assigned
15692 a initial value, a constant 3 is then added for each iteration of the loop.
15693 The compiler does not change the multiplication
15694 \begin_inset LatexCommand \index{Multiplication}
15698 in line 17 however since the processor does support an 8 * 8 bit multiplication.
15700 Note the dead code elimination
15701 \begin_inset LatexCommand \index{Dead-code elimination}
15705 optimization eliminated the dead assignments in line 7 & 8 to I and sum
15713 Sample.c (5:1:0:0) _entry($9) :
15718 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
15723 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
15728 Sample.c(11:4:53:0) preHeaderLbl0($11) :
15733 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
15739 Sample.c(11:6:5:1) _whilecontinue_0($1) :
15744 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
15750 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
15755 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
15761 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
15767 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
15773 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
15779 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
15780 * int}[r0] + 0x2 {short}
15785 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
15790 Sample.c(11:17:21:0)_whilebreak_0($3) :
15795 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
15800 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
15805 Sample.c(15:20:54:0)preHeaderLbl1($13) :
15810 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
15815 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
15820 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
15825 Sample.c(15:24:26:1)_forcond_0($4) :
15830 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
15836 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
15841 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
15842 + ITemp21 [lr21:38]{short}[r4]
15847 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
15853 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
15854 + iTemp15 [lr29:30]{short}[r1]
15859 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
15865 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
15871 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
15877 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
15883 Sample.c(19:38:47:1) goto _forcond_0($4)
15888 Sample.c(19:39:48:0)_forbreak_0($7) :
15893 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
15894 + ITemp11 [lr19:40]{short}[r3]
15899 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
15904 Sample.c(20:42:51:0)_return($8) :
15909 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
15915 Finally the code generated for this function:
15956 ; ----------------------------------------------
15961 ; function function
15966 ; ----------------------------------------------
15976 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
15988 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
16000 ;_whilecontinue_0($1) :
16010 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
16015 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
16074 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
16093 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
16140 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
16180 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
16206 ; iTemp6 [lr5:16]{_near * int}[r0] =
16211 ; iTemp6 [lr5:16]{_near * int}[r0] +
16228 ; goto _whilecontinue_0($1)
16240 ; _whilebreak_0($3) :
16250 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
16262 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
16274 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
16286 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
16305 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
16334 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
16339 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
16384 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
16389 ; iTemp21 [lr21:38]{short}[r4]
16415 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
16448 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
16453 ; iTemp15 [lr29:30]{short}[r1]
16472 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
16519 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
16566 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
16578 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
16592 cjne r5,#0xff,00104$
16604 ; goto _forcond_0($4)
16616 ; _forbreak_0($7) :
16626 ; ret iTemp24 [lr40:41]{short}
16669 A few words about basic block successors, predecessors and dominators
16672 Successors are basic blocks
16673 \begin_inset LatexCommand \index{Basic blocks}
16677 that might execute after this basic block.
16679 Predecessors are basic blocks that might execute before reaching this basic
16682 Dominators are basic blocks that WILL execute before reaching this basic
16708 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
16711 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
16714 c) domVect of [BB4] = BB1 ...
16715 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
16723 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
16733 Thanks to all the other volunteer developers who have helped with coding,
16734 testing, web-page creation, distribution sets, etc.
16735 You know who you are :-)
16742 This document was initially written by Sandeep Dutta
16745 All product names mentioned herein may be trademarks
16746 \begin_inset LatexCommand \index{Trademarks}
16750 of their respective companies.
16757 To avoid confusion, the installation and building options for sdcc itself
16758 (chapter 2) are not part of the index.
16762 \begin_inset LatexCommand \printindex{}