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 documention
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 overriden by:
491 \labelwidthstring 00.00.0000
503 -prefix see tabel below
505 \labelwidthstring 00.00.0000
517 -exec_prefix see tabel below
519 \labelwidthstring 00.00.0000
531 -bindir see tabel below
533 \labelwidthstring 00.00.0000
545 -datadir see tabel below
547 \labelwidthstring 00.00.0000
549 docdir environment variable, see tabel below
551 \labelwidthstring 00.00.0000
553 include_dir_suffix environment variable, see tabel below
555 \labelwidthstring 00.00.0000
557 lib_dir_suffix environment variable, see tabel 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">
1202 ./configure --prefix=
1203 \begin_inset Quotes srd
1207 \begin_inset Quotes srd
1211 \begin_inset Quotes srd
1215 \begin_inset Quotes srd
1221 ./configure --disable-avr-port --disable-xa51-port
1224 To crosscompile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw3
1234 \begin_inset Quotes srd
1237 i586-mingw32msvc-gcc
1238 \begin_inset Quotes srd
1242 \begin_inset Quotes srd
1245 i586-mingw32msvc-g++
1246 \begin_inset Quotes srd
1255 \begin_inset Quotes srd
1258 i586-mingw32msvc-ranlib
1259 \begin_inset Quotes srd
1268 \begin_inset Quotes srd
1271 i586-mingw32msvc-strip
1272 \begin_inset Quotes srd
1281 \begin_inset Quotes srd
1285 \begin_inset Quotes srd
1294 \begin_inset Quotes srd
1298 \begin_inset Quotes srd
1307 \begin_inset Quotes srd
1311 \begin_inset Quotes srd
1320 \begin_inset Quotes srd
1324 \begin_inset Quotes srd
1333 \begin_inset Quotes srd
1337 \begin_inset Quotes srd
1345 sdccconf_h_dir_separator=
1346 \begin_inset Quotes srd
1358 \begin_inset Quotes srd
1366 --disable-device-lib-build
1376 --host=i586-mingw32msvc --build=unknown-unknown-linux-gnu
1380 \begin_inset Quotes sld
1384 \begin_inset Quotes srd
1387 compile on Cygwin for Mingw32(see also sdcc/support/scripts/sdcc_cygwin_mingw32)
1397 \begin_inset Quotes srd
1401 \begin_inset Quotes srd
1410 \begin_inset Quotes srd
1414 \begin_inset Quotes srd
1423 \begin_inset Quotes srd
1427 \begin_inset Quotes srd
1436 \begin_inset Quotes srd
1440 \begin_inset Quotes srd
1449 \begin_inset Quotes srd
1453 \begin_inset Quotes srd
1462 \begin_inset Quotes srd
1466 \begin_inset Quotes srd
1475 \begin_inset Quotes srd
1479 \begin_inset Quotes srd
1487 sdccconf_h_dir_separator=
1488 \begin_inset Quotes srd
1500 \begin_inset Quotes srd
1511 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
1522 -C' turns on caching, which gives a little bit extra speed.
1523 However if options are changed, it can be necessary to delete the config.cache
1528 \begin_inset LatexCommand \index{Install paths}
1536 Binary files (preprocessor, assembler and linker)
1540 \begin_inset Tabular
1541 <lyxtabular version="3" rows="2" columns="3">
1543 <column alignment="block" valignment="top" leftline="true" width="0in">
1544 <column alignment="block" valignment="top" leftline="true" width="0in">
1545 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1546 <row topline="true" bottomline="true">
1547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1563 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1572 <row topline="true" bottomline="true">
1573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1583 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1591 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1617 \begin_inset Tabular
1618 <lyxtabular version="3" rows="2" columns="3">
1620 <column alignment="block" valignment="top" leftline="true" width="1.6in">
1621 <column alignment="block" valignment="top" leftline="true" width="0in">
1622 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1623 <row topline="true" bottomline="true">
1624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1649 <row topline="true" bottomline="true">
1650 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
1662 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1667 /usr/local/share/sdcc/include
1670 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1696 is auto-appended by the compiler, e.g.
1697 small, large, z80, ds390 etc.)
1701 \begin_inset Tabular
1702 <lyxtabular version="3" rows="2" columns="3">
1704 <column alignment="block" valignment="top" leftline="true" width="0in">
1705 <column alignment="block" valignment="top" leftline="true" width="0in">
1706 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1707 <row topline="true" bottomline="true">
1708 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1716 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1724 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1733 <row topline="true" bottomline="true">
1734 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1741 $DATADIR/$LIB_DIR_SUFFIX
1744 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1749 /usr/local/share/sdcc/lib
1752 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1778 \begin_inset Tabular
1779 <lyxtabular version="3" rows="2" columns="3">
1781 <column alignment="block" valignment="top" leftline="true" width="0in">
1782 <column alignment="block" valignment="top" leftline="true" width="0in">
1783 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1784 <row topline="true" bottomline="true">
1785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1810 <row topline="true" bottomline="true">
1811 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1826 /usr/local/share/sdcc/doc
1829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1850 The install paths can still be changed during `make install` with e.g.:
1853 make install prefix=$(HOME)/local/sdcc
1856 Of course this doesn't change the search paths compiled into the binaries.
1860 \begin_inset LatexCommand \index{Search path}
1867 Some search paths or parts of them are determined by configure variables
1872 , see section above).
1873 Further search paths are determined by environment variables during runtime.
1876 The paths searched when running the compiler are as follows (the first catch
1882 Binary files (preprocessor, assembler and linker)
1885 \begin_inset Tabular
1886 <lyxtabular version="3" rows="4" 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">
1918 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1936 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1947 <row topline="true">
1948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1953 Path of argv[0] (if available)
1956 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1964 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1973 <row topline="true" bottomline="true">
1974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2011 \begin_inset Tabular
2012 <lyxtabular version="3" rows="6" columns="3">
2014 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2015 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2016 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2017 <row topline="true" bottomline="true">
2018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2043 <row topline="true">
2044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2062 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2080 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2099 <row topline="true">
2100 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2125 <row topline="true">
2126 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2140 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2152 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2163 <row topline="true">
2164 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2232 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2245 <row topline="true" bottomline="true">
2246 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2262 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2267 /usr/local/share/sdcc/
2272 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2299 -nostdinc disables the last two search paths.
2306 With the exception of
2307 \begin_inset Quotes sld
2321 \begin_inset Quotes srd
2328 is auto-appended by the compiler (e.g.
2329 small, large, z80, ds390 etc.).
2333 \begin_inset Tabular
2334 <lyxtabular version="3" rows="6" columns="3">
2336 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2337 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2338 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2339 <row topline="true" bottomline="true">
2340 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2348 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2356 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2365 <row topline="true">
2366 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2421 <row topline="true">
2422 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2434 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2446 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2461 <row topline="true">
2462 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2473 $LIB_DIR_SUFFIX/<model>
2476 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2490 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2507 <row topline="true">
2508 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2523 $LIB_DIR_SUFFIX/<model>
2526 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2579 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2635 <row topline="true" bottomline="true">
2636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2645 $LIB_DIR_SUFFIX/<model>
2648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2653 /usr/local/share/sdcc/
2660 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2676 Don't delete any of the stray spaces in the table above without checking
2677 the HTML output (last line)!
2693 -nostdlib disables the last two search paths.
2697 \begin_inset LatexCommand \index{Building SDCC}
2702 \layout Subsubsection
2704 Building SDCC on Linux
2709 Download the source package
2711 either from the SDCC CVS repository or from the
2712 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
2718 , it will be named something like sdcc
2731 Bring up a command line terminal, such as xterm.
2736 Unpack the file using a command like:
2739 "tar -xzf sdcc.src.tar.gz
2744 , this will create a sub-directory called sdcc with all of the sources.
2747 Change directory into the main SDCC directory, for example type:
2764 This configures the package for compilation on your system.
2780 All of the source packages will compile, this can take a while.
2796 This copies the binary executables, the include files, the libraries and
2797 the documentation to the install directories.
2798 \layout Subsubsection
2800 Building SDCC on OSX 2.x
2803 Follow the instruction for Linux.
2807 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
2808 )) fails to compile SDCC.
2809 Fortunately there's also gcc 2.9.x installed, which works fine.
2810 This compiler can be selected by running 'configure' with:
2813 ./configure CC=gcc2 CXX=g++2
2814 \layout Subsubsection
2816 Crosscompiling SDCC on Linux for Windows
2819 With the Mingw32 gcc crosscompiler it's easy to compile SDCC for Win32.
2820 See section 'Configure Options'.
2821 \layout Subsubsection
2823 Building SDCC on Windows
2826 With the exception of Cygwin the SDCC binaries uCsim and sdcdb can't be
2828 They use Unix-sockets, which are not available on Win32.
2829 \layout Subsubsection
2831 Windows Install Using a Binary Package
2834 Download the binary package and unpack it using your favorite unpacking
2835 tool (gunzip, WinZip, etc).
2836 This should unpack to a group of sub-directories.
2837 An example directory structure after unpacking the mingw32 package is:
2842 bin for the executables, c:
2850 lib for the include and libraries.
2853 Adjust your environment variable PATH to include the location of the bin
2854 directory or start sdcc using the full path.
2855 \layout Subsubsection
2857 Building SDCC using Cygwin and Mingw32
2860 For building and installing a Cygwin executable follow the instructions
2866 \begin_inset Quotes sld
2870 \begin_inset Quotes srd
2873 Win32-binary can be built, which will not need the Cygwin-DLL.
2874 For the necessary 'configure' options see section 'configure options' or
2875 the script 'sdcc/support/scripts/sdcc_cygwinmingw32'.
2879 In order to install Cygwin on Windows download setup.exe from
2880 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
2886 \begin_inset Quotes sld
2889 default text file type
2890 \begin_inset Quotes srd
2894 \begin_inset Quotes sld
2898 \begin_inset Quotes srd
2901 and download/install at least the following packages.
2902 Some packages are selected by default, others will be automatically selected
2903 because of dependencies with the manually selected packages.
2904 Never deselect these packages!
2913 gcc ; version 3.x is fine, no need to use the old 2.9x
2916 binutils ; selected with gcc
2922 rxvt ; a nice console, which makes life much easier under windoze (see below)
2925 man ; not really needed for building SDCC, but you'll miss it sooner or
2929 less ; not really needed for building SDCC, but you'll miss it sooner or
2933 cvs ; only if you use CVS access
2936 If you want to develop something you'll need:
2939 python ; for the regression tests
2942 gdb ; the gnu debugger, together with the nice GUI
2943 \begin_inset Quotes sld
2947 \begin_inset Quotes srd
2953 openssh ; to access the CF or commit changes
2956 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
2957 use autoconf-stable!
2960 rxvt is a nice console with history.
2961 Replace in your cygwin.bat the line
2970 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
2973 -bg black -fg white -geometry 100x65 -e bash --login
2976 Text selected with the mouse is automatically copied to the clipboard, pasting
2977 works with shift-insert.
2981 The other good tip is to make sure you have no //c/-style paths anywhere,
2982 use /cygdrive/c/ instead.
2983 Using // invokes a network lookup which is very slow.
2985 \begin_inset Quotes sld
2989 \begin_inset Quotes srd
2992 is too long, you can change it with e.g.
2998 SDCC sources use the unix line ending LF.
2999 Life is much easier, if you store the source tree on a drive, which is
3000 mount in binary mode.
3001 And use an editor which can handle LF-only line endings.
3002 Make sure not to commit files with windows line endings.
3003 \layout Subsubsection
3005 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3010 Download the source package
3012 either from the SDCC CVS repository or from the
3013 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3019 , it will be named something like sdcc
3026 SDCC is distributed with all the projects, workspaces, and files you need
3027 to build it using Visual C++ 6.0/NET (except for sdcdb.exe which currently
3028 doesn't build under MSVC).
3029 The workspace name is 'sdcc.dsw'.
3030 Please note that as it is now, all the executables are created in a folder
3034 Once built you need to copy the executables from sdcc
3038 bin before runing SDCC.
3043 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3044 flex.exe, and gawk.exe.
3045 One good place to get them is
3046 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3054 Download the file UnxUtils
3055 \begin_inset LatexCommand \index{UnxUtils}
3060 Now you have to install the utilities and setup MSVC so it can locate the
3062 Here there are two alternatives (choose one!):
3069 a) Extract UnxUtils.zip to your C:
3071 hard disk PRESERVING the original paths, otherwise bison won't work.
3072 (If you are using WinZip make certain that 'Use folder names' is selected)
3076 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3077 in 'Show directories for:' select 'Executable files', and in the directories
3078 window add a new path: 'C:
3088 (As a side effect, you get a bunch of Unix utilities that could be useful,
3089 such as diff and patch.)
3096 This one avoids extracting a bunch of files you may not use, but requires
3101 a) Create a directory were to put the tools needed, or use a directory already
3109 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3110 to such directory WITHOUT preserving the original paths.
3111 (If you are using WinZip make certain that 'Use folder names' is not selected)
3115 c) Rename bison.exe to '_bison.exe'.
3119 d) Create a batch file 'bison.bat' in 'C:
3123 ' and add these lines:
3143 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3147 Steps 'c' and 'd' are needed because bison requires by default that the
3148 files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3149 '/usr/local/share/' I think.
3150 So it is necessary to tell bison where those files are located if they
3151 are not in such directory.
3152 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3156 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3157 in 'Show directories for:' select 'Executable files', and in the directories
3158 window add a new path: 'c:
3161 Note that you can use any other path instead of 'c:
3163 util', even the path where the Visual C++ tools are, probably: 'C:
3167 Microsoft Visual Studio
3172 So you don't have to execute step 'e' :)
3176 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3177 the executables from sdcc
3181 bin, and you can compile using sdcc.
3182 \layout Subsubsection
3184 Building SDCC Using Borland
3187 From the sdcc directory, run the command "make -f Makefile.bcc".
3188 This should regenerate all the .exe files in the bin directory except for
3189 sdcdb.exe (which currently doesn't build under Borland C++).
3192 If you modify any source files and need to rebuild, be aware that the dependanci
3193 es may not be correctly calculated.
3194 The safest option is to delete all .obj files and run the build again.
3195 From a Cygwin BASH prompt, this can easily be done with the commmand:
3205 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
3207 ) -print -exec rm {}
3216 or on Windows NT/2000/XP from the command prompt with the commmand:
3223 del /s *.obj *.lib *.rul
3226 from the sdcc directory.
3229 Building the Documentation
3236 Testing out the SDCC Compiler
3239 The first thing you should do after installing your SDCC compiler is to
3255 \begin_inset LatexCommand \index{version}
3262 at the prompt, and the program should run and tell you the version.
3263 If it doesn't run, or gives a message about not finding sdcc program, then
3264 you need to check over your installation.
3265 Make sure that the sdcc bin directory is in your executable search path
3266 defined by the PATH environment setting (see the Trouble-shooting section
3268 Make sure that the sdcc program is in the bin folder, if not perhaps something
3269 did not install correctly.
3277 is commonly installed as described in section
3278 \begin_inset Quotes sld
3281 Install and search paths
3282 \begin_inset Quotes srd
3291 Make sure the compiler works on a very simple example.
3292 Type in the following test.c program using your favorite
3327 Compile this using the following command:
3336 If all goes well, the compiler will generate a test.asm and test.rel file.
3337 Congratulations, you've just compiled your first program with SDCC.
3338 We used the -c option to tell SDCC not to link the generated code, just
3339 to keep things simple for this step.
3347 The next step is to try it with the linker.
3357 If all goes well the compiler will link with the libraries and produce
3358 a test.ihx output file.
3363 (no test.ihx, and the linker generates warnings), then the problem is most
3364 likely that sdcc cannot find the
3368 usr/local/share/sdcc/lib directory
3372 (see the Install trouble-shooting section for suggestions).
3380 The final test is to ensure sdcc can use the
3384 header files and libraries.
3385 Edit test.c and change it to the following:
3405 strcpy(str1, "testing");
3414 Compile this by typing
3421 This should generate a test.ihx output file, and it should give no warnings
3422 such as not finding the string.h file.
3423 If it cannot find the string.h file, then the problem is that sdcc cannot
3424 find the /usr/local/share/sdcc/include directory
3428 (see the Install trouble-shooting section for suggestions).
3431 Install Trouble-shooting
3432 \begin_inset LatexCommand \index{Install trouble-shooting}
3437 \layout Subsubsection
3439 SDCC does not build correctly.
3442 A thing to try is starting from scratch by unpacking the .tgz source package
3443 again in an empty directory.
3451 ./configure 2>&1 | tee configure.log
3465 make 2>&1 | tee make.log
3472 If anything goes wrong, you can review the log files to locate the problem.
3473 Or a relevant part of this can be attached to an email that could be helpful
3474 when requesting help from the mailing list.
3475 \layout Subsubsection
3478 \begin_inset Quotes sld
3482 \begin_inset Quotes srd
3489 \begin_inset Quotes sld
3493 \begin_inset Quotes srd
3496 command is a script that analyzes your system and performs some configuration
3497 to ensure the source package compiles on your system.
3498 It will take a few minutes to run, and will compile a few tests to determine
3499 what compiler features are installed.
3500 \layout Subsubsection
3503 \begin_inset Quotes sld
3507 \begin_inset Quotes srd
3513 This runs the GNU make tool, which automatically compiles all the source
3514 packages into the final installed binary executables.
3515 \layout Subsubsection
3518 \begin_inset Quotes sld
3522 \begin_inset Quotes erd
3528 This will install the compiler, other executables libraries and include
3529 files in to the appropriate directories.
3531 \begin_inset Quotes sld
3534 Install and Search PATHS
3535 \begin_inset Quotes srd
3540 On most systems you will need super-user privilages to do this.
3546 SDCC is not just a compiler, but a collection of tools by various developers.
3547 These include linkers, assemblers, simulators and other components.
3548 Here is a summary of some of the components.
3549 Note that the included simulator and assembler have separate documentation
3550 which you can find in the source package in their respective directories.
3551 As SDCC grows to include support for other processors, other packages from
3552 various developers are included and may have their own sets of documentation.
3556 You might want to look at the files which are installed in <installdir>.
3557 At the time of this writing, we find the following programs for gcc-builds:
3561 In <installdir>/bin:
3564 sdcc - The compiler.
3567 sdcpp - The C preprocessor.
3570 asx8051 - The assembler for 8051 type processors.
3577 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
3580 aslink -The linker for 8051 type processors.
3587 link-gbz80 - The Z80 and GameBoy Z80 linkers.
3590 s51 - The ucSim 8051 simulator.
3593 sdcdb - The source debugger.
3596 packihx - A tool to pack (compress) Intel hex files.
3599 In <installdir>/share/sdcc/include
3605 In <installdir>/share/sdcc/lib
3608 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
3612 In <installdir>/share/sdcc/doc
3618 As development for other processors proceeds, this list will expand to include
3619 executables to support processors like AVR, PIC, etc.
3620 \layout Subsubsection
3625 This is the actual compiler, it in turn uses the c-preprocessor and invokes
3626 the assembler and linkage editor.
3627 \layout Subsubsection
3630 \begin_inset LatexCommand \index{sdcpp}
3634 - The C-Preprocessor
3637 The preprocessor is a modified version of the GNU preprocessor.
3638 The C preprocessor is used to pull in #include sources, process #ifdef
3639 statements, #defines and so on.
3640 \layout Subsubsection
3642 asx8051, as-z80, as-gbz80, aslink, link-z80, link-gbz80 - The Assemblers
3646 This is retargettable assembler & linkage editor, it was developed by Alan
3648 John Hartman created the version for 8051, and I (Sandeep) have made some
3649 enhancements and bug fixes for it to work properly with the SDCC.
3650 \layout Subsubsection
3653 \begin_inset LatexCommand \index{s51}
3660 S51 is a freeware, opensource simulator developed by Daniel Drotos (
3661 \begin_inset LatexCommand \url{mailto:drdani@mazsola.iit.uni-miskolc.hu}
3666 The simulator is built as part of the build process.
3667 For more information visit Daniel's website at:
3668 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
3673 It currently support the core mcs51, the Dallas DS80C390 and the Philips
3675 \layout Subsubsection
3678 \begin_inset LatexCommand \index{sdcdb}
3682 - Source Level Debugger
3685 Sdcdb is the companion source level debugger.
3686 The current version of the debugger uses Daniel's Simulator S51, but can
3687 be easily changed to use other simulators.
3694 \layout Subsubsection
3696 Single Source File Projects
3699 For single source file 8051 projects the process is very simple.
3700 Compile your programs with the following command
3703 "sdcc sourcefile.c".
3707 This will compile, assemble and link your source file.
3708 Output files are as follows
3712 \begin_inset LatexCommand \index{.asm}
3717 \begin_inset LatexCommand \index{Assembler source}
3721 file created by the compiler
3725 \begin_inset LatexCommand \index{.lst}
3730 \begin_inset LatexCommand \index{Assembler listing}
3734 file created by the Assembler
3738 \begin_inset LatexCommand \index{.rst}
3743 \begin_inset LatexCommand \index{Assembler listing}
3747 file updated with linkedit information, created by linkage editor
3751 \begin_inset LatexCommand \index{.sym}
3756 \begin_inset LatexCommand \index{Symbol listing}
3760 for the sourcefile, created by the assembler
3764 \begin_inset LatexCommand \index{.rel}
3769 \begin_inset LatexCommand \index{Object file}
3773 created by the assembler, input to Linkage editor
3777 \begin_inset LatexCommand \index{.map}
3782 \begin_inset LatexCommand \index{Memory map}
3786 for the load module, created by the Linker
3790 \begin_inset LatexCommand \index{.mem}
3794 - A file with a summary of the memory usage
3798 \begin_inset LatexCommand \index{.ihx}
3802 - The load module in Intel hex format
3803 \begin_inset LatexCommand \index{Intel hex format}
3807 (you can select the Motorola S19 format
3808 \begin_inset LatexCommand \index{Motorola S19 format}
3823 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
3828 If you need another format you might want to use objdump
3829 \begin_inset LatexCommand \index{objdump}
3834 \begin_inset LatexCommand \index{srecord}
3842 \begin_inset LatexCommand \index{.adb}
3846 - An intermediate file containing debug information needed to create the
3858 \begin_inset LatexCommand \index{-\/-debug}
3866 \begin_inset LatexCommand \index{.cdb}
3870 - An optional file (with -
3880 -debug) containing debug information
3885 \begin_inset LatexCommand \index{. (no extension)}
3889 An optional AOMF51 file containing debug information (with -
3903 \begin_inset LatexCommand \index{.dump*}
3907 - Dump file to debug the compiler it self (with -
3917 -dumpall) (see section
3918 \begin_inset Quotes sld
3921 Anatomy of the compiler
3922 \begin_inset Quotes srd
3926 \layout Subsubsection
3928 Projects with Multiple Source Files
3931 SDCC can compile only ONE file at a time.
3932 Let us for example assume that you have a project containing the following
3937 foo1.c (contains some functions)
3939 foo2.c (contains some more functions)
3941 foomain.c (contains more functions and the function main)
3949 The first two files will need to be compiled separately with the commands:
3981 Then compile the source file containing the
3986 \begin_inset LatexCommand \index{Linker}
3990 the files together with the following command:
3998 foomain.c\SpecialChar ~
3999 foo1.rel\SpecialChar ~
4004 \begin_inset LatexCommand \index{.rel}
4016 can be separately compiled as well:
4027 sdcc foomain.rel foo1.rel foo2.rel
4034 The file containing the
4049 file specified in the command line, since the linkage editor processes
4050 file in the order they are presented to it.
4051 \layout Subsubsection
4053 Projects with Additional Libraries
4054 \begin_inset LatexCommand \index{Libraries}
4061 Some reusable routines may be compiled into a library, see the documentation
4062 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
4066 \begin_inset LatexCommand \index{.lib}
4073 Libraries created in this manner can be included in the command line.
4074 Make sure you include the -L <library-path> option to tell the linker where
4075 to look for these files if they are not in the current directory.
4076 Here is an example, assuming you have the source file
4088 (if that is not the same as your current project):
4095 sdcc foomain.c foolib.lib -L mylib
4106 must be an absolute path name.
4110 The most efficient way to use libraries is to keep seperate modules in seperate
4112 The lib file now should name all the modules.rel files.
4113 For an example see the standard library file
4117 in the directory <installdir>/share/lib/small.
4120 Command Line Options
4121 \begin_inset LatexCommand \index{Command Line Options}
4126 \layout Subsubsection
4128 Processor Selection Options
4129 \begin_inset LatexCommand \index{Options processor selection}
4134 \begin_inset LatexCommand \index{Processor selection options}
4140 \labelwidthstring 00.00.0000
4145 \begin_inset LatexCommand \index{-mmcs51}
4151 Generate code for the MCS51
4152 \begin_inset LatexCommand \index{MCS51}
4156 family of processors.
4157 This is the default processor target.
4159 \labelwidthstring 00.00.0000
4164 \begin_inset LatexCommand \index{-mds390}
4170 Generate code for the DS80C390
4171 \begin_inset LatexCommand \index{DS80C390}
4177 \labelwidthstring 00.00.0000
4182 \begin_inset LatexCommand \index{-mds400}
4188 Generate code for the DS80C400
4189 \begin_inset LatexCommand \index{DS80C400}
4195 \labelwidthstring 00.00.0000
4200 \begin_inset LatexCommand \index{-mz80}
4206 Generate code for the Z80
4207 \begin_inset LatexCommand \index{Z80}
4211 family of processors.
4213 \labelwidthstring 00.00.0000
4218 \begin_inset LatexCommand \index{-mgbz80}
4224 Generate code for the GameBoy Z80
4225 \begin_inset LatexCommand \index{GameBoy Z80}
4231 \labelwidthstring 00.00.0000
4236 \begin_inset LatexCommand \index{-mavr}
4242 Generate code for the Atmel AVR
4243 \begin_inset LatexCommand \index{AVR}
4247 processor (In development, not complete).
4248 AVR users should probably have a look at avr-gcc
4249 \begin_inset LatexCommand \url[FIXME: official URL?]{ http://savannah.nongnu.org/download/avr-libc/snapshots/}
4256 I think it is fair to direct users there for now.
4257 Open source is also about avoiding unnecessary work .
4258 But I didn't find the 'official' link.
4260 \labelwidthstring 00.00.0000
4265 \begin_inset LatexCommand \index{-mpic14}
4271 Generate code for the PIC 14
4272 \begin_inset LatexCommand \index{PIC14}
4276 -bit processors (In development, not complete).
4279 p16f627 p16f628 p16f84 p16f873 p16f877?
4281 \labelwidthstring 00.00.0000
4287 Generate code for the Toshiba TLCS-900H
4288 \begin_inset LatexCommand \index{TLCS-900H}
4292 processor (In development, not complete).
4294 \labelwidthstring 00.00.0000
4299 \begin_inset LatexCommand \index{-mxa51}
4305 Generate code for the Philips XA51
4306 \begin_inset LatexCommand \index{XA51}
4310 processor (In development, not complete).
4311 \layout Subsubsection
4313 Preprocessor Options
4314 \begin_inset LatexCommand \index{Options preprocessor}
4319 \begin_inset LatexCommand \index{Preprocessor options}
4325 \labelwidthstring 00.00.0000
4330 \begin_inset LatexCommand \index{-I<path>}
4336 The additional location where the pre processor will look for <..h> or
4337 \begin_inset Quotes eld
4341 \begin_inset Quotes erd
4346 \labelwidthstring 00.00.0000
4351 \begin_inset LatexCommand \index{-D<macro[=value]>}
4357 Command line definition of macros.
4358 Passed to the pre processor.
4360 \labelwidthstring 00.00.0000
4365 \begin_inset LatexCommand \index{-M}
4371 Tell the preprocessor to output a rule suitable for make describing the
4372 dependencies of each object file.
4373 For each source file, the preprocessor outputs one make-rule whose target
4374 is the object file name for that source file and whose dependencies are
4375 all the files `#include'd in it.
4376 This rule may be a single line or may be continued with `
4378 '-newline if it is long.
4379 The list of rules is printed on standard output instead of the preprocessed
4383 \labelwidthstring 00.00.0000
4388 \begin_inset LatexCommand \index{-C}
4394 Tell the preprocessor not to discard comments.
4395 Used with the `-E' option.
4397 \labelwidthstring 00.00.0000
4402 \begin_inset LatexCommand \index{-MM}
4413 Like `-M' but the output mentions only the user header files included with
4415 \begin_inset Quotes eld
4419 System header files included with `#include <file>' are omitted.
4421 \labelwidthstring 00.00.0000
4426 \begin_inset LatexCommand \index{-Aquestion(answer)}
4432 Assert the answer answer for question, in case it is tested with a preprocessor
4433 conditional such as `#if #question(answer)'.
4434 `-A-' disables the standard assertions that normally describe the target
4437 \labelwidthstring 00.00.0000
4443 (answer) Assert the answer answer for question, in case it is tested with
4444 a preprocessor conditional such as `#if #question(answer)'.
4445 `-A-' disables the standard assertions that normally describe the target
4448 \labelwidthstring 00.00.0000
4453 \begin_inset LatexCommand \index{-Umacro}
4459 Undefine macro macro.
4460 `-U' options are evaluated after all `-D' options, but before any `-include'
4461 and `-imacros' options.
4463 \labelwidthstring 00.00.0000
4468 \begin_inset LatexCommand \index{-dM}
4474 Tell the preprocessor to output only a list of the macro definitions that
4475 are in effect at the end of preprocessing.
4476 Used with the `-E' option.
4478 \labelwidthstring 00.00.0000
4483 \begin_inset LatexCommand \index{-dD}
4489 Tell the preprocessor to pass all macro definitions into the output, in
4490 their proper sequence in the rest of the output.
4492 \labelwidthstring 00.00.0000
4497 \begin_inset LatexCommand \index{-dN}
4508 Like `-dD' except that the macro arguments and contents are omitted.
4509 Only `#define name' is included in the output.
4510 \layout Subsubsection
4513 \begin_inset LatexCommand \index{Options linker}
4518 \begin_inset LatexCommand \index{Linker options}
4524 \labelwidthstring 00.00.0000
4544 \begin_inset LatexCommand \index{-\/-lib-path}
4549 \begin_inset LatexCommand \index{-L -\/-lib-path}
4558 <absolute path to additional libraries> This option is passed to the linkage
4559 editor's additional libraries
4560 \begin_inset LatexCommand \index{Libraries}
4565 The path name must be absolute.
4566 Additional library files may be specified in the command line.
4567 See section Compiling programs for more details.
4569 \labelwidthstring 00.00.0000
4586 \begin_inset LatexCommand \index{-\/-xram-loc}
4590 <Value> The start location of the external ram
4591 \begin_inset LatexCommand \index{xdata}
4595 , default value is 0.
4596 The value entered can be in Hexadecimal or Decimal format, e.g.: -
4606 -xram-loc 0x8000 or -
4618 \labelwidthstring 00.00.0000
4635 \begin_inset LatexCommand \index{-\/-code-loc}
4639 <Value> The start location of the code
4640 \begin_inset LatexCommand \index{code}
4644 segment, default value 0.
4645 Note when this option is used the interrupt vector table is also relocated
4646 to the given address.
4647 The value entered can be in Hexadecimal or Decimal format, e.g.: -
4657 -code-loc 0x8000 or -
4669 \labelwidthstring 00.00.0000
4686 \begin_inset LatexCommand \index{-\/-stack-loc}
4690 <Value> By default the stack
4691 \begin_inset LatexCommand \index{stack}
4695 is placed after the data segment.
4696 Using this option the stack can be placed anywhere in the internal memory
4698 The value entered can be in Hexadecimal or Decimal format, e.g.
4709 -stack-loc 0x20 or -
4720 Since the sp register is incremented before a push or call, the initial
4721 sp will be set to one byte prior the provided value.
4722 The provided value should not overlap any other memory areas such as used
4723 register banks or the data segment and with enough space for the current
4726 \labelwidthstring 00.00.0000
4743 \begin_inset LatexCommand \index{-\/-data-loc}
4747 <Value> The start location of the internal ram data
4748 \begin_inset LatexCommand \index{data}
4753 The value entered can be in Hexadecimal or Decimal format, eg.
4775 (By default, the start location of the internal ram data segment is set
4776 as low as possible in memory, taking into account the used register banks
4777 and the bit segment at address 0x20.
4778 For example if register banks 0 and 1 are used without bit variables, the
4779 data segment will be set, if -
4789 -data-loc is not used, to location 0x10.)
4791 \labelwidthstring 00.00.0000
4808 \begin_inset LatexCommand \index{-\/-idata-loc}
4812 <Value> The start location of the indirectly addressable internal ram
4813 \begin_inset LatexCommand \index{idata}
4817 , default value is 0x80.
4818 The value entered can be in Hexadecimal or Decimal format, eg.
4829 -idata-loc 0x88 or -
4841 \labelwidthstring 00.00.0000
4856 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
4865 The linker output (final object code) is in Intel Hex format.
4866 \begin_inset LatexCommand \index{Intel hex format}
4870 (This is the default option).
4872 \labelwidthstring 00.00.0000
4887 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
4896 The linker output (final object code) is in Motorola S19 format
4897 \begin_inset LatexCommand \index{Motorola S19 format}
4902 \layout Subsubsection
4905 \begin_inset LatexCommand \index{Options MCS51}
4910 \begin_inset LatexCommand \index{MCS51 options}
4916 \labelwidthstring 00.00.0000
4931 \begin_inset LatexCommand \index{-\/-model-large}
4937 Generate code for Large model programs see section Memory Models for more
4939 If this option is used all source files in the project should be compiled
4941 In addition the standard library routines are compiled with small model,
4942 they will need to be recompiled.
4944 \labelwidthstring 00.00.0000
4959 \begin_inset LatexCommand \index{-\/-model-small}
4970 Generate code for Small Model programs see section Memory Models for more
4972 This is the default model.
4973 \layout Subsubsection
4976 \begin_inset LatexCommand \index{Options DS390}
4981 \begin_inset LatexCommand \index{DS390 options}
4987 \labelwidthstring 00.00.0000
5004 \begin_inset LatexCommand \index{-\/-model-flat24}
5014 Generate 24-bit flat mode code.
5015 This is the one and only that the ds390 code generator supports right now
5016 and is default when using
5021 See section Memory Models for more details.
5023 \labelwidthstring 00.00.0000
5040 \begin_inset LatexCommand \index{-\/-stack-10bit}
5044 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
5045 This is the one and only that the ds390 code generator supports right now
5046 and is default when using
5051 In this mode, the stack is located in the lower 1K of the internal RAM,
5052 which is mapped to 0x400000.
5053 Note that the support is incomplete, since it still uses a single byte
5054 as the stack pointer.
5055 This means that only the lower 256 bytes of the potential 1K stack space
5056 will actually be used.
5057 However, this does allow you to reclaim the precious 256 bytes of low RAM
5058 for use for the DATA and IDATA segments.
5059 The compiler will not generate any code to put the processor into 10 bit
5061 It is important to ensure that the processor is in this mode before calling
5062 any re-entrant functions compiled with this option.
5063 In principle, this should work with the
5076 \begin_inset LatexCommand \index{-\/-stack-auto}
5082 option, but that has not been tested.
5083 It is incompatible with the
5096 \begin_inset LatexCommand \index{-\/-xstack}
5103 It also only makes sense if the processor is in 24 bit contiguous addressing
5116 -model-flat24 option
5119 \layout Subsubsection
5121 Optimization Options
5122 \begin_inset LatexCommand \index{Options optimization}
5127 \begin_inset LatexCommand \index{Optimization options}
5133 \labelwidthstring 00.00.0000
5148 \begin_inset LatexCommand \index{-\/-nogcse}
5154 Will not do global subexpression elimination, this option may be used when
5155 the compiler creates undesirably large stack/data spaces to store compiler
5157 A warning message will be generated when this happens and the compiler
5158 will indicate the number of extra bytes it allocated.
5159 It recommended that this option NOT be used, #pragma\SpecialChar ~
5161 \begin_inset LatexCommand \index{\#pragma NOGCSE}
5165 can be used to turn off global subexpression elimination
5166 \begin_inset LatexCommand \index{Subexpression elimination}
5170 for a given function only.
5172 \labelwidthstring 00.00.0000
5187 \begin_inset LatexCommand \index{-\/-noinvariant}
5193 Will not do loop invariant optimizations, this may be turned off for reasons
5194 explained for the previous option.
5195 For more details of loop optimizations performed see section Loop Invariants.It
5196 recommended that this option NOT be used, #pragma\SpecialChar ~
5198 \begin_inset LatexCommand \index{\#pragma NOINVARIANT}
5202 can be used to turn off invariant optimizations for a given function only.
5204 \labelwidthstring 00.00.0000
5219 \begin_inset LatexCommand \index{-\/-noinduction}
5225 Will not do loop induction optimizations, see section strength reduction
5226 for more details.It is recommended that this option is NOT used, #pragma\SpecialChar ~
5229 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
5233 can be used to turn off induction optimizations for a given function only.
5235 \labelwidthstring 00.00.0000
5250 \begin_inset LatexCommand \index{-\/-nojtbound}
5261 Will not generate boundary condition check when switch statements
5262 \begin_inset LatexCommand \index{switch statement}
5266 are implemented using jump-tables.
5267 See section Switch Statements for more details.
5268 It is recommended that this option is NOT used, #pragma\SpecialChar ~
5270 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
5274 can be used to turn off boundary checking for jump tables for a given function
5277 \labelwidthstring 00.00.0000
5292 \begin_inset LatexCommand \index{-\/-noloopreverse}
5301 Will not do loop reversal
5302 \begin_inset LatexCommand \index{Loop reversing}
5308 \labelwidthstring 00.00.0000
5325 \begin_inset LatexCommand \index{-\/-nolabelopt }
5329 Will not optimize labels (makes the dumpfiles more readable).
5331 \labelwidthstring 00.00.0000
5346 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
5352 Will not memcpy initialized data in far space from code space.
5353 This saves a few bytes in code space if you don't have initialized data.
5354 \layout Subsubsection
5357 \begin_inset LatexCommand \index{Options other}
5363 \labelwidthstring 00.00.0000
5379 \begin_inset LatexCommand \index{-\/-compile-only}
5384 \begin_inset LatexCommand \index{-c -\/-compile-only}
5390 will compile and assemble the source, but will not call the linkage editor.
5392 \labelwidthstring 00.00.0000
5411 \begin_inset LatexCommand \index{-\/-c1mode}
5417 reads the preprocessed source from standard input and compiles it.
5418 The file name for the assembler output must be specified using the -o option.
5420 \labelwidthstring 00.00.0000
5425 \begin_inset LatexCommand \index{-E}
5431 Run only the C preprocessor.
5432 Preprocess all the C source files specified and output the results to standard
5435 \labelwidthstring 00.00.0000
5441 \begin_inset LatexCommand \index{-o <path/file>}
5447 The output path resp.
5448 file where everything will be placed.
5449 If the parameter is a path, it must have a trailing slash (or backslash
5450 for the Windows binaries) to be recognized as a path.
5453 \labelwidthstring 00.00.0000
5468 \begin_inset LatexCommand \index{-\/-stack-auto}
5479 All functions in the source file will be compiled as
5484 \begin_inset LatexCommand \index{reentrant}
5489 the parameters and local variables will be allocated on the stack
5490 \begin_inset LatexCommand \index{stack}
5495 see section Parameters and Local Variables for more details.
5496 If this option is used all source files in the project should be compiled
5500 \labelwidthstring 00.00.0000
5515 \begin_inset LatexCommand \index{-\/-xstack}
5521 Uses a pseudo stack in the first 256 bytes in the external ram for allocating
5522 variables and passing parameters.
5523 See section on external stack for more details.
5525 \labelwidthstring 00.00.0000
5540 \begin_inset LatexCommand \index{-\/-callee-saves}
5545 \begin_inset LatexCommand \index{function prologue}
5549 function1[,function2][,function3]....
5552 The compiler by default uses a caller saves convention for register saving
5553 across function calls, however this can cause unneccessary register pushing
5554 & popping when calling small functions from larger functions.
5555 This option can be used to switch the register saving convention for the
5556 function names specified.
5557 The compiler will not save registers when calling these functions, no extra
5558 code will be generated at the entry & exit for these functions to save
5559 & restore the registers used by these functions, this can SUBSTANTIALLY
5560 reduce code & improve run time performance of the generated code.
5561 In the future the compiler (with interprocedural analysis) will be able
5562 to determine the appropriate scheme to use for each function call.
5563 DO NOT use this option for built-in functions such as _mulint..., if this
5564 option is used for a library function the appropriate library function
5565 needs to be recompiled with the same option.
5566 If the project consists of multiple source files then all the source file
5567 should be compiled with the same -
5577 -callee-saves option string.
5578 Also see #pragma\SpecialChar ~
5580 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
5586 \labelwidthstring 00.00.0000
5601 \begin_inset LatexCommand \index{-\/-debug}
5610 When this option is used the compiler will generate debug information, that
5611 can be used with the SDCDB.
5612 The debug information is collected in a file with .cdb extension.
5613 For more information see documentation for SDCDB.
5615 \labelwidthstring 00.00.0000
5632 \begin_inset LatexCommand \index{-\/-peep-file}
5636 <filename> This option can be used to use additional rules to be used by
5637 the peep hole optimizer.
5638 See section Peep Hole optimizations for details on how to write these rules.
5640 \labelwidthstring 00.00.0000
5645 \begin_inset LatexCommand \index{-S}
5656 Stop after the stage of compilation proper; do not assemble.
5657 The output is an assembler code file for the input file specified.
5659 \labelwidthstring 00.00.0000
5663 -Wa_asmOption[,asmOption]
5666 \begin_inset LatexCommand \index{-Wa\_asmOption[,asmOption]}
5671 Pass the asmOption to the assembler.
5673 \labelwidthstring 00.00.0000
5677 -Wl_linkOption[,linkOption]
5680 \begin_inset LatexCommand \index{-Wl\_linkOption[,linkOption]}
5685 Pass the linkOption to the linker.
5687 \labelwidthstring 00.00.0000
5702 \begin_inset LatexCommand \index{-\/-int-long-reent}
5708 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
5709 Note by default these libraries are compiled as non-reentrant.
5710 See section Installation for more details.
5712 \labelwidthstring 00.00.0000
5727 \begin_inset LatexCommand \index{-\/-cyclomatic}
5736 This option will cause the compiler to generate an information message for
5737 each function in the source file.
5738 The message contains some
5742 information about the function.
5743 The number of edges and nodes the compiler detected in the control flow
5744 graph of the function, and most importantly the
5746 cyclomatic complexity
5747 \begin_inset LatexCommand \index{Cyclomatic complexity}
5753 see section on Cyclomatic Complexity for more details.
5755 \labelwidthstring 00.00.0000
5770 \begin_inset LatexCommand \index{-\/-float-reent}
5779 Floating point library is compiled as reentrant
5780 \begin_inset LatexCommand \index{reentrant}
5784 .See section Installation for more details.
5786 \labelwidthstring 00.00.0000
5801 \begin_inset LatexCommand \index{-\/-nooverlay}
5807 The compiler will not overlay parameters and local variables of any function,
5808 see section Parameters and local variables for more details.
5810 \labelwidthstring 00.00.0000
5825 \begin_inset LatexCommand \index{-\/-main-return}
5831 This option can be used when the code generated is called by a monitor
5833 The compiler will generate a 'ret' upon return from the 'main'
5834 \begin_inset LatexCommand \index{main return}
5839 The default option is to lock up i.e.
5842 \labelwidthstring 00.00.0000
5857 \begin_inset LatexCommand \index{-\/-no-peep}
5863 Disable peep-hole optimization.
5865 \labelwidthstring 00.00.0000
5880 \begin_inset LatexCommand \index{-\/-peep-asm}
5886 Pass the inline assembler code through the peep hole optimizer.
5887 This can cause unexpected changes to inline assembler code, please go through
5888 the peephole optimizer
5889 \begin_inset LatexCommand \index{Peephole optimizer}
5893 rules defined in the source file tree '<target>/peeph.def' before using
5896 \labelwidthstring 00.00.0000
5913 \begin_inset LatexCommand \index{-\/-iram-size<Value>}
5917 Causes the linker to check if the internal ram usage is within limits of
5920 \labelwidthstring 00.00.0000
5937 \begin_inset LatexCommand \index{-\/-xram-size<Value>}
5941 Causes the linker to check if the external ram usage is within limits of
5944 \labelwidthstring 00.00.0000
5961 \begin_inset LatexCommand \index{-\/-code-size<Value>}
5965 Causes the linker to check if the code usage is within limits of the given
5968 \labelwidthstring 00.00.0000
5983 \begin_inset LatexCommand \index{-\/-nostdincl}
5989 This will prevent the compiler from passing on the default include path
5990 to the preprocessor.
5992 \labelwidthstring 00.00.0000
6007 \begin_inset LatexCommand \index{-\/-nostdlib}
6013 This will prevent the compiler from passing on the default library
6014 \begin_inset LatexCommand \index{Libraries}
6020 \labelwidthstring 00.00.0000
6035 \begin_inset LatexCommand \index{-\/-verbose}
6041 Shows the various actions the compiler is performing.
6043 \labelwidthstring 00.00.0000
6048 \begin_inset LatexCommand \index{-V}
6054 Shows the actual commands the compiler is executing.
6056 \labelwidthstring 00.00.0000
6071 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
6077 Hides your ugly and inefficient c-code from the asm file, so you can always
6078 blame the compiler :).
6080 \labelwidthstring 00.00.0000
6095 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
6101 Include i-codes in the asm file.
6102 Sounds like noise but is most helpfull for debugging the compiler itself.
6104 \labelwidthstring 00.00.0000
6119 \begin_inset LatexCommand \index{-\/-less-pedantic}
6125 Disable some of the more pedantic warnings (jwk burps: please be more specific
6128 \labelwidthstring 00.00.0000
6143 \begin_inset LatexCommand \index{-\/-print-search-dirs}
6149 Display the directories in the compiler's search path
6150 \layout Subsubsection
6152 Intermediate Dump Options
6153 \begin_inset LatexCommand \index{Options intermediate dump}
6158 \begin_inset LatexCommand \index{Intermediate dump options}
6165 The following options are provided for the purpose of retargetting and debugging
6167 These provided a means to dump the intermediate code (iCode
6168 \begin_inset LatexCommand \index{iCode}
6172 ) generated by the compiler in human readable form at various stages of
6173 the compilation process.
6176 \labelwidthstring 00.00.0000
6191 \begin_inset LatexCommand \index{-\/-dumpraw}
6197 This option will cause the compiler to dump the intermediate code into
6200 <source filename>.dumpraw
6202 just after the intermediate code has been generated for a function, i.e.
6203 before any optimizations are done.
6205 \begin_inset LatexCommand \index{Basic blocks}
6209 at this stage ordered in the depth first number, so they may not be in
6210 sequence of execution.
6212 \labelwidthstring 00.00.0000
6227 \begin_inset LatexCommand \index{-\/-dumpgcse}
6233 Will create a dump of iCode's, after global subexpression elimination
6234 \begin_inset LatexCommand \index{Global subexpression elimination}
6240 <source filename>.dumpgcse.
6242 \labelwidthstring 00.00.0000
6257 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
6263 Will create a dump of iCode's, after deadcode elimination
6264 \begin_inset LatexCommand \index{Dead-code elimination}
6270 <source filename>.dumpdeadcode.
6272 \labelwidthstring 00.00.0000
6287 \begin_inset LatexCommand \index{-\/-dumploop}
6296 Will create a dump of iCode's, after loop optimizations
6297 \begin_inset LatexCommand \index{Loop optimization}
6303 <source filename>.dumploop.
6305 \labelwidthstring 00.00.0000
6320 \begin_inset LatexCommand \index{-\/-dumprange}
6329 Will create a dump of iCode's, after live range analysis
6330 \begin_inset LatexCommand \index{Live range analysis}
6336 <source filename>.dumprange.
6338 \labelwidthstring 00.00.0000
6353 \begin_inset LatexCommand \index{-\/-dumlrange}
6359 Will dump the life ranges
6360 \begin_inset LatexCommand \index{Live range analysis}
6366 \labelwidthstring 00.00.0000
6381 \begin_inset LatexCommand \index{-\/-dumpregassign}
6390 Will create a dump of iCode's, after register assignment
6391 \begin_inset LatexCommand \index{Register assignment}
6397 <source filename>.dumprassgn.
6399 \labelwidthstring 00.00.0000
6414 \begin_inset LatexCommand \index{-\/-dumplrange}
6420 Will create a dump of the live ranges of iTemp's
6422 \labelwidthstring 00.00.0000
6437 \begin_inset LatexCommand \index{-\/-dumpall}
6448 Will cause all the above mentioned dumps to be created.
6451 Environment variables
6452 \begin_inset LatexCommand \index{Environment variables}
6459 SDCC recognizes the following environment variables:
6461 \labelwidthstring 00.00.0000
6466 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
6472 SDCC installs a signal handler
6473 \begin_inset LatexCommand \index{signal handler}
6477 to be able to delete temporary files after an user break (^C) or an exception.
6478 If this environment variable is set, SDCC won't install the signal handler
6479 in order to be able to debug SDCC.
6481 \labelwidthstring 00.00.0000
6486 \begin_inset LatexCommand \index{TMP}
6492 \begin_inset LatexCommand \index{TEMP}
6498 \begin_inset LatexCommand \index{TMPDIR}
6504 Path, where temporary files will be created.
6505 The order of the variables is the search order.
6506 In a standard *nix environment these variables are not set, and there's
6507 no need to set them.
6508 On Windows it's recommended to set one of them.
6510 \labelwidthstring 00.00.0000
6515 \begin_inset LatexCommand \index{SDCC\_HOME}
6522 \begin_inset Quotes sld
6525 2.3 Install and search paths
6526 \begin_inset Quotes srd
6531 \labelwidthstring 00.00.0000
6536 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
6543 \begin_inset Quotes sld
6546 2.3 Install and search paths
6547 \begin_inset Quotes srd
6552 \labelwidthstring 00.00.0000
6557 \begin_inset LatexCommand \index{SDCC\_LIB}
6564 \begin_inset Quotes sld
6567 2.3 Install and search paths
6568 \begin_inset Quotes srd
6574 There are some more environment variables recognized by SDCC, but these
6575 are solely used for debugging purposes.
6576 They can change or disappear very quickly, and will never be documentated.
6579 MCS51/DS390 Storage Class
6580 \begin_inset LatexCommand \index{Storage class}
6587 In addition to the ANSI storage classes SDCC allows the following MCS51
6588 specific storage classes.
6589 \layout Subsubsection
6592 \begin_inset LatexCommand \index{xdata}
6599 Variables declared with this storage class will be placed in the extern
6605 storage class for Large Memory model, e.g.:
6611 xdata unsigned char xduc;
6612 \layout Subsubsection
6615 \begin_inset LatexCommand \index{data}
6626 storage class for Small Memory model.
6627 Variables declared with this storage class will be allocated in the internal
6635 \layout Subsubsection
6638 \begin_inset LatexCommand \index{idata}
6645 Variables declared with this storage class will be allocated into the indirectly
6646 addressable portion of the internal ram of a 8051, e.g.:
6653 \layout Subsubsection
6656 \begin_inset LatexCommand \index{bit}
6663 This is a data-type and a storage class specifier.
6664 When a variable is declared as a bit, it is allocated into the bit addressable
6665 memory of 8051, e.g.:
6672 \layout Subsubsection
6675 \begin_inset LatexCommand \index{sfr}
6680 \begin_inset LatexCommand \index{sbit}
6687 Like the bit keyword,
6691 signifies both a data-type and storage class, they are used to describe
6692 the special function registers and special bit variables of a 8051, eg:
6698 sfr at 0x80 P0; /* special function register P0 at location 0x80 */
6700 sbit at 0xd7 CY; /* CY (Carry Flag
6701 \begin_inset LatexCommand \index{Flags}
6706 \begin_inset LatexCommand \index{Carry flag}
6714 \begin_inset LatexCommand \index{Pointers}
6721 SDCC allows (via language extensions) pointers to explicitly point to any
6722 of the memory spaces
6723 \begin_inset LatexCommand \index{Memory model}
6728 In addition to the explicit pointers, the compiler uses (by default) generic
6729 pointers which can be used to point to any of the memory spaces.
6733 Pointer declaration examples:
6742 /* pointer physically in xternal ram pointing to object in internal ram
6745 data unsigned char * xdata p;
6749 /* pointer physically in code rom pointing to data in xdata space */
6751 xdata unsigned char * code p;
6755 /* pointer physically in code space pointing to data in code space */
6757 code unsigned char * code p;
6761 /* the folowing is a generic pointer physically located in xdata space */
6772 Well you get the idea.
6777 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
6790 The highest order byte of the
6794 pointers contains the data space information.
6795 Assembler support routines are called whenever data is stored or retrieved
6801 These are useful for developing reusable library
6802 \begin_inset LatexCommand \index{Libraries}
6807 Explicitly specifying the pointer type will generate the most efficient
6812 \begin_inset LatexCommand \index{Parameters}
6817 \begin_inset LatexCommand \index{Local variable}
6824 Automatic (local) variables and parameters to functions can either be placed
6825 on the stack or in data-space.
6826 The default action of the compiler is to place these variables in the internal
6827 RAM (for small model) or external RAM (for large model).
6828 This in fact makes them
6831 \begin_inset LatexCommand \index{static}
6837 so by default functions are non-reentrant
6838 \begin_inset LatexCommand \index{reentrant}
6846 They can be placed on the stack
6847 \begin_inset LatexCommand \index{stack}
6864 \begin_inset LatexCommand \index{-\/-stack-auto}
6870 option or by using the
6873 \begin_inset LatexCommand \index{reentrant}
6879 keyword in the function declaration, e.g.:
6888 unsigned char foo(char i) reentrant
6901 Since stack space on 8051 is limited, the
6919 option should be used sparingly.
6920 Note that the reentrant keyword just means that the parameters & local
6921 variables will be allocated to the stack, it
6925 mean that the function is register bank independent.
6929 Local variables can be assigned storage classes and absolute
6930 \begin_inset LatexCommand \index{Absolute addressing}
6940 unsigned char foo() {
6946 xdata unsigned char i;
6958 data at 0x31 unsiged char j;
6973 In the above example the variable
6977 will be allocated in the external ram,
6981 in bit addressable space and
7000 or when a function is declared as
7004 this should only be done for static variables.
7007 Parameters however are not allowed any storage class, (storage classes for
7008 parameters will be ignored), their allocation is governed by the memory
7009 model in use, and the reentrancy options.
7013 \begin_inset LatexCommand \index{Overlaying}
7021 \begin_inset LatexCommand \index{reentrant}
7025 functions SDCC will try to reduce internal ram space usage by overlaying
7026 parameters and local variables of a function (if possible).
7027 Parameters and local variables of a function will be allocated to an overlayabl
7028 e segment if the function has
7030 no other function calls and the function is non-reentrant and the memory
7032 \begin_inset LatexCommand \index{Memory model}
7039 If an explicit storage class
7040 \begin_inset LatexCommand \index{Storage class}
7044 is specified for a local variable, it will NOT be overlayed.
7047 Note that the compiler (not the linkage editor) makes the decision for overlayin
7049 Functions that are called from an interrupt service routine should be preceded
7050 by a #pragma\SpecialChar ~
7052 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
7056 if they are not reentrant.
7059 Also note that the compiler does not do any processing of inline
7060 \begin_inset LatexCommand \index{inline}
7064 assembler code, so the compiler might incorrectly assign local variables
7065 and parameters of a function into the overlay segment if the inline assembler
7066 code calls other c-functions that might use the overlay.
7067 In that case the #pragma\SpecialChar ~
7068 NOOVERLAY should be used.
7071 Parameters and Local variables of functions that contain 16 or 32 bit multiplica
7073 \begin_inset LatexCommand \index{Multiplication}
7078 \begin_inset LatexCommand \index{Division}
7082 will NOT be overlayed since these are implemented using external functions,
7092 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
7098 void set_error(unsigned char errcd)
7114 void some_isr () interrupt
7115 \begin_inset LatexCommand \index{interrupt}
7120 \begin_inset LatexCommand \index{using}
7153 In the above example the parameter
7161 would be assigned to the overlayable segment if the #pragma\SpecialChar ~
7163 not present, this could cause unpredictable runtime behavior when called
7165 The #pragma\SpecialChar ~
7166 NOOVERLAY ensures that the parameters and local variables for
7167 the function are NOT overlayed.
7170 Interrupt Service Routines
7173 SDCC allows interrupt service routines to be coded in C, with some extended
7180 void timer_isr (void) interrupt 2 using 1
7193 The number following the
7196 \begin_inset LatexCommand \index{interrupt}
7202 keyword is the interrupt number this routine will service.
7203 The compiler will insert a call to this routine in the interrupt vector
7204 table for the interrupt number specified.
7209 keyword is used to tell the compiler to use the specified register bank
7210 (8051 specific) when generating code for this function.
7211 Note that when some function is called from an interrupt service routine
7212 it should be preceded by a #pragma\SpecialChar ~
7214 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
7218 if it is not reentrant.
7219 A special note here, int (16 bit) and long (32 bit) integer division
7220 \begin_inset LatexCommand \index{Division}
7225 \begin_inset LatexCommand \index{Multiplication}
7230 \begin_inset LatexCommand \index{Modulus}
7234 operations are implemented using external support routines developed in
7235 ANSI-C, if an interrupt service routine needs to do any of these operations
7236 then the support routines (as mentioned in a following section) will have
7237 to be recompiled using the
7250 \begin_inset LatexCommand \index{-\/-stack-auto}
7256 option and the source file will need to be compiled using the
7271 \begin_inset LatexCommand \index{-\/-int-long-rent}
7278 If you have multiple source files in your project, interrupt service routines
7279 can be present in any of them, but a prototype of the isr MUST be present
7280 or included in the file that contains the function
7287 Interrupt Numbers and the corresponding address & descriptions for the Standard
7288 8051 are listed below.
7289 SDCC will automatically adjust the interrupt vector table to the maximum
7290 interrupt number specified.
7296 \begin_inset Tabular
7297 <lyxtabular version="3" rows="6" columns="3">
7299 <column alignment="block" valignment="top" leftline="true" width="0in">
7300 <column alignment="block" valignment="top" leftline="true" width="0in">
7301 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
7302 <row topline="true" bottomline="true">
7303 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7311 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7319 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7328 <row topline="true">
7329 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7337 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7354 <row topline="true">
7355 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7371 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7380 <row topline="true">
7381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7389 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7397 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7406 <row topline="true">
7407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7423 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7432 <row topline="true" bottomline="true">
7433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
7449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
7466 If the interrupt service routine is defined without
7469 \begin_inset LatexCommand \index{using}
7475 a register bank or with register bank 0 (using 0), the compiler will save
7476 the registers used by itself on the stack upon entry and restore them at
7477 exit, however if such an interrupt service routine calls another function
7478 then the entire register bank will be saved on the stack.
7479 This scheme may be advantageous for small interrupt service routines which
7480 have low register usage.
7483 If the interrupt service routine is defined to be using a specific register
7488 are save and restored, if such an interrupt service routine calls another
7489 function (using another register bank) then the entire register bank of
7490 the called function will be saved on the stack.
7491 This scheme is recommended for larger interrupt service routines.
7494 Calling other functions from an interrupt service routine is not recommended,
7495 avoid it if possible.
7499 Also see the _naked modifier.
7507 <TODO: this isn't implemented at all!>
7513 A special keyword may be associated with a function declaring it as
7518 SDCC will generate code to disable all interrupts upon entry to a critical
7519 function and enable them back before returning.
7520 Note that nesting critical functions may cause unpredictable results.
7545 The critical attribute maybe used with other attributes like
7551 \begin_inset LatexCommand \index{Naked functions}
7558 A special keyword may be associated with a function declaring it as
7561 \begin_inset LatexCommand \index{\_naked}
7572 function modifier attribute prevents the compiler from generating prologue
7573 \begin_inset LatexCommand \index{function prologue}
7578 \begin_inset LatexCommand \index{function epilogue}
7582 code for that function.
7583 This means that the user is entirely responsible for such things as saving
7584 any registers that may need to be preserved, selecting the proper register
7585 bank, generating the
7589 instruction at the end, etc.
7590 Practically, this means that the contents of the function must be written
7591 in inline assembler.
7592 This is particularly useful for interrupt functions, which can have a large
7593 (and often unnecessary) prologue/epilogue.
7594 For example, compare the code generated by these two functions:
7600 data unsigned char counter;
7602 void simpleInterrupt(void) interrupt
7603 \begin_inset LatexCommand \index{interrupt}
7621 void nakedInterrupt(void) interrupt 2 _naked
7630 \begin_inset LatexCommand \index{\_asm}
7659 ; MUST explicitly include ret in _naked function.
7666 \begin_inset LatexCommand \index{\_endasm}
7678 For an 8051 target, the generated simpleInterrupt looks like:
7823 whereas nakedInterrupt looks like:
7848 ; MUST explicitly include ret(i) in _naked function.
7854 While there is nothing preventing you from writing C code inside a _naked
7855 function, there are many ways to shoot yourself in the foot doing this,
7856 and it is recommended that you stick to inline assembler.
7859 Functions using private banks
7860 \begin_inset LatexCommand \index{bank}
7870 \begin_inset LatexCommand \index{using}
7876 attribute (which tells the compiler to use a register bank other than the
7877 default bank zero) should only be applied to
7880 \begin_inset LatexCommand \index{interrupt}
7886 functions (see note 1 below).
7887 This will in most circumstances make the generated ISR code more efficient
7888 since it will not have to save registers on the stack.
7895 attribute will have no effect on the generated code for a
7899 function (but may occasionally be useful anyway
7905 possible exception: if a function is called ONLY from 'interrupt' functions
7906 using a particular bank, it can be declared with the same 'using' attribute
7907 as the calling 'interrupt' functions.
7908 For instance, if you have several ISRs using bank one, and all of them
7909 call memcpy(), it might make sense to create a specialized version of memcpy()
7910 'using 1', since this would prevent the ISR from having to save bank zero
7911 to the stack on entry and switch to bank zero before calling the function
7918 (pending: I don't think this has been done yet)
7925 function using a non-zero bank will assume that it can trash that register
7926 bank, and will not save it.
7927 Since high-priority interrupts
7928 \begin_inset LatexCommand \index{interrupt priority}
7932 can interrupt low-priority ones on the 8051 and friends, this means that
7933 if a high-priority ISR
7937 a particular bank occurs while processing a low-priority ISR
7941 the same bank, terrible and bad things can happen.
7942 To prevent this, no single register bank should be
7946 by both a high priority and a low priority ISR.
7947 This is probably most easily done by having all high priority ISRs use
7948 one bank and all low priority ISRs use another.
7949 If you have an ISR which can change priority at runtime, you're on your
7950 own: I suggest using the default bank zero and taking the small performance
7954 It is most efficient if your ISR calls no other functions.
7955 If your ISR must call other functions, it is most efficient if those functions
7956 use the same bank as the ISR (see note 1 below); the next best is if the
7957 called functions use bank zero.
7958 It is very inefficient to call a function using a different, non-zero bank
7964 \begin_inset LatexCommand \index{Absolute addressing}
7971 Data items can be assigned an absolute address with the
7974 \begin_inset LatexCommand \index{at}
7980 keyword, in addition to a storage class, e.g.:
7986 \begin_inset LatexCommand \index{xdata}
7991 \begin_inset LatexCommand \index{at}
7995 0x8000 unsigned char PORTA_8255 ;
7998 In the above example the PORTA_8255 will be allocated to the location 0x8000
7999 of the external ram.
8000 Note that this feature is provided to give the programmer access to
8004 devices attached to the controller.
8005 The compiler does not actually reserve any space for variables declared
8006 in this way (they are implemented with an equate in the assembler).
8007 Thus it is left to the programmer to make sure there are no overlaps with
8008 other variables that are declared without the absolute address.
8009 The assembler listing file (.lst
8010 \begin_inset LatexCommand \index{.lst}
8014 ) and the linker output files (.rst
8015 \begin_inset LatexCommand \index{.rst}
8020 \begin_inset LatexCommand \index{.map}
8024 ) are a good places to look for such overlaps.
8028 Absolute address can be specified for variables in all storage classes,
8035 \begin_inset LatexCommand \index{bit}
8040 \begin_inset LatexCommand \index{at}
8047 The above example will allocate the variable at offset 0x02 in the bit-addressab
8049 There is no real advantage to assigning absolute addresses to variables
8050 in this manner, unless you want strict control over all the variables allocated.
8051 One possible use would be to write hardware portable code.
8052 For example, if you have a routine that uses one or more of the microcontroller
8053 I/O pins, and such pins are different for two different hardwares, you
8054 can declare the I/O pins in you routine using
8067 void DS1306_put(unsigned char value)
8075 unsigned char mask=0x80;
8099 SDI=(value & mask)?1:0;
8140 Then, someplace in the code for the first hardware you would use
8145 bit at 0x80 SDI;\SpecialChar ~
8149 /*I/O port 0, bit 0*/
8151 bit at 0x81 SCLK;\SpecialChar ~
8154 /*I/O port 0, bit 1*/
8156 bit CPOL;\SpecialChar ~
8167 /*This is a variable, let the linker allocate this one*/
8170 Similarly, for the second hardware you would use
8175 bit at 0x83 SDI;\SpecialChar ~
8179 /*I/O port 0, bit 3*/
8181 bit at 0x91 SCLK;\SpecialChar ~
8184 /*I/O port 1, bit 1*/
8186 bit CPOL;\SpecialChar ~
8197 /*This is a variable, let the linker allocate this one*/
8200 and you can use the same hardware dependant routine without changes, as
8201 for example in a library.
8202 This is somehow similar to sbit, but only one absolute address has to be
8203 specified in the whole project.
8207 \begin_inset LatexCommand \index{Startup code}
8214 The compiler inserts a call to the C routine
8216 _sdcc_external_startup()
8217 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
8226 at the start of the CODE area.
8227 This routine is in the runtime library
8228 \begin_inset LatexCommand \index{Runtime library}
8233 By default this routine returns 0, if this routine returns a non-zero value,
8234 the static & global variable initialization will be skipped and the function
8235 main will be invoked Other wise static & global variables will be initialized
8236 before the function main is invoked.
8239 _sdcc_external_startup()
8241 routine to your program to override the default if you need to setup hardware
8242 or perform some other critical operation prior to static & global variable
8246 Inline Assembler Code
8247 \begin_inset LatexCommand \index{Assembler routines}
8254 SDCC allows the use of in-line assembler with a few restriction as regards
8256 All labels defined within inline assembler code
8264 where nnnn is a number less than 100 (which implies a limit of utmost 100
8265 inline assembler labels
8273 It is strongly recommended that each assembly instruction (including labels)
8274 be placed in a separate line (as the example shows).
8288 \begin_inset LatexCommand \index{-\/-peep-asm}
8294 command line option is used, the inline assembler code will be passed through
8295 the peephole optimizer
8296 \begin_inset LatexCommand \index{Peephole optimizer}
8301 This might cause some unexpected changes in the inline assembler code.
8302 Please go throught the peephole optimizer rules defined in file
8306 carefully before using this option.
8313 \begin_inset LatexCommand \index{\_asm}
8343 \begin_inset LatexCommand \index{\_endasm}
8356 The inline assembler code can contain any valid code understood by the assembler
8357 , this includes any assembler directives and comment lines.
8358 The compiler does not do any validation of the code within the
8368 Inline assembler code cannot reference any C-Labels, however it can reference
8370 \begin_inset LatexCommand \index{Labels}
8374 defined by the inline assembler, e.g.:
8400 ; some assembler code
8420 /* some more c code */
8422 clabel:\SpecialChar ~
8424 /* inline assembler cannot reference this label */
8436 $0003: ;label (can be reference by inline assembler only)
8448 /* some more c code */
8456 In other words inline assembly code can access labels defined in inline
8457 assembly within the scope of the funtion.
8458 The same goes the other way, ie.
8459 labels defines in inline assembly CANNOT be accessed by C statements.
8463 \begin_inset LatexCommand \index{int (16 bit)}
8468 \begin_inset LatexCommand \index{long (32 bit)}
8475 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
8476 multiplication and modulus operations are implemented by support routines.
8477 These support routines are all developed in ANSI-C to facilitate porting
8478 to other MCUs, although some model specific assembler optimations are used.
8479 The following files contain the described routine, all of them can be found
8480 in <installdir>/share/sdcc/lib.
8485 \begin_inset Tabular
8486 <lyxtabular version="3" rows="11" columns="2">
8488 <column alignment="center" valignment="top" leftline="true" width="0(null)">
8489 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
8490 <row topline="true" bottomline="true">
8491 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8501 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8512 <row topline="true">
8513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8521 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8526 16 bit multiplication
8530 <row topline="true">
8531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8539 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8544 signed 16 bit division (calls _divuint)
8548 <row topline="true">
8549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8557 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8562 unsigned 16 bit division
8566 <row topline="true">
8567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8575 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8580 signed 16 bit modulus (calls _moduint)
8584 <row topline="true">
8585 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8593 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8598 unsigned 16 bit modulus
8602 <row topline="true">
8603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8611 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8616 32 bit multiplication
8620 <row topline="true">
8621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8634 signed 32 division (calls _divulong)
8638 <row topline="true">
8639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8647 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8652 unsigned 32 division
8656 <row topline="true">
8657 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8665 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8670 signed 32 bit modulus (calls _modulong)
8674 <row topline="true" bottomline="true">
8675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8683 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8688 unsigned 32 bit modulus
8704 Since they are compiled as
8709 \begin_inset LatexCommand \index{reentrant}
8714 \begin_inset LatexCommand \index{interrupt}
8718 service routines should not do any of the above operations.
8719 If this is unavoidable then the above routines will need to be compiled
8733 \begin_inset LatexCommand \index{-\/-stack-auto}
8739 option, after which the source program will have to be compiled with
8752 \begin_inset LatexCommand \index{-\/-int-long-rent}
8759 Notice that you don't have to call this routines directly.
8760 The compiler will use them automatically every time a integer operation
8764 Floating Point Support
8765 \begin_inset LatexCommand \index{Floating point support}
8772 SDCC supports IEEE (single precision 4bytes) floating point numbers.The floating
8773 point support routines are derived from gcc's floatlib.c and consists of
8774 the following routines:
8781 \begin_inset Tabular
8782 <lyxtabular version="3" rows="17" columns="2">
8784 <column alignment="center" valignment="top" leftline="true" width="0(null)">
8785 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
8786 <row topline="true" bottomline="true">
8787 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8804 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8813 <row topline="true">
8814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8831 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8845 add floating point numbers
8849 <row topline="true">
8850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8867 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8881 subtract floating point numbers
8885 <row topline="true">
8886 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8903 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8917 divide floating point numbers
8921 <row topline="true">
8922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8953 multiply floating point numbers
8957 <row topline="true">
8958 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8975 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8989 convert floating point to unsigned char
8993 <row topline="true">
8994 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9011 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9025 convert floating point to signed char
9029 <row topline="true">
9030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9047 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9061 convert floating point to unsigned int
9065 <row topline="true">
9066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9083 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9097 convert floating point to signed int
9101 <row topline="true">
9102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9142 convert floating point to unsigned long
9146 <row topline="true">
9147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9178 convert floating point to signed long
9182 <row topline="true">
9183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9214 convert unsigned char to floating point
9218 <row topline="true">
9219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9236 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9250 convert char to floating point number
9254 <row topline="true">
9255 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9272 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9286 convert unsigned int to floating point
9290 <row topline="true">
9291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9322 convert int to floating point numbers
9326 <row topline="true">
9327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9344 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9358 convert unsigned long to floating point number
9362 <row topline="true" bottomline="true">
9363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9394 convert long to floating point number
9408 Note if all these routines are used simultaneously the data space might
9410 For serious floating point usage it is strongly recommended that the large
9412 Also notice that you don't have to call this routines directly.
9413 The compiler will use them automatically every time a floating point operation
9418 \begin_inset LatexCommand \index{Memory model}
9423 \begin_inset LatexCommand \index{MCS51 memory}
9430 SDCC allows two memory models for MCS51 code, small and large.
9431 Modules compiled with different memory models should
9435 be combined together or the results would be unpredictable.
9436 The library routines supplied with the compiler are compiled as both small
9438 The compiled library modules are contained in seperate directories as small
9439 and large so that you can link to either set.
9443 When the large model is used all variables declared without a storage class
9444 will be allocated into the external ram, this includes all parameters and
9445 local variables (for non-reentrant
9446 \begin_inset LatexCommand \index{reentrant}
9451 When the small model is used variables without storage class are allocated
9452 in the internal ram.
9455 Judicious usage of the processor specific storage classes
9456 \begin_inset LatexCommand \index{Storage class}
9460 and the 'reentrant' function type will yield much more efficient code,
9461 than using the large model.
9462 Several optimizations are disabled when the program is compiled using the
9463 large model, it is therefore strongly recommdended that the small model
9464 be used unless absolutely required.
9468 \begin_inset LatexCommand \index{Memory model}
9473 \begin_inset LatexCommand \index{DS390 memory model}
9480 The only model supported is Flat 24
9481 \begin_inset LatexCommand \index{Flat 24 (memory model)}
9486 This generates code for the 24 bit contiguous addressing mode of the Dallas
9488 In this mode, up to four meg of external RAM or code space can be directly
9490 See the data sheets at www.dalsemi.com for further information on this part.
9494 In older versions of the compiler, this option was used with the MCS51 code
9500 Now, however, the '390 has it's own code generator, selected by the
9509 Note that the compiler does not generate any code to place the processor
9510 into 24 bitmode (although
9514 in the ds390 libraries will do that for you).
9520 \begin_inset LatexCommand \index{Tinibios (DS390)}
9524 , the boot loader or similar code must ensure that the processor is in 24
9525 bit contiguous addressing mode before calling the SDCC startup code.
9543 option, variables will by default be placed into the XDATA segment.
9548 Segments may be placed anywhere in the 4 meg address space using the usual
9560 Note that if any segments are located above 64K, the -r flag must be passed
9561 to the linker to generate the proper segment relocations, and the Intel
9562 HEX output format must be used.
9563 The -r flag can be passed to the linker by using the option
9567 on the sdcc command line.
9568 However, currently the linker can not handle code segments > 64k.
9571 Defines Created by the Compiler
9572 \begin_inset LatexCommand \index{Defines created by the compiler}
9579 The compiler creates the following #defines
9580 \begin_inset LatexCommand \index{\#defines}
9588 \begin_inset LatexCommand \index{SDCC}
9592 - this Symbol is always defined.
9596 \begin_inset LatexCommand \index{SDCC\_mcs51}
9601 \begin_inset LatexCommand \index{SDCC\_ds390}
9606 \begin_inset LatexCommand \index{SDCC\_z80}
9610 , etc - depending on the model used (e.g.: -mds390)
9614 \begin_inset LatexCommand \index{\_\_mcs51}
9619 \begin_inset LatexCommand \index{\_\_ds390}
9624 \begin_inset LatexCommand \index{\_\_z80}
9628 , etc - depending on the model used (e.g.
9633 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
9637 - this symbol is defined when
9655 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
9677 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
9699 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
9721 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
9733 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
9748 \begin_inset LatexCommand \index{Optimizations}
9755 SDCC performs a host of standard optimizations in addition to some MCU specific
9758 \layout Subsubsection
9760 Sub-expression Elimination
9761 \begin_inset LatexCommand \index{Subexpression elimination}
9768 The compiler does local and global common subexpression elimination, e.g.:
9783 will be translated to
9799 Some subexpressions are not as obvious as the above example, e.g.:
9813 In this case the address arithmetic a->b[i] will be computed only once;
9814 the equivalent code in C would be.
9830 The compiler will try to keep these temporary variables in registers.
9831 \layout Subsubsection
9833 Dead-Code Elimination
9834 \begin_inset LatexCommand \index{Dead-code elimination}
9853 i = 1; \SpecialChar ~
9858 global = 1;\SpecialChar ~
9871 global = 3;\SpecialChar ~
9886 int global; void f ()
9899 \layout Subsubsection
9902 \begin_inset LatexCommand \index{Copy propagation}
9965 Note: the dead stores created by this copy propagation will be eliminated
9966 by dead-code elimination.
9967 \layout Subsubsection
9970 \begin_inset LatexCommand \index{Loop optimization}
9977 Two types of loop optimizations are done by SDCC loop invariant lifting
9978 and strength reduction of loop induction variables.
9979 In addition to the strength reduction the optimizer marks the induction
9980 variables and the register allocator tries to keep the induction variables
9981 in registers for the duration of the loop.
9982 Because of this preference of the register allocator
9983 \begin_inset LatexCommand \index{Register allocation}
9987 , loop induction optimization causes an increase in register pressure, which
9988 may cause unwanted spilling of other temporary variables into the stack
9989 \begin_inset LatexCommand \index{stack}
9994 The compiler will generate a warning message when it is forced to allocate
9995 extra space either on the stack or data space.
9996 If this extra space allocation is undesirable then induction optimization
9997 can be eliminated either for the entire source file (with -
10007 -noinduction option) or for a given function only using #pragma\SpecialChar ~
10009 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
10023 for (i = 0 ; i < 100 ; i ++)
10041 for (i = 0; i < 100; i++)
10051 As mentioned previously some loop invariants are not as apparent, all static
10052 address computations are also moved out of the loop.
10057 \begin_inset LatexCommand \index{Strength reduction}
10061 , this optimization substitutes an expression by a cheaper expression:
10067 for (i=0;i < 100; i++)
10087 for (i=0;i< 100;i++) {
10091 ar[itemp1] = itemp2;
10107 The more expensive multiplication
10108 \begin_inset LatexCommand \index{Multiplication}
10112 is changed to a less expensive addition.
10113 \layout Subsubsection
10116 \begin_inset LatexCommand \index{Loop reversing}
10123 This optimization is done to reduce the overhead of checking loop boundaries
10124 for every iteration.
10125 Some simple loops can be reversed and implemented using a
10126 \begin_inset Quotes eld
10129 decrement and jump if not zero
10130 \begin_inset Quotes erd
10134 SDCC checks for the following criterion to determine if a loop is reversible
10135 (note: more sophisticated compilers use data-dependency analysis to make
10136 this determination, SDCC uses a more simple minded analysis).
10139 The 'for' loop is of the form
10145 for (<symbol> = <expression> ; <sym> [< | <=] <expression> ; [<sym>++ |
10155 The <for body> does not contain
10156 \begin_inset Quotes eld
10160 \begin_inset Quotes erd
10164 \begin_inset Quotes erd
10170 All goto's are contained within the loop.
10173 No function calls within the loop.
10176 The loop control variable <sym> is not assigned any value within the loop
10179 The loop control variable does NOT participate in any arithmetic operation
10183 There are NO switch statements in the loop.
10184 \layout Subsubsection
10186 Algebraic Simplifications
10189 SDCC does numerous algebraic simplifications, the following is a small sub-set
10190 of these optimizations.
10196 i = j + 0 ; /* changed to */ i = j;
10198 i /= 2; /* changed to */ i >>= 1;
10200 i = j - j ; /* changed to */ i = 0;
10202 i = j / 1 ; /* changed to */ i = j;
10208 Note the subexpressions
10209 \begin_inset LatexCommand \index{Subexpression}
10213 given above are generally introduced by macro expansions or as a result
10214 of copy/constant propagation.
10215 \layout Subsubsection
10217 'switch' Statements
10218 \begin_inset LatexCommand \index{switch statement}
10225 SDCC changes switch statements to jump tables
10226 \begin_inset LatexCommand \index{jump tables}
10230 when the following conditions are true.
10234 The case labels are in numerical sequence, the labels need not be in order,
10235 and the starting number need not be one or zero.
10241 switch(i) {\SpecialChar ~
10348 Both the above switch statements will be implemented using a jump-table.
10351 The number of case labels is at least three, since it takes two conditional
10352 statements to handle the boundary conditions.
10355 The number of case labels is less than 84, since each label takes 3 bytes
10356 and a jump-table can be utmost 256 bytes long.
10360 Switch statements which have gaps in the numeric sequence or those that
10361 have more that 84 case labels can be split into more than one switch statement
10362 for efficient code generation, e.g.:
10400 If the above switch statement is broken down into two switch statements
10434 case 9: \SpecialChar ~
10444 case 12:\SpecialChar ~
10454 then both the switch statements will be implemented using jump-tables whereas
10455 the unmodified switch statement will not be.
10456 \layout Subsubsection
10458 Bit-shifting Operations
10459 \begin_inset LatexCommand \index{Bit shifting}
10466 Bit shifting is one of the most frequently used operation in embedded programmin
10468 SDCC tries to implement bit-shift operations in the most efficient way
10488 generates the following code:
10506 In general SDCC will never setup a loop if the shift count is known.
10546 Note that SDCC stores numbers in little-endian format (i.e.
10547 lowest order first).
10548 \layout Subsubsection
10551 \begin_inset LatexCommand \index{Bit rotation}
10558 A special case of the bit-shift operation is bit rotation, SDCC recognizes
10559 the following expression to be a left bit-rotation:
10570 i = ((i << 1) | (i >> 7));
10578 will generate the following code:
10594 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
10595 ns of this case will also be recognized as bit-rotation, i.e.:
10601 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
10602 \layout Subsubsection
10605 \begin_inset LatexCommand \index{Highest Order Bit}
10612 It is frequently required to obtain the highest order bit of an integral
10613 type (long, int, short or char types).
10614 SDCC recognizes the following expression to yield the highest order bit
10615 and generates optimized code for it, e.g.:
10636 hob = (gint >> 15) & 1;
10649 will generate the following code:
10688 000A E5*01\SpecialChar ~
10716 000C 33\SpecialChar ~
10747 000D E4\SpecialChar ~
10778 000E 13\SpecialChar ~
10809 000F F5*02\SpecialChar ~
10839 Variations of this case however will
10844 It is a standard C expression, so I heartily recommend this be the only
10845 way to get the highest order bit, (it is portable).
10846 Of course it will be recognized even if it is embedded in other expressions,
10853 xyz = gint + ((gint >> 15) & 1);
10859 will still be recognized.
10860 \layout Subsubsection
10863 \begin_inset LatexCommand \index{Peephole optimizer}
10870 The compiler uses a rule based, pattern matching and re-writing mechanism
10871 for peep-hole optimization.
10876 a peep-hole optimizer by Christopher W.
10877 Fraser (cwfraser@microsoft.com).
10878 A default set of rules are compiled into the compiler, additional rules
10879 may be added with the
10892 \begin_inset LatexCommand \index{-\/-peep-file}
10899 The rule language is best illustrated with examples.
10927 The above rule will change the following assembly
10928 \begin_inset LatexCommand \index{Assembler routines}
10962 Note: All occurrences of a
10966 (pattern variable) must denote the same string.
10967 With the above rule, the assembly sequence:
10985 will remain unmodified.
10989 Other special case optimizations may be added by the user (via
11005 some variants of the 8051 MCU allow only
11014 The following two rules will change all
11036 replace { lcall %1 } by { acall %1 }
11038 replace { ljmp %1 } by { ajmp %1 }
11046 inline-assembler code
11048 is also passed through the peep hole optimizer, thus the peephole optimizer
11049 can also be used as an assembly level macro expander.
11050 The rules themselves are MCU dependent whereas the rule language infra-structur
11051 e is MCU independent.
11052 Peephole optimization rules for other MCU can be easily programmed using
11057 The syntax for a rule is as follows:
11063 rule := replace [ restart ] '{' <assembly sequence> '
11101 <assembly sequence> '
11119 '}' [if <functionName> ] '
11127 <assembly sequence> := assembly instruction (each instruction including
11128 labels must be on a separate line).
11132 The optimizer will apply to the rules one by one from the top in the sequence
11133 of their appearance, it will terminate when all rules are exhausted.
11134 If the 'restart' option is specified, then the optimizer will start matching
11135 the rules again from the top, this option for a rule is expensive (performance)
11136 , it is intended to be used in situations where a transformation will trigger
11137 the same rule again.
11138 An example of this (not a good one, it has side effects) is the following
11165 Note that the replace pattern cannot be a blank, but can be a comment line.
11166 Without the 'restart' option only the inner most 'pop' 'push' pair would
11167 be eliminated, i.e.:
11219 the restart option the rule will be applied again to the resulting code
11220 and then all the pop-push pairs will be eliminated to yield:
11238 A conditional function can be attached to a rule.
11239 Attaching rules are somewhat more involved, let me illustrate this with
11270 The optimizer does a look-up of a function name table defined in function
11275 in the source file SDCCpeeph.c, with the name
11280 If it finds a corresponding entry the function is called.
11281 Note there can be no parameters specified for these functions, in this
11286 is crucial, since the function
11290 expects to find the label in that particular variable (the hash table containin
11291 g the variable bindings is passed as a parameter).
11292 If you want to code more such functions, take a close look at the function
11293 labelInRange and the calling mechanism in source file SDCCpeeph.c.
11294 I know this whole thing is a little kludgey, but maybe some day we will
11295 have some better means.
11296 If you are looking at this file, you will also see the default rules that
11297 are compiled into the compiler, you can add your own rules in the default
11298 set there if you get tired of specifying the -
11312 \begin_inset LatexCommand \index{Pragmas}
11319 SDCC supports the following #pragma directives.
11323 \begin_inset LatexCommand \index{\#pragma SAVE}
11327 - this will save all current options to the SAVE/RESTORE stack.
11332 \begin_inset LatexCommand \index{\#pragma RESTORE}
11336 - will restore saved options from the last save.
11337 SAVEs & RESTOREs can be nested.
11338 SDCC uses a SAVE/RESTORE stack: SAVE pushes current options to the stack,
11339 RESTORE pulls current options from the stack.
11344 \begin_inset LatexCommand \index{\#pragma NOGCSE}
11348 - will stop global subexpression elimination.
11352 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
11356 - will stop loop induction optimizations.
11360 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
11364 - will not generate code for boundary value checking, when switch statements
11365 are turned into jump-tables.
11369 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
11373 - the compiler will not overlay the parameters and local variables of a
11378 \begin_inset LatexCommand \index{\#pragma LESS\_PEDANTIC}
11382 - the compiler will not warn you anymore for obvious mistakes, you'r on
11387 \begin_inset LatexCommand \index{\#pragma NOLOOPREVERSE}
11391 - Will not do loop reversal optimization
11395 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
11399 NONE | {acc[,b[,dpl[,dph]]] - The exclude pragma disables generation of
11401 \begin_inset LatexCommand \index{push/pop}
11405 instruction in ISR function (using interrupt
11406 \begin_inset LatexCommand \index{interrupt}
11411 The directive should be placed immediately before the ISR function definition
11412 and it affects ALL ISR functions following it.
11413 To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
11414 EXCLUDE\SpecialChar ~
11416 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
11424 \begin_inset LatexCommand \index{\#pragma NOIV}
11428 - Do not generate interrupt vector table entries for all ISR functions
11429 defined after the pragma.
11430 This is useful in cases where the interrupt vector table must be defined
11431 manually, or when there is a secondary, manually defined interrupt vector
11433 for the autovector feature of the Cypress EZ-USB FX2).
11437 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
11442 \begin_inset LatexCommand \index{function prologue}
11446 function1[,function2[,function3...]] - The compiler by default uses a caller
11447 saves convention for register saving across function calls, however this
11448 can cause unneccessary register pushing & popping when calling small functions
11449 from larger functions.
11450 This option can be used to switch off the register saving convention for
11451 the function names specified.
11452 The compiler will not save registers when calling these functions, extra
11453 code need to be manually inserted at the entry & exit for these functions
11454 to save & restore the registers used by these functions, this can SUBSTANTIALLY
11455 reduce code & improve run time performance of the generated code.
11456 In the future the compiler (with interprocedural analysis) may be able
11457 to determine the appropriate scheme to use for each function call.
11468 -callee-saves command line option is used, the function names specified
11469 in #pragma\SpecialChar ~
11471 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
11475 is appended to the list of functions specified in the command line.
11478 The pragma's are intended to be used to turn-off certain optimizations which
11479 might cause the compiler to generate extra stack / data space to store
11480 compiler generated temporary variables.
11481 This usually happens in large functions.
11482 Pragma directives should be used as shown in the following example, they
11483 are used to control options & optimizations for a given function; pragmas
11484 should be placed before and/or after a function, placing pragma's inside
11485 a function body could have unpredictable results.
11492 \begin_inset LatexCommand \index{\#pragma SAVE}
11496 /* save the current settings */
11499 \begin_inset LatexCommand \index{\#pragma NOGCSE}
11503 /* turnoff global subexpression elimination */
11505 #pragma NOINDUCTION
11506 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
11510 /* turn off induction optimizations */
11533 \begin_inset LatexCommand \index{\#pragma RESTORE}
11537 /* turn the optimizations back on */
11543 The compiler will generate a warning message when extra space is allocated.
11544 It is strongly recommended that the SAVE and RESTORE pragma's be used when
11545 changing options for a function.
11550 <pending: this is messy and incomplete>
11555 Compiler support routines (_gptrget, _mulint etc)
11558 Stdclib functions (puts, printf, strcat etc)
11561 Math functions (sin, pow, sqrt etc)
11564 license statements for the libraries are missing
11567 Interfacing with Assembly Routines
11568 \begin_inset LatexCommand \index{Assembler routines}
11573 \layout Subsubsection
11575 Global Registers used for Parameter Passing
11576 \begin_inset LatexCommand \index{Parameter passing}
11583 The compiler always uses the global registers
11586 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
11591 \begin_inset LatexCommand \index{B (register)}
11600 \begin_inset LatexCommand \index{ACC}
11606 to pass the first parameter to a routine.
11607 The second parameter onwards is either allocated on the stack (for reentrant
11618 -stack-auto is used) or in the internal / external ram (depending on the
11621 \layout Subsubsection
11623 Assembler Routine(non-reentrant
11624 \begin_inset LatexCommand \index{reentrant}
11629 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
11636 In the following example the function cfunc calls an assembler routine asm_func,
11637 which takes two parameters.
11643 extern int asm_func(unsigned char, unsigned char);
11647 int c_func (unsigned char i, unsigned char j)
11655 return asm_func(i,j);
11669 return c_func(10,9);
11677 The corresponding assembler function is:
11683 .globl _asm_func_PARM_2
11747 add a,_asm_func_PARM_2
11768 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
11788 Note here that the return values are placed in 'dpl' - One byte return value,
11789 'dpl' LSB & 'dph' MSB for two byte values.
11790 'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
11791 b' & 'acc' for four byte values.
11794 The parameter naming convention is _<function_name>_PARM_<n>, where n is
11795 the parameter number starting from 1, and counting from the left.
11796 The first parameter is passed in
11797 \begin_inset Quotes eld
11801 \begin_inset Quotes erd
11804 for One bye parameter,
11805 \begin_inset Quotes eld
11809 \begin_inset Quotes erd
11813 \begin_inset Quotes eld
11817 \begin_inset Quotes erd
11820 for three bytes and
11821 \begin_inset Quotes eld
11825 \begin_inset Quotes erd
11828 for four bytes, the varible name for the second parameter will be _<function_na
11833 Assemble the assembler routine with the following command:
11840 asx8051 -losg asmfunc.asm
11847 Then compile and link the assembler routine to the C source file with the
11855 sdcc cfunc.c asmfunc.rel
11856 \layout Subsubsection
11858 Assembler Routine(reentrant
11859 \begin_inset LatexCommand \index{reentrant}
11864 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
11871 In this case the second parameter onwards will be passed on the stack, the
11872 parameters are pushed from right to left i.e.
11873 after the call the left most parameter will be on the top of the stack.
11874 Here is an example:
11880 extern int asm_func(unsigned char, unsigned char);
11884 int c_func (unsigned char i, unsigned char j) reentrant
11892 return asm_func(i,j);
11906 return c_func(10,9);
11914 The corresponding assembler routine is:
12024 The compiling and linking procedure remains the same, however note the extra
12025 entry & exit linkage required for the assembler code, _bp is the stack
12026 frame pointer and is used to compute the offset into the stack for parameters
12027 and local variables.
12031 \begin_inset LatexCommand \index{stack}
12036 \begin_inset LatexCommand \index{External stack}
12043 The external stack is located at the start of the external ram segment,
12044 and is 256 bytes in size.
12055 -xstack option is used to compile the program, the parameters and local
12056 variables of all reentrant functions are allocated in this area.
12057 This option is provided for programs with large stack space requirements.
12058 When used with the -
12068 -stack-auto option, all parameters and local variables are allocated on
12069 the external stack (note support libraries will need to be recompiled with
12073 The compiler outputs the higher order address byte of the external ram segment
12074 into PORT P2, therefore when using the External Stack option, this port
12075 MAY NOT be used by the application program.
12079 \begin_inset LatexCommand \index{ANSI-compliance}
12086 Deviations from the compliancy.
12089 functions are not always reentrant.
12092 structures cannot be assigned values directly, cannot be passed as function
12093 parameters or assigned to each other and cannot be a return value from
12120 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
12131 struct s foo1 (struct s parms) /* is invalid in SDCC although allowed in
12153 return rets;/* is invalid in SDCC although allowed in ANSI */
12159 \begin_inset LatexCommand \index{long long (not supported)}
12164 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
12172 \begin_inset LatexCommand \index{double (not supported)}
12176 ' precision floating point
12177 \begin_inset LatexCommand \index{Floating point support}
12184 No support for setjmp and longjmp (for now).
12188 \begin_inset LatexCommand \index{K\&R style}
12192 function declarations are NOT allowed.
12198 foo(i,j) /* this old style of function declarations */
12200 int i,j; /* are valid in ANSI but not valid in SDCC */
12214 functions declared as pointers must be dereferenced during the call.
12225 /* has to be called like this */
12227 (*foo)(); /* ansi standard allows calls to be made like 'foo()' */
12230 Cyclomatic Complexity
12231 \begin_inset LatexCommand \index{Cyclomatic complexity}
12238 Cyclomatic complexity of a function is defined as the number of independent
12239 paths the program can take during execution of the function.
12240 This is an important number since it defines the number test cases you
12241 have to generate to validate the function.
12242 The accepted industry standard for complexity number is 10, if the cyclomatic
12243 complexity reported by SDCC exceeds 10 you should think about simplification
12244 of the function logic.
12245 Note that the complexity level is not related to the number of lines of
12246 code in a function.
12247 Large functions can have low complexity, and small functions can have large
12253 SDCC uses the following formula to compute the complexity:
12258 complexity = (number of edges in control flow graph) - (number of nodes
12259 in control flow graph) + 2;
12263 Having said that the industry standard is 10, you should be aware that in
12264 some cases it be may unavoidable to have a complexity level of less than
12266 For example if you have switch statement with more than 10 case labels,
12267 each case label adds one to the complexity level.
12268 The complexity level is by no means an absolute measure of the algorithmic
12269 complexity of the function, it does however provide a good starting point
12270 for which functions you might look at for further optimization.
12276 Here are a few guidelines that will help the compiler generate more efficient
12277 code, some of the tips are specific to this compiler others are generally
12278 good programming practice.
12281 Use the smallest data type to represent your data-value.
12282 If it is known in advance that the value is going to be less than 256 then
12283 use an 'unsigned char' instead of a 'short' or 'int'.
12286 Use unsigned when it is known in advance that the value is not going to
12288 This helps especially if you are doing division or multiplication.
12291 NEVER jump into a LOOP.
12294 Declare the variables to be local whenever possible, especially loop control
12295 variables (induction).
12298 Since the compiler does not always do implicit integral promotion, the programme
12299 r should do an explicit cast when integral promotion is required.
12302 Reducing the size of division, multiplication & modulus operations can reduce
12303 code size substantially.
12304 Take the following code for example.
12310 foobar(unsigned int p1, unsigned char ch)
12314 unsigned char ch1 = p1 % ch ;
12325 For the modulus operation the variable ch will be promoted to unsigned int
12326 first then the modulus operation will be performed (this will lead to a
12327 call to support routine _moduint()), and the result will be casted to a
12329 If the code is changed to
12335 foobar(unsigned int p1, unsigned char ch)
12339 unsigned char ch1 = (unsigned char)p1 % ch ;
12350 It would substantially reduce the code generated (future versions of the
12351 compiler will be smart enough to detect such optimization oppurtunities).
12354 Notes on MCS51 memory
12355 \begin_inset LatexCommand \index{MCS51 memory}
12362 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12363 RAM memory which is structured as follows
12367 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
12370 - Bytes 20-2F - 16 bytes to hold 128 bit variables and,
12372 - Bytes 30-7F - 80 bytes for general purpose use.
12377 Adittionally some members of the MCS51 family may have up to 128 bytes of
12378 additional, indirectly addressable, internal RAM memory (
12383 Furtermore, some chips may have some built in external memory (
12387 ) which should not be confused with the internal, direclty addressable RAM
12393 Usually this built in
12397 memory has to be activated before using it (you can probably find this
12398 information on the datasheet of the microcontroller your are using).
12401 Normally SDCC will only use the first bank
12402 \begin_inset LatexCommand \index{bank}
12406 of registers (register bank 0), but it is possible to specify that other
12407 banks of registers should be used in interrupt
12408 \begin_inset LatexCommand \index{interrupt}
12413 By default, the compiler will place the stack after the last byte of allocated
12414 memory for variables.
12415 For example, if the first 2 banks of registers are used, and only four
12420 variables, it will position the base of the internal stack at address 20
12422 This implies that as the stack
12423 \begin_inset LatexCommand \index{stack}
12427 grows, it will use up the remaining register banks, and the 16 bytes used
12428 by the 128 bit variables, and 80 bytes for general purpose use.
12429 If any bit variables are used, the data variables will be placed after
12430 the byte holding the last bit variable.
12431 For example, if register banks 0 and 1 are used, and there are 9 bit variables
12436 variables will be placed starting at address 0x22.
12448 \begin_inset LatexCommand \index{-\/-data-loc}
12452 to specify the start address of the
12466 -iram-size to specify the size of the total internal RAM (
12478 By default the 8051 linker will place the stack after the last byte of data
12491 \begin_inset LatexCommand \index{-\/-stack-loc}
12495 allows you to specify the start of the stack, i.e.
12496 you could start it after any data in the general purpose area.
12497 If your microcontroller has aditional indirectly addressable internal RAM
12502 ) you can place the stack on it.
12503 You may also need to use -
12514 \begin_inset LatexCommand \index{-\/-data-loc}
12518 to set the start address of the external RAM (
12533 \begin_inset LatexCommand \index{-\/-data-loc}
12537 to specify its size.
12538 Same goes for the code memory, using -
12549 \begin_inset LatexCommand \index{-\/-data-loc}
12564 \begin_inset LatexCommand \index{-\/-data-loc}
12569 If in doubt, don't specify any options and see if the resulting memory
12570 layout is appropiate, then you can twik it.
12573 The 8051 linker generates two files with memory allocation information.
12574 The first, with extension .map shows all the variables and segments.
12575 The second with extension .mem shows the final memory layout.
12576 The linker will complaint either if memory segments overlap, there is not
12577 enough memory, or there is not enough space for stack.
12578 If you get any linking warnings and/or errors related to stack or segments
12579 allocation, take a look at either the .map or .mem files to find out what
12581 The .mem file may even suggest a solution to the problem.
12585 \begin_inset LatexCommand \index{Tools}
12589 included in the distribution
12593 \begin_inset Tabular
12594 <lyxtabular version="3" rows="12" columns="3">
12596 <column alignment="center" valignment="top" leftline="true" width="0pt">
12597 <column alignment="center" valignment="top" leftline="true" width="0pt">
12598 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
12599 <row topline="true" bottomline="true">
12600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12616 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12625 <row topline="true">
12626 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12639 Simulator for various architectures
12642 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12651 <row topline="true">
12652 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12665 header file conversion
12668 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12673 sdcc/support/scripts
12677 <row topline="true">
12678 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12691 header file conversion
12694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12699 sdcc/support/scripts
12703 <row topline="true">
12704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12738 <row topline="true">
12739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12755 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12773 <row topline="true">
12774 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12808 <row topline="true">
12809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12825 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12843 <row topline="true">
12844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12860 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12878 <row topline="true">
12879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12895 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12913 <row topline="true">
12914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12930 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12948 <row topline="true" bottomline="true">
12949 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12965 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12990 Related open source tools
12991 \begin_inset LatexCommand \index{Related tools}
12999 \begin_inset Tabular
13000 <lyxtabular version="3" rows="7" columns="3">
13002 <column alignment="center" valignment="top" leftline="true" width="0pt">
13003 <column alignment="center" valignment="top" leftline="true" width="0pt">
13004 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
13005 <row topline="true" bottomline="true">
13006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13022 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13031 <row topline="true">
13032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13038 \begin_inset LatexCommand \index{gpsim}
13045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13053 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13059 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
13067 <row topline="true">
13068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13074 \begin_inset LatexCommand \index{srecord}
13081 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13086 Object file conversion, checksumming, ...
13089 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13095 \begin_inset LatexCommand \url{http://srecord.sourceforge.net/}
13103 <row topline="true">
13104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13110 \begin_inset LatexCommand \index{objdump}
13117 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13122 Object file conversion, ...
13125 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13130 Part of binutils (should be there anyway)
13134 <row topline="true">
13135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13141 \begin_inset LatexCommand \index{doxygen}
13148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13153 Source code documentation system
13156 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13162 \begin_inset LatexCommand \url{http://www.doxygen.org}
13170 <row topline="true">
13171 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13177 \begin_inset LatexCommand \index{splint}
13184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13189 Statically checks c sources
13192 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13198 \begin_inset LatexCommand \url{http://www.splint.org}
13206 <row topline="true" bottomline="true">
13207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13213 \begin_inset LatexCommand \index{ddd}
13220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13225 Debugger, serves nicely as GUI to sdcdb
13226 \begin_inset LatexCommand \index{sdcdb}
13233 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13239 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
13254 Related documentation / recommended reading
13258 \begin_inset Tabular
13259 <lyxtabular version="3" rows="5" columns="3">
13261 <column alignment="center" valignment="top" leftline="true" width="0pt">
13262 <column alignment="center" valignment="top" leftline="true" width="0pt">
13263 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
13264 <row topline="true" bottomline="true">
13265 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13281 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13290 <row topline="true">
13291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13306 Advanced Compiler Design and Implementation
13309 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13318 <row topline="true">
13319 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13342 \begin_inset LatexCommand \index{C Reference card}
13349 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13355 \begin_inset LatexCommand \url{http://www.refcards.com/about/c.html}
13363 <row topline="true">
13364 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13369 test_suite_spec.pdf
13372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13377 sdcc regression test
13378 \begin_inset LatexCommand \index{Regression test}
13385 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13394 <row topline="true" bottomline="true">
13395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13426 sdcc internal documentation
13429 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13445 Retargetting for other MCUs.
13448 The issues for retargetting the compiler are far too numerous to be covered
13450 What follows is a brief description of each of the seven phases of the
13451 compiler and its MCU dependency.
13454 Parsing the source and building the annotated parse tree.
13455 This phase is largely MCU independent (except for the language extensions).
13456 Syntax & semantic checks are also done in this phase, along with some initial
13457 optimizations like back patching labels and the pattern matching optimizations
13458 like bit-rotation etc.
13461 The second phase involves generating an intermediate code which can be easy
13462 manipulated during the later phases.
13463 This phase is entirely MCU independent.
13464 The intermediate code generation assumes the target machine has unlimited
13465 number of registers, and designates them with the name iTemp.
13466 The compiler can be made to dump a human readable form of the code generated
13480 This phase does the bulk of the standard optimizations and is also MCU independe
13482 This phase can be broken down into several sub-phases:
13486 Break down intermediate code (iCode) into basic blocks.
13488 Do control flow & data flow analysis on the basic blocks.
13490 Do local common subexpression elimination, then global subexpression elimination
13492 Dead code elimination
13496 If loop optimizations caused any changes then do 'global subexpression eliminati
13497 on' and 'dead code elimination' again.
13500 This phase determines the live-ranges; by live range I mean those iTemp
13501 variables defined by the compiler that still survive after all the optimization
13503 Live range analysis
13504 \begin_inset LatexCommand \index{Live range analysis}
13508 is essential for register allocation, since these computation determines
13509 which of these iTemps will be assigned to registers, and for how long.
13512 Phase five is register allocation.
13513 There are two parts to this process.
13517 The first part I call 'register packing' (for lack of a better term).
13518 In this case several MCU specific expression folding is done to reduce
13523 The second part is more MCU independent and deals with allocating registers
13524 to the remaining live ranges.
13525 A lot of MCU specific code does creep into this phase because of the limited
13526 number of index registers available in the 8051.
13529 The Code generation phase is (unhappily), entirely MCU dependent and very
13530 little (if any at all) of this code can be reused for other MCU.
13531 However the scheme for allocating a homogenized assembler operand for each
13532 iCode operand may be reused.
13535 As mentioned in the optimization section the peep-hole optimizer is rule
13536 based system, which can reprogrammed for other MCUs.
13540 \begin_inset LatexCommand \index{sdcdb}
13544 - Source Level Debugger
13545 \begin_inset LatexCommand \index{Debugger}
13552 SDCC is distributed with a source level debugger.
13553 The debugger uses a command line interface, the command repertoire of the
13554 debugger has been kept as close to gdb
13555 \begin_inset LatexCommand \index{gdb}
13559 (the GNU debugger) as possible.
13560 The configuration and build process is part of the standard compiler installati
13561 on, which also builds and installs the debugger in the target directory
13562 specified during configuration.
13563 The debugger allows you debug BOTH at the C source and at the ASM source
13567 Compiling for Debugging
13570 The \SpecialChar \-
13572 debug option must be specified for all files for which debug information
13573 is to be generated.
13574 The complier generates a .adb file for each of these files.
13575 The linker creates the .cdb file from the .adb files and the address information.
13576 This .cdb is used by the debugger.
13579 How the Debugger Works
13592 -debug option is specified the compiler generates extra symbol information
13593 some of which are put into the the assembler source and some are put into
13595 Then the linker creates the .cdb file from the individual .adb files with
13596 the address information for the symbols.
13597 The debugger reads the symbolic information generated by the compiler &
13598 the address information generated by the linker.
13599 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
13600 execution is controlled by the debugger.
13601 When a command is issued for the debugger, it translates it into appropriate
13602 commands for the simulator.
13605 Starting the Debugger
13608 The debugger can be started using the following command line.
13609 (Assume the file you are debugging has the file name foo).
13623 The debugger will look for the following files.
13626 foo.c - the source file.
13629 foo.cdb - the debugger symbol information file.
13632 foo.ihx - the intel hex format
13633 \begin_inset LatexCommand \index{Intel hex format}
13640 Command Line Options.
13653 -directory=<source file directory> this option can used to specify the directory
13655 The debugger will look into the directory list specified for source, cdb
13657 The items in the directory list must be separated by ':', e.g.
13658 if the source files can be in the directories /home/src1 and /home/src2,
13669 -directory option should be -
13679 -directory=/home/src1:/home/src2.
13680 Note there can be no spaces in the option.
13684 -cd <directory> - change to the <directory>.
13687 -fullname - used by GUI front ends.
13690 -cpu <cpu-type> - this argument is passed to the simulator please see the
13691 simulator docs for details.
13694 -X <Clock frequency > this options is passed to the simulator please see
13695 the simulator docs for details.
13698 -s <serial port file> passed to simulator see the simulator docs for details.
13701 -S <serial in,out> passed to simulator see the simulator docs for details.
13707 As mention earlier the command interface for the debugger has been deliberately
13708 kept as close the GNU debugger gdb, as possible.
13709 This will help the integration with existing graphical user interfaces
13710 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
13711 \layout Subsubsection
13713 break [line | file:line | function | file:function]
13716 Set breakpoint at specified line or function:
13725 sdcdb>break foo.c:100
13727 sdcdb>break funcfoo
13729 sdcdb>break foo.c:funcfoo
13730 \layout Subsubsection
13732 clear [line | file:line | function | file:function ]
13735 Clear breakpoint at specified line or function:
13744 sdcdb>clear foo.c:100
13746 sdcdb>clear funcfoo
13748 sdcdb>clear foo.c:funcfoo
13749 \layout Subsubsection
13754 Continue program being debugged, after breakpoint.
13755 \layout Subsubsection
13760 Execute till the end of the current function.
13761 \layout Subsubsection
13766 Delete breakpoint number 'n'.
13767 If used without any option clear ALL user defined break points.
13768 \layout Subsubsection
13770 info [break | stack | frame | registers ]
13773 info break - list all breakpoints
13776 info stack - show the function call stack.
13779 info frame - show information about the current execution frame.
13782 info registers - show content of all registers.
13783 \layout Subsubsection
13788 Step program until it reaches a different source line.
13789 \layout Subsubsection
13794 Step program, proceeding through subroutine calls.
13795 \layout Subsubsection
13800 Start debugged program.
13801 \layout Subsubsection
13806 Print type information of the variable.
13807 \layout Subsubsection
13812 print value of variable.
13813 \layout Subsubsection
13818 load the given file name.
13819 Note this is an alternate method of loading file for debugging.
13820 \layout Subsubsection
13825 print information about current frame.
13826 \layout Subsubsection
13831 Toggle between C source & assembly source.
13832 \layout Subsubsection
13834 ! simulator command
13837 Send the string following '!' to the simulator, the simulator response is
13839 Note the debugger does not interpret the command being sent to the simulator,
13840 so if a command like 'go' is sent the debugger can loose its execution
13841 context and may display incorrect values.
13842 \layout Subsubsection
13849 My name is Bobby Brown"
13852 Interfacing with XEmacs
13853 \begin_inset LatexCommand \index{XEmacs}
13858 \begin_inset LatexCommand \index{Emacs}
13865 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
13866 sdcdb.el and sdcdbsrc.el.
13867 These two files can be found in the $(prefix)/bin directory after the installat
13869 These files need to be loaded into XEmacs for the interface to work.
13870 This can be done at XEmacs startup time by inserting the following into
13871 your '.xemacs' file (which can be found in your HOME directory):
13877 (load-file sdcdbsrc.el)
13883 .xemacs is a lisp file so the () around the command is REQUIRED.
13884 The files can also be loaded dynamically while XEmacs is running, set the
13885 environment variable 'EMACSLOADPATH' to the installation bin directory
13886 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
13887 To start the interface enter the following command:
13901 You will prompted to enter the file name to be debugged.
13906 The command line options that are passed to the simulator directly are bound
13907 to default values in the file sdcdbsrc.el.
13908 The variables are listed below, these values maybe changed as required.
13911 sdcdbsrc-cpu-type '51
13914 sdcdbsrc-frequency '11059200
13917 sdcdbsrc-serial nil
13920 The following is a list of key mapping for the debugger interface.
13928 ;; Current Listing ::
13930 ;;key\SpecialChar ~
13945 binding\SpecialChar ~
13969 ;;---\SpecialChar ~
13984 ------\SpecialChar ~
14024 sdcdb-next-from-src\SpecialChar ~
14050 sdcdb-back-from-src\SpecialChar ~
14076 sdcdb-cont-from-src\SpecialChar ~
14086 SDCDB continue command
14102 sdcdb-step-from-src\SpecialChar ~
14128 sdcdb-whatis-c-sexp\SpecialChar ~
14138 SDCDB ptypecommand for data at
14202 sdcdbsrc-delete\SpecialChar ~
14216 SDCDB Delete all breakpoints if no arg
14264 given or delete arg (C-u arg x)
14280 sdcdbsrc-frame\SpecialChar ~
14295 SDCDB Display current frame if no arg,
14344 given or display frame arg
14409 sdcdbsrc-goto-sdcdb\SpecialChar ~
14419 Goto the SDCDB output buffer
14435 sdcdb-print-c-sexp\SpecialChar ~
14446 SDCDB print command for data at
14510 sdcdbsrc-goto-sdcdb\SpecialChar ~
14520 Goto the SDCDB output buffer
14536 sdcdbsrc-mode\SpecialChar ~
14552 Toggles Sdcdbsrc mode (turns it off)
14556 ;; C-c C-f\SpecialChar ~
14564 sdcdb-finish-from-src\SpecialChar ~
14572 SDCDB finish command
14576 ;; C-x SPC\SpecialChar ~
14584 sdcdb-break\SpecialChar ~
14602 Set break for line with point
14604 ;; ESC t\SpecialChar ~
14614 sdcdbsrc-mode\SpecialChar ~
14630 Toggle Sdcdbsrc mode
14632 ;; ESC m\SpecialChar ~
14642 sdcdbsrc-srcmode\SpecialChar ~
14666 The Z80 and gbz80 port
14669 SDCC can target both the Zilog Z80 and the Nintendo Gameboy's Z80-like gbz80.
14670 The port is incomplete - long support is incomplete (mul, div and mod are
14671 unimplimented), and both float and bitfield support is missing.
14672 Apart from that the code generated is correct.
14675 As always, the code is the authoritave reference - see z80/ralloc.c and z80/gen.c.
14676 The stack frame is similar to that generated by the IAR Z80 compiler.
14677 IX is used as the base pointer, HL is used as a temporary register, and
14678 BC and DE are available for holding varibles.
14679 IY is currently unusued.
14680 Return values are stored in HL.
14681 One bad side effect of using IX as the base pointer is that a functions
14682 stack frame is limited to 127 bytes - this will be fixed in a later version.
14686 \begin_inset LatexCommand \index{Support}
14693 SDCC has grown to be a large project.
14694 The compiler alone (without the preprocessor, assembler and linker) is
14695 about 40,000 lines of code (blank stripped).
14696 The open source nature of this project is a key to its continued growth
14698 You gain the benefit and support of many active software developers and
14700 Is SDCC perfect? No, that's why we need your help.
14701 The developers take pride in fixing reported bugs.
14702 You can help by reporting the bugs and helping other SDCC users.
14703 There are lots of ways to contribute, and we encourage you to take part
14704 in making SDCC a great software package.
14708 The SDCC project is hosted on the sdcc sourceforge site at
14709 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
14714 You'll find the complete set of mailing lists
14715 \begin_inset LatexCommand \index{Mailing list}
14719 , forums, bug reporting system, patch submission
14720 \begin_inset LatexCommand \index{Patch submission}
14725 \begin_inset LatexCommand \index{download}
14729 area and cvs code repository
14730 \begin_inset LatexCommand \index{cvs code repository}
14738 \begin_inset LatexCommand \index{Bugs}
14743 \begin_inset LatexCommand \index{Reporting bugs}
14750 The recommended way of reporting bugs is using the infrastructure of the
14752 You can follow the status of bug reports there and have an overview about
14756 Bug reports are automatically forwarded to the developer mailing list and
14757 will be fixed ASAP.
14758 When reporting a bug, it is very useful to include a small test program
14759 which reproduces the problem.
14760 If you can isolate the problem by looking at the generated assembly code,
14761 this can be very helpful.
14762 Compiling your program with the -
14773 \begin_inset LatexCommand \index{-\/-dumpall}
14777 option can sometimes be useful in locating optimization problems.
14780 Please have a short check that you are using a recent version of SDCC and
14781 the bug is not yet known.
14782 This is the link for reporting bugs:
14783 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
14790 Requesting Features
14791 \begin_inset LatexCommand \index{Feature request}
14796 \begin_inset LatexCommand \index{Requesting features}
14803 Like bug reports feature requests are forwarded to the developer mailing
14805 This is the link for requesting features:
14806 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
14816 These links should take you directly to the
14817 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
14827 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
14828 automated messages (mid 2003)
14832 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
14836 , lists and forums are archived so if you are lucky someone already had
14841 \begin_inset LatexCommand \index{Changelog}
14848 You can follow the status of the cvs version
14849 \begin_inset LatexCommand \index{version}
14853 of SDCC by watching the file
14854 \begin_inset LatexCommand \htmlurl[ChangeLog]{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/sdcc/sdcc/ChangeLog?rev=HEAD&content-type=text/plain}
14858 in the cvs-repository.
14862 \begin_inset LatexCommand \index{Release policy}
14869 Historically there often were long delays between official releases and
14870 the sourceforge download area tends to get not updated at all.
14871 Current excuses might refer to problems with live range analysis, but if
14872 this is fixed, the next problem rising is that another excuse will have
14874 Kidding aside, we have to get better there!
14878 \begin_inset LatexCommand \index{Examples}
14885 You'll find some small examples in the directory sdcc/device/examples/
14888 Maybe we should include some links to real world applications.
14889 Preferrably pointer to pointers (one for each architecture) so this stays
14894 \begin_inset LatexCommand \index{Quality control}
14901 The compiler is passed through nightly compile and build checks.
14907 \begin_inset LatexCommand \index{Regression test}
14911 check that SDCC itself compiles flawlessly on several platforms and checks
14912 the quality of the code generated by SDCC by running the code through simulator
14914 There is a separate document
14917 \begin_inset LatexCommand \index{Test suite}
14926 You'll find the test code in the directory
14928 sdcc/support/regression
14931 You can run these tests manually by running
14935 in this directory (or f.e.
14940 if you don't want to run the complete tests).
14941 The test code might also be interesting if you want to look for examples
14942 \begin_inset LatexCommand \index{Examples}
14946 checking corner cases of SDCC or if you plan to submit patches
14947 \begin_inset LatexCommand \index{Patch submission}
14954 The pic port uses a different set of regression tests, you'll find them
14957 sdcc/src/regression
14963 \begin_inset LatexCommand \index{Compiler internals}
14970 The anatomy of the compiler
14975 This is an excerpt from an atricle published in Circuit Cellar MagaZine
14977 It's a little outdated (the compiler is much more efficient now and user/develo
14978 per friendly), but pretty well exposes the guts of it all.
14984 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
14985 It is fairly easy to retarget for other 8-bit MCU.
14986 Here we take a look at some of the internals of the compiler.
14991 \begin_inset LatexCommand \index{Parsing}
14998 Parsing the input source file and creating an AST (Annotated Syntax Tree
14999 \begin_inset LatexCommand \index{Annotated syntax tree}
15004 This phase also involves propagating types (annotating each node of the
15005 parse tree with type information) and semantic analysis.
15006 There are some MCU specific parsing rules.
15007 For example the storage classes, the extended storage classes are MCU specific
15008 while there may be a xdata storage class for 8051 there is no such storage
15009 class for z80 or Atmel AVR.
15010 SDCC allows MCU specific storage class extensions, i.e.
15011 xdata will be treated as a storage class specifier when parsing 8051 C
15012 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
15017 \begin_inset LatexCommand \index{iCode}
15024 Intermediate code generation.
15025 In this phase the AST is broken down into three-operand form (iCode).
15026 These three operand forms are represented as doubly linked lists.
15027 ICode is the term given to the intermediate form generated by the compiler.
15028 ICode example section shows some examples of iCode generated for some simple
15029 C source functions.
15033 \begin_inset LatexCommand \index{Optimizations}
15040 Bulk of the target independent optimizations is performed in this phase.
15041 The optimizations include constant propagation, common sub-expression eliminati
15042 on, loop invariant code movement, strength reduction of loop induction variables
15043 and dead-code elimination.
15046 Live range analysis
15047 \begin_inset LatexCommand \index{Live range analysis}
15054 During intermediate code generation phase, the compiler assumes the target
15055 machine has infinite number of registers and generates a lot of temporary
15057 The live range computation determines the lifetime of each of these compiler-ge
15058 nerated temporaries.
15059 A picture speaks a thousand words.
15060 ICode example sections show the live range annotations for each of the
15062 It is important to note here, each iCode is assigned a number in the order
15063 of its execution in the function.
15064 The live ranges are computed in terms of these numbers.
15065 The from number is the number of the iCode which first defines the operand
15066 and the to number signifies the iCode which uses this operand last.
15069 Register Allocation
15070 \begin_inset LatexCommand \index{Register allocation}
15077 The register allocation determines the type and number of registers needed
15079 In most MCUs only a few registers can be used for indirect addressing.
15080 In case of 8051 for example the registers R0 & R1 can be used to indirectly
15081 address the internal ram and DPTR to indirectly address the external ram.
15082 The compiler will try to allocate the appropriate register to pointer variables
15084 ICode example section shows the operands annotated with the registers assigned
15086 The compiler will try to keep operands in registers as much as possible;
15087 there are several schemes the compiler uses to do achieve this.
15088 When the compiler runs out of registers the compiler will check to see
15089 if there are any live operands which is not used or defined in the current
15090 basic block being processed, if there are any found then it will push that
15091 operand and use the registers in this block, the operand will then be popped
15092 at the end of the basic block.
15096 There are other MCU specific considerations in this phase.
15097 Some MCUs have an accumulator; very short-lived operands could be assigned
15098 to the accumulator instead of general-purpose register.
15104 Figure II gives a table of iCode operations supported by the compiler.
15105 The code generation involves translating these operations into corresponding
15106 assembly code for the processor.
15107 This sounds overly simple but that is the essence of code generation.
15108 Some of the iCode operations are generated on a MCU specific manner for
15109 example, the z80 port does not use registers to pass parameters so the
15110 SEND and RECV iCode operations will not be generated, and it also does
15111 not support JUMPTABLES.
15118 <Where is Figure II ?>
15122 \begin_inset LatexCommand \index{iCode}
15129 This section shows some details of iCode.
15130 The example C code does not do anything useful; it is used as an example
15131 to illustrate the intermediate code generated by the compiler.
15144 /* This function does nothing useful.
15151 for the purpose of explaining iCode */
15154 short function (data int *x)
15162 short i=10; /* dead initialization eliminated */
15167 short sum=10; /* dead initialization eliminated */
15180 while (*x) *x++ = *p++;
15194 /* compiler detects i,j to be induction variables */
15198 for (i = 0, j = 10 ; i < 10 ; i++, j--) {
15210 mul += i * 3; /* this multiplication remains */
15216 gint += j * 3;/* this multiplication changed to addition */
15233 In addition to the operands each iCode contains information about the filename
15234 and line it corresponds to in the source file.
15235 The first field in the listing should be interpreted as follows:
15240 Filename(linenumber: iCode Execution sequence number : ICode hash table
15241 key : loop depth of the iCode).
15246 Then follows the human readable form of the ICode operation.
15247 Each operand of this triplet form can be of three basic types a) compiler
15248 generated temporary b) user defined variable c) a constant value.
15249 Note that local variables and parameters are replaced by compiler generated
15252 \begin_inset LatexCommand \index{Live range analysis}
15256 are computed only for temporaries (i.e.
15257 live ranges are not computed for global variables).
15259 \begin_inset LatexCommand \index{Register allocation}
15263 are allocated for temporaries only.
15264 Operands are formatted in the following manner:
15269 Operand Name [lr live-from : live-to ] { type information } [ registers
15275 As mentioned earlier the live ranges are computed in terms of the execution
15276 sequence number of the iCodes, for example
15278 the iTemp0 is live from (i.e.
15279 first defined in iCode with execution sequence number 3, and is last used
15280 in the iCode with sequence number 5).
15281 For induction variables such as iTemp21 the live range computation extends
15282 the lifetime from the start to the end of the loop.
15284 The register allocator used the live range information to allocate registers,
15285 the same registers may be used for different temporaries if their live
15286 ranges do not overlap, for example r0 is allocated to both iTemp6 and to
15287 iTemp17 since their live ranges do not overlap.
15288 In addition the allocator also takes into consideration the type and usage
15289 of a temporary, for example itemp6 is a pointer to near space and is used
15290 as to fetch data from (i.e.
15291 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer registers (r0).
15292 Some short lived temporaries are allocated to special registers which have
15293 meaning to the code generator e.g.
15294 iTemp13 is allocated to a pseudo register CC which tells the back end that
15295 the temporary is used only for a conditional jump the code generation makes
15296 use of this information to optimize a compare and jump ICode.
15298 There are several loop optimizations
15299 \begin_inset LatexCommand \index{Loop optimization}
15303 performed by the compiler.
15304 It can detect induction variables iTemp21(i) and iTemp23(j).
15305 Also note the compiler does selective strength reduction
15306 \begin_inset LatexCommand \index{Strength reduction}
15311 the multiplication of an induction variable in line 18 (gint = j * 3) is
15312 changed to addition, a new temporary iTemp17 is allocated and assigned
15313 a initial value, a constant 3 is then added for each iteration of the loop.
15314 The compiler does not change the multiplication
15315 \begin_inset LatexCommand \index{Multiplication}
15319 in line 17 however since the processor does support an 8 * 8 bit multiplication.
15321 Note the dead code elimination
15322 \begin_inset LatexCommand \index{Dead-code elimination}
15326 optimization eliminated the dead assignments in line 7 & 8 to I and sum
15334 Sample.c (5:1:0:0) _entry($9) :
15339 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
15344 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
15349 Sample.c(11:4:53:0) preHeaderLbl0($11) :
15354 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
15360 Sample.c(11:6:5:1) _whilecontinue_0($1) :
15365 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
15371 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
15376 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
15382 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
15388 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
15394 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
15400 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
15401 * int}[r0] + 0x2 {short}
15406 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
15411 Sample.c(11:17:21:0)_whilebreak_0($3) :
15416 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
15421 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
15426 Sample.c(15:20:54:0)preHeaderLbl1($13) :
15431 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
15436 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
15441 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
15446 Sample.c(15:24:26:1)_forcond_0($4) :
15451 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
15457 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
15462 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
15463 + ITemp21 [lr21:38]{short}[r4]
15468 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
15474 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
15475 + iTemp15 [lr29:30]{short}[r1]
15480 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
15486 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
15492 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
15498 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
15504 Sample.c(19:38:47:1) goto _forcond_0($4)
15509 Sample.c(19:39:48:0)_forbreak_0($7) :
15514 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
15515 + ITemp11 [lr19:40]{short}[r3]
15520 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
15525 Sample.c(20:42:51:0)_return($8) :
15530 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
15536 Finally the code generated for this function:
15577 ; ----------------------------------------------
15582 ; function function
15587 ; ----------------------------------------------
15597 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
15609 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
15621 ;_whilecontinue_0($1) :
15631 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
15636 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
15695 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
15714 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
15761 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
15801 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
15827 ; iTemp6 [lr5:16]{_near * int}[r0] =
15832 ; iTemp6 [lr5:16]{_near * int}[r0] +
15849 ; goto _whilecontinue_0($1)
15861 ; _whilebreak_0($3) :
15871 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
15883 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
15895 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
15907 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
15926 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
15955 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
15960 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
16005 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
16010 ; iTemp21 [lr21:38]{short}[r4]
16036 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
16069 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
16074 ; iTemp15 [lr29:30]{short}[r1]
16093 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
16140 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
16187 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
16199 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
16213 cjne r5,#0xff,00104$
16225 ; goto _forcond_0($4)
16237 ; _forbreak_0($7) :
16247 ; ret iTemp24 [lr40:41]{short}
16290 A few words about basic block successors, predecessors and dominators
16293 Successors are basic blocks
16294 \begin_inset LatexCommand \index{Basic blocks}
16298 that might execute after this basic block.
16300 Predecessors are basic blocks that might execute before reaching this basic
16303 Dominators are basic blocks that WILL execute before reaching this basic
16329 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
16332 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
16335 c) domVect of [BB4] = BB1 ...
16336 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
16344 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
16354 Thanks to all the other volunteer developers who have helped with coding,
16355 testing, web-page creation, distribution sets, etc.
16356 You know who you are :-)
16363 This document was initially written by Sandeep Dutta
16366 All product names mentioned herein may be trademarks
16367 \begin_inset LatexCommand \index{Trademarks}
16371 of their respective companies.
16378 To avoid confusion, the installation and building options for sdcc itself
16379 (chapter 2) are not part of the index.
16383 \begin_inset LatexCommand \printindex{}