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
5202 \begin_inset LatexCommand \index{Options Z80}
5207 \begin_inset LatexCommand \index{Z80 options}
5213 \labelwidthstring 00.00.0000
5230 \begin_inset LatexCommand \index{-\/-callee-saves-bc}
5240 Force a called function to always save BC.
5242 \labelwidthstring 00.00.0000
5259 \begin_inset LatexCommand \index{-\/-no-std-crt0}
5263 When linking, skip the standard crt0.o object file.
5264 You must provide your own crt0.o for your system when linking.
5266 \layout Subsubsection
5268 Optimization Options
5269 \begin_inset LatexCommand \index{Options optimization}
5274 \begin_inset LatexCommand \index{Optimization options}
5280 \labelwidthstring 00.00.0000
5295 \begin_inset LatexCommand \index{-\/-nogcse}
5301 Will not do global subexpression elimination, this option may be used when
5302 the compiler creates undesirably large stack/data spaces to store compiler
5304 A warning message will be generated when this happens and the compiler
5305 will indicate the number of extra bytes it allocated.
5306 It recommended that this option NOT be used, #pragma\SpecialChar ~
5308 \begin_inset LatexCommand \index{\#pragma NOGCSE}
5312 can be used to turn off global subexpression elimination
5313 \begin_inset LatexCommand \index{Subexpression elimination}
5317 for a given function only.
5319 \labelwidthstring 00.00.0000
5334 \begin_inset LatexCommand \index{-\/-noinvariant}
5340 Will not do loop invariant optimizations, this may be turned off for reasons
5341 explained for the previous option.
5342 For more details of loop optimizations performed see section Loop Invariants.It
5343 recommended that this option NOT be used, #pragma\SpecialChar ~
5345 \begin_inset LatexCommand \index{\#pragma NOINVARIANT}
5349 can be used to turn off invariant optimizations for a given function only.
5351 \labelwidthstring 00.00.0000
5366 \begin_inset LatexCommand \index{-\/-noinduction}
5372 Will not do loop induction optimizations, see section strength reduction
5373 for more details.It is recommended that this option is NOT used, #pragma\SpecialChar ~
5376 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
5380 can be used to turn off induction optimizations for a given function only.
5382 \labelwidthstring 00.00.0000
5397 \begin_inset LatexCommand \index{-\/-nojtbound}
5408 Will not generate boundary condition check when switch statements
5409 \begin_inset LatexCommand \index{switch statement}
5413 are implemented using jump-tables.
5414 See section Switch Statements for more details.
5415 It is recommended that this option is NOT used, #pragma\SpecialChar ~
5417 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
5421 can be used to turn off boundary checking for jump tables for a given function
5424 \labelwidthstring 00.00.0000
5439 \begin_inset LatexCommand \index{-\/-noloopreverse}
5448 Will not do loop reversal
5449 \begin_inset LatexCommand \index{Loop reversing}
5455 \labelwidthstring 00.00.0000
5472 \begin_inset LatexCommand \index{-\/-nolabelopt }
5476 Will not optimize labels (makes the dumpfiles more readable).
5478 \labelwidthstring 00.00.0000
5493 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
5499 Will not memcpy initialized data in far space from code space.
5500 This saves a few bytes in code space if you don't have initialized data.
5501 \layout Subsubsection
5504 \begin_inset LatexCommand \index{Options other}
5510 \labelwidthstring 00.00.0000
5526 \begin_inset LatexCommand \index{-\/-compile-only}
5531 \begin_inset LatexCommand \index{-c -\/-compile-only}
5537 will compile and assemble the source, but will not call the linkage editor.
5539 \labelwidthstring 00.00.0000
5558 \begin_inset LatexCommand \index{-\/-c1mode}
5564 reads the preprocessed source from standard input and compiles it.
5565 The file name for the assembler output must be specified using the -o option.
5567 \labelwidthstring 00.00.0000
5572 \begin_inset LatexCommand \index{-E}
5578 Run only the C preprocessor.
5579 Preprocess all the C source files specified and output the results to standard
5582 \labelwidthstring 00.00.0000
5588 \begin_inset LatexCommand \index{-o <path/file>}
5594 The output path resp.
5595 file where everything will be placed.
5596 If the parameter is a path, it must have a trailing slash (or backslash
5597 for the Windows binaries) to be recognized as a path.
5600 \labelwidthstring 00.00.0000
5615 \begin_inset LatexCommand \index{-\/-stack-auto}
5626 All functions in the source file will be compiled as
5631 \begin_inset LatexCommand \index{reentrant}
5636 the parameters and local variables will be allocated on the stack
5637 \begin_inset LatexCommand \index{stack}
5642 see section Parameters and Local Variables for more details.
5643 If this option is used all source files in the project should be compiled
5647 \labelwidthstring 00.00.0000
5662 \begin_inset LatexCommand \index{-\/-xstack}
5668 Uses a pseudo stack in the first 256 bytes in the external ram for allocating
5669 variables and passing parameters.
5670 See section on external stack for more details.
5672 \labelwidthstring 00.00.0000
5687 \begin_inset LatexCommand \index{-\/-callee-saves}
5692 \begin_inset LatexCommand \index{function prologue}
5696 function1[,function2][,function3]....
5699 The compiler by default uses a caller saves convention for register saving
5700 across function calls, however this can cause unnecessary register pushing
5701 & popping when calling small functions from larger functions.
5702 This option can be used to switch the register saving convention for the
5703 function names specified.
5704 The compiler will not save registers when calling these functions, no extra
5705 code will be generated at the entry & exit for these functions to save
5706 & restore the registers used by these functions, this can SUBSTANTIALLY
5707 reduce code & improve run time performance of the generated code.
5708 In the future the compiler (with inter procedural analysis) will be able
5709 to determine the appropriate scheme to use for each function call.
5710 DO NOT use this option for built-in functions such as _mulint..., if this
5711 option is used for a library function the appropriate library function
5712 needs to be recompiled with the same option.
5713 If the project consists of multiple source files then all the source file
5714 should be compiled with the same -
5724 -callee-saves option string.
5725 Also see #pragma\SpecialChar ~
5727 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
5733 \labelwidthstring 00.00.0000
5748 \begin_inset LatexCommand \index{-\/-debug}
5757 When this option is used the compiler will generate debug information, that
5758 can be used with the SDCDB.
5759 The debug information is collected in a file with .cdb extension.
5760 For more information see documentation for SDCDB.
5762 \labelwidthstring 00.00.0000
5779 \begin_inset LatexCommand \index{-\/-peep-file}
5783 <filename> This option can be used to use additional rules to be used by
5784 the peep hole optimizer.
5785 See section Peep Hole optimizations for details on how to write these rules.
5787 \labelwidthstring 00.00.0000
5792 \begin_inset LatexCommand \index{-S}
5803 Stop after the stage of compilation proper; do not assemble.
5804 The output is an assembler code file for the input file specified.
5806 \labelwidthstring 00.00.0000
5810 -Wa_asmOption[,asmOption]
5813 \begin_inset LatexCommand \index{-Wa\_asmOption[,asmOption]}
5818 Pass the asmOption to the assembler.
5820 \labelwidthstring 00.00.0000
5824 -Wl_linkOption[,linkOption]
5827 \begin_inset LatexCommand \index{-Wl\_linkOption[,linkOption]}
5832 Pass the linkOption to the linker.
5834 \labelwidthstring 00.00.0000
5849 \begin_inset LatexCommand \index{-\/-int-long-reent}
5855 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
5856 Note by default these libraries are compiled as non-reentrant.
5857 See section Installation for more details.
5859 \labelwidthstring 00.00.0000
5874 \begin_inset LatexCommand \index{-\/-cyclomatic}
5883 This option will cause the compiler to generate an information message for
5884 each function in the source file.
5885 The message contains some
5889 information about the function.
5890 The number of edges and nodes the compiler detected in the control flow
5891 graph of the function, and most importantly the
5893 cyclomatic complexity
5894 \begin_inset LatexCommand \index{Cyclomatic complexity}
5900 see section on Cyclomatic Complexity for more details.
5902 \labelwidthstring 00.00.0000
5917 \begin_inset LatexCommand \index{-\/-float-reent}
5926 Floating point library is compiled as reentrant
5927 \begin_inset LatexCommand \index{reentrant}
5931 .See section Installation for more details.
5933 \labelwidthstring 00.00.0000
5948 \begin_inset LatexCommand \index{-\/-nooverlay}
5954 The compiler will not overlay parameters and local variables of any function,
5955 see section Parameters and local variables for more details.
5957 \labelwidthstring 00.00.0000
5972 \begin_inset LatexCommand \index{-\/-main-return}
5978 This option can be used when the code generated is called by a monitor
5980 The compiler will generate a 'ret' upon return from the 'main'
5981 \begin_inset LatexCommand \index{main return}
5986 The default option is to lock up i.e.
5989 \labelwidthstring 00.00.0000
6004 \begin_inset LatexCommand \index{-\/-no-peep}
6010 Disable peep-hole optimization.
6012 \labelwidthstring 00.00.0000
6027 \begin_inset LatexCommand \index{-\/-peep-asm}
6033 Pass the inline assembler code through the peep hole optimizer.
6034 This can cause unexpected changes to inline assembler code, please go through
6035 the peephole optimizer
6036 \begin_inset LatexCommand \index{Peephole optimizer}
6040 rules defined in the source file tree '<target>/peeph.def' before using
6043 \labelwidthstring 00.00.0000
6060 \begin_inset LatexCommand \index{-\/-iram-size<Value>}
6064 Causes the linker to check if the internal ram usage is within limits of
6067 \labelwidthstring 00.00.0000
6084 \begin_inset LatexCommand \index{-\/-xram-size<Value>}
6088 Causes the linker to check if the external ram usage is within limits of
6091 \labelwidthstring 00.00.0000
6108 \begin_inset LatexCommand \index{-\/-code-size<Value>}
6112 Causes the linker to check if the code usage is within limits of the given
6115 \labelwidthstring 00.00.0000
6130 \begin_inset LatexCommand \index{-\/-nostdincl}
6136 This will prevent the compiler from passing on the default include path
6137 to the preprocessor.
6139 \labelwidthstring 00.00.0000
6154 \begin_inset LatexCommand \index{-\/-nostdlib}
6160 This will prevent the compiler from passing on the default library
6161 \begin_inset LatexCommand \index{Libraries}
6167 \labelwidthstring 00.00.0000
6182 \begin_inset LatexCommand \index{-\/-verbose}
6188 Shows the various actions the compiler is performing.
6190 \labelwidthstring 00.00.0000
6195 \begin_inset LatexCommand \index{-V}
6201 Shows the actual commands the compiler is executing.
6203 \labelwidthstring 00.00.0000
6218 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
6224 Hides your ugly and inefficient c-code from the asm file, so you can always
6225 blame the compiler :).
6227 \labelwidthstring 00.00.0000
6242 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
6248 Include i-codes in the asm file.
6249 Sounds like noise but is most helpful for debugging the compiler itself.
6251 \labelwidthstring 00.00.0000
6266 \begin_inset LatexCommand \index{-\/-less-pedantic}
6272 Disable some of the more pedantic warnings (jwk burps: please be more specific
6275 \labelwidthstring 00.00.0000
6290 \begin_inset LatexCommand \index{-\/-print-search-dirs}
6296 Display the directories in the compiler's search path
6298 \labelwidthstring 00.00.0000
6313 \begin_inset LatexCommand \index{-\/-vc}
6319 Display errors and warnings using MSVC style, so you can use SDCC with
6322 \labelwidthstring 00.00.0000
6337 \begin_inset LatexCommand \index{-\/-use-stdout}
6343 Send errors and warnings to stdout instead of stderr
6344 \layout Subsubsection
6346 Intermediate Dump Options
6347 \begin_inset LatexCommand \index{Options intermediate dump}
6352 \begin_inset LatexCommand \index{Intermediate dump options}
6359 The following options are provided for the purpose of retargetting and debugging
6361 These provided a means to dump the intermediate code (iCode
6362 \begin_inset LatexCommand \index{iCode}
6366 ) generated by the compiler in human readable form at various stages of
6367 the compilation process.
6370 \labelwidthstring 00.00.0000
6385 \begin_inset LatexCommand \index{-\/-dumpraw}
6391 This option will cause the compiler to dump the intermediate code into
6394 <source filename>.dumpraw
6396 just after the intermediate code has been generated for a function, i.e.
6397 before any optimizations are done.
6399 \begin_inset LatexCommand \index{Basic blocks}
6403 at this stage ordered in the depth first number, so they may not be in
6404 sequence of execution.
6406 \labelwidthstring 00.00.0000
6421 \begin_inset LatexCommand \index{-\/-dumpgcse}
6427 Will create a dump of iCode's, after global subexpression elimination
6428 \begin_inset LatexCommand \index{Global subexpression elimination}
6434 <source filename>.dumpgcse.
6436 \labelwidthstring 00.00.0000
6451 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
6457 Will create a dump of iCode's, after deadcode elimination
6458 \begin_inset LatexCommand \index{Dead-code elimination}
6464 <source filename>.dumpdeadcode.
6466 \labelwidthstring 00.00.0000
6481 \begin_inset LatexCommand \index{-\/-dumploop}
6490 Will create a dump of iCode's, after loop optimizations
6491 \begin_inset LatexCommand \index{Loop optimization}
6497 <source filename>.dumploop.
6499 \labelwidthstring 00.00.0000
6514 \begin_inset LatexCommand \index{-\/-dumprange}
6523 Will create a dump of iCode's, after live range analysis
6524 \begin_inset LatexCommand \index{Live range analysis}
6530 <source filename>.dumprange.
6532 \labelwidthstring 00.00.0000
6547 \begin_inset LatexCommand \index{-\/-dumlrange}
6553 Will dump the life ranges
6554 \begin_inset LatexCommand \index{Live range analysis}
6560 \labelwidthstring 00.00.0000
6575 \begin_inset LatexCommand \index{-\/-dumpregassign}
6584 Will create a dump of iCode's, after register assignment
6585 \begin_inset LatexCommand \index{Register assignment}
6591 <source filename>.dumprassgn.
6593 \labelwidthstring 00.00.0000
6608 \begin_inset LatexCommand \index{-\/-dumplrange}
6614 Will create a dump of the live ranges of iTemp's
6616 \labelwidthstring 00.00.0000
6631 \begin_inset LatexCommand \index{-\/-dumpall}
6642 Will cause all the above mentioned dumps to be created.
6645 Environment variables
6646 \begin_inset LatexCommand \index{Environment variables}
6653 SDCC recognizes the following environment variables:
6655 \labelwidthstring 00.00.0000
6660 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
6666 SDCC installs a signal handler
6667 \begin_inset LatexCommand \index{signal handler}
6671 to be able to delete temporary files after an user break (^C) or an exception.
6672 If this environment variable is set, SDCC won't install the signal handler
6673 in order to be able to debug SDCC.
6675 \labelwidthstring 00.00.0000
6680 \begin_inset LatexCommand \index{TMP}
6686 \begin_inset LatexCommand \index{TEMP}
6692 \begin_inset LatexCommand \index{TMPDIR}
6698 Path, where temporary files will be created.
6699 The order of the variables is the search order.
6700 In a standard *nix environment these variables are not set, and there's
6701 no need to set them.
6702 On Windows it's recommended to set one of them.
6704 \labelwidthstring 00.00.0000
6709 \begin_inset LatexCommand \index{SDCC\_HOME}
6716 \begin_inset Quotes sld
6719 2.3 Install and search paths
6720 \begin_inset Quotes srd
6725 \labelwidthstring 00.00.0000
6730 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
6737 \begin_inset Quotes sld
6740 2.3 Install and search paths
6741 \begin_inset Quotes srd
6746 \labelwidthstring 00.00.0000
6751 \begin_inset LatexCommand \index{SDCC\_LIB}
6758 \begin_inset Quotes sld
6761 2.3 Install and search paths
6762 \begin_inset Quotes srd
6768 There are some more environment variables recognized by SDCC, but these
6769 are solely used for debugging purposes.
6770 They can change or disappear very quickly, and will never be documented.
6773 MCS51/DS390 Storage Class
6774 \begin_inset LatexCommand \index{Storage class}
6781 In addition to the ANSI storage classes SDCC allows the following MCS51
6782 specific storage classes.
6783 \layout Subsubsection
6786 \begin_inset LatexCommand \index{xdata}
6793 Variables declared with this storage class will be placed in the extern
6799 storage class for Large Memory model, e.g.:
6804 xdata unsigned char xduc;
6805 \layout Subsubsection
6808 \begin_inset LatexCommand \index{data}
6819 storage class for Small Memory model.
6820 Variables declared with this storage class will be allocated in the internal
6827 \layout Subsubsection
6830 \begin_inset LatexCommand \index{idata}
6837 Variables declared with this storage class will be allocated into the indirectly
6838 addressable portion of the internal ram of a 8051, e.g.:
6844 \layout Subsubsection
6847 \begin_inset LatexCommand \index{bit}
6854 This is a data-type and a storage class specifier.
6855 When a variable is declared as a bit, it is allocated into the bit addressable
6856 memory of 8051, e.g.:
6862 \layout Subsubsection
6865 \begin_inset LatexCommand \index{sfr}
6870 \begin_inset LatexCommand \index{sbit}
6877 Like the bit keyword,
6881 signifies both a data-type and storage class, they are used to describe
6882 the special function registers and special bit variables of a 8051, eg:
6887 sfr at 0x80 P0; /* special function register P0 at location 0x80 */
6889 sbit at 0xd7 CY; /* CY (Carry Flag
6890 \begin_inset LatexCommand \index{Flags}
6895 \begin_inset LatexCommand \index{Carry flag}
6903 \begin_inset LatexCommand \index{Pointers}
6910 SDCC allows (via language extensions) pointers to explicitly point to any
6911 of the memory spaces
6912 \begin_inset LatexCommand \index{Memory model}
6917 In addition to the explicit pointers, the compiler uses (by default) generic
6918 pointers which can be used to point to any of the memory spaces.
6922 Pointer declaration examples:
6927 /* pointer physically in xternal ram pointing to object in internal ram
6930 data unsigned char * xdata p;
6934 /* pointer physically in code rom pointing to data in xdata space */
6936 xdata unsigned char * code p;
6940 /* pointer physically in code space pointing to data in code space */
6942 code unsigned char * code p;
6946 /* the following is a generic pointer physically located in xdata space
6952 Well you get the idea.
6957 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
6970 The highest order byte of the
6974 pointers contains the data space information.
6975 Assembler support routines are called whenever data is stored or retrieved
6981 These are useful for developing reusable library
6982 \begin_inset LatexCommand \index{Libraries}
6987 Explicitly specifying the pointer type will generate the most efficient
6992 \begin_inset LatexCommand \index{Parameters}
6997 \begin_inset LatexCommand \index{Local variable}
7004 Automatic (local) variables and parameters to functions can either be placed
7005 on the stack or in data-space.
7006 The default action of the compiler is to place these variables in the internal
7007 RAM (for small model) or external RAM (for large model).
7008 This in fact makes them
7011 \begin_inset LatexCommand \index{static}
7017 so by default functions are non-reentrant
7018 \begin_inset LatexCommand \index{reentrant}
7026 They can be placed on the stack
7027 \begin_inset LatexCommand \index{stack}
7044 \begin_inset LatexCommand \index{-\/-stack-auto}
7050 option or by using the
7053 \begin_inset LatexCommand \index{reentrant}
7059 keyword in the function declaration, e.g.:
7064 unsigned char foo(char i) reentrant
7074 Since stack space on 8051 is limited, the
7092 option should be used sparingly.
7093 Note that the reentrant keyword just means that the parameters & local
7094 variables will be allocated to the stack, it
7098 mean that the function is register bank independent.
7102 Local variables can be assigned storage classes and absolute
7103 \begin_inset LatexCommand \index{Absolute addressing}
7112 unsigned char foo() {
7118 xdata unsigned char i;
7130 data at 0x31 unsigned char j;
7142 In the above example the variable
7146 will be allocated in the external ram,
7150 in bit addressable space and
7169 or when a function is declared as
7173 this should only be done for static variables.
7176 Parameters however are not allowed any storage class, (storage classes for
7177 parameters will be ignored), their allocation is governed by the memory
7178 model in use, and the reentrancy options.
7182 \begin_inset LatexCommand \index{Overlaying}
7190 \begin_inset LatexCommand \index{reentrant}
7194 functions SDCC will try to reduce internal ram space usage by overlaying
7195 parameters and local variables of a function (if possible).
7196 Parameters and local variables of a function will be allocated to an overlayabl
7197 e segment if the function has
7199 no other function calls and the function is non-reentrant and the memory
7201 \begin_inset LatexCommand \index{Memory model}
7208 If an explicit storage class
7209 \begin_inset LatexCommand \index{Storage class}
7213 is specified for a local variable, it will NOT be overlayed.
7216 Note that the compiler (not the linkage editor) makes the decision for overlayin
7218 Functions that are called from an interrupt service routine should be preceded
7219 by a #pragma\SpecialChar ~
7221 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
7225 if they are not reentrant.
7228 Also note that the compiler does not do any processing of inline
7229 \begin_inset LatexCommand \index{inline}
7233 assembler code, so the compiler might incorrectly assign local variables
7234 and parameters of a function into the overlay segment if the inline assembler
7235 code calls other c-functions that might use the overlay.
7236 In that case the #pragma\SpecialChar ~
7237 NOOVERLAY should be used.
7240 Parameters and Local variables of functions that contain 16 or 32 bit multiplica
7242 \begin_inset LatexCommand \index{Multiplication}
7247 \begin_inset LatexCommand \index{Division}
7251 will NOT be overlayed since these are implemented using external functions,
7260 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
7266 void set_error(unsigned char errcd)
7282 void some_isr () interrupt
7283 \begin_inset LatexCommand \index{interrupt}
7288 \begin_inset LatexCommand \index{using}
7318 In the above example the parameter
7326 would be assigned to the overlayable segment if the #pragma\SpecialChar ~
7328 not present, this could cause unpredictable runtime behavior when called
7330 The #pragma\SpecialChar ~
7331 NOOVERLAY ensures that the parameters and local variables for
7332 the function are NOT overlayed.
7335 Interrupt Service Routines
7338 SDCC allows interrupt service routines to be coded in C, with some extended
7344 void timer_isr (void) interrupt 2 using 1
7354 The number following the
7357 \begin_inset LatexCommand \index{interrupt}
7363 keyword is the interrupt number this routine will service.
7364 The compiler will insert a call to this routine in the interrupt vector
7365 table for the interrupt number specified.
7370 keyword is used to tell the compiler to use the specified register bank
7371 (8051 specific) when generating code for this function.
7372 Note that when some function is called from an interrupt service routine
7373 it should be preceded by a #pragma\SpecialChar ~
7375 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
7379 if it is not reentrant.
7380 A special note here, int (16 bit) and long (32 bit) integer division
7381 \begin_inset LatexCommand \index{Division}
7386 \begin_inset LatexCommand \index{Multiplication}
7391 \begin_inset LatexCommand \index{Modulus}
7395 operations are implemented using external support routines developed in
7396 ANSI-C, if an interrupt service routine needs to do any of these operations
7397 then the support routines (as mentioned in a following section) will have
7398 to be recompiled using the
7411 \begin_inset LatexCommand \index{-\/-stack-auto}
7417 option and the source file will need to be compiled using the
7432 \begin_inset LatexCommand \index{-\/-int-long-rent}
7439 If you have multiple source files in your project, interrupt service routines
7440 can be present in any of them, but a prototype of the isr MUST be present
7441 or included in the file that contains the function
7448 Interrupt Numbers and the corresponding address & descriptions for the Standard
7449 8051 are listed below.
7450 SDCC will automatically adjust the interrupt vector table to the maximum
7451 interrupt number specified.
7457 \begin_inset Tabular
7458 <lyxtabular version="3" rows="6" columns="3">
7460 <column alignment="center" valignment="top" leftline="true" width="0in">
7461 <column alignment="center" valignment="top" leftline="true" width="0in">
7462 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0in">
7463 <row topline="true" bottomline="true">
7464 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7472 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7480 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7489 <row topline="true">
7490 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7498 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7506 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7515 <row topline="true">
7516 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7532 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7541 <row topline="true">
7542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7550 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7558 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7567 <row topline="true">
7568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7576 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7584 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7593 <row topline="true" bottomline="true">
7594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7602 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7610 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7628 If the interrupt service routine is defined without
7631 \begin_inset LatexCommand \index{using}
7637 a register bank or with register bank 0 (using 0), the compiler will save
7638 the registers used by itself on the stack upon entry and restore them at
7639 exit, however if such an interrupt service routine calls another function
7640 then the entire register bank will be saved on the stack.
7641 This scheme may be advantageous for small interrupt service routines which
7642 have low register usage.
7645 If the interrupt service routine is defined to be using a specific register
7650 are save and restored, if such an interrupt service routine calls another
7651 function (using another register bank) then the entire register bank of
7652 the called function will be saved on the stack.
7653 This scheme is recommended for larger interrupt service routines.
7656 Calling other functions from an interrupt service routine is not recommended,
7657 avoid it if possible.
7661 Also see the _naked modifier.
7669 <TODO: this isn't implemented at all!>
7675 A special keyword may be associated with a function declaring it as
7680 SDCC will generate code to disable all interrupts upon entry to a critical
7681 function and enable them back before returning.
7682 Note that nesting critical functions may cause unpredictable results.
7700 The critical attribute maybe used with other attributes like
7706 \begin_inset LatexCommand \index{Naked functions}
7713 A special keyword may be associated with a function declaring it as
7716 \begin_inset LatexCommand \index{\_naked}
7727 function modifier attribute prevents the compiler from generating prologue
7728 \begin_inset LatexCommand \index{function prologue}
7733 \begin_inset LatexCommand \index{function epilogue}
7737 code for that function.
7738 This means that the user is entirely responsible for such things as saving
7739 any registers that may need to be preserved, selecting the proper register
7740 bank, generating the
7744 instruction at the end, etc.
7745 Practically, this means that the contents of the function must be written
7746 in inline assembler.
7747 This is particularly useful for interrupt functions, which can have a large
7748 (and often unnecessary) prologue/epilogue.
7749 For example, compare the code generated by these two functions:
7754 data unsigned char counter;
7756 void simpleInterrupt(void) interrupt
7757 \begin_inset LatexCommand \index{interrupt}
7775 void nakedInterrupt(void) interrupt 2 _naked
7784 \begin_inset LatexCommand \index{\_asm}
7813 ; MUST explicitly include ret in _naked function.
7820 \begin_inset LatexCommand \index{\_endasm}
7829 For an 8051 target, the generated simpleInterrupt looks like:
7970 whereas nakedInterrupt looks like:
7994 ; MUST explicitly include ret(i) in _naked function.
7997 While there is nothing preventing you from writing C code inside a _naked
7998 function, there are many ways to shoot yourself in the foot doing this,
7999 and it is recommended that you stick to inline assembler.
8002 Functions using private banks
8003 \begin_inset LatexCommand \index{bank}
8013 \begin_inset LatexCommand \index{using}
8019 attribute (which tells the compiler to use a register bank other than the
8020 default bank zero) should only be applied to
8023 \begin_inset LatexCommand \index{interrupt}
8029 functions (see note 1 below).
8030 This will in most circumstances make the generated ISR code more efficient
8031 since it will not have to save registers on the stack.
8038 attribute will have no effect on the generated code for a
8042 function (but may occasionally be useful anyway
8048 possible exception: if a function is called ONLY from 'interrupt' functions
8049 using a particular bank, it can be declared with the same 'using' attribute
8050 as the calling 'interrupt' functions.
8051 For instance, if you have several ISRs using bank one, and all of them
8052 call memcpy(), it might make sense to create a specialized version of memcpy()
8053 'using 1', since this would prevent the ISR from having to save bank zero
8054 to the stack on entry and switch to bank zero before calling the function
8061 (pending: I don't think this has been done yet)
8068 function using a non-zero bank will assume that it can trash that register
8069 bank, and will not save it.
8070 Since high-priority interrupts
8071 \begin_inset LatexCommand \index{interrupt priority}
8075 can interrupt low-priority ones on the 8051 and friends, this means that
8076 if a high-priority ISR
8080 a particular bank occurs while processing a low-priority ISR
8084 the same bank, terrible and bad things can happen.
8085 To prevent this, no single register bank should be
8089 by both a high priority and a low priority ISR.
8090 This is probably most easily done by having all high priority ISRs use
8091 one bank and all low priority ISRs use another.
8092 If you have an ISR which can change priority at runtime, you're on your
8093 own: I suggest using the default bank zero and taking the small performance
8097 It is most efficient if your ISR calls no other functions.
8098 If your ISR must call other functions, it is most efficient if those functions
8099 use the same bank as the ISR (see note 1 below); the next best is if the
8100 called functions use bank zero.
8101 It is very inefficient to call a function using a different, non-zero bank
8107 \begin_inset LatexCommand \index{Absolute addressing}
8114 Data items can be assigned an absolute address with the
8117 \begin_inset LatexCommand \index{at}
8123 keyword, in addition to a storage class, e.g.:
8129 \begin_inset LatexCommand \index{xdata}
8134 \begin_inset LatexCommand \index{at}
8138 0x8000 unsigned char PORTA_8255 ;
8141 In the above example the PORTA_8255 will be allocated to the location 0x8000
8142 of the external ram.
8143 Note that this feature is provided to give the programmer access to
8147 devices attached to the controller.
8148 The compiler does not actually reserve any space for variables declared
8149 in this way (they are implemented with an equate in the assembler).
8150 Thus it is left to the programmer to make sure there are no overlaps with
8151 other variables that are declared without the absolute address.
8152 The assembler listing file (.lst
8153 \begin_inset LatexCommand \index{.lst}
8157 ) and the linker output files (.rst
8158 \begin_inset LatexCommand \index{.rst}
8163 \begin_inset LatexCommand \index{.map}
8167 ) are a good places to look for such overlaps.
8171 Absolute address can be specified for variables in all storage classes,
8178 \begin_inset LatexCommand \index{bit}
8183 \begin_inset LatexCommand \index{at}
8190 The above example will allocate the variable at offset 0x02 in the bit-addressab
8192 There is no real advantage to assigning absolute addresses to variables
8193 in this manner, unless you want strict control over all the variables allocated.
8194 One possible use would be to write hardware portable code.
8195 For example, if you have a routine that uses one or more of the microcontroller
8196 I/O pins, and such pins are different for two different hardwares, you
8197 can declare the I/O pins in you routine using
8210 void DS1306_put(unsigned char value)
8218 unsigned char mask=0x80;
8242 SDI=(value & mask)?1:0;
8283 Then, someplace in the code for the first hardware you would use
8288 bit at 0x80 SDI;\SpecialChar ~
8292 /*I/O port 0, bit 0*/
8294 bit at 0x81 SCLK;\SpecialChar ~
8297 /*I/O port 0, bit 1*/
8299 bit CPOL;\SpecialChar ~
8310 /*This is a variable, let the linker allocate this one*/
8313 Similarly, for the second hardware you would use
8318 bit at 0x83 SDI;\SpecialChar ~
8322 /*I/O port 0, bit 3*/
8324 bit at 0x91 SCLK;\SpecialChar ~
8327 /*I/O port 1, bit 1*/
8329 bit CPOL;\SpecialChar ~
8340 /*This is a variable, let the linker allocate this one*/
8343 and you can use the same hardware dependent routine without changes, as
8344 for example in a library.
8345 This is somehow similar to sbit, but only one absolute address has to be
8346 specified in the whole project.
8350 \begin_inset LatexCommand \index{Startup code}
8357 The compiler inserts a call to the C routine
8359 _sdcc_external_startup()
8360 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
8369 at the start of the CODE area.
8370 This routine is in the runtime library
8371 \begin_inset LatexCommand \index{Runtime library}
8376 By default this routine returns 0, if this routine returns a non-zero value,
8377 the static & global variable initialization will be skipped and the function
8378 main will be invoked Other wise static & global variables will be initialized
8379 before the function main is invoked.
8382 _sdcc_external_startup()
8384 routine to your program to override the default if you need to setup hardware
8385 or perform some other critical operation prior to static & global variable
8389 Inline Assembler Code
8390 \begin_inset LatexCommand \index{Assembler routines}
8397 SDCC allows the use of in-line assembler with a few restriction as regards
8399 All labels defined within inline assembler code
8407 where nnnn is a number less than 100 (which implies a limit of utmost 100
8408 inline assembler labels
8416 It is strongly recommended that each assembly instruction (including labels)
8417 be placed in a separate line (as the example shows).
8431 \begin_inset LatexCommand \index{-\/-peep-asm}
8437 command line option is used, the inline assembler code will be passed through
8438 the peephole optimizer
8439 \begin_inset LatexCommand \index{Peephole optimizer}
8444 This might cause some unexpected changes in the inline assembler code.
8445 Please go through the peephole optimizer rules defined in file
8449 carefully before using this option.
8455 \begin_inset LatexCommand \index{\_asm}
8485 \begin_inset LatexCommand \index{\_endasm}
8492 The inline assembler code can contain any valid code understood by the assembler
8493 , this includes any assembler directives and comment lines.
8494 The compiler does not do any validation of the code within the
8504 Inline assembler code cannot reference any C-Labels, however it can reference
8506 \begin_inset LatexCommand \index{Labels}
8510 defined by the inline assembler, e.g.:
8535 ; some assembler code
8555 /* some more c code */
8557 clabel:\SpecialChar ~
8559 /* inline assembler cannot reference this label */
8571 $0003: ;label (can be reference by inline assembler only)
8583 /* some more c code */
8588 In other words inline assembly code can access labels defined in inline
8589 assembly within the scope of the function.
8590 The same goes the other way, ie.
8591 labels defines in inline assembly CANNOT be accessed by C statements.
8595 \begin_inset LatexCommand \index{int (16 bit)}
8600 \begin_inset LatexCommand \index{long (32 bit)}
8607 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
8608 multiplication and modulus operations are implemented by support routines.
8609 These support routines are all developed in ANSI-C to facilitate porting
8610 to other MCUs, although some model specific assembler optimizations are
8612 The following files contain the described routine, all of them can be found
8613 in <installdir>/share/sdcc/lib.
8619 \begin_inset Tabular
8620 <lyxtabular version="3" rows="11" columns="2">
8622 <column alignment="center" valignment="top" leftline="true" width="0(null)">
8623 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
8624 <row topline="true" bottomline="true">
8625 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8635 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
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 16 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 16 bit division (calls _divuint)
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 16 bit 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 16 bit modulus (calls _moduint)
8718 <row topline="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 16 bit modulus
8736 <row topline="true">
8737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8745 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8750 32 bit multiplication
8754 <row topline="true">
8755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8763 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8768 signed 32 division (calls _divulong)
8772 <row topline="true">
8773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8781 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8786 unsigned 32 division
8790 <row topline="true">
8791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8804 signed 32 bit modulus (calls _modulong)
8808 <row topline="true" bottomline="true">
8809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8817 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8822 unsigned 32 bit modulus
8835 Since they are compiled as
8840 \begin_inset LatexCommand \index{reentrant}
8845 \begin_inset LatexCommand \index{interrupt}
8849 service routines should not do any of the above operations.
8850 If this is unavoidable then the above routines will need to be compiled
8864 \begin_inset LatexCommand \index{-\/-stack-auto}
8870 option, after which the source program will have to be compiled with
8883 \begin_inset LatexCommand \index{-\/-int-long-rent}
8890 Notice that you don't have to call this routines directly.
8891 The compiler will use them automatically every time a integer operation
8895 Floating Point Support
8896 \begin_inset LatexCommand \index{Floating point support}
8903 SDCC supports IEEE (single precision 4 bytes) floating point numbers.The
8904 floating point support routines are derived from gcc's floatlib.c and consists
8905 of the following routines:
8913 \begin_inset Tabular
8914 <lyxtabular version="3" rows="17" columns="2">
8916 <column alignment="center" valignment="top" leftline="true" width="0(null)">
8917 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
8918 <row topline="true" bottomline="true">
8919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8936 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8945 <row topline="true">
8946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8963 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8977 add floating point numbers
8981 <row topline="true">
8982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8999 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9013 subtract floating point numbers
9017 <row topline="true">
9018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9035 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9049 divide floating point numbers
9053 <row topline="true">
9054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9071 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9085 multiply floating point numbers
9089 <row topline="true">
9090 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9107 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9121 convert floating point to unsigned char
9125 <row topline="true">
9126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9143 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9157 convert floating point to signed char
9161 <row topline="true">
9162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9179 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9193 convert floating point to unsigned int
9197 <row topline="true">
9198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9215 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9229 convert floating point to signed int
9233 <row topline="true">
9234 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9260 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9274 convert floating point to unsigned long
9278 <row topline="true">
9279 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9310 convert floating point to signed long
9314 <row topline="true">
9315 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9332 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9346 convert unsigned char to floating point
9350 <row topline="true">
9351 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9368 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9382 convert char to floating point number
9386 <row topline="true">
9387 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9418 convert unsigned int to floating point
9422 <row topline="true">
9423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9440 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9454 convert int to floating point numbers
9458 <row topline="true">
9459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9476 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9490 convert unsigned long to floating point number
9494 <row topline="true" bottomline="true">
9495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9512 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9526 convert long to floating point number
9539 Note if all these routines are used simultaneously the data space might
9541 For serious floating point usage it is strongly recommended that the large
9543 Also notice that you don't have to call this routines directly.
9544 The compiler will use them automatically every time a floating point operation
9549 \begin_inset LatexCommand \index{Memory model}
9554 \begin_inset LatexCommand \index{MCS51 memory}
9561 SDCC allows two memory models for MCS51 code, small and large.
9562 Modules compiled with different memory models should
9566 be combined together or the results would be unpredictable.
9567 The library routines supplied with the compiler are compiled as both small
9569 The compiled library modules are contained in separate directories as small
9570 and large so that you can link to either set.
9574 When the large model is used all variables declared without a storage class
9575 will be allocated into the external ram, this includes all parameters and
9576 local variables (for non-reentrant
9577 \begin_inset LatexCommand \index{reentrant}
9582 When the small model is used variables without storage class are allocated
9583 in the internal ram.
9586 Judicious usage of the processor specific storage classes
9587 \begin_inset LatexCommand \index{Storage class}
9591 and the 'reentrant' function type will yield much more efficient code,
9592 than using the large model.
9593 Several optimizations are disabled when the program is compiled using the
9594 large model, it is therefore strongly recommended that the small model
9595 be used unless absolutely required.
9599 \begin_inset LatexCommand \index{Memory model}
9604 \begin_inset LatexCommand \index{DS390 memory model}
9611 The only model supported is Flat 24
9612 \begin_inset LatexCommand \index{Flat 24 (memory model)}
9617 This generates code for the 24 bit contiguous addressing mode of the Dallas
9619 In this mode, up to four meg of external RAM or code space can be directly
9621 See the data sheets at www.dalsemi.com for further information on this part.
9625 In older versions of the compiler, this option was used with the MCS51 code
9631 Now, however, the '390 has it's own code generator, selected by the
9640 Note that the compiler does not generate any code to place the processor
9641 into 24 bitmode (although
9645 in the ds390 libraries will do that for you).
9651 \begin_inset LatexCommand \index{Tinibios (DS390)}
9655 , the boot loader or similar code must ensure that the processor is in 24
9656 bit contiguous addressing mode before calling the SDCC startup code.
9674 option, variables will by default be placed into the XDATA segment.
9679 Segments may be placed anywhere in the 4 meg address space using the usual
9691 Note that if any segments are located above 64K, the -r flag must be passed
9692 to the linker to generate the proper segment relocations, and the Intel
9693 HEX output format must be used.
9694 The -r flag can be passed to the linker by using the option
9698 on the sdcc command line.
9699 However, currently the linker can not handle code segments > 64k.
9702 Defines Created by the Compiler
9703 \begin_inset LatexCommand \index{Defines created by the compiler}
9710 The compiler creates the following #defines
9711 \begin_inset LatexCommand \index{\#defines}
9721 \begin_inset Tabular
9722 <lyxtabular version="3" rows="10" columns="2">
9724 <column alignment="center" valignment="top" leftline="true" width="0(null)">
9725 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
9726 <row topline="true" bottomline="true">
9727 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9748 <row topline="true">
9749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9755 \begin_inset LatexCommand \index{SDCC}
9762 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9767 this Symbol is always defined
9771 <row topline="true">
9772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9778 \begin_inset LatexCommand \index{SDCC\_mcs51}
9783 \begin_inset LatexCommand \index{SDCC\_ds390}
9788 \begin_inset LatexCommand \index{SDCC\_z80}
9795 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9800 depending on the model used (e.g.: -mds390
9804 <row topline="true">
9805 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9811 \begin_inset LatexCommand \index{\_\_mcs51}
9816 \begin_inset LatexCommand \index{\_\_ds390}
9821 \begin_inset LatexCommand \index{\_\_z80}
9828 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9833 depending on the model used (e.g.
9838 <row topline="true">
9839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9845 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
9852 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9875 <row topline="true">
9876 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9882 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
9889 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9912 <row topline="true">
9913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9919 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
9926 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9949 <row topline="true">
9950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9956 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
9963 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9986 <row topline="true">
9987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9993 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
10000 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10013 <row topline="true" bottomline="true">
10014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10020 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
10027 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10049 Redirecting output on Windows Shells
10052 By default SDCC writes it's error messages to
10053 \begin_inset Quotes sld
10057 \begin_inset Quotes srd
10061 To force all messages to
10062 \begin_inset Quotes sld
10066 \begin_inset Quotes srd
10090 \begin_inset LatexCommand \index{-\/-use-stdout}
10095 Aditionaly, if you happen to have visual studio installed in your windows
10096 machine, you can use it to compile your sources using a custom build and
10112 \begin_inset LatexCommand \index{-\/-vc}
10117 Something like this should work:
10161 -model-large -c $(InputPath)
10164 SDCC Technical Data
10168 \begin_inset LatexCommand \index{Optimizations}
10175 SDCC performs a host of standard optimizations in addition to some MCU specific
10178 \layout Subsubsection
10180 Sub-expression Elimination
10181 \begin_inset LatexCommand \index{Subexpression elimination}
10188 The compiler does local and global common subexpression elimination, e.g.:
10199 will be translated to
10211 Some subexpressions are not as obvious as the above example, e.g.:
10221 In this case the address arithmetic a->b[i] will be computed only once;
10222 the equivalent code in C would be.
10234 The compiler will try to keep these temporary variables in registers.
10235 \layout Subsubsection
10237 Dead-Code Elimination
10238 \begin_inset LatexCommand \index{Dead-code elimination}
10257 i = 1; \SpecialChar ~
10262 global = 1;\SpecialChar ~
10275 global = 3;\SpecialChar ~
10286 int global; void f ()
10299 \layout Subsubsection
10302 \begin_inset LatexCommand \index{Copy propagation}
10358 Note: the dead stores created by this copy propagation will be eliminated
10359 by dead-code elimination.
10360 \layout Subsubsection
10363 \begin_inset LatexCommand \index{Loop optimization}
10370 Two types of loop optimizations are done by SDCC loop invariant lifting
10371 and strength reduction of loop induction variables.
10372 In addition to the strength reduction the optimizer marks the induction
10373 variables and the register allocator tries to keep the induction variables
10374 in registers for the duration of the loop.
10375 Because of this preference of the register allocator
10376 \begin_inset LatexCommand \index{Register allocation}
10380 , loop induction optimization causes an increase in register pressure, which
10381 may cause unwanted spilling of other temporary variables into the stack
10382 \begin_inset LatexCommand \index{stack}
10387 The compiler will generate a warning message when it is forced to allocate
10388 extra space either on the stack or data space.
10389 If this extra space allocation is undesirable then induction optimization
10390 can be eliminated either for the entire source file (with -
10400 -noinduction option) or for a given function only using #pragma\SpecialChar ~
10402 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
10415 for (i = 0 ; i < 100 ; i ++)
10429 for (i = 0; i < 100; i++)
10436 As mentioned previously some loop invariants are not as apparent, all static
10437 address computations are also moved out of the loop.
10442 \begin_inset LatexCommand \index{Strength reduction}
10446 , this optimization substitutes an expression by a cheaper expression:
10451 for (i=0;i < 100; i++)
10467 for (i=0;i< 100;i++) {
10473 ar[itemp1] = itemp2;
10490 The more expensive multiplication
10491 \begin_inset LatexCommand \index{Multiplication}
10495 is changed to a less expensive addition.
10496 \layout Subsubsection
10499 \begin_inset LatexCommand \index{Loop reversing}
10506 This optimization is done to reduce the overhead of checking loop boundaries
10507 for every iteration.
10508 Some simple loops can be reversed and implemented using a
10509 \begin_inset Quotes eld
10512 decrement and jump if not zero
10513 \begin_inset Quotes erd
10517 SDCC checks for the following criterion to determine if a loop is reversible
10518 (note: more sophisticated compilers use data-dependency analysis to make
10519 this determination, SDCC uses a more simple minded analysis).
10522 The 'for' loop is of the form
10528 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
10538 The <for body> does not contain
10539 \begin_inset Quotes eld
10543 \begin_inset Quotes erd
10547 \begin_inset Quotes erd
10553 All goto's are contained within the loop.
10556 No function calls within the loop.
10559 The loop control variable <sym> is not assigned any value within the loop
10562 The loop control variable does NOT participate in any arithmetic operation
10566 There are NO switch statements in the loop.
10567 \layout Subsubsection
10569 Algebraic Simplifications
10572 SDCC does numerous algebraic simplifications, the following is a small sub-set
10573 of these optimizations.
10578 i = j + 0 ; /* changed to */ i = j;
10580 i /= 2; /* changed to */ i >>= 1;
10582 i = j - j ; /* changed to */ i = 0;
10584 i = j / 1 ; /* changed to */ i = j;
10587 Note the subexpressions
10588 \begin_inset LatexCommand \index{Subexpression}
10592 given above are generally introduced by macro expansions or as a result
10593 of copy/constant propagation.
10594 \layout Subsubsection
10596 'switch' Statements
10597 \begin_inset LatexCommand \index{switch statement}
10604 SDCC changes switch statements to jump tables
10605 \begin_inset LatexCommand \index{jump tables}
10609 when the following conditions are true.
10613 The case labels are in numerical sequence, the labels need not be in order,
10614 and the starting number need not be one or zero.
10620 switch(i) {\SpecialChar ~
10651 case 4: ...\SpecialChar ~
10683 case 5: ...\SpecialChar ~
10715 case 3: ...\SpecialChar ~
10747 case 6: ...\SpecialChar ~
10815 Both the above switch statements will be implemented using a jump-table.
10819 The number of case labels is at least three, since it takes two conditional
10820 statements to handle the boundary conditions.
10823 The number of case labels is less than 84, since each label takes 3 bytes
10824 and a jump-table can be utmost 256 bytes long.
10828 Switch statements which have gaps in the numeric sequence or those that
10829 have more that 84 case labels can be split into more than one switch statement
10830 for efficient code generation, e.g.:
10880 If the above switch statement is broken down into two switch statements
10919 case 9: \SpecialChar ~
10935 case 12:\SpecialChar ~
10942 then both the switch statements will be implemented using jump-tables whereas
10943 the unmodified switch statement will not be.
10944 \layout Subsubsection
10946 Bit-shifting Operations
10947 \begin_inset LatexCommand \index{Bit shifting}
10954 Bit shifting is one of the most frequently used operation in embedded programmin
10956 SDCC tries to implement bit-shift operations in the most efficient way
10972 generates the following code:
10986 In general SDCC will never setup a loop if the shift count is known.
11018 Note that SDCC stores numbers in little-endian format (i.e.
11019 lowest order first).
11020 \layout Subsubsection
11023 \begin_inset LatexCommand \index{Bit rotation}
11030 A special case of the bit-shift operation is bit rotation, SDCC recognizes
11031 the following expression to be a left bit-rotation:
11041 i = ((i << 1) | (i >> 7));
11050 will generate the following code:
11062 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
11063 ns of this case will also be recognized as bit-rotation, i.e.:
11068 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
11069 \layout Subsubsection
11072 \begin_inset LatexCommand \index{Highest Order Bit}
11079 It is frequently required to obtain the highest order bit of an integral
11080 type (long, int, short or char types).
11081 SDCC recognizes the following expression to yield the highest order bit
11082 and generates optimized code for it, e.g.:
11102 hob = (gint >> 15) & 1;
11112 will generate the following code:
11145 000A E5*01\SpecialChar ~
11171 000C 33\SpecialChar ~
11200 000D E4\SpecialChar ~
11229 000E 13\SpecialChar ~
11258 000F F5*02\SpecialChar ~
11285 Variations of this case however will
11290 It is a standard C expression, so I heartily recommend this be the only
11291 way to get the highest order bit, (it is portable).
11292 Of course it will be recognized even if it is embedded in other expressions,
11298 xyz = gint + ((gint >> 15) & 1);
11301 will still be recognized.
11302 \layout Subsubsection
11305 \begin_inset LatexCommand \index{Peephole optimizer}
11312 The compiler uses a rule based, pattern matching and re-writing mechanism
11313 for peep-hole optimization.
11318 a peep-hole optimizer by Christopher W.
11319 Fraser (cwfraser@microsoft.com).
11320 A default set of rules are compiled into the compiler, additional rules
11321 may be added with the
11334 \begin_inset LatexCommand \index{-\/-peep-file}
11341 The rule language is best illustrated with examples.
11365 The above rule will change the following assembly
11366 \begin_inset LatexCommand \index{Assembler routines}
11388 Note: All occurrences of a
11392 (pattern variable) must denote the same string.
11393 With the above rule, the assembly sequence:
11403 will remain unmodified.
11407 Other special case optimizations may be added by the user (via
11423 some variants of the 8051 MCU allow only
11432 The following two rules will change all
11451 replace { lcall %1 } by { acall %1 }
11453 replace { ljmp %1 } by { ajmp %1 }
11458 inline-assembler code
11460 is also passed through the peep hole optimizer, thus the peephole optimizer
11461 can also be used as an assembly level macro expander.
11462 The rules themselves are MCU dependent whereas the rule language infra-structur
11463 e is MCU independent.
11464 Peephole optimization rules for other MCU can be easily programmed using
11469 The syntax for a rule is as follows:
11474 rule := replace [ restart ] '{' <assembly sequence> '
11512 <assembly sequence> '
11530 '}' [if <functionName> ] '
11535 <assembly sequence> := assembly instruction (each instruction including
11536 labels must be on a separate line).
11540 The optimizer will apply to the rules one by one from the top in the sequence
11541 of their appearance, it will terminate when all rules are exhausted.
11542 If the 'restart' option is specified, then the optimizer will start matching
11543 the rules again from the top, this option for a rule is expensive (performance)
11544 , it is intended to be used in situations where a transformation will trigger
11545 the same rule again.
11546 An example of this (not a good one, it has side effects) is the following
11569 Note that the replace pattern cannot be a blank, but can be a comment line.
11570 Without the 'restart' option only the inner most 'pop' 'push' pair would
11571 be eliminated, i.e.:
11601 the restart option the rule will be applied again to the resulting code
11602 and then all the pop-push pairs will be eliminated to yield:
11612 A conditional function can be attached to a rule.
11613 Attaching rules are somewhat more involved, let me illustrate this with
11640 The optimizer does a look-up of a function name table defined in function
11645 in the source file SDCCpeeph.c, with the name
11650 If it finds a corresponding entry the function is called.
11651 Note there can be no parameters specified for these functions, in this
11656 is crucial, since the function
11660 expects to find the label in that particular variable (the hash table containin
11661 g the variable bindings is passed as a parameter).
11662 If you want to code more such functions, take a close look at the function
11663 labelInRange and the calling mechanism in source file SDCCpeeph.c.
11664 I know this whole thing is a little kludgey, but maybe some day we will
11665 have some better means.
11666 If you are looking at this file, you will also see the default rules that
11667 are compiled into the compiler, you can add your own rules in the default
11668 set there if you get tired of specifying the -
11682 \begin_inset LatexCommand \index{Pragmas}
11689 SDCC supports the following #pragma directives.
11693 \begin_inset LatexCommand \index{\#pragma SAVE}
11697 - this will save all current options to the SAVE/RESTORE stack.
11702 \begin_inset LatexCommand \index{\#pragma RESTORE}
11706 - will restore saved options from the last save.
11707 SAVEs & RESTOREs can be nested.
11708 SDCC uses a SAVE/RESTORE stack: SAVE pushes current options to the stack,
11709 RESTORE pulls current options from the stack.
11714 \begin_inset LatexCommand \index{\#pragma NOGCSE}
11718 - will stop global subexpression elimination.
11722 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
11726 - will stop loop induction optimizations.
11730 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
11734 - will not generate code for boundary value checking, when switch statements
11735 are turned into jump-tables.
11739 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
11743 - the compiler will not overlay the parameters and local variables of a
11748 \begin_inset LatexCommand \index{\#pragma LESS\_PEDANTIC}
11752 - the compiler will not warn you anymore for obvious mistakes, you'r on
11757 \begin_inset LatexCommand \index{\#pragma NOLOOPREVERSE}
11761 - Will not do loop reversal optimization
11765 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
11769 NONE | {acc[,b[,dpl[,dph]]] - The exclude pragma disables generation of
11771 \begin_inset LatexCommand \index{push/pop}
11775 instruction in ISR function (using interrupt
11776 \begin_inset LatexCommand \index{interrupt}
11781 The directive should be placed immediately before the ISR function definition
11782 and it affects ALL ISR functions following it.
11783 To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
11784 EXCLUDE\SpecialChar ~
11786 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
11794 \begin_inset LatexCommand \index{\#pragma NOIV}
11798 - Do not generate interrupt vector table entries for all ISR functions
11799 defined after the pragma.
11800 This is useful in cases where the interrupt vector table must be defined
11801 manually, or when there is a secondary, manually defined interrupt vector
11803 for the autovector feature of the Cypress EZ-USB FX2).
11807 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
11812 \begin_inset LatexCommand \index{function prologue}
11816 function1[,function2[,function3...]] - The compiler by default uses a caller
11817 saves convention for register saving across function calls, however this
11818 can cause unnecessary register pushing & popping when calling small functions
11819 from larger functions.
11820 This option can be used to switch off the register saving convention for
11821 the function names specified.
11822 The compiler will not save registers when calling these functions, extra
11823 code need to be manually inserted at the entry & exit for these functions
11824 to save & restore the registers used by these functions, this can SUBSTANTIALLY
11825 reduce code & improve run time performance of the generated code.
11826 In the future the compiler (with inter procedural analysis) may be able
11827 to determine the appropriate scheme to use for each function call.
11838 -callee-saves command line option is used, the function names specified
11839 in #pragma\SpecialChar ~
11841 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
11845 is appended to the list of functions specified in the command line.
11848 The pragma's are intended to be used to turn-off certain optimizations which
11849 might cause the compiler to generate extra stack / data space to store
11850 compiler generated temporary variables.
11851 This usually happens in large functions.
11852 Pragma directives should be used as shown in the following example, they
11853 are used to control options & optimizations for a given function; pragmas
11854 should be placed before and/or after a function, placing pragma's inside
11855 a function body could have unpredictable results.
11861 \begin_inset LatexCommand \index{\#pragma SAVE}
11865 /* save the current settings */
11868 \begin_inset LatexCommand \index{\#pragma NOGCSE}
11872 /* turnoff global subexpression elimination */
11874 #pragma NOINDUCTION
11875 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
11879 /* turn off induction optimizations */
11902 \begin_inset LatexCommand \index{\#pragma RESTORE}
11906 /* turn the optimizations back on */
11909 The compiler will generate a warning message when extra space is allocated.
11910 It is strongly recommended that the SAVE and RESTORE pragma's be used when
11911 changing options for a function.
11916 <pending: this is messy and incomplete>
11921 Compiler support routines (_gptrget, _mulint etc)
11924 Stdclib functions (puts, printf, strcat etc)
11927 Math functions (sin, pow, sqrt etc)
11930 license statements for the libraries are missing
11933 Interfacing with Assembly Routines
11934 \begin_inset LatexCommand \index{Assembler routines}
11939 \layout Subsubsection
11941 Global Registers used for Parameter Passing
11942 \begin_inset LatexCommand \index{Parameter passing}
11949 The compiler always uses the global registers
11952 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
11957 \begin_inset LatexCommand \index{B (register)}
11966 \begin_inset LatexCommand \index{ACC}
11972 to pass the first parameter to a routine.
11973 The second parameter onwards is either allocated on the stack (for reentrant
11984 -stack-auto is used) or in the internal / external ram (depending on the
11987 \layout Subsubsection
11989 Assembler Routine(non-reentrant
11990 \begin_inset LatexCommand \index{reentrant}
11995 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
12002 In the following example the function c_func calls an assembler routine
12003 asm_func, which takes two parameters.
12008 extern int asm_func(unsigned char, unsigned char);
12012 int c_func (unsigned char i, unsigned char j)
12020 return asm_func(i,j);
12034 return c_func(10,9);
12039 The corresponding assembler function is:
12044 .globl _asm_func_PARM_2
12108 add a,_asm_func_PARM_2
12133 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
12150 Note here that the return values are placed in 'dpl' - One byte return value,
12151 'dpl' LSB & 'dph' MSB for two byte values.
12152 'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
12153 b' & 'acc' for four byte values.
12156 The parameter naming convention is _<function_name>_PARM_<n>, where n is
12157 the parameter number starting from 1, and counting from the left.
12158 The first parameter is passed in
12159 \begin_inset Quotes eld
12163 \begin_inset Quotes erd
12166 for One bye parameter,
12167 \begin_inset Quotes eld
12171 \begin_inset Quotes erd
12175 \begin_inset Quotes eld
12179 \begin_inset Quotes erd
12182 for three bytes and
12183 \begin_inset Quotes eld
12187 \begin_inset Quotes erd
12190 for four bytes, the variable name for the second parameter will be _<function_n
12195 Assemble the assembler routine with the following command:
12202 asx8051 -losg asmfunc.asm
12209 Then compile and link the assembler routine to the C source file with the
12217 sdcc cfunc.c asmfunc.rel
12218 \layout Subsubsection
12220 Assembler Routine(reentrant
12221 \begin_inset LatexCommand \index{reentrant}
12226 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
12233 In this case the second parameter onwards will be passed on the stack, the
12234 parameters are pushed from right to left i.e.
12235 after the call the left most parameter will be on the top of the stack.
12236 Here is an example:
12241 extern int asm_func(unsigned char, unsigned char);
12245 int c_func (unsigned char i, unsigned char j) reentrant
12253 return asm_func(i,j);
12267 return c_func(10,9);
12272 The corresponding assembler routine is:
12378 The compiling and linking procedure remains the same, however note the extra
12379 entry & exit linkage required for the assembler code, _bp is the stack
12380 frame pointer and is used to compute the offset into the stack for parameters
12381 and local variables.
12385 \begin_inset LatexCommand \index{stack}
12390 \begin_inset LatexCommand \index{External stack}
12397 The external stack is located at the start of the external ram segment,
12398 and is 256 bytes in size.
12409 -xstack option is used to compile the program, the parameters and local
12410 variables of all reentrant functions are allocated in this area.
12411 This option is provided for programs with large stack space requirements.
12412 When used with the -
12422 -stack-auto option, all parameters and local variables are allocated on
12423 the external stack (note support libraries will need to be recompiled with
12427 The compiler outputs the higher order address byte of the external ram segment
12428 into PORT P2, therefore when using the External Stack option, this port
12429 MAY NOT be used by the application program.
12433 \begin_inset LatexCommand \index{ANSI-compliance}
12440 Deviations from the compliance:
12443 functions are not always reentrant.
12446 structures cannot be assigned values directly, cannot be passed as function
12447 parameters or assigned to each other and cannot be a return value from
12474 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
12485 struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
12507 return rets;/* is invalid in SDCC although allowed in ANSI */
12514 \begin_inset LatexCommand \index{long long (not supported)}
12519 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
12527 \begin_inset LatexCommand \index{double (not supported)}
12531 ' precision floating point
12532 \begin_inset LatexCommand \index{Floating point support}
12539 No support for setjmp and longjmp (for now).
12543 \begin_inset LatexCommand \index{K\&R style}
12547 function declarations are NOT allowed.
12553 foo(i,j) /* this old style of function declarations */
12555 int i,j; /* are valid in ANSI but not valid in SDCC */
12570 functions declared as pointers must be dereferenced during the call.
12581 /* has to be called like this */
12583 (*foo)(); /* ANSI standard allows calls to be made like 'foo()' */
12587 Cyclomatic Complexity
12588 \begin_inset LatexCommand \index{Cyclomatic complexity}
12595 Cyclomatic complexity of a function is defined as the number of independent
12596 paths the program can take during execution of the function.
12597 This is an important number since it defines the number test cases you
12598 have to generate to validate the function.
12599 The accepted industry standard for complexity number is 10, if the cyclomatic
12600 complexity reported by SDCC exceeds 10 you should think about simplification
12601 of the function logic.
12602 Note that the complexity level is not related to the number of lines of
12603 code in a function.
12604 Large functions can have low complexity, and small functions can have large
12610 SDCC uses the following formula to compute the complexity:
12615 complexity = (number of edges in control flow graph) - (number of nodes
12616 in control flow graph) + 2;
12620 Having said that the industry standard is 10, you should be aware that in
12621 some cases it be may unavoidable to have a complexity level of less than
12623 For example if you have switch statement with more than 10 case labels,
12624 each case label adds one to the complexity level.
12625 The complexity level is by no means an absolute measure of the algorithmic
12626 complexity of the function, it does however provide a good starting point
12627 for which functions you might look at for further optimization.
12633 Here are a few guidelines that will help the compiler generate more efficient
12634 code, some of the tips are specific to this compiler others are generally
12635 good programming practice.
12638 Use the smallest data type to represent your data-value.
12639 If it is known in advance that the value is going to be less than 256 then
12640 use an 'unsigned char' instead of a 'short' or 'int'.
12643 Use unsigned when it is known in advance that the value is not going to
12645 This helps especially if you are doing division or multiplication.
12648 NEVER jump into a LOOP.
12651 Declare the variables to be local whenever possible, especially loop control
12652 variables (induction).
12655 Since the compiler does not always do implicit integral promotion, the programme
12656 r should do an explicit cast when integral promotion is required.
12659 Reducing the size of division, multiplication & modulus operations can reduce
12660 code size substantially.
12661 Take the following code for example.
12667 foobar(unsigned int p1, unsigned char ch)
12675 unsigned char ch1 = p1 % ch ;
12686 For the modulus operation the variable ch will be promoted to unsigned int
12687 first then the modulus operation will be performed (this will lead to a
12688 call to support routine _moduint()), and the result will be casted to a
12690 If the code is changed to
12695 foobar(unsigned int p1, unsigned char ch)
12703 unsigned char ch1 = (unsigned char)p1 % ch ;
12714 It would substantially reduce the code generated (future versions of the
12715 compiler will be smart enough to detect such optimization opportunities).
12719 Notes on MCS51 memory
12720 \begin_inset LatexCommand \index{MCS51 memory}
12727 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12728 RAM memory which is structured as follows
12732 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
12735 - Bytes 20-2F - 16 bytes to hold 128 bit variables and,
12737 - Bytes 30-7F - 80 bytes for general purpose use.
12742 Additionally some members of the MCS51 family may have up to 128 bytes of
12743 additional, indirectly addressable, internal RAM memory (
12748 Furthermore, some chips may have some built in external memory (
12752 ) which should not be confused with the internal, directly addressable RAM
12758 Usually this built in
12762 memory has to be activated before using it (you can probably find this
12763 information on the datasheet of the microcontroller your are using).
12766 Normally SDCC will only use the first bank
12767 \begin_inset LatexCommand \index{bank}
12771 of registers (register bank 0), but it is possible to specify that other
12772 banks of registers should be used in interrupt
12773 \begin_inset LatexCommand \index{interrupt}
12778 By default, the compiler will place the stack after the last byte of allocated
12779 memory for variables.
12780 For example, if the first 2 banks of registers are used, and only four
12785 variables, it will position the base of the internal stack at address 20
12787 This implies that as the stack
12788 \begin_inset LatexCommand \index{stack}
12792 grows, it will use up the remaining register banks, and the 16 bytes used
12793 by the 128 bit variables, and 80 bytes for general purpose use.
12794 If any bit variables are used, the data variables will be placed after
12795 the byte holding the last bit variable.
12796 For example, if register banks 0 and 1 are used, and there are 9 bit variables
12801 variables will be placed starting at address 0x22.
12813 \begin_inset LatexCommand \index{-\/-data-loc}
12817 to specify the start address of the
12831 -iram-size to specify the size of the total internal RAM (
12843 By default the 8051 linker will place the stack after the last byte of data
12856 \begin_inset LatexCommand \index{-\/-stack-loc}
12860 allows you to specify the start of the stack, i.e.
12861 you could start it after any data in the general purpose area.
12862 If your microcontroller has additional indirectly addressable internal
12867 ) you can place the stack on it.
12868 You may also need to use -
12879 \begin_inset LatexCommand \index{-\/-data-loc}
12883 to set the start address of the external RAM (
12898 \begin_inset LatexCommand \index{-\/-data-loc}
12902 to specify its size.
12903 Same goes for the code memory, using -
12914 \begin_inset LatexCommand \index{-\/-data-loc}
12929 \begin_inset LatexCommand \index{-\/-data-loc}
12934 If in doubt, don't specify any options and see if the resulting memory
12935 layout is appropriate, then you can adjust it.
12938 The 8051 linker generates two files with memory allocation information.
12939 The first, with extension .map shows all the variables and segments.
12940 The second with extension .mem shows the final memory layout.
12941 The linker will complaint either if memory segments overlap, there is not
12942 enough memory, or there is not enough space for stack.
12943 If you get any linking warnings and/or errors related to stack or segments
12944 allocation, take a look at either the .map or .mem files to find out what
12946 The .mem file may even suggest a solution to the problem.
12950 \begin_inset LatexCommand \index{Tools}
12954 included in the distribution
12960 \begin_inset Tabular
12961 <lyxtabular version="3" rows="12" columns="3">
12963 <column alignment="center" valignment="top" leftline="true" width="0pt">
12964 <column alignment="center" valignment="top" leftline="true" width="0pt">
12965 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
12966 <row topline="true" bottomline="true">
12967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12992 <row topline="true">
12993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13006 Simulator for various architectures
13009 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13018 <row topline="true">
13019 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13032 header file conversion
13035 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13040 sdcc/support/scripts
13044 <row topline="true">
13045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13053 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13058 header file conversion
13061 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13066 sdcc/support/scripts
13070 <row topline="true">
13071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13087 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13105 <row topline="true">
13106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13140 <row topline="true">
13141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13157 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13175 <row topline="true">
13176 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13210 <row topline="true">
13211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13227 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13245 <row topline="true">
13246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13262 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13280 <row topline="true">
13281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13315 <row topline="true" bottomline="true">
13316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13332 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13359 Related open source tools
13360 \begin_inset LatexCommand \index{Related tools}
13370 \begin_inset Tabular
13371 <lyxtabular version="3" rows="7" columns="3">
13373 <column alignment="center" valignment="top" leftline="true" width="0pt">
13374 <column alignment="center" valignment="top" leftline="true" width="0pt">
13375 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
13376 <row topline="true" bottomline="true">
13377 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13402 <row topline="true">
13403 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13409 \begin_inset LatexCommand \index{gpsim}
13416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13424 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13430 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
13438 <row topline="true">
13439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13445 \begin_inset LatexCommand \index{srecord}
13452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13457 Object file conversion, checksumming, ...
13460 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13466 \begin_inset LatexCommand \url{http://srecord.sourceforge.net/}
13474 <row topline="true">
13475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13481 \begin_inset LatexCommand \index{objdump}
13488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13493 Object file conversion, ...
13496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13501 Part of binutils (should be there anyway)
13505 <row topline="true">
13506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13512 \begin_inset LatexCommand \index{doxygen}
13519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13524 Source code documentation system
13527 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13533 \begin_inset LatexCommand \url{http://www.doxygen.org}
13541 <row topline="true">
13542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13548 \begin_inset LatexCommand \index{splint}
13555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13560 Statically checks c sources
13563 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13569 \begin_inset LatexCommand \url{http://www.splint.org}
13577 <row topline="true" bottomline="true">
13578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13584 \begin_inset LatexCommand \index{ddd}
13591 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13596 Debugger, serves nicely as GUI to sdcdb
13597 \begin_inset LatexCommand \index{sdcdb}
13604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13610 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
13627 Related documentation / recommended reading
13633 \begin_inset Tabular
13634 <lyxtabular version="3" rows="5" columns="3">
13636 <column alignment="center" valignment="top" leftline="true" width="0pt">
13637 <column alignment="center" valignment="top" leftline="true" width="0pt">
13638 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
13639 <row topline="true" bottomline="true">
13640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13656 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13665 <row topline="true">
13666 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13676 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13681 Advanced Compiler Design and Implementation
13684 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13693 <row topline="true">
13694 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13717 \begin_inset LatexCommand \index{C Reference card}
13724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13730 \begin_inset LatexCommand \url{http://www.refcards.com/about/c.html}
13738 <row topline="true">
13739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13744 test_suite_spec.pdf
13747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13752 sdcc regression test
13753 \begin_inset LatexCommand \index{Regression test}
13760 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13769 <row topline="true" bottomline="true">
13770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13796 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13801 sdcc internal documentation
13804 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13822 Retargetting for other MCUs.
13825 The issues for retargetting the compiler are far too numerous to be covered
13827 What follows is a brief description of each of the seven phases of the
13828 compiler and its MCU dependency.
13831 Parsing the source and building the annotated parse tree.
13832 This phase is largely MCU independent (except for the language extensions).
13833 Syntax & semantic checks are also done in this phase, along with some initial
13834 optimizations like back patching labels and the pattern matching optimizations
13835 like bit-rotation etc.
13838 The second phase involves generating an intermediate code which can be easy
13839 manipulated during the later phases.
13840 This phase is entirely MCU independent.
13841 The intermediate code generation assumes the target machine has unlimited
13842 number of registers, and designates them with the name iTemp.
13843 The compiler can be made to dump a human readable form of the code generated
13857 This phase does the bulk of the standard optimizations and is also MCU independe
13859 This phase can be broken down into several sub-phases:
13863 Break down intermediate code (iCode) into basic blocks.
13865 Do control flow & data flow analysis on the basic blocks.
13867 Do local common subexpression elimination, then global subexpression elimination
13869 Dead code elimination
13873 If loop optimizations caused any changes then do 'global subexpression eliminati
13874 on' and 'dead code elimination' again.
13877 This phase determines the live-ranges; by live range I mean those iTemp
13878 variables defined by the compiler that still survive after all the optimization
13880 Live range analysis
13881 \begin_inset LatexCommand \index{Live range analysis}
13885 is essential for register allocation, since these computation determines
13886 which of these iTemps will be assigned to registers, and for how long.
13889 Phase five is register allocation.
13890 There are two parts to this process.
13894 The first part I call 'register packing' (for lack of a better term).
13895 In this case several MCU specific expression folding is done to reduce
13900 The second part is more MCU independent and deals with allocating registers
13901 to the remaining live ranges.
13902 A lot of MCU specific code does creep into this phase because of the limited
13903 number of index registers available in the 8051.
13906 The Code generation phase is (unhappily), entirely MCU dependent and very
13907 little (if any at all) of this code can be reused for other MCU.
13908 However the scheme for allocating a homogenized assembler operand for each
13909 iCode operand may be reused.
13912 As mentioned in the optimization section the peep-hole optimizer is rule
13913 based system, which can reprogrammed for other MCUs.
13917 \begin_inset LatexCommand \index{sdcdb}
13921 - Source Level Debugger
13922 \begin_inset LatexCommand \index{Debugger}
13929 SDCC is distributed with a source level debugger.
13930 The debugger uses a command line interface, the command repertoire of the
13931 debugger has been kept as close to gdb
13932 \begin_inset LatexCommand \index{gdb}
13936 (the GNU debugger) as possible.
13937 The configuration and build process is part of the standard compiler installati
13938 on, which also builds and installs the debugger in the target directory
13939 specified during configuration.
13940 The debugger allows you debug BOTH at the C source and at the ASM source
13944 Compiling for Debugging
13947 The \SpecialChar \-
13949 debug option must be specified for all files for which debug information
13950 is to be generated.
13951 The complier generates a .adb file for each of these files.
13952 The linker creates the .cdb file from the .adb files and the address information.
13953 This .cdb is used by the debugger.
13956 How the Debugger Works
13969 -debug option is specified the compiler generates extra symbol information
13970 some of which are put into the the assembler source and some are put into
13972 Then the linker creates the .cdb file from the individual .adb files with
13973 the address information for the symbols.
13974 The debugger reads the symbolic information generated by the compiler &
13975 the address information generated by the linker.
13976 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
13977 execution is controlled by the debugger.
13978 When a command is issued for the debugger, it translates it into appropriate
13979 commands for the simulator.
13982 Starting the Debugger
13985 The debugger can be started using the following command line.
13986 (Assume the file you are debugging has the file name foo).
14000 The debugger will look for the following files.
14003 foo.c - the source file.
14006 foo.cdb - the debugger symbol information file.
14009 foo.ihx - the Intel hex format
14010 \begin_inset LatexCommand \index{Intel hex format}
14017 Command Line Options.
14030 -directory=<source file directory> this option can used to specify the directory
14032 The debugger will look into the directory list specified for source, cdb
14034 The items in the directory list must be separated by ':', e.g.
14035 if the source files can be in the directories /home/src1 and /home/src2,
14046 -directory option should be -
14056 -directory=/home/src1:/home/src2.
14057 Note there can be no spaces in the option.
14061 -cd <directory> - change to the <directory>.
14064 -fullname - used by GUI front ends.
14067 -cpu <cpu-type> - this argument is passed to the simulator please see the
14068 simulator docs for details.
14071 -X <Clock frequency > this options is passed to the simulator please see
14072 the simulator docs for details.
14075 -s <serial port file> passed to simulator see the simulator docs for details.
14078 -S <serial in,out> passed to simulator see the simulator docs for details.
14084 As mention earlier the command interface for the debugger has been deliberately
14085 kept as close the GNU debugger gdb, as possible.
14086 This will help the integration with existing graphical user interfaces
14087 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
14088 \layout Subsubsection
14090 break [line | file:line | function | file:function]
14093 Set breakpoint at specified line or function:
14102 sdcdb>break foo.c:100
14104 sdcdb>break funcfoo
14106 sdcdb>break foo.c:funcfoo
14107 \layout Subsubsection
14109 clear [line | file:line | function | file:function ]
14112 Clear breakpoint at specified line or function:
14121 sdcdb>clear foo.c:100
14123 sdcdb>clear funcfoo
14125 sdcdb>clear foo.c:funcfoo
14126 \layout Subsubsection
14131 Continue program being debugged, after breakpoint.
14132 \layout Subsubsection
14137 Execute till the end of the current function.
14138 \layout Subsubsection
14143 Delete breakpoint number 'n'.
14144 If used without any option clear ALL user defined break points.
14145 \layout Subsubsection
14147 info [break | stack | frame | registers ]
14150 info break - list all breakpoints
14153 info stack - show the function call stack.
14156 info frame - show information about the current execution frame.
14159 info registers - show content of all registers.
14160 \layout Subsubsection
14165 Step program until it reaches a different source line.
14166 \layout Subsubsection
14171 Step program, proceeding through subroutine calls.
14172 \layout Subsubsection
14177 Start debugged program.
14178 \layout Subsubsection
14183 Print type information of the variable.
14184 \layout Subsubsection
14189 print value of variable.
14190 \layout Subsubsection
14195 load the given file name.
14196 Note this is an alternate method of loading file for debugging.
14197 \layout Subsubsection
14202 print information about current frame.
14203 \layout Subsubsection
14208 Toggle between C source & assembly source.
14209 \layout Subsubsection
14211 ! simulator command
14214 Send the string following '!' to the simulator, the simulator response is
14216 Note the debugger does not interpret the command being sent to the simulator,
14217 so if a command like 'go' is sent the debugger can loose its execution
14218 context and may display incorrect values.
14219 \layout Subsubsection
14226 My name is Bobby Brown"
14229 Interfacing with XEmacs
14230 \begin_inset LatexCommand \index{XEmacs}
14235 \begin_inset LatexCommand \index{Emacs}
14242 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
14243 sdcdb.el and sdcdbsrc.el.
14244 These two files can be found in the $(prefix)/bin directory after the installat
14246 These files need to be loaded into XEmacs for the interface to work.
14247 This can be done at XEmacs startup time by inserting the following into
14248 your '.xemacs' file (which can be found in your HOME directory):
14254 (load-file sdcdbsrc.el)
14260 .xemacs is a lisp file so the () around the command is REQUIRED.
14261 The files can also be loaded dynamically while XEmacs is running, set the
14262 environment variable 'EMACSLOADPATH' to the installation bin directory
14263 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
14264 To start the interface enter the following command:
14278 You will prompted to enter the file name to be debugged.
14283 The command line options that are passed to the simulator directly are bound
14284 to default values in the file sdcdbsrc.el.
14285 The variables are listed below, these values maybe changed as required.
14288 sdcdbsrc-cpu-type '51
14291 sdcdbsrc-frequency '11059200
14294 sdcdbsrc-serial nil
14297 The following is a list of key mapping for the debugger interface.
14305 ;; Current Listing ::
14307 ;;key\SpecialChar ~
14322 binding\SpecialChar ~
14346 ;;---\SpecialChar ~
14361 ------\SpecialChar ~
14401 sdcdb-next-from-src\SpecialChar ~
14427 sdcdb-back-from-src\SpecialChar ~
14453 sdcdb-cont-from-src\SpecialChar ~
14463 SDCDB continue command
14479 sdcdb-step-from-src\SpecialChar ~
14505 sdcdb-whatis-c-sexp\SpecialChar ~
14515 SDCDB ptypecommand for data at
14579 sdcdbsrc-delete\SpecialChar ~
14593 SDCDB Delete all breakpoints if no arg
14641 given or delete arg (C-u arg x)
14657 sdcdbsrc-frame\SpecialChar ~
14672 SDCDB Display current frame if no arg,
14721 given or display frame arg
14786 sdcdbsrc-goto-sdcdb\SpecialChar ~
14796 Goto the SDCDB output buffer
14812 sdcdb-print-c-sexp\SpecialChar ~
14823 SDCDB print command for data at
14887 sdcdbsrc-goto-sdcdb\SpecialChar ~
14897 Goto the SDCDB output buffer
14913 sdcdbsrc-mode\SpecialChar ~
14929 Toggles Sdcdbsrc mode (turns it off)
14933 ;; C-c C-f\SpecialChar ~
14941 sdcdb-finish-from-src\SpecialChar ~
14949 SDCDB finish command
14953 ;; C-x SPC\SpecialChar ~
14961 sdcdb-break\SpecialChar ~
14979 Set break for line with point
14981 ;; ESC t\SpecialChar ~
14991 sdcdbsrc-mode\SpecialChar ~
15007 Toggle Sdcdbsrc mode
15009 ;; ESC m\SpecialChar ~
15019 sdcdbsrc-srcmode\SpecialChar ~
15043 The Z80 and gbz80 port
15046 SDCC can target both the Zilog Z80 and the Nintendo Gameboy's Z80-like gbz80.
15047 The port is incomplete - long support is incomplete (mul, div and mod are
15048 unimplemented), and both float and bitfield support is missing.
15049 Apart from that the code generated is correct.
15052 As always, the code is the authoritave reference - see z80/ralloc.c and z80/gen.c.
15053 The stack frame is similar to that generated by the IAR Z80 compiler.
15054 IX is used as the base pointer, HL is used as a temporary register, and
15055 BC and DE are available for holding variables.
15056 IY is currently unused.
15057 Return values are stored in HL.
15058 One bad side effect of using IX as the base pointer is that a functions
15059 stack frame is limited to 127 bytes - this will be fixed in a later version.
15063 \begin_inset LatexCommand \index{Support}
15070 SDCC has grown to be a large project.
15071 The compiler alone (without the preprocessor, assembler and linker) is
15072 about 40,000 lines of code (blank stripped).
15073 The open source nature of this project is a key to its continued growth
15075 You gain the benefit and support of many active software developers and
15077 Is SDCC perfect? No, that's why we need your help.
15078 The developers take pride in fixing reported bugs.
15079 You can help by reporting the bugs and helping other SDCC users.
15080 There are lots of ways to contribute, and we encourage you to take part
15081 in making SDCC a great software package.
15085 The SDCC project is hosted on the sdcc sourceforge site at
15086 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
15091 You'll find the complete set of mailing lists
15092 \begin_inset LatexCommand \index{Mailing list}
15096 , forums, bug reporting system, patch submission
15097 \begin_inset LatexCommand \index{Patch submission}
15102 \begin_inset LatexCommand \index{download}
15106 area and cvs code repository
15107 \begin_inset LatexCommand \index{cvs code repository}
15115 \begin_inset LatexCommand \index{Bugs}
15120 \begin_inset LatexCommand \index{Reporting bugs}
15127 The recommended way of reporting bugs is using the infrastructure of the
15129 You can follow the status of bug reports there and have an overview about
15133 Bug reports are automatically forwarded to the developer mailing list and
15134 will be fixed ASAP.
15135 When reporting a bug, it is very useful to include a small test program
15136 (the smaller the better) which reproduces the problem.
15137 If you can isolate the problem by looking at the generated assembly code,
15138 this can be very helpful.
15139 Compiling your program with the -
15150 \begin_inset LatexCommand \index{-\/-dumpall}
15154 option can sometimes be useful in locating optimization problems.
15155 When reporting a bug please maker sure you:
15158 Attach the code you are compiling with SDCC.
15162 Specify the exact command you use to run SDCC, or attach your Makefile.
15166 Specify the SDCC version (type "sdcc -v"), your platform, and operating
15171 Provide an exact copy of any error message or incorrect output.
15175 Put something meaningful in the subject of your message.
15178 Please attempt to include these 5 important parts, as applicable, in all
15179 requests for support or when reporting any problems or bugs with SDCC.
15180 Though this will make your message lengthy, it will greatly improve your
15181 chance that SDCC users and developers will be able to help you.
15182 Some SDCC developers are frustrated by bug reports without code provided
15183 that they can use to reproduce and ultimately fix the problem, so please
15184 be sure to provide sample code if you are reporting a bug!
15187 Please have a short check that you are using a recent version of SDCC and
15188 the bug is not yet known.
15189 This is the link for reporting bugs:
15190 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
15197 Requesting Features
15198 \begin_inset LatexCommand \index{Feature request}
15203 \begin_inset LatexCommand \index{Requesting features}
15210 Like bug reports feature requests are forwarded to the developer mailing
15212 This is the link for requesting features:
15213 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
15223 These links should take you directly to the
15224 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
15234 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
15235 automated messages (mid 2003)
15239 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
15243 , lists and forums are archived so if you are lucky someone already had
15248 \begin_inset LatexCommand \index{Changelog}
15255 You can follow the status of the cvs version
15256 \begin_inset LatexCommand \index{version}
15260 of SDCC by watching the file
15261 \begin_inset LatexCommand \htmlurl[ChangeLog]{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/sdcc/sdcc/ChangeLog?rev=HEAD&content-type=text/plain}
15265 in the cvs-repository.
15269 \begin_inset LatexCommand \index{Release policy}
15276 Historically there often were long delays between official releases and
15277 the sourceforge download area tends to get not updated at all.
15278 Current excuses might refer to problems with live range analysis, but if
15279 this is fixed, the next problem rising is that another excuse will have
15281 Kidding aside, we have to get better there! On the other hand there are
15282 daily snapshots available at
15283 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
15287 , and you can always built the very last version (hopefully with many bugs
15288 fixed, and features added) from the source code available at
15289 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
15297 \begin_inset LatexCommand \index{Examples}
15304 You'll find some small examples in the directory sdcc/device/examples/
15307 Maybe we should include some links to real world applications.
15308 Preferably pointer to pointers (one for each architecture) so this stays
15313 \begin_inset LatexCommand \index{Quality control}
15320 The compiler is passed through nightly compile and build checks.
15326 \begin_inset LatexCommand \index{Regression test}
15330 check that SDCC itself compiles flawlessly on several platforms and checks
15331 the quality of the code generated by SDCC by running the code through simulator
15333 There is a separate document
15336 \begin_inset LatexCommand \index{Test suite}
15345 You'll find the test code in the directory
15347 sdcc/support/regression
15350 You can run these tests manually by running
15354 in this directory (or f.e.
15359 if you don't want to run the complete tests).
15360 The test code might also be interesting if you want to look for examples
15361 \begin_inset LatexCommand \index{Examples}
15365 checking corner cases of SDCC or if you plan to submit patches
15366 \begin_inset LatexCommand \index{Patch submission}
15373 The pic port uses a different set of regression tests, you'll find them
15376 sdcc/src/regression
15382 \begin_inset LatexCommand \index{Compiler internals}
15389 The anatomy of the compiler
15394 This is an excerpt from an article published in Circuit Cellar Magazine
15396 It's a little outdated (the compiler is much more efficient now and user/develo
15397 per friendly), but pretty well exposes the guts of it all.
15403 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
15404 It is fairly easy to retarget for other 8-bit MCU.
15405 Here we take a look at some of the internals of the compiler.
15410 \begin_inset LatexCommand \index{Parsing}
15417 Parsing the input source file and creating an AST (Annotated Syntax Tree
15418 \begin_inset LatexCommand \index{Annotated syntax tree}
15423 This phase also involves propagating types (annotating each node of the
15424 parse tree with type information) and semantic analysis.
15425 There are some MCU specific parsing rules.
15426 For example the storage classes, the extended storage classes are MCU specific
15427 while there may be a xdata storage class for 8051 there is no such storage
15428 class for z80 or Atmel AVR.
15429 SDCC allows MCU specific storage class extensions, i.e.
15430 xdata will be treated as a storage class specifier when parsing 8051 C
15431 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
15436 \begin_inset LatexCommand \index{iCode}
15443 Intermediate code generation.
15444 In this phase the AST is broken down into three-operand form (iCode).
15445 These three operand forms are represented as doubly linked lists.
15446 ICode is the term given to the intermediate form generated by the compiler.
15447 ICode example section shows some examples of iCode generated for some simple
15448 C source functions.
15452 \begin_inset LatexCommand \index{Optimizations}
15459 Bulk of the target independent optimizations is performed in this phase.
15460 The optimizations include constant propagation, common sub-expression eliminati
15461 on, loop invariant code movement, strength reduction of loop induction variables
15462 and dead-code elimination.
15465 Live range analysis
15466 \begin_inset LatexCommand \index{Live range analysis}
15473 During intermediate code generation phase, the compiler assumes the target
15474 machine has infinite number of registers and generates a lot of temporary
15476 The live range computation determines the lifetime of each of these compiler-ge
15477 nerated temporaries.
15478 A picture speaks a thousand words.
15479 ICode example sections show the live range annotations for each of the
15481 It is important to note here, each iCode is assigned a number in the order
15482 of its execution in the function.
15483 The live ranges are computed in terms of these numbers.
15484 The from number is the number of the iCode which first defines the operand
15485 and the to number signifies the iCode which uses this operand last.
15488 Register Allocation
15489 \begin_inset LatexCommand \index{Register allocation}
15496 The register allocation determines the type and number of registers needed
15498 In most MCUs only a few registers can be used for indirect addressing.
15499 In case of 8051 for example the registers R0 & R1 can be used to indirectly
15500 address the internal ram and DPTR to indirectly address the external ram.
15501 The compiler will try to allocate the appropriate register to pointer variables
15503 ICode example section shows the operands annotated with the registers assigned
15505 The compiler will try to keep operands in registers as much as possible;
15506 there are several schemes the compiler uses to do achieve this.
15507 When the compiler runs out of registers the compiler will check to see
15508 if there are any live operands which is not used or defined in the current
15509 basic block being processed, if there are any found then it will push that
15510 operand and use the registers in this block, the operand will then be popped
15511 at the end of the basic block.
15515 There are other MCU specific considerations in this phase.
15516 Some MCUs have an accumulator; very short-lived operands could be assigned
15517 to the accumulator instead of general-purpose register.
15523 Figure II gives a table of iCode operations supported by the compiler.
15524 The code generation involves translating these operations into corresponding
15525 assembly code for the processor.
15526 This sounds overly simple but that is the essence of code generation.
15527 Some of the iCode operations are generated on a MCU specific manner for
15528 example, the z80 port does not use registers to pass parameters so the
15529 SEND and RECV iCode operations will not be generated, and it also does
15530 not support JUMPTABLES.
15537 <Where is Figure II ?>
15541 \begin_inset LatexCommand \index{iCode}
15548 This section shows some details of iCode.
15549 The example C code does not do anything useful; it is used as an example
15550 to illustrate the intermediate code generated by the compiler.
15562 /* This function does nothing useful.
15569 for the purpose of explaining iCode */
15572 short function (data int *x)
15580 short i=10; /* dead initialization eliminated */
15585 short sum=10; /* dead initialization eliminated */
15598 while (*x) *x++ = *p++;
15612 /* compiler detects i,j to be induction variables */
15616 for (i = 0, j = 10 ; i < 10 ; i++, j
15642 mul += i * 3; /* this multiplication remains */
15648 gint += j * 3;/* this multiplication changed to addition */
15662 In addition to the operands each iCode contains information about the filename
15663 and line it corresponds to in the source file.
15664 The first field in the listing should be interpreted as follows:
15669 Filename(linenumber: iCode Execution sequence number : ICode hash table
15670 key : loop depth of the iCode).
15675 Then follows the human readable form of the ICode operation.
15676 Each operand of this triplet form can be of three basic types a) compiler
15677 generated temporary b) user defined variable c) a constant value.
15678 Note that local variables and parameters are replaced by compiler generated
15681 \begin_inset LatexCommand \index{Live range analysis}
15685 are computed only for temporaries (i.e.
15686 live ranges are not computed for global variables).
15688 \begin_inset LatexCommand \index{Register allocation}
15692 are allocated for temporaries only.
15693 Operands are formatted in the following manner:
15698 Operand Name [lr live-from : live-to ] { type information } [ registers
15704 As mentioned earlier the live ranges are computed in terms of the execution
15705 sequence number of the iCodes, for example
15707 the iTemp0 is live from (i.e.
15708 first defined in iCode with execution sequence number 3, and is last used
15709 in the iCode with sequence number 5).
15710 For induction variables such as iTemp21 the live range computation extends
15711 the lifetime from the start to the end of the loop.
15713 The register allocator used the live range information to allocate registers,
15714 the same registers may be used for different temporaries if their live
15715 ranges do not overlap, for example r0 is allocated to both iTemp6 and to
15716 iTemp17 since their live ranges do not overlap.
15717 In addition the allocator also takes into consideration the type and usage
15718 of a temporary, for example itemp6 is a pointer to near space and is used
15719 as to fetch data from (i.e.
15720 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer registers (r0).
15721 Some short lived temporaries are allocated to special registers which have
15722 meaning to the code generator e.g.
15723 iTemp13 is allocated to a pseudo register CC which tells the back end that
15724 the temporary is used only for a conditional jump the code generation makes
15725 use of this information to optimize a compare and jump ICode.
15727 There are several loop optimizations
15728 \begin_inset LatexCommand \index{Loop optimization}
15732 performed by the compiler.
15733 It can detect induction variables iTemp21(i) and iTemp23(j).
15734 Also note the compiler does selective strength reduction
15735 \begin_inset LatexCommand \index{Strength reduction}
15740 the multiplication of an induction variable in line 18 (gint = j * 3) is
15741 changed to addition, a new temporary iTemp17 is allocated and assigned
15742 a initial value, a constant 3 is then added for each iteration of the loop.
15743 The compiler does not change the multiplication
15744 \begin_inset LatexCommand \index{Multiplication}
15748 in line 17 however since the processor does support an 8 * 8 bit multiplication.
15750 Note the dead code elimination
15751 \begin_inset LatexCommand \index{Dead-code elimination}
15755 optimization eliminated the dead assignments in line 7 & 8 to I and sum
15763 Sample.c (5:1:0:0) _entry($9) :
15768 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
15773 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
15778 Sample.c(11:4:53:0) preHeaderLbl0($11) :
15783 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
15789 Sample.c(11:6:5:1) _whilecontinue_0($1) :
15794 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
15800 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
15805 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
15811 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
15817 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
15823 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
15829 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
15830 * int}[r0] + 0x2 {short}
15835 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
15840 Sample.c(11:17:21:0)_whilebreak_0($3) :
15845 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
15850 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
15855 Sample.c(15:20:54:0)preHeaderLbl1($13) :
15860 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
15865 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
15870 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
15875 Sample.c(15:24:26:1)_forcond_0($4) :
15880 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
15886 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
15891 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
15892 + ITemp21 [lr21:38]{short}[r4]
15897 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
15903 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
15904 + iTemp15 [lr29:30]{short}[r1]
15909 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
15915 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
15921 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
15927 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
15933 Sample.c(19:38:47:1) goto _forcond_0($4)
15938 Sample.c(19:39:48:0)_forbreak_0($7) :
15943 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
15944 + ITemp11 [lr19:40]{short}[r3]
15949 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
15954 Sample.c(20:42:51:0)_return($8) :
15959 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
15965 Finally the code generated for this function:
16006 ; ----------------------------------------------
16011 ; function function
16016 ; ----------------------------------------------
16026 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
16038 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
16050 ;_whilecontinue_0($1) :
16060 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
16065 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
16124 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
16143 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
16190 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
16230 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
16256 ; iTemp6 [lr5:16]{_near * int}[r0] =
16261 ; iTemp6 [lr5:16]{_near * int}[r0] +
16278 ; goto _whilecontinue_0($1)
16290 ; _whilebreak_0($3) :
16300 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
16312 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
16324 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
16336 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
16355 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
16384 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
16389 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
16434 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
16439 ; iTemp21 [lr21:38]{short}[r4]
16465 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
16498 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
16503 ; iTemp15 [lr29:30]{short}[r1]
16522 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
16569 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
16616 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
16628 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
16642 cjne r5,#0xff,00104$
16654 ; goto _forcond_0($4)
16666 ; _forbreak_0($7) :
16676 ; ret iTemp24 [lr40:41]{short}
16719 A few words about basic block successors, predecessors and dominators
16722 Successors are basic blocks
16723 \begin_inset LatexCommand \index{Basic blocks}
16727 that might execute after this basic block.
16729 Predecessors are basic blocks that might execute before reaching this basic
16732 Dominators are basic blocks that WILL execute before reaching this basic
16758 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
16761 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
16764 c) domVect of [BB4] = BB1 ...
16765 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
16773 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
16783 Thanks to all the other volunteer developers who have helped with coding,
16784 testing, web-page creation, distribution sets, etc.
16785 You know who you are :-)
16792 This document was initially written by Sandeep Dutta
16795 All product names mentioned herein may be trademarks
16796 \begin_inset LatexCommand \index{Trademarks}
16800 of their respective companies.
16807 To avoid confusion, the installation and building options for sdcc itself
16808 (chapter 2) are not part of the index.
16812 \begin_inset LatexCommand \printindex{}