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'
795 <lyxtabular version="3" rows="8" columns="3">
797 <column alignment="block" valignment="top" leftline="true" width="0in">
798 <column alignment="block" valignment="top" leftline="true" width="0in">
799 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
800 <row topline="true" bottomline="true">
801 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
817 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
827 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
837 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
845 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
877 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
889 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
911 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
927 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
949 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
961 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
971 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1017 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1026 <row topline="true" bottomline="true">
1027 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1045 <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):
1071 \begin_inset Tabular
1072 <lyxtabular version="3" rows="4" columns="3">
1074 <column alignment="block" valignment="top" leftline="true" width="0in">
1075 <column alignment="block" valignment="top" leftline="true" width="0in">
1076 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1077 <row topline="true" bottomline="true">
1078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1086 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1094 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1103 <row topline="true" bottomline="true">
1104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1133 <row bottomline="true">
1134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1152 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1161 <row bottomline="true">
1162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1180 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1212 \begin_inset Quotes srd
1216 \begin_inset Quotes srd
1230 \begin_inset Quotes srd
1234 \begin_inset Quotes srd
1262 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1271 \begin_inset Quotes srd
1274 i586-mingw32msvc-gcc
1275 \begin_inset Quotes srd
1279 \begin_inset Quotes srd
1282 i586-mingw32msvc-g++
1283 \begin_inset Quotes srd
1291 \begin_inset Quotes srd
1294 i586-mingw32msvc-ranlib
1295 \begin_inset Quotes srd
1303 \begin_inset Quotes srd
1306 i586-mingw32msvc-strip
1307 \begin_inset Quotes srd
1325 \begin_inset Quotes srd
1329 \begin_inset Quotes srd
1347 \begin_inset Quotes srd
1351 \begin_inset Quotes srd
1359 \begin_inset Quotes srd
1363 \begin_inset Quotes srd
1371 \begin_inset Quotes srd
1375 \begin_inset Quotes srd
1383 \begin_inset Quotes srd
1387 \begin_inset Quotes srd
1394 sdccconf_h_dir_separator=
1395 \begin_inset Quotes srd
1407 \begin_inset Quotes srd
1424 -disable-device-lib-build
1452 -host=i586-mingw32msvc -
1462 -build=unknown-unknown-linux-gnu
1466 \begin_inset Quotes sld
1470 \begin_inset Quotes srd
1473 compile on Cygwin for Mingw32(see also sdcc/support/scripts/sdcc_cygwin_mingw32)
1482 \begin_inset Quotes srd
1486 \begin_inset Quotes srd
1494 \begin_inset Quotes srd
1498 \begin_inset Quotes srd
1516 \begin_inset Quotes srd
1520 \begin_inset Quotes srd
1538 \begin_inset Quotes srd
1542 \begin_inset Quotes srd
1550 \begin_inset Quotes srd
1554 \begin_inset Quotes srd
1562 \begin_inset Quotes srd
1566 \begin_inset Quotes srd
1574 \begin_inset Quotes srd
1578 \begin_inset Quotes srd
1585 sdccconf_h_dir_separator=
1586 \begin_inset Quotes srd
1598 \begin_inset Quotes srd
1618 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
1629 -C' turns on caching, which gives a little bit extra speed.
1630 However if options are changed, it can be necessary to delete the config.cache
1635 \begin_inset LatexCommand \index{Install paths}
1643 Binary files (preprocessor, assembler and linker)
1647 \begin_inset Tabular
1648 <lyxtabular version="3" rows="2" columns="3">
1650 <column alignment="block" valignment="top" leftline="true" width="0in">
1651 <column alignment="block" valignment="top" leftline="true" width="0in">
1652 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1653 <row topline="true" bottomline="true">
1654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1670 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1679 <row topline="true" bottomline="true">
1680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1690 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1698 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1724 \begin_inset Tabular
1725 <lyxtabular version="3" rows="2" columns="3">
1727 <column alignment="block" valignment="top" leftline="true" width="1.6in">
1728 <column alignment="block" valignment="top" leftline="true" width="0in">
1729 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1730 <row topline="true" bottomline="true">
1731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1747 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1756 <row topline="true" bottomline="true">
1757 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
1769 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1774 /usr/local/share/sdcc/include
1777 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1803 is auto-appended by the compiler, e.g.
1804 small, large, z80, ds390 etc.)
1808 \begin_inset Tabular
1809 <lyxtabular version="3" rows="2" columns="3">
1811 <column alignment="block" valignment="top" leftline="true" width="0in">
1812 <column alignment="block" valignment="top" leftline="true" width="0in">
1813 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
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">
1831 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1840 <row topline="true" bottomline="true">
1841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1848 $DATADIR/$LIB_DIR_SUFFIX
1851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1856 /usr/local/share/sdcc/lib
1859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1885 \begin_inset Tabular
1886 <lyxtabular version="3" rows="2" columns="3">
1888 <column alignment="block" valignment="top" leftline="true" width="0in">
1889 <column alignment="block" valignment="top" leftline="true" width="0in">
1890 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1891 <row topline="true" bottomline="true">
1892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1900 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1908 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1917 <row topline="true" bottomline="true">
1918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1933 /usr/local/share/sdcc/doc
1936 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1957 The install paths can still be changed during `make install` with e.g.:
1960 make install prefix=$(HOME)/local/sdcc
1963 Of course this doesn't change the search paths compiled into the binaries.
1967 \begin_inset LatexCommand \index{Search path}
1974 Some search paths or parts of them are determined by configure variables
1979 , see section above).
1980 Further search paths are determined by environment variables during runtime.
1983 The paths searched when running the compiler are as follows (the first catch
1989 Binary files (preprocessor, assembler and linker)
1992 \begin_inset Tabular
1993 <lyxtabular version="3" rows="4" columns="3">
1995 <column alignment="block" valignment="top" leftline="true" width="0in">
1996 <column alignment="block" valignment="top" leftline="true" width="0in">
1997 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1998 <row topline="true" bottomline="true">
1999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2015 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2024 <row topline="true">
2025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2043 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2054 <row topline="true">
2055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2060 Path of argv[0] (if available)
2063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2071 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2080 <row topline="true" bottomline="true">
2081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2089 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2097 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2118 \begin_inset Tabular
2119 <lyxtabular version="3" rows="6" columns="3">
2121 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2122 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2123 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2124 <row topline="true" bottomline="true">
2125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2141 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2150 <row topline="true">
2151 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2187 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2206 <row topline="true">
2207 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2215 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2223 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2232 <row topline="true">
2233 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2247 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2259 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2270 <row topline="true">
2271 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2339 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2352 <row topline="true" bottomline="true">
2353 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2369 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2374 /usr/local/share/sdcc/
2379 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2406 -nostdinc disables the last two search paths.
2413 With the exception of
2414 \begin_inset Quotes sld
2428 \begin_inset Quotes srd
2435 is auto-appended by the compiler (e.g.
2436 small, large, z80, ds390 etc.).
2440 \begin_inset Tabular
2441 <lyxtabular version="3" rows="6" columns="3">
2443 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2444 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2445 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2446 <row topline="true" bottomline="true">
2447 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2455 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2463 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2472 <row topline="true">
2473 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2509 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2528 <row topline="true">
2529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2541 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2568 <row topline="true">
2569 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2580 $LIB_DIR_SUFFIX/<model>
2583 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2597 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2614 <row topline="true">
2615 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2630 $LIB_DIR_SUFFIX/<model>
2633 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2686 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2742 <row topline="true" bottomline="true">
2743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2752 $LIB_DIR_SUFFIX/<model>
2755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2760 /usr/local/share/sdcc/
2767 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2783 Don't delete any of the stray spaces in the table above without checking
2784 the HTML output (last line)!
2800 -nostdlib disables the last two search paths.
2804 \begin_inset LatexCommand \index{Building SDCC}
2809 \layout Subsubsection
2811 Building SDCC on Linux
2816 Download the source package
2818 either from the SDCC CVS repository or from the
2819 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
2825 , it will be named something like sdcc
2838 Bring up a command line terminal, such as xterm.
2843 Unpack the file using a command like:
2846 "tar -xzf sdcc.src.tar.gz
2851 , this will create a sub-directory called sdcc with all of the sources.
2854 Change directory into the main SDCC directory, for example type:
2871 This configures the package for compilation on your system.
2887 All of the source packages will compile, this can take a while.
2903 This copies the binary executables, the include files, the libraries and
2904 the documentation to the install directories.
2905 \layout Subsubsection
2907 Building SDCC on OSX 2.x
2910 Follow the instruction for Linux.
2914 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
2915 )) fails to compile SDCC.
2916 Fortunately there's also gcc 2.9.x installed, which works fine.
2917 This compiler can be selected by running 'configure' with:
2920 ./configure CC=gcc2 CXX=g++2
2921 \layout Subsubsection
2923 Cross compiling SDCC on Linux for Windows
2926 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
2927 See section 'Configure Options'.
2928 \layout Subsubsection
2930 Building SDCC on Windows
2933 With the exception of Cygwin the SDCC binaries uCsim and sdcdb can't be
2935 They use Unix-sockets, which are not available on Win32.
2936 \layout Subsubsection
2938 Windows Install Using a Binary Package
2941 Download the binary package and unpack it using your favorite unpacking
2942 tool (gunzip, WinZip, etc).
2943 This should unpack to a group of sub-directories.
2944 An example directory structure after unpacking the mingw32 package is:
2949 bin for the executables, c:
2957 lib for the include and libraries.
2960 Adjust your environment variable PATH to include the location of the bin
2961 directory or start sdcc using the full path.
2962 \layout Subsubsection
2964 Building SDCC using Cygwin and Mingw32
2967 For building and installing a Cygwin executable follow the instructions
2973 \begin_inset Quotes sld
2977 \begin_inset Quotes srd
2980 Win32-binary can be built, which will not need the Cygwin-DLL.
2981 For the necessary 'configure' options see section 'configure options' or
2982 the script 'sdcc/support/scripts/sdcc_cygwinmingw32'.
2986 In order to install Cygwin on Windows download setup.exe from
2987 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
2993 \begin_inset Quotes sld
2996 default text file type
2997 \begin_inset Quotes srd
3001 \begin_inset Quotes sld
3005 \begin_inset Quotes srd
3008 and download/install at least the following packages.
3009 Some packages are selected by default, others will be automatically selected
3010 because of dependencies with the manually selected packages.
3011 Never deselect these packages!
3020 gcc ; version 3.x is fine, no need to use the old 2.9x
3023 binutils ; selected with gcc
3029 rxvt ; a nice console, which makes life much easier under windoze (see below)
3032 man ; not really needed for building SDCC, but you'll miss it sooner or
3036 less ; not really needed for building SDCC, but you'll miss it sooner or
3040 cvs ; only if you use CVS access
3043 If you want to develop something you'll need:
3046 python ; for the regression tests
3049 gdb ; the gnu debugger, together with the nice GUI
3050 \begin_inset Quotes sld
3054 \begin_inset Quotes srd
3060 openssh ; to access the CF or commit changes
3063 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3064 use autoconf-stable!
3067 rxvt is a nice console with history.
3068 Replace in your cygwin.bat the line
3087 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3090 -bg black -fg white -geometry 100x65 -e bash -
3103 Text selected with the mouse is automatically copied to the clipboard, pasting
3104 works with shift-insert.
3108 The other good tip is to make sure you have no //c/-style paths anywhere,
3109 use /cygdrive/c/ instead.
3110 Using // invokes a network lookup which is very slow.
3112 \begin_inset Quotes sld
3116 \begin_inset Quotes srd
3119 is too long, you can change it with e.g.
3125 SDCC sources use the unix line ending LF.
3126 Life is much easier, if you store the source tree on a drive, which is
3127 mount in binary mode.
3128 And use an editor which can handle LF-only line endings.
3129 Make sure not to commit files with windows line endings.
3130 \layout Subsubsection
3132 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3137 Download the source package
3139 either from the SDCC CVS repository or from the
3140 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3146 , it will be named something like sdcc
3153 SDCC is distributed with all the projects, workspaces, and files you need
3154 to build it using Visual C++ 6.0/NET (except for sdcdb.exe which currently
3155 doesn't build under MSVC).
3156 The workspace name is 'sdcc.dsw'.
3157 Please note that as it is now, all the executables are created in a folder
3161 Once built you need to copy the executables from sdcc
3165 bin before running SDCC.
3170 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3171 flex.exe, and gawk.exe.
3172 One good place to get them is
3173 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3181 Download the file UnxUtils
3182 \begin_inset LatexCommand \index{UnxUtils}
3187 Now you have to install the utilities and setup MSVC so it can locate the
3189 Here there are two alternatives (choose one!):
3196 a) Extract UnxUtils.zip to your C:
3198 hard disk PRESERVING the original paths, otherwise bison won't work.
3199 (If you are using WinZip make certain that 'Use folder names' is selected)
3203 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3204 in 'Show directories for:' select 'Executable files', and in the directories
3205 window add a new path: 'C:
3215 (As a side effect, you get a bunch of Unix utilities that could be useful,
3216 such as diff and patch.)
3223 This one avoids extracting a bunch of files you may not use, but requires
3228 a) Create a directory were to put the tools needed, or use a directory already
3236 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3237 to such directory WITHOUT preserving the original paths.
3238 (If you are using WinZip make certain that 'Use folder names' is not selected)
3242 c) Rename bison.exe to '_bison.exe'.
3246 d) Create a batch file 'bison.bat' in 'C:
3250 ' and add these lines:
3270 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3274 Steps 'c' and 'd' are needed because bison requires by default that the
3275 files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3276 '/usr/local/share/' I think.
3277 So it is necessary to tell bison where those files are located if they
3278 are not in such directory.
3279 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3283 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3284 in 'Show directories for:' select 'Executable files', and in the directories
3285 window add a new path: 'c:
3288 Note that you can use any other path instead of 'c:
3290 util', even the path where the Visual C++ tools are, probably: 'C:
3294 Microsoft Visual Studio
3299 So you don't have to execute step 'e' :)
3303 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3304 the executables from sdcc
3308 bin, and you can compile using sdcc.
3309 \layout Subsubsection
3311 Building SDCC Using Borland
3314 From the sdcc directory, run the command "make -f Makefile.bcc".
3315 This should regenerate all the .exe files in the bin directory except for
3316 sdcdb.exe (which currently doesn't build under Borland C++).
3319 If you modify any source files and need to rebuild, be aware that the dependenci
3320 es may not be correctly calculated.
3321 The safest option is to delete all .obj files and run the build again.
3322 From a Cygwin BASH prompt, this can easily be done with the command:
3332 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
3334 ) -print -exec rm {}
3343 or on Windows NT/2000/XP from the command prompt with the command:
3350 del /s *.obj *.lib *.rul
3353 from the sdcc directory.
3356 Building the Documentation
3363 Testing out the SDCC Compiler
3366 The first thing you should do after installing your SDCC compiler is to
3382 \begin_inset LatexCommand \index{version}
3389 at the prompt, and the program should run and tell you the version.
3390 If it doesn't run, or gives a message about not finding sdcc program, then
3391 you need to check over your installation.
3392 Make sure that the sdcc bin directory is in your executable search path
3393 defined by the PATH environment setting (see the Trouble-shooting section
3395 Make sure that the sdcc program is in the bin folder, if not perhaps something
3396 did not install correctly.
3404 is commonly installed as described in section
3405 \begin_inset Quotes sld
3408 Install and search paths
3409 \begin_inset Quotes srd
3418 Make sure the compiler works on a very simple example.
3419 Type in the following test.c program using your favorite
3445 Compile this using the following command:
3454 If all goes well, the compiler will generate a test.asm and test.rel file.
3455 Congratulations, you've just compiled your first program with SDCC.
3456 We used the -c option to tell SDCC not to link the generated code, just
3457 to keep things simple for this step.
3465 The next step is to try it with the linker.
3475 If all goes well the compiler will link with the libraries and produce
3476 a test.ihx output file.
3481 (no test.ihx, and the linker generates warnings), then the problem is most
3482 likely that sdcc cannot find the
3486 usr/local/share/sdcc/lib directory
3490 (see the Install trouble-shooting section for suggestions).
3498 The final test is to ensure sdcc can use the
3502 header files and libraries.
3503 Edit test.c and change it to the following:
3520 strcpy(str1, "testing");
3527 Compile this by typing
3534 This should generate a test.ihx output file, and it should give no warnings
3535 such as not finding the string.h file.
3536 If it cannot find the string.h file, then the problem is that sdcc cannot
3537 find the /usr/local/share/sdcc/include directory
3541 (see the Install trouble-shooting section for suggestions).
3544 Install Trouble-shooting
3545 \begin_inset LatexCommand \index{Install trouble-shooting}
3550 \layout Subsubsection
3552 SDCC does not build correctly.
3555 A thing to try is starting from scratch by unpacking the .tgz source package
3556 again in an empty directory.
3564 ./configure 2>&1 | tee configure.log
3578 make 2>&1 | tee make.log
3585 If anything goes wrong, you can review the log files to locate the problem.
3586 Or a relevant part of this can be attached to an email that could be helpful
3587 when requesting help from the mailing list.
3588 \layout Subsubsection
3591 \begin_inset Quotes sld
3595 \begin_inset Quotes srd
3602 \begin_inset Quotes sld
3606 \begin_inset Quotes srd
3609 command is a script that analyzes your system and performs some configuration
3610 to ensure the source package compiles on your system.
3611 It will take a few minutes to run, and will compile a few tests to determine
3612 what compiler features are installed.
3613 \layout Subsubsection
3616 \begin_inset Quotes sld
3620 \begin_inset Quotes srd
3626 This runs the GNU make tool, which automatically compiles all the source
3627 packages into the final installed binary executables.
3628 \layout Subsubsection
3631 \begin_inset Quotes sld
3635 \begin_inset Quotes erd
3641 This will install the compiler, other executables libraries and include
3642 files in to the appropriate directories.
3644 \begin_inset Quotes sld
3647 Install and Search PATHS
3648 \begin_inset Quotes srd
3653 On most systems you will need super-user privileges to do this.
3659 SDCC is not just a compiler, but a collection of tools by various developers.
3660 These include linkers, assemblers, simulators and other components.
3661 Here is a summary of some of the components.
3662 Note that the included simulator and assembler have separate documentation
3663 which you can find in the source package in their respective directories.
3664 As SDCC grows to include support for other processors, other packages from
3665 various developers are included and may have their own sets of documentation.
3669 You might want to look at the files which are installed in <installdir>.
3670 At the time of this writing, we find the following programs for gcc-builds:
3674 In <installdir>/bin:
3677 sdcc - The compiler.
3680 sdcpp - The C preprocessor.
3683 asx8051 - The assembler for 8051 type processors.
3690 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
3693 aslink -The linker for 8051 type processors.
3700 link-gbz80 - The Z80 and GameBoy Z80 linkers.
3703 s51 - The ucSim 8051 simulator.
3706 sdcdb - The source debugger.
3709 packihx - A tool to pack (compress) Intel hex files.
3712 In <installdir>/share/sdcc/include
3718 In <installdir>/share/sdcc/lib
3721 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
3725 In <installdir>/share/sdcc/doc
3731 As development for other processors proceeds, this list will expand to include
3732 executables to support processors like AVR, PIC, etc.
3733 \layout Subsubsection
3738 This is the actual compiler, it in turn uses the c-preprocessor and invokes
3739 the assembler and linkage editor.
3740 \layout Subsubsection
3743 \begin_inset LatexCommand \index{sdcpp}
3747 - The C-Preprocessor
3750 The preprocessor is a modified version of the GNU preprocessor.
3751 The C preprocessor is used to pull in #include sources, process #ifdef
3752 statements, #defines and so on.
3753 \layout Subsubsection
3755 asx8051, as-z80, as-gbz80, aslink, link-z80, link-gbz80 - The Assemblers
3759 This is retargettable assembler & linkage editor, it was developed by Alan
3761 John Hartman created the version for 8051, and I (Sandeep) have made some
3762 enhancements and bug fixes for it to work properly with the SDCC.
3763 \layout Subsubsection
3766 \begin_inset LatexCommand \index{s51}
3773 S51 is a freeware, opensource simulator developed by Daniel Drotos (
3774 \begin_inset LatexCommand \url{mailto:drdani@mazsola.iit.uni-miskolc.hu}
3779 The simulator is built as part of the build process.
3780 For more information visit Daniel's web site at:
3781 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
3786 It currently support the core mcs51, the Dallas DS80C390 and the Phillips
3788 \layout Subsubsection
3791 \begin_inset LatexCommand \index{sdcdb}
3795 - Source Level Debugger
3798 Sdcdb is the companion source level debugger.
3799 The current version of the debugger uses Daniel's Simulator S51, but can
3800 be easily changed to use other simulators.
3807 \layout Subsubsection
3809 Single Source File Projects
3812 For single source file 8051 projects the process is very simple.
3813 Compile your programs with the following command
3816 "sdcc sourcefile.c".
3820 This will compile, assemble and link your source file.
3821 Output files are as follows
3825 \begin_inset LatexCommand \index{.asm}
3830 \begin_inset LatexCommand \index{Assembler source}
3834 file created by the compiler
3838 \begin_inset LatexCommand \index{.lst}
3843 \begin_inset LatexCommand \index{Assembler listing}
3847 file created by the Assembler
3851 \begin_inset LatexCommand \index{.rst}
3856 \begin_inset LatexCommand \index{Assembler listing}
3860 file updated with linkedit information, created by linkage editor
3864 \begin_inset LatexCommand \index{.sym}
3869 \begin_inset LatexCommand \index{Symbol listing}
3873 for the sourcefile, created by the assembler
3877 \begin_inset LatexCommand \index{.rel}
3882 \begin_inset LatexCommand \index{Object file}
3886 created by the assembler, input to Linkage editor
3890 \begin_inset LatexCommand \index{.map}
3895 \begin_inset LatexCommand \index{Memory map}
3899 for the load module, created by the Linker
3903 \begin_inset LatexCommand \index{.mem}
3907 - A file with a summary of the memory usage
3911 \begin_inset LatexCommand \index{.ihx}
3915 - The load module in Intel hex format
3916 \begin_inset LatexCommand \index{Intel hex format}
3920 (you can select the Motorola S19 format
3921 \begin_inset LatexCommand \index{Motorola S19 format}
3936 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
3941 If you need another format you might want to use objdump
3942 \begin_inset LatexCommand \index{objdump}
3947 \begin_inset LatexCommand \index{srecord}
3955 \begin_inset LatexCommand \index{.adb}
3959 - An intermediate file containing debug information needed to create the
3971 \begin_inset LatexCommand \index{-\/-debug}
3979 \begin_inset LatexCommand \index{.cdb}
3983 - An optional file (with -
3993 -debug) containing debug information
3998 \begin_inset LatexCommand \index{. (no extension)}
4002 An optional AOMF51 file containing debug information (with -
4016 \begin_inset LatexCommand \index{.dump*}
4020 - Dump file to debug the compiler it self (with -
4030 -dumpall) (see section
4031 \begin_inset Quotes sld
4034 Anatomy of the compiler
4035 \begin_inset Quotes srd
4039 \layout Subsubsection
4041 Projects with Multiple Source Files
4044 SDCC can compile only ONE file at a time.
4045 Let us for example assume that you have a project containing the following
4050 foo1.c (contains some functions)
4052 foo2.c (contains some more functions)
4054 foomain.c (contains more functions and the function main)
4062 The first two files will need to be compiled separately with the commands:
4094 Then compile the source file containing the
4099 \begin_inset LatexCommand \index{Linker}
4103 the files together with the following command:
4111 foomain.c\SpecialChar ~
4112 foo1.rel\SpecialChar ~
4117 \begin_inset LatexCommand \index{.rel}
4129 can be separately compiled as well:
4140 sdcc foomain.rel foo1.rel foo2.rel
4147 The file containing the
4162 file specified in the command line, since the linkage editor processes
4163 file in the order they are presented to it.
4164 \layout Subsubsection
4166 Projects with Additional Libraries
4167 \begin_inset LatexCommand \index{Libraries}
4174 Some reusable routines may be compiled into a library, see the documentation
4175 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
4179 \begin_inset LatexCommand \index{.lib}
4186 Libraries created in this manner can be included in the command line.
4187 Make sure you include the -L <library-path> option to tell the linker where
4188 to look for these files if they are not in the current directory.
4189 Here is an example, assuming you have the source file
4201 (if that is not the same as your current project):
4208 sdcc foomain.c foolib.lib -L mylib
4219 must be an absolute path name.
4223 The most efficient way to use libraries is to keep separate modules in separate
4225 The lib file now should name all the modules.rel files.
4226 For an example see the standard library file
4230 in the directory <installdir>/share/lib/small.
4233 Command Line Options
4234 \begin_inset LatexCommand \index{Command Line Options}
4239 \layout Subsubsection
4241 Processor Selection Options
4242 \begin_inset LatexCommand \index{Options processor selection}
4247 \begin_inset LatexCommand \index{Processor selection options}
4253 \labelwidthstring 00.00.0000
4258 \begin_inset LatexCommand \index{-mmcs51}
4264 Generate code for the MCS51
4265 \begin_inset LatexCommand \index{MCS51}
4269 family of processors.
4270 This is the default processor target.
4272 \labelwidthstring 00.00.0000
4277 \begin_inset LatexCommand \index{-mds390}
4283 Generate code for the DS80C390
4284 \begin_inset LatexCommand \index{DS80C390}
4290 \labelwidthstring 00.00.0000
4295 \begin_inset LatexCommand \index{-mds400}
4301 Generate code for the DS80C400
4302 \begin_inset LatexCommand \index{DS80C400}
4308 \labelwidthstring 00.00.0000
4313 \begin_inset LatexCommand \index{-mz80}
4319 Generate code for the Z80
4320 \begin_inset LatexCommand \index{Z80}
4324 family of processors.
4326 \labelwidthstring 00.00.0000
4331 \begin_inset LatexCommand \index{-mgbz80}
4337 Generate code for the GameBoy Z80
4338 \begin_inset LatexCommand \index{GameBoy Z80}
4344 \labelwidthstring 00.00.0000
4349 \begin_inset LatexCommand \index{-mavr}
4355 Generate code for the Atmel AVR
4356 \begin_inset LatexCommand \index{AVR}
4360 processor (In development, not complete).
4361 AVR users should probably have a look at avr-gcc
4362 \begin_inset LatexCommand \url[FIXME: official URL?]{ http://savannah.nongnu.org/download/avr-libc/snapshots/}
4369 I think it is fair to direct users there for now.
4370 Open source is also about avoiding unnecessary work .
4371 But I didn't find the 'official' link.
4373 \labelwidthstring 00.00.0000
4378 \begin_inset LatexCommand \index{-mpic14}
4384 Generate code for the PIC 14
4385 \begin_inset LatexCommand \index{PIC14}
4389 -bit processors (In development, not complete).
4392 p16f627 p16f628 p16f84 p16f873 p16f877?
4394 \labelwidthstring 00.00.0000
4400 Generate code for the Toshiba TLCS-900H
4401 \begin_inset LatexCommand \index{TLCS-900H}
4405 processor (In development, not complete).
4407 \labelwidthstring 00.00.0000
4412 \begin_inset LatexCommand \index{-mxa51}
4418 Generate code for the Phillips XA51
4419 \begin_inset LatexCommand \index{XA51}
4423 processor (In development, not complete).
4424 \layout Subsubsection
4426 Preprocessor Options
4427 \begin_inset LatexCommand \index{Options preprocessor}
4432 \begin_inset LatexCommand \index{Preprocessor options}
4438 \labelwidthstring 00.00.0000
4443 \begin_inset LatexCommand \index{-I<path>}
4449 The additional location where the pre processor will look for <..h> or
4450 \begin_inset Quotes eld
4454 \begin_inset Quotes erd
4459 \labelwidthstring 00.00.0000
4464 \begin_inset LatexCommand \index{-D<macro[=value]>}
4470 Command line definition of macros.
4471 Passed to the pre processor.
4473 \labelwidthstring 00.00.0000
4478 \begin_inset LatexCommand \index{-M}
4484 Tell the preprocessor to output a rule suitable for make describing the
4485 dependencies of each object file.
4486 For each source file, the preprocessor outputs one make-rule whose target
4487 is the object file name for that source file and whose dependencies are
4488 all the files `#include'd in it.
4489 This rule may be a single line or may be continued with `
4491 '-newline if it is long.
4492 The list of rules is printed on standard output instead of the preprocessed
4496 \labelwidthstring 00.00.0000
4501 \begin_inset LatexCommand \index{-C}
4507 Tell the preprocessor not to discard comments.
4508 Used with the `-E' option.
4510 \labelwidthstring 00.00.0000
4515 \begin_inset LatexCommand \index{-MM}
4526 Like `-M' but the output mentions only the user header files included with
4528 \begin_inset Quotes eld
4532 System header files included with `#include <file>' are omitted.
4534 \labelwidthstring 00.00.0000
4539 \begin_inset LatexCommand \index{-Aquestion(answer)}
4545 Assert the answer answer for question, in case it is tested with a preprocessor
4546 conditional such as `#if #question(answer)'.
4547 `-A-' disables the standard assertions that normally describe the target
4550 \labelwidthstring 00.00.0000
4556 (answer) Assert the answer answer for question, in case it is tested with
4557 a preprocessor conditional such as `#if #question(answer)'.
4558 `-A-' disables the standard assertions that normally describe the target
4561 \labelwidthstring 00.00.0000
4566 \begin_inset LatexCommand \index{-Umacro}
4572 Undefine macro macro.
4573 `-U' options are evaluated after all `-D' options, but before any `-include'
4574 and `-imacros' options.
4576 \labelwidthstring 00.00.0000
4581 \begin_inset LatexCommand \index{-dM}
4587 Tell the preprocessor to output only a list of the macro definitions that
4588 are in effect at the end of preprocessing.
4589 Used with the `-E' option.
4591 \labelwidthstring 00.00.0000
4596 \begin_inset LatexCommand \index{-dD}
4602 Tell the preprocessor to pass all macro definitions into the output, in
4603 their proper sequence in the rest of the output.
4605 \labelwidthstring 00.00.0000
4610 \begin_inset LatexCommand \index{-dN}
4621 Like `-dD' except that the macro arguments and contents are omitted.
4622 Only `#define name' is included in the output.
4623 \layout Subsubsection
4626 \begin_inset LatexCommand \index{Options linker}
4631 \begin_inset LatexCommand \index{Linker options}
4637 \labelwidthstring 00.00.0000
4657 \begin_inset LatexCommand \index{-\/-lib-path}
4662 \begin_inset LatexCommand \index{-L -\/-lib-path}
4671 <absolute path to additional libraries> This option is passed to the linkage
4672 editor's additional libraries
4673 \begin_inset LatexCommand \index{Libraries}
4678 The path name must be absolute.
4679 Additional library files may be specified in the command line.
4680 See section Compiling programs for more details.
4682 \labelwidthstring 00.00.0000
4699 \begin_inset LatexCommand \index{-\/-xram-loc}
4703 <Value> The start location of the external ram
4704 \begin_inset LatexCommand \index{xdata}
4708 , default value is 0.
4709 The value entered can be in Hexadecimal or Decimal format, e.g.: -
4719 -xram-loc 0x8000 or -
4731 \labelwidthstring 00.00.0000
4748 \begin_inset LatexCommand \index{-\/-code-loc}
4752 <Value> The start location of the code
4753 \begin_inset LatexCommand \index{code}
4757 segment, default value 0.
4758 Note when this option is used the interrupt vector table is also relocated
4759 to the given address.
4760 The value entered can be in Hexadecimal or Decimal format, e.g.: -
4770 -code-loc 0x8000 or -
4782 \labelwidthstring 00.00.0000
4799 \begin_inset LatexCommand \index{-\/-stack-loc}
4803 <Value> By default the stack
4804 \begin_inset LatexCommand \index{stack}
4808 is placed after the data segment.
4809 Using this option the stack can be placed anywhere in the internal memory
4811 The value entered can be in Hexadecimal or Decimal format, e.g.
4822 -stack-loc 0x20 or -
4833 Since the sp register is incremented before a push or call, the initial
4834 sp will be set to one byte prior the provided value.
4835 The provided value should not overlap any other memory areas such as used
4836 register banks or the data segment and with enough space for the current
4839 \labelwidthstring 00.00.0000
4856 \begin_inset LatexCommand \index{-\/-data-loc}
4860 <Value> The start location of the internal ram data
4861 \begin_inset LatexCommand \index{data}
4866 The value entered can be in Hexadecimal or Decimal format, eg.
4888 (By default, the start location of the internal ram data segment is set
4889 as low as possible in memory, taking into account the used register banks
4890 and the bit segment at address 0x20.
4891 For example if register banks 0 and 1 are used without bit variables, the
4892 data segment will be set, if -
4902 -data-loc is not used, to location 0x10.)
4904 \labelwidthstring 00.00.0000
4921 \begin_inset LatexCommand \index{-\/-idata-loc}
4925 <Value> The start location of the indirectly addressable internal ram
4926 \begin_inset LatexCommand \index{idata}
4930 , default value is 0x80.
4931 The value entered can be in Hexadecimal or Decimal format, eg.
4942 -idata-loc 0x88 or -
4954 \labelwidthstring 00.00.0000
4969 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
4978 The linker output (final object code) is in Intel Hex format.
4979 \begin_inset LatexCommand \index{Intel hex format}
4983 (This is the default option).
4985 \labelwidthstring 00.00.0000
5000 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5009 The linker output (final object code) is in Motorola S19 format
5010 \begin_inset LatexCommand \index{Motorola S19 format}
5015 \layout Subsubsection
5018 \begin_inset LatexCommand \index{Options MCS51}
5023 \begin_inset LatexCommand \index{MCS51 options}
5029 \labelwidthstring 00.00.0000
5044 \begin_inset LatexCommand \index{-\/-model-large}
5050 Generate code for Large model programs see section Memory Models for more
5052 If this option is used all source files in the project should be compiled
5054 In addition the standard library routines are compiled with small model,
5055 they will need to be recompiled.
5057 \labelwidthstring 00.00.0000
5072 \begin_inset LatexCommand \index{-\/-model-small}
5083 Generate code for Small Model programs see section Memory Models for more
5085 This is the default model.
5086 \layout Subsubsection
5089 \begin_inset LatexCommand \index{Options DS390}
5094 \begin_inset LatexCommand \index{DS390 options}
5100 \labelwidthstring 00.00.0000
5117 \begin_inset LatexCommand \index{-\/-model-flat24}
5127 Generate 24-bit flat mode code.
5128 This is the one and only that the ds390 code generator supports right now
5129 and is default when using
5134 See section Memory Models for more details.
5136 \labelwidthstring 00.00.0000
5153 \begin_inset LatexCommand \index{-\/-stack-10bit}
5157 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
5158 This is the one and only that the ds390 code generator supports right now
5159 and is default when using
5164 In this mode, the stack is located in the lower 1K of the internal RAM,
5165 which is mapped to 0x400000.
5166 Note that the support is incomplete, since it still uses a single byte
5167 as the stack pointer.
5168 This means that only the lower 256 bytes of the potential 1K stack space
5169 will actually be used.
5170 However, this does allow you to reclaim the precious 256 bytes of low RAM
5171 for use for the DATA and IDATA segments.
5172 The compiler will not generate any code to put the processor into 10 bit
5174 It is important to ensure that the processor is in this mode before calling
5175 any re-entrant functions compiled with this option.
5176 In principle, this should work with the
5189 \begin_inset LatexCommand \index{-\/-stack-auto}
5195 option, but that has not been tested.
5196 It is incompatible with the
5209 \begin_inset LatexCommand \index{-\/-xstack}
5216 It also only makes sense if the processor is in 24 bit contiguous addressing
5229 -model-flat24 option
5232 \layout Subsubsection
5234 Optimization Options
5235 \begin_inset LatexCommand \index{Options optimization}
5240 \begin_inset LatexCommand \index{Optimization options}
5246 \labelwidthstring 00.00.0000
5261 \begin_inset LatexCommand \index{-\/-nogcse}
5267 Will not do global subexpression elimination, this option may be used when
5268 the compiler creates undesirably large stack/data spaces to store compiler
5270 A warning message will be generated when this happens and the compiler
5271 will indicate the number of extra bytes it allocated.
5272 It recommended that this option NOT be used, #pragma\SpecialChar ~
5274 \begin_inset LatexCommand \index{\#pragma NOGCSE}
5278 can be used to turn off global subexpression elimination
5279 \begin_inset LatexCommand \index{Subexpression elimination}
5283 for a given function only.
5285 \labelwidthstring 00.00.0000
5300 \begin_inset LatexCommand \index{-\/-noinvariant}
5306 Will not do loop invariant optimizations, this may be turned off for reasons
5307 explained for the previous option.
5308 For more details of loop optimizations performed see section Loop Invariants.It
5309 recommended that this option NOT be used, #pragma\SpecialChar ~
5311 \begin_inset LatexCommand \index{\#pragma NOINVARIANT}
5315 can be used to turn off invariant optimizations for a given function only.
5317 \labelwidthstring 00.00.0000
5332 \begin_inset LatexCommand \index{-\/-noinduction}
5338 Will not do loop induction optimizations, see section strength reduction
5339 for more details.It is recommended that this option is NOT used, #pragma\SpecialChar ~
5342 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
5346 can be used to turn off induction optimizations for a given function only.
5348 \labelwidthstring 00.00.0000
5363 \begin_inset LatexCommand \index{-\/-nojtbound}
5374 Will not generate boundary condition check when switch statements
5375 \begin_inset LatexCommand \index{switch statement}
5379 are implemented using jump-tables.
5380 See section Switch Statements for more details.
5381 It is recommended that this option is NOT used, #pragma\SpecialChar ~
5383 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
5387 can be used to turn off boundary checking for jump tables for a given function
5390 \labelwidthstring 00.00.0000
5405 \begin_inset LatexCommand \index{-\/-noloopreverse}
5414 Will not do loop reversal
5415 \begin_inset LatexCommand \index{Loop reversing}
5421 \labelwidthstring 00.00.0000
5438 \begin_inset LatexCommand \index{-\/-nolabelopt }
5442 Will not optimize labels (makes the dumpfiles more readable).
5444 \labelwidthstring 00.00.0000
5459 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
5465 Will not memcpy initialized data in far space from code space.
5466 This saves a few bytes in code space if you don't have initialized data.
5467 \layout Subsubsection
5470 \begin_inset LatexCommand \index{Options other}
5476 \labelwidthstring 00.00.0000
5492 \begin_inset LatexCommand \index{-\/-compile-only}
5497 \begin_inset LatexCommand \index{-c -\/-compile-only}
5503 will compile and assemble the source, but will not call the linkage editor.
5505 \labelwidthstring 00.00.0000
5524 \begin_inset LatexCommand \index{-\/-c1mode}
5530 reads the preprocessed source from standard input and compiles it.
5531 The file name for the assembler output must be specified using the -o option.
5533 \labelwidthstring 00.00.0000
5538 \begin_inset LatexCommand \index{-E}
5544 Run only the C preprocessor.
5545 Preprocess all the C source files specified and output the results to standard
5548 \labelwidthstring 00.00.0000
5554 \begin_inset LatexCommand \index{-o <path/file>}
5560 The output path resp.
5561 file where everything will be placed.
5562 If the parameter is a path, it must have a trailing slash (or backslash
5563 for the Windows binaries) to be recognized as a path.
5566 \labelwidthstring 00.00.0000
5581 \begin_inset LatexCommand \index{-\/-stack-auto}
5592 All functions in the source file will be compiled as
5597 \begin_inset LatexCommand \index{reentrant}
5602 the parameters and local variables will be allocated on the stack
5603 \begin_inset LatexCommand \index{stack}
5608 see section Parameters and Local Variables for more details.
5609 If this option is used all source files in the project should be compiled
5613 \labelwidthstring 00.00.0000
5628 \begin_inset LatexCommand \index{-\/-xstack}
5634 Uses a pseudo stack in the first 256 bytes in the external ram for allocating
5635 variables and passing parameters.
5636 See section on external stack for more details.
5638 \labelwidthstring 00.00.0000
5653 \begin_inset LatexCommand \index{-\/-callee-saves}
5658 \begin_inset LatexCommand \index{function prologue}
5662 function1[,function2][,function3]....
5665 The compiler by default uses a caller saves convention for register saving
5666 across function calls, however this can cause unnecessary register pushing
5667 & popping when calling small functions from larger functions.
5668 This option can be used to switch the register saving convention for the
5669 function names specified.
5670 The compiler will not save registers when calling these functions, no extra
5671 code will be generated at the entry & exit for these functions to save
5672 & restore the registers used by these functions, this can SUBSTANTIALLY
5673 reduce code & improve run time performance of the generated code.
5674 In the future the compiler (with inter procedural analysis) will be able
5675 to determine the appropriate scheme to use for each function call.
5676 DO NOT use this option for built-in functions such as _mulint..., if this
5677 option is used for a library function the appropriate library function
5678 needs to be recompiled with the same option.
5679 If the project consists of multiple source files then all the source file
5680 should be compiled with the same -
5690 -callee-saves option string.
5691 Also see #pragma\SpecialChar ~
5693 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
5699 \labelwidthstring 00.00.0000
5714 \begin_inset LatexCommand \index{-\/-debug}
5723 When this option is used the compiler will generate debug information, that
5724 can be used with the SDCDB.
5725 The debug information is collected in a file with .cdb extension.
5726 For more information see documentation for SDCDB.
5728 \labelwidthstring 00.00.0000
5745 \begin_inset LatexCommand \index{-\/-peep-file}
5749 <filename> This option can be used to use additional rules to be used by
5750 the peep hole optimizer.
5751 See section Peep Hole optimizations for details on how to write these rules.
5753 \labelwidthstring 00.00.0000
5758 \begin_inset LatexCommand \index{-S}
5769 Stop after the stage of compilation proper; do not assemble.
5770 The output is an assembler code file for the input file specified.
5772 \labelwidthstring 00.00.0000
5776 -Wa_asmOption[,asmOption]
5779 \begin_inset LatexCommand \index{-Wa\_asmOption[,asmOption]}
5784 Pass the asmOption to the assembler.
5786 \labelwidthstring 00.00.0000
5790 -Wl_linkOption[,linkOption]
5793 \begin_inset LatexCommand \index{-Wl\_linkOption[,linkOption]}
5798 Pass the linkOption to the linker.
5800 \labelwidthstring 00.00.0000
5815 \begin_inset LatexCommand \index{-\/-int-long-reent}
5821 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
5822 Note by default these libraries are compiled as non-reentrant.
5823 See section Installation for more details.
5825 \labelwidthstring 00.00.0000
5840 \begin_inset LatexCommand \index{-\/-cyclomatic}
5849 This option will cause the compiler to generate an information message for
5850 each function in the source file.
5851 The message contains some
5855 information about the function.
5856 The number of edges and nodes the compiler detected in the control flow
5857 graph of the function, and most importantly the
5859 cyclomatic complexity
5860 \begin_inset LatexCommand \index{Cyclomatic complexity}
5866 see section on Cyclomatic Complexity for more details.
5868 \labelwidthstring 00.00.0000
5883 \begin_inset LatexCommand \index{-\/-float-reent}
5892 Floating point library is compiled as reentrant
5893 \begin_inset LatexCommand \index{reentrant}
5897 .See section Installation for more details.
5899 \labelwidthstring 00.00.0000
5914 \begin_inset LatexCommand \index{-\/-nooverlay}
5920 The compiler will not overlay parameters and local variables of any function,
5921 see section Parameters and local variables for more details.
5923 \labelwidthstring 00.00.0000
5938 \begin_inset LatexCommand \index{-\/-main-return}
5944 This option can be used when the code generated is called by a monitor
5946 The compiler will generate a 'ret' upon return from the 'main'
5947 \begin_inset LatexCommand \index{main return}
5952 The default option is to lock up i.e.
5955 \labelwidthstring 00.00.0000
5970 \begin_inset LatexCommand \index{-\/-no-peep}
5976 Disable peep-hole optimization.
5978 \labelwidthstring 00.00.0000
5993 \begin_inset LatexCommand \index{-\/-peep-asm}
5999 Pass the inline assembler code through the peep hole optimizer.
6000 This can cause unexpected changes to inline assembler code, please go through
6001 the peephole optimizer
6002 \begin_inset LatexCommand \index{Peephole optimizer}
6006 rules defined in the source file tree '<target>/peeph.def' before using
6009 \labelwidthstring 00.00.0000
6026 \begin_inset LatexCommand \index{-\/-iram-size<Value>}
6030 Causes the linker to check if the internal ram usage is within limits of
6033 \labelwidthstring 00.00.0000
6050 \begin_inset LatexCommand \index{-\/-xram-size<Value>}
6054 Causes the linker to check if the external ram usage is within limits of
6057 \labelwidthstring 00.00.0000
6074 \begin_inset LatexCommand \index{-\/-code-size<Value>}
6078 Causes the linker to check if the code usage is within limits of the given
6081 \labelwidthstring 00.00.0000
6096 \begin_inset LatexCommand \index{-\/-nostdincl}
6102 This will prevent the compiler from passing on the default include path
6103 to the preprocessor.
6105 \labelwidthstring 00.00.0000
6120 \begin_inset LatexCommand \index{-\/-nostdlib}
6126 This will prevent the compiler from passing on the default library
6127 \begin_inset LatexCommand \index{Libraries}
6133 \labelwidthstring 00.00.0000
6148 \begin_inset LatexCommand \index{-\/-verbose}
6154 Shows the various actions the compiler is performing.
6156 \labelwidthstring 00.00.0000
6161 \begin_inset LatexCommand \index{-V}
6167 Shows the actual commands the compiler is executing.
6169 \labelwidthstring 00.00.0000
6184 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
6190 Hides your ugly and inefficient c-code from the asm file, so you can always
6191 blame the compiler :).
6193 \labelwidthstring 00.00.0000
6208 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
6214 Include i-codes in the asm file.
6215 Sounds like noise but is most helpful for debugging the compiler itself.
6217 \labelwidthstring 00.00.0000
6232 \begin_inset LatexCommand \index{-\/-less-pedantic}
6238 Disable some of the more pedantic warnings (jwk burps: please be more specific
6241 \labelwidthstring 00.00.0000
6256 \begin_inset LatexCommand \index{-\/-print-search-dirs}
6262 Display the directories in the compiler's search path
6263 \layout Subsubsection
6265 Intermediate Dump Options
6266 \begin_inset LatexCommand \index{Options intermediate dump}
6271 \begin_inset LatexCommand \index{Intermediate dump options}
6278 The following options are provided for the purpose of retargetting and debugging
6280 These provided a means to dump the intermediate code (iCode
6281 \begin_inset LatexCommand \index{iCode}
6285 ) generated by the compiler in human readable form at various stages of
6286 the compilation process.
6289 \labelwidthstring 00.00.0000
6304 \begin_inset LatexCommand \index{-\/-dumpraw}
6310 This option will cause the compiler to dump the intermediate code into
6313 <source filename>.dumpraw
6315 just after the intermediate code has been generated for a function, i.e.
6316 before any optimizations are done.
6318 \begin_inset LatexCommand \index{Basic blocks}
6322 at this stage ordered in the depth first number, so they may not be in
6323 sequence of execution.
6325 \labelwidthstring 00.00.0000
6340 \begin_inset LatexCommand \index{-\/-dumpgcse}
6346 Will create a dump of iCode's, after global subexpression elimination
6347 \begin_inset LatexCommand \index{Global subexpression elimination}
6353 <source filename>.dumpgcse.
6355 \labelwidthstring 00.00.0000
6370 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
6376 Will create a dump of iCode's, after deadcode elimination
6377 \begin_inset LatexCommand \index{Dead-code elimination}
6383 <source filename>.dumpdeadcode.
6385 \labelwidthstring 00.00.0000
6400 \begin_inset LatexCommand \index{-\/-dumploop}
6409 Will create a dump of iCode's, after loop optimizations
6410 \begin_inset LatexCommand \index{Loop optimization}
6416 <source filename>.dumploop.
6418 \labelwidthstring 00.00.0000
6433 \begin_inset LatexCommand \index{-\/-dumprange}
6442 Will create a dump of iCode's, after live range analysis
6443 \begin_inset LatexCommand \index{Live range analysis}
6449 <source filename>.dumprange.
6451 \labelwidthstring 00.00.0000
6466 \begin_inset LatexCommand \index{-\/-dumlrange}
6472 Will dump the life ranges
6473 \begin_inset LatexCommand \index{Live range analysis}
6479 \labelwidthstring 00.00.0000
6494 \begin_inset LatexCommand \index{-\/-dumpregassign}
6503 Will create a dump of iCode's, after register assignment
6504 \begin_inset LatexCommand \index{Register assignment}
6510 <source filename>.dumprassgn.
6512 \labelwidthstring 00.00.0000
6527 \begin_inset LatexCommand \index{-\/-dumplrange}
6533 Will create a dump of the live ranges of iTemp's
6535 \labelwidthstring 00.00.0000
6550 \begin_inset LatexCommand \index{-\/-dumpall}
6561 Will cause all the above mentioned dumps to be created.
6564 Environment variables
6565 \begin_inset LatexCommand \index{Environment variables}
6572 SDCC recognizes the following environment variables:
6574 \labelwidthstring 00.00.0000
6579 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
6585 SDCC installs a signal handler
6586 \begin_inset LatexCommand \index{signal handler}
6590 to be able to delete temporary files after an user break (^C) or an exception.
6591 If this environment variable is set, SDCC won't install the signal handler
6592 in order to be able to debug SDCC.
6594 \labelwidthstring 00.00.0000
6599 \begin_inset LatexCommand \index{TMP}
6605 \begin_inset LatexCommand \index{TEMP}
6611 \begin_inset LatexCommand \index{TMPDIR}
6617 Path, where temporary files will be created.
6618 The order of the variables is the search order.
6619 In a standard *nix environment these variables are not set, and there's
6620 no need to set them.
6621 On Windows it's recommended to set one of them.
6623 \labelwidthstring 00.00.0000
6628 \begin_inset LatexCommand \index{SDCC\_HOME}
6635 \begin_inset Quotes sld
6638 2.3 Install and search paths
6639 \begin_inset Quotes srd
6644 \labelwidthstring 00.00.0000
6649 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
6656 \begin_inset Quotes sld
6659 2.3 Install and search paths
6660 \begin_inset Quotes srd
6665 \labelwidthstring 00.00.0000
6670 \begin_inset LatexCommand \index{SDCC\_LIB}
6677 \begin_inset Quotes sld
6680 2.3 Install and search paths
6681 \begin_inset Quotes srd
6687 There are some more environment variables recognized by SDCC, but these
6688 are solely used for debugging purposes.
6689 They can change or disappear very quickly, and will never be documented.
6692 MCS51/DS390 Storage Class
6693 \begin_inset LatexCommand \index{Storage class}
6700 In addition to the ANSI storage classes SDCC allows the following MCS51
6701 specific storage classes.
6702 \layout Subsubsection
6705 \begin_inset LatexCommand \index{xdata}
6712 Variables declared with this storage class will be placed in the extern
6718 storage class for Large Memory model, e.g.:
6723 xdata unsigned char xduc;
6724 \layout Subsubsection
6727 \begin_inset LatexCommand \index{data}
6738 storage class for Small Memory model.
6739 Variables declared with this storage class will be allocated in the internal
6746 \layout Subsubsection
6749 \begin_inset LatexCommand \index{idata}
6756 Variables declared with this storage class will be allocated into the indirectly
6757 addressable portion of the internal ram of a 8051, e.g.:
6763 \layout Subsubsection
6766 \begin_inset LatexCommand \index{bit}
6773 This is a data-type and a storage class specifier.
6774 When a variable is declared as a bit, it is allocated into the bit addressable
6775 memory of 8051, e.g.:
6781 \layout Subsubsection
6784 \begin_inset LatexCommand \index{sfr}
6789 \begin_inset LatexCommand \index{sbit}
6796 Like the bit keyword,
6800 signifies both a data-type and storage class, they are used to describe
6801 the special function registers and special bit variables of a 8051, eg:
6806 sfr at 0x80 P0; /* special function register P0 at location 0x80 */
6808 sbit at 0xd7 CY; /* CY (Carry Flag
6809 \begin_inset LatexCommand \index{Flags}
6814 \begin_inset LatexCommand \index{Carry flag}
6822 \begin_inset LatexCommand \index{Pointers}
6829 SDCC allows (via language extensions) pointers to explicitly point to any
6830 of the memory spaces
6831 \begin_inset LatexCommand \index{Memory model}
6836 In addition to the explicit pointers, the compiler uses (by default) generic
6837 pointers which can be used to point to any of the memory spaces.
6841 Pointer declaration examples:
6846 /* pointer physically in xternal ram pointing to object in internal ram
6849 data unsigned char * xdata p;
6853 /* pointer physically in code rom pointing to data in xdata space */
6855 xdata unsigned char * code p;
6859 /* pointer physically in code space pointing to data in code space */
6861 code unsigned char * code p;
6865 /* the following is a generic pointer physically located in xdata space
6871 Well you get the idea.
6876 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
6889 The highest order byte of the
6893 pointers contains the data space information.
6894 Assembler support routines are called whenever data is stored or retrieved
6900 These are useful for developing reusable library
6901 \begin_inset LatexCommand \index{Libraries}
6906 Explicitly specifying the pointer type will generate the most efficient
6911 \begin_inset LatexCommand \index{Parameters}
6916 \begin_inset LatexCommand \index{Local variable}
6923 Automatic (local) variables and parameters to functions can either be placed
6924 on the stack or in data-space.
6925 The default action of the compiler is to place these variables in the internal
6926 RAM (for small model) or external RAM (for large model).
6927 This in fact makes them
6930 \begin_inset LatexCommand \index{static}
6936 so by default functions are non-reentrant
6937 \begin_inset LatexCommand \index{reentrant}
6945 They can be placed on the stack
6946 \begin_inset LatexCommand \index{stack}
6963 \begin_inset LatexCommand \index{-\/-stack-auto}
6969 option or by using the
6972 \begin_inset LatexCommand \index{reentrant}
6978 keyword in the function declaration, e.g.:
6983 unsigned char foo(char i) reentrant
6993 Since stack space on 8051 is limited, the
7011 option should be used sparingly.
7012 Note that the reentrant keyword just means that the parameters & local
7013 variables will be allocated to the stack, it
7017 mean that the function is register bank independent.
7021 Local variables can be assigned storage classes and absolute
7022 \begin_inset LatexCommand \index{Absolute addressing}
7031 unsigned char foo() {
7037 xdata unsigned char i;
7049 data at 0x31 unsigned char j;
7061 In the above example the variable
7065 will be allocated in the external ram,
7069 in bit addressable space and
7088 or when a function is declared as
7092 this should only be done for static variables.
7095 Parameters however are not allowed any storage class, (storage classes for
7096 parameters will be ignored), their allocation is governed by the memory
7097 model in use, and the reentrancy options.
7101 \begin_inset LatexCommand \index{Overlaying}
7109 \begin_inset LatexCommand \index{reentrant}
7113 functions SDCC will try to reduce internal ram space usage by overlaying
7114 parameters and local variables of a function (if possible).
7115 Parameters and local variables of a function will be allocated to an overlayabl
7116 e segment if the function has
7118 no other function calls and the function is non-reentrant and the memory
7120 \begin_inset LatexCommand \index{Memory model}
7127 If an explicit storage class
7128 \begin_inset LatexCommand \index{Storage class}
7132 is specified for a local variable, it will NOT be overlayed.
7135 Note that the compiler (not the linkage editor) makes the decision for overlayin
7137 Functions that are called from an interrupt service routine should be preceded
7138 by a #pragma\SpecialChar ~
7140 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
7144 if they are not reentrant.
7147 Also note that the compiler does not do any processing of inline
7148 \begin_inset LatexCommand \index{inline}
7152 assembler code, so the compiler might incorrectly assign local variables
7153 and parameters of a function into the overlay segment if the inline assembler
7154 code calls other c-functions that might use the overlay.
7155 In that case the #pragma\SpecialChar ~
7156 NOOVERLAY should be used.
7159 Parameters and Local variables of functions that contain 16 or 32 bit multiplica
7161 \begin_inset LatexCommand \index{Multiplication}
7166 \begin_inset LatexCommand \index{Division}
7170 will NOT be overlayed since these are implemented using external functions,
7179 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
7185 void set_error(unsigned char errcd)
7201 void some_isr () interrupt
7202 \begin_inset LatexCommand \index{interrupt}
7207 \begin_inset LatexCommand \index{using}
7237 In the above example the parameter
7245 would be assigned to the overlayable segment if the #pragma\SpecialChar ~
7247 not present, this could cause unpredictable runtime behavior when called
7249 The #pragma\SpecialChar ~
7250 NOOVERLAY ensures that the parameters and local variables for
7251 the function are NOT overlayed.
7254 Interrupt Service Routines
7257 SDCC allows interrupt service routines to be coded in C, with some extended
7263 void timer_isr (void) interrupt 2 using 1
7273 The number following the
7276 \begin_inset LatexCommand \index{interrupt}
7282 keyword is the interrupt number this routine will service.
7283 The compiler will insert a call to this routine in the interrupt vector
7284 table for the interrupt number specified.
7289 keyword is used to tell the compiler to use the specified register bank
7290 (8051 specific) when generating code for this function.
7291 Note that when some function is called from an interrupt service routine
7292 it should be preceded by a #pragma\SpecialChar ~
7294 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
7298 if it is not reentrant.
7299 A special note here, int (16 bit) and long (32 bit) integer division
7300 \begin_inset LatexCommand \index{Division}
7305 \begin_inset LatexCommand \index{Multiplication}
7310 \begin_inset LatexCommand \index{Modulus}
7314 operations are implemented using external support routines developed in
7315 ANSI-C, if an interrupt service routine needs to do any of these operations
7316 then the support routines (as mentioned in a following section) will have
7317 to be recompiled using the
7330 \begin_inset LatexCommand \index{-\/-stack-auto}
7336 option and the source file will need to be compiled using the
7351 \begin_inset LatexCommand \index{-\/-int-long-rent}
7358 If you have multiple source files in your project, interrupt service routines
7359 can be present in any of them, but a prototype of the isr MUST be present
7360 or included in the file that contains the function
7367 Interrupt Numbers and the corresponding address & descriptions for the Standard
7368 8051 are listed below.
7369 SDCC will automatically adjust the interrupt vector table to the maximum
7370 interrupt number specified.
7376 \begin_inset Tabular
7377 <lyxtabular version="3" rows="6" columns="3">
7379 <column alignment="block" valignment="top" leftline="true" width="0in">
7380 <column alignment="block" valignment="top" leftline="true" width="0in">
7381 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
7382 <row topline="true" bottomline="true">
7383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7399 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7408 <row topline="true">
7409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7425 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7434 <row topline="true">
7435 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7451 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7460 <row topline="true">
7461 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7469 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7477 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7486 <row topline="true">
7487 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7503 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7512 <row topline="true" bottomline="true">
7513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7529 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7546 If the interrupt service routine is defined without
7549 \begin_inset LatexCommand \index{using}
7555 a register bank or with register bank 0 (using 0), the compiler will save
7556 the registers used by itself on the stack upon entry and restore them at
7557 exit, however if such an interrupt service routine calls another function
7558 then the entire register bank will be saved on the stack.
7559 This scheme may be advantageous for small interrupt service routines which
7560 have low register usage.
7563 If the interrupt service routine is defined to be using a specific register
7568 are save and restored, if such an interrupt service routine calls another
7569 function (using another register bank) then the entire register bank of
7570 the called function will be saved on the stack.
7571 This scheme is recommended for larger interrupt service routines.
7574 Calling other functions from an interrupt service routine is not recommended,
7575 avoid it if possible.
7579 Also see the _naked modifier.
7587 <TODO: this isn't implemented at all!>
7593 A special keyword may be associated with a function declaring it as
7598 SDCC will generate code to disable all interrupts upon entry to a critical
7599 function and enable them back before returning.
7600 Note that nesting critical functions may cause unpredictable results.
7618 The critical attribute maybe used with other attributes like
7624 \begin_inset LatexCommand \index{Naked functions}
7631 A special keyword may be associated with a function declaring it as
7634 \begin_inset LatexCommand \index{\_naked}
7645 function modifier attribute prevents the compiler from generating prologue
7646 \begin_inset LatexCommand \index{function prologue}
7651 \begin_inset LatexCommand \index{function epilogue}
7655 code for that function.
7656 This means that the user is entirely responsible for such things as saving
7657 any registers that may need to be preserved, selecting the proper register
7658 bank, generating the
7662 instruction at the end, etc.
7663 Practically, this means that the contents of the function must be written
7664 in inline assembler.
7665 This is particularly useful for interrupt functions, which can have a large
7666 (and often unnecessary) prologue/epilogue.
7667 For example, compare the code generated by these two functions:
7672 data unsigned char counter;
7674 void simpleInterrupt(void) interrupt
7675 \begin_inset LatexCommand \index{interrupt}
7693 void nakedInterrupt(void) interrupt 2 _naked
7702 \begin_inset LatexCommand \index{\_asm}
7731 ; MUST explicitly include ret in _naked function.
7738 \begin_inset LatexCommand \index{\_endasm}
7747 For an 8051 target, the generated simpleInterrupt looks like:
7888 whereas nakedInterrupt looks like:
7912 ; MUST explicitly include ret(i) in _naked function.
7915 While there is nothing preventing you from writing C code inside a _naked
7916 function, there are many ways to shoot yourself in the foot doing this,
7917 and it is recommended that you stick to inline assembler.
7920 Functions using private banks
7921 \begin_inset LatexCommand \index{bank}
7931 \begin_inset LatexCommand \index{using}
7937 attribute (which tells the compiler to use a register bank other than the
7938 default bank zero) should only be applied to
7941 \begin_inset LatexCommand \index{interrupt}
7947 functions (see note 1 below).
7948 This will in most circumstances make the generated ISR code more efficient
7949 since it will not have to save registers on the stack.
7956 attribute will have no effect on the generated code for a
7960 function (but may occasionally be useful anyway
7966 possible exception: if a function is called ONLY from 'interrupt' functions
7967 using a particular bank, it can be declared with the same 'using' attribute
7968 as the calling 'interrupt' functions.
7969 For instance, if you have several ISRs using bank one, and all of them
7970 call memcpy(), it might make sense to create a specialized version of memcpy()
7971 'using 1', since this would prevent the ISR from having to save bank zero
7972 to the stack on entry and switch to bank zero before calling the function
7979 (pending: I don't think this has been done yet)
7986 function using a non-zero bank will assume that it can trash that register
7987 bank, and will not save it.
7988 Since high-priority interrupts
7989 \begin_inset LatexCommand \index{interrupt priority}
7993 can interrupt low-priority ones on the 8051 and friends, this means that
7994 if a high-priority ISR
7998 a particular bank occurs while processing a low-priority ISR
8002 the same bank, terrible and bad things can happen.
8003 To prevent this, no single register bank should be
8007 by both a high priority and a low priority ISR.
8008 This is probably most easily done by having all high priority ISRs use
8009 one bank and all low priority ISRs use another.
8010 If you have an ISR which can change priority at runtime, you're on your
8011 own: I suggest using the default bank zero and taking the small performance
8015 It is most efficient if your ISR calls no other functions.
8016 If your ISR must call other functions, it is most efficient if those functions
8017 use the same bank as the ISR (see note 1 below); the next best is if the
8018 called functions use bank zero.
8019 It is very inefficient to call a function using a different, non-zero bank
8025 \begin_inset LatexCommand \index{Absolute addressing}
8032 Data items can be assigned an absolute address with the
8035 \begin_inset LatexCommand \index{at}
8041 keyword, in addition to a storage class, e.g.:
8047 \begin_inset LatexCommand \index{xdata}
8052 \begin_inset LatexCommand \index{at}
8056 0x8000 unsigned char PORTA_8255 ;
8059 In the above example the PORTA_8255 will be allocated to the location 0x8000
8060 of the external ram.
8061 Note that this feature is provided to give the programmer access to
8065 devices attached to the controller.
8066 The compiler does not actually reserve any space for variables declared
8067 in this way (they are implemented with an equate in the assembler).
8068 Thus it is left to the programmer to make sure there are no overlaps with
8069 other variables that are declared without the absolute address.
8070 The assembler listing file (.lst
8071 \begin_inset LatexCommand \index{.lst}
8075 ) and the linker output files (.rst
8076 \begin_inset LatexCommand \index{.rst}
8081 \begin_inset LatexCommand \index{.map}
8085 ) are a good places to look for such overlaps.
8089 Absolute address can be specified for variables in all storage classes,
8096 \begin_inset LatexCommand \index{bit}
8101 \begin_inset LatexCommand \index{at}
8108 The above example will allocate the variable at offset 0x02 in the bit-addressab
8110 There is no real advantage to assigning absolute addresses to variables
8111 in this manner, unless you want strict control over all the variables allocated.
8112 One possible use would be to write hardware portable code.
8113 For example, if you have a routine that uses one or more of the microcontroller
8114 I/O pins, and such pins are different for two different hardwares, you
8115 can declare the I/O pins in you routine using
8128 void DS1306_put(unsigned char value)
8136 unsigned char mask=0x80;
8160 SDI=(value & mask)?1:0;
8201 Then, someplace in the code for the first hardware you would use
8206 bit at 0x80 SDI;\SpecialChar ~
8210 /*I/O port 0, bit 0*/
8212 bit at 0x81 SCLK;\SpecialChar ~
8215 /*I/O port 0, bit 1*/
8217 bit CPOL;\SpecialChar ~
8228 /*This is a variable, let the linker allocate this one*/
8231 Similarly, for the second hardware you would use
8236 bit at 0x83 SDI;\SpecialChar ~
8240 /*I/O port 0, bit 3*/
8242 bit at 0x91 SCLK;\SpecialChar ~
8245 /*I/O port 1, bit 1*/
8247 bit CPOL;\SpecialChar ~
8258 /*This is a variable, let the linker allocate this one*/
8261 and you can use the same hardware dependent routine without changes, as
8262 for example in a library.
8263 This is somehow similar to sbit, but only one absolute address has to be
8264 specified in the whole project.
8268 \begin_inset LatexCommand \index{Startup code}
8275 The compiler inserts a call to the C routine
8277 _sdcc_external_startup()
8278 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
8287 at the start of the CODE area.
8288 This routine is in the runtime library
8289 \begin_inset LatexCommand \index{Runtime library}
8294 By default this routine returns 0, if this routine returns a non-zero value,
8295 the static & global variable initialization will be skipped and the function
8296 main will be invoked Other wise static & global variables will be initialized
8297 before the function main is invoked.
8300 _sdcc_external_startup()
8302 routine to your program to override the default if you need to setup hardware
8303 or perform some other critical operation prior to static & global variable
8307 Inline Assembler Code
8308 \begin_inset LatexCommand \index{Assembler routines}
8315 SDCC allows the use of in-line assembler with a few restriction as regards
8317 All labels defined within inline assembler code
8325 where nnnn is a number less than 100 (which implies a limit of utmost 100
8326 inline assembler labels
8334 It is strongly recommended that each assembly instruction (including labels)
8335 be placed in a separate line (as the example shows).
8349 \begin_inset LatexCommand \index{-\/-peep-asm}
8355 command line option is used, the inline assembler code will be passed through
8356 the peephole optimizer
8357 \begin_inset LatexCommand \index{Peephole optimizer}
8362 This might cause some unexpected changes in the inline assembler code.
8363 Please go through the peephole optimizer rules defined in file
8367 carefully before using this option.
8373 \begin_inset LatexCommand \index{\_asm}
8403 \begin_inset LatexCommand \index{\_endasm}
8410 The inline assembler code can contain any valid code understood by the assembler
8411 , this includes any assembler directives and comment lines.
8412 The compiler does not do any validation of the code within the
8422 Inline assembler code cannot reference any C-Labels, however it can reference
8424 \begin_inset LatexCommand \index{Labels}
8428 defined by the inline assembler, e.g.:
8453 ; some assembler code
8473 /* some more c code */
8475 clabel:\SpecialChar ~
8477 /* inline assembler cannot reference this label */
8489 $0003: ;label (can be reference by inline assembler only)
8501 /* some more c code */
8506 In other words inline assembly code can access labels defined in inline
8507 assembly within the scope of the function.
8508 The same goes the other way, ie.
8509 labels defines in inline assembly CANNOT be accessed by C statements.
8513 \begin_inset LatexCommand \index{int (16 bit)}
8518 \begin_inset LatexCommand \index{long (32 bit)}
8525 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
8526 multiplication and modulus operations are implemented by support routines.
8527 These support routines are all developed in ANSI-C to facilitate porting
8528 to other MCUs, although some model specific assembler optimizations are
8530 The following files contain the described routine, all of them can be found
8531 in <installdir>/share/sdcc/lib.
8536 \begin_inset Tabular
8537 <lyxtabular version="3" rows="11" columns="2">
8539 <column alignment="center" valignment="top" leftline="true" width="0(null)">
8540 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
8541 <row topline="true" bottomline="true">
8542 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8552 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8563 <row topline="true">
8564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8572 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8577 16 bit multiplication
8581 <row topline="true">
8582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8590 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8595 signed 16 bit division (calls _divuint)
8599 <row topline="true">
8600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8608 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8613 unsigned 16 bit division
8617 <row topline="true">
8618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8631 signed 16 bit modulus (calls _moduint)
8635 <row topline="true">
8636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8644 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8649 unsigned 16 bit modulus
8653 <row topline="true">
8654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8662 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8667 32 bit multiplication
8671 <row topline="true">
8672 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8680 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8685 signed 32 division (calls _divulong)
8689 <row topline="true">
8690 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8698 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8703 unsigned 32 division
8707 <row topline="true">
8708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8721 signed 32 bit modulus (calls _modulong)
8725 <row topline="true" bottomline="true">
8726 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8734 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8739 unsigned 32 bit modulus
8755 Since they are compiled as
8760 \begin_inset LatexCommand \index{reentrant}
8765 \begin_inset LatexCommand \index{interrupt}
8769 service routines should not do any of the above operations.
8770 If this is unavoidable then the above routines will need to be compiled
8784 \begin_inset LatexCommand \index{-\/-stack-auto}
8790 option, after which the source program will have to be compiled with
8803 \begin_inset LatexCommand \index{-\/-int-long-rent}
8810 Notice that you don't have to call this routines directly.
8811 The compiler will use them automatically every time a integer operation
8815 Floating Point Support
8816 \begin_inset LatexCommand \index{Floating point support}
8823 SDCC supports IEEE (single precision 4bytes) floating point numbers.The floating
8824 point support routines are derived from gcc's floatlib.c and consists of
8825 the following routines:
8832 \begin_inset Tabular
8833 <lyxtabular version="3" rows="17" columns="2">
8835 <column alignment="center" valignment="top" leftline="true" width="0(null)">
8836 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
8837 <row topline="true" bottomline="true">
8838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8855 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8864 <row topline="true">
8865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8882 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8896 add floating point numbers
8900 <row topline="true">
8901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8918 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8932 subtract floating point numbers
8936 <row topline="true">
8937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8954 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8968 divide floating point numbers
8972 <row topline="true">
8973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9004 multiply floating point numbers
9008 <row topline="true">
9009 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9040 convert floating point to unsigned char
9044 <row topline="true">
9045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9062 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9076 convert floating point to signed char
9080 <row topline="true">
9081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9098 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9112 convert floating point to unsigned int
9116 <row topline="true">
9117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9134 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9148 convert floating point to signed int
9152 <row topline="true">
9153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9179 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9193 convert floating point to unsigned long
9197 <row topline="true">
9198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9215 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9229 convert floating point to signed long
9233 <row topline="true">
9234 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9251 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9265 convert unsigned char to floating point
9269 <row topline="true">
9270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9287 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9301 convert char to floating point number
9305 <row topline="true">
9306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9323 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9337 convert unsigned int to floating point
9341 <row topline="true">
9342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9359 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9373 convert int to floating point numbers
9377 <row topline="true">
9378 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9395 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9409 convert unsigned long to floating point number
9413 <row topline="true" bottomline="true">
9414 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9431 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9445 convert long to floating point number
9459 Note if all these routines are used simultaneously the data space might
9461 For serious floating point usage it is strongly recommended that the large
9463 Also notice that you don't have to call this routines directly.
9464 The compiler will use them automatically every time a floating point operation
9469 \begin_inset LatexCommand \index{Memory model}
9474 \begin_inset LatexCommand \index{MCS51 memory}
9481 SDCC allows two memory models for MCS51 code, small and large.
9482 Modules compiled with different memory models should
9486 be combined together or the results would be unpredictable.
9487 The library routines supplied with the compiler are compiled as both small
9489 The compiled library modules are contained in separate directories as small
9490 and large so that you can link to either set.
9494 When the large model is used all variables declared without a storage class
9495 will be allocated into the external ram, this includes all parameters and
9496 local variables (for non-reentrant
9497 \begin_inset LatexCommand \index{reentrant}
9502 When the small model is used variables without storage class are allocated
9503 in the internal ram.
9506 Judicious usage of the processor specific storage classes
9507 \begin_inset LatexCommand \index{Storage class}
9511 and the 'reentrant' function type will yield much more efficient code,
9512 than using the large model.
9513 Several optimizations are disabled when the program is compiled using the
9514 large model, it is therefore strongly recommended that the small model
9515 be used unless absolutely required.
9519 \begin_inset LatexCommand \index{Memory model}
9524 \begin_inset LatexCommand \index{DS390 memory model}
9531 The only model supported is Flat 24
9532 \begin_inset LatexCommand \index{Flat 24 (memory model)}
9537 This generates code for the 24 bit contiguous addressing mode of the Dallas
9539 In this mode, up to four meg of external RAM or code space can be directly
9541 See the data sheets at www.dalsemi.com for further information on this part.
9545 In older versions of the compiler, this option was used with the MCS51 code
9551 Now, however, the '390 has it's own code generator, selected by the
9560 Note that the compiler does not generate any code to place the processor
9561 into 24 bitmode (although
9565 in the ds390 libraries will do that for you).
9571 \begin_inset LatexCommand \index{Tinibios (DS390)}
9575 , the boot loader or similar code must ensure that the processor is in 24
9576 bit contiguous addressing mode before calling the SDCC startup code.
9594 option, variables will by default be placed into the XDATA segment.
9599 Segments may be placed anywhere in the 4 meg address space using the usual
9611 Note that if any segments are located above 64K, the -r flag must be passed
9612 to the linker to generate the proper segment relocations, and the Intel
9613 HEX output format must be used.
9614 The -r flag can be passed to the linker by using the option
9618 on the sdcc command line.
9619 However, currently the linker can not handle code segments > 64k.
9622 Defines Created by the Compiler
9623 \begin_inset LatexCommand \index{Defines created by the compiler}
9630 The compiler creates the following #defines
9631 \begin_inset LatexCommand \index{\#defines}
9639 \begin_inset LatexCommand \index{SDCC}
9643 - this Symbol is always defined.
9647 \begin_inset LatexCommand \index{SDCC\_mcs51}
9652 \begin_inset LatexCommand \index{SDCC\_ds390}
9657 \begin_inset LatexCommand \index{SDCC\_z80}
9661 , etc - depending on the model used (e.g.: -mds390)
9665 \begin_inset LatexCommand \index{\_\_mcs51}
9670 \begin_inset LatexCommand \index{\_\_ds390}
9675 \begin_inset LatexCommand \index{\_\_z80}
9679 , etc - depending on the model used (e.g.
9684 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
9688 - this symbol is defined when
9706 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
9728 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
9750 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
9772 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
9784 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
9799 \begin_inset LatexCommand \index{Optimizations}
9806 SDCC performs a host of standard optimizations in addition to some MCU specific
9809 \layout Subsubsection
9811 Sub-expression Elimination
9812 \begin_inset LatexCommand \index{Subexpression elimination}
9819 The compiler does local and global common subexpression elimination, e.g.:
9830 will be translated to
9842 Some subexpressions are not as obvious as the above example, e.g.:
9852 In this case the address arithmetic a->b[i] will be computed only once;
9853 the equivalent code in C would be.
9865 The compiler will try to keep these temporary variables in registers.
9866 \layout Subsubsection
9868 Dead-Code Elimination
9869 \begin_inset LatexCommand \index{Dead-code elimination}
9888 i = 1; \SpecialChar ~
9893 global = 1;\SpecialChar ~
9906 global = 3;\SpecialChar ~
9917 int global; void f ()
9930 \layout Subsubsection
9933 \begin_inset LatexCommand \index{Copy propagation}
9989 Note: the dead stores created by this copy propagation will be eliminated
9990 by dead-code elimination.
9991 \layout Subsubsection
9994 \begin_inset LatexCommand \index{Loop optimization}
10001 Two types of loop optimizations are done by SDCC loop invariant lifting
10002 and strength reduction of loop induction variables.
10003 In addition to the strength reduction the optimizer marks the induction
10004 variables and the register allocator tries to keep the induction variables
10005 in registers for the duration of the loop.
10006 Because of this preference of the register allocator
10007 \begin_inset LatexCommand \index{Register allocation}
10011 , loop induction optimization causes an increase in register pressure, which
10012 may cause unwanted spilling of other temporary variables into the stack
10013 \begin_inset LatexCommand \index{stack}
10018 The compiler will generate a warning message when it is forced to allocate
10019 extra space either on the stack or data space.
10020 If this extra space allocation is undesirable then induction optimization
10021 can be eliminated either for the entire source file (with -
10031 -noinduction option) or for a given function only using #pragma\SpecialChar ~
10033 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
10046 for (i = 0 ; i < 100 ; i ++)
10060 for (i = 0; i < 100; i++)
10067 As mentioned previously some loop invariants are not as apparent, all static
10068 address computations are also moved out of the loop.
10073 \begin_inset LatexCommand \index{Strength reduction}
10077 , this optimization substitutes an expression by a cheaper expression:
10082 for (i=0;i < 100; i++)
10098 for (i=0;i< 100;i++) {
10102 ar[itemp1] = itemp2;
10115 The more expensive multiplication
10116 \begin_inset LatexCommand \index{Multiplication}
10120 is changed to a less expensive addition.
10121 \layout Subsubsection
10124 \begin_inset LatexCommand \index{Loop reversing}
10131 This optimization is done to reduce the overhead of checking loop boundaries
10132 for every iteration.
10133 Some simple loops can be reversed and implemented using a
10134 \begin_inset Quotes eld
10137 decrement and jump if not zero
10138 \begin_inset Quotes erd
10142 SDCC checks for the following criterion to determine if a loop is reversible
10143 (note: more sophisticated compilers use data-dependency analysis to make
10144 this determination, SDCC uses a more simple minded analysis).
10147 The 'for' loop is of the form
10153 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
10163 The <for body> does not contain
10164 \begin_inset Quotes eld
10168 \begin_inset Quotes erd
10172 \begin_inset Quotes erd
10178 All goto's are contained within the loop.
10181 No function calls within the loop.
10184 The loop control variable <sym> is not assigned any value within the loop
10187 The loop control variable does NOT participate in any arithmetic operation
10191 There are NO switch statements in the loop.
10192 \layout Subsubsection
10194 Algebraic Simplifications
10197 SDCC does numerous algebraic simplifications, the following is a small sub-set
10198 of these optimizations.
10203 i = j + 0 ; /* changed to */ i = j;
10205 i /= 2; /* changed to */ i >>= 1;
10207 i = j - j ; /* changed to */ i = 0;
10209 i = j / 1 ; /* changed to */ i = j;
10212 Note the subexpressions
10213 \begin_inset LatexCommand \index{Subexpression}
10217 given above are generally introduced by macro expansions or as a result
10218 of copy/constant propagation.
10219 \layout Subsubsection
10221 'switch' Statements
10222 \begin_inset LatexCommand \index{switch statement}
10229 SDCC changes switch statements to jump tables
10230 \begin_inset LatexCommand \index{jump tables}
10234 when the following conditions are true.
10238 The case labels are in numerical sequence, the labels need not be in order,
10239 and the starting number need not be one or zero.
10245 switch(i) {\SpecialChar ~
10349 Both the above switch statements will be implemented using a jump-table.
10353 The number of case labels is at least three, since it takes two conditional
10354 statements to handle the boundary conditions.
10357 The number of case labels is less than 84, since each label takes 3 bytes
10358 and a jump-table can be utmost 256 bytes long.
10362 Switch statements which have gaps in the numeric sequence or those that
10363 have more that 84 case labels can be split into more than one switch statement
10364 for efficient code generation, e.g.:
10414 If the above switch statement is broken down into two switch statements
10453 case 9: \SpecialChar ~
10469 case 12:\SpecialChar ~
10476 then both the switch statements will be implemented using jump-tables whereas
10477 the unmodified switch statement will not be.
10478 \layout Subsubsection
10480 Bit-shifting Operations
10481 \begin_inset LatexCommand \index{Bit shifting}
10488 Bit shifting is one of the most frequently used operation in embedded programmin
10490 SDCC tries to implement bit-shift operations in the most efficient way
10506 generates the following code:
10520 In general SDCC will never setup a loop if the shift count is known.
10552 Note that SDCC stores numbers in little-endian format (i.e.
10553 lowest order first).
10554 \layout Subsubsection
10557 \begin_inset LatexCommand \index{Bit rotation}
10564 A special case of the bit-shift operation is bit rotation, SDCC recognizes
10565 the following expression to be a left bit-rotation:
10575 i = ((i << 1) | (i >> 7));
10584 will generate the following code:
10596 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
10597 ns of this case will also be recognized as bit-rotation, i.e.:
10602 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
10603 \layout Subsubsection
10606 \begin_inset LatexCommand \index{Highest Order Bit}
10613 It is frequently required to obtain the highest order bit of an integral
10614 type (long, int, short or char types).
10615 SDCC recognizes the following expression to yield the highest order bit
10616 and generates optimized code for it, e.g.:
10636 hob = (gint >> 15) & 1;
10646 will generate the following code:
10679 000A E5*01\SpecialChar ~
10705 000C 33\SpecialChar ~
10734 000D E4\SpecialChar ~
10763 000E 13\SpecialChar ~
10792 000F F5*02\SpecialChar ~
10819 Variations of this case however will
10824 It is a standard C expression, so I heartily recommend this be the only
10825 way to get the highest order bit, (it is portable).
10826 Of course it will be recognized even if it is embedded in other expressions,
10832 xyz = gint + ((gint >> 15) & 1);
10835 will still be recognized.
10836 \layout Subsubsection
10839 \begin_inset LatexCommand \index{Peephole optimizer}
10846 The compiler uses a rule based, pattern matching and re-writing mechanism
10847 for peep-hole optimization.
10852 a peep-hole optimizer by Christopher W.
10853 Fraser (cwfraser@microsoft.com).
10854 A default set of rules are compiled into the compiler, additional rules
10855 may be added with the
10868 \begin_inset LatexCommand \index{-\/-peep-file}
10875 The rule language is best illustrated with examples.
10899 The above rule will change the following assembly
10900 \begin_inset LatexCommand \index{Assembler routines}
10922 Note: All occurrences of a
10926 (pattern variable) must denote the same string.
10927 With the above rule, the assembly sequence:
10937 will remain unmodified.
10941 Other special case optimizations may be added by the user (via
10957 some variants of the 8051 MCU allow only
10966 The following two rules will change all
10985 replace { lcall %1 } by { acall %1 }
10987 replace { ljmp %1 } by { ajmp %1 }
10992 inline-assembler code
10994 is also passed through the peep hole optimizer, thus the peephole optimizer
10995 can also be used as an assembly level macro expander.
10996 The rules themselves are MCU dependent whereas the rule language infra-structur
10997 e is MCU independent.
10998 Peephole optimization rules for other MCU can be easily programmed using
11003 The syntax for a rule is as follows:
11008 rule := replace [ restart ] '{' <assembly sequence> '
11046 <assembly sequence> '
11064 '}' [if <functionName> ] '
11069 <assembly sequence> := assembly instruction (each instruction including
11070 labels must be on a separate line).
11074 The optimizer will apply to the rules one by one from the top in the sequence
11075 of their appearance, it will terminate when all rules are exhausted.
11076 If the 'restart' option is specified, then the optimizer will start matching
11077 the rules again from the top, this option for a rule is expensive (performance)
11078 , it is intended to be used in situations where a transformation will trigger
11079 the same rule again.
11080 An example of this (not a good one, it has side effects) is the following
11103 Note that the replace pattern cannot be a blank, but can be a comment line.
11104 Without the 'restart' option only the inner most 'pop' 'push' pair would
11105 be eliminated, i.e.:
11135 the restart option the rule will be applied again to the resulting code
11136 and then all the pop-push pairs will be eliminated to yield:
11146 A conditional function can be attached to a rule.
11147 Attaching rules are somewhat more involved, let me illustrate this with
11174 The optimizer does a look-up of a function name table defined in function
11179 in the source file SDCCpeeph.c, with the name
11184 If it finds a corresponding entry the function is called.
11185 Note there can be no parameters specified for these functions, in this
11190 is crucial, since the function
11194 expects to find the label in that particular variable (the hash table containin
11195 g the variable bindings is passed as a parameter).
11196 If you want to code more such functions, take a close look at the function
11197 labelInRange and the calling mechanism in source file SDCCpeeph.c.
11198 I know this whole thing is a little kludgey, but maybe some day we will
11199 have some better means.
11200 If you are looking at this file, you will also see the default rules that
11201 are compiled into the compiler, you can add your own rules in the default
11202 set there if you get tired of specifying the -
11216 \begin_inset LatexCommand \index{Pragmas}
11223 SDCC supports the following #pragma directives.
11227 \begin_inset LatexCommand \index{\#pragma SAVE}
11231 - this will save all current options to the SAVE/RESTORE stack.
11236 \begin_inset LatexCommand \index{\#pragma RESTORE}
11240 - will restore saved options from the last save.
11241 SAVEs & RESTOREs can be nested.
11242 SDCC uses a SAVE/RESTORE stack: SAVE pushes current options to the stack,
11243 RESTORE pulls current options from the stack.
11248 \begin_inset LatexCommand \index{\#pragma NOGCSE}
11252 - will stop global subexpression elimination.
11256 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
11260 - will stop loop induction optimizations.
11264 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
11268 - will not generate code for boundary value checking, when switch statements
11269 are turned into jump-tables.
11273 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
11277 - the compiler will not overlay the parameters and local variables of a
11282 \begin_inset LatexCommand \index{\#pragma LESS\_PEDANTIC}
11286 - the compiler will not warn you anymore for obvious mistakes, you'r on
11291 \begin_inset LatexCommand \index{\#pragma NOLOOPREVERSE}
11295 - Will not do loop reversal optimization
11299 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
11303 NONE | {acc[,b[,dpl[,dph]]] - The exclude pragma disables generation of
11305 \begin_inset LatexCommand \index{push/pop}
11309 instruction in ISR function (using interrupt
11310 \begin_inset LatexCommand \index{interrupt}
11315 The directive should be placed immediately before the ISR function definition
11316 and it affects ALL ISR functions following it.
11317 To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
11318 EXCLUDE\SpecialChar ~
11320 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
11328 \begin_inset LatexCommand \index{\#pragma NOIV}
11332 - Do not generate interrupt vector table entries for all ISR functions
11333 defined after the pragma.
11334 This is useful in cases where the interrupt vector table must be defined
11335 manually, or when there is a secondary, manually defined interrupt vector
11337 for the autovector feature of the Cypress EZ-USB FX2).
11341 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
11346 \begin_inset LatexCommand \index{function prologue}
11350 function1[,function2[,function3...]] - The compiler by default uses a caller
11351 saves convention for register saving across function calls, however this
11352 can cause unnecessary register pushing & popping when calling small functions
11353 from larger functions.
11354 This option can be used to switch off the register saving convention for
11355 the function names specified.
11356 The compiler will not save registers when calling these functions, extra
11357 code need to be manually inserted at the entry & exit for these functions
11358 to save & restore the registers used by these functions, this can SUBSTANTIALLY
11359 reduce code & improve run time performance of the generated code.
11360 In the future the compiler (with inter procedural analysis) may be able
11361 to determine the appropriate scheme to use for each function call.
11372 -callee-saves command line option is used, the function names specified
11373 in #pragma\SpecialChar ~
11375 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
11379 is appended to the list of functions specified in the command line.
11382 The pragma's are intended to be used to turn-off certain optimizations which
11383 might cause the compiler to generate extra stack / data space to store
11384 compiler generated temporary variables.
11385 This usually happens in large functions.
11386 Pragma directives should be used as shown in the following example, they
11387 are used to control options & optimizations for a given function; pragmas
11388 should be placed before and/or after a function, placing pragma's inside
11389 a function body could have unpredictable results.
11395 \begin_inset LatexCommand \index{\#pragma SAVE}
11399 /* save the current settings */
11402 \begin_inset LatexCommand \index{\#pragma NOGCSE}
11406 /* turnoff global subexpression elimination */
11408 #pragma NOINDUCTION
11409 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
11413 /* turn off induction optimizations */
11436 \begin_inset LatexCommand \index{\#pragma RESTORE}
11440 /* turn the optimizations back on */
11443 The compiler will generate a warning message when extra space is allocated.
11444 It is strongly recommended that the SAVE and RESTORE pragma's be used when
11445 changing options for a function.
11450 <pending: this is messy and incomplete>
11455 Compiler support routines (_gptrget, _mulint etc)
11458 Stdclib functions (puts, printf, strcat etc)
11461 Math functions (sin, pow, sqrt etc)
11464 license statements for the libraries are missing
11467 Interfacing with Assembly Routines
11468 \begin_inset LatexCommand \index{Assembler routines}
11473 \layout Subsubsection
11475 Global Registers used for Parameter Passing
11476 \begin_inset LatexCommand \index{Parameter passing}
11483 The compiler always uses the global registers
11486 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
11491 \begin_inset LatexCommand \index{B (register)}
11500 \begin_inset LatexCommand \index{ACC}
11506 to pass the first parameter to a routine.
11507 The second parameter onwards is either allocated on the stack (for reentrant
11518 -stack-auto is used) or in the internal / external ram (depending on the
11521 \layout Subsubsection
11523 Assembler Routine(non-reentrant
11524 \begin_inset LatexCommand \index{reentrant}
11529 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
11536 In the following example the function c_func calls an assembler routine
11537 asm_func, which takes two parameters.
11542 extern int asm_func(unsigned char, unsigned char);
11546 int c_func (unsigned char i, unsigned char j)
11554 return asm_func(i,j);
11568 return c_func(10,9);
11573 The corresponding assembler function is:
11578 .globl _asm_func_PARM_2
11642 add a,_asm_func_PARM_2
11667 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
11684 Note here that the return values are placed in 'dpl' - One byte return value,
11685 'dpl' LSB & 'dph' MSB for two byte values.
11686 'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
11687 b' & 'acc' for four byte values.
11690 The parameter naming convention is _<function_name>_PARM_<n>, where n is
11691 the parameter number starting from 1, and counting from the left.
11692 The first parameter is passed in
11693 \begin_inset Quotes eld
11697 \begin_inset Quotes erd
11700 for One bye parameter,
11701 \begin_inset Quotes eld
11705 \begin_inset Quotes erd
11709 \begin_inset Quotes eld
11713 \begin_inset Quotes erd
11716 for three bytes and
11717 \begin_inset Quotes eld
11721 \begin_inset Quotes erd
11724 for four bytes, the variable name for the second parameter will be _<function_n
11729 Assemble the assembler routine with the following command:
11736 asx8051 -losg asmfunc.asm
11743 Then compile and link the assembler routine to the C source file with the
11751 sdcc cfunc.c asmfunc.rel
11752 \layout Subsubsection
11754 Assembler Routine(reentrant
11755 \begin_inset LatexCommand \index{reentrant}
11760 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
11767 In this case the second parameter onwards will be passed on the stack, the
11768 parameters are pushed from right to left i.e.
11769 after the call the left most parameter will be on the top of the stack.
11770 Here is an example:
11775 extern int asm_func(unsigned char, unsigned char);
11779 int c_func (unsigned char i, unsigned char j) reentrant
11787 return asm_func(i,j);
11801 return c_func(10,9);
11806 The corresponding assembler routine is:
11912 The compiling and linking procedure remains the same, however note the extra
11913 entry & exit linkage required for the assembler code, _bp is the stack
11914 frame pointer and is used to compute the offset into the stack for parameters
11915 and local variables.
11919 \begin_inset LatexCommand \index{stack}
11924 \begin_inset LatexCommand \index{External stack}
11931 The external stack is located at the start of the external ram segment,
11932 and is 256 bytes in size.
11943 -xstack option is used to compile the program, the parameters and local
11944 variables of all reentrant functions are allocated in this area.
11945 This option is provided for programs with large stack space requirements.
11946 When used with the -
11956 -stack-auto option, all parameters and local variables are allocated on
11957 the external stack (note support libraries will need to be recompiled with
11961 The compiler outputs the higher order address byte of the external ram segment
11962 into PORT P2, therefore when using the External Stack option, this port
11963 MAY NOT be used by the application program.
11967 \begin_inset LatexCommand \index{ANSI-compliance}
11974 Deviations from the compliance:
11977 functions are not always reentrant.
11980 structures cannot be assigned values directly, cannot be passed as function
11981 parameters or assigned to each other and cannot be a return value from
12008 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
12019 struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
12041 return rets;/* is invalid in SDCC although allowed in ANSI */
12048 \begin_inset LatexCommand \index{long long (not supported)}
12053 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
12061 \begin_inset LatexCommand \index{double (not supported)}
12065 ' precision floating point
12066 \begin_inset LatexCommand \index{Floating point support}
12073 No support for setjmp and longjmp (for now).
12077 \begin_inset LatexCommand \index{K\&R style}
12081 function declarations are NOT allowed.
12087 foo(i,j) /* this old style of function declarations */
12089 int i,j; /* are valid in ANSI but not valid in SDCC */
12104 functions declared as pointers must be dereferenced during the call.
12115 /* has to be called like this */
12117 (*foo)(); /* ANSI standard allows calls to be made like 'foo()' */
12121 Cyclomatic Complexity
12122 \begin_inset LatexCommand \index{Cyclomatic complexity}
12129 Cyclomatic complexity of a function is defined as the number of independent
12130 paths the program can take during execution of the function.
12131 This is an important number since it defines the number test cases you
12132 have to generate to validate the function.
12133 The accepted industry standard for complexity number is 10, if the cyclomatic
12134 complexity reported by SDCC exceeds 10 you should think about simplification
12135 of the function logic.
12136 Note that the complexity level is not related to the number of lines of
12137 code in a function.
12138 Large functions can have low complexity, and small functions can have large
12144 SDCC uses the following formula to compute the complexity:
12149 complexity = (number of edges in control flow graph) - (number of nodes
12150 in control flow graph) + 2;
12154 Having said that the industry standard is 10, you should be aware that in
12155 some cases it be may unavoidable to have a complexity level of less than
12157 For example if you have switch statement with more than 10 case labels,
12158 each case label adds one to the complexity level.
12159 The complexity level is by no means an absolute measure of the algorithmic
12160 complexity of the function, it does however provide a good starting point
12161 for which functions you might look at for further optimization.
12167 Here are a few guidelines that will help the compiler generate more efficient
12168 code, some of the tips are specific to this compiler others are generally
12169 good programming practice.
12172 Use the smallest data type to represent your data-value.
12173 If it is known in advance that the value is going to be less than 256 then
12174 use an 'unsigned char' instead of a 'short' or 'int'.
12177 Use unsigned when it is known in advance that the value is not going to
12179 This helps especially if you are doing division or multiplication.
12182 NEVER jump into a LOOP.
12185 Declare the variables to be local whenever possible, especially loop control
12186 variables (induction).
12189 Since the compiler does not always do implicit integral promotion, the programme
12190 r should do an explicit cast when integral promotion is required.
12193 Reducing the size of division, multiplication & modulus operations can reduce
12194 code size substantially.
12195 Take the following code for example.
12201 foobar(unsigned int p1, unsigned char ch)
12209 unsigned char ch1 = p1 % ch ;
12220 For the modulus operation the variable ch will be promoted to unsigned int
12221 first then the modulus operation will be performed (this will lead to a
12222 call to support routine _moduint()), and the result will be casted to a
12224 If the code is changed to
12229 foobar(unsigned int p1, unsigned char ch)
12237 unsigned char ch1 = (unsigned char)p1 % ch ;
12248 It would substantially reduce the code generated (future versions of the
12249 compiler will be smart enough to detect such optimization opportunities).
12253 Notes on MCS51 memory
12254 \begin_inset LatexCommand \index{MCS51 memory}
12261 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12262 RAM memory which is structured as follows
12266 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
12269 - Bytes 20-2F - 16 bytes to hold 128 bit variables and,
12271 - Bytes 30-7F - 80 bytes for general purpose use.
12276 Additionally some members of the MCS51 family may have up to 128 bytes of
12277 additional, indirectly addressable, internal RAM memory (
12282 Furthermore, some chips may have some built in external memory (
12286 ) which should not be confused with the internal, directly addressable RAM
12292 Usually this built in
12296 memory has to be activated before using it (you can probably find this
12297 information on the datasheet of the microcontroller your are using).
12300 Normally SDCC will only use the first bank
12301 \begin_inset LatexCommand \index{bank}
12305 of registers (register bank 0), but it is possible to specify that other
12306 banks of registers should be used in interrupt
12307 \begin_inset LatexCommand \index{interrupt}
12312 By default, the compiler will place the stack after the last byte of allocated
12313 memory for variables.
12314 For example, if the first 2 banks of registers are used, and only four
12319 variables, it will position the base of the internal stack at address 20
12321 This implies that as the stack
12322 \begin_inset LatexCommand \index{stack}
12326 grows, it will use up the remaining register banks, and the 16 bytes used
12327 by the 128 bit variables, and 80 bytes for general purpose use.
12328 If any bit variables are used, the data variables will be placed after
12329 the byte holding the last bit variable.
12330 For example, if register banks 0 and 1 are used, and there are 9 bit variables
12335 variables will be placed starting at address 0x22.
12347 \begin_inset LatexCommand \index{-\/-data-loc}
12351 to specify the start address of the
12365 -iram-size to specify the size of the total internal RAM (
12377 By default the 8051 linker will place the stack after the last byte of data
12390 \begin_inset LatexCommand \index{-\/-stack-loc}
12394 allows you to specify the start of the stack, i.e.
12395 you could start it after any data in the general purpose area.
12396 If your microcontroller has additional indirectly addressable internal
12401 ) you can place the stack on it.
12402 You may also need to use -
12413 \begin_inset LatexCommand \index{-\/-data-loc}
12417 to set the start address of the external RAM (
12432 \begin_inset LatexCommand \index{-\/-data-loc}
12436 to specify its size.
12437 Same goes for the code memory, using -
12448 \begin_inset LatexCommand \index{-\/-data-loc}
12463 \begin_inset LatexCommand \index{-\/-data-loc}
12468 If in doubt, don't specify any options and see if the resulting memory
12469 layout is appropriate, then you can adjust it.
12472 The 8051 linker generates two files with memory allocation information.
12473 The first, with extension .map shows all the variables and segments.
12474 The second with extension .mem shows the final memory layout.
12475 The linker will complaint either if memory segments overlap, there is not
12476 enough memory, or there is not enough space for stack.
12477 If you get any linking warnings and/or errors related to stack or segments
12478 allocation, take a look at either the .map or .mem files to find out what
12480 The .mem file may even suggest a solution to the problem.
12484 \begin_inset LatexCommand \index{Tools}
12488 included in the distribution
12492 \begin_inset Tabular
12493 <lyxtabular version="3" rows="12" columns="3">
12495 <column alignment="center" valignment="top" leftline="true" width="0pt">
12496 <column alignment="center" valignment="top" leftline="true" width="0pt">
12497 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
12498 <row topline="true" bottomline="true">
12499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12507 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12515 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12524 <row topline="true">
12525 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12533 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12538 Simulator for various architectures
12541 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12550 <row topline="true">
12551 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12564 header file conversion
12567 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12572 sdcc/support/scripts
12576 <row topline="true">
12577 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12590 header file conversion
12593 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12598 sdcc/support/scripts
12602 <row topline="true">
12603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12619 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12637 <row topline="true">
12638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12646 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12654 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12672 <row topline="true">
12673 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12707 <row topline="true">
12708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12742 <row topline="true">
12743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12759 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12777 <row topline="true">
12778 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12786 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12794 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12812 <row topline="true">
12813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12847 <row topline="true" bottomline="true">
12848 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12864 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12889 Related open source tools
12890 \begin_inset LatexCommand \index{Related tools}
12898 \begin_inset Tabular
12899 <lyxtabular version="3" rows="7" columns="3">
12901 <column alignment="center" valignment="top" leftline="true" width="0pt">
12902 <column alignment="center" valignment="top" leftline="true" width="0pt">
12903 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
12904 <row topline="true" bottomline="true">
12905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12921 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12930 <row topline="true">
12931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12937 \begin_inset LatexCommand \index{gpsim}
12944 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12952 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12958 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
12966 <row topline="true">
12967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12973 \begin_inset LatexCommand \index{srecord}
12980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12985 Object file conversion, checksumming, ...
12988 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12994 \begin_inset LatexCommand \url{http://srecord.sourceforge.net/}
13002 <row topline="true">
13003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13009 \begin_inset LatexCommand \index{objdump}
13016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13021 Object file conversion, ...
13024 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13029 Part of binutils (should be there anyway)
13033 <row topline="true">
13034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13040 \begin_inset LatexCommand \index{doxygen}
13047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13052 Source code documentation system
13055 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13061 \begin_inset LatexCommand \url{http://www.doxygen.org}
13069 <row topline="true">
13070 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13076 \begin_inset LatexCommand \index{splint}
13083 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13088 Statically checks c sources
13091 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13097 \begin_inset LatexCommand \url{http://www.splint.org}
13105 <row topline="true" bottomline="true">
13106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13112 \begin_inset LatexCommand \index{ddd}
13119 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13124 Debugger, serves nicely as GUI to sdcdb
13125 \begin_inset LatexCommand \index{sdcdb}
13132 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13138 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
13153 Related documentation / recommended reading
13157 \begin_inset Tabular
13158 <lyxtabular version="3" rows="5" columns="3">
13160 <column alignment="center" valignment="top" leftline="true" width="0pt">
13161 <column alignment="center" valignment="top" leftline="true" width="0pt">
13162 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
13163 <row topline="true" bottomline="true">
13164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13180 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13189 <row topline="true">
13190 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13200 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13205 Advanced Compiler Design and Implementation
13208 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13217 <row topline="true">
13218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13241 \begin_inset LatexCommand \index{C Reference card}
13248 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13254 \begin_inset LatexCommand \url{http://www.refcards.com/about/c.html}
13262 <row topline="true">
13263 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13268 test_suite_spec.pdf
13271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13276 sdcc regression test
13277 \begin_inset LatexCommand \index{Regression test}
13284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13293 <row topline="true" bottomline="true">
13294 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13320 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13325 sdcc internal documentation
13328 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13344 Retargetting for other MCUs.
13347 The issues for retargetting the compiler are far too numerous to be covered
13349 What follows is a brief description of each of the seven phases of the
13350 compiler and its MCU dependency.
13353 Parsing the source and building the annotated parse tree.
13354 This phase is largely MCU independent (except for the language extensions).
13355 Syntax & semantic checks are also done in this phase, along with some initial
13356 optimizations like back patching labels and the pattern matching optimizations
13357 like bit-rotation etc.
13360 The second phase involves generating an intermediate code which can be easy
13361 manipulated during the later phases.
13362 This phase is entirely MCU independent.
13363 The intermediate code generation assumes the target machine has unlimited
13364 number of registers, and designates them with the name iTemp.
13365 The compiler can be made to dump a human readable form of the code generated
13379 This phase does the bulk of the standard optimizations and is also MCU independe
13381 This phase can be broken down into several sub-phases:
13385 Break down intermediate code (iCode) into basic blocks.
13387 Do control flow & data flow analysis on the basic blocks.
13389 Do local common subexpression elimination, then global subexpression elimination
13391 Dead code elimination
13395 If loop optimizations caused any changes then do 'global subexpression eliminati
13396 on' and 'dead code elimination' again.
13399 This phase determines the live-ranges; by live range I mean those iTemp
13400 variables defined by the compiler that still survive after all the optimization
13402 Live range analysis
13403 \begin_inset LatexCommand \index{Live range analysis}
13407 is essential for register allocation, since these computation determines
13408 which of these iTemps will be assigned to registers, and for how long.
13411 Phase five is register allocation.
13412 There are two parts to this process.
13416 The first part I call 'register packing' (for lack of a better term).
13417 In this case several MCU specific expression folding is done to reduce
13422 The second part is more MCU independent and deals with allocating registers
13423 to the remaining live ranges.
13424 A lot of MCU specific code does creep into this phase because of the limited
13425 number of index registers available in the 8051.
13428 The Code generation phase is (unhappily), entirely MCU dependent and very
13429 little (if any at all) of this code can be reused for other MCU.
13430 However the scheme for allocating a homogenized assembler operand for each
13431 iCode operand may be reused.
13434 As mentioned in the optimization section the peep-hole optimizer is rule
13435 based system, which can reprogrammed for other MCUs.
13439 \begin_inset LatexCommand \index{sdcdb}
13443 - Source Level Debugger
13444 \begin_inset LatexCommand \index{Debugger}
13451 SDCC is distributed with a source level debugger.
13452 The debugger uses a command line interface, the command repertoire of the
13453 debugger has been kept as close to gdb
13454 \begin_inset LatexCommand \index{gdb}
13458 (the GNU debugger) as possible.
13459 The configuration and build process is part of the standard compiler installati
13460 on, which also builds and installs the debugger in the target directory
13461 specified during configuration.
13462 The debugger allows you debug BOTH at the C source and at the ASM source
13466 Compiling for Debugging
13469 The \SpecialChar \-
13471 debug option must be specified for all files for which debug information
13472 is to be generated.
13473 The complier generates a .adb file for each of these files.
13474 The linker creates the .cdb file from the .adb files and the address information.
13475 This .cdb is used by the debugger.
13478 How the Debugger Works
13491 -debug option is specified the compiler generates extra symbol information
13492 some of which are put into the the assembler source and some are put into
13494 Then the linker creates the .cdb file from the individual .adb files with
13495 the address information for the symbols.
13496 The debugger reads the symbolic information generated by the compiler &
13497 the address information generated by the linker.
13498 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
13499 execution is controlled by the debugger.
13500 When a command is issued for the debugger, it translates it into appropriate
13501 commands for the simulator.
13504 Starting the Debugger
13507 The debugger can be started using the following command line.
13508 (Assume the file you are debugging has the file name foo).
13522 The debugger will look for the following files.
13525 foo.c - the source file.
13528 foo.cdb - the debugger symbol information file.
13531 foo.ihx - the Intel hex format
13532 \begin_inset LatexCommand \index{Intel hex format}
13539 Command Line Options.
13552 -directory=<source file directory> this option can used to specify the directory
13554 The debugger will look into the directory list specified for source, cdb
13556 The items in the directory list must be separated by ':', e.g.
13557 if the source files can be in the directories /home/src1 and /home/src2,
13568 -directory option should be -
13578 -directory=/home/src1:/home/src2.
13579 Note there can be no spaces in the option.
13583 -cd <directory> - change to the <directory>.
13586 -fullname - used by GUI front ends.
13589 -cpu <cpu-type> - this argument is passed to the simulator please see the
13590 simulator docs for details.
13593 -X <Clock frequency > this options is passed to the simulator please see
13594 the simulator docs for details.
13597 -s <serial port file> passed to simulator see the simulator docs for details.
13600 -S <serial in,out> passed to simulator see the simulator docs for details.
13606 As mention earlier the command interface for the debugger has been deliberately
13607 kept as close the GNU debugger gdb, as possible.
13608 This will help the integration with existing graphical user interfaces
13609 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
13610 \layout Subsubsection
13612 break [line | file:line | function | file:function]
13615 Set breakpoint at specified line or function:
13624 sdcdb>break foo.c:100
13626 sdcdb>break funcfoo
13628 sdcdb>break foo.c:funcfoo
13629 \layout Subsubsection
13631 clear [line | file:line | function | file:function ]
13634 Clear breakpoint at specified line or function:
13643 sdcdb>clear foo.c:100
13645 sdcdb>clear funcfoo
13647 sdcdb>clear foo.c:funcfoo
13648 \layout Subsubsection
13653 Continue program being debugged, after breakpoint.
13654 \layout Subsubsection
13659 Execute till the end of the current function.
13660 \layout Subsubsection
13665 Delete breakpoint number 'n'.
13666 If used without any option clear ALL user defined break points.
13667 \layout Subsubsection
13669 info [break | stack | frame | registers ]
13672 info break - list all breakpoints
13675 info stack - show the function call stack.
13678 info frame - show information about the current execution frame.
13681 info registers - show content of all registers.
13682 \layout Subsubsection
13687 Step program until it reaches a different source line.
13688 \layout Subsubsection
13693 Step program, proceeding through subroutine calls.
13694 \layout Subsubsection
13699 Start debugged program.
13700 \layout Subsubsection
13705 Print type information of the variable.
13706 \layout Subsubsection
13711 print value of variable.
13712 \layout Subsubsection
13717 load the given file name.
13718 Note this is an alternate method of loading file for debugging.
13719 \layout Subsubsection
13724 print information about current frame.
13725 \layout Subsubsection
13730 Toggle between C source & assembly source.
13731 \layout Subsubsection
13733 ! simulator command
13736 Send the string following '!' to the simulator, the simulator response is
13738 Note the debugger does not interpret the command being sent to the simulator,
13739 so if a command like 'go' is sent the debugger can loose its execution
13740 context and may display incorrect values.
13741 \layout Subsubsection
13748 My name is Bobby Brown"
13751 Interfacing with XEmacs
13752 \begin_inset LatexCommand \index{XEmacs}
13757 \begin_inset LatexCommand \index{Emacs}
13764 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
13765 sdcdb.el and sdcdbsrc.el.
13766 These two files can be found in the $(prefix)/bin directory after the installat
13768 These files need to be loaded into XEmacs for the interface to work.
13769 This can be done at XEmacs startup time by inserting the following into
13770 your '.xemacs' file (which can be found in your HOME directory):
13776 (load-file sdcdbsrc.el)
13782 .xemacs is a lisp file so the () around the command is REQUIRED.
13783 The files can also be loaded dynamically while XEmacs is running, set the
13784 environment variable 'EMACSLOADPATH' to the installation bin directory
13785 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
13786 To start the interface enter the following command:
13800 You will prompted to enter the file name to be debugged.
13805 The command line options that are passed to the simulator directly are bound
13806 to default values in the file sdcdbsrc.el.
13807 The variables are listed below, these values maybe changed as required.
13810 sdcdbsrc-cpu-type '51
13813 sdcdbsrc-frequency '11059200
13816 sdcdbsrc-serial nil
13819 The following is a list of key mapping for the debugger interface.
13827 ;; Current Listing ::
13829 ;;key\SpecialChar ~
13844 binding\SpecialChar ~
13868 ;;---\SpecialChar ~
13883 ------\SpecialChar ~
13923 sdcdb-next-from-src\SpecialChar ~
13949 sdcdb-back-from-src\SpecialChar ~
13975 sdcdb-cont-from-src\SpecialChar ~
13985 SDCDB continue command
14001 sdcdb-step-from-src\SpecialChar ~
14027 sdcdb-whatis-c-sexp\SpecialChar ~
14037 SDCDB ptypecommand for data at
14101 sdcdbsrc-delete\SpecialChar ~
14115 SDCDB Delete all breakpoints if no arg
14163 given or delete arg (C-u arg x)
14179 sdcdbsrc-frame\SpecialChar ~
14194 SDCDB Display current frame if no arg,
14243 given or display frame arg
14308 sdcdbsrc-goto-sdcdb\SpecialChar ~
14318 Goto the SDCDB output buffer
14334 sdcdb-print-c-sexp\SpecialChar ~
14345 SDCDB print command for data at
14409 sdcdbsrc-goto-sdcdb\SpecialChar ~
14419 Goto the SDCDB output buffer
14435 sdcdbsrc-mode\SpecialChar ~
14451 Toggles Sdcdbsrc mode (turns it off)
14455 ;; C-c C-f\SpecialChar ~
14463 sdcdb-finish-from-src\SpecialChar ~
14471 SDCDB finish command
14475 ;; C-x SPC\SpecialChar ~
14483 sdcdb-break\SpecialChar ~
14501 Set break for line with point
14503 ;; ESC t\SpecialChar ~
14513 sdcdbsrc-mode\SpecialChar ~
14529 Toggle Sdcdbsrc mode
14531 ;; ESC m\SpecialChar ~
14541 sdcdbsrc-srcmode\SpecialChar ~
14565 The Z80 and gbz80 port
14568 SDCC can target both the Zilog Z80 and the Nintendo Gameboy's Z80-like gbz80.
14569 The port is incomplete - long support is incomplete (mul, div and mod are
14570 unimplemented), and both float and bitfield support is missing.
14571 Apart from that the code generated is correct.
14574 As always, the code is the authoritave reference - see z80/ralloc.c and z80/gen.c.
14575 The stack frame is similar to that generated by the IAR Z80 compiler.
14576 IX is used as the base pointer, HL is used as a temporary register, and
14577 BC and DE are available for holding variables.
14578 IY is currently unused.
14579 Return values are stored in HL.
14580 One bad side effect of using IX as the base pointer is that a functions
14581 stack frame is limited to 127 bytes - this will be fixed in a later version.
14585 \begin_inset LatexCommand \index{Support}
14592 SDCC has grown to be a large project.
14593 The compiler alone (without the preprocessor, assembler and linker) is
14594 about 40,000 lines of code (blank stripped).
14595 The open source nature of this project is a key to its continued growth
14597 You gain the benefit and support of many active software developers and
14599 Is SDCC perfect? No, that's why we need your help.
14600 The developers take pride in fixing reported bugs.
14601 You can help by reporting the bugs and helping other SDCC users.
14602 There are lots of ways to contribute, and we encourage you to take part
14603 in making SDCC a great software package.
14607 The SDCC project is hosted on the sdcc sourceforge site at
14608 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
14613 You'll find the complete set of mailing lists
14614 \begin_inset LatexCommand \index{Mailing list}
14618 , forums, bug reporting system, patch submission
14619 \begin_inset LatexCommand \index{Patch submission}
14624 \begin_inset LatexCommand \index{download}
14628 area and cvs code repository
14629 \begin_inset LatexCommand \index{cvs code repository}
14637 \begin_inset LatexCommand \index{Bugs}
14642 \begin_inset LatexCommand \index{Reporting bugs}
14649 The recommended way of reporting bugs is using the infrastructure of the
14651 You can follow the status of bug reports there and have an overview about
14655 Bug reports are automatically forwarded to the developer mailing list and
14656 will be fixed ASAP.
14657 When reporting a bug, it is very useful to include a small test program
14658 which reproduces the problem.
14659 If you can isolate the problem by looking at the generated assembly code,
14660 this can be very helpful.
14661 Compiling your program with the -
14672 \begin_inset LatexCommand \index{-\/-dumpall}
14676 option can sometimes be useful in locating optimization problems.
14679 Please have a short check that you are using a recent version of SDCC and
14680 the bug is not yet known.
14681 This is the link for reporting bugs:
14682 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
14689 Requesting Features
14690 \begin_inset LatexCommand \index{Feature request}
14695 \begin_inset LatexCommand \index{Requesting features}
14702 Like bug reports feature requests are forwarded to the developer mailing
14704 This is the link for requesting features:
14705 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
14715 These links should take you directly to the
14716 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
14726 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
14727 automated messages (mid 2003)
14731 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
14735 , lists and forums are archived so if you are lucky someone already had
14740 \begin_inset LatexCommand \index{Changelog}
14747 You can follow the status of the cvs version
14748 \begin_inset LatexCommand \index{version}
14752 of SDCC by watching the file
14753 \begin_inset LatexCommand \htmlurl[ChangeLog]{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/sdcc/sdcc/ChangeLog?rev=HEAD&content-type=text/plain}
14757 in the cvs-repository.
14761 \begin_inset LatexCommand \index{Release policy}
14768 Historically there often were long delays between official releases and
14769 the sourceforge download area tends to get not updated at all.
14770 Current excuses might refer to problems with live range analysis, but if
14771 this is fixed, the next problem rising is that another excuse will have
14773 Kidding aside, we have to get better there!
14777 \begin_inset LatexCommand \index{Examples}
14784 You'll find some small examples in the directory sdcc/device/examples/
14787 Maybe we should include some links to real world applications.
14788 Preferably pointer to pointers (one for each architecture) so this stays
14793 \begin_inset LatexCommand \index{Quality control}
14800 The compiler is passed through nightly compile and build checks.
14806 \begin_inset LatexCommand \index{Regression test}
14810 check that SDCC itself compiles flawlessly on several platforms and checks
14811 the quality of the code generated by SDCC by running the code through simulator
14813 There is a separate document
14816 \begin_inset LatexCommand \index{Test suite}
14825 You'll find the test code in the directory
14827 sdcc/support/regression
14830 You can run these tests manually by running
14834 in this directory (or f.e.
14839 if you don't want to run the complete tests).
14840 The test code might also be interesting if you want to look for examples
14841 \begin_inset LatexCommand \index{Examples}
14845 checking corner cases of SDCC or if you plan to submit patches
14846 \begin_inset LatexCommand \index{Patch submission}
14853 The pic port uses a different set of regression tests, you'll find them
14856 sdcc/src/regression
14862 \begin_inset LatexCommand \index{Compiler internals}
14869 The anatomy of the compiler
14874 This is an excerpt from an article published in Circuit Cellar Magazine
14876 It's a little outdated (the compiler is much more efficient now and user/develo
14877 per friendly), but pretty well exposes the guts of it all.
14883 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
14884 It is fairly easy to retarget for other 8-bit MCU.
14885 Here we take a look at some of the internals of the compiler.
14890 \begin_inset LatexCommand \index{Parsing}
14897 Parsing the input source file and creating an AST (Annotated Syntax Tree
14898 \begin_inset LatexCommand \index{Annotated syntax tree}
14903 This phase also involves propagating types (annotating each node of the
14904 parse tree with type information) and semantic analysis.
14905 There are some MCU specific parsing rules.
14906 For example the storage classes, the extended storage classes are MCU specific
14907 while there may be a xdata storage class for 8051 there is no such storage
14908 class for z80 or Atmel AVR.
14909 SDCC allows MCU specific storage class extensions, i.e.
14910 xdata will be treated as a storage class specifier when parsing 8051 C
14911 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
14916 \begin_inset LatexCommand \index{iCode}
14923 Intermediate code generation.
14924 In this phase the AST is broken down into three-operand form (iCode).
14925 These three operand forms are represented as doubly linked lists.
14926 ICode is the term given to the intermediate form generated by the compiler.
14927 ICode example section shows some examples of iCode generated for some simple
14928 C source functions.
14932 \begin_inset LatexCommand \index{Optimizations}
14939 Bulk of the target independent optimizations is performed in this phase.
14940 The optimizations include constant propagation, common sub-expression eliminati
14941 on, loop invariant code movement, strength reduction of loop induction variables
14942 and dead-code elimination.
14945 Live range analysis
14946 \begin_inset LatexCommand \index{Live range analysis}
14953 During intermediate code generation phase, the compiler assumes the target
14954 machine has infinite number of registers and generates a lot of temporary
14956 The live range computation determines the lifetime of each of these compiler-ge
14957 nerated temporaries.
14958 A picture speaks a thousand words.
14959 ICode example sections show the live range annotations for each of the
14961 It is important to note here, each iCode is assigned a number in the order
14962 of its execution in the function.
14963 The live ranges are computed in terms of these numbers.
14964 The from number is the number of the iCode which first defines the operand
14965 and the to number signifies the iCode which uses this operand last.
14968 Register Allocation
14969 \begin_inset LatexCommand \index{Register allocation}
14976 The register allocation determines the type and number of registers needed
14978 In most MCUs only a few registers can be used for indirect addressing.
14979 In case of 8051 for example the registers R0 & R1 can be used to indirectly
14980 address the internal ram and DPTR to indirectly address the external ram.
14981 The compiler will try to allocate the appropriate register to pointer variables
14983 ICode example section shows the operands annotated with the registers assigned
14985 The compiler will try to keep operands in registers as much as possible;
14986 there are several schemes the compiler uses to do achieve this.
14987 When the compiler runs out of registers the compiler will check to see
14988 if there are any live operands which is not used or defined in the current
14989 basic block being processed, if there are any found then it will push that
14990 operand and use the registers in this block, the operand will then be popped
14991 at the end of the basic block.
14995 There are other MCU specific considerations in this phase.
14996 Some MCUs have an accumulator; very short-lived operands could be assigned
14997 to the accumulator instead of general-purpose register.
15003 Figure II gives a table of iCode operations supported by the compiler.
15004 The code generation involves translating these operations into corresponding
15005 assembly code for the processor.
15006 This sounds overly simple but that is the essence of code generation.
15007 Some of the iCode operations are generated on a MCU specific manner for
15008 example, the z80 port does not use registers to pass parameters so the
15009 SEND and RECV iCode operations will not be generated, and it also does
15010 not support JUMPTABLES.
15017 <Where is Figure II ?>
15021 \begin_inset LatexCommand \index{iCode}
15028 This section shows some details of iCode.
15029 The example C code does not do anything useful; it is used as an example
15030 to illustrate the intermediate code generated by the compiler.
15042 /* This function does nothing useful.
15049 for the purpose of explaining iCode */
15052 short function (data int *x)
15060 short i=10; /* dead initialization eliminated */
15065 short sum=10; /* dead initialization eliminated */
15078 while (*x) *x++ = *p++;
15092 /* compiler detects i,j to be induction variables */
15096 for (i = 0, j = 10 ; i < 10 ; i++, j
15122 mul += i * 3; /* this multiplication remains */
15128 gint += j * 3;/* this multiplication changed to addition */
15142 In addition to the operands each iCode contains information about the filename
15143 and line it corresponds to in the source file.
15144 The first field in the listing should be interpreted as follows:
15149 Filename(linenumber: iCode Execution sequence number : ICode hash table
15150 key : loop depth of the iCode).
15155 Then follows the human readable form of the ICode operation.
15156 Each operand of this triplet form can be of three basic types a) compiler
15157 generated temporary b) user defined variable c) a constant value.
15158 Note that local variables and parameters are replaced by compiler generated
15161 \begin_inset LatexCommand \index{Live range analysis}
15165 are computed only for temporaries (i.e.
15166 live ranges are not computed for global variables).
15168 \begin_inset LatexCommand \index{Register allocation}
15172 are allocated for temporaries only.
15173 Operands are formatted in the following manner:
15178 Operand Name [lr live-from : live-to ] { type information } [ registers
15184 As mentioned earlier the live ranges are computed in terms of the execution
15185 sequence number of the iCodes, for example
15187 the iTemp0 is live from (i.e.
15188 first defined in iCode with execution sequence number 3, and is last used
15189 in the iCode with sequence number 5).
15190 For induction variables such as iTemp21 the live range computation extends
15191 the lifetime from the start to the end of the loop.
15193 The register allocator used the live range information to allocate registers,
15194 the same registers may be used for different temporaries if their live
15195 ranges do not overlap, for example r0 is allocated to both iTemp6 and to
15196 iTemp17 since their live ranges do not overlap.
15197 In addition the allocator also takes into consideration the type and usage
15198 of a temporary, for example itemp6 is a pointer to near space and is used
15199 as to fetch data from (i.e.
15200 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer registers (r0).
15201 Some short lived temporaries are allocated to special registers which have
15202 meaning to the code generator e.g.
15203 iTemp13 is allocated to a pseudo register CC which tells the back end that
15204 the temporary is used only for a conditional jump the code generation makes
15205 use of this information to optimize a compare and jump ICode.
15207 There are several loop optimizations
15208 \begin_inset LatexCommand \index{Loop optimization}
15212 performed by the compiler.
15213 It can detect induction variables iTemp21(i) and iTemp23(j).
15214 Also note the compiler does selective strength reduction
15215 \begin_inset LatexCommand \index{Strength reduction}
15220 the multiplication of an induction variable in line 18 (gint = j * 3) is
15221 changed to addition, a new temporary iTemp17 is allocated and assigned
15222 a initial value, a constant 3 is then added for each iteration of the loop.
15223 The compiler does not change the multiplication
15224 \begin_inset LatexCommand \index{Multiplication}
15228 in line 17 however since the processor does support an 8 * 8 bit multiplication.
15230 Note the dead code elimination
15231 \begin_inset LatexCommand \index{Dead-code elimination}
15235 optimization eliminated the dead assignments in line 7 & 8 to I and sum
15243 Sample.c (5:1:0:0) _entry($9) :
15248 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
15253 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
15258 Sample.c(11:4:53:0) preHeaderLbl0($11) :
15263 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
15269 Sample.c(11:6:5:1) _whilecontinue_0($1) :
15274 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
15280 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
15285 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
15291 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
15297 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
15303 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
15309 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
15310 * int}[r0] + 0x2 {short}
15315 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
15320 Sample.c(11:17:21:0)_whilebreak_0($3) :
15325 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
15330 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
15335 Sample.c(15:20:54:0)preHeaderLbl1($13) :
15340 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
15345 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
15350 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
15355 Sample.c(15:24:26:1)_forcond_0($4) :
15360 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
15366 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
15371 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
15372 + ITemp21 [lr21:38]{short}[r4]
15377 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
15383 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
15384 + iTemp15 [lr29:30]{short}[r1]
15389 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
15395 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
15401 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
15407 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
15413 Sample.c(19:38:47:1) goto _forcond_0($4)
15418 Sample.c(19:39:48:0)_forbreak_0($7) :
15423 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
15424 + ITemp11 [lr19:40]{short}[r3]
15429 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
15434 Sample.c(20:42:51:0)_return($8) :
15439 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
15445 Finally the code generated for this function:
15486 ; ----------------------------------------------
15491 ; function function
15496 ; ----------------------------------------------
15506 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
15518 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
15530 ;_whilecontinue_0($1) :
15540 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
15545 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
15604 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
15623 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
15670 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
15710 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
15736 ; iTemp6 [lr5:16]{_near * int}[r0] =
15741 ; iTemp6 [lr5:16]{_near * int}[r0] +
15758 ; goto _whilecontinue_0($1)
15770 ; _whilebreak_0($3) :
15780 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
15792 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
15804 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
15816 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
15835 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
15864 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
15869 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
15914 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
15919 ; iTemp21 [lr21:38]{short}[r4]
15945 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
15978 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
15983 ; iTemp15 [lr29:30]{short}[r1]
16002 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
16049 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
16096 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
16108 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
16122 cjne r5,#0xff,00104$
16134 ; goto _forcond_0($4)
16146 ; _forbreak_0($7) :
16156 ; ret iTemp24 [lr40:41]{short}
16199 A few words about basic block successors, predecessors and dominators
16202 Successors are basic blocks
16203 \begin_inset LatexCommand \index{Basic blocks}
16207 that might execute after this basic block.
16209 Predecessors are basic blocks that might execute before reaching this basic
16212 Dominators are basic blocks that WILL execute before reaching this basic
16238 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
16241 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
16244 c) domVect of [BB4] = BB1 ...
16245 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
16253 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
16263 Thanks to all the other volunteer developers who have helped with coding,
16264 testing, web-page creation, distribution sets, etc.
16265 You know who you are :-)
16272 This document was initially written by Sandeep Dutta
16275 All product names mentioned herein may be trademarks
16276 \begin_inset LatexCommand \index{Trademarks}
16280 of their respective companies.
16287 To avoid confusion, the installation and building options for sdcc itself
16288 (chapter 2) are not part of the index.
16292 \begin_inset LatexCommand \printindex{}