1 #LyX 1.3 created this file. For more info see http://www.lyx.org/
6 pdftitle={SDCC Compiler User Guide},
7 pdfauthor={SDCC development team},
8 pdfsubject={installation, user manual},
9 pdfkeywords={8032, 8051, ansi, c, compiler, CPU, DS390,
10 embedded, GPL, manual, mcs51, PIC, small, Z80},
12 linkcolor=blue] {hyperref}
16 \inputencoding default
19 \paperfontsize default
26 \use_numerical_citations 0
27 \paperorientation portrait
34 \paragraph_separation indent
36 \quotes_language swedish
44 Please note: double dashed longoptions (e.g.
45 --version) are written this way: -
59 three consecutive dashes simply result in a long resp.
63 SDCC Compiler User Guide
69 The strings enclosed in $ are automatically updated by cvs:
74 cvs: $Revision$ $Date$
78 \begin_inset LatexCommand \tableofcontents{}
95 is a Freeware, retargettable, optimizing ANSI-C compiler by
99 designed for 8 bit Microprocessors.
100 The current version targets Intel MCS51 based Microprocessors (8031, 8032,
102 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052 CPU}
106 , etc), Zilog Z80 based MCUs, and the Dallas DS80C390 variant.
107 It can be retargetted for other microprocessors, support for PIC, AVR and
108 186 is under development.
109 The entire source code for the compiler is distributed under GPL.
110 SDCC uses ASXXXX & ASLINK, a Freeware, retargettable assembler & linker.
111 SDCC has extensive language extensions suitable for utilizing various microcont
112 rollers and underlying hardware effectively.
117 In addition to the MCU specific optimizations SDCC also does a host of standard
121 global sub expression elimination,
124 loop optimizations (loop invariant, strength reduction of induction variables
128 constant folding & propagation,
134 dead code elimination
144 For the back-end SDCC uses a global register allocation scheme which should
145 be well suited for other 8 bit MCUs.
150 The peep hole optimizer uses a rule based substitution mechanism which is
156 Supported data-types are:
159 char (8 bits, 1 byte),
162 short and int (16 bits, 2 bytes),
165 long (32 bit, 4 bytes)
172 The compiler also allows
174 inline assembler code
176 to be embedded anywhere in a function.
177 In addition, routines developed in assembly can also be called.
181 SDCC also provides an option (-
191 -cyclomatic) to report the relative complexity of a function.
192 These functions can then be further optimized, or hand coded in assembly
198 SDCC also comes with a companion source level debugger SDCDB, the debugger
199 currently uses ucSim a freeware simulator for 8051 and other micro-controllers.
204 The latest version can be downloaded from
205 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
215 Please note: the compiler will probably always be some steps ahead of this
220 \begin_inset LatexCommand \index{Status of documentation}
230 Obviously this has pros and cons
239 All packages used in this compiler system are
247 ; source code for all the sub-packages (pre-processor, assemblers, linkers
248 etc) is distributed with the package.
249 This documentation is maintained using a freeware word processor (LyX).
251 This program is free software; you can redistribute it and/or modify it
252 under the terms of the GNU General Public License
253 \begin_inset LatexCommand \index{GNU General Public License, GPL}
257 as published by the Free Software Foundation; either version 2, or (at
258 your option) any later version.
259 This program is distributed in the hope that it will be useful, but WITHOUT
260 ANY WARRANTY; without even the implied warranty
261 \begin_inset LatexCommand \index{warranty}
265 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
266 See the GNU General Public License for more details.
267 You should have received a copy of the GNU General Public License along
268 with this program; if not, write to the Free Software Foundation, 59 Temple
269 Place - Suite 330, Boston, MA 02111-1307, USA.
270 In other words, you are welcome to use, share and improve this program.
271 You are forbidden to forbid anyone else to use, share and improve what
273 Help stamp out software-hoarding!
276 Typographic conventions
277 \begin_inset LatexCommand \index{Typographic conventions}
284 Throughout this manual, we will use the following convention.
285 Commands you have to type in are printed in
293 Code samples are printed in
298 Interesting items and new terms are printed in
303 Compatibility with previous versions
306 This version has numerous bug fixes compared with the previous version.
307 But we also introduced some incompatibilities with older versions.
308 Not just for the fun of it, but to make the compiler more stable, efficient
310 \begin_inset LatexCommand \index{ANSI-compliance}
320 short is now equivalent to int (16 bits), it used to be equivalent to char
321 (8 bits) which is not ANSI compliant
324 the default directory for gcc-builds where include, library and documentation
325 files are stored is now in /usr/local/share
328 char type parameters to vararg functions are casted to int unless explicitly
345 will push a as an int and as a char resp.
358 -regextend has been removed
371 -noregparms has been removed
384 -stack-after-data has been removed
389 <pending: more incompatibilities?>
395 What do you need before you start installation of SDCC? A computer, and
397 The preferred method of installation is to compile SDCC from source using
399 For Windows some pre-compiled binary distributions are available for your
401 You should have some experience with command line tools and compiler use.
407 The SDCC home page at
408 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
412 is a great place to find distribution sets.
413 You can also find links to the user mailing lists that offer help or discuss
414 SDCC with other SDCC users.
415 Web links to other SDCC related sites can also be found here.
416 This document can be found in the DOC directory of the source package as
418 Some of the other tools (simulator and assembler) included with SDCC contain
419 their own documentation and can be found in the source distribution.
420 If you want the latest unreleased software, the complete source package
421 is available directly by anonymous CVS on cvs.sdcc.sourceforge.net.
424 ANSI C reference / related tools / recommended reading / compiler building:
428 Wishes for the future
431 There are (and always will be) some things that could be done.
432 Here are some I can think of:
439 char KernelFunction3(char p) at 0x340;
447 \begin_inset LatexCommand \index{code banking (not supported)}
455 If you can think of some more, please see the chapter 9 about filing feature
457 \begin_inset LatexCommand \index{Requesting features}
462 \begin_inset LatexCommand \index{Feature request}
472 \begin_inset LatexCommand \index{Installation}
480 \begin_inset LatexCommand \index{Options SDCC configuration}
487 The install paths, search paths and other options are defined when running
489 The defaults can be overridden by:
491 \labelwidthstring 00.00.0000
503 -prefix see table below
505 \labelwidthstring 00.00.0000
517 -exec_prefix see table below
519 \labelwidthstring 00.00.0000
531 -bindir see table below
533 \labelwidthstring 00.00.0000
545 -datadir see table below
547 \labelwidthstring 00.00.0000
549 docdir environment variable, see table below
551 \labelwidthstring 00.00.0000
553 include_dir_suffix environment variable, see table below
555 \labelwidthstring 00.00.0000
557 lib_dir_suffix environment variable, see table below
559 \labelwidthstring 00.00.0000
561 sdccconf_h_dir_separator environment variable, either / or
566 This character will only be used in sdccconf.h; don't forget it's a C-header,
567 therefore a double-backslash is needed there.
569 \labelwidthstring 00.00.0000
581 -disable-mcs51-port Excludes the Intel mcs51 port
583 \labelwidthstring 00.00.0000
595 -disable-gbz80-port Excludes the Gameboy gbz80 port
597 \labelwidthstring 00.00.0000
609 -z80-port Excludes the z80 port
611 \labelwidthstring 00.00.0000
623 -disable-avr-port Excludes the AVR port
625 \labelwidthstring 00.00.0000
637 -disable-ds390-port Excludes the DS390 port
639 \labelwidthstring 00.00.0000
651 -disable-pic-port Excludes the PIC port
653 \labelwidthstring 00.00.0000
665 -disable-xa51-port Excludes the XA51 port
667 \labelwidthstring 00.00.0000
679 -disable-ucsim Disables configuring and building of ucsim
681 \labelwidthstring 00.00.0000
693 -disable-device-lib-build Disables automatically building device libraries
695 \labelwidthstring 00.00.0000
707 -disable-packihx Disables building packihx
709 \labelwidthstring 00.00.0000
721 -enable-libgc Use the Bohem memory allocator.
722 Lower runtime footprint.
725 Furthermore the environment variables CC, CFLAGS, ...
726 the tools and their arguments can be influenced.
727 Please see `configure -
737 -help` and the man/info pages of `configure` for details.
741 The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB,
742 STD_FP_LIB, STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_
743 NAME, SDCC_INCLUDE_NAME, SDCC_LIB_NAME are defined by `configure` too.
744 At the moment it's not possible to change the default settings (it was
745 simply never required.
749 These configure options are compiled into the binaries, and can only be
750 changed by rerunning 'configure' and recompiling SDCC.
751 The configure options are written in
755 to distinguish them from run time environment variables (see section search
761 \begin_inset Quotes sld
765 \begin_inset Quotes srd
768 are used by the SDCC team to build the official Win32 binaries.
769 The SDCC team uses Mingw32 to build the official Windows binaries, because
776 a gcc compiler and last but not least
779 the binaries can be built by cross compiling on Sourceforge's compile farm.
782 See the examples, how to pass the Win32 settings to 'configure'.
783 The other Win32 builds using Borland, VC or whatever don't use 'configure',
784 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
796 <lyxtabular version="3" rows="8" columns="3">
798 <column alignment="block" valignment="top" leftline="true" width="0in">
799 <column alignment="block" valignment="top" leftline="true" width="0in">
800 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
801 <row topline="true" bottomline="true">
802 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
810 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
818 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
828 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
846 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
868 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
878 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
890 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
912 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
950 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
984 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1027 <row topline="true" bottomline="true">
1028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1038 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1046 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1064 'configure' also computes relative paths.
1065 This is needed for full relocatability of a binary package and to complete
1066 search paths (see section search paths below):
1072 \begin_inset Tabular
1073 <lyxtabular version="3" rows="4" columns="3">
1075 <column alignment="block" valignment="top" leftline="true" width="0in">
1076 <column alignment="block" valignment="top" leftline="true" width="0in">
1077 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1078 <row topline="true" bottomline="true">
1079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1095 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1104 <row topline="true" bottomline="true">
1105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1123 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1134 <row bottomline="true">
1135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1162 <row bottomline="true">
1163 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1181 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1214 \begin_inset Quotes srd
1218 \begin_inset Quotes srd
1232 \begin_inset Quotes srd
1236 \begin_inset Quotes srd
1264 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1273 \begin_inset Quotes srd
1276 i586-mingw32msvc-gcc
1277 \begin_inset Quotes srd
1281 \begin_inset Quotes srd
1284 i586-mingw32msvc-g++
1285 \begin_inset Quotes srd
1293 \begin_inset Quotes srd
1296 i586-mingw32msvc-ranlib
1297 \begin_inset Quotes srd
1305 \begin_inset Quotes srd
1308 i586-mingw32msvc-strip
1309 \begin_inset Quotes srd
1327 \begin_inset Quotes srd
1331 \begin_inset Quotes srd
1349 \begin_inset Quotes srd
1353 \begin_inset Quotes srd
1361 \begin_inset Quotes srd
1365 \begin_inset Quotes srd
1373 \begin_inset Quotes srd
1377 \begin_inset Quotes srd
1385 \begin_inset Quotes srd
1389 \begin_inset Quotes srd
1396 sdccconf_h_dir_separator=
1397 \begin_inset Quotes srd
1409 \begin_inset Quotes srd
1426 -disable-device-lib-build
1454 -host=i586-mingw32msvc -
1464 -build=unknown-unknown-linux-gnu
1468 \begin_inset Quotes sld
1472 \begin_inset Quotes srd
1475 compile on Cygwin for Mingw32(see also sdcc/support/scripts/sdcc_cygwin_mingw32)
1484 \begin_inset Quotes srd
1488 \begin_inset Quotes srd
1496 \begin_inset Quotes srd
1500 \begin_inset Quotes srd
1518 \begin_inset Quotes srd
1522 \begin_inset Quotes srd
1540 \begin_inset Quotes srd
1544 \begin_inset Quotes srd
1552 \begin_inset Quotes srd
1556 \begin_inset Quotes srd
1564 \begin_inset Quotes srd
1568 \begin_inset Quotes srd
1576 \begin_inset Quotes srd
1580 \begin_inset Quotes srd
1587 sdccconf_h_dir_separator=
1588 \begin_inset Quotes srd
1600 \begin_inset Quotes srd
1620 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
1631 -C' turns on caching, which gives a little bit extra speed.
1632 However if options are changed, it can be necessary to delete the config.cache
1637 \begin_inset LatexCommand \index{Install paths}
1643 \added_space_top medskip \align center
1645 \begin_inset Tabular
1646 <lyxtabular version="3" rows="5" columns="4">
1648 <column alignment="center" valignment="top" leftline="true" width="0(null)">
1649 <column alignment="center" valignment="top" leftline="true" width="0(null)">
1650 <column alignment="center" valignment="top" leftline="true" width="0(null)">
1651 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
1652 <row topline="true" bottomline="true">
1653 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1663 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1683 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1694 <row topline="true">
1695 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1721 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1734 <row topline="true">
1735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1750 $DATADIR/ $INCLUDE_DIR_SUFFIX
1753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1758 /usr/local/share/sdcc/include
1761 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1774 <row topline="true">
1775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1790 $DATADIR/$LIB_DIR_SUFFIX
1793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1798 /usr/local/share/sdcc/lib
1801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1814 <row topline="true" bottomline="true">
1815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1838 /usr/local/share/sdcc/doc
1841 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1863 *compiler, preprocessor, assembler, and linker
1869 is auto-appended by the compiler, e.g.
1870 small, large, z80, ds390 etc
1873 The install paths can still be changed during `make install` with e.g.:
1876 make install prefix=$(HOME)/local/sdcc
1879 Of course this doesn't change the search paths compiled into the binaries.
1883 \begin_inset LatexCommand \index{Search path}
1890 Some search paths or parts of them are determined by configure variables
1895 , see section above).
1896 Further search paths are determined by environment variables during runtime.
1899 The paths searched when running the compiler are as follows (the first catch
1905 Binary files (preprocessor, assembler and linker)
1911 \begin_inset Tabular
1912 <lyxtabular version="3" rows="4" columns="3">
1914 <column alignment="block" valignment="top" leftline="true" width="0in">
1915 <column alignment="block" valignment="top" leftline="true" width="0in">
1916 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1917 <row topline="true" bottomline="true">
1918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1934 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1943 <row topline="true">
1944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1962 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1973 <row topline="true">
1974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1979 Path of argv[0] (if available)
1982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1999 <row topline="true" bottomline="true">
2000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2016 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2041 \begin_inset Tabular
2042 <lyxtabular version="3" rows="6" columns="3">
2044 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2045 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2046 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2047 <row topline="true" bottomline="true">
2048 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2056 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2064 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2073 <row topline="true">
2074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2110 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2129 <row topline="true">
2130 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2138 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2146 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2155 <row topline="true">
2156 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2170 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2193 <row topline="true">
2194 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2262 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2275 <row topline="true" bottomline="true">
2276 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2292 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2297 /usr/local/share/sdcc/
2302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2330 -nostdinc disables the last two search paths.
2340 With the exception of
2341 \begin_inset Quotes sld
2355 \begin_inset Quotes srd
2362 is auto-appended by the compiler (e.g.
2363 small, large, z80, ds390 etc.).
2370 \begin_inset Tabular
2371 <lyxtabular version="3" rows="6" columns="3">
2373 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2374 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2375 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2376 <row topline="true" bottomline="true">
2377 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2385 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2402 <row topline="true">
2403 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2439 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2458 <row topline="true">
2459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2471 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2498 <row topline="true">
2499 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2510 $LIB_DIR_SUFFIX/<model>
2513 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2527 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2544 <row topline="true">
2545 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2560 $LIB_DIR_SUFFIX/<model>
2563 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2616 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2672 <row topline="true" bottomline="true">
2673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2682 $LIB_DIR_SUFFIX/<model>
2685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2690 /usr/local/share/sdcc/
2697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2715 Don't delete any of the stray spaces in the table above without checking
2716 the HTML output (last line)!
2732 -nostdlib disables the last two search paths.
2736 \begin_inset LatexCommand \index{Building SDCC}
2741 \layout Subsubsection
2743 Building SDCC on Linux
2748 Download the source package
2750 either from the SDCC CVS repository or from the
2751 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
2757 , it will be named something like sdcc
2770 Bring up a command line terminal, such as xterm.
2775 Unpack the file using a command like:
2778 "tar -xzf sdcc.src.tar.gz
2783 , this will create a sub-directory called sdcc with all of the sources.
2786 Change directory into the main SDCC directory, for example type:
2803 This configures the package for compilation on your system.
2819 All of the source packages will compile, this can take a while.
2835 This copies the binary executables, the include files, the libraries and
2836 the documentation to the install directories.
2837 \layout Subsubsection
2839 Building SDCC on OSX 2.x
2842 Follow the instruction for Linux.
2846 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
2847 )) fails to compile SDCC.
2848 Fortunately there's also gcc 2.9.x installed, which works fine.
2849 This compiler can be selected by running 'configure' with:
2852 ./configure CC=gcc2 CXX=g++2
2853 \layout Subsubsection
2855 Cross compiling SDCC on Linux for Windows
2858 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
2859 See section 'Configure Options'.
2860 \layout Subsubsection
2862 Building SDCC on Windows
2865 With the exception of Cygwin the SDCC binaries uCsim and sdcdb can't be
2867 They use Unix-sockets, which are not available on Win32.
2868 \layout Subsubsection
2870 Windows Install Using a Binary Package
2873 Download the binary package and unpack it using your favorite unpacking
2874 tool (gunzip, WinZip, etc).
2875 This should unpack to a group of sub-directories.
2876 An example directory structure after unpacking the mingw32 package is:
2881 bin for the executables, c:
2889 lib for the include and libraries.
2892 Adjust your environment variable PATH to include the location of the bin
2893 directory or start sdcc using the full path.
2894 \layout Subsubsection
2896 Building SDCC using Cygwin and Mingw32
2899 For building and installing a Cygwin executable follow the instructions
2905 \begin_inset Quotes sld
2909 \begin_inset Quotes srd
2912 Win32-binary can be built, which will not need the Cygwin-DLL.
2913 For the necessary 'configure' options see section 'configure options' or
2914 the script 'sdcc/support/scripts/sdcc_cygwinmingw32'.
2918 In order to install Cygwin on Windows download setup.exe from
2919 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
2925 \begin_inset Quotes sld
2928 default text file type
2929 \begin_inset Quotes srd
2933 \begin_inset Quotes sld
2937 \begin_inset Quotes srd
2940 and download/install at least the following packages.
2941 Some packages are selected by default, others will be automatically selected
2942 because of dependencies with the manually selected packages.
2943 Never deselect these packages!
2952 gcc ; version 3.x is fine, no need to use the old 2.9x
2955 binutils ; selected with gcc
2961 rxvt ; a nice console, which makes life much easier under windoze (see below)
2964 man ; not really needed for building SDCC, but you'll miss it sooner or
2968 less ; not really needed for building SDCC, but you'll miss it sooner or
2972 cvs ; only if you use CVS access
2975 If you want to develop something you'll need:
2978 python ; for the regression tests
2981 gdb ; the gnu debugger, together with the nice GUI
2982 \begin_inset Quotes sld
2986 \begin_inset Quotes srd
2992 openssh ; to access the CF or commit changes
2995 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
2996 use autoconf-stable!
2999 rxvt is a nice console with history.
3000 Replace in your cygwin.bat the line
3019 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3022 -bg black -fg white -geometry 100x65 -e bash -
3035 Text selected with the mouse is automatically copied to the clipboard, pasting
3036 works with shift-insert.
3040 The other good tip is to make sure you have no //c/-style paths anywhere,
3041 use /cygdrive/c/ instead.
3042 Using // invokes a network lookup which is very slow.
3044 \begin_inset Quotes sld
3048 \begin_inset Quotes srd
3051 is too long, you can change it with e.g.
3057 SDCC sources use the unix line ending LF.
3058 Life is much easier, if you store the source tree on a drive, which is
3059 mount in binary mode.
3060 And use an editor which can handle LF-only line endings.
3061 Make sure not to commit files with windows line endings.
3062 \layout Subsubsection
3064 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3069 Download the source package
3071 either from the SDCC CVS repository or from the
3072 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3078 , it will be named something like sdcc
3085 SDCC is distributed with all the projects, workspaces, and files you need
3086 to build it using Visual C++ 6.0/NET (except for sdcdb.exe which currently
3087 doesn't build under MSVC).
3088 The workspace name is 'sdcc.dsw'.
3089 Please note that as it is now, all the executables are created in a folder
3093 Once built you need to copy the executables from sdcc
3097 bin before running SDCC.
3102 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3103 flex.exe, and gawk.exe.
3104 One good place to get them is
3105 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3113 Download the file UnxUtils
3114 \begin_inset LatexCommand \index{UnxUtils}
3119 Now you have to install the utilities and setup MSVC so it can locate the
3121 Here there are two alternatives (choose one!):
3128 a) Extract UnxUtils.zip to your C:
3130 hard disk PRESERVING the original paths, otherwise bison won't work.
3131 (If you are using WinZip make certain that 'Use folder names' is selected)
3135 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3136 in 'Show directories for:' select 'Executable files', and in the directories
3137 window add a new path: 'C:
3147 (As a side effect, you get a bunch of Unix utilities that could be useful,
3148 such as diff and patch.)
3155 This one avoids extracting a bunch of files you may not use, but requires
3160 a) Create a directory were to put the tools needed, or use a directory already
3168 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3169 to such directory WITHOUT preserving the original paths.
3170 (If you are using WinZip make certain that 'Use folder names' is not selected)
3174 c) Rename bison.exe to '_bison.exe'.
3178 d) Create a batch file 'bison.bat' in 'C:
3182 ' and add these lines:
3202 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3206 Steps 'c' and 'd' are needed because bison requires by default that the
3207 files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3208 '/usr/local/share/' I think.
3209 So it is necessary to tell bison where those files are located if they
3210 are not in such directory.
3211 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3215 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3216 in 'Show directories for:' select 'Executable files', and in the directories
3217 window add a new path: 'c:
3220 Note that you can use any other path instead of 'c:
3222 util', even the path where the Visual C++ tools are, probably: 'C:
3226 Microsoft Visual Studio
3231 So you don't have to execute step 'e' :)
3235 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3236 the executables from sdcc
3240 bin, and you can compile using sdcc.
3241 \layout Subsubsection
3243 Building SDCC Using Borland
3246 From the sdcc directory, run the command "make -f Makefile.bcc".
3247 This should regenerate all the .exe files in the bin directory except for
3248 sdcdb.exe (which currently doesn't build under Borland C++).
3251 If you modify any source files and need to rebuild, be aware that the dependenci
3252 es may not be correctly calculated.
3253 The safest option is to delete all .obj files and run the build again.
3254 From a Cygwin BASH prompt, this can easily be done with the command:
3264 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
3266 ) -print -exec rm {}
3275 or on Windows NT/2000/XP from the command prompt with the command:
3282 del /s *.obj *.lib *.rul
3285 from the sdcc directory.
3288 Building the Documentation
3295 Testing out the SDCC Compiler
3298 The first thing you should do after installing your SDCC compiler is to
3314 \begin_inset LatexCommand \index{version}
3321 at the prompt, and the program should run and tell you the version.
3322 If it doesn't run, or gives a message about not finding sdcc program, then
3323 you need to check over your installation.
3324 Make sure that the sdcc bin directory is in your executable search path
3325 defined by the PATH environment setting (see the Trouble-shooting section
3327 Make sure that the sdcc program is in the bin folder, if not perhaps something
3328 did not install correctly.
3336 is commonly installed as described in section
3337 \begin_inset Quotes sld
3340 Install and search paths
3341 \begin_inset Quotes srd
3350 Make sure the compiler works on a very simple example.
3351 Type in the following test.c program using your favorite
3377 Compile this using the following command:
3386 If all goes well, the compiler will generate a test.asm and test.rel file.
3387 Congratulations, you've just compiled your first program with SDCC.
3388 We used the -c option to tell SDCC not to link the generated code, just
3389 to keep things simple for this step.
3397 The next step is to try it with the linker.
3407 If all goes well the compiler will link with the libraries and produce
3408 a test.ihx output file.
3413 (no test.ihx, and the linker generates warnings), then the problem is most
3414 likely that sdcc cannot find the
3418 usr/local/share/sdcc/lib directory
3422 (see the Install trouble-shooting section for suggestions).
3430 The final test is to ensure sdcc can use the
3434 header files and libraries.
3435 Edit test.c and change it to the following:
3452 strcpy(str1, "testing");
3459 Compile this by typing
3466 This should generate a test.ihx output file, and it should give no warnings
3467 such as not finding the string.h file.
3468 If it cannot find the string.h file, then the problem is that sdcc cannot
3469 find the /usr/local/share/sdcc/include directory
3473 (see the Install trouble-shooting section for suggestions).
3491 \begin_inset LatexCommand \index{-\/-print-search-dirs}
3495 to find exactly where SDCC is looking for the include and lib files.
3498 Install Trouble-shooting
3499 \begin_inset LatexCommand \index{Install trouble-shooting}
3504 \layout Subsubsection
3506 SDCC does not build correctly.
3509 A thing to try is starting from scratch by unpacking the .tgz source package
3510 again in an empty directory.
3518 ./configure 2>&1 | tee configure.log
3532 make 2>&1 | tee make.log
3539 If anything goes wrong, you can review the log files to locate the problem.
3540 Or a relevant part of this can be attached to an email that could be helpful
3541 when requesting help from the mailing list.
3542 \layout Subsubsection
3545 \begin_inset Quotes sld
3549 \begin_inset Quotes srd
3556 \begin_inset Quotes sld
3560 \begin_inset Quotes srd
3563 command is a script that analyzes your system and performs some configuration
3564 to ensure the source package compiles on your system.
3565 It will take a few minutes to run, and will compile a few tests to determine
3566 what compiler features are installed.
3567 \layout Subsubsection
3570 \begin_inset Quotes sld
3574 \begin_inset Quotes srd
3580 This runs the GNU make tool, which automatically compiles all the source
3581 packages into the final installed binary executables.
3582 \layout Subsubsection
3585 \begin_inset Quotes sld
3589 \begin_inset Quotes erd
3595 This will install the compiler, other executables libraries and include
3596 files in to the appropriate directories.
3598 \begin_inset Quotes sld
3601 Install and Search PATHS
3602 \begin_inset Quotes srd
3607 On most systems you will need super-user privileges to do this.
3613 SDCC is not just a compiler, but a collection of tools by various developers.
3614 These include linkers, assemblers, simulators and other components.
3615 Here is a summary of some of the components.
3616 Note that the included simulator and assembler have separate documentation
3617 which you can find in the source package in their respective directories.
3618 As SDCC grows to include support for other processors, other packages from
3619 various developers are included and may have their own sets of documentation.
3623 You might want to look at the files which are installed in <installdir>.
3624 At the time of this writing, we find the following programs for gcc-builds:
3628 In <installdir>/bin:
3631 sdcc - The compiler.
3634 sdcpp - The C preprocessor.
3637 asx8051 - The assembler for 8051 type processors.
3644 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
3647 aslink -The linker for 8051 type processors.
3654 link-gbz80 - The Z80 and GameBoy Z80 linkers.
3657 s51 - The ucSim 8051 simulator.
3660 sdcdb - The source debugger.
3663 packihx - A tool to pack (compress) Intel hex files.
3666 In <installdir>/share/sdcc/include
3672 In <installdir>/share/sdcc/lib
3675 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
3679 In <installdir>/share/sdcc/doc
3685 As development for other processors proceeds, this list will expand to include
3686 executables to support processors like AVR, PIC, etc.
3687 \layout Subsubsection
3692 This is the actual compiler, it in turn uses the c-preprocessor and invokes
3693 the assembler and linkage editor.
3694 \layout Subsubsection
3697 \begin_inset LatexCommand \index{sdcpp}
3701 - The C-Preprocessor
3704 The preprocessor is a modified version of the GNU preprocessor.
3705 The C preprocessor is used to pull in #include sources, process #ifdef
3706 statements, #defines and so on.
3707 \layout Subsubsection
3709 asx8051, as-z80, as-gbz80, aslink, link-z80, link-gbz80 - The Assemblers
3713 This is retargettable assembler & linkage editor, it was developed by Alan
3715 John Hartman created the version for 8051, and I (Sandeep) have made some
3716 enhancements and bug fixes for it to work properly with the SDCC.
3717 \layout Subsubsection
3720 \begin_inset LatexCommand \index{s51}
3727 S51 is a freeware, opensource simulator developed by Daniel Drotos (
3728 \begin_inset LatexCommand \url{mailto:drdani@mazsola.iit.uni-miskolc.hu}
3733 The simulator is built as part of the build process.
3734 For more information visit Daniel's web site at:
3735 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
3740 It currently support the core mcs51, the Dallas DS80C390 and the Phillips
3742 \layout Subsubsection
3745 \begin_inset LatexCommand \index{sdcdb}
3749 - Source Level Debugger
3752 Sdcdb is the companion source level debugger.
3753 The current version of the debugger uses Daniel's Simulator S51, but can
3754 be easily changed to use other simulators.
3761 \layout Subsubsection
3763 Single Source File Projects
3766 For single source file 8051 projects the process is very simple.
3767 Compile your programs with the following command
3770 "sdcc sourcefile.c".
3774 This will compile, assemble and link your source file.
3775 Output files are as follows
3779 \begin_inset LatexCommand \index{.asm}
3784 \begin_inset LatexCommand \index{Assembler source}
3788 file created by the compiler
3792 \begin_inset LatexCommand \index{.lst}
3797 \begin_inset LatexCommand \index{Assembler listing}
3801 file created by the Assembler
3805 \begin_inset LatexCommand \index{.rst}
3810 \begin_inset LatexCommand \index{Assembler listing}
3814 file updated with linkedit information, created by linkage editor
3818 \begin_inset LatexCommand \index{.sym}
3823 \begin_inset LatexCommand \index{Symbol listing}
3827 for the sourcefile, created by the assembler
3831 \begin_inset LatexCommand \index{.rel}
3836 \begin_inset LatexCommand \index{Object file}
3840 created by the assembler, input to Linkage editor
3844 \begin_inset LatexCommand \index{.map}
3849 \begin_inset LatexCommand \index{Memory map}
3853 for the load module, created by the Linker
3857 \begin_inset LatexCommand \index{.mem}
3861 - A file with a summary of the memory usage
3865 \begin_inset LatexCommand \index{.ihx}
3869 - The load module in Intel hex format
3870 \begin_inset LatexCommand \index{Intel hex format}
3874 (you can select the Motorola S19 format
3875 \begin_inset LatexCommand \index{Motorola S19 format}
3890 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
3895 If you need another format you might want to use objdump
3896 \begin_inset LatexCommand \index{objdump}
3901 \begin_inset LatexCommand \index{srecord}
3909 \begin_inset LatexCommand \index{.adb}
3913 - An intermediate file containing debug information needed to create the
3925 \begin_inset LatexCommand \index{-\/-debug}
3933 \begin_inset LatexCommand \index{.cdb}
3937 - An optional file (with -
3947 -debug) containing debug information
3952 \begin_inset LatexCommand \index{. (no extension)}
3956 An optional AOMF51 file containing debug information (with -
3970 \begin_inset LatexCommand \index{.dump*}
3974 - Dump file to debug the compiler it self (with -
3984 -dumpall) (see section
3985 \begin_inset Quotes sld
3988 Anatomy of the compiler
3989 \begin_inset Quotes srd
3993 \layout Subsubsection
3995 Projects with Multiple Source Files
3998 SDCC can compile only ONE file at a time.
3999 Let us for example assume that you have a project containing the following
4004 foo1.c (contains some functions)
4006 foo2.c (contains some more functions)
4008 foomain.c (contains more functions and the function main)
4016 The first two files will need to be compiled separately with the commands:
4048 Then compile the source file containing the
4053 \begin_inset LatexCommand \index{Linker}
4057 the files together with the following command:
4065 foomain.c\SpecialChar ~
4066 foo1.rel\SpecialChar ~
4071 \begin_inset LatexCommand \index{.rel}
4083 can be separately compiled as well:
4094 sdcc foomain.rel foo1.rel foo2.rel
4101 The file containing the
4116 file specified in the command line, since the linkage editor processes
4117 file in the order they are presented to it.
4118 The linker is invoked from sdcc using a script file with extension .lnk
4119 \begin_inset LatexCommand \index{.lnk}
4124 You can view this file to troubleshoot linking problems such as those arising
4125 from missing libraries.
4126 \layout Subsubsection
4128 Projects with Additional Libraries
4129 \begin_inset LatexCommand \index{Libraries}
4136 Some reusable routines may be compiled into a library, see the documentation
4137 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
4141 \begin_inset LatexCommand \index{.lib}
4148 Libraries created in this manner can be included in the command line.
4149 Make sure you include the -L <library-path> option to tell the linker where
4150 to look for these files if they are not in the current directory.
4151 Here is an example, assuming you have the source file
4163 (if that is not the same as your current project):
4170 sdcc foomain.c foolib.lib -L mylib
4181 must be an absolute path name.
4185 The most efficient way to use libraries is to keep separate modules in separate
4187 The lib file now should name all the modules.rel
4188 \begin_inset LatexCommand \index{rel}
4193 For an example see the standard library file
4197 in the directory <installdir>/share/lib/small.
4200 Command Line Options
4201 \begin_inset LatexCommand \index{Command Line Options}
4206 \layout Subsubsection
4208 Processor Selection Options
4209 \begin_inset LatexCommand \index{Options processor selection}
4214 \begin_inset LatexCommand \index{Processor selection options}
4220 \labelwidthstring 00.00.0000
4225 \begin_inset LatexCommand \index{-mmcs51}
4231 Generate code for the MCS51
4232 \begin_inset LatexCommand \index{MCS51}
4236 family of processors.
4237 This is the default processor target.
4239 \labelwidthstring 00.00.0000
4244 \begin_inset LatexCommand \index{-mds390}
4250 Generate code for the DS80C390
4251 \begin_inset LatexCommand \index{DS80C390}
4257 \labelwidthstring 00.00.0000
4262 \begin_inset LatexCommand \index{-mds400}
4268 Generate code for the DS80C400
4269 \begin_inset LatexCommand \index{DS80C400}
4275 \labelwidthstring 00.00.0000
4280 \begin_inset LatexCommand \index{-mz80}
4286 Generate code for the Z80
4287 \begin_inset LatexCommand \index{Z80}
4291 family of processors.
4293 \labelwidthstring 00.00.0000
4298 \begin_inset LatexCommand \index{-mgbz80}
4304 Generate code for the GameBoy Z80
4305 \begin_inset LatexCommand \index{GameBoy Z80}
4311 \labelwidthstring 00.00.0000
4316 \begin_inset LatexCommand \index{-mavr}
4322 Generate code for the Atmel AVR
4323 \begin_inset LatexCommand \index{AVR}
4327 processor (In development, not complete).
4328 AVR users should probably have a look at avr-gcc
4329 \begin_inset LatexCommand \url[FIXME: official URL?]{ http://savannah.nongnu.org/download/avr-libc/snapshots/}
4336 I think it is fair to direct users there for now.
4337 Open source is also about avoiding unnecessary work .
4338 But I didn't find the 'official' link.
4340 \labelwidthstring 00.00.0000
4345 \begin_inset LatexCommand \index{-mpic14}
4351 Generate code for the PIC 14
4352 \begin_inset LatexCommand \index{PIC14}
4356 -bit processors (In development, not complete).
4359 p16f627 p16f628 p16f84 p16f873 p16f877?
4361 \labelwidthstring 00.00.0000
4367 Generate code for the Toshiba TLCS-900H
4368 \begin_inset LatexCommand \index{TLCS-900H}
4372 processor (In development, not complete).
4374 \labelwidthstring 00.00.0000
4379 \begin_inset LatexCommand \index{-mxa51}
4385 Generate code for the Phillips XA51
4386 \begin_inset LatexCommand \index{XA51}
4390 processor (In development, not complete).
4391 \layout Subsubsection
4393 Preprocessor Options
4394 \begin_inset LatexCommand \index{Options preprocessor}
4399 \begin_inset LatexCommand \index{Preprocessor options}
4405 \labelwidthstring 00.00.0000
4410 \begin_inset LatexCommand \index{-I<path>}
4416 The additional location where the pre processor will look for <..h> or
4417 \begin_inset Quotes eld
4421 \begin_inset Quotes erd
4426 \labelwidthstring 00.00.0000
4431 \begin_inset LatexCommand \index{-D<macro[=value]>}
4437 Command line definition of macros.
4438 Passed to the pre processor.
4440 \labelwidthstring 00.00.0000
4445 \begin_inset LatexCommand \index{-M}
4451 Tell the preprocessor to output a rule suitable for make describing the
4452 dependencies of each object file.
4453 For each source file, the preprocessor outputs one make-rule whose target
4454 is the object file name for that source file and whose dependencies are
4455 all the files `#include'd in it.
4456 This rule may be a single line or may be continued with `
4458 '-newline if it is long.
4459 The list of rules is printed on standard output instead of the preprocessed
4463 \labelwidthstring 00.00.0000
4468 \begin_inset LatexCommand \index{-C}
4474 Tell the preprocessor not to discard comments.
4475 Used with the `-E' option.
4477 \labelwidthstring 00.00.0000
4482 \begin_inset LatexCommand \index{-MM}
4493 Like `-M' but the output mentions only the user header files included with
4495 \begin_inset Quotes eld
4499 System header files included with `#include <file>' are omitted.
4501 \labelwidthstring 00.00.0000
4506 \begin_inset LatexCommand \index{-Aquestion(answer)}
4512 Assert the answer answer for question, in case it is tested with a preprocessor
4513 conditional such as `#if #question(answer)'.
4514 `-A-' disables the standard assertions that normally describe the target
4517 \labelwidthstring 00.00.0000
4523 (answer) Assert the answer answer for question, in case it is tested with
4524 a preprocessor conditional such as `#if #question(answer)'.
4525 `-A-' disables the standard assertions that normally describe the target
4528 \labelwidthstring 00.00.0000
4533 \begin_inset LatexCommand \index{-Umacro}
4539 Undefine macro macro.
4540 `-U' options are evaluated after all `-D' options, but before any `-include'
4541 and `-imacros' options.
4543 \labelwidthstring 00.00.0000
4548 \begin_inset LatexCommand \index{-dM}
4554 Tell the preprocessor to output only a list of the macro definitions that
4555 are in effect at the end of preprocessing.
4556 Used with the `-E' option.
4558 \labelwidthstring 00.00.0000
4563 \begin_inset LatexCommand \index{-dD}
4569 Tell the preprocessor to pass all macro definitions into the output, in
4570 their proper sequence in the rest of the output.
4572 \labelwidthstring 00.00.0000
4577 \begin_inset LatexCommand \index{-dN}
4588 Like `-dD' except that the macro arguments and contents are omitted.
4589 Only `#define name' is included in the output.
4590 \layout Subsubsection
4593 \begin_inset LatexCommand \index{Options linker}
4598 \begin_inset LatexCommand \index{Linker options}
4604 \labelwidthstring 00.00.0000
4624 \begin_inset LatexCommand \index{-\/-lib-path}
4629 \begin_inset LatexCommand \index{-L -\/-lib-path}
4638 <absolute path to additional libraries> This option is passed to the linkage
4639 editor's additional libraries
4640 \begin_inset LatexCommand \index{Libraries}
4645 The path name must be absolute.
4646 Additional library files may be specified in the command line.
4647 See section Compiling programs for more details.
4649 \labelwidthstring 00.00.0000
4666 \begin_inset LatexCommand \index{-\/-xram-loc}
4670 <Value> The start location of the external ram
4671 \begin_inset LatexCommand \index{xdata}
4675 , default value is 0.
4676 The value entered can be in Hexadecimal or Decimal format, e.g.: -
4686 -xram-loc 0x8000 or -
4698 \labelwidthstring 00.00.0000
4715 \begin_inset LatexCommand \index{-\/-code-loc}
4719 <Value> The start location of the code
4720 \begin_inset LatexCommand \index{code}
4724 segment, default value 0.
4725 Note when this option is used the interrupt vector table is also relocated
4726 to the given address.
4727 The value entered can be in Hexadecimal or Decimal format, e.g.: -
4737 -code-loc 0x8000 or -
4749 \labelwidthstring 00.00.0000
4766 \begin_inset LatexCommand \index{-\/-stack-loc}
4770 <Value> By default the stack
4771 \begin_inset LatexCommand \index{stack}
4775 is placed after the data segment.
4776 Using this option the stack can be placed anywhere in the internal memory
4778 The value entered can be in Hexadecimal or Decimal format, e.g.
4789 -stack-loc 0x20 or -
4800 Since the sp register is incremented before a push or call, the initial
4801 sp will be set to one byte prior the provided value.
4802 The provided value should not overlap any other memory areas such as used
4803 register banks or the data segment and with enough space for the current
4806 \labelwidthstring 00.00.0000
4823 \begin_inset LatexCommand \index{-\/-data-loc}
4827 <Value> The start location of the internal ram data
4828 \begin_inset LatexCommand \index{data}
4833 The value entered can be in Hexadecimal or Decimal format, eg.
4855 (By default, the start location of the internal ram data segment is set
4856 as low as possible in memory, taking into account the used register banks
4857 and the bit segment at address 0x20.
4858 For example if register banks 0 and 1 are used without bit variables, the
4859 data segment will be set, if -
4869 -data-loc is not used, to location 0x10.)
4871 \labelwidthstring 00.00.0000
4888 \begin_inset LatexCommand \index{-\/-idata-loc}
4892 <Value> The start location of the indirectly addressable internal ram
4893 \begin_inset LatexCommand \index{idata}
4897 , default value is 0x80.
4898 The value entered can be in Hexadecimal or Decimal format, eg.
4909 -idata-loc 0x88 or -
4921 \labelwidthstring 00.00.0000
4936 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
4945 The linker output (final object code) is in Intel Hex format.
4946 \begin_inset LatexCommand \index{Intel hex format}
4950 (This is the default option).
4952 \labelwidthstring 00.00.0000
4967 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
4976 The linker output (final object code) is in Motorola S19 format
4977 \begin_inset LatexCommand \index{Motorola S19 format}
4982 \layout Subsubsection
4985 \begin_inset LatexCommand \index{Options MCS51}
4990 \begin_inset LatexCommand \index{MCS51 options}
4996 \labelwidthstring 00.00.0000
5011 \begin_inset LatexCommand \index{-\/-model-large}
5017 Generate code for Large model programs see section Memory Models for more
5019 If this option is used all source files in the project should be compiled
5021 In addition the standard library routines are compiled with small model,
5022 they will need to be recompiled.
5024 \labelwidthstring 00.00.0000
5039 \begin_inset LatexCommand \index{-\/-model-small}
5050 Generate code for Small Model programs see section Memory Models for more
5052 This is the default model.
5053 \layout Subsubsection
5056 \begin_inset LatexCommand \index{Options DS390}
5061 \begin_inset LatexCommand \index{DS390 options}
5067 \labelwidthstring 00.00.0000
5084 \begin_inset LatexCommand \index{-\/-model-flat24}
5094 Generate 24-bit flat mode code.
5095 This is the one and only that the ds390 code generator supports right now
5096 and is default when using
5101 See section Memory Models for more details.
5103 \labelwidthstring 00.00.0000
5120 \begin_inset LatexCommand \index{-\/-stack-10bit}
5124 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
5125 This is the one and only that the ds390 code generator supports right now
5126 and is default when using
5131 In this mode, the stack is located in the lower 1K of the internal RAM,
5132 which is mapped to 0x400000.
5133 Note that the support is incomplete, since it still uses a single byte
5134 as the stack pointer.
5135 This means that only the lower 256 bytes of the potential 1K stack space
5136 will actually be used.
5137 However, this does allow you to reclaim the precious 256 bytes of low RAM
5138 for use for the DATA and IDATA segments.
5139 The compiler will not generate any code to put the processor into 10 bit
5141 It is important to ensure that the processor is in this mode before calling
5142 any re-entrant functions compiled with this option.
5143 In principle, this should work with the
5156 \begin_inset LatexCommand \index{-\/-stack-auto}
5162 option, but that has not been tested.
5163 It is incompatible with the
5176 \begin_inset LatexCommand \index{-\/-xstack}
5183 It also only makes sense if the processor is in 24 bit contiguous addressing
5196 -model-flat24 option
5199 \layout Subsubsection
5201 Optimization Options
5202 \begin_inset LatexCommand \index{Options optimization}
5207 \begin_inset LatexCommand \index{Optimization options}
5213 \labelwidthstring 00.00.0000
5228 \begin_inset LatexCommand \index{-\/-nogcse}
5234 Will not do global subexpression elimination, this option may be used when
5235 the compiler creates undesirably large stack/data spaces to store compiler
5237 A warning message will be generated when this happens and the compiler
5238 will indicate the number of extra bytes it allocated.
5239 It recommended that this option NOT be used, #pragma\SpecialChar ~
5241 \begin_inset LatexCommand \index{\#pragma NOGCSE}
5245 can be used to turn off global subexpression elimination
5246 \begin_inset LatexCommand \index{Subexpression elimination}
5250 for a given function only.
5252 \labelwidthstring 00.00.0000
5267 \begin_inset LatexCommand \index{-\/-noinvariant}
5273 Will not do loop invariant optimizations, this may be turned off for reasons
5274 explained for the previous option.
5275 For more details of loop optimizations performed see section Loop Invariants.It
5276 recommended that this option NOT be used, #pragma\SpecialChar ~
5278 \begin_inset LatexCommand \index{\#pragma NOINVARIANT}
5282 can be used to turn off invariant optimizations for a given function only.
5284 \labelwidthstring 00.00.0000
5299 \begin_inset LatexCommand \index{-\/-noinduction}
5305 Will not do loop induction optimizations, see section strength reduction
5306 for more details.It is recommended that this option is NOT used, #pragma\SpecialChar ~
5309 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
5313 can be used to turn off induction optimizations for a given function only.
5315 \labelwidthstring 00.00.0000
5330 \begin_inset LatexCommand \index{-\/-nojtbound}
5341 Will not generate boundary condition check when switch statements
5342 \begin_inset LatexCommand \index{switch statement}
5346 are implemented using jump-tables.
5347 See section Switch Statements for more details.
5348 It is recommended that this option is NOT used, #pragma\SpecialChar ~
5350 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
5354 can be used to turn off boundary checking for jump tables for a given function
5357 \labelwidthstring 00.00.0000
5372 \begin_inset LatexCommand \index{-\/-noloopreverse}
5381 Will not do loop reversal
5382 \begin_inset LatexCommand \index{Loop reversing}
5388 \labelwidthstring 00.00.0000
5405 \begin_inset LatexCommand \index{-\/-nolabelopt }
5409 Will not optimize labels (makes the dumpfiles more readable).
5411 \labelwidthstring 00.00.0000
5426 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
5432 Will not memcpy initialized data in far space from code space.
5433 This saves a few bytes in code space if you don't have initialized data.
5434 \layout Subsubsection
5437 \begin_inset LatexCommand \index{Options other}
5443 \labelwidthstring 00.00.0000
5459 \begin_inset LatexCommand \index{-\/-compile-only}
5464 \begin_inset LatexCommand \index{-c -\/-compile-only}
5470 will compile and assemble the source, but will not call the linkage editor.
5472 \labelwidthstring 00.00.0000
5491 \begin_inset LatexCommand \index{-\/-c1mode}
5497 reads the preprocessed source from standard input and compiles it.
5498 The file name for the assembler output must be specified using the -o option.
5500 \labelwidthstring 00.00.0000
5505 \begin_inset LatexCommand \index{-E}
5511 Run only the C preprocessor.
5512 Preprocess all the C source files specified and output the results to standard
5515 \labelwidthstring 00.00.0000
5521 \begin_inset LatexCommand \index{-o <path/file>}
5527 The output path resp.
5528 file where everything will be placed.
5529 If the parameter is a path, it must have a trailing slash (or backslash
5530 for the Windows binaries) to be recognized as a path.
5533 \labelwidthstring 00.00.0000
5548 \begin_inset LatexCommand \index{-\/-stack-auto}
5559 All functions in the source file will be compiled as
5564 \begin_inset LatexCommand \index{reentrant}
5569 the parameters and local variables will be allocated on the stack
5570 \begin_inset LatexCommand \index{stack}
5575 see section Parameters and Local Variables for more details.
5576 If this option is used all source files in the project should be compiled
5580 \labelwidthstring 00.00.0000
5595 \begin_inset LatexCommand \index{-\/-xstack}
5601 Uses a pseudo stack in the first 256 bytes in the external ram for allocating
5602 variables and passing parameters.
5603 See section on external stack for more details.
5605 \labelwidthstring 00.00.0000
5620 \begin_inset LatexCommand \index{-\/-callee-saves}
5625 \begin_inset LatexCommand \index{function prologue}
5629 function1[,function2][,function3]....
5632 The compiler by default uses a caller saves convention for register saving
5633 across function calls, however this can cause unnecessary register pushing
5634 & popping when calling small functions from larger functions.
5635 This option can be used to switch the register saving convention for the
5636 function names specified.
5637 The compiler will not save registers when calling these functions, no extra
5638 code will be generated at the entry & exit for these functions to save
5639 & restore the registers used by these functions, this can SUBSTANTIALLY
5640 reduce code & improve run time performance of the generated code.
5641 In the future the compiler (with inter procedural analysis) will be able
5642 to determine the appropriate scheme to use for each function call.
5643 DO NOT use this option for built-in functions such as _mulint..., if this
5644 option is used for a library function the appropriate library function
5645 needs to be recompiled with the same option.
5646 If the project consists of multiple source files then all the source file
5647 should be compiled with the same -
5657 -callee-saves option string.
5658 Also see #pragma\SpecialChar ~
5660 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
5666 \labelwidthstring 00.00.0000
5681 \begin_inset LatexCommand \index{-\/-debug}
5690 When this option is used the compiler will generate debug information, that
5691 can be used with the SDCDB.
5692 The debug information is collected in a file with .cdb extension.
5693 For more information see documentation for SDCDB.
5695 \labelwidthstring 00.00.0000
5712 \begin_inset LatexCommand \index{-\/-peep-file}
5716 <filename> This option can be used to use additional rules to be used by
5717 the peep hole optimizer.
5718 See section Peep Hole optimizations for details on how to write these rules.
5720 \labelwidthstring 00.00.0000
5725 \begin_inset LatexCommand \index{-S}
5736 Stop after the stage of compilation proper; do not assemble.
5737 The output is an assembler code file for the input file specified.
5739 \labelwidthstring 00.00.0000
5743 -Wa_asmOption[,asmOption]
5746 \begin_inset LatexCommand \index{-Wa\_asmOption[,asmOption]}
5751 Pass the asmOption to the assembler.
5753 \labelwidthstring 00.00.0000
5757 -Wl_linkOption[,linkOption]
5760 \begin_inset LatexCommand \index{-Wl\_linkOption[,linkOption]}
5765 Pass the linkOption to the linker.
5767 \labelwidthstring 00.00.0000
5782 \begin_inset LatexCommand \index{-\/-int-long-reent}
5788 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
5789 Note by default these libraries are compiled as non-reentrant.
5790 See section Installation for more details.
5792 \labelwidthstring 00.00.0000
5807 \begin_inset LatexCommand \index{-\/-cyclomatic}
5816 This option will cause the compiler to generate an information message for
5817 each function in the source file.
5818 The message contains some
5822 information about the function.
5823 The number of edges and nodes the compiler detected in the control flow
5824 graph of the function, and most importantly the
5826 cyclomatic complexity
5827 \begin_inset LatexCommand \index{Cyclomatic complexity}
5833 see section on Cyclomatic Complexity for more details.
5835 \labelwidthstring 00.00.0000
5850 \begin_inset LatexCommand \index{-\/-float-reent}
5859 Floating point library is compiled as reentrant
5860 \begin_inset LatexCommand \index{reentrant}
5864 .See section Installation for more details.
5866 \labelwidthstring 00.00.0000
5881 \begin_inset LatexCommand \index{-\/-nooverlay}
5887 The compiler will not overlay parameters and local variables of any function,
5888 see section Parameters and local variables for more details.
5890 \labelwidthstring 00.00.0000
5905 \begin_inset LatexCommand \index{-\/-main-return}
5911 This option can be used when the code generated is called by a monitor
5913 The compiler will generate a 'ret' upon return from the 'main'
5914 \begin_inset LatexCommand \index{main return}
5919 The default option is to lock up i.e.
5922 \labelwidthstring 00.00.0000
5937 \begin_inset LatexCommand \index{-\/-no-peep}
5943 Disable peep-hole optimization.
5945 \labelwidthstring 00.00.0000
5960 \begin_inset LatexCommand \index{-\/-peep-asm}
5966 Pass the inline assembler code through the peep hole optimizer.
5967 This can cause unexpected changes to inline assembler code, please go through
5968 the peephole optimizer
5969 \begin_inset LatexCommand \index{Peephole optimizer}
5973 rules defined in the source file tree '<target>/peeph.def' before using
5976 \labelwidthstring 00.00.0000
5993 \begin_inset LatexCommand \index{-\/-iram-size<Value>}
5997 Causes the linker to check if the internal ram usage is within limits of
6000 \labelwidthstring 00.00.0000
6017 \begin_inset LatexCommand \index{-\/-xram-size<Value>}
6021 Causes the linker to check if the external ram usage is within limits of
6024 \labelwidthstring 00.00.0000
6041 \begin_inset LatexCommand \index{-\/-code-size<Value>}
6045 Causes the linker to check if the code usage is within limits of the given
6048 \labelwidthstring 00.00.0000
6063 \begin_inset LatexCommand \index{-\/-nostdincl}
6069 This will prevent the compiler from passing on the default include path
6070 to the preprocessor.
6072 \labelwidthstring 00.00.0000
6087 \begin_inset LatexCommand \index{-\/-nostdlib}
6093 This will prevent the compiler from passing on the default library
6094 \begin_inset LatexCommand \index{Libraries}
6100 \labelwidthstring 00.00.0000
6115 \begin_inset LatexCommand \index{-\/-verbose}
6121 Shows the various actions the compiler is performing.
6123 \labelwidthstring 00.00.0000
6128 \begin_inset LatexCommand \index{-V}
6134 Shows the actual commands the compiler is executing.
6136 \labelwidthstring 00.00.0000
6151 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
6157 Hides your ugly and inefficient c-code from the asm file, so you can always
6158 blame the compiler :).
6160 \labelwidthstring 00.00.0000
6175 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
6181 Include i-codes in the asm file.
6182 Sounds like noise but is most helpful for debugging the compiler itself.
6184 \labelwidthstring 00.00.0000
6199 \begin_inset LatexCommand \index{-\/-less-pedantic}
6205 Disable some of the more pedantic warnings (jwk burps: please be more specific
6208 \labelwidthstring 00.00.0000
6223 \begin_inset LatexCommand \index{-\/-print-search-dirs}
6229 Display the directories in the compiler's search path
6231 \labelwidthstring 00.00.0000
6246 \begin_inset LatexCommand \index{-\/-vc}
6252 Display errors and warnings using MSVC style, so you can use SDCC with
6255 \labelwidthstring 00.00.0000
6270 \begin_inset LatexCommand \index{-\/-use-stdout}
6276 Send errors and warnings to stdout instead of stderr
6277 \layout Subsubsection
6279 Intermediate Dump Options
6280 \begin_inset LatexCommand \index{Options intermediate dump}
6285 \begin_inset LatexCommand \index{Intermediate dump options}
6292 The following options are provided for the purpose of retargetting and debugging
6294 These provided a means to dump the intermediate code (iCode
6295 \begin_inset LatexCommand \index{iCode}
6299 ) generated by the compiler in human readable form at various stages of
6300 the compilation process.
6303 \labelwidthstring 00.00.0000
6318 \begin_inset LatexCommand \index{-\/-dumpraw}
6324 This option will cause the compiler to dump the intermediate code into
6327 <source filename>.dumpraw
6329 just after the intermediate code has been generated for a function, i.e.
6330 before any optimizations are done.
6332 \begin_inset LatexCommand \index{Basic blocks}
6336 at this stage ordered in the depth first number, so they may not be in
6337 sequence of execution.
6339 \labelwidthstring 00.00.0000
6354 \begin_inset LatexCommand \index{-\/-dumpgcse}
6360 Will create a dump of iCode's, after global subexpression elimination
6361 \begin_inset LatexCommand \index{Global subexpression elimination}
6367 <source filename>.dumpgcse.
6369 \labelwidthstring 00.00.0000
6384 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
6390 Will create a dump of iCode's, after deadcode elimination
6391 \begin_inset LatexCommand \index{Dead-code elimination}
6397 <source filename>.dumpdeadcode.
6399 \labelwidthstring 00.00.0000
6414 \begin_inset LatexCommand \index{-\/-dumploop}
6423 Will create a dump of iCode's, after loop optimizations
6424 \begin_inset LatexCommand \index{Loop optimization}
6430 <source filename>.dumploop.
6432 \labelwidthstring 00.00.0000
6447 \begin_inset LatexCommand \index{-\/-dumprange}
6456 Will create a dump of iCode's, after live range analysis
6457 \begin_inset LatexCommand \index{Live range analysis}
6463 <source filename>.dumprange.
6465 \labelwidthstring 00.00.0000
6480 \begin_inset LatexCommand \index{-\/-dumlrange}
6486 Will dump the life ranges
6487 \begin_inset LatexCommand \index{Live range analysis}
6493 \labelwidthstring 00.00.0000
6508 \begin_inset LatexCommand \index{-\/-dumpregassign}
6517 Will create a dump of iCode's, after register assignment
6518 \begin_inset LatexCommand \index{Register assignment}
6524 <source filename>.dumprassgn.
6526 \labelwidthstring 00.00.0000
6541 \begin_inset LatexCommand \index{-\/-dumplrange}
6547 Will create a dump of the live ranges of iTemp's
6549 \labelwidthstring 00.00.0000
6564 \begin_inset LatexCommand \index{-\/-dumpall}
6575 Will cause all the above mentioned dumps to be created.
6578 Environment variables
6579 \begin_inset LatexCommand \index{Environment variables}
6586 SDCC recognizes the following environment variables:
6588 \labelwidthstring 00.00.0000
6593 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
6599 SDCC installs a signal handler
6600 \begin_inset LatexCommand \index{signal handler}
6604 to be able to delete temporary files after an user break (^C) or an exception.
6605 If this environment variable is set, SDCC won't install the signal handler
6606 in order to be able to debug SDCC.
6608 \labelwidthstring 00.00.0000
6613 \begin_inset LatexCommand \index{TMP}
6619 \begin_inset LatexCommand \index{TEMP}
6625 \begin_inset LatexCommand \index{TMPDIR}
6631 Path, where temporary files will be created.
6632 The order of the variables is the search order.
6633 In a standard *nix environment these variables are not set, and there's
6634 no need to set them.
6635 On Windows it's recommended to set one of them.
6637 \labelwidthstring 00.00.0000
6642 \begin_inset LatexCommand \index{SDCC\_HOME}
6649 \begin_inset Quotes sld
6652 2.3 Install and search paths
6653 \begin_inset Quotes srd
6658 \labelwidthstring 00.00.0000
6663 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
6670 \begin_inset Quotes sld
6673 2.3 Install and search paths
6674 \begin_inset Quotes srd
6679 \labelwidthstring 00.00.0000
6684 \begin_inset LatexCommand \index{SDCC\_LIB}
6691 \begin_inset Quotes sld
6694 2.3 Install and search paths
6695 \begin_inset Quotes srd
6701 There are some more environment variables recognized by SDCC, but these
6702 are solely used for debugging purposes.
6703 They can change or disappear very quickly, and will never be documented.
6706 MCS51/DS390 Storage Class
6707 \begin_inset LatexCommand \index{Storage class}
6714 In addition to the ANSI storage classes SDCC allows the following MCS51
6715 specific storage classes.
6716 \layout Subsubsection
6719 \begin_inset LatexCommand \index{xdata}
6726 Variables declared with this storage class will be placed in the extern
6732 storage class for Large Memory model, e.g.:
6737 xdata unsigned char xduc;
6738 \layout Subsubsection
6741 \begin_inset LatexCommand \index{data}
6752 storage class for Small Memory model.
6753 Variables declared with this storage class will be allocated in the internal
6760 \layout Subsubsection
6763 \begin_inset LatexCommand \index{idata}
6770 Variables declared with this storage class will be allocated into the indirectly
6771 addressable portion of the internal ram of a 8051, e.g.:
6777 \layout Subsubsection
6780 \begin_inset LatexCommand \index{bit}
6787 This is a data-type and a storage class specifier.
6788 When a variable is declared as a bit, it is allocated into the bit addressable
6789 memory of 8051, e.g.:
6795 \layout Subsubsection
6798 \begin_inset LatexCommand \index{sfr}
6803 \begin_inset LatexCommand \index{sbit}
6810 Like the bit keyword,
6814 signifies both a data-type and storage class, they are used to describe
6815 the special function registers and special bit variables of a 8051, eg:
6820 sfr at 0x80 P0; /* special function register P0 at location 0x80 */
6822 sbit at 0xd7 CY; /* CY (Carry Flag
6823 \begin_inset LatexCommand \index{Flags}
6828 \begin_inset LatexCommand \index{Carry flag}
6836 \begin_inset LatexCommand \index{Pointers}
6843 SDCC allows (via language extensions) pointers to explicitly point to any
6844 of the memory spaces
6845 \begin_inset LatexCommand \index{Memory model}
6850 In addition to the explicit pointers, the compiler uses (by default) generic
6851 pointers which can be used to point to any of the memory spaces.
6855 Pointer declaration examples:
6860 /* pointer physically in xternal ram pointing to object in internal ram
6863 data unsigned char * xdata p;
6867 /* pointer physically in code rom pointing to data in xdata space */
6869 xdata unsigned char * code p;
6873 /* pointer physically in code space pointing to data in code space */
6875 code unsigned char * code p;
6879 /* the following is a generic pointer physically located in xdata space
6885 Well you get the idea.
6890 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
6903 The highest order byte of the
6907 pointers contains the data space information.
6908 Assembler support routines are called whenever data is stored or retrieved
6914 These are useful for developing reusable library
6915 \begin_inset LatexCommand \index{Libraries}
6920 Explicitly specifying the pointer type will generate the most efficient
6925 \begin_inset LatexCommand \index{Parameters}
6930 \begin_inset LatexCommand \index{Local variable}
6937 Automatic (local) variables and parameters to functions can either be placed
6938 on the stack or in data-space.
6939 The default action of the compiler is to place these variables in the internal
6940 RAM (for small model) or external RAM (for large model).
6941 This in fact makes them
6944 \begin_inset LatexCommand \index{static}
6950 so by default functions are non-reentrant
6951 \begin_inset LatexCommand \index{reentrant}
6959 They can be placed on the stack
6960 \begin_inset LatexCommand \index{stack}
6977 \begin_inset LatexCommand \index{-\/-stack-auto}
6983 option or by using the
6986 \begin_inset LatexCommand \index{reentrant}
6992 keyword in the function declaration, e.g.:
6997 unsigned char foo(char i) reentrant
7007 Since stack space on 8051 is limited, the
7025 option should be used sparingly.
7026 Note that the reentrant keyword just means that the parameters & local
7027 variables will be allocated to the stack, it
7031 mean that the function is register bank independent.
7035 Local variables can be assigned storage classes and absolute
7036 \begin_inset LatexCommand \index{Absolute addressing}
7045 unsigned char foo() {
7051 xdata unsigned char i;
7063 data at 0x31 unsigned char j;
7075 In the above example the variable
7079 will be allocated in the external ram,
7083 in bit addressable space and
7102 or when a function is declared as
7106 this should only be done for static variables.
7109 Parameters however are not allowed any storage class, (storage classes for
7110 parameters will be ignored), their allocation is governed by the memory
7111 model in use, and the reentrancy options.
7115 \begin_inset LatexCommand \index{Overlaying}
7123 \begin_inset LatexCommand \index{reentrant}
7127 functions SDCC will try to reduce internal ram space usage by overlaying
7128 parameters and local variables of a function (if possible).
7129 Parameters and local variables of a function will be allocated to an overlayabl
7130 e segment if the function has
7132 no other function calls and the function is non-reentrant and the memory
7134 \begin_inset LatexCommand \index{Memory model}
7141 If an explicit storage class
7142 \begin_inset LatexCommand \index{Storage class}
7146 is specified for a local variable, it will NOT be overlayed.
7149 Note that the compiler (not the linkage editor) makes the decision for overlayin
7151 Functions that are called from an interrupt service routine should be preceded
7152 by a #pragma\SpecialChar ~
7154 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
7158 if they are not reentrant.
7161 Also note that the compiler does not do any processing of inline
7162 \begin_inset LatexCommand \index{inline}
7166 assembler code, so the compiler might incorrectly assign local variables
7167 and parameters of a function into the overlay segment if the inline assembler
7168 code calls other c-functions that might use the overlay.
7169 In that case the #pragma\SpecialChar ~
7170 NOOVERLAY should be used.
7173 Parameters and Local variables of functions that contain 16 or 32 bit multiplica
7175 \begin_inset LatexCommand \index{Multiplication}
7180 \begin_inset LatexCommand \index{Division}
7184 will NOT be overlayed since these are implemented using external functions,
7193 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
7199 void set_error(unsigned char errcd)
7215 void some_isr () interrupt
7216 \begin_inset LatexCommand \index{interrupt}
7221 \begin_inset LatexCommand \index{using}
7251 In the above example the parameter
7259 would be assigned to the overlayable segment if the #pragma\SpecialChar ~
7261 not present, this could cause unpredictable runtime behavior when called
7263 The #pragma\SpecialChar ~
7264 NOOVERLAY ensures that the parameters and local variables for
7265 the function are NOT overlayed.
7268 Interrupt Service Routines
7271 SDCC allows interrupt service routines to be coded in C, with some extended
7277 void timer_isr (void) interrupt 2 using 1
7287 The number following the
7290 \begin_inset LatexCommand \index{interrupt}
7296 keyword is the interrupt number this routine will service.
7297 The compiler will insert a call to this routine in the interrupt vector
7298 table for the interrupt number specified.
7303 keyword is used to tell the compiler to use the specified register bank
7304 (8051 specific) when generating code for this function.
7305 Note that when some function is called from an interrupt service routine
7306 it should be preceded by a #pragma\SpecialChar ~
7308 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
7312 if it is not reentrant.
7313 A special note here, int (16 bit) and long (32 bit) integer division
7314 \begin_inset LatexCommand \index{Division}
7319 \begin_inset LatexCommand \index{Multiplication}
7324 \begin_inset LatexCommand \index{Modulus}
7328 operations are implemented using external support routines developed in
7329 ANSI-C, if an interrupt service routine needs to do any of these operations
7330 then the support routines (as mentioned in a following section) will have
7331 to be recompiled using the
7344 \begin_inset LatexCommand \index{-\/-stack-auto}
7350 option and the source file will need to be compiled using the
7365 \begin_inset LatexCommand \index{-\/-int-long-rent}
7372 If you have multiple source files in your project, interrupt service routines
7373 can be present in any of them, but a prototype of the isr MUST be present
7374 or included in the file that contains the function
7381 Interrupt Numbers and the corresponding address & descriptions for the Standard
7382 8051 are listed below.
7383 SDCC will automatically adjust the interrupt vector table to the maximum
7384 interrupt number specified.
7390 \begin_inset Tabular
7391 <lyxtabular version="3" rows="6" columns="3">
7393 <column alignment="center" valignment="top" leftline="true" width="0in">
7394 <column alignment="center" valignment="top" leftline="true" width="0in">
7395 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0in">
7396 <row topline="true" bottomline="true">
7397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7405 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7413 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7422 <row topline="true">
7423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7439 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7448 <row topline="true">
7449 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7465 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7474 <row topline="true">
7475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7491 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7500 <row topline="true">
7501 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7526 <row topline="true" bottomline="true">
7527 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7535 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7543 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7561 If the interrupt service routine is defined without
7564 \begin_inset LatexCommand \index{using}
7570 a register bank or with register bank 0 (using 0), the compiler will save
7571 the registers used by itself on the stack upon entry and restore them at
7572 exit, however if such an interrupt service routine calls another function
7573 then the entire register bank will be saved on the stack.
7574 This scheme may be advantageous for small interrupt service routines which
7575 have low register usage.
7578 If the interrupt service routine is defined to be using a specific register
7583 are save and restored, if such an interrupt service routine calls another
7584 function (using another register bank) then the entire register bank of
7585 the called function will be saved on the stack.
7586 This scheme is recommended for larger interrupt service routines.
7589 Calling other functions from an interrupt service routine is not recommended,
7590 avoid it if possible.
7594 Also see the _naked modifier.
7602 <TODO: this isn't implemented at all!>
7608 A special keyword may be associated with a function declaring it as
7613 SDCC will generate code to disable all interrupts upon entry to a critical
7614 function and enable them back before returning.
7615 Note that nesting critical functions may cause unpredictable results.
7633 The critical attribute maybe used with other attributes like
7639 \begin_inset LatexCommand \index{Naked functions}
7646 A special keyword may be associated with a function declaring it as
7649 \begin_inset LatexCommand \index{\_naked}
7660 function modifier attribute prevents the compiler from generating prologue
7661 \begin_inset LatexCommand \index{function prologue}
7666 \begin_inset LatexCommand \index{function epilogue}
7670 code for that function.
7671 This means that the user is entirely responsible for such things as saving
7672 any registers that may need to be preserved, selecting the proper register
7673 bank, generating the
7677 instruction at the end, etc.
7678 Practically, this means that the contents of the function must be written
7679 in inline assembler.
7680 This is particularly useful for interrupt functions, which can have a large
7681 (and often unnecessary) prologue/epilogue.
7682 For example, compare the code generated by these two functions:
7687 data unsigned char counter;
7689 void simpleInterrupt(void) interrupt
7690 \begin_inset LatexCommand \index{interrupt}
7708 void nakedInterrupt(void) interrupt 2 _naked
7717 \begin_inset LatexCommand \index{\_asm}
7746 ; MUST explicitly include ret in _naked function.
7753 \begin_inset LatexCommand \index{\_endasm}
7762 For an 8051 target, the generated simpleInterrupt looks like:
7903 whereas nakedInterrupt looks like:
7927 ; MUST explicitly include ret(i) in _naked function.
7930 While there is nothing preventing you from writing C code inside a _naked
7931 function, there are many ways to shoot yourself in the foot doing this,
7932 and it is recommended that you stick to inline assembler.
7935 Functions using private banks
7936 \begin_inset LatexCommand \index{bank}
7946 \begin_inset LatexCommand \index{using}
7952 attribute (which tells the compiler to use a register bank other than the
7953 default bank zero) should only be applied to
7956 \begin_inset LatexCommand \index{interrupt}
7962 functions (see note 1 below).
7963 This will in most circumstances make the generated ISR code more efficient
7964 since it will not have to save registers on the stack.
7971 attribute will have no effect on the generated code for a
7975 function (but may occasionally be useful anyway
7981 possible exception: if a function is called ONLY from 'interrupt' functions
7982 using a particular bank, it can be declared with the same 'using' attribute
7983 as the calling 'interrupt' functions.
7984 For instance, if you have several ISRs using bank one, and all of them
7985 call memcpy(), it might make sense to create a specialized version of memcpy()
7986 'using 1', since this would prevent the ISR from having to save bank zero
7987 to the stack on entry and switch to bank zero before calling the function
7994 (pending: I don't think this has been done yet)
8001 function using a non-zero bank will assume that it can trash that register
8002 bank, and will not save it.
8003 Since high-priority interrupts
8004 \begin_inset LatexCommand \index{interrupt priority}
8008 can interrupt low-priority ones on the 8051 and friends, this means that
8009 if a high-priority ISR
8013 a particular bank occurs while processing a low-priority ISR
8017 the same bank, terrible and bad things can happen.
8018 To prevent this, no single register bank should be
8022 by both a high priority and a low priority ISR.
8023 This is probably most easily done by having all high priority ISRs use
8024 one bank and all low priority ISRs use another.
8025 If you have an ISR which can change priority at runtime, you're on your
8026 own: I suggest using the default bank zero and taking the small performance
8030 It is most efficient if your ISR calls no other functions.
8031 If your ISR must call other functions, it is most efficient if those functions
8032 use the same bank as the ISR (see note 1 below); the next best is if the
8033 called functions use bank zero.
8034 It is very inefficient to call a function using a different, non-zero bank
8040 \begin_inset LatexCommand \index{Absolute addressing}
8047 Data items can be assigned an absolute address with the
8050 \begin_inset LatexCommand \index{at}
8056 keyword, in addition to a storage class, e.g.:
8062 \begin_inset LatexCommand \index{xdata}
8067 \begin_inset LatexCommand \index{at}
8071 0x8000 unsigned char PORTA_8255 ;
8074 In the above example the PORTA_8255 will be allocated to the location 0x8000
8075 of the external ram.
8076 Note that this feature is provided to give the programmer access to
8080 devices attached to the controller.
8081 The compiler does not actually reserve any space for variables declared
8082 in this way (they are implemented with an equate in the assembler).
8083 Thus it is left to the programmer to make sure there are no overlaps with
8084 other variables that are declared without the absolute address.
8085 The assembler listing file (.lst
8086 \begin_inset LatexCommand \index{.lst}
8090 ) and the linker output files (.rst
8091 \begin_inset LatexCommand \index{.rst}
8096 \begin_inset LatexCommand \index{.map}
8100 ) are a good places to look for such overlaps.
8104 Absolute address can be specified for variables in all storage classes,
8111 \begin_inset LatexCommand \index{bit}
8116 \begin_inset LatexCommand \index{at}
8123 The above example will allocate the variable at offset 0x02 in the bit-addressab
8125 There is no real advantage to assigning absolute addresses to variables
8126 in this manner, unless you want strict control over all the variables allocated.
8127 One possible use would be to write hardware portable code.
8128 For example, if you have a routine that uses one or more of the microcontroller
8129 I/O pins, and such pins are different for two different hardwares, you
8130 can declare the I/O pins in you routine using
8143 void DS1306_put(unsigned char value)
8151 unsigned char mask=0x80;
8175 SDI=(value & mask)?1:0;
8216 Then, someplace in the code for the first hardware you would use
8221 bit at 0x80 SDI;\SpecialChar ~
8225 /*I/O port 0, bit 0*/
8227 bit at 0x81 SCLK;\SpecialChar ~
8230 /*I/O port 0, bit 1*/
8232 bit CPOL;\SpecialChar ~
8243 /*This is a variable, let the linker allocate this one*/
8246 Similarly, for the second hardware you would use
8251 bit at 0x83 SDI;\SpecialChar ~
8255 /*I/O port 0, bit 3*/
8257 bit at 0x91 SCLK;\SpecialChar ~
8260 /*I/O port 1, bit 1*/
8262 bit CPOL;\SpecialChar ~
8273 /*This is a variable, let the linker allocate this one*/
8276 and you can use the same hardware dependent routine without changes, as
8277 for example in a library.
8278 This is somehow similar to sbit, but only one absolute address has to be
8279 specified in the whole project.
8283 \begin_inset LatexCommand \index{Startup code}
8290 The compiler inserts a call to the C routine
8292 _sdcc_external_startup()
8293 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
8302 at the start of the CODE area.
8303 This routine is in the runtime library
8304 \begin_inset LatexCommand \index{Runtime library}
8309 By default this routine returns 0, if this routine returns a non-zero value,
8310 the static & global variable initialization will be skipped and the function
8311 main will be invoked Other wise static & global variables will be initialized
8312 before the function main is invoked.
8315 _sdcc_external_startup()
8317 routine to your program to override the default if you need to setup hardware
8318 or perform some other critical operation prior to static & global variable
8322 Inline Assembler Code
8323 \begin_inset LatexCommand \index{Assembler routines}
8330 SDCC allows the use of in-line assembler with a few restriction as regards
8332 All labels defined within inline assembler code
8340 where nnnn is a number less than 100 (which implies a limit of utmost 100
8341 inline assembler labels
8349 It is strongly recommended that each assembly instruction (including labels)
8350 be placed in a separate line (as the example shows).
8364 \begin_inset LatexCommand \index{-\/-peep-asm}
8370 command line option is used, the inline assembler code will be passed through
8371 the peephole optimizer
8372 \begin_inset LatexCommand \index{Peephole optimizer}
8377 This might cause some unexpected changes in the inline assembler code.
8378 Please go through the peephole optimizer rules defined in file
8382 carefully before using this option.
8388 \begin_inset LatexCommand \index{\_asm}
8418 \begin_inset LatexCommand \index{\_endasm}
8425 The inline assembler code can contain any valid code understood by the assembler
8426 , this includes any assembler directives and comment lines.
8427 The compiler does not do any validation of the code within the
8437 Inline assembler code cannot reference any C-Labels, however it can reference
8439 \begin_inset LatexCommand \index{Labels}
8443 defined by the inline assembler, e.g.:
8468 ; some assembler code
8488 /* some more c code */
8490 clabel:\SpecialChar ~
8492 /* inline assembler cannot reference this label */
8504 $0003: ;label (can be reference by inline assembler only)
8516 /* some more c code */
8521 In other words inline assembly code can access labels defined in inline
8522 assembly within the scope of the function.
8523 The same goes the other way, ie.
8524 labels defines in inline assembly CANNOT be accessed by C statements.
8528 \begin_inset LatexCommand \index{int (16 bit)}
8533 \begin_inset LatexCommand \index{long (32 bit)}
8540 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
8541 multiplication and modulus operations are implemented by support routines.
8542 These support routines are all developed in ANSI-C to facilitate porting
8543 to other MCUs, although some model specific assembler optimizations are
8545 The following files contain the described routine, all of them can be found
8546 in <installdir>/share/sdcc/lib.
8552 \begin_inset Tabular
8553 <lyxtabular version="3" rows="11" columns="2">
8555 <column alignment="center" valignment="top" leftline="true" width="0(null)">
8556 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
8557 <row topline="true" bottomline="true">
8558 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8568 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8579 <row topline="true">
8580 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8588 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8593 16 bit multiplication
8597 <row topline="true">
8598 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8606 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8611 signed 16 bit division (calls _divuint)
8615 <row topline="true">
8616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8624 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8629 unsigned 16 bit division
8633 <row topline="true">
8634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8642 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8647 signed 16 bit modulus (calls _moduint)
8651 <row topline="true">
8652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8665 unsigned 16 bit modulus
8669 <row topline="true">
8670 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8678 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8683 32 bit multiplication
8687 <row topline="true">
8688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8696 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8701 signed 32 division (calls _divulong)
8705 <row topline="true">
8706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8714 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8719 unsigned 32 division
8723 <row topline="true">
8724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8732 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8737 signed 32 bit modulus (calls _modulong)
8741 <row topline="true" bottomline="true">
8742 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8750 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8755 unsigned 32 bit modulus
8768 Since they are compiled as
8773 \begin_inset LatexCommand \index{reentrant}
8778 \begin_inset LatexCommand \index{interrupt}
8782 service routines should not do any of the above operations.
8783 If this is unavoidable then the above routines will need to be compiled
8797 \begin_inset LatexCommand \index{-\/-stack-auto}
8803 option, after which the source program will have to be compiled with
8816 \begin_inset LatexCommand \index{-\/-int-long-rent}
8823 Notice that you don't have to call this routines directly.
8824 The compiler will use them automatically every time a integer operation
8828 Floating Point Support
8829 \begin_inset LatexCommand \index{Floating point support}
8836 SDCC supports IEEE (single precision 4 bytes) floating point numbers.The
8837 floating point support routines are derived from gcc's floatlib.c and consists
8838 of the following routines:
8846 \begin_inset Tabular
8847 <lyxtabular version="3" rows="17" columns="2">
8849 <column alignment="center" valignment="top" leftline="true" width="0(null)">
8850 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
8851 <row topline="true" bottomline="true">
8852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8869 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8878 <row topline="true">
8879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8896 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8910 add floating point numbers
8914 <row topline="true">
8915 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8932 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8946 subtract floating point numbers
8950 <row topline="true">
8951 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8968 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8982 divide floating point numbers
8986 <row topline="true">
8987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9004 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9018 multiply floating point numbers
9022 <row topline="true">
9023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9054 convert floating point to unsigned char
9058 <row topline="true">
9059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9076 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9090 convert floating point to signed char
9094 <row topline="true">
9095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9112 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9126 convert floating point to unsigned int
9130 <row topline="true">
9131 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9162 convert floating point to signed int
9166 <row topline="true">
9167 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9193 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9207 convert floating point to unsigned long
9211 <row topline="true">
9212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9243 convert floating point to signed long
9247 <row topline="true">
9248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9265 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9279 convert unsigned char to floating point
9283 <row topline="true">
9284 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9301 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9315 convert char to floating point number
9319 <row topline="true">
9320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9337 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9351 convert unsigned int to floating point
9355 <row topline="true">
9356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9373 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9387 convert int to floating point numbers
9391 <row topline="true">
9392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9409 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9423 convert unsigned long to floating point number
9427 <row topline="true" bottomline="true">
9428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9445 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9459 convert long to floating point number
9472 Note if all these routines are used simultaneously the data space might
9474 For serious floating point usage it is strongly recommended that the large
9476 Also notice that you don't have to call this routines directly.
9477 The compiler will use them automatically every time a floating point operation
9482 \begin_inset LatexCommand \index{Memory model}
9487 \begin_inset LatexCommand \index{MCS51 memory}
9494 SDCC allows two memory models for MCS51 code, small and large.
9495 Modules compiled with different memory models should
9499 be combined together or the results would be unpredictable.
9500 The library routines supplied with the compiler are compiled as both small
9502 The compiled library modules are contained in separate directories as small
9503 and large so that you can link to either set.
9507 When the large model is used all variables declared without a storage class
9508 will be allocated into the external ram, this includes all parameters and
9509 local variables (for non-reentrant
9510 \begin_inset LatexCommand \index{reentrant}
9515 When the small model is used variables without storage class are allocated
9516 in the internal ram.
9519 Judicious usage of the processor specific storage classes
9520 \begin_inset LatexCommand \index{Storage class}
9524 and the 'reentrant' function type will yield much more efficient code,
9525 than using the large model.
9526 Several optimizations are disabled when the program is compiled using the
9527 large model, it is therefore strongly recommended that the small model
9528 be used unless absolutely required.
9532 \begin_inset LatexCommand \index{Memory model}
9537 \begin_inset LatexCommand \index{DS390 memory model}
9544 The only model supported is Flat 24
9545 \begin_inset LatexCommand \index{Flat 24 (memory model)}
9550 This generates code for the 24 bit contiguous addressing mode of the Dallas
9552 In this mode, up to four meg of external RAM or code space can be directly
9554 See the data sheets at www.dalsemi.com for further information on this part.
9558 In older versions of the compiler, this option was used with the MCS51 code
9564 Now, however, the '390 has it's own code generator, selected by the
9573 Note that the compiler does not generate any code to place the processor
9574 into 24 bitmode (although
9578 in the ds390 libraries will do that for you).
9584 \begin_inset LatexCommand \index{Tinibios (DS390)}
9588 , the boot loader or similar code must ensure that the processor is in 24
9589 bit contiguous addressing mode before calling the SDCC startup code.
9607 option, variables will by default be placed into the XDATA segment.
9612 Segments may be placed anywhere in the 4 meg address space using the usual
9624 Note that if any segments are located above 64K, the -r flag must be passed
9625 to the linker to generate the proper segment relocations, and the Intel
9626 HEX output format must be used.
9627 The -r flag can be passed to the linker by using the option
9631 on the sdcc command line.
9632 However, currently the linker can not handle code segments > 64k.
9635 Defines Created by the Compiler
9636 \begin_inset LatexCommand \index{Defines created by the compiler}
9643 The compiler creates the following #defines
9644 \begin_inset LatexCommand \index{\#defines}
9654 \begin_inset Tabular
9655 <lyxtabular version="3" rows="10" columns="2">
9657 <column alignment="center" valignment="top" leftline="true" width="0(null)">
9658 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
9659 <row topline="true" bottomline="true">
9660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9670 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9681 <row topline="true">
9682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9688 \begin_inset LatexCommand \index{SDCC}
9695 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9700 this Symbol is always defined
9704 <row topline="true">
9705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9711 \begin_inset LatexCommand \index{SDCC\_mcs51}
9716 \begin_inset LatexCommand \index{SDCC\_ds390}
9721 \begin_inset LatexCommand \index{SDCC\_z80}
9728 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9733 depending on the model used (e.g.: -mds390
9737 <row topline="true">
9738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9744 \begin_inset LatexCommand \index{\_\_mcs51}
9749 \begin_inset LatexCommand \index{\_\_ds390}
9754 \begin_inset LatexCommand \index{\_\_z80}
9761 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9766 depending on the model used (e.g.
9771 <row topline="true">
9772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9778 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
9785 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9808 <row topline="true">
9809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9815 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
9822 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9845 <row topline="true">
9846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9852 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
9859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9882 <row topline="true">
9883 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9889 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
9896 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9919 <row topline="true">
9920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9926 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
9933 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9946 <row topline="true" bottomline="true">
9947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9953 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
9960 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9982 Redirecting output on Windows Shells
9985 By default SDCC writes it's error messages to
9986 \begin_inset Quotes sld
9990 \begin_inset Quotes srd
9994 To force all messages to
9995 \begin_inset Quotes sld
9999 \begin_inset Quotes srd
10023 \begin_inset LatexCommand \index{-\/-use-stdout}
10028 Aditionaly, if you happen to have visual studio installed in your windows
10029 machine, you can use it to compile your sources using a custom build and
10045 \begin_inset LatexCommand \index{-\/-vc}
10050 Something like this should work:
10094 -model-large -c $(InputPath)
10097 SDCC Technical Data
10101 \begin_inset LatexCommand \index{Optimizations}
10108 SDCC performs a host of standard optimizations in addition to some MCU specific
10111 \layout Subsubsection
10113 Sub-expression Elimination
10114 \begin_inset LatexCommand \index{Subexpression elimination}
10121 The compiler does local and global common subexpression elimination, e.g.:
10132 will be translated to
10144 Some subexpressions are not as obvious as the above example, e.g.:
10154 In this case the address arithmetic a->b[i] will be computed only once;
10155 the equivalent code in C would be.
10167 The compiler will try to keep these temporary variables in registers.
10168 \layout Subsubsection
10170 Dead-Code Elimination
10171 \begin_inset LatexCommand \index{Dead-code elimination}
10190 i = 1; \SpecialChar ~
10195 global = 1;\SpecialChar ~
10208 global = 3;\SpecialChar ~
10219 int global; void f ()
10232 \layout Subsubsection
10235 \begin_inset LatexCommand \index{Copy propagation}
10291 Note: the dead stores created by this copy propagation will be eliminated
10292 by dead-code elimination.
10293 \layout Subsubsection
10296 \begin_inset LatexCommand \index{Loop optimization}
10303 Two types of loop optimizations are done by SDCC loop invariant lifting
10304 and strength reduction of loop induction variables.
10305 In addition to the strength reduction the optimizer marks the induction
10306 variables and the register allocator tries to keep the induction variables
10307 in registers for the duration of the loop.
10308 Because of this preference of the register allocator
10309 \begin_inset LatexCommand \index{Register allocation}
10313 , loop induction optimization causes an increase in register pressure, which
10314 may cause unwanted spilling of other temporary variables into the stack
10315 \begin_inset LatexCommand \index{stack}
10320 The compiler will generate a warning message when it is forced to allocate
10321 extra space either on the stack or data space.
10322 If this extra space allocation is undesirable then induction optimization
10323 can be eliminated either for the entire source file (with -
10333 -noinduction option) or for a given function only using #pragma\SpecialChar ~
10335 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
10348 for (i = 0 ; i < 100 ; i ++)
10362 for (i = 0; i < 100; i++)
10369 As mentioned previously some loop invariants are not as apparent, all static
10370 address computations are also moved out of the loop.
10375 \begin_inset LatexCommand \index{Strength reduction}
10379 , this optimization substitutes an expression by a cheaper expression:
10384 for (i=0;i < 100; i++)
10400 for (i=0;i< 100;i++) {
10406 ar[itemp1] = itemp2;
10423 The more expensive multiplication
10424 \begin_inset LatexCommand \index{Multiplication}
10428 is changed to a less expensive addition.
10429 \layout Subsubsection
10432 \begin_inset LatexCommand \index{Loop reversing}
10439 This optimization is done to reduce the overhead of checking loop boundaries
10440 for every iteration.
10441 Some simple loops can be reversed and implemented using a
10442 \begin_inset Quotes eld
10445 decrement and jump if not zero
10446 \begin_inset Quotes erd
10450 SDCC checks for the following criterion to determine if a loop is reversible
10451 (note: more sophisticated compilers use data-dependency analysis to make
10452 this determination, SDCC uses a more simple minded analysis).
10455 The 'for' loop is of the form
10461 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
10471 The <for body> does not contain
10472 \begin_inset Quotes eld
10476 \begin_inset Quotes erd
10480 \begin_inset Quotes erd
10486 All goto's are contained within the loop.
10489 No function calls within the loop.
10492 The loop control variable <sym> is not assigned any value within the loop
10495 The loop control variable does NOT participate in any arithmetic operation
10499 There are NO switch statements in the loop.
10500 \layout Subsubsection
10502 Algebraic Simplifications
10505 SDCC does numerous algebraic simplifications, the following is a small sub-set
10506 of these optimizations.
10511 i = j + 0 ; /* changed to */ i = j;
10513 i /= 2; /* changed to */ i >>= 1;
10515 i = j - j ; /* changed to */ i = 0;
10517 i = j / 1 ; /* changed to */ i = j;
10520 Note the subexpressions
10521 \begin_inset LatexCommand \index{Subexpression}
10525 given above are generally introduced by macro expansions or as a result
10526 of copy/constant propagation.
10527 \layout Subsubsection
10529 'switch' Statements
10530 \begin_inset LatexCommand \index{switch statement}
10537 SDCC changes switch statements to jump tables
10538 \begin_inset LatexCommand \index{jump tables}
10542 when the following conditions are true.
10546 The case labels are in numerical sequence, the labels need not be in order,
10547 and the starting number need not be one or zero.
10553 switch(i) {\SpecialChar ~
10584 case 4: ...\SpecialChar ~
10616 case 5: ...\SpecialChar ~
10648 case 3: ...\SpecialChar ~
10680 case 6: ...\SpecialChar ~
10748 Both the above switch statements will be implemented using a jump-table.
10752 The number of case labels is at least three, since it takes two conditional
10753 statements to handle the boundary conditions.
10756 The number of case labels is less than 84, since each label takes 3 bytes
10757 and a jump-table can be utmost 256 bytes long.
10761 Switch statements which have gaps in the numeric sequence or those that
10762 have more that 84 case labels can be split into more than one switch statement
10763 for efficient code generation, e.g.:
10813 If the above switch statement is broken down into two switch statements
10852 case 9: \SpecialChar ~
10868 case 12:\SpecialChar ~
10875 then both the switch statements will be implemented using jump-tables whereas
10876 the unmodified switch statement will not be.
10877 \layout Subsubsection
10879 Bit-shifting Operations
10880 \begin_inset LatexCommand \index{Bit shifting}
10887 Bit shifting is one of the most frequently used operation in embedded programmin
10889 SDCC tries to implement bit-shift operations in the most efficient way
10905 generates the following code:
10919 In general SDCC will never setup a loop if the shift count is known.
10951 Note that SDCC stores numbers in little-endian format (i.e.
10952 lowest order first).
10953 \layout Subsubsection
10956 \begin_inset LatexCommand \index{Bit rotation}
10963 A special case of the bit-shift operation is bit rotation, SDCC recognizes
10964 the following expression to be a left bit-rotation:
10974 i = ((i << 1) | (i >> 7));
10983 will generate the following code:
10995 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
10996 ns of this case will also be recognized as bit-rotation, i.e.:
11001 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
11002 \layout Subsubsection
11005 \begin_inset LatexCommand \index{Highest Order Bit}
11012 It is frequently required to obtain the highest order bit of an integral
11013 type (long, int, short or char types).
11014 SDCC recognizes the following expression to yield the highest order bit
11015 and generates optimized code for it, e.g.:
11035 hob = (gint >> 15) & 1;
11045 will generate the following code:
11078 000A E5*01\SpecialChar ~
11104 000C 33\SpecialChar ~
11133 000D E4\SpecialChar ~
11162 000E 13\SpecialChar ~
11191 000F F5*02\SpecialChar ~
11218 Variations of this case however will
11223 It is a standard C expression, so I heartily recommend this be the only
11224 way to get the highest order bit, (it is portable).
11225 Of course it will be recognized even if it is embedded in other expressions,
11231 xyz = gint + ((gint >> 15) & 1);
11234 will still be recognized.
11235 \layout Subsubsection
11238 \begin_inset LatexCommand \index{Peephole optimizer}
11245 The compiler uses a rule based, pattern matching and re-writing mechanism
11246 for peep-hole optimization.
11251 a peep-hole optimizer by Christopher W.
11252 Fraser (cwfraser@microsoft.com).
11253 A default set of rules are compiled into the compiler, additional rules
11254 may be added with the
11267 \begin_inset LatexCommand \index{-\/-peep-file}
11274 The rule language is best illustrated with examples.
11298 The above rule will change the following assembly
11299 \begin_inset LatexCommand \index{Assembler routines}
11321 Note: All occurrences of a
11325 (pattern variable) must denote the same string.
11326 With the above rule, the assembly sequence:
11336 will remain unmodified.
11340 Other special case optimizations may be added by the user (via
11356 some variants of the 8051 MCU allow only
11365 The following two rules will change all
11384 replace { lcall %1 } by { acall %1 }
11386 replace { ljmp %1 } by { ajmp %1 }
11391 inline-assembler code
11393 is also passed through the peep hole optimizer, thus the peephole optimizer
11394 can also be used as an assembly level macro expander.
11395 The rules themselves are MCU dependent whereas the rule language infra-structur
11396 e is MCU independent.
11397 Peephole optimization rules for other MCU can be easily programmed using
11402 The syntax for a rule is as follows:
11407 rule := replace [ restart ] '{' <assembly sequence> '
11445 <assembly sequence> '
11463 '}' [if <functionName> ] '
11468 <assembly sequence> := assembly instruction (each instruction including
11469 labels must be on a separate line).
11473 The optimizer will apply to the rules one by one from the top in the sequence
11474 of their appearance, it will terminate when all rules are exhausted.
11475 If the 'restart' option is specified, then the optimizer will start matching
11476 the rules again from the top, this option for a rule is expensive (performance)
11477 , it is intended to be used in situations where a transformation will trigger
11478 the same rule again.
11479 An example of this (not a good one, it has side effects) is the following
11502 Note that the replace pattern cannot be a blank, but can be a comment line.
11503 Without the 'restart' option only the inner most 'pop' 'push' pair would
11504 be eliminated, i.e.:
11534 the restart option the rule will be applied again to the resulting code
11535 and then all the pop-push pairs will be eliminated to yield:
11545 A conditional function can be attached to a rule.
11546 Attaching rules are somewhat more involved, let me illustrate this with
11573 The optimizer does a look-up of a function name table defined in function
11578 in the source file SDCCpeeph.c, with the name
11583 If it finds a corresponding entry the function is called.
11584 Note there can be no parameters specified for these functions, in this
11589 is crucial, since the function
11593 expects to find the label in that particular variable (the hash table containin
11594 g the variable bindings is passed as a parameter).
11595 If you want to code more such functions, take a close look at the function
11596 labelInRange and the calling mechanism in source file SDCCpeeph.c.
11597 I know this whole thing is a little kludgey, but maybe some day we will
11598 have some better means.
11599 If you are looking at this file, you will also see the default rules that
11600 are compiled into the compiler, you can add your own rules in the default
11601 set there if you get tired of specifying the -
11615 \begin_inset LatexCommand \index{Pragmas}
11622 SDCC supports the following #pragma directives.
11626 \begin_inset LatexCommand \index{\#pragma SAVE}
11630 - this will save all current options to the SAVE/RESTORE stack.
11635 \begin_inset LatexCommand \index{\#pragma RESTORE}
11639 - will restore saved options from the last save.
11640 SAVEs & RESTOREs can be nested.
11641 SDCC uses a SAVE/RESTORE stack: SAVE pushes current options to the stack,
11642 RESTORE pulls current options from the stack.
11647 \begin_inset LatexCommand \index{\#pragma NOGCSE}
11651 - will stop global subexpression elimination.
11655 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
11659 - will stop loop induction optimizations.
11663 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
11667 - will not generate code for boundary value checking, when switch statements
11668 are turned into jump-tables.
11672 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
11676 - the compiler will not overlay the parameters and local variables of a
11681 \begin_inset LatexCommand \index{\#pragma LESS\_PEDANTIC}
11685 - the compiler will not warn you anymore for obvious mistakes, you'r on
11690 \begin_inset LatexCommand \index{\#pragma NOLOOPREVERSE}
11694 - Will not do loop reversal optimization
11698 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
11702 NONE | {acc[,b[,dpl[,dph]]] - The exclude pragma disables generation of
11704 \begin_inset LatexCommand \index{push/pop}
11708 instruction in ISR function (using interrupt
11709 \begin_inset LatexCommand \index{interrupt}
11714 The directive should be placed immediately before the ISR function definition
11715 and it affects ALL ISR functions following it.
11716 To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
11717 EXCLUDE\SpecialChar ~
11719 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
11727 \begin_inset LatexCommand \index{\#pragma NOIV}
11731 - Do not generate interrupt vector table entries for all ISR functions
11732 defined after the pragma.
11733 This is useful in cases where the interrupt vector table must be defined
11734 manually, or when there is a secondary, manually defined interrupt vector
11736 for the autovector feature of the Cypress EZ-USB FX2).
11740 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
11745 \begin_inset LatexCommand \index{function prologue}
11749 function1[,function2[,function3...]] - The compiler by default uses a caller
11750 saves convention for register saving across function calls, however this
11751 can cause unnecessary register pushing & popping when calling small functions
11752 from larger functions.
11753 This option can be used to switch off the register saving convention for
11754 the function names specified.
11755 The compiler will not save registers when calling these functions, extra
11756 code need to be manually inserted at the entry & exit for these functions
11757 to save & restore the registers used by these functions, this can SUBSTANTIALLY
11758 reduce code & improve run time performance of the generated code.
11759 In the future the compiler (with inter procedural analysis) may be able
11760 to determine the appropriate scheme to use for each function call.
11771 -callee-saves command line option is used, the function names specified
11772 in #pragma\SpecialChar ~
11774 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
11778 is appended to the list of functions specified in the command line.
11781 The pragma's are intended to be used to turn-off certain optimizations which
11782 might cause the compiler to generate extra stack / data space to store
11783 compiler generated temporary variables.
11784 This usually happens in large functions.
11785 Pragma directives should be used as shown in the following example, they
11786 are used to control options & optimizations for a given function; pragmas
11787 should be placed before and/or after a function, placing pragma's inside
11788 a function body could have unpredictable results.
11794 \begin_inset LatexCommand \index{\#pragma SAVE}
11798 /* save the current settings */
11801 \begin_inset LatexCommand \index{\#pragma NOGCSE}
11805 /* turnoff global subexpression elimination */
11807 #pragma NOINDUCTION
11808 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
11812 /* turn off induction optimizations */
11835 \begin_inset LatexCommand \index{\#pragma RESTORE}
11839 /* turn the optimizations back on */
11842 The compiler will generate a warning message when extra space is allocated.
11843 It is strongly recommended that the SAVE and RESTORE pragma's be used when
11844 changing options for a function.
11849 <pending: this is messy and incomplete>
11854 Compiler support routines (_gptrget, _mulint etc)
11857 Stdclib functions (puts, printf, strcat etc)
11860 Math functions (sin, pow, sqrt etc)
11863 license statements for the libraries are missing
11866 Interfacing with Assembly Routines
11867 \begin_inset LatexCommand \index{Assembler routines}
11872 \layout Subsubsection
11874 Global Registers used for Parameter Passing
11875 \begin_inset LatexCommand \index{Parameter passing}
11882 The compiler always uses the global registers
11885 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
11890 \begin_inset LatexCommand \index{B (register)}
11899 \begin_inset LatexCommand \index{ACC}
11905 to pass the first parameter to a routine.
11906 The second parameter onwards is either allocated on the stack (for reentrant
11917 -stack-auto is used) or in the internal / external ram (depending on the
11920 \layout Subsubsection
11922 Assembler Routine(non-reentrant
11923 \begin_inset LatexCommand \index{reentrant}
11928 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
11935 In the following example the function c_func calls an assembler routine
11936 asm_func, which takes two parameters.
11941 extern int asm_func(unsigned char, unsigned char);
11945 int c_func (unsigned char i, unsigned char j)
11953 return asm_func(i,j);
11967 return c_func(10,9);
11972 The corresponding assembler function is:
11977 .globl _asm_func_PARM_2
12041 add a,_asm_func_PARM_2
12066 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
12083 Note here that the return values are placed in 'dpl' - One byte return value,
12084 'dpl' LSB & 'dph' MSB for two byte values.
12085 'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
12086 b' & 'acc' for four byte values.
12089 The parameter naming convention is _<function_name>_PARM_<n>, where n is
12090 the parameter number starting from 1, and counting from the left.
12091 The first parameter is passed in
12092 \begin_inset Quotes eld
12096 \begin_inset Quotes erd
12099 for One bye parameter,
12100 \begin_inset Quotes eld
12104 \begin_inset Quotes erd
12108 \begin_inset Quotes eld
12112 \begin_inset Quotes erd
12115 for three bytes and
12116 \begin_inset Quotes eld
12120 \begin_inset Quotes erd
12123 for four bytes, the variable name for the second parameter will be _<function_n
12128 Assemble the assembler routine with the following command:
12135 asx8051 -losg asmfunc.asm
12142 Then compile and link the assembler routine to the C source file with the
12150 sdcc cfunc.c asmfunc.rel
12151 \layout Subsubsection
12153 Assembler Routine(reentrant
12154 \begin_inset LatexCommand \index{reentrant}
12159 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
12166 In this case the second parameter onwards will be passed on the stack, the
12167 parameters are pushed from right to left i.e.
12168 after the call the left most parameter will be on the top of the stack.
12169 Here is an example:
12174 extern int asm_func(unsigned char, unsigned char);
12178 int c_func (unsigned char i, unsigned char j) reentrant
12186 return asm_func(i,j);
12200 return c_func(10,9);
12205 The corresponding assembler routine is:
12311 The compiling and linking procedure remains the same, however note the extra
12312 entry & exit linkage required for the assembler code, _bp is the stack
12313 frame pointer and is used to compute the offset into the stack for parameters
12314 and local variables.
12318 \begin_inset LatexCommand \index{stack}
12323 \begin_inset LatexCommand \index{External stack}
12330 The external stack is located at the start of the external ram segment,
12331 and is 256 bytes in size.
12342 -xstack option is used to compile the program, the parameters and local
12343 variables of all reentrant functions are allocated in this area.
12344 This option is provided for programs with large stack space requirements.
12345 When used with the -
12355 -stack-auto option, all parameters and local variables are allocated on
12356 the external stack (note support libraries will need to be recompiled with
12360 The compiler outputs the higher order address byte of the external ram segment
12361 into PORT P2, therefore when using the External Stack option, this port
12362 MAY NOT be used by the application program.
12366 \begin_inset LatexCommand \index{ANSI-compliance}
12373 Deviations from the compliance:
12376 functions are not always reentrant.
12379 structures cannot be assigned values directly, cannot be passed as function
12380 parameters or assigned to each other and cannot be a return value from
12407 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
12418 struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
12440 return rets;/* is invalid in SDCC although allowed in ANSI */
12447 \begin_inset LatexCommand \index{long long (not supported)}
12452 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
12460 \begin_inset LatexCommand \index{double (not supported)}
12464 ' precision floating point
12465 \begin_inset LatexCommand \index{Floating point support}
12472 No support for setjmp and longjmp (for now).
12476 \begin_inset LatexCommand \index{K\&R style}
12480 function declarations are NOT allowed.
12486 foo(i,j) /* this old style of function declarations */
12488 int i,j; /* are valid in ANSI but not valid in SDCC */
12503 functions declared as pointers must be dereferenced during the call.
12514 /* has to be called like this */
12516 (*foo)(); /* ANSI standard allows calls to be made like 'foo()' */
12520 Cyclomatic Complexity
12521 \begin_inset LatexCommand \index{Cyclomatic complexity}
12528 Cyclomatic complexity of a function is defined as the number of independent
12529 paths the program can take during execution of the function.
12530 This is an important number since it defines the number test cases you
12531 have to generate to validate the function.
12532 The accepted industry standard for complexity number is 10, if the cyclomatic
12533 complexity reported by SDCC exceeds 10 you should think about simplification
12534 of the function logic.
12535 Note that the complexity level is not related to the number of lines of
12536 code in a function.
12537 Large functions can have low complexity, and small functions can have large
12543 SDCC uses the following formula to compute the complexity:
12548 complexity = (number of edges in control flow graph) - (number of nodes
12549 in control flow graph) + 2;
12553 Having said that the industry standard is 10, you should be aware that in
12554 some cases it be may unavoidable to have a complexity level of less than
12556 For example if you have switch statement with more than 10 case labels,
12557 each case label adds one to the complexity level.
12558 The complexity level is by no means an absolute measure of the algorithmic
12559 complexity of the function, it does however provide a good starting point
12560 for which functions you might look at for further optimization.
12566 Here are a few guidelines that will help the compiler generate more efficient
12567 code, some of the tips are specific to this compiler others are generally
12568 good programming practice.
12571 Use the smallest data type to represent your data-value.
12572 If it is known in advance that the value is going to be less than 256 then
12573 use an 'unsigned char' instead of a 'short' or 'int'.
12576 Use unsigned when it is known in advance that the value is not going to
12578 This helps especially if you are doing division or multiplication.
12581 NEVER jump into a LOOP.
12584 Declare the variables to be local whenever possible, especially loop control
12585 variables (induction).
12588 Since the compiler does not always do implicit integral promotion, the programme
12589 r should do an explicit cast when integral promotion is required.
12592 Reducing the size of division, multiplication & modulus operations can reduce
12593 code size substantially.
12594 Take the following code for example.
12600 foobar(unsigned int p1, unsigned char ch)
12608 unsigned char ch1 = p1 % ch ;
12619 For the modulus operation the variable ch will be promoted to unsigned int
12620 first then the modulus operation will be performed (this will lead to a
12621 call to support routine _moduint()), and the result will be casted to a
12623 If the code is changed to
12628 foobar(unsigned int p1, unsigned char ch)
12636 unsigned char ch1 = (unsigned char)p1 % ch ;
12647 It would substantially reduce the code generated (future versions of the
12648 compiler will be smart enough to detect such optimization opportunities).
12652 Notes on MCS51 memory
12653 \begin_inset LatexCommand \index{MCS51 memory}
12660 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12661 RAM memory which is structured as follows
12665 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
12668 - Bytes 20-2F - 16 bytes to hold 128 bit variables and,
12670 - Bytes 30-7F - 80 bytes for general purpose use.
12675 Additionally some members of the MCS51 family may have up to 128 bytes of
12676 additional, indirectly addressable, internal RAM memory (
12681 Furthermore, some chips may have some built in external memory (
12685 ) which should not be confused with the internal, directly addressable RAM
12691 Usually this built in
12695 memory has to be activated before using it (you can probably find this
12696 information on the datasheet of the microcontroller your are using).
12699 Normally SDCC will only use the first bank
12700 \begin_inset LatexCommand \index{bank}
12704 of registers (register bank 0), but it is possible to specify that other
12705 banks of registers should be used in interrupt
12706 \begin_inset LatexCommand \index{interrupt}
12711 By default, the compiler will place the stack after the last byte of allocated
12712 memory for variables.
12713 For example, if the first 2 banks of registers are used, and only four
12718 variables, it will position the base of the internal stack at address 20
12720 This implies that as the stack
12721 \begin_inset LatexCommand \index{stack}
12725 grows, it will use up the remaining register banks, and the 16 bytes used
12726 by the 128 bit variables, and 80 bytes for general purpose use.
12727 If any bit variables are used, the data variables will be placed after
12728 the byte holding the last bit variable.
12729 For example, if register banks 0 and 1 are used, and there are 9 bit variables
12734 variables will be placed starting at address 0x22.
12746 \begin_inset LatexCommand \index{-\/-data-loc}
12750 to specify the start address of the
12764 -iram-size to specify the size of the total internal RAM (
12776 By default the 8051 linker will place the stack after the last byte of data
12789 \begin_inset LatexCommand \index{-\/-stack-loc}
12793 allows you to specify the start of the stack, i.e.
12794 you could start it after any data in the general purpose area.
12795 If your microcontroller has additional indirectly addressable internal
12800 ) you can place the stack on it.
12801 You may also need to use -
12812 \begin_inset LatexCommand \index{-\/-data-loc}
12816 to set the start address of the external RAM (
12831 \begin_inset LatexCommand \index{-\/-data-loc}
12835 to specify its size.
12836 Same goes for the code memory, using -
12847 \begin_inset LatexCommand \index{-\/-data-loc}
12862 \begin_inset LatexCommand \index{-\/-data-loc}
12867 If in doubt, don't specify any options and see if the resulting memory
12868 layout is appropriate, then you can adjust it.
12871 The 8051 linker generates two files with memory allocation information.
12872 The first, with extension .map shows all the variables and segments.
12873 The second with extension .mem shows the final memory layout.
12874 The linker will complaint either if memory segments overlap, there is not
12875 enough memory, or there is not enough space for stack.
12876 If you get any linking warnings and/or errors related to stack or segments
12877 allocation, take a look at either the .map or .mem files to find out what
12879 The .mem file may even suggest a solution to the problem.
12883 \begin_inset LatexCommand \index{Tools}
12887 included in the distribution
12893 \begin_inset Tabular
12894 <lyxtabular version="3" rows="12" columns="3">
12896 <column alignment="center" valignment="top" leftline="true" width="0pt">
12897 <column alignment="center" valignment="top" leftline="true" width="0pt">
12898 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
12899 <row topline="true" bottomline="true">
12900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12908 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12916 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12925 <row topline="true">
12926 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12934 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12939 Simulator for various architectures
12942 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12951 <row topline="true">
12952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12965 header file conversion
12968 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12973 sdcc/support/scripts
12977 <row topline="true">
12978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12986 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12991 header file conversion
12994 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12999 sdcc/support/scripts
13003 <row topline="true">
13004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13038 <row topline="true">
13039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13055 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13073 <row topline="true">
13074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13108 <row topline="true">
13109 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13125 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13143 <row topline="true">
13144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13178 <row topline="true">
13179 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13187 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13195 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13213 <row topline="true">
13214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13230 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13248 <row topline="true" bottomline="true">
13249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13265 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13292 Related open source tools
13293 \begin_inset LatexCommand \index{Related tools}
13303 \begin_inset Tabular
13304 <lyxtabular version="3" rows="7" columns="3">
13306 <column alignment="center" valignment="top" leftline="true" width="0pt">
13307 <column alignment="center" valignment="top" leftline="true" width="0pt">
13308 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
13309 <row topline="true" bottomline="true">
13310 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13326 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13335 <row topline="true">
13336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13342 \begin_inset LatexCommand \index{gpsim}
13349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13357 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13363 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
13371 <row topline="true">
13372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13378 \begin_inset LatexCommand \index{srecord}
13385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13390 Object file conversion, checksumming, ...
13393 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13399 \begin_inset LatexCommand \url{http://srecord.sourceforge.net/}
13407 <row topline="true">
13408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13414 \begin_inset LatexCommand \index{objdump}
13421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13426 Object file conversion, ...
13429 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13434 Part of binutils (should be there anyway)
13438 <row topline="true">
13439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13445 \begin_inset LatexCommand \index{doxygen}
13452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13457 Source code documentation system
13460 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13466 \begin_inset LatexCommand \url{http://www.doxygen.org}
13474 <row topline="true">
13475 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13481 \begin_inset LatexCommand \index{splint}
13488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13493 Statically checks c sources
13496 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13502 \begin_inset LatexCommand \url{http://www.splint.org}
13510 <row topline="true" bottomline="true">
13511 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13517 \begin_inset LatexCommand \index{ddd}
13524 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13529 Debugger, serves nicely as GUI to sdcdb
13530 \begin_inset LatexCommand \index{sdcdb}
13537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13543 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
13560 Related documentation / recommended reading
13566 \begin_inset Tabular
13567 <lyxtabular version="3" rows="5" columns="3">
13569 <column alignment="center" valignment="top" leftline="true" width="0pt">
13570 <column alignment="center" valignment="top" leftline="true" width="0pt">
13571 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
13572 <row topline="true" bottomline="true">
13573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13589 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13598 <row topline="true">
13599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13609 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13614 Advanced Compiler Design and Implementation
13617 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13626 <row topline="true">
13627 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13644 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13650 \begin_inset LatexCommand \index{C Reference card}
13657 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13663 \begin_inset LatexCommand \url{http://www.refcards.com/about/c.html}
13671 <row topline="true">
13672 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13677 test_suite_spec.pdf
13680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13685 sdcc regression test
13686 \begin_inset LatexCommand \index{Regression test}
13693 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13702 <row topline="true" bottomline="true">
13703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13729 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13734 sdcc internal documentation
13737 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13755 Retargetting for other MCUs.
13758 The issues for retargetting the compiler are far too numerous to be covered
13760 What follows is a brief description of each of the seven phases of the
13761 compiler and its MCU dependency.
13764 Parsing the source and building the annotated parse tree.
13765 This phase is largely MCU independent (except for the language extensions).
13766 Syntax & semantic checks are also done in this phase, along with some initial
13767 optimizations like back patching labels and the pattern matching optimizations
13768 like bit-rotation etc.
13771 The second phase involves generating an intermediate code which can be easy
13772 manipulated during the later phases.
13773 This phase is entirely MCU independent.
13774 The intermediate code generation assumes the target machine has unlimited
13775 number of registers, and designates them with the name iTemp.
13776 The compiler can be made to dump a human readable form of the code generated
13790 This phase does the bulk of the standard optimizations and is also MCU independe
13792 This phase can be broken down into several sub-phases:
13796 Break down intermediate code (iCode) into basic blocks.
13798 Do control flow & data flow analysis on the basic blocks.
13800 Do local common subexpression elimination, then global subexpression elimination
13802 Dead code elimination
13806 If loop optimizations caused any changes then do 'global subexpression eliminati
13807 on' and 'dead code elimination' again.
13810 This phase determines the live-ranges; by live range I mean those iTemp
13811 variables defined by the compiler that still survive after all the optimization
13813 Live range analysis
13814 \begin_inset LatexCommand \index{Live range analysis}
13818 is essential for register allocation, since these computation determines
13819 which of these iTemps will be assigned to registers, and for how long.
13822 Phase five is register allocation.
13823 There are two parts to this process.
13827 The first part I call 'register packing' (for lack of a better term).
13828 In this case several MCU specific expression folding is done to reduce
13833 The second part is more MCU independent and deals with allocating registers
13834 to the remaining live ranges.
13835 A lot of MCU specific code does creep into this phase because of the limited
13836 number of index registers available in the 8051.
13839 The Code generation phase is (unhappily), entirely MCU dependent and very
13840 little (if any at all) of this code can be reused for other MCU.
13841 However the scheme for allocating a homogenized assembler operand for each
13842 iCode operand may be reused.
13845 As mentioned in the optimization section the peep-hole optimizer is rule
13846 based system, which can reprogrammed for other MCUs.
13850 \begin_inset LatexCommand \index{sdcdb}
13854 - Source Level Debugger
13855 \begin_inset LatexCommand \index{Debugger}
13862 SDCC is distributed with a source level debugger.
13863 The debugger uses a command line interface, the command repertoire of the
13864 debugger has been kept as close to gdb
13865 \begin_inset LatexCommand \index{gdb}
13869 (the GNU debugger) as possible.
13870 The configuration and build process is part of the standard compiler installati
13871 on, which also builds and installs the debugger in the target directory
13872 specified during configuration.
13873 The debugger allows you debug BOTH at the C source and at the ASM source
13877 Compiling for Debugging
13880 The \SpecialChar \-
13882 debug option must be specified for all files for which debug information
13883 is to be generated.
13884 The complier generates a .adb file for each of these files.
13885 The linker creates the .cdb file from the .adb files and the address information.
13886 This .cdb is used by the debugger.
13889 How the Debugger Works
13902 -debug option is specified the compiler generates extra symbol information
13903 some of which are put into the the assembler source and some are put into
13905 Then the linker creates the .cdb file from the individual .adb files with
13906 the address information for the symbols.
13907 The debugger reads the symbolic information generated by the compiler &
13908 the address information generated by the linker.
13909 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
13910 execution is controlled by the debugger.
13911 When a command is issued for the debugger, it translates it into appropriate
13912 commands for the simulator.
13915 Starting the Debugger
13918 The debugger can be started using the following command line.
13919 (Assume the file you are debugging has the file name foo).
13933 The debugger will look for the following files.
13936 foo.c - the source file.
13939 foo.cdb - the debugger symbol information file.
13942 foo.ihx - the Intel hex format
13943 \begin_inset LatexCommand \index{Intel hex format}
13950 Command Line Options.
13963 -directory=<source file directory> this option can used to specify the directory
13965 The debugger will look into the directory list specified for source, cdb
13967 The items in the directory list must be separated by ':', e.g.
13968 if the source files can be in the directories /home/src1 and /home/src2,
13979 -directory option should be -
13989 -directory=/home/src1:/home/src2.
13990 Note there can be no spaces in the option.
13994 -cd <directory> - change to the <directory>.
13997 -fullname - used by GUI front ends.
14000 -cpu <cpu-type> - this argument is passed to the simulator please see the
14001 simulator docs for details.
14004 -X <Clock frequency > this options is passed to the simulator please see
14005 the simulator docs for details.
14008 -s <serial port file> passed to simulator see the simulator docs for details.
14011 -S <serial in,out> passed to simulator see the simulator docs for details.
14017 As mention earlier the command interface for the debugger has been deliberately
14018 kept as close the GNU debugger gdb, as possible.
14019 This will help the integration with existing graphical user interfaces
14020 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
14021 \layout Subsubsection
14023 break [line | file:line | function | file:function]
14026 Set breakpoint at specified line or function:
14035 sdcdb>break foo.c:100
14037 sdcdb>break funcfoo
14039 sdcdb>break foo.c:funcfoo
14040 \layout Subsubsection
14042 clear [line | file:line | function | file:function ]
14045 Clear breakpoint at specified line or function:
14054 sdcdb>clear foo.c:100
14056 sdcdb>clear funcfoo
14058 sdcdb>clear foo.c:funcfoo
14059 \layout Subsubsection
14064 Continue program being debugged, after breakpoint.
14065 \layout Subsubsection
14070 Execute till the end of the current function.
14071 \layout Subsubsection
14076 Delete breakpoint number 'n'.
14077 If used without any option clear ALL user defined break points.
14078 \layout Subsubsection
14080 info [break | stack | frame | registers ]
14083 info break - list all breakpoints
14086 info stack - show the function call stack.
14089 info frame - show information about the current execution frame.
14092 info registers - show content of all registers.
14093 \layout Subsubsection
14098 Step program until it reaches a different source line.
14099 \layout Subsubsection
14104 Step program, proceeding through subroutine calls.
14105 \layout Subsubsection
14110 Start debugged program.
14111 \layout Subsubsection
14116 Print type information of the variable.
14117 \layout Subsubsection
14122 print value of variable.
14123 \layout Subsubsection
14128 load the given file name.
14129 Note this is an alternate method of loading file for debugging.
14130 \layout Subsubsection
14135 print information about current frame.
14136 \layout Subsubsection
14141 Toggle between C source & assembly source.
14142 \layout Subsubsection
14144 ! simulator command
14147 Send the string following '!' to the simulator, the simulator response is
14149 Note the debugger does not interpret the command being sent to the simulator,
14150 so if a command like 'go' is sent the debugger can loose its execution
14151 context and may display incorrect values.
14152 \layout Subsubsection
14159 My name is Bobby Brown"
14162 Interfacing with XEmacs
14163 \begin_inset LatexCommand \index{XEmacs}
14168 \begin_inset LatexCommand \index{Emacs}
14175 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
14176 sdcdb.el and sdcdbsrc.el.
14177 These two files can be found in the $(prefix)/bin directory after the installat
14179 These files need to be loaded into XEmacs for the interface to work.
14180 This can be done at XEmacs startup time by inserting the following into
14181 your '.xemacs' file (which can be found in your HOME directory):
14187 (load-file sdcdbsrc.el)
14193 .xemacs is a lisp file so the () around the command is REQUIRED.
14194 The files can also be loaded dynamically while XEmacs is running, set the
14195 environment variable 'EMACSLOADPATH' to the installation bin directory
14196 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
14197 To start the interface enter the following command:
14211 You will prompted to enter the file name to be debugged.
14216 The command line options that are passed to the simulator directly are bound
14217 to default values in the file sdcdbsrc.el.
14218 The variables are listed below, these values maybe changed as required.
14221 sdcdbsrc-cpu-type '51
14224 sdcdbsrc-frequency '11059200
14227 sdcdbsrc-serial nil
14230 The following is a list of key mapping for the debugger interface.
14238 ;; Current Listing ::
14240 ;;key\SpecialChar ~
14255 binding\SpecialChar ~
14279 ;;---\SpecialChar ~
14294 ------\SpecialChar ~
14334 sdcdb-next-from-src\SpecialChar ~
14360 sdcdb-back-from-src\SpecialChar ~
14386 sdcdb-cont-from-src\SpecialChar ~
14396 SDCDB continue command
14412 sdcdb-step-from-src\SpecialChar ~
14438 sdcdb-whatis-c-sexp\SpecialChar ~
14448 SDCDB ptypecommand for data at
14512 sdcdbsrc-delete\SpecialChar ~
14526 SDCDB Delete all breakpoints if no arg
14574 given or delete arg (C-u arg x)
14590 sdcdbsrc-frame\SpecialChar ~
14605 SDCDB Display current frame if no arg,
14654 given or display frame arg
14719 sdcdbsrc-goto-sdcdb\SpecialChar ~
14729 Goto the SDCDB output buffer
14745 sdcdb-print-c-sexp\SpecialChar ~
14756 SDCDB print command for data at
14820 sdcdbsrc-goto-sdcdb\SpecialChar ~
14830 Goto the SDCDB output buffer
14846 sdcdbsrc-mode\SpecialChar ~
14862 Toggles Sdcdbsrc mode (turns it off)
14866 ;; C-c C-f\SpecialChar ~
14874 sdcdb-finish-from-src\SpecialChar ~
14882 SDCDB finish command
14886 ;; C-x SPC\SpecialChar ~
14894 sdcdb-break\SpecialChar ~
14912 Set break for line with point
14914 ;; ESC t\SpecialChar ~
14924 sdcdbsrc-mode\SpecialChar ~
14940 Toggle Sdcdbsrc mode
14942 ;; ESC m\SpecialChar ~
14952 sdcdbsrc-srcmode\SpecialChar ~
14976 The Z80 and gbz80 port
14979 SDCC can target both the Zilog Z80 and the Nintendo Gameboy's Z80-like gbz80.
14980 The port is incomplete - long support is incomplete (mul, div and mod are
14981 unimplemented), and both float and bitfield support is missing.
14982 Apart from that the code generated is correct.
14985 As always, the code is the authoritave reference - see z80/ralloc.c and z80/gen.c.
14986 The stack frame is similar to that generated by the IAR Z80 compiler.
14987 IX is used as the base pointer, HL is used as a temporary register, and
14988 BC and DE are available for holding variables.
14989 IY is currently unused.
14990 Return values are stored in HL.
14991 One bad side effect of using IX as the base pointer is that a functions
14992 stack frame is limited to 127 bytes - this will be fixed in a later version.
14996 \begin_inset LatexCommand \index{Support}
15003 SDCC has grown to be a large project.
15004 The compiler alone (without the preprocessor, assembler and linker) is
15005 about 40,000 lines of code (blank stripped).
15006 The open source nature of this project is a key to its continued growth
15008 You gain the benefit and support of many active software developers and
15010 Is SDCC perfect? No, that's why we need your help.
15011 The developers take pride in fixing reported bugs.
15012 You can help by reporting the bugs and helping other SDCC users.
15013 There are lots of ways to contribute, and we encourage you to take part
15014 in making SDCC a great software package.
15018 The SDCC project is hosted on the sdcc sourceforge site at
15019 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
15024 You'll find the complete set of mailing lists
15025 \begin_inset LatexCommand \index{Mailing list}
15029 , forums, bug reporting system, patch submission
15030 \begin_inset LatexCommand \index{Patch submission}
15035 \begin_inset LatexCommand \index{download}
15039 area and cvs code repository
15040 \begin_inset LatexCommand \index{cvs code repository}
15048 \begin_inset LatexCommand \index{Bugs}
15053 \begin_inset LatexCommand \index{Reporting bugs}
15060 The recommended way of reporting bugs is using the infrastructure of the
15062 You can follow the status of bug reports there and have an overview about
15066 Bug reports are automatically forwarded to the developer mailing list and
15067 will be fixed ASAP.
15068 When reporting a bug, it is very useful to include a small test program
15069 (the smaller the better) which reproduces the problem.
15070 If you can isolate the problem by looking at the generated assembly code,
15071 this can be very helpful.
15072 Compiling your program with the -
15083 \begin_inset LatexCommand \index{-\/-dumpall}
15087 option can sometimes be useful in locating optimization problems.
15088 When reporting a bug please maker sure you:
15091 Attach the code you are compiling with SDCC.
15095 Specify the exact command you use to run SDCC, or attach your Makefile.
15099 Specify the SDCC version (type "sdcc -v"), your platform, and operating
15104 Provide an exact copy of any error message or incorrect output.
15108 Put something meaningful in the subject of your message.
15111 Please attempt to include these 5 important parts, as applicable, in all
15112 requests for support or when reporting any problems or bugs with SDCC.
15113 Though this will make your message lengthy, it will greatly improve your
15114 chance that SDCC users and developers will be able to help you.
15115 Some SDCC developers are frustrated by bug reports without code provided
15116 that they can use to reproduce and ultimately fix the problem, so please
15117 be sure to provide sample code if you are reporting a bug!
15120 Please have a short check that you are using a recent version of SDCC and
15121 the bug is not yet known.
15122 This is the link for reporting bugs:
15123 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
15130 Requesting Features
15131 \begin_inset LatexCommand \index{Feature request}
15136 \begin_inset LatexCommand \index{Requesting features}
15143 Like bug reports feature requests are forwarded to the developer mailing
15145 This is the link for requesting features:
15146 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
15156 These links should take you directly to the
15157 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
15167 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
15168 automated messages (mid 2003)
15172 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
15176 , lists and forums are archived so if you are lucky someone already had
15181 \begin_inset LatexCommand \index{Changelog}
15188 You can follow the status of the cvs version
15189 \begin_inset LatexCommand \index{version}
15193 of SDCC by watching the file
15194 \begin_inset LatexCommand \htmlurl[ChangeLog]{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/sdcc/sdcc/ChangeLog?rev=HEAD&content-type=text/plain}
15198 in the cvs-repository.
15202 \begin_inset LatexCommand \index{Release policy}
15209 Historically there often were long delays between official releases and
15210 the sourceforge download area tends to get not updated at all.
15211 Current excuses might refer to problems with live range analysis, but if
15212 this is fixed, the next problem rising is that another excuse will have
15214 Kidding aside, we have to get better there! On the other hand there are
15215 daily snapshots available at
15216 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
15220 , and you can always built the very last version (hopefully with many bugs
15221 fixed, and features added) from the source code available at
15222 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
15230 \begin_inset LatexCommand \index{Examples}
15237 You'll find some small examples in the directory sdcc/device/examples/
15240 Maybe we should include some links to real world applications.
15241 Preferably pointer to pointers (one for each architecture) so this stays
15246 \begin_inset LatexCommand \index{Quality control}
15253 The compiler is passed through nightly compile and build checks.
15259 \begin_inset LatexCommand \index{Regression test}
15263 check that SDCC itself compiles flawlessly on several platforms and checks
15264 the quality of the code generated by SDCC by running the code through simulator
15266 There is a separate document
15269 \begin_inset LatexCommand \index{Test suite}
15278 You'll find the test code in the directory
15280 sdcc/support/regression
15283 You can run these tests manually by running
15287 in this directory (or f.e.
15292 if you don't want to run the complete tests).
15293 The test code might also be interesting if you want to look for examples
15294 \begin_inset LatexCommand \index{Examples}
15298 checking corner cases of SDCC or if you plan to submit patches
15299 \begin_inset LatexCommand \index{Patch submission}
15306 The pic port uses a different set of regression tests, you'll find them
15309 sdcc/src/regression
15315 \begin_inset LatexCommand \index{Compiler internals}
15322 The anatomy of the compiler
15327 This is an excerpt from an article published in Circuit Cellar Magazine
15329 It's a little outdated (the compiler is much more efficient now and user/develo
15330 per friendly), but pretty well exposes the guts of it all.
15336 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
15337 It is fairly easy to retarget for other 8-bit MCU.
15338 Here we take a look at some of the internals of the compiler.
15343 \begin_inset LatexCommand \index{Parsing}
15350 Parsing the input source file and creating an AST (Annotated Syntax Tree
15351 \begin_inset LatexCommand \index{Annotated syntax tree}
15356 This phase also involves propagating types (annotating each node of the
15357 parse tree with type information) and semantic analysis.
15358 There are some MCU specific parsing rules.
15359 For example the storage classes, the extended storage classes are MCU specific
15360 while there may be a xdata storage class for 8051 there is no such storage
15361 class for z80 or Atmel AVR.
15362 SDCC allows MCU specific storage class extensions, i.e.
15363 xdata will be treated as a storage class specifier when parsing 8051 C
15364 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
15369 \begin_inset LatexCommand \index{iCode}
15376 Intermediate code generation.
15377 In this phase the AST is broken down into three-operand form (iCode).
15378 These three operand forms are represented as doubly linked lists.
15379 ICode is the term given to the intermediate form generated by the compiler.
15380 ICode example section shows some examples of iCode generated for some simple
15381 C source functions.
15385 \begin_inset LatexCommand \index{Optimizations}
15392 Bulk of the target independent optimizations is performed in this phase.
15393 The optimizations include constant propagation, common sub-expression eliminati
15394 on, loop invariant code movement, strength reduction of loop induction variables
15395 and dead-code elimination.
15398 Live range analysis
15399 \begin_inset LatexCommand \index{Live range analysis}
15406 During intermediate code generation phase, the compiler assumes the target
15407 machine has infinite number of registers and generates a lot of temporary
15409 The live range computation determines the lifetime of each of these compiler-ge
15410 nerated temporaries.
15411 A picture speaks a thousand words.
15412 ICode example sections show the live range annotations for each of the
15414 It is important to note here, each iCode is assigned a number in the order
15415 of its execution in the function.
15416 The live ranges are computed in terms of these numbers.
15417 The from number is the number of the iCode which first defines the operand
15418 and the to number signifies the iCode which uses this operand last.
15421 Register Allocation
15422 \begin_inset LatexCommand \index{Register allocation}
15429 The register allocation determines the type and number of registers needed
15431 In most MCUs only a few registers can be used for indirect addressing.
15432 In case of 8051 for example the registers R0 & R1 can be used to indirectly
15433 address the internal ram and DPTR to indirectly address the external ram.
15434 The compiler will try to allocate the appropriate register to pointer variables
15436 ICode example section shows the operands annotated with the registers assigned
15438 The compiler will try to keep operands in registers as much as possible;
15439 there are several schemes the compiler uses to do achieve this.
15440 When the compiler runs out of registers the compiler will check to see
15441 if there are any live operands which is not used or defined in the current
15442 basic block being processed, if there are any found then it will push that
15443 operand and use the registers in this block, the operand will then be popped
15444 at the end of the basic block.
15448 There are other MCU specific considerations in this phase.
15449 Some MCUs have an accumulator; very short-lived operands could be assigned
15450 to the accumulator instead of general-purpose register.
15456 Figure II gives a table of iCode operations supported by the compiler.
15457 The code generation involves translating these operations into corresponding
15458 assembly code for the processor.
15459 This sounds overly simple but that is the essence of code generation.
15460 Some of the iCode operations are generated on a MCU specific manner for
15461 example, the z80 port does not use registers to pass parameters so the
15462 SEND and RECV iCode operations will not be generated, and it also does
15463 not support JUMPTABLES.
15470 <Where is Figure II ?>
15474 \begin_inset LatexCommand \index{iCode}
15481 This section shows some details of iCode.
15482 The example C code does not do anything useful; it is used as an example
15483 to illustrate the intermediate code generated by the compiler.
15495 /* This function does nothing useful.
15502 for the purpose of explaining iCode */
15505 short function (data int *x)
15513 short i=10; /* dead initialization eliminated */
15518 short sum=10; /* dead initialization eliminated */
15531 while (*x) *x++ = *p++;
15545 /* compiler detects i,j to be induction variables */
15549 for (i = 0, j = 10 ; i < 10 ; i++, j
15575 mul += i * 3; /* this multiplication remains */
15581 gint += j * 3;/* this multiplication changed to addition */
15595 In addition to the operands each iCode contains information about the filename
15596 and line it corresponds to in the source file.
15597 The first field in the listing should be interpreted as follows:
15602 Filename(linenumber: iCode Execution sequence number : ICode hash table
15603 key : loop depth of the iCode).
15608 Then follows the human readable form of the ICode operation.
15609 Each operand of this triplet form can be of three basic types a) compiler
15610 generated temporary b) user defined variable c) a constant value.
15611 Note that local variables and parameters are replaced by compiler generated
15614 \begin_inset LatexCommand \index{Live range analysis}
15618 are computed only for temporaries (i.e.
15619 live ranges are not computed for global variables).
15621 \begin_inset LatexCommand \index{Register allocation}
15625 are allocated for temporaries only.
15626 Operands are formatted in the following manner:
15631 Operand Name [lr live-from : live-to ] { type information } [ registers
15637 As mentioned earlier the live ranges are computed in terms of the execution
15638 sequence number of the iCodes, for example
15640 the iTemp0 is live from (i.e.
15641 first defined in iCode with execution sequence number 3, and is last used
15642 in the iCode with sequence number 5).
15643 For induction variables such as iTemp21 the live range computation extends
15644 the lifetime from the start to the end of the loop.
15646 The register allocator used the live range information to allocate registers,
15647 the same registers may be used for different temporaries if their live
15648 ranges do not overlap, for example r0 is allocated to both iTemp6 and to
15649 iTemp17 since their live ranges do not overlap.
15650 In addition the allocator also takes into consideration the type and usage
15651 of a temporary, for example itemp6 is a pointer to near space and is used
15652 as to fetch data from (i.e.
15653 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer registers (r0).
15654 Some short lived temporaries are allocated to special registers which have
15655 meaning to the code generator e.g.
15656 iTemp13 is allocated to a pseudo register CC which tells the back end that
15657 the temporary is used only for a conditional jump the code generation makes
15658 use of this information to optimize a compare and jump ICode.
15660 There are several loop optimizations
15661 \begin_inset LatexCommand \index{Loop optimization}
15665 performed by the compiler.
15666 It can detect induction variables iTemp21(i) and iTemp23(j).
15667 Also note the compiler does selective strength reduction
15668 \begin_inset LatexCommand \index{Strength reduction}
15673 the multiplication of an induction variable in line 18 (gint = j * 3) is
15674 changed to addition, a new temporary iTemp17 is allocated and assigned
15675 a initial value, a constant 3 is then added for each iteration of the loop.
15676 The compiler does not change the multiplication
15677 \begin_inset LatexCommand \index{Multiplication}
15681 in line 17 however since the processor does support an 8 * 8 bit multiplication.
15683 Note the dead code elimination
15684 \begin_inset LatexCommand \index{Dead-code elimination}
15688 optimization eliminated the dead assignments in line 7 & 8 to I and sum
15696 Sample.c (5:1:0:0) _entry($9) :
15701 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
15706 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
15711 Sample.c(11:4:53:0) preHeaderLbl0($11) :
15716 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
15722 Sample.c(11:6:5:1) _whilecontinue_0($1) :
15727 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
15733 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
15738 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
15744 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
15750 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
15756 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
15762 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
15763 * int}[r0] + 0x2 {short}
15768 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
15773 Sample.c(11:17:21:0)_whilebreak_0($3) :
15778 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
15783 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
15788 Sample.c(15:20:54:0)preHeaderLbl1($13) :
15793 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
15798 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
15803 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
15808 Sample.c(15:24:26:1)_forcond_0($4) :
15813 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
15819 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
15824 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
15825 + ITemp21 [lr21:38]{short}[r4]
15830 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
15836 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
15837 + iTemp15 [lr29:30]{short}[r1]
15842 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
15848 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
15854 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
15860 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
15866 Sample.c(19:38:47:1) goto _forcond_0($4)
15871 Sample.c(19:39:48:0)_forbreak_0($7) :
15876 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
15877 + ITemp11 [lr19:40]{short}[r3]
15882 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
15887 Sample.c(20:42:51:0)_return($8) :
15892 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
15898 Finally the code generated for this function:
15939 ; ----------------------------------------------
15944 ; function function
15949 ; ----------------------------------------------
15959 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
15971 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
15983 ;_whilecontinue_0($1) :
15993 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
15998 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
16057 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
16076 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
16123 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
16163 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
16189 ; iTemp6 [lr5:16]{_near * int}[r0] =
16194 ; iTemp6 [lr5:16]{_near * int}[r0] +
16211 ; goto _whilecontinue_0($1)
16223 ; _whilebreak_0($3) :
16233 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
16245 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
16257 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
16269 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
16288 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
16317 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
16322 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
16367 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
16372 ; iTemp21 [lr21:38]{short}[r4]
16398 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
16431 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
16436 ; iTemp15 [lr29:30]{short}[r1]
16455 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
16502 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
16549 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
16561 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
16575 cjne r5,#0xff,00104$
16587 ; goto _forcond_0($4)
16599 ; _forbreak_0($7) :
16609 ; ret iTemp24 [lr40:41]{short}
16652 A few words about basic block successors, predecessors and dominators
16655 Successors are basic blocks
16656 \begin_inset LatexCommand \index{Basic blocks}
16660 that might execute after this basic block.
16662 Predecessors are basic blocks that might execute before reaching this basic
16665 Dominators are basic blocks that WILL execute before reaching this basic
16691 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
16694 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
16697 c) domVect of [BB4] = BB1 ...
16698 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
16706 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
16716 Thanks to all the other volunteer developers who have helped with coding,
16717 testing, web-page creation, distribution sets, etc.
16718 You know who you are :-)
16725 This document was initially written by Sandeep Dutta
16728 All product names mentioned herein may be trademarks
16729 \begin_inset LatexCommand \index{Trademarks}
16733 of their respective companies.
16740 To avoid confusion, the installation and building options for sdcc itself
16741 (chapter 2) are not part of the index.
16745 \begin_inset LatexCommand \printindex{}