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
21 \papersize letterpaper
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 Architecture specific stuff (like memory models, code examples) should maybe
67 into seperate sections/chapters/appendices (it is hard to document PIC or
71 a 8051 centered document)
74 SDCC Compiler User Guide
77 The strings enclosed in $ are automatically updated by cvs:
91 \begin_inset LatexCommand \tableofcontents{}
108 is a Freeware, retargettable, optimizing ANSI-C compiler by
112 designed for 8 bit Microprocessors.
113 The current version targets Intel MCS51 based Microprocessors (8031, 8032,
115 \begin_inset LatexCommand \index{8031, 8032, 8051, 8052 CPU}
119 , etc), Zilog Z80 based MCUs, and the Dallas DS80C390 variant.
120 It can be retargetted for other microprocessors, support for Microchip
121 PIC, Atmel AVR is under development.
122 The entire source code for the compiler is distributed under GPL.
123 SDCC uses ASXXXX & ASLINK, a Freeware, retargettable assembler & linker.
124 SDCC has extensive language extensions suitable for utilizing various microcont
125 rollers and underlying hardware effectively.
130 In addition to the MCU specific optimizations SDCC also does a host of standard
134 global sub expression elimination,
137 loop optimizations (loop invariant, strength reduction of induction variables
141 constant folding & propagation,
147 dead code elimination
157 For the back-end SDCC uses a global register allocation scheme which should
158 be well suited for other 8 bit MCUs.
163 The peep hole optimizer uses a rule based substitution mechanism which is
169 Supported data-types are:
172 char (8 bits, 1 byte),
175 short and int (16 bits, 2 bytes),
178 long (32 bit, 4 bytes)
185 The compiler also allows
187 inline assembler code
189 to be embedded anywhere in a function.
190 In addition, routines developed in assembly can also be called.
194 SDCC also provides an option (-
204 -cyclomatic) to report the relative complexity of a function.
205 These functions can then be further optimized, or hand coded in assembly
211 SDCC also comes with a companion source level debugger SDCDB, the debugger
212 currently uses ucSim a freeware simulator for 8051 and other micro-controllers.
217 The latest version can be downloaded from
218 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
228 Please note: the compiler will probably always be some steps ahead of this
233 \begin_inset LatexCommand \index{Status of documentation}
243 Obviously this has pros and cons
252 All packages used in this compiler system are
260 ; source code for all the sub-packages (pre-processor, assemblers, linkers
261 etc) is distributed with the package.
262 This documentation is maintained using a freeware word processor (LyX).
264 This program is free software; you can redistribute it and/or modify it
265 under the terms of the GNU General Public License
266 \begin_inset LatexCommand \index{GNU General Public License, GPL}
270 as published by the Free Software Foundation; either version 2, or (at
271 your option) any later version.
272 This program is distributed in the hope that it will be useful, but WITHOUT
273 ANY WARRANTY; without even the implied warranty
274 \begin_inset LatexCommand \index{warranty}
278 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
279 See the GNU General Public License for more details.
280 You should have received a copy of the GNU General Public License along
281 with this program; if not, write to the Free Software Foundation, 59 Temple
282 Place - Suite 330, Boston, MA 02111-1307, USA.
283 In other words, you are welcome to use, share and improve this program.
284 You are forbidden to forbid anyone else to use, share and improve what
286 Help stamp out software-hoarding!
289 Typographic conventions
290 \begin_inset LatexCommand \index{Typographic conventions}
297 Throughout this manual, we will use the following convention.
298 Commands you have to type in are printed in
306 Code samples are printed in
311 Interesting items and new terms are printed in
316 Compatibility with previous versions
319 This version has numerous bug fixes compared with the previous version.
320 But we also introduced some incompatibilities with older versions.
321 Not just for the fun of it, but to make the compiler more stable, efficient
323 \begin_inset LatexCommand \index{ANSI-compliance}
333 short is now equivalent to int (16 bits), it used to be equivalent to char
334 (8 bits) which is not ANSI compliant
337 the default directory for gcc-builds where include, library and documentation
338 files are stored is now in /usr/local/share
341 char type parameters to vararg functions are casted to int unless explicitly
358 will push a as an int and as a char resp.
371 -regextend has been removed
384 -noregparms has been removed
397 -stack-after-data has been removed
402 <pending: more incompatibilities?>
408 What do you need before you start installation of SDCC? A computer, and
410 The preferred method of installation is to compile SDCC from source using
412 For Windows some pre-compiled binary distributions are available for your
414 You should have some experience with command line tools and compiler use.
420 The SDCC home page at
421 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
425 is a great place to find distribution sets.
426 You can also find links to the user mailing lists that offer help or discuss
427 SDCC with other SDCC users.
428 Web links to other SDCC related sites can also be found here.
429 This document can be found in the DOC directory of the source package as
431 Some of the other tools (simulator and assembler) included with SDCC contain
432 their own documentation and can be found in the source distribution.
433 If you want the latest unreleased software, the complete source package
434 is available directly by anonymous CVS on cvs.sdcc.sourceforge.net.
437 Wishes for the future
440 There are (and always will be) some things that could be done.
441 Here are some I can think of:
448 char KernelFunction3(char p) at 0x340;
456 \begin_inset LatexCommand \index{code banking (not supported)}
466 If you can think of some more, please see the chapter
467 \begin_inset LatexCommand \ref{sub:Requesting-Features}
471 about filing feature requests
472 \begin_inset LatexCommand \index{Requesting features}
477 \begin_inset LatexCommand \index{Feature request}
487 \begin_inset LatexCommand \index{Installation}
494 For most users it is sufficient to skip to either section
495 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
500 \begin_inset LatexCommand \ref{sub:Windows-Install}
505 More detailled instructions follow below.
509 \begin_inset LatexCommand \index{Options SDCC configuration}
516 The install paths, search paths and other options are defined when running
518 The defaults can be overridden by:
520 \labelwidthstring 00.00.0000
532 -prefix see table below
534 \labelwidthstring 00.00.0000
546 -exec_prefix see table below
548 \labelwidthstring 00.00.0000
560 -bindir see table below
562 \labelwidthstring 00.00.0000
574 -datadir see table below
576 \labelwidthstring 00.00.0000
578 docdir environment variable, see table below
580 \labelwidthstring 00.00.0000
582 include_dir_suffix environment variable, see table below
584 \labelwidthstring 00.00.0000
586 lib_dir_suffix environment variable, see table below
588 \labelwidthstring 00.00.0000
590 sdccconf_h_dir_separator environment variable, either / or
595 This character will only be used in sdccconf.h; don't forget it's a C-header,
596 therefore a double-backslash is needed there.
598 \labelwidthstring 00.00.0000
610 -disable-mcs51-port Excludes the Intel mcs51 port
612 \labelwidthstring 00.00.0000
624 -disable-gbz80-port Excludes the Gameboy gbz80 port
626 \labelwidthstring 00.00.0000
638 -z80-port Excludes the z80 port
640 \labelwidthstring 00.00.0000
652 -disable-avr-port Excludes the AVR port
654 \labelwidthstring 00.00.0000
666 -disable-ds390-port Excludes the DS390 port
668 \labelwidthstring 00.00.0000
680 -disable-pic-port Excludes the PIC port
682 \labelwidthstring 00.00.0000
694 -disable-xa51-port Excludes the XA51 port
696 \labelwidthstring 00.00.0000
708 -disable-ucsim Disables configuring and building of ucsim
710 \labelwidthstring 00.00.0000
722 -disable-device-lib-build Disables automatically building device libraries
724 \labelwidthstring 00.00.0000
736 -disable-packihx Disables building packihx
738 \labelwidthstring 00.00.0000
750 -enable-libgc Use the Bohem memory allocator.
751 Lower runtime footprint.
754 Furthermore the environment variables CC, CFLAGS, ...
755 the tools and their arguments can be influenced.
756 Please see `configure -
766 -help` and the man/info pages of `configure` for details.
770 The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB,
771 STD_FP_LIB, STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_
772 NAME, SDCC_INCLUDE_NAME, SDCC_LIB_NAME are defined by `configure` too.
773 At the moment it's not possible to change the default settings (it was
774 simply never required.
778 These configure options are compiled into the binaries, and can only be
779 changed by rerunning 'configure' and recompiling SDCC.
780 The configure options are written in
784 to distinguish them from run time environment variables (see section search
790 \begin_inset Quotes sld
794 \begin_inset Quotes srd
797 are used by the SDCC team to build the official Win32 binaries.
798 The SDCC team uses Mingw32 to build the official Windows binaries, because
805 a gcc compiler and last but not least
808 the binaries can be built by cross compiling on Sourceforge's compile farm.
811 See the examples, how to pass the Win32 settings to 'configure'.
812 The other Win32 builds using Borland, VC or whatever don't use 'configure',
813 but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
825 <lyxtabular version="3" rows="8" columns="3">
827 <column alignment="block" valignment="top" leftline="true" width="0in">
828 <column alignment="block" valignment="top" leftline="true" width="0in">
829 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
830 <row topline="true" bottomline="true">
831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
847 <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">
875 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
907 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
919 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
941 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
979 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
991 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1001 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1028 <row topline="true">
1029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1047 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1056 <row topline="true" bottomline="true">
1057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1075 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1093 'configure' also computes relative paths.
1094 This is needed for full relocatability of a binary package and to complete
1095 search paths (see section search paths below):
1101 \begin_inset Tabular
1102 <lyxtabular version="3" rows="4" columns="3">
1104 <column alignment="block" valignment="top" leftline="true" width="0in">
1105 <column alignment="block" valignment="top" leftline="true" width="0in">
1106 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1107 <row topline="true" bottomline="true">
1108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1124 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1133 <row topline="true" 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">
1163 <row bottomline="true">
1164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1182 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1191 <row bottomline="true">
1192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1202 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1210 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1243 \begin_inset Quotes srd
1247 \begin_inset Quotes srd
1261 \begin_inset Quotes srd
1265 \begin_inset Quotes srd
1293 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1302 \begin_inset Quotes srd
1305 i586-mingw32msvc-gcc
1306 \begin_inset Quotes srd
1310 \begin_inset Quotes srd
1313 i586-mingw32msvc-g++
1314 \begin_inset Quotes srd
1322 \begin_inset Quotes srd
1325 i586-mingw32msvc-ranlib
1326 \begin_inset Quotes srd
1334 \begin_inset Quotes srd
1337 i586-mingw32msvc-strip
1338 \begin_inset Quotes srd
1356 \begin_inset Quotes srd
1360 \begin_inset Quotes srd
1378 \begin_inset Quotes srd
1382 \begin_inset Quotes srd
1390 \begin_inset Quotes srd
1394 \begin_inset Quotes srd
1402 \begin_inset Quotes srd
1406 \begin_inset Quotes srd
1414 \begin_inset Quotes srd
1418 \begin_inset Quotes srd
1425 sdccconf_h_dir_separator=
1426 \begin_inset Quotes srd
1438 \begin_inset Quotes srd
1455 -disable-device-lib-build
1483 -host=i586-mingw32msvc -
1493 -build=unknown-unknown-linux-gnu
1497 \begin_inset Quotes sld
1501 \begin_inset Quotes srd
1504 compile on Cygwin for Mingw32(see also sdcc/support/scripts/sdcc_cygwin_mingw32)
1513 \begin_inset Quotes srd
1517 \begin_inset Quotes srd
1525 \begin_inset Quotes srd
1529 \begin_inset Quotes srd
1547 \begin_inset Quotes srd
1551 \begin_inset Quotes srd
1569 \begin_inset Quotes srd
1573 \begin_inset Quotes srd
1581 \begin_inset Quotes srd
1585 \begin_inset Quotes srd
1593 \begin_inset Quotes srd
1597 \begin_inset Quotes srd
1605 \begin_inset Quotes srd
1609 \begin_inset Quotes srd
1616 sdccconf_h_dir_separator=
1617 \begin_inset Quotes srd
1629 \begin_inset Quotes srd
1649 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
1660 -C' turns on caching, which gives a little bit extra speed.
1661 However if options are changed, it can be necessary to delete the config.cache
1666 \begin_inset LatexCommand \index{Install paths}
1672 \added_space_top medskip \align center
1674 \begin_inset Tabular
1675 <lyxtabular version="3" rows="5" columns="4">
1677 <column alignment="left" valignment="top" leftline="true" width="0">
1678 <column alignment="left" valignment="top" leftline="true" width="0">
1679 <column alignment="left" valignment="top" leftline="true" width="0">
1680 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
1681 <row topline="true" bottomline="true">
1682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1692 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1702 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1712 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1723 <row topline="true">
1724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1732 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1742 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1750 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1763 <row topline="true">
1764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1779 $DATADIR/ $INCLUDE_DIR_SUFFIX
1782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1787 /usr/local/share/sdcc/include
1790 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1803 <row topline="true">
1804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1812 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1819 $DATADIR/$LIB_DIR_SUFFIX
1822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1827 /usr/local/share/sdcc/lib
1830 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1843 <row topline="true" bottomline="true">
1844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1852 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1867 /usr/local/share/sdcc/doc
1870 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1892 *compiler, preprocessor, assembler, and linker
1898 is auto-appended by the compiler, e.g.
1899 small, large, z80, ds390 etc
1902 The install paths can still be changed during `make install` with e.g.:
1905 make install prefix=$(HOME)/local/sdcc
1908 Of course this doesn't change the search paths compiled into the binaries.
1912 \begin_inset LatexCommand \index{Search path}
1919 Some search paths or parts of them are determined by configure variables
1924 , see section above).
1925 Further search paths are determined by environment variables during runtime.
1928 The paths searched when running the compiler are as follows (the first catch
1934 Binary files (preprocessor, assembler and linker)
1940 \begin_inset Tabular
1941 <lyxtabular version="3" rows="4" columns="3">
1943 <column alignment="block" valignment="top" leftline="true" width="0in">
1944 <column alignment="block" valignment="top" leftline="true" width="0in">
1945 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1946 <row topline="true" bottomline="true">
1947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1963 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1972 <row topline="true">
1973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1983 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1991 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2002 <row topline="true">
2003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2008 Path of argv[0] (if available)
2011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2028 <row topline="true" bottomline="true">
2029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2070 \begin_inset Tabular
2071 <lyxtabular version="3" rows="6" columns="3">
2073 <column alignment="left" valignment="top" leftline="true" width="0">
2074 <column alignment="left" valignment="top" leftline="true" width="0">
2075 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
2076 <row topline="true" bottomline="true">
2077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2102 <row topline="true">
2103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2139 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2158 <row topline="true">
2159 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2186 <row topline="true">
2187 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2196 $PREFIX2DATA_DIR/$INCLUDE_DIR_SUFFIX
2199 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2206 $SDCC_ HOME/share/sdcc/include
2209 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2222 <row topline="true">
2223 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2232 $BIN2DATADIR/$INCLUDE_DIR_SUFFIX
2235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2240 path(argv[0])/../sdcc/include
2243 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2256 <row topline="true" bottomline="true">
2257 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2265 $DATADIR/$INCLUDE_DIR_SUFFIX
2268 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2273 /usr/local/share/sdcc/include
2276 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2304 -nostdinc disables the last two search paths.
2314 With the exception of
2315 \begin_inset Quotes sld
2329 \begin_inset Quotes srd
2336 is auto-appended by the compiler (e.g.
2337 small, large, z80, ds390 etc.).
2344 \begin_inset Tabular
2345 <lyxtabular version="3" rows="6" columns="3">
2347 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2348 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2349 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2350 <row topline="true" bottomline="true">
2351 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2359 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2367 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2376 <row topline="true">
2377 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2395 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2413 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2432 <row topline="true">
2433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2445 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2457 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2472 <row topline="true">
2473 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2484 $LIB_DIR_SUFFIX/<model>
2487 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2501 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2518 <row topline="true">
2519 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2534 $LIB_DIR_SUFFIX/<model>
2537 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2590 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2646 <row topline="true" bottomline="true">
2647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2656 $LIB_DIR_SUFFIX/<model>
2659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2664 /usr/local/share/sdcc/
2671 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2689 Don't delete any of the stray spaces in the table above without checking
2690 the HTML output (last line)!
2706 -nostdlib disables the last two search paths.
2710 \begin_inset LatexCommand \index{Building SDCC}
2715 \layout Subsubsection
2717 Building SDCC on Linux
2718 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
2727 Download the source package
2729 either from the SDCC CVS repository or from the
2730 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
2736 , it will be named something like sdcc
2749 Bring up a command line terminal, such as xterm.
2754 Unpack the file using a command like:
2757 "tar -xzf sdcc.src.tar.gz
2762 , this will create a sub-directory called sdcc with all of the sources.
2765 Change directory into the main SDCC directory, for example type:
2782 This configures the package for compilation on your system.
2798 All of the source packages will compile, this can take a while.
2814 This copies the binary executables, the include files, the libraries and
2815 the documentation to the install directories.
2816 \layout Subsubsection
2818 Building SDCC on OSX 2.x
2821 Follow the instruction for Linux.
2825 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
2826 )) fails to compile SDCC.
2827 Fortunately there's also gcc 2.9.x installed, which works fine.
2828 This compiler can be selected by running 'configure' with:
2831 ./configure CC=gcc2 CXX=g++2
2832 \layout Subsubsection
2834 Cross compiling SDCC on Linux for Windows
2837 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
2838 See section 'Configure Options'.
2839 \layout Subsubsection
2841 Building SDCC on Windows
2844 With the exception of Cygwin the SDCC binaries uCsim and sdcdb can't be
2846 They use Unix-sockets, which are not available on Win32.
2847 \layout Subsubsection
2849 Building SDCC using Cygwin and Mingw32
2852 For building and installing a Cygwin executable follow the instructions
2858 \begin_inset Quotes sld
2862 \begin_inset Quotes srd
2865 Win32-binary can be built, which will not need the Cygwin-DLL.
2866 For the necessary 'configure' options see section 'configure options' or
2867 the script 'sdcc/support/scripts/sdcc_cygwinmingw32'.
2871 In order to install Cygwin on Windows download setup.exe from
2872 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
2878 \begin_inset Quotes sld
2881 default text file type
2882 \begin_inset Quotes srd
2886 \begin_inset Quotes sld
2890 \begin_inset Quotes srd
2893 and download/install at least the following packages.
2894 Some packages are selected by default, others will be automatically selected
2895 because of dependencies with the manually selected packages.
2896 Never deselect these packages!
2905 gcc ; version 3.x is fine, no need to use the old 2.9x
2908 binutils ; selected with gcc
2914 rxvt ; a nice console, which makes life much easier under windoze (see below)
2917 man ; not really needed for building SDCC, but you'll miss it sooner or
2921 less ; not really needed for building SDCC, but you'll miss it sooner or
2925 cvs ; only if you use CVS access
2928 If you want to develop something you'll need:
2931 python ; for the regression tests
2934 gdb ; the gnu debugger, together with the nice GUI
2935 \begin_inset Quotes sld
2939 \begin_inset Quotes srd
2945 openssh ; to access the CF or commit changes
2948 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
2949 use autoconf-stable!
2952 rxvt is a nice console with history.
2953 Replace in your cygwin.bat the line
2972 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
2975 -bg black -fg white -geometry 100x65 -e bash -
2988 Text selected with the mouse is automatically copied to the clipboard, pasting
2989 works with shift-insert.
2993 The other good tip is to make sure you have no //c/-style paths anywhere,
2994 use /cygdrive/c/ instead.
2995 Using // invokes a network lookup which is very slow.
2997 \begin_inset Quotes sld
3001 \begin_inset Quotes srd
3004 is too long, you can change it with e.g.
3010 SDCC sources use the unix line ending LF.
3011 Life is much easier, if you store the source tree on a drive which is mounted
3013 And use an editor which can handle LF-only line endings.
3014 Make sure not to commit files with windows line endings.
3015 The tabulator spacing used in the project is 8.
3016 \layout Subsubsection
3018 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3023 Download the source package
3025 either from the SDCC CVS repository or from the
3026 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3032 , it will be named something like sdcc
3039 SDCC is distributed with all the projects, workspaces, and files you need
3040 to build it using Visual C++ 6.0/NET (except for sdcdb.exe which currently
3041 doesn't build under MSVC).
3042 The workspace name is 'sdcc.dsw'.
3043 Please note that as it is now, all the executables are created in a folder
3047 Once built you need to copy the executables from sdcc
3051 bin before running SDCC.
3056 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3057 flex.exe, and gawk.exe.
3058 One good place to get them is
3059 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3067 Download the file UnxUtils
3068 \begin_inset LatexCommand \index{UnxUtils}
3073 Now you have to install the utilities and setup MSVC so it can locate the
3075 Here there are two alternatives (choose one!):
3082 a) Extract UnxUtils.zip to your C:
3084 hard disk PRESERVING the original paths, otherwise bison won't work.
3085 (If you are using WinZip make certain that 'Use folder names' is selected)
3089 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3090 in 'Show directories for:' select 'Executable files', and in the directories
3091 window add a new path: 'C:
3101 (As a side effect, you get a bunch of Unix utilities that could be useful,
3102 such as diff and patch.)
3109 This one avoids extracting a bunch of files you may not use, but requires
3114 a) Create a directory were to put the tools needed, or use a directory already
3122 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3123 to such directory WITHOUT preserving the original paths.
3124 (If you are using WinZip make certain that 'Use folder names' is not selected)
3128 c) Rename bison.exe to '_bison.exe'.
3132 d) Create a batch file 'bison.bat' in 'C:
3136 ' and add these lines:
3156 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3160 Steps 'c' and 'd' are needed because bison requires by default that the
3161 files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3162 '/usr/local/share/' I think.
3163 So it is necessary to tell bison where those files are located if they
3164 are not in such directory.
3165 That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3169 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3170 in 'Show directories for:' select 'Executable files', and in the directories
3171 window add a new path: 'c:
3174 Note that you can use any other path instead of 'c:
3176 util', even the path where the Visual C++ tools are, probably: 'C:
3180 Microsoft Visual Studio
3185 So you don't have to execute step 'e' :)
3189 Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3190 the executables from sdcc
3194 bin, and you can compile using sdcc.
3195 \layout Subsubsection
3197 Building SDCC Using Borland
3200 From the sdcc directory, run the command "make -f Makefile.bcc".
3201 This should regenerate all the .exe files in the bin directory except for
3202 sdcdb.exe (which currently doesn't build under Borland C++).
3205 If you modify any source files and need to rebuild, be aware that the dependenci
3206 es may not be correctly calculated.
3207 The safest option is to delete all .obj files and run the build again.
3208 From a Cygwin BASH prompt, this can easily be done with the command (be
3209 sure you are in the sdcc directory):
3219 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul'
3221 ) -print -exec rm {}
3230 or on Windows NT/2000/XP from the command prompt with the command:
3237 del /s *.obj *.lib *.rul
3240 from the sdcc directory.
3241 \layout Subsubsection
3243 Windows Install Using a Binary Package
3244 \begin_inset LatexCommand \label{sub:Windows-Install}
3251 Download the binary package from
3252 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3256 and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
3257 This should unpack to a group of sub-directories.
3258 An example directory structure after unpacking the mingw32 package is:
3263 bin for the executables, c:
3271 lib for the include and libraries.
3274 Adjust your environment variable PATH to include the location of the bin
3275 directory or start sdcc using the full path.
3278 Building the Documentation
3281 If the necessary tools are installed it is as easy as changing into the
3282 doc directory and typing
3286 \begin_inset Quotes srd
3290 \begin_inset Quotes srd
3297 If you want to avoid installing the tools you will have some success with
3298 a bootable Knoppix CD
3299 \begin_inset LatexCommand \url{http://www.knopper.net}
3306 Testing the SDCC Compiler
3309 The first thing you should do after installing your SDCC compiler is to
3325 \begin_inset LatexCommand \index{version}
3332 at the prompt, and the program should run and tell you the version.
3333 If it doesn't run, or gives a message about not finding sdcc program, then
3334 you need to check over your installation.
3335 Make sure that the sdcc bin directory is in your executable search path
3336 defined by the PATH environment setting (see the Trouble-shooting section
3338 Make sure that the sdcc program is in the bin folder, if not perhaps something
3339 did not install correctly.
3347 is commonly installed as described in section
3348 \begin_inset Quotes sld
3351 Install and search paths
3352 \begin_inset Quotes srd
3361 Make sure the compiler works on a very simple example.
3362 Type in the following test.c program using your favorite
3388 Compile this using the following command:
3397 If all goes well, the compiler will generate a test.asm and test.rel file.
3398 Congratulations, you've just compiled your first program with SDCC.
3399 We used the -c option to tell SDCC not to link the generated code, just
3400 to keep things simple for this step.
3408 The next step is to try it with the linker.
3418 If all goes well the compiler will link with the libraries and produce
3419 a test.ihx output file.
3424 (no test.ihx, and the linker generates warnings), then the problem is most
3425 likely that sdcc cannot find the
3429 usr/local/share/sdcc/lib directory
3433 (see the Install trouble-shooting section for suggestions).
3441 The final test is to ensure sdcc can use the
3445 header files and libraries.
3446 Edit test.c and change it to the following:
3463 strcpy(str1, "testing");
3470 Compile this by typing
3477 This should generate a test.ihx output file, and it should give no warnings
3478 such as not finding the string.h file.
3479 If it cannot find the string.h file, then the problem is that sdcc cannot
3480 find the /usr/local/share/sdcc/include directory
3484 (see the Install trouble-shooting section for suggestions).
3502 \begin_inset LatexCommand \index{-\/-print-search-dirs}
3506 to find exactly where SDCC is looking for the include and lib files.
3509 Install Trouble-shooting
3510 \begin_inset LatexCommand \index{Install trouble-shooting}
3515 \layout Subsubsection
3517 SDCC does not build correctly.
3520 A thing to try is starting from scratch by unpacking the .tgz source package
3521 again in an empty directory.
3529 ./configure 2>&1 | tee configure.log
3543 make 2>&1 | tee make.log
3550 If anything goes wrong, you can review the log files to locate the problem.
3551 Or a relevant part of this can be attached to an email that could be helpful
3552 when requesting help from the mailing list.
3553 \layout Subsubsection
3556 \begin_inset Quotes sld
3560 \begin_inset Quotes srd
3567 \begin_inset Quotes sld
3571 \begin_inset Quotes srd
3574 command is a script that analyzes your system and performs some configuration
3575 to ensure the source package compiles on your system.
3576 It will take a few minutes to run, and will compile a few tests to determine
3577 what compiler features are installed.
3578 \layout Subsubsection
3581 \begin_inset Quotes sld
3585 \begin_inset Quotes srd
3591 This runs the GNU make tool, which automatically compiles all the source
3592 packages into the final installed binary executables.
3593 \layout Subsubsection
3596 \begin_inset Quotes sld
3600 \begin_inset Quotes erd
3606 This will install the compiler, other executables libraries and include
3607 files into the appropriate directories.
3609 \begin_inset Quotes sld
3612 Install and Search PATHS
3613 \begin_inset Quotes srd
3618 On most systems you will need super-user privileges to do this.
3624 SDCC is not just a compiler, but a collection of tools by various developers.
3625 These include linkers, assemblers, simulators and other components.
3626 Here is a summary of some of the components.
3627 Note that the included simulator and assembler have separate documentation
3628 which you can find in the source package in their respective directories.
3629 As SDCC grows to include support for other processors, other packages from
3630 various developers are included and may have their own sets of documentation.
3634 You might want to look at the files which are installed in <installdir>.
3635 At the time of this writing, we find the following programs for gcc-builds:
3639 In <installdir>/bin:
3642 sdcc - The compiler.
3645 sdcpp - The C preprocessor.
3648 asx8051 - The assembler for 8051 type processors.
3655 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
3658 aslink -The linker for 8051 type processors.
3665 link-gbz80 - The Z80 and GameBoy Z80 linkers.
3668 s51 - The ucSim 8051 simulator.
3671 sdcdb - The source debugger.
3674 packihx - A tool to pack (compress) Intel hex files.
3677 In <installdir>/share/sdcc/include
3683 In <installdir>/share/sdcc/lib
3686 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
3690 In <installdir>/share/sdcc/doc
3696 As development for other processors proceeds, this list will expand to include
3697 executables to support processors like AVR, PIC, etc.
3698 \layout Subsubsection
3703 This is the actual compiler, it in turn uses the c-preprocessor and invokes
3704 the assembler and linkage editor.
3705 \layout Subsubsection
3708 \begin_inset LatexCommand \index{sdcpp}
3712 - The C-Preprocessor
3715 The preprocessor is a modified version of the GNU preprocessor.
3716 The C preprocessor is used to pull in #include sources, process #ifdef
3717 statements, #defines and so on.
3718 \layout Subsubsection
3720 asx8051, as-z80, as-gbz80, aslink, link-z80, link-gbz80 - The Assemblers
3724 This is retargettable assembler & linkage editor, it was developed by Alan
3726 John Hartman created the version for 8051, and I (Sandeep) have made some
3727 enhancements and bug fixes for it to work properly with SDCC.
3728 \layout Subsubsection
3731 \begin_inset LatexCommand \index{s51}
3738 S51 is a freeware, opensource simulator developed by Daniel Drotos (
3739 \begin_inset LatexCommand \url{mailto:drdani@mazsola.iit.uni-miskolc.hu}
3744 The simulator is built as part of the build process.
3745 For more information visit Daniel's web site at:
3746 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
3751 It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
3753 \layout Subsubsection
3756 \begin_inset LatexCommand \index{sdcdb}
3760 - Source Level Debugger
3763 Sdcdb is the companion source level debugger.
3764 The current version of the debugger uses Daniel's Simulator S51
3765 \begin_inset LatexCommand \index{s51}
3769 , but can be easily changed to use other simulators.
3776 \layout Subsubsection
3778 Single Source File Projects
3781 For single source file 8051 projects the process is very simple.
3782 Compile your programs with the following command
3785 "sdcc sourcefile.c".
3789 This will compile, assemble and link your source file.
3790 Output files are as follows
3794 \begin_inset LatexCommand \index{.asm}
3799 \begin_inset LatexCommand \index{Assembler source}
3803 file created by the compiler
3807 \begin_inset LatexCommand \index{.lst}
3812 \begin_inset LatexCommand \index{Assembler listing}
3816 file created by the Assembler
3820 \begin_inset LatexCommand \index{.rst}
3825 \begin_inset LatexCommand \index{Assembler listing}
3829 file updated with linkedit information, created by linkage editor
3833 \begin_inset LatexCommand \index{.sym}
3838 \begin_inset LatexCommand \index{Symbol listing}
3842 for the sourcefile, created by the assembler
3846 \begin_inset LatexCommand \index{.rel}
3851 \begin_inset LatexCommand \index{Object file}
3855 created by the assembler, input to Linkage editor
3859 \begin_inset LatexCommand \index{.map}
3864 \begin_inset LatexCommand \index{Memory map}
3868 for the load module, created by the Linker
3872 \begin_inset LatexCommand \index{.mem}
3876 - A file with a summary of the memory usage
3880 \begin_inset LatexCommand \index{.ihx}
3884 - The load module in Intel hex format
3885 \begin_inset LatexCommand \index{Intel hex format}
3889 (you can select the Motorola S19 format
3890 \begin_inset LatexCommand \index{Motorola S19 format}
3905 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
3910 If you need another format you might want to use
3917 \begin_inset LatexCommand \index{objdump}
3928 \begin_inset LatexCommand \index{srecord}
3936 \begin_inset LatexCommand \index{.adb}
3940 - An intermediate file containing debug information needed to create the
3952 \begin_inset LatexCommand \index{-\/-debug}
3960 \begin_inset LatexCommand \index{.cdb}
3964 - An optional file (with -
3974 -debug) containing debug information
3979 \begin_inset LatexCommand \index{. (no extension)}
3984 \begin_inset LatexCommand \index{AOMF51}
3988 file containing debug information (with -
3999 This format is commonly used by third party tools (debuggers
4000 \begin_inset LatexCommand \index{Debugger}
4004 , simulators, emulators)
4008 \begin_inset LatexCommand \index{.dump*}
4012 - Dump file to debug the compiler it self (with -
4022 -dumpall) (see section
4023 \begin_inset Quotes sld
4026 Anatomy of the compiler
4027 \begin_inset Quotes srd
4031 \layout Subsubsection
4033 Projects with Multiple Source Files
4036 SDCC can compile only ONE file at a time.
4037 Let us for example assume that you have a project containing the following
4042 foo1.c (contains some functions)
4044 foo2.c (contains some more functions)
4046 foomain.c (contains more functions and the function main)
4054 The first two files will need to be compiled separately with the commands:
4086 Then compile the source file containing the
4091 \begin_inset LatexCommand \index{Linker}
4095 the files together with the following command:
4103 foomain.c\SpecialChar ~
4104 foo1.rel\SpecialChar ~
4109 \begin_inset LatexCommand \index{.rel}
4121 can be separately compiled as well:
4132 sdcc foomain.rel foo1.rel foo2.rel
4139 The file containing the
4154 file specified in the command line, since the linkage editor processes
4155 file in the order they are presented to it.
4156 The linker is invoked from sdcc using a script file with extension .lnk
4157 \begin_inset LatexCommand \index{.lnk}
4162 You can view this file to troubleshoot linking problems such as those arising
4163 from missing libraries.
4164 \layout Subsubsection
4166 Projects with Additional Libraries
4167 \begin_inset LatexCommand \index{Libraries}
4174 Some reusable routines may be compiled into a library, see the documentation
4175 for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
4179 \begin_inset LatexCommand \index{.lib}
4186 Libraries created in this manner can be included in the command line.
4187 Make sure you include the -L <library-path> option to tell the linker where
4188 to look for these files if they are not in the current directory.
4189 Here is an example, assuming you have the source file
4201 (if that is not the same as your current project):
4208 sdcc foomain.c foolib.lib -L mylib
4219 must be an absolute path name.
4223 The most efficient way to use libraries is to keep separate modules in separate
4225 The lib file now should name all the modules.rel
4226 \begin_inset LatexCommand \index{rel}
4231 For an example see the standard library file
4235 in the directory <installdir>/share/lib/small.
4238 Command Line Options
4239 \begin_inset LatexCommand \index{Command Line Options}
4244 \layout Subsubsection
4246 Processor Selection Options
4247 \begin_inset LatexCommand \index{Options processor selection}
4252 \begin_inset LatexCommand \index{Processor selection options}
4258 \labelwidthstring 00.00.0000
4263 \begin_inset LatexCommand \index{-mmcs51}
4269 Generate code for the Intel MCS51
4270 \begin_inset LatexCommand \index{MCS51}
4274 family of processors.
4275 This is the default processor target.
4277 \labelwidthstring 00.00.0000
4282 \begin_inset LatexCommand \index{-mds390}
4288 Generate code for the Dallas DS80C390
4289 \begin_inset LatexCommand \index{DS80C390}
4295 \labelwidthstring 00.00.0000
4300 \begin_inset LatexCommand \index{-mds400}
4306 Generate code for the Dallas DS80C400
4307 \begin_inset LatexCommand \index{DS80C400}
4313 \labelwidthstring 00.00.0000
4318 \begin_inset LatexCommand \index{-mz80}
4324 Generate code for the Zilog Z80
4325 \begin_inset LatexCommand \index{Z80}
4329 family of processors.
4331 \labelwidthstring 00.00.0000
4336 \begin_inset LatexCommand \index{-mgbz80}
4342 Generate code for the GameBoy Z80
4343 \begin_inset LatexCommand \index{GameBoy Z80}
4349 \labelwidthstring 00.00.0000
4354 \begin_inset LatexCommand \index{-mavr}
4360 Generate code for the Atmel AVR
4361 \begin_inset LatexCommand \index{AVR}
4365 processor (In development, not complete).
4366 AVR users should probably have a look at avr-gcc
4367 \begin_inset LatexCommand \url{ http://savannah.nongnu.org/download/avr-libc/snapshots/}
4374 I think it is fair to direct users there for now.
4375 Open source is also about avoiding unnecessary work .
4376 But I didn't find the 'official' link.
4378 \labelwidthstring 00.00.0000
4383 \begin_inset LatexCommand \index{-mpic14}
4389 Generate code for the Microchip PIC 14
4390 \begin_inset LatexCommand \index{PIC14}
4394 -bit processors (p16f84 and variants).
4397 p16f627 p16f628 p16f84 p16f873 p16f877?
4399 \labelwidthstring 00.00.0000
4404 \begin_inset LatexCommand \index{-mpic16}
4410 Generate code for the Microchip PIC 16
4411 \begin_inset LatexCommand \index{PIC16}
4415 -bit processors (p18f452 and variants).
4417 \labelwidthstring 00.00.0000
4423 Generate code for the Toshiba TLCS-900H
4424 \begin_inset LatexCommand \index{TLCS-900H}
4428 processor (In development, not complete).
4430 \labelwidthstring 00.00.0000
4435 \begin_inset LatexCommand \index{-mxa51}
4441 Generate code for the Phillips XA51
4442 \begin_inset LatexCommand \index{XA51}
4446 processor (In development, not complete).
4447 \layout Subsubsection
4449 Preprocessor Options
4450 \begin_inset LatexCommand \index{Options preprocessor}
4455 \begin_inset LatexCommand \index{Preprocessor options}
4461 \labelwidthstring 00.00.0000
4466 \begin_inset LatexCommand \index{-I<path>}
4472 The additional location where the pre processor will look for <..h> or
4473 \begin_inset Quotes eld
4477 \begin_inset Quotes erd
4482 \labelwidthstring 00.00.0000
4487 \begin_inset LatexCommand \index{-D<macro[=value]>}
4493 Command line definition of macros.
4494 Passed to the preprocessor.
4496 \labelwidthstring 00.00.0000
4501 \begin_inset LatexCommand \index{-M}
4507 Tell the preprocessor to output a rule suitable for make describing the
4508 dependencies of each object file.
4509 For each source file, the preprocessor outputs one make-rule whose target
4510 is the object file name for that source file and whose dependencies are
4511 all the files `#include'd in it.
4512 This rule may be a single line or may be continued with `
4514 '-newline if it is long.
4515 The list of rules is printed on standard output instead of the preprocessed
4518 \begin_inset LatexCommand \index{-E}
4524 \labelwidthstring 00.00.0000
4529 \begin_inset LatexCommand \index{-C}
4535 Tell the preprocessor not to discard comments.
4536 Used with the `-E' option.
4538 \labelwidthstring 00.00.0000
4543 \begin_inset LatexCommand \index{-MM}
4554 Like `-M' but the output mentions only the user header files included with
4556 \begin_inset Quotes eld
4560 System header files included with `#include <file>' are omitted.
4562 \labelwidthstring 00.00.0000
4567 \begin_inset LatexCommand \index{-Aquestion(answer)}
4573 Assert the answer answer for question, in case it is tested with a preprocessor
4574 conditional such as `#if #question(answer)'.
4575 `-A-' disables the standard assertions that normally describe the target
4578 \labelwidthstring 00.00.0000
4583 \begin_inset LatexCommand \index{-Umacro}
4589 Undefine macro macro.
4590 `-U' options are evaluated after all `-D' options, but before any `-include'
4591 and `-imacros' options.
4593 \labelwidthstring 00.00.0000
4598 \begin_inset LatexCommand \index{-dM}
4604 Tell the preprocessor to output only a list of the macro definitions that
4605 are in effect at the end of preprocessing.
4606 Used with the `-E' option.
4608 \labelwidthstring 00.00.0000
4613 \begin_inset LatexCommand \index{-dD}
4619 Tell the preprocessor to pass all macro definitions into the output, in
4620 their proper sequence in the rest of the output.
4622 \labelwidthstring 00.00.0000
4627 \begin_inset LatexCommand \index{-dN}
4638 Like `-dD' except that the macro arguments and contents are omitted.
4639 Only `#define name' is included in the output.
4640 \layout Subsubsection
4643 \begin_inset LatexCommand \index{Options linker}
4648 \begin_inset LatexCommand \index{Linker options}
4654 \labelwidthstring 00.00.0000
4674 \begin_inset LatexCommand \index{-\/-lib-path}
4679 \begin_inset LatexCommand \index{-L -\/-lib-path}
4688 <absolute path to additional libraries> This option is passed to the linkage
4689 editor's additional libraries
4690 \begin_inset LatexCommand \index{Libraries}
4695 The path name must be absolute.
4696 Additional library files may be specified in the command line.
4697 See section Compiling programs for more details.
4699 \labelwidthstring 00.00.0000
4716 \begin_inset LatexCommand \index{-\/-xram-loc}
4720 <Value> The start location of the external ram
4721 \begin_inset LatexCommand \index{xdata}
4725 , default value is 0.
4726 The value entered can be in Hexadecimal or Decimal format, e.g.: -
4736 -xram-loc 0x8000 or -
4748 \labelwidthstring 00.00.0000
4765 \begin_inset LatexCommand \index{-\/-code-loc}
4769 <Value> The start location of the code
4770 \begin_inset LatexCommand \index{code}
4774 segment, default value 0.
4775 Note when this option is used the interrupt vector table is also relocated
4776 to the given address.
4777 The value entered can be in Hexadecimal or Decimal format, e.g.: -
4787 -code-loc 0x8000 or -
4799 \labelwidthstring 00.00.0000
4816 \begin_inset LatexCommand \index{-\/-stack-loc}
4820 <Value> By default the stack
4821 \begin_inset LatexCommand \index{stack}
4825 is placed after the data segment.
4826 Using this option the stack can be placed anywhere in the internal memory
4828 The value entered can be in Hexadecimal or Decimal format, e.g.
4839 -stack-loc 0x20 or -
4850 Since the sp register is incremented before a push or call, the initial
4851 sp will be set to one byte prior the provided value.
4852 The provided value should not overlap any other memory areas such as used
4853 register banks or the data segment and with enough space for the current
4856 \labelwidthstring 00.00.0000
4873 \begin_inset LatexCommand \index{-\/-data-loc}
4877 <Value> The start location of the internal ram data
4878 \begin_inset LatexCommand \index{data}
4883 The value entered can be in Hexadecimal or Decimal format, eg.
4905 (By default, the start location of the internal ram data segment is set
4906 as low as possible in memory, taking into account the used register banks
4907 and the bit segment at address 0x20.
4908 For example if register banks 0 and 1 are used without bit variables, the
4909 data segment will be set, if -
4919 -data-loc is not used, to location 0x10.)
4921 \labelwidthstring 00.00.0000
4938 \begin_inset LatexCommand \index{-\/-idata-loc}
4942 <Value> The start location of the indirectly addressable internal ram
4943 \begin_inset LatexCommand \index{idata}
4947 , default value is 0x80.
4948 The value entered can be in Hexadecimal or Decimal format, eg.
4959 -idata-loc 0x88 or -
4971 \labelwidthstring 00.00.0000
4986 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
4995 The linker output (final object code) is in Intel Hex format.
4996 \begin_inset LatexCommand \index{Intel hex format}
5000 (This is the default option).
5002 \labelwidthstring 00.00.0000
5017 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5026 The linker output (final object code) is in Motorola S19 format
5027 \begin_inset LatexCommand \index{Motorola S19 format}
5032 \layout Subsubsection
5035 \begin_inset LatexCommand \index{Options MCS51}
5040 \begin_inset LatexCommand \index{MCS51 options}
5046 \labelwidthstring 00.00.0000
5061 \begin_inset LatexCommand \index{-\/-model-small}
5072 Generate code for Small Model programs see section Memory Models for more
5074 This is the default model.
5076 \labelwidthstring 00.00.0000
5091 \begin_inset LatexCommand \index{-\/-model-large}
5097 Generate code for Large model programs see section Memory Models for more
5099 If this option is used all source files in the project should be compiled
5102 \labelwidthstring 00.00.0000
5117 \begin_inset LatexCommand \index{-\/-xstack}
5123 Uses a pseudo stack in the first 256 bytes in the external ram for allocating
5124 variables and passing parameters.
5125 See section on external stack for more details.
5127 \labelwidthstring 00.00.0000
5144 \begin_inset LatexCommand \index{-\/-iram-size<Value>}
5148 Causes the linker to check if the internal ram usage is within limits of
5151 \labelwidthstring 00.00.0000
5168 \begin_inset LatexCommand \index{-\/-xram-size<Value>}
5172 Causes the linker to check if the external ram usage is within limits of
5175 \labelwidthstring 00.00.0000
5192 \begin_inset LatexCommand \index{-\/-data-loc}
5196 Causes the linker to check if the code memory usage is within limits of
5198 \layout Subsubsection
5201 \begin_inset LatexCommand \index{Options DS390}
5206 \begin_inset LatexCommand \index{DS390 options}
5212 \labelwidthstring 00.00.0000
5229 \begin_inset LatexCommand \index{-\/-model-flat24}
5239 Generate 24-bit flat mode code.
5240 This is the one and only that the ds390 code generator supports right now
5241 and is default when using
5246 See section Memory Models for more details.
5248 \labelwidthstring 00.00.0000
5265 \begin_inset LatexCommand \index{-\/-stack-10bit}
5269 Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
5270 This is the one and only that the ds390 code generator supports right now
5271 and is default when using
5276 In this mode, the stack is located in the lower 1K of the internal RAM,
5277 which is mapped to 0x400000.
5278 Note that the support is incomplete, since it still uses a single byte
5279 as the stack pointer.
5280 This means that only the lower 256 bytes of the potential 1K stack space
5281 will actually be used.
5282 However, this does allow you to reclaim the precious 256 bytes of low RAM
5283 for use for the DATA and IDATA segments.
5284 The compiler will not generate any code to put the processor into 10 bit
5286 It is important to ensure that the processor is in this mode before calling
5287 any re-entrant functions compiled with this option.
5288 In principle, this should work with the
5301 \begin_inset LatexCommand \index{-\/-stack-auto}
5307 option, but that has not been tested.
5308 It is incompatible with the
5321 \begin_inset LatexCommand \index{-\/-xstack}
5328 It also only makes sense if the processor is in 24 bit contiguous addressing
5341 -model-flat24 option
5344 \layout Subsubsection
5347 \begin_inset LatexCommand \index{Options Z80}
5352 \begin_inset LatexCommand \index{Z80 options}
5358 \labelwidthstring 00.00.0000
5375 \begin_inset LatexCommand \index{-\/-callee-saves-bc}
5385 Force a called function to always save BC.
5387 \labelwidthstring 00.00.0000
5404 \begin_inset LatexCommand \index{-\/-no-std-crt0}
5408 When linking, skip the standard crt0.o object file.
5409 You must provide your own crt0.o for your system when linking.
5411 \layout Subsubsection
5413 Optimization Options
5414 \begin_inset LatexCommand \index{Options optimization}
5419 \begin_inset LatexCommand \index{Optimization options}
5425 \labelwidthstring 00.00.0000
5440 \begin_inset LatexCommand \index{-\/-nogcse}
5446 Will not do global subexpression elimination, this option may be used when
5447 the compiler creates undesirably large stack/data spaces to store compiler
5449 A warning message will be generated when this happens and the compiler
5450 will indicate the number of extra bytes it allocated.
5451 It recommended that this option NOT be used, #pragma\SpecialChar ~
5453 \begin_inset LatexCommand \index{\#pragma NOGCSE}
5457 can be used to turn off global subexpression elimination
5458 \begin_inset LatexCommand \index{Subexpression elimination}
5462 for a given function only.
5464 \labelwidthstring 00.00.0000
5479 \begin_inset LatexCommand \index{-\/-noinvariant}
5485 Will not do loop invariant optimizations, this may be turned off for reasons
5486 explained for the previous option.
5487 For more details of loop optimizations performed see section Loop Invariants.It
5488 recommended that this option NOT be used, #pragma\SpecialChar ~
5490 \begin_inset LatexCommand \index{\#pragma NOINVARIANT}
5494 can be used to turn off invariant optimizations for a given function only.
5496 \labelwidthstring 00.00.0000
5511 \begin_inset LatexCommand \index{-\/-noinduction}
5517 Will not do loop induction optimizations, see section strength reduction
5518 for more details.It is recommended that this option is NOT used, #pragma\SpecialChar ~
5521 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
5525 can be used to turn off induction optimizations for a given function only.
5527 \labelwidthstring 00.00.0000
5542 \begin_inset LatexCommand \index{-\/-nojtbound}
5553 Will not generate boundary condition check when switch statements
5554 \begin_inset LatexCommand \index{switch statement}
5558 are implemented using jump-tables.
5559 See section Switch Statements for more details.
5560 It is recommended that this option is NOT used, #pragma\SpecialChar ~
5562 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
5566 can be used to turn off boundary checking for jump tables for a given function
5569 \labelwidthstring 00.00.0000
5584 \begin_inset LatexCommand \index{-\/-noloopreverse}
5593 Will not do loop reversal
5594 \begin_inset LatexCommand \index{Loop reversing}
5600 \labelwidthstring 00.00.0000
5617 \begin_inset LatexCommand \index{-\/-nolabelopt }
5621 Will not optimize labels (makes the dumpfiles more readable).
5623 \labelwidthstring 00.00.0000
5638 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
5644 Will not memcpy initialized data from code space into xdata space.
5645 This saves a few bytes in code space if you don't have initialized data.
5646 \layout Subsubsection
5649 \begin_inset LatexCommand \index{Options other}
5655 \labelwidthstring 00.00.0000
5671 \begin_inset LatexCommand \index{-\/-compile-only}
5676 \begin_inset LatexCommand \index{-c -\/-compile-only}
5682 will compile and assemble the source, but will not call the linkage editor.
5684 \labelwidthstring 00.00.0000
5703 \begin_inset LatexCommand \index{-\/-c1mode}
5709 reads the preprocessed source from standard input and compiles it.
5710 The file name for the assembler output must be specified using the -o option.
5712 \labelwidthstring 00.00.0000
5717 \begin_inset LatexCommand \index{-E}
5723 Run only the C preprocessor.
5724 Preprocess all the C source files specified and output the results to standard
5727 \labelwidthstring 00.00.0000
5733 \begin_inset LatexCommand \index{-o <path/file>}
5739 The output path resp.
5740 file where everything will be placed.
5741 If the parameter is a path, it must have a trailing slash (or backslash
5742 for the Windows binaries) to be recognized as a path.
5745 \labelwidthstring 00.00.0000
5760 \begin_inset LatexCommand \index{-\/-stack-auto}
5771 All functions in the source file will be compiled as
5776 \begin_inset LatexCommand \index{reentrant}
5781 the parameters and local variables will be allocated on the stack
5782 \begin_inset LatexCommand \index{stack}
5787 see section Parameters and Local Variables for more details.
5788 If this option is used all source files in the project should be compiled
5792 \labelwidthstring 00.00.0000
5807 \begin_inset LatexCommand \index{-\/-callee-saves}
5811 function1[,function2][,function3]....
5814 The compiler by default uses a caller saves convention for register saving
5815 across function calls, however this can cause unnecessary register pushing
5816 & popping when calling small functions from larger functions.
5817 This option can be used to switch the register saving convention for the
5818 function names specified.
5819 The compiler will not save registers when calling these functions, no extra
5820 code will be generated at the entry & exit (function prologue
5823 \begin_inset LatexCommand \index{function prologue}
5832 \begin_inset LatexCommand \index{function epilogue}
5838 ) for these functions to save & restore the registers used by these functions,
5839 this can SUBSTANTIALLY reduce code & improve run time performance of the
5841 In the future the compiler (with inter procedural analysis) will be able
5842 to determine the appropriate scheme to use for each function call.
5843 DO NOT use this option for built-in functions such as _mulint..., if this
5844 option is used for a library function the appropriate library function
5845 needs to be recompiled with the same option.
5846 If the project consists of multiple source files then all the source file
5847 should be compiled with the same -
5857 -callee-saves option string.
5858 Also see #pragma\SpecialChar ~
5860 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
5866 \labelwidthstring 00.00.0000
5881 \begin_inset LatexCommand \index{-\/-debug}
5890 When this option is used the compiler will generate debug information, that
5891 can be used with the SDCDB.
5892 The debug information is collected in a file with .cdb extension.
5893 For more information see documentation for SDCDB.
5895 \labelwidthstring 00.00.0000
5900 \begin_inset LatexCommand \index{-S}
5911 Stop after the stage of compilation proper; do not assemble.
5912 The output is an assembler code file for the input file specified.
5914 \labelwidthstring 00.00.0000
5918 -Wa_asmOption[,asmOption]
5921 \begin_inset LatexCommand \index{-Wa\_asmOption[,asmOption]}
5926 Pass the asmOption to the assembler.
5928 \labelwidthstring 00.00.0000
5932 -Wl_linkOption[,linkOption]
5935 \begin_inset LatexCommand \index{-Wl\_linkOption[,linkOption]}
5940 Pass the linkOption to the linker.
5942 \labelwidthstring 00.00.0000
5957 \begin_inset LatexCommand \index{-\/-int-long-reent}
5963 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
5964 Note by default these libraries are compiled as non-reentrant.
5965 See section Installation for more details.
5967 \labelwidthstring 00.00.0000
5982 \begin_inset LatexCommand \index{-\/-cyclomatic}
5991 This option will cause the compiler to generate an information message for
5992 each function in the source file.
5993 The message contains some
5997 information about the function.
5998 The number of edges and nodes the compiler detected in the control flow
5999 graph of the function, and most importantly the
6001 cyclomatic complexity
6002 \begin_inset LatexCommand \index{Cyclomatic complexity}
6008 see section on Cyclomatic Complexity for more details.
6010 \labelwidthstring 00.00.0000
6025 \begin_inset LatexCommand \index{-\/-float-reent}
6034 Floating point library is compiled as reentrant
6035 \begin_inset LatexCommand \index{reentrant}
6040 See section Installation for more details.
6042 \labelwidthstring 00.00.0000
6057 \begin_inset LatexCommand \index{-\/-nooverlay}
6063 The compiler will not overlay parameters and local variables of any function,
6064 see section Parameters and local variables for more details.
6066 \labelwidthstring 00.00.0000
6081 \begin_inset LatexCommand \index{-\/-main-return}
6087 This option can be used when the code generated is called by a monitor
6089 The compiler will generate a 'ret' upon return from the 'main'
6090 \begin_inset LatexCommand \index{main return}
6095 The default option is to lock up i.e.
6102 \labelwidthstring 00.00.0000
6119 \begin_inset LatexCommand \index{-\/-peep-file}
6123 <filename> This option can be used to use additional rules to be used by
6124 the peep hole optimizer.
6125 See section Peep Hole optimizations for details on how to write these rules.
6127 \labelwidthstring 00.00.0000
6142 \begin_inset LatexCommand \index{-\/-no-peep}
6148 Disable peep-hole optimization.
6150 \labelwidthstring 00.00.0000
6165 \begin_inset LatexCommand \index{-\/-peep-asm}
6171 Pass the inline assembler code through the peep hole optimizer.
6172 This can cause unexpected changes to inline assembler code, please go through
6173 the peephole optimizer
6174 \begin_inset LatexCommand \index{Peephole optimizer}
6178 rules defined in the source file tree '<target>/peeph.def' before using
6181 \labelwidthstring 00.00.0000
6196 \begin_inset LatexCommand \index{-\/-nostdincl}
6202 This will prevent the compiler from passing on the default include path
6203 to the preprocessor.
6205 \labelwidthstring 00.00.0000
6220 \begin_inset LatexCommand \index{-\/-nostdlib}
6226 This will prevent the compiler from passing on the default library
6227 \begin_inset LatexCommand \index{Libraries}
6233 \labelwidthstring 00.00.0000
6248 \begin_inset LatexCommand \index{-\/-verbose}
6254 Shows the various actions the compiler is performing.
6256 \labelwidthstring 00.00.0000
6261 \begin_inset LatexCommand \index{-V}
6267 Shows the actual commands the compiler is executing.
6269 \labelwidthstring 00.00.0000
6284 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
6290 Hides your ugly and inefficient c-code from the asm file, so you can always
6291 blame the compiler :).
6293 \labelwidthstring 00.00.0000
6308 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
6314 Include i-codes in the asm file.
6315 Sounds like noise but is most helpful for debugging the compiler itself.
6317 \labelwidthstring 00.00.0000
6332 \begin_inset LatexCommand \index{-\/-less-pedantic}
6338 Disable some of the more pedantic warnings (jwk burps: please be more specific
6341 \labelwidthstring 00.00.0000
6356 \begin_inset LatexCommand \index{-\/-print-search-dirs}
6362 Display the directories in the compiler's search path
6364 \labelwidthstring 00.00.0000
6379 \begin_inset LatexCommand \index{-\/-vc}
6385 Display errors and warnings using MSVC style, so you can use SDCC with
6388 \labelwidthstring 00.00.0000
6403 \begin_inset LatexCommand \index{-\/-use-stdout}
6409 Send errors and warnings to stdout instead of stderr.
6410 \layout Subsubsection
6412 Intermediate Dump Options
6413 \begin_inset LatexCommand \index{Options intermediate dump}
6418 \begin_inset LatexCommand \index{Intermediate dump options}
6425 The following options are provided for the purpose of retargetting and debugging
6427 These provided a means to dump the intermediate code (iCode
6428 \begin_inset LatexCommand \index{iCode}
6432 ) generated by the compiler in human readable form at various stages of
6433 the compilation process.
6436 \labelwidthstring 00.00.0000
6451 \begin_inset LatexCommand \index{-\/-dumpraw}
6457 This option will cause the compiler to dump the intermediate code into
6460 <source filename>.dumpraw
6462 just after the intermediate code has been generated for a function, i.e.
6463 before any optimizations are done.
6465 \begin_inset LatexCommand \index{Basic blocks}
6469 at this stage ordered in the depth first number, so they may not be in
6470 sequence of execution.
6472 \labelwidthstring 00.00.0000
6487 \begin_inset LatexCommand \index{-\/-dumpgcse}
6493 Will create a dump of iCode's, after global subexpression elimination
6494 \begin_inset LatexCommand \index{Global subexpression elimination}
6500 <source filename>.dumpgcse.
6502 \labelwidthstring 00.00.0000
6517 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
6523 Will create a dump of iCode's, after deadcode elimination
6524 \begin_inset LatexCommand \index{Dead-code elimination}
6530 <source filename>.dumpdeadcode.
6532 \labelwidthstring 00.00.0000
6547 \begin_inset LatexCommand \index{-\/-dumploop}
6556 Will create a dump of iCode's, after loop optimizations
6557 \begin_inset LatexCommand \index{Loop optimization}
6563 <source filename>.dumploop.
6565 \labelwidthstring 00.00.0000
6580 \begin_inset LatexCommand \index{-\/-dumprange}
6589 Will create a dump of iCode's, after live range analysis
6590 \begin_inset LatexCommand \index{Live range analysis}
6596 <source filename>.dumprange.
6598 \labelwidthstring 00.00.0000
6613 \begin_inset LatexCommand \index{-\/-dumlrange}
6619 Will dump the life ranges
6620 \begin_inset LatexCommand \index{Live range analysis}
6626 \labelwidthstring 00.00.0000
6641 \begin_inset LatexCommand \index{-\/-dumpregassign}
6650 Will create a dump of iCode's, after register assignment
6651 \begin_inset LatexCommand \index{Register assignment}
6657 <source filename>.dumprassgn.
6659 \labelwidthstring 00.00.0000
6674 \begin_inset LatexCommand \index{-\/-dumplrange}
6680 Will create a dump of the live ranges of iTemp's
6682 \labelwidthstring 00.00.0000
6697 \begin_inset LatexCommand \index{-\/-dumpall}
6708 Will cause all the above mentioned dumps to be created.
6709 \layout Subsubsection
6711 Redirecting output on Windows Shells
6714 By default SDCC writes it's error messages to
6715 \begin_inset Quotes sld
6719 \begin_inset Quotes srd
6723 To force all messages to
6724 \begin_inset Quotes sld
6728 \begin_inset Quotes srd
6752 \begin_inset LatexCommand \index{-\/-use-stdout}
6757 Aditionaly, if you happen to have visual studio installed in your windows
6758 machine, you can use it to compile your sources using a custom build and
6774 \begin_inset LatexCommand \index{-\/-vc}
6779 Something like this should work:
6823 -model-large -c $(InputPath)
6826 Environment variables
6827 \begin_inset LatexCommand \index{Environment variables}
6834 SDCC recognizes the following environment variables:
6836 \labelwidthstring 00.00.0000
6841 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
6847 SDCC installs a signal handler
6848 \begin_inset LatexCommand \index{signal handler}
6852 to be able to delete temporary files after an user break (^C) or an exception.
6853 If this environment variable is set, SDCC won't install the signal handler
6854 in order to be able to debug SDCC.
6856 \labelwidthstring 00.00.0000
6863 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
6869 Path, where temporary files will be created.
6870 The order of the variables is the search order.
6871 In a standard *nix environment these variables are not set, and there's
6872 no need to set them.
6873 On Windows it's recommended to set one of them.
6875 \labelwidthstring 00.00.0000
6880 \begin_inset LatexCommand \index{SDCC\_HOME}
6887 \begin_inset Quotes sld
6890 2.3 Install and search paths
6891 \begin_inset Quotes srd
6896 \labelwidthstring 00.00.0000
6901 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
6908 \begin_inset Quotes sld
6911 2.3 Install and search paths
6912 \begin_inset Quotes srd
6917 \labelwidthstring 00.00.0000
6922 \begin_inset LatexCommand \index{SDCC\_LIB}
6929 \begin_inset Quotes sld
6932 2.3 Install and search paths
6933 \begin_inset Quotes srd
6939 There are some more environment variables recognized by SDCC, but these
6940 are solely used for debugging purposes.
6941 They can change or disappear very quickly, and will never be documented.
6944 MCS51/DS390 Storage Class
6945 \begin_inset LatexCommand \index{Storage class}
6952 In addition to the ANSI storage classes SDCC allows the following MCS51
6953 specific storage classes.
6954 \layout Subsubsection
6957 \begin_inset LatexCommand \index{data}
6968 storage class for Small Memory model.
6969 Variables declared with this storage class will be allocated in the directly
6970 addressable portion of the internal RAM of a 8051, e.g.:
6975 data unsigned char test_data;
6978 Writing 0x01 to this variable generates the assembly code:
6983 75*00 01\SpecialChar ~
6989 \layout Subsubsection
6992 \begin_inset LatexCommand \index{xdata}
6999 Variables declared with this storage class will be placed in the external
7005 storage class for Large Memory model, e.g.:
7010 xdata unsigned char test_xdata;
7013 Writing 0x01 to this variable generates the assembly code:
7018 90s00r00\SpecialChar ~
7047 \layout Subsubsection
7050 \begin_inset LatexCommand \index{idata}
7057 Variables declared with this storage class will be allocated into the indirectly
7058 addressable portion of the internal ram of a 8051, e.g.:
7063 idata unsigned char test_idata;
7066 Writing 0x01 to this variable generates the assembly code:
7093 \layout Subsubsection
7096 \begin_inset LatexCommand \index{pdata}
7103 Paged xdata access is currently not as straightforward as using the other
7104 addressing modes of a 8051.
7105 The following example writes 0x01 to the address pointed to.
7106 Please note, pdata access physically accesses xdata memory.
7107 The high byte of the address is determined by port P2 (or in case of some
7108 8051 variants by a separate Special Function Register).
7113 pdata unsigned char *test_pdata_ptr;
7125 test_pdata_ptr = (pdata *)0xfe;
7131 *test_pdata_ptr = 1;
7136 Generates the assembly code:
7141 75*01 FE\SpecialChar ~
7145 _test_pdata_ptr,#0xFE
7177 Be extremely carefull if you use pdata together with the -
7188 \begin_inset LatexCommand \index{-\/-xstack}
7193 \layout Subsubsection
7196 \begin_inset LatexCommand \index{code}
7203 'Variables' declared with this storage class will be placed in the code
7209 code unsigned char test_code;
7212 Read access to this variable generates the assembly code:
7217 90s00r6F\SpecialChar ~
7220 mov dptr,#_test_code
7243 \layout Subsubsection
7246 \begin_inset LatexCommand \index{bit}
7253 This is a data-type and a storage class specifier.
7254 When a variable is declared as a bit, it is allocated into the bit addressable
7255 memory of 8051, e.g.:
7263 Writing 1 to this variable generates the assembly code:
7277 \layout Subsubsection
7280 \begin_inset LatexCommand \index{sfr}
7285 \begin_inset LatexCommand \index{sbit}
7292 Like the bit keyword,
7296 signifies both a data-type and storage class, they are used to describe
7297 the special function registers and special bit variables of a 8051, eg:
7303 \begin_inset LatexCommand \index{at}
7307 0x80 P0;\SpecialChar ~
7308 /* special function register P0 at location 0x80 */
7310 sbit at 0xd7 CY; /* CY (Carry Flag
7311 \begin_inset LatexCommand \index{Flags}
7316 \begin_inset LatexCommand \index{Carry flag}
7321 \layout Subsubsection
7324 \begin_inset LatexCommand \index{Pointers}
7328 to MCS51/DS390 specific memory spaces
7331 SDCC allows (via language extensions) pointers to explicitly point to any
7332 of the memory spaces
7333 \begin_inset LatexCommand \index{Memory model}
7338 In addition to the explicit pointers, the compiler uses (by default) generic
7339 pointers which can be used to point to any of the memory spaces.
7343 Pointer declaration examples:
7348 /* pointer physically in internal ram pointing to object in external ram
7351 xdata unsigned char * data p;
7355 /* pointer physically in external ram pointing to object in internal ram
7358 data unsigned char * xdata p;
7362 /* pointer physically in code rom pointing to data in xdata space */
7364 xdata unsigned char * code p;
7368 /* pointer physically in code space pointing to data in code space */
7370 code unsigned char * code p;
7374 /* the following is a generic pointer physically located in xdata space
7380 Well you get the idea.
7385 All unqualified pointers are treated as 3-byte (4-byte for the ds390)
7398 The highest order byte of the
7402 pointers contains the data space information.
7403 Assembler support routines are called whenever data is stored or retrieved
7409 These are useful for developing reusable library
7410 \begin_inset LatexCommand \index{Libraries}
7415 Explicitly specifying the pointer type will generate the most efficient
7420 \begin_inset LatexCommand \index{Absolute addressing}
7427 Data items can be assigned an absolute address with the
7430 \begin_inset LatexCommand \index{at}
7436 keyword, in addition to a storage class, e.g.:
7442 \begin_inset LatexCommand \index{xdata}
7447 \begin_inset LatexCommand \index{at}
7451 0x7ffe unsigned int chksum;
7454 In the above example the variable chksum will located at 0x7ffe and 0x7fff
7455 of the external ram.
7456 The compiler does not actually reserve any space for variables declared
7457 in this way (they are implemented with an equate in the assembler).
7458 Thus it is left to the programmer to make sure there are no overlaps with
7459 other variables that are declared without the absolute address.
7460 The assembler listing file (.lst
7461 \begin_inset LatexCommand \index{.lst}
7465 ) and the linker output files (.rst
7466 \begin_inset LatexCommand \index{.rst}
7471 \begin_inset LatexCommand \index{.map}
7475 ) are good places to look for such overlaps.
7478 In case of memory mapped I/O devices the keyword
7482 should be used to tell the compiler that accesses might not be optimized
7489 \begin_inset LatexCommand \index{volatile}
7494 \begin_inset LatexCommand \index{xdata}
7499 \begin_inset LatexCommand \index{at}
7503 0x8000 unsigned char PORTA_8255;
7506 Absolute address can be specified for variables in all storage classes,
7513 \begin_inset LatexCommand \index{bit}
7518 \begin_inset LatexCommand \index{at}
7525 The above example will allocate the variable at offset 0x02 in the bit-addressab
7527 There is no real advantage to assigning absolute addresses to variables
7528 in this manner, unless you want strict control over all the variables allocated.
7529 One possible use would be to write hardware portable code.
7530 For example, if you have a routine that uses one or more of the microcontroller
7531 I/O pins, and such pins are different for two different hardwares, you
7532 can declare the I/O pins in your routine using:
7537 extern volatile bit SDI;
7539 extern volatile bit SCLK;
7541 extern volatile bit CPOL;
7545 void DS1306_put(unsigned char value)
7553 unsigned char mask=0x80;
7577 SDI=(value & mask)?1:0;
7618 Then, someplace in the code for the first hardware you would use
7623 bit at 0x80 SDI;\SpecialChar ~
7627 /* I/O port 0, bit 0 */
7629 bit at 0x81 SCLK;\SpecialChar ~
7632 /* I/O port 0, bit 1 */
7634 bit CPOL;\SpecialChar ~
7645 /* This is a variable, let the linker allocate this one */
7648 Similarly, for the second hardware you would use
7653 bit at 0x83 SDI;\SpecialChar ~
7657 /* I/O port 0, bit 3 */
7659 bit at 0x91 SCLK;\SpecialChar ~
7662 /* I/O port 1, bit 1 */
7664 bit CPOL;\SpecialChar ~
7675 /* This is a variable, let the linker allocate this one */
7678 and you can use the same hardware dependent routine without changes, as
7679 for example in a library.
7680 This is somehow similar to sbit, but only one absolute address has to be
7681 specified in the whole project.
7685 \begin_inset LatexCommand \index{Parameters}
7690 \begin_inset LatexCommand \index{Local variable}
7697 Automatic (local) variables and parameters to functions can either be placed
7698 on the stack or in data-space.
7699 The default action of the compiler is to place these variables in the internal
7700 RAM (for small model) or external RAM (for large model).
7701 This in fact makes them
7704 \begin_inset LatexCommand \index{static}
7710 so by default functions are non-reentrant
7711 \begin_inset LatexCommand \index{reentrant}
7719 They can be placed on the stack
7720 \begin_inset LatexCommand \index{stack}
7737 \begin_inset LatexCommand \index{-\/-stack-auto}
7743 option or by using the
7746 \begin_inset LatexCommand \index{reentrant}
7752 keyword in the function declaration, e.g.:
7757 unsigned char foo(char i) reentrant
7771 Since stack space on 8051 is limited, the
7789 option should be used sparingly.
7790 Note that the reentrant keyword just means that the parameters & local
7791 variables will be allocated to the stack, it
7795 mean that the function is register bank independent.
7799 Local variables can be assigned storage classes and absolute
7800 \begin_inset LatexCommand \index{Absolute addressing}
7817 xdata unsigned char i;
7829 data at 0x31 unsigned char j;
7841 In the above example the variable
7845 will be allocated in the external ram,
7849 in bit addressable space and
7868 or when a function is declared as
7872 this should only be done for static variables.
7875 Parameters however are not allowed any storage class, (storage classes for
7876 parameters will be ignored), their allocation is governed by the memory
7877 model in use, and the reentrancy options.
7881 \begin_inset LatexCommand \label{sub:Overlaying}
7886 \begin_inset LatexCommand \index{Overlaying}
7894 \begin_inset LatexCommand \index{reentrant}
7898 functions SDCC will try to reduce internal ram space usage by overlaying
7899 parameters and local variables of a function (if possible).
7900 Parameters and local variables of a function will be allocated to an overlayabl
7901 e segment if the function has
7903 no other function calls and the function is non-reentrant and the memory
7905 \begin_inset LatexCommand \index{Memory model}
7912 If an explicit storage class
7913 \begin_inset LatexCommand \index{Storage class}
7917 is specified for a local variable, it will NOT be overlayed.
7920 Note that the compiler (not the linkage editor) makes the decision for overlayin
7922 Functions that are called from an interrupt service routine should be preceded
7923 by a #pragma\SpecialChar ~
7925 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
7929 if they are not reentrant.
7932 Also note that the compiler does not do any processing of inline
7933 \begin_inset LatexCommand \index{inline}
7937 assembler code, so the compiler might incorrectly assign local variables
7938 and parameters of a function into the overlay segment if the inline assembler
7939 code calls other c-functions that might use the overlay.
7940 In that case the #pragma\SpecialChar ~
7941 NOOVERLAY should be used.
7944 Parameters and Local variables of functions that contain 16 or 32 bit multiplica
7946 \begin_inset LatexCommand \index{Multiplication}
7951 \begin_inset LatexCommand \index{Division}
7955 will NOT be overlayed since these are implemented using external functions,
7964 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
7970 void set_error(unsigned char errcd)
7986 void some_isr () interrupt
7987 \begin_inset LatexCommand \index{interrupt}
8017 In the above example the parameter
8025 would be assigned to the overlayable segment if the #pragma\SpecialChar ~
8027 not present, this could cause unpredictable runtime behavior when called
8029 The #pragma\SpecialChar ~
8030 NOOVERLAY ensures that the parameters and local variables for
8031 the function are NOT overlayed.
8034 Interrupt Service Routines
8037 SDCC allows interrupt service routines to be coded in C, with some extended
8043 void timer_isr (void) interrupt 1 using 1
8057 The optional number following the
8060 \begin_inset LatexCommand \index{interrupt}
8066 keyword is the interrupt number this routine will service.
8067 When present, the compiler will insert a call to this routine in the interrupt
8068 vector table for the interrupt number specified.
8073 keyword can be used to tell the compiler to use the specified register
8074 bank (8051 specific) when generating code for this function.
8075 Note that when some function is called from an interrupt service routine
8076 it should be preceded by a #pragma\SpecialChar ~
8078 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
8082 if it is not reentrant.
8083 Furthermore nonreentrant functions should not be called from the main program
8084 while the interrupt service routine might be active.
8085 If the interrupt service routines changes variables which are accessed
8086 by other functions these variables should be declared
8091 \begin_inset LatexCommand \index{volatile}
8099 A special note here, int (16 bit) and long (32 bit) integer division
8100 \begin_inset LatexCommand \index{Division}
8105 \begin_inset LatexCommand \index{Multiplication}
8110 \begin_inset LatexCommand \index{Modulus}
8114 operations are implemented using external support routines developed in
8115 ANSI-C, if an interrupt service routine needs to do any of these operations
8116 then the support routines (as mentioned in a following section) will have
8117 to be recompiled using the
8130 \begin_inset LatexCommand \index{-\/-stack-auto}
8136 option and the source file will need to be compiled using the
8151 \begin_inset LatexCommand \index{-\/-int-long-rent}
8158 If you have multiple source files in your project, interrupt service routines
8159 can be present in any of them, but a prototype of the isr MUST be present
8160 or included in the file that contains the function
8167 Interrupt numbers and the corresponding address & descriptions for the Standard
8168 8051/8052 are listed below.
8169 SDCC will automatically adjust the interrupt vector table to the maximum
8170 interrupt number specified.
8176 \begin_inset Tabular
8177 <lyxtabular version="3" rows="7" columns="3">
8179 <column alignment="center" valignment="top" leftline="true" width="0in">
8180 <column alignment="left" valignment="top" leftline="true" width="0in">
8181 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0in">
8182 <row topline="true" bottomline="true">
8183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8208 <row topline="true">
8209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8225 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8234 <row topline="true">
8235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8251 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8260 <row topline="true">
8261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8277 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8286 <row topline="true">
8287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8303 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8312 <row topline="true">
8313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8329 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8338 <row topline="true" bottomline="true">
8339 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
8355 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
8373 If the interrupt service routine is defined without
8376 \begin_inset LatexCommand \index{using}
8382 a register bank or with register bank 0 (using 0), the compiler will save
8383 the registers used by itself on the stack upon entry and restore them at
8384 exit, however if such an interrupt service routine calls another function
8385 then the entire register bank will be saved on the stack.
8386 This scheme may be advantageous for small interrupt service routines which
8387 have low register usage.
8390 If the interrupt service routine is defined to be using a specific register
8395 are save and restored, if such an interrupt service routine calls another
8396 function (using another register bank) then the entire register bank of
8397 the called function will be saved on the stack.
8398 This scheme is recommended for larger interrupt service routines.
8401 Calling other functions from an interrupt service routine is not recommended,
8402 avoid it if possible.
8404 For some pitfalls see section
8405 \begin_inset LatexCommand \ref{sub:Overlaying}
8409 about Overlaying and section
8410 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
8414 about Functions using private banks.
8424 <TODO: this isn't implemented at all!>
8430 A special keyword may be associated with a function declaring it as
8435 SDCC will generate code to disable all interrupts upon entry to a critical
8436 function and enable them back before returning.
8437 Note that nesting critical functions may cause unpredictable results.
8463 The critical attribute maybe used with other attributes like
8469 \begin_inset LatexCommand \label{sub:Naked-Functions}
8474 \begin_inset LatexCommand \index{Naked functions}
8481 A special keyword may be associated with a function declaring it as
8484 \begin_inset LatexCommand \index{\_naked}
8495 function modifier attribute prevents the compiler from generating prologue
8496 \begin_inset LatexCommand \index{function prologue}
8501 \begin_inset LatexCommand \index{function epilogue}
8505 code for that function.
8506 This means that the user is entirely responsible for such things as saving
8507 any registers that may need to be preserved, selecting the proper register
8508 bank, generating the
8512 instruction at the end, etc.
8513 Practically, this means that the contents of the function must be written
8514 in inline assembler.
8515 This is particularly useful for interrupt functions, which can have a large
8516 (and often unnecessary) prologue/epilogue.
8517 For example, compare the code generated by these two functions:
8523 \begin_inset LatexCommand \index{volatile}
8527 data unsigned char counter;
8531 void simpleInterrupt(void) interrupt
8532 \begin_inset LatexCommand \index{interrupt}
8550 void nakedInterrupt(void) interrupt 2 _naked
8559 \begin_inset LatexCommand \index{\_asm}
8588 ; MUST explicitly include ret or reti in _naked function.
8595 \begin_inset LatexCommand \index{\_endasm}
8604 For an 8051 target, the generated simpleInterrupt looks like:
8745 whereas nakedInterrupt looks like:
8769 ; MUST explicitly include ret or reti in _naked function.
8772 The #pragma directive EXCLUDE
8773 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
8777 also allows to reduce pushing & popping the registers.
8780 While there is nothing preventing you from writing C code inside a _naked
8781 function, there are many ways to shoot yourself in the foot doing this,
8782 and it is recommended that you stick to inline assembler.
8785 Functions using private banks
8786 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
8791 \begin_inset LatexCommand \index{bank}
8801 \begin_inset LatexCommand \index{using}
8807 attribute (which tells the compiler to use a register bank other than the
8808 default bank zero) should only be applied to
8811 \begin_inset LatexCommand \index{interrupt}
8817 functions (see note 1 below).
8818 This will in most circumstances make the generated ISR code more efficient
8819 since it will not have to save registers on the stack.
8826 attribute will have no effect on the generated code for a
8830 function (but may occasionally be useful anyway
8836 possible exception: if a function is called ONLY from 'interrupt' functions
8837 using a particular bank, it can be declared with the same 'using' attribute
8838 as the calling 'interrupt' functions.
8839 For instance, if you have several ISRs using bank one, and all of them
8840 call memcpy(), it might make sense to create a specialized version of memcpy()
8841 'using 1', since this would prevent the ISR from having to save bank zero
8842 to the stack on entry and switch to bank zero before calling the function
8849 (pending: I don't think this has been done yet)
8856 function using a non-zero bank will assume that it can trash that register
8857 bank, and will not save it.
8858 Since high-priority interrupts
8859 \begin_inset LatexCommand \index{interrupt priority}
8863 can interrupt low-priority ones on the 8051 and friends, this means that
8864 if a high-priority ISR
8868 a particular bank occurs while processing a low-priority ISR
8872 the same bank, terrible and bad things can happen.
8873 To prevent this, no single register bank should be
8877 by both a high priority and a low priority ISR.
8878 This is probably most easily done by having all high priority ISRs use
8879 one bank and all low priority ISRs use another.
8880 If you have an ISR which can change priority at runtime, you're on your
8881 own: I suggest using the default bank zero and taking the small performance
8885 It is most efficient if your ISR calls no other functions.
8886 If your ISR must call other functions, it is most efficient if those functions
8887 use the same bank as the ISR (see note 1 below); the next best is if the
8888 called functions use bank zero.
8889 It is very inefficient to call a function using a different, non-zero bank
8895 \begin_inset LatexCommand \label{sub:Startup-Code}
8900 \begin_inset LatexCommand \index{Startup code}
8907 The compiler inserts a call to the C routine
8909 _sdcc_external_startup()
8910 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
8919 at the start of the CODE area.
8920 This routine is in the runtime library
8921 \begin_inset LatexCommand \index{Runtime library}
8926 By default this routine returns 0, if this routine returns a non-zero value,
8927 the static & global variable initialization will be skipped and the function
8928 main will be invoked.
8929 Otherwise static & global variables will be initialized before the function
8933 _sdcc_external_startup()
8935 routine to your program to override the default if you need to setup hardware
8936 or perform some other critical operation prior to static & global variable
8938 See also the compiler option
8957 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
8964 Inline Assembler Code
8965 \begin_inset LatexCommand \index{Assembler routines}
8972 SDCC allows the use of in-line assembler with a few restriction as regards
8974 All labels defined within inline assembler code
8982 where nnnn is a number less than 100 (which implies a limit of utmost 100
8983 inline assembler labels
8991 It is strongly recommended that each assembly instruction (including labels)
8992 be placed in a separate line (as the example shows).
9006 \begin_inset LatexCommand \index{-\/-peep-asm}
9012 command line option is used, the inline assembler code will be passed through
9013 the peephole optimizer
9014 \begin_inset LatexCommand \index{Peephole optimizer}
9019 This might cause some unexpected changes in the inline assembler code.
9020 Please go through the peephole optimizer rules defined in file
9024 carefully before using this option.
9030 \begin_inset LatexCommand \index{\_asm}
9060 \begin_inset LatexCommand \index{\_endasm}
9067 The inline assembler code can contain any valid code understood by the assembler
9068 , this includes any assembler directives and comment lines.
9069 The compiler does not do any validation of the code within the
9079 Inline assembler code cannot reference any C-Labels, however it can reference
9081 \begin_inset LatexCommand \index{Labels}
9085 defined by the inline assembler, e.g.:
9110 ; some assembler code
9130 /* some more c code */
9132 clabel:\SpecialChar ~
9134 /* inline assembler cannot reference this label */
9146 $0003: ;label (can be reference by inline assembler only)
9158 /* some more c code */
9163 In other words inline assembly code can access labels defined in inline
9164 assembly within the scope of the function.
9165 The same goes the other way, ie.
9166 labels defines in inline assembly CANNOT be accessed by C statements.
9169 An example acessing a C variable is in section
9170 \begin_inset LatexCommand \ref{sub:Naked-Functions}
9177 Interfacing with Assembler Code
9178 \begin_inset LatexCommand \index{Assembler routines}
9183 \layout Subsubsection
9185 Global Registers used for Parameter Passing
9186 \begin_inset LatexCommand \index{Parameter passing}
9193 The compiler always uses the global registers
9196 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
9201 \begin_inset LatexCommand \index{B (register)}
9210 \begin_inset LatexCommand \index{ACC}
9216 to pass the first parameter to a routine.
9217 The second parameter onwards is either allocated on the stack (for reentrant
9228 -stack-auto is used) or in data / xdata memory (depending on the memory
9231 \layout Subsubsection
9233 Assembler Routine(non-reentrant
9234 \begin_inset LatexCommand \index{reentrant}
9239 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
9246 In the following example the function c_func calls an assembler routine
9247 asm_func, which takes two parameters.
9252 extern int asm_func(unsigned char, unsigned char);
9256 int c_func (unsigned char i, unsigned char j)
9264 return asm_func(i,j);
9278 return c_func(10,9);
9283 The corresponding assembler function is:
9288 .globl _asm_func_PARM_2
9352 add a,_asm_func_PARM_2
9377 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
9394 Note here that the return values are placed in 'dpl' - One byte return value,
9395 'dpl' LSB & 'dph' MSB for two byte values.
9396 'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
9397 b' & 'acc' for four byte values.
9400 The parameter naming convention is _<function_name>_PARM_<n>, where n is
9401 the parameter number starting from 1, and counting from the left.
9402 The first parameter is passed in
9403 \begin_inset Quotes eld
9407 \begin_inset Quotes erd
9410 for One bye parameter,
9411 \begin_inset Quotes eld
9415 \begin_inset Quotes erd
9419 \begin_inset Quotes eld
9423 \begin_inset Quotes erd
9427 \begin_inset Quotes eld
9431 \begin_inset Quotes erd
9434 for four bytes, the variable name for the second parameter will be _<function_n
9439 Assemble the assembler routine with the following command:
9446 asx8051 -losg asmfunc.asm
9453 Then compile and link the assembler routine to the C source file with the
9461 sdcc cfunc.c asmfunc.rel
9462 \layout Subsubsection
9464 Assembler Routine(reentrant
9465 \begin_inset LatexCommand \index{reentrant}
9470 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
9477 In this case the second parameter onwards will be passed on the stack, the
9478 parameters are pushed from right to left i.e.
9479 after the call the left most parameter will be on the top of the stack.
9485 extern int asm_func(unsigned char, unsigned char);
9489 int c_func (unsigned char i, unsigned char j) reentrant
9497 return asm_func(i,j);
9511 return c_func(10,9);
9516 The corresponding assembler routine is:
9622 The compiling and linking procedure remains the same, however note the extra
9623 entry & exit linkage required for the assembler code, _bp is the stack
9624 frame pointer and is used to compute the offset into the stack for parameters
9625 and local variables.
9629 \begin_inset LatexCommand \index{int (16 bit)}
9634 \begin_inset LatexCommand \index{long (32 bit)}
9641 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
9642 multiplication and modulus operations are implemented by support routines.
9643 These support routines are all developed in ANSI-C to facilitate porting
9644 to other MCUs, although some model specific assembler optimizations are
9646 The following files contain the described routines, all of them can be
9647 found in <installdir>/share/sdcc/lib.
9653 \begin_inset Tabular
9654 <lyxtabular version="3" rows="11" columns="2">
9656 <column alignment="left" valignment="top" leftline="true" width="0">
9657 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
9658 <row topline="true" bottomline="true">
9659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9669 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9680 <row topline="true">
9681 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9689 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9694 16 bit multiplication
9698 <row topline="true">
9699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9707 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9712 signed 16 bit division (calls _divuint)
9716 <row topline="true">
9717 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9725 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9730 unsigned 16 bit division
9734 <row topline="true">
9735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9743 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9748 signed 16 bit modulus (calls _moduint)
9752 <row topline="true">
9753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9761 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9766 unsigned 16 bit modulus
9770 <row topline="true">
9771 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9779 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9784 32 bit multiplication
9788 <row topline="true">
9789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9797 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9802 signed 32 division (calls _divulong)
9806 <row topline="true">
9807 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9815 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9820 unsigned 32 division
9824 <row topline="true">
9825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9833 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9838 signed 32 bit modulus (calls _modulong)
9842 <row topline="true" bottomline="true">
9843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9856 unsigned 32 bit modulus
9869 Since they are compiled as
9874 \begin_inset LatexCommand \index{reentrant}
9879 \begin_inset LatexCommand \index{interrupt}
9883 service routines should not do any of the above operations.
9884 If this is unavoidable then the above routines will need to be compiled
9898 \begin_inset LatexCommand \index{-\/-stack-auto}
9904 option, after which the source program will have to be compiled with
9917 \begin_inset LatexCommand \index{-\/-int-long-rent}
9924 Notice that you don't have to call this routines directly.
9925 The compiler will use them automatically every time a integer operation
9929 Floating Point Support
9930 \begin_inset LatexCommand \index{Floating point support}
9937 SDCC supports IEEE (single precision 4 bytes) floating point numbers.The
9938 floating point support routines are derived from gcc's floatlib.c and consists
9939 of the following routines:
9947 \begin_inset Tabular
9948 <lyxtabular version="3" rows="17" columns="2">
9950 <column alignment="left" valignment="top" leftline="true" width="0">
9951 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
9952 <row topline="true" bottomline="true">
9953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9970 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
9979 <row topline="true">
9980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
9997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10011 add floating point numbers
10015 <row topline="true">
10016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10033 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10047 subtract floating point numbers
10051 <row topline="true">
10052 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10069 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10083 divide floating point numbers
10087 <row topline="true">
10088 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10105 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10119 multiply floating point numbers
10123 <row topline="true">
10124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10141 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10155 convert floating point to unsigned char
10159 <row topline="true">
10160 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10177 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10191 convert floating point to signed char
10195 <row topline="true">
10196 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10213 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10227 convert floating point to unsigned int
10231 <row topline="true">
10232 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10263 convert floating point to signed int
10267 <row topline="true">
10268 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10294 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10308 convert floating point to unsigned long
10312 <row topline="true">
10313 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10330 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10344 convert floating point to signed long
10348 <row topline="true">
10349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10366 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10380 convert unsigned char to floating point
10384 <row topline="true">
10385 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10416 convert char to floating point number
10420 <row topline="true">
10421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10438 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10452 convert unsigned int to floating point
10456 <row topline="true">
10457 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10474 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10488 convert int to floating point numbers
10492 <row topline="true">
10493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10510 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10524 convert unsigned long to floating point number
10528 <row topline="true" bottomline="true">
10529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10560 convert long to floating point number
10573 Note if all these routines are used simultaneously the data space might
10575 For serious floating point usage it is strongly recommended that the large
10577 Also notice that you don't have to call this routines directly.
10578 The compiler will use them automatically every time a floating point operation
10582 MCS51 Memory Models
10583 \begin_inset LatexCommand \index{Memory model}
10588 \begin_inset LatexCommand \index{MCS51 memory}
10595 SDCC allows two memory models for MCS51 code,
10604 Modules compiled with different memory models should
10608 be combined together or the results would be unpredictable.
10609 The library routines supplied with the compiler are compiled as both small
10611 The compiled library modules are contained in separate directories as small
10612 and large so that you can link to either set.
10616 When the large model is used all variables declared without a storage class
10617 will be allocated into the external ram, this includes all parameters and
10618 local variables (for non-reentrant
10619 \begin_inset LatexCommand \index{reentrant}
10624 When the small model is used variables without storage class are allocated
10625 in the internal ram.
10628 Judicious usage of the processor specific storage classes
10629 \begin_inset LatexCommand \index{Storage class}
10633 and the 'reentrant' function type will yield much more efficient code,
10634 than using the large model.
10635 Several optimizations are disabled when the program is compiled using the
10636 large model, it is therefore strongly recommended that the small model
10637 be used unless absolutely required.
10640 DS390 Memory Models
10641 \begin_inset LatexCommand \index{Memory model}
10646 \begin_inset LatexCommand \index{DS390 memory model}
10653 The only model supported is Flat 24
10654 \begin_inset LatexCommand \index{Flat 24 (memory model)}
10659 This generates code for the 24 bit contiguous addressing mode of the Dallas
10661 In this mode, up to four meg of external RAM or code space can be directly
10663 See the data sheets at www.dalsemi.com for further information on this part.
10667 Note that the compiler does not generate any code to place the processor
10668 into 24 bitmode (although
10672 in the ds390 libraries will do that for you).
10678 \begin_inset LatexCommand \index{Tinibios (DS390)}
10682 , the boot loader or similar code must ensure that the processor is in 24
10683 bit contiguous addressing mode before calling the SDCC startup code.
10701 option, variables will by default be placed into the XDATA segment.
10706 Segments may be placed anywhere in the 4 meg address space using the usual
10718 Note that if any segments are located above 64K, the -r flag must be passed
10719 to the linker to generate the proper segment relocations, and the Intel
10720 HEX output format must be used.
10721 The -r flag can be passed to the linker by using the option
10725 on the sdcc command line.
10726 However, currently the linker can not handle code segments > 64k.
10730 \begin_inset LatexCommand \index{Pragmas}
10737 SDCC supports the following #pragma directives.
10741 \begin_inset LatexCommand \index{\#pragma SAVE}
10745 - this will save all current options to the SAVE/RESTORE stack.
10750 \begin_inset LatexCommand \index{\#pragma RESTORE}
10754 - will restore saved options from the last save.
10755 SAVEs & RESTOREs can be nested.
10756 SDCC uses a SAVE/RESTORE stack: SAVE pushes current options to the stack,
10757 RESTORE pulls current options from the stack.
10762 \begin_inset LatexCommand \index{\#pragma NOGCSE}
10766 - will stop global common subexpression elimination.
10770 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
10774 - will stop loop induction optimizations.
10778 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
10782 - will not generate code for boundary value checking, when switch statements
10783 are turned into jump-tables (dangerous).
10788 \begin_inset LatexCommand \index{\#pragma NOOVERLAY}
10792 - the compiler will not overlay the parameters and local variables of a
10797 \begin_inset LatexCommand \index{\#pragma LESS\_PEDANTIC}
10801 - the compiler will not warn you anymore for obvious mistakes, you'r on
10806 \begin_inset LatexCommand \index{\#pragma NOLOOPREVERSE}
10810 - Will not do loop reversal optimization
10814 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
10818 NONE | {acc[,b[,dpl[,dph]]] - The exclude pragma disables generation of
10820 \begin_inset LatexCommand \index{push/pop}
10824 instruction in ISR function (using interrupt
10825 \begin_inset LatexCommand \index{interrupt}
10830 The directive should be placed immediately before the ISR function definition
10831 and it affects ALL ISR functions following it.
10832 To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
10833 EXCLUDE\SpecialChar ~
10835 \begin_inset LatexCommand \index{\#pragma EXCLUDE}
10843 \begin_inset LatexCommand \index{\#pragma NOIV}
10847 - Do not generate interrupt vector table entries for all ISR functions
10848 defined after the pragma.
10849 This is useful in cases where the interrupt vector table must be defined
10850 manually, or when there is a secondary, manually defined interrupt vector
10852 for the autovector feature of the Cypress EZ-USB FX2).
10856 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
10861 \begin_inset LatexCommand \index{function prologue}
10865 function1[,function2[,function3...]] - The compiler by default uses a caller
10866 saves convention for register saving across function calls, however this
10867 can cause unnecessary register pushing & popping when calling small functions
10868 from larger functions.
10869 This option can be used to switch off the register saving convention for
10870 the function names specified.
10871 The compiler will not save registers when calling these functions, extra
10872 code need to be manually inserted at the entry & exit for these functions
10873 to save & restore the registers used by these functions, this can SUBSTANTIALLY
10874 reduce code & improve run time performance of the generated code.
10875 In the future the compiler (with inter procedural analysis) may be able
10876 to determine the appropriate scheme to use for each function call.
10887 -callee-saves command line option is used, the function names specified
10888 in #pragma\SpecialChar ~
10890 \begin_inset LatexCommand \index{\#pragma CALLEE-SAVES}
10894 is appended to the list of functions specified in the command line.
10897 The pragma's are intended to be used to turn-off certain optimizations which
10898 might cause the compiler to generate extra stack / data space to store
10899 compiler generated temporary variables.
10900 This usually happens in large functions.
10901 Pragma directives should be used as shown in the following example, they
10902 are used to control options & optimizations for a given function; pragmas
10903 should be placed before and/or after a function, placing pragma's inside
10904 a function body could have unpredictable results.
10910 \begin_inset LatexCommand \index{\#pragma SAVE}
10921 /* save the current settings */
10924 \begin_inset LatexCommand \index{\#pragma NOGCSE}
10933 /* turnoff global subexpression elimination */
10935 #pragma NOINDUCTION
10936 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
10940 /* turn off induction optimizations */
10963 \begin_inset LatexCommand \index{\#pragma RESTORE}
10967 /* turn the optimizations back on */
10970 The compiler will generate a warning message when extra space is allocated.
10971 It is strongly recommended that the SAVE and RESTORE pragma's be used when
10972 changing options for a function.
10975 Defines Created by the Compiler
10976 \begin_inset LatexCommand \index{Defines created by the compiler}
10983 The compiler creates the following #defines
10984 \begin_inset LatexCommand \index{\#defines}
10994 \begin_inset Tabular
10995 <lyxtabular version="3" rows="10" columns="2">
10997 <column alignment="left" valignment="top" leftline="true" width="0">
10998 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0">
10999 <row topline="true" bottomline="true">
11000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11010 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11021 <row topline="true">
11022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11028 \begin_inset LatexCommand \index{SDCC}
11035 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11040 this Symbol is always defined
11044 <row topline="true">
11045 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11051 \begin_inset LatexCommand \index{SDCC\_mcs51}
11056 \begin_inset LatexCommand \index{SDCC\_ds390}
11061 \begin_inset LatexCommand \index{SDCC\_z80}
11068 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11073 depending on the model used (e.g.: -mds390
11077 <row topline="true">
11078 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11084 \begin_inset LatexCommand \index{\_\_mcs51}
11089 \begin_inset LatexCommand \index{\_\_ds390}
11094 \begin_inset LatexCommand \index{\_\_z80}
11101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11106 depending on the model used (e.g.
11111 <row topline="true">
11112 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11118 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
11125 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11148 <row topline="true">
11149 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11155 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
11162 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11185 <row topline="true">
11186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11192 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
11199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11222 <row topline="true">
11223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11229 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
11236 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11259 <row topline="true">
11260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11266 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
11273 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11286 <row topline="true" bottomline="true">
11287 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
11293 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
11300 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
11322 Debugging with SDCDB
11323 \begin_inset LatexCommand \index{sdcdb}
11330 SDCC is distributed with a source level debugger
11331 \begin_inset LatexCommand \index{Debugger}
11336 The debugger uses a command line interface, the command repertoire of the
11337 debugger has been kept as close to gdb
11338 \begin_inset LatexCommand \index{gdb}
11342 (the GNU debugger) as possible.
11343 The configuration and build process is part of the standard compiler installati
11344 on, which also builds and installs the debugger in the target directory
11345 specified during configuration.
11346 The debugger allows you debug BOTH at the C source and at the ASM source
11348 Sdcdb is available on Unix platforms only.
11351 Compiling for Debugging
11354 The \SpecialChar \-
11356 debug option must be specified for all files for which debug information
11357 is to be generated.
11358 The complier generates a .adb file for each of these files.
11359 The linker creates the .cdb file from the .adb files and the address information.
11360 This .cdb is used by the debugger.
11363 How the Debugger Works
11376 -debug option is specified the compiler generates extra symbol information
11377 some of which are put into the the assembler source and some are put into
11379 Then the linker creates the .cdb file from the individual .adb files with
11380 the address information for the symbols.
11381 The debugger reads the symbolic information generated by the compiler &
11382 the address information generated by the linker.
11383 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
11384 execution is controlled by the debugger.
11385 When a command is issued for the debugger, it translates it into appropriate
11386 commands for the simulator.
11389 Starting the Debugger
11392 The debugger can be started using the following command line.
11393 (Assume the file you are debugging has the file name foo).
11407 The debugger will look for the following files.
11410 foo.c - the source file.
11413 foo.cdb - the debugger symbol information file.
11416 foo.ihx - the Intel hex format
11417 \begin_inset LatexCommand \index{Intel hex format}
11424 Command Line Options.
11437 -directory=<source file directory> this option can used to specify the directory
11439 The debugger will look into the directory list specified for source, cdb
11441 The items in the directory list must be separated by ':', e.g.
11442 if the source files can be in the directories /home/src1 and /home/src2,
11453 -directory option should be -
11463 -directory=/home/src1:/home/src2.
11464 Note there can be no spaces in the option.
11468 -cd <directory> - change to the <directory>.
11471 -fullname - used by GUI front ends.
11474 -cpu <cpu-type> - this argument is passed to the simulator please see the
11475 simulator docs for details.
11478 -X <Clock frequency > this options is passed to the simulator please see
11479 the simulator docs for details.
11482 -s <serial port file> passed to simulator see the simulator docs for details.
11485 -S <serial in,out> passed to simulator see the simulator docs for details.
11491 As mentioned earlier the command interface for the debugger has been deliberatel
11492 y kept as close the GNU debugger gdb, as possible.
11493 This will help the integration with existing graphical user interfaces
11494 (like ddd, xxgdb or xemacs) existing for the GNU debugger.
11495 If you use a graphical user interface for the debugger you can skip the
11497 \layout Subsubsection*
11499 break [line | file:line | function | file:function]
11502 Set breakpoint at specified line or function:
11511 sdcdb>break foo.c:100
11513 sdcdb>break funcfoo
11515 sdcdb>break foo.c:funcfoo
11516 \layout Subsubsection*
11518 clear [line | file:line | function | file:function ]
11521 Clear breakpoint at specified line or function:
11530 sdcdb>clear foo.c:100
11532 sdcdb>clear funcfoo
11534 sdcdb>clear foo.c:funcfoo
11535 \layout Subsubsection*
11540 Continue program being debugged, after breakpoint.
11541 \layout Subsubsection*
11546 Execute till the end of the current function.
11547 \layout Subsubsection*
11552 Delete breakpoint number 'n'.
11553 If used without any option clear ALL user defined break points.
11554 \layout Subsubsection*
11556 info [break | stack | frame | registers ]
11559 info break - list all breakpoints
11562 info stack - show the function call stack.
11565 info frame - show information about the current execution frame.
11568 info registers - show content of all registers.
11569 \layout Subsubsection*
11574 Step program until it reaches a different source line.
11575 \layout Subsubsection*
11580 Step program, proceeding through subroutine calls.
11581 \layout Subsubsection*
11586 Start debugged program.
11587 \layout Subsubsection*
11592 Print type information of the variable.
11593 \layout Subsubsection*
11598 print value of variable.
11599 \layout Subsubsection*
11604 load the given file name.
11605 Note this is an alternate method of loading file for debugging.
11606 \layout Subsubsection*
11611 print information about current frame.
11612 \layout Subsubsection*
11617 Toggle between C source & assembly source.
11618 \layout Subsubsection*
11620 ! simulator command
11623 Send the string following '!' to the simulator, the simulator response is
11625 Note the debugger does not interpret the command being sent to the simulator,
11626 so if a command like 'go' is sent the debugger can loose its execution
11627 context and may display incorrect values.
11628 \layout Subsubsection*
11635 My name is Bobby Brown"
11638 Interfacing with XEmacs
11639 \begin_inset LatexCommand \index{XEmacs}
11644 \begin_inset LatexCommand \index{Emacs}
11651 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
11652 sdcdb.el and sdcdbsrc.el.
11653 These two files can be found in the $(prefix)/bin directory after the installat
11655 These files need to be loaded into XEmacs for the interface to work.
11656 This can be done at XEmacs startup time by inserting the following into
11657 your '.xemacs' file (which can be found in your HOME directory):
11663 (load-file sdcdbsrc.el)
11669 .xemacs is a lisp file so the () around the command is REQUIRED.
11670 The files can also be loaded dynamically while XEmacs is running, set the
11671 environment variable 'EMACSLOADPATH' to the installation bin directory
11672 (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
11673 To start the interface enter the following command:
11687 You will prompted to enter the file name to be debugged.
11692 The command line options that are passed to the simulator directly are bound
11693 to default values in the file sdcdbsrc.el.
11694 The variables are listed below, these values maybe changed as required.
11697 sdcdbsrc-cpu-type '51
11700 sdcdbsrc-frequency '11059200
11703 sdcdbsrc-serial nil
11706 The following is a list of key mapping for the debugger interface.
11714 ;; Current Listing ::
11716 ;;key\SpecialChar ~
11731 binding\SpecialChar ~
11755 ;;---\SpecialChar ~
11770 ------\SpecialChar ~
11810 sdcdb-next-from-src\SpecialChar ~
11836 sdcdb-back-from-src\SpecialChar ~
11862 sdcdb-cont-from-src\SpecialChar ~
11872 SDCDB continue command
11888 sdcdb-step-from-src\SpecialChar ~
11914 sdcdb-whatis-c-sexp\SpecialChar ~
11924 SDCDB ptypecommand for data at
11988 sdcdbsrc-delete\SpecialChar ~
12002 SDCDB Delete all breakpoints if no arg
12050 given or delete arg (C-u arg x)
12066 sdcdbsrc-frame\SpecialChar ~
12081 SDCDB Display current frame if no arg,
12130 given or display frame arg
12195 sdcdbsrc-goto-sdcdb\SpecialChar ~
12205 Goto the SDCDB output buffer
12221 sdcdb-print-c-sexp\SpecialChar ~
12232 SDCDB print command for data at
12296 sdcdbsrc-goto-sdcdb\SpecialChar ~
12306 Goto the SDCDB output buffer
12322 sdcdbsrc-mode\SpecialChar ~
12338 Toggles Sdcdbsrc mode (turns it off)
12342 ;; C-c C-f\SpecialChar ~
12350 sdcdb-finish-from-src\SpecialChar ~
12358 SDCDB finish command
12362 ;; C-x SPC\SpecialChar ~
12370 sdcdb-break\SpecialChar ~
12388 Set break for line with point
12390 ;; ESC t\SpecialChar ~
12400 sdcdbsrc-mode\SpecialChar ~
12416 Toggle Sdcdbsrc mode
12418 ;; ESC m\SpecialChar ~
12428 sdcdbsrc-srcmode\SpecialChar ~
12450 Here are a few guidelines that will help the compiler generate more efficient
12451 code, some of the tips are specific to this compiler others are generally
12452 good programming practice.
12455 Use the smallest data type to represent your data-value.
12456 If it is known in advance that the value is going to be less than 256 then
12457 use an 'unsigned char' instead of a 'short' or 'int'.
12460 Use unsigned when it is known in advance that the value is not going to
12462 This helps especially if you are doing division or multiplication.
12465 NEVER jump into a LOOP.
12468 Declare the variables to be local whenever possible, especially loop control
12469 variables (induction).
12472 Since the compiler does not always do implicit integral promotion, the programme
12473 r should do an explicit cast when integral promotion is required.
12476 Reducing the size of division, multiplication & modulus operations can reduce
12477 code size substantially.
12478 Take the following code for example.
12484 foobar(unsigned int p1, unsigned char ch)
12492 unsigned char ch1 = p1 % ch ;
12503 For the modulus operation the variable ch will be promoted to unsigned int
12504 first then the modulus operation will be performed (this will lead to a
12505 call to support routine _moduint()), and the result will be casted to a
12507 If the code is changed to
12512 foobar(unsigned int p1, unsigned char ch)
12520 unsigned char ch1 = (unsigned char)p1 % ch ;
12531 It would substantially reduce the code generated (future versions of the
12532 compiler will be smart enough to detect such optimization opportunities).
12536 Have a look at the assembly listing to get a
12537 \begin_inset Quotes sld
12541 \begin_inset Quotes srd
12544 for the code generation.
12547 Notes on MCS51 memory
12548 \begin_inset LatexCommand \index{MCS51 memory}
12555 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
12556 RAM memory which is structured as follows
12560 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
12563 - Bytes 20-2F - 16 bytes to hold 128 bit
12564 \begin_inset LatexCommand \index{bit}
12570 - Bytes 30-7F - 80 bytes for general purpose use.
12575 Additionally some members of the MCS51 family may have up to 128 bytes of
12576 additional, indirectly addressable, internal RAM memory (
12581 \begin_inset LatexCommand \index{idata}
12586 Furthermore, some chips may have some built in external memory (
12591 \begin_inset LatexCommand \index{xdata}
12595 ) which should not be confused with the internal, directly addressable RAM
12601 \begin_inset LatexCommand \index{data}
12606 Sometimes this built in
12610 memory has to be activated before using it (you can probably find this
12611 information on the datasheet of the microcontroller your are using).
12614 Normally SDCC will only use the first bank
12615 \begin_inset LatexCommand \index{bank}
12619 of registers (register bank 0), but it is possible to specify that other
12620 banks of registers should be used in interrupt
12621 \begin_inset LatexCommand \index{interrupt}
12626 By default, the compiler will place the stack after the last byte of allocated
12627 memory for variables.
12628 For example, if the first 2 banks of registers are used, and only four
12633 variables, it will position the base of the internal stack at address 20
12635 This implies that as the stack
12636 \begin_inset LatexCommand \index{stack}
12640 grows, it will use up the remaining register banks, and the 16 bytes used
12641 by the 128 bit variables, and 80 bytes for general purpose use.
12642 If any bit variables are used, the data variables will be placed after
12643 the byte holding the last bit variable.
12644 For example, if register banks 0 and 1 are used, and there are 9 bit variables
12649 variables will be placed starting at address 0x22.
12661 \begin_inset LatexCommand \index{-\/-data-loc}
12665 to specify the start address of the
12679 -iram-size to specify the size of the total internal RAM (
12691 By default the 8051 linker will place the stack after the last byte of data
12704 \begin_inset LatexCommand \index{-\/-stack-loc}
12708 allows you to specify the start of the stack, i.e.
12709 you could start it after any data in the general purpose area.
12710 If your microcontroller has additional indirectly addressable internal
12715 ) you can place the stack on it.
12716 You may also need to use -
12727 \begin_inset LatexCommand \index{-\/-data-loc}
12731 to set the start address of the external RAM (
12746 \begin_inset LatexCommand \index{-\/-data-loc}
12750 to specify its size.
12751 Same goes for the code memory, using -
12762 \begin_inset LatexCommand \index{-\/-data-loc}
12777 \begin_inset LatexCommand \index{-\/-data-loc}
12782 If in doubt, don't specify any options and see if the resulting memory
12783 layout is appropriate, then you can adjust it.
12786 The 8051 linker generates two files with memory allocation information.
12787 The first, with extension .map shows all the variables and segments.
12788 The second with extension .mem shows the final memory layout.
12789 The linker will complaint either if memory segments overlap, there is not
12790 enough memory, or there is not enough space for stack.
12791 If you get any linking warnings and/or errors related to stack or segments
12792 allocation, take a look at either the .map or .mem files to find out what
12794 The .mem file may even suggest a solution to the problem.
12798 \begin_inset LatexCommand \index{Tools}
12802 included in the distribution
12806 \begin_inset Tabular
12807 <lyxtabular version="3" rows="12" columns="3">
12809 <column alignment="left" valignment="top" leftline="true" width="0pt">
12810 <column alignment="left" valignment="top" leftline="true" width="0pt">
12811 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
12812 <row topline="true" bottomline="true">
12813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12821 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12829 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12838 <row topline="true">
12839 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12847 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12852 Simulator for various architectures
12855 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12864 <row topline="true">
12865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12878 header file conversion
12881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12886 sdcc/support/scripts
12890 <row topline="true">
12891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12904 header file conversion
12907 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12912 sdcc/support/scripts
12916 <row topline="true">
12917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12925 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12933 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12951 <row topline="true">
12952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12960 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12968 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12986 <row topline="true">
12987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13003 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13021 <row topline="true">
13022 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13030 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13038 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13056 <row topline="true">
13057 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13065 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13073 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13091 <row topline="true">
13092 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13108 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13126 <row topline="true">
13127 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13143 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13161 <row topline="true" bottomline="true">
13162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13178 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13205 Related open source tools
13206 \begin_inset LatexCommand \index{Related tools}
13214 \begin_inset Tabular
13215 <lyxtabular version="3" rows="8" columns="3">
13217 <column alignment="left" valignment="top" leftline="true" width="0pt">
13218 <column alignment="left" valignment="top" leftline="true" width="30line%">
13219 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
13220 <row topline="true" bottomline="true">
13221 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13229 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13237 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13246 <row topline="true">
13247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13253 \begin_inset LatexCommand \index{gpsim}
13260 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13268 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13274 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
13282 <row topline="true">
13283 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13299 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13305 \begin_inset LatexCommand \url{http://digilander.libero.it/fbradasc/FLP5.html}
13313 <row topline="true">
13314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13320 \begin_inset LatexCommand \index{srecord}
13327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13332 Object file conversion, checksumming, ...
13335 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13341 \begin_inset LatexCommand \url{http://srecord.sourceforge.net/}
13349 <row topline="true">
13350 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13356 \begin_inset LatexCommand \index{objdump}
13363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13368 Object file conversion, ...
13371 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13376 Part of binutils (should be there anyway)
13380 <row topline="true">
13381 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13387 \begin_inset LatexCommand \index{doxygen}
13394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13399 Source code documentation system
13402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13408 \begin_inset LatexCommand \url{http://www.doxygen.org}
13416 <row topline="true">
13417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13423 \begin_inset LatexCommand \index{splint}
13430 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13435 Statically checks c sources
13438 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13444 \begin_inset LatexCommand \url{http://www.splint.org}
13452 <row topline="true" bottomline="true">
13453 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13459 \begin_inset LatexCommand \index{ddd}
13466 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13471 Debugger, serves nicely as GUI to sdcdb
13472 \begin_inset LatexCommand \index{sdcdb}
13479 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13485 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
13502 Related documentation / recommended reading
13506 \begin_inset Tabular
13507 <lyxtabular version="3" rows="5" columns="3">
13509 <column alignment="left" valignment="top" leftline="true" width="0pt">
13510 <column alignment="left" valignment="top" leftline="true" width="30line%">
13511 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
13512 <row topline="true" bottomline="true">
13513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13529 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13538 <row topline="true">
13539 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13549 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13554 Advanced Compiler Design and Implementation
13557 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13566 <row topline="true">
13567 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13584 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13590 \begin_inset LatexCommand \index{C Reference card}
13597 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13603 \begin_inset LatexCommand \url{http://www.refcards.com/about/c.html}
13611 <row topline="true">
13612 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13617 test_suite_spec.pdf
13620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13625 sdcc regression test
13626 \begin_inset LatexCommand \index{Regression test}
13633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13642 <row topline="true" bottomline="true">
13643 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13674 sdcc internal documentation
13677 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13696 \begin_inset LatexCommand \index{Support}
13703 SDCC has grown to be a large project.
13704 The compiler alone (without the preprocessor, assembler and linker) is
13705 well over 100,000 lines of code (blank stripped).
13706 The open source nature of this project is a key to its continued growth
13708 You gain the benefit and support of many active software developers and
13710 Is SDCC perfect? No, that's why we need your help.
13711 The developers take pride in fixing reported bugs.
13712 You can help by reporting the bugs and helping other SDCC users.
13713 There are lots of ways to contribute, and we encourage you to take part
13714 in making SDCC a great software package.
13718 The SDCC project is hosted on the sdcc sourceforge site at
13719 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
13724 You'll find the complete set of mailing lists
13725 \begin_inset LatexCommand \index{Mailing list}
13729 , forums, bug reporting system, patch submission
13730 \begin_inset LatexCommand \index{Patch submission}
13735 \begin_inset LatexCommand \index{download}
13739 area and cvs code repository
13740 \begin_inset LatexCommand \index{cvs code repository}
13748 \begin_inset LatexCommand \index{Bugs}
13753 \begin_inset LatexCommand \index{Reporting bugs}
13760 The recommended way of reporting bugs is using the infrastructure of the
13762 You can follow the status of bug reports there and have an overview about
13766 Bug reports are automatically forwarded to the developer mailing list and
13767 will be fixed ASAP.
13768 When reporting a bug, it is very useful to include a small test program
13769 (the smaller the better) which reproduces the problem.
13770 If you can isolate the problem by looking at the generated assembly code,
13771 this can be very helpful.
13772 Compiling your program with the -
13783 \begin_inset LatexCommand \index{-\/-dumpall}
13787 option can sometimes be useful in locating optimization problems.
13788 When reporting a bug please maker sure you:
13791 Attach the code you are compiling with SDCC.
13795 Specify the exact command you use to run SDCC, or attach your Makefile.
13799 Specify the SDCC version (type "sdcc -v"), your platform, and operating
13804 Provide an exact copy of any error message or incorrect output.
13808 Put something meaningful in the subject of your message.
13811 Please attempt to include these 5 important parts, as applicable, in all
13812 requests for support or when reporting any problems or bugs with SDCC.
13813 Though this will make your message lengthy, it will greatly improve your
13814 chance that SDCC users and developers will be able to help you.
13815 Some SDCC developers are frustrated by bug reports without code provided
13816 that they can use to reproduce and ultimately fix the problem, so please
13817 be sure to provide sample code if you are reporting a bug!
13820 Please have a short check that you are using a recent version of SDCC and
13821 the bug is not yet known.
13822 This is the link for reporting bugs:
13823 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
13830 Requesting Features
13831 \begin_inset LatexCommand \label{sub:Requesting-Features}
13836 \begin_inset LatexCommand \index{Feature request}
13841 \begin_inset LatexCommand \index{Requesting features}
13848 Like bug reports feature requests are forwarded to the developer mailing
13850 This is the link for requesting features:
13851 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
13861 These links should take you directly to the
13862 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
13872 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
13873 automated messages (mid 2003)
13877 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
13881 , lists and forums are archived so if you are lucky someone already had
13886 \begin_inset LatexCommand \index{Changelog}
13893 You can follow the status of the cvs version
13894 \begin_inset LatexCommand \index{version}
13898 of SDCC by watching the file
13899 \begin_inset LatexCommand \htmlurl[ChangeLog]{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/sdcc/sdcc/ChangeLog?rev=HEAD&content-type=text/plain}
13903 in the cvs-repository.
13907 \begin_inset LatexCommand \index{Release policy}
13914 Historically there often were long delays between official releases and
13915 the sourceforge download area tends to get not updated at all.
13916 Current excuses might refer to problems with live range analysis, but if
13917 this is fixed, the next problem rising is that another excuse will have
13919 Kidding aside, we have to get better there! On the other hand there are
13920 daily snapshots available at
13921 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
13925 , and you can always built the very last version (hopefully with many bugs
13926 fixed, and features added) from the source code available at
13927 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
13935 \begin_inset LatexCommand \index{Examples}
13942 You'll find some small examples in the directory sdcc/device/examples/
13945 Maybe we should include some links to real world applications.
13946 Preferably pointer to pointers (one for each architecture) so this stays
13951 \begin_inset LatexCommand \index{Quality control}
13958 The compiler is passed through nightly compile and build checks.
13964 \begin_inset LatexCommand \index{Regression test}
13968 check that SDCC itself compiles flawlessly on several platforms and checks
13969 the quality of the code generated by SDCC by running the code through simulator
13971 There is a separate document
13974 \begin_inset LatexCommand \index{Test suite}
13983 You'll find the test code in the directory
13985 sdcc/support/regression
13988 You can run these tests manually by running
13992 in this directory (or f.e.
13997 if you don't want to run the complete tests).
13998 The test code might also be interesting if you want to look for examples
13999 \begin_inset LatexCommand \index{Examples}
14003 checking corner cases of SDCC or if you plan to submit patches
14004 \begin_inset LatexCommand \index{Patch submission}
14011 The pic port uses a different set of regression tests, you'll find them
14014 sdcc/src/regression
14019 SDCC Technical Data
14023 \begin_inset LatexCommand \index{Optimizations}
14030 SDCC performs a host of standard optimizations in addition to some MCU specific
14033 \layout Subsubsection
14035 Sub-expression Elimination
14036 \begin_inset LatexCommand \index{Subexpression elimination}
14043 The compiler does local and global common subexpression elimination, e.g.:
14054 will be translated to
14066 Some subexpressions are not as obvious as the above example, e.g.:
14076 In this case the address arithmetic a->b[i] will be computed only once;
14077 the equivalent code in C would be.
14089 The compiler will try to keep these temporary variables in registers.
14090 \layout Subsubsection
14092 Dead-Code Elimination
14093 \begin_inset LatexCommand \index{Dead-code elimination}
14114 i = 1; \SpecialChar ~
14123 global = 1;\SpecialChar ~
14136 global = 3;\SpecialChar ~
14162 \layout Subsubsection
14165 \begin_inset LatexCommand \index{Copy propagation}
14221 Note: the dead stores created by this copy propagation will be eliminated
14222 by dead-code elimination.
14223 \layout Subsubsection
14226 \begin_inset LatexCommand \index{Loop optimization}
14233 Two types of loop optimizations are done by SDCC loop invariant lifting
14234 and strength reduction of loop induction variables.
14235 In addition to the strength reduction the optimizer marks the induction
14236 variables and the register allocator tries to keep the induction variables
14237 in registers for the duration of the loop.
14238 Because of this preference of the register allocator
14239 \begin_inset LatexCommand \index{Register allocation}
14243 , loop induction optimization causes an increase in register pressure, which
14244 may cause unwanted spilling of other temporary variables into the stack
14245 \begin_inset LatexCommand \index{stack}
14250 The compiler will generate a warning message when it is forced to allocate
14251 extra space either on the stack or data space.
14252 If this extra space allocation is undesirable then induction optimization
14253 can be eliminated either for the entire source file (with -
14263 -noinduction option) or for a given function only using #pragma\SpecialChar ~
14265 \begin_inset LatexCommand \index{\#pragma NOINDUCTION}
14278 for (i = 0 ; i < 100 ; i ++)
14294 for (i = 0; i < 100; i++)
14303 As mentioned previously some loop invariants are not as apparent, all static
14304 address computations are also moved out of the loop.
14309 \begin_inset LatexCommand \index{Strength reduction}
14313 , this optimization substitutes an expression by a cheaper expression:
14318 for (i=0;i < 100; i++)
14336 for (i=0;i< 100;i++) {
14342 ar[itemp1] = itemp2;
14359 The more expensive multiplication
14360 \begin_inset LatexCommand \index{Multiplication}
14364 is changed to a less expensive addition.
14365 \layout Subsubsection
14368 \begin_inset LatexCommand \index{Loop reversing}
14375 This optimization is done to reduce the overhead of checking loop boundaries
14376 for every iteration.
14377 Some simple loops can be reversed and implemented using a
14378 \begin_inset Quotes eld
14381 decrement and jump if not zero
14382 \begin_inset Quotes erd
14386 SDCC checks for the following criterion to determine if a loop is reversible
14387 (note: more sophisticated compilers use data-dependency analysis to make
14388 this determination, SDCC uses a more simple minded analysis).
14391 The 'for' loop is of the form
14397 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
14407 The <for body> does not contain
14408 \begin_inset Quotes eld
14412 \begin_inset Quotes erd
14416 \begin_inset Quotes erd
14422 All goto's are contained within the loop.
14425 No function calls within the loop.
14428 The loop control variable <sym> is not assigned any value within the loop
14431 The loop control variable does NOT participate in any arithmetic operation
14435 There are NO switch statements in the loop.
14436 \layout Subsubsection
14438 Algebraic Simplifications
14441 SDCC does numerous algebraic simplifications, the following is a small sub-set
14442 of these optimizations.
14447 i = j + 0 ; /* changed to */ i = j;
14449 i /= 2;\SpecialChar ~
14453 /* changed to */ i >>= 1;
14455 i = j - j ; /* changed to */ i = 0;
14457 i = j / 1 ; /* changed to */ i = j;
14460 Note the subexpressions
14461 \begin_inset LatexCommand \index{Subexpression}
14465 given above are generally introduced by macro expansions or as a result
14466 of copy/constant propagation.
14467 \layout Subsubsection
14469 'switch' Statements
14470 \begin_inset LatexCommand \index{switch statement}
14477 SDCC changes switch statements to jump tables
14478 \begin_inset LatexCommand \index{jump tables}
14482 when the following conditions are true.
14486 The case labels are in numerical sequence, the labels need not be in order,
14487 and the starting number need not be one or zero.
14493 switch(i) {\SpecialChar ~
14524 case 4: ...\SpecialChar ~
14556 case 5: ...\SpecialChar ~
14588 case 3: ...\SpecialChar ~
14620 case 6: ...\SpecialChar ~
14688 Both the above switch statements will be implemented using a jump-table.
14689 The example to the right side is slightly more efficient as the check for
14690 the lower boundary of the jump-table is not needed.
14694 The number of case labels is at least three, since it takes two conditional
14695 statements to handle the boundary conditions.
14698 The number of case labels is less than 84, since each label takes 3 bytes
14699 and a jump-table can be utmost 256 bytes long.
14702 Switch statements which have gaps in the numeric sequence or those that
14703 have more that 84 case labels can be split into more than one switch statement
14704 for efficient code generation, e.g.:
14754 If the above switch statement is broken down into two switch statements
14793 case 9:\SpecialChar ~
14800 case 10:\SpecialChar ~
14806 case 11:\SpecialChar ~
14812 case 12:\SpecialChar ~
14819 then both the switch statements will be implemented using jump-tables whereas
14820 the unmodified switch statement will not be.
14821 You might also consider dummy cases 0 and 5 to 8 in this example.
14822 The pragma NOJTBOUND
14823 \begin_inset LatexCommand \index{\#pragma NOJTBOUND}
14827 can be used to turn off checking the
14840 \layout Subsubsection
14842 Bit-shifting Operations
14843 \begin_inset LatexCommand \index{Bit shifting}
14850 Bit shifting is one of the most frequently used operation in embedded programmin
14852 SDCC tries to implement bit-shift operations in the most efficient way
14868 generates the following code:
14885 In general SDCC will never setup a loop if the shift count is known.
14927 Note that SDCC stores numbers in little-endian
14928 \begin_inset LatexCommand \index{little-endian}
14933 \begin_inset LatexCommand \index{Endianness}
14938 lowest order first).
14939 \layout Subsubsection
14942 \begin_inset LatexCommand \index{Bit rotation}
14949 A special case of the bit-shift operation is bit rotation, SDCC recognizes
14950 the following expression to be a left bit-rotation:
14960 i = ((i << 1) | (i >> 7));
14969 will generate the following code:
14988 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
14989 ns of this case will also be recognized as bit-rotation, i.e.:
14994 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
14995 \layout Subsubsection
14998 \begin_inset LatexCommand \index{Highest Order Bit}
15005 It is frequently required to obtain the highest order bit of an integral
15006 type (long, int, short or char types).
15007 SDCC recognizes the following expression to yield the highest order bit
15008 and generates optimized code for it, e.g.:
15030 hob = (gint >> 15) & 1;
15040 will generate the following code:
15073 000A E5*01\SpecialChar ~
15100 000C 23\SpecialChar ~
15131 000D 54 01\SpecialChar ~
15158 000F F5*02\SpecialChar ~
15186 Variations of this case however will
15191 It is a standard C expression, so I heartily recommend this be the only
15192 way to get the highest order bit, (it is portable).
15193 Of course it will be recognized even if it is embedded in other expressions,
15199 xyz = gint + ((gint >> 15) & 1);
15202 will still be recognized.
15203 \layout Subsubsection
15206 \begin_inset LatexCommand \index{Peephole optimizer}
15213 The compiler uses a rule based, pattern matching and re-writing mechanism
15214 for peep-hole optimization.
15219 a peep-hole optimizer by Christopher W.
15220 Fraser (cwfraser@microsoft.com).
15221 A default set of rules are compiled into the compiler, additional rules
15222 may be added with the
15235 \begin_inset LatexCommand \index{-\/-peep-file}
15242 The rule language is best illustrated with examples.
15266 The above rule will change the following assembly
15267 \begin_inset LatexCommand \index{Assembler routines}
15289 Note: All occurrences of a
15293 (pattern variable) must denote the same string.
15294 With the above rule, the assembly sequence:
15304 will remain unmodified.
15308 Other special case optimizations may be added by the user (via
15324 some variants of the 8051 MCU allow only
15333 The following two rules will change all
15352 replace { lcall %1 } by { acall %1 }
15354 replace { ljmp %1 } by { ajmp %1 }
15359 inline-assembler code
15361 is also passed through the peep hole optimizer, thus the peephole optimizer
15362 can also be used as an assembly level macro expander.
15363 The rules themselves are MCU dependent whereas the rule language infra-structur
15364 e is MCU independent.
15365 Peephole optimization rules for other MCU can be easily programmed using
15370 The syntax for a rule is as follows:
15375 rule := replace [ restart ] '{' <assembly sequence> '
15413 <assembly sequence> '
15431 '}' [if <functionName> ] '
15436 <assembly sequence> := assembly instruction (each instruction including
15437 labels must be on a separate line).
15441 The optimizer will apply to the rules one by one from the top in the sequence
15442 of their appearance, it will terminate when all rules are exhausted.
15443 If the 'restart' option is specified, then the optimizer will start matching
15444 the rules again from the top, this option for a rule is expensive (performance)
15445 , it is intended to be used in situations where a transformation will trigger
15446 the same rule again.
15447 An example of this (not a good one, it has side effects) is the following
15470 Note that the replace pattern cannot be a blank, but can be a comment line.
15471 Without the 'restart' option only the inner most 'pop' 'push' pair would
15472 be eliminated, i.e.:
15502 the restart option the rule will be applied again to the resulting code
15503 and then all the pop-push pairs will be eliminated to yield:
15513 A conditional function can be attached to a rule.
15514 Attaching rules are somewhat more involved, let me illustrate this with
15541 The optimizer does a look-up of a function name table defined in function
15546 in the source file SDCCpeeph.c, with the name
15551 If it finds a corresponding entry the function is called.
15552 Note there can be no parameters specified for these functions, in this
15557 is crucial, since the function
15561 expects to find the label in that particular variable (the hash table containin
15562 g the variable bindings is passed as a parameter).
15563 If you want to code more such functions, take a close look at the function
15564 labelInRange and the calling mechanism in source file SDCCpeeph.c.
15565 Currently implemented are
15567 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
15568 24bitMode, portIsDS390, 24bitModeAndPortDS390
15577 I know this whole thing is a little kludgey, but maybe some day we will
15578 have some better means.
15579 If you are looking at this file, you will see the default rules that are
15580 compiled into the compiler, you can add your own rules in the default set
15581 there if you get tired of specifying the -
15601 <pending: this is messy and incomplete>
15606 Compiler support routines (_gptrget, _mulint etc)
15609 Stdclib functions (puts, printf, strcat etc)
15612 Math functions (sin, pow, sqrt etc)
15616 \begin_inset LatexCommand \index{Libraries}
15620 included in SDCC should have a license at least as liberal as the GNU Lesser
15621 General Public License
15622 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
15633 license statements for the libraries are missing.
15634 sdcc/device/lib/ser_ir.c
15638 come with a GPL (as opposed to LGPL) License - this will not be liberal
15639 enough for many embedded programmers.
15643 \begin_inset LatexCommand \label{sub:External-Stack}
15648 \begin_inset LatexCommand \index{stack}
15653 \begin_inset LatexCommand \index{External stack}
15660 The external stack (-
15671 \begin_inset LatexCommand \index{-\/-xstack}
15675 ) is located at the start of the external ram segment, and is 256 bytes
15687 -xstack option is used to compile the program, the parameters and local
15688 variables of all reentrant functions are allocated in this area.
15689 This option is provided for programs with large stack space requirements.
15690 When used with the -
15701 \begin_inset LatexCommand \index{-\/-stack-auto}
15705 option, all parameters and local variables are allocated on the external
15706 stack (note support libraries will need to be recompiled with the same
15710 The compiler outputs the higher order address byte of the external ram segment
15711 into PORT P2, therefore when using the External Stack option, this port
15712 MAY NOT be used by the application program.
15716 \begin_inset LatexCommand \index{ANSI-compliance}
15723 Deviations from the compliance:
15726 functions are not always reentrant.
15729 structures cannot be assigned values directly, cannot be passed as function
15730 parameters or assigned to each other and cannot be a return value from
15757 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
15768 struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
15790 return rets;/* is invalid in SDCC although allowed in ANSI */
15797 \begin_inset LatexCommand \index{long long (not supported)}
15802 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
15810 \begin_inset LatexCommand \index{double (not supported)}
15814 ' precision floating point
15815 \begin_inset LatexCommand \index{Floating point support}
15822 No support for setjmp and longjmp (for now).
15826 \begin_inset LatexCommand \index{K\&R style}
15830 function declarations are NOT allowed.
15836 foo(i,j) /* this old style of function declarations */
15838 int i,j; /* are valid in ANSI but not valid in SDCC */
15853 functions declared as pointers must be dereferenced during the call.
15864 /* has to be called like this */
15866 (*foo)(); /* ANSI standard allows calls to be made like 'foo()' */
15870 Cyclomatic Complexity
15871 \begin_inset LatexCommand \index{Cyclomatic complexity}
15878 Cyclomatic complexity of a function is defined as the number of independent
15879 paths the program can take during execution of the function.
15880 This is an important number since it defines the number test cases you
15881 have to generate to validate the function.
15882 The accepted industry standard for complexity number is 10, if the cyclomatic
15883 complexity reported by SDCC exceeds 10 you should think about simplification
15884 of the function logic.
15885 Note that the complexity level is not related to the number of lines of
15886 code in a function.
15887 Large functions can have low complexity, and small functions can have large
15893 SDCC uses the following formula to compute the complexity:
15898 complexity = (number of edges in control flow graph) - (number of nodes
15899 in control flow graph) + 2;
15903 Having said that the industry standard is 10, you should be aware that in
15904 some cases it be may unavoidable to have a complexity level of less than
15906 For example if you have switch statement with more than 10 case labels,
15907 each case label adds one to the complexity level.
15908 The complexity level is by no means an absolute measure of the algorithmic
15909 complexity of the function, it does however provide a good starting point
15910 for which functions you might look at for further optimization.
15914 \layout Subsubsection
15917 \begin_inset LatexCommand \index{MCS51 variants}
15924 MCS51 processors are available from many vendors and come in many different
15926 While they might differ considerably in respect to Special Function Registers
15927 the core MCS51 is usually not modified or is kept compatible.
15929 \layout Subsubsection*
15931 pdata access by SFR
15934 With the upcome of devices with internal xdata and flash memory devices
15935 using port P2 as dedicated I/O port is becoming more popular.
15936 Switching the high byte for pdata
15937 \begin_inset LatexCommand \index{pdata}
15941 access which was formerly done by port P2 is then achieved by a Special
15943 In well-established MCS51 tradition the address of this
15947 is where the chip designers decided to put it.
15948 As pdata addressing is used in the startup code for the initialization
15949 of xdata variables a separate startup code should be used as described
15951 \begin_inset LatexCommand \ref{sub:Startup-Code}
15956 \layout Subsubsection*
15958 Other Features available by SFR
15961 Some MCS51 variants offer features like Double DPTR
15962 \begin_inset LatexCommand \index{DPTR}
15966 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
15967 These are currently not used for the MCS51 port.
15968 If you absolutely need them you can fall back to inline assembly or submit
15970 \layout Subsubsection
15972 The Z80 and gbz80 port
15975 SDCC can target both the Zilog
15976 \begin_inset LatexCommand \index{Z80}
15980 and the Nintendo Gameboy's Z80-like gbz80
15981 \begin_inset LatexCommand \index{GameBoy Z80}
15986 The Z80 port is passed through the same
15989 \begin_inset LatexCommand \index{Regression test}
15995 as MCS51 and DS390 ports, so floating point support, support for long variables
15996 and bitfield support is fine.
15999 As always, the code is the authoritative reference - see z80/ralloc.c and
16001 The stack frame is similar to that generated by the IAR Z80 compiler.
16002 IX is used as the base pointer, HL is used as a temporary register, and
16003 BC and DE are available for holding variables.
16004 IY is currently unused.
16005 Return values are stored in HL.
16006 One bad side effect of using IX as the base pointer is that a functions
16007 stack frame is limited to 127 bytes - this will be fixed in a later version.
16010 Retargetting for other MCUs.
16013 The issues for retargetting the compiler are far too numerous to be covered
16015 What follows is a brief description of each of the seven phases of the
16016 compiler and its MCU dependency.
16019 Parsing the source and building the annotated parse tree.
16020 This phase is largely MCU independent (except for the language extensions).
16021 Syntax & semantic checks are also done in this phase, along with some initial
16022 optimizations like back patching labels and the pattern matching optimizations
16023 like bit-rotation etc.
16026 The second phase involves generating an intermediate code which can be easy
16027 manipulated during the later phases.
16028 This phase is entirely MCU independent.
16029 The intermediate code generation assumes the target machine has unlimited
16030 number of registers, and designates them with the name iTemp.
16031 The compiler can be made to dump a human readable form of the code generated
16045 This phase does the bulk of the standard optimizations and is also MCU independe
16047 This phase can be broken down into several sub-phases:
16051 Break down intermediate code (iCode) into basic blocks.
16053 Do control flow & data flow analysis on the basic blocks.
16055 Do local common subexpression elimination, then global subexpression elimination
16057 Dead code elimination
16061 If loop optimizations caused any changes then do 'global subexpression eliminati
16062 on' and 'dead code elimination' again.
16065 This phase determines the live-ranges; by live range I mean those iTemp
16066 variables defined by the compiler that still survive after all the optimization
16068 Live range analysis
16069 \begin_inset LatexCommand \index{Live range analysis}
16073 is essential for register allocation, since these computation determines
16074 which of these iTemps will be assigned to registers, and for how long.
16077 Phase five is register allocation.
16078 There are two parts to this process.
16082 The first part I call 'register packing' (for lack of a better term).
16083 In this case several MCU specific expression folding is done to reduce
16088 The second part is more MCU independent and deals with allocating registers
16089 to the remaining live ranges.
16090 A lot of MCU specific code does creep into this phase because of the limited
16091 number of index registers available in the 8051.
16094 The Code generation phase is (unhappily), entirely MCU dependent and very
16095 little (if any at all) of this code can be reused for other MCU.
16096 However the scheme for allocating a homogenized assembler operand for each
16097 iCode operand may be reused.
16100 As mentioned in the optimization section the peep-hole optimizer is rule
16101 based system, which can reprogrammed for other MCUs.
16105 \begin_inset LatexCommand \index{Compiler internals}
16112 The anatomy of the compiler
16117 This is an excerpt from an article published in Circuit Cellar Magazine
16119 It's a little outdated (the compiler is much more efficient now and user/develo
16120 per friendly), but pretty well exposes the guts of it all.
16126 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
16127 It is fairly easy to retarget for other 8-bit MCU.
16128 Here we take a look at some of the internals of the compiler.
16133 \begin_inset LatexCommand \index{Parsing}
16140 Parsing the input source file and creating an AST (Annotated Syntax Tree
16141 \begin_inset LatexCommand \index{Annotated syntax tree}
16146 This phase also involves propagating types (annotating each node of the
16147 parse tree with type information) and semantic analysis.
16148 There are some MCU specific parsing rules.
16149 For example the storage classes, the extended storage classes are MCU specific
16150 while there may be a xdata storage class for 8051 there is no such storage
16151 class for z80 or Atmel AVR.
16152 SDCC allows MCU specific storage class extensions, i.e.
16153 xdata will be treated as a storage class specifier when parsing 8051 C
16154 code but will be treated as a C identifier when parsing z80 or ATMEL AVR
16159 \begin_inset LatexCommand \index{iCode}
16166 Intermediate code generation.
16167 In this phase the AST is broken down into three-operand form (iCode).
16168 These three operand forms are represented as doubly linked lists.
16169 ICode is the term given to the intermediate form generated by the compiler.
16170 ICode example section shows some examples of iCode generated for some simple
16171 C source functions.
16175 \begin_inset LatexCommand \index{Optimizations}
16182 Bulk of the target independent optimizations is performed in this phase.
16183 The optimizations include constant propagation, common sub-expression eliminati
16184 on, loop invariant code movement, strength reduction of loop induction variables
16185 and dead-code elimination.
16188 Live range analysis
16189 \begin_inset LatexCommand \index{Live range analysis}
16196 During intermediate code generation phase, the compiler assumes the target
16197 machine has infinite number of registers and generates a lot of temporary
16199 The live range computation determines the lifetime of each of these compiler-ge
16200 nerated temporaries.
16201 A picture speaks a thousand words.
16202 ICode example sections show the live range annotations for each of the
16204 It is important to note here, each iCode is assigned a number in the order
16205 of its execution in the function.
16206 The live ranges are computed in terms of these numbers.
16207 The from number is the number of the iCode which first defines the operand
16208 and the to number signifies the iCode which uses this operand last.
16211 Register Allocation
16212 \begin_inset LatexCommand \index{Register allocation}
16219 The register allocation determines the type and number of registers needed
16221 In most MCUs only a few registers can be used for indirect addressing.
16222 In case of 8051 for example the registers R0 & R1 can be used to indirectly
16223 address the internal ram and DPTR to indirectly address the external ram.
16224 The compiler will try to allocate the appropriate register to pointer variables
16226 ICode example section shows the operands annotated with the registers assigned
16228 The compiler will try to keep operands in registers as much as possible;
16229 there are several schemes the compiler uses to do achieve this.
16230 When the compiler runs out of registers the compiler will check to see
16231 if there are any live operands which is not used or defined in the current
16232 basic block being processed, if there are any found then it will push that
16233 operand and use the registers in this block, the operand will then be popped
16234 at the end of the basic block.
16238 There are other MCU specific considerations in this phase.
16239 Some MCUs have an accumulator; very short-lived operands could be assigned
16240 to the accumulator instead of general-purpose register.
16246 Figure II gives a table of iCode operations supported by the compiler.
16247 The code generation involves translating these operations into corresponding
16248 assembly code for the processor.
16249 This sounds overly simple but that is the essence of code generation.
16250 Some of the iCode operations are generated on a MCU specific manner for
16251 example, the z80 port does not use registers to pass parameters so the
16252 SEND and RECV iCode operations will not be generated, and it also does
16253 not support JUMPTABLES.
16260 <Where is Figure II ?>
16264 \begin_inset LatexCommand \index{iCode}
16271 This section shows some details of iCode.
16272 The example C code does not do anything useful; it is used as an example
16273 to illustrate the intermediate code generated by the compiler.
16285 /* This function does nothing useful.
16292 for the purpose of explaining iCode */
16295 short function (data int *x)
16303 short i=10; /* dead initialization eliminated */
16308 short sum=10; /* dead initialization eliminated */
16321 while (*x) *x++ = *p++;
16335 /* compiler detects i,j to be induction variables */
16339 for (i = 0, j = 10 ; i < 10 ; i++, j
16365 mul += i * 3; /* this multiplication remains */
16371 gint += j * 3;/* this multiplication changed to addition */
16385 In addition to the operands each iCode contains information about the filename
16386 and line it corresponds to in the source file.
16387 The first field in the listing should be interpreted as follows:
16392 Filename(linenumber: iCode Execution sequence number : ICode hash table
16393 key : loop depth of the iCode).
16398 Then follows the human readable form of the ICode operation.
16399 Each operand of this triplet form can be of three basic types a) compiler
16400 generated temporary b) user defined variable c) a constant value.
16401 Note that local variables and parameters are replaced by compiler generated
16404 \begin_inset LatexCommand \index{Live range analysis}
16408 are computed only for temporaries (i.e.
16409 live ranges are not computed for global variables).
16411 \begin_inset LatexCommand \index{Register allocation}
16415 are allocated for temporaries only.
16416 Operands are formatted in the following manner:
16421 Operand Name [lr live-from : live-to ] { type information } [ registers
16427 As mentioned earlier the live ranges are computed in terms of the execution
16428 sequence number of the iCodes, for example
16430 the iTemp0 is live from (i.e.
16431 first defined in iCode with execution sequence number 3, and is last used
16432 in the iCode with sequence number 5).
16433 For induction variables such as iTemp21 the live range computation extends
16434 the lifetime from the start to the end of the loop.
16436 The register allocator used the live range information to allocate registers,
16437 the same registers may be used for different temporaries if their live
16438 ranges do not overlap, for example r0 is allocated to both iTemp6 and to
16439 iTemp17 since their live ranges do not overlap.
16440 In addition the allocator also takes into consideration the type and usage
16441 of a temporary, for example itemp6 is a pointer to near space and is used
16442 as to fetch data from (i.e.
16443 used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer registers (r0).
16444 Some short lived temporaries are allocated to special registers which have
16445 meaning to the code generator e.g.
16446 iTemp13 is allocated to a pseudo register CC which tells the back end that
16447 the temporary is used only for a conditional jump the code generation makes
16448 use of this information to optimize a compare and jump ICode.
16450 There are several loop optimizations
16451 \begin_inset LatexCommand \index{Loop optimization}
16455 performed by the compiler.
16456 It can detect induction variables iTemp21(i) and iTemp23(j).
16457 Also note the compiler does selective strength reduction
16458 \begin_inset LatexCommand \index{Strength reduction}
16463 the multiplication of an induction variable in line 18 (gint = j * 3) is
16464 changed to addition, a new temporary iTemp17 is allocated and assigned
16465 a initial value, a constant 3 is then added for each iteration of the loop.
16466 The compiler does not change the multiplication
16467 \begin_inset LatexCommand \index{Multiplication}
16471 in line 17 however since the processor does support an 8 * 8 bit multiplication.
16473 Note the dead code elimination
16474 \begin_inset LatexCommand \index{Dead-code elimination}
16478 optimization eliminated the dead assignments in line 7 & 8 to I and sum
16486 Sample.c (5:1:0:0) _entry($9) :
16491 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
16496 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv
16501 Sample.c(11:4:53:0) preHeaderLbl0($11) :
16506 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
16512 Sample.c(11:6:5:1) _whilecontinue_0($1) :
16517 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
16523 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
16528 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
16534 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
16540 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
16546 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
16552 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
16553 * int}[r0] + 0x2 {short}
16558 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
16563 Sample.c(11:17:21:0)_whilebreak_0($3) :
16568 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
16573 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
16578 Sample.c(15:20:54:0)preHeaderLbl1($13) :
16583 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
16588 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
16593 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
16598 Sample.c(15:24:26:1)_forcond_0($4) :
16603 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
16609 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
16614 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
16615 + ITemp21 [lr21:38]{short}[r4]
16620 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
16626 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
16627 + iTemp15 [lr29:30]{short}[r1]
16632 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
16638 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
16644 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
16650 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
16656 Sample.c(19:38:47:1) goto _forcond_0($4)
16661 Sample.c(19:39:48:0)_forbreak_0($7) :
16666 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
16667 + ITemp11 [lr19:40]{short}[r3]
16672 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
16677 Sample.c(20:42:51:0)_return($8) :
16682 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
16688 Finally the code generated for this function:
16729 ; ----------------------------------------------
16734 ; function function
16739 ; ----------------------------------------------
16749 ; iTemp0 [lr3:5]{_near * int}[r2] = recv
16761 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
16773 ;_whilecontinue_0($1) :
16783 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
16788 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
16847 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
16866 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
16913 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
16953 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
16979 ; iTemp6 [lr5:16]{_near * int}[r0] =
16984 ; iTemp6 [lr5:16]{_near * int}[r0] +
17001 ; goto _whilecontinue_0($1)
17013 ; _whilebreak_0($3) :
17023 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
17035 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
17047 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
17059 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
17078 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
17107 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
17112 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
17157 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] +
17162 ; iTemp21 [lr21:38]{short}[r4]
17188 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
17221 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] +
17226 ; iTemp15 [lr29:30]{short}[r1]
17245 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
17292 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
17339 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
17351 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
17365 cjne r5,#0xff,00104$
17377 ; goto _forcond_0($4)
17389 ; _forbreak_0($7) :
17399 ; ret iTemp24 [lr40:41]{short}
17442 A few words about basic block successors, predecessors and dominators
17445 Successors are basic blocks
17446 \begin_inset LatexCommand \index{Basic blocks}
17450 that might execute after this basic block.
17452 Predecessors are basic blocks that might execute before reaching this basic
17455 Dominators are basic blocks that WILL execute before reaching this basic
17489 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
17492 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
17495 c) domVect of [BB4] = BB1 ...
17496 here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
17504 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
17514 Thanks to all the other volunteer developers who have helped with coding,
17515 testing, web-page creation, distribution sets, etc.
17516 You know who you are :-)
17523 This document was initially written by Sandeep Dutta
17526 All product names mentioned herein may be trademarks
17527 \begin_inset LatexCommand \index{Trademarks}
17531 of their respective companies.
17538 To avoid confusion, the installation and building options for sdcc itself
17539 (chapter 2) are not part of the index.
17543 \begin_inset LatexCommand \printindex{}